| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2011 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2011 The WebRTC project authors. All Rights Reserved. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
| 5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
| 6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
| 7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
| 8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
| 9 */ | 9 */ |
| 10 | 10 |
| 11 #include <string.h> | 11 #include <string.h> |
| 12 | 12 |
| 13 #include <memory> | 13 #include <memory> |
| 14 | 14 |
| 15 #include "webrtc/media/base/videoframe_unittest.h" | 15 #include "webrtc/media/base/videoframe_unittest.h" |
| 16 #include "webrtc/media/engine/webrtcvideoframe.h" | 16 #include "webrtc/media/engine/webrtcvideoframe.h" |
| 17 #include "webrtc/test/fake_texture_frame.h" | 17 #include "webrtc/test/fake_texture_frame.h" |
| 18 | 18 |
| 19 namespace { | 19 namespace { |
| 20 | 20 |
| 21 class WebRtcVideoTestFrame : public cricket::WebRtcVideoFrame { | 21 class WebRtcVideoTestFrame : public cricket::WebRtcVideoFrame { |
| 22 public: | 22 public: |
| 23 using cricket::WebRtcVideoFrame::SetRotation; | 23 using cricket::WebRtcVideoFrame::set_rotation; |
| 24 | 24 |
| 25 virtual VideoFrame* CreateEmptyFrame(int w, | 25 virtual VideoFrame* CreateEmptyFrame(int w, |
| 26 int h, | 26 int h, |
| 27 int64_t time_stamp) const override { | 27 int64_t time_stamp) const override { |
| 28 WebRtcVideoTestFrame* frame = new WebRtcVideoTestFrame(); | 28 WebRtcVideoTestFrame* frame = new WebRtcVideoTestFrame(); |
| 29 frame->InitToBlack(w, h, time_stamp); | 29 frame->InitToBlack(w, h, time_stamp); |
| 30 return frame; | 30 return frame; |
| 31 } | 31 } |
| 32 }; | 32 }; |
| 33 | 33 |
| (...skipping 27 matching lines...) Expand all Loading... |
| 61 | 61 |
| 62 // Create the new frame from the CapturedFrame. | 62 // Create the new frame from the CapturedFrame. |
| 63 cricket::WebRtcVideoFrame frame; | 63 cricket::WebRtcVideoFrame frame; |
| 64 EXPECT_TRUE( | 64 EXPECT_TRUE( |
| 65 frame.Init(&captured_frame, cropped_width, cropped_height, | 65 frame.Init(&captured_frame, cropped_width, cropped_height, |
| 66 apply_rotation)); | 66 apply_rotation)); |
| 67 | 67 |
| 68 // Verify the new frame. | 68 // Verify the new frame. |
| 69 EXPECT_EQ(5678, frame.GetTimeStamp()); | 69 EXPECT_EQ(5678, frame.GetTimeStamp()); |
| 70 if (apply_rotation) | 70 if (apply_rotation) |
| 71 EXPECT_EQ(webrtc::kVideoRotation_0, frame.GetVideoRotation()); | 71 EXPECT_EQ(webrtc::kVideoRotation_0, frame.rotation()); |
| 72 else | 72 else |
| 73 EXPECT_EQ(frame_rotation, frame.GetVideoRotation()); | 73 EXPECT_EQ(frame_rotation, frame.rotation()); |
| 74 // If |apply_rotation| and the frame rotation is 90 or 270, width and | 74 // If |apply_rotation| and the frame rotation is 90 or 270, width and |
| 75 // height are flipped. | 75 // height are flipped. |
| 76 if (apply_rotation && (frame_rotation == webrtc::kVideoRotation_90 | 76 if (apply_rotation && (frame_rotation == webrtc::kVideoRotation_90 |
| 77 || frame_rotation == webrtc::kVideoRotation_270)) { | 77 || frame_rotation == webrtc::kVideoRotation_270)) { |
| 78 EXPECT_EQ(cropped_width, frame.height()); | 78 EXPECT_EQ(cropped_width, frame.height()); |
| 79 EXPECT_EQ(cropped_height, frame.width()); | 79 EXPECT_EQ(cropped_height, frame.width()); |
| 80 } else { | 80 } else { |
| 81 EXPECT_EQ(cropped_width, frame.width()); | 81 EXPECT_EQ(cropped_width, frame.width()); |
| 82 EXPECT_EQ(cropped_height, frame.height()); | 82 EXPECT_EQ(cropped_height, frame.height()); |
| 83 } | 83 } |
| (...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 296 } | 296 } |
| 297 | 297 |
| 298 TEST_F(WebRtcVideoFrameTest, ApplyRotationToFrame) { | 298 TEST_F(WebRtcVideoFrameTest, ApplyRotationToFrame) { |
| 299 WebRtcVideoTestFrame applied0; | 299 WebRtcVideoTestFrame applied0; |
| 300 EXPECT_TRUE(IsNull(applied0)); | 300 EXPECT_TRUE(IsNull(applied0)); |
| 301 std::unique_ptr<rtc::MemoryStream> ms(CreateYuvSample(kWidth, kHeight, 12)); | 301 std::unique_ptr<rtc::MemoryStream> ms(CreateYuvSample(kWidth, kHeight, 12)); |
| 302 EXPECT_TRUE( | 302 EXPECT_TRUE( |
| 303 LoadFrame(ms.get(), cricket::FOURCC_I420, kWidth, kHeight, &applied0)); | 303 LoadFrame(ms.get(), cricket::FOURCC_I420, kWidth, kHeight, &applied0)); |
| 304 | 304 |
| 305 // Claim that this frame needs to be rotated for 90 degree. | 305 // Claim that this frame needs to be rotated for 90 degree. |
| 306 applied0.SetRotation(webrtc::kVideoRotation_90); | 306 applied0.set_rotation(webrtc::kVideoRotation_90); |
| 307 | 307 |
| 308 // Apply rotation on frame 1. Output should be different from frame 1. | 308 // Apply rotation on frame 1. Output should be different from frame 1. |
| 309 WebRtcVideoTestFrame* applied90 = const_cast<WebRtcVideoTestFrame*>( | 309 WebRtcVideoTestFrame* applied90 = const_cast<WebRtcVideoTestFrame*>( |
| 310 static_cast<const WebRtcVideoTestFrame*>( | 310 static_cast<const WebRtcVideoTestFrame*>( |
| 311 applied0.GetCopyWithRotationApplied())); | 311 applied0.GetCopyWithRotationApplied())); |
| 312 EXPECT_TRUE(applied90); | 312 EXPECT_TRUE(applied90); |
| 313 EXPECT_EQ(applied90->GetVideoRotation(), webrtc::kVideoRotation_0); | 313 EXPECT_EQ(applied90->rotation(), webrtc::kVideoRotation_0); |
| 314 EXPECT_FALSE(IsEqual(applied0, *applied90, 0)); | 314 EXPECT_FALSE(IsEqual(applied0, *applied90, 0)); |
| 315 | 315 |
| 316 // Claim the frame 2 needs to be rotated for another 270 degree. The output | 316 // Claim the frame 2 needs to be rotated for another 270 degree. The output |
| 317 // from frame 2 rotation should be the same as frame 1. | 317 // from frame 2 rotation should be the same as frame 1. |
| 318 applied90->SetRotation(webrtc::kVideoRotation_270); | 318 applied90->set_rotation(webrtc::kVideoRotation_270); |
| 319 const cricket::VideoFrame* applied360 = | 319 const cricket::VideoFrame* applied360 = |
| 320 applied90->GetCopyWithRotationApplied(); | 320 applied90->GetCopyWithRotationApplied(); |
| 321 EXPECT_TRUE(applied360); | 321 EXPECT_TRUE(applied360); |
| 322 EXPECT_EQ(applied360->GetVideoRotation(), webrtc::kVideoRotation_0); | 322 EXPECT_EQ(applied360->rotation(), webrtc::kVideoRotation_0); |
| 323 EXPECT_TRUE(IsEqual(applied0, *applied360, 0)); | 323 EXPECT_TRUE(IsEqual(applied0, *applied360, 0)); |
| 324 } | 324 } |
| OLD | NEW |