OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/base/video_frame.h" | 5 #include "media/base/video_frame.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/string_piece.h" | 8 #include "base/string_piece.h" |
9 #include "media/base/limits.h" | 9 #include "media/base/limits.h" |
10 #include "media/base/video_util.h" | 10 #include "media/base/video_util.h" |
11 | 11 |
12 namespace media { | 12 namespace media { |
13 | 13 |
14 // static | 14 // static |
15 scoped_refptr<VideoFrame> VideoFrame::CreateFrame( | 15 scoped_refptr<VideoFrame> VideoFrame::CreateFrame( |
16 VideoFrame::Format format, | 16 VideoFrame::Format format, |
17 size_t width, | 17 size_t width, |
18 size_t height, | 18 size_t height, |
19 base::TimeDelta timestamp, | 19 base::TimeDelta timestamp, |
20 base::TimeDelta duration) { | 20 base::TimeDelta duration) { |
21 DCHECK(IsValidConfig(format, width, height)); | 21 DCHECK(IsValidConfig(format, width, height)); |
22 scoped_refptr<VideoFrame> frame(new VideoFrame( | 22 scoped_refptr<VideoFrame> frame(new VideoFrame( |
23 format, width, height, timestamp, duration)); | 23 format, width, height, timestamp, duration)); |
24 switch (format) { | 24 switch (format) { |
25 case VideoFrame::RGB555: | |
26 case VideoFrame::RGB565: | |
27 frame->AllocateRGB(2u); | |
28 break; | |
29 case VideoFrame::RGB24: | |
30 frame->AllocateRGB(3u); | |
31 break; | |
32 case VideoFrame::RGB32: | 25 case VideoFrame::RGB32: |
33 case VideoFrame::RGBA: | |
34 frame->AllocateRGB(4u); | 26 frame->AllocateRGB(4u); |
35 break; | 27 break; |
36 case VideoFrame::YV12: | 28 case VideoFrame::YV12: |
37 case VideoFrame::YV16: | 29 case VideoFrame::YV16: |
38 frame->AllocateYUV(); | 30 frame->AllocateYUV(); |
39 break; | 31 break; |
40 case VideoFrame::ASCII: | |
41 frame->AllocateRGB(1u); | |
42 break; | |
43 default: | 32 default: |
44 NOTREACHED(); | 33 NOTREACHED() << format; |
45 return NULL; | 34 return NULL; |
scherkus (not reviewing)
2012/04/10 21:32:31
do we expect clients to handle NULL from CreateFra
Ami GONE FROM CHROMIUM
2012/04/10 22:01:07
Done.
| |
46 } | 35 } |
47 return frame; | 36 return frame; |
48 } | 37 } |
49 | 38 |
50 // static | 39 // static |
51 bool VideoFrame::IsValidConfig( | 40 bool VideoFrame::IsValidConfig( |
52 VideoFrame::Format format, | 41 VideoFrame::Format format, |
53 size_t width, | 42 size_t width, |
54 size_t height) { | 43 size_t height) { |
55 | 44 |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
168 } | 157 } |
169 | 158 |
170 // In multi-plane allocations, only a single block of memory is allocated | 159 // In multi-plane allocations, only a single block of memory is allocated |
171 // on the heap, and other |data| pointers point inside the same, single block | 160 // on the heap, and other |data| pointers point inside the same, single block |
172 // so just delete index 0. | 161 // so just delete index 0. |
173 delete[] data_[0]; | 162 delete[] data_[0]; |
174 } | 163 } |
175 | 164 |
176 bool VideoFrame::IsValidPlane(size_t plane) const { | 165 bool VideoFrame::IsValidPlane(size_t plane) const { |
177 switch (format_) { | 166 switch (format_) { |
178 case RGB555: | |
179 case RGB565: | |
180 case RGB24: | |
181 case RGB32: | 167 case RGB32: |
182 case RGBA: | |
183 return plane == kRGBPlane; | 168 return plane == kRGBPlane; |
184 | 169 |
185 case YV12: | 170 case YV12: |
186 case YV16: | 171 case YV16: |
187 return plane == kYPlane || plane == kUPlane || plane == kVPlane; | 172 return plane == kYPlane || plane == kUPlane || plane == kVPlane; |
188 | 173 |
189 case NATIVE_TEXTURE: | 174 case NATIVE_TEXTURE: |
190 NOTREACHED() << "NATIVE_TEXTUREs don't use plane-related methods!"; | 175 NOTREACHED() << "NATIVE_TEXTUREs don't use plane-related methods!"; |
191 return false; | 176 return false; |
192 | 177 |
193 default: | 178 default: |
194 break; | 179 break; |
195 } | 180 } |
196 | 181 |
197 // Intentionally leave out non-production formats. | 182 // Intentionally leave out non-production formats. |
198 NOTREACHED() << "Unsupported video frame format: " << format_; | 183 NOTREACHED() << "Unsupported video frame format: " << format_; |
199 return false; | 184 return false; |
200 } | 185 } |
201 | 186 |
202 int VideoFrame::stride(size_t plane) const { | 187 int VideoFrame::stride(size_t plane) const { |
203 DCHECK(IsValidPlane(plane)); | 188 DCHECK(IsValidPlane(plane)); |
204 return strides_[plane]; | 189 return strides_[plane]; |
205 } | 190 } |
206 | 191 |
207 int VideoFrame::row_bytes(size_t plane) const { | 192 int VideoFrame::row_bytes(size_t plane) const { |
208 DCHECK(IsValidPlane(plane)); | 193 DCHECK(IsValidPlane(plane)); |
209 switch (format_) { | 194 switch (format_) { |
210 // 16bpp. | |
211 case RGB555: | |
212 case RGB565: | |
213 return width_ * 2; | |
214 | |
215 // 24bpp. | |
216 case RGB24: | |
217 return width_ * 3; | |
218 | |
219 // 32bpp. | 195 // 32bpp. |
220 case RGB32: | 196 case RGB32: |
221 case RGBA: | |
222 return width_ * 4; | 197 return width_ * 4; |
223 | 198 |
224 // Planar, 8bpp. | 199 // Planar, 8bpp. |
225 case YV12: | 200 case YV12: |
226 case YV16: | 201 case YV16: |
227 if (plane == kYPlane) | 202 if (plane == kYPlane) |
228 return width_; | 203 return width_; |
229 return RoundUp(width_, 2) / 2; | 204 return RoundUp(width_, 2) / 2; |
230 | 205 |
231 default: | 206 default: |
232 break; | 207 break; |
233 } | 208 } |
234 | 209 |
235 // Intentionally leave out non-production formats. | 210 // Intentionally leave out non-production formats. |
236 NOTREACHED() << "Unsupported video frame format: " << format_; | 211 NOTREACHED() << "Unsupported video frame format: " << format_; |
237 return 0; | 212 return 0; |
238 } | 213 } |
239 | 214 |
240 int VideoFrame::rows(size_t plane) const { | 215 int VideoFrame::rows(size_t plane) const { |
241 DCHECK(IsValidPlane(plane)); | 216 DCHECK(IsValidPlane(plane)); |
242 switch (format_) { | 217 switch (format_) { |
243 case RGB555: | |
244 case RGB565: | |
245 case RGB24: | |
246 case RGB32: | 218 case RGB32: |
247 case RGBA: | |
248 case YV16: | 219 case YV16: |
249 return height_; | 220 return height_; |
250 | 221 |
251 case YV12: | 222 case YV12: |
252 if (plane == kYPlane) | 223 if (plane == kYPlane) |
253 return height_; | 224 return height_; |
254 return RoundUp(height_, 2) / 2; | 225 return RoundUp(height_, 2) / 2; |
255 | 226 |
256 default: | 227 default: |
257 break; | 228 break; |
(...skipping 29 matching lines...) Expand all Loading... | |
287 break; | 258 break; |
288 for(int row = 0; row < rows(plane); row++) { | 259 for(int row = 0; row < rows(plane); row++) { |
289 base::MD5Update(context, base::StringPiece( | 260 base::MD5Update(context, base::StringPiece( |
290 reinterpret_cast<char*>(data(plane) + stride(plane) * row), | 261 reinterpret_cast<char*>(data(plane) + stride(plane) * row), |
291 row_bytes(plane))); | 262 row_bytes(plane))); |
292 } | 263 } |
293 } | 264 } |
294 } | 265 } |
295 | 266 |
296 } // namespace media | 267 } // namespace media |
OLD | NEW |