diff options
author | Daniel Schürmann <daschuer@mixxx.org> | 2021-04-28 09:38:57 +0200 |
---|---|---|
committer | Daniel Schürmann <daschuer@mixxx.org> | 2021-04-28 09:38:57 +0200 |
commit | 3f9d90c16e9e6e8256c25b7f3caad4e4d98aeff9 (patch) | |
tree | 0514da3c75ecd17f330134579a7e0d41af971488 /src/sources | |
parent | c9f52dc1d115a5d8a1d77cad3a71121baadb25e8 (diff) | |
parent | 9ba57d6ad20920b1d413593ab40f5fc53ab717a4 (diff) |
Merge remote-tracking branch 'upstream/2.3' into main
Diffstat (limited to 'src/sources')
-rw-r--r-- | src/sources/soundsourceffmpeg.cpp | 21 | ||||
-rw-r--r-- | src/sources/soundsourceffmpeg.h | 3 |
2 files changed, 14 insertions, 10 deletions
diff --git a/src/sources/soundsourceffmpeg.cpp b/src/sources/soundsourceffmpeg.cpp index 5b5b66ed38..4729191764 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( @@ -785,6 +789,9 @@ SINT readNextPacket( AVPacket* pavPacket, SINT flushFrameIndex) { while (true) { + // The underlying buffer will be provided by av_read_frame() + // and is only borrowed until the next packet is read. + DEBUG_ASSERT(!pavPacket->buf); const auto av_read_frame_result = av_read_frame( pavFormatContext, @@ -880,22 +887,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,14 +1026,10 @@ ReadableSampleFrames SoundSourceFFmpeg::readSampleFramesClamped( // Start decoding into the output buffer from the current position CSAMPLE* pOutputSampleBuffer = writableSampleFrames.writableData(); - AVPacket avPacket; - av_init_packet(&avPacket); - avPacket.data = nullptr; - avPacket.size = 0; 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; |