From a0a20160cd91e5eb9d6f4bd30418d22c3c3aa59d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Axel=20D=C3=B6rfler?= Date: Fri, 23 Jan 2004 07:55:01 +0000 Subject: [PATCH] Updated all decoders to the changed codec API (from meta_descriptions to BMediaFormats based detection). git-svn-id: file:///srv/svn/repos/haiku/trunk/current@6248 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- .../plugins/mp3_decoder/mp3DecoderPlugin.cpp | 45 ++++++++++++++----- .../plugins/mp3_decoder/mp3DecoderPlugin.h | 4 +- .../media/plugins/musepack/MusePack.cpp | 15 +++++-- src/add-ons/media/plugins/musepack/MusePack.h | 2 +- .../plugins/musepack/MusePackDecoder.cpp | 8 ++++ .../media/plugins/musepack/MusePackDecoder.h | 4 +- .../media/plugins/musepack/MusePackReader.cpp | 12 +++-- .../plugins/ogg/OggReaderPluginCodecs.cpp | 19 ++++---- .../plugins/raw_decoder/RawDecoderPlugin.cpp | 40 +++++++++++++++-- .../plugins/raw_decoder/RawDecoderPlugin.h | 4 +- .../media/plugins/speex/speexCodecPlugin.cpp | 25 +++++++++-- .../media/plugins/speex/speexCodecPlugin.h | 5 ++- .../plugins/vorbis/vorbisCodecPlugin.cpp | 28 +++++++++--- .../media/plugins/vorbis/vorbisCodecPlugin.h | 3 +- 14 files changed, 168 insertions(+), 46 deletions(-) diff --git a/src/add-ons/media/plugins/mp3_decoder/mp3DecoderPlugin.cpp b/src/add-ons/media/plugins/mp3_decoder/mp3DecoderPlugin.cpp index a9538b8d76..f663600434 100644 --- a/src/add-ons/media/plugins/mp3_decoder/mp3DecoderPlugin.cpp +++ b/src/add-ons/media/plugins/mp3_decoder/mp3DecoderPlugin.cpp @@ -82,6 +82,15 @@ mp3Decoder::~mp3Decoder() } +void +mp3Decoder::GetCodecInfo(media_codec_info &info) +{ + strcpy(info.short_name, "mp3"); + strcpy(info.pretty_name, "MPEG 1/2.5 audio layer 1/2/3 decoder, based on mpeg123 mpglib"); + // ToDo: could alter the above string depending on the real format +} + + status_t mp3Decoder::Setup(media_format *ioEncodedFormat, const void *infoBuffer, int32 infoSize) @@ -334,18 +343,32 @@ mp3DecoderPlugin::NewDecoder() status_t -mp3DecoderPlugin::RegisterPlugin() +mp3DecoderPlugin::RegisterDecoder() { - PublishDecoder("audiocodec/mpeg1layer1", "mp3", "MPEG 1 audio layer 1 decoder, based on mpeg123 mpglib"); - PublishDecoder("audiocodec/mpeg1layer2", "mp3", "MPEG 1 audio layer 2 decoder, based on mpeg123 mpglib"); - PublishDecoder("audiocodec/mpeg1layer3", "mp3", "MPEG 1 audio layer 3 decoder, based on mpeg123 mpglib"); - PublishDecoder("audiocodec/mpeg2layer1", "mp3", "MPEG 2 audio layer 1 decoder, based on mpeg123 mpglib"); - PublishDecoder("audiocodec/mpeg2layer2", "mp3", "MPEG 2 audio layer 2 decoder, based on mpeg123 mpglib"); - PublishDecoder("audiocodec/mpeg2layer3", "mp3", "MPEG 2 audio layer 3 decoder, based on mpeg123 mpglib"); - PublishDecoder("audiocodec/mpeg2.5layer1", "mp3", "MPEG 2.5 audio layer 1 decoder, based on mpeg123 mpglib"); - PublishDecoder("audiocodec/mpeg2.5layer2", "mp3", "MPEG 2.5 audio layer 2 decoder, based on mpeg123 mpglib"); - PublishDecoder("audiocodec/mpeg2.5layer3", "mp3", "MPEG 2.5 audio layer 3 decoder, based on mpeg123 mpglib"); - return B_OK; + const mpeg_id ids[] = { + B_MPEG_1_AUDIO_LAYER_1, + B_MPEG_1_AUDIO_LAYER_2, + B_MPEG_1_AUDIO_LAYER_3, // "MP3" + B_MPEG_2_AUDIO_LAYER_1, + B_MPEG_2_AUDIO_LAYER_2, + B_MPEG_2_AUDIO_LAYER_3, + B_MPEG_2_5_AUDIO_LAYER_1, + B_MPEG_2_5_AUDIO_LAYER_2, + B_MPEG_2_5_AUDIO_LAYER_3, + }; + const size_t numIDs = sizeof(ids) / sizeof(mpeg_id); + + media_format_description descriptions[numIDs]; + for (size_t i = 0; i < numIDs; i++) { + descriptions[i].family = B_MPEG_FORMAT_FAMILY; + descriptions[i].u.mpeg.id = ids[i]; + } + + media_format format; + format.type = B_MEDIA_ENCODED_AUDIO; + format.u.encoded_audio = media_encoded_audio_format::wildcard; + + return BMediaFormats().MakeFormatFor(descriptions, numIDs, &format); } diff --git a/src/add-ons/media/plugins/mp3_decoder/mp3DecoderPlugin.h b/src/add-ons/media/plugins/mp3_decoder/mp3DecoderPlugin.h index 507d8ecbc8..c4aceeaad1 100644 --- a/src/add-ons/media/plugins/mp3_decoder/mp3DecoderPlugin.h +++ b/src/add-ons/media/plugins/mp3_decoder/mp3DecoderPlugin.h @@ -8,6 +8,8 @@ public: mp3Decoder(); ~mp3Decoder(); + void GetCodecInfo(media_codec_info &codecInfo); + status_t Setup(media_format *ioEncodedFormat, const void *infoBuffer, int32 infoSize); @@ -45,5 +47,5 @@ class mp3DecoderPlugin : public DecoderPlugin { public: Decoder * NewDecoder(); - status_t RegisterPlugin(); + status_t RegisterDecoder(); }; diff --git a/src/add-ons/media/plugins/musepack/MusePack.cpp b/src/add-ons/media/plugins/musepack/MusePack.cpp index 886c9253d2..a11f546bac 100644 --- a/src/add-ons/media/plugins/musepack/MusePack.cpp +++ b/src/add-ons/media/plugins/musepack/MusePack.cpp @@ -22,10 +22,19 @@ MusePackPlugin::NewDecoder() } status_t -MusePackPlugin::RegisterPlugin() +MusePackPlugin::RegisterDecoder() { - PublishDecoder("audiocodec/musepack", "musepack", "musepack decoder"); - return B_OK; + media_format_description description; + description.family = B_MISC_FORMAT_FAMILY; + description.u.misc.file_format = 'mpc '; + description.u.misc.codec = 'MPC7'; + // 7 is the most recent stream version + + media_format format; + format.type = B_MEDIA_ENCODED_AUDIO; + format.u.encoded_audio = media_encoded_audio_format::wildcard; + + return BMediaFormats().MakeFormatFor(&description, 1, &format); } diff --git a/src/add-ons/media/plugins/musepack/MusePack.h b/src/add-ons/media/plugins/musepack/MusePack.h index 7a88792684..9c5e1c78e3 100644 --- a/src/add-ons/media/plugins/musepack/MusePack.h +++ b/src/add-ons/media/plugins/musepack/MusePack.h @@ -15,7 +15,7 @@ class MusePackPlugin : public ReaderPlugin, public DecoderPlugin { Reader *NewReader(); Decoder *NewDecoder(); - status_t RegisterPlugin(); + status_t RegisterDecoder(); }; #endif /* MUSEPACK_PLUGIN_H */ diff --git a/src/add-ons/media/plugins/musepack/MusePackDecoder.cpp b/src/add-ons/media/plugins/musepack/MusePackDecoder.cpp index 7c0b35dd7f..02cb250ae5 100644 --- a/src/add-ons/media/plugins/musepack/MusePackDecoder.cpp +++ b/src/add-ons/media/plugins/musepack/MusePackDecoder.cpp @@ -21,6 +21,14 @@ MusePackDecoder::~MusePackDecoder() } +void +MusePackDecoder::GetCodecInfo(media_codec_info &info) +{ + strcpy(info.short_name, "musepack"); + strcpy(info.pretty_name, "MusePack audio codec based on mpcdec by Andree Buschmann"); +} + + status_t MusePackDecoder::Setup(media_format *ioEncodedFormat, const void *infoBuffer, int32 infoSize) { diff --git a/src/add-ons/media/plugins/musepack/MusePackDecoder.h b/src/add-ons/media/plugins/musepack/MusePackDecoder.h index eb8141e012..6be87cb4b9 100644 --- a/src/add-ons/media/plugins/musepack/MusePackDecoder.h +++ b/src/add-ons/media/plugins/musepack/MusePackDecoder.h @@ -16,7 +16,9 @@ class MusePackDecoder : public Decoder { public: MusePackDecoder(); ~MusePackDecoder(); - + + void GetCodecInfo(media_codec_info &info); + status_t Setup(media_format *ioEncodedFormat, const void *infoBuffer, int32 infoSize); diff --git a/src/add-ons/media/plugins/musepack/MusePackReader.cpp b/src/add-ons/media/plugins/musepack/MusePackReader.cpp index b3dfe33c0d..711da1d340 100644 --- a/src/add-ons/media/plugins/musepack/MusePackReader.cpp +++ b/src/add-ons/media/plugins/musepack/MusePackReader.cpp @@ -41,11 +41,12 @@ MusePackReader::Sniff(int32 *_streamCount) int error = fInfo.ReadStreamInfo(file); if (error > B_OK) { // error came from engine - printf("MusePack: ReadStreamInfo() engine error %d\n", error); + printf("MusePackReader: ReadStreamInfo() engine error %d\n", error); return B_ERROR; } else if (error < B_OK) return error; + printf("MusePackReader: recognized MPC file\n"); *_streamCount = 1; return B_OK; } @@ -87,10 +88,13 @@ MusePackReader::GetStreamInfo(void *cookie, int64 *_frameCount, bigtime_t *_dura media_format_description description; description.family = B_MISC_FORMAT_FAMILY; + description.u.misc.file_format = 'mpc '; description.u.misc.codec = 'MPC7'; - // ToDo: does this make any sense? BTW '7' is the most recent stream version... - BMediaFormats formats; - formats.GetFormatFor(description, format); + // 7 is the most recent stream version + + status_t status = BMediaFormats().GetFormatFor(description, format); + if (status < B_OK) + return status; // allocate and initialize internal decoder MPC_decoder *decoder = new MPC_decoder(static_cast(Source())); diff --git a/src/add-ons/media/plugins/ogg/OggReaderPluginCodecs.cpp b/src/add-ons/media/plugins/ogg/OggReaderPluginCodecs.cpp index 3d6c4fc924..cd42e1c065 100644 --- a/src/add-ons/media/plugins/ogg/OggReaderPluginCodecs.cpp +++ b/src/add-ons/media/plugins/ogg/OggReaderPluginCodecs.cpp @@ -123,8 +123,9 @@ GetVorbisCodecStreamInfo(std::vector * packets, format->type = B_MEDIA_ENCODED_AUDIO; format->user_data_type = B_CODEC_TYPE_INFO; strncpy((char*)format->user_data, "vorb", 4); - format->u.encoded_audio.encoding - = (media_encoded_audio_format::audio_encoding)'vorb'; + // ToDo: that won't work any longer + //format->u.encoded_audio.encoding + // = (media_encoded_audio_format::audio_encoding)'vorb'; if (info.bitrate_nominal > 0) { format->u.encoded_audio.bit_rate = info.bitrate_nominal; } else if (info.bitrate_upper > 0) { @@ -205,8 +206,9 @@ GetSpeexCodecStreamInfo(std::vector * packets, format->type = B_MEDIA_ENCODED_AUDIO; format->user_data_type = B_CODEC_TYPE_INFO; strncpy((char*)format->user_data,"Spee",4); - format->u.encoded_audio.encoding - = (media_encoded_audio_format::audio_encoding)'Spee'; + // ToDo: that won't work any longer + //format->u.encoded_audio.encoding + // = (media_encoded_audio_format::audio_encoding)'Spee'; if (header->bitrate > 0) { format->u.encoded_audio.bit_rate = header->bitrate; } else { @@ -301,10 +303,11 @@ GetTobiasCodecStreamInfo(std::vector * packets, format->type = B_MEDIA_ENCODED_VIDEO; format->user_data_type = B_CODEC_TYPE_INFO; strncpy((char*)format->user_data,header->subtype,4); - int32 encoding = header->subtype[0] << 24 | header->subtype[1] << 16 - | header->subtype[2] << 8 | header->subtype[3]; - format->u.encoded_video.encoding - = (media_encoded_video_format::video_encoding)encoding; + //int32 encoding = header->subtype[0] << 24 | header->subtype[1] << 16 + // | header->subtype[2] << 8 | header->subtype[3]; + // ToDo: that won't work any longer + //format->u.encoded_video.encoding + // = (media_encoded_video_format::video_encoding)encoding; format->u.encoded_video.frame_size = header->video.width * header->video.height; format->u.encoded_video.output.display.line_width = header->video.width; diff --git a/src/add-ons/media/plugins/raw_decoder/RawDecoderPlugin.cpp b/src/add-ons/media/plugins/raw_decoder/RawDecoderPlugin.cpp index afaa43f8ac..04552eefe2 100644 --- a/src/add-ons/media/plugins/raw_decoder/RawDecoderPlugin.cpp +++ b/src/add-ons/media/plugins/raw_decoder/RawDecoderPlugin.cpp @@ -20,6 +20,19 @@ AudioBufferSize(int32 channel_count, uint32 sample_format, float frame_rate, big return (sample_format & 0xf) * channel_count * (size_t)((frame_rate * buffer_duration) / 1000000.0); } + +void +RawDecoder::GetCodecInfo(media_codec_info &info) +{ + strcpy(info.short_name, "raw"); + + if (fInputFormat.IsAudio()) + strcpy(info.pretty_name, "Raw audio decoder"); + else + strcpy(info.pretty_name, "Raw video decoder"); +} + + status_t RawDecoder::Setup(media_format *ioEncodedFormat, const void *infoBuffer, int32 infoSize) @@ -471,11 +484,30 @@ RawDecoderPlugin::NewDecoder() } status_t -RawDecoderPlugin::RegisterPlugin() +RawDecoderPlugin::RegisterDecoder() { - PublishDecoder("audiocodec/raw", "raw", "RAW audio decoder"); - PublishDecoder("videocodec/raw", "raw", "RAW video decoder"); - return B_OK; + BMediaFormats formats; + media_format_description description; + media_format format; + + // audio decoder + + description.family = B_MISC_FORMAT_FAMILY; + description.u.beos.format = B_BEOS_FORMAT_RAW_AUDIO; + format.type = B_MEDIA_ENCODED_AUDIO; + format.u.encoded_audio = media_encoded_audio_format::wildcard; + + status_t status = formats.MakeFormatFor(&description, 1, &format); + if (status < B_OK) + return status; + + // video decoder + + description.u.beos.format = B_BEOS_FORMAT_RAW_VIDEO; + format.type = B_MEDIA_ENCODED_VIDEO; + format.u.encoded_video = media_encoded_video_format::wildcard; + + return formats.MakeFormatFor(&description, 1, &format); } MediaPlugin *instantiate_plugin() diff --git a/src/add-ons/media/plugins/raw_decoder/RawDecoderPlugin.h b/src/add-ons/media/plugins/raw_decoder/RawDecoderPlugin.h index 6e98cfee92..e2d4b7f8dc 100644 --- a/src/add-ons/media/plugins/raw_decoder/RawDecoderPlugin.h +++ b/src/add-ons/media/plugins/raw_decoder/RawDecoderPlugin.h @@ -3,6 +3,8 @@ class RawDecoder : public Decoder { public: + void GetCodecInfo(media_codec_info &info); + status_t Setup(media_format *ioEncodedFormat, const void *infoBuffer, int32 infoSize); @@ -43,5 +45,5 @@ class RawDecoderPlugin : public DecoderPlugin { public: Decoder * NewDecoder(); - status_t RegisterPlugin(); + status_t RegisterDecoder(); }; diff --git a/src/add-ons/media/plugins/speex/speexCodecPlugin.cpp b/src/add-ons/media/plugins/speex/speexCodecPlugin.cpp index c0ba3868b6..95774b7889 100644 --- a/src/add-ons/media/plugins/speex/speexCodecPlugin.cpp +++ b/src/add-ons/media/plugins/speex/speexCodecPlugin.cpp @@ -42,6 +42,14 @@ speexDecoder::~speexDecoder() } +void +speexDecoder::GetCodecInfo(media_codec_info &info) +{ + strcpy(info.short_name, "speex"); + strcpy(info.pretty_name, "speex decoder, based on libspeex"); +} + + status_t speexDecoder::Setup(media_format *inputFormat, const void *infoBuffer, int32 infoSize) @@ -225,7 +233,7 @@ speexDecoder::Seek(uint32 seekTo, bigtime_t seekTime, bigtime_t *time) { TRACE("speexDecoder::Seek\n"); - int ignore = 0; +// int ignore = 0; // speex_decoder_ctl(fDecoderState, SPEEX_RESET_STATE, &ignore); return B_OK; } @@ -309,10 +317,19 @@ speexDecoderPlugin::NewDecoder() status_t -speexDecoderPlugin::RegisterPlugin() +speexDecoderPlugin::RegisterDecoder() { - PublishDecoder("audiocodec/speex", "speex", "speex decoder, based on libspeex"); - return B_OK; + // ToDo: what about B_OGG_FORMAT_FAMILY? + media_format_description description; + description.family = B_MISC_FORMAT_FAMILY; + description.u.misc.file_format = 'ogg '; + description.u.misc.codec = 'spee'; + + media_format format; + format.type = B_MEDIA_ENCODED_AUDIO; + format.u.encoded_audio = media_encoded_audio_format::wildcard; + + return BMediaFormats().MakeFormatFor(&description, 1, &format); } diff --git a/src/add-ons/media/plugins/speex/speexCodecPlugin.h b/src/add-ons/media/plugins/speex/speexCodecPlugin.h index 7a3c67a5af..b72ef96f4a 100644 --- a/src/add-ons/media/plugins/speex/speexCodecPlugin.h +++ b/src/add-ons/media/plugins/speex/speexCodecPlugin.h @@ -9,7 +9,8 @@ class speexDecoder : public Decoder public: speexDecoder(); ~speexDecoder(); - + + void GetCodecInfo(media_codec_info &info); status_t Setup(media_format *inputFormat, const void *infoBuffer, int32 infoSize); @@ -44,5 +45,5 @@ class speexDecoderPlugin : public DecoderPlugin { public: Decoder * NewDecoder(); - status_t RegisterPlugin(); + status_t RegisterDecoder(); }; diff --git a/src/add-ons/media/plugins/vorbis/vorbisCodecPlugin.cpp b/src/add-ons/media/plugins/vorbis/vorbisCodecPlugin.cpp index fc595f9711..1044328142 100644 --- a/src/add-ons/media/plugins/vorbis/vorbisCodecPlugin.cpp +++ b/src/add-ons/media/plugins/vorbis/vorbisCodecPlugin.cpp @@ -41,6 +41,14 @@ vorbisDecoder::~vorbisDecoder() } +void +vorbisDecoder::GetCodecInfo(media_codec_info &info) +{ + strcpy(info.short_name, "vorbis"); + strcpy(info.pretty_name, "vorbis decoder, based on libvorbis"); +} + + status_t vorbisDecoder::Setup(media_format *inputFormat, const void *infoBuffer, int32 infoSize) @@ -87,8 +95,9 @@ vorbisDecoder::Setup(media_format *inputFormat, void vorbisDecoder::CopyInfoToEncodedFormat(media_format * format) { format->type = B_MEDIA_ENCODED_AUDIO; - format->u.encoded_audio.encoding - = (media_encoded_audio_format::audio_encoding)'vorb'; +// ToDo: this won't work any longer +// format->u.encoded_audio.encoding +// = (media_encoded_audio_format::audio_encoding)'vorb'; if (fInfo.bitrate_nominal > 0) { format->u.encoded_audio.bit_rate = fInfo.bitrate_nominal; } else if (fInfo.bitrate_upper > 0) { @@ -224,10 +233,19 @@ vorbisDecoderPlugin::NewDecoder() status_t -vorbisDecoderPlugin::RegisterPlugin() +vorbisDecoderPlugin::RegisterDecoder() { - PublishDecoder("audiocodec/vorbis", "vorbis", "vorbis decoder, based on libvorbis"); - return B_OK; + media_format_description description; + // ToDo: what about B_OGG_FORMAT_FAMILY? + description.family = B_MISC_FORMAT_FAMILY; + description.u.misc.file_format = 'ogg '; + description.u.misc.codec = 'vorb'; + + media_format format; + format.type = B_MEDIA_ENCODED_AUDIO; + format.u.encoded_audio = media_encoded_audio_format::wildcard; + + return BMediaFormats().MakeFormatFor(&description, 1, &format); } diff --git a/src/add-ons/media/plugins/vorbis/vorbisCodecPlugin.h b/src/add-ons/media/plugins/vorbis/vorbisCodecPlugin.h index c868f846e3..c91d0c23d5 100644 --- a/src/add-ons/media/plugins/vorbis/vorbisCodecPlugin.h +++ b/src/add-ons/media/plugins/vorbis/vorbisCodecPlugin.h @@ -8,6 +8,7 @@ public: vorbisDecoder(); ~vorbisDecoder(); + void GetCodecInfo(media_codec_info &info); status_t Setup(media_format *inputFormat, const void *infoBuffer, int32 infoSize); @@ -39,5 +40,5 @@ class vorbisDecoderPlugin : public DecoderPlugin { public: Decoder * NewDecoder(); - status_t RegisterPlugin(); + status_t RegisterDecoder(); };