1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "media/cast/test/utility/video_utility.h"
10 #include "third_party/libyuv/include/libyuv/compare.h"
11 #include "ui/gfx/size.h"
16 double I420PSNR(const scoped_refptr<media::VideoFrame>& frame1,
17 const scoped_refptr<media::VideoFrame>& frame2) {
18 if (frame1->coded_size().width() != frame2->coded_size().width() ||
19 frame1->coded_size().height() != frame2->coded_size().height())
22 return libyuv::I420Psnr(frame1->data(VideoFrame::kYPlane),
23 frame1->stride(VideoFrame::kYPlane),
24 frame1->data(VideoFrame::kUPlane),
25 frame1->stride(VideoFrame::kUPlane),
26 frame1->data(VideoFrame::kVPlane),
27 frame1->stride(VideoFrame::kVPlane),
28 frame2->data(VideoFrame::kYPlane),
29 frame2->stride(VideoFrame::kYPlane),
30 frame2->data(VideoFrame::kUPlane),
31 frame2->stride(VideoFrame::kUPlane),
32 frame2->data(VideoFrame::kVPlane),
33 frame2->stride(VideoFrame::kVPlane),
34 frame1->coded_size().width(),
35 frame1->coded_size().height());
38 void PopulateVideoFrame(VideoFrame* frame, int start_value) {
39 int height = frame->coded_size().height();
40 int stride_y = frame->stride(VideoFrame::kYPlane);
41 int stride_u = frame->stride(VideoFrame::kUPlane);
42 int stride_v = frame->stride(VideoFrame::kVPlane);
43 int half_height = (height + 1) / 2;
44 uint8* y_plane = frame->data(VideoFrame::kYPlane);
45 uint8* u_plane = frame->data(VideoFrame::kUPlane);
46 uint8* v_plane = frame->data(VideoFrame::kVPlane);
49 for (int j = 0; j < height; ++j)
50 for (int i = 0; i < stride_y; ++i) {
51 *y_plane = static_cast<uint8>(start_value + i + j);
56 for (int j = 0; j < half_height; ++j)
57 for (int i = 0; i < stride_u; ++i) {
58 *u_plane = static_cast<uint8>(start_value + i + j);
63 for (int j = 0; j < half_height; ++j)
64 for (int i = 0; i < stride_v; ++i) {
65 *v_plane = static_cast<uint8>(start_value + i + j);
70 bool PopulateVideoFrameFromFile(VideoFrame* frame, FILE* video_file) {
71 int width = frame->coded_size().width();
72 int height = frame->coded_size().height();
73 int half_width = (width + 1) / 2;
74 int half_height = (height + 1) / 2;
75 size_t frame_size = width * height + 2 * half_width * half_height;
76 uint8* y_plane = frame->data(VideoFrame::kYPlane);
77 uint8* u_plane = frame->data(VideoFrame::kUPlane);
78 uint8* v_plane = frame->data(VideoFrame::kVPlane);
80 uint8* raw_data = new uint8[frame_size];
81 size_t count = fread(raw_data, 1, frame_size, video_file);
82 if (count != frame_size)
85 memcpy(y_plane, raw_data, width * height);
86 memcpy(u_plane, raw_data + width * height, half_width * half_height);
88 raw_data + width * height + half_width * half_height,
89 half_width * half_height);