MediaTrack: Style fixes

This commit is contained in:
John Scipione 2013-08-31 15:10:56 -04:00
parent 0ef692e702
commit 8bcc3722ba
2 changed files with 215 additions and 167 deletions

View File

@ -82,7 +82,7 @@ public:
// The data returned through ReadFrames() will be in the format that's // The data returned through ReadFrames() will be in the format that's
// returned by this function. // returned by this function.
status_t DecodedFormat(media_format* _inOutFormat, status_t DecodedFormat(media_format* _format,
uint32 flags = 0); uint32 flags = 0);
// CountFrames and Duration return the total number of frame and the // CountFrames and Duration return the total number of frame and the
@ -113,15 +113,15 @@ public:
// in microseconds, is in the media_header structure. // in microseconds, is in the media_header structure.
status_t ReadFrames(void* buffer, int64* _frameCount, status_t ReadFrames(void* buffer, int64* _frameCount,
media_header* mediaHeader = NULL); media_header* header = NULL);
status_t ReadFrames(void* buffer, int64* _frameCount, status_t ReadFrames(void* buffer, int64* _frameCount,
media_header* mediaHeader, media_header* header,
media_decode_info* info); media_decode_info* info);
status_t ReplaceFrames(const void* buffer, status_t ReplaceFrames(const void* buffer,
int64* _inOutFrameCount, int64* _frameCount,
const media_header* mediaHeader); const media_header* header);
// SeekToTime and SeekToFrame are used for seeking to a particular // SeekToTime and SeekToFrame are used for seeking to a particular
@ -135,14 +135,12 @@ public:
// frame or _after_ this frame, pass B_MEDIA_SEEK_CLOSEST_FORWARD or // frame or _after_ this frame, pass B_MEDIA_SEEK_CLOSEST_FORWARD or
// B_MEDIA_SEEK_CLOSEST_BACKWARD as the flags field. // B_MEDIA_SEEK_CLOSEST_BACKWARD as the flags field.
status_t SeekToTime(bigtime_t* _inOutTime, status_t SeekToTime(bigtime_t* _time, int32 flags = 0);
int32 flags = 0); status_t SeekToFrame(int64* _frame, int32 flags = 0);
status_t SeekToFrame(int64* _inOutFrame,
int32 flags = 0);
status_t FindKeyFrameForTime(bigtime_t* _inOutTime, status_t FindKeyFrameForTime(bigtime_t* _time,
int32 flags = 0) const; int32 flags = 0) const;
status_t FindKeyFrameForFrame(int64* _inOutFrame, status_t FindKeyFrameForFrame(int64* _frame,
int32 flags = 0) const; int32 flags = 0) const;
// ReadChunk returns, in _buffer, the next _size bytes of // ReadChunk returns, in _buffer, the next _size bytes of
@ -153,7 +151,7 @@ public:
// it with ReadFrames. // it with ReadFrames.
status_t ReadChunk(char** _buffer, int32* _size, status_t ReadChunk(char** _buffer, int32* _size,
media_header* mediaHeader = NULL); media_header* _header = NULL);
// //

View File

