tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

commit ac2c1ca4323d95052b9e8489a4b9307d359ccb9c
parent 704e01bf9fe136a9f3e5f9b87d4bb137a4bdc848
Author: Landry Breuil <landry@openbsd.org>
Date:   Mon, 24 Nov 2025 15:38:14 +0000

Bug 1962139 - Adapt FFmpegVideoDecoder for ffmpeg8 r=media-playback-reviewers,alwu

Provide IsKeyFrame() helper handling various versions, and use it where
appropriate. Also, In ffmpeg 8 the offset is to be found in the packet struct,
not anymore in the frame struct, so use a variable local to DoDecode()

Differential Revision: https://phabricator.services.mozilla.com/D272254

Diffstat:
Mdom/media/platforms/ffmpeg/FFmpegVideoDecoder.cpp | 46+++++++++++++++++++++++++++++-----------------
1 file changed, 29 insertions(+), 17 deletions(-)

diff --git a/dom/media/platforms/ffmpeg/FFmpegVideoDecoder.cpp b/dom/media/platforms/ffmpeg/FFmpegVideoDecoder.cpp @@ -1065,6 +1065,14 @@ static int64_t GetFramePts(const AVFrame* aFrame) { #endif } +static bool IsKeyFrame(const AVFrame* aFrame) { +#if LIBAVCODEC_VERSION_MAJOR > 61 + return !!(aFrame->flags & AV_FRAME_FLAG_KEY); +#else + return !!aFrame->key_frame; +#endif +} + #if LIBAVCODEC_VERSION_MAJOR >= 58 void FFmpegVideoDecoder<LIBAV_VER>::DecodeStats::DecodeStart() { mDecodeStart = TimeStamp::Now(); @@ -1273,6 +1281,12 @@ MediaResult FFmpegVideoDecoder<LIBAV_VER>::DoDecode( # endif int res = mLib->avcodec_receive_frame(mCodecContext, mFrame); + int64_t fpos = +# if LIBAVCODEC_VERSION_MAJOR > 61 + packet->pos; +# else + mFrame->pkt_pos; +# endif if (res == int(AVERROR_EOF)) { if (MaybeQueueDrain(aResults)) { FFMPEG_LOG(" Output buffer shortage."); @@ -1308,11 +1322,11 @@ MediaResult FFmpegVideoDecoder<LIBAV_VER>::DoDecode( RESULT_DETAIL("HW decoding is slow, switching back to SW decode")); } if (mUsingV4L2) { - rv = CreateImageV4L2(mFrame->pkt_pos, GetFramePts(mFrame), - Duration(mFrame), aResults); + rv = CreateImageV4L2(fpos, GetFramePts(mFrame), Duration(mFrame), + aResults); } else { - rv = CreateImageVAAPI(mFrame->pkt_pos, GetFramePts(mFrame), - Duration(mFrame), aResults); + rv = CreateImageVAAPI(fpos, GetFramePts(mFrame), Duration(mFrame), + aResults); } // If VA-API/V4L2 playback failed, just quit. Decoder is going to be @@ -1325,15 +1339,15 @@ MediaResult FFmpegVideoDecoder<LIBAV_VER>::DoDecode( } # elif defined(MOZ_ENABLE_D3D11VA) mDecodeStats.UpdateDecodeTimes(Duration(mFrame)); - rv = CreateImageD3D11(mFrame->pkt_pos, GetFramePts(mFrame), - Duration(mFrame), aResults); + rv = CreateImageD3D11(fpos, GetFramePts(mFrame), Duration(mFrame), + aResults); # elif defined(MOZ_WIDGET_ANDROID) InputInfo info(aSample); info.mTimecode = -1; TakeInputInfo(mFrame, info); mDecodeStats.UpdateDecodeTimes(info.mDuration); - rv = CreateImageMediaCodec(mFrame->pkt_pos, GetFramePts(mFrame), - info.mTimecode, info.mDuration, aResults); + rv = CreateImageMediaCodec(fpos, GetFramePts(mFrame), info.mTimecode, + info.mDuration, aResults); # else mDecodeStats.UpdateDecodeTimes(Duration(mFrame)); return MediaResult(NS_ERROR_DOM_MEDIA_DECODE_ERR, @@ -1343,8 +1357,7 @@ MediaResult FFmpegVideoDecoder<LIBAV_VER>::DoDecode( # endif { mDecodeStats.UpdateDecodeTimes(Duration(mFrame)); - rv = CreateImage(mFrame->pkt_pos, GetFramePts(mFrame), Duration(mFrame), - aResults); + rv = CreateImage(fpos, GetFramePts(mFrame), Duration(mFrame), aResults); } if (NS_FAILED(rv)) { return rv; @@ -1704,7 +1717,7 @@ MediaResult FFmpegVideoDecoder<LIBAV_VER>::CreateImage( v = VideoData::CreateFromImage( mInfo.mDisplay, aOffset, TimeUnit::FromMicroseconds(aPts), TimeUnit::FromMicroseconds(aDuration), wrapper->AsImage(), - !!mFrame->key_frame, TimeUnit::FromMicroseconds(-1)); + IsKeyFrame(mFrame), TimeUnit::FromMicroseconds(-1)); } #endif #if defined(MOZ_WIDGET_GTK) && defined(MOZ_USE_HWDECODE) @@ -1742,7 +1755,7 @@ MediaResult FFmpegVideoDecoder<LIBAV_VER>::CreateImage( v = VideoData::CreateFromImage( mInfo.mDisplay, aOffset, TimeUnit::FromMicroseconds(aPts), TimeUnit::FromMicroseconds(aDuration), surface->GetAsImage(), - !!mFrame->key_frame, TimeUnit::FromMicroseconds(-1)); + IsKeyFrame(mFrame), TimeUnit::FromMicroseconds(-1)); } else { FFMPEG_LOG("Failed to uploaded video data to DMABuf"); } @@ -1762,7 +1775,7 @@ MediaResult FFmpegVideoDecoder<LIBAV_VER>::CreateImage( Result<already_AddRefed<VideoData>, MediaResult> r = VideoData::CreateAndCopyData( mInfo, mImageContainer, aOffset, TimeUnit::FromMicroseconds(aPts), - TimeUnit::FromMicroseconds(aDuration), b, !!mFrame->key_frame, + TimeUnit::FromMicroseconds(aDuration), b, IsKeyFrame(mFrame), TimeUnit::FromMicroseconds(mFrame->pkt_dts), mInfo.ScaledImageRect(mFrame->width, mFrame->height), mImageAllocator); @@ -1840,11 +1853,10 @@ MediaResult FFmpegVideoDecoder<LIBAV_VER>::CreateImageVAAPI( mInfo.mTransferFunction ? TransferFunctionToString(mInfo.mTransferFunction.value()) : "unknown"); - RefPtr<VideoData> vp = VideoData::CreateFromImage( mInfo.mDisplay, aOffset, TimeUnit::FromMicroseconds(aPts), TimeUnit::FromMicroseconds(aDuration), surface->GetAsImage(), - !!mFrame->key_frame, TimeUnit::FromMicroseconds(mFrame->pkt_dts)); + IsKeyFrame(mFrame), TimeUnit::FromMicroseconds(mFrame->pkt_dts)); if (!vp) { return MediaResult(NS_ERROR_DOM_MEDIA_DECODE_ERR, @@ -1893,7 +1905,7 @@ MediaResult FFmpegVideoDecoder<LIBAV_VER>::CreateImageV4L2( RefPtr<VideoData> vp = VideoData::CreateFromImage( mInfo.mDisplay, aOffset, TimeUnit::FromMicroseconds(aPts), TimeUnit::FromMicroseconds(aDuration), surface->GetAsImage(), - !!mFrame->key_frame, TimeUnit::FromMicroseconds(mFrame->pkt_dts)); + IsKeyFrame(mFrame), TimeUnit::FromMicroseconds(mFrame->pkt_dts)); if (!vp) { return MediaResult(NS_ERROR_DOM_MEDIA_DECODE_ERR, @@ -2347,7 +2359,7 @@ MediaResult FFmpegVideoDecoder<LIBAV_VER>::CreateImageD3D11( RefPtr<VideoData> v = VideoData::CreateFromImage( mInfo.mDisplay, aOffset, TimeUnit::FromMicroseconds(aPts), - TimeUnit::FromMicroseconds(aDuration), image, !!mFrame->key_frame, + TimeUnit::FromMicroseconds(aDuration), image, IsKeyFrame(mFrame), TimeUnit::FromMicroseconds(mFrame->pkt_dts)); if (!v) { nsPrintfCString msg("D3D image allocation error");