diff --git a/api/video/video_frame_buffer.cc b/api/video/video_frame_buffer.cc index 1e5320d883..b9fd9cd92a 100644 --- a/api/video/video_frame_buffer.cc +++ b/api/video/video_frame_buffer.cc @@ -14,26 +14,10 @@ namespace webrtc { -rtc::scoped_refptr VideoFrameBuffer::GetI420() { - if (type() == Type::kI420 || type() == Type::kI420A) { - return static_cast(this); - } else { - return nullptr; - } -} - -rtc::scoped_refptr VideoFrameBuffer::GetI420() - const { - if (type() == Type::kI420 || type() == Type::kI420A) { - return static_cast(this); - } else { - return nullptr; - } -} - -I420ABufferInterface* VideoFrameBuffer::GetI420A() { - RTC_CHECK(type() == Type::kI420A); - return static_cast(this); +const I420BufferInterface* VideoFrameBuffer::GetI420() const { + // Overridden by subclasses that can return an I420 buffer without any + // conversion, in particular, I420BufferInterface. + return nullptr; } const I420ABufferInterface* VideoFrameBuffer::GetI420A() const { @@ -41,21 +25,11 @@ const I420ABufferInterface* VideoFrameBuffer::GetI420A() const { return static_cast(this); } -I444BufferInterface* VideoFrameBuffer::GetI444() { - RTC_CHECK(type() == Type::kI444); - return static_cast(this); -} - const I444BufferInterface* VideoFrameBuffer::GetI444() const { RTC_CHECK(type() == Type::kI444); return static_cast(this); } -I010BufferInterface* VideoFrameBuffer::GetI010() { - RTC_CHECK(type() == Type::kI010); - return static_cast(this); -} - const I010BufferInterface* VideoFrameBuffer::GetI010() const { RTC_CHECK(type() == Type::kI010); return static_cast(this); @@ -77,6 +51,10 @@ rtc::scoped_refptr I420BufferInterface::ToI420() { return this; } +const I420BufferInterface* I420BufferInterface::GetI420() const { + return this; +} + VideoFrameBuffer::Type I420ABufferInterface::type() const { return Type::kI420A; } diff --git a/api/video/video_frame_buffer.h b/api/video/video_frame_buffer.h index af18e57db7..3b8db14bf9 100644 --- a/api/video/video_frame_buffer.h +++ b/api/video/video_frame_buffer.h @@ -71,18 +71,12 @@ class VideoFrameBuffer : public rtc::RefCountInterface { // 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. - virtual rtc::scoped_refptr GetI420(); - virtual rtc::scoped_refptr GetI420() const; + virtual const I420BufferInterface* 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(); const I444BufferInterface* GetI444() const; - I010BufferInterface* GetI010(); const I010BufferInterface* GetI010() const; protected: @@ -127,6 +121,7 @@ class I420BufferInterface : public PlanarYuv8Buffer { int ChromaHeight() const final; rtc::scoped_refptr ToI420() final; + const I420BufferInterface* GetI420() const final; protected: ~I420BufferInterface() override {} diff --git a/common_video/video_frame_unittest.cc b/common_video/video_frame_unittest.cc index b7d8c300c3..70dedc9256 100644 --- a/common_video/video_frame_unittest.cc +++ b/common_video/video_frame_unittest.cc @@ -320,9 +320,9 @@ TEST(TestVideoFrame, ShallowCopy) { VideoFrame frame2(frame1); EXPECT_EQ(frame1.video_frame_buffer(), frame2.video_frame_buffer()); - rtc::scoped_refptr yuv1 = + const webrtc::I420BufferInterface* yuv1 = frame1.video_frame_buffer()->GetI420(); - rtc::scoped_refptr yuv2 = + const webrtc::I420BufferInterface* yuv2 = frame2.video_frame_buffer()->GetI420(); EXPECT_EQ(yuv1->DataY(), yuv2->DataY()); EXPECT_EQ(yuv1->DataU(), yuv2->DataU()); diff --git a/examples/unityplugin/video_observer.cc b/examples/unityplugin/video_observer.cc index a78ef57e41..7e33b08e27 100644 --- a/examples/unityplugin/video_observer.cc +++ b/examples/unityplugin/video_observer.cc @@ -33,7 +33,7 @@ void VideoObserver::OnFrame(const webrtc::VideoFrame& frame) { } else { // The buffer has alpha channel. - webrtc::I420ABufferInterface* i420a_buffer = buffer->GetI420A(); + const webrtc::I420ABufferInterface* i420a_buffer = buffer->GetI420A(); OnI420FrameReady(i420a_buffer->DataY(), i420a_buffer->DataU(), i420a_buffer->DataV(), i420a_buffer->DataA(), diff --git a/modules/video_coding/codecs/h264/h264_decoder_impl.cc b/modules/video_coding/codecs/h264/h264_decoder_impl.cc index 5c83d694e3..580b8a863c 100644 --- a/modules/video_coding/codecs/h264/h264_decoder_impl.cc +++ b/modules/video_coding/codecs/h264/h264_decoder_impl.cc @@ -283,7 +283,7 @@ int32_t H264DecoderImpl::Decode(const EncodedImage& input_image, VideoFrame* input_frame = static_cast(av_buffer_get_opaque(av_frame_->buf[0])); RTC_DCHECK(input_frame); - rtc::scoped_refptr i420_buffer = + const webrtc::I420BufferInterface* i420_buffer = input_frame->video_frame_buffer()->GetI420(); RTC_CHECK_EQ(av_frame_->data[kYPlaneIndex], i420_buffer->DataY()); RTC_CHECK_EQ(av_frame_->data[kUPlaneIndex], i420_buffer->DataU()); diff --git a/modules/video_coding/codecs/vp9/vp9_impl.cc b/modules/video_coding/codecs/vp9/vp9_impl.cc index abb54b6b93..45dacfd1a8 100644 --- a/modules/video_coding/codecs/vp9/vp9_impl.cc +++ b/modules/video_coding/codecs/vp9/vp9_impl.cc @@ -912,7 +912,8 @@ int VP9EncoderImpl::Encode(const VideoFrame& input_image, // Keep reference to buffer until encode completes. rtc::scoped_refptr i420_buffer; - rtc::scoped_refptr i010_buffer; + const I010BufferInterface* i010_buffer; + rtc::scoped_refptr i010_copy; switch (profile_) { case VP9Profile::kProfile0: { i420_buffer = input_image.video_frame_buffer()->ToI420(); @@ -935,8 +936,9 @@ int VP9EncoderImpl::Encode(const VideoFrame& input_image, break; } default: { - i010_buffer = + i010_copy = I010Buffer::Copy(*input_image.video_frame_buffer()->ToI420()); + i010_buffer = i010_copy.get(); } } raw_->planes[VPX_PLANE_Y] = const_cast(