Hi all,
I am currently writing a video manager in C++ for a project I am working
on. I am using ffmpeg to decode everything, but I
am actually using FMOD to play the audio decoded by ffmpeg since FMOD is
what the rest of the project uses. Originally
I set it up so that each packet would get decoded, sent to FMOD, and then
played. This worked, but the result was very
choppy and sounded awful because there was some lag in between decoding a
frame of audio and actually playing it.
To fix this what I tried doing was loading everything before anything
actually gets played, and then playing each frame in turn afterwards.
Again, it was very choppy due to each frame being treated as a separate
sound by FMOD.
So now what I am trying to do is to read everything into one giant buffer,
and then pass the entire sound off to FMOD at once in a
single chunk. I thought I set this up correctly, but I eventually start
getting memory access violations on the 100th or so audio packet.
What I tried doing is this (this code runs for each audio packet):
int frameSize = _audioBufferSize - pointerIncrement;
uint8_t *packetData = packet.data;
int packetSize = packet.size;
int numBytesUsed = 0;
while (packetSize > 0) {
numBytesUsed = avcodec_decode_audio2(_audioContext, (int16_t
*)_audioBuffer + pointerIncrement, &frameSize, packetData, packetSize);
pointerIncrement += frameSize;
frameSize = _audioBufferSize - pointerIncrement;
if (numBytesUsed > 0) {
// Update data pointer and size for next frame
packetData += numBytesUsed;
packetSize -= numBytesUsed;
}
}
My memory access violations are occurring in avcodec_decode_audio2(), and if
I remove the pointerIncrement stuff they go away. However, I can't get rid
of that because otherwise the data from the current frame will just
overwrite the previous frame (correct?). Note that I am 100% positive that
the
buffer is big enough for all of the data. I don't know enough about the
details of the avcodec_decode_audio2() function to be able to figure out
what the
issue is, but if someone could be so kind as to point out what I'm doing
wrong or give me some ideas of things I could check I'd appreciate it a lot.
Alternately, if there is an easier way to read the entire data into a single
buffer, I'm all ears.
Thanks,
Mark
_______________________________________________
libav-user mailing list
[email protected]
https://lists.mplayerhq.hu/mailman/listinfo/libav-user