Chromium Code Reviews| 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/filters/skcanvas_video_renderer.h" | 5 #include "media/filters/skcanvas_video_renderer.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "media/base/video_frame.h" | 8 #include "media/base/video_frame.h" |
| 9 #include "media/base/yuv_convert.h" | 9 #include "media/base/yuv_convert.h" |
| 10 #include "third_party/libyuv/include/libyuv.h" | 10 #include "third_party/libyuv/include/libyuv.h" |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 37 // a temporary resource if it is not used for 3 sec. | 37 // a temporary resource if it is not used for 3 sec. |
| 38 const int kTemporaryResourceDeletionDelay = 3; // Seconds; | 38 const int kTemporaryResourceDeletionDelay = 3; // Seconds; |
| 39 | 39 |
| 40 bool IsYUV(media::VideoFrame::Format format) { | 40 bool IsYUV(media::VideoFrame::Format format) { |
| 41 switch (format) { | 41 switch (format) { |
| 42 case VideoFrame::YV12: | 42 case VideoFrame::YV12: |
| 43 case VideoFrame::YV16: | 43 case VideoFrame::YV16: |
| 44 case VideoFrame::I420: | 44 case VideoFrame::I420: |
| 45 case VideoFrame::YV12A: | 45 case VideoFrame::YV12A: |
| 46 case VideoFrame::YV12J: | 46 case VideoFrame::YV12J: |
| 47 case VideoFrame::YV12HD: | |
| 47 case VideoFrame::YV24: | 48 case VideoFrame::YV24: |
| 48 case VideoFrame::NV12: | 49 case VideoFrame::NV12: |
| 49 return true; | 50 return true; |
| 50 case VideoFrame::UNKNOWN: | 51 case VideoFrame::UNKNOWN: |
| 51 case VideoFrame::NATIVE_TEXTURE: | 52 case VideoFrame::NATIVE_TEXTURE: |
| 52 #if defined(VIDEO_HOLE) | 53 #if defined(VIDEO_HOLE) |
| 53 case VideoFrame::HOLE: | 54 case VideoFrame::HOLE: |
| 54 #endif // defined(VIDEO_HOLE) | 55 #endif // defined(VIDEO_HOLE) |
| 55 return false; | 56 return false; |
| 56 } | 57 } |
| 57 NOTREACHED() << "Invalid videoframe format provided: " << format; | 58 NOTREACHED() << "Invalid videoframe format provided: " << format; |
| 58 return false; | 59 return false; |
| 59 } | 60 } |
| 60 | 61 |
| 61 bool IsJPEGColorSpace(media::VideoFrame::Format format) { | 62 bool IsJPEGColorSpace(media::VideoFrame::Format format) { |
| 62 switch (format) { | 63 switch (format) { |
| 63 case VideoFrame::YV12J: | 64 case VideoFrame::YV12J: |
| 64 return true; | 65 return true; |
| 65 case VideoFrame::YV12: | 66 case VideoFrame::YV12: |
| 67 case VideoFrame::YV12HD: | |
| 66 case VideoFrame::YV16: | 68 case VideoFrame::YV16: |
| 67 case VideoFrame::I420: | 69 case VideoFrame::I420: |
| 68 case VideoFrame::YV12A: | 70 case VideoFrame::YV12A: |
| 69 case VideoFrame::YV24: | 71 case VideoFrame::YV24: |
| 70 case VideoFrame::NV12: | 72 case VideoFrame::NV12: |
| 71 case VideoFrame::UNKNOWN: | 73 case VideoFrame::UNKNOWN: |
| 72 case VideoFrame::NATIVE_TEXTURE: | 74 case VideoFrame::NATIVE_TEXTURE: |
| 73 #if defined(VIDEO_HOLE) | 75 #if defined(VIDEO_HOLE) |
| 74 case VideoFrame::HOLE: | 76 case VideoFrame::HOLE: |
| 75 #endif // defined(VIDEO_HOLE) | 77 #endif // defined(VIDEO_HOLE) |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 134 video_frame->data(media::VideoFrame::kVPlane) + uv_offset, | 136 video_frame->data(media::VideoFrame::kVPlane) + uv_offset, |
| 135 static_cast<uint8*>(rgb_pixels), | 137 static_cast<uint8*>(rgb_pixels), |
| 136 video_frame->visible_rect().width(), | 138 video_frame->visible_rect().width(), |
| 137 video_frame->visible_rect().height(), | 139 video_frame->visible_rect().height(), |
| 138 video_frame->stride(media::VideoFrame::kYPlane), | 140 video_frame->stride(media::VideoFrame::kYPlane), |
| 139 video_frame->stride(media::VideoFrame::kUPlane), | 141 video_frame->stride(media::VideoFrame::kUPlane), |
| 140 row_bytes, | 142 row_bytes, |
| 141 media::YV12J); | 143 media::YV12J); |
| 142 break; | 144 break; |
| 143 | 145 |
| 146 case media::VideoFrame::YV12HD: | |
| 147 media::ConvertYUVToRGB32( | |
| 148 video_frame->data(media::VideoFrame::kYPlane) + y_offset, | |
| 149 video_frame->data(media::VideoFrame::kUPlane) + uv_offset, | |
| 150 video_frame->data(media::VideoFrame::kVPlane) + uv_offset, | |
| 151 static_cast<uint8*>(rgb_pixels), | |
| 152 video_frame->visible_rect().width(), | |
| 153 video_frame->visible_rect().height(), | |
| 154 video_frame->stride(media::VideoFrame::kYPlane), | |
| 155 video_frame->stride(media::VideoFrame::kUPlane), | |
| 156 row_bytes, | |
| 157 media::YV12HD); | |
| 158 break; | |
| 159 | |
| 144 case media::VideoFrame::YV16: | 160 case media::VideoFrame::YV16: |
| 145 LIBYUV_I422_TO_ARGB( | 161 LIBYUV_I422_TO_ARGB( |
| 146 video_frame->data(media::VideoFrame::kYPlane) + y_offset, | 162 video_frame->data(media::VideoFrame::kYPlane) + y_offset, |
| 147 video_frame->stride(media::VideoFrame::kYPlane), | 163 video_frame->stride(media::VideoFrame::kYPlane), |
| 148 video_frame->data(media::VideoFrame::kUPlane) + uv_offset, | 164 video_frame->data(media::VideoFrame::kUPlane) + uv_offset, |
| 149 video_frame->stride(media::VideoFrame::kUPlane), | 165 video_frame->stride(media::VideoFrame::kUPlane), |
| 150 video_frame->data(media::VideoFrame::kVPlane) + uv_offset, | 166 video_frame->data(media::VideoFrame::kVPlane) + uv_offset, |
| 151 video_frame->stride(media::VideoFrame::kVPlane), | 167 video_frame->stride(media::VideoFrame::kVPlane), |
| 152 static_cast<uint8*>(rgb_pixels), | 168 static_cast<uint8*>(rgb_pixels), |
| 153 row_bytes, | 169 row_bytes, |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 201 DCHECK_EQ(video_frame->format(), media::VideoFrame::NATIVE_TEXTURE); | 217 DCHECK_EQ(video_frame->format(), media::VideoFrame::NATIVE_TEXTURE); |
| 202 SkBitmap tmp; | 218 SkBitmap tmp; |
| 203 tmp.installPixels( | 219 tmp.installPixels( |
| 204 SkImageInfo::MakeN32Premul(video_frame->visible_rect().width(), | 220 SkImageInfo::MakeN32Premul(video_frame->visible_rect().width(), |
| 205 video_frame->visible_rect().height()), | 221 video_frame->visible_rect().height()), |
| 206 rgb_pixels, | 222 rgb_pixels, |
| 207 row_bytes); | 223 row_bytes); |
| 208 video_frame->ReadPixelsFromNativeTexture(tmp); | 224 video_frame->ReadPixelsFromNativeTexture(tmp); |
| 209 break; | 225 break; |
| 210 } | 226 } |
| 211 default: | 227 case VideoFrame::UNKNOWN: |
| 228 case VideoFrame::NV12: | |
| 212 NOTREACHED(); | 229 NOTREACHED(); |
| 213 break; | |
| 214 } | 230 } |
| 215 } | 231 } |
| 216 | 232 |
| 217 } // anonymous namespace | 233 } // anonymous namespace |
| 218 | 234 |
| 219 // Generates an RGB image from a VideoFrame. Convert YUV to RGB plain on GPU. | 235 // Generates an RGB image from a VideoFrame. Convert YUV to RGB plain on GPU. |
| 220 class VideoImageGenerator : public SkImageGenerator { | 236 class VideoImageGenerator : public SkImageGenerator { |
| 221 public: | 237 public: |
| 222 VideoImageGenerator(const scoped_refptr<VideoFrame>& frame) : frame_(frame) { | 238 VideoImageGenerator(const scoped_refptr<VideoFrame>& frame) : frame_(frame) { |
| 223 DCHECK(frame_.get()); | 239 DCHECK(frame_.get()); |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 249 return true; | 265 return true; |
| 250 } | 266 } |
| 251 | 267 |
| 252 bool onGetYUV8Planes(SkISize sizes[3], | 268 bool onGetYUV8Planes(SkISize sizes[3], |
| 253 void* planes[3], | 269 void* planes[3], |
| 254 size_t row_bytes[3], | 270 size_t row_bytes[3], |
| 255 SkYUVColorSpace* color_space) override { | 271 SkYUVColorSpace* color_space) override { |
| 256 if (!frame_.get() || !IsYUV(frame_->format())) | 272 if (!frame_.get() || !IsYUV(frame_->format())) |
| 257 return false; | 273 return false; |
| 258 | 274 |
| 275 // Skia currently can't convert Rec709 "HD" color space YUV to RGB. | |
| 276 // TODO(rileya): Add support for HD color space in Skia's YUV conversions. | |
|
DaleCurtis
2014/12/15 18:47:34
Doesn't this just need the right matrix below? Wit
rileya (GONE FROM CHROMIUM)
2014/12/16 22:05:59
Skia needs the 709 matrix to get plumbed into its
| |
| 277 if (frame_->format() == VideoFrame::YV12HD) | |
| 278 return false; | |
| 279 | |
| 259 if (color_space) { | 280 if (color_space) { |
| 260 if (IsJPEGColorSpace(frame_->format())) | 281 if (IsJPEGColorSpace(frame_->format())) |
| 261 *color_space = kJPEG_SkYUVColorSpace; | 282 *color_space = kJPEG_SkYUVColorSpace; |
| 262 else | 283 else |
| 263 *color_space = kRec601_SkYUVColorSpace; | 284 *color_space = kRec601_SkYUVColorSpace; |
| 264 } | 285 } |
| 265 | 286 |
| 266 for (int plane = VideoFrame::kYPlane; plane <= VideoFrame::kVPlane; | 287 for (int plane = VideoFrame::kYPlane; plane <= VideoFrame::kVPlane; |
| 267 ++plane) { | 288 ++plane) { |
| 268 if (sizes) { | 289 if (sizes) { |
| (...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 453 last_frame_timestamp_ = media::kNoTimestamp(); | 474 last_frame_timestamp_ = media::kNoTimestamp(); |
| 454 } | 475 } |
| 455 | 476 |
| 456 void SkCanvasVideoRenderer::ResetAcceleratedLastFrame() { | 477 void SkCanvasVideoRenderer::ResetAcceleratedLastFrame() { |
| 457 accelerated_last_frame_.reset(); | 478 accelerated_last_frame_.reset(); |
| 458 accelerated_generator_ = nullptr; | 479 accelerated_generator_ = nullptr; |
| 459 accelerated_last_frame_timestamp_ = media::kNoTimestamp(); | 480 accelerated_last_frame_timestamp_ = media::kNoTimestamp(); |
| 460 } | 481 } |
| 461 | 482 |
| 462 } // namespace media | 483 } // namespace media |
| OLD | NEW |