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

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

Issue 18123002: Migrate webkit/renderer/media/ to content/renderer/media/. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: delegates Created 7 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 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 #include "webkit/renderer/media/webmediaplayer_impl.h" 5 #include "content/renderer/media/webmediaplayer_impl.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <limits> 8 #include <limits>
9 #include <string> 9 #include <string>
10 #include <vector> 10 #include <vector>
11 11
12 #include "base/bind.h" 12 #include "base/bind.h"
13 #include "base/callback.h" 13 #include "base/callback.h"
14 #include "base/command_line.h" 14 #include "base/command_line.h"
15 #include "base/debug/crash_logging.h" 15 #include "base/debug/crash_logging.h"
16 #include "base/message_loop/message_loop_proxy.h" 16 #include "base/message_loop/message_loop_proxy.h"
17 #include "base/metrics/histogram.h" 17 #include "base/metrics/histogram.h"
18 #include "base/strings/string_number_conversions.h" 18 #include "base/strings/string_number_conversions.h"
19 #include "base/synchronization/waitable_event.h" 19 #include "base/synchronization/waitable_event.h"
20 #include "cc/layers/video_layer.h" 20 #include "cc/layers/video_layer.h"
21 #include "content/public/renderer/media_player_load_delegate.h"
22 #include "content/renderer/media/buffered_data_source.h"
23 #include "content/renderer/media/texttrack_impl.h"
24 #include "content/renderer/media/webaudiosourceprovider_impl.h"
25 #include "content/renderer/media/webinbandtexttrack_impl.h"
26 #include "content/renderer/media/webmediaplayer_delegate.h"
27 #include "content/renderer/media/webmediaplayer_params.h"
28 #include "content/renderer/media/webmediaplayer_util.h"
29 #include "content/renderer/media/webmediasourceclient_impl.h"
21 #include "gpu/GLES2/gl2extchromium.h" 30 #include "gpu/GLES2/gl2extchromium.h"
22 #include "media/audio/null_audio_sink.h" 31 #include "media/audio/null_audio_sink.h"
23 #include "media/base/bind_to_loop.h" 32 #include "media/base/bind_to_loop.h"
24 #include "media/base/filter_collection.h" 33 #include "media/base/filter_collection.h"
25 #include "media/base/limits.h" 34 #include "media/base/limits.h"
26 #include "media/base/media_log.h" 35 #include "media/base/media_log.h"
27 #include "media/base/media_switches.h" 36 #include "media/base/media_switches.h"
28 #include "media/base/pipeline.h" 37 #include "media/base/pipeline.h"
29 #include "media/base/video_frame.h" 38 #include "media/base/video_frame.h"
30 #include "media/filters/audio_renderer_impl.h" 39 #include "media/filters/audio_renderer_impl.h"
31 #include "media/filters/chunk_demuxer.h" 40 #include "media/filters/chunk_demuxer.h"
32 #include "media/filters/ffmpeg_audio_decoder.h" 41 #include "media/filters/ffmpeg_audio_decoder.h"
33 #include "media/filters/ffmpeg_demuxer.h" 42 #include "media/filters/ffmpeg_demuxer.h"
34 #include "media/filters/ffmpeg_video_decoder.h" 43 #include "media/filters/ffmpeg_video_decoder.h"
35 #include "media/filters/opus_audio_decoder.h" 44 #include "media/filters/opus_audio_decoder.h"
36 #include "media/filters/video_renderer_base.h" 45 #include "media/filters/video_renderer_base.h"
37 #include "media/filters/vpx_video_decoder.h" 46 #include "media/filters/vpx_video_decoder.h"
38 #include "third_party/WebKit/public/platform/WebRect.h" 47 #include "third_party/WebKit/public/platform/WebRect.h"
39 #include "third_party/WebKit/public/platform/WebSize.h" 48 #include "third_party/WebKit/public/platform/WebSize.h"
40 #include "third_party/WebKit/public/platform/WebString.h" 49 #include "third_party/WebKit/public/platform/WebString.h"
41 #include "third_party/WebKit/public/platform/WebURL.h" 50 #include "third_party/WebKit/public/platform/WebURL.h"
42 #include "third_party/WebKit/public/web/WebMediaSource.h" 51 #include "third_party/WebKit/public/web/WebMediaSource.h"
43 #include "third_party/WebKit/public/web/WebRuntimeFeatures.h" 52 #include "third_party/WebKit/public/web/WebRuntimeFeatures.h"
44 #include "third_party/WebKit/public/web/WebView.h" 53 #include "third_party/WebKit/public/web/WebView.h"
45 #include "v8/include/v8.h" 54 #include "v8/include/v8.h"
46 #include "webkit/plugins/ppapi/ppapi_webplugin_impl.h" 55 #include "webkit/plugins/ppapi/ppapi_webplugin_impl.h"
47 #include "webkit/renderer/compositor_bindings/web_layer_impl.h" 56 #include "webkit/renderer/compositor_bindings/web_layer_impl.h"
48 #include "webkit/renderer/media/buffered_data_source.h"
49 #include "webkit/renderer/media/crypto/key_systems.h" 57 #include "webkit/renderer/media/crypto/key_systems.h"
50 #include "webkit/renderer/media/texttrack_impl.h"
51 #include "webkit/renderer/media/webaudiosourceprovider_impl.h"
52 #include "webkit/renderer/media/webinbandtexttrack_impl.h"
53 #include "webkit/renderer/media/webmediaplayer_delegate.h"
54 #include "webkit/renderer/media/webmediaplayer_params.h"
55 #include "webkit/renderer/media/webmediaplayer_util.h"
56 #include "webkit/renderer/media/webmediasourceclient_impl.h"
57 58
58 using WebKit::WebCanvas; 59 using WebKit::WebCanvas;
59 using WebKit::WebMediaPlayer; 60 using WebKit::WebMediaPlayer;
60 using WebKit::WebRect; 61 using WebKit::WebRect;
61 using WebKit::WebSize; 62 using WebKit::WebSize;
62 using WebKit::WebString; 63 using WebKit::WebString;
63 using media::PipelineStatus; 64 using media::PipelineStatus;
65 using webkit_media::IsSupportedKeySystem;
66 using webkit_media::KeySystemNameForUMA;
67 using webkit_media::ProxyDecryptor;
64 68
65 namespace { 69 namespace {
66 70
67 // Amount of extra memory used by each player instance reported to V8. 71 // Amount of extra memory used by each player instance reported to V8.
68 // It is not exact number -- first, it differs on different platforms, 72 // It is not exact number -- first, it differs on different platforms,
69 // and second, it is very hard to calculate. Instead, use some arbitrary 73 // and second, it is very hard to calculate. Instead, use some arbitrary
70 // value that will cause garbage collection from time to time. We don't want 74 // value that will cause garbage collection from time to time. We don't want
71 // it to happen on every allocation, but don't want 5k players to sit in memory 75 // it to happen on every allocation, but don't want 5k players to sit in memory
72 // either. Looks that chosen constant achieves both goals, at least for audio 76 // either. Looks that chosen constant achieves both goals, at least for audio
73 // objects. (Do not worry about video objects yet, JS programs do not create 77 // objects. (Do not worry about video objects yet, JS programs do not create
(...skipping 16 matching lines...) Expand all
90 // Also our timers are not very accurate (especially for ogg), which becomes 94 // Also our timers are not very accurate (especially for ogg), which becomes
91 // evident at low speeds and on Vista. Since other speeds are risky and outside 95 // evident at low speeds and on Vista. Since other speeds are risky and outside
92 // the norms, we think 1/16x to 16x is a safe and useful range for now. 96 // the norms, we think 1/16x to 16x is a safe and useful range for now.
93 const double kMinRate = 0.0625; 97 const double kMinRate = 0.0625;
94 const double kMaxRate = 16.0; 98 const double kMaxRate = 16.0;
95 99
96 // Prefix for histograms related to Encrypted Media Extensions. 100 // Prefix for histograms related to Encrypted Media Extensions.
97 const char* kMediaEme = "Media.EME."; 101 const char* kMediaEme = "Media.EME.";
98 } // namespace 102 } // namespace
99 103
100 namespace webkit_media { 104 namespace content {
101 105
102 #define COMPILE_ASSERT_MATCHING_ENUM(name) \ 106 #define COMPILE_ASSERT_MATCHING_ENUM(name) \
103 COMPILE_ASSERT(static_cast<int>(WebMediaPlayer::CORSMode ## name) == \ 107 COMPILE_ASSERT(static_cast<int>(WebMediaPlayer::CORSMode ## name) == \
104 static_cast<int>(BufferedResourceLoader::k ## name), \ 108 static_cast<int>(BufferedResourceLoader::k ## name), \
105 mismatching_enums) 109 mismatching_enums)
106 COMPILE_ASSERT_MATCHING_ENUM(Unspecified); 110 COMPILE_ASSERT_MATCHING_ENUM(Unspecified);
107 COMPILE_ASSERT_MATCHING_ENUM(Anonymous); 111 COMPILE_ASSERT_MATCHING_ENUM(Anonymous);
108 COMPILE_ASSERT_MATCHING_ENUM(UseCredentials); 112 COMPILE_ASSERT_MATCHING_ENUM(UseCredentials);
109 #undef COMPILE_ASSERT_MATCHING_ENUM 113 #undef COMPILE_ASSERT_MATCHING_ENUM
110 114
(...skipping 20 matching lines...) Expand all
131 network_state_(WebMediaPlayer::NetworkStateEmpty), 135 network_state_(WebMediaPlayer::NetworkStateEmpty),
132 ready_state_(WebMediaPlayer::ReadyStateHaveNothing), 136 ready_state_(WebMediaPlayer::ReadyStateHaveNothing),
133 main_loop_(base::MessageLoopProxy::current()), 137 main_loop_(base::MessageLoopProxy::current()),
134 media_loop_(params.message_loop_proxy()), 138 media_loop_(params.message_loop_proxy()),
135 paused_(true), 139 paused_(true),
136 seeking_(false), 140 seeking_(false),
137 playback_rate_(0.0f), 141 playback_rate_(0.0f),
138 pending_seek_(false), 142 pending_seek_(false),
139 pending_seek_seconds_(0.0f), 143 pending_seek_seconds_(0.0f),
140 client_(client), 144 client_(client),
145 load_delegate_(params.load_delegate()),
141 delegate_(delegate), 146 delegate_(delegate),
142 media_log_(params.media_log()), 147 media_log_(params.media_log()),
143 accelerated_compositing_reported_(false), 148 accelerated_compositing_reported_(false),
144 incremented_externally_allocated_memory_(false), 149 incremented_externally_allocated_memory_(false),
145 gpu_factories_(params.gpu_factories()), 150 gpu_factories_(params.gpu_factories()),
146 is_local_source_(false), 151 is_local_source_(false),
147 supports_save_(true), 152 supports_save_(true),
148 starting_(false), 153 starting_(false),
149 chunk_demuxer_(NULL), 154 chunk_demuxer_(NULL),
150 pending_repaint_(false), 155 pending_repaint_(false),
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
235 if (url.SchemeIs("file")) return kFileURLScheme; 240 if (url.SchemeIs("file")) return kFileURLScheme;
236 if (url.SchemeIs("blob")) return kBlobURLScheme; 241 if (url.SchemeIs("blob")) return kBlobURLScheme;
237 if (url.SchemeIs("data")) return kDataURLScheme; 242 if (url.SchemeIs("data")) return kDataURLScheme;
238 if (url.SchemeIs("filesystem")) return kFileSystemScheme; 243 if (url.SchemeIs("filesystem")) return kFileSystemScheme;
239 return kUnknownURLScheme; 244 return kUnknownURLScheme;
240 } 245 }
241 246
242 } // anonymous namespace 247 } // anonymous namespace
243 248
244 void WebMediaPlayerImpl::load(const WebKit::WebURL& url, CORSMode cors_mode) { 249 void WebMediaPlayerImpl::load(const WebKit::WebURL& url, CORSMode cors_mode) {
245 DCHECK(main_loop_->BelongsToCurrentThread()); 250 load(url, NULL, cors_mode);
246
247 LoadSetup(url);
248
249 // Otherwise it's a regular request which requires resolving the URL first.
250 GURL gurl(url);
251 data_source_.reset(new BufferedDataSource(
252 main_loop_,
253 frame_,
254 media_log_.get(),
255 base::Bind(&WebMediaPlayerImpl::NotifyDownloading, AsWeakPtr())));
256 data_source_->Initialize(
257 url, static_cast<BufferedResourceLoader::CORSMode>(cors_mode),
258 base::Bind(
259 &WebMediaPlayerImpl::DataSourceInitialized,
260 AsWeakPtr(), gurl));
261
262 is_local_source_ = !gurl.SchemeIs("http") && !gurl.SchemeIs("https");
263 } 251 }
264 252
265 void WebMediaPlayerImpl::load(const WebKit::WebURL& url, 253 void WebMediaPlayerImpl::load(const WebKit::WebURL& url,
266 WebKit::WebMediaSource* media_source, 254 WebKit::WebMediaSource* media_source,
267 CORSMode cors_mode) { 255 CORSMode cors_mode) {
268 LoadSetup(url); 256 if (load_delegate_) {
269 257 load_delegate_->DeferLoad(base::Bind(
270 // Media source pipelines can start immediately. 258 &WebMediaPlayerImpl::ContinueLoad, AsWeakPtr(), url, media_source,
271 supports_save_ = false; 259 cors_mode));
272 StartPipeline(media_source); 260 return;
261 }
262 ContinueLoad(url, media_source, cors_mode);
273 } 263 }
274 264
275 void WebMediaPlayerImpl::LoadSetup(const WebKit::WebURL& url) { 265 void WebMediaPlayerImpl::ContinueLoad(const WebKit::WebURL& url,
266 WebKit::WebMediaSource* media_source,
267 CORSMode cors_mode) {
268 DCHECK(main_loop_->BelongsToCurrentThread());
269
276 GURL gurl(url); 270 GURL gurl(url);
277 UMA_HISTOGRAM_ENUMERATION("Media.URLScheme", URLScheme(gurl), kMaxURLScheme); 271 UMA_HISTOGRAM_ENUMERATION("Media.URLScheme", URLScheme(gurl), kMaxURLScheme);
278 272
279 // Set subresource URL for crash reporting. 273 // Set subresource URL for crash reporting.
280 base::debug::SetCrashKeyValue("subresource_url", gurl.spec()); 274 base::debug::SetCrashKeyValue("subresource_url", gurl.spec());
281 275
282 // Handle any volume/preload changes that occurred before load(). 276 // Handle any volume/preload changes that occurred before load().
283 setVolume(GetClient()->volume()); 277 setVolume(GetClient()->volume());
284 setPreload(GetClient()->preload()); 278 setPreload(GetClient()->preload());
285 279
286 SetNetworkState(WebMediaPlayer::NetworkStateLoading); 280 SetNetworkState(WebMediaPlayer::NetworkStateLoading);
287 SetReadyState(WebMediaPlayer::ReadyStateHaveNothing); 281 SetReadyState(WebMediaPlayer::ReadyStateHaveNothing);
288 media_log_->AddEvent(media_log_->CreateLoadEvent(url.spec())); 282 media_log_->AddEvent(media_log_->CreateLoadEvent(url.spec()));
283
284 // Media source pipelines can start immediately.
285 if (media_source) {
286 supports_save_ = false;
287 StartPipeline(media_source);
288 return;
289 }
290
291 // Otherwise it's a regular request which requires resolving the URL first.
292 data_source_.reset(new BufferedDataSource(
293 main_loop_,
294 frame_,
295 media_log_.get(),
296 base::Bind(&WebMediaPlayerImpl::NotifyDownloading, AsWeakPtr())));
297 data_source_->Initialize(
298 url, static_cast<BufferedResourceLoader::CORSMode>(cors_mode),
299 base::Bind(
300 &WebMediaPlayerImpl::DataSourceInitialized,
301 AsWeakPtr(), gurl));
302
303 is_local_source_ = !gurl.SchemeIs("http") && !gurl.SchemeIs("https");
289 } 304 }
290 305
291 void WebMediaPlayerImpl::play() { 306 void WebMediaPlayerImpl::play() {
292 DCHECK(main_loop_->BelongsToCurrentThread()); 307 DCHECK(main_loop_->BelongsToCurrentThread());
293 308
294 paused_ = false; 309 paused_ = false;
295 pipeline_->SetPlaybackRate(playback_rate_); 310 pipeline_->SetPlaybackRate(playback_rate_);
296 311
297 media_log_->AddEvent(media_log_->CreateEvent(media::MediaLogEvent::PLAY)); 312 media_log_->AddEvent(media_log_->CreateEvent(media::MediaLogEvent::PLAY));
298 313
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
376 } 391 }
377 392
378 void WebMediaPlayerImpl::setVolume(double volume) { 393 void WebMediaPlayerImpl::setVolume(double volume) {
379 DCHECK(main_loop_->BelongsToCurrentThread()); 394 DCHECK(main_loop_->BelongsToCurrentThread());
380 395
381 pipeline_->SetVolume(volume); 396 pipeline_->SetVolume(volume);
382 } 397 }
383 398
384 #define COMPILE_ASSERT_MATCHING_ENUM(webkit_name, chromium_name) \ 399 #define COMPILE_ASSERT_MATCHING_ENUM(webkit_name, chromium_name) \
385 COMPILE_ASSERT(static_cast<int>(WebMediaPlayer::webkit_name) == \ 400 COMPILE_ASSERT(static_cast<int>(WebMediaPlayer::webkit_name) == \
386 static_cast<int>(webkit_media::chromium_name), \ 401 static_cast<int>(content::chromium_name), \
387 mismatching_enums) 402 mismatching_enums)
388 COMPILE_ASSERT_MATCHING_ENUM(PreloadNone, NONE); 403 COMPILE_ASSERT_MATCHING_ENUM(PreloadNone, NONE);
389 COMPILE_ASSERT_MATCHING_ENUM(PreloadMetaData, METADATA); 404 COMPILE_ASSERT_MATCHING_ENUM(PreloadMetaData, METADATA);
390 COMPILE_ASSERT_MATCHING_ENUM(PreloadAuto, AUTO); 405 COMPILE_ASSERT_MATCHING_ENUM(PreloadAuto, AUTO);
391 #undef COMPILE_ASSERT_MATCHING_ENUM 406 #undef COMPILE_ASSERT_MATCHING_ENUM
392 407
393 void WebMediaPlayerImpl::setPreload(WebMediaPlayer::Preload preload) { 408 void WebMediaPlayerImpl::setPreload(WebMediaPlayer::Preload preload) {
394 DCHECK(main_loop_->BelongsToCurrentThread()); 409 DCHECK(main_loop_->BelongsToCurrentThread());
395 410
396 if (data_source_) 411 if (data_source_)
397 data_source_->SetPreload(static_cast<webkit_media::Preload>(preload)); 412 data_source_->SetPreload(static_cast<content::Preload>(preload));
398 } 413 }
399 414
400 bool WebMediaPlayerImpl::hasVideo() const { 415 bool WebMediaPlayerImpl::hasVideo() const {
401 DCHECK(main_loop_->BelongsToCurrentThread()); 416 DCHECK(main_loop_->BelongsToCurrentThread());
402 417
403 return pipeline_->HasVideo(); 418 return pipeline_->HasVideo();
404 } 419 }
405 420
406 bool WebMediaPlayerImpl::hasAudio() const { 421 bool WebMediaPlayerImpl::hasAudio() const {
407 DCHECK(main_loop_->BelongsToCurrentThread()); 422 DCHECK(main_loop_->BelongsToCurrentThread());
(...skipping 808 matching lines...) Expand 10 before | Expand all | Expand 10 after
1216 current_frame_ = frame; 1231 current_frame_ = frame;
1217 1232
1218 if (pending_repaint_) 1233 if (pending_repaint_)
1219 return; 1234 return;
1220 1235
1221 pending_repaint_ = true; 1236 pending_repaint_ = true;
1222 main_loop_->PostTask(FROM_HERE, base::Bind( 1237 main_loop_->PostTask(FROM_HERE, base::Bind(
1223 &WebMediaPlayerImpl::Repaint, AsWeakPtr())); 1238 &WebMediaPlayerImpl::Repaint, AsWeakPtr()));
1224 } 1239 }
1225 1240
1226 } // namespace webkit_media 1241 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698