Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(246)

Side by Side Diff: webkit/glue/webmediaplayer_impl.h

Issue 7493030: Split WebMediaPlayerImpl::Proxy into its own class. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src
Patch Set: rebase Created 9 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 // Delegate calls from WebCore::MediaPlayerPrivate to Chrome's video player. 5 // Delegate calls from WebCore::MediaPlayerPrivate to Chrome's video player.
6 // It contains PipelineImpl which is the actual media player pipeline, it glues 6 // It contains PipelineImpl which is the actual media player pipeline, it glues
7 // the media player pipeline, data source, audio renderer and renderer. 7 // the media player pipeline, data source, audio renderer and renderer.
8 // PipelineImpl would creates multiple threads and access some public methods 8 // PipelineImpl would creates multiple threads and access some public methods
9 // of this class, so we need to be extra careful about concurrent access of 9 // of this class, so we need to be extra careful about concurrent access of
10 // methods and members. 10 // methods and members.
11 // 11 //
12 // WebMediaPlayerImpl works with multiple objects, the most important ones are: 12 // WebMediaPlayerImpl works with multiple objects, the most important ones are:
13 // 13 //
14 // media::PipelineImpl 14 // media::PipelineImpl
15 // The media playback pipeline. 15 // The media playback pipeline.
16 // 16 //
17 // WebVideoRenderer 17 // WebVideoRenderer
18 // Video renderer object. 18 // Video renderer object.
19 // 19 //
20 // WebMediaPlayerImpl::Proxy
21 // Proxies methods calls from the media pipeline to WebKit.
22 //
23 // WebKit::WebMediaPlayerClient 20 // WebKit::WebMediaPlayerClient
24 // WebKit client of this media player object. 21 // WebKit client of this media player object.
25 // 22 //
26 // The following diagram shows the relationship of these objects: 23 // The following diagram shows the relationship of these objects:
27 // (note: ref-counted reference is marked by a "r".) 24 // (note: ref-counted reference is marked by a "r".)
28 // 25 //
29 // WebMediaPlayerImpl ------> PipelineImpl 26 // WebMediaPlayerImpl ------> PipelineImpl
30 // | ^ | r 27 // | ^ | r
31 // | | v 28 // | | v
32 // | | WebVideoRenderer 29 // | | WebVideoRenderer
33 // | | ^ r 30 // | | ^ r
34 // | | | 31 // | | |
35 // | r | r | 32 // | r | r |
36 // .------> Proxy <-----. 33 // .------> Proxy <-----.
acolwell GONE FROM CHROMIUM 2011/07/27 16:03:03 Update diagram to reflect new class name
scherkus (not reviewing) 2011/07/27 17:48:19 Done.
37 // | 34 // |
38 // | 35 // |
39 // v 36 // v
40 // WebMediaPlayerClient 37 // WebMediaPlayerClient
41 // 38 //
42 // Notice that Proxy and WebVideoRenderer are referencing each other. This 39 // Notice that WebMediaPlayerProxy and WebVideoRenderer are referencing each
43 // interdependency has to be treated carefully. 40 // other. This interdependency has to be treated carefully.
44 // 41 //
45 // Other issues: 42 // Other issues:
46 // During tear down of the whole browser or a tab, the DOM tree may not be 43 // During tear down of the whole browser or a tab, the DOM tree may not be
47 // destructed nicely, and there will be some dangling media threads trying to 44 // destructed nicely, and there will be some dangling media threads trying to
48 // the main thread, so we need this class to listen to destruction event of the 45 // the main thread, so we need this class to listen to destruction event of the
49 // main thread and cleanup the media threads when the even is received. Also 46 // main thread and cleanup the media threads when the even is received. Also
50 // at destruction of this class we will need to unhook it from destruction event 47 // at destruction of this class we will need to unhook it from destruction event
51 // list of the main thread. 48 // list of the main thread.
52 49
53 #ifndef WEBKIT_GLUE_WEBMEDIAPLAYER_IMPL_H_ 50 #ifndef WEBKIT_GLUE_WEBMEDIAPLAYER_IMPL_H_
54 #define WEBKIT_GLUE_WEBMEDIAPLAYER_IMPL_H_ 51 #define WEBKIT_GLUE_WEBMEDIAPLAYER_IMPL_H_
55 52
56 #include "base/memory/ref_counted.h" 53 #include "base/memory/ref_counted.h"
57 #include "base/memory/scoped_ptr.h" 54 #include "base/memory/scoped_ptr.h"
58 #include "base/message_loop.h" 55 #include "base/message_loop.h"
59 #include "base/threading/thread.h"
60 #include "base/synchronization/lock.h"
61 #include "base/synchronization/waitable_event.h"
62 #include "media/filters/chunk_demuxer.h"
63 #include "media/filters/chunk_demuxer_client.h"
64 #include "media/base/filters.h" 56 #include "media/base/filters.h"
65 #include "media/base/message_loop_factory.h" 57 #include "media/base/message_loop_factory.h"
66 #include "media/base/pipeline.h" 58 #include "media/base/pipeline.h"
67 #include "skia/ext/platform_canvas.h" 59 #include "skia/ext/platform_canvas.h"
68 #include "third_party/WebKit/Source/WebKit/chromium/public/WebMediaPlayer.h" 60 #include "third_party/WebKit/Source/WebKit/chromium/public/WebMediaPlayer.h"
69 #include "third_party/WebKit/Source/WebKit/chromium/public/WebMediaPlayerClient. h" 61 #include "third_party/WebKit/Source/WebKit/chromium/public/WebMediaPlayerClient. h"
70 #include "ui/gfx/rect.h"
71 #include "ui/gfx/size.h"
72 #include "webkit/glue/media/web_data_source.h"
73 62
74 class GURL; 63 class GURL;
75 64
76 namespace WebKit { 65 namespace WebKit {
77 class WebFrame; 66 class WebFrame;
78 } 67 }
79 68
80 namespace webkit_glue { 69 namespace webkit_glue {
81 70
82 class MediaResourceLoaderBridgeFactory; 71 class MediaResourceLoaderBridgeFactory;
83 class MediaStreamClient; 72 class MediaStreamClient;
73 class WebMediaPlayerProxy;
84 class WebVideoRenderer; 74 class WebVideoRenderer;
85 75
86 class WebMediaPlayerImpl 76 class WebMediaPlayerImpl
87 : public WebKit::WebMediaPlayer, 77 : public WebKit::WebMediaPlayer,
88 public MessageLoop::DestructionObserver { 78 public MessageLoop::DestructionObserver {
89 public: 79 public:
90 // A proxy class that dispatches method calls from the media pipeline to
91 // WebKit. Since there are multiple threads in the media pipeline and there's
92 // need for the media pipeline to call to WebKit, e.g. repaint requests,
93 // initialization events, etc, we have this class to bridge all method calls
94 // from the media pipeline on different threads and serialize these calls
95 // on the render thread.
96 // Because of the nature of this object that it works with different threads,
97 // it is made ref-counted.
98 class Proxy
99 : public base::RefCountedThreadSafe<Proxy>,
100 public media::ChunkDemuxerClient {
101 public:
102 Proxy(MessageLoop* render_loop,
103 WebMediaPlayerImpl* webmediaplayer);
104
105 // Methods for Filter -> WebMediaPlayerImpl communication.
106 void Repaint();
107 void SetVideoRenderer(scoped_refptr<WebVideoRenderer> video_renderer);
108 WebDataSourceBuildObserverHack* GetBuildObserver();
109
110 // Methods for WebMediaPlayerImpl -> Filter communication.
111 void Paint(SkCanvas* canvas, const gfx::Rect& dest_rect);
112 void SetSize(const gfx::Rect& rect);
113 void Detach();
114 void GetCurrentFrame(scoped_refptr<media::VideoFrame>* frame_out);
115 void PutCurrentFrame(scoped_refptr<media::VideoFrame> frame);
116 bool HasSingleOrigin();
117 void AbortDataSources();
118
119 // Methods for PipelineImpl -> WebMediaPlayerImpl communication.
120 void PipelineInitializationCallback(media::PipelineStatus status);
121 void PipelineSeekCallback(media::PipelineStatus status);
122 void PipelineEndedCallback(media::PipelineStatus status);
123 void PipelineErrorCallback(media::PipelineStatus error);
124 void NetworkEventCallback(media::PipelineStatus status);
125
126 // Methods for ChunkDemuxerClient interface.
127 virtual void DemuxerOpened(media::ChunkDemuxer* demuxer);
128 virtual void DemuxerClosed();
129
130 // Methods for Demuxer communication.
131 void DemuxerFlush();
132 bool DemuxerAppend(const uint8* data, size_t length);
133 void DemuxerEndOfStream(media::PipelineStatus status);
134 void DemuxerShutdown();
135
136 void DemuxerOpenedTask(const scoped_refptr<media::ChunkDemuxer>& demuxer);
137 void DemuxerClosedTask();
138
139 // Returns the message loop used by the proxy.
140 MessageLoop* message_loop() { return render_loop_; }
141
142 private:
143 friend class base::RefCountedThreadSafe<Proxy>;
144
145 virtual ~Proxy();
146
147 // Adds a data source to data_sources_.
148 void AddDataSource(WebDataSource* data_source);
149
150 // Invoke |webmediaplayer_| to perform a repaint.
151 void RepaintTask();
152
153 // Notify |webmediaplayer_| that initialization has finished.
154 void PipelineInitializationTask(media::PipelineStatus status);
155
156 // Notify |webmediaplayer_| that a seek has finished.
157 void PipelineSeekTask(media::PipelineStatus status);
158
159 // Notify |webmediaplayer_| that the media has ended.
160 void PipelineEndedTask(media::PipelineStatus status);
161
162 // Notify |webmediaplayer_| that a pipeline error has occurred during
163 // playback.
164 void PipelineErrorTask(media::PipelineStatus error);
165
166 // Notify |webmediaplayer_| that there's a network event.
167 void NetworkEventTask(media::PipelineStatus status);
168
169 // The render message loop where WebKit lives.
170 MessageLoop* render_loop_;
171 WebMediaPlayerImpl* webmediaplayer_;
172
173 base::Lock data_sources_lock_;
174 typedef std::list<scoped_refptr<WebDataSource> > DataSourceList;
175 DataSourceList data_sources_;
176 scoped_ptr<WebDataSourceBuildObserverHack> build_observer_;
177
178 scoped_refptr<WebVideoRenderer> video_renderer_;
179
180 base::Lock lock_;
181 int outstanding_repaints_;
182
183 scoped_refptr<media::ChunkDemuxer> chunk_demuxer_;
184 };
185
186 // Construct a WebMediaPlayerImpl with reference to the client, and media 80 // Construct a WebMediaPlayerImpl with reference to the client, and media
187 // filter collection. By providing the filter collection the implementor can 81 // filter collection. By providing the filter collection the implementor can
188 // provide more specific media filters that does resource loading and 82 // provide more specific media filters that does resource loading and
189 // rendering. |collection| should contain filter factories for: 83 // rendering. |collection| should contain filter factories for:
190 // 1. Data source 84 // 1. Data source
191 // 2. Audio renderer 85 // 2. Audio renderer
192 // 3. Video renderer (optional) 86 // 3. Video renderer (optional)
193 // 87 //
194 // There are some default filters provided by this method: 88 // There are some default filters provided by this method:
195 // 1. FFmpeg demuxer 89 // 1. FFmpeg demuxer
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
285 179
286 // As we are closing the tab or even the browser, |main_loop_| is destroyed 180 // As we are closing the tab or even the browser, |main_loop_| is destroyed
287 // even before this object gets destructed, so we need to know when 181 // even before this object gets destructed, so we need to know when
288 // |main_loop_| is being destroyed and we can stop posting repaint task 182 // |main_loop_| is being destroyed and we can stop posting repaint task
289 // to it. 183 // to it.
290 virtual void WillDestroyCurrentMessageLoop(); 184 virtual void WillDestroyCurrentMessageLoop();
291 185
292 void Repaint(); 186 void Repaint();
293 187
294 void OnPipelineInitialize(media::PipelineStatus status); 188 void OnPipelineInitialize(media::PipelineStatus status);
295
296 void OnPipelineSeek(media::PipelineStatus status); 189 void OnPipelineSeek(media::PipelineStatus status);
297
298 void OnPipelineEnded(media::PipelineStatus status); 190 void OnPipelineEnded(media::PipelineStatus status);
299
300 void OnPipelineError(media::PipelineStatus error); 191 void OnPipelineError(media::PipelineStatus error);
301
302 void OnNetworkEvent(media::PipelineStatus status); 192 void OnNetworkEvent(media::PipelineStatus status);
303
304 void OnDemuxerOpened(); 193 void OnDemuxerOpened();
305 194
306 private: 195 private:
307 // Helpers that set the network/ready state and notifies the client if 196 // Helpers that set the network/ready state and notifies the client if
308 // they've changed. 197 // they've changed.
309 void SetNetworkState(WebKit::WebMediaPlayer::NetworkState state); 198 void SetNetworkState(WebKit::WebMediaPlayer::NetworkState state);
310 void SetReadyState(WebKit::WebMediaPlayer::ReadyState state); 199 void SetReadyState(WebKit::WebMediaPlayer::ReadyState state);
311 200
312 // Destroy resources held. 201 // Destroy resources held.
313 void Destroy(); 202 void Destroy();
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
346 // time we pause and then return that value in currentTime(). Otherwise our 235 // time we pause and then return that value in currentTime(). Otherwise our
347 // clock can creep forward a little bit while the asynchronous 236 // clock can creep forward a little bit while the asynchronous
348 // SetPlaybackRate(0) is being executed. 237 // SetPlaybackRate(0) is being executed.
349 bool paused_; 238 bool paused_;
350 bool seeking_; 239 bool seeking_;
351 float playback_rate_; 240 float playback_rate_;
352 base::TimeDelta paused_time_; 241 base::TimeDelta paused_time_;
353 242
354 WebKit::WebMediaPlayerClient* client_; 243 WebKit::WebMediaPlayerClient* client_;
355 244
356 scoped_refptr<Proxy> proxy_; 245 scoped_refptr<WebMediaPlayerProxy> proxy_;
357 246
358 MediaStreamClient* media_stream_client_; 247 MediaStreamClient* media_stream_client_;
359 248
360 #if WEBKIT_USING_CG 249 #if WEBKIT_USING_CG
361 scoped_ptr<skia::PlatformCanvas> skia_canvas_; 250 scoped_ptr<skia::PlatformCanvas> skia_canvas_;
362 #endif 251 #endif
363 252
364 DISALLOW_COPY_AND_ASSIGN(WebMediaPlayerImpl); 253 DISALLOW_COPY_AND_ASSIGN(WebMediaPlayerImpl);
365 }; 254 };
366 255
367 } // namespace webkit_glue 256 } // namespace webkit_glue
368 257
369 #endif // WEBKIT_GLUE_WEBMEDIAPLAYER_IMPL_H_ 258 #endif // WEBKIT_GLUE_WEBMEDIAPLAYER_IMPL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698