Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(722)

Side by Side Diff: webrtc/api/video/video_frame_buffer.cc

Issue 2847383002: Add support for multiple pixel formats in VideoFrameBuffer (Closed)
Patch Set: Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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.
23 class LegacyI420Wrapper : public I420BufferInterface {
24 public:
25 explicit LegacyI420Wrapper(rtc::scoped_refptr<VideoFrameBuffer> buffer)
26 : buffer_(buffer) {}
27
28 int width() const override { return buffer_->width(); }
29 int height() const override { return buffer_->height(); }
30
31 const uint8_t* DataY() const override { return buffer_->DataY(); }
32 const uint8_t* DataU() const override { return buffer_->DataU(); }
33 const uint8_t* DataV() const override { return buffer_->DataV(); }
34
35 int StrideY() const override { return buffer_->StrideY(); }
36 int StrideU() const override { return buffer_->StrideU(); }
37 int StrideV() const override { return buffer_->StrideV(); }
38
39 private:
40 rtc::scoped_refptr<VideoFrameBuffer> buffer_;
41 };
42
43 } // namespace
44
45 // TODO(magjed): The default implementations in VideoFrameBuffer are provided in
46 // order to support the deprecated interface until external clients are updated.
47 // Remove once done.
48 VideoFrameBuffer::PixelFormat VideoFrameBuffer::Format() const {
49 return native_handle() ? PixelFormat::kNative : PixelFormat::kI420;
50 }
51
52 const uint8_t* VideoFrameBuffer::DataY() const {
53 return const_cast<VideoFrameBuffer*>(this)->ToI420()->DataY();
54 }
55
56 const uint8_t* VideoFrameBuffer::DataU() const {
57 return const_cast<VideoFrameBuffer*>(this)->ToI420()->DataU();
58 }
59
60 const uint8_t* VideoFrameBuffer::DataV() const {
61 return const_cast<VideoFrameBuffer*>(this)->ToI420()->DataV();
62 }
63
64 // Returns the number of bytes between successive rows for a given plane.
65 int VideoFrameBuffer::StrideY() const {
66 return const_cast<VideoFrameBuffer*>(this)->ToI420()->StrideY();
67 }
68
69 int VideoFrameBuffer::StrideU() const {
70 return const_cast<VideoFrameBuffer*>(this)->ToI420()->StrideU();
71 }
72
73 int VideoFrameBuffer::StrideV() const {
74 return const_cast<VideoFrameBuffer*>(this)->ToI420()->StrideV();
75 }
76
77 void* VideoFrameBuffer::native_handle() const {
78 RTC_DCHECK(Format() != PixelFormat::kNative);
79 return nullptr;
80 }
81
82 rtc::scoped_refptr<VideoFrameBuffer> VideoFrameBuffer::NativeToI420Buffer() {
83 return ToI420();
84 }
85
86 rtc::scoped_refptr<I420BufferInterface> VideoFrameBuffer::ToI420() {
87 return new rtc::RefCountedObject<LegacyI420Wrapper>(NativeToI420Buffer());
88 }
89
90 rtc::scoped_refptr<I444BufferInterface> VideoFrameBuffer::ToI444() {
91 RTC_NOTREACHED();
92 return nullptr;
93 }
94
95 VideoFrameBuffer::PixelFormat I420BufferInterface::Format() const {
96 return PixelFormat::kI420;
97 }
98
99 rtc::scoped_refptr<I420BufferInterface> I420BufferInterface::ToI420() {
100 return this;
101 }
102
103 VideoFrameBuffer::PixelFormat I444BufferInterface::Format() const {
104 return PixelFormat::kI444;
105 }
106
107 rtc::scoped_refptr<I420BufferInterface> I444BufferInterface::ToI420() {
108 rtc::scoped_refptr<I420Buffer> i420_buffer =
109 I420Buffer::Create(width(), height());
110 libyuv::I420ToI444(
111 DataY(), StrideY(),
112 DataU(), StrideU(),
113 DataV(), StrideV(),
114 i420_buffer->MutableDataY(), i420_buffer->StrideY(),
115 i420_buffer->MutableDataU(), i420_buffer->StrideU(),
116 i420_buffer->MutableDataV(), i420_buffer->StrideV(),
117 width(), height());
118 return i420_buffer;
119 }
120
121 rtc::scoped_refptr<I444BufferInterface> I444BufferInterface::ToI444() {
122 return this;
123 }
124
125 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698