Hi, this is my first post here. First I would like to thank the WebM
team here for providing these great libraries. I am adding webm
playback capabilities in an iPhone app I am working on and the video
pipeline is super fast, thanks!
Now to some trouble I am having regarding audio. I am using the
libwebm library to parse the webm file and using libvorbis to decode
the audio. Here is what I am doing and what is going wrong, any help
would be greatly appreciated.
After the webm file is loaded I loop through the tracks and look for
the first audio track. Once I have it I then initialize the vorbis
libraries like so:
// initialize vorbis
vorbis_info_init(&_
vorbis.info);
vorbis_comment_init(&_vorbis.comment);
memset(&_vorbis.dspState,0,sizeof(_vorbis.dspState));
memset(&_vorbis.block,0,sizeof(_vorbis.block));
size_t size;
unsigned char * data = (unsigned char *)audioTrack-
>GetCodecPrivate(size);
_vorbis.oggPacket.packet = data+3; // NOTE "vorbis" does not start
until +3 into this packet.
_vorbis.oggPacket.bytes = size-3;
_vorbis.oggPacket.b_o_s = true;
_vorbis.oggPacket.e_o_s = false;
_vorbis.oggPacket.granulepos = 0;
_vorbis.oggPacket.packetno = 0;
int r;
r = vorbis_synthesis_headerin(&_
vorbis.info, &_vorbis.comment,
&_vorbis.oggPacket);
if( r<0 )
debug(DBG_WARNING,"vorbis_synthesis_headerin failed, error: %d", r);
r = vorbis_synthesis_init(&_vorbis.dspState, &_
vorbis.info);
if( r<0 )
debug(DBG_WARNING,"vorbis_synthesis_init failed, error: %d", r);
r = vorbis_block_init(&_vorbis.dspState, &_vorbis.block);
if( r<0 )
debug(DBG_WARNING,"vorbis_block_init failed, error: %d", r);
If you notice the "NOTE" above I am having to offset the pointer from
GetCodecPrivate by 3 otherwise the vorbis header is incorrect. If I
add 3 then everything initializes ok. Is there a bug in libwebm
regarding the codecs private data?
Now, lets assume that everything is ok and that +3 offset is a bug but
by adding 3 were ok. The next problem I am having is in decoding the
audio itself.
To parse the audio I loop through the available clusters and block
entries for the audio track I am interested in. Once I have some
audio data I deal with it like so:
if( trackNum==_audioInfo.audioTrack && _soundSource )
{
// Use this Audio Track
const long size = block->GetSize();
if( size>_audioInfo.audioPageSize )
{
if( _audioInfo.audioPage ) delete [] _audioInfo.audioPage;
_audioInfo.audioPage = new unsigned char[size];
_audioInfo.audioPageSize = size;
}
if( size>0 ) // NOTE: First time through size is only 1, seems bad??
{
block->Read(_reader.reader, _audioInfo.audioPage);
_vorbis.oggPacket.packet = _audioInfo.audioPage;
_vorbis.oggPacket.bytes = size;
_vorbis.oggPacket.b_o_s = false;
_vorbis.oggPacket.packetno++;
_vorbis.oggPacket.granulepos = -1;
if( vorbis_synthesis(&_vorbis.block, &_vorbis.oggPacket)==0 ) //
NOTE: <-- Memory access violation.
{
vorbis_synthesis_blockin(&_vorbis.dspState, &_vorbis.block);
}
// send audio to audio device...
}
I am new to libwebm and vorbis so there is a good chance I am simply
doing something wrong. What happens for me now is that
vorbis_synthesis has a memory access viloation as it looks like
pointers in codec_setup_info.mode_param fields were not initialized.
Any ideas?
Thanks.
-=ben