tor-browser

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

commit 5e579f1966d61524ad6c61676f7f1d7e7caafb30
parent a6489518026dad5dfdec7861fb7a731f69ba96b1
Author: Michael Froman <mjfroman@mac.com>
Date:   Thu, 13 Nov 2025 18:36:53 +0000

Bug 1996020 - use frame buffer pool in DesktopCaptureImpl::OnCaptureResult r=dbaker

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

Diffstat:
Mdom/media/systemservices/video_engine/desktop_capture_impl.cc | 21++++++++++++++-------
Mdom/media/systemservices/video_engine/desktop_capture_impl.h | 3+++
2 files changed, 17 insertions(+), 7 deletions(-)

diff --git a/dom/media/systemservices/video_engine/desktop_capture_impl.cc b/dom/media/systemservices/video_engine/desktop_capture_impl.cc @@ -273,7 +273,8 @@ DesktopCaptureImpl::DesktopCaptureImpl(const int32_t aId, const char* aUniqueId, mDeviceType(aType), mControlThread(mozilla::GetCurrentSerialEventTarget()), mNextFrameMinimumTime(Timestamp::Zero()), - mCallbacks("DesktopCaptureImpl::mCallbacks") {} + mCallbacks("DesktopCaptureImpl::mCallbacks"), + mBufferPool(false, 2) {} DesktopCaptureImpl::~DesktopCaptureImpl() { MOZ_ASSERT(!mCaptureThread); @@ -399,6 +400,8 @@ int32_t DesktopCaptureImpl::StopCapture() { mRequestedCapability = mozilla::Nothing(); } + mBufferPool.Release(); + if (mCaptureThread) { // CaptureThread shutdown. mCaptureThread->AsyncShutdown(); @@ -472,18 +475,22 @@ void DesktopCaptureImpl::OnCaptureResult(DesktopCapturer::Result aResult, return; } - int stride_y = width; - int stride_uv = (width + 1) / 2; - // Setting absolute height (in case it was negative). // In Windows, the image starts bottom left, instead of top left. // Setting a negative source height, inverts the image (within LibYuv). mozilla::PerformanceRecorder<mozilla::CopyVideoStage> rec( "DesktopCaptureImpl::ConvertToI420"_ns, mTrackingId, width, abs(height)); - // TODO(nisse): Use a pool? - webrtc::scoped_refptr<I420Buffer> buffer = - I420Buffer::Create(width, abs(height), stride_y, stride_uv, stride_uv); + + webrtc::scoped_refptr<webrtc::I420Buffer> buffer = + mBufferPool.CreateI420Buffer(width, abs(height)); + if (!buffer) { + RTC_LOG(LS_ERROR) << "Failed to allocate I420Buffer from pool."; + MOZ_ASSERT_UNREACHABLE( + "We might fail to allocate a buffer, but with this " + "being a recycling pool that shouldn't happen"); + return; + } const int conversionResult = libyuv::ConvertToI420( videoFrame, videoFrameLength, buffer->MutableDataY(), buffer->StrideY(), diff --git a/dom/media/systemservices/video_engine/desktop_capture_impl.h b/dom/media/systemservices/video_engine/desktop_capture_impl.h @@ -24,6 +24,7 @@ #include "api/sequence_checker.h" #include "api/video/video_frame.h" #include "api/video/video_sink_interface.h" +#include "common_video/include/video_frame_buffer_pool.h" #include "modules/desktop_capture/desktop_capturer.h" #include "modules/video_capture/video_capture.h" #include "mozilla/DataMutex.h" @@ -135,6 +136,8 @@ class DesktopCaptureImpl : public DesktopCapturer::Callback, mCallbacks; // Subscribers to this event will be notified when the capture has ended. mozilla::MediaEventProducer<void> mCaptureEndedEvent; + + webrtc::VideoFrameBufferPool mBufferPool; }; } // namespace webrtc