blob: bc8ec4be99802a3b58f31051b7ea237dc2e17730 [file] [log] [blame]
Niels Möllerc961c782016-02-29 12:11:451/*
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
nissef0daa062017-01-10 15:44:2611#include <stdio.h>
12#include <string.h>
13
14#include "webrtc/api/video/i420_buffer.h"
15#include "webrtc/api/video/video_frame.h"
Niels Möllerc961c782016-02-29 12:11:4516#include "webrtc/test/frame_utils.h"
Niels Möllerc961c782016-02-29 12:11:4517
18namespace webrtc {
19namespace test {
20
21bool EqualPlane(const uint8_t* data1,
22 const uint8_t* data2,
nissea186ef62016-04-15 10:43:3923 int stride1,
24 int stride2,
Niels Möllerc961c782016-02-29 12:11:4525 int width,
26 int height) {
27 for (int y = 0; y < height; ++y) {
28 if (memcmp(data1, data2, width) != 0)
29 return false;
nissea186ef62016-04-15 10:43:3930 data1 += stride1;
31 data2 += stride2;
Niels Möllerc961c782016-02-29 12:11:4532 }
33 return true;
34}
nissea186ef62016-04-15 10:43:3935
Niels Möllerc961c782016-02-29 12:11:4536bool FramesEqual(const webrtc::VideoFrame& f1, const webrtc::VideoFrame& f2) {
nissea186ef62016-04-15 10:43:3937 if (f1.timestamp() != f2.timestamp() ||
Niels Möllerc961c782016-02-29 12:11:4538 f1.ntp_time_ms() != f2.ntp_time_ms() ||
39 f1.render_time_ms() != f2.render_time_ms()) {
40 return false;
41 }
nissea186ef62016-04-15 10:43:3942 return FrameBufsEqual(f1.video_frame_buffer(), f2.video_frame_buffer());
Niels Möllerc961c782016-02-29 12:11:4543}
44
nisse5ed79722016-03-30 06:44:1945bool FrameBufsEqual(const rtc::scoped_refptr<webrtc::VideoFrameBuffer>& f1,
46 const rtc::scoped_refptr<webrtc::VideoFrameBuffer>& f2) {
nissea186ef62016-04-15 10:43:3947 if (f1 == f2) {
48 return true;
49 }
50 // Exlude nullptr (except if both are nullptr, as above)
51 if (!f1 || !f2) {
52 return false;
53 }
54
Magnus Jedvert8c7220c2017-06-07 09:32:5055 if (f1->width() != f2->width() || f1->height() != f2->height() ||
56 f1->type() != f2->type()) {
nissea186ef62016-04-15 10:43:3957 return false;
58 }
nissea186ef62016-04-15 10:43:3959
Magnus Jedvert8c7220c2017-06-07 09:32:5060 rtc::scoped_refptr<webrtc::I420BufferInterface> f1_i420 = f1->ToI420();
61 rtc::scoped_refptr<webrtc::I420BufferInterface> f2_i420 = f2->ToI420();
62 return EqualPlane(f1_i420->DataY(), f2_i420->DataY(),
63 f1_i420->StrideY(), f2_i420->StrideY(),
64 f1_i420->width(), f1_i420->height()) &&
65 EqualPlane(f1_i420->DataU(), f2_i420->DataU(),
66 f1_i420->StrideU(), f2_i420->StrideU(),
67 f1_i420->ChromaWidth(), f1_i420->ChromaHeight()) &&
68 EqualPlane(f1_i420->DataV(), f2_i420->DataV(),
69 f1_i420->StrideV(), f2_i420->StrideV(),
70 f1_i420->ChromaWidth(), f1_i420->ChromaHeight());
nisse5ed79722016-03-30 06:44:1971}
72
nissecc1422c2016-09-30 11:14:0773rtc::scoped_refptr<I420Buffer> ReadI420Buffer(int width, int height, FILE *f) {
74 int half_width = (width + 1) / 2;
75 rtc::scoped_refptr<I420Buffer> buffer(
76 // Explicit stride, no padding between rows.
77 I420Buffer::Create(width, height, width, half_width, half_width));
78 size_t size_y = static_cast<size_t>(width) * height;
79 size_t size_uv = static_cast<size_t>(half_width) * ((height + 1) / 2);
80
81 if (fread(buffer->MutableDataY(), 1, size_y, f) < size_y)
82 return nullptr;
83 if (fread(buffer->MutableDataU(), 1, size_uv, f) < size_uv)
84 return nullptr;
85 if (fread(buffer->MutableDataV(), 1, size_uv, f) < size_uv)
86 return nullptr;
87 return buffer;
88}
89
Niels Möllerc961c782016-02-29 12:11:4590} // namespace test
91} // namespace webrtc