Skip to content

Commit 5e579f1

Browse files
mjfromanmfromanmoz
authored andcommitted
Bug 1996020 - use frame buffer pool in DesktopCaptureImpl::OnCaptureResult r=dbaker
Differential Revision: https://phabricator.services.mozilla.com/D270253
1 parent a648951 commit 5e579f1

File tree

2 files changed

+17
-7
lines changed

2 files changed

+17
-7
lines changed

dom/media/systemservices/video_engine/desktop_capture_impl.cc

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,8 @@ DesktopCaptureImpl::DesktopCaptureImpl(const int32_t aId, const char* aUniqueId,
273273
mDeviceType(aType),
274274
mControlThread(mozilla::GetCurrentSerialEventTarget()),
275275
mNextFrameMinimumTime(Timestamp::Zero()),
276-
mCallbacks("DesktopCaptureImpl::mCallbacks") {}
276+
mCallbacks("DesktopCaptureImpl::mCallbacks"),
277+
mBufferPool(false, 2) {}
277278

278279
DesktopCaptureImpl::~DesktopCaptureImpl() {
279280
MOZ_ASSERT(!mCaptureThread);
@@ -399,6 +400,8 @@ int32_t DesktopCaptureImpl::StopCapture() {
399400
mRequestedCapability = mozilla::Nothing();
400401
}
401402

403+
mBufferPool.Release();
404+
402405
if (mCaptureThread) {
403406
// CaptureThread shutdown.
404407
mCaptureThread->AsyncShutdown();
@@ -472,18 +475,22 @@ void DesktopCaptureImpl::OnCaptureResult(DesktopCapturer::Result aResult,
472475
return;
473476
}
474477

475-
int stride_y = width;
476-
int stride_uv = (width + 1) / 2;
477-
478478
// Setting absolute height (in case it was negative).
479479
// In Windows, the image starts bottom left, instead of top left.
480480
// Setting a negative source height, inverts the image (within LibYuv).
481481

482482
mozilla::PerformanceRecorder<mozilla::CopyVideoStage> rec(
483483
"DesktopCaptureImpl::ConvertToI420"_ns, mTrackingId, width, abs(height));
484-
// TODO(nisse): Use a pool?
485-
webrtc::scoped_refptr<I420Buffer> buffer =
486-
I420Buffer::Create(width, abs(height), stride_y, stride_uv, stride_uv);
484+
485+
webrtc::scoped_refptr<webrtc::I420Buffer> buffer =
486+
mBufferPool.CreateI420Buffer(width, abs(height));
487+
if (!buffer) {
488+
RTC_LOG(LS_ERROR) << "Failed to allocate I420Buffer from pool.";
489+
MOZ_ASSERT_UNREACHABLE(
490+
"We might fail to allocate a buffer, but with this "
491+
"being a recycling pool that shouldn't happen");
492+
return;
493+
}
487494

488495
const int conversionResult = libyuv::ConvertToI420(
489496
videoFrame, videoFrameLength, buffer->MutableDataY(), buffer->StrideY(),

dom/media/systemservices/video_engine/desktop_capture_impl.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include "api/sequence_checker.h"
2525
#include "api/video/video_frame.h"
2626
#include "api/video/video_sink_interface.h"
27+
#include "common_video/include/video_frame_buffer_pool.h"
2728
#include "modules/desktop_capture/desktop_capturer.h"
2829
#include "modules/video_capture/video_capture.h"
2930
#include "mozilla/DataMutex.h"
@@ -135,6 +136,8 @@ class DesktopCaptureImpl : public DesktopCapturer::Callback,
135136
mCallbacks;
136137
// Subscribers to this event will be notified when the capture has ended.
137138
mozilla::MediaEventProducer<void> mCaptureEndedEvent;
139+
140+
webrtc::VideoFrameBufferPool mBufferPool;
138141
};
139142

140143
} // namespace webrtc

0 commit comments

Comments
 (0)