Skip to content

Commit

Permalink
AvFormatDecoder: forward the AVCodecContext* from GetFrame()
Browse files Browse the repository at this point in the history
to the functions that use it, instead of reading it from the map again.
  • Loading branch information
ulmus-scott authored and bennettpeter committed Jan 6, 2025
1 parent cbe8886 commit cda772e
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 37 deletions.
8 changes: 4 additions & 4 deletions mythtv/libs/libmythtv/DVD/mythdvddecoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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;

Expand Down Expand Up @@ -330,15 +330,15 @@ 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;

if (m_returnContext == nullptr)
{
// 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;
Expand Down
4 changes: 2 additions & 2 deletions mythtv/libs/libmythtv/DVD/mythdvddecoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
39 changes: 15 additions & 24 deletions mythtv/libs/libmythtv/decoders/avformatdecoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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
{
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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)
Expand All @@ -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))
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand All @@ -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
Expand All @@ -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;
}
Expand Down
14 changes: 7 additions & 7 deletions mythtv/libs/libmythtv/decoders/avformatdecoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit cda772e

Please sign in to comment.