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