added unimplemented mp3 reader, adjusted wav reader to recent api changes

git-svn-id: file:///srv/svn/repos/haiku/trunk/current@5251 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
beveloper
2003-11-04 01:31:01 +00:00
parent 0238e54c3b
commit ba36517465
6 changed files with 274 additions and 6 deletions
+2
View File
@@ -1,4 +1,6 @@
SubDir OBOS_TOP src add-ons media plugins ;
SubInclude OBOS_TOP src add-ons media plugins mp3_reader ;
SubInclude OBOS_TOP src add-ons media plugins wav_reader ;
SubInclude OBOS_TOP src add-ons media plugins raw_decoder ;
@@ -0,0 +1,9 @@
SubDir OBOS_TOP src add-ons media plugins mp3_reader ;
UsePrivateHeaders media ;
Addon mp3_reader : media plugins :
MP3ReaderPlugin.cpp
;
LinkSharedOSLibs mp3_reader : be libmedia.so ;
@@ -0,0 +1,199 @@
#include <stdio.h>
#include <string.h>
#include <malloc.h>
#include <DataIO.h>
#include <ByteOrder.h>
#include <InterfaceDefs.h>
#include "MP3ReaderPlugin.h"
#define TRACE_THIS 1
#if TRACE_THIS
#define TRACE printf
#else
#define TRACE ((void)0)
#endif
struct mp3data
{
int64 position;
char * chunkBuffer;
};
mp3Reader::mp3Reader()
{
TRACE("mp3Reader::mp3Reader\n");
fSource = dynamic_cast<BPositionIO *>(Reader::Source());
}
mp3Reader::~mp3Reader()
{
}
const char *
mp3Reader::Copyright()
{
return "mp3 reader, " B_UTF8_COPYRIGHT " by Marcus Overhagen";
}
status_t
mp3Reader::Sniff(int32 *streamCount)
{
TRACE("mp3Reader::Sniff\n");
//fDataSize = Source()->Seek(0, SEEK_END);
//if (sizeof(fRawHeader) != Source()->ReadAt(0, &fRawHeader, sizeof(fRawHeader))) {
TRACE("mp3Reader::Sniff: data size is %Ld bytes\n", fDataSize);
*streamCount = 1;
return B_OK;
}
status_t
mp3Reader::AllocateCookie(int32 streamNumber, void **cookie)
{
TRACE("mp3Reader::AllocateCookie\n");
mp3data *data = new mp3data;
/*
data->position = 0;
data->datasize = fDataSize;
data->framesize = (B_LENDIAN_TO_HOST_INT16(fRawHeader.common.bits_per_sample) / 8) * B_LENDIAN_TO_HOST_INT16(fRawHeader.common.channels);
data->fps = B_LENDIAN_TO_HOST_INT32(fRawHeader.common.samples_per_sec) / B_LENDIAN_TO_HOST_INT16(fRawHeader.common.channels);
data->buffersize = (65536 / data->framesize) * data->framesize;
data->buffer = malloc(data->buffersize);
data->framecount = fDataSize / data->framesize;
data->duration = (data->framecount * 1000000LL) / data->fps;
TRACE(" framesize %ld\n", data->framesize);
TRACE(" fps %ld\n", data->fps);
TRACE(" buffersize %ld\n", data->buffersize);
TRACE(" framecount %Ld\n", data->framecount);
TRACE(" duration %Ld\n", data->duration);
memset(&data->format, 0, sizeof(data->format));
data->format.type = B_MEDIA_RAW_AUDIO;
data->format.u.raw_audio.frame_rate = data->fps;
data->format.u.raw_audio.channel_count = B_LENDIAN_TO_HOST_INT16(fRawHeader.common.channels);
data->format.u.raw_audio.format = media_raw_audio_format::B_AUDIO_SHORT; // XXX fixme
data->format.u.raw_audio.byte_order = B_MEDIA_LITTLE_ENDIAN;
data->format.u.raw_audio.buffer_size = data->buffersize;
*/
// store the cookie
*cookie = data;
return B_OK;
}
status_t
mp3Reader::FreeCookie(void *cookie)
{
TRACE("mp3Reader::FreeCookie\n");
mp3data *data = reinterpret_cast<mp3data *>(cookie);
/*
free(data->buffer);
*/
delete data;
return B_OK;
}
status_t
mp3Reader::GetStreamInfo(void *cookie, int64 *frameCount, bigtime_t *duration,
media_format *format, void **infoBuffer, int32 *infoSize)
{
// mp3data *data = reinterpret_cast<mp3data *>(cookie);
/*
*frameCount = data->framecount;
*duration = data->duration;
*format = data->format;
*infoBuffer = 0;
*infoSize = 0;
*/
return B_OK;
}
status_t
mp3Reader::Seek(void *cookie,
uint32 seekTo,
int64 *frame, bigtime_t *time)
{
// mp3data *data = reinterpret_cast<mp3data *>(cookie);
/*
uint64 pos;
if (frame) {
pos = *frame * data->framesize;
TRACE("mp3Reader::Seek to frame %Ld, pos %Ld\n", *frame, pos);
} else if (time) {
pos = (*time * data->fps) / 1000000LL;
TRACE("mp3Reader::Seek to time %Ld, pos %Ld\n", *time, pos);
*time = (pos * 1000000LL) / data->fps;
TRACE("mp3Reader::Seek newtime %Ld\n", *time);
} else {
return B_ERROR;
}
if (pos < 0 || pos > data->datasize) {
TRACE("mp3Reader::Seek invalid position %Ld\n", pos);
return B_ERROR;
}
data->position = pos;
*/
return B_OK;
}
status_t
mp3Reader::GetNextChunk(void *cookie,
void **chunkBuffer, int32 *chunkSize,
media_header *mediaHeader)
{
// mp3data *data = reinterpret_cast<mp3data *>(cookie);
status_t result = B_OK;
/*
int32 readsize = data->datasize - data->position;
if (readsize > data->buffersize) {
readsize = data->buffersize;
result = B_LAST_BUFFER_ERROR;
}
if (readsize != Source()->ReadAt(44 + data->position, data->buffer, readsize)) {
TRACE("mp3Reader::GetNextChunk: unexpected read error\n");
return B_ERROR;
}
if (mediaHeader) {
// memset(mediaHeader, 0, sizeof(*mediaHeader));
// mediaHeader->type = B_MEDIA_RAW_AUDIO;
// mediaHeader->size_used = buffersize;
// mediaHeader->start_time = ((data->position / data->framesize) * 1000000LL) / data->fps;
// mediaHeader->file_pos = 44 + data->position;
}
data->position += readsize;
*chunkBuffer = data->buffer;
*chunkSize = readsize;
*/
return result;
}
Reader *
mp3ReaderPlugin::NewReader()
{
return new mp3Reader;
}
MediaPlugin *
instantiate_plugin()
{
return new mp3ReaderPlugin;
}
@@ -0,0 +1,50 @@
#ifndef _MP3_READER_PLUGIN_H
#define _MP3_READER_PLUGIN_H
#include "ReaderPlugin.h"
namespace BPrivate { namespace media {
class mp3Reader : public Reader
{
public:
mp3Reader();
~mp3Reader();
const char *Copyright();
status_t Sniff(int32 *streamCount);
status_t AllocateCookie(int32 streamNumber, void **cookie);
status_t FreeCookie(void *cookie);
status_t GetStreamInfo(void *cookie, int64 *frameCount, bigtime_t *duration,
media_format *format, void **infoBuffer, int32 *infoSize);
status_t Seek(void *cookie,
uint32 seekTo,
int64 *frame, bigtime_t *time);
status_t GetNextChunk(void *cookie,
void **chunkBuffer, int32 *chunkSize,
media_header *mediaHeader);
BPositionIO *Source() { return fSource; }
private:
BPositionIO * fSource;
uint64 fDataSize;
};
class mp3ReaderPlugin : public ReaderPlugin
{
public:
Reader *NewReader();
};
} } // namespace BPrivate::media
using namespace BPrivate::media;
#endif
@@ -35,7 +35,6 @@ struct wavdata
WavReader::WavReader()
{
TRACE("WavReader::WavReader\n");
fSource = dynamic_cast<BPositionIO *>(Reader::Source());
}
WavReader::~WavReader()
@@ -54,6 +53,8 @@ WavReader::Sniff(int32 *streamCount)
{
TRACE("WavReader::Sniff\n");
fSource = dynamic_cast<BPositionIO *>(Reader::Source());
fDataSize = Source()->Seek(0, SEEK_END);
if (fDataSize < sizeof(fRawHeader)) {
TRACE("WavReader::Sniff: too small\n");
@@ -126,6 +127,9 @@ WavReader::AllocateCookie(int32 streamNumber, void **cookie)
data->format.u.raw_audio.format = media_raw_audio_format::B_AUDIO_SHORT; // XXX fixme
data->format.u.raw_audio.byte_order = B_MEDIA_LITTLE_ENDIAN;
data->format.u.raw_audio.buffer_size = data->buffersize;
// store the cookie
*cookie = data;
return B_OK;
}
@@ -160,20 +164,24 @@ WavReader::GetStreamInfo(void *cookie, int64 *frameCount, bigtime_t *duration,
status_t
WavReader::Seek(void *cookie,
media_seek_type seekTo,
uint32 seekTo,
int64 *frame, bigtime_t *time)
{
wavdata *data = reinterpret_cast<wavdata *>(cookie);
uint64 pos;
if (frame) {
if (seekTo & B_MEDIA_SEEK_TO_FRAME) {
pos = *frame * data->framesize;
*time = (pos * 1000000LL) / data->fps;
TRACE("WavReader::Seek to frame %Ld, pos %Ld\n", *frame, pos);
} else if (time) {
TRACE("WavReader::Seek newtime %Ld\n", *time);
} else if (seekTo & B_MEDIA_SEEK_TO_TIME) {
pos = (*time * data->fps) / 1000000LL;
TRACE("WavReader::Seek to time %Ld, pos %Ld\n", *time, pos);
*time = (pos * 1000000LL) / data->fps;
*frame = pos / data->framesize;
TRACE("WavReader::Seek newtime %Ld\n", *time);
TRACE("WavReader::Seek newframe %Ld\n", *frame);
} else {
return B_ERROR;
}
@@ -18,7 +18,7 @@ public:
media_format *format, void **infoBuffer, int32 *infoSize);
status_t Seek(void *cookie,
media_seek_type seekTo,
uint32 seekTo,
int64 *frame, bigtime_t *time);
status_t GetNextChunk(void *cookie,