Register media add-ons on BMediaFormat::GetFormatFor().

* Fixes #11018.
* In this case the FormatManager format list is accessed without going
throught the AddOnManager, so we must tell the AddOnManager to register
the add-ons (as this is what populates the FormatManager format list).
* Remove now unneeded workaround in mp3_decoder_test.
This commit is contained in:
Adrien Destugues 2014-10-22 15:25:06 +02:00
parent 2d88b1bd33
commit 72d4735712
4 changed files with 13 additions and 29 deletions

View File

@ -95,7 +95,7 @@ AddOnManager::GetDecoderForFormat(entry_ref* _decoderRef,
return B_MEDIA_BAD_FORMAT;
BAutolock locker(fLock);
_RegisterAddOns();
RegisterAddOns();
// Since the list of decoders is unsorted, we need to search for
// a decoder by add-on directory, in order to maintain the shadowing
@ -128,7 +128,7 @@ AddOnManager::GetReaders(entry_ref* outRefs, int32* outCount,
int32 maxCount)
{
BAutolock locker(fLock);
_RegisterAddOns();
RegisterAddOns();
*outCount = 0;
@ -158,7 +158,7 @@ status_t
AddOnManager::GetEncoder(entry_ref* _encoderRef, int32 id)
{
BAutolock locker(fLock);
_RegisterAddOns();
RegisterAddOns();
encoder_info* info;
for (fEncoderList.Rewind(); fEncoderList.GetNext(&info);) {
@ -177,7 +177,7 @@ status_t
AddOnManager::GetWriter(entry_ref* _ref, uint32 internalID)
{
BAutolock locker(fLock);
_RegisterAddOns();
RegisterAddOns();
writer_info* info;
for (fWriterList.Rewind(); fWriterList.GetNext(&info);) {
@ -195,7 +195,7 @@ status_t
AddOnManager::GetFileFormat(media_file_format* _fileFormat, int32 cookie)
{
BAutolock locker(fLock);
_RegisterAddOns();
RegisterAddOns();
media_file_format* fileFormat;
if (fWriterFileFormats.Get(cookie, &fileFormat)) {
@ -213,7 +213,7 @@ AddOnManager::GetCodecInfo(media_codec_info* _codecInfo,
media_format* _inputFormat, media_format* _outputFormat, int32 cookie)
{
BAutolock locker(fLock);
_RegisterAddOns();
RegisterAddOns();
encoder_info* info;
if (fEncoderList.Get(cookie, &info)) {
@ -232,7 +232,7 @@ AddOnManager::GetCodecInfo(media_codec_info* _codecInfo,
void
AddOnManager::_RegisterAddOns()
AddOnManager::RegisterAddOns()
{
// Check if add-ons are already registered.
if (!fReaderList.IsEmpty() || !fWriterList.IsEmpty()

View File

@ -50,8 +50,9 @@ public:
media_format* _inputFormat,
media_format* _outputFormat, int32 cookie);
void RegisterAddOns();
private:
void _RegisterAddOns();
status_t _RegisterAddOn(const entry_ref& ref);
status_t _UnregisterAddOn(const entry_ref& ref);

View File

@ -364,6 +364,10 @@ update_media_formats()
if (!sLock.IsLocked())
return B_NOT_ALLOWED;
// We want the add-ons to register themselves with the format manager, so
// the list is up to date.
AddOnManager::GetInstance()->RegisterAddOns();
BMessage reply;
FormatManager::GetInstance()->GetFormats(sLastFormatsUpdate, reply);

View File

@ -124,27 +124,6 @@ main(int argc, char* argv[])
{
BApplication app("application/x-vnd.mp3-decoder-test");
// TODO: The following code block is a workaround for the bug #11018
// (https://dev.haiku-os.org/ticket/11018). Please remove this code block,
// once the bug is being resolved.
// The workaround triggers the loading of all media plugins prior to using
// methods of class BMediaFormats. Using the function get_next_encoder()
// is used because of two facts
// 1. It is publicly available and thus can be used by 3rd party apps,
// too.
// 2. It is already available by including BMediaFormats.h, so there is
// no need to include another header for this workaround.
// Also, please leave the workaround code at this -prominent- place
// instead of moving it to the more appropriate place in
// InitializeMp3DecodingCookie(). This way it acts as a reminder to fix
// the bug :)
int32 workaroundCookie = 0;
media_codec_info workaroundMediaCodecInfo;
status_t workaroundStatus = get_next_encoder(&workaroundCookie,
&workaroundMediaCodecInfo);
if (workaroundStatus < B_OK)
exit(99);
cookie_decode decodingCookie;
if (InitializeMp3DecodingCookie(&decodingCookie) != B_OK)
exit(1);