From d48068518481e7687258fdf603a57cd6dbb6f0bd Mon Sep 17 00:00:00 2001 From: beveloper Date: Sun, 29 Feb 2004 17:14:16 +0000 Subject: [PATCH] since GetStreamInfo is called multiple times, moved initialization into AllocateCookie git-svn-id: file:///srv/svn/repos/haiku/trunk/current@6800 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- .../media/plugins/musepack/MusePackReader.cpp | 63 ++++++++++++------- .../media/plugins/musepack/MusePackReader.h | 3 + 2 files changed, 45 insertions(+), 21 deletions(-) diff --git a/src/add-ons/media/plugins/musepack/MusePackReader.cpp b/src/add-ons/media/plugins/musepack/MusePackReader.cpp index 711da1d340..7013f9f098 100644 --- a/src/add-ons/media/plugins/musepack/MusePackReader.cpp +++ b/src/add-ons/media/plugins/musepack/MusePackReader.cpp @@ -5,7 +5,6 @@ #include "MusePackReader.h" -#include "mpc/mpc_dec.h" #include #include @@ -55,6 +54,16 @@ MusePackReader::Sniff(int32 *_streamCount) void MusePackReader::GetFileFormatInfo(media_file_format *mff) { + + mff->capabilities = media_file_format::B_READABLE + | media_file_format::B_KNOWS_ENCODED_AUDIO + | media_file_format::B_IMPERFECTLY_SEEKABLE; + mff->family = B_MISC_FORMAT_FAMILY; + mff->version = 100; + strcpy(mff->mime_type, "audio/x-mpc"); + strcpy(mff->file_extension, "mpc"); + strcpy(mff->short_name, "MusePack"); + strcpy(mff->pretty_name, "MusePack"); } @@ -63,6 +72,36 @@ MusePackReader::AllocateCookie(int32 streamNumber, void **_cookie) { // we don't need a cookie - we only know one single stream *_cookie = NULL; + + 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 + + status_t status = BMediaFormats().GetFormatFor(description, &fFormat); + if (status < B_OK) + return status; + + // allocate and initialize internal decoder + fDecoder = new MPC_decoder(static_cast(Source())); + fDecoder->RESET_Globals(); + fDecoder->RESET_Synthesis(); + fDecoder->SetStreamInfo(&fInfo); + if (!fDecoder->FileInit()) { + delete fDecoder; + fDecoder = 0; + return B_ERROR; + } + +#if 0 // not required to report + fFormat.u.encoded_audio.output.frame_rate = fInfo.simple.SampleFreq; + fFormat.u.encoded_audio.output.channel_count = fInfo.simple.Channels; + fFormat.u.encoded_audio.output.format = media_raw_audio_format::B_AUDIO_FLOAT; + fFormat.u.encoded_audio.output.byte_order = B_MEDIA_HOST_ENDIAN; + fFormat.u.encoded_audio.output.buffer_size = sizeof(MPC_SAMPLE_FORMAT) * FRAMELEN * 2; +#endif + return B_OK; } @@ -86,28 +125,10 @@ MusePackReader::GetStreamInfo(void *cookie, int64 *_frameCount, bigtime_t *_dura *_duration = bigtime_t(1000.0 * (fInfo.simple.Frames - 0.5) * FRAMELEN / (fInfo.simple.SampleFreq / 1000) + 0.5); - 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 - - 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())); - decoder->RESET_Globals(); - decoder->RESET_Synthesis(); - decoder->SetStreamInfo(&fInfo); - if (!decoder->FileInit()) { - delete decoder; - return B_ERROR; - } + *format = fFormat; // we provide the stream info in this place - *_infoBuffer = (void *)decoder; + *_infoBuffer = (void *)fDecoder; *_infoSize = sizeof(MPC_decoder); return B_OK; diff --git a/src/add-ons/media/plugins/musepack/MusePackReader.h b/src/add-ons/media/plugins/musepack/MusePackReader.h index 3ecb710478..96fc5ec584 100644 --- a/src/add-ons/media/plugins/musepack/MusePackReader.h +++ b/src/add-ons/media/plugins/musepack/MusePackReader.h @@ -10,6 +10,7 @@ #include #include "mpc/in_mpc.h" +#include "mpc/mpc_dec.h" class MusePackReader : public Reader { @@ -37,6 +38,8 @@ class MusePackReader : public Reader { private: StreamInfo fInfo; + media_format fFormat; + MPC_decoder *fDecoder; }; #endif /* MUSEPACK_READER_H */