diff --git a/webrtc/media/base/videoframe.h b/webrtc/media/base/videoframe.h index 1f282c5f29..3d765ad5df 100644 --- a/webrtc/media/base/videoframe.h +++ b/webrtc/media/base/videoframe.h @@ -97,14 +97,6 @@ class VideoFrame { int h, const uint8_t* sample, size_t sample_size); - - protected: - // Creates an empty frame. - virtual VideoFrame* CreateEmptyFrame(int w, - int h, - int64_t timestamp_us) const = 0; - - virtual void set_rotation(webrtc::VideoRotation rotation) = 0; }; } // namespace cricket diff --git a/webrtc/media/base/videoframe_unittest.h b/webrtc/media/base/videoframe_unittest.h index 39985617c5..f19d0325d6 100644 --- a/webrtc/media/base/videoframe_unittest.h +++ b/webrtc/media/base/videoframe_unittest.h @@ -835,7 +835,7 @@ class VideoFrameTest : public testing::Test { data_size, 0, webrtc::kVideoRotation_0)); \ int width_rotate = frame1.width(); \ int height_rotate = frame1.height(); \ - frame3.InitToEmptyBuffer(width_rotate, height_rotate, 0); \ + frame3.InitToEmptyBuffer(width_rotate, height_rotate); \ libyuv::I420Mirror(frame2.video_frame_buffer()->DataY(), \ frame2.video_frame_buffer()->StrideY(), \ frame2.video_frame_buffer()->DataU(), \ @@ -847,8 +847,8 @@ class VideoFrameTest : public testing::Test { frame3.video_frame_buffer()->MutableDataU(), \ frame3.video_frame_buffer()->StrideU(), \ frame3.video_frame_buffer()->MutableDataV(), \ - frame3.video_frame_buffer()->StrideV(), \ - kWidth, kHeight); \ + frame3.video_frame_buffer()->StrideV(), kWidth, \ + kHeight); \ EXPECT_TRUE(IsEqual(frame1, frame3, 0)); \ } @@ -873,7 +873,7 @@ class VideoFrameTest : public testing::Test { data_size, 0, webrtc::kVideoRotation_0)); \ int width_rotate = frame1.width(); \ int height_rotate = frame1.height(); \ - frame3.InitToEmptyBuffer(width_rotate, height_rotate, 0); \ + frame3.InitToEmptyBuffer(width_rotate, height_rotate); \ libyuv::I420Rotate(frame2.video_frame_buffer()->DataY(), \ frame2.video_frame_buffer()->StrideY(), \ frame2.video_frame_buffer()->DataU(), \ @@ -885,8 +885,8 @@ class VideoFrameTest : public testing::Test { frame3.video_frame_buffer()->MutableDataU(), \ frame3.video_frame_buffer()->StrideU(), \ frame3.video_frame_buffer()->MutableDataV(), \ - frame3.video_frame_buffer()->StrideV(), \ - kWidth, kHeight, libyuv::kRotate##ROTATE); \ + frame3.video_frame_buffer()->StrideV(), kWidth, \ + kHeight, libyuv::kRotate##ROTATE); \ EXPECT_TRUE(IsEqual(frame1, frame3, 0)); \ } @@ -1480,7 +1480,7 @@ class VideoFrameTest : public testing::Test { out, out_size, stride)); } - frame2.InitToEmptyBuffer(kWidth, kHeight, 0); + frame2.InitToEmptyBuffer(kWidth, kHeight); for (int i = 0; i < repeat_from; ++i) { EXPECT_EQ(0, RGBToI420(out, stride, frame2.video_frame_buffer()->MutableDataY(), diff --git a/webrtc/media/engine/webrtcvideoframe.cc b/webrtc/media/engine/webrtcvideoframe.cc index 4f89c8b85d..2ff4042c52 100644 --- a/webrtc/media/engine/webrtcvideoframe.cc +++ b/webrtc/media/engine/webrtcvideoframe.cc @@ -149,26 +149,11 @@ bool WebRtcVideoFrame::Reset(uint32_t format, return true; } -VideoFrame* WebRtcVideoFrame::CreateEmptyFrame(int w, - int h, - int64_t timestamp_us) const { - WebRtcVideoFrame* frame = new WebRtcVideoFrame(); - frame->InitToEmptyBuffer(w, h, rtc::kNumNanosecsPerMicrosec * timestamp_us); - return frame; -} - void WebRtcVideoFrame::InitToEmptyBuffer(int w, int h) { video_frame_buffer_ = new rtc::RefCountedObject(w, h); rotation_ = webrtc::kVideoRotation_0; } -void WebRtcVideoFrame::InitToEmptyBuffer(int w, int h, - int64_t time_stamp_ns) { - video_frame_buffer_ = new rtc::RefCountedObject(w, h); - SetTimeStamp(time_stamp_ns); - rotation_ = webrtc::kVideoRotation_0; -} - const VideoFrame* WebRtcVideoFrame::GetCopyWithRotationApplied() const { // If the frame is not rotated, the caller should reuse this frame instead of // making a redundant copy. @@ -185,19 +170,19 @@ const VideoFrame* WebRtcVideoFrame::GetCopyWithRotationApplied() const { return rotated_frame_.get(); } - int orig_width = width(); - int orig_height = height(); + int current_width = width(); + int current_height = height(); - int rotated_width = orig_width; - int rotated_height = orig_height; + int rotated_width = current_width; + int rotated_height = current_height; if (rotation() == webrtc::kVideoRotation_90 || rotation() == webrtc::kVideoRotation_270) { - rotated_width = orig_height; - rotated_height = orig_width; + std::swap(rotated_width, rotated_height); } - rotated_frame_.reset( - CreateEmptyFrame(rotated_width, rotated_height, timestamp_us_)); + rtc::scoped_refptr buffer = + new rtc::RefCountedObject(rotated_width, + rotated_height); // TODO(guoweis): Add a function in webrtc_libyuv.cc to convert from // VideoRotation to libyuv::RotationMode. @@ -205,18 +190,16 @@ const VideoFrame* WebRtcVideoFrame::GetCopyWithRotationApplied() const { video_frame_buffer_->DataY(), video_frame_buffer_->StrideY(), video_frame_buffer_->DataU(), video_frame_buffer_->StrideU(), video_frame_buffer_->DataV(), video_frame_buffer_->StrideV(), - rotated_frame_->video_frame_buffer()->MutableDataY(), - rotated_frame_->video_frame_buffer()->StrideY(), - rotated_frame_->video_frame_buffer()->MutableDataU(), - rotated_frame_->video_frame_buffer()->StrideU(), - rotated_frame_->video_frame_buffer()->MutableDataV(), - rotated_frame_->video_frame_buffer()->StrideV(), - orig_width, orig_height, + buffer->MutableDataY(), buffer->StrideY(), buffer->MutableDataU(), + buffer->StrideU(), buffer->MutableDataV(), buffer->StrideV(), + current_width, current_height, static_cast(rotation())); if (ret == 0) { - return rotated_frame_.get(); + rotated_frame_.reset( + new WebRtcVideoFrame(buffer, webrtc::kVideoRotation_0, timestamp_us_)); } - return nullptr; + + return rotated_frame_.get(); } } // namespace cricket diff --git a/webrtc/media/engine/webrtcvideoframe.h b/webrtc/media/engine/webrtcvideoframe.h index 29bdb32f2b..07525e7f3e 100644 --- a/webrtc/media/engine/webrtcvideoframe.h +++ b/webrtc/media/engine/webrtcvideoframe.h @@ -19,6 +19,7 @@ #include "webrtc/common_types.h" #include "webrtc/common_video/include/video_frame_buffer.h" #include "webrtc/media/base/videoframe.h" +#include "webrtc/base/gtest_prod_util.h" namespace cricket { @@ -72,7 +73,6 @@ class WebRtcVideoFrame : public VideoFrame { bool Init(const CapturedFrame* frame, int dw, int dh, bool apply_rotation); void InitToEmptyBuffer(int w, int h); - void InitToEmptyBuffer(int w, int h, int64_t time_stamp_ns); int width() const override; int height() const override; @@ -96,9 +96,6 @@ class WebRtcVideoFrame : public VideoFrame { const VideoFrame* GetCopyWithRotationApplied() const override; protected: - void set_rotation(webrtc::VideoRotation rotation) override { - rotation_ = rotation; - } // Creates a frame from a raw sample with FourCC |format| and size |w| x |h|. // |h| can be negative indicating a vertically flipped image. // |dw| is destination width; can be less than |w| if cropping is desired. @@ -116,8 +113,8 @@ class WebRtcVideoFrame : public VideoFrame { bool apply_rotation); private: - VideoFrame* CreateEmptyFrame(int w, int h, - int64_t time_stamp_ns) const override; + // The test mutates |rotation_|, so it needs to be a friend. + FRIEND_TEST_ALL_PREFIXES(WebRtcVideoFrameTest, ApplyRotationToFrame); // An opaque reference counted handle that stores the pixel data. rtc::scoped_refptr video_frame_buffer_; diff --git a/webrtc/media/engine/webrtcvideoframe_unittest.cc b/webrtc/media/engine/webrtcvideoframe_unittest.cc index abfd0aea3c..fbb7ebd625 100644 --- a/webrtc/media/engine/webrtcvideoframe_unittest.cc +++ b/webrtc/media/engine/webrtcvideoframe_unittest.cc @@ -16,37 +16,11 @@ #include "webrtc/media/engine/webrtcvideoframe.h" #include "webrtc/test/fake_texture_frame.h" -namespace { +namespace cricket { -class WebRtcVideoTestFrame : public cricket::WebRtcVideoFrame { +class WebRtcVideoFrameTest : public VideoFrameTest { public: - WebRtcVideoTestFrame() {} - WebRtcVideoTestFrame( - const rtc::scoped_refptr& buffer, - int64_t time_stamp_ns, - webrtc::VideoRotation rotation) - : WebRtcVideoFrame(buffer, time_stamp_ns, rotation) {} - - // The ApplyRotationToFrame test needs this as a public method. - using cricket::WebRtcVideoFrame::set_rotation; - - virtual VideoFrame* CreateEmptyFrame(int w, - int h, - int64_t time_stamp) const override { - rtc::scoped_refptr buffer( - new rtc::RefCountedObject(w, h)); - buffer->SetToBlack(); - return new WebRtcVideoTestFrame( - buffer, time_stamp, webrtc::kVideoRotation_0); - } -}; - -} // namespace - -class WebRtcVideoFrameTest : public VideoFrameTest { - public: - WebRtcVideoFrameTest() { - } + WebRtcVideoFrameTest() {} void TestInit(int cropped_width, int cropped_height, webrtc::VideoRotation frame_rotation, @@ -55,8 +29,8 @@ class WebRtcVideoFrameTest : public VideoFrameTest { const int frame_height = 1080; // Build the CapturedFrame. - cricket::CapturedFrame captured_frame; - captured_frame.fourcc = cricket::FOURCC_I420; + CapturedFrame captured_frame; + captured_frame.fourcc = FOURCC_I420; captured_frame.time_stamp = rtc::TimeNanos(); captured_frame.rotation = frame_rotation; captured_frame.width = frame_width; @@ -70,7 +44,7 @@ class WebRtcVideoFrameTest : public VideoFrameTest { captured_frame.data = captured_frame_buffer.get(); // Create the new frame from the CapturedFrame. - cricket::WebRtcVideoFrame frame; + WebRtcVideoFrame frame; EXPECT_TRUE( frame.Init(&captured_frame, cropped_width, cropped_height, apply_rotation)); @@ -95,9 +69,8 @@ class WebRtcVideoFrameTest : public VideoFrameTest { } }; -#define TEST_WEBRTCVIDEOFRAME(X) TEST_F(WebRtcVideoFrameTest, X) { \ - VideoFrameTest::X(); \ -} +#define TEST_WEBRTCVIDEOFRAME(X) \ + TEST_F(WebRtcVideoFrameTest, X) { VideoFrameTest::X(); } TEST_WEBRTCVIDEOFRAME(ConstructI420) TEST_WEBRTCVIDEOFRAME(ConstructI422) @@ -281,7 +254,7 @@ TEST_F(WebRtcVideoFrameTest, TextureInitialValues) { new rtc::RefCountedObject( dummy_handle, 640, 480); // Timestamp is converted from ns to us, so last three digits are lost. - cricket::WebRtcVideoFrame frame(buffer, 20000, webrtc::kVideoRotation_0); + WebRtcVideoFrame frame(buffer, 20000, webrtc::kVideoRotation_0); EXPECT_EQ(dummy_handle, frame.video_frame_buffer()->native_handle()); EXPECT_EQ(640, frame.width()); EXPECT_EQ(480, frame.height()); @@ -299,8 +272,8 @@ TEST_F(WebRtcVideoFrameTest, CopyTextureFrame) { new rtc::RefCountedObject( dummy_handle, 640, 480); // Timestamp is converted from ns to us, so last three digits are lost. - cricket::WebRtcVideoFrame frame1(buffer, 20000, webrtc::kVideoRotation_0); - cricket::VideoFrame* frame2 = frame1.Copy(); + WebRtcVideoFrame frame1(buffer, 20000, webrtc::kVideoRotation_0); + VideoFrame* frame2 = frame1.Copy(); EXPECT_EQ(frame1.video_frame_buffer()->native_handle(), frame2->video_frame_buffer()->native_handle()); EXPECT_EQ(frame1.width(), frame2->width()); @@ -311,17 +284,17 @@ TEST_F(WebRtcVideoFrameTest, CopyTextureFrame) { } TEST_F(WebRtcVideoFrameTest, ApplyRotationToFrame) { - WebRtcVideoTestFrame applied0; + WebRtcVideoFrame applied0; EXPECT_TRUE(IsNull(applied0)); - EXPECT_TRUE(LoadFrame(CreateYuvSample(kWidth, kHeight, 12).get(), - cricket::FOURCC_I420, kWidth, kHeight, &applied0)); + EXPECT_TRUE(LoadFrame(CreateYuvSample(kWidth, kHeight, 12).get(), FOURCC_I420, + kWidth, kHeight, &applied0)); // Claim that this frame needs to be rotated for 90 degree. - applied0.set_rotation(webrtc::kVideoRotation_90); + applied0.rotation_ = webrtc::kVideoRotation_90; // Apply rotation on frame 1. Output should be different from frame 1. - WebRtcVideoTestFrame* applied90 = const_cast( - static_cast( + WebRtcVideoFrame* applied90 = + const_cast(static_cast( applied0.GetCopyWithRotationApplied())); EXPECT_TRUE(applied90); EXPECT_EQ(applied90->rotation(), webrtc::kVideoRotation_0); @@ -329,10 +302,11 @@ TEST_F(WebRtcVideoFrameTest, ApplyRotationToFrame) { // Claim the frame 2 needs to be rotated for another 270 degree. The output // from frame 2 rotation should be the same as frame 1. - applied90->set_rotation(webrtc::kVideoRotation_270); - const cricket::VideoFrame* applied360 = - applied90->GetCopyWithRotationApplied(); + applied90->rotation_ = webrtc::kVideoRotation_270; + const VideoFrame* applied360 = applied90->GetCopyWithRotationApplied(); EXPECT_TRUE(applied360); EXPECT_EQ(applied360->rotation(), webrtc::kVideoRotation_0); EXPECT_TRUE(IsEqual(applied0, *applied360, 0)); } + +} // namespace cricket