| 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 LOG(FATAL) << "Unsupported frame format: " << format; |
| 45 return NULL; | |
| 46 } | 34 } |
| 47 return frame; | 35 return frame; |
| 48 } | 36 } |
| 49 | 37 |
| 50 // static | 38 // static |
| 51 bool VideoFrame::IsValidConfig( | 39 bool VideoFrame::IsValidConfig( |
| 52 VideoFrame::Format format, | 40 VideoFrame::Format format, |
| 53 size_t width, | 41 size_t width, |
| 54 size_t height) { | 42 size_t height) { |
| 55 | 43 |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 168 } | 156 } |
| 169 | 157 |
| 170 // In multi-plane allocations, only a single block of memory is allocated | 158 // 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 | 159 // on the heap, and other |data| pointers point inside the same, single block |
| 172 // so just delete index 0. | 160 // so just delete index 0. |
| 173 delete[] data_[0]; | 161 delete[] data_[0]; |
| 174 } | 162 } |
| 175 | 163 |
| 176 bool VideoFrame::IsValidPlane(size_t plane) const { | 164 bool VideoFrame::IsValidPlane(size_t plane) const { |
| 177 switch (format_) { | 165 switch (format_) { |
| 178 case RGB555: | |
| 179 case RGB565: | |
| 180 case RGB24: | |
| 181 case RGB32: | 166 case RGB32: |
| 182 case RGBA: | |
| 183 return plane == kRGBPlane; | 167 return plane == kRGBPlane; |
| 184 | 168 |
| 185 case YV12: | 169 case YV12: |
| 186 case YV16: | 170 case YV16: |
| 187 return plane == kYPlane || plane == kUPlane || plane == kVPlane; | 171 return plane == kYPlane || plane == kUPlane || plane == kVPlane; |
| 188 | 172 |
| 189 case NATIVE_TEXTURE: | 173 case NATIVE_TEXTURE: |
| 190 NOTREACHED() << "NATIVE_TEXTUREs don't use plane-related methods!"; | 174 NOTREACHED() << "NATIVE_TEXTUREs don't use plane-related methods!"; |
| 191 return false; | 175 return false; |
| 192 | 176 |
| 193 default: | 177 default: |
| 194 break; | 178 break; |
| 195 } | 179 } |
| 196 | 180 |
| 197 // Intentionally leave out non-production formats. | 181 // Intentionally leave out non-production formats. |
| 198 NOTREACHED() << "Unsupported video frame format: " << format_; | 182 NOTREACHED() << "Unsupported video frame format: " << format_; |
| 199 return false; | 183 return false; |
| 200 } | 184 } |
| 201 | 185 |
| 202 int VideoFrame::stride(size_t plane) const { | 186 int VideoFrame::stride(size_t plane) const { |
| 203 DCHECK(IsValidPlane(plane)); | 187 DCHECK(IsValidPlane(plane)); |
| 204 return strides_[plane]; | 188 return strides_[plane]; |
| 205 } | 189 } |
| 206 | 190 |
| 207 int VideoFrame::row_bytes(size_t plane) const { | 191 int VideoFrame::row_bytes(size_t plane) const { |
| 208 DCHECK(IsValidPlane(plane)); | 192 DCHECK(IsValidPlane(plane)); |
| 209 switch (format_) { | 193 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. | 194 // 32bpp. |
| 220 case RGB32: | 195 case RGB32: |
| 221 case RGBA: | |
| 222 return width_ * 4; | 196 return width_ * 4; |
| 223 | 197 |
| 224 // Planar, 8bpp. | 198 // Planar, 8bpp. |
| 225 case YV12: | 199 case YV12: |
| 226 case YV16: | 200 case YV16: |
| 227 if (plane == kYPlane) | 201 if (plane == kYPlane) |
| 228 return width_; | 202 return width_; |
| 229 return RoundUp(width_, 2) / 2; | 203 return RoundUp(width_, 2) / 2; |
| 230 | 204 |
| 231 default: | 205 default: |
| 232 break; | 206 break; |
| 233 } | 207 } |
| 234 | 208 |
| 235 // Intentionally leave out non-production formats. | 209 // Intentionally leave out non-production formats. |
| 236 NOTREACHED() << "Unsupported video frame format: " << format_; | 210 NOTREACHED() << "Unsupported video frame format: " << format_; |
| 237 return 0; | 211 return 0; |
| 238 } | 212 } |
| 239 | 213 |
| 240 int VideoFrame::rows(size_t plane) const { | 214 int VideoFrame::rows(size_t plane) const { |
| 241 DCHECK(IsValidPlane(plane)); | 215 DCHECK(IsValidPlane(plane)); |
| 242 switch (format_) { | 216 switch (format_) { |
| 243 case RGB555: | |
| 244 case RGB565: | |
| 245 case RGB24: | |
| 246 case RGB32: | 217 case RGB32: |
| 247 case RGBA: | |
| 248 case YV16: | 218 case YV16: |
| 249 return height_; | 219 return height_; |
| 250 | 220 |
| 251 case YV12: | 221 case YV12: |
| 252 if (plane == kYPlane) | 222 if (plane == kYPlane) |
| 253 return height_; | 223 return height_; |
| 254 return RoundUp(height_, 2) / 2; | 224 return RoundUp(height_, 2) / 2; |
| 255 | 225 |
| 256 default: | 226 default: |
| 257 break; | 227 break; |
| (...skipping 29 matching lines...) Expand all Loading... |
| 287 break; | 257 break; |
| 288 for(int row = 0; row < rows(plane); row++) { | 258 for(int row = 0; row < rows(plane); row++) { |
| 289 base::MD5Update(context, base::StringPiece( | 259 base::MD5Update(context, base::StringPiece( |
| 290 reinterpret_cast<char*>(data(plane) + stride(plane) * row), | 260 reinterpret_cast<char*>(data(plane) + stride(plane) * row), |
| 291 row_bytes(plane))); | 261 row_bytes(plane))); |
| 292 } | 262 } |
| 293 } | 263 } |
| 294 } | 264 } |
| 295 | 265 |
| 296 } // namespace media | 266 } // namespace media |
| OLD | NEW |