Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (c) 2017 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2017 The WebRTC project authors. All Rights Reserved. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license | 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 | 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 | 6 * tree. An additional intellectual property rights grant can be found |
| 7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
| 8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
| 9 */ | 9 */ |
| 10 | 10 |
| 11 #include "webrtc/api/video/video_frame_buffer.h" | 11 #include "webrtc/api/video/video_frame_buffer.h" |
| 12 | 12 |
| 13 #include "libyuv/convert_from.h" | 13 #include "libyuv/convert.h" |
| 14 #include "webrtc/api/video/i420_buffer.h" | 14 #include "webrtc/api/video/i420_buffer.h" |
| 15 #include "webrtc/base/checks.h" | 15 #include "webrtc/base/checks.h" |
| 16 | 16 |
| 17 namespace webrtc { | 17 namespace webrtc { |
| 18 | 18 |
| 19 namespace { | 19 namespace { |
| 20 | 20 |
| 21 // TODO(magjed): Remove this class. It is only used for providing a default | 21 // TODO(magjed): Remove this class. It is only used for providing a default |
| 22 // implementation of ToI420() until external clients are updated. ToI420() will | 22 // implementation of ToI420() until external clients are updated. ToI420() will |
| 23 // then be made pure virtual. This adapter adapts a VideoFrameBuffer (which is | 23 // then be made pure virtual. This adapter adapts a VideoFrameBuffer (which is |
| 24 // expected to be in I420 format) to the PlanarYuvBuffer interface. The reason | 24 // expected to be in I420 format) to I420BufferInterface. The reason this is |
| 25 // this is needed is because of the return type mismatch in NativeToI420Buffer | 25 // needed is because of the return type mismatch in NativeToI420Buffer (returns |
| 26 // (returns VideoFrameBuffer) vs ToI420 (returns PlanarYuvBuffer). | 26 // VideoFrameBuffer) vs ToI420 (returns I420BufferInterface). |
| 27 class PlanarYuvBufferAdapter : public PlanarYuvBuffer { | 27 class I420InterfaceAdapter : public I420BufferInterface { |
| 28 public: | 28 public: |
| 29 explicit PlanarYuvBufferAdapter(rtc::scoped_refptr<VideoFrameBuffer> buffer) | 29 explicit I420InterfaceAdapter(rtc::scoped_refptr<VideoFrameBuffer> buffer) |
| 30 : buffer_(buffer) {} | 30 : buffer_(buffer) {} |
| 31 | 31 |
| 32 Type type() const override { return Type::kI420; } | |
| 33 | |
| 34 int width() const override { return buffer_->width(); } | 32 int width() const override { return buffer_->width(); } |
| 35 int height() const override { return buffer_->height(); } | 33 int height() const override { return buffer_->height(); } |
| 36 | 34 |
| 37 const uint8_t* DataY() const override { return buffer_->DataY(); } | 35 const uint8_t* DataY() const override { return buffer_->DataY(); } |
| 38 const uint8_t* DataU() const override { return buffer_->DataU(); } | 36 const uint8_t* DataU() const override { return buffer_->DataU(); } |
| 39 const uint8_t* DataV() const override { return buffer_->DataV(); } | 37 const uint8_t* DataV() const override { return buffer_->DataV(); } |
| 40 | 38 |
| 41 int StrideY() const override { return buffer_->StrideY(); } | 39 int StrideY() const override { return buffer_->StrideY(); } |
| 42 int StrideU() const override { return buffer_->StrideU(); } | 40 int StrideU() const override { return buffer_->StrideU(); } |
| 43 int StrideV() const override { return buffer_->StrideV(); } | 41 int StrideV() const override { return buffer_->StrideV(); } |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 82 | 80 |
| 83 void* VideoFrameBuffer::native_handle() const { | 81 void* VideoFrameBuffer::native_handle() const { |
| 84 RTC_DCHECK(type() != Type::kNative); | 82 RTC_DCHECK(type() != Type::kNative); |
| 85 return nullptr; | 83 return nullptr; |
| 86 } | 84 } |
| 87 | 85 |
| 88 rtc::scoped_refptr<VideoFrameBuffer> VideoFrameBuffer::NativeToI420Buffer() { | 86 rtc::scoped_refptr<VideoFrameBuffer> VideoFrameBuffer::NativeToI420Buffer() { |
| 89 return ToI420(); | 87 return ToI420(); |
| 90 } | 88 } |
| 91 | 89 |
| 92 rtc::scoped_refptr<PlanarYuvBuffer> VideoFrameBuffer::ToI420() { | 90 rtc::scoped_refptr<I420BufferInterface> VideoFrameBuffer::ToI420() { |
| 93 return new rtc::RefCountedObject<PlanarYuvBufferAdapter>( | 91 return new rtc::RefCountedObject<I420InterfaceAdapter>(NativeToI420Buffer()); |
| 94 NativeToI420Buffer()); | |
| 95 } | 92 } |
| 96 | 93 |
| 97 rtc::scoped_refptr<PlanarYuvBuffer> VideoFrameBuffer::GetI420() { | 94 rtc::scoped_refptr<I420BufferInterface> VideoFrameBuffer::GetI420() { |
|
nisse-webrtc
2017/05/29 14:20:05
I think this default implementation can be deleted
| |
| 98 RTC_CHECK(type() == Type::kI420); | 95 RTC_CHECK(type() == Type::kI420); |
| 99 // TODO(magjed): static_cast to PlanarYuvBuffer instead once external clients | 96 // TODO(magjed): static_cast to I420BufferInterface instead once external |
| 100 // are updated. | 97 // clients are updated. |
| 101 return new rtc::RefCountedObject<PlanarYuvBufferAdapter>(this); | 98 return new rtc::RefCountedObject<I420InterfaceAdapter>(this); |
| 102 } | 99 } |
| 103 | 100 |
| 104 rtc::scoped_refptr<PlanarYuvBuffer> VideoFrameBuffer::GetI444() { | 101 rtc::scoped_refptr<I444BufferInterface> VideoFrameBuffer::GetI444() { |
| 105 RTC_CHECK(type() == Type::kI444); | 102 RTC_CHECK(type() == Type::kI444); |
| 106 return static_cast<PlanarYuvBuffer*>(this); | 103 return static_cast<I444BufferInterface*>(this); |
| 107 } | 104 } |
| 108 | 105 |
| 109 rtc::scoped_refptr<PlanarYuvBuffer> PlanarYuvBuffer::ToI420() { | 106 VideoFrameBuffer::Type I420BufferInterface::type() const { |
| 110 switch (type()) { | 107 return Type::kI420; |
| 111 case Type::kI420: | |
| 112 return this; | |
| 113 case Type::kI444: { | |
| 114 rtc::scoped_refptr<I420Buffer> i420_buffer = | |
| 115 I420Buffer::Create(width(), height()); | |
| 116 libyuv::I420ToI444(DataY(), StrideY(), DataU(), StrideU(), DataV(), | |
| 117 StrideV(), i420_buffer->MutableDataY(), | |
| 118 i420_buffer->StrideY(), i420_buffer->MutableDataU(), | |
| 119 i420_buffer->StrideU(), i420_buffer->MutableDataV(), | |
| 120 i420_buffer->StrideV(), width(), height()); | |
| 121 return i420_buffer; | |
| 122 } | |
| 123 default: | |
| 124 RTC_NOTREACHED(); | |
| 125 return nullptr; | |
| 126 } | |
| 127 } | 108 } |
| 128 | 109 |
| 129 int PlanarYuvBuffer::ChromaWidth() const { | 110 int I420BufferInterface::ChromaWidth() const { |
| 130 switch (type()) { | 111 return (width() + 1) / 2; |
| 131 case Type::kI420: | |
| 132 return (width() + 1) / 2; | |
| 133 case Type::kI444: | |
| 134 return width(); | |
| 135 default: | |
| 136 RTC_NOTREACHED(); | |
| 137 return 0; | |
| 138 } | |
| 139 } | 112 } |
| 140 | 113 |
| 141 int PlanarYuvBuffer::ChromaHeight() const { | 114 int I420BufferInterface::ChromaHeight() const { |
| 142 switch (type()) { | 115 return (height() + 1) / 2; |
| 143 case Type::kI420: | 116 } |
| 144 return (height() + 1) / 2; | 117 |
| 145 case Type::kI444: | 118 rtc::scoped_refptr<I420BufferInterface> I420BufferInterface::ToI420() { |
| 146 return height(); | 119 return this; |
| 147 default: | 120 } |
| 148 RTC_NOTREACHED(); | 121 |
| 149 return 0; | 122 VideoFrameBuffer::Type I444BufferInterface::type() const { |
| 150 } | 123 return Type::kI444; |
| 124 } | |
| 125 | |
| 126 int I444BufferInterface::ChromaWidth() const { | |
| 127 return width(); | |
| 128 } | |
| 129 | |
| 130 int I444BufferInterface::ChromaHeight() const { | |
| 131 return height(); | |
| 132 } | |
| 133 | |
| 134 rtc::scoped_refptr<I420BufferInterface> I444BufferInterface::ToI420() { | |
| 135 rtc::scoped_refptr<I420Buffer> i420_buffer = | |
| 136 I420Buffer::Create(width(), height()); | |
| 137 libyuv::I444ToI420(DataY(), StrideY(), DataU(), StrideU(), DataV(), StrideV(), | |
| 138 i420_buffer->MutableDataY(), i420_buffer->StrideY(), | |
| 139 i420_buffer->MutableDataU(), i420_buffer->StrideU(), | |
| 140 i420_buffer->MutableDataV(), i420_buffer->StrideV(), | |
| 141 width(), height()); | |
| 142 return i420_buffer; | |
| 151 } | 143 } |
| 152 | 144 |
| 153 } // namespace webrtc | 145 } // namespace webrtc |
| OLD | NEW |