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

Side by Side Diff: content/renderer/media/webmediaplayer_impl.h

Issue 495353003: Move WebMediaPlayerImpl and its dependencies to media/blink. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: . Created 6 years, 3 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
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #ifndef CONTENT_RENDERER_MEDIA_WEBMEDIAPLAYER_IMPL_H_
6 #define CONTENT_RENDERER_MEDIA_WEBMEDIAPLAYER_IMPL_H_
7
8 #include <string>
9 #include <vector>
10
11 #include "base/basictypes.h"
12 #include "base/memory/ref_counted.h"
13 #include "base/memory/scoped_ptr.h"
14 #include "base/memory/weak_ptr.h"
15 #include "base/threading/thread.h"
16 #include "content/renderer/media/buffered_data_source_host_impl.h"
17 #include "content/renderer/media/video_frame_compositor.h"
18 #include "media/base/audio_renderer_sink.h"
19 // TODO(xhwang): Remove when we remove prefixed EME implementation.
20 #include "media/base/media_keys.h"
21 #include "media/base/pipeline.h"
22 #include "media/base/text_track.h"
23 #include "media/filters/skcanvas_video_renderer.h"
24 #include "skia/ext/platform_canvas.h"
25 #include "third_party/WebKit/public/platform/WebAudioSourceProvider.h"
26 #include "third_party/WebKit/public/platform/WebContentDecryptionModuleResult.h"
27 #include "third_party/WebKit/public/platform/WebGraphicsContext3D.h"
28 #include "third_party/WebKit/public/platform/WebMediaPlayer.h"
29 #include "third_party/WebKit/public/platform/WebMediaPlayerClient.h"
30 #include "url/gurl.h"
31
32 namespace blink {
33 class WebLocalFrame;
34 }
35
36 namespace base {
37 class SingleThreadTaskRunner;
38 }
39
40 namespace cc_blink {
41 class WebLayerImpl;
42 }
43
44 namespace media {
45 class AudioHardwareConfig;
46 class ChunkDemuxer;
47 class GpuVideoAcceleratorFactories;
48 class MediaLog;
49 }
50
51
52 namespace content {
53 class BufferedDataSource;
54 class EncryptedMediaPlayerSupport;
55 class VideoFrameCompositor;
56 class WebAudioSourceProviderImpl;
57 class WebMediaPlayerDelegate;
58 class WebMediaPlayerParams;
59 class WebTextTrackImpl;
60
61 // The canonical implementation of blink::WebMediaPlayer that's backed by
62 // media::Pipeline. Handles normal resource loading, Media Source, and
63 // Encrypted Media.
64 class WebMediaPlayerImpl
65 : public blink::WebMediaPlayer,
66 public base::SupportsWeakPtr<WebMediaPlayerImpl> {
67 public:
68 // Constructs a WebMediaPlayer implementation using Chromium's media stack.
69 // |delegate| may be null.
70 WebMediaPlayerImpl(blink::WebLocalFrame* frame,
71 blink::WebMediaPlayerClient* client,
72 base::WeakPtr<WebMediaPlayerDelegate> delegate,
73 const WebMediaPlayerParams& params);
74 virtual ~WebMediaPlayerImpl();
75
76 virtual void load(LoadType load_type,
77 const blink::WebURL& url,
78 CORSMode cors_mode);
79
80 // Playback controls.
81 virtual void play();
82 virtual void pause();
83 virtual bool supportsSave() const;
84 virtual void seek(double seconds);
85 virtual void setRate(double rate);
86 virtual void setVolume(double volume);
87 virtual void setPreload(blink::WebMediaPlayer::Preload preload);
88 virtual blink::WebTimeRanges buffered() const;
89 virtual double maxTimeSeekable() const;
90
91 // Methods for painting.
92 virtual void paint(blink::WebCanvas* canvas,
93 const blink::WebRect& rect,
94 unsigned char alpha,
95 SkXfermode::Mode mode);
96 // TODO(dshwang): remove it because above method replaces. crbug.com/401027
97 virtual void paint(blink::WebCanvas* canvas,
98 const blink::WebRect& rect,
99 unsigned char alpha);
100
101 // True if the loaded media has a playable video/audio track.
102 virtual bool hasVideo() const;
103 virtual bool hasAudio() const;
104
105 // Dimensions of the video.
106 virtual blink::WebSize naturalSize() const;
107
108 // Getters of playback state.
109 virtual bool paused() const;
110 virtual bool seeking() const;
111 virtual double duration() const;
112 virtual double timelineOffset() const;
113 virtual double currentTime() const;
114
115 // Internal states of loading and network.
116 // TODO(hclam): Ask the pipeline about the state rather than having reading
117 // them from members which would cause race conditions.
118 virtual blink::WebMediaPlayer::NetworkState networkState() const;
119 virtual blink::WebMediaPlayer::ReadyState readyState() const;
120
121 virtual bool didLoadingProgress();
122
123 virtual bool hasSingleSecurityOrigin() const;
124 virtual bool didPassCORSAccessCheck() const;
125
126 virtual double mediaTimeForTimeValue(double timeValue) const;
127
128 virtual unsigned decodedFrameCount() const;
129 virtual unsigned droppedFrameCount() const;
130 virtual unsigned audioDecodedByteCount() const;
131 virtual unsigned videoDecodedByteCount() const;
132
133 virtual bool copyVideoTextureToPlatformTexture(
134 blink::WebGraphicsContext3D* web_graphics_context,
135 unsigned int texture,
136 unsigned int level,
137 unsigned int internal_format,
138 unsigned int type,
139 bool premultiply_alpha,
140 bool flip_y);
141
142 virtual blink::WebAudioSourceProvider* audioSourceProvider();
143
144 virtual MediaKeyException generateKeyRequest(
145 const blink::WebString& key_system,
146 const unsigned char* init_data,
147 unsigned init_data_length);
148
149 virtual MediaKeyException addKey(const blink::WebString& key_system,
150 const unsigned char* key,
151 unsigned key_length,
152 const unsigned char* init_data,
153 unsigned init_data_length,
154 const blink::WebString& session_id);
155
156 virtual MediaKeyException cancelKeyRequest(
157 const blink::WebString& key_system,
158 const blink::WebString& session_id);
159
160 // TODO(jrummell): Remove this method once Blink updated to use the other
161 // two methods.
162 virtual void setContentDecryptionModule(
163 blink::WebContentDecryptionModule* cdm);
164 virtual void setContentDecryptionModule(
165 blink::WebContentDecryptionModule* cdm,
166 blink::WebContentDecryptionModuleResult result);
167 virtual void setContentDecryptionModuleSync(
168 blink::WebContentDecryptionModule* cdm);
169
170 void OnPipelineSeeked(bool time_changed, media::PipelineStatus status);
171 void OnPipelineEnded();
172 void OnPipelineError(media::PipelineStatus error);
173 void OnPipelineMetadata(media::PipelineMetadata metadata);
174 void OnPipelineBufferingStateChanged(media::BufferingState buffering_state);
175 void OnDemuxerOpened();
176 void OnAddTextTrack(const media::TextTrackConfig& config,
177 const media::AddTextTrackDoneCB& done_cb);
178
179 private:
180 // Called after |defer_load_cb_| has decided to allow the load. If
181 // |defer_load_cb_| is null this is called immediately.
182 void DoLoad(LoadType load_type,
183 const blink::WebURL& url,
184 CORSMode cors_mode);
185
186 // Called after asynchronous initialization of a data source completed.
187 void DataSourceInitialized(bool success);
188
189 // Called when the data source is downloading or paused.
190 void NotifyDownloading(bool is_downloading);
191
192 // Creates a media::Renderer that will be used by the |pipeline_|.
193 scoped_ptr<media::Renderer> CreateRenderer();
194
195 // Finishes starting the pipeline due to a call to load().
196 void StartPipeline();
197
198 // Helpers that set the network/ready state and notifies the client if
199 // they've changed.
200 void SetNetworkState(blink::WebMediaPlayer::NetworkState state);
201 void SetReadyState(blink::WebMediaPlayer::ReadyState state);
202
203 // Gets the duration value reported by the pipeline.
204 double GetPipelineDuration() const;
205
206 // Callbacks from |pipeline_| that are forwarded to |client_|.
207 void OnDurationChanged();
208 void OnNaturalSizeChanged(gfx::Size size);
209 void OnOpacityChanged(bool opaque);
210
211 // Called by VideoRendererImpl on its internal thread with the new frame to be
212 // painted.
213 void FrameReady(const scoped_refptr<media::VideoFrame>& frame);
214
215 // Returns the current video frame from |compositor_|. Blocks until the
216 // compositor can return the frame.
217 scoped_refptr<media::VideoFrame> GetCurrentFrameFromCompositor();
218
219 blink::WebLocalFrame* frame_;
220
221 // TODO(hclam): get rid of these members and read from the pipeline directly.
222 blink::WebMediaPlayer::NetworkState network_state_;
223 blink::WebMediaPlayer::ReadyState ready_state_;
224
225 // Preload state for when |data_source_| is created after setPreload().
226 BufferedDataSource::Preload preload_;
227
228 // Task runner for posting tasks on Chrome's main thread. Also used
229 // for DCHECKs so methods calls won't execute in the wrong thread.
230 const scoped_refptr<base::SingleThreadTaskRunner> main_task_runner_;
231
232 scoped_refptr<base::SingleThreadTaskRunner> media_task_runner_;
233 scoped_refptr<media::MediaLog> media_log_;
234 media::Pipeline pipeline_;
235
236 // The LoadType passed in the |load_type| parameter of the load() call.
237 LoadType load_type_;
238
239 // Cache of metadata for answering hasAudio(), hasVideo(), and naturalSize().
240 media::PipelineMetadata pipeline_metadata_;
241
242 // Whether the video is known to be opaque or not.
243 bool opaque_;
244
245 // Playback state.
246 //
247 // TODO(scherkus): we have these because Pipeline favours the simplicity of a
248 // single "playback rate" over worrying about paused/stopped etc... It forces
249 // all clients to manage the pause+playback rate externally, but is that
250 // really a bad thing?
251 //
252 // TODO(scherkus): since SetPlaybackRate(0) is asynchronous and we don't want
253 // to hang the render thread during pause(), we record the time at the same
254 // time we pause and then return that value in currentTime(). Otherwise our
255 // clock can creep forward a little bit while the asynchronous
256 // SetPlaybackRate(0) is being executed.
257 bool paused_;
258 bool seeking_;
259 double playback_rate_;
260 base::TimeDelta paused_time_;
261
262 // TODO(scherkus): Replace with an explicit ended signal to HTMLMediaElement,
263 // see http://crbug.com/409280
264 bool ended_;
265
266 // Seek gets pending if another seek is in progress. Only last pending seek
267 // will have effect.
268 bool pending_seek_;
269 double pending_seek_seconds_;
270
271 // Tracks whether to issue time changed notifications during buffering state
272 // changes.
273 bool should_notify_time_changed_;
274
275 blink::WebMediaPlayerClient* client_;
276
277 base::WeakPtr<WebMediaPlayerDelegate> delegate_;
278
279 base::Callback<void(const base::Closure&)> defer_load_cb_;
280
281 // Factories for supporting video accelerators. May be null.
282 scoped_refptr<media::GpuVideoAcceleratorFactories> gpu_factories_;
283
284 // Routes audio playback to either AudioRendererSink or WebAudio.
285 scoped_refptr<WebAudioSourceProviderImpl> audio_source_provider_;
286
287 bool supports_save_;
288
289 // These two are mutually exclusive:
290 // |data_source_| is used for regular resource loads.
291 // |chunk_demuxer_| is used for Media Source resource loads.
292 //
293 // |demuxer_| will contain the appropriate demuxer based on which resource
294 // load strategy we're using.
295 scoped_ptr<BufferedDataSource> data_source_;
296 scoped_ptr<media::Demuxer> demuxer_;
297 media::ChunkDemuxer* chunk_demuxer_;
298
299 BufferedDataSourceHostImpl buffered_data_source_host_;
300
301 // Video rendering members.
302 scoped_refptr<base::SingleThreadTaskRunner> compositor_task_runner_;
303 VideoFrameCompositor* compositor_; // Deleted on |compositor_task_runner_|.
304 media::SkCanvasVideoRenderer skcanvas_video_renderer_;
305
306 // The compositor layer for displaying the video content when using composited
307 // playback.
308 scoped_ptr<cc_blink::WebLayerImpl> video_weblayer_;
309
310 // Text track objects get a unique index value when they're created.
311 int text_track_index_;
312
313 scoped_ptr<EncryptedMediaPlayerSupport> encrypted_media_support_;
314
315 const media::AudioHardwareConfig& audio_hardware_config_;
316
317 DISALLOW_COPY_AND_ASSIGN(WebMediaPlayerImpl);
318 };
319
320 } // namespace content
321
322 #endif // CONTENT_RENDERER_MEDIA_WEBMEDIAPLAYER_IMPL_H_
OLDNEW
« no previous file with comments | « content/renderer/media/webmediaplayer_delegate.h ('k') | content/renderer/media/webmediaplayer_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698