divide GetNextChunk and non-const media_format behavior into new member function InitializeInput
git-svn-id: file:///srv/svn/repos/haiku/trunk/current@6148 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -27,6 +27,10 @@ vorbisDecoder::vorbisDecoder()
|
|||||||
vorbis_info_init(&fInfo);
|
vorbis_info_init(&fInfo);
|
||||||
vorbis_comment_init(&fComment);
|
vorbis_comment_init(&fComment);
|
||||||
|
|
||||||
|
fHeaderPacketParsed = false;
|
||||||
|
fCommentPacketParsed = false;
|
||||||
|
fCodebookPacketParsed = false;
|
||||||
|
|
||||||
fStartTime = 0;
|
fStartTime = 0;
|
||||||
fFrameSize = 0;
|
fFrameSize = 0;
|
||||||
fOutputBufferSize = 0;
|
fOutputBufferSize = 0;
|
||||||
@@ -40,27 +44,53 @@ vorbisDecoder::~vorbisDecoder()
|
|||||||
|
|
||||||
|
|
||||||
status_t
|
status_t
|
||||||
vorbisDecoder::Setup(media_format *ioEncodedFormat,
|
vorbisDecoder::Setup(media_format *inputFormat,
|
||||||
const void *infoBuffer, int32 infoSize)
|
const void *infoBuffer, int32 infoSize)
|
||||||
{
|
{
|
||||||
if ((ioEncodedFormat->type != B_MEDIA_UNKNOWN_TYPE)
|
if ((inputFormat->type != B_MEDIA_UNKNOWN_TYPE)
|
||||||
&& (ioEncodedFormat->type != B_MEDIA_ENCODED_AUDIO)) {
|
&& (inputFormat->type != B_MEDIA_ENCODED_AUDIO)) {
|
||||||
TRACE("vorbisDecoder::Setup not called with audio/unknown stream: not vorbis");
|
TRACE("vorbisDecoder::Setup not called with audio/unknown stream: not vorbis");
|
||||||
return B_ERROR;
|
return B_ERROR;
|
||||||
}
|
}
|
||||||
if (infoSize != sizeof(ogg_packet)) {
|
if (inputFormat->MetaDataSize() == sizeof(ogg_packet)) {
|
||||||
TRACE("vorbisDecoder::Setup not called with ogg_packet info: not vorbis");
|
if (!fHeaderPacketParsed) {
|
||||||
return B_ERROR;
|
// header packet passed in meta data
|
||||||
}
|
ogg_packet * packet = (ogg_packet*)inputFormat->MetaData();
|
||||||
ogg_packet * packet = (ogg_packet*)infoBuffer;
|
|
||||||
// parse header packet
|
// parse header packet
|
||||||
if (vorbis_synthesis_headerin(&fInfo,&fComment,packet) != 0) {
|
if (vorbis_synthesis_headerin(&fInfo,&fComment,packet) != 0) {
|
||||||
TRACE("vorbisDecoder::Setup: vorbis_synthesis_headerin failed: not vorbis header");
|
TRACE("vorbisDecoder::Setup: vorbis_synthesis_headerin failed: not vorbis header");
|
||||||
return B_ERROR;
|
return B_ERROR;
|
||||||
}
|
}
|
||||||
// get comment packet
|
fHeaderPacketParsed = true;
|
||||||
|
}
|
||||||
|
} else if (inputFormat->MetaDataSize() != 0) {
|
||||||
|
// unexpected meta data
|
||||||
|
return B_ERROR;
|
||||||
|
}
|
||||||
|
return InitializeInput(inputFormat);
|
||||||
|
}
|
||||||
|
|
||||||
|
status_t
|
||||||
|
vorbisDecoder::InitializeInput(media_format *ioEncodedFormat)
|
||||||
|
{
|
||||||
|
ogg_packet * packet;
|
||||||
int32 size;
|
int32 size;
|
||||||
media_header mh;
|
media_header mh;
|
||||||
|
if (!fHeaderPacketParsed) {
|
||||||
|
// get header packet
|
||||||
|
if (GetNextChunk((void**)&packet, &size, &mh) != B_OK) {
|
||||||
|
TRACE("vorbisDecoder::Setup: GetNextChunk failed to get comment\n");
|
||||||
|
return B_ERROR;
|
||||||
|
}
|
||||||
|
// parse header packet
|
||||||
|
if (vorbis_synthesis_headerin(&fInfo,&fComment,packet) != 0) {
|
||||||
|
TRACE("vorbisDecoder::Setup: vorbis_synthesis_headerin failed: not vorbis header");
|
||||||
|
return B_ERROR;
|
||||||
|
}
|
||||||
|
fHeaderPacketParsed = true;
|
||||||
|
}
|
||||||
|
if (!fCommentPacketParsed) {
|
||||||
|
// get comment packet
|
||||||
if (GetNextChunk((void**)&packet, &size, &mh) != B_OK) {
|
if (GetNextChunk((void**)&packet, &size, &mh) != B_OK) {
|
||||||
TRACE("vorbisDecoder::Setup: GetNextChunk failed to get comment\n");
|
TRACE("vorbisDecoder::Setup: GetNextChunk failed to get comment\n");
|
||||||
return B_ERROR;
|
return B_ERROR;
|
||||||
@@ -70,6 +100,9 @@ vorbisDecoder::Setup(media_format *ioEncodedFormat,
|
|||||||
TRACE("vorbiseDecoder::Setup: vorbis_synthesis_headerin failed: not vorbis comment");
|
TRACE("vorbiseDecoder::Setup: vorbis_synthesis_headerin failed: not vorbis comment");
|
||||||
return B_ERROR;
|
return B_ERROR;
|
||||||
}
|
}
|
||||||
|
fCommentPacketParsed = true;
|
||||||
|
}
|
||||||
|
if (!fCodebookPacketParsed) {
|
||||||
// get codebook packet
|
// get codebook packet
|
||||||
if (GetNextChunk((void**)&packet, &size, &mh) != B_OK) {
|
if (GetNextChunk((void**)&packet, &size, &mh) != B_OK) {
|
||||||
TRACE("vorbisDecoder::Setup: GetNextChunk failed to get codebook\n");
|
TRACE("vorbisDecoder::Setup: GetNextChunk failed to get codebook\n");
|
||||||
@@ -83,8 +116,10 @@ vorbisDecoder::Setup(media_format *ioEncodedFormat,
|
|||||||
// initialize decoder
|
// initialize decoder
|
||||||
vorbis_synthesis_init(&fDspState,&fInfo);
|
vorbis_synthesis_init(&fDspState,&fInfo);
|
||||||
vorbis_block_init(&fDspState,&fBlock);
|
vorbis_block_init(&fDspState,&fBlock);
|
||||||
|
}
|
||||||
// fill out the encoding format
|
// fill out the encoding format
|
||||||
CopyInfoToEncodedFormat(ioEncodedFormat);
|
CopyInfoToEncodedFormat(ioEncodedFormat);
|
||||||
|
|
||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -8,9 +8,11 @@ public:
|
|||||||
vorbisDecoder();
|
vorbisDecoder();
|
||||||
~vorbisDecoder();
|
~vorbisDecoder();
|
||||||
|
|
||||||
status_t Setup(media_format *ioEncodedFormat,
|
status_t Setup(media_format *inputFormat,
|
||||||
const void *infoBuffer, int32 infoSize);
|
const void *infoBuffer, int32 infoSize);
|
||||||
|
|
||||||
|
status_t InitializeInput(media_format * ioEncodedFormat);
|
||||||
|
|
||||||
status_t NegotiateOutputFormat(media_format *ioDecodedFormat);
|
status_t NegotiateOutputFormat(media_format *ioDecodedFormat);
|
||||||
|
|
||||||
status_t Seek(uint32 seekTo,
|
status_t Seek(uint32 seekTo,
|
||||||
@@ -25,6 +27,9 @@ private:
|
|||||||
void CopyInfoToEncodedFormat(media_format * format);
|
void CopyInfoToEncodedFormat(media_format * format);
|
||||||
void CopyInfoToDecodedFormat(media_raw_audio_format * raf);
|
void CopyInfoToDecodedFormat(media_raw_audio_format * raf);
|
||||||
|
|
||||||
|
bool fHeaderPacketParsed;
|
||||||
|
bool fCommentPacketParsed;
|
||||||
|
bool fCodebookPacketParsed;
|
||||||
vorbis_info fInfo;
|
vorbis_info fInfo;
|
||||||
vorbis_comment fComment;
|
vorbis_comment fComment;
|
||||||
vorbis_dsp_state fDspState;
|
vorbis_dsp_state fDspState;
|
||||||
|
|||||||
Reference in New Issue
Block a user