|
From: Lasse Kärkkäi. <tr...@us...> - 2011-02-08 14:31:18
|
Module: editor
Branch: master
Commit: 21197de51a15e93838f68bb98101c8a378d11a25
Author: Lasse Karkkainen <tro...@tr...>
Date: Tue Feb 8 14:57:11 2011 +0100
Further FFMPEG cleanup, no functional changes.
---
ffmpeg.cc | 17 ++++++-----------
pitchvis.cc | 1 +
2 files changed, 7 insertions(+), 11 deletions(-)
diff --git a/ffmpeg.cc b/ffmpeg.cc
index 45f8386..7ae263a 100644
--- a/ffmpeg.cc
+++ b/ffmpeg.cc
@@ -145,30 +145,25 @@ void FFmpeg::decodeNextFrame() {
} videoFrame;
int frameFinished=0;
+ std::vector<char, AvMalloc<char> > decodedBuffer(AVCODEC_MAX_AUDIO_FRAME_SIZE);
while (!frameFinished) {
ReadFramePacket packet(pFormatCtx);
- int packetSize = packet.size;
- quint8 *packetData = packet.data;
+ unsigned packetPos = 0;
if (packet.stream_index==audioStream) {
- while (packetSize) {
- if (packetSize < 0) throw std::logic_error("negative audio packet size?!");
+ while (packetPos < packet.size) {
if (m_quit || m_seekTarget == m_seekTarget) return;
- std::vector<char, AvMalloc<char> > decodedBuffer(AVCODEC_MAX_AUDIO_FRAME_SIZE);
- int outsize = AVCODEC_MAX_AUDIO_FRAME_SIZE;
+ int outsize = decodedBuffer.size(); // In bytes
int bytesUsed;
{
short* decodedPtr = reinterpret_cast<short*>(&decodedBuffer[0]);
#if LIBAVCODEC_VERSION_INT > ((52<<16)+(25<<8)+0)
bytesUsed = avcodec_decode_audio3(pAudioCodecCtx, decodedPtr, &outsize, &packet);
#else
- bytesUsed = avcodec_decode_audio2(pAudioCodecCtx, decodedPtr, &outsize, packetData, packetSize);
+ bytesUsed = avcodec_decode_audio2(pAudioCodecCtx, decodedPtr, &outsize, packet.data + packetPos, packet.size - packetPos);
#endif
}
- // Negative means an error
if (bytesUsed < 0) throw std::runtime_error("cannot decode audio frame");
- // Move forward within the packet
- packetSize -= bytesUsed;
- packetData += bytesUsed;
+ packetPos += bytesUsed;
// Update position if timecode is available
if (packet.time() == packet.time()) m_position = packet.time();
// Output samples
diff --git a/pitchvis.cc b/pitchvis.cc
index 1d9c40a..2151e6f 100644
--- a/pitchvis.cc
+++ b/pitchvis.cc
@@ -56,6 +56,7 @@ void PitchVis::run()
}
}
}
+ // DEBUG: std::ofstream("audio.raw", std::ios::binary).write(reinterpret_cast<char*>(&data[0]), data.size() * sizeof(float));
// Filter the analyzer output data into QPainterPaths.
std::vector<Analyzer::Moments::const_iterator> mit(channels), mend(channels);
for (unsigned ch = 0; ch < channels; ++ch) {
|