Ignore title parameter for navigator.registerProtocolHandler
[chromium-blink-merge.git] / media / cast / test / utility / video_utility.cc
blob81475d85f1f81da9a6976db3497dfa3c08fc185c
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"
7 #include <math.h>
8 #include <cstdio>
10 #include "third_party/libyuv/include/libyuv/compare.h"
11 #include "ui/gfx/size.h"
13 namespace media {
14 namespace cast {
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())
20 return -1;
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);
48 // Set Y.
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);
52 ++y_plane;
55 // Set U.
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);
59 ++u_plane;
62 // Set V.
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);
66 ++v_plane;
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)
83 return false;
85 memcpy(y_plane, raw_data, width * height);
86 memcpy(u_plane, raw_data + width * height, half_width * half_height);
87 memcpy(v_plane,
88 raw_data + width * height + half_width * half_height,
89 half_width * half_height);
90 delete[] raw_data;
91 return true;
94 } // namespace cast
95 } // namespace media