| 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), video_frame->visible_rect().width(), |
| 152 video_frame->visible_rect().height(), |
| 153 video_frame->stride(media::VideoFrame::kYPlane), |
| 154 video_frame->stride(media::VideoFrame::kUPlane), row_bytes, |
| 155 media::YV12HD); |
| 156 break; |
| 157 |
| 144 case media::VideoFrame::YV16: | 158 case media::VideoFrame::YV16: |
| 145 LIBYUV_I422_TO_ARGB( | 159 LIBYUV_I422_TO_ARGB( |
| 146 video_frame->data(media::VideoFrame::kYPlane) + y_offset, | 160 video_frame->data(media::VideoFrame::kYPlane) + y_offset, |
| 147 video_frame->stride(media::VideoFrame::kYPlane), | 161 video_frame->stride(media::VideoFrame::kYPlane), |
| 148 video_frame->data(media::VideoFrame::kUPlane) + uv_offset, | 162 video_frame->data(media::VideoFrame::kUPlane) + uv_offset, |
| 149 video_frame->stride(media::VideoFrame::kUPlane), | 163 video_frame->stride(media::VideoFrame::kUPlane), |
| 150 video_frame->data(media::VideoFrame::kVPlane) + uv_offset, | 164 video_frame->data(media::VideoFrame::kVPlane) + uv_offset, |
| 151 video_frame->stride(media::VideoFrame::kVPlane), | 165 video_frame->stride(media::VideoFrame::kVPlane), |
| 152 static_cast<uint8*>(rgb_pixels), | 166 static_cast<uint8*>(rgb_pixels), |
| 153 row_bytes, | 167 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); | 215 DCHECK_EQ(video_frame->format(), media::VideoFrame::NATIVE_TEXTURE); |
| 202 SkBitmap tmp; | 216 SkBitmap tmp; |
| 203 tmp.installPixels( | 217 tmp.installPixels( |
| 204 SkImageInfo::MakeN32Premul(video_frame->visible_rect().width(), | 218 SkImageInfo::MakeN32Premul(video_frame->visible_rect().width(), |
| 205 video_frame->visible_rect().height()), | 219 video_frame->visible_rect().height()), |
| 206 rgb_pixels, | 220 rgb_pixels, |
| 207 row_bytes); | 221 row_bytes); |
| 208 video_frame->ReadPixelsFromNativeTexture(tmp); | 222 video_frame->ReadPixelsFromNativeTexture(tmp); |
| 209 break; | 223 break; |
| 210 } | 224 } |
| 211 default: | 225 case VideoFrame::UNKNOWN: |
| 226 case VideoFrame::NV12: |
| 212 NOTREACHED(); | 227 NOTREACHED(); |
| 213 break; | |
| 214 } | 228 } |
| 215 } | 229 } |
| 216 | 230 |
| 217 } // anonymous namespace | 231 } // anonymous namespace |
| 218 | 232 |
| 219 // Generates an RGB image from a VideoFrame. Convert YUV to RGB plain on GPU. | 233 // Generates an RGB image from a VideoFrame. Convert YUV to RGB plain on GPU. |
| 220 class VideoImageGenerator : public SkImageGenerator { | 234 class VideoImageGenerator : public SkImageGenerator { |
| 221 public: | 235 public: |
| 222 VideoImageGenerator(const scoped_refptr<VideoFrame>& frame) : frame_(frame) { | 236 VideoImageGenerator(const scoped_refptr<VideoFrame>& frame) : frame_(frame) { |
| 223 DCHECK(frame_.get()); | 237 DCHECK(frame_.get()); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 246 return false; | 260 return false; |
| 247 // If skia couldn't do the YUV conversion on GPU, we will on CPU. | 261 // If skia couldn't do the YUV conversion on GPU, we will on CPU. |
| 248 ConvertVideoFrameToRGBPixels(frame_, pixels, row_bytes); | 262 ConvertVideoFrameToRGBPixels(frame_, pixels, row_bytes); |
| 249 return true; | 263 return true; |
| 250 } | 264 } |
| 251 | 265 |
| 252 bool onGetYUV8Planes(SkISize sizes[3], | 266 bool onGetYUV8Planes(SkISize sizes[3], |
| 253 void* planes[3], | 267 void* planes[3], |
| 254 size_t row_bytes[3], | 268 size_t row_bytes[3], |
| 255 SkYUVColorSpace* color_space) override { | 269 SkYUVColorSpace* color_space) override { |
| 256 if (!frame_.get() || !IsYUV(frame_->format())) | 270 if (!frame_.get() || !IsYUV(frame_->format()) || |
| 271 // TODO(rileya): Skia currently doesn't support Rec709 YUV conversion, |
| 272 // Remove this case once it does. As-is we will fall back on the |
| 273 // pure-software path in this case. |
| 274 frame_->format() == VideoFrame::YV12HD) { |
| 257 return false; | 275 return false; |
| 276 } |
| 258 | 277 |
| 259 if (color_space) { | 278 if (color_space) { |
| 260 if (IsJPEGColorSpace(frame_->format())) | 279 if (IsJPEGColorSpace(frame_->format())) |
| 261 *color_space = kJPEG_SkYUVColorSpace; | 280 *color_space = kJPEG_SkYUVColorSpace; |
| 262 else | 281 else |
| 263 *color_space = kRec601_SkYUVColorSpace; | 282 *color_space = kRec601_SkYUVColorSpace; |
| 264 } | 283 } |
| 265 | 284 |
| 266 for (int plane = VideoFrame::kYPlane; plane <= VideoFrame::kVPlane; | 285 for (int plane = VideoFrame::kYPlane; plane <= VideoFrame::kVPlane; |
| 267 ++plane) { | 286 ++plane) { |
| (...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 453 last_frame_timestamp_ = media::kNoTimestamp(); | 472 last_frame_timestamp_ = media::kNoTimestamp(); |
| 454 } | 473 } |
| 455 | 474 |
| 456 void SkCanvasVideoRenderer::ResetAcceleratedLastFrame() { | 475 void SkCanvasVideoRenderer::ResetAcceleratedLastFrame() { |
| 457 accelerated_last_frame_.reset(); | 476 accelerated_last_frame_.reset(); |
| 458 accelerated_generator_ = nullptr; | 477 accelerated_generator_ = nullptr; |
| 459 accelerated_last_frame_timestamp_ = media::kNoTimestamp(); | 478 accelerated_last_frame_timestamp_ = media::kNoTimestamp(); |
| 460 } | 479 } |
| 461 | 480 |
| 462 } // namespace media | 481 } // namespace media |
| OLD | NEW |