Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(15)

Side by Side Diff: webrtc/media/engine/webrtcvideoframe_unittest.cc

Issue 1865283002: Use microsecond timestamp in cricket::VideoFrame. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Add missing override, intending to reland. Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 // The ApplyRotationToFrame test needs this as a public method.
23 using cricket::WebRtcVideoFrame::set_rotation; 24 using cricket::WebRtcVideoFrame::set_rotation;
24 25
25 virtual VideoFrame* CreateEmptyFrame(int w, 26 virtual VideoFrame* CreateEmptyFrame(int w,
26 int h, 27 int h,
27 int64_t time_stamp) const override { 28 int64_t time_stamp) const override {
28 WebRtcVideoTestFrame* frame = new WebRtcVideoTestFrame(); 29 WebRtcVideoTestFrame* frame = new WebRtcVideoTestFrame();
29 frame->InitToBlack(w, h, time_stamp); 30 frame->InitToBlack(w, h, time_stamp);
30 return frame; 31 return frame;
31 } 32 }
32 }; 33 };
33 34
34 } // namespace 35 } // namespace
35 36
36 class WebRtcVideoFrameTest : public VideoFrameTest<cricket::WebRtcVideoFrame> { 37 class WebRtcVideoFrameTest : public VideoFrameTest<cricket::WebRtcVideoFrame> {
37 public: 38 public:
38 WebRtcVideoFrameTest() { 39 WebRtcVideoFrameTest() {
39 } 40 }
40 41
41 void TestInit(int cropped_width, int cropped_height, 42 void TestInit(int cropped_width, int cropped_height,
42 webrtc::VideoRotation frame_rotation, 43 webrtc::VideoRotation frame_rotation,
43 bool apply_rotation) { 44 bool apply_rotation) {
44 const int frame_width = 1920; 45 const int frame_width = 1920;
45 const int frame_height = 1080; 46 const int frame_height = 1080;
46 47
47 // Build the CapturedFrame. 48 // Build the CapturedFrame.
48 cricket::CapturedFrame captured_frame; 49 cricket::CapturedFrame captured_frame;
49 captured_frame.fourcc = cricket::FOURCC_I420; 50 captured_frame.fourcc = cricket::FOURCC_I420;
50 captured_frame.time_stamp = 5678; 51 captured_frame.time_stamp = rtc::TimeNanos();
51 captured_frame.rotation = frame_rotation; 52 captured_frame.rotation = frame_rotation;
52 captured_frame.width = frame_width; 53 captured_frame.width = frame_width;
53 captured_frame.height = frame_height; 54 captured_frame.height = frame_height;
54 captured_frame.data_size = (frame_width * frame_height) + 55 captured_frame.data_size = (frame_width * frame_height) +
55 ((frame_width + 1) / 2) * ((frame_height + 1) / 2) * 2; 56 ((frame_width + 1) / 2) * ((frame_height + 1) / 2) * 2;
56 std::unique_ptr<uint8_t[]> captured_frame_buffer( 57 std::unique_ptr<uint8_t[]> captured_frame_buffer(
57 new uint8_t[captured_frame.data_size]); 58 new uint8_t[captured_frame.data_size]);
58 // Initialize memory to satisfy DrMemory tests. 59 // Initialize memory to satisfy DrMemory tests.
59 memset(captured_frame_buffer.get(), 0, captured_frame.data_size); 60 memset(captured_frame_buffer.get(), 0, captured_frame.data_size);
60 captured_frame.data = captured_frame_buffer.get(); 61 captured_frame.data = captured_frame_buffer.get();
61 62
62 // Create the new frame from the CapturedFrame. 63 // Create the new frame from the CapturedFrame.
63 cricket::WebRtcVideoFrame frame; 64 cricket::WebRtcVideoFrame frame;
64 EXPECT_TRUE( 65 EXPECT_TRUE(
65 frame.Init(&captured_frame, cropped_width, cropped_height, 66 frame.Init(&captured_frame, cropped_width, cropped_height,
66 apply_rotation)); 67 apply_rotation));
67 68
68 // Verify the new frame. 69 // Verify the new frame.
69 EXPECT_EQ(5678, frame.GetTimeStamp()); 70 EXPECT_EQ(captured_frame.time_stamp / rtc::kNumNanosecsPerMicrosec,
71 frame.timestamp_us());
70 if (apply_rotation) 72 if (apply_rotation)
71 EXPECT_EQ(webrtc::kVideoRotation_0, frame.rotation()); 73 EXPECT_EQ(webrtc::kVideoRotation_0, frame.rotation());
72 else 74 else
73 EXPECT_EQ(frame_rotation, frame.rotation()); 75 EXPECT_EQ(frame_rotation, frame.rotation());
74 // If |apply_rotation| and the frame rotation is 90 or 270, width and 76 // If |apply_rotation| and the frame rotation is 90 or 270, width and
75 // height are flipped. 77 // height are flipped.
76 if (apply_rotation && (frame_rotation == webrtc::kVideoRotation_90 78 if (apply_rotation && (frame_rotation == webrtc::kVideoRotation_90
77 || frame_rotation == webrtc::kVideoRotation_270)) { 79 || frame_rotation == webrtc::kVideoRotation_270)) {
78 EXPECT_EQ(cropped_width, frame.height()); 80 EXPECT_EQ(cropped_width, frame.height());
79 EXPECT_EQ(cropped_height, frame.width()); 81 EXPECT_EQ(cropped_height, frame.width());
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after
264 TEST_F(WebRtcVideoFrameTest, InitRotated90DontApplyRotation) { 266 TEST_F(WebRtcVideoFrameTest, InitRotated90DontApplyRotation) {
265 TestInit(640, 360, webrtc::kVideoRotation_90, false); 267 TestInit(640, 360, webrtc::kVideoRotation_90, false);
266 } 268 }
267 269
268 TEST_F(WebRtcVideoFrameTest, TextureInitialValues) { 270 TEST_F(WebRtcVideoFrameTest, TextureInitialValues) {
269 webrtc::test::FakeNativeHandle* dummy_handle = 271 webrtc::test::FakeNativeHandle* dummy_handle =
270 new webrtc::test::FakeNativeHandle(); 272 new webrtc::test::FakeNativeHandle();
271 webrtc::NativeHandleBuffer* buffer = 273 webrtc::NativeHandleBuffer* buffer =
272 new rtc::RefCountedObject<webrtc::test::FakeNativeHandleBuffer>( 274 new rtc::RefCountedObject<webrtc::test::FakeNativeHandleBuffer>(
273 dummy_handle, 640, 480); 275 dummy_handle, 640, 480);
274 cricket::WebRtcVideoFrame frame(buffer, 200, webrtc::kVideoRotation_0); 276 // Timestamp is converted from ns to us, so last three digits are lost.
277 cricket::WebRtcVideoFrame frame(buffer, 20000, webrtc::kVideoRotation_0);
275 EXPECT_EQ(dummy_handle, frame.GetNativeHandle()); 278 EXPECT_EQ(dummy_handle, frame.GetNativeHandle());
276 EXPECT_EQ(640, frame.width()); 279 EXPECT_EQ(640, frame.width());
277 EXPECT_EQ(480, frame.height()); 280 EXPECT_EQ(480, frame.height());
278 EXPECT_EQ(200, frame.GetTimeStamp()); 281 EXPECT_EQ(20000, frame.GetTimeStamp());
279 frame.SetTimeStamp(400); 282 EXPECT_EQ(20, frame.timestamp_us());
280 EXPECT_EQ(400, frame.GetTimeStamp()); 283 frame.set_timestamp_us(40);
284 EXPECT_EQ(40000, frame.GetTimeStamp());
285 EXPECT_EQ(40, frame.timestamp_us());
281 } 286 }
282 287
283 TEST_F(WebRtcVideoFrameTest, CopyTextureFrame) { 288 TEST_F(WebRtcVideoFrameTest, CopyTextureFrame) {
284 webrtc::test::FakeNativeHandle* dummy_handle = 289 webrtc::test::FakeNativeHandle* dummy_handle =
285 new webrtc::test::FakeNativeHandle(); 290 new webrtc::test::FakeNativeHandle();
286 webrtc::NativeHandleBuffer* buffer = 291 webrtc::NativeHandleBuffer* buffer =
287 new rtc::RefCountedObject<webrtc::test::FakeNativeHandleBuffer>( 292 new rtc::RefCountedObject<webrtc::test::FakeNativeHandleBuffer>(
288 dummy_handle, 640, 480); 293 dummy_handle, 640, 480);
289 cricket::WebRtcVideoFrame frame1(buffer, 200, webrtc::kVideoRotation_0); 294 // Timestamp is converted from ns to us, so last three digits are lost.
295 cricket::WebRtcVideoFrame frame1(buffer, 20000, webrtc::kVideoRotation_0);
290 cricket::VideoFrame* frame2 = frame1.Copy(); 296 cricket::VideoFrame* frame2 = frame1.Copy();
291 EXPECT_EQ(frame1.GetNativeHandle(), frame2->GetNativeHandle()); 297 EXPECT_EQ(frame1.GetNativeHandle(), frame2->GetNativeHandle());
292 EXPECT_EQ(frame1.width(), frame2->width()); 298 EXPECT_EQ(frame1.width(), frame2->width());
293 EXPECT_EQ(frame1.height(), frame2->height()); 299 EXPECT_EQ(frame1.height(), frame2->height());
294 EXPECT_EQ(frame1.GetTimeStamp(), frame2->GetTimeStamp()); 300 EXPECT_EQ(frame1.GetTimeStamp(), frame2->GetTimeStamp());
301 EXPECT_EQ(frame1.timestamp_us(), frame2->timestamp_us());
295 delete frame2; 302 delete frame2;
296 } 303 }
297 304
298 TEST_F(WebRtcVideoFrameTest, ApplyRotationToFrame) { 305 TEST_F(WebRtcVideoFrameTest, ApplyRotationToFrame) {
299 WebRtcVideoTestFrame applied0; 306 WebRtcVideoTestFrame applied0;
300 EXPECT_TRUE(IsNull(applied0)); 307 EXPECT_TRUE(IsNull(applied0));
301 std::unique_ptr<rtc::MemoryStream> ms(CreateYuvSample(kWidth, kHeight, 12)); 308 std::unique_ptr<rtc::MemoryStream> ms(CreateYuvSample(kWidth, kHeight, 12));
302 EXPECT_TRUE( 309 EXPECT_TRUE(
303 LoadFrame(ms.get(), cricket::FOURCC_I420, kWidth, kHeight, &applied0)); 310 LoadFrame(ms.get(), cricket::FOURCC_I420, kWidth, kHeight, &applied0));
304 311
(...skipping 10 matching lines...) Expand all
315 322
316 // Claim the frame 2 needs to be rotated for another 270 degree. The output 323 // 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. 324 // from frame 2 rotation should be the same as frame 1.
318 applied90->set_rotation(webrtc::kVideoRotation_270); 325 applied90->set_rotation(webrtc::kVideoRotation_270);
319 const cricket::VideoFrame* applied360 = 326 const cricket::VideoFrame* applied360 =
320 applied90->GetCopyWithRotationApplied(); 327 applied90->GetCopyWithRotationApplied();
321 EXPECT_TRUE(applied360); 328 EXPECT_TRUE(applied360);
322 EXPECT_EQ(applied360->rotation(), webrtc::kVideoRotation_0); 329 EXPECT_EQ(applied360->rotation(), webrtc::kVideoRotation_0);
323 EXPECT_TRUE(IsEqual(applied0, *applied360, 0)); 330 EXPECT_TRUE(IsEqual(applied0, *applied360, 0));
324 } 331 }
OLDNEW
« no previous file with comments | « webrtc/media/engine/webrtcvideoframe.cc ('k') | webrtc/media/engine/webrtcvideoframefactory_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698