blob: 21daa44f97d4899996609a9c8f12bbd4f9f714a5 [file] [log] [blame]
Niels Möller739fcb92016-02-29 13:11:45 +01001/*
2 * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved.
3 *
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
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
11#include "webrtc/test/frame_utils.h"
12#include "webrtc/video_frame.h"
13
14namespace webrtc {
15namespace test {
16
17bool EqualPlane(const uint8_t* data1,
18 const uint8_t* data2,
nisse26acec42016-04-15 03:43:39 -070019 int stride1,
20 int stride2,
Niels Möller739fcb92016-02-29 13:11:45 +010021 int width,
22 int height) {
23 for (int y = 0; y < height; ++y) {
24 if (memcmp(data1, data2, width) != 0)
25 return false;
nisse26acec42016-04-15 03:43:39 -070026 data1 += stride1;
27 data2 += stride2;
Niels Möller739fcb92016-02-29 13:11:45 +010028 }
29 return true;
30}
nisse26acec42016-04-15 03:43:39 -070031
Niels Möller739fcb92016-02-29 13:11:45 +010032bool FramesEqual(const webrtc::VideoFrame& f1, const webrtc::VideoFrame& f2) {
nisse26acec42016-04-15 03:43:39 -070033 if (f1.timestamp() != f2.timestamp() ||
Niels Möller739fcb92016-02-29 13:11:45 +010034 f1.ntp_time_ms() != f2.ntp_time_ms() ||
35 f1.render_time_ms() != f2.render_time_ms()) {
36 return false;
37 }
nisse26acec42016-04-15 03:43:39 -070038 return FrameBufsEqual(f1.video_frame_buffer(), f2.video_frame_buffer());
Niels Möller739fcb92016-02-29 13:11:45 +010039}
40
nisse7cc9cc02016-03-29 23:44:19 -070041bool FrameBufsEqual(const rtc::scoped_refptr<webrtc::VideoFrameBuffer>& f1,
42 const rtc::scoped_refptr<webrtc::VideoFrameBuffer>& f2) {
nisse26acec42016-04-15 03:43:39 -070043 if (f1 == f2) {
44 return true;
45 }
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()) {
nisse7cc9cc02016-03-29 23:44:19 -070060 return false;
61 }
62 const int half_width = (f1->width() + 1) / 2;
63 const int half_height = (f1->height() + 1) / 2;
64 return EqualPlane(f1->data(webrtc::kYPlane), f2->data(webrtc::kYPlane),
nisse26acec42016-04-15 03:43:39 -070065 f1->stride(webrtc::kYPlane), f2->stride(webrtc::kYPlane),
66 f1->width(), f1->height()) &&
nisse7cc9cc02016-03-29 23:44:19 -070067 EqualPlane(f1->data(webrtc::kUPlane), f2->data(webrtc::kUPlane),
nisse26acec42016-04-15 03:43:39 -070068 f1->stride(webrtc::kUPlane), f2->stride(webrtc::kUPlane),
69 half_width, half_height) &&
nisse7cc9cc02016-03-29 23:44:19 -070070 EqualPlane(f1->data(webrtc::kVPlane), f2->data(webrtc::kVPlane),
nisse26acec42016-04-15 03:43:39 -070071 f1->stride(webrtc::kVPlane), f2->stride(webrtc::kVPlane),
72 half_width, half_height);
nisse7cc9cc02016-03-29 23:44:19 -070073}
74
Niels Möller739fcb92016-02-29 13:11:45 +010075} // namespace test
76} // namespace webrtc