[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> |
| 10 | |
[email protected] | 08273c7b | 2011-09-17 00:33:51 | [diff] [blame] | 11 | #include "base/bind.h" |
[email protected] | 2041cf34 | 2010-02-19 03:15:59 | [diff] [blame] | 12 | #include "base/callback.h" |
[email protected] | 7502ef1 | 2014-01-25 01:19:27 | [diff] [blame] | 13 | #include "base/callback_helpers.h" |
[email protected] | ca04095f | 2014-02-07 10:23:56 | [diff] [blame] | 14 | #include "base/debug/alias.h" |
[email protected] | 926f8fd | 2013-04-12 20:27:53 | [diff] [blame] | 15 | #include "base/debug/crash_logging.h" |
[email protected] | b0b258f | 2011-11-08 00:34:23 | [diff] [blame] | 16 | #include "base/metrics/histogram.h" |
acolwell | b403494 | 2014-08-28 15:42:43 | [diff] [blame] | 17 | #include "base/single_thread_task_runner.h" |
[email protected] | cf02541b | 2012-04-11 08:02:17 | [diff] [blame] | 18 | #include "base/synchronization/waitable_event.h" |
anujk.sharma | 2fa37a0 | 2015-04-30 05:51:32 | [diff] [blame] | 19 | #include "base/thread_task_runner_handle.h" |
ssid | 9525f467 | 2015-01-28 12:13:15 | [diff] [blame] | 20 | #include "base/trace_event/trace_event.h" |
[email protected] | 3856462 | 2014-08-19 02:47:18 | [diff] [blame] | 21 | #include "cc/blink/web_layer_impl.h" |
[email protected] | 21c3f750 | 2013-03-23 03:29:51 | [diff] [blame] | 22 | #include "cc/layers/video_layer.h" |
dongseong.hwang | 0c4e9d8 | 2015-01-08 20:11:13 | [diff] [blame] | 23 | #include "gpu/blink/webgraphicscontext3d_impl.h" |
[email protected] | e4fc09e | 2012-04-06 03:17:44 | [diff] [blame] | 24 | #include "media/audio/null_audio_sink.h" |
[email protected] | 2eccbed | 2014-01-10 05:15:53 | [diff] [blame] | 25 | #include "media/base/bind_to_current_loop.h" |
xhwang | 0ad11e51 | 2014-11-25 23:43:09 | [diff] [blame] | 26 | #include "media/base/cdm_context.h" |
[email protected] | 32da100 | 2010-03-03 21:57:35 | [diff] [blame] | 27 | #include "media/base/limits.h" |
[email protected] | 090f731 | 2011-08-05 23:26:40 | [diff] [blame] | 28 | #include "media/base/media_log.h" |
[email protected] | 8a56106 | 2013-11-22 01:19:31 | [diff] [blame] | 29 | #include "media/base/text_renderer.h" |
[email protected] | e81283bb | 2010-08-31 18:01:21 | [diff] [blame] | 30 | #include "media/base/video_frame.h" |
acolwell | 9e0840d | 2014-09-06 19:01:32 | [diff] [blame] | 31 | #include "media/blink/texttrack_impl.h" |
| 32 | #include "media/blink/webaudiosourceprovider_impl.h" |
xhwang | 97de420 | 2014-11-25 08:44:01 | [diff] [blame] | 33 | #include "media/blink/webcontentdecryptionmodule_impl.h" |
acolwell | 9e0840d | 2014-09-06 19:01:32 | [diff] [blame] | 34 | #include "media/blink/webinbandtexttrack_impl.h" |
| 35 | #include "media/blink/webmediaplayer_delegate.h" |
acolwell | 9e0840d | 2014-09-06 19:01:32 | [diff] [blame] | 36 | #include "media/blink/webmediaplayer_util.h" |
| 37 | #include "media/blink/webmediasource_impl.h" |
[email protected] | efe7cd2 | 2012-09-12 23:55:01 | [diff] [blame] | 38 | #include "media/filters/chunk_demuxer.h" |
[email protected] | ddbc6ff | 2013-04-19 15:28:33 | [diff] [blame] | 39 | #include "media/filters/ffmpeg_demuxer.h" |
jrummell | c9d8e53 | 2015-02-26 18:38:19 | [diff] [blame] | 40 | #include "third_party/WebKit/public/platform/WebEncryptedMediaTypes.h" |
[email protected] | 745746d | 2013-08-23 02:09:16 | [diff] [blame] | 41 | #include "third_party/WebKit/public/platform/WebMediaSource.h" |
[email protected] | c1088446 | 2013-05-30 00:22:09 | [diff] [blame] | 42 | #include "third_party/WebKit/public/platform/WebRect.h" |
| 43 | #include "third_party/WebKit/public/platform/WebSize.h" |
| 44 | #include "third_party/WebKit/public/platform/WebString.h" |
| 45 | #include "third_party/WebKit/public/platform/WebURL.h" |
[email protected] | 8050465 | 2014-04-18 04:41:50 | [diff] [blame] | 46 | #include "third_party/WebKit/public/web/WebLocalFrame.h" |
xhwang | bab66f5 | 2014-12-02 23:49:50 | [diff] [blame] | 47 | #include "third_party/WebKit/public/web/WebRuntimeFeatures.h" |
[email protected] | 65b8528 | 2014-03-31 23:32:31 | [diff] [blame] | 48 | #include "third_party/WebKit/public/web/WebSecurityOrigin.h" |
[email protected] | 2255a933 | 2013-06-17 05:12:31 | [diff] [blame] | 49 | #include "third_party/WebKit/public/web/WebView.h" |
[email protected] | b3f2b91 | 2009-04-09 16:18:52 | [diff] [blame] | 50 | |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame] | 51 | using blink::WebCanvas; |
| 52 | using blink::WebMediaPlayer; |
| 53 | using blink::WebRect; |
| 54 | using blink::WebSize; |
| 55 | using blink::WebString; |
[email protected] | ec9212f | 2008-12-18 21:40:36 | [diff] [blame] | 56 | |
[email protected] | 8931c41a | 2009-07-07 17:31:49 | [diff] [blame] | 57 | namespace { |
| 58 | |
[email protected] | 378f0b7 | 2009-08-11 17:11:42 | [diff] [blame] | 59 | // Limits the range of playback rate. |
| 60 | // |
| 61 | // TODO(kylep): Revisit these. |
| 62 | // |
| 63 | // Vista has substantially lower performance than XP or Windows7. If you speed |
| 64 | // up a video too much, it can't keep up, and rendering stops updating except on |
| 65 | // the time bar. For really high speeds, audio becomes a bottleneck and we just |
| 66 | // use up the data we have, which may not achieve the speed requested, but will |
| 67 | // not crash the tab. |
| 68 | // |
| 69 | // A very slow speed, ie 0.00000001x, causes the machine to lock up. (It seems |
| 70 | // like a busy loop). It gets unresponsive, although its not completely dead. |
| 71 | // |
| 72 | // Also our timers are not very accurate (especially for ogg), which becomes |
| 73 | // evident at low speeds and on Vista. Since other speeds are risky and outside |
| 74 | // 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] | 75 | const double kMinRate = 0.0625; |
| 76 | const double kMaxRate = 16.0; |
[email protected] | 378f0b7 | 2009-08-11 17:11:42 | [diff] [blame] | 77 | |
[email protected] | 8931c41a | 2009-07-07 17:31:49 | [diff] [blame] | 78 | } // namespace |
| 79 | |
acolwell | 9e0840d | 2014-09-06 19:01:32 | [diff] [blame] | 80 | namespace media { |
[email protected] | add5177 | 2009-06-11 18:25:17 | [diff] [blame] | 81 | |
[email protected] | 6683e1b | 2014-04-10 01:45:38 | [diff] [blame] | 82 | class BufferedDataSourceHostImpl; |
| 83 | |
mostynb | 502b00b | 2015-01-05 23:43:40 | [diff] [blame] | 84 | #define STATIC_ASSERT_MATCHING_ENUM(name) \ |
| 85 | static_assert(static_cast<int>(WebMediaPlayer::CORSMode ## name) == \ |
| 86 | static_cast<int>(BufferedResourceLoader::k ## name), \ |
| 87 | "mismatching enum values: " #name) |
| 88 | STATIC_ASSERT_MATCHING_ENUM(Unspecified); |
| 89 | STATIC_ASSERT_MATCHING_ENUM(Anonymous); |
| 90 | STATIC_ASSERT_MATCHING_ENUM(UseCredentials); |
| 91 | #undef STATIC_ASSERT_MATCHING_ENUM |
[email protected] | a5a0110 | 2012-06-06 17:01:24 | [diff] [blame] | 92 | |
[email protected] | 2c539b8 | 2012-08-18 04:10:19 | [diff] [blame] | 93 | #define BIND_TO_RENDER_LOOP(function) \ |
acolwell | b403494 | 2014-08-28 15:42:43 | [diff] [blame] | 94 | (DCHECK(main_task_runner_->BelongsToCurrentThread()), \ |
acolwell | 9e0840d | 2014-09-06 19:01:32 | [diff] [blame] | 95 | BindToCurrentLoop(base::Bind(function, AsWeakPtr()))) |
[email protected] | 5983adb | 2012-10-24 00:12:00 | [diff] [blame] | 96 | |
[email protected] | 4e98219 | 2014-06-21 13:35:45 | [diff] [blame] | 97 | #define BIND_TO_RENDER_LOOP1(function, arg1) \ |
acolwell | b403494 | 2014-08-28 15:42:43 | [diff] [blame] | 98 | (DCHECK(main_task_runner_->BelongsToCurrentThread()), \ |
acolwell | 9e0840d | 2014-09-06 19:01:32 | [diff] [blame] | 99 | BindToCurrentLoop(base::Bind(function, AsWeakPtr(), arg1))) |
[email protected] | 4e98219 | 2014-06-21 13:35:45 | [diff] [blame] | 100 | |
[email protected] | 5b5bb9d | 2010-10-22 19:57:36 | [diff] [blame] | 101 | WebMediaPlayerImpl::WebMediaPlayerImpl( |
[email protected] | 35b2a97 | 2014-04-04 15:50:22 | [diff] [blame] | 102 | blink::WebLocalFrame* frame, |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame] | 103 | blink::WebMediaPlayerClient* client, |
[email protected] | b897665 | 2011-10-26 23:46:55 | [diff] [blame] | 104 | base::WeakPtr<WebMediaPlayerDelegate> delegate, |
xhwang | 6fa35620 | 2014-12-11 00:44:12 | [diff] [blame] | 105 | scoped_ptr<RendererFactory> renderer_factory, |
xhwang | d718083 | 2015-04-03 05:38:15 | [diff] [blame] | 106 | CdmFactory* cdm_factory, |
[email protected] | e82b2bd | 2013-01-02 17:47:57 | [diff] [blame] | 107 | const WebMediaPlayerParams& params) |
[email protected] | f6af759 | 2014-02-28 10:09:11 | [diff] [blame] | 108 | : frame_(frame), |
[email protected] | ef405f66b | 2012-04-18 02:39:55 | [diff] [blame] | 109 | network_state_(WebMediaPlayer::NetworkStateEmpty), |
| 110 | ready_state_(WebMediaPlayer::ReadyStateHaveNothing), |
acolwell | a5081a4 | 2014-08-28 23:42:52 | [diff] [blame] | 111 | preload_(BufferedDataSource::AUTO), |
anujk.sharma | 2fa37a0 | 2015-04-30 05:51:32 | [diff] [blame] | 112 | main_task_runner_(base::ThreadTaskRunnerHandle::Get()), |
acolwell | 755d12d | 2014-08-30 01:09:19 | [diff] [blame] | 113 | media_task_runner_(params.media_task_runner()), |
| 114 | media_log_(params.media_log()), |
acolwell | b403494 | 2014-08-28 15:42:43 | [diff] [blame] | 115 | pipeline_(media_task_runner_, media_log_.get()), |
[email protected] | f988d9b | 2014-07-25 00:35:43 | [diff] [blame] | 116 | load_type_(LoadTypeURL), |
[email protected] | 75e145a | 2014-04-15 17:44:32 | [diff] [blame] | 117 | opaque_(false), |
[email protected] | 4948090 | 2009-07-14 20:23:43 | [diff] [blame] | 118 | paused_(true), |
[email protected] | b3766a2 | 2010-12-22 17:34:13 | [diff] [blame] | 119 | seeking_(false), |
a.berwal | 338bf00 | 2015-04-22 11:14:50 | [diff] [blame] | 120 | playback_rate_(0.0), |
scherkus | d2c745b | 2014-09-04 05:03:40 | [diff] [blame] | 121 | ended_(false), |
[email protected] | 5d11eff | 2011-09-15 00:06:06 | [diff] [blame] | 122 | pending_seek_(false), |
[email protected] | b1a975e | 2011-12-21 00:12:39 | [diff] [blame] | 123 | pending_seek_seconds_(0.0f), |
[email protected] | ba7d5f9 | 2014-06-24 05:37:40 | [diff] [blame] | 124 | should_notify_time_changed_(false), |
[email protected] | 5badb08 | 2010-06-11 17:40:15 | [diff] [blame] | 125 | client_(client), |
[email protected] | baff451 | 2011-10-19 18:21:07 | [diff] [blame] | 126 | delegate_(delegate), |
[email protected] | d726eddc | 2013-07-02 22:25:55 | [diff] [blame] | 127 | defer_load_cb_(params.defer_load_cb()), |
dongseong.hwang | 0c4e9d8 | 2015-01-08 20:11:13 | [diff] [blame] | 128 | context_3d_cb_(params.context_3d_cb()), |
[email protected] | 132dd57c | 2012-08-10 23:24:34 | [diff] [blame] | 129 | supports_save_(true), |
[email protected] | f5443ef7 | 2013-04-22 04:03:38 | [diff] [blame] | 130 | chunk_demuxer_(NULL), |
Bartosz Fabianowski | 85a82381 | 2015-04-16 10:27:51 | [diff] [blame] | 131 | // Threaded compositing isn't enabled universally yet. |
| 132 | compositor_task_runner_( |
| 133 | params.compositor_task_runner() |
| 134 | ? params.compositor_task_runner() |
| 135 | : base::MessageLoop::current()->task_runner()), |
[email protected] | dd061e1 | 2014-05-06 19:21:22 | [diff] [blame] | 136 | compositor_(new VideoFrameCompositor( |
Bartosz Fabianowski | 85a82381 | 2015-04-16 10:27:51 | [diff] [blame] | 137 | compositor_task_runner_, |
[email protected] | 75e145a | 2014-04-15 17:44:32 | [diff] [blame] | 138 | BIND_TO_RENDER_LOOP(&WebMediaPlayerImpl::OnNaturalSizeChanged), |
[email protected] | dd061e1 | 2014-05-06 19:21:22 | [diff] [blame] | 139 | BIND_TO_RENDER_LOOP(&WebMediaPlayerImpl::OnOpacityChanged))), |
xhwang | 9bd8c73 | 2015-04-13 23:27:53 | [diff] [blame] | 140 | encrypted_media_support_(cdm_factory, |
| 141 | client, |
| 142 | params.media_permission(), |
| 143 | base::Bind(&WebMediaPlayerImpl::SetCdm, |
| 144 | AsWeakPtr(), |
| 145 | base::Bind(&IgnoreCdmAttached))), |
xhwang | 6fa35620 | 2014-12-11 00:44:12 | [diff] [blame] | 146 | renderer_factory_(renderer_factory.Pass()) { |
[email protected] | c93eb0a6 | 2011-08-09 22:47:24 | [diff] [blame] | 147 | media_log_->AddEvent( |
acolwell | 9e0840d | 2014-09-06 19:01:32 | [diff] [blame] | 148 | media_log_->CreateEvent(MediaLogEvent::WEBMEDIAPLAYER_CREATED)); |
[email protected] | 4e6be3f | 2009-05-07 02:24:44 | [diff] [blame] | 149 | |
xhwang | 0ad11e51 | 2014-11-25 23:43:09 | [diff] [blame] | 150 | if (params.initial_cdm()) { |
xhwang | 9bd8c73 | 2015-04-13 23:27:53 | [diff] [blame] | 151 | SetCdm(base::Bind(&IgnoreCdmAttached), |
| 152 | ToWebContentDecryptionModuleImpl(params.initial_cdm()) |
| 153 | ->GetCdmContext()); |
xhwang | 0ad11e51 | 2014-11-25 23:43:09 | [diff] [blame] | 154 | } |
| 155 | |
xhwang | f94a634d | 2014-10-22 22:07:27 | [diff] [blame] | 156 | // TODO(xhwang): When we use an external Renderer, many methods won't work, |
xhwang | 6fa35620 | 2014-12-11 00:44:12 | [diff] [blame] | 157 | // e.g. GetCurrentFrameFromCompositor(). See http://crbug.com/434861 |
[email protected] | c50edb96 | 2013-10-19 18:05:07 | [diff] [blame] | 158 | |
[email protected] | ddbc6ff | 2013-04-19 15:28:33 | [diff] [blame] | 159 | // Use the null sink if no sink was provided. |
[email protected] | 4a91488 | 2013-01-10 00:43:48 | [diff] [blame] | 160 | audio_source_provider_ = new WebAudioSourceProviderImpl( |
[email protected] | ff875be5 | 2013-06-02 23:47:38 | [diff] [blame] | 161 | params.audio_renderer_sink().get() |
| 162 | ? params.audio_renderer_sink() |
acolwell | 9e0840d | 2014-09-06 19:01:32 | [diff] [blame] | 163 | : new NullAudioSink(media_task_runner_)); |
[email protected] | ec9212f | 2008-12-18 21:40:36 | [diff] [blame] | 164 | } |
| 165 | |
[email protected] | 4e6be3f | 2009-05-07 02:24:44 | [diff] [blame] | 166 | WebMediaPlayerImpl::~WebMediaPlayerImpl() { |
[email protected] | ce70c98 | 2013-12-20 17:04:32 | [diff] [blame] | 167 | client_->setWebLayer(NULL); |
[email protected] | 21c3f750 | 2013-03-23 03:29:51 | [diff] [blame] | 168 | |
acolwell | b403494 | 2014-08-28 15:42:43 | [diff] [blame] | 169 | DCHECK(main_task_runner_->BelongsToCurrentThread()); |
[email protected] | c93eb0a6 | 2011-08-09 22:47:24 | [diff] [blame] | 170 | media_log_->AddEvent( |
acolwell | 9e0840d | 2014-09-06 19:01:32 | [diff] [blame] | 171 | media_log_->CreateEvent(MediaLogEvent::WEBMEDIAPLAYER_DESTROYED)); |
[email protected] | d43ed91 | 2009-02-03 04:52:53 | [diff] [blame] | 172 | |
dalecurtis | 6d269ed | 2014-09-11 21:18:13 | [diff] [blame] | 173 | if (delegate_) |
[email protected] | baff451 | 2011-10-19 18:21:07 | [diff] [blame] | 174 | delegate_->PlayerGone(this); |
| 175 | |
[email protected] | f6af759 | 2014-02-28 10:09:11 | [diff] [blame] | 176 | // Abort any pending IO so stopping the pipeline doesn't get blocked. |
| 177 | if (data_source_) |
| 178 | data_source_->Abort(); |
| 179 | if (chunk_demuxer_) { |
| 180 | chunk_demuxer_->Shutdown(); |
| 181 | chunk_demuxer_ = NULL; |
| 182 | } |
| 183 | |
xhwang | 6fa35620 | 2014-12-11 00:44:12 | [diff] [blame] | 184 | renderer_factory_.reset(); |
[email protected] | f6af759 | 2014-02-28 10:09:11 | [diff] [blame] | 185 | |
| 186 | // Make sure to kill the pipeline so there's no more media threads running. |
| 187 | // Note: stopping the pipeline might block for a long time. |
| 188 | base::WaitableEvent waiter(false, false); |
| 189 | pipeline_.Stop( |
| 190 | base::Bind(&base::WaitableEvent::Signal, base::Unretained(&waiter))); |
| 191 | waiter.Wait(); |
| 192 | |
[email protected] | dd061e1 | 2014-05-06 19:21:22 | [diff] [blame] | 193 | compositor_task_runner_->DeleteSoon(FROM_HERE, compositor_); |
[email protected] | ec9212f | 2008-12-18 21:40:36 | [diff] [blame] | 194 | } |
| 195 | |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame] | 196 | void WebMediaPlayerImpl::load(LoadType load_type, const blink::WebURL& url, |
[email protected] | 62e5e68 | 2013-03-07 23:53:24 | [diff] [blame] | 197 | CORSMode cors_mode) { |
[email protected] | 2a06ca6 | 2014-06-04 13:59:52 | [diff] [blame] | 198 | DVLOG(1) << __FUNCTION__ << "(" << load_type << ", " << url << ", " |
| 199 | << cors_mode << ")"; |
[email protected] | d726eddc | 2013-07-02 22:25:55 | [diff] [blame] | 200 | if (!defer_load_cb_.is_null()) { |
| 201 | defer_load_cb_.Run(base::Bind( |
[email protected] | ef8394c | 2013-08-21 20:26:30 | [diff] [blame] | 202 | &WebMediaPlayerImpl::DoLoad, AsWeakPtr(), load_type, url, cors_mode)); |
[email protected] | d726eddc | 2013-07-02 22:25:55 | [diff] [blame] | 203 | return; |
| 204 | } |
[email protected] | ef8394c | 2013-08-21 20:26:30 | [diff] [blame] | 205 | DoLoad(load_type, url, cors_mode); |
[email protected] | 62e5e68 | 2013-03-07 23:53:24 | [diff] [blame] | 206 | } |
| 207 | |
[email protected] | ef8394c | 2013-08-21 20:26:30 | [diff] [blame] | 208 | void WebMediaPlayerImpl::DoLoad(LoadType load_type, |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame] | 209 | const blink::WebURL& url, |
[email protected] | d726eddc | 2013-07-02 22:25:55 | [diff] [blame] | 210 | CORSMode cors_mode) { |
acolwell | b403494 | 2014-08-28 15:42:43 | [diff] [blame] | 211 | DCHECK(main_task_runner_->BelongsToCurrentThread()); |
[email protected] | d726eddc | 2013-07-02 22:25:55 | [diff] [blame] | 212 | |
[email protected] | 62e5e68 | 2013-03-07 23:53:24 | [diff] [blame] | 213 | GURL gurl(url); |
[email protected] | e2f6bba | 2014-06-09 20:08:07 | [diff] [blame] | 214 | ReportMediaSchemeUma(gurl); |
[email protected] | 62e5e68 | 2013-03-07 23:53:24 | [diff] [blame] | 215 | |
[email protected] | 926f8fd | 2013-04-12 20:27:53 | [diff] [blame] | 216 | // Set subresource URL for crash reporting. |
| 217 | base::debug::SetCrashKeyValue("subresource_url", gurl.spec()); |
| 218 | |
[email protected] | ef8394c | 2013-08-21 20:26:30 | [diff] [blame] | 219 | load_type_ = load_type; |
| 220 | |
[email protected] | 62e5e68 | 2013-03-07 23:53:24 | [diff] [blame] | 221 | SetNetworkState(WebMediaPlayer::NetworkStateLoading); |
| 222 | SetReadyState(WebMediaPlayer::ReadyStateHaveNothing); |
| 223 | media_log_->AddEvent(media_log_->CreateLoadEvent(url.spec())); |
[email protected] | d726eddc | 2013-07-02 22:25:55 | [diff] [blame] | 224 | |
| 225 | // Media source pipelines can start immediately. |
[email protected] | ef8394c | 2013-08-21 20:26:30 | [diff] [blame] | 226 | if (load_type == LoadTypeMediaSource) { |
[email protected] | d726eddc | 2013-07-02 22:25:55 | [diff] [blame] | 227 | supports_save_ = false; |
[email protected] | ef8394c | 2013-08-21 20:26:30 | [diff] [blame] | 228 | StartPipeline(); |
[email protected] | d726eddc | 2013-07-02 22:25:55 | [diff] [blame] | 229 | return; |
| 230 | } |
| 231 | |
| 232 | // Otherwise it's a regular request which requires resolving the URL first. |
| 233 | data_source_.reset(new BufferedDataSource( |
[email protected] | fee8a90 | 2014-06-03 13:43:36 | [diff] [blame] | 234 | url, |
| 235 | static_cast<BufferedResourceLoader::CORSMode>(cors_mode), |
acolwell | b403494 | 2014-08-28 15:42:43 | [diff] [blame] | 236 | main_task_runner_, |
[email protected] | d726eddc | 2013-07-02 22:25:55 | [diff] [blame] | 237 | frame_, |
| 238 | media_log_.get(), |
[email protected] | 6683e1b | 2014-04-10 01:45:38 | [diff] [blame] | 239 | &buffered_data_source_host_, |
[email protected] | d726eddc | 2013-07-02 22:25:55 | [diff] [blame] | 240 | base::Bind(&WebMediaPlayerImpl::NotifyDownloading, AsWeakPtr()))); |
dalecurtis | 9157fc9e | 2015-01-16 01:09:11 | [diff] [blame] | 241 | data_source_->SetPreload(preload_); |
[email protected] | d726eddc | 2013-07-02 22:25:55 | [diff] [blame] | 242 | data_source_->Initialize( |
[email protected] | fee8a90 | 2014-06-03 13:43:36 | [diff] [blame] | 243 | base::Bind(&WebMediaPlayerImpl::DataSourceInitialized, AsWeakPtr())); |
[email protected] | 62e5e68 | 2013-03-07 23:53:24 | [diff] [blame] | 244 | } |
| 245 | |
[email protected] | 4e6be3f | 2009-05-07 02:24:44 | [diff] [blame] | 246 | void WebMediaPlayerImpl::play() { |
[email protected] | 2a06ca6 | 2014-06-04 13:59:52 | [diff] [blame] | 247 | DVLOG(1) << __FUNCTION__; |
acolwell | b403494 | 2014-08-28 15:42:43 | [diff] [blame] | 248 | DCHECK(main_task_runner_->BelongsToCurrentThread()); |
[email protected] | d43ed91 | 2009-02-03 04:52:53 | [diff] [blame] | 249 | |
[email protected] | 4948090 | 2009-07-14 20:23:43 | [diff] [blame] | 250 | paused_ = false; |
[email protected] | f6af759 | 2014-02-28 10:09:11 | [diff] [blame] | 251 | pipeline_.SetPlaybackRate(playback_rate_); |
[email protected] | 039b754 | 2013-10-17 22:06:25 | [diff] [blame] | 252 | if (data_source_) |
| 253 | data_source_->MediaIsPlaying(); |
[email protected] | 090f731 | 2011-08-05 23:26:40 | [diff] [blame] | 254 | |
acolwell | 9e0840d | 2014-09-06 19:01:32 | [diff] [blame] | 255 | media_log_->AddEvent(media_log_->CreateEvent(MediaLogEvent::PLAY)); |
[email protected] | baff451 | 2011-10-19 18:21:07 | [diff] [blame] | 256 | |
dalecurtis | 6d269ed | 2014-09-11 21:18:13 | [diff] [blame] | 257 | if (delegate_ && playback_rate_ > 0) |
[email protected] | baff451 | 2011-10-19 18:21:07 | [diff] [blame] | 258 | delegate_->DidPlay(this); |
[email protected] | ec9212f | 2008-12-18 21:40:36 | [diff] [blame] | 259 | } |
| 260 | |
[email protected] | 4e6be3f | 2009-05-07 02:24:44 | [diff] [blame] | 261 | void WebMediaPlayerImpl::pause() { |
[email protected] | 2a06ca6 | 2014-06-04 13:59:52 | [diff] [blame] | 262 | DVLOG(1) << __FUNCTION__; |
acolwell | b403494 | 2014-08-28 15:42:43 | [diff] [blame] | 263 | DCHECK(main_task_runner_->BelongsToCurrentThread()); |
[email protected] | d43ed91 | 2009-02-03 04:52:53 | [diff] [blame] | 264 | |
dalecurtis | 6d269ed | 2014-09-11 21:18:13 | [diff] [blame] | 265 | const bool was_already_paused = paused_ || playback_rate_ == 0; |
[email protected] | 4948090 | 2009-07-14 20:23:43 | [diff] [blame] | 266 | paused_ = true; |
a.berwal | 338bf00 | 2015-04-22 11:14:50 | [diff] [blame] | 267 | pipeline_.SetPlaybackRate(0.0); |
[email protected] | 039b754 | 2013-10-17 22:06:25 | [diff] [blame] | 268 | if (data_source_) |
| 269 | data_source_->MediaIsPaused(); |
dalecurtis | 2e50e6f6 | 2015-01-09 02:42:52 | [diff] [blame] | 270 | UpdatePausedTime(); |
[email protected] | 090f731 | 2011-08-05 23:26:40 | [diff] [blame] | 271 | |
acolwell | 9e0840d | 2014-09-06 19:01:32 | [diff] [blame] | 272 | media_log_->AddEvent(media_log_->CreateEvent(MediaLogEvent::PAUSE)); |
[email protected] | baff451 | 2011-10-19 18:21:07 | [diff] [blame] | 273 | |
dalecurtis | 6d269ed | 2014-09-11 21:18:13 | [diff] [blame] | 274 | if (!was_already_paused && delegate_) |
[email protected] | baff451 | 2011-10-19 18:21:07 | [diff] [blame] | 275 | delegate_->DidPause(this); |
[email protected] | ec9212f | 2008-12-18 21:40:36 | [diff] [blame] | 276 | } |
| 277 | |
[email protected] | 574a1d6 | 2009-07-17 03:23:46 | [diff] [blame] | 278 | bool WebMediaPlayerImpl::supportsSave() const { |
acolwell | b403494 | 2014-08-28 15:42:43 | [diff] [blame] | 279 | DCHECK(main_task_runner_->BelongsToCurrentThread()); |
[email protected] | 132dd57c | 2012-08-10 23:24:34 | [diff] [blame] | 280 | return supports_save_; |
[email protected] | 574a1d6 | 2009-07-17 03:23:46 | [diff] [blame] | 281 | } |
| 282 | |
[email protected] | 39bdde3 | 2013-04-17 17:44:20 | [diff] [blame] | 283 | void WebMediaPlayerImpl::seek(double seconds) { |
xhwang | 12d8d04 | 2014-12-01 21:48:57 | [diff] [blame] | 284 | DVLOG(1) << __FUNCTION__ << "(" << seconds << "s)"; |
acolwell | b403494 | 2014-08-28 15:42:43 | [diff] [blame] | 285 | DCHECK(main_task_runner_->BelongsToCurrentThread()); |
[email protected] | d43ed91 | 2009-02-03 04:52:53 | [diff] [blame] | 286 | |
scherkus | d2c745b | 2014-09-04 05:03:40 | [diff] [blame] | 287 | ended_ = false; |
| 288 | |
srirama.m | ccf67181 | 2015-01-08 11:59:13 | [diff] [blame] | 289 | ReadyState old_state = ready_state_; |
[email protected] | 1bb66680 | 2013-11-28 06:12:08 | [diff] [blame] | 290 | if (ready_state_ > WebMediaPlayer::ReadyStateHaveMetadata) |
| 291 | SetReadyState(WebMediaPlayer::ReadyStateHaveMetadata); |
| 292 | |
[email protected] | bb8a70b | 2013-06-26 06:23:35 | [diff] [blame] | 293 | base::TimeDelta seek_time = ConvertSecondsToTimestamp(seconds); |
| 294 | |
[email protected] | d228aeec | 2014-06-20 19:16:49 | [diff] [blame] | 295 | if (seeking_) { |
[email protected] | 5d11eff | 2011-09-15 00:06:06 | [diff] [blame] | 296 | pending_seek_ = true; |
| 297 | pending_seek_seconds_ = seconds; |
[email protected] | efe7cd2 | 2012-09-12 23:55:01 | [diff] [blame] | 298 | if (chunk_demuxer_) |
[email protected] | bb8a70b | 2013-06-26 06:23:35 | [diff] [blame] | 299 | chunk_demuxer_->CancelPendingSeek(seek_time); |
[email protected] | 5d11eff | 2011-09-15 00:06:06 | [diff] [blame] | 300 | return; |
| 301 | } |
| 302 | |
[email protected] | c93eb0a6 | 2011-08-09 22:47:24 | [diff] [blame] | 303 | media_log_->AddEvent(media_log_->CreateSeekEvent(seconds)); |
| 304 | |
[email protected] | 44ff37c0 | 2009-10-24 01:03:03 | [diff] [blame] | 305 | // Update our paused time. |
srirama.m | ccf67181 | 2015-01-08 11:59:13 | [diff] [blame] | 306 | // In paused state ignore the seek operations to current time if the loading |
| 307 | // is completed and generate OnPipelineBufferingStateChanged event to |
| 308 | // eventually fire seeking and seeked events |
srirama.m | 36ab268 | 2014-12-11 04:20:01 | [diff] [blame] | 309 | if (paused_) { |
| 310 | if (paused_time_ != seek_time) { |
| 311 | paused_time_ = seek_time; |
srirama.m | ccf67181 | 2015-01-08 11:59:13 | [diff] [blame] | 312 | } else if (old_state == ReadyStateHaveEnoughData) { |
srirama.m | 8f4a3756 | 2014-12-13 08:16:18 | [diff] [blame] | 313 | main_task_runner_->PostTask( |
srirama.m | 36ab268 | 2014-12-11 04:20:01 | [diff] [blame] | 314 | FROM_HERE, |
| 315 | base::Bind(&WebMediaPlayerImpl::OnPipelineBufferingStateChanged, |
srirama.m | 8f4a3756 | 2014-12-13 08:16:18 | [diff] [blame] | 316 | AsWeakPtr(), BUFFERING_HAVE_ENOUGH)); |
srirama.m | 36ab268 | 2014-12-11 04:20:01 | [diff] [blame] | 317 | return; |
| 318 | } |
| 319 | } |
[email protected] | 44ff37c0 | 2009-10-24 01:03:03 | [diff] [blame] | 320 | |
[email protected] | b3766a2 | 2010-12-22 17:34:13 | [diff] [blame] | 321 | seeking_ = true; |
| 322 | |
[email protected] | efe7cd2 | 2012-09-12 23:55:01 | [diff] [blame] | 323 | if (chunk_demuxer_) |
[email protected] | bb8a70b | 2013-06-26 06:23:35 | [diff] [blame] | 324 | chunk_demuxer_->StartWaitingForSeek(seek_time); |
[email protected] | 020fba3 | 2011-06-29 16:37:46 | [diff] [blame] | 325 | |
[email protected] | 44ff37c0 | 2009-10-24 01:03:03 | [diff] [blame] | 326 | // Kick off the asynchronous seek! |
[email protected] | f6af759 | 2014-02-28 10:09:11 | [diff] [blame] | 327 | pipeline_.Seek( |
[email protected] | 44ff37c0 | 2009-10-24 01:03:03 | [diff] [blame] | 328 | seek_time, |
[email protected] | 4e98219 | 2014-06-21 13:35:45 | [diff] [blame] | 329 | BIND_TO_RENDER_LOOP1(&WebMediaPlayerImpl::OnPipelineSeeked, true)); |
[email protected] | ec9212f | 2008-12-18 21:40:36 | [diff] [blame] | 330 | } |
| 331 | |
[email protected] | 39bdde3 | 2013-04-17 17:44:20 | [diff] [blame] | 332 | void WebMediaPlayerImpl::setRate(double rate) { |
[email protected] | 2a06ca6 | 2014-06-04 13:59:52 | [diff] [blame] | 333 | DVLOG(1) << __FUNCTION__ << "(" << rate << ")"; |
acolwell | b403494 | 2014-08-28 15:42:43 | [diff] [blame] | 334 | DCHECK(main_task_runner_->BelongsToCurrentThread()); |
[email protected] | d43ed91 | 2009-02-03 04:52:53 | [diff] [blame] | 335 | |
[email protected] | 378f0b7 | 2009-08-11 17:11:42 | [diff] [blame] | 336 | // TODO(kylep): Remove when support for negatives is added. Also, modify the |
| 337 | // following checks so rewind uses reasonable values also. |
[email protected] | 39bdde3 | 2013-04-17 17:44:20 | [diff] [blame] | 338 | if (rate < 0.0) |
[email protected] | 378f0b7 | 2009-08-11 17:11:42 | [diff] [blame] | 339 | return; |
| 340 | |
| 341 | // Limit rates to reasonable values by clamping. |
[email protected] | 39bdde3 | 2013-04-17 17:44:20 | [diff] [blame] | 342 | if (rate != 0.0) { |
[email protected] | 378f0b7 | 2009-08-11 17:11:42 | [diff] [blame] | 343 | if (rate < kMinRate) |
| 344 | rate = kMinRate; |
| 345 | else if (rate > kMaxRate) |
| 346 | rate = kMaxRate; |
dalecurtis | bb761e1 | 2014-09-12 01:16:35 | [diff] [blame] | 347 | if (playback_rate_ == 0 && !paused_ && delegate_) |
dalecurtis | 6d269ed | 2014-09-11 21:18:13 | [diff] [blame] | 348 | delegate_->DidPlay(this); |
dalecurtis | bb761e1 | 2014-09-12 01:16:35 | [diff] [blame] | 349 | } else if (playback_rate_ != 0 && !paused_ && delegate_) { |
dalecurtis | 6d269ed | 2014-09-11 21:18:13 | [diff] [blame] | 350 | delegate_->DidPause(this); |
[email protected] | 378f0b7 | 2009-08-11 17:11:42 | [diff] [blame] | 351 | } |
| 352 | |
[email protected] | 4948090 | 2009-07-14 20:23:43 | [diff] [blame] | 353 | playback_rate_ = rate; |
| 354 | if (!paused_) { |
[email protected] | f6af759 | 2014-02-28 10:09:11 | [diff] [blame] | 355 | pipeline_.SetPlaybackRate(rate); |
[email protected] | 039b754 | 2013-10-17 22:06:25 | [diff] [blame] | 356 | if (data_source_) |
| 357 | data_source_->MediaPlaybackRateChanged(rate); |
[email protected] | 4948090 | 2009-07-14 20:23:43 | [diff] [blame] | 358 | } |
[email protected] | ec9212f | 2008-12-18 21:40:36 | [diff] [blame] | 359 | } |
| 360 | |
[email protected] | 39bdde3 | 2013-04-17 17:44:20 | [diff] [blame] | 361 | void WebMediaPlayerImpl::setVolume(double volume) { |
[email protected] | 2a06ca6 | 2014-06-04 13:59:52 | [diff] [blame] | 362 | DVLOG(1) << __FUNCTION__ << "(" << volume << ")"; |
acolwell | b403494 | 2014-08-28 15:42:43 | [diff] [blame] | 363 | DCHECK(main_task_runner_->BelongsToCurrentThread()); |
[email protected] | d43ed91 | 2009-02-03 04:52:53 | [diff] [blame] | 364 | |
[email protected] | f6af759 | 2014-02-28 10:09:11 | [diff] [blame] | 365 | pipeline_.SetVolume(volume); |
[email protected] | ec9212f | 2008-12-18 21:40:36 | [diff] [blame] | 366 | } |
[email protected] | f0a51fb5 | 2009-03-05 12:46:38 | [diff] [blame] | 367 | |
mostynb | 502b00b | 2015-01-05 23:43:40 | [diff] [blame] | 368 | #define STATIC_ASSERT_MATCHING_ENUM(webkit_name, chromium_name) \ |
| 369 | static_assert(static_cast<int>(WebMediaPlayer::webkit_name) == \ |
| 370 | static_cast<int>(BufferedDataSource::chromium_name), \ |
| 371 | "mismatching enum values: " #webkit_name) |
| 372 | STATIC_ASSERT_MATCHING_ENUM(PreloadNone, NONE); |
| 373 | STATIC_ASSERT_MATCHING_ENUM(PreloadMetaData, METADATA); |
| 374 | STATIC_ASSERT_MATCHING_ENUM(PreloadAuto, AUTO); |
| 375 | #undef STATIC_ASSERT_MATCHING_ENUM |
[email protected] | 23a8b1d8 | 2011-04-05 16:28:20 | [diff] [blame] | 376 | |
[email protected] | ef405f66b | 2012-04-18 02:39:55 | [diff] [blame] | 377 | void WebMediaPlayerImpl::setPreload(WebMediaPlayer::Preload preload) { |
[email protected] | 2a06ca6 | 2014-06-04 13:59:52 | [diff] [blame] | 378 | DVLOG(1) << __FUNCTION__ << "(" << preload << ")"; |
acolwell | b403494 | 2014-08-28 15:42:43 | [diff] [blame] | 379 | DCHECK(main_task_runner_->BelongsToCurrentThread()); |
[email protected] | 4e6be3f | 2009-05-07 02:24:44 | [diff] [blame] | 380 | |
acolwell | a5081a4 | 2014-08-28 23:42:52 | [diff] [blame] | 381 | preload_ = static_cast<BufferedDataSource::Preload>(preload); |
[email protected] | b49beeb | 2013-03-01 20:04:00 | [diff] [blame] | 382 | if (data_source_) |
[email protected] | 09c6022 | 2014-08-07 16:42:31 | [diff] [blame] | 383 | data_source_->SetPreload(preload_); |
[email protected] | 4e6be3f | 2009-05-07 02:24:44 | [diff] [blame] | 384 | } |
| 385 | |
[email protected] | 4e6be3f | 2009-05-07 02:24:44 | [diff] [blame] | 386 | bool WebMediaPlayerImpl::hasVideo() const { |
acolwell | b403494 | 2014-08-28 15:42:43 | [diff] [blame] | 387 | DCHECK(main_task_runner_->BelongsToCurrentThread()); |
[email protected] | d43ed91 | 2009-02-03 04:52:53 | [diff] [blame] | 388 | |
[email protected] | b887777 | 2014-03-26 20:17:15 | [diff] [blame] | 389 | return pipeline_metadata_.has_video; |
[email protected] | d43ed91 | 2009-02-03 04:52:53 | [diff] [blame] | 390 | } |
| 391 | |
[email protected] | fc367af | 2009-08-14 23:06:35 | [diff] [blame] | 392 | bool WebMediaPlayerImpl::hasAudio() const { |
acolwell | b403494 | 2014-08-28 15:42:43 | [diff] [blame] | 393 | DCHECK(main_task_runner_->BelongsToCurrentThread()); |
[email protected] | fc367af | 2009-08-14 23:06:35 | [diff] [blame] | 394 | |
[email protected] | b887777 | 2014-03-26 20:17:15 | [diff] [blame] | 395 | return pipeline_metadata_.has_audio; |
[email protected] | fc367af | 2009-08-14 23:06:35 | [diff] [blame] | 396 | } |
| 397 | |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame] | 398 | blink::WebSize WebMediaPlayerImpl::naturalSize() const { |
acolwell | b403494 | 2014-08-28 15:42:43 | [diff] [blame] | 399 | DCHECK(main_task_runner_->BelongsToCurrentThread()); |
[email protected] | d43ed91 | 2009-02-03 04:52:53 | [diff] [blame] | 400 | |
[email protected] | b887777 | 2014-03-26 20:17:15 | [diff] [blame] | 401 | return blink::WebSize(pipeline_metadata_.natural_size); |
[email protected] | d43ed91 | 2009-02-03 04:52:53 | [diff] [blame] | 402 | } |
| 403 | |
[email protected] | 4e6be3f | 2009-05-07 02:24:44 | [diff] [blame] | 404 | bool WebMediaPlayerImpl::paused() const { |
acolwell | b403494 | 2014-08-28 15:42:43 | [diff] [blame] | 405 | DCHECK(main_task_runner_->BelongsToCurrentThread()); |
[email protected] | d43ed91 | 2009-02-03 04:52:53 | [diff] [blame] | 406 | |
[email protected] | f6af759 | 2014-02-28 10:09:11 | [diff] [blame] | 407 | return pipeline_.GetPlaybackRate() == 0.0f; |
[email protected] | d43ed91 | 2009-02-03 04:52:53 | [diff] [blame] | 408 | } |
| 409 | |
[email protected] | 4e6be3f | 2009-05-07 02:24:44 | [diff] [blame] | 410 | bool WebMediaPlayerImpl::seeking() const { |
acolwell | b403494 | 2014-08-28 15:42:43 | [diff] [blame] | 411 | DCHECK(main_task_runner_->BelongsToCurrentThread()); |
[email protected] | d43ed91 | 2009-02-03 04:52:53 | [diff] [blame] | 412 | |
[email protected] | ef405f66b | 2012-04-18 02:39:55 | [diff] [blame] | 413 | if (ready_state_ == WebMediaPlayer::ReadyStateHaveNothing) |
[email protected] | 0acebfa | 2009-08-21 22:45:40 | [diff] [blame] | 414 | return false; |
[email protected] | 67cd505 | 2009-09-10 21:53:22 | [diff] [blame] | 415 | |
[email protected] | b3766a2 | 2010-12-22 17:34:13 | [diff] [blame] | 416 | return seeking_; |
[email protected] | ec9212f | 2008-12-18 21:40:36 | [diff] [blame] | 417 | } |
| 418 | |
[email protected] | 39bdde3 | 2013-04-17 17:44:20 | [diff] [blame] | 419 | double WebMediaPlayerImpl::duration() const { |
acolwell | b403494 | 2014-08-28 15:42:43 | [diff] [blame] | 420 | DCHECK(main_task_runner_->BelongsToCurrentThread()); |
[email protected] | 39bdde3 | 2013-04-17 17:44:20 | [diff] [blame] | 421 | |
| 422 | if (ready_state_ == WebMediaPlayer::ReadyStateHaveNothing) |
| 423 | return std::numeric_limits<double>::quiet_NaN(); |
| 424 | |
[email protected] | 39bdde3 | 2013-04-17 17:44:20 | [diff] [blame] | 425 | return GetPipelineDuration(); |
[email protected] | d43ed91 | 2009-02-03 04:52:53 | [diff] [blame] | 426 | } |
| 427 | |
[email protected] | db66d009 | 2014-04-16 07:15:12 | [diff] [blame] | 428 | double WebMediaPlayerImpl::timelineOffset() const { |
acolwell | b403494 | 2014-08-28 15:42:43 | [diff] [blame] | 429 | DCHECK(main_task_runner_->BelongsToCurrentThread()); |
[email protected] | db66d009 | 2014-04-16 07:15:12 | [diff] [blame] | 430 | |
| 431 | if (pipeline_metadata_.timeline_offset.is_null()) |
| 432 | return std::numeric_limits<double>::quiet_NaN(); |
| 433 | |
| 434 | return pipeline_metadata_.timeline_offset.ToJsTime(); |
| 435 | } |
| 436 | |
[email protected] | 39bdde3 | 2013-04-17 17:44:20 | [diff] [blame] | 437 | double WebMediaPlayerImpl::currentTime() const { |
acolwell | b403494 | 2014-08-28 15:42:43 | [diff] [blame] | 438 | DCHECK(main_task_runner_->BelongsToCurrentThread()); |
scherkus | d2c745b | 2014-09-04 05:03:40 | [diff] [blame] | 439 | DCHECK_NE(ready_state_, WebMediaPlayer::ReadyStateHaveNothing); |
| 440 | |
| 441 | // TODO(scherkus): Replace with an explicit ended signal to HTMLMediaElement, |
| 442 | // see http://crbug.com/409280 |
| 443 | if (ended_) |
| 444 | return duration(); |
| 445 | |
[email protected] | f6af759 | 2014-02-28 10:09:11 | [diff] [blame] | 446 | return (paused_ ? paused_time_ : pipeline_.GetMediaTime()).InSecondsF(); |
[email protected] | d43ed91 | 2009-02-03 04:52:53 | [diff] [blame] | 447 | } |
| 448 | |
[email protected] | ef405f66b | 2012-04-18 02:39:55 | [diff] [blame] | 449 | WebMediaPlayer::NetworkState WebMediaPlayerImpl::networkState() const { |
acolwell | b403494 | 2014-08-28 15:42:43 | [diff] [blame] | 450 | DCHECK(main_task_runner_->BelongsToCurrentThread()); |
[email protected] | ddb1e5a | 2010-12-13 20:10:45 | [diff] [blame] | 451 | return network_state_; |
| 452 | } |
| 453 | |
[email protected] | ef405f66b | 2012-04-18 02:39:55 | [diff] [blame] | 454 | WebMediaPlayer::ReadyState WebMediaPlayerImpl::readyState() const { |
acolwell | b403494 | 2014-08-28 15:42:43 | [diff] [blame] | 455 | DCHECK(main_task_runner_->BelongsToCurrentThread()); |
[email protected] | ddb1e5a | 2010-12-13 20:10:45 | [diff] [blame] | 456 | return ready_state_; |
| 457 | } |
| 458 | |
[email protected] | 02022fc | 2014-05-16 00:05:31 | [diff] [blame] | 459 | blink::WebTimeRanges WebMediaPlayerImpl::buffered() const { |
acolwell | b403494 | 2014-08-28 15:42:43 | [diff] [blame] | 460 | DCHECK(main_task_runner_->BelongsToCurrentThread()); |
[email protected] | 779a832 | 2014-08-22 21:28:37 | [diff] [blame] | 461 | |
acolwell | 9e0840d | 2014-09-06 19:01:32 | [diff] [blame] | 462 | Ranges<base::TimeDelta> buffered_time_ranges = |
[email protected] | 02022fc | 2014-05-16 00:05:31 | [diff] [blame] | 463 | pipeline_.GetBufferedTimeRanges(); |
[email protected] | 779a832 | 2014-08-22 21:28:37 | [diff] [blame] | 464 | |
| 465 | const base::TimeDelta duration = pipeline_.GetMediaDuration(); |
acolwell | 9e0840d | 2014-09-06 19:01:32 | [diff] [blame] | 466 | if (duration != kInfiniteDuration()) { |
[email protected] | 779a832 | 2014-08-22 21:28:37 | [diff] [blame] | 467 | buffered_data_source_host_.AddBufferedTimeRanges( |
| 468 | &buffered_time_ranges, duration); |
| 469 | } |
[email protected] | 02022fc | 2014-05-16 00:05:31 | [diff] [blame] | 470 | return ConvertToWebTimeRanges(buffered_time_ranges); |
| 471 | } |
| 472 | |
philipj | b0e6f3f | 2014-09-30 09:51:53 | [diff] [blame] | 473 | blink::WebTimeRanges WebMediaPlayerImpl::seekable() const { |
acolwell | b403494 | 2014-08-28 15:42:43 | [diff] [blame] | 474 | DCHECK(main_task_runner_->BelongsToCurrentThread()); |
[email protected] | 39bdde3 | 2013-04-17 17:44:20 | [diff] [blame] | 475 | |
dalecurtis | 56359cb | 2014-10-28 00:06:29 | [diff] [blame] | 476 | if (ready_state_ < WebMediaPlayer::ReadyStateHaveMetadata) |
philipj | b0e6f3f | 2014-09-30 09:51:53 | [diff] [blame] | 477 | return blink::WebTimeRanges(); |
| 478 | |
dalecurtis | 56359cb | 2014-10-28 00:06:29 | [diff] [blame] | 479 | const double seekable_end = duration(); |
| 480 | |
| 481 | // Allow a special exception for seeks to zero for streaming sources with a |
| 482 | // finite duration; this allows looping to work. |
| 483 | const bool allow_seek_to_zero = data_source_ && data_source_->IsStreaming() && |
mateuszs | 3371ab0 | 2015-04-24 13:20:23 | [diff] [blame] | 484 | std::isfinite(seekable_end); |
dalecurtis | 56359cb | 2014-10-28 00:06:29 | [diff] [blame] | 485 | |
| 486 | // TODO(dalecurtis): Technically this allows seeking on media which return an |
| 487 | // infinite duration so long as DataSource::IsStreaming() is false. While not |
| 488 | // expected, disabling this breaks semi-live players, http://crbug.com/427412. |
| 489 | const blink::WebTimeRange seekable_range( |
| 490 | 0.0, allow_seek_to_zero ? 0.0 : seekable_end); |
philipj | b0e6f3f | 2014-09-30 09:51:53 | [diff] [blame] | 491 | return blink::WebTimeRanges(&seekable_range, 1); |
[email protected] | ec9212f | 2008-12-18 21:40:36 | [diff] [blame] | 492 | } |
| 493 | |
[email protected] | 5d2b3e4c | 2014-05-12 23:27:30 | [diff] [blame] | 494 | bool WebMediaPlayerImpl::didLoadingProgress() { |
acolwell | b403494 | 2014-08-28 15:42:43 | [diff] [blame] | 495 | DCHECK(main_task_runner_->BelongsToCurrentThread()); |
[email protected] | 6683e1b | 2014-04-10 01:45:38 | [diff] [blame] | 496 | bool pipeline_progress = pipeline_.DidLoadingProgress(); |
| 497 | bool data_progress = buffered_data_source_host_.DidLoadingProgress(); |
| 498 | return pipeline_progress || data_progress; |
[email protected] | d43ed91 | 2009-02-03 04:52:53 | [diff] [blame] | 499 | } |
| 500 | |
[email protected] | dd5c797 | 2014-08-21 15:00:37 | [diff] [blame] | 501 | void WebMediaPlayerImpl::paint(blink::WebCanvas* canvas, |
| 502 | const blink::WebRect& rect, |
[email protected] | dd5c797 | 2014-08-21 15:00:37 | [diff] [blame] | 503 | unsigned char alpha, |
| 504 | SkXfermode::Mode mode) { |
acolwell | b403494 | 2014-08-28 15:42:43 | [diff] [blame] | 505 | DCHECK(main_task_runner_->BelongsToCurrentThread()); |
[email protected] | dd061e1 | 2014-05-06 19:21:22 | [diff] [blame] | 506 | TRACE_EVENT0("media", "WebMediaPlayerImpl:paint"); |
[email protected] | 4e6be3f | 2009-05-07 02:24:44 | [diff] [blame] | 507 | |
[email protected] | 5e1502e | 2014-03-24 22:48:44 | [diff] [blame] | 508 | // TODO(scherkus): Clarify paint() API contract to better understand when and |
| 509 | // why it's being called. For example, today paint() is called when: |
| 510 | // - We haven't reached HAVE_CURRENT_DATA and need to paint black |
| 511 | // - We're painting to a canvas |
| 512 | // See http://crbug.com/341225 http://crbug.com/342621 for details. |
mcasas | f1236fc2 | 2015-05-29 22:38:56 | [diff] [blame^] | 513 | scoped_refptr<VideoFrame> video_frame = GetCurrentFrameFromCompositor(); |
[email protected] | 0fe5d43b | 2014-01-24 23:32:45 | [diff] [blame] | 514 | |
[email protected] | b49beeb | 2013-03-01 20:04:00 | [diff] [blame] | 515 | gfx::Rect gfx_rect(rect); |
dongseong.hwang | 0c4e9d8 | 2015-01-08 20:11:13 | [diff] [blame] | 516 | Context3D context_3d; |
| 517 | if (video_frame.get() && |
mcasas | f1236fc2 | 2015-05-29 22:38:56 | [diff] [blame^] | 518 | video_frame->storage_type() == VideoFrame::STORAGE_TEXTURE) { |
| 519 | if (!context_3d_cb_.is_null()) |
dongseong.hwang | 0c4e9d8 | 2015-01-08 20:11:13 | [diff] [blame] | 520 | context_3d = context_3d_cb_.Run(); |
dongseong.hwang | 0c4e9d8 | 2015-01-08 20:11:13 | [diff] [blame] | 521 | // GPU Process crashed. |
| 522 | if (!context_3d.gl) |
| 523 | return; |
| 524 | } |
| 525 | skcanvas_video_renderer_.Paint(video_frame, canvas, gfx_rect, alpha, mode, |
| 526 | pipeline_metadata_.video_rotation, context_3d); |
[email protected] | ec9212f | 2008-12-18 21:40:36 | [diff] [blame] | 527 | } |
[email protected] | 5df5165 | 2009-01-17 00:03:00 | [diff] [blame] | 528 | |
[email protected] | 38259a7a8 | 2009-07-29 21:49:49 | [diff] [blame] | 529 | bool WebMediaPlayerImpl::hasSingleSecurityOrigin() const { |
[email protected] | b49beeb | 2013-03-01 20:04:00 | [diff] [blame] | 530 | if (data_source_) |
| 531 | return data_source_->HasSingleOrigin(); |
[email protected] | fcdb746 | 2009-10-21 21:05:11 | [diff] [blame] | 532 | return true; |
[email protected] | 38259a7a8 | 2009-07-29 21:49:49 | [diff] [blame] | 533 | } |
| 534 | |
[email protected] | 3fe2711 | 2012-06-07 04:00:01 | [diff] [blame] | 535 | bool WebMediaPlayerImpl::didPassCORSAccessCheck() const { |
[email protected] | b49beeb | 2013-03-01 20:04:00 | [diff] [blame] | 536 | if (data_source_) |
| 537 | return data_source_->DidPassCORSAccessCheck(); |
| 538 | return false; |
[email protected] | 3fe2711 | 2012-06-07 04:00:01 | [diff] [blame] | 539 | } |
| 540 | |
[email protected] | 39bdde3 | 2013-04-17 17:44:20 | [diff] [blame] | 541 | double WebMediaPlayerImpl::mediaTimeForTimeValue(double timeValue) const { |
[email protected] | e06e16d8 | 2011-05-26 22:13:33 | [diff] [blame] | 542 | return ConvertSecondsToTimestamp(timeValue).InSecondsF(); |
| 543 | } |
| 544 | |
[email protected] | d82b18ae | 2011-03-23 21:28:59 | [diff] [blame] | 545 | unsigned WebMediaPlayerImpl::decodedFrameCount() const { |
acolwell | b403494 | 2014-08-28 15:42:43 | [diff] [blame] | 546 | DCHECK(main_task_runner_->BelongsToCurrentThread()); |
[email protected] | 4c51bc66 | 2011-02-16 02:03:16 | [diff] [blame] | 547 | |
acolwell | 9e0840d | 2014-09-06 19:01:32 | [diff] [blame] | 548 | PipelineStatistics stats = pipeline_.GetStatistics(); |
[email protected] | 4c51bc66 | 2011-02-16 02:03:16 | [diff] [blame] | 549 | return stats.video_frames_decoded; |
| 550 | } |
| 551 | |
[email protected] | d82b18ae | 2011-03-23 21:28:59 | [diff] [blame] | 552 | unsigned WebMediaPlayerImpl::droppedFrameCount() const { |
acolwell | b403494 | 2014-08-28 15:42:43 | [diff] [blame] | 553 | DCHECK(main_task_runner_->BelongsToCurrentThread()); |
[email protected] | 4c51bc66 | 2011-02-16 02:03:16 | [diff] [blame] | 554 | |
acolwell | 9e0840d | 2014-09-06 19:01:32 | [diff] [blame] | 555 | PipelineStatistics stats = pipeline_.GetStatistics(); |
[email protected] | dd061e1 | 2014-05-06 19:21:22 | [diff] [blame] | 556 | return stats.video_frames_dropped; |
[email protected] | 4c51bc66 | 2011-02-16 02:03:16 | [diff] [blame] | 557 | } |
| 558 | |
[email protected] | d82b18ae | 2011-03-23 21:28:59 | [diff] [blame] | 559 | unsigned WebMediaPlayerImpl::audioDecodedByteCount() const { |
acolwell | b403494 | 2014-08-28 15:42:43 | [diff] [blame] | 560 | DCHECK(main_task_runner_->BelongsToCurrentThread()); |
[email protected] | 4c51bc66 | 2011-02-16 02:03:16 | [diff] [blame] | 561 | |
acolwell | 9e0840d | 2014-09-06 19:01:32 | [diff] [blame] | 562 | PipelineStatistics stats = pipeline_.GetStatistics(); |
[email protected] | 4c51bc66 | 2011-02-16 02:03:16 | [diff] [blame] | 563 | return stats.audio_bytes_decoded; |
| 564 | } |
| 565 | |
[email protected] | d82b18ae | 2011-03-23 21:28:59 | [diff] [blame] | 566 | unsigned WebMediaPlayerImpl::videoDecodedByteCount() const { |
acolwell | b403494 | 2014-08-28 15:42:43 | [diff] [blame] | 567 | DCHECK(main_task_runner_->BelongsToCurrentThread()); |
[email protected] | 4c51bc66 | 2011-02-16 02:03:16 | [diff] [blame] | 568 | |
acolwell | 9e0840d | 2014-09-06 19:01:32 | [diff] [blame] | 569 | PipelineStatistics stats = pipeline_.GetStatistics(); |
[email protected] | 4c51bc66 | 2011-02-16 02:03:16 | [diff] [blame] | 570 | return stats.video_bytes_decoded; |
| 571 | } |
| 572 | |
[email protected] | 6523b24 | 2013-03-13 11:10:07 | [diff] [blame] | 573 | bool WebMediaPlayerImpl::copyVideoTextureToPlatformTexture( |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame] | 574 | blink::WebGraphicsContext3D* web_graphics_context, |
[email protected] | 6523b24 | 2013-03-13 11:10:07 | [diff] [blame] | 575 | unsigned int texture, |
| 576 | unsigned int level, |
| 577 | unsigned int internal_format, |
[email protected] | 9aa2b278 | 2013-05-14 00:13:31 | [diff] [blame] | 578 | unsigned int type, |
[email protected] | 6523b24 | 2013-03-13 11:10:07 | [diff] [blame] | 579 | bool premultiply_alpha, |
| 580 | bool flip_y) { |
dongseong.hwang | 46305b1 | 2015-03-05 18:28:04 | [diff] [blame] | 581 | return copyVideoTextureToPlatformTexture(web_graphics_context, texture, |
| 582 | internal_format, type, |
| 583 | premultiply_alpha, flip_y); |
| 584 | } |
| 585 | |
| 586 | bool WebMediaPlayerImpl::copyVideoTextureToPlatformTexture( |
| 587 | blink::WebGraphicsContext3D* web_graphics_context, |
| 588 | unsigned int texture, |
| 589 | unsigned int internal_format, |
| 590 | unsigned int type, |
| 591 | bool premultiply_alpha, |
| 592 | bool flip_y) { |
[email protected] | bfc05f2 | 2013-10-19 17:55:16 | [diff] [blame] | 593 | TRACE_EVENT0("media", "WebMediaPlayerImpl:copyVideoTextureToPlatformTexture"); |
| 594 | |
mcasas | f1236fc2 | 2015-05-29 22:38:56 | [diff] [blame^] | 595 | scoped_refptr<VideoFrame> video_frame = GetCurrentFrameFromCompositor(); |
[email protected] | dd061e1 | 2014-05-06 19:21:22 | [diff] [blame] | 596 | |
dongseong.hwang | 0c4e9d8 | 2015-01-08 20:11:13 | [diff] [blame] | 597 | if (!video_frame.get() || |
mcasas | f1236fc2 | 2015-05-29 22:38:56 | [diff] [blame^] | 598 | video_frame->storage_type() != VideoFrame::STORAGE_TEXTURE) { |
[email protected] | e56f88c7 | 2013-06-25 22:31:29 | [diff] [blame] | 599 | return false; |
dongseong.hwang | 0c4e9d8 | 2015-01-08 20:11:13 | [diff] [blame] | 600 | } |
[email protected] | df41e25 | 2014-02-03 23:39:50 | [diff] [blame] | 601 | |
dongseong.hwang | 0c4e9d8 | 2015-01-08 20:11:13 | [diff] [blame] | 602 | // TODO(dshwang): need more elegant way to convert WebGraphicsContext3D to |
| 603 | // GLES2Interface. |
| 604 | gpu::gles2::GLES2Interface* gl = |
| 605 | static_cast<gpu_blink::WebGraphicsContext3DImpl*>(web_graphics_context) |
| 606 | ->GetGLInterface(); |
| 607 | SkCanvasVideoRenderer::CopyVideoFrameTextureToGLTexture( |
dongseong.hwang | 46305b1 | 2015-03-05 18:28:04 | [diff] [blame] | 608 | gl, video_frame.get(), texture, internal_format, type, premultiply_alpha, |
| 609 | flip_y); |
[email protected] | e56f88c7 | 2013-06-25 22:31:29 | [diff] [blame] | 610 | return true; |
[email protected] | 6523b24 | 2013-03-13 11:10:07 | [diff] [blame] | 611 | } |
| 612 | |
[email protected] | 2ca7d5c | 2012-10-23 07:30:54 | [diff] [blame] | 613 | WebMediaPlayer::MediaKeyException |
[email protected] | f7a6b99 | 2012-04-19 09:45:56 | [diff] [blame] | 614 | WebMediaPlayerImpl::generateKeyRequest(const WebString& key_system, |
| 615 | const unsigned char* init_data, |
| 616 | unsigned init_data_length) { |
acolwell | b403494 | 2014-08-28 15:42:43 | [diff] [blame] | 617 | DCHECK(main_task_runner_->BelongsToCurrentThread()); |
[email protected] | 7502ef1 | 2014-01-25 01:19:27 | [diff] [blame] | 618 | |
xhwang | 16ff136 | 2014-11-19 00:16:34 | [diff] [blame] | 619 | return encrypted_media_support_.GenerateKeyRequest( |
acolwell | e2ea518 | 2014-08-25 23:01:07 | [diff] [blame] | 620 | frame_, key_system, init_data, init_data_length); |
[email protected] | f7a6b99 | 2012-04-19 09:45:56 | [diff] [blame] | 621 | } |
| 622 | |
[email protected] | 2ca7d5c | 2012-10-23 07:30:54 | [diff] [blame] | 623 | WebMediaPlayer::MediaKeyException WebMediaPlayerImpl::addKey( |
| 624 | const WebString& key_system, |
| 625 | const unsigned char* key, |
| 626 | unsigned key_length, |
| 627 | const unsigned char* init_data, |
| 628 | unsigned init_data_length, |
| 629 | const WebString& session_id) { |
acolwell | b403494 | 2014-08-28 15:42:43 | [diff] [blame] | 630 | DCHECK(main_task_runner_->BelongsToCurrentThread()); |
[email protected] | f7a6b99 | 2012-04-19 09:45:56 | [diff] [blame] | 631 | |
xhwang | 16ff136 | 2014-11-19 00:16:34 | [diff] [blame] | 632 | return encrypted_media_support_.AddKey( |
acolwell | e2ea518 | 2014-08-25 23:01:07 | [diff] [blame] | 633 | key_system, key, key_length, init_data, init_data_length, session_id); |
[email protected] | f7a6b99 | 2012-04-19 09:45:56 | [diff] [blame] | 634 | } |
| 635 | |
[email protected] | 2ca7d5c | 2012-10-23 07:30:54 | [diff] [blame] | 636 | WebMediaPlayer::MediaKeyException WebMediaPlayerImpl::cancelKeyRequest( |
| 637 | const WebString& key_system, |
| 638 | const WebString& session_id) { |
acolwell | b403494 | 2014-08-28 15:42:43 | [diff] [blame] | 639 | DCHECK(main_task_runner_->BelongsToCurrentThread()); |
[email protected] | 0b9999d | 2014-02-20 02:16:11 | [diff] [blame] | 640 | |
xhwang | 16ff136 | 2014-11-19 00:16:34 | [diff] [blame] | 641 | return encrypted_media_support_.CancelKeyRequest(key_system, session_id); |
[email protected] | f7a6b99 | 2012-04-19 09:45:56 | [diff] [blame] | 642 | } |
| 643 | |
[email protected] | 7bce183 | 2014-01-09 00:01:22 | [diff] [blame] | 644 | void WebMediaPlayerImpl::setContentDecryptionModule( |
[email protected] | 9ebc3b03f | 2014-08-13 04:01:23 | [diff] [blame] | 645 | blink::WebContentDecryptionModule* cdm, |
| 646 | blink::WebContentDecryptionModuleResult result) { |
acolwell | b403494 | 2014-08-28 15:42:43 | [diff] [blame] | 647 | DCHECK(main_task_runner_->BelongsToCurrentThread()); |
[email protected] | 9ebc3b03f | 2014-08-13 04:01:23 | [diff] [blame] | 648 | |
xhwang | 97de420 | 2014-11-25 08:44:01 | [diff] [blame] | 649 | // TODO(xhwang): Support setMediaKeys(0) if necessary: http://crbug.com/330324 |
| 650 | if (!cdm) { |
| 651 | result.completeWithError( |
| 652 | blink::WebContentDecryptionModuleExceptionNotSupportedError, 0, |
| 653 | "Null MediaKeys object is not supported."); |
| 654 | return; |
| 655 | } |
| 656 | |
xhwang | 9bd8c73 | 2015-04-13 23:27:53 | [diff] [blame] | 657 | SetCdm(BIND_TO_RENDER_LOOP1(&WebMediaPlayerImpl::OnCdmAttached, result), |
| 658 | ToWebContentDecryptionModuleImpl(cdm)->GetCdmContext()); |
xhwang | 97de420 | 2014-11-25 08:44:01 | [diff] [blame] | 659 | } |
| 660 | |
xhwang | e8c4181a | 2014-12-06 08:10:01 | [diff] [blame] | 661 | void WebMediaPlayerImpl::OnEncryptedMediaInitData( |
jrummell | cf78967c | 2015-04-03 05:03:58 | [diff] [blame] | 662 | EmeInitDataType init_data_type, |
xhwang | e8c4181a | 2014-12-06 08:10:01 | [diff] [blame] | 663 | const std::vector<uint8>& init_data) { |
jrummell | cf78967c | 2015-04-03 05:03:58 | [diff] [blame] | 664 | DCHECK(init_data_type != EmeInitDataType::UNKNOWN); |
xhwang | bab66f5 | 2014-12-02 23:49:50 | [diff] [blame] | 665 | |
xhwang | e8c4181a | 2014-12-06 08:10:01 | [diff] [blame] | 666 | // Do not fire "encrypted" event if encrypted media is not enabled. |
xhwang | bab66f5 | 2014-12-02 23:49:50 | [diff] [blame] | 667 | // TODO(xhwang): Handle this in |client_|. |
| 668 | if (!blink::WebRuntimeFeatures::isPrefixedEncryptedMediaEnabled() && |
| 669 | !blink::WebRuntimeFeatures::isEncryptedMediaEnabled()) { |
| 670 | return; |
| 671 | } |
| 672 | |
xhwang | e8c4181a | 2014-12-06 08:10:01 | [diff] [blame] | 673 | // TODO(xhwang): Update this UMA name. |
xhwang | bab66f5 | 2014-12-02 23:49:50 | [diff] [blame] | 674 | UMA_HISTOGRAM_COUNTS("Media.EME.NeedKey", 1); |
| 675 | |
| 676 | encrypted_media_support_.SetInitDataType(init_data_type); |
| 677 | |
jrummell | cf78967c | 2015-04-03 05:03:58 | [diff] [blame] | 678 | client_->encrypted(ConvertToWebInitDataType(init_data_type), |
| 679 | vector_as_array(&init_data), |
| 680 | base::saturated_cast<unsigned int>(init_data.size())); |
xhwang | bab66f5 | 2014-12-02 23:49:50 | [diff] [blame] | 681 | } |
| 682 | |
jrummell | 74fc4f94 | 2015-03-02 22:48:27 | [diff] [blame] | 683 | void WebMediaPlayerImpl::OnWaitingForDecryptionKey() { |
| 684 | client_->didBlockPlaybackWaitingForKey(); |
| 685 | |
| 686 | // TODO(jrummell): didResumePlaybackBlockedForKey() should only be called |
| 687 | // when a key has been successfully added (e.g. OnSessionKeysChange() with |
| 688 | // |has_additional_usable_key| = true). http://crbug.com/461903 |
| 689 | client_->didResumePlaybackBlockedForKey(); |
| 690 | } |
| 691 | |
xhwang | 9bd8c73 | 2015-04-13 23:27:53 | [diff] [blame] | 692 | void WebMediaPlayerImpl::SetCdm(const CdmAttachedCB& cdm_attached_cb, |
| 693 | CdmContext* cdm_context) { |
jrummell | 87a2db5 | 2015-05-05 22:27:18 | [diff] [blame] | 694 | // If CDM initialization succeeded, tell the pipeline about it. |
| 695 | if (cdm_context) |
| 696 | pipeline_.SetCdm(cdm_context, cdm_attached_cb); |
xhwang | 97de420 | 2014-11-25 08:44:01 | [diff] [blame] | 697 | } |
| 698 | |
| 699 | void WebMediaPlayerImpl::OnCdmAttached( |
| 700 | blink::WebContentDecryptionModuleResult result, |
| 701 | bool success) { |
| 702 | if (success) { |
| 703 | result.complete(); |
| 704 | return; |
| 705 | } |
| 706 | |
| 707 | result.completeWithError( |
| 708 | blink::WebContentDecryptionModuleExceptionNotSupportedError, 0, |
| 709 | "Unable to set MediaKeys object"); |
[email protected] | 9ebc3b03f | 2014-08-13 04:01:23 | [diff] [blame] | 710 | } |
| 711 | |
[email protected] | 4e98219 | 2014-06-21 13:35:45 | [diff] [blame] | 712 | void WebMediaPlayerImpl::OnPipelineSeeked(bool time_changed, |
| 713 | PipelineStatus status) { |
| 714 | DVLOG(1) << __FUNCTION__ << "(" << time_changed << ", " << status << ")"; |
acolwell | b403494 | 2014-08-28 15:42:43 | [diff] [blame] | 715 | DCHECK(main_task_runner_->BelongsToCurrentThread()); |
[email protected] | 5d11eff | 2011-09-15 00:06:06 | [diff] [blame] | 716 | seeking_ = false; |
| 717 | if (pending_seek_) { |
| 718 | pending_seek_ = false; |
| 719 | seek(pending_seek_seconds_); |
| 720 | return; |
| 721 | } |
| 722 | |
acolwell | 9e0840d | 2014-09-06 19:01:32 | [diff] [blame] | 723 | if (status != PIPELINE_OK) { |
[email protected] | 10a64d9 | 2012-04-10 21:08:02 | [diff] [blame] | 724 | OnPipelineError(status); |
| 725 | return; |
[email protected] | 9670691 | 2009-07-15 17:18:05 | [diff] [blame] | 726 | } |
[email protected] | 10a64d9 | 2012-04-10 21:08:02 | [diff] [blame] | 727 | |
| 728 | // Update our paused time. |
| 729 | if (paused_) |
dalecurtis | 2e50e6f6 | 2015-01-09 02:42:52 | [diff] [blame] | 730 | UpdatePausedTime(); |
[email protected] | 10a64d9 | 2012-04-10 21:08:02 | [diff] [blame] | 731 | |
[email protected] | ba7d5f9 | 2014-06-24 05:37:40 | [diff] [blame] | 732 | should_notify_time_changed_ = time_changed; |
[email protected] | 8931c41a | 2009-07-07 17:31:49 | [diff] [blame] | 733 | } |
| 734 | |
[email protected] | 6954fe1 | 2013-01-03 03:22:32 | [diff] [blame] | 735 | void WebMediaPlayerImpl::OnPipelineEnded() { |
[email protected] | 2a06ca6 | 2014-06-04 13:59:52 | [diff] [blame] | 736 | DVLOG(1) << __FUNCTION__; |
acolwell | b403494 | 2014-08-28 15:42:43 | [diff] [blame] | 737 | DCHECK(main_task_runner_->BelongsToCurrentThread()); |
scherkus | d2c745b | 2014-09-04 05:03:40 | [diff] [blame] | 738 | |
| 739 | // Ignore state changes until we've completed all outstanding seeks. |
| 740 | if (seeking_ || pending_seek_) |
| 741 | return; |
| 742 | |
| 743 | ended_ = true; |
[email protected] | ce70c98 | 2013-12-20 17:04:32 | [diff] [blame] | 744 | client_->timeChanged(); |
[email protected] | 57653784 | 2009-08-12 23:52:05 | [diff] [blame] | 745 | } |
| 746 | |
[email protected] | a9590c2 | 2011-03-16 16:57:02 | [diff] [blame] | 747 | void WebMediaPlayerImpl::OnPipelineError(PipelineStatus error) { |
acolwell | b403494 | 2014-08-28 15:42:43 | [diff] [blame] | 748 | DCHECK(main_task_runner_->BelongsToCurrentThread()); |
acolwell | 9e0840d | 2014-09-06 19:01:32 | [diff] [blame] | 749 | DCHECK_NE(error, PIPELINE_OK); |
[email protected] | a8e2cb8 | 2012-08-17 00:02:39 | [diff] [blame] | 750 | |
| 751 | if (ready_state_ == WebMediaPlayer::ReadyStateHaveNothing) { |
| 752 | // Any error that occurs before reaching ReadyStateHaveMetadata should |
| 753 | // be considered a format error. |
| 754 | SetNetworkState(WebMediaPlayer::NetworkStateFormatError); |
[email protected] | a8e2cb8 | 2012-08-17 00:02:39 | [diff] [blame] | 755 | return; |
| 756 | } |
| 757 | |
[email protected] | be57ee5 | 2013-05-28 22:27:27 | [diff] [blame] | 758 | SetNetworkState(PipelineErrorToNetworkState(error)); |
[email protected] | a9590c2 | 2011-03-16 16:57:02 | [diff] [blame] | 759 | |
acolwell | 9e0840d | 2014-09-06 19:01:32 | [diff] [blame] | 760 | if (error == PIPELINE_ERROR_DECRYPT) |
xhwang | 16ff136 | 2014-11-19 00:16:34 | [diff] [blame] | 761 | encrypted_media_support_.OnPipelineDecryptError(); |
[email protected] | db190487d | 2009-07-30 18:51:52 | [diff] [blame] | 762 | } |
| 763 | |
[email protected] | b887777 | 2014-03-26 20:17:15 | [diff] [blame] | 764 | void WebMediaPlayerImpl::OnPipelineMetadata( |
acolwell | 9e0840d | 2014-09-06 19:01:32 | [diff] [blame] | 765 | PipelineMetadata metadata) { |
[email protected] | 2a06ca6 | 2014-06-04 13:59:52 | [diff] [blame] | 766 | DVLOG(1) << __FUNCTION__; |
[email protected] | a8e2cb8 | 2012-08-17 00:02:39 | [diff] [blame] | 767 | |
[email protected] | b887777 | 2014-03-26 20:17:15 | [diff] [blame] | 768 | pipeline_metadata_ = metadata; |
[email protected] | 739847c0 | 2014-01-16 00:12:25 | [diff] [blame] | 769 | |
dalecurtis | 849cf4b2 | 2015-03-27 18:35:45 | [diff] [blame] | 770 | UMA_HISTOGRAM_ENUMERATION("Media.VideoRotation", metadata.video_rotation, |
acolwell | 9e0840d | 2014-09-06 19:01:32 | [diff] [blame] | 771 | VIDEO_ROTATION_MAX + 1); |
[email protected] | b887777 | 2014-03-26 20:17:15 | [diff] [blame] | 772 | SetReadyState(WebMediaPlayer::ReadyStateHaveMetadata); |
[email protected] | 21c3f750 | 2013-03-23 03:29:51 | [diff] [blame] | 773 | |
[email protected] | b887777 | 2014-03-26 20:17:15 | [diff] [blame] | 774 | if (hasVideo()) { |
| 775 | DCHECK(!video_weblayer_); |
[email protected] | f78c3e8 | 2014-08-08 01:24:47 | [diff] [blame] | 776 | scoped_refptr<cc::VideoLayer> layer = |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 777 | cc::VideoLayer::Create(cc_blink::WebLayerImpl::LayerSettings(), |
| 778 | compositor_, pipeline_metadata_.video_rotation); |
[email protected] | f78c3e8 | 2014-08-08 01:24:47 | [diff] [blame] | 779 | |
acolwell | 9e0840d | 2014-09-06 19:01:32 | [diff] [blame] | 780 | if (pipeline_metadata_.video_rotation == VIDEO_ROTATION_90 || |
| 781 | pipeline_metadata_.video_rotation == VIDEO_ROTATION_270) { |
[email protected] | f78c3e8 | 2014-08-08 01:24:47 | [diff] [blame] | 782 | gfx::Size size = pipeline_metadata_.natural_size; |
| 783 | pipeline_metadata_.natural_size = gfx::Size(size.height(), size.width()); |
| 784 | } |
| 785 | |
[email protected] | 3856462 | 2014-08-19 02:47:18 | [diff] [blame] | 786 | video_weblayer_.reset(new cc_blink::WebLayerImpl(layer)); |
[email protected] | 75e145a | 2014-04-15 17:44:32 | [diff] [blame] | 787 | video_weblayer_->setOpaque(opaque_); |
[email protected] | a7c4f58 | 2014-04-16 18:44:49 | [diff] [blame] | 788 | client_->setWebLayer(video_weblayer_.get()); |
[email protected] | a8e2cb8 | 2012-08-17 00:02:39 | [diff] [blame] | 789 | } |
[email protected] | a8e2cb8 | 2012-08-17 00:02:39 | [diff] [blame] | 790 | } |
| 791 | |
[email protected] | ba7d5f9 | 2014-06-24 05:37:40 | [diff] [blame] | 792 | void WebMediaPlayerImpl::OnPipelineBufferingStateChanged( |
acolwell | 9e0840d | 2014-09-06 19:01:32 | [diff] [blame] | 793 | BufferingState buffering_state) { |
[email protected] | ba7d5f9 | 2014-06-24 05:37:40 | [diff] [blame] | 794 | DVLOG(1) << __FUNCTION__ << "(" << buffering_state << ")"; |
[email protected] | b887777 | 2014-03-26 20:17:15 | [diff] [blame] | 795 | |
[email protected] | ba7d5f9 | 2014-06-24 05:37:40 | [diff] [blame] | 796 | // Ignore buffering state changes until we've completed all outstanding seeks. |
| 797 | if (seeking_ || pending_seek_) |
| 798 | return; |
[email protected] | b887777 | 2014-03-26 20:17:15 | [diff] [blame] | 799 | |
[email protected] | ba7d5f9 | 2014-06-24 05:37:40 | [diff] [blame] | 800 | // TODO(scherkus): Handle other buffering states when Pipeline starts using |
| 801 | // them and translate them ready state changes http://crbug.com/144683 |
acolwell | 9e0840d | 2014-09-06 19:01:32 | [diff] [blame] | 802 | DCHECK_EQ(buffering_state, BUFFERING_HAVE_ENOUGH); |
[email protected] | ba7d5f9 | 2014-06-24 05:37:40 | [diff] [blame] | 803 | SetReadyState(WebMediaPlayer::ReadyStateHaveEnoughData); |
| 804 | |
dalecurtis | 849cf4b2 | 2015-03-27 18:35:45 | [diff] [blame] | 805 | // Let the DataSource know we have enough data. It may use this information to |
| 806 | // release unused network connections. |
| 807 | if (data_source_) |
| 808 | data_source_->OnBufferingHaveEnough(); |
| 809 | |
[email protected] | ba7d5f9 | 2014-06-24 05:37:40 | [diff] [blame] | 810 | // Blink expects a timeChanged() in response to a seek(). |
| 811 | if (should_notify_time_changed_) |
| 812 | client_->timeChanged(); |
[email protected] | b887777 | 2014-03-26 20:17:15 | [diff] [blame] | 813 | } |
| 814 | |
[email protected] | ef8394c | 2013-08-21 20:26:30 | [diff] [blame] | 815 | void WebMediaPlayerImpl::OnDemuxerOpened() { |
acolwell | b403494 | 2014-08-28 15:42:43 | [diff] [blame] | 816 | DCHECK(main_task_runner_->BelongsToCurrentThread()); |
[email protected] | ce70c98 | 2013-12-20 17:04:32 | [diff] [blame] | 817 | client_->mediaSourceOpened(new WebMediaSourceImpl( |
wolenetz | 7ffc4de | 2015-04-01 17:14:43 | [diff] [blame] | 818 | chunk_demuxer_, base::Bind(&MediaLog::AddLogEvent, media_log_))); |
[email protected] | 81bb332 | 2011-07-21 15:55:50 | [diff] [blame] | 819 | } |
| 820 | |
[email protected] | 8a56106 | 2013-11-22 01:19:31 | [diff] [blame] | 821 | void WebMediaPlayerImpl::OnAddTextTrack( |
acolwell | 9e0840d | 2014-09-06 19:01:32 | [diff] [blame] | 822 | const TextTrackConfig& config, |
| 823 | const AddTextTrackDoneCB& done_cb) { |
acolwell | b403494 | 2014-08-28 15:42:43 | [diff] [blame] | 824 | DCHECK(main_task_runner_->BelongsToCurrentThread()); |
[email protected] | 7153772 | 2013-05-23 06:47:53 | [diff] [blame] | 825 | |
[email protected] | 8a56106 | 2013-11-22 01:19:31 | [diff] [blame] | 826 | const WebInbandTextTrackImpl::Kind web_kind = |
| 827 | static_cast<WebInbandTextTrackImpl::Kind>(config.kind()); |
| 828 | const blink::WebString web_label = |
| 829 | blink::WebString::fromUTF8(config.label()); |
| 830 | const blink::WebString web_language = |
| 831 | blink::WebString::fromUTF8(config.language()); |
[email protected] | 427ff10 | 2013-11-26 23:45:40 | [diff] [blame] | 832 | const blink::WebString web_id = |
| 833 | blink::WebString::fromUTF8(config.id()); |
[email protected] | 7153772 | 2013-05-23 06:47:53 | [diff] [blame] | 834 | |
[email protected] | 8a56106 | 2013-11-22 01:19:31 | [diff] [blame] | 835 | scoped_ptr<WebInbandTextTrackImpl> web_inband_text_track( |
henriks | 9cce5fa | 2014-12-12 09:35:30 | [diff] [blame] | 836 | new WebInbandTextTrackImpl(web_kind, web_label, web_language, web_id)); |
[email protected] | 8a56106 | 2013-11-22 01:19:31 | [diff] [blame] | 837 | |
acolwell | 9e0840d | 2014-09-06 19:01:32 | [diff] [blame] | 838 | scoped_ptr<TextTrack> text_track(new TextTrackImpl( |
acolwell | b403494 | 2014-08-28 15:42:43 | [diff] [blame] | 839 | main_task_runner_, client_, web_inband_text_track.Pass())); |
[email protected] | 8a56106 | 2013-11-22 01:19:31 | [diff] [blame] | 840 | |
| 841 | done_cb.Run(text_track.Pass()); |
[email protected] | 7153772 | 2013-05-23 06:47:53 | [diff] [blame] | 842 | } |
| 843 | |
[email protected] | fee8a90 | 2014-06-03 13:43:36 | [diff] [blame] | 844 | void WebMediaPlayerImpl::DataSourceInitialized(bool success) { |
acolwell | b403494 | 2014-08-28 15:42:43 | [diff] [blame] | 845 | DCHECK(main_task_runner_->BelongsToCurrentThread()); |
[email protected] | a941529 | 2012-01-19 19:55:20 | [diff] [blame] | 846 | |
[email protected] | d250190da3b | 2012-07-23 22:57:30 | [diff] [blame] | 847 | if (!success) { |
[email protected] | ef405f66b | 2012-04-18 02:39:55 | [diff] [blame] | 848 | SetNetworkState(WebMediaPlayer::NetworkStateFormatError); |
[email protected] | a941529 | 2012-01-19 19:55:20 | [diff] [blame] | 849 | return; |
| 850 | } |
| 851 | |
[email protected] | ef8394c | 2013-08-21 20:26:30 | [diff] [blame] | 852 | StartPipeline(); |
[email protected] | a941529 | 2012-01-19 19:55:20 | [diff] [blame] | 853 | } |
| 854 | |
[email protected] | 122f4025 | 2012-06-12 05:01:56 | [diff] [blame] | 855 | void WebMediaPlayerImpl::NotifyDownloading(bool is_downloading) { |
| 856 | if (!is_downloading && network_state_ == WebMediaPlayer::NetworkStateLoading) |
| 857 | SetNetworkState(WebMediaPlayer::NetworkStateIdle); |
| 858 | else if (is_downloading && network_state_ == WebMediaPlayer::NetworkStateIdle) |
| 859 | SetNetworkState(WebMediaPlayer::NetworkStateLoading); |
| 860 | media_log_->AddEvent( |
| 861 | media_log_->CreateBooleanEvent( |
acolwell | 9e0840d | 2014-09-06 19:01:32 | [diff] [blame] | 862 | MediaLogEvent::NETWORK_ACTIVITY_SET, |
[email protected] | 122f4025 | 2012-06-12 05:01:56 | [diff] [blame] | 863 | "is_downloading_data", is_downloading)); |
| 864 | } |
| 865 | |
[email protected] | ef8394c | 2013-08-21 20:26:30 | [diff] [blame] | 866 | void WebMediaPlayerImpl::StartPipeline() { |
acolwell | b403494 | 2014-08-28 15:42:43 | [diff] [blame] | 867 | DCHECK(main_task_runner_->BelongsToCurrentThread()); |
[email protected] | ddbc6ff | 2013-04-19 15:28:33 | [diff] [blame] | 868 | |
[email protected] | 0814ac6 | 2013-06-07 21:01:29 | [diff] [blame] | 869 | // Keep track if this is a MSE or non-MSE playback. |
[email protected] | ef8394c | 2013-08-21 20:26:30 | [diff] [blame] | 870 | UMA_HISTOGRAM_BOOLEAN("Media.MSE.Playback", |
| 871 | (load_type_ == LoadTypeMediaSource)); |
[email protected] | 0814ac6 | 2013-06-07 21:01:29 | [diff] [blame] | 872 | |
acolwell | 9e0840d | 2014-09-06 19:01:32 | [diff] [blame] | 873 | LogCB mse_log_cb; |
xhwang | e8c4181a | 2014-12-06 08:10:01 | [diff] [blame] | 874 | Demuxer::EncryptedMediaInitDataCB encrypted_media_init_data_cb = |
| 875 | BIND_TO_RENDER_LOOP(&WebMediaPlayerImpl::OnEncryptedMediaInitData); |
[email protected] | 2b57e2e | 2014-05-09 11:07:25 | [diff] [blame] | 876 | |
[email protected] | ddbc6ff | 2013-04-19 15:28:33 | [diff] [blame] | 877 | // Figure out which demuxer to use. |
[email protected] | ef8394c | 2013-08-21 20:26:30 | [diff] [blame] | 878 | if (load_type_ != LoadTypeMediaSource) { |
[email protected] | ddbc6ff | 2013-04-19 15:28:33 | [diff] [blame] | 879 | DCHECK(!chunk_demuxer_); |
[email protected] | f5443ef7 | 2013-04-22 04:03:38 | [diff] [blame] | 880 | DCHECK(data_source_); |
| 881 | |
xhwang | e8c4181a | 2014-12-06 08:10:01 | [diff] [blame] | 882 | demuxer_.reset(new FFmpegDemuxer(media_task_runner_, data_source_.get(), |
| 883 | encrypted_media_init_data_cb, media_log_)); |
[email protected] | ddbc6ff | 2013-04-19 15:28:33 | [diff] [blame] | 884 | } else { |
[email protected] | f5443ef7 | 2013-04-22 04:03:38 | [diff] [blame] | 885 | DCHECK(!chunk_demuxer_); |
| 886 | DCHECK(!data_source_); |
| 887 | |
wolenetz | 7ffc4de | 2015-04-01 17:14:43 | [diff] [blame] | 888 | mse_log_cb = base::Bind(&MediaLog::AddLogEvent, media_log_); |
[email protected] | 2b57e2e | 2014-05-09 11:07:25 | [diff] [blame] | 889 | |
acolwell | 9e0840d | 2014-09-06 19:01:32 | [diff] [blame] | 890 | chunk_demuxer_ = new ChunkDemuxer( |
[email protected] | ef8394c | 2013-08-21 20:26:30 | [diff] [blame] | 891 | BIND_TO_RENDER_LOOP(&WebMediaPlayerImpl::OnDemuxerOpened), |
xhwang | e8c4181a | 2014-12-06 08:10:01 | [diff] [blame] | 892 | encrypted_media_init_data_cb, mse_log_cb, media_log_, true); |
[email protected] | f5443ef7 | 2013-04-22 04:03:38 | [diff] [blame] | 893 | demuxer_.reset(chunk_demuxer_); |
[email protected] | ddbc6ff | 2013-04-19 15:28:33 | [diff] [blame] | 894 | } |
| 895 | |
[email protected] | f5443ef7 | 2013-04-22 04:03:38 | [diff] [blame] | 896 | // ... and we're ready to go! |
[email protected] | d228aeec | 2014-06-20 19:16:49 | [diff] [blame] | 897 | seeking_ = true; |
xhwang | f94a634d | 2014-10-22 22:07:27 | [diff] [blame] | 898 | |
[email protected] | f6af759 | 2014-02-28 10:09:11 | [diff] [blame] | 899 | pipeline_.Start( |
xhwang | 5980590 | 2014-08-29 01:44:15 | [diff] [blame] | 900 | demuxer_.get(), |
Bartosz Fabianowski | 85a82381 | 2015-04-16 10:27:51 | [diff] [blame] | 901 | renderer_factory_->CreateRenderer( |
| 902 | media_task_runner_, audio_source_provider_.get(), compositor_), |
[email protected] | f5443ef7 | 2013-04-22 04:03:38 | [diff] [blame] | 903 | BIND_TO_RENDER_LOOP(&WebMediaPlayerImpl::OnPipelineEnded), |
| 904 | BIND_TO_RENDER_LOOP(&WebMediaPlayerImpl::OnPipelineError), |
[email protected] | 4e98219 | 2014-06-21 13:35:45 | [diff] [blame] | 905 | BIND_TO_RENDER_LOOP1(&WebMediaPlayerImpl::OnPipelineSeeked, false), |
[email protected] | b887777 | 2014-03-26 20:17:15 | [diff] [blame] | 906 | BIND_TO_RENDER_LOOP(&WebMediaPlayerImpl::OnPipelineMetadata), |
[email protected] | ba7d5f9 | 2014-06-24 05:37:40 | [diff] [blame] | 907 | BIND_TO_RENDER_LOOP(&WebMediaPlayerImpl::OnPipelineBufferingStateChanged), |
xhwang | 5980590 | 2014-08-29 01:44:15 | [diff] [blame] | 908 | BIND_TO_RENDER_LOOP(&WebMediaPlayerImpl::OnDurationChanged), |
jrummell | 74fc4f94 | 2015-03-02 22:48:27 | [diff] [blame] | 909 | BIND_TO_RENDER_LOOP(&WebMediaPlayerImpl::OnAddTextTrack), |
| 910 | BIND_TO_RENDER_LOOP(&WebMediaPlayerImpl::OnWaitingForDecryptionKey)); |
[email protected] | f5443ef7 | 2013-04-22 04:03:38 | [diff] [blame] | 911 | } |
| 912 | |
| 913 | void WebMediaPlayerImpl::SetNetworkState(WebMediaPlayer::NetworkState state) { |
[email protected] | 2a06ca6 | 2014-06-04 13:59:52 | [diff] [blame] | 914 | DVLOG(1) << __FUNCTION__ << "(" << state << ")"; |
acolwell | b403494 | 2014-08-28 15:42:43 | [diff] [blame] | 915 | DCHECK(main_task_runner_->BelongsToCurrentThread()); |
[email protected] | f5443ef7 | 2013-04-22 04:03:38 | [diff] [blame] | 916 | network_state_ = state; |
| 917 | // Always notify to ensure client has the latest value. |
[email protected] | ce70c98 | 2013-12-20 17:04:32 | [diff] [blame] | 918 | client_->networkStateChanged(); |
[email protected] | f5443ef7 | 2013-04-22 04:03:38 | [diff] [blame] | 919 | } |
| 920 | |
| 921 | void WebMediaPlayerImpl::SetReadyState(WebMediaPlayer::ReadyState state) { |
[email protected] | 2a06ca6 | 2014-06-04 13:59:52 | [diff] [blame] | 922 | DVLOG(1) << __FUNCTION__ << "(" << state << ")"; |
acolwell | b403494 | 2014-08-28 15:42:43 | [diff] [blame] | 923 | DCHECK(main_task_runner_->BelongsToCurrentThread()); |
[email protected] | f5443ef7 | 2013-04-22 04:03:38 | [diff] [blame] | 924 | |
[email protected] | fee8a90 | 2014-06-03 13:43:36 | [diff] [blame] | 925 | if (state == WebMediaPlayer::ReadyStateHaveEnoughData && data_source_ && |
| 926 | data_source_->assume_fully_buffered() && |
[email protected] | f5443ef7 | 2013-04-22 04:03:38 | [diff] [blame] | 927 | network_state_ == WebMediaPlayer::NetworkStateLoading) |
| 928 | SetNetworkState(WebMediaPlayer::NetworkStateLoaded); |
| 929 | |
| 930 | ready_state_ = state; |
| 931 | // Always notify to ensure client has the latest value. |
[email protected] | ce70c98 | 2013-12-20 17:04:32 | [diff] [blame] | 932 | client_->readyStateChanged(); |
[email protected] | f5443ef7 | 2013-04-22 04:03:38 | [diff] [blame] | 933 | } |
| 934 | |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame] | 935 | blink::WebAudioSourceProvider* WebMediaPlayerImpl::audioSourceProvider() { |
[email protected] | ff875be5 | 2013-06-02 23:47:38 | [diff] [blame] | 936 | return audio_source_provider_.get(); |
[email protected] | f5443ef7 | 2013-04-22 04:03:38 | [diff] [blame] | 937 | } |
| 938 | |
[email protected] | f5443ef7 | 2013-04-22 04:03:38 | [diff] [blame] | 939 | double WebMediaPlayerImpl::GetPipelineDuration() const { |
[email protected] | f6af759 | 2014-02-28 10:09:11 | [diff] [blame] | 940 | base::TimeDelta duration = pipeline_.GetMediaDuration(); |
[email protected] | f5443ef7 | 2013-04-22 04:03:38 | [diff] [blame] | 941 | |
| 942 | // Return positive infinity if the resource is unbounded. |
| 943 | // 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] | 944 | if (duration == kInfiniteDuration()) |
[email protected] | f5443ef7 | 2013-04-22 04:03:38 | [diff] [blame] | 945 | return std::numeric_limits<double>::infinity(); |
| 946 | |
| 947 | return duration.InSecondsF(); |
| 948 | } |
| 949 | |
[email protected] | 75e145a | 2014-04-15 17:44:32 | [diff] [blame] | 950 | void WebMediaPlayerImpl::OnDurationChanged() { |
[email protected] | f5443ef7 | 2013-04-22 04:03:38 | [diff] [blame] | 951 | if (ready_state_ == WebMediaPlayer::ReadyStateHaveNothing) |
| 952 | return; |
| 953 | |
[email protected] | ce70c98 | 2013-12-20 17:04:32 | [diff] [blame] | 954 | client_->durationChanged(); |
[email protected] | f5443ef7 | 2013-04-22 04:03:38 | [diff] [blame] | 955 | } |
| 956 | |
[email protected] | 75e145a | 2014-04-15 17:44:32 | [diff] [blame] | 957 | void WebMediaPlayerImpl::OnNaturalSizeChanged(gfx::Size size) { |
acolwell | b403494 | 2014-08-28 15:42:43 | [diff] [blame] | 958 | DCHECK(main_task_runner_->BelongsToCurrentThread()); |
[email protected] | 739847c0 | 2014-01-16 00:12:25 | [diff] [blame] | 959 | DCHECK_NE(ready_state_, WebMediaPlayer::ReadyStateHaveNothing); |
| 960 | TRACE_EVENT0("media", "WebMediaPlayerImpl::OnNaturalSizeChanged"); |
| 961 | |
| 962 | media_log_->AddEvent( |
| 963 | media_log_->CreateVideoSizeSetEvent(size.width(), size.height())); |
[email protected] | b887777 | 2014-03-26 20:17:15 | [diff] [blame] | 964 | pipeline_metadata_.natural_size = size; |
[email protected] | 739847c0 | 2014-01-16 00:12:25 | [diff] [blame] | 965 | |
| 966 | client_->sizeChanged(); |
| 967 | } |
| 968 | |
[email protected] | 75e145a | 2014-04-15 17:44:32 | [diff] [blame] | 969 | void WebMediaPlayerImpl::OnOpacityChanged(bool opaque) { |
acolwell | b403494 | 2014-08-28 15:42:43 | [diff] [blame] | 970 | DCHECK(main_task_runner_->BelongsToCurrentThread()); |
[email protected] | 75e145a | 2014-04-15 17:44:32 | [diff] [blame] | 971 | DCHECK_NE(ready_state_, WebMediaPlayer::ReadyStateHaveNothing); |
| 972 | |
| 973 | opaque_ = opaque; |
[email protected] | 75e145a | 2014-04-15 17:44:32 | [diff] [blame] | 974 | if (video_weblayer_) |
| 975 | video_weblayer_->setOpaque(opaque_); |
| 976 | } |
| 977 | |
[email protected] | dd061e1 | 2014-05-06 19:21:22 | [diff] [blame] | 978 | static void GetCurrentFrameAndSignal( |
| 979 | VideoFrameCompositor* compositor, |
acolwell | 9e0840d | 2014-09-06 19:01:32 | [diff] [blame] | 980 | scoped_refptr<VideoFrame>* video_frame_out, |
[email protected] | dd061e1 | 2014-05-06 19:21:22 | [diff] [blame] | 981 | base::WaitableEvent* event) { |
| 982 | TRACE_EVENT0("media", "GetCurrentFrameAndSignal"); |
dalecurtis | 44ce4de | 2015-05-11 18:42:07 | [diff] [blame] | 983 | *video_frame_out = compositor->GetCurrentFrameAndUpdateIfStale(); |
[email protected] | dd061e1 | 2014-05-06 19:21:22 | [diff] [blame] | 984 | event->Signal(); |
| 985 | } |
| 986 | |
acolwell | 9e0840d | 2014-09-06 19:01:32 | [diff] [blame] | 987 | scoped_refptr<VideoFrame> |
[email protected] | dd061e1 | 2014-05-06 19:21:22 | [diff] [blame] | 988 | WebMediaPlayerImpl::GetCurrentFrameFromCompositor() { |
| 989 | TRACE_EVENT0("media", "WebMediaPlayerImpl::GetCurrentFrameFromCompositor"); |
| 990 | if (compositor_task_runner_->BelongsToCurrentThread()) |
dalecurtis | 44ce4de | 2015-05-11 18:42:07 | [diff] [blame] | 991 | return compositor_->GetCurrentFrameAndUpdateIfStale(); |
[email protected] | dd061e1 | 2014-05-06 19:21:22 | [diff] [blame] | 992 | |
| 993 | // Use a posted task and waitable event instead of a lock otherwise |
| 994 | // WebGL/Canvas can see different content than what the compositor is seeing. |
acolwell | 9e0840d | 2014-09-06 19:01:32 | [diff] [blame] | 995 | scoped_refptr<VideoFrame> video_frame; |
[email protected] | dd061e1 | 2014-05-06 19:21:22 | [diff] [blame] | 996 | base::WaitableEvent event(false, false); |
| 997 | compositor_task_runner_->PostTask(FROM_HERE, |
| 998 | base::Bind(&GetCurrentFrameAndSignal, |
| 999 | base::Unretained(compositor_), |
| 1000 | &video_frame, |
| 1001 | &event)); |
| 1002 | event.Wait(); |
| 1003 | return video_frame; |
| 1004 | } |
| 1005 | |
dalecurtis | 2e50e6f6 | 2015-01-09 02:42:52 | [diff] [blame] | 1006 | void WebMediaPlayerImpl::UpdatePausedTime() { |
| 1007 | DCHECK(main_task_runner_->BelongsToCurrentThread()); |
| 1008 | |
| 1009 | // pause() may be called after playback has ended and the HTMLMediaElement |
| 1010 | // requires that currentTime() == duration() after ending. We want to ensure |
| 1011 | // |paused_time_| matches currentTime() in this case or a future seek() may |
| 1012 | // incorrectly discard what it thinks is a seek to the existing time. |
| 1013 | paused_time_ = |
| 1014 | ended_ ? pipeline_.GetMediaDuration() : pipeline_.GetMediaTime(); |
| 1015 | } |
| 1016 | |
acolwell | 9e0840d | 2014-09-06 19:01:32 | [diff] [blame] | 1017 | } // namespace media |