From 8e3fcaf95e93ef6db8c88dd310a0dd6279660042 Mon Sep 17 00:00:00 2001 From: Hendrik Leppkes Date: Tue, 23 Aug 2022 13:10:10 +0200 Subject: [PATCH] Fix use of deprecated functions/fields --- decoder/LAVVideo/decoders/avcodec.cpp | 4 ++-- .../subtitles/LAVSubtitleProvider.cpp | 18 +++++++++------ .../LAVVideo/subtitles/LAVSubtitleProvider.h | 2 ++ demuxer/Demuxers/BDDemuxer.cpp | 23 +++++++++---------- 4 files changed, 26 insertions(+), 21 deletions(-) diff --git a/decoder/LAVVideo/decoders/avcodec.cpp b/decoder/LAVVideo/decoders/avcodec.cpp index afd7cee3f..9560cb342 100644 --- a/decoder/LAVVideo/decoders/avcodec.cpp +++ b/decoder/LAVVideo/decoders/avcodec.cpp @@ -1205,8 +1205,8 @@ STDMETHODIMP CDecAvcodec::DecodePacket(AVPacket *avpkt, REFERENCE_TIME rtStartIn if (m_bFFReordering) { rtStart = m_pFrame->pts; - if (m_pFrame->pkt_duration) - rtStop = m_pFrame->pts + m_pFrame->pkt_duration; + if (m_pFrame->duration) + rtStop = m_pFrame->pts + m_pFrame->duration; else rtStop = AV_NOPTS_VALUE; } diff --git a/decoder/LAVVideo/subtitles/LAVSubtitleProvider.cpp b/decoder/LAVVideo/subtitles/LAVSubtitleProvider.cpp index 5f66629ef..20dfdac02 100644 --- a/decoder/LAVVideo/subtitles/LAVSubtitleProvider.cpp +++ b/decoder/LAVVideo/subtitles/LAVSubtitleProvider.cpp @@ -91,6 +91,8 @@ void CLAVSubtitleProvider::CloseDecoder() av_parser_close(m_pParser); m_pParser = nullptr; } + + av_packet_free(&m_pSubtitlePacket); } STDMETHODIMP CLAVSubtitleProvider::SetConsumer(ISubRenderConsumer *pConsumer) @@ -246,6 +248,8 @@ STDMETHODIMP CLAVSubtitleProvider::Flush() context.isMovable = true; m_pLAVVideo->SetInDVDMenu(false); + av_packet_free(&m_pSubtitlePacket); + return S_OK; } @@ -278,8 +282,8 @@ STDMETHODIMP CLAVSubtitleProvider::Decode(BYTE *buf, int buflen, REFERENCE_TIME { ASSERT(m_pAVCtx); - AVPacket avpkt; - av_init_packet(&avpkt); + if (m_pSubtitlePacket == nullptr) + m_pSubtitlePacket = av_packet_alloc(); AVSubtitle sub; memset(&sub, 0, sizeof(sub)); @@ -314,12 +318,12 @@ STDMETHODIMP CLAVSubtitleProvider::Decode(BYTE *buf, int buflen, REFERENCE_TIME } if (pOut_size > 0) { - avpkt.data = pOut; - avpkt.size = pOut_size; - avpkt.pts = rtStart; - avpkt.duration = 0; + m_pSubtitlePacket->data = pOut; + m_pSubtitlePacket->size = pOut_size; + m_pSubtitlePacket->pts = rtStart; + m_pSubtitlePacket->duration = 0; - int ret = avcodec_decode_subtitle2(m_pAVCtx, &sub, &got_sub, &avpkt); + int ret = avcodec_decode_subtitle2(m_pAVCtx, &sub, &got_sub, m_pSubtitlePacket); if (ret < 0) { DbgLog((LOG_TRACE, 50, L"CLAVSubtitleProvider::Decode - decoding failed despite successfull parsing")); got_sub = 0; diff --git a/decoder/LAVVideo/subtitles/LAVSubtitleProvider.h b/decoder/LAVVideo/subtitles/LAVSubtitleProvider.h index bc9a90d58..1e2b8b37f 100644 --- a/decoder/LAVVideo/subtitles/LAVSubtitleProvider.h +++ b/decoder/LAVVideo/subtitles/LAVSubtitleProvider.h @@ -120,6 +120,8 @@ class CLAVSubtitleProvider ULONGLONG m_SubPicId = 0; BOOL m_bComposit = TRUE; + AVPacket *m_pSubtitlePacket = nullptr; + std::list m_SubFrames; struct _AM_PROPERTY_SPHLI *m_pHLI = nullptr; diff --git a/demuxer/Demuxers/BDDemuxer.cpp b/demuxer/Demuxers/BDDemuxer.cpp index 0fea01865..7d2720785 100644 --- a/demuxer/Demuxers/BDDemuxer.cpp +++ b/demuxer/Demuxers/BDDemuxer.cpp @@ -463,12 +463,12 @@ STDMETHODIMP CBDDemuxer::FillMVCExtensionQueue(REFERENCE_TIME rtBase) int ret, count = 0; bool found = (rtBase == Packet::INVALID_TIME); - AVPacket mvcPacket = {0}; - av_init_packet(&mvcPacket); + AVPacket *pMVCPacket = av_packet_alloc(); while (count < MVC_DEMUX_COUNT) { - ret = av_read_frame(m_MVCFormatContext, &mvcPacket); + av_packet_unref(pMVCPacket); + ret = av_read_frame(m_MVCFormatContext, pMVCPacket); if (ret == AVERROR(EINTR) || ret == AVERROR(EAGAIN)) { @@ -479,19 +479,18 @@ STDMETHODIMP CBDDemuxer::FillMVCExtensionQueue(REFERENCE_TIME rtBase) DbgLog((LOG_TRACE, 10, L"EOF reading MVC extension data")); break; } - else if (mvcPacket.size <= 0 || mvcPacket.stream_index != m_MVCStreamIndex) + else if (pMVCPacket->size <= 0 || pMVCPacket->stream_index != m_MVCStreamIndex) { - av_packet_unref(&mvcPacket); continue; } else { - AVStream *stream = m_MVCFormatContext->streams[mvcPacket.stream_index]; + AVStream *stream = m_MVCFormatContext->streams[pMVCPacket->stream_index]; REFERENCE_TIME rtDTS = - m_lavfDemuxer->ConvertTimestampToRT(mvcPacket.dts, stream->time_base.num, stream->time_base.den); + m_lavfDemuxer->ConvertTimestampToRT(pMVCPacket->dts, stream->time_base.num, stream->time_base.den); REFERENCE_TIME rtPTS = - m_lavfDemuxer->ConvertTimestampToRT(mvcPacket.pts, stream->time_base.num, stream->time_base.den); + m_lavfDemuxer->ConvertTimestampToRT(pMVCPacket->pts, stream->time_base.num, stream->time_base.den); if (rtBase == Packet::INVALID_TIME || rtDTS == Packet::INVALID_TIME) { @@ -502,7 +501,6 @@ STDMETHODIMP CBDDemuxer::FillMVCExtensionQueue(REFERENCE_TIME rtBase) DbgLog((LOG_TRACE, 10, L"CBDDemuxer::FillMVCExtensionQueue(): Dropping MVC extension at %I64d, base is %I64d", rtDTS, rtBase)); - av_packet_unref(&mvcPacket); continue; } else if (rtDTS == rtBase) @@ -513,21 +511,22 @@ STDMETHODIMP CBDDemuxer::FillMVCExtensionQueue(REFERENCE_TIME rtBase) Packet *pPacket = new Packet(); if (!pPacket) { - av_packet_unref(&mvcPacket); + av_packet_free(&pMVCPacket); return E_OUTOFMEMORY; } - pPacket->SetPacket(&mvcPacket); + pPacket->SetPacket(pMVCPacket); pPacket->rtDTS = rtDTS; pPacket->rtPTS = rtPTS; m_lavfDemuxer->QueueMVCExtension(pPacket); - av_packet_unref(&mvcPacket); count++; } }; + av_packet_free(&pMVCPacket); + if (found) return S_OK; else if (count > 0)