diff --git a/D141827.diff b/D141827.diff new file mode 100644 index 0000000..67caf5f --- /dev/null +++ b/D141827.diff @@ -0,0 +1,207 @@ +diff -up firefox-99.0/dom/media/platforms/ffmpeg/FFmpegVideoFramePool.cpp.D141827 firefox-99.0/dom/media/platforms/ffmpeg/FFmpegVideoFramePool.cpp +--- firefox-99.0/dom/media/platforms/ffmpeg/FFmpegVideoFramePool.cpp.D141827 2022-03-31 01:24:44.000000000 +0200 ++++ firefox-99.0/dom/media/platforms/ffmpeg/FFmpegVideoFramePool.cpp 2022-04-07 10:10:11.608526890 +0200 +@@ -6,7 +6,7 @@ + + #include "FFmpegVideoFramePool.h" + #include "FFmpegLog.h" +-#include "mozilla/widget/DMABufLibWrapper.h" ++#include "mozilla/widget/DMABufLibWrapper.h" + #include "libavutil/pixfmt.h" + + #undef FFMPEG_LOG +@@ -15,11 +15,11 @@ + + namespace mozilla { + +-RefPtr VideoFrameSurfaceVAAPI::GetAsImage() { ++RefPtr VideoFrameSurface::GetAsImage() { + return new layers::DMABUFSurfaceImage(mSurface); + } + +-VideoFrameSurfaceVAAPI::VideoFrameSurfaceVAAPI(DMABufSurface* aSurface) ++VideoFrameSurface::VideoFrameSurface(DMABufSurface* aSurface) + : mSurface(aSurface), + mLib(nullptr), + mAVHWFramesContext(nullptr), +@@ -30,22 +30,22 @@ VideoFrameSurfaceVAAPI::VideoFrameSurfac + MOZ_ASSERT(mSurface); + MOZ_RELEASE_ASSERT(mSurface->GetAsDMABufSurfaceYUV()); + mSurface->GlobalRefCountCreate(); +- FFMPEG_LOG("VideoFrameSurfaceVAAPI: creating surface UID = %d", ++ FFMPEG_LOG("VideoFrameSurface: creating surface UID = %d", + mSurface->GetUID()); + } + +-void VideoFrameSurfaceVAAPI::LockVAAPIData(AVCodecContext* aAVCodecContext, ++void VideoFrameSurface::LockVAAPIData(AVCodecContext* aAVCodecContext, + AVFrame* aAVFrame, + FFmpegLibWrapper* aLib) { +- FFMPEG_LOG("VideoFrameSurfaceVAAPI: VAAPI locking dmabuf surface UID = %d", ++ FFMPEG_LOG("VideoFrameSurface: VAAPI locking dmabuf surface UID = %d", + mSurface->GetUID()); + mLib = aLib; + mAVHWFramesContext = aLib->av_buffer_ref(aAVCodecContext->hw_frames_ctx); + mHWAVBuffer = aLib->av_buffer_ref(aAVFrame->buf[0]); + } + +-void VideoFrameSurfaceVAAPI::ReleaseVAAPIData(bool aForFrameRecycle) { +- FFMPEG_LOG("VideoFrameSurfaceVAAPI: VAAPI releasing dmabuf surface UID = %d", ++void VideoFrameSurface::ReleaseVAAPIData(bool aForFrameRecycle) { ++ FFMPEG_LOG("VideoFrameSurface: VAAPI releasing dmabuf surface UID = %d", + mSurface->GetUID()); + + // It's possible to unref GPU data while IsUsed() is still set. +@@ -67,8 +67,8 @@ void VideoFrameSurfaceVAAPI::ReleaseVAAP + } + } + +-VideoFrameSurfaceVAAPI::~VideoFrameSurfaceVAAPI() { +- FFMPEG_LOG("VideoFrameSurfaceVAAPI: deleting dmabuf surface UID = %d", ++VideoFrameSurface::~VideoFrameSurface() { ++ FFMPEG_LOG("VideoFrameSurface: deleting dmabuf surface UID = %d", + mSurface->GetUID()); + // We're about to quit, no need to recycle the frames. + ReleaseVAAPIData(/* aForFrameRecycle */ false); +@@ -84,9 +84,8 @@ VideoFramePool::~VideoFramePool() { + void VideoFramePool::ReleaseUnusedVAAPIFrames() { + MutexAutoLock lock(mSurfaceLock); + for (const auto& surface : mDMABufSurfaces) { +- auto* vaapiSurface = surface->AsVideoFrameSurfaceVAAPI(); +- if (!vaapiSurface->IsUsed()) { +- vaapiSurface->ReleaseVAAPIData(); ++ if (!surface->IsUsed()) { ++ surface->ReleaseVAAPIData(); + } + } + } +@@ -96,8 +95,7 @@ RefPtr VideoFramePool + if (surface->IsUsed()) { + continue; + } +- auto* vaapiSurface = surface->AsVideoFrameSurfaceVAAPI(); +- vaapiSurface->ReleaseVAAPIData(); ++ surface->ReleaseVAAPIData(); + return surface; + } + return nullptr; +@@ -121,7 +119,7 @@ RefPtr VideoFramePool + return nullptr; + } + FFMPEG_LOG("Created new VA-API DMABufSurface UID = %d", surface->GetUID()); +- RefPtr surf = new VideoFrameSurfaceVAAPI(surface); ++ RefPtr surf = new VideoFrameSurface(surface); + if (!mTextureCreationWorks) { + mTextureCreationWorks = Some(surface->VerifyTextureCreation()); + } +@@ -138,11 +136,8 @@ RefPtr VideoFramePool + } + FFMPEG_LOG("Reusing VA-API DMABufSurface UID = %d", surface->GetUID()); + } +- +- auto* vaapiSurface = videoSurface->AsVideoFrameSurfaceVAAPI(); +- vaapiSurface->LockVAAPIData(aAVCodecContext, aAVFrame, aLib); +- vaapiSurface->MarkAsUsed(); +- ++ videoSurface->LockVAAPIData(aAVCodecContext, aAVFrame, aLib); ++ videoSurface->MarkAsUsed(); + return videoSurface; + } + +diff -up firefox-99.0/dom/media/platforms/ffmpeg/FFmpegVideoFramePool.h.D141827 firefox-99.0/dom/media/platforms/ffmpeg/FFmpegVideoFramePool.h +--- firefox-99.0/dom/media/platforms/ffmpeg/FFmpegVideoFramePool.h.D141827 2022-03-31 01:24:44.000000000 +0200 ++++ firefox-99.0/dom/media/platforms/ffmpeg/FFmpegVideoFramePool.h 2022-04-07 10:09:46.527708638 +0200 +@@ -17,42 +17,17 @@ + namespace mozilla { + + class VideoFramePool; +-class VideoFrameSurfaceVAAPI; + +-class VideoFrameSurface { +- public: +- NS_INLINE_DECL_THREADSAFE_REFCOUNTING(VideoFrameSurface) +- +- VideoFrameSurface() = default; +- +- virtual VideoFrameSurfaceVAAPI* AsVideoFrameSurfaceVAAPI() { return nullptr; } +- +- virtual void SetYUVColorSpace(gfx::YUVColorSpace aColorSpace) = 0; +- virtual void SetColorRange(gfx::ColorRange aColorRange) = 0; +- +- virtual RefPtr GetDMABufSurface() { return nullptr; }; +- virtual RefPtr GetAsImage() = 0; +- +- // Don't allow VideoFrameSurface plain copy as it leads to +- // unexpected DMABufSurface/HW buffer releases and we don't want to +- // deep copy them. +- VideoFrameSurface(const VideoFrameSurface&) = delete; +- const VideoFrameSurface& operator=(VideoFrameSurface const&) = delete; +- +- protected: +- virtual ~VideoFrameSurface(){}; +-}; +- +-// VideoFrameSurfaceVAAPI holds a reference to GPU data with a video frame. ++// VideoFrameSurface holds a reference to GPU data with a video frame. + // + // Actual GPU pixel data are stored at DMABufSurface and + // DMABufSurface is passed to gecko GL rendering pipeline via. + // DMABUFSurfaceImage. + // +-// VideoFrameSurfaceVAAPI can optionally hold VA-API ffmpeg related data to keep ++// VideoFrameSurface can optionally hold VA-API ffmpeg related data to keep + // GPU data locked untill we need them. + // +-// VideoFrameSurfaceVAAPI is used for both HW accelerated video decoding ++// VideoFrameSurface is used for both HW accelerated video decoding + // (VA-API) and ffmpeg SW decoding. + // + // VA-API scenario +@@ -72,13 +47,13 @@ class VideoFrameSurface { + // Unfortunately there isn't any obvious way how to mark particular VASurface + // as used. The best we can do is to hold a reference to particular AVBuffer + // from decoded AVFrame and AVHWFramesContext which owns the AVBuffer. +-class VideoFrameSurfaceVAAPI final : public VideoFrameSurface { ++class VideoFrameSurface { + friend class VideoFramePool; + + public: +- explicit VideoFrameSurfaceVAAPI(DMABufSurface* aSurface); ++ NS_INLINE_DECL_THREADSAFE_REFCOUNTING(VideoFrameSurface) + +- VideoFrameSurfaceVAAPI* AsVideoFrameSurfaceVAAPI() final { return this; } ++ explicit VideoFrameSurface(DMABufSurface* aSurface); + + void SetYUVColorSpace(mozilla::gfx::YUVColorSpace aColorSpace) { + mSurface->GetAsDMABufSurfaceYUV()->SetYUVColorSpace(aColorSpace); +@@ -93,6 +68,12 @@ class VideoFrameSurfaceVAAPI final : pub + + RefPtr GetAsImage(); + ++ // Don't allow VideoFrameSurface plain copy as it leads to ++ // unexpected DMABufSurface/HW buffer releases and we don't want to ++ // deep copy them. ++ VideoFrameSurface(const VideoFrameSurface&) = delete; ++ const VideoFrameSurface& operator=(VideoFrameSurface const&) = delete; ++ + protected: + // Lock VAAPI related data + void LockVAAPIData(AVCodecContext* aAVCodecContext, AVFrame* aAVFrame, +@@ -107,7 +88,7 @@ class VideoFrameSurfaceVAAPI final : pub + void MarkAsUsed() { mSurface->GlobalRefAdd(); } + + private: +- virtual ~VideoFrameSurfaceVAAPI(); ++ virtual ~VideoFrameSurface(); + + const RefPtr mSurface; + const FFmpegLibWrapper* mLib; +@@ -132,7 +113,7 @@ class VideoFramePool final { + private: + // Protect mDMABufSurfaces pool access + Mutex mSurfaceLock; +- nsTArray> mDMABufSurfaces; ++ nsTArray> mDMABufSurfaces; + // We may fail to create texture over DMABuf memory due to driver bugs so + // check that before we export first DMABuf video frame. + Maybe mTextureCreationWorks; diff --git a/D141828.diff b/D141828.diff new file mode 100644 index 0000000..b2475e9 --- /dev/null +++ b/D141828.diff @@ -0,0 +1,252 @@ +diff -up firefox-99.0/dom/media/platforms/ffmpeg/ffmpeg58/moz.build.D141828 firefox-99.0/dom/media/platforms/ffmpeg/ffmpeg58/moz.build +--- firefox-99.0/dom/media/platforms/ffmpeg/ffmpeg58/moz.build.D141828 2022-03-31 01:24:44.000000000 +0200 ++++ firefox-99.0/dom/media/platforms/ffmpeg/ffmpeg58/moz.build 2022-04-07 10:11:34.981246890 +0200 +@@ -30,6 +30,9 @@ if CONFIG['MOZ_WAYLAND']: + CXXFLAGS += CONFIG['MOZ_GTK3_CFLAGS'] + DEFINES['MOZ_WAYLAND_USE_VAAPI'] = 1 + USE_LIBS += ['mozva'] ++ UNIFIED_SOURCES += [ ++ '../FFmpegVideoFramePool.cpp', ++ ] + + include("/ipc/chromium/chromium-config.mozbuild") + +diff -up firefox-99.0/dom/media/platforms/ffmpeg/ffmpeg59/moz.build.D141828 firefox-99.0/dom/media/platforms/ffmpeg/ffmpeg59/moz.build +--- firefox-99.0/dom/media/platforms/ffmpeg/ffmpeg59/moz.build.D141828 2022-03-31 01:24:44.000000000 +0200 ++++ firefox-99.0/dom/media/platforms/ffmpeg/ffmpeg59/moz.build 2022-04-07 10:11:34.981246890 +0200 +@@ -30,6 +30,9 @@ if CONFIG["MOZ_WAYLAND"]: + CXXFLAGS += CONFIG["MOZ_GTK3_CFLAGS"] + DEFINES["MOZ_WAYLAND_USE_VAAPI"] = 1 + USE_LIBS += ["mozva"] ++ UNIFIED_SOURCES += [ ++ "../FFmpegVideoFramePool.cpp", ++ ] + + include("/ipc/chromium/chromium-config.mozbuild") + +diff -up firefox-99.0/dom/media/platforms/ffmpeg/FFmpegVideoDecoder.cpp.D141828 firefox-99.0/dom/media/platforms/ffmpeg/FFmpegVideoDecoder.cpp +--- firefox-99.0/dom/media/platforms/ffmpeg/FFmpegVideoDecoder.cpp.D141828 2022-03-31 01:24:44.000000000 +0200 ++++ firefox-99.0/dom/media/platforms/ffmpeg/FFmpegVideoDecoder.cpp 2022-04-07 10:11:34.981246890 +0200 +@@ -814,7 +814,7 @@ MediaResult FFmpegVideoDecoder(); ++ mVideoFramePool = MakeUnique>(); + } + + // Release unused VA-API surfaces before avcodec_receive_frame() as +diff -up firefox-99.0/dom/media/platforms/ffmpeg/FFmpegVideoDecoder.h.D141828 firefox-99.0/dom/media/platforms/ffmpeg/FFmpegVideoDecoder.h +--- firefox-99.0/dom/media/platforms/ffmpeg/FFmpegVideoDecoder.h.D141828 2022-03-31 01:24:44.000000000 +0200 ++++ firefox-99.0/dom/media/platforms/ffmpeg/FFmpegVideoDecoder.h 2022-04-07 10:11:34.981246890 +0200 +@@ -16,6 +16,9 @@ + #if LIBAVCODEC_VERSION_MAJOR >= 57 && LIBAVUTIL_VERSION_MAJOR >= 56 + # include "mozilla/layers/TextureClient.h" + #endif ++#ifdef MOZ_WAYLAND_USE_VAAPI ++# include "FFmpegVideoFramePool.h" ++#endif + + struct _VADRMPRIMESurfaceDescriptor; + typedef struct _VADRMPRIMESurfaceDescriptor VADRMPRIMESurfaceDescriptor; +@@ -23,7 +26,6 @@ typedef struct _VADRMPRIMESurfaceDescrip + namespace mozilla { + + class ImageBufferWrapper; +-class VideoFramePool; + + template + class FFmpegVideoDecoder : public FFmpegDataDecoder {}; +@@ -138,7 +140,7 @@ class FFmpegVideoDecoder + AVBufferRef* mVAAPIDeviceContext; + bool mEnableHardwareDecoding; + VADisplay mDisplay; +- UniquePtr mVideoFramePool; ++ UniquePtr> mVideoFramePool; + static nsTArray mAcceleratedFormats; + #endif + RefPtr mImageAllocator; +diff -up firefox-99.0/dom/media/platforms/ffmpeg/FFmpegVideoFramePool.cpp.D141828 firefox-99.0/dom/media/platforms/ffmpeg/FFmpegVideoFramePool.cpp +--- firefox-99.0/dom/media/platforms/ffmpeg/FFmpegVideoFramePool.cpp.D141828 2022-04-07 10:11:34.980246857 +0200 ++++ firefox-99.0/dom/media/platforms/ffmpeg/FFmpegVideoFramePool.cpp 2022-04-07 10:16:02.390971008 +0200 +@@ -5,6 +5,7 @@ + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + #include "FFmpegVideoFramePool.h" ++#include "PlatformDecoderModule.h" + #include "FFmpegLog.h" + #include "mozilla/widget/DMABufLibWrapper.h" + #include "libavutil/pixfmt.h" +@@ -15,11 +16,11 @@ + + namespace mozilla { + +-RefPtr VideoFrameSurface::GetAsImage() { ++RefPtr VideoFrameSurface::GetAsImage() { + return new layers::DMABUFSurfaceImage(mSurface); + } + +-VideoFrameSurface::VideoFrameSurface(DMABufSurface* aSurface) ++VideoFrameSurface::VideoFrameSurface(DMABufSurface* aSurface) + : mSurface(aSurface), + mLib(nullptr), + mAVHWFramesContext(nullptr), +@@ -34,7 +35,7 @@ VideoFrameSurface::VideoFrameSurface(DMA + mSurface->GetUID()); + } + +-void VideoFrameSurface::LockVAAPIData(AVCodecContext* aAVCodecContext, ++void VideoFrameSurface::LockVAAPIData(AVCodecContext* aAVCodecContext, + AVFrame* aAVFrame, + FFmpegLibWrapper* aLib) { + FFMPEG_LOG("VideoFrameSurface: VAAPI locking dmabuf surface UID = %d", +@@ -44,7 +45,7 @@ void VideoFrameSurface::LockVAAPIData(AV + mHWAVBuffer = aLib->av_buffer_ref(aAVFrame->buf[0]); + } + +-void VideoFrameSurface::ReleaseVAAPIData(bool aForFrameRecycle) { ++void VideoFrameSurface::ReleaseVAAPIData(bool aForFrameRecycle) { + FFMPEG_LOG("VideoFrameSurface: VAAPI releasing dmabuf surface UID = %d", + mSurface->GetUID()); + +@@ -67,21 +68,22 @@ void VideoFrameSurface::ReleaseVAAPIData + } + } + +-VideoFrameSurface::~VideoFrameSurface() { ++VideoFrameSurface::~VideoFrameSurface() { + FFMPEG_LOG("VideoFrameSurface: deleting dmabuf surface UID = %d", + mSurface->GetUID()); + // We're about to quit, no need to recycle the frames. + ReleaseVAAPIData(/* aForFrameRecycle */ false); + } + +-VideoFramePool::VideoFramePool() : mSurfaceLock("VideoFramePoolSurfaceLock") {} ++VideoFramePool::VideoFramePool() ++ : mSurfaceLock("VideoFramePoolSurfaceLock") {} + +-VideoFramePool::~VideoFramePool() { ++VideoFramePool::~VideoFramePool() { + MutexAutoLock lock(mSurfaceLock); + mDMABufSurfaces.Clear(); + } + +-void VideoFramePool::ReleaseUnusedVAAPIFrames() { ++void VideoFramePool::ReleaseUnusedVAAPIFrames() { + MutexAutoLock lock(mSurfaceLock); + for (const auto& surface : mDMABufSurfaces) { + if (!surface->IsUsed()) { +@@ -90,7 +92,8 @@ void VideoFramePool::ReleaseUnusedVAAPIF + } + } + +-RefPtr VideoFramePool::GetFreeVideoFrameSurface() { ++RefPtr> ++VideoFramePool::GetFreeVideoFrameSurface() { + for (auto& surface : mDMABufSurfaces) { + if (surface->IsUsed()) { + continue; +@@ -101,7 +104,8 @@ RefPtr VideoFramePool + return nullptr; + } + +-RefPtr VideoFramePool::GetVideoFrameSurface( ++RefPtr> ++VideoFramePool::GetVideoFrameSurface( + VADRMPRIMESurfaceDescriptor& aVaDesc, AVCodecContext* aAVCodecContext, + AVFrame* aAVFrame, FFmpegLibWrapper* aLib) { + if (aVaDesc.fourcc != VA_FOURCC_NV12 && aVaDesc.fourcc != VA_FOURCC_YV12 && +@@ -111,7 +115,8 @@ RefPtr VideoFramePool + } + + MutexAutoLock lock(mSurfaceLock); +- RefPtr videoSurface = GetFreeVideoFrameSurface(); ++ RefPtr> videoSurface = ++ GetFreeVideoFrameSurface(); + if (!videoSurface) { + RefPtr surface = + DMABufSurfaceYUV::CreateYUVSurface(aVaDesc); +@@ -119,7 +124,8 @@ RefPtr VideoFramePool + return nullptr; + } + FFMPEG_LOG("Created new VA-API DMABufSurface UID = %d", surface->GetUID()); +- RefPtr surf = new VideoFrameSurface(surface); ++ RefPtr> surf = ++ new VideoFrameSurface(surface); + if (!mTextureCreationWorks) { + mTextureCreationWorks = Some(surface->VerifyTextureCreation()); + } +diff -up firefox-99.0/dom/media/platforms/ffmpeg/FFmpegVideoFramePool.h.D141828 firefox-99.0/dom/media/platforms/ffmpeg/FFmpegVideoFramePool.h +--- firefox-99.0/dom/media/platforms/ffmpeg/FFmpegVideoFramePool.h.D141828 2022-04-07 10:11:34.980246857 +0200 ++++ firefox-99.0/dom/media/platforms/ffmpeg/FFmpegVideoFramePool.h 2022-04-07 10:14:54.478755409 +0200 +@@ -7,8 +7,9 @@ + #ifndef __FFmpegVideoFramePool_h__ + #define __FFmpegVideoFramePool_h__ + +-#include "FFmpegVideoDecoder.h" + #include "FFmpegLibWrapper.h" ++#include "FFmpegLibs.h" ++#include "FFmpegLog.h" + + #include "mozilla/layers/DMABUFSurfaceImage.h" + #include "mozilla/widget/DMABufLibWrapper.h" +@@ -16,8 +17,6 @@ + + namespace mozilla { + +-class VideoFramePool; +- + // VideoFrameSurface holds a reference to GPU data with a video frame. + // + // Actual GPU pixel data are stored at DMABufSurface and +@@ -47,8 +46,19 @@ class VideoFramePool; + // Unfortunately there isn't any obvious way how to mark particular VASurface + // as used. The best we can do is to hold a reference to particular AVBuffer + // from decoded AVFrame and AVHWFramesContext which owns the AVBuffer. +-class VideoFrameSurface { +- friend class VideoFramePool; ++template ++class VideoFrameSurface {}; ++template <> ++class VideoFrameSurface; ++ ++template ++class VideoFramePool {}; ++template <> ++class VideoFramePool; ++ ++template <> ++class VideoFrameSurface { ++ friend class VideoFramePool; + + public: + NS_INLINE_DECL_THREADSAFE_REFCOUNTING(VideoFrameSurface) +@@ -97,23 +107,24 @@ class VideoFrameSurface { + }; + + // VideoFramePool class is thread-safe. +-class VideoFramePool final { ++template <> ++class VideoFramePool { + public: + VideoFramePool(); + ~VideoFramePool(); + +- RefPtr GetVideoFrameSurface( ++ RefPtr> GetVideoFrameSurface( + VADRMPRIMESurfaceDescriptor& aVaDesc, AVCodecContext* aAVCodecContext, + AVFrame* aAVFrame, FFmpegLibWrapper* aLib); + void ReleaseUnusedVAAPIFrames(); + + private: +- RefPtr GetFreeVideoFrameSurface(); ++ RefPtr> GetFreeVideoFrameSurface(); + + private: + // Protect mDMABufSurfaces pool access + Mutex mSurfaceLock; +- nsTArray> mDMABufSurfaces; ++ nsTArray>> mDMABufSurfaces; + // We may fail to create texture over DMABuf memory due to driver bugs so + // check that before we export first DMABuf video frame. + Maybe mTextureCreationWorks; diff --git a/firefox.spec b/firefox.spec index 86390b6..55459a5 100644 --- a/firefox.spec +++ b/firefox.spec @@ -241,6 +241,8 @@ Patch402: mozilla-1196777.patch Patch407: mozilla-1667096.patch Patch408: mozilla-1663844.patch Patch415: mozilla-1670333.patch +Patch416: D141827.diff +Patch417: D141828.diff # PGO/LTO patches Patch600: pgo.patch @@ -480,6 +482,8 @@ This package contains results of tests executed during build. %patch407 -p1 -b .1667096 %patch408 -p1 -b .1663844 %patch415 -p1 -b .1670333 +%patch416 -p1 -b .D141827 +%patch417 -p1 -b .D141828 # PGO patches %if %{build_with_pgo}