| OLD | NEW |
| 1 /* | 1 /* |
| 2 * libjingle | 2 * libjingle |
| 3 * Copyright 2011 Google Inc. | 3 * Copyright 2011 Google Inc. |
| 4 * | 4 * |
| 5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
| 6 * modification, are permitted provided that the following conditions are met: | 6 * modification, are permitted provided that the following conditions are met: |
| 7 * | 7 * |
| 8 * 1. Redistributions of source code must retain the above copyright notice, | 8 * 1. Redistributions of source code must retain the above copyright notice, |
| 9 * this list of conditions and the following disclaimer. | 9 * this list of conditions and the following disclaimer. |
| 10 * 2. Redistributions in binary form must reproduce the above copyright notice, | 10 * 2. Redistributions in binary form must reproduce the above copyright notice, |
| (...skipping 23 matching lines...) Expand all Loading... |
| 34 namespace { | 34 namespace { |
| 35 | 35 |
| 36 class WebRtcVideoTestFrame : public cricket::WebRtcVideoFrame { | 36 class WebRtcVideoTestFrame : public cricket::WebRtcVideoFrame { |
| 37 public: | 37 public: |
| 38 using cricket::WebRtcVideoFrame::SetRotation; | 38 using cricket::WebRtcVideoFrame::SetRotation; |
| 39 | 39 |
| 40 virtual VideoFrame* CreateEmptyFrame(int w, | 40 virtual VideoFrame* CreateEmptyFrame(int w, |
| 41 int h, | 41 int h, |
| 42 size_t pixel_width, | 42 size_t pixel_width, |
| 43 size_t pixel_height, | 43 size_t pixel_height, |
| 44 int64_t elapsed_time, | |
| 45 int64_t time_stamp) const override { | 44 int64_t time_stamp) const override { |
| 46 WebRtcVideoTestFrame* frame = new WebRtcVideoTestFrame(); | 45 WebRtcVideoTestFrame* frame = new WebRtcVideoTestFrame(); |
| 47 frame->InitToBlack(w, h, pixel_width, pixel_height, elapsed_time, | 46 frame->InitToBlack(w, h, pixel_width, pixel_height, time_stamp); |
| 48 time_stamp); | |
| 49 return frame; | 47 return frame; |
| 50 } | 48 } |
| 51 }; | 49 }; |
| 52 | 50 |
| 53 } // namespace | 51 } // namespace |
| 54 | 52 |
| 55 class WebRtcVideoFrameTest : public VideoFrameTest<cricket::WebRtcVideoFrame> { | 53 class WebRtcVideoFrameTest : public VideoFrameTest<cricket::WebRtcVideoFrame> { |
| 56 public: | 54 public: |
| 57 WebRtcVideoFrameTest() { | 55 WebRtcVideoFrameTest() { |
| 58 } | 56 } |
| 59 | 57 |
| 60 void TestInit(int cropped_width, int cropped_height, | 58 void TestInit(int cropped_width, int cropped_height, |
| 61 webrtc::VideoRotation frame_rotation, | 59 webrtc::VideoRotation frame_rotation, |
| 62 bool apply_rotation) { | 60 bool apply_rotation) { |
| 63 const int frame_width = 1920; | 61 const int frame_width = 1920; |
| 64 const int frame_height = 1080; | 62 const int frame_height = 1080; |
| 65 | 63 |
| 66 // Build the CapturedFrame. | 64 // Build the CapturedFrame. |
| 67 cricket::CapturedFrame captured_frame; | 65 cricket::CapturedFrame captured_frame; |
| 68 captured_frame.fourcc = cricket::FOURCC_I420; | 66 captured_frame.fourcc = cricket::FOURCC_I420; |
| 69 captured_frame.pixel_width = 1; | 67 captured_frame.pixel_width = 1; |
| 70 captured_frame.pixel_height = 1; | 68 captured_frame.pixel_height = 1; |
| 71 captured_frame.elapsed_time = 1234; | |
| 72 captured_frame.time_stamp = 5678; | 69 captured_frame.time_stamp = 5678; |
| 73 captured_frame.rotation = frame_rotation; | 70 captured_frame.rotation = frame_rotation; |
| 74 captured_frame.width = frame_width; | 71 captured_frame.width = frame_width; |
| 75 captured_frame.height = frame_height; | 72 captured_frame.height = frame_height; |
| 76 captured_frame.data_size = (frame_width * frame_height) + | 73 captured_frame.data_size = (frame_width * frame_height) + |
| 77 ((frame_width + 1) / 2) * ((frame_height + 1) / 2) * 2; | 74 ((frame_width + 1) / 2) * ((frame_height + 1) / 2) * 2; |
| 78 rtc::scoped_ptr<uint8[]> captured_frame_buffer( | 75 rtc::scoped_ptr<uint8[]> captured_frame_buffer( |
| 79 new uint8[captured_frame.data_size]); | 76 new uint8[captured_frame.data_size]); |
| 80 // Initialize memory to satisfy DrMemory tests. | 77 // Initialize memory to satisfy DrMemory tests. |
| 81 memset(captured_frame_buffer.get(), 0, captured_frame.data_size); | 78 memset(captured_frame_buffer.get(), 0, captured_frame.data_size); |
| 82 captured_frame.data = captured_frame_buffer.get(); | 79 captured_frame.data = captured_frame_buffer.get(); |
| 83 | 80 |
| 84 // Create the new frame from the CapturedFrame. | 81 // Create the new frame from the CapturedFrame. |
| 85 cricket::WebRtcVideoFrame frame; | 82 cricket::WebRtcVideoFrame frame; |
| 86 EXPECT_TRUE( | 83 EXPECT_TRUE( |
| 87 frame.Init(&captured_frame, cropped_width, cropped_height, | 84 frame.Init(&captured_frame, cropped_width, cropped_height, |
| 88 apply_rotation)); | 85 apply_rotation)); |
| 89 | 86 |
| 90 // Verify the new frame. | 87 // Verify the new frame. |
| 91 EXPECT_EQ(1u, frame.GetPixelWidth()); | 88 EXPECT_EQ(1u, frame.GetPixelWidth()); |
| 92 EXPECT_EQ(1u, frame.GetPixelHeight()); | 89 EXPECT_EQ(1u, frame.GetPixelHeight()); |
| 93 EXPECT_EQ(1234, frame.GetElapsedTime()); | |
| 94 EXPECT_EQ(5678, frame.GetTimeStamp()); | 90 EXPECT_EQ(5678, frame.GetTimeStamp()); |
| 95 if (apply_rotation) | 91 if (apply_rotation) |
| 96 EXPECT_EQ(webrtc::kVideoRotation_0, frame.GetRotation()); | 92 EXPECT_EQ(webrtc::kVideoRotation_0, frame.GetRotation()); |
| 97 else | 93 else |
| 98 EXPECT_EQ(frame_rotation, frame.GetRotation()); | 94 EXPECT_EQ(frame_rotation, frame.GetRotation()); |
| 99 // If |apply_rotation| and the frame rotation is 90 or 270, width and | 95 // If |apply_rotation| and the frame rotation is 90 or 270, width and |
| 100 // height are flipped. | 96 // height are flipped. |
| 101 if (apply_rotation && (frame_rotation == webrtc::kVideoRotation_90 | 97 if (apply_rotation && (frame_rotation == webrtc::kVideoRotation_90 |
| 102 || frame_rotation == webrtc::kVideoRotation_270)) { | 98 || frame_rotation == webrtc::kVideoRotation_270)) { |
| 103 EXPECT_EQ(static_cast<size_t>(cropped_width), frame.GetHeight()); | 99 EXPECT_EQ(static_cast<size_t>(cropped_width), frame.GetHeight()); |
| (...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 296 TEST_F(WebRtcVideoFrameTest, InitRotated90DontApplyRotation) { | 292 TEST_F(WebRtcVideoFrameTest, InitRotated90DontApplyRotation) { |
| 297 TestInit(640, 360, webrtc::kVideoRotation_90, false); | 293 TestInit(640, 360, webrtc::kVideoRotation_90, false); |
| 298 } | 294 } |
| 299 | 295 |
| 300 TEST_F(WebRtcVideoFrameTest, TextureInitialValues) { | 296 TEST_F(WebRtcVideoFrameTest, TextureInitialValues) { |
| 301 webrtc::test::FakeNativeHandle* dummy_handle = | 297 webrtc::test::FakeNativeHandle* dummy_handle = |
| 302 new webrtc::test::FakeNativeHandle(); | 298 new webrtc::test::FakeNativeHandle(); |
| 303 webrtc::NativeHandleBuffer* buffer = | 299 webrtc::NativeHandleBuffer* buffer = |
| 304 new rtc::RefCountedObject<webrtc::test::FakeNativeHandleBuffer>( | 300 new rtc::RefCountedObject<webrtc::test::FakeNativeHandleBuffer>( |
| 305 dummy_handle, 640, 480); | 301 dummy_handle, 640, 480); |
| 306 cricket::WebRtcVideoFrame frame(buffer, 100, 200, webrtc::kVideoRotation_0); | 302 cricket::WebRtcVideoFrame frame(buffer, 200, webrtc::kVideoRotation_0); |
| 307 EXPECT_EQ(dummy_handle, frame.GetNativeHandle()); | 303 EXPECT_EQ(dummy_handle, frame.GetNativeHandle()); |
| 308 EXPECT_EQ(640u, frame.GetWidth()); | 304 EXPECT_EQ(640u, frame.GetWidth()); |
| 309 EXPECT_EQ(480u, frame.GetHeight()); | 305 EXPECT_EQ(480u, frame.GetHeight()); |
| 310 EXPECT_EQ(100, frame.GetElapsedTime()); | |
| 311 EXPECT_EQ(200, frame.GetTimeStamp()); | 306 EXPECT_EQ(200, frame.GetTimeStamp()); |
| 312 frame.SetElapsedTime(300); | |
| 313 EXPECT_EQ(300, frame.GetElapsedTime()); | |
| 314 frame.SetTimeStamp(400); | 307 frame.SetTimeStamp(400); |
| 315 EXPECT_EQ(400, frame.GetTimeStamp()); | 308 EXPECT_EQ(400, frame.GetTimeStamp()); |
| 316 } | 309 } |
| 317 | 310 |
| 318 TEST_F(WebRtcVideoFrameTest, CopyTextureFrame) { | 311 TEST_F(WebRtcVideoFrameTest, CopyTextureFrame) { |
| 319 webrtc::test::FakeNativeHandle* dummy_handle = | 312 webrtc::test::FakeNativeHandle* dummy_handle = |
| 320 new webrtc::test::FakeNativeHandle(); | 313 new webrtc::test::FakeNativeHandle(); |
| 321 webrtc::NativeHandleBuffer* buffer = | 314 webrtc::NativeHandleBuffer* buffer = |
| 322 new rtc::RefCountedObject<webrtc::test::FakeNativeHandleBuffer>( | 315 new rtc::RefCountedObject<webrtc::test::FakeNativeHandleBuffer>( |
| 323 dummy_handle, 640, 480); | 316 dummy_handle, 640, 480); |
| 324 cricket::WebRtcVideoFrame frame1(buffer, 100, 200, webrtc::kVideoRotation_0); | 317 cricket::WebRtcVideoFrame frame1(buffer, 200, webrtc::kVideoRotation_0); |
| 325 cricket::VideoFrame* frame2 = frame1.Copy(); | 318 cricket::VideoFrame* frame2 = frame1.Copy(); |
| 326 EXPECT_EQ(frame1.GetNativeHandle(), frame2->GetNativeHandle()); | 319 EXPECT_EQ(frame1.GetNativeHandle(), frame2->GetNativeHandle()); |
| 327 EXPECT_EQ(frame1.GetWidth(), frame2->GetWidth()); | 320 EXPECT_EQ(frame1.GetWidth(), frame2->GetWidth()); |
| 328 EXPECT_EQ(frame1.GetHeight(), frame2->GetHeight()); | 321 EXPECT_EQ(frame1.GetHeight(), frame2->GetHeight()); |
| 329 EXPECT_EQ(frame1.GetElapsedTime(), frame2->GetElapsedTime()); | |
| 330 EXPECT_EQ(frame1.GetTimeStamp(), frame2->GetTimeStamp()); | 322 EXPECT_EQ(frame1.GetTimeStamp(), frame2->GetTimeStamp()); |
| 331 delete frame2; | 323 delete frame2; |
| 332 } | 324 } |
| 333 | 325 |
| 334 TEST_F(WebRtcVideoFrameTest, ApplyRotationToFrame) { | 326 TEST_F(WebRtcVideoFrameTest, ApplyRotationToFrame) { |
| 335 WebRtcVideoTestFrame applied0; | 327 WebRtcVideoTestFrame applied0; |
| 336 EXPECT_TRUE(IsNull(applied0)); | 328 EXPECT_TRUE(IsNull(applied0)); |
| 337 rtc::scoped_ptr<rtc::MemoryStream> ms(CreateYuvSample(kWidth, kHeight, 12)); | 329 rtc::scoped_ptr<rtc::MemoryStream> ms(CreateYuvSample(kWidth, kHeight, 12)); |
| 338 EXPECT_TRUE( | 330 EXPECT_TRUE( |
| 339 LoadFrame(ms.get(), cricket::FOURCC_I420, kWidth, kHeight, &applied0)); | 331 LoadFrame(ms.get(), cricket::FOURCC_I420, kWidth, kHeight, &applied0)); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 351 | 343 |
| 352 // Claim the frame 2 needs to be rotated for another 270 degree. The output | 344 // Claim the frame 2 needs to be rotated for another 270 degree. The output |
| 353 // from frame 2 rotation should be the same as frame 1. | 345 // from frame 2 rotation should be the same as frame 1. |
| 354 applied90->SetRotation(webrtc::kVideoRotation_270); | 346 applied90->SetRotation(webrtc::kVideoRotation_270); |
| 355 const cricket::VideoFrame* applied360 = | 347 const cricket::VideoFrame* applied360 = |
| 356 applied90->GetCopyWithRotationApplied(); | 348 applied90->GetCopyWithRotationApplied(); |
| 357 EXPECT_TRUE(applied360); | 349 EXPECT_TRUE(applied360); |
| 358 EXPECT_EQ(applied360->GetVideoRotation(), webrtc::kVideoRotation_0); | 350 EXPECT_EQ(applied360->GetVideoRotation(), webrtc::kVideoRotation_0); |
| 359 EXPECT_TRUE(IsEqual(applied0, *applied360, 0)); | 351 EXPECT_TRUE(IsEqual(applied0, *applied360, 0)); |
| 360 } | 352 } |
| OLD | NEW |