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 3 // found in the LICENSE file. 4 // 5 // The video renderer implementation to be use by the media pipeline. It lives 6 // inside video renderer thread and also WebKit's main thread. We need to be 7 // extra careful about members shared by two different threads, especially 8 // video frame buffers. 9 10 #ifndef WEBKIT_GLUE_MEDIA_VIDEO_RENDERER_IMPL_H_ 11 #define WEBKIT_GLUE_MEDIA_VIDEO_RENDERER_IMPL_H_ 12 13 #include "media/base/buffers.h" 14 #include "media/base/filters.h" 15 #include "media/filters/video_renderer_base.h" 16 #include "skia/ext/platform_canvas.h" 17 #include "third_party/WebKit/Source/WebKit/chromium/public/WebMediaPlayer.h" 18 #include "ui/gfx/rect.h" 19 #include "ui/gfx/size.h" 20 #include "webkit/glue/media/web_video_renderer.h" 21 #include "webkit/glue/webmediaplayer_impl.h" 22 23 namespace webkit_glue { 24 25 class VideoRendererImpl : public WebVideoRenderer { 26 public: 27 explicit VideoRendererImpl(bool pts_logging); 28 virtual ~VideoRendererImpl(); 29 30 // WebVideoRenderer implementation. 31 virtual void SetWebMediaPlayerImplProxy(WebMediaPlayerImpl::Proxy* proxy); 32 virtual void SetRect(const gfx::Rect& rect); 33 virtual void Paint(SkCanvas* canvas, const gfx::Rect& dest_rect); 34 virtual void GetCurrentFrame(scoped_refptr<media::VideoFrame>* frame_out); 35 virtual void PutCurrentFrame(scoped_refptr<media::VideoFrame> frame); 36 37 protected: 38 // Method called by VideoRendererBase during initialization. 39 virtual bool OnInitialize(media::VideoDecoder* decoder); 40 41 // Method called by the VideoRendererBase when stopping. 42 virtual void OnStop(media::FilterCallback* callback); 43 44 // Method called by the VideoRendererBase when a frame is available. 45 virtual void OnFrameAvailable(); 46 47 private: 48 // Determine the conditions to perform fast paint. Returns true if we can do 49 // fast paint otherwise false. 50 bool CanFastPaint(SkCanvas* canvas, const gfx::Rect& dest_rect); 51 52 // Slow paint does a YUV => RGB, and scaled blit in two separate operations. 53 void SlowPaint(media::VideoFrame* video_frame, 54 SkCanvas* canvas, 55 const gfx::Rect& dest_rect); 56 57 // Fast paint does YUV => RGB, scaling, blitting all in one step into the 58 // canvas. It's not always safe and appropriate to perform fast paint. 59 // CanFastPaint() is used to determine the conditions. 60 void FastPaint(media::VideoFrame* video_frame, 61 SkCanvas* canvas, 62 const gfx::Rect& dest_rect); 63 64 void TransformToSkIRect(const SkMatrix& matrix, const gfx::Rect& src_rect, 65 SkIRect* dest_rect); 66 67 // Pointer to our parent object that is called to request repaints. 68 scoped_refptr<WebMediaPlayerImpl::Proxy> proxy_; 69 70 // An RGB bitmap used to convert the video frames. 71 SkBitmap bitmap_; 72 73 // These two members are used to determine if the |bitmap_| contains 74 // an already converted image of the current frame. IMPORTANT NOTE: The 75 // value of |last_converted_frame_| must only be used for comparison purposes, 76 // and it should be assumed that the value of the pointer is INVALID unless 77 // it matches the pointer returned from GetCurrentFrame(). Even then, just 78 // to make sure, we compare the timestamp to be sure the bits in the 79 // |current_frame_bitmap_| are valid. 80 media::VideoFrame* last_converted_frame_; 81 base::TimeDelta last_converted_timestamp_; 82 83 // The size of the video. 84 gfx::Size video_size_; 85 86 // Whether we're logging video presentation timestamps (PTS). 87 bool pts_logging_; 88 89 DISALLOW_COPY_AND_ASSIGN(VideoRendererImpl); 90 }; 91 92 } // namespace webkit_glue 93 94 #endif // WEBKIT_GLUE_MEDIA_VIDEO_RENDERER_IMPL_H_ 95