| 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 #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/renderer/media/buffered_data_source.h" |
| 22 #include "content/renderer/media/texttrack_impl.h" |
| 23 #include "content/renderer/media/webaudiosourceprovider_impl.h" |
| 24 #include "content/renderer/media/webinbandtexttrack_impl.h" |
| 25 #include "content/renderer/media/webmediaplayer_delegate.h" |
| 26 #include "content/renderer/media/webmediaplayer_params.h" |
| 27 #include "content/renderer/media/webmediaplayer_util.h" |
| 28 #include "content/renderer/media/webmediasourceclient_impl.h" |
| 21 #include "gpu/GLES2/gl2extchromium.h" | 29 #include "gpu/GLES2/gl2extchromium.h" |
| 22 #include "media/audio/null_audio_sink.h" | 30 #include "media/audio/null_audio_sink.h" |
| 23 #include "media/base/bind_to_loop.h" | 31 #include "media/base/bind_to_loop.h" |
| 24 #include "media/base/filter_collection.h" | 32 #include "media/base/filter_collection.h" |
| 25 #include "media/base/limits.h" | 33 #include "media/base/limits.h" |
| 26 #include "media/base/media_log.h" | 34 #include "media/base/media_log.h" |
| 27 #include "media/base/media_switches.h" | 35 #include "media/base/media_switches.h" |
| 28 #include "media/base/pipeline.h" | 36 #include "media/base/pipeline.h" |
| 29 #include "media/base/video_frame.h" | 37 #include "media/base/video_frame.h" |
| 30 #include "media/filters/audio_renderer_impl.h" | 38 #include "media/filters/audio_renderer_impl.h" |
| 31 #include "media/filters/chunk_demuxer.h" | 39 #include "media/filters/chunk_demuxer.h" |
| 32 #include "media/filters/ffmpeg_audio_decoder.h" | 40 #include "media/filters/ffmpeg_audio_decoder.h" |
| 33 #include "media/filters/ffmpeg_demuxer.h" | 41 #include "media/filters/ffmpeg_demuxer.h" |
| 34 #include "media/filters/ffmpeg_video_decoder.h" | 42 #include "media/filters/ffmpeg_video_decoder.h" |
| 35 #include "media/filters/opus_audio_decoder.h" | 43 #include "media/filters/opus_audio_decoder.h" |
| 36 #include "media/filters/video_renderer_base.h" | 44 #include "media/filters/video_renderer_base.h" |
| 37 #include "media/filters/vpx_video_decoder.h" | 45 #include "media/filters/vpx_video_decoder.h" |
| 38 #include "third_party/WebKit/public/platform/WebRect.h" | 46 #include "third_party/WebKit/public/platform/WebRect.h" |
| 39 #include "third_party/WebKit/public/platform/WebSize.h" | 47 #include "third_party/WebKit/public/platform/WebSize.h" |
| 40 #include "third_party/WebKit/public/platform/WebString.h" | 48 #include "third_party/WebKit/public/platform/WebString.h" |
| 41 #include "third_party/WebKit/public/platform/WebURL.h" | 49 #include "third_party/WebKit/public/platform/WebURL.h" |
| 42 #include "third_party/WebKit/public/web/WebMediaSource.h" | 50 #include "third_party/WebKit/public/web/WebMediaSource.h" |
| 43 #include "third_party/WebKit/public/web/WebRuntimeFeatures.h" | 51 #include "third_party/WebKit/public/web/WebRuntimeFeatures.h" |
| 44 #include "third_party/WebKit/public/web/WebView.h" | 52 #include "third_party/WebKit/public/web/WebView.h" |
| 45 #include "v8/include/v8.h" | 53 #include "v8/include/v8.h" |
| 46 #include "webkit/plugins/ppapi/ppapi_webplugin_impl.h" | 54 #include "webkit/plugins/ppapi/ppapi_webplugin_impl.h" |
| 47 #include "webkit/renderer/compositor_bindings/web_layer_impl.h" | 55 #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" | 56 #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 | 57 |
| 58 using WebKit::WebCanvas; | 58 using WebKit::WebCanvas; |
| 59 using WebKit::WebMediaPlayer; | 59 using WebKit::WebMediaPlayer; |
| 60 using WebKit::WebRect; | 60 using WebKit::WebRect; |
| 61 using WebKit::WebSize; | 61 using WebKit::WebSize; |
| 62 using WebKit::WebString; | 62 using WebKit::WebString; |
| 63 using media::PipelineStatus; | 63 using media::PipelineStatus; |
| 64 using webkit_media::IsSupportedKeySystem; |
| 65 using webkit_media::KeySystemNameForUMA; |
| 66 using webkit_media::ProxyDecryptor; |
| 64 | 67 |
| 65 namespace { | 68 namespace { |
| 66 | 69 |
| 67 // Amount of extra memory used by each player instance reported to V8. | 70 // Amount of extra memory used by each player instance reported to V8. |
| 68 // It is not exact number -- first, it differs on different platforms, | 71 // It is not exact number -- first, it differs on different platforms, |
| 69 // and second, it is very hard to calculate. Instead, use some arbitrary | 72 // 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 | 73 // 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 | 74 // 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 | 75 // 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 | 76 // objects. (Do not worry about video objects yet, JS programs do not create |
| (...skipping 16 matching lines...) Expand all Loading... |
| 90 // Also our timers are not very accurate (especially for ogg), which becomes | 93 // 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 | 94 // 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. | 95 // the norms, we think 1/16x to 16x is a safe and useful range for now. |
| 93 const double kMinRate = 0.0625; | 96 const double kMinRate = 0.0625; |
| 94 const double kMaxRate = 16.0; | 97 const double kMaxRate = 16.0; |
| 95 | 98 |
| 96 // Prefix for histograms related to Encrypted Media Extensions. | 99 // Prefix for histograms related to Encrypted Media Extensions. |
| 97 const char* kMediaEme = "Media.EME."; | 100 const char* kMediaEme = "Media.EME."; |
| 98 } // namespace | 101 } // namespace |
| 99 | 102 |
| 100 namespace webkit_media { | 103 namespace content { |
| 101 | 104 |
| 102 #define COMPILE_ASSERT_MATCHING_ENUM(name) \ | 105 #define COMPILE_ASSERT_MATCHING_ENUM(name) \ |
| 103 COMPILE_ASSERT(static_cast<int>(WebMediaPlayer::CORSMode ## name) == \ | 106 COMPILE_ASSERT(static_cast<int>(WebMediaPlayer::CORSMode ## name) == \ |
| 104 static_cast<int>(BufferedResourceLoader::k ## name), \ | 107 static_cast<int>(BufferedResourceLoader::k ## name), \ |
| 105 mismatching_enums) | 108 mismatching_enums) |
| 106 COMPILE_ASSERT_MATCHING_ENUM(Unspecified); | 109 COMPILE_ASSERT_MATCHING_ENUM(Unspecified); |
| 107 COMPILE_ASSERT_MATCHING_ENUM(Anonymous); | 110 COMPILE_ASSERT_MATCHING_ENUM(Anonymous); |
| 108 COMPILE_ASSERT_MATCHING_ENUM(UseCredentials); | 111 COMPILE_ASSERT_MATCHING_ENUM(UseCredentials); |
| 109 #undef COMPILE_ASSERT_MATCHING_ENUM | 112 #undef COMPILE_ASSERT_MATCHING_ENUM |
| 110 | 113 |
| (...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 387 } | 390 } |
| 388 | 391 |
| 389 void WebMediaPlayerImpl::setVolume(double volume) { | 392 void WebMediaPlayerImpl::setVolume(double volume) { |
| 390 DCHECK(main_loop_->BelongsToCurrentThread()); | 393 DCHECK(main_loop_->BelongsToCurrentThread()); |
| 391 | 394 |
| 392 pipeline_->SetVolume(volume); | 395 pipeline_->SetVolume(volume); |
| 393 } | 396 } |
| 394 | 397 |
| 395 #define COMPILE_ASSERT_MATCHING_ENUM(webkit_name, chromium_name) \ | 398 #define COMPILE_ASSERT_MATCHING_ENUM(webkit_name, chromium_name) \ |
| 396 COMPILE_ASSERT(static_cast<int>(WebMediaPlayer::webkit_name) == \ | 399 COMPILE_ASSERT(static_cast<int>(WebMediaPlayer::webkit_name) == \ |
| 397 static_cast<int>(webkit_media::chromium_name), \ | 400 static_cast<int>(content::chromium_name), \ |
| 398 mismatching_enums) | 401 mismatching_enums) |
| 399 COMPILE_ASSERT_MATCHING_ENUM(PreloadNone, NONE); | 402 COMPILE_ASSERT_MATCHING_ENUM(PreloadNone, NONE); |
| 400 COMPILE_ASSERT_MATCHING_ENUM(PreloadMetaData, METADATA); | 403 COMPILE_ASSERT_MATCHING_ENUM(PreloadMetaData, METADATA); |
| 401 COMPILE_ASSERT_MATCHING_ENUM(PreloadAuto, AUTO); | 404 COMPILE_ASSERT_MATCHING_ENUM(PreloadAuto, AUTO); |
| 402 #undef COMPILE_ASSERT_MATCHING_ENUM | 405 #undef COMPILE_ASSERT_MATCHING_ENUM |
| 403 | 406 |
| 404 void WebMediaPlayerImpl::setPreload(WebMediaPlayer::Preload preload) { | 407 void WebMediaPlayerImpl::setPreload(WebMediaPlayer::Preload preload) { |
| 405 DCHECK(main_loop_->BelongsToCurrentThread()); | 408 DCHECK(main_loop_->BelongsToCurrentThread()); |
| 406 | 409 |
| 407 if (data_source_) | 410 if (data_source_) |
| 408 data_source_->SetPreload(static_cast<webkit_media::Preload>(preload)); | 411 data_source_->SetPreload(static_cast<content::Preload>(preload)); |
| 409 } | 412 } |
| 410 | 413 |
| 411 bool WebMediaPlayerImpl::hasVideo() const { | 414 bool WebMediaPlayerImpl::hasVideo() const { |
| 412 DCHECK(main_loop_->BelongsToCurrentThread()); | 415 DCHECK(main_loop_->BelongsToCurrentThread()); |
| 413 | 416 |
| 414 return pipeline_->HasVideo(); | 417 return pipeline_->HasVideo(); |
| 415 } | 418 } |
| 416 | 419 |
| 417 bool WebMediaPlayerImpl::hasAudio() const { | 420 bool WebMediaPlayerImpl::hasAudio() const { |
| 418 DCHECK(main_loop_->BelongsToCurrentThread()); | 421 DCHECK(main_loop_->BelongsToCurrentThread()); |
| (...skipping 815 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1234 current_frame_ = frame; | 1237 current_frame_ = frame; |
| 1235 | 1238 |
| 1236 if (pending_repaint_) | 1239 if (pending_repaint_) |
| 1237 return; | 1240 return; |
| 1238 | 1241 |
| 1239 pending_repaint_ = true; | 1242 pending_repaint_ = true; |
| 1240 main_loop_->PostTask(FROM_HERE, base::Bind( | 1243 main_loop_->PostTask(FROM_HERE, base::Bind( |
| 1241 &WebMediaPlayerImpl::Repaint, AsWeakPtr())); | 1244 &WebMediaPlayerImpl::Repaint, AsWeakPtr())); |
| 1242 } | 1245 } |
| 1243 | 1246 |
| 1244 } // namespace webkit_media | 1247 } // namespace content |
| OLD | NEW |