Plugin loading: style fixes.
* Fix style issues pointed by stippi. Thanks! * Rework the FormatManager instanciation to be thread safe.
This commit is contained in:
@@ -24,6 +24,7 @@
|
||||
|
||||
#include "debug.h"
|
||||
|
||||
#include "FormatManager.h"
|
||||
#include "MetaFormat.h"
|
||||
|
||||
|
||||
@@ -246,9 +247,10 @@ void
|
||||
AddOnManager::_RegisterAddOns()
|
||||
{
|
||||
// Check if add-ons are already registered.
|
||||
if(!fReaderList.IsEmpty() || !fWriterList.IsEmpty()
|
||||
|| !fDecoderList.IsEmpty() || !fEncoderList.IsEmpty())
|
||||
if (!fReaderList.IsEmpty() || !fWriterList.IsEmpty()
|
||||
|| !fDecoderList.IsEmpty() || !fEncoderList.IsEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
char** directories = NULL;
|
||||
size_t directoryCount = 0;
|
||||
@@ -348,7 +350,8 @@ printf("removing reader '%s'\n", readerInfo->ref.name);
|
||||
printf("removing decoder '%s'\n", decoderInfo->ref.name);
|
||||
media_format* format;
|
||||
for (decoderInfo->formats.Rewind();
|
||||
decoderInfo->formats.GetNext(&format);) {
|
||||
decoderInfo->formats.GetNext(&format);) {
|
||||
FormatManager::GetInstance()->RemoveFormat(*format);
|
||||
}
|
||||
fDecoderList.RemoveCurrent();
|
||||
break;
|
||||
|
||||
@@ -129,6 +129,30 @@ FormatManager::FormatManager()
|
||||
}
|
||||
|
||||
|
||||
pthread_once_t FormatManager::sInitOnce;
|
||||
FormatManager* FormatManager::sInstance = NULL;
|
||||
|
||||
|
||||
/* static */ void
|
||||
FormatManager::CreateInstance()
|
||||
{
|
||||
sInstance = new FormatManager();
|
||||
}
|
||||
|
||||
|
||||
/* static */ FormatManager*
|
||||
FormatManager::GetInstance()
|
||||
{
|
||||
static FormatManager* sFormatManager = NULL;
|
||||
if (sFormatManager == NULL)
|
||||
pthread_once(&sInitOnce, &CreateInstance);
|
||||
|
||||
return sFormatManager;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
FormatManager::~FormatManager()
|
||||
{
|
||||
}
|
||||
@@ -220,8 +244,7 @@ FormatManager::MakeFormatFor(const media_format_description* descriptions,
|
||||
|
||||
status_t result = B_OK;
|
||||
// TODO: Support "flags" (B_SET_DEFAULT, B_EXCLUSIVE, B_NO_MERGE)!
|
||||
int32 i = 0;
|
||||
for(i = 0; i < descriptionCount; i++) {
|
||||
for (int32 i = 0; i < descriptionCount; i++) {
|
||||
meta_format* metaFormat = new(std::nothrow) meta_format(
|
||||
descriptions[i], format, codec);
|
||||
if (metaFormat == NULL
|
||||
|
||||
@@ -12,13 +12,13 @@
|
||||
|
||||
#include <Locker.h>
|
||||
#include <ObjectList.h>
|
||||
#include <pthread.h>
|
||||
|
||||
#include "MetaFormat.h"
|
||||
|
||||
|
||||
class FormatManager {
|
||||
public:
|
||||
FormatManager();
|
||||
~FormatManager();
|
||||
|
||||
void GetFormats(bigtime_t lastUpdate, BMessage& reply);
|
||||
@@ -29,6 +29,11 @@ public:
|
||||
void* _reserved);
|
||||
void RemoveFormat(const media_format& format);
|
||||
|
||||
static FormatManager* GetInstance();
|
||||
|
||||
private:
|
||||
FormatManager();
|
||||
static void CreateInstance();
|
||||
private:
|
||||
typedef BPrivate::media::meta_format meta_format;
|
||||
|
||||
@@ -36,6 +41,9 @@ private:
|
||||
BLocker fLock;
|
||||
bigtime_t fLastUpdate;
|
||||
int32 fNextCodecID;
|
||||
|
||||
static FormatManager* sInstance;
|
||||
static pthread_once_t sInitOnce;
|
||||
};
|
||||
|
||||
#endif // _FORMAT_MANAGER_H
|
||||
|
||||
@@ -42,32 +42,33 @@ get_next_encoder(int32* cookie, const media_file_format* fileFormat,
|
||||
return B_BAD_VALUE;
|
||||
|
||||
while (true) {
|
||||
media_codec_info codec_info;
|
||||
media_format_family format_family;
|
||||
media_format input_format;
|
||||
media_format output_format;
|
||||
media_codec_info candidateCodecInfo;
|
||||
media_format_family candidateFormatFamily;
|
||||
media_format candidateInputFormat;
|
||||
media_format candidateOutputFormat;
|
||||
|
||||
status_t ret = AddOnManager::GetInstance()->GetCodecInfo(&codec_info,
|
||||
&format_family, &input_format, &output_format, *cookie);
|
||||
status_t ret = AddOnManager::GetInstance()->GetCodecInfo(
|
||||
&candidateCodecInfo, &candidateFormatFamily,
|
||||
&candidateInputFormat, &candidateOutputFormat, *cookie);
|
||||
|
||||
if (ret != B_OK)
|
||||
return ret;
|
||||
|
||||
*cookie = *cookie + 1;
|
||||
|
||||
if (fileFormat != NULL && format_family != B_ANY_FORMAT_FAMILY
|
||||
if (fileFormat != NULL && candidateFormatFamily != B_ANY_FORMAT_FAMILY
|
||||
&& fileFormat->family != B_ANY_FORMAT_FAMILY
|
||||
&& fileFormat->family != format_family) {
|
||||
&& fileFormat->family != candidateFormatFamily) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!input_format.Matches(inputFormat))
|
||||
if (!candidateInputFormat.Matches(inputFormat))
|
||||
continue;
|
||||
|
||||
if (_outputFormat != NULL)
|
||||
*_outputFormat = output_format;
|
||||
*_outputFormat = candidateOutputFormat;
|
||||
|
||||
*_codecInfo = codec_info;
|
||||
*_codecInfo = candidateCodecInfo;
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -91,27 +92,28 @@ get_next_encoder(int32* cookie, const media_file_format* fileFormat,
|
||||
}
|
||||
|
||||
while (true) {
|
||||
media_codec_info codec_info;
|
||||
media_format_family format_family;
|
||||
media_format input_format;
|
||||
media_format output_format;
|
||||
media_codec_info candidateCodecInfo;
|
||||
media_format_family candidateFormatFamily;
|
||||
media_format candidateInputFormat;
|
||||
media_format candidateOutputFormat;
|
||||
|
||||
status_t ret = AddOnManager::GetInstance()->GetCodecInfo(&codec_info,
|
||||
&format_family, &input_format, &output_format, *cookie);
|
||||
status_t ret = AddOnManager::GetInstance()->GetCodecInfo(
|
||||
&candidateCodecInfo, &candidateFormatFamily, &candidateInputFormat,
|
||||
&candidateOutputFormat, *cookie);
|
||||
|
||||
if (ret != B_OK)
|
||||
return ret;
|
||||
|
||||
*cookie = *cookie + 1;
|
||||
|
||||
if (fileFormat != NULL && format_family != B_ANY_FORMAT_FAMILY
|
||||
if (fileFormat != NULL && candidateFormatFamily != B_ANY_FORMAT_FAMILY
|
||||
&& fileFormat->family != B_ANY_FORMAT_FAMILY
|
||||
&& fileFormat->family != format_family) {
|
||||
&& fileFormat->family != candidateFormatFamily) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!input_format.Matches(inputFormat)
|
||||
|| !output_format.Matches(outputFormat)) {
|
||||
if (!candidateInputFormat.Matches(inputFormat)
|
||||
|| !candidateOutputFormat.Matches(outputFormat)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -121,11 +123,11 @@ get_next_encoder(int32* cookie, const media_file_format* fileFormat,
|
||||
// possible, we actually have to instantiate an Encoder here and
|
||||
// ask it to specifiy the format.
|
||||
if (_acceptedInputFormat != NULL)
|
||||
*_acceptedInputFormat = input_format;
|
||||
*_acceptedInputFormat = candidateInputFormat;
|
||||
if (_acceptedOutputFormat != NULL)
|
||||
*_acceptedOutputFormat = output_format;
|
||||
*_acceptedOutputFormat = candidateOutputFormat;
|
||||
|
||||
*_codecInfo = codec_info;
|
||||
*_codecInfo = candidateCodecInfo;
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -139,18 +141,16 @@ get_next_encoder(int32* cookie, media_codec_info* _codecInfo)
|
||||
if (cookie == NULL || _codecInfo == NULL)
|
||||
return B_BAD_VALUE;
|
||||
|
||||
media_codec_info codec_info;
|
||||
media_format_family format_family;
|
||||
media_format input_format;
|
||||
media_format output_format;
|
||||
media_format_family formatFamily;
|
||||
media_format inputFormat;
|
||||
media_format outputFormat;
|
||||
|
||||
status_t ret = AddOnManager::GetInstance()->GetCodecInfo(&codec_info,
|
||||
&format_family, &input_format, &output_format, *cookie);
|
||||
status_t ret = AddOnManager::GetInstance()->GetCodecInfo(_codecInfo,
|
||||
&formatFamily, &inputFormat, &outputFormat, *cookie);
|
||||
if (ret != B_OK)
|
||||
return ret;
|
||||
|
||||
*cookie = *cookie + 1;
|
||||
*_codecInfo = codec_info;
|
||||
|
||||
return B_OK;
|
||||
}
|
||||
@@ -354,14 +354,10 @@ meta_format::Compare(const meta_format* a, const meta_format* b)
|
||||
|
||||
|
||||
/** We share one global list for all BMediaFormats in the team - since the
|
||||
* format data can change at any time, we have to ask the server to update
|
||||
* the list to ensure that we are working on the latest data set.
|
||||
* The list we get from the server is always sorted by description.
|
||||
* The formats lock has to be hold when you call this function.
|
||||
* format data can change at any time, we have to update the list to ensure
|
||||
* that we are working on the latest data set. The list is always sorted by
|
||||
* description. The formats lock has to be held when you call this function.
|
||||
*/
|
||||
|
||||
FormatManager* gFormatManager = NULL;
|
||||
|
||||
static status_t
|
||||
update_media_formats()
|
||||
{
|
||||
@@ -369,9 +365,7 @@ update_media_formats()
|
||||
return B_NOT_ALLOWED;
|
||||
|
||||
BMessage reply;
|
||||
if (gFormatManager == NULL)
|
||||
gFormatManager = new FormatManager;
|
||||
gFormatManager->GetFormats(sLastFormatsUpdate, reply);
|
||||
FormatManager::GetInstance()->GetFormats(sLastFormatsUpdate, reply);
|
||||
|
||||
// do we need an update at all?
|
||||
bool needUpdate;
|
||||
@@ -622,10 +616,7 @@ BMediaFormats::MakeFormatFor(const media_format_description* descriptions,
|
||||
int32 descriptionCount, media_format* format, uint32 flags,
|
||||
void* _reserved)
|
||||
{
|
||||
if (gFormatManager == NULL)
|
||||
gFormatManager = new FormatManager;
|
||||
|
||||
status_t status = gFormatManager->MakeFormatFor(descriptions,
|
||||
status_t status = FormatManager::GetInstance()->MakeFormatFor(descriptions,
|
||||
descriptionCount, *format, flags, _reserved);
|
||||
|
||||
return status;
|
||||
|
||||
Reference in New Issue
Block a user