| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "media/cast/test/utility/video_utility.h" | 5 #include "media/cast/test/utility/video_utility.h" |
| 6 | 6 |
| 7 #include <math.h> | 7 #include <math.h> |
| 8 #include <cstdio> | 8 #include <cstdio> |
| 9 | 9 |
| 10 #include "third_party/libyuv/include/libyuv/compare.h" | 10 #include "third_party/libyuv/include/libyuv/compare.h" |
| (...skipping 20 matching lines...) Expand all Loading... |
| 31 frame2->stride(VideoFrame::kUPlane), | 31 frame2->stride(VideoFrame::kUPlane), |
| 32 frame2->data(VideoFrame::kVPlane), | 32 frame2->data(VideoFrame::kVPlane), |
| 33 frame2->stride(VideoFrame::kVPlane), | 33 frame2->stride(VideoFrame::kVPlane), |
| 34 frame1->coded_size().width(), | 34 frame1->coded_size().width(), |
| 35 frame1->coded_size().height()); | 35 frame1->coded_size().height()); |
| 36 } | 36 } |
| 37 | 37 |
| 38 void PopulateVideoFrame(VideoFrame* frame, int start_value) { | 38 void PopulateVideoFrame(VideoFrame* frame, int start_value) { |
| 39 int width = frame->coded_size().width(); | 39 int width = frame->coded_size().width(); |
| 40 int height = frame->coded_size().height(); | 40 int height = frame->coded_size().height(); |
| 41 int half_width = (width + 1) / 2; | 41 int stride_y = frame->stride(VideoFrame::kYPlane); |
| 42 int stride_u = frame->stride(VideoFrame::kUPlane); |
| 43 int stride_v = frame->stride(VideoFrame::kVPlane); |
| 42 int half_height = (height + 1) / 2; | 44 int half_height = (height + 1) / 2; |
| 43 uint8* y_plane = frame->data(VideoFrame::kYPlane); | 45 uint8* y_plane = frame->data(VideoFrame::kYPlane); |
| 44 uint8* u_plane = frame->data(VideoFrame::kUPlane); | 46 uint8* u_plane = frame->data(VideoFrame::kUPlane); |
| 45 uint8* v_plane = frame->data(VideoFrame::kVPlane); | 47 uint8* v_plane = frame->data(VideoFrame::kVPlane); |
| 46 | 48 |
| 47 // Set Y. | 49 // Set Y. |
| 48 for (int i = 0; i < width * height; ++i) { | 50 for (int j = 0; j < height; ++j) |
| 49 y_plane[i] = static_cast<uint8>(start_value + i); | 51 for (int i = 0; i < stride_y; ++i) { |
| 50 } | 52 *y_plane = static_cast<uint8>(start_value + i + j); |
| 53 ++y_plane; |
| 54 } |
| 51 | 55 |
| 52 // Set U. | 56 // Set U. |
| 53 for (int i = 0; i < half_width * half_height; ++i) { | 57 for (int j = 0; j < half_height; ++j) |
| 54 u_plane[i] = static_cast<uint8>(start_value + i); | 58 for (int i = 0; i < stride_u; ++i) { |
| 55 } | 59 *u_plane = static_cast<uint8>(start_value + i + j); |
| 60 ++u_plane; |
| 61 } |
| 56 | 62 |
| 57 // Set V. | 63 // Set V. |
| 58 for (int i = 0; i < half_width * half_height; ++i) { | 64 for (int j = 0; j < half_height; ++j) |
| 59 v_plane[i] = static_cast<uint8>(start_value + i); | 65 for (int i = 0; i < stride_v; ++i) { |
| 60 } | 66 *v_plane = static_cast<uint8>(start_value + i + j); |
| 67 ++v_plane; |
| 68 } |
| 61 } | 69 } |
| 62 | 70 |
| 63 bool PopulateVideoFrameFromFile(VideoFrame* frame, FILE* video_file) { | 71 bool PopulateVideoFrameFromFile(VideoFrame* frame, FILE* video_file) { |
| 64 int width = frame->coded_size().width(); | 72 int width = frame->coded_size().width(); |
| 65 int height = frame->coded_size().height(); | 73 int height = frame->coded_size().height(); |
| 66 int half_width = (width + 1) / 2; | 74 int half_width = (width + 1) / 2; |
| 67 int half_height = (height + 1) / 2; | 75 int half_height = (height + 1) / 2; |
| 68 size_t frame_size = width * height + 2 * half_width * half_height; | 76 size_t frame_size = width * height + 2 * half_width * half_height; |
| 69 uint8* y_plane = frame->data(VideoFrame::kYPlane); | 77 uint8* y_plane = frame->data(VideoFrame::kYPlane); |
| 70 uint8* u_plane = frame->data(VideoFrame::kUPlane); | 78 uint8* u_plane = frame->data(VideoFrame::kUPlane); |
| 71 uint8* v_plane = frame->data(VideoFrame::kVPlane); | 79 uint8* v_plane = frame->data(VideoFrame::kVPlane); |
| 72 | 80 |
| 73 uint8* raw_data = new uint8[frame_size]; | 81 uint8* raw_data = new uint8[frame_size]; |
| 74 size_t count = fread(raw_data, 1, frame_size, video_file); | 82 size_t count = fread(raw_data, 1, frame_size, video_file); |
| 75 if (count != frame_size) | 83 if (count != frame_size) |
| 76 return false; | 84 return false; |
| 77 | 85 |
| 78 memcpy(y_plane, raw_data, width * height); | 86 memcpy(y_plane, raw_data, width * height); |
| 79 memcpy(u_plane, raw_data + width * height, half_width * half_height); | 87 memcpy(u_plane, raw_data + width * height, half_width * half_height); |
| 80 memcpy(v_plane, | 88 memcpy(v_plane, |
| 81 raw_data + width * height + half_width * half_height, | 89 raw_data + width * height + half_width * half_height, |
| 82 half_width * half_height); | 90 half_width * half_height); |
| 83 delete[] raw_data; | 91 delete[] raw_data; |
| 84 return true; | 92 return true; |
| 85 } | 93 } |
| 86 | 94 |
| 87 } // namespace cast | 95 } // namespace cast |
| 88 } // namespace media | 96 } // namespace media |
| OLD | NEW |