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 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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>(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 defined(OS_MACOSX) |
80 if (frame->format() == VideoFrame::NV12) { | 81 if (frame->format() == VideoFrame::NV12) { |
81 const int stride_uv = frame->stride(VideoFrame::kUVPlane); | 82 const int stride_uv = frame->stride(VideoFrame::kUVPlane); |
82 uint8* uv_plane = frame->data(VideoFrame::kUVPlane); | 83 uint8* uv_plane = frame->data(VideoFrame::kUVPlane); |
83 | 84 |
84 // Set U and V. | 85 // Set U and V. |
85 for (int j = 0; j < half_height; ++j) { | 86 for (int j = 0; j < half_height; ++j) { |
86 const int stripe_j = (j / stripe_size) * stripe_size; | 87 const int stripe_j = (j / stripe_size) * stripe_size; |
87 for (int i = 0; i < stride_uv; i += 2) { | 88 for (int i = 0; i < stride_uv; i += 2) { |
88 const int stripe_i = (i / stripe_size) * stripe_size; | 89 const int stripe_i = (i / stripe_size) * stripe_size; |
89 *uv_plane = *(uv_plane + 1) = | 90 *uv_plane = *(uv_plane + 1) = |
90 static_cast<uint8>(start_value + stripe_i + stripe_j); | 91 static_cast<uint8>(start_value + stripe_i + stripe_j); |
91 uv_plane += 2; | 92 uv_plane += 2; |
92 } | 93 } |
93 } | 94 } |
94 } else { // I420, YV12, etc. | 95 } else |
| 96 #endif |
| 97 { |
| 98 DCHECK(frame->format() == VideoFrame::I420 || |
| 99 frame->format() == VideoFrame::YV12); |
95 const int stride_u = frame->stride(VideoFrame::kUPlane); | 100 const int stride_u = frame->stride(VideoFrame::kUPlane); |
96 const int stride_v = frame->stride(VideoFrame::kVPlane); | 101 const int stride_v = frame->stride(VideoFrame::kVPlane); |
97 uint8* u_plane = frame->data(VideoFrame::kUPlane); | 102 uint8* u_plane = frame->data(VideoFrame::kUPlane); |
98 uint8* v_plane = frame->data(VideoFrame::kVPlane); | 103 uint8* v_plane = frame->data(VideoFrame::kVPlane); |
99 | 104 |
100 // Set U. | 105 // Set U. |
101 for (int j = 0; j < half_height; ++j) { | 106 for (int j = 0; j < half_height; ++j) { |
102 const int stripe_j = (j / stripe_size) * stripe_size; | 107 const int stripe_j = (j / stripe_size) * stripe_size; |
103 for (int i = 0; i < stride_u; ++i) { | 108 for (int i = 0; i < stride_u; ++i) { |
104 const int stripe_i = (i / stripe_size) * stripe_size; | 109 const int stripe_i = (i / stripe_size) * stripe_size; |
105 *u_plane = static_cast<uint8>(start_value + stripe_i + stripe_j); | 110 *u_plane = static_cast<uint8>(start_value + stripe_i + stripe_j); |
106 ++u_plane; | 111 ++u_plane; |
107 } | 112 } |
108 } | 113 } |
109 | 114 |
110 // Set V. | 115 // Set V. |
111 for (int j = 0; j < half_height; ++j) { | 116 for (int j = 0; j < half_height; ++j) { |
112 const int stripe_j = (j / stripe_size) * stripe_size; | 117 const int stripe_j = (j / stripe_size) * stripe_size; |
113 for (int i = 0; i < stride_v; ++i) { | 118 for (int i = 0; i < stride_v; ++i) { |
114 const int stripe_i = (i / stripe_size) * stripe_size; | 119 const int stripe_i = (i / stripe_size) * stripe_size; |
115 *u_plane = static_cast<uint8>(start_value + stripe_i + stripe_j); | 120 *v_plane = static_cast<uint8>(start_value + stripe_i + stripe_j); |
116 ++v_plane; | 121 ++v_plane; |
117 } | 122 } |
118 } | 123 } |
119 } | 124 } |
120 } | 125 } |
121 | 126 |
122 void PopulateVideoFrameWithNoise(VideoFrame* frame) { | 127 void PopulateVideoFrameWithNoise(VideoFrame* frame) { |
123 int height = frame->coded_size().height(); | 128 const int height = frame->coded_size().height(); |
124 int stride_y = frame->stride(VideoFrame::kYPlane); | 129 const int stride_y = frame->stride(VideoFrame::kYPlane); |
125 int stride_u = frame->stride(VideoFrame::kUPlane); | 130 const int stride_u = frame->stride(VideoFrame::kUPlane); |
126 int stride_v = frame->stride(VideoFrame::kVPlane); | 131 const int stride_v = frame->stride(VideoFrame::kVPlane); |
127 int half_height = (height + 1) / 2; | 132 const int half_height = (height + 1) / 2; |
128 uint8* y_plane = frame->data(VideoFrame::kYPlane); | 133 uint8* const y_plane = frame->data(VideoFrame::kYPlane); |
129 uint8* u_plane = frame->data(VideoFrame::kUPlane); | 134 uint8* const u_plane = frame->data(VideoFrame::kUPlane); |
130 uint8* v_plane = frame->data(VideoFrame::kVPlane); | 135 uint8* const v_plane = frame->data(VideoFrame::kVPlane); |
131 | 136 |
132 base::RandBytes(y_plane, height * stride_y); | 137 base::RandBytes(y_plane, height * stride_y); |
133 base::RandBytes(u_plane, half_height * stride_u); | 138 base::RandBytes(u_plane, half_height * stride_u); |
134 base::RandBytes(v_plane, half_height * stride_v); | 139 base::RandBytes(v_plane, half_height * stride_v); |
135 } | 140 } |
136 | 141 |
137 bool PopulateVideoFrameFromFile(VideoFrame* frame, FILE* video_file) { | 142 bool PopulateVideoFrameFromFile(VideoFrame* frame, FILE* video_file) { |
138 int width = frame->coded_size().width(); | 143 const int width = frame->coded_size().width(); |
139 int height = frame->coded_size().height(); | 144 const int height = frame->coded_size().height(); |
140 int half_width = (width + 1) / 2; | 145 const int half_width = (width + 1) / 2; |
141 int half_height = (height + 1) / 2; | 146 const int half_height = (height + 1) / 2; |
142 size_t frame_size = width * height + 2 * half_width * half_height; | 147 const size_t frame_size = width * height + 2 * half_width * half_height; |
143 uint8* y_plane = frame->data(VideoFrame::kYPlane); | 148 uint8* const y_plane = frame->data(VideoFrame::kYPlane); |
144 uint8* u_plane = frame->data(VideoFrame::kUPlane); | 149 uint8* const u_plane = frame->data(VideoFrame::kUPlane); |
145 uint8* v_plane = frame->data(VideoFrame::kVPlane); | 150 uint8* const v_plane = frame->data(VideoFrame::kVPlane); |
146 | 151 |
147 uint8* raw_data = new uint8[frame_size]; | 152 uint8* const raw_data = new uint8[frame_size]; |
148 size_t count = fread(raw_data, 1, frame_size, video_file); | 153 const size_t count = fread(raw_data, 1, frame_size, video_file); |
149 if (count != frame_size) | 154 if (count != frame_size) |
150 return false; | 155 return false; |
151 | 156 |
152 memcpy(y_plane, raw_data, width * height); | 157 memcpy(y_plane, raw_data, width * height); |
153 memcpy(u_plane, raw_data + width * height, half_width * half_height); | 158 memcpy(u_plane, raw_data + width * height, half_width * half_height); |
154 memcpy(v_plane, | 159 memcpy(v_plane, |
155 raw_data + width * height + half_width * half_height, | 160 raw_data + width * height + half_width * half_height, |
156 half_width * half_height); | 161 half_width * half_height); |
157 delete[] raw_data; | 162 delete[] raw_data; |
158 return true; | 163 return true; |
159 } | 164 } |
160 | 165 |
161 } // namespace cast | 166 } // namespace cast |
162 } // namespace media | 167 } // namespace media |
OLD | NEW |