From 0ab6f1d0804cd8d68a00a1afeee7b70b463dc2a9 Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Thu, 18 Feb 2021 00:18:35 -0800 Subject: [PATCH] Mpeg: Update videos to latest FFmpeg packet pump. --- Core/HLE/sceMpeg.cpp | 14 ++++++++++++++ Core/HW/MediaEngine.cpp | 18 ++++++++++++++++-- 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/Core/HLE/sceMpeg.cpp b/Core/HLE/sceMpeg.cpp index 4c4a4b0e59..3701f08a47 100644 --- a/Core/HLE/sceMpeg.cpp +++ b/Core/HLE/sceMpeg.cpp @@ -993,7 +993,21 @@ static bool decodePmpVideo(PSPPointer ringbuffer, u32 pmpctxA // decode video frame +#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(57, 48, 101) + avcodec_send_packet(pCodecCtx, &packet); + int len = avcodec_receive_frame(pCodecCtx, pFrame); + if (len == 0) { + len = pFrame->pkt_size; + got_picture = 1; + } else if (len == AVERROR(EAGAIN)) { + len = 0; + got_picture = 0; + } else { + got_picture = 0; + } +#else int len = avcodec_decode_video2(pCodecCtx, pFrame, &got_picture, &packet); +#endif DEBUG_LOG(ME, "got_picture %d", got_picture); if (got_picture){ SwsContext *img_convert_ctx = NULL; diff --git a/Core/HW/MediaEngine.cpp b/Core/HW/MediaEngine.cpp index f8f008f73d..2dfddfdc89 100644 --- a/Core/HW/MediaEngine.cpp +++ b/Core/HW/MediaEngine.cpp @@ -664,9 +664,9 @@ bool MediaEngine::stepVideo(int videoPixelMode, bool skipFrame) { while (!bGetFrame) { bool dataEnd = av_read_frame(m_pFormatCtx, &packet) < 0; // Even if we've read all frames, some may have been re-ordered frames at the end. - // Still need to decode those, so keep calling avcodec_decode_video2(). + // Still need to decode those, so keep calling avcodec_decode_video2() / avcodec_receive_frame(). if (dataEnd || packet.stream_index == m_videoStream) { - // avcodec_decode_video2() gives us the re-ordered frames with a NULL packet. + // avcodec_decode_video2() / avcodec_send_packet() gives us the re-ordered frames with a NULL packet. #if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(57, 12, 100) if (dataEnd) av_packet_unref(&packet); @@ -675,7 +675,21 @@ bool MediaEngine::stepVideo(int videoPixelMode, bool skipFrame) { av_free_packet(&packet); #endif +#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(57, 48, 101) + avcodec_send_packet(m_pCodecCtx, &packet); + int result = avcodec_receive_frame(m_pCodecCtx, m_pFrame); + if (result == 0) { + result = m_pFrame->pkt_size; + frameFinished = 1; + } else if (result == AVERROR(EAGAIN)) { + result = 0; + frameFinished = 0; + } else { + frameFinished = 0; + } +#else int result = avcodec_decode_video2(m_pCodecCtx, m_pFrame, &frameFinished, &packet); +#endif if (frameFinished) { if (!m_pFrameRGB) { setVideoDim();