diff --git a/mythtv/libs/libmythtv/DVD/mythdvddecoder.cpp b/mythtv/libs/libmythtv/DVD/mythdvddecoder.cpp index 4ffebaa02d8..c08acc0a738 100644 --- a/mythtv/libs/libmythtv/DVD/mythdvddecoder.cpp +++ b/mythtv/libs/libmythtv/DVD/mythdvddecoder.cpp @@ -269,7 +269,7 @@ void MythDVDDecoder::CheckContext(int64_t Pts) } -bool MythDVDDecoder::ProcessVideoPacket(AVStream *Stream, AVPacket *Pkt, bool &Retry) +bool MythDVDDecoder::ProcessVideoPacket(AVCodecContext* codecContext, AVStream *Stream, AVPacket *Pkt, bool &Retry) { int64_t pts = Pkt->pts; @@ -278,7 +278,7 @@ bool MythDVDDecoder::ProcessVideoPacket(AVStream *Stream, AVPacket *Pkt, bool &R CheckContext(pts); - bool ret = AvFormatDecoder::ProcessVideoPacket(Stream, Pkt, Retry); + bool ret = AvFormatDecoder::ProcessVideoPacket(codecContext, Stream, Pkt, Retry); if (Retry) return ret; @@ -330,7 +330,7 @@ bool MythDVDDecoder::ProcessVideoPacket(AVStream *Stream, AVPacket *Pkt, bool &R return ret; } -bool MythDVDDecoder::ProcessVideoFrame(AVStream *Stream, AVFrame *Frame) +bool MythDVDDecoder::ProcessVideoFrame(AVCodecContext* codecContext, AVStream *Stream, AVFrame *Frame) { bool ret = true; @@ -338,7 +338,7 @@ bool MythDVDDecoder::ProcessVideoFrame(AVStream *Stream, AVFrame *Frame) { // Only process video frames if we're not searching for // the previous video frame after seeking in a slideshow. - ret = AvFormatDecoder::ProcessVideoFrame(Stream, Frame); + ret = AvFormatDecoder::ProcessVideoFrame(codecContext, Stream, Frame); } return ret; diff --git a/mythtv/libs/libmythtv/DVD/mythdvddecoder.h b/mythtv/libs/libmythtv/DVD/mythdvddecoder.h index 264ee276a3f..868099b812a 100644 --- a/mythtv/libs/libmythtv/DVD/mythdvddecoder.h +++ b/mythtv/libs/libmythtv/DVD/mythdvddecoder.h @@ -23,8 +23,8 @@ class MythDVDDecoder : public AvFormatDecoder protected: int ReadPacket (AVFormatContext *Ctx, AVPacket *Pkt, bool &StorePacket) override; - bool ProcessVideoPacket(AVStream *Stream, AVPacket *Pkt, bool &Retry) override; - bool ProcessVideoFrame (AVStream *Stream, AVFrame *Frame) override; + bool ProcessVideoPacket(AVCodecContext* codecContext, AVStream *Stream, AVPacket *Pkt, bool &Retry) override; + bool ProcessVideoFrame (AVCodecContext* codecContext, AVStream *Stream, AVFrame *Frame) override; bool ProcessDataPacket (AVStream *Curstream, AVPacket *Pkt, DecodeType Decodetype) override; private: diff --git a/mythtv/libs/libmythtv/decoders/avformatdecoder.cpp b/mythtv/libs/libmythtv/decoders/avformatdecoder.cpp index 33c141d0e1f..3309b3e023e 100644 --- a/mythtv/libs/libmythtv/decoders/avformatdecoder.cpp +++ b/mythtv/libs/libmythtv/decoders/avformatdecoder.cpp @@ -3002,9 +3002,8 @@ static constexpr uint32_t SLICE_MIN { 0x00000101 }; static constexpr uint32_t SLICE_MAX { 0x000001af }; //static constexpr uint32_t SEQ_END_CODE { 0x000001b7 }; -void AvFormatDecoder::MpegPreProcessPkt(AVStream *stream, AVPacket *pkt) +void AvFormatDecoder::MpegPreProcessPkt(AVCodecContext* context, AVStream *stream, AVPacket *pkt) { - AVCodecContext *context = m_codecMap.GetCodecContext(stream); const uint8_t *bufptr = pkt->data; const uint8_t *bufend = pkt->data + pkt->size; @@ -3097,9 +3096,8 @@ void AvFormatDecoder::MpegPreProcessPkt(AVStream *stream, AVPacket *pkt) } // Returns the number of frame starts identified in the packet. -int AvFormatDecoder::H264PreProcessPkt(AVStream *stream, AVPacket *pkt) +int AvFormatDecoder::H264PreProcessPkt(AVCodecContext* context, AVStream *stream, AVPacket *pkt) { - AVCodecContext *context = m_codecMap.GetCodecContext(stream); const uint8_t *buf = pkt->data; const uint8_t *buf_end = pkt->data + pkt->size; int num_frames = 0; @@ -3200,18 +3198,17 @@ int AvFormatDecoder::H264PreProcessPkt(AVStream *stream, AVPacket *pkt) return num_frames; } -bool AvFormatDecoder::PreProcessVideoPacket(AVStream *curstream, AVPacket *pkt) +bool AvFormatDecoder::PreProcessVideoPacket(AVCodecContext* context, AVStream *curstream, AVPacket *pkt) { - AVCodecContext *context = m_codecMap.GetCodecContext(curstream); int num_frames = 1; if (CODEC_IS_MPEG(context->codec_id)) { - MpegPreProcessPkt(curstream, pkt); + MpegPreProcessPkt(context, curstream, pkt); } else if (CODEC_IS_H264(context->codec_id)) { - num_frames = H264PreProcessPkt(curstream, pkt); + num_frames = H264PreProcessPkt(context, curstream, pkt); } else { @@ -3259,11 +3256,10 @@ bool AvFormatDecoder::PreProcessVideoPacket(AVStream *curstream, AVPacket *pkt) return true; } -bool AvFormatDecoder::ProcessVideoPacket(AVStream *curstream, AVPacket *pkt, bool &Retry) +bool AvFormatDecoder::ProcessVideoPacket(AVCodecContext* context, AVStream *curstream, AVPacket *pkt, bool &Retry) { int ret = 0; int gotpicture = 0; - AVCodecContext *context = m_codecMap.GetCodecContext(curstream); MythAVFrame mpa_pic; if (!mpa_pic) return false; @@ -3360,7 +3356,7 @@ bool AvFormatDecoder::ProcessVideoPacket(AVStream *curstream, AVPacket *pkt, boo .arg(pkt->pts).arg(mpa_pic->pts).arg(pkt->pts) .arg(mpa_pic->pkt_dts)); - ProcessVideoFrame(curstream, mpa_pic); + ProcessVideoFrame(context, curstream, mpa_pic); } if (!sentPacket) @@ -3374,11 +3370,8 @@ bool AvFormatDecoder::ProcessVideoPacket(AVStream *curstream, AVPacket *pkt, boo return true; } -bool AvFormatDecoder::ProcessVideoFrame(AVStream *Stream, AVFrame *AvFrame) +bool AvFormatDecoder::ProcessVideoFrame(AVCodecContext* context, AVStream *Stream, AVFrame *AvFrame) { - - auto * context = m_codecMap.GetCodecContext(Stream); - // look for A53 captions auto * side_data = av_frame_get_side_data(AvFrame, AV_FRAME_DATA_A53_CC); if (side_data && (side_data->size > 0)) @@ -3744,7 +3737,7 @@ void AvFormatDecoder::ProcessDSMCCPacket([[maybe_unused]] const AVStream *str, #endif // USING_MHEG } -bool AvFormatDecoder::ProcessSubtitlePacket(AVStream *curstream, AVPacket *pkt) +bool AvFormatDecoder::ProcessSubtitlePacket(AVCodecContext* codecContext, AVStream *curstream, AVPacket *pkt) { if (!m_parent->GetSubReader(pkt->stream_index)) return true; @@ -3792,8 +3785,7 @@ bool AvFormatDecoder::ProcessSubtitlePacket(AVStream *curstream, AVPacket *pkt) || pkt->stream_index == forcedSubIdx) { m_avCodecLock.lock(); - AVCodecContext *ctx = m_codecMap.GetCodecContext(curstream); - avcodec_decode_subtitle2(ctx, &subtitle, &gotSubtitles, pkt); + avcodec_decode_subtitle2(codecContext, &subtitle, &gotSubtitles, pkt); m_avCodecLock.unlock(); subtitle.start_display_time += pts; @@ -4374,10 +4366,9 @@ static void extract_mono_channel(uint channel, AudioInfo *audioInfo, } } -bool AvFormatDecoder::ProcessAudioPacket(AVStream *curstream, AVPacket *pkt, +bool AvFormatDecoder::ProcessAudioPacket(AVCodecContext* ctx, AVStream *curstream, AVPacket *pkt, DecodeType decodetype) { - AVCodecContext *ctx = m_codecMap.GetCodecContext(curstream); int ret = 0; int data_size = 0; bool firstloop = true; @@ -4797,7 +4788,7 @@ bool AvFormatDecoder::GetFrame(DecodeType decodetype, bool &Retry) { case AVMEDIA_TYPE_AUDIO: { - if (!ProcessAudioPacket(curstream, pkt, decodetype)) + if (!ProcessAudioPacket(context, curstream, pkt, decodetype)) have_err = true; else GenerateDummyVideoFrames(); @@ -4811,7 +4802,7 @@ bool AvFormatDecoder::GetFrame(DecodeType decodetype, bool &Retry) break; } - if (!PreProcessVideoPacket(curstream, pkt)) + if (!PreProcessVideoPacket(context, curstream, pkt)) continue; // If the resolution changed in XXXPreProcessPkt, we may @@ -4835,14 +4826,14 @@ bool AvFormatDecoder::GetFrame(DecodeType decodetype, bool &Retry) break; } - if (!ProcessVideoPacket(curstream, pkt, Retry)) + if (!ProcessVideoPacket(context, curstream, pkt, Retry)) have_err = true; break; } case AVMEDIA_TYPE_SUBTITLE: { - if (!ProcessSubtitlePacket(curstream, pkt)) + if (!ProcessSubtitlePacket(context, curstream, pkt)) have_err = true; break; } diff --git a/mythtv/libs/libmythtv/decoders/avformatdecoder.h b/mythtv/libs/libmythtv/decoders/avformatdecoder.h index 967d0015cf9..7f5c9a615e4 100644 --- a/mythtv/libs/libmythtv/decoders/avformatdecoder.h +++ b/mythtv/libs/libmythtv/decoders/avformatdecoder.h @@ -180,14 +180,14 @@ class AvFormatDecoder : public DecoderBase bool selectedStream = false); /// Preprocess a packet, setting the video parms if necessary. - void MpegPreProcessPkt(AVStream *stream, AVPacket *pkt); - int H264PreProcessPkt(AVStream *stream, AVPacket *pkt); - bool PreProcessVideoPacket(AVStream *stream, AVPacket *pkt); - virtual bool ProcessVideoPacket(AVStream *stream, AVPacket *pkt, bool &Retry); - virtual bool ProcessVideoFrame(AVStream *Stream, AVFrame *AvFrame); - bool ProcessAudioPacket(AVStream *stream, AVPacket *pkt, + void MpegPreProcessPkt(AVCodecContext* codecContext, AVStream *stream, AVPacket *pkt); + int H264PreProcessPkt(AVCodecContext* codecContext, AVStream *stream, AVPacket *pkt); + bool PreProcessVideoPacket(AVCodecContext* codecContext, AVStream *stream, AVPacket *pkt); + virtual bool ProcessVideoPacket(AVCodecContext* codecContext, AVStream *stream, AVPacket *pkt, bool &Retry); + virtual bool ProcessVideoFrame(AVCodecContext* codecContext, AVStream *Stream, AVFrame *AvFrame); + bool ProcessAudioPacket(AVCodecContext* codecContext, AVStream *stream, AVPacket *pkt, DecodeType decodetype); - bool ProcessSubtitlePacket(AVStream *stream, AVPacket *pkt); + bool ProcessSubtitlePacket(AVCodecContext* codecContext, AVStream *stream, AVPacket *pkt); bool ProcessRawTextPacket(AVPacket* Packet); virtual bool ProcessDataPacket(AVStream *curstream, AVPacket *pkt, DecodeType decodetype);