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