diff options
author | Uwe Klotz <uklotz@mixxx.org> | 2021-04-24 22:33:07 +0200 |
---|---|---|
committer | Uwe Klotz <uklotz@mixxx.org> | 2021-04-24 22:37:44 +0200 |
commit | 193504789575fba1bbe7705c86a0a2b237481127 (patch) | |
tree | 812a30ca503be8cce8d4015c85a5dd3334ce350c /src/sources | |
parent | 86a22e60e4a6decf28cb598909b6a520c31b4c0a (diff) |
FFmpeg: Remove dependency on sizeof(AVPacket)
Diffstat (limited to 'src/sources')
-rw-r--r-- | src/sources/soundsourceffmpeg.cpp | 24 | ||||
-rw-r--r-- | src/sources/soundsourceffmpeg.h | 3 |
2 files changed, 11 insertions, 16 deletions
diff --git a/src/sources/soundsourceffmpeg.cpp b/src/sources/soundsourceffmpeg.cpp index c25231ca97..94d2553fd7 100644 --- a/src/sources/soundsourceffmpeg.cpp +++ b/src/sources/soundsourceffmpeg.cpp @@ -464,13 +464,17 @@ SoundSourceProviderPriority SoundSourceProviderFFmpeg::getPriorityHint( SoundSourceFFmpeg::SoundSourceFFmpeg(const QUrl& url) : SoundSource(url), m_pavStream(nullptr), + m_pavPacket(av_packet_alloc()), m_pavDecodedFrame(nullptr), m_pavResampledFrame(nullptr), m_seekPrerollFrameCount(0) { + DEBUG_ASSERT(m_pavPacket); } SoundSourceFFmpeg::~SoundSourceFFmpeg() { close(); + av_packet_free(&m_pavPacket); + DEBUG_ASSERT(!m_pavPacket); } SoundSource::OpenResult SoundSourceFFmpeg::tryOpen( @@ -880,22 +884,22 @@ bool SoundSourceFFmpeg::adjustCurrentPosition(SINT startIndex) { } bool SoundSourceFFmpeg::consumeNextAVPacket( - AVPacket* pavPacket, AVPacket** ppavNextPacket) { - DEBUG_ASSERT(pavPacket); + AVPacket** ppavNextPacket) { + DEBUG_ASSERT(m_pavPacket); DEBUG_ASSERT(ppavNextPacket); if (!*ppavNextPacket) { // Read next packet from stream const SINT packetFrameIndex = readNextPacket( m_pavInputFormatContext, m_pavStream, - pavPacket, + m_pavPacket, m_frameBuffer.writeIndex()); if (packetFrameIndex == ReadAheadFrameBuffer::kInvalidFrameIndex) { // Invalidate current position and abort reading m_frameBuffer.invalidate(); return false; } - *ppavNextPacket = pavPacket; + *ppavNextPacket = m_pavPacket; } auto* pavNextPacket = *ppavNextPacket; @@ -1019,20 +1023,10 @@ ReadableSampleFrames SoundSourceFFmpeg::readSampleFramesClamped( // Start decoding into the output buffer from the current position CSAMPLE* pOutputSampleBuffer = writableSampleFrames.writableData(); - AVPacket avPacket; -#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(58, 133, 100) - get_packet_defaults(&avPacket); -#else - // Deprecated in FFmpeg 4.4 - // See also: https://github.com/FFmpeg/FFmpeg/blob/master/doc/APIchanges - av_init_packet(&avPacket); - avPacket.data = nullptr; - avPacket.size = 0; -#endif AVPacket* pavNextPacket = nullptr; while (m_frameBuffer.isValid() && // no decoding error occurred (pavNextPacket || !writableFrameRange.empty()) && // not yet finished - consumeNextAVPacket(&avPacket, &pavNextPacket)) { // next packet consumed + consumeNextAVPacket(&pavNextPacket)) { // next packet consumed int avcodec_receive_frame_result; // One or more AV packets are required for decoding the next AV frame do { diff --git a/src/sources/soundsourceffmpeg.h b/src/sources/soundsourceffmpeg.h index 762ba08f6f..a36e49c05c 100644 --- a/src/sources/soundsourceffmpeg.h +++ b/src/sources/soundsourceffmpeg.h @@ -40,7 +40,6 @@ class SoundSourceFFmpeg : public SoundSource { SINT startIndex); bool consumeNextAVPacket( - AVPacket* pavPacket, AVPacket** ppavNextPacket); // Takes ownership of an input format context and ensures that @@ -178,6 +177,8 @@ class SoundSourceFFmpeg : public SoundSource { uint64_t m_avStreamChannelLayout; uint64_t m_avResampledChannelLayout; + AVPacket* m_pavPacket; + AVFrame* m_pavDecodedFrame; AVFrame* m_pavResampledFrame; |