2003-11-24 01:19:21 +03:00
|
|
|
#include "MediaExtractor.h"
|
2003-11-24 02:50:27 +03:00
|
|
|
#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);
|
2003-11-24 01:19:21 +03:00
|
|
|
|
|
|
|
MediaExtractor::MediaExtractor(BDataIO * source, int32 flags)
|
|
|
|
{
|
2003-11-24 02:50:27 +03:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-11-24 01:19:21 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
MediaExtractor::~MediaExtractor()
|
|
|
|
{
|
2003-11-24 02:50:27 +03:00
|
|
|
// free all stream cookies
|
|
|
|
for (int32 i = 0; i < fStreamCount; i++) {
|
|
|
|
if (fStreamInfo[i].cookie)
|
|
|
|
fReader->FreeCookie(fStreamInfo[i].cookie);
|
|
|
|
}
|
|
|
|
|
|
|
|
delete fStreamInfo;
|
|
|
|
delete fSource;
|
2003-11-24 01:19:21 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
status_t
|
|
|
|
MediaExtractor::InitCheck()
|
|
|
|
{
|
2003-11-24 02:50:27 +03:00
|
|
|
return fErr;
|
2003-11-24 01:19:21 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
MediaExtractor::GetFileFormatInfo(media_file_format *mfi) const
|
|
|
|
{
|
2003-11-24 02:50:27 +03:00
|
|
|
*mfi = fMff;
|
2003-11-24 01:19:21 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
int32
|
|
|
|
MediaExtractor::StreamCount()
|
|
|
|
{
|
2003-11-24 02:50:27 +03:00
|
|
|
return fStreamCount;
|
2003-11-24 01:19:21 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
media_format *
|
|
|
|
MediaExtractor::EncodedFormat(int32 stream)
|
|
|
|
{
|
2003-11-24 02:50:27 +03:00
|
|
|
return &fStreamInfo[stream].encodedFormat;
|
2003-11-24 01:19:21 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
int64
|
|
|
|
MediaExtractor::CountFrames(int32 stream) const
|
|
|
|
{
|
2003-11-24 02:50:27 +03:00
|
|
|
int64 frameCount;
|
|
|
|
bigtime_t duration;
|
|
|
|
media_format format;
|
|
|
|
void *infoBuffer;
|
|
|
|
int32 infoSize;
|
|
|
|
|
|
|
|
fReader->GetStreamInfo(fStreamInfo[stream].cookie, &frameCount, &duration, &format, &infoBuffer, &infoSize);
|
|
|
|
|
|
|
|
return frameCount;
|
2003-11-24 01:19:21 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
bigtime_t
|
|
|
|
MediaExtractor::Duration(int32 stream) const
|
|
|
|
{
|
2003-11-24 02:50:27 +03:00
|
|
|
int64 frameCount;
|
|
|
|
bigtime_t duration;
|
|
|
|
media_format format;
|
|
|
|
void *infoBuffer;
|
|
|
|
int32 infoSize;
|
|
|
|
|
|
|
|
fReader->GetStreamInfo(fStreamInfo[stream].cookie, &frameCount, &duration, &format, &infoBuffer, &infoSize);
|
|
|
|
|
|
|
|
return duration;
|
2003-11-24 01:19:21 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void *
|
|
|
|
MediaExtractor::InfoBuffer(int32 stream) const
|
|
|
|
{
|
2003-11-24 02:50:27 +03:00
|
|
|
return fStreamInfo[stream].infoBuffer;
|
2003-11-24 01:19:21 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
int32
|
|
|
|
MediaExtractor::InfoBufferSize(int32 stream) const
|
|
|
|
{
|
2003-11-24 02:50:27 +03:00
|
|
|
return fStreamInfo[stream].infoBufferSize;
|
2003-11-24 01:19:21 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
status_t
|
|
|
|
MediaExtractor::Seek(int32 stream, uint32 seekTo,
|
|
|
|
int64 *frame, bigtime_t *time)
|
|
|
|
{
|
2003-11-24 02:50:27 +03:00
|
|
|
status_t result;
|
|
|
|
result = fReader->Seek(fStreamInfo[stream].cookie, seekTo, frame, time);
|
|
|
|
if (result != B_OK)
|
|
|
|
return result;
|
|
|
|
|
|
|
|
// clear buffered chunks
|
2003-11-24 01:19:21 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
status_t
|
|
|
|
MediaExtractor::GetNextChunk(int32 stream,
|
|
|
|
void **chunkBuffer, int32 *chunkSize,
|
|
|
|
media_header *mediaHeader)
|
|
|
|
{
|
2003-11-24 02:50:27 +03:00
|
|
|
// get buffered chunk
|
2003-11-24 01:19:21 +03:00
|
|
|
return B_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
status_t
|
|
|
|
MediaExtractor::CreateDecoder(int32 stream, Decoder **decoder, media_codec_info *mci)
|
2003-11-24 02:50:27 +03:00
|
|
|
{
|
|
|
|
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)
|
2003-11-24 01:19:21 +03:00
|
|
|
{
|
|
|
|
return B_OK;
|
|
|
|
}
|
|
|
|
|