@ -1,7 +1,12 @@
/* /*
* Copyright 2009-2010, Stephan Aßmus <superstippi@gmx.de>
* Copyright 2002-2007, Marcus Overhagen <marcus@overhagen.de> * Copyright 2002-2007, Marcus Overhagen <marcus@overhagen.de>
* Copyright 2009-2010, Stephan Aßmus <superstippi@gmx.de>
* Copyright 2013, Haiku, Inc. All Rights Reserved.
* All rights reserved. Distributed under the terms of the MIT license. * All rights reserved. Distributed under the terms of the MIT license.
*
* Authors:
* Stephan Aßmus, superstippi@gmx.de
* Marcus Overhagen, marcus@overhagen.de
*/ */
@ -9,8 +14,9 @@
#include <new> #include <new>
#include <string.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h>
#include <Roster.h> #include <Roster.h>
@ -56,18 +62,19 @@ enum {
class RawDecoderChunkProvider : public ChunkProvider { class RawDecoderChunkProvider : public ChunkProvider {
public: public:
RawDecoderChunkProvider(Decoder* decoder, int buffer_size, RawDecoderChunkProvider(Decoder* decoder,
int frame_size); int buffer_size, int frame_size);
virtual ~RawDecoderChunkProvider(); virtual ~RawDecoderChunkProvider();
status_t GetNextChunk(const void** chunkBuffer, size_t* chunkSize, status_t GetNextChunk(const void** chunkBuffer,
media_header* mediaHeader); size_t* chunkSize,
media_header* mediaHeader);
private: private:
Decoder* fDecoder; Decoder* fDecoder;
void* fBuffer; void* fBuffer;
int fBufferSize; int fBufferSize;
int fFrameSize; int fFrameSize;
}; };
@ -78,6 +85,7 @@ private:
BMediaTrack::~BMediaTrack() BMediaTrack::~BMediaTrack()
{ {
CALLED(); CALLED();
gPluginManager.DestroyDecoder(fRawDecoder); gPluginManager.DestroyDecoder(fRawDecoder);
gPluginManager.DestroyDecoder(fDecoder); gPluginManager.DestroyDecoder(fDecoder);
gPluginManager.DestroyEncoder(fEncoder); gPluginManager.DestroyEncoder(fEncoder);
@ -91,38 +99,43 @@ status_t
BMediaTrack::InitCheck() const BMediaTrack::InitCheck() const
{ {
CALLED(); CALLED();
return fInitStatus; return fInitStatus;
} }
status_t status_t
BMediaTrack::GetCodecInfo(media_codec_info* mci) const BMediaTrack::GetCodecInfo(media_codec_info* _codecInfo) const
{ {
CALLED(); CALLED();
if (!fDecoder)
if (fDecoder == NULL)
return B_NO_INIT; return B_NO_INIT;
*mci = fCodecInfo; *_codecInfo = fCodecInfo;
strlcpy(mci->pretty_name, fCodecInfo.pretty_name, sizeof(mci->pretty_name)); strlcpy(_codecInfo->pretty_name, fCodecInfo.pretty_name,
sizeof(_codecInfo->pretty_name));
return B_OK; return B_OK;
} }
status_t status_t
BMediaTrack::EncodedFormat(media_format *out_format) const BMediaTrack::EncodedFormat(media_format* _format) const
{ {
CALLED(); CALLED();
if (!out_format)
if (_format == NULL)
return B_BAD_VALUE; return B_BAD_VALUE;
if (!fExtractor)
if (fExtractor == NULL)
return B_NO_INIT; return B_NO_INIT;
*out_format = *fExtractor->EncodedFormat(fStream); *_format = *fExtractor->EncodedFormat(fStream);
#ifdef TRACE_MEDIA_TRACK #ifdef TRACE_MEDIA_TRACK
char s[200]; char s[200];
string_for_format(*out_format, s, sizeof(s)); string_for_format(*_format, s, sizeof(s));
printf("BMediaTrack::EncodedFormat: %s\n", s); printf("BMediaTrack::EncodedFormat: %s\n", s);
#endif #endif
@ -130,22 +143,26 @@ BMediaTrack::EncodedFormat(media_format *out_format) const
} }
// for BeOS R5 compatibilitly // for BeOS R5 compatibility
extern "C" status_t DecodedFormat__11BMediaTrackP12media_format(BMediaTrack *self, media_format *inout_format); extern "C" status_t DecodedFormat__11BMediaTrackP12media_format(
status_t DecodedFormat__11BMediaTrackP12media_format(BMediaTrack *self, BMediaTrack* self, media_format* _format);
media_format *inout_format)
status_t DecodedFormat__11BMediaTrackP12media_format(BMediaTrack* self,
media_format* _format)
{ {
return self->DecodedFormat(inout_format, 0); return self->DecodedFormat(_format, 0);
} }
status_t status_t
BMediaTrack::DecodedFormat(media_format *inout_format, uint32 flags) BMediaTrack::DecodedFormat(media_format* _format, uint32 flags)
{ {
CALLED(); CALLED();
if (!inout_format)
if (_format == NULL)
return B_BAD_VALUE; return B_BAD_VALUE;
if (!fExtractor || !fDecoder)
if (fExtractor == NULL || fDecoder == NULL)
return B_NO_INIT; return B_NO_INIT;
gPluginManager.DestroyDecoder(fRawDecoder); gPluginManager.DestroyDecoder(fRawDecoder);
@ -153,83 +170,90 @@ BMediaTrack::DecodedFormat(media_format *inout_format, uint32 flags)
#ifdef TRACE_MEDIA_TRACK #ifdef TRACE_MEDIA_TRACK
char s[200]; char s[200];
string_for_format(*inout_format, s, sizeof(s)); string_for_format(*_format, s, sizeof(s));
printf("BMediaTrack::DecodedFormat: req1: %s\n", s); printf("BMediaTrack::DecodedFormat: req1: %s\n", s);
#endif #endif
if ((fWorkaroundFlags & FORCE_RAW_AUDIO) || ((fWorkaroundFlags & IGNORE_ENCODED_AUDIO) && inout_format->type == B_MEDIA_ENCODED_AUDIO)) { if ((fWorkaroundFlags & FORCE_RAW_AUDIO)
inout_format->type = B_MEDIA_RAW_AUDIO; || ((fWorkaroundFlags & IGNORE_ENCODED_AUDIO)
inout_format->u.raw_audio = media_multi_audio_format::wildcard; && _format->type == B_MEDIA_ENCODED_AUDIO)) {
_format->type = B_MEDIA_RAW_AUDIO;
_format->u.raw_audio = media_multi_audio_format::wildcard;
} }
if ((fWorkaroundFlags & FORCE_RAW_VIDEO) || ((fWorkaroundFlags & IGNORE_ENCODED_VIDEO) && inout_format->type == B_MEDIA_ENCODED_VIDEO)) { if ((fWorkaroundFlags & FORCE_RAW_VIDEO)
inout_format->type = B_MEDIA_RAW_VIDEO; || ((fWorkaroundFlags & IGNORE_ENCODED_VIDEO)
inout_format->u.raw_video = media_raw_video_format::wildcard; && _format->type == B_MEDIA_ENCODED_VIDEO)) {
_format->type = B_MEDIA_RAW_VIDEO;
_format->u.raw_video = media_raw_video_format::wildcard;
} }
if (inout_format->type == B_MEDIA_RAW_AUDIO) { if (_format->type == B_MEDIA_RAW_AUDIO) {
if (fWorkaroundFlags & FORCE_RAW_AUDIO_HOST_ENDIAN) if (fWorkaroundFlags & FORCE_RAW_AUDIO_HOST_ENDIAN)
inout_format->u.raw_audio.byte_order = B_MEDIA_HOST_ENDIAN; _format->u.raw_audio.byte_order = B_MEDIA_HOST_ENDIAN;
if (fWorkaroundFlags & FORCE_RAW_AUDIO_INT16_FORMAT)
inout_format->u.raw_audio.format = media_raw_audio_format::B_AUDIO_SHORT;
if (fWorkaroundFlags & FORCE_RAW_AUDIO_INT32_FORMAT)
inout_format->u.raw_audio.format = media_raw_audio_format::B_AUDIO_INT;
if (fWorkaroundFlags & FORCE_RAW_AUDIO_FLOAT_FORMAT)
inout_format->u.raw_audio.format = media_raw_audio_format::B_AUDIO_FLOAT;
}
#ifdef TRACE_MEDIA_TRACK if (fWorkaroundFlags & FORCE_RAW_AUDIO_INT16_FORMAT) {
string_for_format(*inout_format, s, sizeof(s)); _format->u.raw_audio.format
printf("BMediaTrack::DecodedFormat: req2: %s\n", s); = media_raw_audio_format::B_AUDIO_SHORT;
#endif }
if (fWorkaroundFlags & FORCE_RAW_AUDIO_INT32_FORMAT) {
fFormat = *inout_format; _format->u.raw_audio.format
= media_raw_audio_format::B_AUDIO_INT;
status_t res; }
if (fWorkaroundFlags & FORCE_RAW_AUDIO_FLOAT_FORMAT) {
res = fDecoder->NegotiateOutputFormat(inout_format); _format->u.raw_audio.format
= media_raw_audio_format::B_AUDIO_FLOAT;
#ifdef TRACE_MEDIA_TRACK
string_for_format(*inout_format, s, sizeof(s));
printf("BMediaTrack::DecodedFormat: nego: %s\n", s);
#endif
if (inout_format->type == 0)
debugger("Decoder didn't set output format type");
if (inout_format->type == B_MEDIA_RAW_AUDIO) {
if (inout_format->u.raw_audio.byte_order == 0)
debugger("Decoder didn't set raw audio output byte order");
if (inout_format->u.raw_audio.format == 0)
debugger("Decoder didn't set raw audio output sample format");
if (inout_format->u.raw_audio.buffer_size <= 0)
debugger("Decoder didn't set raw audio output buffer size");
}
if (inout_format->type == B_MEDIA_RAW_VIDEO) {
if (inout_format->u.raw_video.display.format == 0)
debugger("Decoder didn't set raw video output color space");
if (inout_format->u.raw_video.display.line_width == 0)
debugger("Decoder didn't set raw video output line_width");
if (inout_format->u.raw_video.display.line_count == 0)
debugger("Decoder didn't set raw video output line_count");
if (inout_format->u.raw_video.display.bytes_per_row == 0)
debugger("Decoder didn't set raw video output bytes_per_row");
}
if (0 == (flags & B_MEDIA_DISABLE_FORMAT_TRANSLATION)) {
if (fFormat.type == B_MEDIA_RAW_AUDIO
&& inout_format->type == B_MEDIA_RAW_AUDIO
&& fFormat.u.raw_audio.format != 0
&& fFormat.u.raw_audio.format != inout_format->u.raw_audio.format) {
if (SetupFormatTranslation(*inout_format, &fFormat)) {
*inout_format = fFormat;
}
} }
} }
fFormat = *inout_format; #ifdef TRACE_MEDIA_TRACK
string_for_format(*_format, s, sizeof(s));
printf("BMediaTrack::DecodedFormat: req2: %s\n", s);
#endif
// string_for_format(*inout_format, s, sizeof(s)); fFormat = *_format;
// printf("BMediaTrack::DecodedFormat: res: %s\n", s); status_t result = fDecoder->NegotiateOutputFormat(_format);
return res; #ifdef TRACE_MEDIA_TRACK
string_for_format(*_format, s, sizeof(s));
printf("BMediaTrack::DecodedFormat: nego: %s\n", s);
#endif
if (_format->type == 0)
debugger("Decoder didn't set output format type");
if (_format->type == B_MEDIA_RAW_AUDIO) {
if (_format->u.raw_audio.byte_order == 0)
debugger("Decoder didn't set raw audio output byte order");
if (_format->u.raw_audio.format == 0)
debugger("Decoder didn't set raw audio output sample format");
if (_format->u.raw_audio.buffer_size <= 0)
debugger("Decoder didn't set raw audio output buffer size");
}
if (_format->type == B_MEDIA_RAW_VIDEO) {
if (_format->u.raw_video.display.format == 0)
debugger("Decoder didn't set raw video output color space");
if (_format->u.raw_video.display.line_width == 0)
debugger("Decoder didn't set raw video output line_width");
if (_format->u.raw_video.display.line_count == 0)
debugger("Decoder didn't set raw video output line_count");
if (_format->u.raw_video.display.bytes_per_row == 0)
debugger("Decoder didn't set raw video output bytes_per_row");
}
if ((flags & B_MEDIA_DISABLE_FORMAT_TRANSLATION) == 0) {
if (fFormat.type == B_MEDIA_RAW_AUDIO
&& _format->type == B_MEDIA_RAW_AUDIO
&& fFormat.u.raw_audio.format != 0
&& fFormat.u.raw_audio.format != _format->u.raw_audio.format) {
if (SetupFormatTranslation(*_format, &fFormat))
*_format = fFormat;
}
}
fFormat = *_format;
// string_for_format(*_format, s, sizeof(s));
// printf("BMediaTrack::DecodedFormat: status: %s\n", s);
return result;
} }
@ -237,8 +261,10 @@ status_t
BMediaTrack::GetMetaData(BMessage* _data) const BMediaTrack::GetMetaData(BMessage* _data) const
{ {
CALLED(); CALLED();
if (fExtractor == NULL) if (fExtractor == NULL)
return B_NO_INIT; return B_NO_INIT;
if (_data == NULL) if (_data == NULL)
return B_BAD_VALUE; return B_BAD_VALUE;
@ -252,6 +278,7 @@ int64
BMediaTrack::CountFrames() const BMediaTrack::CountFrames() const
{ {
CALLED(); CALLED();
int64 frames = fExtractor ? fExtractor->CountFrames(fStream) : 0; int64 frames = fExtractor ? fExtractor->CountFrames(fStream) : 0;
// printf("BMediaTrack::CountFrames: %lld\n", frames); // printf("BMediaTrack::CountFrames: %lld\n", frames);
return frames; return frames;
@ -262,6 +289,7 @@ bigtime_t
BMediaTrack::Duration() const BMediaTrack::Duration() const
{ {
CALLED(); CALLED();
bigtime_t duration = fExtractor ? fExtractor->Duration(fStream) : 0; bigtime_t duration = fExtractor ? fExtractor->Duration(fStream) : 0;
// printf("BMediaTrack::Duration: %lld\n", duration); // printf("BMediaTrack::Duration: %lld\n", duration);
return duration; return duration;
@ -281,26 +309,23 @@ BMediaTrack::CurrentTime() const
return fCurrentTime; return fCurrentTime;
} }
// BMediaTrack::ReadFrames(char *, long long *, media_header *) // BMediaTrack::ReadFrames(char*, long long*, media_header*)
// Compatibility for R5 and below. Required by Corum III and Civ:CTP. // Compatibility for R5 and below. Required by Corum III and Civ:CTP.
#if __GNUC__ < 3 #if __GNUC__ < 3
extern "C" status_t extern "C" status_t
ReadFrames__11BMediaTrackPcPxP12media_header(BMediaTrack *self, ReadFrames__11BMediaTrackPcPxP12media_header(BMediaTrack* self,
char *out_buffer, char* _buffer, int64* _frameCount, media_header* header)
int64 *out_frameCount,
media_header *mh)
{ {
return self->ReadFrames(out_buffer, out_frameCount, mh, 0); return self->ReadFrames(_buffer, _frameCount, header, 0);
} }
#endif // __GNUC__ < 3 #endif // __GNUC__ < 3
status_t status_t
BMediaTrack::ReadFrames(void* buffer, int64* _frameCount, BMediaTrack::ReadFrames(void* buffer, int64* _frameCount, media_header* header)
media_header* mediaHeader)
{ {
return ReadFrames(buffer, _frameCount, mediaHeader, NULL); return ReadFrames(buffer, _frameCount, header, NULL);
} }
@ -309,9 +334,11 @@ BMediaTrack::ReadFrames(void* buffer, int64* _frameCount,
media_header* _header, media_decode_info* info) media_header* _header, media_decode_info* info)
{ {
// CALLED(); // CALLED();
if (!fDecoder)
if (fDecoder == NULL)
return B_NO_INIT; return B_NO_INIT;
if (!buffer || !_frameCount)
if (buffer == NULL || _frameCount == NULL)
return B_BAD_VALUE; return B_BAD_VALUE;
media_header header; media_header header;
@ -321,41 +348,45 @@ BMediaTrack::ReadFrames(void* buffer, int64* _frameCount,
// Always clear the header first, as the decoder may not set all fields. // Always clear the header first, as the decoder may not set all fields.
memset(_header, 0, sizeof(media_header)); memset(_header, 0, sizeof(media_header));
status_t result; status_t result = fRawDecoder != NULL
if (fRawDecoder) ? fRawDecoder->Decode(buffer, _frameCount, _header, info)
result = fRawDecoder->Decode(buffer, _frameCount, _header, info); : fDecoder->Decode(buffer, _frameCount, _header, info);
else
result = fDecoder->Decode(buffer, _frameCount, _header, info);
if (result == B_OK) { if (result == B_OK) {
fCurrentFrame += *_frameCount; fCurrentFrame += *_frameCount;
bigtime_t framesDuration = (bigtime_t)(*_frameCount * 1000000 bigtime_t framesDuration = (bigtime_t)(*_frameCount * 1000000
/ _FrameRate()); / _FrameRate());
fCurrentTime = _header->start_time + framesDuration; fCurrentTime = _header->start_time + framesDuration;
// This debug output shows drift between calculated fCurrentFrame and time-based #if 0
// current frame, if there is any. // This debug output shows drift between calculated fCurrentFrame and
//if (fFormat.type == B_MEDIA_RAW_AUDIO) { // time-based current frame, if there is any.
//printf("current frame: %lld / calculated: %lld (%.2f/%.2f)\r", fCurrentFrame, if (fFormat.type == B_MEDIA_RAW_AUDIO) {
//int64(fCurrentTime * _FrameRate() / 1000000.0 + 0.5), fCurrentTime / 1000000.0, printf("current frame: %lld / calculated: %lld (%.2f/%.2f)\r",
//(float)fCurrentFrame / _FrameRate()); fCurrentFrame,
//fflush(stdout); int64(fCurrentTime * _FrameRate() / 1000000.0 + 0.5),
//} fCurrentTime / 1000000.0, (float)fCurrentFrame / _FrameRate());
fflush(stdout);
}
#endif
} else { } else {
ERROR("BMediaTrack::ReadFrames: decoder returned error %#" B_PRIx32 ERROR("BMediaTrack::ReadFrames: decoder returned error %#" B_PRIx32
" (%s)\n", result, strerror(result)); " (%s)\n", result, strerror(result));
*_frameCount = 0; *_frameCount = 0;
} }
// PRINT(1, "BMediaTrack::ReadFrames: stream %ld, start-time %5Ld.%06Ld, " #if 0
// "%lld frames\n", fStream, _header->start_time / 1000000, PRINT(1, "BMediaTrack::ReadFrames: stream %ld, start-time %5Ld.%06Ld, "
// _header->start_time % 1000000, *out_frameCount); "%lld frames\n", fStream, _header->start_time / 1000000,
_header->start_time % 1000000, *out_frameCount);
#endif
return result; return result;
} }
status_t status_t
BMediaTrack::ReplaceFrames(const void* inBuffer, int64* inOutFrameCount, BMediaTrack::ReplaceFrames(const void* inBuffer, int64* _frameCount,
const media_header* mediaHeader) const media_header* header)
{ {
UNIMPLEMENTED(); UNIMPLEMENTED();
@ -371,8 +402,10 @@ status_t
BMediaTrack::SeekToTime(bigtime_t* _time, int32 flags) BMediaTrack::SeekToTime(bigtime_t* _time, int32 flags)
{ {
CALLED(); CALLED();
if (fDecoder == NULL || fExtractor == NULL) if (fDecoder == NULL || fExtractor == NULL)
return B_NO_INIT; return B_NO_INIT;
if (_time == NULL) if (_time == NULL)
return B_BAD_VALUE; return B_BAD_VALUE;
@ -396,7 +429,7 @@ BMediaTrack::SeekToTime(bigtime_t* _time, int32 flags)
return result; return result;
} }
if (fRawDecoder) { if (fRawDecoder != NULL) {
result = fRawDecoder->SeekedTo(frame, *_time); result = fRawDecoder->SeekedTo(frame, *_time);
if (result != B_OK) { if (result != B_OK) {
ERROR("BMediaTrack::SeekToTime: raw decoder seek failed\n"); ERROR("BMediaTrack::SeekToTime: raw decoder seek failed\n");
@ -418,8 +451,10 @@ status_t
BMediaTrack::SeekToFrame(int64* _frame, int32 flags) BMediaTrack::SeekToFrame(int64* _frame, int32 flags)
{ {
CALLED(); CALLED();
if (fDecoder == NULL || fExtractor == NULL) if (fDecoder == NULL || fExtractor == NULL)
return B_NO_INIT; return B_NO_INIT;
if (_frame == NULL) if (_frame == NULL)
return B_BAD_VALUE; return B_BAD_VALUE;
@ -465,8 +500,10 @@ status_t
BMediaTrack::FindKeyFrameForTime(bigtime_t* _time, int32 flags) const BMediaTrack::FindKeyFrameForTime(bigtime_t* _time, int32 flags) const
{ {
CALLED(); CALLED();
if (fExtractor == NULL) if (fExtractor == NULL)
return B_NO_INIT; return B_NO_INIT;
if (_time == NULL) if (_time == NULL)
return B_BAD_VALUE; return B_BAD_VALUE;
@ -489,8 +526,10 @@ status_t
BMediaTrack::FindKeyFrameForFrame(int64* _frame, int32 flags) const BMediaTrack::FindKeyFrameForFrame(int64* _frame, int32 flags) const
{ {
CALLED(); CALLED();
if (fExtractor == NULL) if (fExtractor == NULL)
return B_NO_INIT; return B_NO_INIT;
if (_frame == NULL) if (_frame == NULL)
return B_BAD_VALUE; return B_BAD_VALUE;
@ -513,8 +552,10 @@ status_t
BMediaTrack::ReadChunk(char** _buffer, int32* _size, media_header* _header) BMediaTrack::ReadChunk(char** _buffer, int32* _size, media_header* _header)
{ {
CALLED(); CALLED();
if (fExtractor == NULL) if (fExtractor == NULL)
return B_NO_INIT; return B_NO_INIT;
if (_buffer == NULL || _size == NULL) if (_buffer == NULL || _size == NULL)
return B_BAD_VALUE; return B_BAD_VALUE;
@ -627,6 +668,7 @@ BMediaTrack::Web()
BParameterWeb* web; BParameterWeb* web;
if (GetParameterWeb(&web) == B_OK) if (GetParameterWeb(&web) == B_OK)
return web; return web;
return NULL; return NULL;
} }
@ -694,9 +736,9 @@ BMediaTrack::GetQuality(float* quality)
return B_BAD_VALUE; return B_BAD_VALUE;
encode_parameters parameters; encode_parameters parameters;
status_t ret = GetEncodeParameters(&parameters); status_t result = GetEncodeParameters(&parameters);
if (ret != B_OK) if (result != B_OK)
return ret; return result;
*quality = parameters.quality; *quality = parameters.quality;
@ -708,12 +750,13 @@ status_t
BMediaTrack::SetQuality(float quality) BMediaTrack::SetQuality(float quality)
{ {
encode_parameters parameters; encode_parameters parameters;
status_t ret = GetEncodeParameters(&parameters); status_t result = GetEncodeParameters(&parameters);
if (ret != B_OK) if (result != B_OK)
return ret; return result;
if (quality < 0.0f) if (quality < 0.0f)
quality = 0.0f; quality = 0.0f;
if (quality > 1.0f) if (quality > 1.0f)
quality = 1.0f; quality = 1.0f;
@ -737,7 +780,7 @@ BMediaTrack::GetEncodeParameters(encode_parameters* parameters) const
status_t status_t
BMediaTrack::SetEncodeParameters(encode_parameters *parameters) BMediaTrack::SetEncodeParameters(encode_parameters* parameters)
{ {
if (parameters == NULL) if (parameters == NULL)
return B_BAD_VALUE; return B_BAD_VALUE;
@ -762,6 +805,7 @@ BMediaTrack::BMediaTrack(BPrivate::media::MediaExtractor* extractor,
int32 stream) int32 stream)
{ {
CALLED(); CALLED();
fWorkaroundFlags = 0; fWorkaroundFlags = 0;
fDecoder = NULL; fDecoder = NULL;
fRawDecoder = NULL; fRawDecoder = NULL;
@ -832,7 +876,7 @@ BMediaTrack::BMediaTrack(BPrivate::media::MediaWriter* writer,
// Does nothing, returns B_ERROR, for Zeta compatiblity only // Does nothing, returns B_ERROR, for Zeta compatiblity only
status_t status_t
BMediaTrack::ControlCodec(int32 selector, void *io_data, size_t size) BMediaTrack::ControlCodec(int32 selector, void* io_data, size_t size)
{ {
return B_ERROR; return B_ERROR;
} }
@ -866,7 +910,7 @@ BMediaTrack::SetupWorkaround()
bool bool
BMediaTrack::SetupFormatTranslation(const media_format &from, media_format *to) BMediaTrack::SetupFormatTranslation(const media_format &from, media_format* to)
{ {
gPluginManager.DestroyDecoder(fRawDecoder); gPluginManager.DestroyDecoder(fRawDecoder);
fRawDecoder = NULL; fRawDecoder = NULL;
@ -877,8 +921,8 @@ BMediaTrack::SetupFormatTranslation(const media_format &from, media_format *to)
printf("BMediaTrack::SetupFormatTranslation: from: %s\n", s); printf("BMediaTrack::SetupFormatTranslation: from: %s\n", s);
#endif #endif
status_t res = gPluginManager.CreateDecoder(&fRawDecoder, from); status_t result = gPluginManager.CreateDecoder(&fRawDecoder, from);
if (res != B_OK) { if (result != B_OK) {
ERROR("BMediaTrack::SetupFormatTranslation: CreateDecoder failed\n"); ERROR("BMediaTrack::SetupFormatTranslation: CreateDecoder failed\n");
return false; return false;
} }
@ -887,20 +931,20 @@ BMediaTrack::SetupFormatTranslation(const media_format &from, media_format *to)
int buffer_size = from.u.raw_audio.buffer_size; int buffer_size = from.u.raw_audio.buffer_size;
int frame_size = (from.u.raw_audio.format & 15) int frame_size = (from.u.raw_audio.format & 15)
* from.u.raw_audio.channel_count; * from.u.raw_audio.channel_count;
media_format notconstFrom = from; media_format fromNotConst = from;
ChunkProvider *chunkProvider ChunkProvider* chunkProvider
= new(std::nothrow) RawDecoderChunkProvider(fDecoder, buffer_size, = new (std::nothrow) RawDecoderChunkProvider(fDecoder, buffer_size,
frame_size); frame_size);
if (!chunkProvider) { if (chunkProvider == NULL) {
ERROR("BMediaTrack::SetupFormatTranslation: can't create chunk " ERROR("BMediaTrack::SetupFormatTranslation: can't create chunk "
"provider\n"); "provider\n");
goto error; goto error;
} }
fRawDecoder->SetChunkProvider(chunkProvider); fRawDecoder->SetChunkProvider(chunkProvider);
res = fRawDecoder->Setup(&notconstFrom, 0, 0); result = fRawDecoder->Setup(&fromNotConst, 0, 0);
if (res != B_OK) { if (result != B_OK) {
ERROR("BMediaTrack::SetupFormatTranslation: Setup failed\n"); ERROR("BMediaTrack::SetupFormatTranslation: Setup failed\n");
goto error; goto error;
} }
@ -910,8 +954,8 @@ BMediaTrack::SetupFormatTranslation(const media_format &from, media_format *to)
printf("BMediaTrack::SetupFormatTranslation: to: %s\n", s); printf("BMediaTrack::SetupFormatTranslation: to: %s\n", s);
#endif #endif
res = fRawDecoder->NegotiateOutputFormat(to); result = fRawDecoder->NegotiateOutputFormat(to);
if (res != B_OK) { if (result != B_OK) {
ERROR("BMediaTrack::SetupFormatTranslation: NegotiateOutputFormat " ERROR("BMediaTrack::SetupFormatTranslation: NegotiateOutputFormat "
"failed\n"); "failed\n");
goto error; goto error;
@ -919,7 +963,7 @@ BMediaTrack::SetupFormatTranslation(const media_format &from, media_format *to)
#ifdef TRACE_MEDIA_TRACK #ifdef TRACE_MEDIA_TRACK
string_for_format(*to, s, sizeof(s)); string_for_format(*to, s, sizeof(s));
printf("BMediaTrack::SetupFormatTranslation: res: %s\n", s); printf("BMediaTrack::SetupFormatTranslation: result: %s\n", s);
#endif #endif
return true; return true;
@ -948,12 +992,12 @@ BMediaTrack::_FrameRate() const
} }
} }
/* #if 0
// unimplemented // unimplemented
BMediaTrack::BMediaTrack() BMediaTrack::BMediaTrack()
BMediaTrack::BMediaTrack(const BMediaTrack &) BMediaTrack::BMediaTrack(const BMediaTrack &)
BMediaTrack &BMediaTrack::operator=(const BMediaTrack &) BMediaTrack &BMediaTrack::operator=(const BMediaTrack &)
*/ #endif
status_t BMediaTrack::_Reserved_BMediaTrack_0(int32 arg, ...) { return B_ERROR; } status_t BMediaTrack::_Reserved_BMediaTrack_0(int32 arg, ...) { return B_ERROR; }
status_t BMediaTrack::_Reserved_BMediaTrack_1(int32 arg, ...) { return B_ERROR; } status_t BMediaTrack::_Reserved_BMediaTrack_1(int32 arg, ...) { return B_ERROR; }
@ -1005,33 +1049,39 @@ status_t BMediaTrack::_Reserved_BMediaTrack_46(int32 arg, ...) { return B_ERROR;
status_t BMediaTrack::_Reserved_BMediaTrack_47(int32 arg, ...) { return B_ERROR; } status_t BMediaTrack::_Reserved_BMediaTrack_47(int32 arg, ...) { return B_ERROR; }
RawDecoderChunkProvider::RawDecoderChunkProvider(Decoder *decoder, int buffer_size, int frame_size) RawDecoderChunkProvider::RawDecoderChunkProvider(Decoder* decoder,
int buffer_size, int frame_size)
{ {
// printf("RawDecoderChunkProvider: buffer_size %d, frame_size %d\n", buffer_size, frame_size); // printf("RawDecoderChunkProvider: buffer_size %d, frame_size %d\n",
// buffer_size, frame_size);
fDecoder = decoder; fDecoder = decoder;
fFrameSize = frame_size; fFrameSize = frame_size;
fBufferSize = buffer_size; fBufferSize = buffer_size;
fBuffer = malloc(buffer_size); fBuffer = malloc(buffer_size);
} }
RawDecoderChunkProvider::~RawDecoderChunkProvider() RawDecoderChunkProvider::~RawDecoderChunkProvider()
{ {
free(fBuffer); free(fBuffer);
} }
status_t status_t
RawDecoderChunkProvider::GetNextChunk(const void **chunkBuffer, size_t *chunkSize, RawDecoderChunkProvider::GetNextChunk(const void** chunkBuffer,
media_header *mediaHeader) size_t* chunkSize, media_header* header)
{ {
int64 frames; int64 frames;
media_decode_info info; media_decode_info info;
status_t res = fDecoder->Decode(fBuffer, &frames, mediaHeader, &info); status_t result = fDecoder->Decode(fBuffer, &frames, header, &info);
if (res == B_OK) { if (result == B_OK) {
*chunkBuffer = fBuffer; *chunkBuffer = fBuffer;
*chunkSize = frames * fFrameSize; *chunkSize = frames * fFrameSize;
// printf("RawDecoderChunkProvider::GetNextChunk, %lld frames, %ld bytes, start-time %lld\n", frames, *chunkSize, mediaHeader->start_time); // printf("RawDecoderChunkProvider::GetNextChunk, %lld frames, "
} else { // "%ld bytes, start-time %lld\n", frames, *chunkSize,
// header->start_time);
} else
ERROR("RawDecoderChunkProvider::GetNextChunk failed\n"); ERROR("RawDecoderChunkProvider::GetNextChunk failed\n");
}
return res; return result;
} }