diff --git a/src/add-ons/media/plugins/mp3_decoder/Jamfile b/src/add-ons/media/plugins/mp3_decoder/Jamfile index 19a9ba9e8e..82282ca794 100644 --- a/src/add-ons/media/plugins/mp3_decoder/Jamfile +++ b/src/add-ons/media/plugins/mp3_decoder/Jamfile @@ -4,6 +4,10 @@ UsePrivateHeaders media ; Addon mp3_decoder : media plugins : mp3DecoderPlugin.cpp + : + false + : + $(OBOS_TOP)/objects/x86.R1/add-ons/media/plugins/mp3_decoder/mpglib/libmpglib.a ; LinkSharedOSLibs mp3_decoder : be libmedia.so ; diff --git a/src/add-ons/media/plugins/mp3_decoder/mp3DecoderPlugin.cpp b/src/add-ons/media/plugins/mp3_decoder/mp3DecoderPlugin.cpp new file mode 100644 index 0000000000..766a1ac69d --- /dev/null +++ b/src/add-ons/media/plugins/mp3_decoder/mp3DecoderPlugin.cpp @@ -0,0 +1,113 @@ +#include +#include +#include +#include "mp3DecoderPlugin.h" + +#define TRACE_THIS 1 +#if TRACE_THIS + #define TRACE printf +#else + #define TRACE ((void)0) +#endif + +#define OUTPUT_BUFFER_SIZE 65536 + +mp3Decoder::mp3Decoder() +{ + InitMP3(&fMpgLibPrivate); +} + +mp3Decoder::~mp3Decoder() +{ + ExitMP3(&fMpgLibPrivate); +} + + +status_t +mp3Decoder::Sniff(media_format *format, void **infoBuffer, int32 *infoSize) +{ + fFormat.type = B_MEDIA_RAW_AUDIO; + fFormat.u.raw_audio.frame_rate = 44100; + fFormat.u.raw_audio.channel_count = 2; + fFormat.u.raw_audio.format = media_raw_audio_format::B_AUDIO_SHORT; + fFormat.u.raw_audio.byte_order = B_MEDIA_LITTLE_ENDIAN; + fFormat.u.raw_audio.buffer_size = OUTPUT_BUFFER_SIZE; + return B_OK; +} + + +status_t +mp3Decoder::GetOutputFormat(media_format *format) +{ + *format = fFormat; + return B_OK; +} + +status_t +mp3Decoder::Seek(media_seek_type seekTo, + int64 *frame, bigtime_t *time) +{ + ExitMP3(&fMpgLibPrivate); + InitMP3(&fMpgLibPrivate); + return B_OK; +} + + +status_t +mp3Decoder::Decode(void *buffer, int64 *frameCount, + media_header *mediaHeader, media_decode_info *info) +{ + void *chunkBuffer; + int32 chunkSize; + if (B_OK != GetNextChunk(&chunkBuffer, &chunkSize, mediaHeader)) { + TRACE("mp3Decoder::Decode: GetNextChunk failed\n"); + return B_ERROR; + } + + int availsize; + int outsize; + int result; + + availsize = OUTPUT_BUFFER_SIZE; + result = decodeMP3(&fMpgLibPrivate, (char *)chunkBuffer, chunkSize, (char *)buffer, availsize, &outsize); + if (result == MP3_ERR) { + TRACE("mp3Decoder::Decode: decodeMP3 returned MP3_ERR\n"); + return B_ERROR; + } + buffer = (char *)buffer + outsize; + availsize -= outsize; + + do { + result = decodeMP3(&fMpgLibPrivate, 0, 0, (char *)buffer, availsize, &outsize); + buffer = (char *)buffer + outsize; + availsize -= outsize; + if (availsize < 0) { + TRACE("mp3Decoder::Decode: decoded to much\n"); + exit(1); + } + } while (result == MP3_OK); + + *frameCount = (OUTPUT_BUFFER_SIZE - availsize) / 4; + return B_OK; +} + + +Decoder * +mp3DecoderPlugin::NewDecoder() +{ + static BLocker locker; + static bool initdone = false; + locker.Lock(); + if (!initdone) { + InitMpgLib(); + initdone = true; + } + locker.Unlock(); + return new mp3Decoder; +} + + +MediaPlugin *instantiate_plugin() +{ + return new mp3DecoderPlugin; +} diff --git a/src/add-ons/media/plugins/mp3_decoder/mp3DecoderPlugin.h b/src/add-ons/media/plugins/mp3_decoder/mp3DecoderPlugin.h new file mode 100644 index 0000000000..46bd8980a9 --- /dev/null +++ b/src/add-ons/media/plugins/mp3_decoder/mp3DecoderPlugin.h @@ -0,0 +1,32 @@ +#include "DecoderPlugin.h" + +#include "mpglib/mpglib.h" + +class mp3Decoder : public Decoder +{ +public: + mp3Decoder(); + ~mp3Decoder(); + + status_t Sniff(media_format *format, void **infoBuffer, int32 *infoSize); + + status_t GetOutputFormat(media_format *format); + + status_t Seek(media_seek_type seekTo, + int64 *frame, bigtime_t *time); + + status_t Decode(void *buffer, int64 *frameCount, + media_header *mediaHeader, media_decode_info *info); +private: + media_format fFormat; + struct mpstr fMpgLibPrivate; +}; + + +class mp3DecoderPlugin : public DecoderPlugin +{ +public: + Decoder *NewDecoder(); +}; + +MediaPlugin *instantiate_plugin(); diff --git a/src/add-ons/media/plugins/mp3_decoder/mpglib/mpg123.h b/src/add-ons/media/plugins/mp3_decoder/mpglib/mpg123.h index b4a03d05f4..28592e58dc 100644 --- a/src/add-ons/media/plugins/mp3_decoder/mpglib/mpg123.h +++ b/src/add-ons/media/plugins/mp3_decoder/mpglib/mpg123.h @@ -1,3 +1,6 @@ +#ifndef _MPG123_H +#define _MPG123_H + #include #include #include @@ -165,3 +168,5 @@ extern real decwin[512+32]; extern real *pnts[5]; extern struct parameter param; + +#endif diff --git a/src/add-ons/media/plugins/mp3_decoder/mpglib/mpglib.h b/src/add-ons/media/plugins/mp3_decoder/mpglib/mpglib.h index 40c5e11532..205cf99a27 100644 --- a/src/add-ons/media/plugins/mp3_decoder/mpglib/mpglib.h +++ b/src/add-ons/media/plugins/mp3_decoder/mpglib/mpglib.h @@ -1,6 +1,8 @@ #ifndef _MPGLIB_H #define _MPGLIB_H +#include "mpg123.h" + struct buf { unsigned char *pnt; long size;