| 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 "base/rand_util.h" | 10 #include "base/rand_util.h" |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 59 } | 59 } |
| 60 | 60 |
| 61 void PopulateVideoFrame(VideoFrame* frame, int start_value) { | 61 void PopulateVideoFrame(VideoFrame* frame, int start_value) { |
| 62 const gfx::Size frame_size = frame->coded_size(); | 62 const gfx::Size frame_size = frame->coded_size(); |
| 63 const int stripe_size = | 63 const int stripe_size = |
| 64 std::max(32, std::min(frame_size.width(), frame_size.height()) / 8) & -2; | 64 std::max(32, std::min(frame_size.width(), frame_size.height()) / 8) & -2; |
| 65 | 65 |
| 66 // Set Y. | 66 // Set Y. |
| 67 const int height = frame_size.height(); | 67 const int height = frame_size.height(); |
| 68 const int stride_y = frame->stride(VideoFrame::kYPlane); | 68 const int stride_y = frame->stride(VideoFrame::kYPlane); |
| 69 uint8* y_plane = frame->data(VideoFrame::kYPlane); | 69 uint8_t* y_plane = frame->data(VideoFrame::kYPlane); |
| 70 for (int j = 0; j < height; ++j) { | 70 for (int j = 0; j < height; ++j) { |
| 71 const int stripe_j = (j / stripe_size) * stripe_size; | 71 const int stripe_j = (j / stripe_size) * stripe_size; |
| 72 for (int i = 0; i < stride_y; ++i) { | 72 for (int i = 0; i < stride_y; ++i) { |
| 73 const int stripe_i = (i / stripe_size) * stripe_size; | 73 const int stripe_i = (i / stripe_size) * stripe_size; |
| 74 *y_plane = static_cast<uint8>(start_value + stripe_i + stripe_j); | 74 *y_plane = static_cast<uint8_t>(start_value + stripe_i + stripe_j); |
| 75 ++y_plane; | 75 ++y_plane; |
| 76 } | 76 } |
| 77 } | 77 } |
| 78 | 78 |
| 79 const int half_height = (height + 1) / 2; | 79 const int half_height = (height + 1) / 2; |
| 80 if (frame->format() == PIXEL_FORMAT_NV12) { | 80 if (frame->format() == PIXEL_FORMAT_NV12) { |
| 81 const int stride_uv = frame->stride(VideoFrame::kUVPlane); | 81 const int stride_uv = frame->stride(VideoFrame::kUVPlane); |
| 82 uint8* uv_plane = frame->data(VideoFrame::kUVPlane); | 82 uint8_t* uv_plane = frame->data(VideoFrame::kUVPlane); |
| 83 | 83 |
| 84 // Set U and V. | 84 // Set U and V. |
| 85 for (int j = 0; j < half_height; ++j) { | 85 for (int j = 0; j < half_height; ++j) { |
| 86 const int stripe_j = (j / stripe_size) * stripe_size; | 86 const int stripe_j = (j / stripe_size) * stripe_size; |
| 87 for (int i = 0; i < stride_uv; i += 2) { | 87 for (int i = 0; i < stride_uv; i += 2) { |
| 88 const int stripe_i = (i / stripe_size) * stripe_size; | 88 const int stripe_i = (i / stripe_size) * stripe_size; |
| 89 *uv_plane = *(uv_plane + 1) = | 89 *uv_plane = *(uv_plane + 1) = |
| 90 static_cast<uint8>(start_value + stripe_i + stripe_j); | 90 static_cast<uint8_t>(start_value + stripe_i + stripe_j); |
| 91 uv_plane += 2; | 91 uv_plane += 2; |
| 92 } | 92 } |
| 93 } | 93 } |
| 94 } else { | 94 } else { |
| 95 DCHECK(frame->format() == PIXEL_FORMAT_I420 || | 95 DCHECK(frame->format() == PIXEL_FORMAT_I420 || |
| 96 frame->format() == PIXEL_FORMAT_YV12); | 96 frame->format() == PIXEL_FORMAT_YV12); |
| 97 const int stride_u = frame->stride(VideoFrame::kUPlane); | 97 const int stride_u = frame->stride(VideoFrame::kUPlane); |
| 98 const int stride_v = frame->stride(VideoFrame::kVPlane); | 98 const int stride_v = frame->stride(VideoFrame::kVPlane); |
| 99 uint8* u_plane = frame->data(VideoFrame::kUPlane); | 99 uint8_t* u_plane = frame->data(VideoFrame::kUPlane); |
| 100 uint8* v_plane = frame->data(VideoFrame::kVPlane); | 100 uint8_t* v_plane = frame->data(VideoFrame::kVPlane); |
| 101 | 101 |
| 102 // Set U. | 102 // Set U. |
| 103 for (int j = 0; j < half_height; ++j) { | 103 for (int j = 0; j < half_height; ++j) { |
| 104 const int stripe_j = (j / stripe_size) * stripe_size; | 104 const int stripe_j = (j / stripe_size) * stripe_size; |
| 105 for (int i = 0; i < stride_u; ++i) { | 105 for (int i = 0; i < stride_u; ++i) { |
| 106 const int stripe_i = (i / stripe_size) * stripe_size; | 106 const int stripe_i = (i / stripe_size) * stripe_size; |
| 107 *u_plane = static_cast<uint8>(start_value + stripe_i + stripe_j); | 107 *u_plane = static_cast<uint8_t>(start_value + stripe_i + stripe_j); |
| 108 ++u_plane; | 108 ++u_plane; |
| 109 } | 109 } |
| 110 } | 110 } |
| 111 | 111 |
| 112 // Set V. | 112 // Set V. |
| 113 for (int j = 0; j < half_height; ++j) { | 113 for (int j = 0; j < half_height; ++j) { |
| 114 const int stripe_j = (j / stripe_size) * stripe_size; | 114 const int stripe_j = (j / stripe_size) * stripe_size; |
| 115 for (int i = 0; i < stride_v; ++i) { | 115 for (int i = 0; i < stride_v; ++i) { |
| 116 const int stripe_i = (i / stripe_size) * stripe_size; | 116 const int stripe_i = (i / stripe_size) * stripe_size; |
| 117 *v_plane = static_cast<uint8>(start_value + stripe_i + stripe_j); | 117 *v_plane = static_cast<uint8_t>(start_value + stripe_i + stripe_j); |
| 118 ++v_plane; | 118 ++v_plane; |
| 119 } | 119 } |
| 120 } | 120 } |
| 121 } | 121 } |
| 122 } | 122 } |
| 123 | 123 |
| 124 void PopulateVideoFrameWithNoise(VideoFrame* frame) { | 124 void PopulateVideoFrameWithNoise(VideoFrame* frame) { |
| 125 const int height = frame->coded_size().height(); | 125 const int height = frame->coded_size().height(); |
| 126 const int stride_y = frame->stride(VideoFrame::kYPlane); | 126 const int stride_y = frame->stride(VideoFrame::kYPlane); |
| 127 const int stride_u = frame->stride(VideoFrame::kUPlane); | 127 const int stride_u = frame->stride(VideoFrame::kUPlane); |
| 128 const int stride_v = frame->stride(VideoFrame::kVPlane); | 128 const int stride_v = frame->stride(VideoFrame::kVPlane); |
| 129 const int half_height = (height + 1) / 2; | 129 const int half_height = (height + 1) / 2; |
| 130 uint8* const y_plane = frame->data(VideoFrame::kYPlane); | 130 uint8_t* const y_plane = frame->data(VideoFrame::kYPlane); |
| 131 uint8* const u_plane = frame->data(VideoFrame::kUPlane); | 131 uint8_t* const u_plane = frame->data(VideoFrame::kUPlane); |
| 132 uint8* const v_plane = frame->data(VideoFrame::kVPlane); | 132 uint8_t* const v_plane = frame->data(VideoFrame::kVPlane); |
| 133 | 133 |
| 134 base::RandBytes(y_plane, height * stride_y); | 134 base::RandBytes(y_plane, height * stride_y); |
| 135 base::RandBytes(u_plane, half_height * stride_u); | 135 base::RandBytes(u_plane, half_height * stride_u); |
| 136 base::RandBytes(v_plane, half_height * stride_v); | 136 base::RandBytes(v_plane, half_height * stride_v); |
| 137 } | 137 } |
| 138 | 138 |
| 139 bool PopulateVideoFrameFromFile(VideoFrame* frame, FILE* video_file) { | 139 bool PopulateVideoFrameFromFile(VideoFrame* frame, FILE* video_file) { |
| 140 const int width = frame->coded_size().width(); | 140 const int width = frame->coded_size().width(); |
| 141 const int height = frame->coded_size().height(); | 141 const int height = frame->coded_size().height(); |
| 142 const int half_width = (width + 1) / 2; | 142 const int half_width = (width + 1) / 2; |
| 143 const int half_height = (height + 1) / 2; | 143 const int half_height = (height + 1) / 2; |
| 144 const size_t frame_size = width * height + 2 * half_width * half_height; | 144 const size_t frame_size = width * height + 2 * half_width * half_height; |
| 145 uint8* const y_plane = frame->data(VideoFrame::kYPlane); | 145 uint8_t* const y_plane = frame->data(VideoFrame::kYPlane); |
| 146 uint8* const u_plane = frame->data(VideoFrame::kUPlane); | 146 uint8_t* const u_plane = frame->data(VideoFrame::kUPlane); |
| 147 uint8* const v_plane = frame->data(VideoFrame::kVPlane); | 147 uint8_t* const v_plane = frame->data(VideoFrame::kVPlane); |
| 148 | 148 |
| 149 uint8* const raw_data = new uint8[frame_size]; | 149 uint8_t* const raw_data = new uint8_t[frame_size]; |
| 150 const size_t count = fread(raw_data, 1, frame_size, video_file); | 150 const size_t count = fread(raw_data, 1, frame_size, video_file); |
| 151 if (count != frame_size) | 151 if (count != frame_size) |
| 152 return false; | 152 return false; |
| 153 | 153 |
| 154 memcpy(y_plane, raw_data, width * height); | 154 memcpy(y_plane, raw_data, width * height); |
| 155 memcpy(u_plane, raw_data + width * height, half_width * half_height); | 155 memcpy(u_plane, raw_data + width * height, half_width * half_height); |
| 156 memcpy(v_plane, | 156 memcpy(v_plane, |
| 157 raw_data + width * height + half_width * half_height, | 157 raw_data + width * height + half_width * half_height, |
| 158 half_width * half_height); | 158 half_width * half_height); |
| 159 delete[] raw_data; | 159 delete[] raw_data; |
| 160 return true; | 160 return true; |
| 161 } | 161 } |
| 162 | 162 |
| 163 } // namespace cast | 163 } // namespace cast |
| 164 } // namespace media | 164 } // namespace media |
| OLD | NEW |