Skip to content

Commit

Permalink
ObjCFrameBuffer getBuffer callback can return nullptr
Browse files Browse the repository at this point in the history
https://bugs.webkit.org/show_bug.cgi?id=259265
rdar://112220174

Reviewed by Eric Carlson.

RemoteVideoFrameProxy::pixelBuffer() is not guaranteed to always return a non null pixel buffer.
It is trying to do so by returning a black frame if grabbing the actual video frame fails.
But the black frame creation can itself fail.

To prevent this, we are updating ObjCFrameBuffer so that, should the pixel buffer be nullptr,
ObjCFrameBuffer::ToI420 will itself returns nullptr instead ofa I420BufferInterface which is empty inside.
The rest of libwebrtc deals with nullptr I420BufferInterface by exiting encoding early.

Manually tested by updating RemoteVideoFrameProxy::pixelBuffer() to return nullptr.

* Source/ThirdParty/libwebrtc/Source/webrtc/sdk/objc/native/src/objc_frame_buffer.mm:
(webrtc::ObjCFrameBuffer::ToI420):
(webrtc::ObjCFrameBuffer::wrapped_frame_buffer const):

Canonical link: https://commits.webkit.org/266097@main
  • Loading branch information
youennf committed Jul 17, 2023
1 parent e0823a9 commit 61b0933
Showing 1 changed file with 7 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@ explicit ObjCI420FrameBuffer(id<RTCI420Buffer> frame_buffer)
}

rtc::scoped_refptr<I420BufferInterface> ObjCFrameBuffer::ToI420() {
auto frameBuffer = wrapped_frame_buffer();
if (!frameBuffer)
return nullptr;
rtc::scoped_refptr<I420BufferInterface> buffer =
rtc::make_ref_counted<ObjCI420FrameBuffer>([wrapped_frame_buffer() toI420]);

Expand All @@ -90,8 +93,10 @@ explicit ObjCI420FrameBuffer(id<RTCI420Buffer> frame_buffer)
id<RTCVideoFrameBuffer> ObjCFrameBuffer::wrapped_frame_buffer() const {
#if defined(WEBRTC_WEBKIT_BUILD)
webrtc::MutexLock lock(&mutex_);
if (!frame_buffer_ && frame_buffer_provider_.getBuffer)
const_cast<ObjCFrameBuffer*>(this)->frame_buffer_ = [[RTCCVPixelBuffer alloc] initWithPixelBuffer:frame_buffer_provider_.getBuffer(frame_buffer_provider_.pointer)];
if (!frame_buffer_ && frame_buffer_provider_.getBuffer && frame_buffer_provider_.pointer) {
if (auto* buffer = frame_buffer_provider_.getBuffer(frame_buffer_provider_.pointer))
const_cast<ObjCFrameBuffer*>(this)->frame_buffer_ = [[RTCCVPixelBuffer alloc] initWithPixelBuffer:frame_buffer_provider_.getBuffer(frame_buffer_provider_.pointer)];
}
#endif
return frame_buffer_;
}
Expand Down

0 comments on commit 61b0933

Please sign in to comment.