From ade0dc9860df6a6b555ed0cfebef7ce9bd98a36f Mon Sep 17 00:00:00 2001 From: Ilya Nikolaevskiy Date: Mon, 29 Apr 2019 11:25:50 +0200 Subject: [PATCH] Make FrameBuffer be able to signal if it's trivially convertible to I420 Bug: chromium:930186,webrtc:10310 Change-Id: I7857c33d3616ac58738b22816f9c78fe9e6d1d3c Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/134206 Commit-Queue: Ilya Nikolaevskiy Reviewed-by: Niels Moller Cr-Commit-Position: refs/heads/master@{#27798} --- api/video/video_frame_buffer.cc | 14 ++++++++++---- api/video/video_frame_buffer.h | 15 +++++++++++---- 2 files changed, 21 insertions(+), 8 deletions(-) diff --git a/api/video/video_frame_buffer.cc b/api/video/video_frame_buffer.cc index 41276bec27..1e5320d883 100644 --- a/api/video/video_frame_buffer.cc +++ b/api/video/video_frame_buffer.cc @@ -15,14 +15,20 @@ namespace webrtc { rtc::scoped_refptr VideoFrameBuffer::GetI420() { - RTC_CHECK(type() == Type::kI420); - return static_cast(this); + if (type() == Type::kI420 || type() == Type::kI420A) { + return static_cast(this); + } else { + return nullptr; + } } rtc::scoped_refptr VideoFrameBuffer::GetI420() const { - RTC_CHECK(type() == Type::kI420); - return static_cast(this); + if (type() == Type::kI420 || type() == Type::kI420A) { + return static_cast(this); + } else { + return nullptr; + } } I420ABufferInterface* VideoFrameBuffer::GetI420A() { diff --git a/api/video/video_frame_buffer.h b/api/video/video_frame_buffer.h index 7fb603e1eb..af18e57db7 100644 --- a/api/video/video_frame_buffer.h +++ b/api/video/video_frame_buffer.h @@ -65,12 +65,19 @@ class VideoFrameBuffer : public rtc::RefCountInterface { // software encoders. virtual rtc::scoped_refptr ToI420() = 0; - // These functions should only be called if type() is of the correct type. - // Calling with a different type will result in a crash. + // GetI420() methods should return I420 buffer if conversion is trivial, i.e + // no change for binary data is needed. Otherwise these methods should return + // nullptr. One example of buffer with that property is + // WebrtcVideoFrameAdapter in Chrome - it's I420 buffer backed by a shared + // memory buffer. Therefore it must have type kNative. Yet, ToI420() + // doesn't affect binary data at all. Another example is any I420A buffer. // TODO(magjed): Return raw pointers for GetI420 once deprecated interface is // removed. - rtc::scoped_refptr GetI420(); - rtc::scoped_refptr GetI420() const; + virtual rtc::scoped_refptr GetI420(); + virtual rtc::scoped_refptr GetI420() const; + + // These functions should only be called if type() is of the correct type. + // Calling with a different type will result in a crash. I420ABufferInterface* GetI420A(); const I420ABufferInterface* GetI420A() const; I444BufferInterface* GetI444();