OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2013 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 "webrtc/test/frame_utils.h" | 11 #include "webrtc/test/frame_utils.h" |
12 #include "webrtc/video_frame.h" | 12 #include "webrtc/video_frame.h" |
13 | 13 |
14 namespace webrtc { | 14 namespace webrtc { |
15 namespace test { | 15 namespace test { |
16 | 16 |
17 bool EqualPlane(const uint8_t* data1, | 17 bool EqualPlane(const uint8_t* data1, |
18 const uint8_t* data2, | 18 const uint8_t* data2, |
19 int stride, | 19 int stride1, |
| 20 int stride2, |
20 int width, | 21 int width, |
21 int height) { | 22 int height) { |
22 for (int y = 0; y < height; ++y) { | 23 for (int y = 0; y < height; ++y) { |
23 if (memcmp(data1, data2, width) != 0) | 24 if (memcmp(data1, data2, width) != 0) |
24 return false; | 25 return false; |
25 data1 += stride; | 26 data1 += stride1; |
26 data2 += stride; | 27 data2 += stride2; |
27 } | 28 } |
28 return true; | 29 return true; |
29 } | 30 } |
| 31 |
30 bool FramesEqual(const webrtc::VideoFrame& f1, const webrtc::VideoFrame& f2) { | 32 bool FramesEqual(const webrtc::VideoFrame& f1, const webrtc::VideoFrame& f2) { |
31 if (f1.width() != f2.width() || f1.height() != f2.height() || | 33 if (f1.timestamp() != f2.timestamp() || |
32 f1.stride(webrtc::kYPlane) != f2.stride(webrtc::kYPlane) || | |
33 f1.stride(webrtc::kUPlane) != f2.stride(webrtc::kUPlane) || | |
34 f1.stride(webrtc::kVPlane) != f2.stride(webrtc::kVPlane) || | |
35 f1.timestamp() != f2.timestamp() || | |
36 f1.ntp_time_ms() != f2.ntp_time_ms() || | 34 f1.ntp_time_ms() != f2.ntp_time_ms() || |
37 f1.render_time_ms() != f2.render_time_ms()) { | 35 f1.render_time_ms() != f2.render_time_ms()) { |
38 return false; | 36 return false; |
39 } | 37 } |
40 const int half_width = (f1.width() + 1) / 2; | 38 return FrameBufsEqual(f1.video_frame_buffer(), f2.video_frame_buffer()); |
41 const int half_height = (f1.height() + 1) / 2; | |
42 return EqualPlane(f1.buffer(webrtc::kYPlane), f2.buffer(webrtc::kYPlane), | |
43 f1.stride(webrtc::kYPlane), f1.width(), f1.height()) && | |
44 EqualPlane(f1.buffer(webrtc::kUPlane), f2.buffer(webrtc::kUPlane), | |
45 f1.stride(webrtc::kUPlane), half_width, half_height) && | |
46 EqualPlane(f1.buffer(webrtc::kVPlane), f2.buffer(webrtc::kVPlane), | |
47 f1.stride(webrtc::kVPlane), half_width, half_height); | |
48 } | 39 } |
49 | 40 |
50 bool FrameBufsEqual(const rtc::scoped_refptr<webrtc::VideoFrameBuffer>& f1, | 41 bool FrameBufsEqual(const rtc::scoped_refptr<webrtc::VideoFrameBuffer>& f1, |
51 const rtc::scoped_refptr<webrtc::VideoFrameBuffer>& f2) { | 42 const rtc::scoped_refptr<webrtc::VideoFrameBuffer>& f2) { |
52 if (f1->width() != f2->width() || f1->height() != f2->height() || | 43 if (f1 == f2) { |
53 f1->stride(webrtc::kYPlane) != f2->stride(webrtc::kYPlane) || | 44 return true; |
54 f1->stride(webrtc::kUPlane) != f2->stride(webrtc::kUPlane) || | 45 } |
55 f1->stride(webrtc::kVPlane) != f2->stride(webrtc::kVPlane)) { | 46 // Exlude nullptr (except if both are nullptr, as above) |
| 47 if (!f1 || !f2) { |
| 48 return false; |
| 49 } |
| 50 |
| 51 if (f1->width() != f2->width() || f1->height() != f2->height()) { |
| 52 return false; |
| 53 } |
| 54 // Exclude native handle |
| 55 if (f1->native_handle()) { |
| 56 return f1->native_handle() == f2->native_handle(); |
| 57 } |
| 58 |
| 59 if (f2->native_handle()) { |
56 return false; | 60 return false; |
57 } | 61 } |
58 const int half_width = (f1->width() + 1) / 2; | 62 const int half_width = (f1->width() + 1) / 2; |
59 const int half_height = (f1->height() + 1) / 2; | 63 const int half_height = (f1->height() + 1) / 2; |
60 return EqualPlane(f1->data(webrtc::kYPlane), f2->data(webrtc::kYPlane), | 64 return EqualPlane(f1->data(webrtc::kYPlane), f2->data(webrtc::kYPlane), |
61 f1->stride(webrtc::kYPlane), f1->width(), f1->height()) && | 65 f1->stride(webrtc::kYPlane), f2->stride(webrtc::kYPlane), |
| 66 f1->width(), f1->height()) && |
62 EqualPlane(f1->data(webrtc::kUPlane), f2->data(webrtc::kUPlane), | 67 EqualPlane(f1->data(webrtc::kUPlane), f2->data(webrtc::kUPlane), |
63 f1->stride(webrtc::kUPlane), half_width, half_height) && | 68 f1->stride(webrtc::kUPlane), f2->stride(webrtc::kUPlane), |
| 69 half_width, half_height) && |
64 EqualPlane(f1->data(webrtc::kVPlane), f2->data(webrtc::kVPlane), | 70 EqualPlane(f1->data(webrtc::kVPlane), f2->data(webrtc::kVPlane), |
65 f1->stride(webrtc::kVPlane), half_width, half_height); | 71 f1->stride(webrtc::kVPlane), f2->stride(webrtc::kVPlane), |
| 72 half_width, half_height); |
66 } | 73 } |
67 | 74 |
68 } // namespace test | 75 } // namespace test |
69 } // namespace webrtc | 76 } // namespace webrtc |
OLD | NEW |