integrated mpglib into mp3_decoder. obviously, the api needs to be changed.
git-svn-id: file:///srv/svn/repos/haiku/trunk/current@5435 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -4,6 +4,10 @@ UsePrivateHeaders media ;
|
|||||||
|
|
||||||
Addon mp3_decoder : media plugins :
|
Addon mp3_decoder : media plugins :
|
||||||
mp3DecoderPlugin.cpp
|
mp3DecoderPlugin.cpp
|
||||||
|
:
|
||||||
|
false
|
||||||
|
:
|
||||||
|
$(OBOS_TOP)/objects/x86.R1/add-ons/media/plugins/mp3_decoder/mpglib/libmpglib.a
|
||||||
;
|
;
|
||||||
|
|
||||||
LinkSharedOSLibs mp3_decoder : be libmedia.so ;
|
LinkSharedOSLibs mp3_decoder : be libmedia.so ;
|
||||||
|
|||||||
@@ -0,0 +1,113 @@
|
|||||||
|
#include <stdio.h>
|
||||||
|
#include <DataIO.h>
|
||||||
|
#include <Locker.h>
|
||||||
|
#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;
|
||||||
|
}
|
||||||
@@ -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();
|
||||||
@@ -1,3 +1,6 @@
|
|||||||
|
#ifndef _MPG123_H
|
||||||
|
#define _MPG123_H
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
@@ -165,3 +168,5 @@ extern real decwin[512+32];
|
|||||||
extern real *pnts[5];
|
extern real *pnts[5];
|
||||||
|
|
||||||
extern struct parameter param;
|
extern struct parameter param;
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
#ifndef _MPGLIB_H
|
#ifndef _MPGLIB_H
|
||||||
#define _MPGLIB_H
|
#define _MPGLIB_H
|
||||||
|
|
||||||
|
#include "mpg123.h"
|
||||||
|
|
||||||
struct buf {
|
struct buf {
|
||||||
unsigned char *pnt;
|
unsigned char *pnt;
|
||||||
long size;
|
long size;
|
||||||
|
|||||||
Reference in New Issue
Block a user