From af916899cc8ec685ebeaf414d5aa86ca83e1fca6 Mon Sep 17 00:00:00 2001 From: nisse Date: Tue, 10 Jan 2017 07:44:26 -0800 Subject: [PATCH] Move VideoFrame and related declarations to webrtc/api/video. Moves webrtc/common_video/rotation.h and parts of webrtc/common_video/include/video_frame_buffer.h and webrtc/video_frame.h, and adds to a new GN target api:video_frame_api. BUG=webrtc:5880 Review-Url: https://codereview.webrtc.org/2517173004 Cr-Commit-Position: refs/heads/master@{#15993} --- webrtc/DEPS | 1 - webrtc/api/BUILD.gn | 6 + webrtc/api/mediastreaminterface.h | 6 +- webrtc/api/video/i420_buffer.cc | 260 ++++++++++++++++++ webrtc/api/video/i420_buffer.h | 116 ++++++++ webrtc/api/video/video_frame.cc | 66 +++++ webrtc/api/video/video_frame.h | 119 ++++++++ webrtc/api/video/video_frame_buffer.h | 55 ++++ webrtc/common_types.h | 2 +- webrtc/common_video/BUILD.gn | 7 +- .../common_video/i420_video_frame_unittest.cc | 21 +- .../include/corevideo_frame_buffer.h | 1 - .../common_video/include/i420_buffer_pool.h | 2 +- .../common_video/include/video_frame_buffer.h | 126 +-------- .../libyuv/include/webrtc_libyuv.h | 12 +- webrtc/common_video/libyuv/libyuv_unittest.cc | 3 +- webrtc/common_video/libyuv/webrtc_libyuv.cc | 4 +- webrtc/common_video/rotation.h | 14 +- webrtc/common_video/video_frame.cc | 33 --- webrtc/common_video/video_frame_buffer.cc | 230 ---------------- webrtc/common_video/video_render_frames.h | 2 +- .../peerconnection/client/linux/main_wnd.cc | 8 +- .../peerconnection/client/main_wnd.cc | 7 +- .../examples/peerconnection/client/main_wnd.h | 2 +- webrtc/media/base/adaptedvideotracksource.cc | 4 +- webrtc/media/base/fakevideocapturer.h | 3 +- webrtc/media/base/fakevideorenderer.h | 2 +- webrtc/media/base/testutils.cc | 2 +- webrtc/media/base/videobroadcaster.cc | 5 +- webrtc/media/base/videobroadcaster.h | 2 +- .../media/base/videobroadcaster_unittest.cc | 7 +- webrtc/media/base/videocapturer.cc | 5 +- webrtc/media/base/videocapturer.h | 6 + webrtc/media/base/videoframe.h | 2 +- webrtc/media/base/videosourcebase.h | 2 +- webrtc/media/devices/gtkvideorenderer.cc | 9 +- webrtc/media/engine/fakewebrtccall.h | 2 +- .../engine/fakewebrtcvideocapturemodule.h | 3 +- ...encodersoftwarefallbackwrapper_unittest.cc | 3 +- webrtc/media/engine/webrtcvideoengine2.cc | 3 +- webrtc/media/engine/webrtcvideoengine2.h | 2 +- .../engine/webrtcvideoengine2_unittest.cc | 2 +- webrtc/modules/include/module_common_types.h | 2 +- webrtc/modules/rtp_rtcp/include/rtp_cvo.h | 2 +- .../rtp_rtcp/source/rtp_header_extensions.h | 2 +- .../test/video_capture_unittest.cc | 3 +- webrtc/modules/video_capture/video_capture.h | 2 +- .../video_capture/video_capture_defines.h | 2 +- .../video_capture/video_capture_impl.cc | 1 + .../video_capture/video_capture_impl.h | 3 +- .../codecs/h264/h264_decoder_impl.cc | 2 + .../modules/video_coding/codecs/i420/i420.cc | 1 + .../codecs/interface/video_codec_interface.h | 2 +- .../codecs/test/videoprocessor.cc | 1 + .../video_coding/codecs/test/videoprocessor.h | 2 +- .../codecs/test/videoprocessor_unittest.cc | 1 + .../codecs/vp8/simulcast_encoder_adapter.cc | 1 + .../vp8/simulcast_encoder_adapter_unittest.cc | 2 + .../codecs/vp8/simulcast_unittest.h | 2 + .../codecs/vp8/test/vp8_impl_unittest.cc | 1 + .../video_coding/codecs/vp8/vp8_impl.h | 1 + .../codecs/vp8/vp8_sequence_coder.cc | 1 + .../video_coding/codecs/vp9/vp9_impl.cc | 1 + .../modules/video_coding/generic_encoder.cc | 1 + .../include/video_codec_interface.h | 2 +- .../video_coding/include/video_coding.h | 2 +- .../include/video_coding_defines.h | 2 + .../video_coding/video_sender_unittest.cc | 1 + .../sdk/android/src/jni/native_handle_impl.h | 2 +- .../src/jni/surfacetexturehelper_jni.h | 2 +- .../objc/Framework/Classes/RTCI420Shader.mm | 2 +- .../Framework/Classes/RTCNativeNV12Shader.mm | 2 +- .../Framework/Classes/RTCShader+Private.h | 2 +- .../Framework/Classes/RTCVideoFrame+Private.h | 4 +- .../objc/Framework/Classes/RTCVideoFrame.mm | 2 +- .../Classes/avfoundationvideocapturer.h | 2 +- .../Classes/avfoundationvideocapturer.mm | 25 +- .../Classes/h264_video_toolbox_decoder.cc | 1 + .../Classes/h264_video_toolbox_encoder.h | 2 +- webrtc/test/fake_decoder.cc | 2 + webrtc/test/fake_texture_frame.h | 8 +- webrtc/test/fake_videorenderer.h | 2 +- webrtc/test/frame_generator.cc | 2 + webrtc/test/frame_generator.h | 2 +- webrtc/test/frame_generator_capturer.h | 3 +- webrtc/test/frame_utils.cc | 6 +- webrtc/test/testsupport/frame_reader.cc | 2 +- .../test/testsupport/frame_reader_unittest.cc | 2 +- .../test/testsupport/metrics/video_metrics.cc | 3 +- webrtc/test/video_capturer.h | 2 +- webrtc/video/overuse_frame_detector.cc | 2 +- .../video/overuse_frame_detector_unittest.cc | 1 + webrtc/video/vie_encoder.h | 2 +- webrtc/video/vie_encoder_unittest.cc | 1 + webrtc/video_frame.h | 114 +------- 95 files changed, 803 insertions(+), 607 deletions(-) create mode 100644 webrtc/api/video/i420_buffer.cc create mode 100644 webrtc/api/video/i420_buffer.h create mode 100644 webrtc/api/video/video_frame.cc create mode 100644 webrtc/api/video/video_frame.h create mode 100644 webrtc/api/video/video_frame_buffer.h diff --git a/webrtc/DEPS b/webrtc/DEPS index 16589362e2..36a5b738db 100644 --- a/webrtc/DEPS +++ b/webrtc/DEPS @@ -11,7 +11,6 @@ include_rules = [ # Individual headers that will be moved out of here, see webrtc:4243. "+webrtc/call.h", "+webrtc/common_types.h", - "+webrtc/common_video/rotation.h", "+webrtc/config.h", "+webrtc/transport.h", "+webrtc/typedefs.h", diff --git a/webrtc/api/BUILD.gn b/webrtc/api/BUILD.gn index 7fbcb5dab2..7c5e302d65 100644 --- a/webrtc/api/BUILD.gn +++ b/webrtc/api/BUILD.gn @@ -177,11 +177,17 @@ rtc_source_set("transport_api") { rtc_source_set("video_frame_api") { sources = [ + "video/i420_buffer.cc", + "video/i420_buffer.h", + "video/video_frame.cc", + "video/video_frame.h", + "video/video_frame_buffer.h", "video/video_rotation.h", ] deps = [ "../base:rtc_base_approved", + "../system_wrappers", ] # TODO(nisse): This logic is duplicated in multiple places. diff --git a/webrtc/api/mediastreaminterface.h b/webrtc/api/mediastreaminterface.h index d7493a7d29..693e5d00f0 100644 --- a/webrtc/api/mediastreaminterface.h +++ b/webrtc/api/mediastreaminterface.h @@ -22,13 +22,17 @@ #include #include +#include "webrtc/api/video/video_frame.h" +// TODO(nisse): Transition hack, Chrome expects that including this +// file declares I420Buffer. Delete after users of I420Buffer are +// fixed to include the new header. +#include "webrtc/api/video/i420_buffer.h" #include "webrtc/base/refcount.h" #include "webrtc/base/scoped_ref_ptr.h" #include "webrtc/base/optional.h" #include "webrtc/media/base/mediachannel.h" #include "webrtc/media/base/videosinkinterface.h" #include "webrtc/media/base/videosourceinterface.h" -#include "webrtc/video_frame.h" namespace webrtc { diff --git a/webrtc/api/video/i420_buffer.cc b/webrtc/api/video/i420_buffer.cc new file mode 100644 index 0000000000..031b15940a --- /dev/null +++ b/webrtc/api/video/i420_buffer.cc @@ -0,0 +1,260 @@ +/* + * Copyright (c) 2015 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/i420_buffer.h" + +#include + +#include +#include + +#include "webrtc/base/checks.h" +#include "webrtc/base/keep_ref_until_done.h" +#include "libyuv/convert.h" +#include "libyuv/planar_functions.h" +#include "libyuv/scale.h" + +// Aligning pointer to 64 bytes for improved performance, e.g. use SIMD. +static const int kBufferAlignment = 64; + +namespace webrtc { + +namespace { + +int I420DataSize(int height, int stride_y, int stride_u, int stride_v) { + return stride_y * height + (stride_u + stride_v) * ((height + 1) / 2); +} + +} // namespace + +I420Buffer::I420Buffer(int width, int height) + : I420Buffer(width, height, width, (width + 1) / 2, (width + 1) / 2) { +} + +I420Buffer::I420Buffer(int width, + int height, + int stride_y, + int stride_u, + int stride_v) + : width_(width), + height_(height), + stride_y_(stride_y), + stride_u_(stride_u), + stride_v_(stride_v), + data_(static_cast(AlignedMalloc( + I420DataSize(height, stride_y, stride_u, stride_v), + kBufferAlignment))) { + RTC_DCHECK_GT(width, 0); + RTC_DCHECK_GT(height, 0); + RTC_DCHECK_GE(stride_y, width); + RTC_DCHECK_GE(stride_u, (width + 1) / 2); + RTC_DCHECK_GE(stride_v, (width + 1) / 2); +} + +I420Buffer::~I420Buffer() { +} + +// static +rtc::scoped_refptr I420Buffer::Create(int width, int height) { + return new rtc::RefCountedObject(width, height); +} + +// static +rtc::scoped_refptr I420Buffer::Create(int width, + int height, + int stride_y, + int stride_u, + int stride_v) { + return new rtc::RefCountedObject( + width, height, stride_y, stride_u, stride_v); +} + +// static +rtc::scoped_refptr I420Buffer::Copy( + const VideoFrameBuffer& source) { + return Copy(source.width(), source.height(), + source.DataY(), source.StrideY(), + source.DataU(), source.StrideU(), + source.DataV(), source.StrideV()); +} + +// static +rtc::scoped_refptr I420Buffer::Copy( + int width, int height, + const uint8_t* data_y, int stride_y, + const uint8_t* data_u, int stride_u, + const uint8_t* data_v, int stride_v) { + // Note: May use different strides than the input data. + rtc::scoped_refptr buffer = Create(width, height); + RTC_CHECK_EQ(0, libyuv::I420Copy(data_y, stride_y, + data_u, stride_u, + data_v, stride_v, + buffer->MutableDataY(), buffer->StrideY(), + buffer->MutableDataU(), buffer->StrideU(), + buffer->MutableDataV(), buffer->StrideV(), + width, height)); + return buffer; +} + +// static +rtc::scoped_refptr I420Buffer::Rotate( + const VideoFrameBuffer& src, VideoRotation rotation) { + RTC_CHECK(src.DataY()); + RTC_CHECK(src.DataU()); + RTC_CHECK(src.DataV()); + + int rotated_width = src.width(); + int rotated_height = src.height(); + if (rotation == webrtc::kVideoRotation_90 || + rotation == webrtc::kVideoRotation_270) { + std::swap(rotated_width, rotated_height); + } + + rtc::scoped_refptr buffer = + I420Buffer::Create(rotated_width, rotated_height); + + RTC_CHECK_EQ(0, libyuv::I420Rotate( + src.DataY(), src.StrideY(), + src.DataU(), src.StrideU(), + src.DataV(), src.StrideV(), + buffer->MutableDataY(), buffer->StrideY(), buffer->MutableDataU(), + buffer->StrideU(), buffer->MutableDataV(), buffer->StrideV(), + src.width(), src.height(), + static_cast(rotation))); + + return buffer; +} + +// static +rtc::scoped_refptr I420Buffer::Rotate( + rtc::scoped_refptr src, + VideoRotation rotation) { + if (rotation == webrtc::kVideoRotation_0) { + return src; + } else { + return Rotate(*src, rotation); + } +} + +void I420Buffer::InitializeData() { + memset(data_.get(), 0, + I420DataSize(height_, stride_y_, stride_u_, stride_v_)); +} + +int I420Buffer::width() const { + return width_; +} + +int I420Buffer::height() const { + return height_; +} + +const uint8_t* I420Buffer::DataY() const { + return data_.get(); +} +const uint8_t* I420Buffer::DataU() const { + return data_.get() + stride_y_ * height_; +} +const uint8_t* I420Buffer::DataV() const { + return data_.get() + stride_y_ * height_ + stride_u_ * ((height_ + 1) / 2); +} + +int I420Buffer::StrideY() const { + return stride_y_; +} +int I420Buffer::StrideU() const { + return stride_u_; +} +int I420Buffer::StrideV() const { + return stride_v_; +} + +void* I420Buffer::native_handle() const { + return nullptr; +} + +rtc::scoped_refptr I420Buffer::NativeToI420Buffer() { + RTC_NOTREACHED(); + return nullptr; +} + +uint8_t* I420Buffer::MutableDataY() { + return const_cast(DataY()); +} +uint8_t* I420Buffer::MutableDataU() { + return const_cast(DataU()); +} +uint8_t* I420Buffer::MutableDataV() { + return const_cast(DataV()); +} + +// static +void I420Buffer::SetBlack(I420Buffer* buffer) { + RTC_CHECK(libyuv::I420Rect(buffer->MutableDataY(), buffer->StrideY(), + buffer->MutableDataU(), buffer->StrideU(), + buffer->MutableDataV(), buffer->StrideV(), + 0, 0, buffer->width(), buffer->height(), + 0, 128, 128) == 0); +} + +void I420Buffer::CropAndScaleFrom( + const VideoFrameBuffer& src, + int offset_x, + int offset_y, + int crop_width, + int crop_height) { + RTC_CHECK_LE(crop_width, src.width()); + RTC_CHECK_LE(crop_height, src.height()); + RTC_CHECK_LE(crop_width + offset_x, src.width()); + RTC_CHECK_LE(crop_height + offset_y, src.height()); + RTC_CHECK_GE(offset_x, 0); + RTC_CHECK_GE(offset_y, 0); + + // Make sure offset is even so that u/v plane becomes aligned. + const int uv_offset_x = offset_x / 2; + const int uv_offset_y = offset_y / 2; + offset_x = uv_offset_x * 2; + offset_y = uv_offset_y * 2; + + const uint8_t* y_plane = + src.DataY() + src.StrideY() * offset_y + offset_x; + const uint8_t* u_plane = + src.DataU() + src.StrideU() * uv_offset_y + uv_offset_x; + const uint8_t* v_plane = + src.DataV() + src.StrideV() * uv_offset_y + uv_offset_x; + int res = libyuv::I420Scale(y_plane, src.StrideY(), + u_plane, src.StrideU(), + v_plane, src.StrideV(), + crop_width, crop_height, + MutableDataY(), StrideY(), + MutableDataU(), StrideU(), + MutableDataV(), StrideV(), + width(), height(), libyuv::kFilterBox); + + RTC_DCHECK_EQ(res, 0); +} + +void I420Buffer::CropAndScaleFrom( + const VideoFrameBuffer& src) { + const int crop_width = + std::min(src.width(), width() * src.height() / height()); + const int crop_height = + std::min(src.height(), height() * src.width() / width()); + + CropAndScaleFrom( + src, + (src.width() - crop_width) / 2, (src.height() - crop_height) / 2, + crop_width, crop_height); +} + +void I420Buffer::ScaleFrom(const VideoFrameBuffer& src) { + CropAndScaleFrom(src, 0, 0, src.width(), src.height()); +} + +} // namespace webrtc diff --git a/webrtc/api/video/i420_buffer.h b/webrtc/api/video/i420_buffer.h new file mode 100644 index 0000000000..388a3dd769 --- /dev/null +++ b/webrtc/api/video/i420_buffer.h @@ -0,0 +1,116 @@ +/* + * Copyright (c) 2015 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. + */ + +#ifndef WEBRTC_API_VIDEO_I420_BUFFER_H_ +#define WEBRTC_API_VIDEO_I420_BUFFER_H_ + +#include + +#include "webrtc/api/video/video_rotation.h" +#include "webrtc/api/video/video_frame_buffer.h" +#include "webrtc/system_wrappers/include/aligned_malloc.h" + +namespace webrtc { + +// Plain I420 buffer in standard memory. +class I420Buffer : public VideoFrameBuffer { + public: + static rtc::scoped_refptr Create(int width, int height); + static rtc::scoped_refptr Create(int width, + int height, + int stride_y, + int stride_u, + int stride_v); + + // Create a new buffer and copy the pixel data. + static rtc::scoped_refptr Copy(const VideoFrameBuffer& buffer); + + static rtc::scoped_refptr Copy( + int width, int height, + const uint8_t* data_y, int stride_y, + const uint8_t* data_u, int stride_u, + const uint8_t* data_v, int stride_v); + + // Returns a rotated copy of |src|. + static rtc::scoped_refptr Rotate(const VideoFrameBuffer& src, + VideoRotation rotation); + + // Sets the buffer to all black. + static void SetBlack(I420Buffer* buffer); + + // Sets all three planes to all zeros. Used to work around for + // quirks in memory checkers + // (https://bugs.chromium.org/p/libyuv/issues/detail?id=377) and + // ffmpeg (http://crbug.com/390941). + // TODO(nisse): Deprecated. Should be deleted if/when those issues + // are resolved in a better way. Or in the mean time, use SetBlack. + void InitializeData(); + + // TODO(nisse): Deprecated, use static method instead. + void SetToBlack() { SetBlack(this); } + + int width() const override; + int height() const override; + const uint8_t* DataY() const override; + const uint8_t* DataU() const override; + const uint8_t* DataV() const override; + + int StrideY() const override; + int StrideU() const override; + int StrideV() const override; + + void* native_handle() const override; + rtc::scoped_refptr NativeToI420Buffer() override; + + uint8_t* MutableDataY(); + uint8_t* MutableDataU(); + uint8_t* MutableDataV(); + + // Scale the cropped area of |src| to the size of |this| buffer, and + // write the result into |this|. + void CropAndScaleFrom(const VideoFrameBuffer& src, + int offset_x, + int offset_y, + int crop_width, + int crop_height); + + // The common case of a center crop, when needed to adjust the + // aspect ratio without distorting the image. + void CropAndScaleFrom(const VideoFrameBuffer& src); + + // Scale all of |src| to the size of |this| buffer, with no cropping. + void ScaleFrom(const VideoFrameBuffer& src); + + // TODO(nisse): Deprecated, delete once downstream applications are updated. + // Returns a rotated versions of |src|. Native buffers are not + // supported. The reason this function doesn't return an I420Buffer, + // is that it returns |src| unchanged in case |rotation| is zero. + static rtc::scoped_refptr Rotate( + rtc::scoped_refptr src, + VideoRotation rotation); + + protected: + I420Buffer(int width, int height); + I420Buffer(int width, int height, int stride_y, int stride_u, int stride_v); + + ~I420Buffer() override; + + private: + const int width_; + const int height_; + const int stride_y_; + const int stride_u_; + const int stride_v_; + const std::unique_ptr data_; +}; + +} // namespace webrtc + +#endif // WEBRTC_API_VIDEO_I420_BUFFER_H_ diff --git a/webrtc/api/video/video_frame.cc b/webrtc/api/video/video_frame.cc new file mode 100644 index 0000000000..bd9c72c352 --- /dev/null +++ b/webrtc/api/video/video_frame.cc @@ -0,0 +1,66 @@ +/* + * Copyright (c) 2012 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.h" + +#include "webrtc/base/checks.h" +#include "webrtc/base/timeutils.h" + +namespace webrtc { + +VideoFrame::VideoFrame(const rtc::scoped_refptr& buffer, + webrtc::VideoRotation rotation, + int64_t timestamp_us) + : video_frame_buffer_(buffer), + timestamp_rtp_(0), + ntp_time_ms_(0), + timestamp_us_(timestamp_us), + rotation_(rotation) {} + +VideoFrame::VideoFrame(const rtc::scoped_refptr& buffer, + uint32_t timestamp, + int64_t render_time_ms, + VideoRotation rotation) + : video_frame_buffer_(buffer), + timestamp_rtp_(timestamp), + ntp_time_ms_(0), + timestamp_us_(render_time_ms * rtc::kNumMicrosecsPerMillisec), + rotation_(rotation) { + RTC_DCHECK(buffer); +} + +VideoFrame::~VideoFrame() = default; + +VideoFrame::VideoFrame(const VideoFrame&) = default; +VideoFrame::VideoFrame(VideoFrame&&) = default; +VideoFrame& VideoFrame::operator=(const VideoFrame&) = default; +VideoFrame& VideoFrame::operator=(VideoFrame&&) = default; + +int VideoFrame::width() const { + return video_frame_buffer_ ? video_frame_buffer_->width() : 0; +} + +int VideoFrame::height() const { + return video_frame_buffer_ ? video_frame_buffer_->height() : 0; +} + +rtc::scoped_refptr VideoFrame::video_frame_buffer() const { + return video_frame_buffer_; +} + +void VideoFrame::set_render_time_ms(int64_t render_time_ms) { + set_timestamp_us(render_time_ms * rtc::kNumMicrosecsPerMillisec); +} + +int64_t VideoFrame::render_time_ms() const { + return timestamp_us() / rtc::kNumMicrosecsPerMillisec; +} + +} // namespace webrtc diff --git a/webrtc/api/video/video_frame.h b/webrtc/api/video/video_frame.h new file mode 100644 index 0000000000..f960fa9200 --- /dev/null +++ b/webrtc/api/video/video_frame.h @@ -0,0 +1,119 @@ +/* + * Copyright (c) 2014 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. + */ + +#ifndef WEBRTC_API_VIDEO_VIDEO_FRAME_H_ +#define WEBRTC_API_VIDEO_VIDEO_FRAME_H_ + +#include + +#include "webrtc/api/video/video_rotation.h" +#include "webrtc/api/video/video_frame_buffer.h" + +// TODO(nisse): Transition hack, some downstream applications expect +// that including this file also defines base/timeutils.h constants. +// Delete after applications are fixed to include the right headers. +#include "webrtc/base/timeutils.h" + +namespace webrtc { + +class VideoFrame { + public: + // TODO(nisse): This constructor is consistent with the now deleted + // cricket::WebRtcVideoFrame. We should consider whether or not we + // want to stick to this style and deprecate the other constructor. + VideoFrame(const rtc::scoped_refptr& buffer, + webrtc::VideoRotation rotation, + int64_t timestamp_us); + + // Preferred constructor. + VideoFrame(const rtc::scoped_refptr& buffer, + uint32_t timestamp, + int64_t render_time_ms, + VideoRotation rotation); + + ~VideoFrame(); + + // Support move and copy. + VideoFrame(const VideoFrame&); + VideoFrame(VideoFrame&&); + VideoFrame& operator=(const VideoFrame&); + VideoFrame& operator=(VideoFrame&&); + + // Get frame width. + int width() const; + + // Get frame height. + int height() const; + + // System monotonic clock, same timebase as rtc::TimeMicros(). + int64_t timestamp_us() const { return timestamp_us_; } + void set_timestamp_us(int64_t timestamp_us) { timestamp_us_ = timestamp_us; } + + // TODO(nisse): After the cricket::VideoFrame and webrtc::VideoFrame + // merge, timestamps other than timestamp_us will likely be + // deprecated. + + // Set frame timestamp (90kHz). + void set_timestamp(uint32_t timestamp) { timestamp_rtp_ = timestamp; } + + // Get frame timestamp (90kHz). + uint32_t timestamp() const { return timestamp_rtp_; } + + // For now, transport_frame_id and rtp timestamp are the same. + // TODO(nisse): Must be handled differently for QUIC. + uint32_t transport_frame_id() const { return timestamp(); } + + // Set capture ntp time in milliseconds. + void set_ntp_time_ms(int64_t ntp_time_ms) { ntp_time_ms_ = ntp_time_ms; } + + // Get capture ntp time in milliseconds. + int64_t ntp_time_ms() const { return ntp_time_ms_; } + + // Naming convention for Coordination of Video Orientation. Please see + // http://www.etsi.org/deliver/etsi_ts/126100_126199/126114/12.07.00_60/ts_126114v120700p.pdf + // + // "pending rotation" or "pending" = a frame that has a VideoRotation > 0. + // + // "not pending" = a frame that has a VideoRotation == 0. + // + // "apply rotation" = modify a frame from being "pending" to being "not + // pending" rotation (a no-op for "unrotated"). + // + VideoRotation rotation() const { return rotation_; } + void set_rotation(VideoRotation rotation) { rotation_ = rotation; } + + // Set render time in milliseconds. + void set_render_time_ms(int64_t render_time_ms); + + // Get render time in milliseconds. + int64_t render_time_ms() const; + + // Return the underlying buffer. Never nullptr for a properly + // initialized VideoFrame. + rtc::scoped_refptr video_frame_buffer() const; + + // TODO(nisse): Deprecated. + // Return true if the frame is stored in a texture. + bool is_texture() const { + return video_frame_buffer()->native_handle() != nullptr; + } + + private: + // An opaque reference counted handle that stores the pixel data. + rtc::scoped_refptr video_frame_buffer_; + uint32_t timestamp_rtp_; + int64_t ntp_time_ms_; + int64_t timestamp_us_; + VideoRotation rotation_; +}; + +} // namespace webrtc + +#endif // WEBRTC_API_VIDEO_VIDEO_FRAME_H_ diff --git a/webrtc/api/video/video_frame_buffer.h b/webrtc/api/video/video_frame_buffer.h new file mode 100644 index 0000000000..c8c2e5d5d4 --- /dev/null +++ b/webrtc/api/video/video_frame_buffer.h @@ -0,0 +1,55 @@ +/* + * Copyright (c) 2015 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. + */ + +#ifndef WEBRTC_API_VIDEO_VIDEO_FRAME_BUFFER_H_ +#define WEBRTC_API_VIDEO_VIDEO_FRAME_BUFFER_H_ + +#include + +#include "webrtc/base/refcount.h" +#include "webrtc/base/scoped_ref_ptr.h" + +namespace webrtc { + +// Interface of a simple frame buffer containing pixel data. This interface does +// not contain any frame metadata such as rotation, timestamp, pixel_width, etc. +class VideoFrameBuffer : public rtc::RefCountInterface { + public: + // The resolution of the frame in pixels. For formats where some planes are + // subsampled, this is the highest-resolution plane. + virtual int width() const = 0; + virtual int height() const = 0; + + // Returns pointer to the pixel data for a given plane. The memory is owned by + // the VideoFrameBuffer object and must not be freed by the caller. + virtual const uint8_t* DataY() const = 0; + virtual const uint8_t* DataU() const = 0; + virtual const uint8_t* DataV() const = 0; + + // Returns the number of bytes between successive rows for a given plane. + virtual int StrideY() const = 0; + virtual int StrideU() const = 0; + virtual int StrideV() const = 0; + + // Return the handle of the underlying video frame. This is used when the + // frame is backed by a texture. + virtual void* native_handle() const = 0; + + // Returns a new memory-backed frame buffer converted from this buffer's + // native handle. + virtual rtc::scoped_refptr NativeToI420Buffer() = 0; + + protected: + ~VideoFrameBuffer() override {} +}; + +} // namespace webrtc + +#endif // WEBRTC_API_VIDEO_VIDEO_FRAME_BUFFER_H_ diff --git a/webrtc/common_types.h b/webrtc/common_types.h index 0a1c67c63a..948bd006c8 100644 --- a/webrtc/common_types.h +++ b/webrtc/common_types.h @@ -18,9 +18,9 @@ #include #include +#include "webrtc/api/video/video_rotation.h" #include "webrtc/base/checks.h" #include "webrtc/base/optional.h" -#include "webrtc/common_video/rotation.h" #include "webrtc/typedefs.h" #if defined(_MSC_VER) diff --git a/webrtc/common_video/BUILD.gn b/webrtc/common_video/BUILD.gn index 0aefefd193..3b33bcca8d 100644 --- a/webrtc/common_video/BUILD.gn +++ b/webrtc/common_video/BUILD.gn @@ -60,12 +60,13 @@ rtc_static_library("common_video") { "../base:rtc_task_queue", "../system_wrappers", ] + public_deps = [ + "../api:video_frame_api", + ] if (rtc_build_libyuv) { deps += [ "$rtc_libyuv_dir" ] - public_deps = [ - "$rtc_libyuv_dir", - ] + public_deps += [ "$rtc_libyuv_dir" ] } else { # Need to add a directory normally exported by libyuv. include_dirs += [ "$rtc_libyuv_dir/include" ] diff --git a/webrtc/common_video/i420_video_frame_unittest.cc b/webrtc/common_video/i420_video_frame_unittest.cc index 49cc4654fb..e03762eb39 100644 --- a/webrtc/common_video/i420_video_frame_unittest.cc +++ b/webrtc/common_video/i420_video_frame_unittest.cc @@ -11,11 +11,12 @@ #include #include +#include "webrtc/api/video/video_frame.h" #include "webrtc/base/bind.h" +#include "webrtc/base/timeutils.h" #include "webrtc/test/fake_texture_frame.h" #include "webrtc/test/frame_utils.h" #include "webrtc/test/gtest.h" -#include "webrtc/video_frame.h" namespace webrtc { @@ -280,7 +281,7 @@ class TestI420BufferRotate TEST_P(TestI420BufferRotate, Rotates) { rtc::scoped_refptr buffer = CreateGradient(640, 480); rtc::scoped_refptr rotated_buffer = - I420Buffer::Rotate(buffer, GetParam()); + I420Buffer::Rotate(*buffer, GetParam()); CheckRotate(640, 480, GetParam(), *rotated_buffer); } @@ -290,4 +291,20 @@ INSTANTIATE_TEST_CASE_P(Rotate, TestI420BufferRotate, kVideoRotation_180, kVideoRotation_270)); +class TestI420BufferRotateOld + : public ::testing::TestWithParam {}; + +TEST_P(TestI420BufferRotateOld, Rotates) { + rtc::scoped_refptr buffer = CreateGradient(640, 480); + rtc::scoped_refptr rotated_buffer = + I420Buffer::Rotate(buffer, GetParam()); + CheckRotate(640, 480, GetParam(), *rotated_buffer); +} + +INSTANTIATE_TEST_CASE_P(Rotate, TestI420BufferRotateOld, + ::testing::Values(kVideoRotation_0, + kVideoRotation_90, + kVideoRotation_180, + kVideoRotation_270)); + } // namespace webrtc diff --git a/webrtc/common_video/include/corevideo_frame_buffer.h b/webrtc/common_video/include/corevideo_frame_buffer.h index c925cbfc97..a00b6770ff 100644 --- a/webrtc/common_video/include/corevideo_frame_buffer.h +++ b/webrtc/common_video/include/corevideo_frame_buffer.h @@ -57,4 +57,3 @@ class CoreVideoFrameBuffer : public NativeHandleBuffer { } // namespace webrtc #endif // WEBRTC_COMMON_VIDEO_INCLUDE_COREVIDEO_FRAME_BUFFER_H_ - diff --git a/webrtc/common_video/include/i420_buffer_pool.h b/webrtc/common_video/include/i420_buffer_pool.h index f0562634ae..454a8cd9d7 100644 --- a/webrtc/common_video/include/i420_buffer_pool.h +++ b/webrtc/common_video/include/i420_buffer_pool.h @@ -14,8 +14,8 @@ #include #include +#include "webrtc/api/video/i420_buffer.h" #include "webrtc/base/race_checker.h" -#include "webrtc/common_video/include/video_frame_buffer.h" namespace webrtc { diff --git a/webrtc/common_video/include/video_frame_buffer.h b/webrtc/common_video/include/video_frame_buffer.h index 4f8468a07b..dfdd480b5d 100644 --- a/webrtc/common_video/include/video_frame_buffer.h +++ b/webrtc/common_video/include/video_frame_buffer.h @@ -11,135 +11,17 @@ #ifndef WEBRTC_COMMON_VIDEO_INCLUDE_VIDEO_FRAME_BUFFER_H_ #define WEBRTC_COMMON_VIDEO_INCLUDE_VIDEO_FRAME_BUFFER_H_ -#include - #include +#include "webrtc/api/video/video_frame_buffer.h" +// TODO(nisse): For backwards compatibility, files including this file +// expect it to declare I420Buffer. Delete after callers are updated. +#include "webrtc/api/video/i420_buffer.h" #include "webrtc/base/callback.h" -#include "webrtc/base/refcount.h" #include "webrtc/base/scoped_ref_ptr.h" -#include "webrtc/common_video/rotation.h" -#include "webrtc/system_wrappers/include/aligned_malloc.h" namespace webrtc { -// Interface of a simple frame buffer containing pixel data. This interface does -// not contain any frame metadata such as rotation, timestamp, pixel_width, etc. -class VideoFrameBuffer : public rtc::RefCountInterface { - public: - // The resolution of the frame in pixels. For formats where some planes are - // subsampled, this is the highest-resolution plane. - virtual int width() const = 0; - virtual int height() const = 0; - - // Returns pointer to the pixel data for a given plane. The memory is owned by - // the VideoFrameBuffer object and must not be freed by the caller. - virtual const uint8_t* DataY() const = 0; - virtual const uint8_t* DataU() const = 0; - virtual const uint8_t* DataV() const = 0; - - // Returns the number of bytes between successive rows for a given plane. - virtual int StrideY() const = 0; - virtual int StrideU() const = 0; - virtual int StrideV() const = 0; - - // Return the handle of the underlying video frame. This is used when the - // frame is backed by a texture. - virtual void* native_handle() const = 0; - - // Returns a new memory-backed frame buffer converted from this buffer's - // native handle. - virtual rtc::scoped_refptr NativeToI420Buffer() = 0; - - protected: - virtual ~VideoFrameBuffer(); -}; - -// Plain I420 buffer in standard memory. -class I420Buffer : public VideoFrameBuffer { - public: - static rtc::scoped_refptr Create(int width, int height); - static rtc::scoped_refptr Create(int width, - int height, - int stride_y, - int stride_u, - int stride_v); - - // Create a new buffer and copy the pixel data. - static rtc::scoped_refptr Copy(const VideoFrameBuffer& buffer); - - static rtc::scoped_refptr Copy( - int width, int height, - const uint8_t* data_y, int stride_y, - const uint8_t* data_u, int stride_u, - const uint8_t* data_v, int stride_v); - - // Returns a rotated versions of |src|. Native buffers are not - // supported. The reason this function doesn't return an I420Buffer, - // is that it returns |src| unchanged in case |rotation| is zero. - // TODO(nisse): Consider dropping the special handling of zero - // rotation, and leave any optimizing that case to the caller. - static rtc::scoped_refptr Rotate( - rtc::scoped_refptr src, - VideoRotation rotation); - - // Sets all three planes to all zeros. Used to work around for - // quirks in memory checkers - // (https://bugs.chromium.org/p/libyuv/issues/detail?id=377) and - // ffmpeg (http://crbug.com/390941). - // TODO(nisse): Should be deleted if/when those issues are resolved - // in a better way. - void InitializeData(); - - // Sets the frame buffer to all black. - void SetToBlack(); - - int width() const override; - int height() const override; - const uint8_t* DataY() const override; - const uint8_t* DataU() const override; - const uint8_t* DataV() const override; - - uint8_t* MutableDataY(); - uint8_t* MutableDataU(); - uint8_t* MutableDataV(); - int StrideY() const override; - int StrideU() const override; - int StrideV() const override; - - void* native_handle() const override; - rtc::scoped_refptr NativeToI420Buffer() override; - - // Scale the cropped area of |src| to the size of |this| buffer, and - // write the result into |this|. - void CropAndScaleFrom(const VideoFrameBuffer& src, - int offset_x, - int offset_y, - int crop_width, - int crop_height); - - // The common case of a center crop, when needed to adjust the - // aspect ratio without distorting the image. - void CropAndScaleFrom(const VideoFrameBuffer& src); - - // Scale all of |src| to the size of |this| buffer, with no cropping. - void ScaleFrom(const VideoFrameBuffer& src); - - protected: - I420Buffer(int width, int height); - I420Buffer(int width, int height, int stride_y, int stride_u, int stride_v); - - ~I420Buffer() override; - - private: - const int width_; - const int height_; - const int stride_y_; - const int stride_u_; - const int stride_v_; - const std::unique_ptr data_; -}; - // Base class for native-handle buffer is a wrapper around a |native_handle|. // This is used for convenience as most native-handle implementations can share // many VideoFrame implementations, but need to implement a few others (such diff --git a/webrtc/common_video/libyuv/include/webrtc_libyuv.h b/webrtc/common_video/libyuv/include/webrtc_libyuv.h index 3cfee01d75..6d7ed1fd02 100644 --- a/webrtc/common_video/libyuv/include/webrtc_libyuv.h +++ b/webrtc/common_video/libyuv/include/webrtc_libyuv.h @@ -18,13 +18,14 @@ #include #include +#include "webrtc/api/video/video_frame.h" #include "webrtc/common_types.h" // RawVideoTypes. -#include "webrtc/common_video/rotation.h" #include "webrtc/typedefs.h" -#include "webrtc/video_frame.h" namespace webrtc { +class I420Buffer; + // Supported video types. enum VideoType { kUnknown, @@ -97,9 +98,10 @@ int ExtractBuffer(const VideoFrame& input_frame, size_t size, uint8_t* buffer); // Return value: 0 if OK, < 0 otherwise. // TODO(nisse): Delete this wrapper, and let users call libyuv directly. Most -// calls pass |src_video_type| == kI420, and should use libyuv::I420Copy. The -// only exception at the time of this writing is -// VideoCaptureImpl::IncomingFrame, which still needs libyuv::ConvertToI420. +// calls pass |src_video_type| == kI420, and should use libyuv::I420Copy. Also +// remember to delete the I420Buffer forward declaration above. The only +// exception at the time of this writing is VideoCaptureImpl::IncomingFrame, +// which still needs libyuv::ConvertToI420. int ConvertToI420(VideoType src_video_type, const uint8_t* src_frame, int crop_x, diff --git a/webrtc/common_video/libyuv/libyuv_unittest.cc b/webrtc/common_video/libyuv/libyuv_unittest.cc index 87cd03714c..8f421f3038 100644 --- a/webrtc/common_video/libyuv/libyuv_unittest.cc +++ b/webrtc/common_video/libyuv/libyuv_unittest.cc @@ -13,12 +13,13 @@ #include +#include "webrtc/api/video/i420_buffer.h" +#include "webrtc/api/video/video_frame.h" #include "webrtc/common_video/libyuv/include/webrtc_libyuv.h" #include "webrtc/test/frame_utils.h" #include "webrtc/test/gmock.h" #include "webrtc/test/gtest.h" #include "webrtc/test/testsupport/fileutils.h" -#include "webrtc/video_frame.h" namespace webrtc { diff --git a/webrtc/common_video/libyuv/webrtc_libyuv.cc b/webrtc/common_video/libyuv/webrtc_libyuv.cc index 0bb592d733..ae8d6b1ef5 100644 --- a/webrtc/common_video/libyuv/webrtc_libyuv.cc +++ b/webrtc/common_video/libyuv/webrtc_libyuv.cc @@ -13,8 +13,10 @@ #include #include "webrtc/base/checks.h" +// TODO(nisse): Only needed for the deprecated ConvertToI420. +#include "webrtc/api/video/i420_buffer.h" -// NOTE(ajm): Path provided by gyp. +// NOTE(ajm): Path provided by gn. #include "libyuv.h" // NOLINT namespace webrtc { diff --git a/webrtc/common_video/rotation.h b/webrtc/common_video/rotation.h index 46a9ecc5ea..f01c812944 100644 --- a/webrtc/common_video/rotation.h +++ b/webrtc/common_video/rotation.h @@ -8,19 +8,11 @@ * be found in the AUTHORS file in the root of the source tree. */ +// TODO(nisse): Delete this file, once downstream code is updated. + #ifndef WEBRTC_COMMON_VIDEO_ROTATION_H_ #define WEBRTC_COMMON_VIDEO_ROTATION_H_ -namespace webrtc { - -// enum for clockwise rotation. -enum VideoRotation { - kVideoRotation_0 = 0, - kVideoRotation_90 = 90, - kVideoRotation_180 = 180, - kVideoRotation_270 = 270 -}; - -} // namespace webrtc +#include "webrtc/api/video/video_rotation.h" #endif // WEBRTC_COMMON_VIDEO_ROTATION_H_ diff --git a/webrtc/common_video/video_frame.cc b/webrtc/common_video/video_frame.cc index d9c5c2f783..55eb5351c3 100644 --- a/webrtc/common_video/video_frame.cc +++ b/webrtc/common_video/video_frame.cc @@ -23,39 +23,6 @@ namespace webrtc { // to optimized bitstream readers. See avcodec_decode_video2. const size_t EncodedImage::kBufferPaddingBytesH264 = 8; -VideoFrame::VideoFrame(const rtc::scoped_refptr& buffer, - webrtc::VideoRotation rotation, - int64_t timestamp_us) - : video_frame_buffer_(buffer), - timestamp_rtp_(0), - ntp_time_ms_(0), - timestamp_us_(timestamp_us), - rotation_(rotation) {} - -VideoFrame::VideoFrame(const rtc::scoped_refptr& buffer, - uint32_t timestamp, - int64_t render_time_ms, - VideoRotation rotation) - : video_frame_buffer_(buffer), - timestamp_rtp_(timestamp), - ntp_time_ms_(0), - timestamp_us_(render_time_ms * rtc::kNumMicrosecsPerMillisec), - rotation_(rotation) { - RTC_DCHECK(buffer); -} - -int VideoFrame::width() const { - return video_frame_buffer_ ? video_frame_buffer_->width() : 0; -} - -int VideoFrame::height() const { - return video_frame_buffer_ ? video_frame_buffer_->height() : 0; -} - -rtc::scoped_refptr VideoFrame::video_frame_buffer() const { - return video_frame_buffer_; -} - size_t EncodedImage::GetBufferPaddingBytes(VideoCodecType codec_type) { switch (codec_type) { case kVideoCodecVP8: diff --git a/webrtc/common_video/video_frame_buffer.cc b/webrtc/common_video/video_frame_buffer.cc index d23b4c5d45..4646bf491f 100644 --- a/webrtc/common_video/video_frame_buffer.cc +++ b/webrtc/common_video/video_frame_buffer.cc @@ -19,238 +19,8 @@ #include "libyuv/planar_functions.h" #include "libyuv/scale.h" -// Aligning pointer to 64 bytes for improved performance, e.g. use SIMD. -static const int kBufferAlignment = 64; - namespace webrtc { -namespace { - -int I420DataSize(int height, int stride_y, int stride_u, int stride_v) { - return stride_y * height + (stride_u + stride_v) * ((height + 1) / 2); -} - -} // namespace - -VideoFrameBuffer::~VideoFrameBuffer() {} - -I420Buffer::I420Buffer(int width, int height) - : I420Buffer(width, height, width, (width + 1) / 2, (width + 1) / 2) { -} - -I420Buffer::I420Buffer(int width, - int height, - int stride_y, - int stride_u, - int stride_v) - : width_(width), - height_(height), - stride_y_(stride_y), - stride_u_(stride_u), - stride_v_(stride_v), - data_(static_cast(AlignedMalloc( - I420DataSize(height, stride_y, stride_u, stride_v), - kBufferAlignment))) { - RTC_DCHECK_GT(width, 0); - RTC_DCHECK_GT(height, 0); - RTC_DCHECK_GE(stride_y, width); - RTC_DCHECK_GE(stride_u, (width + 1) / 2); - RTC_DCHECK_GE(stride_v, (width + 1) / 2); -} - -I420Buffer::~I420Buffer() { -} - -// static -rtc::scoped_refptr I420Buffer::Create(int width, int height) { - return new rtc::RefCountedObject(width, height); -} - -// static -rtc::scoped_refptr I420Buffer::Create(int width, - int height, - int stride_y, - int stride_u, - int stride_v) { - return new rtc::RefCountedObject( - width, height, stride_y, stride_u, stride_v); -} - -// static -rtc::scoped_refptr I420Buffer::Copy( - const VideoFrameBuffer& source) { - return Copy(source.width(), source.height(), - source.DataY(), source.StrideY(), - source.DataU(), source.StrideU(), - source.DataV(), source.StrideV()); -} - -// static -rtc::scoped_refptr I420Buffer::Copy( - int width, int height, - const uint8_t* data_y, int stride_y, - const uint8_t* data_u, int stride_u, - const uint8_t* data_v, int stride_v) { - // Note: May use different strides than the input data. - rtc::scoped_refptr buffer = Create(width, height); - RTC_CHECK_EQ(0, libyuv::I420Copy(data_y, stride_y, - data_u, stride_u, - data_v, stride_v, - buffer->MutableDataY(), buffer->StrideY(), - buffer->MutableDataU(), buffer->StrideU(), - buffer->MutableDataV(), buffer->StrideV(), - width, height)); - return buffer; -} - -// static -rtc::scoped_refptr I420Buffer::Rotate( - rtc::scoped_refptr src, - VideoRotation rotation) { - RTC_CHECK(src->DataY()); - RTC_CHECK(src->DataU()); - RTC_CHECK(src->DataV()); - - if (rotation == webrtc::kVideoRotation_0) { - return src; - } - - int rotated_width = src->width(); - int rotated_height = src->height(); - if (rotation == webrtc::kVideoRotation_90 || - rotation == webrtc::kVideoRotation_270) { - std::swap(rotated_width, rotated_height); - } - - rtc::scoped_refptr buffer = - I420Buffer::Create(rotated_width, rotated_height); - - RTC_CHECK_EQ(0, libyuv::I420Rotate( - src->DataY(), src->StrideY(), - src->DataU(), src->StrideU(), - src->DataV(), src->StrideV(), - buffer->MutableDataY(), buffer->StrideY(), buffer->MutableDataU(), - buffer->StrideU(), buffer->MutableDataV(), buffer->StrideV(), - src->width(), src->height(), - static_cast(rotation))); - - return buffer; -} - -void I420Buffer::InitializeData() { - memset(data_.get(), 0, - I420DataSize(height_, stride_y_, stride_u_, stride_v_)); -} - -int I420Buffer::width() const { - return width_; -} - -int I420Buffer::height() const { - return height_; -} - -const uint8_t* I420Buffer::DataY() const { - return data_.get(); -} -const uint8_t* I420Buffer::DataU() const { - return data_.get() + stride_y_ * height_; -} -const uint8_t* I420Buffer::DataV() const { - return data_.get() + stride_y_ * height_ + stride_u_ * ((height_ + 1) / 2); -} - -uint8_t* I420Buffer::MutableDataY() { - return const_cast(DataY()); -} -uint8_t* I420Buffer::MutableDataU() { - return const_cast(DataU()); -} -uint8_t* I420Buffer::MutableDataV() { - return const_cast(DataV()); -} - -int I420Buffer::StrideY() const { - return stride_y_; -} -int I420Buffer::StrideU() const { - return stride_u_; -} -int I420Buffer::StrideV() const { - return stride_v_; -} - -void* I420Buffer::native_handle() const { - return nullptr; -} - -rtc::scoped_refptr I420Buffer::NativeToI420Buffer() { - RTC_NOTREACHED(); - return nullptr; -} - -void I420Buffer::SetToBlack() { - RTC_CHECK(libyuv::I420Rect(MutableDataY(), StrideY(), - MutableDataU(), StrideU(), - MutableDataV(), StrideV(), - 0, 0, width(), height(), - 0, 128, 128) == 0); -} - -void I420Buffer::CropAndScaleFrom( - const VideoFrameBuffer& src, - int offset_x, - int offset_y, - int crop_width, - int crop_height) { - RTC_CHECK_LE(crop_width, src.width()); - RTC_CHECK_LE(crop_height, src.height()); - RTC_CHECK_LE(crop_width + offset_x, src.width()); - RTC_CHECK_LE(crop_height + offset_y, src.height()); - RTC_CHECK_GE(offset_x, 0); - RTC_CHECK_GE(offset_y, 0); - - // Make sure offset is even so that u/v plane becomes aligned. - const int uv_offset_x = offset_x / 2; - const int uv_offset_y = offset_y / 2; - offset_x = uv_offset_x * 2; - offset_y = uv_offset_y * 2; - - const uint8_t* y_plane = - src.DataY() + src.StrideY() * offset_y + offset_x; - const uint8_t* u_plane = - src.DataU() + src.StrideU() * uv_offset_y + uv_offset_x; - const uint8_t* v_plane = - src.DataV() + src.StrideV() * uv_offset_y + uv_offset_x; - int res = libyuv::I420Scale(y_plane, src.StrideY(), - u_plane, src.StrideU(), - v_plane, src.StrideV(), - crop_width, crop_height, - MutableDataY(), StrideY(), - MutableDataU(), StrideU(), - MutableDataV(), StrideV(), - width(), height(), libyuv::kFilterBox); - - RTC_DCHECK_EQ(res, 0); -} - -void I420Buffer::CropAndScaleFrom( - const VideoFrameBuffer& src) { - const int crop_width = - std::min(src.width(), width() * src.height() / height()); - const int crop_height = - std::min(src.height(), height() * src.width() / width()); - - CropAndScaleFrom( - src, - (src.width() - crop_width) / 2, (src.height() - crop_height) / 2, - crop_width, crop_height); -} - -void I420Buffer::ScaleFrom(const VideoFrameBuffer& src) { - CropAndScaleFrom(src, 0, 0, src.width(), src.height()); -} - NativeHandleBuffer::NativeHandleBuffer(void* native_handle, int width, int height) diff --git a/webrtc/common_video/video_render_frames.h b/webrtc/common_video/video_render_frames.h index 26a7ef5137..38bc0e9e19 100644 --- a/webrtc/common_video/video_render_frames.h +++ b/webrtc/common_video/video_render_frames.h @@ -15,8 +15,8 @@ #include +#include "webrtc/api/video/video_frame.h" #include "webrtc/base/optional.h" -#include "webrtc/video_frame.h" namespace webrtc { diff --git a/webrtc/examples/peerconnection/client/linux/main_wnd.cc b/webrtc/examples/peerconnection/client/linux/main_wnd.cc index fa7ea4e8d0..5298382267 100644 --- a/webrtc/examples/peerconnection/client/linux/main_wnd.cc +++ b/webrtc/examples/peerconnection/client/linux/main_wnd.cc @@ -15,6 +15,7 @@ #include #include "libyuv/convert_from.h" +#include "webrtc/api/video/i420_buffer.h" #include "webrtc/examples/peerconnection/client/defaults.h" #include "webrtc/base/common.h" #include "webrtc/base/logging.h" @@ -523,9 +524,10 @@ void GtkMainWnd::VideoRenderer::OnFrame( gdk_threads_enter(); rtc::scoped_refptr buffer( - webrtc::I420Buffer::Rotate(video_frame.video_frame_buffer(), - video_frame.rotation())); - + video_frame.video_frame_buffer()); + if (video_frame.rotation() != webrtc::kVideoRotation_0) { + buffer = webrtc::I420Buffer::Rotate(*buffer, video_frame.rotation()); + } SetSize(buffer->width(), buffer->height()); libyuv::I420ToRGBA(buffer->DataY(), buffer->StrideY(), diff --git a/webrtc/examples/peerconnection/client/main_wnd.cc b/webrtc/examples/peerconnection/client/main_wnd.cc index 22a45b0445..4830d29d15 100644 --- a/webrtc/examples/peerconnection/client/main_wnd.cc +++ b/webrtc/examples/peerconnection/client/main_wnd.cc @@ -13,6 +13,7 @@ #include #include "libyuv/convert_argb.h" +#include "webrtc/api/video/i420_buffer.h" #include "webrtc/examples/peerconnection/client/defaults.h" #include "webrtc/base/arraysize.h" #include "webrtc/base/common.h" @@ -606,8 +607,10 @@ void MainWnd::VideoRenderer::OnFrame( AutoLock lock(this); rtc::scoped_refptr buffer( - webrtc::I420Buffer::Rotate(video_frame.video_frame_buffer(), - video_frame.rotation())); + video_frame.video_frame_buffer()); + if (video_frame.rotation() != webrtc::kVideoRotation_0) { + buffer = webrtc::I420Buffer::Rotate(*buffer, video_frame.rotation()); + } SetSize(buffer->width(), buffer->height()); diff --git a/webrtc/examples/peerconnection/client/main_wnd.h b/webrtc/examples/peerconnection/client/main_wnd.h index 543b7ce573..d61f95df74 100644 --- a/webrtc/examples/peerconnection/client/main_wnd.h +++ b/webrtc/examples/peerconnection/client/main_wnd.h @@ -17,11 +17,11 @@ #include #include "webrtc/api/mediastreaminterface.h" +#include "webrtc/api/video/video_frame.h" #include "webrtc/base/win32.h" #include "webrtc/examples/peerconnection/client/peer_connection_client.h" #include "webrtc/media/base/mediachannel.h" #include "webrtc/media/base/videocommon.h" -#include "webrtc/video_frame.h" class MainWndCallback { public: diff --git a/webrtc/media/base/adaptedvideotracksource.cc b/webrtc/media/base/adaptedvideotracksource.cc index 5900439e12..38735d489a 100644 --- a/webrtc/media/base/adaptedvideotracksource.cc +++ b/webrtc/media/base/adaptedvideotracksource.cc @@ -10,6 +10,8 @@ #include "webrtc/media/base/adaptedvideotracksource.h" +#include "webrtc/api/video/i420_buffer.h" + namespace rtc { AdaptedVideoTrackSource::AdaptedVideoTrackSource() { @@ -48,7 +50,7 @@ void AdaptedVideoTrackSource::OnFrame(const webrtc::VideoFrame& frame) { !buffer->native_handle()) { /* Apply pending rotation. */ broadcaster_.OnFrame(webrtc::VideoFrame( - webrtc::I420Buffer::Rotate(buffer, frame.rotation()), + webrtc::I420Buffer::Rotate(*buffer, frame.rotation()), webrtc::kVideoRotation_0, frame.timestamp_us())); } else { broadcaster_.OnFrame(frame); diff --git a/webrtc/media/base/fakevideocapturer.h b/webrtc/media/base/fakevideocapturer.h index f1d349792b..b5bfd34964 100644 --- a/webrtc/media/base/fakevideocapturer.h +++ b/webrtc/media/base/fakevideocapturer.h @@ -16,10 +16,11 @@ #include #include +#include "webrtc/api/video/i420_buffer.h" +#include "webrtc/api/video/video_frame.h" #include "webrtc/base/timeutils.h" #include "webrtc/media/base/videocapturer.h" #include "webrtc/media/base/videocommon.h" -#include "webrtc/video_frame.h" namespace cricket { diff --git a/webrtc/media/base/fakevideorenderer.h b/webrtc/media/base/fakevideorenderer.h index a2e0d28e63..7255c05f83 100644 --- a/webrtc/media/base/fakevideorenderer.h +++ b/webrtc/media/base/fakevideorenderer.h @@ -11,9 +11,9 @@ #ifndef WEBRTC_MEDIA_BASE_FAKEVIDEORENDERER_H_ #define WEBRTC_MEDIA_BASE_FAKEVIDEORENDERER_H_ +#include "webrtc/api/video/video_frame.h" #include "webrtc/base/logging.h" #include "webrtc/media/base/videosinkinterface.h" -#include "webrtc/video_frame.h" namespace cricket { diff --git a/webrtc/media/base/testutils.cc b/webrtc/media/base/testutils.cc index 93d1bc0b3d..0af8d16b77 100644 --- a/webrtc/media/base/testutils.cc +++ b/webrtc/media/base/testutils.cc @@ -14,6 +14,7 @@ #include #include +#include "webrtc/api/video/video_frame.h" #include "webrtc/base/bytebuffer.h" #include "webrtc/base/fileutils.h" #include "webrtc/base/gunit.h" @@ -23,7 +24,6 @@ #include "webrtc/base/testutils.h" #include "webrtc/media/base/rtpdump.h" #include "webrtc/media/base/videocapturer.h" -#include "webrtc/video_frame.h" namespace cricket { diff --git a/webrtc/media/base/videobroadcaster.cc b/webrtc/media/base/videobroadcaster.cc index 6d6ffa747c..6655d93656 100644 --- a/webrtc/media/base/videobroadcaster.cc +++ b/webrtc/media/base/videobroadcaster.cc @@ -12,6 +12,7 @@ #include +#include "webrtc/api/video/i420_buffer.h" #include "webrtc/base/checks.h" #include "webrtc/base/logging.h" @@ -109,8 +110,8 @@ VideoBroadcaster::GetBlackFrameBuffer(int width, int height) { if (!black_frame_buffer_ || black_frame_buffer_->width() != width || black_frame_buffer_->height() != height) { rtc::scoped_refptr buffer = - new RefCountedObject(width, height); - buffer->SetToBlack(); + webrtc::I420Buffer::Create(width, height); + webrtc::I420Buffer::SetBlack(buffer.get()); black_frame_buffer_ = buffer; } diff --git a/webrtc/media/base/videobroadcaster.h b/webrtc/media/base/videobroadcaster.h index 9fae1d4024..ccf5b3dd91 100644 --- a/webrtc/media/base/videobroadcaster.h +++ b/webrtc/media/base/videobroadcaster.h @@ -15,11 +15,11 @@ #include #include +#include "webrtc/api/video/video_frame.h" #include "webrtc/base/criticalsection.h" #include "webrtc/base/thread_checker.h" #include "webrtc/media/base/videosinkinterface.h" #include "webrtc/media/base/videosourcebase.h" -#include "webrtc/video_frame.h" namespace rtc { diff --git a/webrtc/media/base/videobroadcaster_unittest.cc b/webrtc/media/base/videobroadcaster_unittest.cc index c80f0853af..30a678b1c1 100644 --- a/webrtc/media/base/videobroadcaster_unittest.cc +++ b/webrtc/media/base/videobroadcaster_unittest.cc @@ -8,10 +8,11 @@ * be found in the AUTHORS file in the root of the source tree. */ +#include "webrtc/api/video/i420_buffer.h" +#include "webrtc/api/video/video_frame.h" #include "webrtc/base/gunit.h" #include "webrtc/media/base/fakevideorenderer.h" #include "webrtc/media/base/videobroadcaster.h" -#include "webrtc/video_frame.h" using rtc::VideoBroadcaster; using rtc::VideoSinkWants; @@ -43,7 +44,7 @@ TEST(VideoBroadcasterTest, OnFrame) { rtc::scoped_refptr buffer( webrtc::I420Buffer::Create(kWidth, kHeight)); // Initialize, to avoid warnings on use of initialized values. - buffer->SetToBlack(); + webrtc::I420Buffer::SetBlack(buffer); webrtc::VideoFrame frame(buffer, webrtc::kVideoRotation_0, 0); @@ -141,7 +142,7 @@ TEST(VideoBroadcasterTest, SinkWantsBlackFrames) { broadcaster.AddOrUpdateSink(&sink2, wants2); rtc::scoped_refptr buffer( - new rtc::RefCountedObject(100, 200)); + webrtc::I420Buffer::Create(100, 200)); // Makes it not all black. buffer->InitializeData(); diff --git a/webrtc/media/base/videocapturer.cc b/webrtc/media/base/videocapturer.cc index ced48a575e..7810a48d4d 100644 --- a/webrtc/media/base/videocapturer.cc +++ b/webrtc/media/base/videocapturer.cc @@ -14,9 +14,10 @@ #include +#include "webrtc/api/video/i420_buffer.h" +#include "webrtc/api/video/video_frame.h" #include "webrtc/base/common.h" #include "webrtc/base/logging.h" -#include "webrtc/video_frame.h" namespace cricket { @@ -214,7 +215,7 @@ void VideoCapturer::OnFrame(const webrtc::VideoFrame& frame, return; } broadcaster_.OnFrame(webrtc::VideoFrame( - webrtc::I420Buffer::Rotate(buffer, frame.rotation()), + webrtc::I420Buffer::Rotate(*buffer, frame.rotation()), webrtc::kVideoRotation_0, frame.timestamp_us())); } else { broadcaster_.OnFrame(frame); diff --git a/webrtc/media/base/videocapturer.h b/webrtc/media/base/videocapturer.h index 76ab95a2b8..510063bc16 100644 --- a/webrtc/media/base/videocapturer.h +++ b/webrtc/media/base/videocapturer.h @@ -20,6 +20,12 @@ #include #include +// TODO(nisse): Transition hack, some downstream applications expect that +// including this file declares I420Buffer and NativeHandleBuffer. Delete after +// users of these classes are fixed to include the right headers. +#include "webrtc/api/video/i420_buffer.h" +#include "webrtc/common_video/include/video_frame_buffer.h" + #include "webrtc/base/constructormagic.h" #include "webrtc/base/criticalsection.h" #include "webrtc/media/base/videosourceinterface.h" diff --git a/webrtc/media/base/videoframe.h b/webrtc/media/base/videoframe.h index 7ae5b9ab93..8e8a05d7e2 100644 --- a/webrtc/media/base/videoframe.h +++ b/webrtc/media/base/videoframe.h @@ -20,7 +20,7 @@ // this file can be deleted. #include "webrtc/base/logging.h" -#include "webrtc/video_frame.h" +#include "webrtc/api/video/video_frame.h" // TODO(nisse): Similarly, some applications expect that including this file // implies a forward declaration of rtc::Thread. diff --git a/webrtc/media/base/videosourcebase.h b/webrtc/media/base/videosourcebase.h index 5ddef093b4..36c6e4e7ce 100644 --- a/webrtc/media/base/videosourcebase.h +++ b/webrtc/media/base/videosourcebase.h @@ -13,9 +13,9 @@ #include +#include "webrtc/api/video/video_frame.h" #include "webrtc/base/thread_checker.h" #include "webrtc/media/base/videosourceinterface.h" -#include "webrtc/video_frame.h" namespace rtc { diff --git a/webrtc/media/devices/gtkvideorenderer.cc b/webrtc/media/devices/gtkvideorenderer.cc index b88c391caf..f4a1412454 100644 --- a/webrtc/media/devices/gtkvideorenderer.cc +++ b/webrtc/media/devices/gtkvideorenderer.cc @@ -10,8 +10,9 @@ // Implementation of GtkVideoRenderer +#include "webrtc/api/video/i420_buffer.h" +#include "webrtc/api/video/video_frame.h" #include "webrtc/media/devices/gtkvideorenderer.h" -#include "webrtc/video_frame.h" #include #include @@ -82,8 +83,10 @@ bool GtkVideoRenderer::SetSize(int width, int height) { void GtkVideoRenderer::OnFrame(const webrtc::VideoFrame& video_frame) { rtc::scoped_refptr buffer( - webrtc::I420Buffer::Rotate(video_frame.video_frame_buffer(), - video_frame.rotation())); + video_frame.video_frame_buffer()); + if (video_frame.rotation() != webrtc::kVideoRotation_0) { + buffer = webrtc::I420Buffer::Rotate(*buffer, video_frame.rotation()); + } // Need to set size as the frame might be rotated. if (!SetSize(buffer->width(), buffer->height())) { diff --git a/webrtc/media/engine/fakewebrtccall.h b/webrtc/media/engine/fakewebrtccall.h index dc0c1da8e0..c862c1c171 100644 --- a/webrtc/media/engine/fakewebrtccall.h +++ b/webrtc/media/engine/fakewebrtccall.h @@ -25,12 +25,12 @@ #include #include +#include "webrtc/api/video/video_frame.h" #include "webrtc/base/buffer.h" #include "webrtc/call/audio_receive_stream.h" #include "webrtc/call/audio_send_stream.h" #include "webrtc/call/call.h" #include "webrtc/call/flexfec_receive_stream.h" -#include "webrtc/video_frame.h" #include "webrtc/video_receive_stream.h" #include "webrtc/video_send_stream.h" diff --git a/webrtc/media/engine/fakewebrtcvideocapturemodule.h b/webrtc/media/engine/fakewebrtcvideocapturemodule.h index e6f0ecc114..0d5299922f 100644 --- a/webrtc/media/engine/fakewebrtcvideocapturemodule.h +++ b/webrtc/media/engine/fakewebrtcvideocapturemodule.h @@ -13,6 +13,7 @@ #include +#include "webrtc/api/video/i420_buffer.h" #include "webrtc/media/base/testutils.h" #include "webrtc/media/engine/webrtcvideocapturer.h" @@ -65,7 +66,7 @@ class FakeWebRtcVideoCaptureModule : public webrtc::VideoCaptureModule { if (!running_) return; rtc::scoped_refptr buffer = - new rtc::RefCountedObject(w, h); + webrtc::I420Buffer::Create(w, h); // Initialize memory to satisfy DrMemory tests. See // https://bugs.chromium.org/p/libyuv/issues/detail?id=377 buffer->InitializeData(); diff --git a/webrtc/media/engine/videoencodersoftwarefallbackwrapper_unittest.cc b/webrtc/media/engine/videoencodersoftwarefallbackwrapper_unittest.cc index 096552bbfa..0616a5ffc5 100644 --- a/webrtc/media/engine/videoencodersoftwarefallbackwrapper_unittest.cc +++ b/webrtc/media/engine/videoencodersoftwarefallbackwrapper_unittest.cc @@ -12,6 +12,7 @@ #include +#include "webrtc/api/video/i420_buffer.h" #include "webrtc/base/checks.h" #include "webrtc/modules/video_coding/codecs/vp8/temporal_layers.h" #include "webrtc/modules/video_coding/include/video_codec_interface.h" @@ -126,7 +127,7 @@ class VideoEncoderSoftwareFallbackWrapperTest : public ::testing::Test { void VideoEncoderSoftwareFallbackWrapperTest::EncodeFrame() { rtc::scoped_refptr buffer = I420Buffer::Create( kWidth, kHeight, kWidth, (kWidth + 1) / 2, (kWidth + 1) / 2); - buffer->SetToBlack(); + I420Buffer::SetBlack(buffer); std::vector types(1, kVideoFrameKey); frame_.reset(new VideoFrame(buffer, 0, 0, webrtc::kVideoRotation_0)); diff --git a/webrtc/media/engine/webrtcvideoengine2.cc b/webrtc/media/engine/webrtcvideoengine2.cc index 202f0c26fa..e43cb7e6e2 100644 --- a/webrtc/media/engine/webrtcvideoengine2.cc +++ b/webrtc/media/engine/webrtcvideoengine2.cc @@ -16,6 +16,7 @@ #include #include +#include "webrtc/api/video/i420_buffer.h" #include "webrtc/base/copyonwritebuffer.h" #include "webrtc/base/logging.h" #include "webrtc/base/stringutils.h" @@ -1680,7 +1681,7 @@ bool WebRtcVideoChannel2::WebRtcVideoSendStream::SetVideoSend( rtc::scoped_refptr black_buffer( webrtc::I420Buffer::Create(last_frame_info_.width, last_frame_info_.height)); - black_buffer->SetToBlack(); + webrtc::I420Buffer::SetBlack(black_buffer); encoder_sink_->OnFrame(webrtc::VideoFrame( black_buffer, last_frame_info_.rotation, last_frame_timestamp_us_)); diff --git a/webrtc/media/engine/webrtcvideoengine2.h b/webrtc/media/engine/webrtcvideoengine2.h index c7aeaaee4a..1fb794eece 100644 --- a/webrtc/media/engine/webrtcvideoengine2.h +++ b/webrtc/media/engine/webrtcvideoengine2.h @@ -18,6 +18,7 @@ #include #include "webrtc/api/call/transport.h" +#include "webrtc/api/video/video_frame.h" #include "webrtc/base/asyncinvoker.h" #include "webrtc/base/criticalsection.h" #include "webrtc/base/networkroute.h" @@ -29,7 +30,6 @@ #include "webrtc/media/base/mediaengine.h" #include "webrtc/media/engine/webrtcvideodecoderfactory.h" #include "webrtc/media/engine/webrtcvideoencoderfactory.h" -#include "webrtc/video_frame.h" #include "webrtc/video_receive_stream.h" #include "webrtc/video_send_stream.h" diff --git a/webrtc/media/engine/webrtcvideoengine2_unittest.cc b/webrtc/media/engine/webrtcvideoengine2_unittest.cc index 5944883e1c..8349469669 100644 --- a/webrtc/media/engine/webrtcvideoengine2_unittest.cc +++ b/webrtc/media/engine/webrtcvideoengine2_unittest.cc @@ -84,7 +84,7 @@ rtc::scoped_refptr CreateBlackFrameBuffer( int height) { rtc::scoped_refptr buffer = webrtc::I420Buffer::Create(width, height); - buffer->SetToBlack(); + webrtc::I420Buffer::SetBlack(buffer); return buffer; } diff --git a/webrtc/modules/include/module_common_types.h b/webrtc/modules/include/module_common_types.h index 513411a791..c7854322fd 100644 --- a/webrtc/modules/include/module_common_types.h +++ b/webrtc/modules/include/module_common_types.h @@ -17,11 +17,11 @@ #include #include +#include "webrtc/api/video/video_rotation.h" #include "webrtc/base/constructormagic.h" #include "webrtc/base/deprecation.h" #include "webrtc/base/safe_conversions.h" #include "webrtc/common_types.h" -#include "webrtc/common_video/rotation.h" #include "webrtc/modules/video_coding/codecs/vp8/include/vp8_globals.h" #include "webrtc/modules/video_coding/codecs/vp9/include/vp9_globals.h" #include "webrtc/modules/video_coding/codecs/h264/include/h264_globals.h" diff --git a/webrtc/modules/rtp_rtcp/include/rtp_cvo.h b/webrtc/modules/rtp_rtcp/include/rtp_cvo.h index b60b06e5df..5fa0619947 100644 --- a/webrtc/modules/rtp_rtcp/include/rtp_cvo.h +++ b/webrtc/modules/rtp_rtcp/include/rtp_cvo.h @@ -10,8 +10,8 @@ #ifndef WEBRTC_MODULES_RTP_RTCP_INCLUDE_RTP_CVO_H_ #define WEBRTC_MODULES_RTP_RTCP_INCLUDE_RTP_CVO_H_ +#include "webrtc/api/video/video_rotation.h" #include "webrtc/base/checks.h" -#include "webrtc/common_video/rotation.h" namespace webrtc { diff --git a/webrtc/modules/rtp_rtcp/source/rtp_header_extensions.h b/webrtc/modules/rtp_rtcp/source/rtp_header_extensions.h index 56e4c157cf..ea6f9dbc9c 100644 --- a/webrtc/modules/rtp_rtcp/source/rtp_header_extensions.h +++ b/webrtc/modules/rtp_rtcp/source/rtp_header_extensions.h @@ -12,7 +12,7 @@ #include -#include "webrtc/common_video/rotation.h" +#include "webrtc/api/video/video_rotation.h" #include "webrtc/modules/rtp_rtcp/include/rtp_rtcp_defines.h" namespace webrtc { diff --git a/webrtc/modules/video_capture/test/video_capture_unittest.cc b/webrtc/modules/video_capture/test/video_capture_unittest.cc index 169848867f..d0c3ec9b25 100644 --- a/webrtc/modules/video_capture/test/video_capture_unittest.cc +++ b/webrtc/modules/video_capture/test/video_capture_unittest.cc @@ -14,6 +14,8 @@ #include #include +#include "webrtc/api/video/i420_buffer.h" +#include "webrtc/api/video/video_frame.h" #include "webrtc/base/scoped_ref_ptr.h" #include "webrtc/base/timeutils.h" #include "webrtc/common_video/libyuv/include/webrtc_libyuv.h" @@ -24,7 +26,6 @@ #include "webrtc/system_wrappers/include/sleep.h" #include "webrtc/test/frame_utils.h" #include "webrtc/test/gtest.h" -#include "webrtc/video_frame.h" using webrtc::CriticalSectionWrapper; using webrtc::CriticalSectionScoped; diff --git a/webrtc/modules/video_capture/video_capture.h b/webrtc/modules/video_capture/video_capture.h index dc22e6aeb5..884953b5e1 100644 --- a/webrtc/modules/video_capture/video_capture.h +++ b/webrtc/modules/video_capture/video_capture.h @@ -11,7 +11,7 @@ #ifndef WEBRTC_MODULES_VIDEO_CAPTURE_VIDEO_CAPTURE_H_ #define WEBRTC_MODULES_VIDEO_CAPTURE_VIDEO_CAPTURE_H_ -#include "webrtc/common_video/rotation.h" +#include "webrtc/api/video/video_rotation.h" #include "webrtc/media/base/videosinkinterface.h" #include "webrtc/modules/include/module.h" #include "webrtc/modules/video_capture/video_capture_defines.h" diff --git a/webrtc/modules/video_capture/video_capture_defines.h b/webrtc/modules/video_capture/video_capture_defines.h index 5124d745ac..261ee67750 100644 --- a/webrtc/modules/video_capture/video_capture_defines.h +++ b/webrtc/modules/video_capture/video_capture_defines.h @@ -11,9 +11,9 @@ #ifndef WEBRTC_MODULES_VIDEO_CAPTURE_VIDEO_CAPTURE_DEFINES_H_ #define WEBRTC_MODULES_VIDEO_CAPTURE_VIDEO_CAPTURE_DEFINES_H_ +#include "webrtc/api/video/video_frame.h" #include "webrtc/modules/include/module_common_types.h" #include "webrtc/typedefs.h" -#include "webrtc/video_frame.h" namespace webrtc { diff --git a/webrtc/modules/video_capture/video_capture_impl.cc b/webrtc/modules/video_capture/video_capture_impl.cc index e3c78f18ef..fe0906e639 100644 --- a/webrtc/modules/video_capture/video_capture_impl.cc +++ b/webrtc/modules/video_capture/video_capture_impl.cc @@ -12,6 +12,7 @@ #include +#include "webrtc/api/video/i420_buffer.h" #include "webrtc/base/refcount.h" #include "webrtc/base/timeutils.h" #include "webrtc/base/trace_event.h" diff --git a/webrtc/modules/video_capture/video_capture_impl.h b/webrtc/modules/video_capture/video_capture_impl.h index a507450fb1..6083726a67 100644 --- a/webrtc/modules/video_capture/video_capture_impl.h +++ b/webrtc/modules/video_capture/video_capture_impl.h @@ -15,12 +15,11 @@ * video_capture_impl.h */ +#include "webrtc/api/video/video_frame.h" #include "webrtc/base/scoped_ref_ptr.h" #include "webrtc/common_video/libyuv/include/webrtc_libyuv.h" -#include "webrtc/common_video/rotation.h" #include "webrtc/modules/video_capture/video_capture.h" #include "webrtc/modules/video_capture/video_capture_config.h" -#include "webrtc/video_frame.h" namespace webrtc { diff --git a/webrtc/modules/video_coding/codecs/h264/h264_decoder_impl.cc b/webrtc/modules/video_coding/codecs/h264/h264_decoder_impl.cc index d67a43420c..c26b94c04d 100644 --- a/webrtc/modules/video_coding/codecs/h264/h264_decoder_impl.cc +++ b/webrtc/modules/video_coding/codecs/h264/h264_decoder_impl.cc @@ -20,10 +20,12 @@ extern "C" { #include "third_party/ffmpeg/libavutil/imgutils.h" } // extern "C" +#include "webrtc/api/video/i420_buffer.h" #include "webrtc/base/checks.h" #include "webrtc/base/criticalsection.h" #include "webrtc/base/keep_ref_until_done.h" #include "webrtc/base/logging.h" +#include "webrtc/common_video/include/video_frame_buffer.h" #include "webrtc/system_wrappers/include/metrics.h" namespace webrtc { diff --git a/webrtc/modules/video_coding/codecs/i420/i420.cc b/webrtc/modules/video_coding/codecs/i420/i420.cc index ad4a8a1a40..d05ba7f519 100644 --- a/webrtc/modules/video_coding/codecs/i420/i420.cc +++ b/webrtc/modules/video_coding/codecs/i420/i420.cc @@ -13,6 +13,7 @@ #include #include +#include "webrtc/api/video/i420_buffer.h" #include "webrtc/common_video/libyuv/include/webrtc_libyuv.h" namespace { diff --git a/webrtc/modules/video_coding/codecs/interface/video_codec_interface.h b/webrtc/modules/video_coding/codecs/interface/video_codec_interface.h index 6bcfa909bd..98b504041b 100644 --- a/webrtc/modules/video_coding/codecs/interface/video_codec_interface.h +++ b/webrtc/modules/video_coding/codecs/interface/video_codec_interface.h @@ -15,13 +15,13 @@ "use video_coding/include") #include +#include "webrtc/api/video/video_frame.h" #include "webrtc/common_types.h" #include "webrtc/modules/include/module_common_types.h" #include "webrtc/modules/video_coding/include/video_error_codes.h" #include "webrtc/typedefs.h" #include "webrtc/video_decoder.h" #include "webrtc/video_encoder.h" -#include "webrtc/video_frame.h" namespace webrtc { diff --git a/webrtc/modules/video_coding/codecs/test/videoprocessor.cc b/webrtc/modules/video_coding/codecs/test/videoprocessor.cc index 63f0a87150..53f5f16f50 100644 --- a/webrtc/modules/video_coding/codecs/test/videoprocessor.cc +++ b/webrtc/modules/video_coding/codecs/test/videoprocessor.cc @@ -17,6 +17,7 @@ #include #include +#include "webrtc/api/video/i420_buffer.h" #include "webrtc/base/checks.h" #include "webrtc/base/timeutils.h" #include "webrtc/modules/video_coding/include/video_codec_initializer.h" diff --git a/webrtc/modules/video_coding/codecs/test/videoprocessor.h b/webrtc/modules/video_coding/codecs/test/videoprocessor.h index f87ccc5f23..a217b1132e 100644 --- a/webrtc/modules/video_coding/codecs/test/videoprocessor.h +++ b/webrtc/modules/video_coding/codecs/test/videoprocessor.h @@ -14,6 +14,7 @@ #include #include +#include "webrtc/api/video/video_frame.h" #include "webrtc/base/checks.h" #include "webrtc/common_video/libyuv/include/webrtc_libyuv.h" #include "webrtc/modules/video_coding/include/video_codec_interface.h" @@ -21,7 +22,6 @@ #include "webrtc/modules/video_coding/codecs/test/stats.h" #include "webrtc/test/testsupport/frame_reader.h" #include "webrtc/test/testsupport/frame_writer.h" -#include "webrtc/video_frame.h" namespace webrtc { diff --git a/webrtc/modules/video_coding/codecs/test/videoprocessor_unittest.cc b/webrtc/modules/video_coding/codecs/test/videoprocessor_unittest.cc index 9d6e5762a4..9846fbcfde 100644 --- a/webrtc/modules/video_coding/codecs/test/videoprocessor_unittest.cc +++ b/webrtc/modules/video_coding/codecs/test/videoprocessor_unittest.cc @@ -8,6 +8,7 @@ * be found in the AUTHORS file in the root of the source tree. */ +#include "webrtc/api/video/i420_buffer.h" #include "webrtc/modules/video_coding/codecs/test/mock/mock_packet_manipulator.h" #include "webrtc/modules/video_coding/codecs/test/videoprocessor.h" #include "webrtc/modules/video_coding/include/mock/mock_video_codec_interface.h" diff --git a/webrtc/modules/video_coding/codecs/vp8/simulcast_encoder_adapter.cc b/webrtc/modules/video_coding/codecs/vp8/simulcast_encoder_adapter.cc index bbb3f0985c..ae1151162a 100644 --- a/webrtc/modules/video_coding/codecs/vp8/simulcast_encoder_adapter.cc +++ b/webrtc/modules/video_coding/codecs/vp8/simulcast_encoder_adapter.cc @@ -15,6 +15,7 @@ // NOTE(ajm): Path provided by gyp. #include "libyuv/scale.h" // NOLINT +#include "webrtc/api/video/i420_buffer.h" #include "webrtc/base/checks.h" #include "webrtc/modules/video_coding/codecs/vp8/screenshare_layers.h" #include "webrtc/modules/video_coding/utility/simulcast_rate_allocator.h" diff --git a/webrtc/modules/video_coding/codecs/vp8/simulcast_encoder_adapter_unittest.cc b/webrtc/modules/video_coding/codecs/vp8/simulcast_encoder_adapter_unittest.cc index e95ecf5d91..2b1035fca1 100644 --- a/webrtc/modules/video_coding/codecs/vp8/simulcast_encoder_adapter_unittest.cc +++ b/webrtc/modules/video_coding/codecs/vp8/simulcast_encoder_adapter_unittest.cc @@ -11,6 +11,7 @@ #include #include +#include "webrtc/common_video/include/video_frame_buffer.h" #include "webrtc/modules/video_coding/codecs/vp8/simulcast_encoder_adapter.h" #include "webrtc/modules/video_coding/codecs/vp8/simulcast_unittest.h" #include "webrtc/modules/video_coding/include/video_codec_interface.h" @@ -502,6 +503,7 @@ TEST_F(TestSimulcastEncoderAdapterFake, EXPECT_TRUE(adapter_->SupportsNativeHandle()); } +// TODO(nisse): Reuse definition in webrtc/test/fake_texture_handle.h. class FakeNativeHandleBuffer : public NativeHandleBuffer { public: FakeNativeHandleBuffer(void* native_handle, int width, int height) diff --git a/webrtc/modules/video_coding/codecs/vp8/simulcast_unittest.h b/webrtc/modules/video_coding/codecs/vp8/simulcast_unittest.h index 1740153252..d140b0a529 100644 --- a/webrtc/modules/video_coding/codecs/vp8/simulcast_unittest.h +++ b/webrtc/modules/video_coding/codecs/vp8/simulcast_unittest.h @@ -16,6 +16,8 @@ #include #include +#include "webrtc/api/video/i420_buffer.h" +#include "webrtc/api/video/video_frame.h" #include "webrtc/base/checks.h" #include "webrtc/common_video/libyuv/include/webrtc_libyuv.h" #include "webrtc/modules/video_coding/codecs/vp8/include/vp8.h" diff --git a/webrtc/modules/video_coding/codecs/vp8/test/vp8_impl_unittest.cc b/webrtc/modules/video_coding/codecs/vp8/test/vp8_impl_unittest.cc index 5bcbb9b1b3..de612f0404 100644 --- a/webrtc/modules/video_coding/codecs/vp8/test/vp8_impl_unittest.cc +++ b/webrtc/modules/video_coding/codecs/vp8/test/vp8_impl_unittest.cc @@ -12,6 +12,7 @@ #include +#include "webrtc/api/video/i420_buffer.h" #include "webrtc/base/checks.h" #include "webrtc/base/optional.h" #include "webrtc/base/timeutils.h" diff --git a/webrtc/modules/video_coding/codecs/vp8/vp8_impl.h b/webrtc/modules/video_coding/codecs/vp8/vp8_impl.h index 10977b1d8a..d24dfa36a2 100644 --- a/webrtc/modules/video_coding/codecs/vp8/vp8_impl.h +++ b/webrtc/modules/video_coding/codecs/vp8/vp8_impl.h @@ -23,6 +23,7 @@ #include "vpx/vp8cx.h" #include "vpx/vp8dx.h" +#include "webrtc/api/video/video_frame.h" #include "webrtc/common_video/include/i420_buffer_pool.h" #include "webrtc/modules/video_coding/include/video_codec_interface.h" #include "webrtc/modules/video_coding/codecs/vp8/include/vp8.h" diff --git a/webrtc/modules/video_coding/codecs/vp8/vp8_sequence_coder.cc b/webrtc/modules/video_coding/codecs/vp8/vp8_sequence_coder.cc index 857976d5d2..41a94d53b0 100644 --- a/webrtc/modules/video_coding/codecs/vp8/vp8_sequence_coder.cc +++ b/webrtc/modules/video_coding/codecs/vp8/vp8_sequence_coder.cc @@ -10,6 +10,7 @@ #include +#include "webrtc/api/video/video_frame.h" #include "webrtc/base/checks.h" #include "webrtc/base/timeutils.h" #include "webrtc/common_video/include/video_image.h" diff --git a/webrtc/modules/video_coding/codecs/vp9/vp9_impl.cc b/webrtc/modules/video_coding/codecs/vp9/vp9_impl.cc index 4559d4a6c6..47ca8726b0 100644 --- a/webrtc/modules/video_coding/codecs/vp9/vp9_impl.cc +++ b/webrtc/modules/video_coding/codecs/vp9/vp9_impl.cc @@ -26,6 +26,7 @@ #include "webrtc/base/keep_ref_until_done.h" #include "webrtc/base/logging.h" #include "webrtc/base/trace_event.h" +#include "webrtc/common_video/include/video_frame_buffer.h" #include "webrtc/common_video/libyuv/include/webrtc_libyuv.h" #include "webrtc/modules/include/module_common_types.h" #include "webrtc/modules/video_coding/codecs/vp9/screenshare_layers.h" diff --git a/webrtc/modules/video_coding/generic_encoder.cc b/webrtc/modules/video_coding/generic_encoder.cc index 1786e72ea2..41f2cad6ff 100644 --- a/webrtc/modules/video_coding/generic_encoder.cc +++ b/webrtc/modules/video_coding/generic_encoder.cc @@ -12,6 +12,7 @@ #include +#include "webrtc/api/video/i420_buffer.h" #include "webrtc/base/checks.h" #include "webrtc/base/logging.h" #include "webrtc/base/trace_event.h" diff --git a/webrtc/modules/video_coding/include/video_codec_interface.h b/webrtc/modules/video_coding/include/video_codec_interface.h index 5dcfaffadb..306fbef632 100644 --- a/webrtc/modules/video_coding/include/video_codec_interface.h +++ b/webrtc/modules/video_coding/include/video_codec_interface.h @@ -13,13 +13,13 @@ #include +#include "webrtc/api/video/video_frame.h" #include "webrtc/common_types.h" #include "webrtc/modules/include/module_common_types.h" #include "webrtc/modules/video_coding/include/video_error_codes.h" #include "webrtc/typedefs.h" #include "webrtc/video_decoder.h" #include "webrtc/video_encoder.h" -#include "webrtc/video_frame.h" namespace webrtc { diff --git a/webrtc/modules/video_coding/include/video_coding.h b/webrtc/modules/video_coding/include/video_coding.h index 7b6bd32416..f7f66a7240 100644 --- a/webrtc/modules/video_coding/include/video_coding.h +++ b/webrtc/modules/video_coding/include/video_coding.h @@ -21,11 +21,11 @@ #include #endif +#include "webrtc/api/video/video_frame.h" #include "webrtc/modules/include/module.h" #include "webrtc/modules/include/module_common_types.h" #include "webrtc/modules/video_coding/include/video_coding_defines.h" #include "webrtc/system_wrappers/include/event_wrapper.h" -#include "webrtc/video_frame.h" namespace webrtc { diff --git a/webrtc/modules/video_coding/include/video_coding_defines.h b/webrtc/modules/video_coding/include/video_coding_defines.h index 4657804896..122ddc6315 100644 --- a/webrtc/modules/video_coding/include/video_coding_defines.h +++ b/webrtc/modules/video_coding/include/video_coding_defines.h @@ -14,8 +14,10 @@ #include #include +#include "webrtc/api/video/video_frame.h" #include "webrtc/modules/include/module_common_types.h" #include "webrtc/typedefs.h" +// For EncodedImage #include "webrtc/video_frame.h" namespace webrtc { diff --git a/webrtc/modules/video_coding/video_sender_unittest.cc b/webrtc/modules/video_coding/video_sender_unittest.cc index a670d8f48f..f0246ca673 100644 --- a/webrtc/modules/video_coding/video_sender_unittest.cc +++ b/webrtc/modules/video_coding/video_sender_unittest.cc @@ -11,6 +11,7 @@ #include #include +#include "webrtc/api/video/i420_buffer.h" #include "webrtc/modules/video_coding/codecs/vp8/include/vp8.h" #include "webrtc/modules/video_coding/codecs/vp8/include/vp8_common_types.h" #include "webrtc/modules/video_coding/codecs/vp8/temporal_layers.h" diff --git a/webrtc/sdk/android/src/jni/native_handle_impl.h b/webrtc/sdk/android/src/jni/native_handle_impl.h index d8fb153d38..6829b7ba56 100644 --- a/webrtc/sdk/android/src/jni/native_handle_impl.h +++ b/webrtc/sdk/android/src/jni/native_handle_impl.h @@ -13,8 +13,8 @@ #include +#include "webrtc/api/video/video_rotation.h" #include "webrtc/common_video/include/video_frame_buffer.h" -#include "webrtc/common_video/rotation.h" namespace webrtc_jni { diff --git a/webrtc/sdk/android/src/jni/surfacetexturehelper_jni.h b/webrtc/sdk/android/src/jni/surfacetexturehelper_jni.h index deea41475e..07d65c0143 100644 --- a/webrtc/sdk/android/src/jni/surfacetexturehelper_jni.h +++ b/webrtc/sdk/android/src/jni/surfacetexturehelper_jni.h @@ -15,9 +15,9 @@ #include "webrtc/sdk/android/src/jni/jni_helpers.h" #include "webrtc/sdk/android/src/jni/native_handle_impl.h" +#include "webrtc/api/video/video_frame_buffer.h" #include "webrtc/base/refcount.h" #include "webrtc/base/scoped_ref_ptr.h" -#include "webrtc/common_video/include/video_frame_buffer.h" namespace webrtc_jni { diff --git a/webrtc/sdk/objc/Framework/Classes/RTCI420Shader.mm b/webrtc/sdk/objc/Framework/Classes/RTCI420Shader.mm index e0c9642269..d325840cf5 100644 --- a/webrtc/sdk/objc/Framework/Classes/RTCI420Shader.mm +++ b/webrtc/sdk/objc/Framework/Classes/RTCI420Shader.mm @@ -15,8 +15,8 @@ #import "RTCShader+Private.h" #import "WebRTC/RTCVideoFrame.h" +#include "webrtc/api/video/video_rotation.h" #include "webrtc/base/optional.h" -#include "webrtc/common_video/rotation.h" // |kNumTextures| must not exceed 8, which is the limit in OpenGLES2. Two sets // of 3 textures are used here, one for each of the Y, U and V planes. Having diff --git a/webrtc/sdk/objc/Framework/Classes/RTCNativeNV12Shader.mm b/webrtc/sdk/objc/Framework/Classes/RTCNativeNV12Shader.mm index 75a575b075..5000dbc2fa 100644 --- a/webrtc/sdk/objc/Framework/Classes/RTCNativeNV12Shader.mm +++ b/webrtc/sdk/objc/Framework/Classes/RTCNativeNV12Shader.mm @@ -19,9 +19,9 @@ #import "RTCShader+Private.h" #import "WebRTC/RTCVideoFrame.h" +#include "webrtc/api/video/video_rotation.h" #include "webrtc/base/checks.h" #include "webrtc/base/optional.h" -#include "webrtc/common_video/rotation.h" static const char kNV12FragmentShaderSource[] = SHADER_VERSION diff --git a/webrtc/sdk/objc/Framework/Classes/RTCShader+Private.h b/webrtc/sdk/objc/Framework/Classes/RTCShader+Private.h index 547d26235d..ea0f787fc8 100644 --- a/webrtc/sdk/objc/Framework/Classes/RTCShader+Private.h +++ b/webrtc/sdk/objc/Framework/Classes/RTCShader+Private.h @@ -18,7 +18,7 @@ #import #endif -#include "webrtc/common_video/rotation.h" +#include "webrtc/api/video/video_rotation.h" RTC_EXTERN const char kRTCVertexShaderSource[]; diff --git a/webrtc/sdk/objc/Framework/Classes/RTCVideoFrame+Private.h b/webrtc/sdk/objc/Framework/Classes/RTCVideoFrame+Private.h index b47ee4b465..e844d64790 100644 --- a/webrtc/sdk/objc/Framework/Classes/RTCVideoFrame+Private.h +++ b/webrtc/sdk/objc/Framework/Classes/RTCVideoFrame+Private.h @@ -10,8 +10,8 @@ #import "WebRTC/RTCVideoFrame.h" -#include "webrtc/common_video/include/video_frame_buffer.h" -#include "webrtc/common_video/rotation.h" +#include "webrtc/api/video/video_frame_buffer.h" +#include "webrtc/api/video/video_rotation.h" NS_ASSUME_NONNULL_BEGIN diff --git a/webrtc/sdk/objc/Framework/Classes/RTCVideoFrame.mm b/webrtc/sdk/objc/Framework/Classes/RTCVideoFrame.mm index 4b2b75415f..5805e30cb5 100644 --- a/webrtc/sdk/objc/Framework/Classes/RTCVideoFrame.mm +++ b/webrtc/sdk/objc/Framework/Classes/RTCVideoFrame.mm @@ -12,7 +12,7 @@ #include -#include "webrtc/common_video/rotation.h" +#include "webrtc/api/video/video_rotation.h" @implementation RTCVideoFrame { rtc::scoped_refptr _videoBuffer; diff --git a/webrtc/sdk/objc/Framework/Classes/avfoundationvideocapturer.h b/webrtc/sdk/objc/Framework/Classes/avfoundationvideocapturer.h index 8bf949b36f..6253405ac9 100644 --- a/webrtc/sdk/objc/Framework/Classes/avfoundationvideocapturer.h +++ b/webrtc/sdk/objc/Framework/Classes/avfoundationvideocapturer.h @@ -13,9 +13,9 @@ #import +#include "webrtc/api/video/video_frame.h" #include "webrtc/common_video/include/i420_buffer_pool.h" #include "webrtc/media/base/videocapturer.h" -#include "webrtc/video_frame.h" @class RTCAVFoundationVideoCapturerInternal; diff --git a/webrtc/sdk/objc/Framework/Classes/avfoundationvideocapturer.mm b/webrtc/sdk/objc/Framework/Classes/avfoundationvideocapturer.mm index cecb13cdb9..526cdbe455 100644 --- a/webrtc/sdk/objc/Framework/Classes/avfoundationvideocapturer.mm +++ b/webrtc/sdk/objc/Framework/Classes/avfoundationvideocapturer.mm @@ -17,13 +17,13 @@ #import "WebRTC/RTCLogging.h" #include "avfoundationformatmapper.h" -#include "libyuv/rotate.h" + +#include "webrtc/api/video/video_rotation.h" #include "webrtc/base/bind.h" #include "webrtc/base/checks.h" #include "webrtc/base/logging.h" #include "webrtc/base/thread.h" #include "webrtc/common_video/include/corevideo_frame_buffer.h" -#include "webrtc/common_video/rotation.h" namespace webrtc { @@ -160,25 +160,12 @@ void AVFoundationVideoCapturer::CaptureSampleBuffer( // Applying rotation is only supported for legacy reasons and performance is // not critical here. if (apply_rotation() && rotation != kVideoRotation_0) { - buffer = buffer->NativeToI420Buffer(); - rtc::scoped_refptr rotated_buffer; - if (rotation == kVideoRotation_0 || rotation == kVideoRotation_180) { - rotated_buffer = I420Buffer::Create(adapted_width, adapted_height); - } else { - // Swap width and height. - rotated_buffer = I420Buffer::Create(adapted_height, adapted_width); + buffer = I420Buffer::Rotate(buffer->NativeToI420Buffer(), + rotation); + if (rotation == kVideoRotation_90 || rotation == kVideoRotation_270) { std::swap(captured_width, captured_height); } - libyuv::I420Rotate( - buffer->DataY(), buffer->StrideY(), - buffer->DataU(), buffer->StrideU(), - buffer->DataV(), buffer->StrideV(), - rotated_buffer->MutableDataY(), rotated_buffer->StrideY(), - rotated_buffer->MutableDataU(), rotated_buffer->StrideU(), - rotated_buffer->MutableDataV(), rotated_buffer->StrideV(), - buffer->width(), buffer->height(), - static_cast(rotation)); - buffer = rotated_buffer; + rotation = kVideoRotation_0; } diff --git a/webrtc/sdk/objc/Framework/Classes/h264_video_toolbox_decoder.cc b/webrtc/sdk/objc/Framework/Classes/h264_video_toolbox_decoder.cc index 31c8baf167..2507027689 100644 --- a/webrtc/sdk/objc/Framework/Classes/h264_video_toolbox_decoder.cc +++ b/webrtc/sdk/objc/Framework/Classes/h264_video_toolbox_decoder.cc @@ -17,6 +17,7 @@ #include "RTCUIApplication.h" #endif #include "libyuv/convert.h" +#include "webrtc/api/video/video_frame.h" #include "webrtc/base/checks.h" #include "webrtc/base/logging.h" #include "webrtc/common_video/include/corevideo_frame_buffer.h" diff --git a/webrtc/sdk/objc/Framework/Classes/h264_video_toolbox_encoder.h b/webrtc/sdk/objc/Framework/Classes/h264_video_toolbox_encoder.h index 1cfad21cd0..5de9a242df 100644 --- a/webrtc/sdk/objc/Framework/Classes/h264_video_toolbox_encoder.h +++ b/webrtc/sdk/objc/Framework/Classes/h264_video_toolbox_encoder.h @@ -12,10 +12,10 @@ #ifndef WEBRTC_SDK_OBJC_FRAMEWORK_CLASSES_H264_VIDEO_TOOLBOX_ENCODER_H_ #define WEBRTC_SDK_OBJC_FRAMEWORK_CLASSES_H264_VIDEO_TOOLBOX_ENCODER_H_ +#include "webrtc/api/video/video_rotation.h" #include "webrtc/base/criticalsection.h" #include "webrtc/common_video/h264/h264_bitstream_parser.h" #include "webrtc/common_video/include/bitrate_adjuster.h" -#include "webrtc/common_video/rotation.h" #include "webrtc/media/base/codec.h" #include "webrtc/modules/video_coding/codecs/h264/include/h264.h" #include "webrtc/modules/video_coding/utility/quality_scaler.h" diff --git a/webrtc/test/fake_decoder.cc b/webrtc/test/fake_decoder.cc index 4a35e78921..25f80779e2 100644 --- a/webrtc/test/fake_decoder.cc +++ b/webrtc/test/fake_decoder.cc @@ -10,6 +10,8 @@ #include "webrtc/test/fake_decoder.h" +#include "webrtc/api/video/i420_buffer.h" +#include "webrtc/base/timeutils.h" #include "webrtc/test/gtest.h" namespace webrtc { diff --git a/webrtc/test/fake_texture_frame.h b/webrtc/test/fake_texture_frame.h index 5e7571d87b..c857f48343 100644 --- a/webrtc/test/fake_texture_frame.h +++ b/webrtc/test/fake_texture_frame.h @@ -10,9 +10,9 @@ #ifndef WEBRTC_TEST_FAKE_TEXTURE_FRAME_H_ #define WEBRTC_TEST_FAKE_TEXTURE_FRAME_H_ +#include "webrtc/api/video/video_frame.h" #include "webrtc/base/checks.h" #include "webrtc/common_video/include/video_frame_buffer.h" -#include "webrtc/video_frame.h" namespace webrtc { namespace test { @@ -39,11 +39,7 @@ class FakeNativeHandleBuffer : public NativeHandleBuffer { private: rtc::scoped_refptr NativeToI420Buffer() override { rtc::scoped_refptr buffer = I420Buffer::Create(width_, height_); - int half_height = (height_ + 1) / 2; - int half_width = (width_ + 1) / 2; - memset(buffer->MutableDataY(), 0, height_ * width_); - memset(buffer->MutableDataU(), 0, half_height * half_width); - memset(buffer->MutableDataV(), 0, half_height * half_width); + I420Buffer::SetBlack(buffer); return buffer; } }; diff --git a/webrtc/test/fake_videorenderer.h b/webrtc/test/fake_videorenderer.h index ff43fc09e4..6a4015de58 100644 --- a/webrtc/test/fake_videorenderer.h +++ b/webrtc/test/fake_videorenderer.h @@ -11,8 +11,8 @@ #ifndef WEBRTC_TEST_FAKE_VIDEORENDERER_H_ #define WEBRTC_TEST_FAKE_VIDEORENDERER_H_ +#include "webrtc/api/video/video_frame.h" #include "webrtc/media/base/videosinkinterface.h" -#include "webrtc/video_frame.h" namespace webrtc { namespace test { diff --git a/webrtc/test/frame_generator.cc b/webrtc/test/frame_generator.cc index 6ba06cf972..6ed98f5ac0 100644 --- a/webrtc/test/frame_generator.cc +++ b/webrtc/test/frame_generator.cc @@ -15,8 +15,10 @@ #include +#include "webrtc/api/video/i420_buffer.h" #include "webrtc/base/checks.h" #include "webrtc/base/keep_ref_until_done.h" +#include "webrtc/common_video/include/video_frame_buffer.h" #include "webrtc/common_video/libyuv/include/webrtc_libyuv.h" #include "webrtc/system_wrappers/include/clock.h" #include "webrtc/test/frame_utils.h" diff --git a/webrtc/test/frame_generator.h b/webrtc/test/frame_generator.h index 9a643f8161..cea3dda1c2 100644 --- a/webrtc/test/frame_generator.h +++ b/webrtc/test/frame_generator.h @@ -13,10 +13,10 @@ #include #include +#include "webrtc/api/video/video_frame.h" #include "webrtc/base/criticalsection.h" #include "webrtc/media/base/videosourceinterface.h" #include "webrtc/typedefs.h" -#include "webrtc/video_frame.h" namespace webrtc { class Clock; diff --git a/webrtc/test/frame_generator_capturer.h b/webrtc/test/frame_generator_capturer.h index 01bc04b688..3a1b6c9151 100644 --- a/webrtc/test/frame_generator_capturer.h +++ b/webrtc/test/frame_generator_capturer.h @@ -13,12 +13,11 @@ #include #include +#include "webrtc/api/video/video_frame.h" #include "webrtc/base/criticalsection.h" #include "webrtc/base/platform_thread.h" -#include "webrtc/common_video/rotation.h" #include "webrtc/test/video_capturer.h" #include "webrtc/typedefs.h" -#include "webrtc/video_frame.h" namespace webrtc { diff --git a/webrtc/test/frame_utils.cc b/webrtc/test/frame_utils.cc index b332b8fb91..6113747c57 100644 --- a/webrtc/test/frame_utils.cc +++ b/webrtc/test/frame_utils.cc @@ -8,8 +8,12 @@ * be found in the AUTHORS file in the root of the source tree. */ +#include +#include + +#include "webrtc/api/video/i420_buffer.h" +#include "webrtc/api/video/video_frame.h" #include "webrtc/test/frame_utils.h" -#include "webrtc/video_frame.h" namespace webrtc { namespace test { diff --git a/webrtc/test/testsupport/frame_reader.cc b/webrtc/test/testsupport/frame_reader.cc index dc0d822e9b..2593afd8c8 100644 --- a/webrtc/test/testsupport/frame_reader.cc +++ b/webrtc/test/testsupport/frame_reader.cc @@ -12,9 +12,9 @@ #include +#include "webrtc/api/video/i420_buffer.h" #include "webrtc/test/frame_utils.h" #include "webrtc/test/testsupport/fileutils.h" -#include "webrtc/common_video/include/video_frame_buffer.h" namespace webrtc { namespace test { diff --git a/webrtc/test/testsupport/frame_reader_unittest.cc b/webrtc/test/testsupport/frame_reader_unittest.cc index d0b286e059..58a3245fd4 100644 --- a/webrtc/test/testsupport/frame_reader_unittest.cc +++ b/webrtc/test/testsupport/frame_reader_unittest.cc @@ -10,9 +10,9 @@ #include "webrtc/test/testsupport/frame_reader.h" +#include "webrtc/api/video/i420_buffer.h" #include "webrtc/test/gtest.h" #include "webrtc/test/testsupport/fileutils.h" -#include "webrtc/common_video/include/video_frame_buffer.h" namespace webrtc { namespace test { diff --git a/webrtc/test/testsupport/metrics/video_metrics.cc b/webrtc/test/testsupport/metrics/video_metrics.cc index 3013b61355..289533763c 100644 --- a/webrtc/test/testsupport/metrics/video_metrics.cc +++ b/webrtc/test/testsupport/metrics/video_metrics.cc @@ -16,9 +16,10 @@ #include // min_element, max_element #include +#include "webrtc/api/video/i420_buffer.h" +#include "webrtc/api/video/video_frame.h" #include "webrtc/common_video/libyuv/include/webrtc_libyuv.h" #include "webrtc/test/frame_utils.h" -#include "webrtc/video_frame.h" #include "libyuv/convert.h" namespace webrtc { diff --git a/webrtc/test/video_capturer.h b/webrtc/test/video_capturer.h index 9b761eb2a5..111f986643 100644 --- a/webrtc/test/video_capturer.h +++ b/webrtc/test/video_capturer.h @@ -12,8 +12,8 @@ #include +#include "webrtc/api/video/video_frame.h" #include "webrtc/media/base/videosourceinterface.h" -#include "webrtc/video_frame.h" namespace webrtc { diff --git a/webrtc/video/overuse_frame_detector.cc b/webrtc/video/overuse_frame_detector.cc index f4a9c866e0..ad81fcc085 100644 --- a/webrtc/video/overuse_frame_detector.cc +++ b/webrtc/video/overuse_frame_detector.cc @@ -17,12 +17,12 @@ #include #include +#include "webrtc/api/video/video_frame.h" #include "webrtc/base/analytics/exp_filter.h" #include "webrtc/base/checks.h" #include "webrtc/base/logging.h" #include "webrtc/common_video/include/frame_callback.h" #include "webrtc/system_wrappers/include/clock.h" -#include "webrtc/video_frame.h" #if defined(WEBRTC_MAC) && !defined(WEBRTC_IOS) #include diff --git a/webrtc/video/overuse_frame_detector_unittest.cc b/webrtc/video/overuse_frame_detector_unittest.cc index 6768591f01..2c53f7df3c 100644 --- a/webrtc/video/overuse_frame_detector_unittest.cc +++ b/webrtc/video/overuse_frame_detector_unittest.cc @@ -10,6 +10,7 @@ #include +#include "webrtc/api/video/i420_buffer.h" #include "webrtc/base/event.h" #include "webrtc/system_wrappers/include/clock.h" #include "webrtc/test/gmock.h" diff --git a/webrtc/video/vie_encoder.h b/webrtc/video/vie_encoder.h index c086644e14..b81bf5b8d7 100644 --- a/webrtc/video/vie_encoder.h +++ b/webrtc/video/vie_encoder.h @@ -15,6 +15,7 @@ #include #include +#include "webrtc/api/video/video_rotation.h" #include "webrtc/base/criticalsection.h" #include "webrtc/base/event.h" #include "webrtc/base/sequenced_task_checker.h" @@ -22,7 +23,6 @@ #include "webrtc/call/call.h" #include "webrtc/common_types.h" #include "webrtc/common_video/include/video_bitrate_allocator.h" -#include "webrtc/common_video/rotation.h" #include "webrtc/media/base/videosinkinterface.h" #include "webrtc/modules/video_coding/include/video_coding_defines.h" #include "webrtc/modules/video_coding/utility/quality_scaler.h" diff --git a/webrtc/video/vie_encoder_unittest.cc b/webrtc/video/vie_encoder_unittest.cc index 7dd59212e0..c42825d05c 100644 --- a/webrtc/video/vie_encoder_unittest.cc +++ b/webrtc/video/vie_encoder_unittest.cc @@ -11,6 +11,7 @@ #include #include +#include "webrtc/api/video/i420_buffer.h" #include "webrtc/base/logging.h" #include "webrtc/system_wrappers/include/metrics_default.h" #include "webrtc/test/encoder_settings.h" diff --git a/webrtc/video_frame.h b/webrtc/video_frame.h index bec43f80cc..3b0c16c12e 100644 --- a/webrtc/video_frame.h +++ b/webrtc/video_frame.h @@ -11,117 +11,19 @@ #ifndef WEBRTC_VIDEO_FRAME_H_ #define WEBRTC_VIDEO_FRAME_H_ -#include "webrtc/base/scoped_ref_ptr.h" -#include "webrtc/base/timeutils.h" +// TODO(nisse): This header file should eventually be deleted. For +// declarations of classes related to unencoded video frame, use the +// headers under api/video instead. The EncodedImage class stays in +// this file until we have figured out how to refactor and clean up +// related interfaces. + +#include "webrtc/api/video/video_frame.h" +#include "webrtc/api/video/i420_buffer.h" #include "webrtc/common_types.h" -#include "webrtc/common_video/include/video_frame_buffer.h" -#include "webrtc/common_video/rotation.h" #include "webrtc/typedefs.h" namespace webrtc { -class VideoFrame { - public: - // TODO(nisse): This constructor is consistent with - // cricket::WebRtcVideoFrame. After the class - // cricket::WebRtcVideoFrame and its baseclass cricket::VideoFrame - // are deleted, we should consider whether or not we want to stick - // to this style and deprecate the other constructors. - VideoFrame(const rtc::scoped_refptr& buffer, - webrtc::VideoRotation rotation, - int64_t timestamp_us); - - // Preferred constructor. - VideoFrame(const rtc::scoped_refptr& buffer, - uint32_t timestamp, - int64_t render_time_ms, - VideoRotation rotation); - - // Support move and copy. - VideoFrame(const VideoFrame&) = default; - VideoFrame(VideoFrame&&) = default; - VideoFrame& operator=(const VideoFrame&) = default; - VideoFrame& operator=(VideoFrame&&) = default; - - // Get frame width. - int width() const; - - // Get frame height. - int height() const; - - // System monotonic clock, same timebase as rtc::TimeMicros(). - int64_t timestamp_us() const { return timestamp_us_; } - void set_timestamp_us(int64_t timestamp_us) { - timestamp_us_ = timestamp_us; - } - - // TODO(nisse): After the cricket::VideoFrame and webrtc::VideoFrame - // merge, timestamps other than timestamp_us will likely be - // deprecated. - - // Set frame timestamp (90kHz). - void set_timestamp(uint32_t timestamp) { timestamp_rtp_ = timestamp; } - - // Get frame timestamp (90kHz). - uint32_t timestamp() const { return timestamp_rtp_; } - - // For now, transport_frame_id and rtp timestamp are the same. - // TODO(nisse): Must be handled differently for QUIC. - uint32_t transport_frame_id() const { return timestamp(); } - - // Set capture ntp time in milliseconds. - void set_ntp_time_ms(int64_t ntp_time_ms) { - ntp_time_ms_ = ntp_time_ms; - } - - // Get capture ntp time in milliseconds. - int64_t ntp_time_ms() const { return ntp_time_ms_; } - - // Naming convention for Coordination of Video Orientation. Please see - // http://www.etsi.org/deliver/etsi_ts/126100_126199/126114/12.07.00_60/ts_126114v120700p.pdf - // - // "pending rotation" or "pending" = a frame that has a VideoRotation > 0. - // - // "not pending" = a frame that has a VideoRotation == 0. - // - // "apply rotation" = modify a frame from being "pending" to being "not - // pending" rotation (a no-op for "unrotated"). - // - VideoRotation rotation() const { return rotation_; } - void set_rotation(VideoRotation rotation) { - rotation_ = rotation; - } - - // Set render time in milliseconds. - void set_render_time_ms(int64_t render_time_ms) { - set_timestamp_us(render_time_ms * rtc::kNumMicrosecsPerMillisec);; - } - - // Get render time in milliseconds. - int64_t render_time_ms() const { - return timestamp_us() / rtc::kNumMicrosecsPerMillisec; - } - - // Return the underlying buffer. Never nullptr for a properly - // initialized VideoFrame. - rtc::scoped_refptr video_frame_buffer() const; - - // Return true if the frame is stored in a texture. - bool is_texture() const { - return video_frame_buffer() && - video_frame_buffer()->native_handle() != nullptr; - } - - private: - // An opaque reference counted handle that stores the pixel data. - rtc::scoped_refptr video_frame_buffer_; - uint32_t timestamp_rtp_; - int64_t ntp_time_ms_; - int64_t timestamp_us_; - VideoRotation rotation_; -}; - - // TODO(pbos): Rename EncodedFrame and reformat this class' members. class EncodedImage { public: