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