Index: webrtc/api/video/video_frame_buffer.cc |
diff --git a/webrtc/api/video/video_frame_buffer.cc b/webrtc/api/video/video_frame_buffer.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..19685438e52f7ed537f31a5cc54f0551b39620b0 |
--- /dev/null |
+++ b/webrtc/api/video/video_frame_buffer.cc |
@@ -0,0 +1,131 @@ |
+/* |
+ * Copyright (c) 2017 The WebRTC project authors. All Rights Reserved. |
+ * |
+ * Use of this source code is governed by a BSD-style license |
+ * that can be found in the LICENSE file in the root of the source |
+ * tree. An additional intellectual property rights grant can be found |
+ * in the file PATENTS. All contributing project authors may |
+ * be found in the AUTHORS file in the root of the source tree. |
+ */ |
+ |
+#include "webrtc/api/video/video_frame_buffer.h" |
+ |
+#include "libyuv/convert_from.h" |
+#include "webrtc/api/video/i420_buffer.h" |
+#include "webrtc/base/checks.h" |
+ |
+namespace webrtc { |
+ |
+namespace { |
+ |
+// Class for handling legacy implementations of NativeToI420Buffer() and |
+// adapting them into the new ToI420() function. |
nisse-webrtc
2017/05/04 08:15:29
I'm afraid I don't understand what problem this cl
magjed_webrtc
2017/05/04 12:25:13
The problem it solves is providing a default imple
nisse-webrtc
2017/05/05 11:33:04
I see. If we keep this, I think the comment should
magjed_webrtc
2017/05/05 12:25:24
So the problem is that existing implementations do
nisse-webrtc
2017/05/05 12:45:29
I think I finally get it. So VideoFrameBuffer has
|
+class LegacyI420Wrapper : public PlanarYuvBuffer { |
+ public: |
+ explicit LegacyI420Wrapper(rtc::scoped_refptr<VideoFrameBuffer> buffer) |
+ : buffer_(buffer) {} |
+ |
+ PixelFormat Format() const override { return PixelFormat::kI420; } |
+ |
+ int width() const override { return buffer_->width(); } |
+ int height() const override { return buffer_->height(); } |
+ |
+ const uint8_t* DataY() const override { return buffer_->DataY(); } |
+ const uint8_t* DataU() const override { return buffer_->DataU(); } |
+ const uint8_t* DataV() const override { return buffer_->DataV(); } |
+ |
+ int StrideY() const override { return buffer_->StrideY(); } |
+ int StrideU() const override { return buffer_->StrideU(); } |
+ int StrideV() const override { return buffer_->StrideV(); } |
+ |
+ private: |
+ rtc::scoped_refptr<VideoFrameBuffer> buffer_; |
+}; |
+ |
+} // namespace |
+ |
+// TODO(magjed): The default implementations in VideoFrameBuffer are provided in |
+// order to support the deprecated interface until external clients are updated. |
+// Remove once done. |
+VideoFrameBuffer::PixelFormat VideoFrameBuffer::Format() const { |
+ return native_handle() ? PixelFormat::kNative : PixelFormat::kI420; |
+} |
+ |
+const uint8_t* VideoFrameBuffer::DataY() const { |
+ return const_cast<VideoFrameBuffer*>(this)->ToI420()->DataY(); |
nisse-webrtc
2017/05/04 08:15:29
This is more forgiving in the native_handle case t
magjed_webrtc
2017/05/04 12:25:13
Done. Just to clarify, these functions will soon b
|
+} |
+ |
+const uint8_t* VideoFrameBuffer::DataU() const { |
+ return const_cast<VideoFrameBuffer*>(this)->ToI420()->DataU(); |
+} |
+ |
+const uint8_t* VideoFrameBuffer::DataV() const { |
+ return const_cast<VideoFrameBuffer*>(this)->ToI420()->DataV(); |
+} |
+ |
+// Returns the number of bytes between successive rows for a given plane. |
+int VideoFrameBuffer::StrideY() const { |
+ return const_cast<VideoFrameBuffer*>(this)->ToI420()->StrideY(); |
+} |
+ |
+int VideoFrameBuffer::StrideU() const { |
+ return const_cast<VideoFrameBuffer*>(this)->ToI420()->StrideU(); |
+} |
+ |
+int VideoFrameBuffer::StrideV() const { |
+ return const_cast<VideoFrameBuffer*>(this)->ToI420()->StrideV(); |
+} |
+ |
+void* VideoFrameBuffer::native_handle() const { |
+ RTC_DCHECK(Format() != PixelFormat::kNative); |
+ return nullptr; |
+} |
+ |
+rtc::scoped_refptr<VideoFrameBuffer> VideoFrameBuffer::NativeToI420Buffer() { |
+ return ToI420(); |
+} |
+ |
+rtc::scoped_refptr<PlanarYuvBuffer> VideoFrameBuffer::ToI420() { |
+ return new rtc::RefCountedObject<LegacyI420Wrapper>(NativeToI420Buffer()); |
+} |
+ |
+rtc::scoped_refptr<PlanarYuvBuffer> VideoFrameBuffer::GetI420() { |
+ RTC_NOTREACHED(); |
nisse-webrtc
2017/05/05 12:45:28
Wouldn't we need a working default implementation
magjed_webrtc
2017/05/06 19:01:45
Yes, done. When I think about, these GetXXX functi
nisse-webrtc
2017/05/08 06:43:10
I still think it might make sense to have GetFoo b
|
+ return nullptr; |
+} |
+ |
+rtc::scoped_refptr<PlanarYuvBuffer> VideoFrameBuffer::GetI444() { |
+ RTC_NOTREACHED(); |
+ return nullptr; |
+} |
+ |
+rtc::scoped_refptr<PlanarYuvBuffer> PlanarYuvBuffer::ToI420() { |
+ rtc::scoped_refptr<I420Buffer> i420_buffer; |
nisse-webrtc
2017/05/05 11:33:04
Merge declaration with below assignment?
magjed_webrtc
2017/05/05 12:25:24
Not allowed to have declarations inside switch-sta
nisse-webrtc
2017/05/05 12:45:29
So you'd need to add a pair of braces to declare v
magjed_webrtc
2017/05/06 19:01:45
Thanks, I didn't know about this. Done.
nisse-webrtc
2017/05/08 06:43:10
I guess the reason you can't have declarations in
|
+ switch (Format()) { |
+ case PixelFormat::kI420: |
+ return this; |
+ case PixelFormat::kI444: |
+ i420_buffer = I420Buffer::Create(width(), height()); |
+ libyuv::I420ToI444(DataY(), StrideY(), DataU(), StrideU(), DataV(), |
+ StrideV(), i420_buffer->MutableDataY(), |
+ i420_buffer->StrideY(), i420_buffer->MutableDataU(), |
+ i420_buffer->StrideU(), i420_buffer->MutableDataV(), |
+ i420_buffer->StrideV(), width(), height()); |
+ return i420_buffer; |
+ default: |
+ RTC_NOTREACHED(); |
+ return nullptr; |
+ } |
+} |
+ |
+rtc::scoped_refptr<PlanarYuvBuffer> PlanarYuvBuffer::GetI420() { |
+ RTC_DCHECK(Format() == PixelFormat::kI420); |
+ return this; |
+} |
+ |
+rtc::scoped_refptr<PlanarYuvBuffer> PlanarYuvBuffer::GetI444() { |
+ RTC_DCHECK(Format() == PixelFormat::kI444); |
+ return this; |
+} |
+ |
+} // namespace webrtc |