|
From: Yoda-JM <yo...@us...> - 2009-07-13 15:45:52
|
Module: performous
Branch: master
Commit: 80b922c376209bd1e40e98d593c851c9117c816d
Author: Vincent Le Ligeour <yo...@us...>
Date: Mon Jul 13 17:45:20 2009 +0200
Fixed one everlonging ffmpeg problem
---
game/ffmpeg.cc | 18 +++++++++++++++---
1 files changed, 15 insertions(+), 3 deletions(-)
diff --git a/game/ffmpeg.cc b/game/ffmpeg.cc
index 31f49cd..44cc0a9 100644
--- a/game/ffmpeg.cc
+++ b/game/ffmpeg.cc
@@ -210,6 +210,18 @@ void FFmpeg::decodeNextFrame() {
AVFrame* operator->() { return m_frame; }
} videoFrame;
+ class AudioBuffer {
+ public:
+ AudioBuffer(size_t _size): m_buffer((int16_t*)av_malloc(_size*sizeof(int16_t))) {
+ if (!m_buffer) throw std::runtime_error("Unable to allocate AudioBuffer");
+ }
+ ~AudioBuffer() { av_free(m_buffer); }
+ operator int16_t*() { return m_buffer; }
+ int16_t* operator->() { return m_buffer; }
+ private:
+ int16_t* m_buffer;
+ };
+
int frameFinished=0;
while (!frameFinished) {
ReadFramePacket packet(pFormatCtx);
@@ -244,9 +256,9 @@ void FFmpeg::decodeNextFrame() {
while (packetSize) {
if (packetSize < 0) throw std::logic_error("negative audio packet size?!");
if (m_quit || m_seekTarget == m_seekTarget) return;
- std::vector<int16_t> audioFrames(AVCODEC_MAX_AUDIO_FRAME_SIZE);
+ AudioBuffer audioFrames(AVCODEC_MAX_AUDIO_FRAME_SIZE);
int outsize = AVCODEC_MAX_AUDIO_FRAME_SIZE*sizeof(int16_t);
- int decodeSize = avcodec_decode_audio2(pAudioCodecCtx, &audioFrames[0], &outsize, packetData, packetSize);
+ int decodeSize = avcodec_decode_audio2(pAudioCodecCtx, audioFrames, &outsize, packetData, packetSize);
// Handle special cases
if (decodeSize == 0) break;
if (outsize == 0) continue;
@@ -257,7 +269,7 @@ void FFmpeg::decodeNextFrame() {
// Convert outsize from bytes into number of frames (samples)
outsize /= sizeof(int16_t) * pAudioCodecCtx->channels;
std::vector<int16_t> resampled(AVCODEC_MAX_AUDIO_FRAME_SIZE);
- int frames = audio_resample(pResampleCtx, &resampled[0], &audioFrames[0], outsize);
+ int frames = audio_resample(pResampleCtx, &resampled[0], audioFrames, outsize);
// Construct AudioFrame and add it to the queue
AudioFrame* tmp = new AudioFrame();
std::copy(resampled.begin(), resampled.begin() + frames * AUDIO_CHANNELS, std::back_inserter(tmp->data));
|