tor-browser

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

commit 803cd3c7617fd38eba1b454b55d308d9609ee164
parent 8bae5f49b3cae9c9de197268c60ea61da4a625f4
Author: Michael Froman <mjfroman@mac.com>
Date:   Tue, 28 Oct 2025 19:20:26 +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 | 23++++++++++++++++-------
Mdom/media/systemservices/video_engine/desktop_capture_impl.h | 3+++
2 files changed, 19 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,24 @@ 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); + // The more basic I420Buffer constructor defaults stride_y to width; + // and stride_u and stride_v as (width + 1) / 2, so we can use this + // call to CreateI420Buffer that takes only width and height. + 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