blob: 0f411447458173331b48db59de325b7a4cc174c4 [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,
19 int stride,
20 int width,
21 int height) {
22 for (int y = 0; y < height; ++y) {
23 if (memcmp(data1, data2, width) != 0)
24 return false;
25 data1 += stride;
26 data2 += stride;
27 }
28 return true;
29}
30bool FramesEqual(const webrtc::VideoFrame& f1, const webrtc::VideoFrame& f2) {
31 if (f1.width() != f2.width() || f1.height() != f2.height() ||
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() ||
37 f1.render_time_ms() != f2.render_time_ms()) {
38 return false;
39 }
40 const int half_width = (f1.width() + 1) / 2;
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}
49
nisse7cc9cc02016-03-29 23:44:19 -070050bool FrameBufsEqual(const rtc::scoped_refptr<webrtc::VideoFrameBuffer>& f1,
51 const rtc::scoped_refptr<webrtc::VideoFrameBuffer>& f2) {
52 if (f1->width() != f2->width() || f1->height() != f2->height() ||
53 f1->stride(webrtc::kYPlane) != f2->stride(webrtc::kYPlane) ||
54 f1->stride(webrtc::kUPlane) != f2->stride(webrtc::kUPlane) ||
55 f1->stride(webrtc::kVPlane) != f2->stride(webrtc::kVPlane)) {
56 return false;
57 }
58 const int half_width = (f1->width() + 1) / 2;
59 const int half_height = (f1->height() + 1) / 2;
60 return EqualPlane(f1->data(webrtc::kYPlane), f2->data(webrtc::kYPlane),
61 f1->stride(webrtc::kYPlane), f1->width(), f1->height()) &&
62 EqualPlane(f1->data(webrtc::kUPlane), f2->data(webrtc::kUPlane),
63 f1->stride(webrtc::kUPlane), half_width, half_height) &&
64 EqualPlane(f1->data(webrtc::kVPlane), f2->data(webrtc::kVPlane),
65 f1->stride(webrtc::kVPlane), half_width, half_height);
66}
67
Niels Möller739fcb92016-02-29 13:11:45 +010068} // namespace test
69} // namespace webrtc