Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 #ifndef CONTENT_RENDERER_MEDIA_WEBMEDIAPLAYER_MS_H_ | 5 #ifndef CONTENT_RENDERER_MEDIA_WEBMEDIAPLAYER_MS_H_ |
| 6 #define CONTENT_RENDERER_MEDIA_WEBMEDIAPLAYER_MS_H_ | 6 #define CONTENT_RENDERER_MEDIA_WEBMEDIAPLAYER_MS_H_ |
| 7 | 7 |
| 8 #include "base/memory/ref_counted.h" | 8 #include "base/memory/ref_counted.h" |
| 9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
| 10 #include "base/memory/weak_ptr.h" | 10 #include "base/memory/weak_ptr.h" |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 46 // provides video frames for rendering. | 46 // provides video frames for rendering. |
| 47 // | 47 // |
| 48 // TODO(wjia): add AudioPlayer. | 48 // TODO(wjia): add AudioPlayer. |
| 49 // AudioPlayer | 49 // AudioPlayer |
| 50 // plays audio streams. | 50 // plays audio streams. |
| 51 // | 51 // |
| 52 // blink::WebMediaPlayerClient | 52 // blink::WebMediaPlayerClient |
| 53 // WebKit client of this media player object. | 53 // WebKit client of this media player object. |
| 54 class WebMediaPlayerMS | 54 class WebMediaPlayerMS |
| 55 : public blink::WebMediaPlayer, | 55 : public blink::WebMediaPlayer, |
| 56 public cc::VideoFrameProvider, | |
| 57 public base::SupportsWeakPtr<WebMediaPlayerMS> { | 56 public base::SupportsWeakPtr<WebMediaPlayerMS> { |
| 58 public: | 57 public: |
| 59 // Construct a WebMediaPlayerMS with reference to the client, and | 58 // Construct a WebMediaPlayerMS with reference to the client, and |
| 60 // a MediaStreamClient which provides VideoFrameProvider. | 59 // a MediaStreamClient which provides VideoFrameProvider. |
| 61 WebMediaPlayerMS(blink::WebFrame* frame, | 60 WebMediaPlayerMS( |
| 62 blink::WebMediaPlayerClient* client, | 61 blink::WebFrame* frame, |
| 63 base::WeakPtr<media::WebMediaPlayerDelegate> delegate, | 62 blink::WebMediaPlayerClient* client, |
| 64 media::MediaLog* media_log, | 63 base::WeakPtr<media::WebMediaPlayerDelegate> delegate, |
| 65 scoped_ptr<MediaStreamRendererFactory> factory); | 64 media::MediaLog* media_log, |
| 65 scoped_ptr<MediaStreamRendererFactory> factory, | |
| 66 scoped_refptr<base::SingleThreadTaskRunner> compositor_thread); | |
| 67 | |
| 66 virtual ~WebMediaPlayerMS(); | 68 virtual ~WebMediaPlayerMS(); |
| 67 | 69 |
| 68 virtual void load(LoadType load_type, | 70 virtual void load(LoadType load_type, |
| 69 const blink::WebURL& url, | 71 const blink::WebURL& url, |
| 70 CORSMode cors_mode); | 72 CORSMode cors_mode); |
| 71 | 73 |
| 72 // Playback controls. | 74 // Playback controls. |
| 73 virtual void play(); | 75 virtual void play(); |
| 74 virtual void pause(); | 76 virtual void pause(); |
| 75 virtual bool supportsSave() const; | 77 virtual bool supportsSave() const; |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 118 virtual unsigned videoDecodedByteCount() const; | 120 virtual unsigned videoDecodedByteCount() const; |
| 119 | 121 |
| 120 bool copyVideoTextureToPlatformTexture( | 122 bool copyVideoTextureToPlatformTexture( |
| 121 blink::WebGraphicsContext3D* web_graphics_context, | 123 blink::WebGraphicsContext3D* web_graphics_context, |
| 122 unsigned int texture, | 124 unsigned int texture, |
| 123 unsigned int internal_format, | 125 unsigned int internal_format, |
| 124 unsigned int type, | 126 unsigned int type, |
| 125 bool premultiply_alpha, | 127 bool premultiply_alpha, |
| 126 bool flip_y) override; | 128 bool flip_y) override; |
| 127 | 129 |
| 128 // VideoFrameProvider implementation. | 130 private: |
| 129 void SetVideoFrameProviderClient( | 131 class Compositor : public cc::VideoFrameProvider { |
|
DaleCurtis
2015/08/14 17:07:56
Hmm, this is larger than I anticipated; I thought
qiangchen
2015/08/14 18:16:39
Essentially this is just a code refactoring. The w
DaleCurtis
2015/08/14 18:31:25
I'm okay with that so long as you're signing up to
| |
| 130 cc::VideoFrameProvider::Client* client) override; | 132 public: |
| 131 bool UpdateCurrentFrame(base::TimeTicks deadline_min, | 133 Compositor(scoped_refptr<base::SingleThreadTaskRunner> compositor_thread); |
|
DaleCurtis
2015/08/14 18:31:25
explicit const&
qiangchen
2015/08/14 20:09:42
Done.
| |
| 132 base::TimeTicks deadline_max) override; | 134 ~Compositor() override; |
| 133 bool HasCurrentFrame() override; | |
| 134 scoped_refptr<media::VideoFrame> GetCurrentFrame() override; | |
| 135 void PutCurrentFrame() override; | |
| 136 | 135 |
| 137 private: | 136 |
| 137 void EnqueueFrame(scoped_refptr<media::VideoFrame> frame); | |
|
DaleCurtis
2015/08/14 18:31:25
const&
qiangchen
2015/08/14 20:09:42
Done.
| |
| 138 | |
| 139 // Metadata about current frame | |
| 140 gfx::Size CurrentFrameSize(); | |
| 141 base::TimeDelta CurrentFrameTimestamp(); | |
| 142 unsigned TotalFrameCount(); | |
| 143 unsigned DroppedFrameCount(); | |
| 144 | |
| 145 // Get a reference to Current Frame. Different from GetCurrentFrame | |
| 146 // function, as a call to the latter would mean the current frame gets | |
| 147 // rendered. Thus when one needs the frame for other purpose, one should | |
| 148 // call this function. | |
| 149 scoped_refptr<media::VideoFrame> CurrentFrame(); | |
| 150 | |
| 151 // VideoFrameProvider implementation. | |
| 152 void SetVideoFrameProviderClient( | |
| 153 cc::VideoFrameProvider::Client* client) override; | |
| 154 bool UpdateCurrentFrame(base::TimeTicks deadline_min, | |
| 155 base::TimeTicks deadline_max) override; | |
| 156 bool HasCurrentFrame() override; | |
| 157 scoped_refptr<media::VideoFrame> GetCurrentFrame() override; | |
| 158 void PutCurrentFrame() override; | |
| 159 | |
| 160 static void StartRendering(Compositor* compositor); | |
|
DaleCurtis
2015/08/14 18:31:25
I don't see why you need these to be static. You c
qiangchen
2015/08/14 20:09:42
Not quite familiar with base::Bind. It seems I hav
DaleCurtis
2015/08/14 20:47:29
You can use base::Unretained(compositor_) here sin
| |
| 161 static void StopRendering(Compositor* compositor, | |
| 162 media::SkCanvasVideoRenderer* video_renderer); | |
| 163 private: | |
| 164 scoped_refptr<base::SingleThreadTaskRunner> compositor_thread_; | |
| 165 | |
| 166 // A pointer back to the compositor to inform it about state changes. This | |
| 167 // is | |
| 168 // not NULL while the compositor is actively using this webmediaplayer. | |
| 169 cc::VideoFrameProvider::Client* video_frame_provider_client_; | |
| 170 | |
| 171 // |current_frame_| is updated only on main thread. The object it holds | |
| 172 // can be freed on the compositor thread if it is the last to hold a | |
| 173 // reference but media::VideoFrame is a thread-safe ref-pointer. It is | |
| 174 // however read on the compositing thread so locking is required around all | |
| 175 // modifications on the main thread, and all reads on the compositing | |
| 176 // thread. | |
| 177 scoped_refptr<media::VideoFrame> current_frame_; | |
| 178 // |current_frame_used_| is updated on both main and compositing thread. | |
| 179 // It's used to track whether |current_frame_| was painted for detecting | |
| 180 // when to increase |dropped_frame_count_|. | |
| 181 bool current_frame_used_; | |
| 182 | |
| 183 base::TimeDelta current_time_; | |
| 184 base::TimeTicks last_deadline_max_; | |
| 185 unsigned total_frame_count_; | |
| 186 unsigned dropped_frame_count_; | |
| 187 | |
| 188 bool paused_; | |
| 189 | |
| 190 // |current_frame_lock_| protects |current_frame_used_| and | |
| 191 // |current_frame_|. | |
| 192 base::Lock current_frame_lock_; | |
| 193 | |
| 194 }; | |
| 195 | |
| 138 // The callback for VideoFrameProvider to signal a new frame is available. | 196 // The callback for VideoFrameProvider to signal a new frame is available. |
| 139 void OnFrameAvailable(const scoped_refptr<media::VideoFrame>& frame); | 197 void OnFrameAvailable(const scoped_refptr<media::VideoFrame>& frame); |
| 140 // Need repaint due to state change. | 198 // Need repaint due to state change. |
| 141 void RepaintInternal(); | 199 void RepaintInternal(); |
| 142 | 200 |
| 143 // The callback for source to report error. | 201 // The callback for source to report error. |
| 144 void OnSourceError(); | 202 void OnSourceError(); |
| 145 | 203 |
| 146 // Helpers that set the network/ready state and notifies the client if | 204 // Helpers that set the network/ready state and notifies the client if |
| 147 // they've changed. | 205 // they've changed. |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 164 base::ThreadChecker thread_checker_; | 222 base::ThreadChecker thread_checker_; |
| 165 | 223 |
| 166 blink::WebMediaPlayerClient* client_; | 224 blink::WebMediaPlayerClient* client_; |
| 167 | 225 |
| 168 base::WeakPtr<media::WebMediaPlayerDelegate> delegate_; | 226 base::WeakPtr<media::WebMediaPlayerDelegate> delegate_; |
| 169 | 227 |
| 170 // Specify content:: to disambiguate from cc::. | 228 // Specify content:: to disambiguate from cc::. |
| 171 scoped_refptr<content::VideoFrameProvider> video_frame_provider_; | 229 scoped_refptr<content::VideoFrameProvider> video_frame_provider_; |
| 172 bool paused_; | 230 bool paused_; |
| 173 | 231 |
| 174 // |current_frame_| is updated only on main thread. The object it holds | |
| 175 // can be freed on the compositor thread if it is the last to hold a | |
| 176 // reference but media::VideoFrame is a thread-safe ref-pointer. It is | |
| 177 // however read on the compositing thread so locking is required around all | |
| 178 // modifications on the main thread, and all reads on the compositing thread. | |
| 179 scoped_refptr<media::VideoFrame> current_frame_; | |
| 180 // |current_frame_used_| is updated on both main and compositing thread. | |
| 181 // It's used to track whether |current_frame_| was painted for detecting | |
| 182 // when to increase |dropped_frame_count_|. | |
| 183 bool current_frame_used_; | |
| 184 // |current_frame_lock_| protects |current_frame_used_| and |current_frame_|. | |
| 185 base::Lock current_frame_lock_; | |
| 186 | |
| 187 scoped_ptr<cc_blink::WebLayerImpl> video_weblayer_; | 232 scoped_ptr<cc_blink::WebLayerImpl> video_weblayer_; |
| 188 | 233 |
| 189 // A pointer back to the compositor to inform it about state changes. This is | 234 bool received_first_frame_; |
| 190 // not NULL while the compositor is actively using this webmediaplayer. | |
| 191 cc::VideoFrameProvider::Client* video_frame_provider_client_; | |
| 192 | 235 |
| 193 bool received_first_frame_; | |
| 194 base::TimeDelta current_time_; | |
| 195 unsigned total_frame_count_; | |
| 196 unsigned dropped_frame_count_; | |
| 197 media::SkCanvasVideoRenderer video_renderer_; | 236 media::SkCanvasVideoRenderer video_renderer_; |
| 198 | 237 |
| 199 scoped_refptr<MediaStreamAudioRenderer> audio_renderer_; | 238 scoped_refptr<MediaStreamAudioRenderer> audio_renderer_; |
| 200 | 239 |
| 201 scoped_refptr<media::MediaLog> media_log_; | 240 scoped_refptr<media::MediaLog> media_log_; |
| 202 | 241 |
| 203 scoped_ptr<MediaStreamRendererFactory> renderer_factory_; | 242 scoped_ptr<MediaStreamRendererFactory> renderer_factory_; |
| 204 | 243 |
| 244 // WebMediaPlayerMS owns the Compositor instance, but the destructions of | |
| 245 // compositor should take place on Compositor Thread. | |
| 246 Compositor* compositor_; | |
|
DaleCurtis
2015/08/14 18:31:25
Should probably still be a scoped_ptr and you can
qiangchen
2015/08/14 20:09:42
Done.
| |
| 247 | |
| 248 scoped_refptr<base::SingleThreadTaskRunner> compositor_thread_; | |
| 249 | |
| 205 DISALLOW_COPY_AND_ASSIGN(WebMediaPlayerMS); | 250 DISALLOW_COPY_AND_ASSIGN(WebMediaPlayerMS); |
| 206 }; | 251 }; |
| 207 | 252 |
| 208 } // namespace content | 253 } // namespace content |
| 209 | 254 |
| 210 #endif // CONTENT_RENDERER_MEDIA_WEBMEDIAPLAYER_MS_H_ | 255 #endif // CONTENT_RENDERER_MEDIA_WEBMEDIAPLAYER_MS_H_ |
| OLD | NEW |