integrating codec API, added some MediaExtractor functionality

git-svn-id: file:///srv/svn/repos/haiku/trunk/current@5470 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
beveloper
2003-11-23 23:50:27 +00:00
parent 8545b8bd8d
commit 7a115dc75d
4 changed files with 148 additions and 16 deletions
+11 -4
View File
@@ -1,7 +1,10 @@
#ifndef _DECODER_PLUGIN_H
#define _DECODER_PLUGIN_H
#include <MediaTrack.h>
#include <MediaFormats.h>
#include "MediaPlugin.h"
#include "ReaderPlugin.h"
#include "MediaExtractor.h"
namespace BPrivate { namespace media {
@@ -26,9 +29,11 @@ public:
media_header *mediaHeader);
private:
void Setup(Reader *reader, void *readerCookie);
Reader * fReader;
void * fReaderCookie;
friend class MediaExtractor;
void Setup(MediaExtractor *extractor, int32 stream);
MediaExtractor * fExtractor;
int32 fStream;
};
@@ -46,3 +51,5 @@ public:
} } // namespace BPrivate::media
using namespace BPrivate::media;
#endif
+20
View File
@@ -7,6 +7,15 @@
namespace BPrivate {
namespace media {
struct stream_info
{
status_t status;
void * cookie;
void * infoBuffer;
int32 infoBufferSize;
media_format encodedFormat;
};
class MediaExtractor
{
public:
@@ -33,7 +42,18 @@ public:
media_header *mediaHeader);
status_t CreateDecoder(int32 stream, Decoder **decoder, media_codec_info *mci);
private:
status_t fErr;
BDataIO *fSource;
Reader *fReader;
stream_info * fStreamInfo;
int32 fStreamCount;
media_file_format fMff;
};
}; // namespace media
+4 -4
View File
@@ -15,14 +15,14 @@ status_t
Decoder::GetNextChunk(void **chunkBuffer, int32 *chunkSize,
media_header *mediaHeader)
{
return fReader->GetNextChunk(fReaderCookie, chunkBuffer, chunkSize, mediaHeader);
return fExtractor->GetNextChunk(fStream, chunkBuffer, chunkSize, mediaHeader);
}
void
Decoder::Setup(Reader *reader, void *readerCookie)
Decoder::Setup(MediaExtractor *extractor, int32 stream)
{
fReader = reader;
fReaderCookie = readerCookie;
fExtractor = extractor;
fStream = stream;
}
DecoderPlugin::DecoderPlugin()
+113 -8
View File
@@ -1,65 +1,145 @@
#include "MediaExtractor.h"
#include <stdio.h>
#include <string.h>
status_t _CreateReader(Reader **reader, int32 *streamCount, media_file_format *mff, BDataIO *source);
status_t _CreateDecoder(Decoder **decoder, media_codec_info *mci, const media_format *format);
MediaExtractor::MediaExtractor(BDataIO * source, int32 flags)
{
fSource = source;
fStreamInfo = 0;
fStreamCount = 0;
fReader = 0;
fErr = _CreateReader(&fReader, &fStreamCount, &fMff, source);
if (fErr)
return;
fStreamInfo = new stream_info[fStreamCount];
// initialize stream infos
for (int32 i = 0; i < fStreamCount; i++) {
fStreamInfo[i].status = B_OK;
fStreamInfo[i].cookie = 0;
fStreamInfo[i].infoBuffer = 0;
fStreamInfo[i].infoBufferSize = 0;
memset(&fStreamInfo[i].encodedFormat, 0, sizeof(fStreamInfo[i].encodedFormat));
}
// create all stream cookies
for (int32 i = 0; i < fStreamCount; i++) {
if (B_OK != fReader->AllocateCookie(i, &fStreamInfo[i].cookie)) {
fStreamInfo[i].cookie = 0;
fStreamInfo[i].status = B_ERROR;
printf("MediaExtractor::MediaExtractor: AllocateCookie for stream %ld failed\n", i);
}
}
// get info for all streams
for (int32 i = 0; i < fStreamCount; i++) {
if (fStreamInfo[i].status != B_OK)
continue;
int64 frameCount;
bigtime_t duration;
if (B_OK != fReader->GetStreamInfo(fStreamInfo[i].cookie, &frameCount, &duration,
&fStreamInfo[i].encodedFormat,
&fStreamInfo[i].infoBuffer,
&fStreamInfo[i].infoBufferSize)) {
fStreamInfo[i].status = B_ERROR;
printf("MediaExtractor::MediaExtractor: GetStreamInfo for stream %ld failed\n", i);
}
}
}
MediaExtractor::~MediaExtractor()
{
// free all stream cookies
for (int32 i = 0; i < fStreamCount; i++) {
if (fStreamInfo[i].cookie)
fReader->FreeCookie(fStreamInfo[i].cookie);
}
delete fStreamInfo;
delete fSource;
}
status_t
MediaExtractor::InitCheck()
{
return B_OK;
return fErr;
}
void
MediaExtractor::GetFileFormatInfo(media_file_format *mfi) const
{
*mfi = fMff;
}
int32
MediaExtractor::StreamCount()
{
return 0;
return fStreamCount;
}
media_format *
MediaExtractor::EncodedFormat(int32 stream)
{
return 0;
return &fStreamInfo[stream].encodedFormat;
}
int64
MediaExtractor::CountFrames(int32 stream) const
{
return 0;
int64 frameCount;
bigtime_t duration;
media_format format;
void *infoBuffer;
int32 infoSize;
fReader->GetStreamInfo(fStreamInfo[stream].cookie, &frameCount, &duration, &format, &infoBuffer, &infoSize);
return frameCount;
}
bigtime_t
MediaExtractor::Duration(int32 stream) const
{
return 0;
int64 frameCount;
bigtime_t duration;
media_format format;
void *infoBuffer;
int32 infoSize;
fReader->GetStreamInfo(fStreamInfo[stream].cookie, &frameCount, &duration, &format, &infoBuffer, &infoSize);
return duration;
}
void *
MediaExtractor::InfoBuffer(int32 stream) const
{
return 0;
return fStreamInfo[stream].infoBuffer;
}
int32
MediaExtractor::InfoBufferSize(int32 stream) const
{
return 0;
return fStreamInfo[stream].infoBufferSize;
}
status_t
MediaExtractor::Seek(int32 stream, uint32 seekTo,
int64 *frame, bigtime_t *time)
{
return B_OK;
status_t result;
result = fReader->Seek(fStreamInfo[stream].cookie, seekTo, frame, time);
if (result != B_OK)
return result;
// clear buffered chunks
}
status_t
@@ -67,11 +147,36 @@ MediaExtractor::GetNextChunk(int32 stream,
void **chunkBuffer, int32 *chunkSize,
media_header *mediaHeader)
{
// get buffered chunk
return B_OK;
}
status_t
MediaExtractor::CreateDecoder(int32 stream, Decoder **decoder, media_codec_info *mci)
{
if (fStreamInfo[stream].status != B_OK) {
printf("MediaExtractor::CreateDecoder can't create decoder for stream %ld\n", stream);
return B_ERROR;
}
if (B_OK != _CreateDecoder(decoder, mci, &fStreamInfo[stream].encodedFormat)) {
printf("MediaExtractor::CreateDecoder failed for stream %ld\n", stream);
return B_ERROR;
}
(*decoder)->Setup(this, stream);
return B_OK;
}
status_t
_CreateReader(Reader **reader, int32 *streamCount, media_file_format *mff, BDataIO *source)
{
return B_OK;
}
status_t
_CreateDecoder(Decoder **decoder, media_codec_info *mci, const media_format *format)
{
return B_OK;
}