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

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: More Android fixes 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 // Called when the ContentDecryptionModule has been attached to the
216 // pipeline/decoders.
217 void ContentDecryptionModuleAttached(
218 blink::WebContentDecryptionModuleResult result,
219 bool success);
220
221 // Returns the current video frame from |compositor_|. Blocks until the
222 // compositor can return the frame.
223 scoped_refptr<media::VideoFrame> GetCurrentFrameFromCompositor();
224
225 blink::WebLocalFrame* frame_;
226
227 // TODO(hclam): get rid of these members and read from the pipeline directly.
228 blink::WebMediaPlayer::NetworkState network_state_;
229 blink::WebMediaPlayer::ReadyState ready_state_;
230
231 // Preload state for when |data_source_| is created after setPreload().
232 BufferedDataSource::Preload preload_;
233
234 // Task runner for posting tasks on Chrome's main thread. Also used
235 // for DCHECKs so methods calls won't execute in the wrong thread.
236 const scoped_refptr<base::SingleThreadTaskRunner> main_task_runner_;
237
238 scoped_refptr<base::SingleThreadTaskRunner> media_task_runner_;
239 scoped_refptr<media::MediaLog> media_log_;
240 media::Pipeline pipeline_;
241
242 // The LoadType passed in the |load_type| parameter of the load() call.
243 LoadType load_type_;
244
245 // Cache of metadata for answering hasAudio(), hasVideo(), and naturalSize().
246 media::PipelineMetadata pipeline_metadata_;
247
248 // Whether the video is known to be opaque or not.
249 bool opaque_;
250
251 // Playback state.
252 //
253 // TODO(scherkus): we have these because Pipeline favours the simplicity of a
254 // single "playback rate" over worrying about paused/stopped etc... It forces
255 // all clients to manage the pause+playback rate externally, but is that
256 // really a bad thing?
257 //
258 // TODO(scherkus): since SetPlaybackRate(0) is asynchronous and we don't want
259 // to hang the render thread during pause(), we record the time at the same
260 // time we pause and then return that value in currentTime(). Otherwise our
261 // clock can creep forward a little bit while the asynchronous
262 // SetPlaybackRate(0) is being executed.
263 bool paused_;
264 bool seeking_;
265 double playback_rate_;
266 base::TimeDelta paused_time_;
267
268 // Seek gets pending if another seek is in progress. Only last pending seek
269 // will have effect.
270 bool pending_seek_;
271 double pending_seek_seconds_;
272
273 // Tracks whether to issue time changed notifications during buffering state
274 // changes.
275 bool should_notify_time_changed_;
276
277 blink::WebMediaPlayerClient* client_;
278
279 base::WeakPtr<WebMediaPlayerDelegate> delegate_;
280
281 base::Callback<void(const base::Closure&)> defer_load_cb_;
282
283 // Factories for supporting video accelerators. May be null.
284 scoped_refptr<media::GpuVideoAcceleratorFactories> gpu_factories_;
285
286 // Routes audio playback to either AudioRendererSink or WebAudio.
287 scoped_refptr<WebAudioSourceProviderImpl> audio_source_provider_;
288
289 bool supports_save_;
290
291 // These two are mutually exclusive:
292 // |data_source_| is used for regular resource loads.
293 // |chunk_demuxer_| is used for Media Source resource loads.
294 //
295 // |demuxer_| will contain the appropriate demuxer based on which resource
296 // load strategy we're using.
297 scoped_ptr<BufferedDataSource> data_source_;
298 scoped_ptr<media::Demuxer> demuxer_;
299 media::ChunkDemuxer* chunk_demuxer_;
300
301 BufferedDataSourceHostImpl buffered_data_source_host_;
302
303 // Video rendering members.
304 scoped_refptr<base::SingleThreadTaskRunner> compositor_task_runner_;
305 VideoFrameCompositor* compositor_; // Deleted on |compositor_task_runner_|.
306 media::SkCanvasVideoRenderer skcanvas_video_renderer_;
307
308 // The compositor layer for displaying the video content when using composited
309 // playback.
310 scoped_ptr<cc_blink::WebLayerImpl> video_weblayer_;
311
312 // Text track objects get a unique index value when they're created.
313 int text_track_index_;
314
315 scoped_ptr<EncryptedMediaPlayerSupport> encrypted_media_support_;
316
317 const media::AudioHardwareConfig& audio_hardware_config_;
318
319 DISALLOW_COPY_AND_ASSIGN(WebMediaPlayerImpl);
320 };
321
322 } // namespace content
323
324 #endif // CONTENT_RENDERER_MEDIA_WEBMEDIAPLAYER_IMPL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698