OLD | NEW |
---|---|
(Empty) | |
1 /* | |
2 * Copyright (c) 2017 The WebRTC project authors. All Rights Reserved. | |
3 * | |
4 * Use of this source code is governed by a BSD-style license | |
5 * that can be found in the LICENSE file in the root of the source | |
6 * tree. An additional intellectual property rights grant can be found | |
7 * in the file PATENTS. All contributing project authors may | |
8 * be found in the AUTHORS file in the root of the source tree. | |
9 */ | |
10 | |
11 #include "webrtc/api/video/video_frame_buffer.h" | |
12 | |
13 #include "libyuv/convert_from.h" | |
14 #include "webrtc/api/video/i420_buffer.h" | |
15 #include "webrtc/base/checks.h" | |
16 | |
17 namespace webrtc { | |
18 | |
19 namespace { | |
20 | |
21 // Class for handling legacy implementations of NativeToI420Buffer() and | |
22 // 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
| |
23 class LegacyI420Wrapper : public PlanarYuvBuffer { | |
24 public: | |
25 explicit LegacyI420Wrapper(rtc::scoped_refptr<VideoFrameBuffer> buffer) | |
26 : buffer_(buffer) {} | |
27 | |
28 PixelFormat Format() const override { return PixelFormat::kI420; } | |
29 | |
30 int width() const override { return buffer_->width(); } | |
31 int height() const override { return buffer_->height(); } | |
32 | |
33 const uint8_t* DataY() const override { return buffer_->DataY(); } | |
34 const uint8_t* DataU() const override { return buffer_->DataU(); } | |
35 const uint8_t* DataV() const override { return buffer_->DataV(); } | |
36 | |
37 int StrideY() const override { return buffer_->StrideY(); } | |
38 int StrideU() const override { return buffer_->StrideU(); } | |
39 int StrideV() const override { return buffer_->StrideV(); } | |
40 | |
41 private: | |
42 rtc::scoped_refptr<VideoFrameBuffer> buffer_; | |
43 }; | |
44 | |
45 } // namespace | |
46 | |
47 // TODO(magjed): The default implementations in VideoFrameBuffer are provided in | |
48 // order to support the deprecated interface until external clients are updated. | |
49 // Remove once done. | |
50 VideoFrameBuffer::PixelFormat VideoFrameBuffer::Format() const { | |
51 return native_handle() ? PixelFormat::kNative : PixelFormat::kI420; | |
52 } | |
53 | |
54 const uint8_t* VideoFrameBuffer::DataY() const { | |
55 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
| |
56 } | |
57 | |
58 const uint8_t* VideoFrameBuffer::DataU() const { | |
59 return const_cast<VideoFrameBuffer*>(this)->ToI420()->DataU(); | |
60 } | |
61 | |
62 const uint8_t* VideoFrameBuffer::DataV() const { | |
63 return const_cast<VideoFrameBuffer*>(this)->ToI420()->DataV(); | |
64 } | |
65 | |
66 // Returns the number of bytes between successive rows for a given plane. | |
67 int VideoFrameBuffer::StrideY() const { | |
68 return const_cast<VideoFrameBuffer*>(this)->ToI420()->StrideY(); | |
69 } | |
70 | |
71 int VideoFrameBuffer::StrideU() const { | |
72 return const_cast<VideoFrameBuffer*>(this)->ToI420()->StrideU(); | |
73 } | |
74 | |
75 int VideoFrameBuffer::StrideV() const { | |
76 return const_cast<VideoFrameBuffer*>(this)->ToI420()->StrideV(); | |
77 } | |
78 | |
79 void* VideoFrameBuffer::native_handle() const { | |
80 RTC_DCHECK(Format() != PixelFormat::kNative); | |
81 return nullptr; | |
82 } | |
83 | |
84 rtc::scoped_refptr<VideoFrameBuffer> VideoFrameBuffer::NativeToI420Buffer() { | |
85 return ToI420(); | |
86 } | |
87 | |
88 rtc::scoped_refptr<PlanarYuvBuffer> VideoFrameBuffer::ToI420() { | |
89 return new rtc::RefCountedObject<LegacyI420Wrapper>(NativeToI420Buffer()); | |
90 } | |
91 | |
92 rtc::scoped_refptr<PlanarYuvBuffer> VideoFrameBuffer::GetI420() { | |
93 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
| |
94 return nullptr; | |
95 } | |
96 | |
97 rtc::scoped_refptr<PlanarYuvBuffer> VideoFrameBuffer::GetI444() { | |
98 RTC_NOTREACHED(); | |
99 return nullptr; | |
100 } | |
101 | |
102 rtc::scoped_refptr<PlanarYuvBuffer> PlanarYuvBuffer::ToI420() { | |
103 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
| |
104 switch (Format()) { | |
105 case PixelFormat::kI420: | |
106 return this; | |
107 case PixelFormat::kI444: | |
108 i420_buffer = I420Buffer::Create(width(), height()); | |
109 libyuv::I420ToI444(DataY(), StrideY(), DataU(), StrideU(), DataV(), | |
110 StrideV(), i420_buffer->MutableDataY(), | |
111 i420_buffer->StrideY(), i420_buffer->MutableDataU(), | |
112 i420_buffer->StrideU(), i420_buffer->MutableDataV(), | |
113 i420_buffer->StrideV(), width(), height()); | |
114 return i420_buffer; | |
115 default: | |
116 RTC_NOTREACHED(); | |
117 return nullptr; | |
118 } | |
119 } | |
120 | |
121 rtc::scoped_refptr<PlanarYuvBuffer> PlanarYuvBuffer::GetI420() { | |
122 RTC_DCHECK(Format() == PixelFormat::kI420); | |
123 return this; | |
124 } | |
125 | |
126 rtc::scoped_refptr<PlanarYuvBuffer> PlanarYuvBuffer::GetI444() { | |
127 RTC_DCHECK(Format() == PixelFormat::kI444); | |
128 return this; | |
129 } | |
130 | |
131 } // namespace webrtc | |
OLD | NEW |