| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "webkit/media/video_renderer_impl.h" | 5 #include "webkit/media/video_renderer_impl.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/skia/include/core/SkCanvas.h" | 10 #include "third_party/skia/include/core/SkCanvas.h" |
| 11 #include "third_party/skia/include/core/SkDevice.h" | 11 #include "third_party/skia/include/core/SkDevice.h" |
| 12 #include "webkit/media/webmediaplayer_proxy.h" | 12 #include "webkit/media/webmediaplayer_proxy.h" |
| 13 | 13 |
| 14 namespace webkit_media { | 14 namespace webkit_media { |
| 15 | 15 |
| 16 VideoRendererImpl::VideoRendererImpl(bool pts_logging) | 16 VideoRendererImpl::VideoRendererImpl( |
| 17 : last_converted_frame_(NULL), | 17 const scoped_refptr<WebMediaPlayerProxy>& proxy) |
| 18 pts_logging_(pts_logging) { | 18 : proxy_(proxy), |
| 19 last_converted_frame_(NULL) { |
| 19 } | 20 } |
| 20 | 21 |
| 21 VideoRendererImpl::~VideoRendererImpl() {} | 22 VideoRendererImpl::~VideoRendererImpl() {} |
| 22 | 23 |
| 23 bool VideoRendererImpl::OnInitialize(media::VideoDecoder* decoder) { | 24 bool VideoRendererImpl::OnInitialize(media::VideoDecoder* decoder) { |
| 24 natural_size_ = decoder->natural_size(); | 25 natural_size_ = decoder->natural_size(); |
| 25 bitmap_.setConfig(SkBitmap::kARGB_8888_Config, | 26 bitmap_.setConfig(SkBitmap::kARGB_8888_Config, |
| 26 natural_size_.width(), natural_size_.height()); | 27 natural_size_.width(), natural_size_.height()); |
| 27 bitmap_.allocPixels(); | 28 bitmap_.allocPixels(); |
| 28 bitmap_.eraseRGB(0x00, 0x00, 0x00); | 29 bitmap_.eraseRGB(0x00, 0x00, 0x00); |
| 29 bitmap_.setIsVolatile(true); | 30 bitmap_.setIsVolatile(true); |
| 30 return true; | 31 return true; |
| 31 } | 32 } |
| 32 | 33 |
| 33 void VideoRendererImpl::OnStop(const base::Closure& callback) { | 34 void VideoRendererImpl::OnStop(const base::Closure& callback) { |
| 34 if (!callback.is_null()) | 35 if (!callback.is_null()) |
| 35 callback.Run(); | 36 callback.Run(); |
| 36 } | 37 } |
| 37 | 38 |
| 38 void VideoRendererImpl::OnFrameAvailable() { | 39 void VideoRendererImpl::OnFrameAvailable() { |
| 39 proxy_->Repaint(); | 40 proxy_->Repaint(); |
| 40 } | 41 } |
| 41 | 42 |
| 42 void VideoRendererImpl::SetWebMediaPlayerProxy(WebMediaPlayerProxy* proxy) { | |
| 43 proxy_ = proxy; | |
| 44 } | |
| 45 | |
| 46 void VideoRendererImpl::SetRect(const gfx::Rect& rect) {} | |
| 47 | |
| 48 // This method is always called on the renderer's thread. | 43 // This method is always called on the renderer's thread. |
| 49 void VideoRendererImpl::Paint(SkCanvas* canvas, const gfx::Rect& dest_rect) { | 44 void VideoRendererImpl::Paint(SkCanvas* canvas, const gfx::Rect& dest_rect) { |
| 50 scoped_refptr<media::VideoFrame> video_frame; | 45 scoped_refptr<media::VideoFrame> video_frame; |
| 51 GetCurrentFrame(&video_frame); | 46 GetCurrentFrame(&video_frame); |
| 52 if (!video_frame) { | 47 if (!video_frame) { |
| 53 SkPaint paint; | 48 SkPaint paint; |
| 54 paint.setColor(SK_ColorBLACK); | 49 paint.setColor(SK_ColorBLACK); |
| 55 canvas->drawRectCoords( | 50 canvas->drawRectCoords( |
| 56 static_cast<float>(dest_rect.x()), | 51 static_cast<float>(dest_rect.x()), |
| 57 static_cast<float>(dest_rect.y()), | 52 static_cast<float>(dest_rect.y()), |
| 58 static_cast<float>(dest_rect.right()), | 53 static_cast<float>(dest_rect.right()), |
| 59 static_cast<float>(dest_rect.bottom()), | 54 static_cast<float>(dest_rect.bottom()), |
| 60 paint); | 55 paint); |
| 61 } else { | 56 } else { |
| 62 if (CanFastPaint(canvas, dest_rect)) { | 57 if (CanFastPaint(canvas, dest_rect)) { |
| 63 FastPaint(video_frame, canvas, dest_rect); | 58 FastPaint(video_frame, canvas, dest_rect); |
| 64 } else { | 59 } else { |
| 65 SlowPaint(video_frame, canvas, dest_rect); | 60 SlowPaint(video_frame, canvas, dest_rect); |
| 66 } | 61 } |
| 67 | |
| 68 // Presentation timestamp logging is primarily used to measure performance | |
| 69 // on low-end devices. When profiled on an Intel Atom N280 @ 1.66GHz this | |
| 70 // code had a ~63 microsecond perf hit when logging to a file (not stdout), | |
| 71 // which is neglible enough for measuring playback performance. | |
| 72 if (pts_logging_) | |
| 73 VLOG(1) << "pts=" << video_frame->GetTimestamp().InMicroseconds(); | |
| 74 } | 62 } |
| 75 | 63 |
| 76 PutCurrentFrame(video_frame); | 64 PutCurrentFrame(video_frame); |
| 77 } | 65 } |
| 78 | 66 |
| 79 // CanFastPaint is a helper method to determine the conditions for fast | 67 // CanFastPaint is a helper method to determine the conditions for fast |
| 80 // painting. The conditions are: | 68 // painting. The conditions are: |
| 81 // 1. No skew in canvas matrix. | 69 // 1. No skew in canvas matrix. |
| 82 // 2. No flipping nor mirroring. | 70 // 2. No flipping nor mirroring. |
| 83 // 3. Canvas has pixel format ARGB8888. | 71 // 3. Canvas has pixel format ARGB8888. |
| (...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 269 video_frame->stride(media::VideoFrame::kUPlane), | 257 video_frame->stride(media::VideoFrame::kUPlane), |
| 270 bitmap.rowBytes(), | 258 bitmap.rowBytes(), |
| 271 yuv_type, | 259 yuv_type, |
| 272 media::ROTATE_0, | 260 media::ROTATE_0, |
| 273 media::FILTER_BILINEAR); | 261 media::FILTER_BILINEAR); |
| 274 bitmap.unlockPixels(); | 262 bitmap.unlockPixels(); |
| 275 } | 263 } |
| 276 } | 264 } |
| 277 | 265 |
| 278 } // namespace webkit_media | 266 } // namespace webkit_media |
| OLD | NEW |