diff options
Diffstat (limited to 'webrtc/common_video')
21 files changed, 190 insertions, 329 deletions
diff --git a/webrtc/common_video/BUILD.gn b/webrtc/common_video/BUILD.gn index 473c757a75..4ef968d60f 100644 --- a/webrtc/common_video/BUILD.gn +++ b/webrtc/common_video/BUILD.gn @@ -10,7 +10,7 @@ import("../build/webrtc.gni") config("common_video_config") { include_dirs = [ - "interface", + "include", "libyuv/include", ] } @@ -18,10 +18,10 @@ config("common_video_config") { source_set("common_video") { sources = [ "i420_buffer_pool.cc", + "include/i420_buffer_pool.h", + "include/incoming_video_stream.h", + "include/video_frame_buffer.h", "incoming_video_stream.cc", - "interface/i420_buffer_pool.h", - "interface/incoming_video_stream.h", - "interface/video_frame_buffer.h", "libyuv/include/scaler.h", "libyuv/include/webrtc_libyuv.h", "libyuv/scaler.cc", diff --git a/webrtc/common_video/common_video.gyp b/webrtc/common_video/common_video.gyp index 5c0ecb8208..fe14da1d2e 100644 --- a/webrtc/common_video/common_video.gyp +++ b/webrtc/common_video/common_video.gyp @@ -14,7 +14,7 @@ 'type': 'static_library', 'include_dirs': [ '<(webrtc_root)/modules/interface/', - 'interface', + 'include', 'libyuv/include', ], 'dependencies': [ @@ -23,7 +23,7 @@ ], 'direct_dependent_settings': { 'include_dirs': [ - 'interface', + 'include', 'libyuv/include', ], }, @@ -42,9 +42,9 @@ 'i420_buffer_pool.cc', 'video_frame.cc', 'incoming_video_stream.cc', - 'interface/i420_buffer_pool.h', - 'interface/incoming_video_stream.h', - 'interface/video_frame_buffer.h', + 'include/i420_buffer_pool.h', + 'include/incoming_video_stream.h', + 'include/video_frame_buffer.h', 'libyuv/include/scaler.h', 'libyuv/include/webrtc_libyuv.h', 'libyuv/scaler.cc', diff --git a/webrtc/common_video/common_video_unittests.gyp b/webrtc/common_video/common_video_unittests.gyp index beeab5ddca..b5e892caf0 100644 --- a/webrtc/common_video/common_video_unittests.gyp +++ b/webrtc/common_video/common_video_unittests.gyp @@ -17,6 +17,7 @@ '<(DEPTH)/testing/gtest.gyp:gtest', '<(webrtc_root)/system_wrappers/system_wrappers.gyp:system_wrappers', '<(webrtc_root)/test/test.gyp:test_support_main', + '<(webrtc_root)/test/test.gyp:fake_video_frames', ], 'sources': [ 'i420_buffer_pool_unittest.cc', diff --git a/webrtc/common_video/i420_buffer_pool.cc b/webrtc/common_video/i420_buffer_pool.cc index c746666a16..98daec99f6 100644 --- a/webrtc/common_video/i420_buffer_pool.cc +++ b/webrtc/common_video/i420_buffer_pool.cc @@ -8,7 +8,7 @@ * be found in the AUTHORS file in the root of the source tree. */ -#include "webrtc/common_video/interface/i420_buffer_pool.h" +#include "webrtc/common_video/include/i420_buffer_pool.h" #include "webrtc/base/checks.h" diff --git a/webrtc/common_video/i420_buffer_pool_unittest.cc b/webrtc/common_video/i420_buffer_pool_unittest.cc index a1596ebb09..b030ee774a 100644 --- a/webrtc/common_video/i420_buffer_pool_unittest.cc +++ b/webrtc/common_video/i420_buffer_pool_unittest.cc @@ -11,7 +11,7 @@ #include <string> #include "testing/gtest/include/gtest/gtest.h" -#include "webrtc/common_video/interface/i420_buffer_pool.h" +#include "webrtc/common_video/include/i420_buffer_pool.h" namespace webrtc { diff --git a/webrtc/common_video/i420_video_frame_unittest.cc b/webrtc/common_video/i420_video_frame_unittest.cc index da3996b9bd..1ec451cb79 100644 --- a/webrtc/common_video/i420_video_frame_unittest.cc +++ b/webrtc/common_video/i420_video_frame_unittest.cc @@ -8,8 +8,6 @@ * be found in the AUTHORS file in the root of the source tree. */ -#include "webrtc/video_frame.h" - #include <math.h> #include <string.h> @@ -17,6 +15,7 @@ #include "webrtc/base/bind.h" #include "webrtc/base/scoped_ptr.h" #include "webrtc/test/fake_texture_frame.h" +#include "webrtc/video_frame.h" namespace webrtc { @@ -25,7 +24,6 @@ bool EqualPlane(const uint8_t* data1, int stride, int width, int height); -bool EqualFrames(const VideoFrame& frame1, const VideoFrame& frame2); int ExpectedSize(int plane_stride, int image_height, PlaneType type); TEST(TestVideoFrame, InitialValues) { @@ -103,7 +101,7 @@ TEST(TestVideoFrame, CopyFrame) { stride_u, stride_v, kRotation)); // Frame of smaller dimensions. EXPECT_EQ(0, small_frame.CopyFrame(big_frame)); - EXPECT_TRUE(EqualFrames(small_frame, big_frame)); + EXPECT_TRUE(small_frame.EqualsFrame(big_frame)); EXPECT_EQ(kRotation, small_frame.rotation()); // Frame of larger dimensions. @@ -113,7 +111,7 @@ TEST(TestVideoFrame, CopyFrame) { memset(small_frame.buffer(kUPlane), 2, small_frame.allocated_size(kUPlane)); memset(small_frame.buffer(kVPlane), 3, small_frame.allocated_size(kVPlane)); EXPECT_EQ(0, big_frame.CopyFrame(small_frame)); - EXPECT_TRUE(EqualFrames(small_frame, big_frame)); + EXPECT_TRUE(small_frame.EqualsFrame(big_frame)); } TEST(TestVideoFrame, ShallowCopy) { @@ -174,7 +172,7 @@ TEST(TestVideoFrame, ShallowCopy) { TEST(TestVideoFrame, Reset) { VideoFrame frame; - ASSERT_TRUE(frame.CreateEmptyFrame(5, 5, 5, 5, 5) == 0); + ASSERT_EQ(frame.CreateEmptyFrame(5, 5, 5, 5, 5), 0); frame.set_ntp_time_ms(1); frame.set_timestamp(2); frame.set_render_time_ms(3); @@ -244,7 +242,7 @@ TEST(TestVideoFrame, FailToReuseAllocation) { TEST(TestVideoFrame, TextureInitialValues) { test::FakeNativeHandle* handle = new test::FakeNativeHandle(); - VideoFrame frame = test::CreateFakeNativeHandleFrame( + VideoFrame frame = test::FakeNativeHandle::CreateFrame( handle, 640, 480, 100, 10, webrtc::kVideoRotation_0); EXPECT_EQ(640, frame.width()); EXPECT_EQ(480, frame.height()); @@ -258,48 +256,4 @@ TEST(TestVideoFrame, TextureInitialValues) { EXPECT_EQ(20, frame.render_time_ms()); } -bool EqualPlane(const uint8_t* data1, - const uint8_t* data2, - int stride, - int width, - int height) { - for (int y = 0; y < height; ++y) { - if (memcmp(data1, data2, width) != 0) - return false; - data1 += stride; - data2 += stride; - } - return true; -} - -bool EqualFrames(const VideoFrame& frame1, const VideoFrame& frame2) { - if ((frame1.width() != frame2.width()) || - (frame1.height() != frame2.height()) || - (frame1.stride(kYPlane) != frame2.stride(kYPlane)) || - (frame1.stride(kUPlane) != frame2.stride(kUPlane)) || - (frame1.stride(kVPlane) != frame2.stride(kVPlane)) || - (frame1.timestamp() != frame2.timestamp()) || - (frame1.ntp_time_ms() != frame2.ntp_time_ms()) || - (frame1.render_time_ms() != frame2.render_time_ms())) { - return false; - } - const int half_width = (frame1.width() + 1) / 2; - const int half_height = (frame1.height() + 1) / 2; - return EqualPlane(frame1.buffer(kYPlane), frame2.buffer(kYPlane), - frame1.stride(kYPlane), frame1.width(), frame1.height()) && - EqualPlane(frame1.buffer(kUPlane), frame2.buffer(kUPlane), - frame1.stride(kUPlane), half_width, half_height) && - EqualPlane(frame1.buffer(kVPlane), frame2.buffer(kVPlane), - frame1.stride(kVPlane), half_width, half_height); -} - -int ExpectedSize(int plane_stride, int image_height, PlaneType type) { - if (type == kYPlane) { - return (plane_stride * image_height); - } else { - int half_height = (image_height + 1) / 2; - return (plane_stride * half_height); - } -} - } // namespace webrtc diff --git a/webrtc/common_video/interface/i420_buffer_pool.h b/webrtc/common_video/include/i420_buffer_pool.h index df862cdba5..5ab1510689 100644 --- a/webrtc/common_video/interface/i420_buffer_pool.h +++ b/webrtc/common_video/include/i420_buffer_pool.h @@ -8,13 +8,13 @@ * be found in the AUTHORS file in the root of the source tree. */ -#ifndef WEBRTC_COMMON_VIDEO_INTERFACE_I420_BUFFER_POOL_H_ -#define WEBRTC_COMMON_VIDEO_INTERFACE_I420_BUFFER_POOL_H_ +#ifndef WEBRTC_COMMON_VIDEO_INCLUDE_I420_BUFFER_POOL_H_ +#define WEBRTC_COMMON_VIDEO_INCLUDE_I420_BUFFER_POOL_H_ #include <list> #include "webrtc/base/thread_checker.h" -#include "webrtc/common_video/interface/video_frame_buffer.h" +#include "webrtc/common_video/include/video_frame_buffer.h" namespace webrtc { @@ -40,4 +40,4 @@ class I420BufferPool { } // namespace webrtc -#endif // WEBRTC_COMMON_VIDEO_INTERFACE_I420_BUFFER_POOL_H_ +#endif // WEBRTC_COMMON_VIDEO_INCLUDE_I420_BUFFER_POOL_H_ diff --git a/webrtc/common_video/interface/incoming_video_stream.h b/webrtc/common_video/include/incoming_video_stream.h index 74ecc4e837..e3147eb871 100644 --- a/webrtc/common_video/interface/incoming_video_stream.h +++ b/webrtc/common_video/include/incoming_video_stream.h @@ -8,9 +8,10 @@ * be found in the AUTHORS file in the root of the source tree. */ -#ifndef WEBRTC_COMMON_VIDEO_INTERFACE_INCOMING_VIDEO_STREAM_H_ -#define WEBRTC_COMMON_VIDEO_INTERFACE_INCOMING_VIDEO_STREAM_H_ +#ifndef WEBRTC_COMMON_VIDEO_INCLUDE_INCOMING_VIDEO_STREAM_H_ +#define WEBRTC_COMMON_VIDEO_INCLUDE_INCOMING_VIDEO_STREAM_H_ +#include "webrtc/base/platform_thread.h" #include "webrtc/base/scoped_ptr.h" #include "webrtc/base/thread_annotations.h" #include "webrtc/common_video/video_render_frames.h" @@ -18,7 +19,6 @@ namespace webrtc { class CriticalSectionWrapper; class EventTimerWrapper; -class ThreadWrapper; class VideoRenderCallback { public: @@ -31,7 +31,7 @@ class VideoRenderCallback { class IncomingVideoStream : public VideoRenderCallback { public: - explicit IncomingVideoStream(uint32_t stream_id); + IncomingVideoStream(uint32_t stream_id, bool disable_prerenderer_smoothing); ~IncomingVideoStream(); // Get callback to deliver frames to the module. @@ -72,12 +72,17 @@ class IncomingVideoStream : public VideoRenderCallback { enum { kEventMaxWaitTimeMs = 100 }; enum { kFrameRatePeriodMs = 1000 }; + void DeliverFrame(const VideoFrame& video_frame); + uint32_t const stream_id_; + const bool disable_prerenderer_smoothing_; // Critsects in allowed to enter order. const rtc::scoped_ptr<CriticalSectionWrapper> stream_critsect_; const rtc::scoped_ptr<CriticalSectionWrapper> thread_critsect_; const rtc::scoped_ptr<CriticalSectionWrapper> buffer_critsect_; - rtc::scoped_ptr<ThreadWrapper> incoming_render_thread_ + // TODO(pbos): Make plain member and stop resetting this thread, just + // start/stoping it is enough. + rtc::scoped_ptr<rtc::PlatformThread> incoming_render_thread_ GUARDED_BY(thread_critsect_); rtc::scoped_ptr<EventTimerWrapper> deliver_buffer_event_; @@ -99,4 +104,4 @@ class IncomingVideoStream : public VideoRenderCallback { } // namespace webrtc -#endif // WEBRTC_COMMON_VIDEO_INTERFACE_INCOMING_VIDEO_STREAM_H_ +#endif // WEBRTC_COMMON_VIDEO_INCLUDE_INCOMING_VIDEO_STREAM_H_ diff --git a/webrtc/common_video/interface/video_frame_buffer.h b/webrtc/common_video/include/video_frame_buffer.h index 1062165b81..710d2862f0 100644 --- a/webrtc/common_video/interface/video_frame_buffer.h +++ b/webrtc/common_video/include/video_frame_buffer.h @@ -8,8 +8,8 @@ * be found in the AUTHORS file in the root of the source tree. */ -#ifndef WEBRTC_VIDEO_FRAME_BUFFER_H_ -#define WEBRTC_VIDEO_FRAME_BUFFER_H_ +#ifndef WEBRTC_COMMON_VIDEO_INCLUDE_VIDEO_FRAME_BUFFER_H_ +#define WEBRTC_COMMON_VIDEO_INCLUDE_VIDEO_FRAME_BUFFER_H_ #include "webrtc/base/callback.h" #include "webrtc/base/refcount.h" @@ -154,4 +154,4 @@ rtc::scoped_refptr<VideoFrameBuffer> ShallowCenterCrop( } // namespace webrtc -#endif // WEBRTC_VIDEO_FRAME_BUFFER_H_ +#endif // WEBRTC_COMMON_VIDEO_INCLUDE_VIDEO_FRAME_BUFFER_H_ diff --git a/webrtc/common_video/interface/video_image.h b/webrtc/common_video/include/video_image.h index 4cbf23f1a1..4a6e451c0f 100644 --- a/webrtc/common_video/interface/video_image.h +++ b/webrtc/common_video/include/video_image.h @@ -8,10 +8,10 @@ * be found in the AUTHORS file in the root of the source tree. */ -#ifndef COMMON_VIDEO_INTERFACE_VIDEO_IMAGE_H -#define COMMON_VIDEO_INTERFACE_VIDEO_IMAGE_H +#ifndef WEBRTC_COMMON_VIDEO_INCLUDE_VIDEO_IMAGE_H_ +#define WEBRTC_COMMON_VIDEO_INCLUDE_VIDEO_IMAGE_H_ // TODO(pbos): Remove this file and include webrtc/video_frame.h instead. #include "webrtc/video_frame.h" -#endif // COMMON_VIDEO_INTERFACE_VIDEO_IMAGE_H +#endif // WEBRTC_COMMON_VIDEO_INCLUDE_VIDEO_IMAGE_H_ diff --git a/webrtc/common_video/incoming_video_stream.cc b/webrtc/common_video/incoming_video_stream.cc index 79bbb8a7b6..1272ecc5bb 100644 --- a/webrtc/common_video/incoming_video_stream.cc +++ b/webrtc/common_video/incoming_video_stream.cc @@ -8,7 +8,7 @@ * be found in the AUTHORS file in the root of the source tree. */ -#include "webrtc/common_video/interface/incoming_video_stream.h" +#include "webrtc/common_video/include/incoming_video_stream.h" #include <assert.h> @@ -21,18 +21,21 @@ #include <sys/time.h> #endif +#include "webrtc/base/platform_thread.h" #include "webrtc/common_video/libyuv/include/webrtc_libyuv.h" #include "webrtc/common_video/video_render_frames.h" #include "webrtc/system_wrappers/include/critical_section_wrapper.h" #include "webrtc/system_wrappers/include/event_wrapper.h" -#include "webrtc/system_wrappers/include/thread_wrapper.h" #include "webrtc/system_wrappers/include/tick_util.h" #include "webrtc/system_wrappers/include/trace.h" +#include "webrtc/video_renderer.h" namespace webrtc { -IncomingVideoStream::IncomingVideoStream(uint32_t stream_id) +IncomingVideoStream::IncomingVideoStream(uint32_t stream_id, + bool disable_prerenderer_smoothing) : stream_id_(stream_id), + disable_prerenderer_smoothing_(disable_prerenderer_smoothing), stream_critsect_(CriticalSectionWrapper::CreateCriticalSection()), thread_critsect_(CriticalSectionWrapper::CreateCriticalSection()), buffer_critsect_(CriticalSectionWrapper::CreateCriticalSection()), @@ -49,8 +52,7 @@ IncomingVideoStream::IncomingVideoStream(uint32_t stream_id) temp_frame_(), start_image_(), timeout_image_(), - timeout_time_() { -} + timeout_time_() {} IncomingVideoStream::~IncomingVideoStream() { Stop(); @@ -80,11 +82,15 @@ int32_t IncomingVideoStream::RenderFrame(const uint32_t stream_id, last_rate_calculation_time_ms_ = now_ms; } - // Insert frame. - CriticalSectionScoped csB(buffer_critsect_.get()); - if (render_buffers_->AddFrame(video_frame) == 1) - deliver_buffer_event_->Set(); - + // Hand over or insert frame. + if (disable_prerenderer_smoothing_) { + DeliverFrame(video_frame); + } else { + CriticalSectionScoped csB(buffer_critsect_.get()); + if (render_buffers_->AddFrame(video_frame) == 1) { + deliver_buffer_event_->Set(); + } + } return 0; } @@ -128,21 +134,20 @@ int32_t IncomingVideoStream::Start() { return 0; } - CriticalSectionScoped csT(thread_critsect_.get()); - assert(incoming_render_thread_ == NULL); + if (!disable_prerenderer_smoothing_) { + CriticalSectionScoped csT(thread_critsect_.get()); + assert(incoming_render_thread_ == NULL); - incoming_render_thread_ = ThreadWrapper::CreateThread( - IncomingVideoStreamThreadFun, this, "IncomingVideoStreamThread"); - if (!incoming_render_thread_) { - return -1; - } + incoming_render_thread_.reset(new rtc::PlatformThread( + IncomingVideoStreamThreadFun, this, "IncomingVideoStreamThread")); + if (!incoming_render_thread_) { + return -1; + } - if (incoming_render_thread_->Start()) { - } else { - return -1; + incoming_render_thread_->Start(); + incoming_render_thread_->SetPriority(rtc::kRealtimePriority); + deliver_buffer_event_->StartTimer(false, kEventStartupTimeMs); } - incoming_render_thread_->SetPriority(kRealtimePriority); - deliver_buffer_event_->StartTimer(false, kEventStartupTimeMs); running_ = true; return 0; @@ -155,7 +160,7 @@ int32_t IncomingVideoStream::Stop() { return 0; } - ThreadWrapper* thread = NULL; + rtc::PlatformThread* thread = NULL; { CriticalSectionScoped cs_thread(thread_critsect_.get()); if (incoming_render_thread_) { @@ -169,11 +174,8 @@ int32_t IncomingVideoStream::Stop() { } } if (thread) { - if (thread->Stop()) { - delete thread; - } else { - assert(false); - } + thread->Stop(); + delete thread; } running_ = false; return 0; @@ -205,6 +207,7 @@ bool IncomingVideoStream::IncomingVideoStreamProcess() { // Terminating return false; } + // Get a new frame to render and the time for the frame after this one. VideoFrame frame_to_render; uint32_t wait_time; @@ -220,37 +223,41 @@ bool IncomingVideoStream::IncomingVideoStreamProcess() { } deliver_buffer_event_->StartTimer(false, wait_time); - if (frame_to_render.IsZeroSize()) { - if (render_callback_) { - if (last_render_time_ms_ == 0 && !start_image_.IsZeroSize()) { - // We have not rendered anything and have a start image. - temp_frame_.CopyFrame(start_image_); - render_callback_->RenderFrame(stream_id_, temp_frame_); - } else if (!timeout_image_.IsZeroSize() && - last_render_time_ms_ + timeout_time_ < - TickTime::MillisecondTimestamp()) { - // Render a timeout image. - temp_frame_.CopyFrame(timeout_image_); - render_callback_->RenderFrame(stream_id_, temp_frame_); - } - } + DeliverFrame(frame_to_render); + } + return true; +} - // No frame. - return true; +void IncomingVideoStream::DeliverFrame(const VideoFrame& video_frame) { + CriticalSectionScoped cs(thread_critsect_.get()); + if (video_frame.IsZeroSize()) { + if (render_callback_) { + if (last_render_time_ms_ == 0 && !start_image_.IsZeroSize()) { + // We have not rendered anything and have a start image. + temp_frame_.CopyFrame(start_image_); + render_callback_->RenderFrame(stream_id_, temp_frame_); + } else if (!timeout_image_.IsZeroSize() && + last_render_time_ms_ + timeout_time_ < + TickTime::MillisecondTimestamp()) { + // Render a timeout image. + temp_frame_.CopyFrame(timeout_image_); + render_callback_->RenderFrame(stream_id_, temp_frame_); + } } - // Send frame for rendering. - if (external_callback_) { - external_callback_->RenderFrame(stream_id_, frame_to_render); - } else if (render_callback_) { - render_callback_->RenderFrame(stream_id_, frame_to_render); - } + // No frame. + return; + } - // We're done with this frame. - if (!frame_to_render.IsZeroSize()) - last_render_time_ms_ = frame_to_render.render_time_ms(); + // Send frame for rendering. + if (external_callback_) { + external_callback_->RenderFrame(stream_id_, video_frame); + } else if (render_callback_) { + render_callback_->RenderFrame(stream_id_, video_frame); } - return true; + + // We're done with this frame. + last_render_time_ms_ = video_frame.render_time_ms(); } } // namespace webrtc diff --git a/webrtc/common_video/libyuv/include/scaler.h b/webrtc/common_video/libyuv/include/scaler.h index c04d01f33b..2b92f8148b 100644 --- a/webrtc/common_video/libyuv/include/scaler.h +++ b/webrtc/common_video/libyuv/include/scaler.h @@ -15,7 +15,7 @@ #ifndef WEBRTC_COMMON_VIDEO_LIBYUV_INCLUDE_SCALER_H_ #define WEBRTC_COMMON_VIDEO_LIBYUV_INCLUDE_SCALER_H_ -#include "webrtc/common_video/interface/i420_buffer_pool.h" +#include "webrtc/common_video/include/i420_buffer_pool.h" #include "webrtc/common_video/libyuv/include/webrtc_libyuv.h" #include "webrtc/typedefs.h" #include "webrtc/video_frame.h" diff --git a/webrtc/common_video/libyuv/include/webrtc_libyuv.h b/webrtc/common_video/libyuv/include/webrtc_libyuv.h index baf8c171ad..d66736fb24 100644 --- a/webrtc/common_video/libyuv/include/webrtc_libyuv.h +++ b/webrtc/common_video/libyuv/include/webrtc_libyuv.h @@ -152,6 +152,7 @@ int ConvertNV12ToRGB565(const uint8_t* src_frame, double I420PSNR(const VideoFrame* ref_frame, const VideoFrame* test_frame); // Compute SSIM for an I420 frame (all planes). double I420SSIM(const VideoFrame* ref_frame, const VideoFrame* test_frame); -} + +} // namespace webrtc #endif // WEBRTC_COMMON_VIDEO_LIBYUV_INCLUDE_WEBRTC_LIBYUV_H_ diff --git a/webrtc/common_video/libyuv/libyuv_unittest.cc b/webrtc/common_video/libyuv/libyuv_unittest.cc index b674b51b67..e7cf0759f6 100644 --- a/webrtc/common_video/libyuv/libyuv_unittest.cc +++ b/webrtc/common_video/libyuv/libyuv_unittest.cc @@ -97,7 +97,7 @@ TestLibYuv::TestLibYuv() width_(352), height_(288), size_y_(width_ * height_), - size_uv_(((width_ + 1 ) / 2) * ((height_ + 1) / 2)), + size_uv_(((width_ + 1) / 2) * ((height_ + 1) / 2)), frame_length_(CalcBufferSize(kI420, 352, 288)) { orig_buffer_.reset(new uint8_t[frame_length_]); } @@ -142,9 +142,9 @@ TEST_F(TestLibYuv, ConvertTest) { double psnr = 0.0; VideoFrame res_i420_frame; - EXPECT_EQ(0,res_i420_frame.CreateEmptyFrame(width_, height_, width_, - (width_ + 1) / 2, - (width_ + 1) / 2)); + EXPECT_EQ(0, res_i420_frame.CreateEmptyFrame(width_, height_, width_, + (width_ + 1) / 2, + (width_ + 1) / 2)); printf("\nConvert #%d I420 <-> I420 \n", j); rtc::scoped_ptr<uint8_t[]> out_i420_buffer(new uint8_t[frame_length_]); EXPECT_EQ(0, ConvertFromI420(orig_frame_, kI420, 0, @@ -281,8 +281,8 @@ TEST_F(TestLibYuv, ConvertAlignedFrame) { int stride_y = 0; int stride_uv = 0; Calc16ByteAlignedStride(width_, &stride_y, &stride_uv); - EXPECT_EQ(0,res_i420_frame.CreateEmptyFrame(width_, height_, - stride_y, stride_uv, stride_uv)); + EXPECT_EQ(0, res_i420_frame.CreateEmptyFrame(width_, height_, + stride_y, stride_uv, stride_uv)); rtc::scoped_ptr<uint8_t[]> out_i420_buffer(new uint8_t[frame_length_]); EXPECT_EQ(0, ConvertFromI420(orig_frame_, kI420, 0, out_i420_buffer.get())); @@ -303,27 +303,27 @@ TEST_F(TestLibYuv, RotateTest) { VideoFrame rotated_res_i420_frame; int rotated_width = height_; int rotated_height = width_; - int stride_y ; + int stride_y; int stride_uv; Calc16ByteAlignedStride(rotated_width, &stride_y, &stride_uv); - EXPECT_EQ(0,rotated_res_i420_frame.CreateEmptyFrame(rotated_width, - rotated_height, - stride_y, - stride_uv, - stride_uv)); + EXPECT_EQ(0, rotated_res_i420_frame.CreateEmptyFrame(rotated_width, + rotated_height, + stride_y, + stride_uv, + stride_uv)); EXPECT_EQ(0, ConvertToI420(kI420, orig_buffer_.get(), 0, 0, width_, height_, 0, kVideoRotation_90, &rotated_res_i420_frame)); EXPECT_EQ(0, ConvertToI420(kI420, orig_buffer_.get(), 0, 0, width_, height_, 0, kVideoRotation_270, &rotated_res_i420_frame)); - EXPECT_EQ(0,rotated_res_i420_frame.CreateEmptyFrame(width_, height_, - width_, (width_ + 1) / 2, - (width_ + 1) / 2)); + EXPECT_EQ(0, rotated_res_i420_frame.CreateEmptyFrame(width_, height_, + width_, (width_ + 1) / 2, + (width_ + 1) / 2)); EXPECT_EQ(0, ConvertToI420(kI420, orig_buffer_.get(), 0, 0, width_, height_, 0, kVideoRotation_180, &rotated_res_i420_frame)); } TEST_F(TestLibYuv, alignment) { - int value = 0x3FF; // 1023 + int value = 0x3FF; // 1023 EXPECT_EQ(0x400, AlignInt(value, 128)); // Low 7 bits are zero. EXPECT_EQ(0x400, AlignInt(value, 64)); // Low 6 bits are zero. EXPECT_EQ(0x400, AlignInt(value, 32)); // Low 5 bits are zero. @@ -346,4 +346,4 @@ TEST_F(TestLibYuv, StrideAlignment) { EXPECT_EQ(64, stride_uv); } -} // namespace +} // namespace webrtc diff --git a/webrtc/common_video/libyuv/scaler_unittest.cc b/webrtc/common_video/libyuv/scaler_unittest.cc index 568311bc2e..6d026383a2 100644 --- a/webrtc/common_video/libyuv/scaler_unittest.cc +++ b/webrtc/common_video/libyuv/scaler_unittest.cc @@ -15,7 +15,6 @@ #include "webrtc/common_video/libyuv/include/scaler.h" #include "webrtc/system_wrappers/include/tick_util.h" #include "webrtc/test/testsupport/fileutils.h" -#include "webrtc/test/testsupport/gtest_disable.h" namespace webrtc { @@ -114,8 +113,13 @@ TEST_F(TestScaler, ScaleSendingBufferTooSmall) { EXPECT_EQ(half_height_, test_frame2.height()); } -//TODO (mikhal): Converge the test into one function that accepts the method. -TEST_F(TestScaler, DISABLED_ON_ANDROID(PointScaleTest)) { +// TODO(mikhal): Converge the test into one function that accepts the method. +#if defined(WEBRTC_ANDROID) +#define MAYBE_PointScaleTest DISABLED_PointScaleTest +#else +#define MAYBE_PointScaleTest PointScaleTest +#endif +TEST_F(TestScaler, MAYBE_PointScaleTest) { double avg_psnr; FILE* source_file2; ScaleMethod method = kScalePoint; @@ -182,7 +186,12 @@ TEST_F(TestScaler, DISABLED_ON_ANDROID(PointScaleTest)) { ASSERT_EQ(0, fclose(source_file2)); } -TEST_F(TestScaler, DISABLED_ON_ANDROID(BiLinearScaleTest)) { +#if defined(WEBRTC_ANDROID) +#define MAYBE_BilinearScaleTest DISABLED_BiLinearScaleTest +#else +#define MAYBE_BilinearScaleTest BiLinearScaleTest +#endif +TEST_F(TestScaler, MAYBE_BiLinearScaleTest) { double avg_psnr; FILE* source_file2; ScaleMethod method = kScaleBilinear; @@ -234,7 +243,12 @@ TEST_F(TestScaler, DISABLED_ON_ANDROID(BiLinearScaleTest)) { 400, 300); } -TEST_F(TestScaler, DISABLED_ON_ANDROID(BoxScaleTest)) { +#if defined(WEBRTC_ANDROID) +#define MAYBE_BoxScaleTest DISABLED_BoxScaleTest +#else +#define MAYBE_BoxScaleTest BoxScaleTest +#endif +TEST_F(TestScaler, MAYBE_BoxScaleTest) { double avg_psnr; FILE* source_file2; ScaleMethod method = kScaleBox; @@ -322,7 +336,7 @@ double TestScaler::ComputeAvgSequencePSNR(FILE* input_file, return avg_psnr; } -// TODO (mikhal): Move part to a separate scale test. +// TODO(mikhal): Move part to a separate scale test. void TestScaler::ScaleSequence(ScaleMethod method, FILE* source_file, std::string out_name, int src_width, int src_height, diff --git a/webrtc/common_video/libyuv/webrtc_libyuv.cc b/webrtc/common_video/libyuv/webrtc_libyuv.cc index bf95624769..48f5c2036b 100644 --- a/webrtc/common_video/libyuv/webrtc_libyuv.cc +++ b/webrtc/common_video/libyuv/webrtc_libyuv.cc @@ -58,7 +58,7 @@ VideoType RawVideoTypeToCommonVideoVideoType(RawVideoType type) { int AlignInt(int value, int alignment) { assert(!((alignment - 1) & alignment)); - return ((value + alignment - 1) & ~ (alignment - 1)); + return ((value + alignment - 1) & ~(alignment - 1)); } void Calc16ByteAlignedStride(int width, int* stride_y, int* stride_uv) { @@ -119,8 +119,8 @@ int PrintVideoFrame(const VideoFrame& frame, FILE* file) { } plane_buffer += frame.stride(plane_type); } - } - return 0; + } + return 0; } int ExtractBuffer(const VideoFrame& input_frame, size_t size, uint8_t* buffer) { @@ -176,7 +176,7 @@ int ConvertRGB24ToARGB(const uint8_t* src_frame, uint8_t* dst_frame, } libyuv::RotationMode ConvertRotationMode(VideoRotation rotation) { - switch(rotation) { + switch (rotation) { case kVideoRotation_0: return libyuv::kRotate0; case kVideoRotation_90: @@ -191,7 +191,7 @@ libyuv::RotationMode ConvertRotationMode(VideoRotation rotation) { } int ConvertVideoType(VideoType video_type) { - switch(video_type) { + switch (video_type) { case kUnknown: return libyuv::FOURCC_ANY; case kI420: @@ -243,7 +243,7 @@ int ConvertToI420(VideoType src_video_type, // Stride values should correspond to the destination values. if (rotation == kVideoRotation_90 || rotation == kVideoRotation_270) { dst_width = dst_frame->height(); - dst_height =dst_frame->width(); + dst_height = dst_frame->width(); } return libyuv::ConvertToI420(src_frame, sample_size, dst_frame->buffer(kYPlane), diff --git a/webrtc/common_video/plane.cc b/webrtc/common_video/plane.cc deleted file mode 100644 index e0bbba10ba..0000000000 --- a/webrtc/common_video/plane.cc +++ /dev/null @@ -1,80 +0,0 @@ -/* - * 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/common_video/plane.h" - -#include <string.h> // memcpy - -#include <algorithm> // swap - -namespace webrtc { - -// Aligning pointer to 64 bytes for improved performance, e.g. use SIMD. -static const int kBufferAlignment = 64; - -Plane::Plane() - : allocated_size_(0), - plane_size_(0), - stride_(0) {} - -Plane::~Plane() {} - -int Plane::CreateEmptyPlane(int allocated_size, int stride, int plane_size) { - if (allocated_size < 1 || stride < 1 || plane_size < 1) - return -1; - stride_ = stride; - if (MaybeResize(allocated_size) < 0) - return -1; - plane_size_ = plane_size; - return 0; -} - -int Plane::MaybeResize(int new_size) { - if (new_size <= 0) - return -1; - if (new_size <= allocated_size_) - return 0; - rtc::scoped_ptr<uint8_t, AlignedFreeDeleter> new_buffer( - static_cast<uint8_t*>(AlignedMalloc(new_size, kBufferAlignment))); - if (buffer_.get()) { - memcpy(new_buffer.get(), buffer_.get(), plane_size_); - } - buffer_.reset(new_buffer.release()); - allocated_size_ = new_size; - return 0; -} - -int Plane::Copy(const Plane& plane) { - if (MaybeResize(plane.allocated_size_) < 0) - return -1; - if (plane.buffer_.get()) - memcpy(buffer_.get(), plane.buffer_.get(), plane.plane_size_); - stride_ = plane.stride_; - plane_size_ = plane.plane_size_; - return 0; -} - -int Plane::Copy(int size, int stride, const uint8_t* buffer) { - if (MaybeResize(size) < 0) - return -1; - memcpy(buffer_.get(), buffer, size); - plane_size_ = size; - stride_ = stride; - return 0; -} - -void Plane::Swap(Plane& plane) { - std::swap(stride_, plane.stride_); - std::swap(allocated_size_, plane.allocated_size_); - std::swap(plane_size_, plane.plane_size_); - buffer_.swap(plane.buffer_); -} - -} // namespace webrtc diff --git a/webrtc/common_video/plane.h b/webrtc/common_video/plane.h deleted file mode 100644 index 3ef949adf0..0000000000 --- a/webrtc/common_video/plane.h +++ /dev/null @@ -1,75 +0,0 @@ -/* - * 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. - */ - -#ifndef COMMON_VIDEO_PLANE_H -#define COMMON_VIDEO_PLANE_H - -#include "webrtc/base/scoped_ptr.h" -#include "webrtc/system_wrappers/include/aligned_malloc.h" -#include "webrtc/typedefs.h" - -namespace webrtc { - -// Helper class for VideoFrame: Store plane data and perform basic plane -// operations. -class Plane { - public: - Plane(); - ~Plane(); - // CreateEmptyPlane - set allocated size, actual plane size and stride: - // If current size is smaller than current size, then a buffer of sufficient - // size will be allocated. - // Return value: 0 on success ,-1 on error. - int CreateEmptyPlane(int allocated_size, int stride, int plane_size); - - // Copy the entire plane data. - // Return value: 0 on success ,-1 on error. - int Copy(const Plane& plane); - - // Copy buffer: If current size is smaller - // than current size, then a buffer of sufficient size will be allocated. - // Return value: 0 on success ,-1 on error. - int Copy(int size, int stride, const uint8_t* buffer); - - // Swap plane data. - void Swap(Plane& plane); - - // Get allocated size. - int allocated_size() const {return allocated_size_;} - - // Set actual size. - void ResetSize() {plane_size_ = 0;} - - // Return true is plane size is zero, false if not. - bool IsZeroSize() const {return plane_size_ == 0;} - - // Get stride value. - int stride() const {return stride_;} - - // Return data pointer. - const uint8_t* buffer() const {return buffer_.get();} - // Overloading with non-const. - uint8_t* buffer() {return buffer_.get();} - - private: - // Resize when needed: If current allocated size is less than new_size, buffer - // will be updated. Old data will be copied to new buffer. - // Return value: 0 on success ,-1 on error. - int MaybeResize(int new_size); - - rtc::scoped_ptr<uint8_t, AlignedFreeDeleter> buffer_; - int allocated_size_; - int plane_size_; - int stride_; -}; // Plane - -} // namespace webrtc - -#endif // COMMON_VIDEO_PLANE_H diff --git a/webrtc/common_video/video_frame.cc b/webrtc/common_video/video_frame.cc index 7cdbd53f9d..8ccd821d09 100644 --- a/webrtc/common_video/video_frame.cc +++ b/webrtc/common_video/video_frame.cc @@ -19,6 +19,26 @@ namespace webrtc { +bool EqualPlane(const uint8_t* data1, + const uint8_t* data2, + int stride, + int width, + int height) { + for (int y = 0; y < height; ++y) { + if (memcmp(data1, data2, width) != 0) + return false; + data1 += stride; + data2 += stride; + } + return true; +} + +int ExpectedSize(int plane_stride, int image_height, PlaneType type) { + if (type == kYPlane) + return plane_stride * image_height; + return plane_stride * ((image_height + 1) / 2); +} + VideoFrame::VideoFrame() { // Intentionally using Reset instead of initializer list so that any missed // fields in Reset will be caught by memory checkers. @@ -202,4 +222,24 @@ VideoFrame VideoFrame::ConvertNativeToI420Frame() const { return frame; } +bool VideoFrame::EqualsFrame(const VideoFrame& frame) const { + if (width() != frame.width() || height() != frame.height() || + stride(kYPlane) != frame.stride(kYPlane) || + stride(kUPlane) != frame.stride(kUPlane) || + stride(kVPlane) != frame.stride(kVPlane) || + timestamp() != frame.timestamp() || + ntp_time_ms() != frame.ntp_time_ms() || + render_time_ms() != frame.render_time_ms()) { + return false; + } + const int half_width = (width() + 1) / 2; + const int half_height = (height() + 1) / 2; + return EqualPlane(buffer(kYPlane), frame.buffer(kYPlane), + stride(kYPlane), width(), height()) && + EqualPlane(buffer(kUPlane), frame.buffer(kUPlane), + stride(kUPlane), half_width, half_height) && + EqualPlane(buffer(kVPlane), frame.buffer(kVPlane), + stride(kVPlane), half_width, half_height); +} + } // namespace webrtc diff --git a/webrtc/common_video/video_frame_buffer.cc b/webrtc/common_video/video_frame_buffer.cc index 36ee14a17f..492bc49587 100644 --- a/webrtc/common_video/video_frame_buffer.cc +++ b/webrtc/common_video/video_frame_buffer.cc @@ -8,21 +8,15 @@ * be found in the AUTHORS file in the root of the source tree. */ -#include "webrtc/common_video/interface/video_frame_buffer.h" +#include "webrtc/common_video/include/video_frame_buffer.h" -#include "webrtc/base/bind.h" #include "webrtc/base/checks.h" +#include "webrtc/base/keep_ref_until_done.h" // Aligning pointer to 64 bytes for improved performance, e.g. use SIMD. static const int kBufferAlignment = 64; namespace webrtc { -namespace { - -// Used in rtc::Bind to keep a buffer alive until destructor is called. -static void NoLongerUsedCallback(rtc::scoped_refptr<VideoFrameBuffer> dummy) {} - -} // anonymous namespace uint8_t* VideoFrameBuffer::MutableData(PlaneType type) { RTC_NOTREACHED(); @@ -238,7 +232,7 @@ rtc::scoped_refptr<VideoFrameBuffer> ShallowCenterCrop( y_plane, buffer->stride(kYPlane), u_plane, buffer->stride(kUPlane), v_plane, buffer->stride(kVPlane), - rtc::Bind(&NoLongerUsedCallback, buffer)); + rtc::KeepRefUntilDone(buffer)); } } // namespace webrtc diff --git a/webrtc/common_video/video_render_frames.cc b/webrtc/common_video/video_render_frames.cc index f4ece5e8e9..8b447cb10f 100644 --- a/webrtc/common_video/video_render_frames.cc +++ b/webrtc/common_video/video_render_frames.cc @@ -12,7 +12,7 @@ #include <assert.h> -#include "webrtc/modules/interface/module_common_types.h" +#include "webrtc/modules/include/module_common_types.h" #include "webrtc/system_wrappers/include/tick_util.h" #include "webrtc/system_wrappers/include/trace.h" @@ -20,7 +20,7 @@ namespace webrtc { const uint32_t KEventMaxWaitTimeMs = 200; const uint32_t kMinRenderDelayMs = 10; -const uint32_t kMaxRenderDelayMs= 500; +const uint32_t kMaxRenderDelayMs = 500; VideoRenderFrames::VideoRenderFrames() : render_delay_ms_(10) { |