[email protected] | 85a37afd | 2013-05-30 22:51:15 | [diff] [blame] | 1 | // Copyright 2013 The Chromium Authors. All rights reserved. |
[email protected] | 891acc9 | 2009-04-27 19:56:41 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
[email protected] | ec9212f | 2008-12-18 21:40:36 | [diff] [blame] | 4 | |
acolwell | 9e0840d | 2014-09-06 19:01:32 | [diff] [blame] | 5 | #include "media/blink/webmediaplayer_impl.h" |
[email protected] | 8931c41a | 2009-07-07 17:31:49 | [diff] [blame] | 6 | |
[email protected] | c2a45e24 | 2013-02-15 20:24:58 | [diff] [blame] | 7 | #include <algorithm> |
mateuszs | 3371ab0 | 2015-04-24 13:20:23 | [diff] [blame] | 8 | #include <cmath> |
[email protected] | 47b06ceb | 2010-08-04 22:41:11 | [diff] [blame] | 9 | #include <limits> |
guidou | c7babef | 2015-10-22 00:42:35 | [diff] [blame] | 10 | #include <string> |
dcheng | 652f5ff | 2015-12-27 08:54:00 | [diff] [blame] | 11 | #include <utility> |
[email protected] | 47b06ceb | 2010-08-04 22:41:11 | [diff] [blame] | 12 | |
[email protected] | 08273c7b | 2011-09-17 00:33:51 | [diff] [blame] | 13 | #include "base/bind.h" |
sandersd | 1c0bba0 | 2016-03-04 23:14:08 | [diff] [blame] | 14 | #include "base/bind_helpers.h" |
[email protected] | 2041cf34 | 2010-02-19 03:15:59 | [diff] [blame] | 15 | #include "base/callback.h" |
[email protected] | 7502ef1 | 2014-01-25 01:19:27 | [diff] [blame] | 16 | #include "base/callback_helpers.h" |
sandersd | 1e49fb6 | 2015-12-12 01:18:06 | [diff] [blame] | 17 | #include "base/command_line.h" |
[email protected] | ca04095f | 2014-02-07 10:23:56 | [diff] [blame] | 18 | #include "base/debug/alias.h" |
[email protected] | 926f8fd | 2013-04-12 20:27:53 | [diff] [blame] | 19 | #include "base/debug/crash_logging.h" |
dalecurtis | 6e3901e | 2016-03-16 20:51:08 | [diff] [blame] | 20 | #include "base/debug/dump_without_crashing.h" |
[email protected] | b0b258f | 2011-11-08 00:34:23 | [diff] [blame] | 21 | #include "base/metrics/histogram.h" |
dalecurtis | 6e3901e | 2016-03-16 20:51:08 | [diff] [blame] | 22 | #include "base/rand_util.h" |
acolwell | b403494 | 2014-08-28 15:42:43 | [diff] [blame] | 23 | #include "base/single_thread_task_runner.h" |
[email protected] | cf02541b | 2012-04-11 08:02:17 | [diff] [blame] | 24 | #include "base/synchronization/waitable_event.h" |
wdzierzanowski | fd4cd91c5 | 2015-12-02 23:50:20 | [diff] [blame] | 25 | #include "base/task_runner_util.h" |
anujk.sharma | 2fa37a0 | 2015-04-30 05:51:32 | [diff] [blame] | 26 | #include "base/thread_task_runner_handle.h" |
ssid | 9525f467 | 2015-01-28 12:13:15 | [diff] [blame] | 27 | #include "base/trace_event/trace_event.h" |
sandersd | 1e49fb6 | 2015-12-12 01:18:06 | [diff] [blame] | 28 | #include "build/build_config.h" |
[email protected] | 3856462 | 2014-08-19 02:47:18 | [diff] [blame] | 29 | #include "cc/blink/web_layer_impl.h" |
[email protected] | 21c3f750 | 2013-03-23 03:29:51 | [diff] [blame] | 30 | #include "cc/layers/video_layer.h" |
dongseong.hwang | 0c4e9d8 | 2015-01-08 20:11:13 | [diff] [blame] | 31 | #include "gpu/blink/webgraphicscontext3d_impl.h" |
[email protected] | e4fc09e | 2012-04-06 03:17:44 | [diff] [blame] | 32 | #include "media/audio/null_audio_sink.h" |
[email protected] | 2eccbed | 2014-01-10 05:15:53 | [diff] [blame] | 33 | #include "media/base/bind_to_current_loop.h" |
xhwang | 0ad11e51 | 2014-11-25 23:43:09 | [diff] [blame] | 34 | #include "media/base/cdm_context.h" |
[email protected] | 32da100 | 2010-03-03 21:57:35 | [diff] [blame] | 35 | #include "media/base/limits.h" |
[email protected] | 090f731 | 2011-08-05 23:26:40 | [diff] [blame] | 36 | #include "media/base/media_log.h" |
sandersd | 1e49fb6 | 2015-12-12 01:18:06 | [diff] [blame] | 37 | #include "media/base/media_switches.h" |
[email protected] | 8a56106 | 2013-11-22 01:19:31 | [diff] [blame] | 38 | #include "media/base/text_renderer.h" |
watk | 9f9dfdc9 | 2015-09-04 21:33:29 | [diff] [blame] | 39 | #include "media/base/timestamp_constants.h" |
[email protected] | e81283bb | 2010-08-31 18:01:21 | [diff] [blame] | 40 | #include "media/base/video_frame.h" |
acolwell | 9e0840d | 2014-09-06 19:01:32 | [diff] [blame] | 41 | #include "media/blink/texttrack_impl.h" |
| 42 | #include "media/blink/webaudiosourceprovider_impl.h" |
xhwang | 97de420 | 2014-11-25 08:44:01 | [diff] [blame] | 43 | #include "media/blink/webcontentdecryptionmodule_impl.h" |
acolwell | 9e0840d | 2014-09-06 19:01:32 | [diff] [blame] | 44 | #include "media/blink/webinbandtexttrack_impl.h" |
| 45 | #include "media/blink/webmediaplayer_delegate.h" |
acolwell | 9e0840d | 2014-09-06 19:01:32 | [diff] [blame] | 46 | #include "media/blink/webmediaplayer_util.h" |
| 47 | #include "media/blink/webmediasource_impl.h" |
[email protected] | efe7cd2 | 2012-09-12 23:55:01 | [diff] [blame] | 48 | #include "media/filters/chunk_demuxer.h" |
[email protected] | ddbc6ff | 2013-04-19 15:28:33 | [diff] [blame] | 49 | #include "media/filters/ffmpeg_demuxer.h" |
jrummell | c9d8e53 | 2015-02-26 18:38:19 | [diff] [blame] | 50 | #include "third_party/WebKit/public/platform/WebEncryptedMediaTypes.h" |
srirama.m | 26f864d0 | 2015-07-14 05:21:46 | [diff] [blame] | 51 | #include "third_party/WebKit/public/platform/WebMediaPlayerClient.h" |
| 52 | #include "third_party/WebKit/public/platform/WebMediaPlayerEncryptedMediaClient.h" |
[email protected] | 745746d | 2013-08-23 02:09:16 | [diff] [blame] | 53 | #include "third_party/WebKit/public/platform/WebMediaSource.h" |
[email protected] | c1088446 | 2013-05-30 00:22:09 | [diff] [blame] | 54 | #include "third_party/WebKit/public/platform/WebRect.h" |
mek | 966863c | 2016-02-04 23:39:05 | [diff] [blame] | 55 | #include "third_party/WebKit/public/platform/WebSecurityOrigin.h" |
[email protected] | c1088446 | 2013-05-30 00:22:09 | [diff] [blame] | 56 | #include "third_party/WebKit/public/platform/WebSize.h" |
| 57 | #include "third_party/WebKit/public/platform/WebString.h" |
| 58 | #include "third_party/WebKit/public/platform/WebURL.h" |
xhwang | 0acca44b | 2015-06-18 00:43:31 | [diff] [blame] | 59 | #include "third_party/WebKit/public/web/WebFrame.h" |
[email protected] | 8050465 | 2014-04-18 04:41:50 | [diff] [blame] | 60 | #include "third_party/WebKit/public/web/WebLocalFrame.h" |
[email protected] | 2255a933 | 2013-06-17 05:12:31 | [diff] [blame] | 61 | #include "third_party/WebKit/public/web/WebView.h" |
[email protected] | b3f2b91 | 2009-04-09 16:18:52 | [diff] [blame] | 62 | |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame] | 63 | using blink::WebCanvas; |
| 64 | using blink::WebMediaPlayer; |
| 65 | using blink::WebRect; |
| 66 | using blink::WebSize; |
| 67 | using blink::WebString; |
hubbe | d5f3688 | 2016-01-15 22:40:37 | [diff] [blame] | 68 | using gpu::gles2::GLES2Interface; |
| 69 | |
danakj | 365175c | 2016-02-06 00:37:37 | [diff] [blame] | 70 | #define STATIC_ASSERT_ENUM(a, b) \ |
| 71 | static_assert(static_cast<int>(a) == static_cast<int>(b), \ |
| 72 | "mismatching enums: " #a) |
| 73 | |
hubbe | d5f3688 | 2016-01-15 22:40:37 | [diff] [blame] | 74 | namespace media { |
[email protected] | ec9212f | 2008-12-18 21:40:36 | [diff] [blame] | 75 | |
[email protected] | 8931c41a | 2009-07-07 17:31:49 | [diff] [blame] | 76 | namespace { |
| 77 | |
[email protected] | 378f0b7 | 2009-08-11 17:11:42 | [diff] [blame] | 78 | // Limits the range of playback rate. |
| 79 | // |
| 80 | // TODO(kylep): Revisit these. |
| 81 | // |
| 82 | // Vista has substantially lower performance than XP or Windows7. If you speed |
| 83 | // up a video too much, it can't keep up, and rendering stops updating except on |
| 84 | // the time bar. For really high speeds, audio becomes a bottleneck and we just |
| 85 | // use up the data we have, which may not achieve the speed requested, but will |
| 86 | // not crash the tab. |
| 87 | // |
| 88 | // A very slow speed, ie 0.00000001x, causes the machine to lock up. (It seems |
| 89 | // like a busy loop). It gets unresponsive, although its not completely dead. |
| 90 | // |
| 91 | // Also our timers are not very accurate (especially for ogg), which becomes |
| 92 | // evident at low speeds and on Vista. Since other speeds are risky and outside |
| 93 | // the norms, we think 1/16x to 16x is a safe and useful range for now. |
[email protected] | 39bdde3 | 2013-04-17 17:44:20 | [diff] [blame] | 94 | const double kMinRate = 0.0625; |
| 95 | const double kMaxRate = 16.0; |
[email protected] | 378f0b7 | 2009-08-11 17:11:42 | [diff] [blame] | 96 | |
hubbe | d5f3688 | 2016-01-15 22:40:37 | [diff] [blame] | 97 | void SetSinkIdOnMediaThread(scoped_refptr<WebAudioSourceProviderImpl> sink, |
| 98 | const std::string& device_id, |
| 99 | const url::Origin& security_origin, |
| 100 | const SwitchOutputDeviceCB& callback) { |
guidou | c7babef | 2015-10-22 00:42:35 | [diff] [blame] | 101 | if (sink->GetOutputDevice()) { |
| 102 | sink->GetOutputDevice()->SwitchOutputDevice(device_id, security_origin, |
| 103 | callback); |
| 104 | } else { |
hubbe | d5f3688 | 2016-01-15 22:40:37 | [diff] [blame] | 105 | callback.Run(OUTPUT_DEVICE_STATUS_ERROR_INTERNAL); |
guidou | c7babef | 2015-10-22 00:42:35 | [diff] [blame] | 106 | } |
| 107 | } |
| 108 | |
dalecurtis | 0431cbf | 2016-03-12 01:19:43 | [diff] [blame] | 109 | bool IsSuspendUponHiddenEnabled() { |
| 110 | #if !defined(OS_ANDROID) |
| 111 | // Suspend/Resume is only enabled by default on Android. |
| 112 | return base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 113 | switches::kEnableMediaSuspend); |
| 114 | #else |
| 115 | return !base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 116 | switches::kDisableMediaSuspend); |
| 117 | #endif |
| 118 | } |
| 119 | |
[email protected] | 8931c41a | 2009-07-07 17:31:49 | [diff] [blame] | 120 | } // namespace |
| 121 | |
[email protected] | 6683e1b | 2014-04-10 01:45:38 | [diff] [blame] | 122 | class BufferedDataSourceHostImpl; |
| 123 | |
danakj | 365175c | 2016-02-06 00:37:37 | [diff] [blame] | 124 | STATIC_ASSERT_ENUM(WebMediaPlayer::CORSModeUnspecified, |
| 125 | UrlData::CORS_UNSPECIFIED); |
| 126 | STATIC_ASSERT_ENUM(WebMediaPlayer::CORSModeAnonymous, UrlData::CORS_ANONYMOUS); |
| 127 | STATIC_ASSERT_ENUM(WebMediaPlayer::CORSModeUseCredentials, |
| 128 | UrlData::CORS_USE_CREDENTIALS); |
[email protected] | a5a0110 | 2012-06-06 17:01:24 | [diff] [blame] | 129 | |
[email protected] | 2c539b8 | 2012-08-18 04:10:19 | [diff] [blame] | 130 | #define BIND_TO_RENDER_LOOP(function) \ |
acolwell | b403494 | 2014-08-28 15:42:43 | [diff] [blame] | 131 | (DCHECK(main_task_runner_->BelongsToCurrentThread()), \ |
acolwell | 9e0840d | 2014-09-06 19:01:32 | [diff] [blame] | 132 | BindToCurrentLoop(base::Bind(function, AsWeakPtr()))) |
[email protected] | 5983adb | 2012-10-24 00:12:00 | [diff] [blame] | 133 | |
[email protected] | 4e98219 | 2014-06-21 13:35:45 | [diff] [blame] | 134 | #define BIND_TO_RENDER_LOOP1(function, arg1) \ |
acolwell | b403494 | 2014-08-28 15:42:43 | [diff] [blame] | 135 | (DCHECK(main_task_runner_->BelongsToCurrentThread()), \ |
acolwell | 9e0840d | 2014-09-06 19:01:32 | [diff] [blame] | 136 | BindToCurrentLoop(base::Bind(function, AsWeakPtr(), arg1))) |
[email protected] | 4e98219 | 2014-06-21 13:35:45 | [diff] [blame] | 137 | |
[email protected] | 5b5bb9d | 2010-10-22 19:57:36 | [diff] [blame] | 138 | WebMediaPlayerImpl::WebMediaPlayerImpl( |
[email protected] | 35b2a97 | 2014-04-04 15:50:22 | [diff] [blame] | 139 | blink::WebLocalFrame* frame, |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame] | 140 | blink::WebMediaPlayerClient* client, |
srirama.m | 26f864d0 | 2015-07-14 05:21:46 | [diff] [blame] | 141 | blink::WebMediaPlayerEncryptedMediaClient* encrypted_client, |
[email protected] | b897665 | 2011-10-26 23:46:55 | [diff] [blame] | 142 | base::WeakPtr<WebMediaPlayerDelegate> delegate, |
xhwang | 6fa35620 | 2014-12-11 00:44:12 | [diff] [blame] | 143 | scoped_ptr<RendererFactory> renderer_factory, |
hubbe | 5f0ad43b | 2015-12-14 20:57:26 | [diff] [blame] | 144 | linked_ptr<UrlIndex> url_index, |
[email protected] | e82b2bd | 2013-01-02 17:47:57 | [diff] [blame] | 145 | const WebMediaPlayerParams& params) |
[email protected] | f6af759 | 2014-02-28 10:09:11 | [diff] [blame] | 146 | : frame_(frame), |
[email protected] | ef405f66b | 2012-04-18 02:39:55 | [diff] [blame] | 147 | network_state_(WebMediaPlayer::NetworkStateEmpty), |
| 148 | ready_state_(WebMediaPlayer::ReadyStateHaveNothing), |
acolwell | a5081a4 | 2014-08-28 23:42:52 | [diff] [blame] | 149 | preload_(BufferedDataSource::AUTO), |
sandersd | c6ab163a | 2015-12-12 03:56:13 | [diff] [blame] | 150 | buffering_strategy_( |
| 151 | BufferedDataSourceInterface::BUFFERING_STRATEGY_NORMAL), |
anujk.sharma | 2fa37a0 | 2015-04-30 05:51:32 | [diff] [blame] | 152 | main_task_runner_(base::ThreadTaskRunnerHandle::Get()), |
acolwell | 755d12d | 2014-08-30 01:09:19 | [diff] [blame] | 153 | media_task_runner_(params.media_task_runner()), |
dcastagna | 617d086b | 2015-08-20 01:39:30 | [diff] [blame] | 154 | worker_task_runner_(params.worker_task_runner()), |
acolwell | 755d12d | 2014-08-30 01:09:19 | [diff] [blame] | 155 | media_log_(params.media_log()), |
acolwell | b403494 | 2014-08-28 15:42:43 | [diff] [blame] | 156 | pipeline_(media_task_runner_, media_log_.get()), |
sandersd | 1c0bba0 | 2016-03-04 23:14:08 | [diff] [blame] | 157 | pipeline_controller_( |
| 158 | &pipeline_, |
| 159 | base::Bind(&WebMediaPlayerImpl::CreateRenderer, |
| 160 | base::Unretained(this)), |
| 161 | base::Bind(&WebMediaPlayerImpl::OnPipelineSeeked, AsWeakPtr()), |
| 162 | base::Bind(&WebMediaPlayerImpl::OnPipelineSuspended, AsWeakPtr()), |
| 163 | base::Bind(&WebMediaPlayerImpl::OnPipelineResumed, AsWeakPtr()), |
| 164 | base::Bind(&WebMediaPlayerImpl::OnPipelineError, AsWeakPtr())), |
[email protected] | f988d9b | 2014-07-25 00:35:43 | [diff] [blame] | 165 | load_type_(LoadTypeURL), |
[email protected] | 75e145a | 2014-04-15 17:44:32 | [diff] [blame] | 166 | opaque_(false), |
wolenetz | 1b2ae7d | 2015-06-10 00:44:21 | [diff] [blame] | 167 | playback_rate_(0.0), |
[email protected] | 4948090 | 2009-07-14 20:23:43 | [diff] [blame] | 168 | paused_(true), |
[email protected] | b3766a2 | 2010-12-22 17:34:13 | [diff] [blame] | 169 | seeking_(false), |
watk | dee516f | 2016-02-18 02:22:19 | [diff] [blame] | 170 | pending_suspend_resume_cycle_(false), |
scherkus | d2c745b | 2014-09-04 05:03:40 | [diff] [blame] | 171 | ended_(false), |
yoichio | 863bebf | 2016-03-04 07:56:58 | [diff] [blame] | 172 | should_notify_time_changed_(false), |
watk | dee516f | 2016-02-18 02:22:19 | [diff] [blame] | 173 | fullscreen_(false), |
| 174 | decoder_requires_restart_for_fullscreen_(false), |
[email protected] | 5badb08 | 2010-06-11 17:40:15 | [diff] [blame] | 175 | client_(client), |
srirama.m | 26f864d0 | 2015-07-14 05:21:46 | [diff] [blame] | 176 | encrypted_client_(encrypted_client), |
[email protected] | baff451 | 2011-10-19 18:21:07 | [diff] [blame] | 177 | delegate_(delegate), |
dalecurtis | bb3eaac | 2016-01-27 21:10:25 | [diff] [blame] | 178 | delegate_id_(0), |
[email protected] | d726eddc | 2013-07-02 22:25:55 | [diff] [blame] | 179 | defer_load_cb_(params.defer_load_cb()), |
dongseong.hwang | 0c4e9d8 | 2015-01-08 20:11:13 | [diff] [blame] | 180 | context_3d_cb_(params.context_3d_cb()), |
dalecurtis | 83266c7 | 2015-10-29 18:43:20 | [diff] [blame] | 181 | adjust_allocated_memory_cb_(params.adjust_allocated_memory_cb()), |
| 182 | last_reported_memory_usage_(0), |
[email protected] | 132dd57c | 2012-08-10 23:24:34 | [diff] [blame] | 183 | supports_save_(true), |
[email protected] | f5443ef7 | 2013-04-22 04:03:38 | [diff] [blame] | 184 | chunk_demuxer_(NULL), |
hubbe | 5f0ad43b | 2015-12-14 20:57:26 | [diff] [blame] | 185 | url_index_(url_index), |
Bartosz Fabianowski | 85a82381 | 2015-04-16 10:27:51 | [diff] [blame] | 186 | // Threaded compositing isn't enabled universally yet. |
| 187 | compositor_task_runner_( |
| 188 | params.compositor_task_runner() |
| 189 | ? params.compositor_task_runner() |
| 190 | : base::MessageLoop::current()->task_runner()), |
[email protected] | dd061e1 | 2014-05-06 19:21:22 | [diff] [blame] | 191 | compositor_(new VideoFrameCompositor( |
Bartosz Fabianowski | 85a82381 | 2015-04-16 10:27:51 | [diff] [blame] | 192 | compositor_task_runner_, |
[email protected] | 75e145a | 2014-04-15 17:44:32 | [diff] [blame] | 193 | BIND_TO_RENDER_LOOP(&WebMediaPlayerImpl::OnNaturalSizeChanged), |
[email protected] | dd061e1 | 2014-05-06 19:21:22 | [diff] [blame] | 194 | BIND_TO_RENDER_LOOP(&WebMediaPlayerImpl::OnOpacityChanged))), |
xhwang | 8073945 | 2016-01-13 00:48:00 | [diff] [blame] | 195 | is_cdm_attached_(false), |
hubbe | d5f3688 | 2016-01-15 22:40:37 | [diff] [blame] | 196 | #if defined(OS_ANDROID) // WMPI_CAST |
dalecurtis | bb3eaac | 2016-01-27 21:10:25 | [diff] [blame] | 197 | cast_impl_(this, client_, params.context_3d_cb()), |
hubbe | d5f3688 | 2016-01-15 22:40:37 | [diff] [blame] | 198 | #endif |
dalecurtis | bb3eaac | 2016-01-27 21:10:25 | [diff] [blame] | 199 | volume_(1.0), |
| 200 | volume_multiplier_(1.0), |
watk | dee516f | 2016-02-18 02:22:19 | [diff] [blame] | 201 | renderer_factory_(std::move(renderer_factory)), |
dalecurtis | 2ff781da | 2016-03-03 01:52:13 | [diff] [blame] | 202 | surface_manager_(params.surface_manager()), |
| 203 | suppress_destruction_errors_(false) { |
dalecurtis | 83266c7 | 2015-10-29 18:43:20 | [diff] [blame] | 204 | DCHECK(!adjust_allocated_memory_cb_.is_null()); |
xhwang | 59d4175a | 2016-01-14 03:19:30 | [diff] [blame] | 205 | DCHECK(renderer_factory_); |
servolk | ef1e5ef | 2016-03-25 04:55:26 | [diff] [blame] | 206 | DCHECK(client_); |
dalecurtis | 83266c7 | 2015-10-29 18:43:20 | [diff] [blame] | 207 | |
dalecurtis | bb3eaac | 2016-01-27 21:10:25 | [diff] [blame] | 208 | if (delegate_) |
| 209 | delegate_id_ = delegate_->AddObserver(this); |
sandersd | 1e49fb6 | 2015-12-12 01:18:06 | [diff] [blame] | 210 | |
[email protected] | c93eb0a6 | 2011-08-09 22:47:24 | [diff] [blame] | 211 | media_log_->AddEvent( |
acolwell | 9e0840d | 2014-09-06 19:01:32 | [diff] [blame] | 212 | media_log_->CreateEvent(MediaLogEvent::WEBMEDIAPLAYER_CREATED)); |
[email protected] | 4e6be3f | 2009-05-07 02:24:44 | [diff] [blame] | 213 | |
xhwang | 0ad11e51 | 2014-11-25 23:43:09 | [diff] [blame] | 214 | if (params.initial_cdm()) { |
xhwang | 9bd8c73 | 2015-04-13 23:27:53 | [diff] [blame] | 215 | SetCdm(base::Bind(&IgnoreCdmAttached), |
| 216 | ToWebContentDecryptionModuleImpl(params.initial_cdm()) |
| 217 | ->GetCdmContext()); |
xhwang | 0ad11e51 | 2014-11-25 23:43:09 | [diff] [blame] | 218 | } |
| 219 | |
xhwang | f94a634d | 2014-10-22 22:07:27 | [diff] [blame] | 220 | // TODO(xhwang): When we use an external Renderer, many methods won't work, |
xhwang | 6fa35620 | 2014-12-11 00:44:12 | [diff] [blame] | 221 | // e.g. GetCurrentFrameFromCompositor(). See http://crbug.com/434861 |
[email protected] | c50edb96 | 2013-10-19 18:05:07 | [diff] [blame] | 222 | |
[email protected] | ddbc6ff | 2013-04-19 15:28:33 | [diff] [blame] | 223 | // Use the null sink if no sink was provided. |
[email protected] | 4a91488 | 2013-01-10 00:43:48 | [diff] [blame] | 224 | audio_source_provider_ = new WebAudioSourceProviderImpl( |
[email protected] | ff875be5 | 2013-06-02 23:47:38 | [diff] [blame] | 225 | params.audio_renderer_sink().get() |
| 226 | ? params.audio_renderer_sink() |
acolwell | 9e0840d | 2014-09-06 19:01:32 | [diff] [blame] | 227 | : new NullAudioSink(media_task_runner_)); |
[email protected] | ec9212f | 2008-12-18 21:40:36 | [diff] [blame] | 228 | } |
| 229 | |
[email protected] | 4e6be3f | 2009-05-07 02:24:44 | [diff] [blame] | 230 | WebMediaPlayerImpl::~WebMediaPlayerImpl() { |
[email protected] | ce70c98 | 2013-12-20 17:04:32 | [diff] [blame] | 231 | client_->setWebLayer(NULL); |
[email protected] | 21c3f750 | 2013-03-23 03:29:51 | [diff] [blame] | 232 | |
acolwell | b403494 | 2014-08-28 15:42:43 | [diff] [blame] | 233 | DCHECK(main_task_runner_->BelongsToCurrentThread()); |
[email protected] | d43ed91 | 2009-02-03 04:52:53 | [diff] [blame] | 234 | |
sandersd | 1e49fb6 | 2015-12-12 01:18:06 | [diff] [blame] | 235 | if (delegate_) { |
dalecurtis | bb3eaac | 2016-01-27 21:10:25 | [diff] [blame] | 236 | delegate_->PlayerGone(delegate_id_); |
| 237 | delegate_->RemoveObserver(delegate_id_); |
sandersd | 1e49fb6 | 2015-12-12 01:18:06 | [diff] [blame] | 238 | } |
[email protected] | baff451 | 2011-10-19 18:21:07 | [diff] [blame] | 239 | |
[email protected] | f6af759 | 2014-02-28 10:09:11 | [diff] [blame] | 240 | // Abort any pending IO so stopping the pipeline doesn't get blocked. |
dalecurtis | 2ff781da | 2016-03-03 01:52:13 | [diff] [blame] | 241 | suppress_destruction_errors_ = true; |
[email protected] | f6af759 | 2014-02-28 10:09:11 | [diff] [blame] | 242 | if (data_source_) |
| 243 | data_source_->Abort(); |
| 244 | if (chunk_demuxer_) { |
| 245 | chunk_demuxer_->Shutdown(); |
sandersd | 1c0bba0 | 2016-03-04 23:14:08 | [diff] [blame] | 246 | chunk_demuxer_ = nullptr; |
[email protected] | f6af759 | 2014-02-28 10:09:11 | [diff] [blame] | 247 | } |
| 248 | |
xhwang | 6fa35620 | 2014-12-11 00:44:12 | [diff] [blame] | 249 | renderer_factory_.reset(); |
[email protected] | f6af759 | 2014-02-28 10:09:11 | [diff] [blame] | 250 | |
| 251 | // Make sure to kill the pipeline so there's no more media threads running. |
| 252 | // Note: stopping the pipeline might block for a long time. |
| 253 | base::WaitableEvent waiter(false, false); |
| 254 | pipeline_.Stop( |
| 255 | base::Bind(&base::WaitableEvent::Signal, base::Unretained(&waiter))); |
| 256 | waiter.Wait(); |
| 257 | |
dalecurtis | 83266c7 | 2015-10-29 18:43:20 | [diff] [blame] | 258 | if (last_reported_memory_usage_) |
| 259 | adjust_allocated_memory_cb_.Run(-last_reported_memory_usage_); |
| 260 | |
[email protected] | dd061e1 | 2014-05-06 19:21:22 | [diff] [blame] | 261 | compositor_task_runner_->DeleteSoon(FROM_HERE, compositor_); |
xhwang | ea8bb356 | 2015-06-08 21:18:37 | [diff] [blame] | 262 | |
| 263 | media_log_->AddEvent( |
| 264 | media_log_->CreateEvent(MediaLogEvent::WEBMEDIAPLAYER_DESTROYED)); |
[email protected] | ec9212f | 2008-12-18 21:40:36 | [diff] [blame] | 265 | } |
| 266 | |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame] | 267 | void WebMediaPlayerImpl::load(LoadType load_type, const blink::WebURL& url, |
[email protected] | 62e5e68 | 2013-03-07 23:53:24 | [diff] [blame] | 268 | CORSMode cors_mode) { |
[email protected] | 2a06ca6 | 2014-06-04 13:59:52 | [diff] [blame] | 269 | DVLOG(1) << __FUNCTION__ << "(" << load_type << ", " << url << ", " |
| 270 | << cors_mode << ")"; |
[email protected] | d726eddc | 2013-07-02 22:25:55 | [diff] [blame] | 271 | if (!defer_load_cb_.is_null()) { |
| 272 | defer_load_cb_.Run(base::Bind( |
[email protected] | ef8394c | 2013-08-21 20:26:30 | [diff] [blame] | 273 | &WebMediaPlayerImpl::DoLoad, AsWeakPtr(), load_type, url, cors_mode)); |
[email protected] | d726eddc | 2013-07-02 22:25:55 | [diff] [blame] | 274 | return; |
| 275 | } |
[email protected] | ef8394c | 2013-08-21 20:26:30 | [diff] [blame] | 276 | DoLoad(load_type, url, cors_mode); |
[email protected] | 62e5e68 | 2013-03-07 23:53:24 | [diff] [blame] | 277 | } |
| 278 | |
watk | dee516f | 2016-02-18 02:22:19 | [diff] [blame] | 279 | void WebMediaPlayerImpl::enteredFullscreen() { |
| 280 | fullscreen_ = true; |
| 281 | if (decoder_requires_restart_for_fullscreen_) |
| 282 | ScheduleRestart(); |
| 283 | } |
| 284 | |
| 285 | void WebMediaPlayerImpl::exitedFullscreen() { |
| 286 | fullscreen_ = false; |
| 287 | if (decoder_requires_restart_for_fullscreen_) |
| 288 | ScheduleRestart(); |
| 289 | } |
| 290 | |
[email protected] | ef8394c | 2013-08-21 20:26:30 | [diff] [blame] | 291 | void WebMediaPlayerImpl::DoLoad(LoadType load_type, |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame] | 292 | const blink::WebURL& url, |
[email protected] | d726eddc | 2013-07-02 22:25:55 | [diff] [blame] | 293 | CORSMode cors_mode) { |
hubbe | d82bed5 | 2015-12-15 23:07:16 | [diff] [blame] | 294 | DVLOG(1) << __FUNCTION__; |
acolwell | b403494 | 2014-08-28 15:42:43 | [diff] [blame] | 295 | DCHECK(main_task_runner_->BelongsToCurrentThread()); |
[email protected] | d726eddc | 2013-07-02 22:25:55 | [diff] [blame] | 296 | |
[email protected] | 62e5e68 | 2013-03-07 23:53:24 | [diff] [blame] | 297 | GURL gurl(url); |
xhwang | bffbf45 | 2016-04-01 05:26:45 | [diff] [blame^] | 298 | ReportMetrics(load_type, gurl, frame_->getSecurityOrigin()); |
[email protected] | 62e5e68 | 2013-03-07 23:53:24 | [diff] [blame] | 299 | |
[email protected] | 926f8fd | 2013-04-12 20:27:53 | [diff] [blame] | 300 | // Set subresource URL for crash reporting. |
| 301 | base::debug::SetCrashKeyValue("subresource_url", gurl.spec()); |
| 302 | |
[email protected] | ef8394c | 2013-08-21 20:26:30 | [diff] [blame] | 303 | load_type_ = load_type; |
| 304 | |
[email protected] | 62e5e68 | 2013-03-07 23:53:24 | [diff] [blame] | 305 | SetNetworkState(WebMediaPlayer::NetworkStateLoading); |
| 306 | SetReadyState(WebMediaPlayer::ReadyStateHaveNothing); |
kinuko | f19cde7 | 2015-12-18 23:15:25 | [diff] [blame] | 307 | media_log_->AddEvent(media_log_->CreateLoadEvent(url.string().utf8())); |
[email protected] | d726eddc | 2013-07-02 22:25:55 | [diff] [blame] | 308 | |
| 309 | // Media source pipelines can start immediately. |
[email protected] | ef8394c | 2013-08-21 20:26:30 | [diff] [blame] | 310 | if (load_type == LoadTypeMediaSource) { |
[email protected] | d726eddc | 2013-07-02 22:25:55 | [diff] [blame] | 311 | supports_save_ = false; |
[email protected] | ef8394c | 2013-08-21 20:26:30 | [diff] [blame] | 312 | StartPipeline(); |
hubbe | 5f0ad43b | 2015-12-14 20:57:26 | [diff] [blame] | 313 | } else { |
avayvod | e46d7bef | 2016-03-30 23:18:26 | [diff] [blame] | 314 | // TODO(hubbe): This experiment is temporary and should be removed once |
| 315 | // we have enough data to support the primacy of the new media cache. |
| 316 | // See http://crbug.com/514719 for details. |
| 317 | // Otherwise it's a regular request which requires resolving the URL first. |
| 318 | if (base::FeatureList::IsEnabled(kUseNewMediaCache)) { |
| 319 | // Remove this when MultiBufferDataSource becomes default. |
| 320 | LOG(WARNING) << "Using MultibufferDataSource"; |
| 321 | data_source_.reset(new MultibufferDataSource( |
| 322 | url, static_cast<UrlData::CORSMode>(cors_mode), main_task_runner_, |
| 323 | url_index_, frame_, media_log_.get(), &buffered_data_source_host_, |
| 324 | base::Bind(&WebMediaPlayerImpl::NotifyDownloading, AsWeakPtr()))); |
| 325 | } else { |
| 326 | data_source_.reset(new BufferedDataSource( |
| 327 | url, static_cast<BufferedResourceLoader::CORSMode>(cors_mode), |
| 328 | main_task_runner_, frame_, media_log_.get(), |
| 329 | &buffered_data_source_host_, |
| 330 | base::Bind(&WebMediaPlayerImpl::NotifyDownloading, AsWeakPtr()))); |
| 331 | } |
| 332 | data_source_->SetPreload(preload_); |
| 333 | data_source_->SetBufferingStrategy(buffering_strategy_); |
| 334 | data_source_->Initialize( |
| 335 | base::Bind(&WebMediaPlayerImpl::DataSourceInitialized, AsWeakPtr())); |
hubbe | 5f0ad43b | 2015-12-14 20:57:26 | [diff] [blame] | 336 | } |
hubbe | d5f3688 | 2016-01-15 22:40:37 | [diff] [blame] | 337 | |
| 338 | #if defined(OS_ANDROID) // WMPI_CAST |
dalecurtis | bb3eaac | 2016-01-27 21:10:25 | [diff] [blame] | 339 | cast_impl_.Initialize(url, frame_, delegate_id_); |
hubbe | d5f3688 | 2016-01-15 22:40:37 | [diff] [blame] | 340 | #endif |
[email protected] | 62e5e68 | 2013-03-07 23:53:24 | [diff] [blame] | 341 | } |
| 342 | |
[email protected] | 4e6be3f | 2009-05-07 02:24:44 | [diff] [blame] | 343 | void WebMediaPlayerImpl::play() { |
[email protected] | 2a06ca6 | 2014-06-04 13:59:52 | [diff] [blame] | 344 | DVLOG(1) << __FUNCTION__; |
acolwell | b403494 | 2014-08-28 15:42:43 | [diff] [blame] | 345 | DCHECK(main_task_runner_->BelongsToCurrentThread()); |
[email protected] | d43ed91 | 2009-02-03 04:52:53 | [diff] [blame] | 346 | |
hubbe | d5f3688 | 2016-01-15 22:40:37 | [diff] [blame] | 347 | #if defined(OS_ANDROID) // WMPI_CAST |
| 348 | if (isRemote()) { |
dalecurtis | 6e2716d | 2016-01-21 04:49:15 | [diff] [blame] | 349 | cast_impl_.play(); |
hubbe | d5f3688 | 2016-01-15 22:40:37 | [diff] [blame] | 350 | return; |
| 351 | } |
| 352 | #endif |
| 353 | |
dalecurtis | 0431cbf | 2016-03-12 01:19:43 | [diff] [blame] | 354 | const bool was_paused = paused_; |
[email protected] | 4948090 | 2009-07-14 20:23:43 | [diff] [blame] | 355 | paused_ = false; |
yoichio | 863bebf | 2016-03-04 07:56:58 | [diff] [blame] | 356 | pipeline_.SetPlaybackRate(playback_rate_); |
sandersd | 1c0bba0 | 2016-03-04 23:14:08 | [diff] [blame] | 357 | |
[email protected] | 039b754 | 2013-10-17 22:06:25 | [diff] [blame] | 358 | if (data_source_) |
| 359 | data_source_->MediaIsPlaying(); |
[email protected] | 090f731 | 2011-08-05 23:26:40 | [diff] [blame] | 360 | |
acolwell | 9e0840d | 2014-09-06 19:01:32 | [diff] [blame] | 361 | media_log_->AddEvent(media_log_->CreateEvent(MediaLogEvent::PLAY)); |
[email protected] | baff451 | 2011-10-19 18:21:07 | [diff] [blame] | 362 | |
dalecurtis | 0431cbf | 2016-03-12 01:19:43 | [diff] [blame] | 363 | if (playback_rate_ > 0 && was_paused) { |
yoichio | 863bebf | 2016-03-04 07:56:58 | [diff] [blame] | 364 | NotifyPlaybackStarted(); |
sandersd | 1c0bba0 | 2016-03-04 23:14:08 | [diff] [blame] | 365 | |
dalecurtis | 0431cbf | 2016-03-12 01:19:43 | [diff] [blame] | 366 | // Resume the player if allowed. We always call Resume() in case there is a |
| 367 | // pending suspend that should be aborted. If the pipeline is not suspended, |
| 368 | // Resume() will have no effect. |
| 369 | if (IsAutomaticResumeAllowed()) |
sandersd | 1c0bba0 | 2016-03-04 23:14:08 | [diff] [blame] | 370 | pipeline_controller_.Resume(); |
dalecurtis | 5bbc487e | 2016-02-27 04:15:05 | [diff] [blame] | 371 | } |
[email protected] | ec9212f | 2008-12-18 21:40:36 | [diff] [blame] | 372 | } |
| 373 | |
[email protected] | 4e6be3f | 2009-05-07 02:24:44 | [diff] [blame] | 374 | void WebMediaPlayerImpl::pause() { |
[email protected] | 2a06ca6 | 2014-06-04 13:59:52 | [diff] [blame] | 375 | DVLOG(1) << __FUNCTION__; |
acolwell | b403494 | 2014-08-28 15:42:43 | [diff] [blame] | 376 | DCHECK(main_task_runner_->BelongsToCurrentThread()); |
[email protected] | d43ed91 | 2009-02-03 04:52:53 | [diff] [blame] | 377 | |
dalecurtis | 6d269ed | 2014-09-11 21:18:13 | [diff] [blame] | 378 | const bool was_already_paused = paused_ || playback_rate_ == 0; |
[email protected] | 4948090 | 2009-07-14 20:23:43 | [diff] [blame] | 379 | paused_ = true; |
hubbe | d5f3688 | 2016-01-15 22:40:37 | [diff] [blame] | 380 | |
| 381 | #if defined(OS_ANDROID) // WMPI_CAST |
| 382 | if (isRemote()) { |
dalecurtis | 6e2716d | 2016-01-21 04:49:15 | [diff] [blame] | 383 | cast_impl_.pause(); |
hubbe | d5f3688 | 2016-01-15 22:40:37 | [diff] [blame] | 384 | return; |
| 385 | } |
| 386 | #endif |
| 387 | |
a.berwal | 338bf00 | 2015-04-22 11:14:50 | [diff] [blame] | 388 | pipeline_.SetPlaybackRate(0.0); |
sandersd | 1c0bba0 | 2016-03-04 23:14:08 | [diff] [blame] | 389 | |
| 390 | // pause() may be called after playback has ended and the HTMLMediaElement |
| 391 | // requires that currentTime() == duration() after ending. We want to ensure |
| 392 | // |paused_time_| matches currentTime() in this case or a future seek() may |
| 393 | // incorrectly discard what it thinks is a seek to the existing time. |
| 394 | paused_time_ = |
| 395 | ended_ ? pipeline_.GetMediaDuration() : pipeline_.GetMediaTime(); |
[email protected] | 090f731 | 2011-08-05 23:26:40 | [diff] [blame] | 396 | |
acolwell | 9e0840d | 2014-09-06 19:01:32 | [diff] [blame] | 397 | media_log_->AddEvent(media_log_->CreateEvent(MediaLogEvent::PAUSE)); |
[email protected] | baff451 | 2011-10-19 18:21:07 | [diff] [blame] | 398 | |
dalecurtis | bb3eaac | 2016-01-27 21:10:25 | [diff] [blame] | 399 | if (!was_already_paused) |
dalecurtis | 0f0097a | 2015-12-01 17:40:47 | [diff] [blame] | 400 | NotifyPlaybackPaused(); |
[email protected] | ec9212f | 2008-12-18 21:40:36 | [diff] [blame] | 401 | } |
| 402 | |
[email protected] | 574a1d6 | 2009-07-17 03:23:46 | [diff] [blame] | 403 | bool WebMediaPlayerImpl::supportsSave() const { |
acolwell | b403494 | 2014-08-28 15:42:43 | [diff] [blame] | 404 | DCHECK(main_task_runner_->BelongsToCurrentThread()); |
[email protected] | 132dd57c | 2012-08-10 23:24:34 | [diff] [blame] | 405 | return supports_save_; |
[email protected] | 574a1d6 | 2009-07-17 03:23:46 | [diff] [blame] | 406 | } |
| 407 | |
[email protected] | 39bdde3 | 2013-04-17 17:44:20 | [diff] [blame] | 408 | void WebMediaPlayerImpl::seek(double seconds) { |
xhwang | 12d8d04 | 2014-12-01 21:48:57 | [diff] [blame] | 409 | DVLOG(1) << __FUNCTION__ << "(" << seconds << "s)"; |
acolwell | b403494 | 2014-08-28 15:42:43 | [diff] [blame] | 410 | DCHECK(main_task_runner_->BelongsToCurrentThread()); |
sandersd | 1c0bba0 | 2016-03-04 23:14:08 | [diff] [blame] | 411 | DoSeek(base::TimeDelta::FromSecondsD(seconds), true); |
| 412 | } |
| 413 | |
| 414 | void WebMediaPlayerImpl::DoSeek(base::TimeDelta time, bool time_updated) { |
| 415 | DCHECK(main_task_runner_->BelongsToCurrentThread()); |
[email protected] | d43ed91 | 2009-02-03 04:52:53 | [diff] [blame] | 416 | |
scherkus | d2c745b | 2014-09-04 05:03:40 | [diff] [blame] | 417 | ended_ = false; |
| 418 | |
hubbe | d5f3688 | 2016-01-15 22:40:37 | [diff] [blame] | 419 | #if defined(OS_ANDROID) // WMPI_CAST |
| 420 | if (isRemote()) { |
sandersd | 1c0bba0 | 2016-03-04 23:14:08 | [diff] [blame] | 421 | cast_impl_.seek(time); |
hubbe | d5f3688 | 2016-01-15 22:40:37 | [diff] [blame] | 422 | return; |
| 423 | } |
| 424 | #endif |
| 425 | |
srirama.m | ccf67181 | 2015-01-08 11:59:13 | [diff] [blame] | 426 | ReadyState old_state = ready_state_; |
[email protected] | 1bb66680 | 2013-11-28 06:12:08 | [diff] [blame] | 427 | if (ready_state_ > WebMediaPlayer::ReadyStateHaveMetadata) |
| 428 | SetReadyState(WebMediaPlayer::ReadyStateHaveMetadata); |
| 429 | |
sandersd | 1c0bba0 | 2016-03-04 23:14:08 | [diff] [blame] | 430 | // When paused, we know exactly what the current time is and can elide seeks |
| 431 | // to it. However, there are two cases that are not elided: |
| 432 | // 1) When the pipeline state is not stable. |
| 433 | // In this case we just let |pipeline_controller_| decide what to do, as |
| 434 | // it has complete information. |
| 435 | // 2) For MSE. |
| 436 | // Because the buffers may have changed between seeks, MSE seeks are |
| 437 | // never elided. |
| 438 | if (paused_ && pipeline_controller_.IsStable() && paused_time_ == time && |
| 439 | !chunk_demuxer_) { |
| 440 | // If the ready state was high enough before, we can indicate that the seek |
| 441 | // completed just by restoring it. Otherwise we will just wait for the real |
| 442 | // ready state change to eventually happen. |
| 443 | if (old_state == ReadyStateHaveEnoughData) { |
srirama.m | 8f4a3756 | 2014-12-13 08:16:18 | [diff] [blame] | 444 | main_task_runner_->PostTask( |
srirama.m | 36ab268 | 2014-12-11 04:20:01 | [diff] [blame] | 445 | FROM_HERE, |
| 446 | base::Bind(&WebMediaPlayerImpl::OnPipelineBufferingStateChanged, |
srirama.m | 8f4a3756 | 2014-12-13 08:16:18 | [diff] [blame] | 447 | AsWeakPtr(), BUFFERING_HAVE_ENOUGH)); |
srirama.m | 36ab268 | 2014-12-11 04:20:01 | [diff] [blame] | 448 | } |
sandersd | 1c0bba0 | 2016-03-04 23:14:08 | [diff] [blame] | 449 | return; |
srirama.m | 36ab268 | 2014-12-11 04:20:01 | [diff] [blame] | 450 | } |
[email protected] | 44ff37c0 | 2009-10-24 01:03:03 | [diff] [blame] | 451 | |
[email protected] | b3766a2 | 2010-12-22 17:34:13 | [diff] [blame] | 452 | seeking_ = true; |
sandersd | 1c0bba0 | 2016-03-04 23:14:08 | [diff] [blame] | 453 | seek_time_ = time; |
| 454 | if (paused_) |
| 455 | paused_time_ = time; |
| 456 | pipeline_controller_.Seek(time, time_updated); |
[email protected] | b3766a2 | 2010-12-22 17:34:13 | [diff] [blame] | 457 | |
dalecurtis | 0431cbf | 2016-03-12 01:19:43 | [diff] [blame] | 458 | // Resume the pipeline if allowed so that the correct frame is displayed. We |
| 459 | // always call Resume() in case there is a pending suspend that should be |
| 460 | // aborted. If the pipeline is not suspended, Resume() will have no effect. |
| 461 | if (IsAutomaticResumeAllowed()) |
sandersd | 1c0bba0 | 2016-03-04 23:14:08 | [diff] [blame] | 462 | pipeline_controller_.Resume(); |
[email protected] | ec9212f | 2008-12-18 21:40:36 | [diff] [blame] | 463 | } |
| 464 | |
[email protected] | 39bdde3 | 2013-04-17 17:44:20 | [diff] [blame] | 465 | void WebMediaPlayerImpl::setRate(double rate) { |
[email protected] | 2a06ca6 | 2014-06-04 13:59:52 | [diff] [blame] | 466 | DVLOG(1) << __FUNCTION__ << "(" << rate << ")"; |
acolwell | b403494 | 2014-08-28 15:42:43 | [diff] [blame] | 467 | DCHECK(main_task_runner_->BelongsToCurrentThread()); |
[email protected] | d43ed91 | 2009-02-03 04:52:53 | [diff] [blame] | 468 | |
[email protected] | 378f0b7 | 2009-08-11 17:11:42 | [diff] [blame] | 469 | // TODO(kylep): Remove when support for negatives is added. Also, modify the |
| 470 | // following checks so rewind uses reasonable values also. |
[email protected] | 39bdde3 | 2013-04-17 17:44:20 | [diff] [blame] | 471 | if (rate < 0.0) |
[email protected] | 378f0b7 | 2009-08-11 17:11:42 | [diff] [blame] | 472 | return; |
| 473 | |
| 474 | // Limit rates to reasonable values by clamping. |
[email protected] | 39bdde3 | 2013-04-17 17:44:20 | [diff] [blame] | 475 | if (rate != 0.0) { |
[email protected] | 378f0b7 | 2009-08-11 17:11:42 | [diff] [blame] | 476 | if (rate < kMinRate) |
| 477 | rate = kMinRate; |
| 478 | else if (rate > kMaxRate) |
| 479 | rate = kMaxRate; |
dalecurtis | bb3eaac | 2016-01-27 21:10:25 | [diff] [blame] | 480 | if (playback_rate_ == 0 && !paused_) |
dalecurtis | 0f0097a | 2015-12-01 17:40:47 | [diff] [blame] | 481 | NotifyPlaybackStarted(); |
dalecurtis | bb3eaac | 2016-01-27 21:10:25 | [diff] [blame] | 482 | } else if (playback_rate_ != 0 && !paused_) { |
dalecurtis | 0f0097a | 2015-12-01 17:40:47 | [diff] [blame] | 483 | NotifyPlaybackPaused(); |
[email protected] | 378f0b7 | 2009-08-11 17:11:42 | [diff] [blame] | 484 | } |
| 485 | |
[email protected] | 4948090 | 2009-07-14 20:23:43 | [diff] [blame] | 486 | playback_rate_ = rate; |
| 487 | if (!paused_) { |
[email protected] | f6af759 | 2014-02-28 10:09:11 | [diff] [blame] | 488 | pipeline_.SetPlaybackRate(rate); |
[email protected] | 039b754 | 2013-10-17 22:06:25 | [diff] [blame] | 489 | if (data_source_) |
| 490 | data_source_->MediaPlaybackRateChanged(rate); |
[email protected] | 4948090 | 2009-07-14 20:23:43 | [diff] [blame] | 491 | } |
[email protected] | ec9212f | 2008-12-18 21:40:36 | [diff] [blame] | 492 | } |
| 493 | |
[email protected] | 39bdde3 | 2013-04-17 17:44:20 | [diff] [blame] | 494 | void WebMediaPlayerImpl::setVolume(double volume) { |
[email protected] | 2a06ca6 | 2014-06-04 13:59:52 | [diff] [blame] | 495 | DVLOG(1) << __FUNCTION__ << "(" << volume << ")"; |
acolwell | b403494 | 2014-08-28 15:42:43 | [diff] [blame] | 496 | DCHECK(main_task_runner_->BelongsToCurrentThread()); |
dalecurtis | bb3eaac | 2016-01-27 21:10:25 | [diff] [blame] | 497 | volume_ = volume; |
| 498 | pipeline_.SetVolume(volume_ * volume_multiplier_); |
[email protected] | ec9212f | 2008-12-18 21:40:36 | [diff] [blame] | 499 | } |
[email protected] | f0a51fb5 | 2009-03-05 12:46:38 | [diff] [blame] | 500 | |
guidou | c7babef | 2015-10-22 00:42:35 | [diff] [blame] | 501 | void WebMediaPlayerImpl::setSinkId( |
| 502 | const blink::WebString& sink_id, |
| 503 | const blink::WebSecurityOrigin& security_origin, |
| 504 | blink::WebSetSinkIdCallbacks* web_callback) { |
guidou | 69223ce | 2015-06-16 10:36:19 | [diff] [blame] | 505 | DCHECK(main_task_runner_->BelongsToCurrentThread()); |
guidou | 5754e61 | 2015-07-31 08:09:41 | [diff] [blame] | 506 | DVLOG(1) << __FUNCTION__; |
guidou | c7babef | 2015-10-22 00:42:35 | [diff] [blame] | 507 | |
guidou | 5754e61 | 2015-07-31 08:09:41 | [diff] [blame] | 508 | media::SwitchOutputDeviceCB callback = |
| 509 | media::ConvertToSwitchOutputDeviceCB(web_callback); |
guidou | c7babef | 2015-10-22 00:42:35 | [diff] [blame] | 510 | media_task_runner_->PostTask( |
| 511 | FROM_HERE, |
| 512 | base::Bind(&SetSinkIdOnMediaThread, audio_source_provider_, |
| 513 | sink_id.utf8(), static_cast<url::Origin>(security_origin), |
| 514 | callback)); |
guidou | 69223ce | 2015-06-16 10:36:19 | [diff] [blame] | 515 | } |
| 516 | |
danakj | 365175c | 2016-02-06 00:37:37 | [diff] [blame] | 517 | STATIC_ASSERT_ENUM(WebMediaPlayer::PreloadNone, BufferedDataSource::NONE); |
| 518 | STATIC_ASSERT_ENUM(WebMediaPlayer::PreloadMetaData, |
| 519 | BufferedDataSource::METADATA); |
| 520 | STATIC_ASSERT_ENUM(WebMediaPlayer::PreloadAuto, BufferedDataSource::AUTO); |
[email protected] | 23a8b1d8 | 2011-04-05 16:28:20 | [diff] [blame] | 521 | |
[email protected] | ef405f66b | 2012-04-18 02:39:55 | [diff] [blame] | 522 | void WebMediaPlayerImpl::setPreload(WebMediaPlayer::Preload preload) { |
[email protected] | 2a06ca6 | 2014-06-04 13:59:52 | [diff] [blame] | 523 | DVLOG(1) << __FUNCTION__ << "(" << preload << ")"; |
acolwell | b403494 | 2014-08-28 15:42:43 | [diff] [blame] | 524 | DCHECK(main_task_runner_->BelongsToCurrentThread()); |
[email protected] | 4e6be3f | 2009-05-07 02:24:44 | [diff] [blame] | 525 | |
acolwell | a5081a4 | 2014-08-28 23:42:52 | [diff] [blame] | 526 | preload_ = static_cast<BufferedDataSource::Preload>(preload); |
[email protected] | b49beeb | 2013-03-01 20:04:00 | [diff] [blame] | 527 | if (data_source_) |
[email protected] | 09c6022 | 2014-08-07 16:42:31 | [diff] [blame] | 528 | data_source_->SetPreload(preload_); |
[email protected] | 4e6be3f | 2009-05-07 02:24:44 | [diff] [blame] | 529 | } |
| 530 | |
danakj | 365175c | 2016-02-06 00:37:37 | [diff] [blame] | 531 | STATIC_ASSERT_ENUM(WebMediaPlayer::BufferingStrategy::Normal, |
| 532 | BufferedDataSource::BUFFERING_STRATEGY_NORMAL); |
| 533 | STATIC_ASSERT_ENUM(WebMediaPlayer::BufferingStrategy::Aggressive, |
| 534 | BufferedDataSource::BUFFERING_STRATEGY_AGGRESSIVE); |
sandersd | c6ab163a | 2015-12-12 03:56:13 | [diff] [blame] | 535 | |
| 536 | void WebMediaPlayerImpl::setBufferingStrategy( |
| 537 | WebMediaPlayer::BufferingStrategy buffering_strategy) { |
| 538 | DVLOG(1) << __FUNCTION__; |
| 539 | DCHECK(main_task_runner_->BelongsToCurrentThread()); |
| 540 | |
dalecurtis | 37fe586 | 2016-03-15 19:29:09 | [diff] [blame] | 541 | #if defined(OS_ANDROID) |
| 542 | // We disallow aggressive buffering on Android since it matches the behavior |
| 543 | // of the platform media player and may have data usage penalties. |
| 544 | // TODO(dalecurtis, hubbe): We should probably stop using "pause-and-buffer" |
| 545 | // everywhere. See http://crbug.com/594669 for more details. |
| 546 | buffering_strategy_ = BufferedDataSource::BUFFERING_STRATEGY_NORMAL; |
| 547 | #else |
sandersd | c6ab163a | 2015-12-12 03:56:13 | [diff] [blame] | 548 | buffering_strategy_ = |
| 549 | static_cast<BufferedDataSource::BufferingStrategy>(buffering_strategy); |
dalecurtis | 37fe586 | 2016-03-15 19:29:09 | [diff] [blame] | 550 | #endif |
| 551 | |
sandersd | c6ab163a | 2015-12-12 03:56:13 | [diff] [blame] | 552 | if (data_source_) |
| 553 | data_source_->SetBufferingStrategy(buffering_strategy_); |
| 554 | } |
| 555 | |
[email protected] | 4e6be3f | 2009-05-07 02:24:44 | [diff] [blame] | 556 | bool WebMediaPlayerImpl::hasVideo() const { |
acolwell | b403494 | 2014-08-28 15:42:43 | [diff] [blame] | 557 | DCHECK(main_task_runner_->BelongsToCurrentThread()); |
[email protected] | d43ed91 | 2009-02-03 04:52:53 | [diff] [blame] | 558 | |
[email protected] | b887777 | 2014-03-26 20:17:15 | [diff] [blame] | 559 | return pipeline_metadata_.has_video; |
[email protected] | d43ed91 | 2009-02-03 04:52:53 | [diff] [blame] | 560 | } |
| 561 | |
[email protected] | fc367af | 2009-08-14 23:06:35 | [diff] [blame] | 562 | bool WebMediaPlayerImpl::hasAudio() const { |
acolwell | b403494 | 2014-08-28 15:42:43 | [diff] [blame] | 563 | DCHECK(main_task_runner_->BelongsToCurrentThread()); |
[email protected] | fc367af | 2009-08-14 23:06:35 | [diff] [blame] | 564 | |
[email protected] | b887777 | 2014-03-26 20:17:15 | [diff] [blame] | 565 | return pipeline_metadata_.has_audio; |
[email protected] | fc367af | 2009-08-14 23:06:35 | [diff] [blame] | 566 | } |
| 567 | |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame] | 568 | blink::WebSize WebMediaPlayerImpl::naturalSize() const { |
acolwell | b403494 | 2014-08-28 15:42:43 | [diff] [blame] | 569 | DCHECK(main_task_runner_->BelongsToCurrentThread()); |
[email protected] | d43ed91 | 2009-02-03 04:52:53 | [diff] [blame] | 570 | |
[email protected] | b887777 | 2014-03-26 20:17:15 | [diff] [blame] | 571 | return blink::WebSize(pipeline_metadata_.natural_size); |
[email protected] | d43ed91 | 2009-02-03 04:52:53 | [diff] [blame] | 572 | } |
| 573 | |
[email protected] | 4e6be3f | 2009-05-07 02:24:44 | [diff] [blame] | 574 | bool WebMediaPlayerImpl::paused() const { |
acolwell | b403494 | 2014-08-28 15:42:43 | [diff] [blame] | 575 | DCHECK(main_task_runner_->BelongsToCurrentThread()); |
[email protected] | d43ed91 | 2009-02-03 04:52:53 | [diff] [blame] | 576 | |
hubbe | d5f3688 | 2016-01-15 22:40:37 | [diff] [blame] | 577 | #if defined(OS_ANDROID) // WMPI_CAST |
| 578 | if (isRemote()) |
| 579 | return cast_impl_.paused(); |
| 580 | #endif |
[email protected] | f6af759 | 2014-02-28 10:09:11 | [diff] [blame] | 581 | return pipeline_.GetPlaybackRate() == 0.0f; |
[email protected] | d43ed91 | 2009-02-03 04:52:53 | [diff] [blame] | 582 | } |
| 583 | |
[email protected] | 4e6be3f | 2009-05-07 02:24:44 | [diff] [blame] | 584 | bool WebMediaPlayerImpl::seeking() const { |
acolwell | b403494 | 2014-08-28 15:42:43 | [diff] [blame] | 585 | DCHECK(main_task_runner_->BelongsToCurrentThread()); |
[email protected] | d43ed91 | 2009-02-03 04:52:53 | [diff] [blame] | 586 | |
[email protected] | ef405f66b | 2012-04-18 02:39:55 | [diff] [blame] | 587 | if (ready_state_ == WebMediaPlayer::ReadyStateHaveNothing) |
[email protected] | 0acebfa | 2009-08-21 22:45:40 | [diff] [blame] | 588 | return false; |
[email protected] | 67cd505 | 2009-09-10 21:53:22 | [diff] [blame] | 589 | |
[email protected] | b3766a2 | 2010-12-22 17:34:13 | [diff] [blame] | 590 | return seeking_; |
[email protected] | ec9212f | 2008-12-18 21:40:36 | [diff] [blame] | 591 | } |
| 592 | |
[email protected] | 39bdde3 | 2013-04-17 17:44:20 | [diff] [blame] | 593 | double WebMediaPlayerImpl::duration() const { |
acolwell | b403494 | 2014-08-28 15:42:43 | [diff] [blame] | 594 | DCHECK(main_task_runner_->BelongsToCurrentThread()); |
[email protected] | 39bdde3 | 2013-04-17 17:44:20 | [diff] [blame] | 595 | |
| 596 | if (ready_state_ == WebMediaPlayer::ReadyStateHaveNothing) |
| 597 | return std::numeric_limits<double>::quiet_NaN(); |
| 598 | |
[email protected] | 39bdde3 | 2013-04-17 17:44:20 | [diff] [blame] | 599 | return GetPipelineDuration(); |
[email protected] | d43ed91 | 2009-02-03 04:52:53 | [diff] [blame] | 600 | } |
| 601 | |
[email protected] | db66d009 | 2014-04-16 07:15:12 | [diff] [blame] | 602 | double WebMediaPlayerImpl::timelineOffset() const { |
acolwell | b403494 | 2014-08-28 15:42:43 | [diff] [blame] | 603 | DCHECK(main_task_runner_->BelongsToCurrentThread()); |
[email protected] | db66d009 | 2014-04-16 07:15:12 | [diff] [blame] | 604 | |
| 605 | if (pipeline_metadata_.timeline_offset.is_null()) |
| 606 | return std::numeric_limits<double>::quiet_NaN(); |
| 607 | |
| 608 | return pipeline_metadata_.timeline_offset.ToJsTime(); |
| 609 | } |
| 610 | |
[email protected] | 39bdde3 | 2013-04-17 17:44:20 | [diff] [blame] | 611 | double WebMediaPlayerImpl::currentTime() const { |
acolwell | b403494 | 2014-08-28 15:42:43 | [diff] [blame] | 612 | DCHECK(main_task_runner_->BelongsToCurrentThread()); |
scherkus | d2c745b | 2014-09-04 05:03:40 | [diff] [blame] | 613 | DCHECK_NE(ready_state_, WebMediaPlayer::ReadyStateHaveNothing); |
| 614 | |
| 615 | // TODO(scherkus): Replace with an explicit ended signal to HTMLMediaElement, |
| 616 | // see http://crbug.com/409280 |
| 617 | if (ended_) |
| 618 | return duration(); |
| 619 | |
sandersd | 1c0bba0 | 2016-03-04 23:14:08 | [diff] [blame] | 620 | if (seeking()) |
| 621 | return seek_time_.InSecondsF(); |
wolenetz | 1b2ae7d | 2015-06-10 00:44:21 | [diff] [blame] | 622 | |
hubbe | d5f3688 | 2016-01-15 22:40:37 | [diff] [blame] | 623 | #if defined(OS_ANDROID) // WMPI_CAST |
sandersd | 1c0bba0 | 2016-03-04 23:14:08 | [diff] [blame] | 624 | if (isRemote()) |
hubbe | d5f3688 | 2016-01-15 22:40:37 | [diff] [blame] | 625 | return cast_impl_.currentTime(); |
hubbe | d5f3688 | 2016-01-15 22:40:37 | [diff] [blame] | 626 | #endif |
| 627 | |
sandersd | 1c0bba0 | 2016-03-04 23:14:08 | [diff] [blame] | 628 | if (paused_) |
hubbe | d5f3688 | 2016-01-15 22:40:37 | [diff] [blame] | 629 | return paused_time_.InSecondsF(); |
hubbe | d5f3688 | 2016-01-15 22:40:37 | [diff] [blame] | 630 | |
| 631 | return pipeline_.GetMediaTime().InSecondsF(); |
[email protected] | d43ed91 | 2009-02-03 04:52:53 | [diff] [blame] | 632 | } |
| 633 | |
danakj | 13afe036 | 2016-02-27 01:22:50 | [diff] [blame] | 634 | WebMediaPlayer::NetworkState WebMediaPlayerImpl::getNetworkState() const { |
acolwell | b403494 | 2014-08-28 15:42:43 | [diff] [blame] | 635 | DCHECK(main_task_runner_->BelongsToCurrentThread()); |
[email protected] | ddb1e5a | 2010-12-13 20:10:45 | [diff] [blame] | 636 | return network_state_; |
| 637 | } |
| 638 | |
danakj | 13afe036 | 2016-02-27 01:22:50 | [diff] [blame] | 639 | WebMediaPlayer::ReadyState WebMediaPlayerImpl::getReadyState() const { |
acolwell | b403494 | 2014-08-28 15:42:43 | [diff] [blame] | 640 | DCHECK(main_task_runner_->BelongsToCurrentThread()); |
[email protected] | ddb1e5a | 2010-12-13 20:10:45 | [diff] [blame] | 641 | return ready_state_; |
| 642 | } |
| 643 | |
[email protected] | 02022fc | 2014-05-16 00:05:31 | [diff] [blame] | 644 | blink::WebTimeRanges WebMediaPlayerImpl::buffered() const { |
acolwell | b403494 | 2014-08-28 15:42:43 | [diff] [blame] | 645 | DCHECK(main_task_runner_->BelongsToCurrentThread()); |
[email protected] | 779a832 | 2014-08-22 21:28:37 | [diff] [blame] | 646 | |
acolwell | 9e0840d | 2014-09-06 19:01:32 | [diff] [blame] | 647 | Ranges<base::TimeDelta> buffered_time_ranges = |
[email protected] | 02022fc | 2014-05-16 00:05:31 | [diff] [blame] | 648 | pipeline_.GetBufferedTimeRanges(); |
[email protected] | 779a832 | 2014-08-22 21:28:37 | [diff] [blame] | 649 | |
| 650 | const base::TimeDelta duration = pipeline_.GetMediaDuration(); |
acolwell | 9e0840d | 2014-09-06 19:01:32 | [diff] [blame] | 651 | if (duration != kInfiniteDuration()) { |
[email protected] | 779a832 | 2014-08-22 21:28:37 | [diff] [blame] | 652 | buffered_data_source_host_.AddBufferedTimeRanges( |
| 653 | &buffered_time_ranges, duration); |
| 654 | } |
[email protected] | 02022fc | 2014-05-16 00:05:31 | [diff] [blame] | 655 | return ConvertToWebTimeRanges(buffered_time_ranges); |
| 656 | } |
| 657 | |
philipj | b0e6f3f | 2014-09-30 09:51:53 | [diff] [blame] | 658 | blink::WebTimeRanges WebMediaPlayerImpl::seekable() const { |
acolwell | b403494 | 2014-08-28 15:42:43 | [diff] [blame] | 659 | DCHECK(main_task_runner_->BelongsToCurrentThread()); |
[email protected] | 39bdde3 | 2013-04-17 17:44:20 | [diff] [blame] | 660 | |
dalecurtis | 56359cb | 2014-10-28 00:06:29 | [diff] [blame] | 661 | if (ready_state_ < WebMediaPlayer::ReadyStateHaveMetadata) |
philipj | b0e6f3f | 2014-09-30 09:51:53 | [diff] [blame] | 662 | return blink::WebTimeRanges(); |
| 663 | |
dalecurtis | 56359cb | 2014-10-28 00:06:29 | [diff] [blame] | 664 | const double seekable_end = duration(); |
| 665 | |
| 666 | // Allow a special exception for seeks to zero for streaming sources with a |
| 667 | // finite duration; this allows looping to work. |
| 668 | const bool allow_seek_to_zero = data_source_ && data_source_->IsStreaming() && |
mateuszs | 3371ab0 | 2015-04-24 13:20:23 | [diff] [blame] | 669 | std::isfinite(seekable_end); |
dalecurtis | 56359cb | 2014-10-28 00:06:29 | [diff] [blame] | 670 | |
| 671 | // TODO(dalecurtis): Technically this allows seeking on media which return an |
| 672 | // infinite duration so long as DataSource::IsStreaming() is false. While not |
| 673 | // expected, disabling this breaks semi-live players, http://crbug.com/427412. |
| 674 | const blink::WebTimeRange seekable_range( |
| 675 | 0.0, allow_seek_to_zero ? 0.0 : seekable_end); |
philipj | b0e6f3f | 2014-09-30 09:51:53 | [diff] [blame] | 676 | return blink::WebTimeRanges(&seekable_range, 1); |
[email protected] | ec9212f | 2008-12-18 21:40:36 | [diff] [blame] | 677 | } |
| 678 | |
[email protected] | 5d2b3e4c | 2014-05-12 23:27:30 | [diff] [blame] | 679 | bool WebMediaPlayerImpl::didLoadingProgress() { |
acolwell | b403494 | 2014-08-28 15:42:43 | [diff] [blame] | 680 | DCHECK(main_task_runner_->BelongsToCurrentThread()); |
[email protected] | 6683e1b | 2014-04-10 01:45:38 | [diff] [blame] | 681 | bool pipeline_progress = pipeline_.DidLoadingProgress(); |
| 682 | bool data_progress = buffered_data_source_host_.DidLoadingProgress(); |
| 683 | return pipeline_progress || data_progress; |
[email protected] | d43ed91 | 2009-02-03 04:52:53 | [diff] [blame] | 684 | } |
| 685 | |
[email protected] | dd5c797 | 2014-08-21 15:00:37 | [diff] [blame] | 686 | void WebMediaPlayerImpl::paint(blink::WebCanvas* canvas, |
| 687 | const blink::WebRect& rect, |
[email protected] | dd5c797 | 2014-08-21 15:00:37 | [diff] [blame] | 688 | unsigned char alpha, |
| 689 | SkXfermode::Mode mode) { |
acolwell | b403494 | 2014-08-28 15:42:43 | [diff] [blame] | 690 | DCHECK(main_task_runner_->BelongsToCurrentThread()); |
[email protected] | dd061e1 | 2014-05-06 19:21:22 | [diff] [blame] | 691 | TRACE_EVENT0("media", "WebMediaPlayerImpl:paint"); |
[email protected] | 4e6be3f | 2009-05-07 02:24:44 | [diff] [blame] | 692 | |
xhwang | 8073945 | 2016-01-13 00:48:00 | [diff] [blame] | 693 | if (is_cdm_attached_) |
| 694 | return; |
| 695 | |
mcasas | f1236fc2 | 2015-05-29 22:38:56 | [diff] [blame] | 696 | scoped_refptr<VideoFrame> video_frame = GetCurrentFrameFromCompositor(); |
[email protected] | 0fe5d43b | 2014-01-24 23:32:45 | [diff] [blame] | 697 | |
[email protected] | b49beeb | 2013-03-01 20:04:00 | [diff] [blame] | 698 | gfx::Rect gfx_rect(rect); |
dongseong.hwang | 0c4e9d8 | 2015-01-08 20:11:13 | [diff] [blame] | 699 | Context3D context_3d; |
mcasas | 265bdbf8 | 2015-06-12 18:44:07 | [diff] [blame] | 700 | if (video_frame.get() && video_frame->HasTextures()) { |
mcasas | f1236fc2 | 2015-05-29 22:38:56 | [diff] [blame] | 701 | if (!context_3d_cb_.is_null()) |
dongseong.hwang | 0c4e9d8 | 2015-01-08 20:11:13 | [diff] [blame] | 702 | context_3d = context_3d_cb_.Run(); |
dongseong.hwang | 0c4e9d8 | 2015-01-08 20:11:13 | [diff] [blame] | 703 | // GPU Process crashed. |
| 704 | if (!context_3d.gl) |
| 705 | return; |
| 706 | } |
danakj | 795f173 | 2015-08-31 23:40:22 | [diff] [blame] | 707 | skcanvas_video_renderer_.Paint(video_frame, canvas, gfx::RectF(gfx_rect), |
| 708 | alpha, mode, pipeline_metadata_.video_rotation, |
| 709 | context_3d); |
[email protected] | ec9212f | 2008-12-18 21:40:36 | [diff] [blame] | 710 | } |
[email protected] | 5df5165 | 2009-01-17 00:03:00 | [diff] [blame] | 711 | |
[email protected] | 38259a7a8 | 2009-07-29 21:49:49 | [diff] [blame] | 712 | bool WebMediaPlayerImpl::hasSingleSecurityOrigin() const { |
[email protected] | b49beeb | 2013-03-01 20:04:00 | [diff] [blame] | 713 | if (data_source_) |
| 714 | return data_source_->HasSingleOrigin(); |
[email protected] | fcdb746 | 2009-10-21 21:05:11 | [diff] [blame] | 715 | return true; |
[email protected] | 38259a7a8 | 2009-07-29 21:49:49 | [diff] [blame] | 716 | } |
| 717 | |
[email protected] | 3fe2711 | 2012-06-07 04:00:01 | [diff] [blame] | 718 | bool WebMediaPlayerImpl::didPassCORSAccessCheck() const { |
[email protected] | b49beeb | 2013-03-01 20:04:00 | [diff] [blame] | 719 | if (data_source_) |
| 720 | return data_source_->DidPassCORSAccessCheck(); |
| 721 | return false; |
[email protected] | 3fe2711 | 2012-06-07 04:00:01 | [diff] [blame] | 722 | } |
| 723 | |
[email protected] | 39bdde3 | 2013-04-17 17:44:20 | [diff] [blame] | 724 | double WebMediaPlayerImpl::mediaTimeForTimeValue(double timeValue) const { |
qinmin | b4c3978 | 2015-08-10 18:43:24 | [diff] [blame] | 725 | return base::TimeDelta::FromSecondsD(timeValue).InSecondsF(); |
[email protected] | e06e16d8 | 2011-05-26 22:13:33 | [diff] [blame] | 726 | } |
| 727 | |
[email protected] | d82b18ae | 2011-03-23 21:28:59 | [diff] [blame] | 728 | unsigned WebMediaPlayerImpl::decodedFrameCount() const { |
acolwell | b403494 | 2014-08-28 15:42:43 | [diff] [blame] | 729 | DCHECK(main_task_runner_->BelongsToCurrentThread()); |
[email protected] | 4c51bc66 | 2011-02-16 02:03:16 | [diff] [blame] | 730 | |
acolwell | 9e0840d | 2014-09-06 19:01:32 | [diff] [blame] | 731 | PipelineStatistics stats = pipeline_.GetStatistics(); |
[email protected] | 4c51bc66 | 2011-02-16 02:03:16 | [diff] [blame] | 732 | return stats.video_frames_decoded; |
| 733 | } |
| 734 | |
[email protected] | d82b18ae | 2011-03-23 21:28:59 | [diff] [blame] | 735 | unsigned WebMediaPlayerImpl::droppedFrameCount() const { |
acolwell | b403494 | 2014-08-28 15:42:43 | [diff] [blame] | 736 | DCHECK(main_task_runner_->BelongsToCurrentThread()); |
[email protected] | 4c51bc66 | 2011-02-16 02:03:16 | [diff] [blame] | 737 | |
acolwell | 9e0840d | 2014-09-06 19:01:32 | [diff] [blame] | 738 | PipelineStatistics stats = pipeline_.GetStatistics(); |
[email protected] | dd061e1 | 2014-05-06 19:21:22 | [diff] [blame] | 739 | return stats.video_frames_dropped; |
[email protected] | 4c51bc66 | 2011-02-16 02:03:16 | [diff] [blame] | 740 | } |
| 741 | |
chakshu.a | 94326b7 | 2016-03-08 05:11:44 | [diff] [blame] | 742 | size_t WebMediaPlayerImpl::audioDecodedByteCount() const { |
acolwell | b403494 | 2014-08-28 15:42:43 | [diff] [blame] | 743 | DCHECK(main_task_runner_->BelongsToCurrentThread()); |
[email protected] | 4c51bc66 | 2011-02-16 02:03:16 | [diff] [blame] | 744 | |
acolwell | 9e0840d | 2014-09-06 19:01:32 | [diff] [blame] | 745 | PipelineStatistics stats = pipeline_.GetStatistics(); |
[email protected] | 4c51bc66 | 2011-02-16 02:03:16 | [diff] [blame] | 746 | return stats.audio_bytes_decoded; |
| 747 | } |
| 748 | |
chakshu.a | 94326b7 | 2016-03-08 05:11:44 | [diff] [blame] | 749 | size_t WebMediaPlayerImpl::videoDecodedByteCount() const { |
acolwell | b403494 | 2014-08-28 15:42:43 | [diff] [blame] | 750 | DCHECK(main_task_runner_->BelongsToCurrentThread()); |
[email protected] | 4c51bc66 | 2011-02-16 02:03:16 | [diff] [blame] | 751 | |
acolwell | 9e0840d | 2014-09-06 19:01:32 | [diff] [blame] | 752 | PipelineStatistics stats = pipeline_.GetStatistics(); |
[email protected] | 4c51bc66 | 2011-02-16 02:03:16 | [diff] [blame] | 753 | return stats.video_bytes_decoded; |
| 754 | } |
| 755 | |
[email protected] | 6523b24 | 2013-03-13 11:10:07 | [diff] [blame] | 756 | bool WebMediaPlayerImpl::copyVideoTextureToPlatformTexture( |
danakj | 46070b0 | 2016-03-28 21:54:11 | [diff] [blame] | 757 | gpu::gles2::GLES2Interface* gl, |
zmo | 57d577a | 2015-10-30 18:28:59 | [diff] [blame] | 758 | unsigned int texture, |
| 759 | unsigned int internal_format, |
| 760 | unsigned int type, |
| 761 | bool premultiply_alpha, |
| 762 | bool flip_y) { |
[email protected] | bfc05f2 | 2013-10-19 17:55:16 | [diff] [blame] | 763 | TRACE_EVENT0("media", "WebMediaPlayerImpl:copyVideoTextureToPlatformTexture"); |
| 764 | |
mcasas | f1236fc2 | 2015-05-29 22:38:56 | [diff] [blame] | 765 | scoped_refptr<VideoFrame> video_frame = GetCurrentFrameFromCompositor(); |
[email protected] | dd061e1 | 2014-05-06 19:21:22 | [diff] [blame] | 766 | |
mcasas | 265bdbf8 | 2015-06-12 18:44:07 | [diff] [blame] | 767 | if (!video_frame.get() || !video_frame->HasTextures() || |
dcastagna | 31a65d43 | 2015-06-11 19:01:00 | [diff] [blame] | 768 | media::VideoFrame::NumPlanes(video_frame->format()) != 1) { |
[email protected] | e56f88c7 | 2013-06-25 22:31:29 | [diff] [blame] | 769 | return false; |
dongseong.hwang | 0c4e9d8 | 2015-01-08 20:11:13 | [diff] [blame] | 770 | } |
[email protected] | df41e25 | 2014-02-03 23:39:50 | [diff] [blame] | 771 | |
dcastagna | 31a65d43 | 2015-06-11 19:01:00 | [diff] [blame] | 772 | SkCanvasVideoRenderer::CopyVideoFrameSingleTextureToGLTexture( |
zmo | 57d577a | 2015-10-30 18:28:59 | [diff] [blame] | 773 | gl, video_frame.get(), texture, internal_format, type, premultiply_alpha, |
| 774 | flip_y); |
[email protected] | e56f88c7 | 2013-06-25 22:31:29 | [diff] [blame] | 775 | return true; |
[email protected] | 6523b24 | 2013-03-13 11:10:07 | [diff] [blame] | 776 | } |
| 777 | |
[email protected] | 7bce183 | 2014-01-09 00:01:22 | [diff] [blame] | 778 | void WebMediaPlayerImpl::setContentDecryptionModule( |
[email protected] | 9ebc3b03f | 2014-08-13 04:01:23 | [diff] [blame] | 779 | blink::WebContentDecryptionModule* cdm, |
| 780 | blink::WebContentDecryptionModuleResult result) { |
acolwell | b403494 | 2014-08-28 15:42:43 | [diff] [blame] | 781 | DCHECK(main_task_runner_->BelongsToCurrentThread()); |
[email protected] | 9ebc3b03f | 2014-08-13 04:01:23 | [diff] [blame] | 782 | |
jrummell | 06f2707 | 2015-06-08 18:12:38 | [diff] [blame] | 783 | // Once the CDM is set it can't be cleared as there may be frames being |
| 784 | // decrypted on other threads. So fail this request. |
| 785 | // http://crbug.com/462365#c7. |
xhwang | 97de420 | 2014-11-25 08:44:01 | [diff] [blame] | 786 | if (!cdm) { |
| 787 | result.completeWithError( |
jrummell | 06f2707 | 2015-06-08 18:12:38 | [diff] [blame] | 788 | blink::WebContentDecryptionModuleExceptionInvalidStateError, 0, |
| 789 | "The existing MediaKeys object cannot be removed at this time."); |
xhwang | 97de420 | 2014-11-25 08:44:01 | [diff] [blame] | 790 | return; |
| 791 | } |
| 792 | |
jrummell | 89e61d8 | 2015-07-23 20:03:34 | [diff] [blame] | 793 | // Create a local copy of |result| to avoid problems with the callback |
| 794 | // getting passed to the media thread and causing |result| to be destructed |
jrummell | 4acbec91 | 2016-02-27 02:45:03 | [diff] [blame] | 795 | // on the wrong thread in some failure conditions. Blink should prevent |
| 796 | // multiple simultaneous calls. |
| 797 | DCHECK(!set_cdm_result_); |
jrummell | 89e61d8 | 2015-07-23 20:03:34 | [diff] [blame] | 798 | set_cdm_result_.reset(new blink::WebContentDecryptionModuleResult(result)); |
| 799 | |
| 800 | SetCdm(BIND_TO_RENDER_LOOP(&WebMediaPlayerImpl::OnCdmAttached), |
xhwang | 9bd8c73 | 2015-04-13 23:27:53 | [diff] [blame] | 801 | ToWebContentDecryptionModuleImpl(cdm)->GetCdmContext()); |
xhwang | 97de420 | 2014-11-25 08:44:01 | [diff] [blame] | 802 | } |
| 803 | |
xhwang | e8c4181a | 2014-12-06 08:10:01 | [diff] [blame] | 804 | void WebMediaPlayerImpl::OnEncryptedMediaInitData( |
jrummell | cf78967c | 2015-04-03 05:03:58 | [diff] [blame] | 805 | EmeInitDataType init_data_type, |
Avi Drissman | 97785ea | 2015-12-19 01:11:31 | [diff] [blame] | 806 | const std::vector<uint8_t>& init_data) { |
jrummell | cf78967c | 2015-04-03 05:03:58 | [diff] [blame] | 807 | DCHECK(init_data_type != EmeInitDataType::UNKNOWN); |
xhwang | bab66f5 | 2014-12-02 23:49:50 | [diff] [blame] | 808 | |
ddorwin | 301ccdb | 2016-02-25 02:39:17 | [diff] [blame] | 809 | // TODO(xhwang): Update this UMA name. https://crbug.com/589251 |
xhwang | bab66f5 | 2014-12-02 23:49:50 | [diff] [blame] | 810 | UMA_HISTOGRAM_COUNTS("Media.EME.NeedKey", 1); |
| 811 | |
srirama.m | 26f864d0 | 2015-07-14 05:21:46 | [diff] [blame] | 812 | encrypted_client_->encrypted( |
davidben | b50f00c | 2015-12-01 00:01:50 | [diff] [blame] | 813 | ConvertToWebInitDataType(init_data_type), init_data.data(), |
srirama.m | 26f864d0 | 2015-07-14 05:21:46 | [diff] [blame] | 814 | base::saturated_cast<unsigned int>(init_data.size())); |
xhwang | bab66f5 | 2014-12-02 23:49:50 | [diff] [blame] | 815 | } |
| 816 | |
servolk | 81e01e0 | 2016-03-05 03:29:15 | [diff] [blame] | 817 | void WebMediaPlayerImpl::OnFFmpegMediaTracksUpdated( |
| 818 | scoped_ptr<MediaTracks> tracks) { |
| 819 | // For MSE/chunk_demuxer case the media track updates are handled by |
| 820 | // WebSourceBufferImpl. |
| 821 | DCHECK(demuxer_.get()); |
| 822 | DCHECK(!chunk_demuxer_); |
servolk | ef1e5ef | 2016-03-25 04:55:26 | [diff] [blame] | 823 | |
| 824 | // Report the media track information to blink. |
| 825 | for (const auto& track : tracks->tracks()) { |
| 826 | if (track->type() == MediaTrack::Audio) { |
| 827 | auto track_id = client_->addAudioTrack( |
| 828 | blink::WebString::fromUTF8(track->id()), |
| 829 | blink::WebMediaPlayerClient::AudioTrackKindMain, |
| 830 | blink::WebString::fromUTF8(track->label()), |
| 831 | blink::WebString::fromUTF8(track->language()), |
| 832 | /*enabled*/ true); |
| 833 | (void)track_id; |
| 834 | } else if (track->type() == MediaTrack::Video) { |
| 835 | auto track_id = client_->addVideoTrack( |
| 836 | blink::WebString::fromUTF8(track->id()), |
| 837 | blink::WebMediaPlayerClient::VideoTrackKindMain, |
| 838 | blink::WebString::fromUTF8(track->label()), |
| 839 | blink::WebString::fromUTF8(track->language()), |
| 840 | /*selected*/ true); |
| 841 | (void)track_id; |
| 842 | } else { |
| 843 | // Text tracks are not supported through this code path yet. |
| 844 | NOTREACHED(); |
| 845 | } |
| 846 | } |
servolk | 81e01e0 | 2016-03-05 03:29:15 | [diff] [blame] | 847 | } |
| 848 | |
jrummell | 74fc4f94 | 2015-03-02 22:48:27 | [diff] [blame] | 849 | void WebMediaPlayerImpl::OnWaitingForDecryptionKey() { |
srirama.m | 26f864d0 | 2015-07-14 05:21:46 | [diff] [blame] | 850 | encrypted_client_->didBlockPlaybackWaitingForKey(); |
jrummell | 74fc4f94 | 2015-03-02 22:48:27 | [diff] [blame] | 851 | |
| 852 | // TODO(jrummell): didResumePlaybackBlockedForKey() should only be called |
| 853 | // when a key has been successfully added (e.g. OnSessionKeysChange() with |
| 854 | // |has_additional_usable_key| = true). http://crbug.com/461903 |
srirama.m | 26f864d0 | 2015-07-14 05:21:46 | [diff] [blame] | 855 | encrypted_client_->didResumePlaybackBlockedForKey(); |
jrummell | 74fc4f94 | 2015-03-02 22:48:27 | [diff] [blame] | 856 | } |
| 857 | |
xhwang | 9bd8c73 | 2015-04-13 23:27:53 | [diff] [blame] | 858 | void WebMediaPlayerImpl::SetCdm(const CdmAttachedCB& cdm_attached_cb, |
| 859 | CdmContext* cdm_context) { |
xhwang | 8073945 | 2016-01-13 00:48:00 | [diff] [blame] | 860 | if (!cdm_context) { |
| 861 | cdm_attached_cb.Run(false); |
| 862 | return; |
| 863 | } |
| 864 | |
jrummell | 87a2db5 | 2015-05-05 22:27:18 | [diff] [blame] | 865 | // If CDM initialization succeeded, tell the pipeline about it. |
xhwang | 8073945 | 2016-01-13 00:48:00 | [diff] [blame] | 866 | pipeline_.SetCdm(cdm_context, cdm_attached_cb); |
xhwang | 97de420 | 2014-11-25 08:44:01 | [diff] [blame] | 867 | } |
| 868 | |
jrummell | 89e61d8 | 2015-07-23 20:03:34 | [diff] [blame] | 869 | void WebMediaPlayerImpl::OnCdmAttached(bool success) { |
xhwang | 97de420 | 2014-11-25 08:44:01 | [diff] [blame] | 870 | if (success) { |
jrummell | 89e61d8 | 2015-07-23 20:03:34 | [diff] [blame] | 871 | set_cdm_result_->complete(); |
| 872 | set_cdm_result_.reset(); |
xhwang | 8073945 | 2016-01-13 00:48:00 | [diff] [blame] | 873 | is_cdm_attached_ = true; |
xhwang | 97de420 | 2014-11-25 08:44:01 | [diff] [blame] | 874 | return; |
| 875 | } |
| 876 | |
jrummell | 89e61d8 | 2015-07-23 20:03:34 | [diff] [blame] | 877 | set_cdm_result_->completeWithError( |
xhwang | 97de420 | 2014-11-25 08:44:01 | [diff] [blame] | 878 | blink::WebContentDecryptionModuleExceptionNotSupportedError, 0, |
| 879 | "Unable to set MediaKeys object"); |
jrummell | 89e61d8 | 2015-07-23 20:03:34 | [diff] [blame] | 880 | set_cdm_result_.reset(); |
[email protected] | 9ebc3b03f | 2014-08-13 04:01:23 | [diff] [blame] | 881 | } |
| 882 | |
sandersd | 1c0bba0 | 2016-03-04 23:14:08 | [diff] [blame] | 883 | void WebMediaPlayerImpl::OnPipelineSeeked(bool time_updated) { |
[email protected] | 5d11eff | 2011-09-15 00:06:06 | [diff] [blame] | 884 | seeking_ = false; |
wolenetz | 1b2ae7d | 2015-06-10 00:44:21 | [diff] [blame] | 885 | seek_time_ = base::TimeDelta(); |
hubbe | 5a2dec02 | 2016-03-17 01:14:23 | [diff] [blame] | 886 | if (paused_) { |
| 887 | #if defined(OS_ANDROID) // WMPI_CAST |
| 888 | if (isRemote()) { |
| 889 | paused_time_ = base::TimeDelta::FromSecondsD(cast_impl_.currentTime()); |
| 890 | } else { |
| 891 | paused_time_ = pipeline_.GetMediaTime(); |
| 892 | } |
| 893 | #else |
sandersd | 1c0bba0 | 2016-03-04 23:14:08 | [diff] [blame] | 894 | paused_time_ = pipeline_.GetMediaTime(); |
hubbe | 5a2dec02 | 2016-03-17 01:14:23 | [diff] [blame] | 895 | #endif |
| 896 | } |
sandersd | 1c0bba0 | 2016-03-04 23:14:08 | [diff] [blame] | 897 | if (time_updated) |
| 898 | should_notify_time_changed_ = true; |
[email protected] | 8931c41a | 2009-07-07 17:31:49 | [diff] [blame] | 899 | } |
| 900 | |
sandersd | 1c0bba0 | 2016-03-04 23:14:08 | [diff] [blame] | 901 | void WebMediaPlayerImpl::OnPipelineSuspended() { |
hubbe | d5f3688 | 2016-01-15 22:40:37 | [diff] [blame] | 902 | #if defined(OS_ANDROID) |
| 903 | if (isRemote()) { |
dalecurtis | 6b91661 | 2016-03-22 20:42:36 | [diff] [blame] | 904 | if (delegate_) |
| 905 | delegate_->PlayerGone(delegate_id_); |
hubbe | d5f3688 | 2016-01-15 22:40:37 | [diff] [blame] | 906 | scoped_refptr<VideoFrame> frame = cast_impl_.GetCastingBanner(); |
| 907 | if (frame) { |
| 908 | compositor_->PaintFrameUsingOldRenderingPath(frame); |
| 909 | } |
| 910 | } |
| 911 | #endif |
| 912 | |
dalecurtis | 3a7d38f4 | 2016-03-07 21:17:13 | [diff] [blame] | 913 | memory_usage_reporting_timer_.Stop(); |
| 914 | ReportMemoryUsage(); |
sandersd | 1c0bba0 | 2016-03-04 23:14:08 | [diff] [blame] | 915 | |
dalecurtis | 37fe586 | 2016-03-15 19:29:09 | [diff] [blame] | 916 | // If we're not in an aggressive buffering state, tell the data source we have |
| 917 | // enough data so that it may release the connection. |
| 918 | if (buffering_strategy_ != |
| 919 | BufferedDataSource::BUFFERING_STRATEGY_AGGRESSIVE) { |
liberato | 3f9f32b | 2016-03-16 16:54:51 | [diff] [blame] | 920 | if (data_source_) |
| 921 | data_source_->OnBufferingHaveEnough(true); |
dalecurtis | 37fe586 | 2016-03-15 19:29:09 | [diff] [blame] | 922 | } |
| 923 | |
sandersd | 1c0bba0 | 2016-03-04 23:14:08 | [diff] [blame] | 924 | if (pending_suspend_resume_cycle_) { |
watk | dee516f | 2016-02-18 02:22:19 | [diff] [blame] | 925 | pending_suspend_resume_cycle_ = false; |
sandersd | 1c0bba0 | 2016-03-04 23:14:08 | [diff] [blame] | 926 | pipeline_controller_.Resume(); |
sandersd | 1e49fb6 | 2015-12-12 01:18:06 | [diff] [blame] | 927 | return; |
| 928 | } |
| 929 | } |
| 930 | |
sandersd | 1c0bba0 | 2016-03-04 23:14:08 | [diff] [blame] | 931 | void WebMediaPlayerImpl::OnPipelineResumed() { |
dalecurtis | 0431cbf | 2016-03-12 01:19:43 | [diff] [blame] | 932 | if (playback_rate_ > 0 && !paused_) { |
sandersd | 1c0bba0 | 2016-03-04 23:14:08 | [diff] [blame] | 933 | NotifyPlaybackStarted(); |
dalecurtis | 0431cbf | 2016-03-12 01:19:43 | [diff] [blame] | 934 | } else if (!playback_rate_ || paused_ || ended_) { |
| 935 | // Resend our paused notification so the pipeline is considered for idle |
| 936 | // resource reclamation; duplicate pause notifications are ignored. |
| 937 | NotifyPlaybackPaused(); |
| 938 | } |
sandersd | 1c0bba0 | 2016-03-04 23:14:08 | [diff] [blame] | 939 | } |
| 940 | |
[email protected] | 6954fe1 | 2013-01-03 03:22:32 | [diff] [blame] | 941 | void WebMediaPlayerImpl::OnPipelineEnded() { |
[email protected] | 2a06ca6 | 2014-06-04 13:59:52 | [diff] [blame] | 942 | DVLOG(1) << __FUNCTION__; |
acolwell | b403494 | 2014-08-28 15:42:43 | [diff] [blame] | 943 | DCHECK(main_task_runner_->BelongsToCurrentThread()); |
scherkus | d2c745b | 2014-09-04 05:03:40 | [diff] [blame] | 944 | |
sandersd | 1c0bba0 | 2016-03-04 23:14:08 | [diff] [blame] | 945 | // Ignore state changes until we've completed all outstanding operations. |
| 946 | if (!pipeline_controller_.IsStable()) |
scherkus | d2c745b | 2014-09-04 05:03:40 | [diff] [blame] | 947 | return; |
| 948 | |
| 949 | ended_ = true; |
[email protected] | ce70c98 | 2013-12-20 17:04:32 | [diff] [blame] | 950 | client_->timeChanged(); |
[email protected] | 57653784 | 2009-08-12 23:52:05 | [diff] [blame] | 951 | } |
| 952 | |
[email protected] | a9590c2 | 2011-03-16 16:57:02 | [diff] [blame] | 953 | void WebMediaPlayerImpl::OnPipelineError(PipelineStatus error) { |
hubbe | d82bed5 | 2015-12-15 23:07:16 | [diff] [blame] | 954 | DVLOG(1) << __FUNCTION__; |
acolwell | b403494 | 2014-08-28 15:42:43 | [diff] [blame] | 955 | DCHECK(main_task_runner_->BelongsToCurrentThread()); |
acolwell | 9e0840d | 2014-09-06 19:01:32 | [diff] [blame] | 956 | DCHECK_NE(error, PIPELINE_OK); |
[email protected] | a8e2cb8 | 2012-08-17 00:02:39 | [diff] [blame] | 957 | |
dalecurtis | 2ff781da | 2016-03-03 01:52:13 | [diff] [blame] | 958 | if (suppress_destruction_errors_) |
| 959 | return; |
| 960 | |
dalecurtis | 60030663 | 2016-03-19 00:28:34 | [diff] [blame] | 961 | // Release the delegate for player errors; this drops the media session and |
| 962 | // avoids idle suspension from ticking. |
| 963 | if (delegate_) |
| 964 | delegate_->PlayerGone(delegate_id_); |
| 965 | |
dalecurtis | 6e3901e | 2016-03-16 20:51:08 | [diff] [blame] | 966 | #if defined(OS_ANDROID) |
| 967 | // For 10% of pipeline decode failures log the playback URL. The URL is set |
| 968 | // as the crash-key 'subresource_url' during DoLoad(). |
| 969 | // |
| 970 | // TODO(dalecurtis): This is temporary to track down higher than average |
| 971 | // decode failure rates for video-only content. See http://crbug.com/595076. |
| 972 | if (base::RandDouble() <= 0.1 && error == PIPELINE_ERROR_DECODE) |
| 973 | base::debug::DumpWithoutCrashing(); |
| 974 | #endif |
| 975 | |
dalecurtis | 2ff781da | 2016-03-03 01:52:13 | [diff] [blame] | 976 | media_log_->AddEvent(media_log_->CreatePipelineErrorEvent(error)); |
| 977 | |
[email protected] | a8e2cb8 | 2012-08-17 00:02:39 | [diff] [blame] | 978 | if (ready_state_ == WebMediaPlayer::ReadyStateHaveNothing) { |
| 979 | // Any error that occurs before reaching ReadyStateHaveMetadata should |
| 980 | // be considered a format error. |
| 981 | SetNetworkState(WebMediaPlayer::NetworkStateFormatError); |
[email protected] | a8e2cb8 | 2012-08-17 00:02:39 | [diff] [blame] | 982 | return; |
| 983 | } |
| 984 | |
[email protected] | be57ee5 | 2013-05-28 22:27:27 | [diff] [blame] | 985 | SetNetworkState(PipelineErrorToNetworkState(error)); |
[email protected] | db190487d | 2009-07-30 18:51:52 | [diff] [blame] | 986 | } |
| 987 | |
[email protected] | b887777 | 2014-03-26 20:17:15 | [diff] [blame] | 988 | void WebMediaPlayerImpl::OnPipelineMetadata( |
acolwell | 9e0840d | 2014-09-06 19:01:32 | [diff] [blame] | 989 | PipelineMetadata metadata) { |
[email protected] | 2a06ca6 | 2014-06-04 13:59:52 | [diff] [blame] | 990 | DVLOG(1) << __FUNCTION__; |
[email protected] | a8e2cb8 | 2012-08-17 00:02:39 | [diff] [blame] | 991 | |
[email protected] | b887777 | 2014-03-26 20:17:15 | [diff] [blame] | 992 | pipeline_metadata_ = metadata; |
[email protected] | 739847c0 | 2014-01-16 00:12:25 | [diff] [blame] | 993 | |
dalecurtis | 849cf4b2 | 2015-03-27 18:35:45 | [diff] [blame] | 994 | UMA_HISTOGRAM_ENUMERATION("Media.VideoRotation", metadata.video_rotation, |
acolwell | 9e0840d | 2014-09-06 19:01:32 | [diff] [blame] | 995 | VIDEO_ROTATION_MAX + 1); |
[email protected] | b887777 | 2014-03-26 20:17:15 | [diff] [blame] | 996 | SetReadyState(WebMediaPlayer::ReadyStateHaveMetadata); |
[email protected] | 21c3f750 | 2013-03-23 03:29:51 | [diff] [blame] | 997 | |
[email protected] | b887777 | 2014-03-26 20:17:15 | [diff] [blame] | 998 | if (hasVideo()) { |
| 999 | DCHECK(!video_weblayer_); |
loyso | 0940d41 | 2016-03-14 01:30:31 | [diff] [blame] | 1000 | scoped_refptr<cc::VideoLayer> layer = |
| 1001 | cc::VideoLayer::Create(compositor_, pipeline_metadata_.video_rotation); |
[email protected] | f78c3e8 | 2014-08-08 01:24:47 | [diff] [blame] | 1002 | |
acolwell | 9e0840d | 2014-09-06 19:01:32 | [diff] [blame] | 1003 | if (pipeline_metadata_.video_rotation == VIDEO_ROTATION_90 || |
| 1004 | pipeline_metadata_.video_rotation == VIDEO_ROTATION_270) { |
[email protected] | f78c3e8 | 2014-08-08 01:24:47 | [diff] [blame] | 1005 | gfx::Size size = pipeline_metadata_.natural_size; |
| 1006 | pipeline_metadata_.natural_size = gfx::Size(size.height(), size.width()); |
| 1007 | } |
| 1008 | |
[email protected] | 3856462 | 2014-08-19 02:47:18 | [diff] [blame] | 1009 | video_weblayer_.reset(new cc_blink::WebLayerImpl(layer)); |
jbauman | 952274d | 2015-09-10 23:23:36 | [diff] [blame] | 1010 | video_weblayer_->layer()->SetContentsOpaque(opaque_); |
| 1011 | video_weblayer_->SetContentsOpaqueIsFixed(true); |
[email protected] | a7c4f58 | 2014-04-16 18:44:49 | [diff] [blame] | 1012 | client_->setWebLayer(video_weblayer_.get()); |
[email protected] | a8e2cb8 | 2012-08-17 00:02:39 | [diff] [blame] | 1013 | } |
dalecurtis | 8e4dc68 | 2016-03-15 02:30:30 | [diff] [blame] | 1014 | |
| 1015 | // Tell the delegate we can now be safely suspended due to inactivity if a |
| 1016 | // subsequent play event does not occur. |
| 1017 | if (paused_) |
| 1018 | NotifyPlaybackPaused(); |
sandersd | 520b46bd | 2016-03-21 21:18:44 | [diff] [blame] | 1019 | |
| 1020 | // If the frame is hidden, it may be time to suspend playback. |
| 1021 | if (delegate_ && delegate_->IsHidden()) |
| 1022 | OnHidden(); |
[email protected] | a8e2cb8 | 2012-08-17 00:02:39 | [diff] [blame] | 1023 | } |
| 1024 | |
[email protected] | ba7d5f9 | 2014-06-24 05:37:40 | [diff] [blame] | 1025 | void WebMediaPlayerImpl::OnPipelineBufferingStateChanged( |
acolwell | 9e0840d | 2014-09-06 19:01:32 | [diff] [blame] | 1026 | BufferingState buffering_state) { |
[email protected] | ba7d5f9 | 2014-06-24 05:37:40 | [diff] [blame] | 1027 | DVLOG(1) << __FUNCTION__ << "(" << buffering_state << ")"; |
[email protected] | b887777 | 2014-03-26 20:17:15 | [diff] [blame] | 1028 | |
sandersd | 1c0bba0 | 2016-03-04 23:14:08 | [diff] [blame] | 1029 | // Ignore buffering state changes until we've completed all outstanding |
| 1030 | // operations. |
| 1031 | if (!pipeline_controller_.IsStable()) |
[email protected] | ba7d5f9 | 2014-06-24 05:37:40 | [diff] [blame] | 1032 | return; |
[email protected] | b887777 | 2014-03-26 20:17:15 | [diff] [blame] | 1033 | |
[email protected] | ba7d5f9 | 2014-06-24 05:37:40 | [diff] [blame] | 1034 | // TODO(scherkus): Handle other buffering states when Pipeline starts using |
| 1035 | // them and translate them ready state changes http://crbug.com/144683 |
acolwell | 9e0840d | 2014-09-06 19:01:32 | [diff] [blame] | 1036 | DCHECK_EQ(buffering_state, BUFFERING_HAVE_ENOUGH); |
[email protected] | ba7d5f9 | 2014-06-24 05:37:40 | [diff] [blame] | 1037 | SetReadyState(WebMediaPlayer::ReadyStateHaveEnoughData); |
| 1038 | |
dalecurtis | 849cf4b2 | 2015-03-27 18:35:45 | [diff] [blame] | 1039 | // Let the DataSource know we have enough data. It may use this information to |
| 1040 | // release unused network connections. |
| 1041 | if (data_source_) |
dalecurtis | 37fe586 | 2016-03-15 19:29:09 | [diff] [blame] | 1042 | data_source_->OnBufferingHaveEnough(false); |
dalecurtis | 849cf4b2 | 2015-03-27 18:35:45 | [diff] [blame] | 1043 | |
[email protected] | ba7d5f9 | 2014-06-24 05:37:40 | [diff] [blame] | 1044 | // Blink expects a timeChanged() in response to a seek(). |
| 1045 | if (should_notify_time_changed_) |
| 1046 | client_->timeChanged(); |
dalecurtis | 0f0097a | 2015-12-01 17:40:47 | [diff] [blame] | 1047 | |
| 1048 | // Once we have enough, start reporting the total memory usage. We'll also |
| 1049 | // report once playback starts. |
| 1050 | ReportMemoryUsage(); |
[email protected] | b887777 | 2014-03-26 20:17:15 | [diff] [blame] | 1051 | } |
| 1052 | |
[email protected] | ef8394c | 2013-08-21 20:26:30 | [diff] [blame] | 1053 | void WebMediaPlayerImpl::OnDemuxerOpened() { |
acolwell | b403494 | 2014-08-28 15:42:43 | [diff] [blame] | 1054 | DCHECK(main_task_runner_->BelongsToCurrentThread()); |
wolenetz | 1fb319d | 2015-07-14 17:49:04 | [diff] [blame] | 1055 | client_->mediaSourceOpened( |
| 1056 | new WebMediaSourceImpl(chunk_demuxer_, media_log_)); |
[email protected] | 81bb332 | 2011-07-21 15:55:50 | [diff] [blame] | 1057 | } |
| 1058 | |
[email protected] | 8a56106 | 2013-11-22 01:19:31 | [diff] [blame] | 1059 | void WebMediaPlayerImpl::OnAddTextTrack( |
acolwell | 9e0840d | 2014-09-06 19:01:32 | [diff] [blame] | 1060 | const TextTrackConfig& config, |
| 1061 | const AddTextTrackDoneCB& done_cb) { |
acolwell | b403494 | 2014-08-28 15:42:43 | [diff] [blame] | 1062 | DCHECK(main_task_runner_->BelongsToCurrentThread()); |
[email protected] | 7153772 | 2013-05-23 06:47:53 | [diff] [blame] | 1063 | |
[email protected] | 8a56106 | 2013-11-22 01:19:31 | [diff] [blame] | 1064 | const WebInbandTextTrackImpl::Kind web_kind = |
| 1065 | static_cast<WebInbandTextTrackImpl::Kind>(config.kind()); |
| 1066 | const blink::WebString web_label = |
| 1067 | blink::WebString::fromUTF8(config.label()); |
| 1068 | const blink::WebString web_language = |
| 1069 | blink::WebString::fromUTF8(config.language()); |
[email protected] | 427ff10 | 2013-11-26 23:45:40 | [diff] [blame] | 1070 | const blink::WebString web_id = |
| 1071 | blink::WebString::fromUTF8(config.id()); |
[email protected] | 7153772 | 2013-05-23 06:47:53 | [diff] [blame] | 1072 | |
[email protected] | 8a56106 | 2013-11-22 01:19:31 | [diff] [blame] | 1073 | scoped_ptr<WebInbandTextTrackImpl> web_inband_text_track( |
henriks | 9cce5fa | 2014-12-12 09:35:30 | [diff] [blame] | 1074 | new WebInbandTextTrackImpl(web_kind, web_label, web_language, web_id)); |
[email protected] | 8a56106 | 2013-11-22 01:19:31 | [diff] [blame] | 1075 | |
servolk | 92333c0e | 2016-03-30 17:13:46 | [diff] [blame] | 1076 | scoped_ptr<media::TextTrack> text_track(new TextTrackImpl( |
dcheng | 652f5ff | 2015-12-27 08:54:00 | [diff] [blame] | 1077 | main_task_runner_, client_, std::move(web_inband_text_track))); |
[email protected] | 8a56106 | 2013-11-22 01:19:31 | [diff] [blame] | 1078 | |
dcheng | 652f5ff | 2015-12-27 08:54:00 | [diff] [blame] | 1079 | done_cb.Run(std::move(text_track)); |
[email protected] | 7153772 | 2013-05-23 06:47:53 | [diff] [blame] | 1080 | } |
| 1081 | |
dalecurtis | 0431cbf | 2016-03-12 01:19:43 | [diff] [blame] | 1082 | void WebMediaPlayerImpl::OnHidden() { |
sandersd | 1e49fb6 | 2015-12-12 01:18:06 | [diff] [blame] | 1083 | DCHECK(main_task_runner_->BelongsToCurrentThread()); |
dalecurtis | 0431cbf | 2016-03-12 01:19:43 | [diff] [blame] | 1084 | if (!IsSuspendUponHiddenEnabled()) |
sandersd | 1e49fb6 | 2015-12-12 01:18:06 | [diff] [blame] | 1085 | return; |
sandersd | 1e49fb6 | 2015-12-12 01:18:06 | [diff] [blame] | 1086 | |
dalecurtis | 0431cbf | 2016-03-12 01:19:43 | [diff] [blame] | 1087 | #if defined(OS_ANDROID) // WMPI_CAST |
hubbe | d5f3688 | 2016-01-15 22:40:37 | [diff] [blame] | 1088 | // If we're remote, the pipeline should already be suspended. |
| 1089 | if (isRemote()) |
| 1090 | return; |
| 1091 | #endif |
| 1092 | |
sandersd | 520b46bd | 2016-03-21 21:18:44 | [diff] [blame] | 1093 | // Don't suspend before metadata is available, as we don't know if there is a |
| 1094 | // video track yet. |
| 1095 | if (ready_state_ < WebMediaPlayer::ReadyStateHaveMetadata) |
| 1096 | return; |
| 1097 | |
dalecurtis | 0431cbf | 2016-03-12 01:19:43 | [diff] [blame] | 1098 | // Don't suspend players which only have audio and have not completed |
| 1099 | // playback. The user can still control these players via the MediaSession UI. |
| 1100 | // If the player has never started playback, OnSuspendRequested() will handle |
| 1101 | // release of any idle resources. |
| 1102 | if (!hasVideo() && !paused_ && !ended_) |
| 1103 | return; |
| 1104 | |
dalecurtis | 37fe586 | 2016-03-15 19:29:09 | [diff] [blame] | 1105 | // Always reset the buffering strategy to normal when suspending for hidden to |
| 1106 | // prevent an idle network connection from lingering. |
| 1107 | setBufferingStrategy(WebMediaPlayer::BufferingStrategy::Normal); |
dalecurtis | 0431cbf | 2016-03-12 01:19:43 | [diff] [blame] | 1108 | pipeline_controller_.Suspend(); |
watk | 01dc013 | 2016-03-23 23:10:40 | [diff] [blame] | 1109 | // If we're in the middle of a suspend/resume cycle we no longer want to |
| 1110 | // resume when the suspend completes. |
| 1111 | pending_suspend_resume_cycle_ = false; |
dalecurtis | 0431cbf | 2016-03-12 01:19:43 | [diff] [blame] | 1112 | if (delegate_) |
| 1113 | delegate_->PlayerGone(delegate_id_); |
sandersd | 1e49fb6 | 2015-12-12 01:18:06 | [diff] [blame] | 1114 | } |
| 1115 | |
| 1116 | void WebMediaPlayerImpl::OnShown() { |
| 1117 | DCHECK(main_task_runner_->BelongsToCurrentThread()); |
dalecurtis | 0431cbf | 2016-03-12 01:19:43 | [diff] [blame] | 1118 | if (!IsSuspendUponHiddenEnabled()) |
sandersd | 1e49fb6 | 2015-12-12 01:18:06 | [diff] [blame] | 1119 | return; |
sandersd | 1e49fb6 | 2015-12-12 01:18:06 | [diff] [blame] | 1120 | |
dalecurtis | 0431cbf | 2016-03-12 01:19:43 | [diff] [blame] | 1121 | #if defined(OS_ANDROID) // WMPI_CAST |
hubbe | d5f3688 | 2016-01-15 22:40:37 | [diff] [blame] | 1122 | // If we're remote, the pipeline should stay suspended. |
| 1123 | if (isRemote()) |
| 1124 | return; |
| 1125 | #endif |
| 1126 | |
sandersd | 520b46bd | 2016-03-21 21:18:44 | [diff] [blame] | 1127 | // If we do not yet have metadata, the only way we could have been suspended |
| 1128 | // is by a OnSuspendRequested() with |must_suspend| set. In that case we need |
| 1129 | // to resume, otherwise playback will be broken. |
| 1130 | // |
| 1131 | // Otherwise, resume if we should be playing. |
| 1132 | if (ready_state_ < WebMediaPlayer::ReadyStateHaveMetadata || |
| 1133 | (!ended_ && !paused_)) { |
sandersd | 1c0bba0 | 2016-03-04 23:14:08 | [diff] [blame] | 1134 | pipeline_controller_.Resume(); |
sandersd | 520b46bd | 2016-03-21 21:18:44 | [diff] [blame] | 1135 | } |
sandersd | 1e49fb6 | 2015-12-12 01:18:06 | [diff] [blame] | 1136 | } |
| 1137 | |
dalecurtis | 0431cbf | 2016-03-12 01:19:43 | [diff] [blame] | 1138 | void WebMediaPlayerImpl::OnSuspendRequested(bool must_suspend) { |
| 1139 | DCHECK(main_task_runner_->BelongsToCurrentThread()); |
| 1140 | |
| 1141 | #if defined(OS_ANDROID) // WMPI_CAST |
| 1142 | // If we're remote, the pipeline should already be suspended. |
| 1143 | if (isRemote()) |
| 1144 | return; |
| 1145 | #endif |
| 1146 | |
dalecurtis | 8413f9ef | 2016-03-17 19:23:33 | [diff] [blame] | 1147 | #if defined(OS_MACOSX) |
| 1148 | // TODO(sandersd): Idle suspend is disabled on OSX since hardware decoded |
| 1149 | // frames are owned by the video decoder in the GPU process. A mechanism for |
| 1150 | // detaching ownership from the decoder is needed. http://crbug.com/595716. |
| 1151 | return; |
| 1152 | #else |
dalecurtis | 0431cbf | 2016-03-12 01:19:43 | [diff] [blame] | 1153 | // Suspend should never be requested unless required or we're already in an |
| 1154 | // idle state (paused or ended). |
| 1155 | DCHECK(must_suspend || paused_ || ended_); |
| 1156 | |
| 1157 | // Always suspend, but only notify the delegate if we must; this allows any |
| 1158 | // exposed UI for player controls to continue to function even though the |
| 1159 | // player has now been suspended. |
| 1160 | pipeline_controller_.Suspend(); |
| 1161 | if (must_suspend && delegate_) |
| 1162 | delegate_->PlayerGone(delegate_id_); |
dalecurtis | 8413f9ef | 2016-03-17 19:23:33 | [diff] [blame] | 1163 | #endif |
dalecurtis | 0431cbf | 2016-03-12 01:19:43 | [diff] [blame] | 1164 | } |
| 1165 | |
dalecurtis | bb3eaac | 2016-01-27 21:10:25 | [diff] [blame] | 1166 | void WebMediaPlayerImpl::OnPlay() { |
| 1167 | play(); |
| 1168 | client_->playbackStateChanged(); |
| 1169 | } |
| 1170 | |
| 1171 | void WebMediaPlayerImpl::OnPause() { |
| 1172 | pause(); |
| 1173 | client_->playbackStateChanged(); |
| 1174 | } |
| 1175 | |
| 1176 | void WebMediaPlayerImpl::OnVolumeMultiplierUpdate(double multiplier) { |
| 1177 | volume_multiplier_ = multiplier; |
| 1178 | setVolume(volume_); |
| 1179 | } |
| 1180 | |
watk | dee516f | 2016-02-18 02:22:19 | [diff] [blame] | 1181 | void WebMediaPlayerImpl::ScheduleRestart() { |
sandersd | 1c0bba0 | 2016-03-04 23:14:08 | [diff] [blame] | 1182 | if (!pipeline_controller_.IsSuspended()) { |
watk | dee516f | 2016-02-18 02:22:19 | [diff] [blame] | 1183 | pending_suspend_resume_cycle_ = true; |
sandersd | 1c0bba0 | 2016-03-04 23:14:08 | [diff] [blame] | 1184 | pipeline_controller_.Suspend(); |
watk | dee516f | 2016-02-18 02:22:19 | [diff] [blame] | 1185 | } |
| 1186 | } |
| 1187 | |
hubbe | d5f3688 | 2016-01-15 22:40:37 | [diff] [blame] | 1188 | #if defined(OS_ANDROID) // WMPI_CAST |
hubbe | d5f3688 | 2016-01-15 22:40:37 | [diff] [blame] | 1189 | bool WebMediaPlayerImpl::isRemote() const { |
| 1190 | return cast_impl_.isRemote(); |
| 1191 | } |
| 1192 | |
| 1193 | void WebMediaPlayerImpl::SetMediaPlayerManager( |
| 1194 | RendererMediaPlayerManagerInterface* media_player_manager) { |
| 1195 | cast_impl_.SetMediaPlayerManager(media_player_manager); |
| 1196 | } |
| 1197 | |
| 1198 | void WebMediaPlayerImpl::requestRemotePlayback() { |
| 1199 | cast_impl_.requestRemotePlayback(); |
| 1200 | } |
| 1201 | |
| 1202 | void WebMediaPlayerImpl::requestRemotePlaybackControl() { |
| 1203 | cast_impl_.requestRemotePlaybackControl(); |
| 1204 | } |
| 1205 | |
| 1206 | void WebMediaPlayerImpl::OnRemotePlaybackEnded() { |
| 1207 | DVLOG(1) << __FUNCTION__; |
| 1208 | DCHECK(main_task_runner_->BelongsToCurrentThread()); |
| 1209 | |
| 1210 | ended_ = true; |
| 1211 | client_->timeChanged(); |
| 1212 | } |
| 1213 | |
| 1214 | void WebMediaPlayerImpl::OnDisconnectedFromRemoteDevice(double t) { |
sandersd | 1c0bba0 | 2016-03-04 23:14:08 | [diff] [blame] | 1215 | DoSeek(base::TimeDelta::FromSecondsD(t), false); |
| 1216 | if (delegate_ && !delegate_->IsHidden()) |
| 1217 | pipeline_controller_.Resume(); |
hubbe | d5f3688 | 2016-01-15 22:40:37 | [diff] [blame] | 1218 | |
hubbe | d5f3688 | 2016-01-15 22:40:37 | [diff] [blame] | 1219 | // We already told the delegate we're paused when remoting started. |
| 1220 | client_->playbackStateChanged(); |
| 1221 | client_->disconnectedFromRemoteDevice(); |
| 1222 | } |
| 1223 | |
| 1224 | void WebMediaPlayerImpl::SuspendForRemote() { |
sandersd | 1c0bba0 | 2016-03-04 23:14:08 | [diff] [blame] | 1225 | if (!pipeline_controller_.IsSuspended()) { |
| 1226 | pipeline_controller_.Suspend(); |
| 1227 | } else { |
| 1228 | // TODO(sandersd): If PipelineController::Suspend() called |suspended_cb| |
| 1229 | // when already suspended, we wouldn't need this case. |
hubbe | d5f3688 | 2016-01-15 22:40:37 | [diff] [blame] | 1230 | scoped_refptr<VideoFrame> frame = cast_impl_.GetCastingBanner(); |
| 1231 | if (frame) { |
| 1232 | compositor_->PaintFrameUsingOldRenderingPath(frame); |
| 1233 | } |
| 1234 | } |
hubbe | d5f3688 | 2016-01-15 22:40:37 | [diff] [blame] | 1235 | } |
| 1236 | |
| 1237 | gfx::Size WebMediaPlayerImpl::GetCanvasSize() const { |
| 1238 | if (!video_weblayer_) |
| 1239 | return pipeline_metadata_.natural_size; |
| 1240 | |
| 1241 | return video_weblayer_->bounds(); |
| 1242 | } |
| 1243 | |
| 1244 | void WebMediaPlayerImpl::SetDeviceScaleFactor(float scale_factor) { |
| 1245 | cast_impl_.SetDeviceScaleFactor(scale_factor); |
| 1246 | } |
| 1247 | #endif // defined(OS_ANDROID) // WMPI_CAST |
| 1248 | |
[email protected] | fee8a90 | 2014-06-03 13:43:36 | [diff] [blame] | 1249 | void WebMediaPlayerImpl::DataSourceInitialized(bool success) { |
hubbe | d82bed5 | 2015-12-15 23:07:16 | [diff] [blame] | 1250 | DVLOG(1) << __FUNCTION__; |
acolwell | b403494 | 2014-08-28 15:42:43 | [diff] [blame] | 1251 | DCHECK(main_task_runner_->BelongsToCurrentThread()); |
[email protected] | a941529 | 2012-01-19 19:55:20 | [diff] [blame] | 1252 | |
[email protected] | d250190da3b | 2012-07-23 22:57:30 | [diff] [blame] | 1253 | if (!success) { |
[email protected] | ef405f66b | 2012-04-18 02:39:55 | [diff] [blame] | 1254 | SetNetworkState(WebMediaPlayer::NetworkStateFormatError); |
[email protected] | a941529 | 2012-01-19 19:55:20 | [diff] [blame] | 1255 | return; |
| 1256 | } |
| 1257 | |
[email protected] | ef8394c | 2013-08-21 20:26:30 | [diff] [blame] | 1258 | StartPipeline(); |
[email protected] | a941529 | 2012-01-19 19:55:20 | [diff] [blame] | 1259 | } |
| 1260 | |
[email protected] | 122f4025 | 2012-06-12 05:01:56 | [diff] [blame] | 1261 | void WebMediaPlayerImpl::NotifyDownloading(bool is_downloading) { |
hubbe | d82bed5 | 2015-12-15 23:07:16 | [diff] [blame] | 1262 | DVLOG(1) << __FUNCTION__; |
[email protected] | 122f4025 | 2012-06-12 05:01:56 | [diff] [blame] | 1263 | if (!is_downloading && network_state_ == WebMediaPlayer::NetworkStateLoading) |
| 1264 | SetNetworkState(WebMediaPlayer::NetworkStateIdle); |
| 1265 | else if (is_downloading && network_state_ == WebMediaPlayer::NetworkStateIdle) |
| 1266 | SetNetworkState(WebMediaPlayer::NetworkStateLoading); |
| 1267 | media_log_->AddEvent( |
| 1268 | media_log_->CreateBooleanEvent( |
acolwell | 9e0840d | 2014-09-06 19:01:32 | [diff] [blame] | 1269 | MediaLogEvent::NETWORK_ACTIVITY_SET, |
[email protected] | 122f4025 | 2012-06-12 05:01:56 | [diff] [blame] | 1270 | "is_downloading_data", is_downloading)); |
| 1271 | } |
| 1272 | |
watk | dee516f | 2016-02-18 02:22:19 | [diff] [blame] | 1273 | // TODO(watk): Move this state management out of WMPI. |
| 1274 | void WebMediaPlayerImpl::OnSurfaceRequested( |
| 1275 | const SurfaceCreatedCB& surface_created_cb) { |
| 1276 | DCHECK(main_task_runner_->BelongsToCurrentThread()); |
| 1277 | DCHECK(surface_manager_); |
| 1278 | |
| 1279 | // A null callback indicates that the decoder is going away. |
| 1280 | if (surface_created_cb.is_null()) { |
| 1281 | decoder_requires_restart_for_fullscreen_ = false; |
| 1282 | return; |
| 1283 | } |
| 1284 | |
| 1285 | // If we're getting a surface request it means GVD is initializing, so until |
| 1286 | // we get a null surface request, GVD is the active decoder. While that's the |
| 1287 | // case we should restart the pipeline on fullscreen transitions so that when |
| 1288 | // we create a new GVD it will request a surface again and get the right kind |
| 1289 | // of surface for the fullscreen state. |
| 1290 | // TODO(watk): Don't require a pipeline restart to switch surfaces for |
| 1291 | // cases where it isn't necessary. |
| 1292 | decoder_requires_restart_for_fullscreen_ = true; |
| 1293 | if (fullscreen_) { |
| 1294 | surface_manager_->CreateFullscreenSurface(pipeline_metadata_.natural_size, |
| 1295 | surface_created_cb); |
| 1296 | } else { |
| 1297 | // Tell the decoder to create its own surface. |
| 1298 | surface_created_cb.Run(SurfaceManager::kNoSurfaceID); |
| 1299 | } |
| 1300 | } |
| 1301 | |
sandersd | 1e49fb6 | 2015-12-12 01:18:06 | [diff] [blame] | 1302 | scoped_ptr<Renderer> WebMediaPlayerImpl::CreateRenderer() { |
watk | dee516f | 2016-02-18 02:22:19 | [diff] [blame] | 1303 | RequestSurfaceCB request_surface_cb; |
| 1304 | #if defined(OS_ANDROID) |
| 1305 | request_surface_cb = |
| 1306 | BIND_TO_RENDER_LOOP(&WebMediaPlayerImpl::OnSurfaceRequested); |
| 1307 | #endif |
sandersd | 1e49fb6 | 2015-12-12 01:18:06 | [diff] [blame] | 1308 | return renderer_factory_->CreateRenderer( |
| 1309 | media_task_runner_, worker_task_runner_, audio_source_provider_.get(), |
watk | dee516f | 2016-02-18 02:22:19 | [diff] [blame] | 1310 | compositor_, request_surface_cb); |
sandersd | 1e49fb6 | 2015-12-12 01:18:06 | [diff] [blame] | 1311 | } |
| 1312 | |
[email protected] | ef8394c | 2013-08-21 20:26:30 | [diff] [blame] | 1313 | void WebMediaPlayerImpl::StartPipeline() { |
acolwell | b403494 | 2014-08-28 15:42:43 | [diff] [blame] | 1314 | DCHECK(main_task_runner_->BelongsToCurrentThread()); |
[email protected] | ddbc6ff | 2013-04-19 15:28:33 | [diff] [blame] | 1315 | |
xhwang | e8c4181a | 2014-12-06 08:10:01 | [diff] [blame] | 1316 | Demuxer::EncryptedMediaInitDataCB encrypted_media_init_data_cb = |
| 1317 | BIND_TO_RENDER_LOOP(&WebMediaPlayerImpl::OnEncryptedMediaInitData); |
[email protected] | 2b57e2e | 2014-05-09 11:07:25 | [diff] [blame] | 1318 | |
[email protected] | ddbc6ff | 2013-04-19 15:28:33 | [diff] [blame] | 1319 | // Figure out which demuxer to use. |
[email protected] | ef8394c | 2013-08-21 20:26:30 | [diff] [blame] | 1320 | if (load_type_ != LoadTypeMediaSource) { |
[email protected] | ddbc6ff | 2013-04-19 15:28:33 | [diff] [blame] | 1321 | DCHECK(!chunk_demuxer_); |
[email protected] | f5443ef7 | 2013-04-22 04:03:38 | [diff] [blame] | 1322 | DCHECK(data_source_); |
| 1323 | |
j.isorce | f6778e65 | 2015-11-16 17:14:25 | [diff] [blame] | 1324 | #if !defined(MEDIA_DISABLE_FFMPEG) |
servolk | 81e01e0 | 2016-03-05 03:29:15 | [diff] [blame] | 1325 | Demuxer::MediaTracksUpdatedCB media_tracks_updated_cb = |
servolk | ef1e5ef | 2016-03-25 04:55:26 | [diff] [blame] | 1326 | BIND_TO_RENDER_LOOP(&WebMediaPlayerImpl::OnFFmpegMediaTracksUpdated); |
servolk | 81e01e0 | 2016-03-05 03:29:15 | [diff] [blame] | 1327 | |
xhwang | e8c4181a | 2014-12-06 08:10:01 | [diff] [blame] | 1328 | demuxer_.reset(new FFmpegDemuxer(media_task_runner_, data_source_.get(), |
servolk | 81e01e0 | 2016-03-05 03:29:15 | [diff] [blame] | 1329 | encrypted_media_init_data_cb, |
| 1330 | media_tracks_updated_cb, media_log_)); |
j.isorce | f6778e65 | 2015-11-16 17:14:25 | [diff] [blame] | 1331 | #else |
| 1332 | OnPipelineError(PipelineStatus::DEMUXER_ERROR_COULD_NOT_OPEN); |
| 1333 | return; |
| 1334 | #endif |
[email protected] | ddbc6ff | 2013-04-19 15:28:33 | [diff] [blame] | 1335 | } else { |
[email protected] | f5443ef7 | 2013-04-22 04:03:38 | [diff] [blame] | 1336 | DCHECK(!chunk_demuxer_); |
| 1337 | DCHECK(!data_source_); |
| 1338 | |
acolwell | 9e0840d | 2014-09-06 19:01:32 | [diff] [blame] | 1339 | chunk_demuxer_ = new ChunkDemuxer( |
[email protected] | ef8394c | 2013-08-21 20:26:30 | [diff] [blame] | 1340 | BIND_TO_RENDER_LOOP(&WebMediaPlayerImpl::OnDemuxerOpened), |
wolenetz | 1fb319d | 2015-07-14 17:49:04 | [diff] [blame] | 1341 | encrypted_media_init_data_cb, media_log_, true); |
[email protected] | f5443ef7 | 2013-04-22 04:03:38 | [diff] [blame] | 1342 | demuxer_.reset(chunk_demuxer_); |
[email protected] | ddbc6ff | 2013-04-19 15:28:33 | [diff] [blame] | 1343 | } |
| 1344 | |
sandersd | b5e2146 | 2016-03-09 01:49:07 | [diff] [blame] | 1345 | // TODO(sandersd): FileSystem objects may also be non-static, but due to our |
| 1346 | // caching layer such situations are broken already. http://crbug.com/593159 |
| 1347 | bool is_static = !chunk_demuxer_; |
| 1348 | |
[email protected] | f5443ef7 | 2013-04-22 04:03:38 | [diff] [blame] | 1349 | // ... and we're ready to go! |
[email protected] | d228aeec | 2014-06-20 19:16:49 | [diff] [blame] | 1350 | seeking_ = true; |
xhwang | f94a634d | 2014-10-22 22:07:27 | [diff] [blame] | 1351 | |
sandersd | 1e49fb6 | 2015-12-12 01:18:06 | [diff] [blame] | 1352 | // TODO(sandersd): On Android, defer Start() if the tab is not visible. |
sandersd | 1c0bba0 | 2016-03-04 23:14:08 | [diff] [blame] | 1353 | bool is_streaming = (data_source_ && data_source_->IsStreaming()); |
| 1354 | pipeline_controller_.Start( |
sandersd | b5e2146 | 2016-03-09 01:49:07 | [diff] [blame] | 1355 | demuxer_.get(), is_streaming, is_static, |
[email protected] | f5443ef7 | 2013-04-22 04:03:38 | [diff] [blame] | 1356 | BIND_TO_RENDER_LOOP(&WebMediaPlayerImpl::OnPipelineEnded), |
[email protected] | b887777 | 2014-03-26 20:17:15 | [diff] [blame] | 1357 | BIND_TO_RENDER_LOOP(&WebMediaPlayerImpl::OnPipelineMetadata), |
[email protected] | ba7d5f9 | 2014-06-24 05:37:40 | [diff] [blame] | 1358 | BIND_TO_RENDER_LOOP(&WebMediaPlayerImpl::OnPipelineBufferingStateChanged), |
xhwang | 5980590 | 2014-08-29 01:44:15 | [diff] [blame] | 1359 | BIND_TO_RENDER_LOOP(&WebMediaPlayerImpl::OnDurationChanged), |
jrummell | 74fc4f94 | 2015-03-02 22:48:27 | [diff] [blame] | 1360 | BIND_TO_RENDER_LOOP(&WebMediaPlayerImpl::OnAddTextTrack), |
| 1361 | BIND_TO_RENDER_LOOP(&WebMediaPlayerImpl::OnWaitingForDecryptionKey)); |
[email protected] | f5443ef7 | 2013-04-22 04:03:38 | [diff] [blame] | 1362 | } |
| 1363 | |
| 1364 | void WebMediaPlayerImpl::SetNetworkState(WebMediaPlayer::NetworkState state) { |
[email protected] | 2a06ca6 | 2014-06-04 13:59:52 | [diff] [blame] | 1365 | DVLOG(1) << __FUNCTION__ << "(" << state << ")"; |
acolwell | b403494 | 2014-08-28 15:42:43 | [diff] [blame] | 1366 | DCHECK(main_task_runner_->BelongsToCurrentThread()); |
[email protected] | f5443ef7 | 2013-04-22 04:03:38 | [diff] [blame] | 1367 | network_state_ = state; |
| 1368 | // Always notify to ensure client has the latest value. |
[email protected] | ce70c98 | 2013-12-20 17:04:32 | [diff] [blame] | 1369 | client_->networkStateChanged(); |
[email protected] | f5443ef7 | 2013-04-22 04:03:38 | [diff] [blame] | 1370 | } |
| 1371 | |
| 1372 | void WebMediaPlayerImpl::SetReadyState(WebMediaPlayer::ReadyState state) { |
[email protected] | 2a06ca6 | 2014-06-04 13:59:52 | [diff] [blame] | 1373 | DVLOG(1) << __FUNCTION__ << "(" << state << ")"; |
acolwell | b403494 | 2014-08-28 15:42:43 | [diff] [blame] | 1374 | DCHECK(main_task_runner_->BelongsToCurrentThread()); |
[email protected] | f5443ef7 | 2013-04-22 04:03:38 | [diff] [blame] | 1375 | |
[email protected] | fee8a90 | 2014-06-03 13:43:36 | [diff] [blame] | 1376 | if (state == WebMediaPlayer::ReadyStateHaveEnoughData && data_source_ && |
| 1377 | data_source_->assume_fully_buffered() && |
[email protected] | f5443ef7 | 2013-04-22 04:03:38 | [diff] [blame] | 1378 | network_state_ == WebMediaPlayer::NetworkStateLoading) |
| 1379 | SetNetworkState(WebMediaPlayer::NetworkStateLoaded); |
| 1380 | |
| 1381 | ready_state_ = state; |
| 1382 | // Always notify to ensure client has the latest value. |
[email protected] | ce70c98 | 2013-12-20 17:04:32 | [diff] [blame] | 1383 | client_->readyStateChanged(); |
[email protected] | f5443ef7 | 2013-04-22 04:03:38 | [diff] [blame] | 1384 | } |
| 1385 | |
Dana Jansens | 7133125 | 2016-03-09 20:57:22 | [diff] [blame] | 1386 | blink::WebAudioSourceProvider* WebMediaPlayerImpl::getAudioSourceProvider() { |
[email protected] | ff875be5 | 2013-06-02 23:47:38 | [diff] [blame] | 1387 | return audio_source_provider_.get(); |
[email protected] | f5443ef7 | 2013-04-22 04:03:38 | [diff] [blame] | 1388 | } |
| 1389 | |
[email protected] | f5443ef7 | 2013-04-22 04:03:38 | [diff] [blame] | 1390 | double WebMediaPlayerImpl::GetPipelineDuration() const { |
[email protected] | f6af759 | 2014-02-28 10:09:11 | [diff] [blame] | 1391 | base::TimeDelta duration = pipeline_.GetMediaDuration(); |
[email protected] | f5443ef7 | 2013-04-22 04:03:38 | [diff] [blame] | 1392 | |
| 1393 | // Return positive infinity if the resource is unbounded. |
| 1394 | // http://www.whatwg.org/specs/web-apps/current-work/multipage/video.html#dom-media-duration |
acolwell | 9e0840d | 2014-09-06 19:01:32 | [diff] [blame] | 1395 | if (duration == kInfiniteDuration()) |
[email protected] | f5443ef7 | 2013-04-22 04:03:38 | [diff] [blame] | 1396 | return std::numeric_limits<double>::infinity(); |
| 1397 | |
| 1398 | return duration.InSecondsF(); |
| 1399 | } |
| 1400 | |
[email protected] | 75e145a | 2014-04-15 17:44:32 | [diff] [blame] | 1401 | void WebMediaPlayerImpl::OnDurationChanged() { |
[email protected] | f5443ef7 | 2013-04-22 04:03:38 | [diff] [blame] | 1402 | if (ready_state_ == WebMediaPlayer::ReadyStateHaveNothing) |
| 1403 | return; |
| 1404 | |
[email protected] | ce70c98 | 2013-12-20 17:04:32 | [diff] [blame] | 1405 | client_->durationChanged(); |
[email protected] | f5443ef7 | 2013-04-22 04:03:38 | [diff] [blame] | 1406 | } |
| 1407 | |
[email protected] | 75e145a | 2014-04-15 17:44:32 | [diff] [blame] | 1408 | void WebMediaPlayerImpl::OnNaturalSizeChanged(gfx::Size size) { |
acolwell | b403494 | 2014-08-28 15:42:43 | [diff] [blame] | 1409 | DCHECK(main_task_runner_->BelongsToCurrentThread()); |
[email protected] | 739847c0 | 2014-01-16 00:12:25 | [diff] [blame] | 1410 | DCHECK_NE(ready_state_, WebMediaPlayer::ReadyStateHaveNothing); |
| 1411 | TRACE_EVENT0("media", "WebMediaPlayerImpl::OnNaturalSizeChanged"); |
| 1412 | |
| 1413 | media_log_->AddEvent( |
| 1414 | media_log_->CreateVideoSizeSetEvent(size.width(), size.height())); |
[email protected] | 739847c0 | 2014-01-16 00:12:25 | [diff] [blame] | 1415 | |
watk | dee516f | 2016-02-18 02:22:19 | [diff] [blame] | 1416 | if (fullscreen_ && surface_manager_ && |
| 1417 | pipeline_metadata_.natural_size != size) { |
| 1418 | surface_manager_->NaturalSizeChanged(size); |
| 1419 | } |
| 1420 | |
| 1421 | pipeline_metadata_.natural_size = size; |
[email protected] | 739847c0 | 2014-01-16 00:12:25 | [diff] [blame] | 1422 | client_->sizeChanged(); |
| 1423 | } |
| 1424 | |
[email protected] | 75e145a | 2014-04-15 17:44:32 | [diff] [blame] | 1425 | void WebMediaPlayerImpl::OnOpacityChanged(bool opaque) { |
acolwell | b403494 | 2014-08-28 15:42:43 | [diff] [blame] | 1426 | DCHECK(main_task_runner_->BelongsToCurrentThread()); |
[email protected] | 75e145a | 2014-04-15 17:44:32 | [diff] [blame] | 1427 | DCHECK_NE(ready_state_, WebMediaPlayer::ReadyStateHaveNothing); |
| 1428 | |
| 1429 | opaque_ = opaque; |
jbauman | 952274d | 2015-09-10 23:23:36 | [diff] [blame] | 1430 | // Modify content opaqueness of cc::Layer directly so that |
| 1431 | // SetContentsOpaqueIsFixed is ignored. |
[email protected] | 75e145a | 2014-04-15 17:44:32 | [diff] [blame] | 1432 | if (video_weblayer_) |
jbauman | 952274d | 2015-09-10 23:23:36 | [diff] [blame] | 1433 | video_weblayer_->layer()->SetContentsOpaque(opaque_); |
[email protected] | 75e145a | 2014-04-15 17:44:32 | [diff] [blame] | 1434 | } |
| 1435 | |
[email protected] | dd061e1 | 2014-05-06 19:21:22 | [diff] [blame] | 1436 | static void GetCurrentFrameAndSignal( |
| 1437 | VideoFrameCompositor* compositor, |
acolwell | 9e0840d | 2014-09-06 19:01:32 | [diff] [blame] | 1438 | scoped_refptr<VideoFrame>* video_frame_out, |
[email protected] | dd061e1 | 2014-05-06 19:21:22 | [diff] [blame] | 1439 | base::WaitableEvent* event) { |
| 1440 | TRACE_EVENT0("media", "GetCurrentFrameAndSignal"); |
dalecurtis | 44ce4de | 2015-05-11 18:42:07 | [diff] [blame] | 1441 | *video_frame_out = compositor->GetCurrentFrameAndUpdateIfStale(); |
[email protected] | dd061e1 | 2014-05-06 19:21:22 | [diff] [blame] | 1442 | event->Signal(); |
| 1443 | } |
| 1444 | |
acolwell | 9e0840d | 2014-09-06 19:01:32 | [diff] [blame] | 1445 | scoped_refptr<VideoFrame> |
[email protected] | dd061e1 | 2014-05-06 19:21:22 | [diff] [blame] | 1446 | WebMediaPlayerImpl::GetCurrentFrameFromCompositor() { |
| 1447 | TRACE_EVENT0("media", "WebMediaPlayerImpl::GetCurrentFrameFromCompositor"); |
| 1448 | if (compositor_task_runner_->BelongsToCurrentThread()) |
dalecurtis | 44ce4de | 2015-05-11 18:42:07 | [diff] [blame] | 1449 | return compositor_->GetCurrentFrameAndUpdateIfStale(); |
[email protected] | dd061e1 | 2014-05-06 19:21:22 | [diff] [blame] | 1450 | |
| 1451 | // Use a posted task and waitable event instead of a lock otherwise |
| 1452 | // WebGL/Canvas can see different content than what the compositor is seeing. |
acolwell | 9e0840d | 2014-09-06 19:01:32 | [diff] [blame] | 1453 | scoped_refptr<VideoFrame> video_frame; |
[email protected] | dd061e1 | 2014-05-06 19:21:22 | [diff] [blame] | 1454 | base::WaitableEvent event(false, false); |
| 1455 | compositor_task_runner_->PostTask(FROM_HERE, |
| 1456 | base::Bind(&GetCurrentFrameAndSignal, |
| 1457 | base::Unretained(compositor_), |
| 1458 | &video_frame, |
| 1459 | &event)); |
| 1460 | event.Wait(); |
| 1461 | return video_frame; |
| 1462 | } |
| 1463 | |
dalecurtis | 0f0097a | 2015-12-01 17:40:47 | [diff] [blame] | 1464 | void WebMediaPlayerImpl::NotifyPlaybackStarted() { |
hubbe | d5f3688 | 2016-01-15 22:40:37 | [diff] [blame] | 1465 | #if defined(OS_ANDROID) // WMPI_CAST |
dalecurtis | 5bbc487e | 2016-02-27 04:15:05 | [diff] [blame] | 1466 | // We do not tell our delegates about remote playback, because that would |
hubbe | d5f3688 | 2016-01-15 22:40:37 | [diff] [blame] | 1467 | // keep the device awake, which is not what we want. |
| 1468 | if (isRemote()) |
| 1469 | return; |
| 1470 | #endif |
dalecurtis | 5bbc487e | 2016-02-27 04:15:05 | [diff] [blame] | 1471 | |
sandersd | 1c0bba0 | 2016-03-04 23:14:08 | [diff] [blame] | 1472 | // NotifyPlaybackStarted() may be called by interactions while suspended, |
| 1473 | // (play/pause in particular). Those actions won't have any effect until the |
| 1474 | // pipeline is resumed. |
| 1475 | // TODO(dalecurtis): Should these be dropped at the call sites instead? |
| 1476 | // Alternatively, rename this method to include Maybe or Changed, and handle |
| 1477 | // multiple calls safely. |
| 1478 | if (pipeline_controller_.IsSuspended()) |
dalecurtis | 5bbc487e | 2016-02-27 04:15:05 | [diff] [blame] | 1479 | return; |
| 1480 | |
dalecurtis | bb3eaac | 2016-01-27 21:10:25 | [diff] [blame] | 1481 | if (delegate_) { |
| 1482 | delegate_->DidPlay(delegate_id_, hasVideo(), hasAudio(), false, |
| 1483 | pipeline_.GetMediaDuration()); |
| 1484 | } |
dalecurtis | 0f0097a | 2015-12-01 17:40:47 | [diff] [blame] | 1485 | if (!memory_usage_reporting_timer_.IsRunning()) { |
| 1486 | memory_usage_reporting_timer_.Start(FROM_HERE, |
| 1487 | base::TimeDelta::FromSeconds(2), this, |
| 1488 | &WebMediaPlayerImpl::ReportMemoryUsage); |
| 1489 | } |
| 1490 | } |
| 1491 | |
| 1492 | void WebMediaPlayerImpl::NotifyPlaybackPaused() { |
hubbe | d5f3688 | 2016-01-15 22:40:37 | [diff] [blame] | 1493 | #if defined(OS_ANDROID) // WMPI_CAST |
| 1494 | if (isRemote()) |
| 1495 | return; |
| 1496 | #endif |
sandersd | 1c0bba0 | 2016-03-04 23:14:08 | [diff] [blame] | 1497 | |
| 1498 | // Same as above, NotifyPlaybackPaused() may be called by interactions while |
| 1499 | // suspended, but those actions won't have any effect until the pipeline is |
| 1500 | // resumed. |
| 1501 | if (pipeline_controller_.IsSuspended()) |
| 1502 | return; |
| 1503 | |
| 1504 | if (delegate_) |
dalecurtis | bb3eaac | 2016-01-27 21:10:25 | [diff] [blame] | 1505 | delegate_->DidPause(delegate_id_, ended_); |
dalecurtis | 0f0097a | 2015-12-01 17:40:47 | [diff] [blame] | 1506 | memory_usage_reporting_timer_.Stop(); |
| 1507 | ReportMemoryUsage(); |
| 1508 | } |
| 1509 | |
dalecurtis | 83266c7 | 2015-10-29 18:43:20 | [diff] [blame] | 1510 | void WebMediaPlayerImpl::ReportMemoryUsage() { |
| 1511 | DCHECK(main_task_runner_->BelongsToCurrentThread()); |
| 1512 | |
wdzierzanowski | fd4cd91c5 | 2015-12-02 23:50:20 | [diff] [blame] | 1513 | // About base::Unretained() usage below: We destroy |demuxer_| on the main |
| 1514 | // thread. Before that, however, ~WebMediaPlayerImpl() posts a task to the |
| 1515 | // media thread and waits for it to finish. Hence, the GetMemoryUsage() task |
| 1516 | // posted here must finish earlier. |
| 1517 | |
| 1518 | if (demuxer_) { |
| 1519 | base::PostTaskAndReplyWithResult( |
| 1520 | media_task_runner_.get(), FROM_HERE, |
| 1521 | base::Bind(&Demuxer::GetMemoryUsage, base::Unretained(demuxer_.get())), |
| 1522 | base::Bind(&WebMediaPlayerImpl::FinishMemoryUsageReport, AsWeakPtr())); |
| 1523 | } else { |
| 1524 | FinishMemoryUsageReport(0); |
| 1525 | } |
| 1526 | } |
| 1527 | |
| 1528 | void WebMediaPlayerImpl::FinishMemoryUsageReport(int64_t demuxer_memory_usage) { |
| 1529 | DCHECK(main_task_runner_->BelongsToCurrentThread()); |
| 1530 | |
dalecurtis | 83266c7 | 2015-10-29 18:43:20 | [diff] [blame] | 1531 | const PipelineStatistics stats = pipeline_.GetStatistics(); |
| 1532 | const int64_t current_memory_usage = |
| 1533 | stats.audio_memory_usage + stats.video_memory_usage + |
| 1534 | (data_source_ ? data_source_->GetMemoryUsage() : 0) + |
wdzierzanowski | fd4cd91c5 | 2015-12-02 23:50:20 | [diff] [blame] | 1535 | demuxer_memory_usage; |
dalecurtis | 83266c7 | 2015-10-29 18:43:20 | [diff] [blame] | 1536 | |
dalecurtis | 3a7d38f4 | 2016-03-07 21:17:13 | [diff] [blame] | 1537 | // Note, this isn't entirely accurate, there may be VideoFrames held by the |
| 1538 | // compositor or other resources that we're unaware of. |
| 1539 | |
dalecurtis | 83266c7 | 2015-10-29 18:43:20 | [diff] [blame] | 1540 | DVLOG(2) << "Memory Usage -- Audio: " << stats.audio_memory_usage |
| 1541 | << ", Video: " << stats.video_memory_usage << ", DataSource: " |
| 1542 | << (data_source_ ? data_source_->GetMemoryUsage() : 0) |
wdzierzanowski | fd4cd91c5 | 2015-12-02 23:50:20 | [diff] [blame] | 1543 | << ", Demuxer: " << demuxer_memory_usage; |
dalecurtis | 83266c7 | 2015-10-29 18:43:20 | [diff] [blame] | 1544 | |
| 1545 | const int64_t delta = current_memory_usage - last_reported_memory_usage_; |
| 1546 | last_reported_memory_usage_ = current_memory_usage; |
| 1547 | adjust_allocated_memory_cb_.Run(delta); |
| 1548 | } |
| 1549 | |
dalecurtis | 0431cbf | 2016-03-12 01:19:43 | [diff] [blame] | 1550 | bool WebMediaPlayerImpl::IsAutomaticResumeAllowed() { |
| 1551 | #if defined(OS_ANDROID) |
| 1552 | return !hasVideo() || (delegate_ && !delegate_->IsHidden()); |
| 1553 | #else |
| 1554 | // On non-Android platforms Resume() is always allowed. |
| 1555 | return true; |
| 1556 | #endif |
| 1557 | } |
| 1558 | |
acolwell | 9e0840d | 2014-09-06 19:01:32 | [diff] [blame] | 1559 | } // namespace media |