[email protected] | b781e77 | 2011-02-04 20:27:51 | [diff] [blame] | 1 | // Copyright (c) 2011 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 | |
[email protected] | 8931c41a | 2009-07-07 17:31:49 | [diff] [blame] | 5 | #include "webkit/glue/webmediaplayer_impl.h" |
| 6 | |
[email protected] | 47b06ceb | 2010-08-04 22:41:11 | [diff] [blame] | 7 | #include <limits> |
[email protected] | d82b18ae | 2011-03-23 21:28:59 | [diff] [blame] | 8 | #include <string> |
[email protected] | 47b06ceb | 2010-08-04 22:41:11 | [diff] [blame] | 9 | |
[email protected] | 08273c7b | 2011-09-17 00:33:51 | [diff] [blame] | 10 | #include "base/bind.h" |
[email protected] | 2041cf34 | 2010-02-19 03:15:59 | [diff] [blame] | 11 | #include "base/callback.h" |
[email protected] | 963ab91 | 2010-01-22 19:56:14 | [diff] [blame] | 12 | #include "base/command_line.h" |
[email protected] | b6c2955 | 2011-03-14 15:56:29 | [diff] [blame] | 13 | #include "media/base/composite_data_source_factory.h" |
[email protected] | f8db813 | 2010-12-03 00:27:49 | [diff] [blame] | 14 | #include "media/base/filter_collection.h" |
[email protected] | 32da100 | 2010-03-03 21:57:35 | [diff] [blame] | 15 | #include "media/base/limits.h" |
[email protected] | 090f731 | 2011-08-05 23:26:40 | [diff] [blame] | 16 | #include "media/base/media_log.h" |
[email protected] | 963ab91 | 2010-01-22 19:56:14 | [diff] [blame] | 17 | #include "media/base/media_switches.h" |
[email protected] | 583634b | 2010-11-11 17:47:15 | [diff] [blame] | 18 | #include "media/base/pipeline_impl.h" |
[email protected] | e81283bb | 2010-08-31 18:01:21 | [diff] [blame] | 19 | #include "media/base/video_frame.h" |
[email protected] | 4af58de | 2011-03-30 20:28:50 | [diff] [blame] | 20 | #include "media/filters/adaptive_demuxer.h" |
[email protected] | 81bb332 | 2011-07-21 15:55:50 | [diff] [blame] | 21 | #include "media/filters/chunk_demuxer_factory.h" |
[email protected] | 08107faa | 2011-08-24 16:49:01 | [diff] [blame] | 22 | #include "media/filters/dummy_demuxer_factory.h" |
[email protected] | 4c616fa5 | 2009-03-30 20:10:07 | [diff] [blame] | 23 | #include "media/filters/ffmpeg_audio_decoder.h" |
[email protected] | c88c7c2 | 2011-03-14 19:44:22 | [diff] [blame] | 24 | #include "media/filters/ffmpeg_demuxer_factory.h" |
[email protected] | 720ac73 | 2009-04-02 23:55:44 | [diff] [blame] | 25 | #include "media/filters/ffmpeg_video_decoder.h" |
[email protected] | 891acc9 | 2009-04-27 19:56:41 | [diff] [blame] | 26 | #include "media/filters/null_audio_renderer.h" |
[email protected] | c1d9cdc | 2011-01-17 06:50:01 | [diff] [blame] | 27 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebRect.h" |
| 28 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebSize.h" |
| 29 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebURL.h" |
| 30 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebVideoFrame.h" |
[email protected] | 38aefc31 | 2011-09-20 05:06:37 | [diff] [blame^] | 31 | #include "v8/include/v8.h" |
[email protected] | 5b5bb9d | 2010-10-22 19:57:36 | [diff] [blame] | 32 | #include "webkit/glue/media/buffered_data_source.h" |
[email protected] | 5b5bb9d | 2010-10-22 19:57:36 | [diff] [blame] | 33 | #include "webkit/glue/media/simple_data_source.h" |
[email protected] | ab2c473 | 2011-07-20 19:57:40 | [diff] [blame] | 34 | #include "webkit/glue/media/media_stream_client.h" |
[email protected] | add5177 | 2009-06-11 18:25:17 | [diff] [blame] | 35 | #include "webkit/glue/media/video_renderer_impl.h" |
[email protected] | 8400e03 | 2010-02-26 18:50:11 | [diff] [blame] | 36 | #include "webkit/glue/media/web_video_renderer.h" |
[email protected] | a2330610 | 2011-08-09 22:50:26 | [diff] [blame] | 37 | #include "webkit/glue/webmediaplayer_proxy.h" |
[email protected] | e81283bb | 2010-08-31 18:01:21 | [diff] [blame] | 38 | #include "webkit/glue/webvideoframe_impl.h" |
[email protected] | b3f2b91 | 2009-04-09 16:18:52 | [diff] [blame] | 39 | |
[email protected] | df143bdc | 2009-06-16 17:34:19 | [diff] [blame] | 40 | using WebKit::WebCanvas; |
[email protected] | b3f2b91 | 2009-04-09 16:18:52 | [diff] [blame] | 41 | using WebKit::WebRect; |
| 42 | using WebKit::WebSize; |
[email protected] | a9590c2 | 2011-03-16 16:57:02 | [diff] [blame] | 43 | using media::PipelineStatus; |
[email protected] | ec9212f | 2008-12-18 21:40:36 | [diff] [blame] | 44 | |
[email protected] | 8931c41a | 2009-07-07 17:31:49 | [diff] [blame] | 45 | namespace { |
| 46 | |
[email protected] | 38aefc31 | 2011-09-20 05:06:37 | [diff] [blame^] | 47 | // Amount of extra memory used by each player instance reported to V8. |
| 48 | // It is not exact number -- first, it differs on different platforms, |
| 49 | // and second, it is very hard to calculate. Instead, use some arbitrary |
| 50 | // value that will cause garbage collection from time to time. We don't want |
| 51 | // it to happen on every allocation, but don't want 5k players to sit in memory |
| 52 | // either. Looks that chosen constant achieves both goals, at least for audio |
| 53 | // objects. (Do not worry about video objects yet, JS programs do not create |
| 54 | // thousands of them...) |
| 55 | const int kPlayerExtraMemory = 1024 * 1024; |
| 56 | |
[email protected] | 378f0b7 | 2009-08-11 17:11:42 | [diff] [blame] | 57 | // Limits the range of playback rate. |
| 58 | // |
| 59 | // TODO(kylep): Revisit these. |
| 60 | // |
| 61 | // Vista has substantially lower performance than XP or Windows7. If you speed |
| 62 | // up a video too much, it can't keep up, and rendering stops updating except on |
| 63 | // the time bar. For really high speeds, audio becomes a bottleneck and we just |
| 64 | // use up the data we have, which may not achieve the speed requested, but will |
| 65 | // not crash the tab. |
| 66 | // |
| 67 | // A very slow speed, ie 0.00000001x, causes the machine to lock up. (It seems |
| 68 | // like a busy loop). It gets unresponsive, although its not completely dead. |
| 69 | // |
| 70 | // Also our timers are not very accurate (especially for ogg), which becomes |
| 71 | // evident at low speeds and on Vista. Since other speeds are risky and outside |
| 72 | // the norms, we think 1/16x to 16x is a safe and useful range for now. |
| 73 | const float kMinRate = 0.0625f; |
| 74 | const float kMaxRate = 16.0f; |
| 75 | |
[email protected] | b781e77 | 2011-02-04 20:27:51 | [diff] [blame] | 76 | // Platform independent method for converting and rounding floating point |
| 77 | // seconds to an int64 timestamp. |
| 78 | // |
| 79 | // Refer to https://bugs.webkit.org/show_bug.cgi?id=52697 for details. |
| 80 | base::TimeDelta ConvertSecondsToTimestamp(float seconds) { |
| 81 | float microseconds = seconds * base::Time::kMicrosecondsPerSecond; |
| 82 | float integer = ceilf(microseconds); |
| 83 | float difference = integer - microseconds; |
| 84 | |
| 85 | // Round down if difference is large enough. |
| 86 | if ((microseconds > 0 && difference > 0.5f) || |
| 87 | (microseconds <= 0 && difference >= 0.5f)) { |
| 88 | integer -= 1.0f; |
| 89 | } |
| 90 | |
| 91 | // Now we can safely cast to int64 microseconds. |
| 92 | return base::TimeDelta::FromMicroseconds(static_cast<int64>(integer)); |
| 93 | } |
| 94 | |
[email protected] | 8931c41a | 2009-07-07 17:31:49 | [diff] [blame] | 95 | } // namespace |
| 96 | |
[email protected] | add5177 | 2009-06-11 18:25:17 | [diff] [blame] | 97 | namespace webkit_glue { |
| 98 | |
[email protected] | 5b5bb9d | 2010-10-22 19:57:36 | [diff] [blame] | 99 | WebMediaPlayerImpl::WebMediaPlayerImpl( |
| 100 | WebKit::WebMediaPlayerClient* client, |
[email protected] | f78d1dfc | 2011-01-15 07:09:27 | [diff] [blame] | 101 | media::FilterCollection* collection, |
[email protected] | ab2c473 | 2011-07-20 19:57:40 | [diff] [blame] | 102 | media::MessageLoopFactory* message_loop_factory, |
[email protected] | 090f731 | 2011-08-05 23:26:40 | [diff] [blame] | 103 | MediaStreamClient* media_stream_client, |
| 104 | media::MediaLog* media_log) |
[email protected] | 4e6be3f | 2009-05-07 02:24:44 | [diff] [blame] | 105 | : network_state_(WebKit::WebMediaPlayer::Empty), |
| 106 | ready_state_(WebKit::WebMediaPlayer::HaveNothing), |
[email protected] | d43ed91 | 2009-02-03 04:52:53 | [diff] [blame] | 107 | main_loop_(NULL), |
[email protected] | 457d834 | 2010-10-23 01:20:37 | [diff] [blame] | 108 | filter_collection_(collection), |
[email protected] | a8e24d52 | 2010-12-01 07:13:58 | [diff] [blame] | 109 | pipeline_(NULL), |
[email protected] | f78d1dfc | 2011-01-15 07:09:27 | [diff] [blame] | 110 | message_loop_factory_(message_loop_factory), |
[email protected] | 4948090 | 2009-07-14 20:23:43 | [diff] [blame] | 111 | paused_(true), |
[email protected] | b3766a2 | 2010-12-22 17:34:13 | [diff] [blame] | 112 | seeking_(false), |
[email protected] | 4948090 | 2009-07-14 20:23:43 | [diff] [blame] | 113 | playback_rate_(0.0f), |
[email protected] | 5d11eff | 2011-09-15 00:06:06 | [diff] [blame] | 114 | pending_seek_(false), |
[email protected] | 5badb08 | 2010-06-11 17:40:15 | [diff] [blame] | 115 | client_(client), |
[email protected] | ab2c473 | 2011-07-20 19:57:40 | [diff] [blame] | 116 | proxy_(NULL), |
[email protected] | 090f731 | 2011-08-05 23:26:40 | [diff] [blame] | 117 | media_stream_client_(media_stream_client), |
| 118 | media_log_(media_log) { |
[email protected] | 4e6be3f | 2009-05-07 02:24:44 | [diff] [blame] | 119 | // Saves the current message loop. |
| 120 | DCHECK(!main_loop_); |
| 121 | main_loop_ = MessageLoop::current(); |
[email protected] | c93eb0a6 | 2011-08-09 22:47:24 | [diff] [blame] | 122 | media_log_->AddEvent( |
| 123 | media_log_->CreateEvent(media::MediaLogEvent::WEBMEDIAPLAYER_CREATED)); |
[email protected] | a8e24d52 | 2010-12-01 07:13:58 | [diff] [blame] | 124 | } |
[email protected] | 4e6be3f | 2009-05-07 02:24:44 | [diff] [blame] | 125 | |
[email protected] | a8e24d52 | 2010-12-01 07:13:58 | [diff] [blame] | 126 | bool WebMediaPlayerImpl::Initialize( |
[email protected] | 7968428 | 2010-12-06 21:15:46 | [diff] [blame] | 127 | WebKit::WebFrame* frame, |
[email protected] | a8e24d52 | 2010-12-01 07:13:58 | [diff] [blame] | 128 | bool use_simple_data_source, |
| 129 | scoped_refptr<WebVideoRenderer> web_video_renderer) { |
[email protected] | f78d1dfc | 2011-01-15 07:09:27 | [diff] [blame] | 130 | MessageLoop* pipeline_message_loop = |
| 131 | message_loop_factory_->GetMessageLoop("PipelineThread"); |
| 132 | if (!pipeline_message_loop) { |
[email protected] | 3b4cbbf | 2009-07-11 00:16:19 | [diff] [blame] | 133 | NOTREACHED() << "Could not start PipelineThread"; |
[email protected] | a8e24d52 | 2010-12-01 07:13:58 | [diff] [blame] | 134 | return false; |
[email protected] | 3b4cbbf | 2009-07-11 00:16:19 | [diff] [blame] | 135 | } |
| 136 | |
[email protected] | 38aefc31 | 2011-09-20 05:06:37 | [diff] [blame^] | 137 | // Let V8 know we started new thread if we did not did it yet. |
| 138 | // Made separate task to avoid deletion of player currently being created. |
| 139 | // Also, delaying GC until after player starts gets rid of starting lag -- |
| 140 | // collection happens in parallel with playing. |
| 141 | // TODO(enal): remove when we get rid of per-audio-stream thread. |
| 142 | if (destructor_or_task_had_run_.get() == NULL) { |
| 143 | destructor_or_task_had_run_ = new DestructorOrTaskHadRun(); |
| 144 | main_loop_->PostTask( |
| 145 | FROM_HERE, |
| 146 | NewRunnableFunction(WebMediaPlayerImpl::UsesExtraMemoryTask, |
| 147 | destructor_or_task_had_run_)); |
| 148 | } |
| 149 | |
[email protected] | c93eb0a6 | 2011-08-09 22:47:24 | [diff] [blame] | 150 | pipeline_ = new media::PipelineImpl(pipeline_message_loop, media_log_); |
[email protected] | db190487d | 2009-07-30 18:51:52 | [diff] [blame] | 151 | |
[email protected] | 4e6be3f | 2009-05-07 02:24:44 | [diff] [blame] | 152 | // Also we want to be notified of |main_loop_| destruction. |
| 153 | main_loop_->AddDestructionObserver(this); |
[email protected] | 8931c41a | 2009-07-07 17:31:49 | [diff] [blame] | 154 | |
| 155 | // Creates the proxy. |
[email protected] | a2330610 | 2011-08-09 22:50:26 | [diff] [blame] | 156 | proxy_ = new WebMediaPlayerProxy(main_loop_, this); |
| 157 | web_video_renderer->SetWebMediaPlayerProxy(proxy_); |
[email protected] | 457d834 | 2010-10-23 01:20:37 | [diff] [blame] | 158 | proxy_->SetVideoRenderer(web_video_renderer); |
[email protected] | 8931c41a | 2009-07-07 17:31:49 | [diff] [blame] | 159 | |
[email protected] | 57653784 | 2009-08-12 23:52:05 | [diff] [blame] | 160 | // Set our pipeline callbacks. |
[email protected] | 583634b | 2010-11-11 17:47:15 | [diff] [blame] | 161 | pipeline_->Init( |
[email protected] | 460e571 | 2011-08-09 23:25:53 | [diff] [blame] | 162 | base::Bind(&WebMediaPlayerProxy::PipelineEndedCallback, |
| 163 | proxy_.get()), |
| 164 | base::Bind(&WebMediaPlayerProxy::PipelineErrorCallback, |
| 165 | proxy_.get()), |
| 166 | base::Bind(&WebMediaPlayerProxy::NetworkEventCallback, |
| 167 | proxy_.get())); |
[email protected] | db190487d | 2009-07-30 18:51:52 | [diff] [blame] | 168 | |
[email protected] | 5b5bb9d | 2010-10-22 19:57:36 | [diff] [blame] | 169 | // A simple data source that keeps all data in memory. |
[email protected] | b6c2955 | 2011-03-14 15:56:29 | [diff] [blame] | 170 | scoped_ptr<media::DataSourceFactory> simple_data_source_factory( |
| 171 | SimpleDataSource::CreateFactory(MessageLoop::current(), frame, |
[email protected] | 24d75c7 | 2011-08-09 17:53:45 | [diff] [blame] | 172 | media_log_, |
[email protected] | b6c2955 | 2011-03-14 15:56:29 | [diff] [blame] | 173 | proxy_->GetBuildObserver())); |
[email protected] | 457d834 | 2010-10-23 01:20:37 | [diff] [blame] | 174 | |
[email protected] | 5b5bb9d | 2010-10-22 19:57:36 | [diff] [blame] | 175 | // A sophisticated data source that does memory caching. |
[email protected] | b6c2955 | 2011-03-14 15:56:29 | [diff] [blame] | 176 | scoped_ptr<media::DataSourceFactory> buffered_data_source_factory( |
| 177 | BufferedDataSource::CreateFactory(MessageLoop::current(), frame, |
[email protected] | 24d75c7 | 2011-08-09 17:53:45 | [diff] [blame] | 178 | media_log_, |
[email protected] | b6c2955 | 2011-03-14 15:56:29 | [diff] [blame] | 179 | proxy_->GetBuildObserver())); |
| 180 | |
| 181 | scoped_ptr<media::CompositeDataSourceFactory> data_source_factory( |
| 182 | new media::CompositeDataSourceFactory()); |
[email protected] | 457d834 | 2010-10-23 01:20:37 | [diff] [blame] | 183 | |
[email protected] | 5b5bb9d | 2010-10-22 19:57:36 | [diff] [blame] | 184 | if (use_simple_data_source) { |
[email protected] | b6c2955 | 2011-03-14 15:56:29 | [diff] [blame] | 185 | data_source_factory->AddFactory(simple_data_source_factory.release()); |
| 186 | data_source_factory->AddFactory(buffered_data_source_factory.release()); |
[email protected] | 5b5bb9d | 2010-10-22 19:57:36 | [diff] [blame] | 187 | } else { |
[email protected] | b6c2955 | 2011-03-14 15:56:29 | [diff] [blame] | 188 | data_source_factory->AddFactory(buffered_data_source_factory.release()); |
| 189 | data_source_factory->AddFactory(simple_data_source_factory.release()); |
[email protected] | 5b5bb9d | 2010-10-22 19:57:36 | [diff] [blame] | 190 | } |
| 191 | |
[email protected] | c88c7c2 | 2011-03-14 19:44:22 | [diff] [blame] | 192 | scoped_ptr<media::DemuxerFactory> demuxer_factory( |
| 193 | new media::FFmpegDemuxerFactory(data_source_factory.release(), |
| 194 | pipeline_message_loop)); |
[email protected] | 4af58de | 2011-03-30 20:28:50 | [diff] [blame] | 195 | if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kEnableAdaptive)) { |
| 196 | demuxer_factory.reset(new media::AdaptiveDemuxerFactory( |
| 197 | demuxer_factory.release())); |
[email protected] | 81bb332 | 2011-07-21 15:55:50 | [diff] [blame] | 198 | |
| 199 | std::string sourceUrl; |
| 200 | |
| 201 | // TODO(acolwell): Uncomment once WebKit changes are checked in. |
| 202 | // https://bugs.webkit.org/show_bug.cgi?id=64731 |
| 203 | //sourceUrl = GetClient()->sourceURL().spec(); |
| 204 | |
| 205 | if (!sourceUrl.empty()) { |
| 206 | demuxer_factory.reset( |
| 207 | new media::ChunkDemuxerFactory(sourceUrl, |
| 208 | demuxer_factory.release(), |
| 209 | proxy_)); |
| 210 | } |
[email protected] | 4af58de | 2011-03-30 20:28:50 | [diff] [blame] | 211 | } |
[email protected] | c88c7c2 | 2011-03-14 19:44:22 | [diff] [blame] | 212 | filter_collection_->SetDemuxerFactory(demuxer_factory.release()); |
[email protected] | b6c2955 | 2011-03-14 15:56:29 | [diff] [blame] | 213 | |
[email protected] | 8931c41a | 2009-07-07 17:31:49 | [diff] [blame] | 214 | // Add in the default filter factories. |
[email protected] | f78d1dfc | 2011-01-15 07:09:27 | [diff] [blame] | 215 | filter_collection_->AddAudioDecoder(new media::FFmpegAudioDecoder( |
| 216 | message_loop_factory_->GetMessageLoop("AudioDecoderThread"))); |
| 217 | filter_collection_->AddVideoDecoder(new media::FFmpegVideoDecoder( |
| 218 | message_loop_factory_->GetMessageLoop("VideoDecoderThread"), NULL)); |
[email protected] | b7ba5b5 | 2010-11-15 22:04:49 | [diff] [blame] | 219 | filter_collection_->AddAudioRenderer(new media::NullAudioRenderer()); |
[email protected] | a8e24d52 | 2010-12-01 07:13:58 | [diff] [blame] | 220 | |
| 221 | return true; |
[email protected] | ec9212f | 2008-12-18 21:40:36 | [diff] [blame] | 222 | } |
| 223 | |
[email protected] | 4e6be3f | 2009-05-07 02:24:44 | [diff] [blame] | 224 | WebMediaPlayerImpl::~WebMediaPlayerImpl() { |
[email protected] | 8931c41a | 2009-07-07 17:31:49 | [diff] [blame] | 225 | Destroy(); |
[email protected] | c93eb0a6 | 2011-08-09 22:47:24 | [diff] [blame] | 226 | media_log_->AddEvent( |
| 227 | media_log_->CreateEvent(media::MediaLogEvent::WEBMEDIAPLAYER_DESTROYED)); |
[email protected] | d43ed91 | 2009-02-03 04:52:53 | [diff] [blame] | 228 | |
[email protected] | 4e6be3f | 2009-05-07 02:24:44 | [diff] [blame] | 229 | // Finally tell the |main_loop_| we don't want to be notified of destruction |
[email protected] | d43ed91 | 2009-02-03 04:52:53 | [diff] [blame] | 230 | // event. |
| 231 | if (main_loop_) { |
| 232 | main_loop_->RemoveDestructionObserver(this); |
| 233 | } |
[email protected] | ec9212f | 2008-12-18 21:40:36 | [diff] [blame] | 234 | } |
| 235 | |
[email protected] | 4e6be3f | 2009-05-07 02:24:44 | [diff] [blame] | 236 | void WebMediaPlayerImpl::load(const WebKit::WebURL& url) { |
[email protected] | 8931c41a | 2009-07-07 17:31:49 | [diff] [blame] | 237 | DCHECK(MessageLoop::current() == main_loop_); |
| 238 | DCHECK(proxy_); |
[email protected] | d43ed91 | 2009-02-03 04:52:53 | [diff] [blame] | 239 | |
[email protected] | ab2c473 | 2011-07-20 19:57:40 | [diff] [blame] | 240 | if (media_stream_client_) { |
[email protected] | 08107faa | 2011-08-24 16:49:01 | [diff] [blame] | 241 | bool has_video = false; |
| 242 | bool has_audio = false; |
[email protected] | ab2c473 | 2011-07-20 19:57:40 | [diff] [blame] | 243 | scoped_refptr<media::VideoDecoder> new_decoder = |
| 244 | media_stream_client_->GetVideoDecoder(url, message_loop_factory_.get()); |
| 245 | if (new_decoder.get()) { |
| 246 | // Remove the default decoder. |
| 247 | scoped_refptr<media::VideoDecoder> old_videodecoder; |
| 248 | filter_collection_->SelectVideoDecoder(&old_videodecoder); |
| 249 | filter_collection_->AddVideoDecoder(new_decoder.get()); |
[email protected] | 08107faa | 2011-08-24 16:49:01 | [diff] [blame] | 250 | has_video = true; |
[email protected] | ab2c473 | 2011-07-20 19:57:40 | [diff] [blame] | 251 | } |
[email protected] | 08107faa | 2011-08-24 16:49:01 | [diff] [blame] | 252 | |
| 253 | // TODO(wjia): add audio decoder handling when it's available. |
| 254 | if (has_video || has_audio) |
| 255 | filter_collection_->SetDemuxerFactory( |
| 256 | new media::DummyDemuxerFactory(has_video, has_audio)); |
[email protected] | ab2c473 | 2011-07-20 19:57:40 | [diff] [blame] | 257 | } |
| 258 | |
[email protected] | 835070f | 2010-05-18 23:48:29 | [diff] [blame] | 259 | // Handle any volume changes that occured before load(). |
| 260 | setVolume(GetClient()->volume()); |
[email protected] | 23a8b1d8 | 2011-04-05 16:28:20 | [diff] [blame] | 261 | // Get the preload value. |
| 262 | setPreload(GetClient()->preload()); |
[email protected] | 835070f | 2010-05-18 23:48:29 | [diff] [blame] | 263 | |
[email protected] | a728102 | 2009-06-17 17:58:04 | [diff] [blame] | 264 | // Initialize the pipeline. |
[email protected] | 8931c41a | 2009-07-07 17:31:49 | [diff] [blame] | 265 | SetNetworkState(WebKit::WebMediaPlayer::Loading); |
| 266 | SetReadyState(WebKit::WebMediaPlayer::HaveNothing); |
[email protected] | 3b4cbbf | 2009-07-11 00:16:19 | [diff] [blame] | 267 | pipeline_->Start( |
[email protected] | 9e16697 | 2010-11-03 05:40:13 | [diff] [blame] | 268 | filter_collection_.release(), |
[email protected] | 8931c41a | 2009-07-07 17:31:49 | [diff] [blame] | 269 | url.spec(), |
[email protected] | 460e571 | 2011-08-09 23:25:53 | [diff] [blame] | 270 | base::Bind(&WebMediaPlayerProxy::PipelineInitializationCallback, |
| 271 | proxy_.get())); |
| 272 | |
[email protected] | 24d75c7 | 2011-08-09 17:53:45 | [diff] [blame] | 273 | media_log_->AddEvent(media_log_->CreateLoadEvent(url.spec())); |
[email protected] | ec9212f | 2008-12-18 21:40:36 | [diff] [blame] | 274 | } |
| 275 | |
[email protected] | 4e6be3f | 2009-05-07 02:24:44 | [diff] [blame] | 276 | void WebMediaPlayerImpl::cancelLoad() { |
[email protected] | 8931c41a | 2009-07-07 17:31:49 | [diff] [blame] | 277 | DCHECK(MessageLoop::current() == main_loop_); |
[email protected] | ec9212f | 2008-12-18 21:40:36 | [diff] [blame] | 278 | } |
| 279 | |
[email protected] | 4e6be3f | 2009-05-07 02:24:44 | [diff] [blame] | 280 | void WebMediaPlayerImpl::play() { |
[email protected] | 8931c41a | 2009-07-07 17:31:49 | [diff] [blame] | 281 | DCHECK(MessageLoop::current() == main_loop_); |
[email protected] | d43ed91 | 2009-02-03 04:52:53 | [diff] [blame] | 282 | |
[email protected] | 4948090 | 2009-07-14 20:23:43 | [diff] [blame] | 283 | paused_ = false; |
| 284 | pipeline_->SetPlaybackRate(playback_rate_); |
[email protected] | 090f731 | 2011-08-05 23:26:40 | [diff] [blame] | 285 | |
[email protected] | 24d75c7 | 2011-08-09 17:53:45 | [diff] [blame] | 286 | media_log_->AddEvent(media_log_->CreateEvent(media::MediaLogEvent::PLAY)); |
[email protected] | ec9212f | 2008-12-18 21:40:36 | [diff] [blame] | 287 | } |
| 288 | |
[email protected] | 4e6be3f | 2009-05-07 02:24:44 | [diff] [blame] | 289 | void WebMediaPlayerImpl::pause() { |
[email protected] | 8931c41a | 2009-07-07 17:31:49 | [diff] [blame] | 290 | DCHECK(MessageLoop::current() == main_loop_); |
[email protected] | d43ed91 | 2009-02-03 04:52:53 | [diff] [blame] | 291 | |
[email protected] | 4948090 | 2009-07-14 20:23:43 | [diff] [blame] | 292 | paused_ = true; |
[email protected] | 3b4cbbf | 2009-07-11 00:16:19 | [diff] [blame] | 293 | pipeline_->SetPlaybackRate(0.0f); |
[email protected] | f467d03 | 2009-10-23 00:56:24 | [diff] [blame] | 294 | paused_time_ = pipeline_->GetCurrentTime(); |
[email protected] | 090f731 | 2011-08-05 23:26:40 | [diff] [blame] | 295 | |
[email protected] | 24d75c7 | 2011-08-09 17:53:45 | [diff] [blame] | 296 | media_log_->AddEvent(media_log_->CreateEvent(media::MediaLogEvent::PAUSE)); |
[email protected] | ec9212f | 2008-12-18 21:40:36 | [diff] [blame] | 297 | } |
| 298 | |
[email protected] | 574a1d6 | 2009-07-17 03:23:46 | [diff] [blame] | 299 | bool WebMediaPlayerImpl::supportsFullscreen() const { |
| 300 | DCHECK(MessageLoop::current() == main_loop_); |
| 301 | return true; |
| 302 | } |
| 303 | |
| 304 | bool WebMediaPlayerImpl::supportsSave() const { |
| 305 | DCHECK(MessageLoop::current() == main_loop_); |
| 306 | return true; |
| 307 | } |
| 308 | |
[email protected] | 4e6be3f | 2009-05-07 02:24:44 | [diff] [blame] | 309 | void WebMediaPlayerImpl::seek(float seconds) { |
[email protected] | 8931c41a | 2009-07-07 17:31:49 | [diff] [blame] | 310 | DCHECK(MessageLoop::current() == main_loop_); |
[email protected] | d43ed91 | 2009-02-03 04:52:53 | [diff] [blame] | 311 | |
[email protected] | 2a6c2569 | 2009-08-18 00:25:55 | [diff] [blame] | 312 | // WebKit fires a seek(0) at the very start, however pipeline already does a |
| 313 | // seek(0) internally. Avoid doing seek(0) the second time because this will |
| 314 | // cause extra pre-rolling and will break servers without range request |
| 315 | // support. |
[email protected] | d8840af4 | 2009-08-25 21:27:56 | [diff] [blame] | 316 | // |
| 317 | // We still have to notify WebKit that time has changed otherwise |
| 318 | // HTMLMediaElement gets into an inconsistent state. |
[email protected] | 2a6c2569 | 2009-08-18 00:25:55 | [diff] [blame] | 319 | if (pipeline_->GetCurrentTime().ToInternalValue() == 0 && seconds == 0) { |
[email protected] | d8840af4 | 2009-08-25 21:27:56 | [diff] [blame] | 320 | GetClient()->timeChanged(); |
[email protected] | 2a6c2569 | 2009-08-18 00:25:55 | [diff] [blame] | 321 | return; |
| 322 | } |
[email protected] | 57653784 | 2009-08-12 23:52:05 | [diff] [blame] | 323 | |
[email protected] | 5d11eff | 2011-09-15 00:06:06 | [diff] [blame] | 324 | if (seeking_) { |
| 325 | pending_seek_ = true; |
| 326 | pending_seek_seconds_ = seconds; |
| 327 | return; |
| 328 | } |
| 329 | |
[email protected] | c93eb0a6 | 2011-08-09 22:47:24 | [diff] [blame] | 330 | media_log_->AddEvent(media_log_->CreateSeekEvent(seconds)); |
| 331 | |
[email protected] | b781e77 | 2011-02-04 20:27:51 | [diff] [blame] | 332 | base::TimeDelta seek_time = ConvertSecondsToTimestamp(seconds); |
[email protected] | 44ff37c0 | 2009-10-24 01:03:03 | [diff] [blame] | 333 | |
| 334 | // Update our paused time. |
| 335 | if (paused_) { |
| 336 | paused_time_ = seek_time; |
| 337 | } |
| 338 | |
[email protected] | b3766a2 | 2010-12-22 17:34:13 | [diff] [blame] | 339 | seeking_ = true; |
| 340 | |
[email protected] | 81bb332 | 2011-07-21 15:55:50 | [diff] [blame] | 341 | proxy_->DemuxerFlush(); |
[email protected] | 020fba3 | 2011-06-29 16:37:46 | [diff] [blame] | 342 | |
[email protected] | 44ff37c0 | 2009-10-24 01:03:03 | [diff] [blame] | 343 | // Kick off the asynchronous seek! |
[email protected] | 3b4cbbf | 2009-07-11 00:16:19 | [diff] [blame] | 344 | pipeline_->Seek( |
[email protected] | 44ff37c0 | 2009-10-24 01:03:03 | [diff] [blame] | 345 | seek_time, |
[email protected] | 460e571 | 2011-08-09 23:25:53 | [diff] [blame] | 346 | base::Bind(&WebMediaPlayerProxy::PipelineSeekCallback, |
| 347 | proxy_.get())); |
[email protected] | ec9212f | 2008-12-18 21:40:36 | [diff] [blame] | 348 | } |
| 349 | |
[email protected] | 4e6be3f | 2009-05-07 02:24:44 | [diff] [blame] | 350 | void WebMediaPlayerImpl::setEndTime(float seconds) { |
[email protected] | 8931c41a | 2009-07-07 17:31:49 | [diff] [blame] | 351 | DCHECK(MessageLoop::current() == main_loop_); |
[email protected] | d43ed91 | 2009-02-03 04:52:53 | [diff] [blame] | 352 | |
| 353 | // TODO(hclam): add method call when it has been implemented. |
| 354 | return; |
[email protected] | ec9212f | 2008-12-18 21:40:36 | [diff] [blame] | 355 | } |
[email protected] | d43ed91 | 2009-02-03 04:52:53 | [diff] [blame] | 356 | |
[email protected] | 4e6be3f | 2009-05-07 02:24:44 | [diff] [blame] | 357 | void WebMediaPlayerImpl::setRate(float rate) { |
[email protected] | 8931c41a | 2009-07-07 17:31:49 | [diff] [blame] | 358 | DCHECK(MessageLoop::current() == main_loop_); |
[email protected] | d43ed91 | 2009-02-03 04:52:53 | [diff] [blame] | 359 | |
[email protected] | 378f0b7 | 2009-08-11 17:11:42 | [diff] [blame] | 360 | // TODO(kylep): Remove when support for negatives is added. Also, modify the |
| 361 | // following checks so rewind uses reasonable values also. |
| 362 | if (rate < 0.0f) |
| 363 | return; |
| 364 | |
| 365 | // Limit rates to reasonable values by clamping. |
| 366 | if (rate != 0.0f) { |
| 367 | if (rate < kMinRate) |
| 368 | rate = kMinRate; |
| 369 | else if (rate > kMaxRate) |
| 370 | rate = kMaxRate; |
| 371 | } |
| 372 | |
[email protected] | 4948090 | 2009-07-14 20:23:43 | [diff] [blame] | 373 | playback_rate_ = rate; |
| 374 | if (!paused_) { |
| 375 | pipeline_->SetPlaybackRate(rate); |
| 376 | } |
[email protected] | ec9212f | 2008-12-18 21:40:36 | [diff] [blame] | 377 | } |
| 378 | |
[email protected] | 4e6be3f | 2009-05-07 02:24:44 | [diff] [blame] | 379 | void WebMediaPlayerImpl::setVolume(float volume) { |
[email protected] | 8931c41a | 2009-07-07 17:31:49 | [diff] [blame] | 380 | DCHECK(MessageLoop::current() == main_loop_); |
[email protected] | d43ed91 | 2009-02-03 04:52:53 | [diff] [blame] | 381 | |
[email protected] | 3b4cbbf | 2009-07-11 00:16:19 | [diff] [blame] | 382 | pipeline_->SetVolume(volume); |
[email protected] | ec9212f | 2008-12-18 21:40:36 | [diff] [blame] | 383 | } |
[email protected] | f0a51fb5 | 2009-03-05 12:46:38 | [diff] [blame] | 384 | |
[email protected] | 4e6be3f | 2009-05-07 02:24:44 | [diff] [blame] | 385 | void WebMediaPlayerImpl::setVisible(bool visible) { |
[email protected] | 8931c41a | 2009-07-07 17:31:49 | [diff] [blame] | 386 | DCHECK(MessageLoop::current() == main_loop_); |
[email protected] | d43ed91 | 2009-02-03 04:52:53 | [diff] [blame] | 387 | |
| 388 | // TODO(hclam): add appropriate method call when pipeline has it implemented. |
| 389 | return; |
[email protected] | ec9212f | 2008-12-18 21:40:36 | [diff] [blame] | 390 | } |
[email protected] | d43ed91 | 2009-02-03 04:52:53 | [diff] [blame] | 391 | |
[email protected] | 23a8b1d8 | 2011-04-05 16:28:20 | [diff] [blame] | 392 | #define COMPILE_ASSERT_MATCHING_ENUM(webkit_name, chromium_name) \ |
[email protected] | 474c37a | 2011-08-23 20:24:52 | [diff] [blame] | 393 | COMPILE_ASSERT(static_cast<int>(WebKit::WebMediaPlayer::webkit_name) == \ |
| 394 | static_cast<int>(media::chromium_name), \ |
| 395 | mismatching_enums) |
[email protected] | 23a8b1d8 | 2011-04-05 16:28:20 | [diff] [blame] | 396 | COMPILE_ASSERT_MATCHING_ENUM(None, NONE); |
| 397 | COMPILE_ASSERT_MATCHING_ENUM(MetaData, METADATA); |
| 398 | COMPILE_ASSERT_MATCHING_ENUM(Auto, AUTO); |
| 399 | |
| 400 | void WebMediaPlayerImpl::setPreload(WebKit::WebMediaPlayer::Preload preload) { |
[email protected] | 8931c41a | 2009-07-07 17:31:49 | [diff] [blame] | 401 | DCHECK(MessageLoop::current() == main_loop_); |
[email protected] | 4e6be3f | 2009-05-07 02:24:44 | [diff] [blame] | 402 | |
[email protected] | 23a8b1d8 | 2011-04-05 16:28:20 | [diff] [blame] | 403 | pipeline_->SetPreload(static_cast<media::Preload>(preload)); |
[email protected] | 4e6be3f | 2009-05-07 02:24:44 | [diff] [blame] | 404 | } |
| 405 | |
| 406 | bool WebMediaPlayerImpl::totalBytesKnown() { |
[email protected] | 8931c41a | 2009-07-07 17:31:49 | [diff] [blame] | 407 | DCHECK(MessageLoop::current() == main_loop_); |
[email protected] | d43ed91 | 2009-02-03 04:52:53 | [diff] [blame] | 408 | |
[email protected] | 3b4cbbf | 2009-07-11 00:16:19 | [diff] [blame] | 409 | return pipeline_->GetTotalBytes() != 0; |
[email protected] | d43ed91 | 2009-02-03 04:52:53 | [diff] [blame] | 410 | } |
| 411 | |
[email protected] | 4e6be3f | 2009-05-07 02:24:44 | [diff] [blame] | 412 | bool WebMediaPlayerImpl::hasVideo() const { |
[email protected] | 8931c41a | 2009-07-07 17:31:49 | [diff] [blame] | 413 | DCHECK(MessageLoop::current() == main_loop_); |
[email protected] | d43ed91 | 2009-02-03 04:52:53 | [diff] [blame] | 414 | |
[email protected] | cee3234 | 2011-03-09 15:58:16 | [diff] [blame] | 415 | return pipeline_->HasVideo(); |
[email protected] | d43ed91 | 2009-02-03 04:52:53 | [diff] [blame] | 416 | } |
| 417 | |
[email protected] | fc367af | 2009-08-14 23:06:35 | [diff] [blame] | 418 | bool WebMediaPlayerImpl::hasAudio() const { |
| 419 | DCHECK(MessageLoop::current() == main_loop_); |
| 420 | |
[email protected] | cee3234 | 2011-03-09 15:58:16 | [diff] [blame] | 421 | return pipeline_->HasAudio(); |
[email protected] | fc367af | 2009-08-14 23:06:35 | [diff] [blame] | 422 | } |
| 423 | |
[email protected] | 4e6be3f | 2009-05-07 02:24:44 | [diff] [blame] | 424 | WebKit::WebSize WebMediaPlayerImpl::naturalSize() const { |
[email protected] | 8931c41a | 2009-07-07 17:31:49 | [diff] [blame] | 425 | DCHECK(MessageLoop::current() == main_loop_); |
[email protected] | d43ed91 | 2009-02-03 04:52:53 | [diff] [blame] | 426 | |
[email protected] | 2975fa53 | 2011-09-19 20:18:33 | [diff] [blame] | 427 | gfx::Size size; |
| 428 | pipeline_->GetNaturalVideoSize(&size); |
| 429 | return WebKit::WebSize(size); |
[email protected] | d43ed91 | 2009-02-03 04:52:53 | [diff] [blame] | 430 | } |
| 431 | |
[email protected] | 4e6be3f | 2009-05-07 02:24:44 | [diff] [blame] | 432 | bool WebMediaPlayerImpl::paused() const { |
[email protected] | 8931c41a | 2009-07-07 17:31:49 | [diff] [blame] | 433 | DCHECK(MessageLoop::current() == main_loop_); |
[email protected] | d43ed91 | 2009-02-03 04:52:53 | [diff] [blame] | 434 | |
[email protected] | 3b4cbbf | 2009-07-11 00:16:19 | [diff] [blame] | 435 | return pipeline_->GetPlaybackRate() == 0.0f; |
[email protected] | d43ed91 | 2009-02-03 04:52:53 | [diff] [blame] | 436 | } |
| 437 | |
[email protected] | 4e6be3f | 2009-05-07 02:24:44 | [diff] [blame] | 438 | bool WebMediaPlayerImpl::seeking() const { |
[email protected] | 8931c41a | 2009-07-07 17:31:49 | [diff] [blame] | 439 | DCHECK(MessageLoop::current() == main_loop_); |
[email protected] | d43ed91 | 2009-02-03 04:52:53 | [diff] [blame] | 440 | |
[email protected] | 0acebfa | 2009-08-21 22:45:40 | [diff] [blame] | 441 | if (ready_state_ == WebKit::WebMediaPlayer::HaveNothing) |
| 442 | return false; |
[email protected] | 67cd505 | 2009-09-10 21:53:22 | [diff] [blame] | 443 | |
[email protected] | b3766a2 | 2010-12-22 17:34:13 | [diff] [blame] | 444 | return seeking_; |
[email protected] | ec9212f | 2008-12-18 21:40:36 | [diff] [blame] | 445 | } |
| 446 | |
[email protected] | 4e6be3f | 2009-05-07 02:24:44 | [diff] [blame] | 447 | float WebMediaPlayerImpl::duration() const { |
[email protected] | 8931c41a | 2009-07-07 17:31:49 | [diff] [blame] | 448 | DCHECK(MessageLoop::current() == main_loop_); |
[email protected] | d43ed91 | 2009-02-03 04:52:53 | [diff] [blame] | 449 | |
[email protected] | 47b06ceb | 2010-08-04 22:41:11 | [diff] [blame] | 450 | base::TimeDelta duration = pipeline_->GetMediaDuration(); |
| 451 | if (duration.InMicroseconds() == media::Limits::kMaxTimeInMicroseconds) |
| 452 | return std::numeric_limits<float>::infinity(); |
| 453 | return static_cast<float>(duration.InSecondsF()); |
[email protected] | d43ed91 | 2009-02-03 04:52:53 | [diff] [blame] | 454 | } |
| 455 | |
[email protected] | 4e6be3f | 2009-05-07 02:24:44 | [diff] [blame] | 456 | float WebMediaPlayerImpl::currentTime() const { |
[email protected] | 8931c41a | 2009-07-07 17:31:49 | [diff] [blame] | 457 | DCHECK(MessageLoop::current() == main_loop_); |
[email protected] | f467d03 | 2009-10-23 00:56:24 | [diff] [blame] | 458 | if (paused_) { |
| 459 | return static_cast<float>(paused_time_.InSecondsF()); |
| 460 | } |
[email protected] | 128740b | 2009-07-17 22:09:28 | [diff] [blame] | 461 | return static_cast<float>(pipeline_->GetCurrentTime().InSecondsF()); |
[email protected] | d43ed91 | 2009-02-03 04:52:53 | [diff] [blame] | 462 | } |
| 463 | |
[email protected] | 4e6be3f | 2009-05-07 02:24:44 | [diff] [blame] | 464 | int WebMediaPlayerImpl::dataRate() const { |
[email protected] | 8931c41a | 2009-07-07 17:31:49 | [diff] [blame] | 465 | DCHECK(MessageLoop::current() == main_loop_); |
[email protected] | d43ed91 | 2009-02-03 04:52:53 | [diff] [blame] | 466 | |
| 467 | // TODO(hclam): Add this method call if pipeline has it in the interface. |
| 468 | return 0; |
| 469 | } |
| 470 | |
[email protected] | ddb1e5a | 2010-12-13 20:10:45 | [diff] [blame] | 471 | WebKit::WebMediaPlayer::NetworkState WebMediaPlayerImpl::networkState() const { |
| 472 | return network_state_; |
| 473 | } |
| 474 | |
| 475 | WebKit::WebMediaPlayer::ReadyState WebMediaPlayerImpl::readyState() const { |
| 476 | return ready_state_; |
| 477 | } |
| 478 | |
[email protected] | f70f8e1 | 2010-05-25 21:30:39 | [diff] [blame] | 479 | const WebKit::WebTimeRanges& WebMediaPlayerImpl::buffered() { |
| 480 | DCHECK(MessageLoop::current() == main_loop_); |
| 481 | |
| 482 | // Update buffered_ with the most recent buffered time. |
[email protected] | 69a8385 | 2010-06-12 01:12:13 | [diff] [blame] | 483 | if (buffered_.size() > 0) { |
| 484 | float buffered_time = static_cast<float>( |
| 485 | pipeline_->GetBufferedTime().InSecondsF()); |
| 486 | if (buffered_time >= buffered_[0].start) |
| 487 | buffered_[0].end = buffered_time; |
| 488 | } |
[email protected] | f70f8e1 | 2010-05-25 21:30:39 | [diff] [blame] | 489 | |
| 490 | return buffered_; |
| 491 | } |
| 492 | |
[email protected] | 4e6be3f | 2009-05-07 02:24:44 | [diff] [blame] | 493 | float WebMediaPlayerImpl::maxTimeSeekable() const { |
[email protected] | 8931c41a | 2009-07-07 17:31:49 | [diff] [blame] | 494 | DCHECK(MessageLoop::current() == main_loop_); |
[email protected] | d43ed91 | 2009-02-03 04:52:53 | [diff] [blame] | 495 | |
[email protected] | 38259a7a8 | 2009-07-29 21:49:49 | [diff] [blame] | 496 | // If we are performing streaming, we report that we cannot seek at all. |
| 497 | // We are using this flag to indicate if the data source supports seeking |
| 498 | // or not. We should be able to seek even if we are performing streaming. |
| 499 | // TODO(hclam): We need to update this when we have better caching. |
| 500 | if (pipeline_->IsStreaming()) |
[email protected] | 7329360 | 2009-04-29 00:30:22 | [diff] [blame] | 501 | return 0.0f; |
[email protected] | fd286f2 | 2010-04-20 23:45:15 | [diff] [blame] | 502 | return static_cast<float>(pipeline_->GetMediaDuration().InSecondsF()); |
[email protected] | ec9212f | 2008-12-18 21:40:36 | [diff] [blame] | 503 | } |
| 504 | |
[email protected] | 4e6be3f | 2009-05-07 02:24:44 | [diff] [blame] | 505 | unsigned long long WebMediaPlayerImpl::bytesLoaded() const { |
[email protected] | 8931c41a | 2009-07-07 17:31:49 | [diff] [blame] | 506 | DCHECK(MessageLoop::current() == main_loop_); |
[email protected] | d43ed91 | 2009-02-03 04:52:53 | [diff] [blame] | 507 | |
[email protected] | 3b4cbbf | 2009-07-11 00:16:19 | [diff] [blame] | 508 | return pipeline_->GetBufferedBytes(); |
[email protected] | d43ed91 | 2009-02-03 04:52:53 | [diff] [blame] | 509 | } |
| 510 | |
[email protected] | 4e6be3f | 2009-05-07 02:24:44 | [diff] [blame] | 511 | unsigned long long WebMediaPlayerImpl::totalBytes() const { |
[email protected] | 8931c41a | 2009-07-07 17:31:49 | [diff] [blame] | 512 | DCHECK(MessageLoop::current() == main_loop_); |
[email protected] | d43ed91 | 2009-02-03 04:52:53 | [diff] [blame] | 513 | |
[email protected] | 3b4cbbf | 2009-07-11 00:16:19 | [diff] [blame] | 514 | return pipeline_->GetTotalBytes(); |
[email protected] | d43ed91 | 2009-02-03 04:52:53 | [diff] [blame] | 515 | } |
| 516 | |
[email protected] | 4e6be3f | 2009-05-07 02:24:44 | [diff] [blame] | 517 | void WebMediaPlayerImpl::setSize(const WebSize& size) { |
[email protected] | 8931c41a | 2009-07-07 17:31:49 | [diff] [blame] | 518 | DCHECK(MessageLoop::current() == main_loop_); |
| 519 | DCHECK(proxy_); |
[email protected] | d43ed91 | 2009-02-03 04:52:53 | [diff] [blame] | 520 | |
[email protected] | 8931c41a | 2009-07-07 17:31:49 | [diff] [blame] | 521 | proxy_->SetSize(gfx::Rect(0, 0, size.width, size.height)); |
[email protected] | ec9212f | 2008-12-18 21:40:36 | [diff] [blame] | 522 | } |
| 523 | |
[email protected] | df143bdc | 2009-06-16 17:34:19 | [diff] [blame] | 524 | void WebMediaPlayerImpl::paint(WebCanvas* canvas, |
[email protected] | 4e6be3f | 2009-05-07 02:24:44 | [diff] [blame] | 525 | const WebRect& rect) { |
[email protected] | 8931c41a | 2009-07-07 17:31:49 | [diff] [blame] | 526 | DCHECK(MessageLoop::current() == main_loop_); |
| 527 | DCHECK(proxy_); |
[email protected] | 4e6be3f | 2009-05-07 02:24:44 | [diff] [blame] | 528 | |
[email protected] | 8c89e779 | 2009-08-19 21:18:34 | [diff] [blame] | 529 | #if WEBKIT_USING_SKIA |
[email protected] | 8931c41a | 2009-07-07 17:31:49 | [diff] [blame] | 530 | proxy_->Paint(canvas, rect); |
[email protected] | 776775e | 2009-09-21 15:21:29 | [diff] [blame] | 531 | #elif WEBKIT_USING_CG |
[email protected] | 32da100 | 2010-03-03 21:57:35 | [diff] [blame] | 532 | // Get the current scaling in X and Y. |
| 533 | CGAffineTransform mat = CGContextGetCTM(canvas); |
| 534 | float scale_x = sqrt(mat.a * mat.a + mat.b * mat.b); |
| 535 | float scale_y = sqrt(mat.c * mat.c + mat.d * mat.d); |
| 536 | float inverse_scale_x = SkScalarNearlyZero(scale_x) ? 0.0f : 1.0f / scale_x; |
| 537 | float inverse_scale_y = SkScalarNearlyZero(scale_y) ? 0.0f : 1.0f / scale_y; |
| 538 | int scaled_width = static_cast<int>(rect.width * fabs(scale_x)); |
| 539 | int scaled_height = static_cast<int>(rect.height * fabs(scale_y)); |
| 540 | |
| 541 | // Make sure we don't create a huge canvas. |
| 542 | // TODO(hclam): Respect the aspect ratio. |
| 543 | if (scaled_width > static_cast<int>(media::Limits::kMaxCanvas)) |
| 544 | scaled_width = media::Limits::kMaxCanvas; |
| 545 | if (scaled_height > static_cast<int>(media::Limits::kMaxCanvas)) |
| 546 | scaled_height = media::Limits::kMaxCanvas; |
| 547 | |
[email protected] | 776775e | 2009-09-21 15:21:29 | [diff] [blame] | 548 | // If there is no preexisting platform canvas, or if the size has |
| 549 | // changed, recreate the canvas. This is to avoid recreating the bitmap |
| 550 | // buffer over and over for each frame of video. |
| 551 | if (!skia_canvas_.get() || |
[email protected] | 32da100 | 2010-03-03 21:57:35 | [diff] [blame] | 552 | skia_canvas_->getDevice()->width() != scaled_width || |
| 553 | skia_canvas_->getDevice()->height() != scaled_height) { |
| 554 | skia_canvas_.reset( |
| 555 | new skia::PlatformCanvas(scaled_width, scaled_height, true)); |
[email protected] | 776775e | 2009-09-21 15:21:29 | [diff] [blame] | 556 | } |
| 557 | |
| 558 | // Draw to our temporary skia canvas. |
[email protected] | 32da100 | 2010-03-03 21:57:35 | [diff] [blame] | 559 | gfx::Rect normalized_rect(scaled_width, scaled_height); |
[email protected] | 776775e | 2009-09-21 15:21:29 | [diff] [blame] | 560 | proxy_->Paint(skia_canvas_.get(), normalized_rect); |
| 561 | |
| 562 | // The mac coordinate system is flipped vertical from the normal skia |
| 563 | // coordinates. During painting of the frame, flip the coordinates |
| 564 | // system and, for simplicity, also translate the clip rectangle to |
| 565 | // start at 0,0. |
| 566 | CGContextSaveGState(canvas); |
| 567 | CGContextTranslateCTM(canvas, rect.x, rect.height + rect.y); |
[email protected] | 32da100 | 2010-03-03 21:57:35 | [diff] [blame] | 568 | CGContextScaleCTM(canvas, inverse_scale_x, -inverse_scale_y); |
[email protected] | 776775e | 2009-09-21 15:21:29 | [diff] [blame] | 569 | |
| 570 | // We need a local variable CGRect version for DrawToContext. |
| 571 | CGRect normalized_cgrect = |
| 572 | CGRectMake(normalized_rect.x(), normalized_rect.y(), |
| 573 | normalized_rect.width(), normalized_rect.height()); |
| 574 | |
| 575 | // Copy the frame rendered to our temporary skia canvas onto the passed in |
| 576 | // canvas. |
[email protected] | 62f2e80 | 2011-05-26 14:28:35 | [diff] [blame] | 577 | skia::DrawToNativeContext(skia_canvas_.get(), canvas, 0, 0, |
| 578 | &normalized_cgrect); |
[email protected] | 776775e | 2009-09-21 15:21:29 | [diff] [blame] | 579 | |
| 580 | CGContextRestoreGState(canvas); |
[email protected] | 8c89e779 | 2009-08-19 21:18:34 | [diff] [blame] | 581 | #else |
[email protected] | 776775e | 2009-09-21 15:21:29 | [diff] [blame] | 582 | NOTIMPLEMENTED() << "We only support rendering to skia or CG"; |
[email protected] | 8c89e779 | 2009-08-19 21:18:34 | [diff] [blame] | 583 | #endif |
[email protected] | ec9212f | 2008-12-18 21:40:36 | [diff] [blame] | 584 | } |
[email protected] | 5df5165 | 2009-01-17 00:03:00 | [diff] [blame] | 585 | |
[email protected] | 38259a7a8 | 2009-07-29 21:49:49 | [diff] [blame] | 586 | bool WebMediaPlayerImpl::hasSingleSecurityOrigin() const { |
[email protected] | cf31d6f | 2010-10-26 02:23:47 | [diff] [blame] | 587 | if (proxy_) |
| 588 | return proxy_->HasSingleOrigin(); |
[email protected] | fcdb746 | 2009-10-21 21:05:11 | [diff] [blame] | 589 | return true; |
[email protected] | 38259a7a8 | 2009-07-29 21:49:49 | [diff] [blame] | 590 | } |
| 591 | |
| 592 | WebKit::WebMediaPlayer::MovieLoadType |
| 593 | WebMediaPlayerImpl::movieLoadType() const { |
| 594 | DCHECK(MessageLoop::current() == main_loop_); |
| 595 | |
| 596 | // TODO(hclam): If the pipeline is performing streaming, we say that this is |
| 597 | // a live stream. But instead it should be a StoredStream if we have proper |
| 598 | // caching. |
| 599 | if (pipeline_->IsStreaming()) |
| 600 | return WebKit::WebMediaPlayer::LiveStream; |
| 601 | return WebKit::WebMediaPlayer::Unknown; |
| 602 | } |
| 603 | |
[email protected] | e06e16d8 | 2011-05-26 22:13:33 | [diff] [blame] | 604 | float WebMediaPlayerImpl::mediaTimeForTimeValue(float timeValue) const { |
| 605 | return ConvertSecondsToTimestamp(timeValue).InSecondsF(); |
| 606 | } |
| 607 | |
[email protected] | d82b18ae | 2011-03-23 21:28:59 | [diff] [blame] | 608 | unsigned WebMediaPlayerImpl::decodedFrameCount() const { |
[email protected] | 4c51bc66 | 2011-02-16 02:03:16 | [diff] [blame] | 609 | DCHECK(MessageLoop::current() == main_loop_); |
| 610 | |
| 611 | media::PipelineStatistics stats = pipeline_->GetStatistics(); |
| 612 | return stats.video_frames_decoded; |
| 613 | } |
| 614 | |
[email protected] | d82b18ae | 2011-03-23 21:28:59 | [diff] [blame] | 615 | unsigned WebMediaPlayerImpl::droppedFrameCount() const { |
[email protected] | 4c51bc66 | 2011-02-16 02:03:16 | [diff] [blame] | 616 | DCHECK(MessageLoop::current() == main_loop_); |
| 617 | |
| 618 | media::PipelineStatistics stats = pipeline_->GetStatistics(); |
| 619 | return stats.video_frames_dropped; |
| 620 | } |
| 621 | |
[email protected] | d82b18ae | 2011-03-23 21:28:59 | [diff] [blame] | 622 | unsigned WebMediaPlayerImpl::audioDecodedByteCount() const { |
[email protected] | 4c51bc66 | 2011-02-16 02:03:16 | [diff] [blame] | 623 | DCHECK(MessageLoop::current() == main_loop_); |
| 624 | |
| 625 | media::PipelineStatistics stats = pipeline_->GetStatistics(); |
| 626 | return stats.audio_bytes_decoded; |
| 627 | } |
| 628 | |
[email protected] | d82b18ae | 2011-03-23 21:28:59 | [diff] [blame] | 629 | unsigned WebMediaPlayerImpl::videoDecodedByteCount() const { |
[email protected] | 4c51bc66 | 2011-02-16 02:03:16 | [diff] [blame] | 630 | DCHECK(MessageLoop::current() == main_loop_); |
| 631 | |
| 632 | media::PipelineStatistics stats = pipeline_->GetStatistics(); |
| 633 | return stats.video_bytes_decoded; |
| 634 | } |
| 635 | |
[email protected] | e81283bb | 2010-08-31 18:01:21 | [diff] [blame] | 636 | WebKit::WebVideoFrame* WebMediaPlayerImpl::getCurrentFrame() { |
| 637 | scoped_refptr<media::VideoFrame> video_frame; |
| 638 | proxy_->GetCurrentFrame(&video_frame); |
| 639 | if (video_frame.get()) |
| 640 | return new WebVideoFrameImpl(video_frame); |
| 641 | return NULL; |
| 642 | } |
| 643 | |
| 644 | void WebMediaPlayerImpl::putCurrentFrame( |
| 645 | WebKit::WebVideoFrame* web_video_frame) { |
| 646 | if (web_video_frame) { |
[email protected] | ad8e04a | 2010-11-01 04:16:27 | [diff] [blame] | 647 | scoped_refptr<media::VideoFrame> video_frame( |
| 648 | WebVideoFrameImpl::toVideoFrame(web_video_frame)); |
[email protected] | e81283bb | 2010-08-31 18:01:21 | [diff] [blame] | 649 | proxy_->PutCurrentFrame(video_frame); |
| 650 | delete web_video_frame; |
| 651 | } |
| 652 | } |
| 653 | |
[email protected] | 81bb332 | 2011-07-21 15:55:50 | [diff] [blame] | 654 | // TODO(acolwell): Uncomment once WebKit changes are checked in. |
| 655 | // https://bugs.webkit.org/show_bug.cgi?id=64731 |
| 656 | /* |
| 657 | bool WebMediaPlayerImpl::sourceAppend(const unsigned char* data, |
| 658 | unsigned length) { |
| 659 | DCHECK(MessageLoop::current() == main_loop_); |
| 660 | return proxy_->DemuxerAppend(data, length); |
| 661 | } |
| 662 | |
| 663 | void WebMediaPlayerImpl::sourceEndOfStream( |
| 664 | WebKit::WebMediaPlayer::EndOfStreamStatus status) { |
| 665 | DCHECK(MessageLoop::current() == main_loop_); |
| 666 | media::PipelineStatus pipeline_status = media::PIPELINE_OK; |
| 667 | |
| 668 | switch(status) { |
[email protected] | e4064fd | 2011-08-04 16:15:51 | [diff] [blame] | 669 | case WebKit::WebMediaPlayer::EosNoError: |
| 670 | break; |
[email protected] | 81bb332 | 2011-07-21 15:55:50 | [diff] [blame] | 671 | case WebKit::WebMediaPlayer::EosNetworkError: |
| 672 | pipeline_status = media::PIPELINE_ERROR_NETWORK; |
| 673 | break; |
| 674 | case WebKit::WebMediaPlayer::EosDecodeError: |
| 675 | pipeline_status = media::PIPELINE_ERROR_DECODE; |
| 676 | break; |
| 677 | default: |
| 678 | NOTIMPLEMENTED(); |
| 679 | } |
| 680 | |
| 681 | proxy_->DemuxerEndOfStream(pipeline_status); |
| 682 | } |
| 683 | */ |
| 684 | |
[email protected] | 4e6be3f | 2009-05-07 02:24:44 | [diff] [blame] | 685 | void WebMediaPlayerImpl::WillDestroyCurrentMessageLoop() { |
[email protected] | 8931c41a | 2009-07-07 17:31:49 | [diff] [blame] | 686 | Destroy(); |
| 687 | main_loop_ = NULL; |
| 688 | } |
| 689 | |
| 690 | void WebMediaPlayerImpl::Repaint() { |
| 691 | DCHECK(MessageLoop::current() == main_loop_); |
| 692 | GetClient()->repaint(); |
| 693 | } |
| 694 | |
[email protected] | a9590c2 | 2011-03-16 16:57:02 | [diff] [blame] | 695 | void WebMediaPlayerImpl::OnPipelineInitialize(PipelineStatus status) { |
[email protected] | 8931c41a | 2009-07-07 17:31:49 | [diff] [blame] | 696 | DCHECK(MessageLoop::current() == main_loop_); |
[email protected] | a9590c2 | 2011-03-16 16:57:02 | [diff] [blame] | 697 | if (status == media::PIPELINE_OK) { |
[email protected] | 67cd505 | 2009-09-10 21:53:22 | [diff] [blame] | 698 | // Only keep one time range starting from 0. |
[email protected] | c8ca48ea | 2009-10-16 01:59:17 | [diff] [blame] | 699 | WebKit::WebTimeRanges new_buffered(static_cast<size_t>(1)); |
[email protected] | 747ca43 | 2009-10-09 22:44:48 | [diff] [blame] | 700 | new_buffered[0].start = 0.0f; |
| 701 | new_buffered[0].end = |
[email protected] | fd286f2 | 2010-04-20 23:45:15 | [diff] [blame] | 702 | static_cast<float>(pipeline_->GetMediaDuration().InSecondsF()); |
[email protected] | 747ca43 | 2009-10-09 22:44:48 | [diff] [blame] | 703 | buffered_.swap(new_buffered); |
[email protected] | 67cd505 | 2009-09-10 21:53:22 | [diff] [blame] | 704 | |
[email protected] | 65bdef09c | 2011-05-20 05:41:27 | [diff] [blame] | 705 | if (pipeline_->IsLoaded()) { |
| 706 | SetNetworkState(WebKit::WebMediaPlayer::Loaded); |
| 707 | } |
| 708 | |
[email protected] | 64d3d79 | 2010-04-02 03:03:07 | [diff] [blame] | 709 | // Since we have initialized the pipeline, say we have everything otherwise |
| 710 | // we'll remain either loading/idle. |
[email protected] | 9670691 | 2009-07-15 17:18:05 | [diff] [blame] | 711 | // TODO(hclam): change this to report the correct status. |
| 712 | SetReadyState(WebKit::WebMediaPlayer::HaveMetadata); |
| 713 | SetReadyState(WebKit::WebMediaPlayer::HaveEnoughData); |
[email protected] | 9670691 | 2009-07-15 17:18:05 | [diff] [blame] | 714 | } else { |
[email protected] | a9590c2 | 2011-03-16 16:57:02 | [diff] [blame] | 715 | // TODO(hclam): should use |status| to determine the state |
[email protected] | 9670691 | 2009-07-15 17:18:05 | [diff] [blame] | 716 | // properly and reports error using MediaError. |
| 717 | // WebKit uses FormatError to indicate an error for bogus URL or bad file. |
| 718 | // Since we are at the initialization stage we can safely treat every error |
| 719 | // as format error. Should post a task to call to |webmediaplayer_|. |
| 720 | SetNetworkState(WebKit::WebMediaPlayer::FormatError); |
| 721 | } |
[email protected] | 83f2a8a | 2009-08-18 22:42:15 | [diff] [blame] | 722 | |
| 723 | // Repaint to trigger UI update. |
| 724 | Repaint(); |
[email protected] | 9670691 | 2009-07-15 17:18:05 | [diff] [blame] | 725 | } |
| 726 | |
[email protected] | a9590c2 | 2011-03-16 16:57:02 | [diff] [blame] | 727 | void WebMediaPlayerImpl::OnPipelineSeek(PipelineStatus status) { |
[email protected] | 9670691 | 2009-07-15 17:18:05 | [diff] [blame] | 728 | DCHECK(MessageLoop::current() == main_loop_); |
[email protected] | 5d11eff | 2011-09-15 00:06:06 | [diff] [blame] | 729 | seeking_ = false; |
| 730 | if (pending_seek_) { |
| 731 | pending_seek_ = false; |
| 732 | seek(pending_seek_seconds_); |
| 733 | return; |
| 734 | } |
| 735 | |
[email protected] | a9590c2 | 2011-03-16 16:57:02 | [diff] [blame] | 736 | if (status == media::PIPELINE_OK) { |
[email protected] | 44ff37c0 | 2009-10-24 01:03:03 | [diff] [blame] | 737 | // Update our paused time. |
| 738 | if (paused_) { |
| 739 | paused_time_ = pipeline_->GetCurrentTime(); |
| 740 | } |
| 741 | |
[email protected] | 0acebfa | 2009-08-21 22:45:40 | [diff] [blame] | 742 | SetReadyState(WebKit::WebMediaPlayer::HaveEnoughData); |
[email protected] | 9670691 | 2009-07-15 17:18:05 | [diff] [blame] | 743 | GetClient()->timeChanged(); |
| 744 | } |
[email protected] | 8931c41a | 2009-07-07 17:31:49 | [diff] [blame] | 745 | } |
| 746 | |
[email protected] | a9590c2 | 2011-03-16 16:57:02 | [diff] [blame] | 747 | void WebMediaPlayerImpl::OnPipelineEnded(PipelineStatus status) { |
[email protected] | 57653784 | 2009-08-12 23:52:05 | [diff] [blame] | 748 | DCHECK(MessageLoop::current() == main_loop_); |
[email protected] | a9590c2 | 2011-03-16 16:57:02 | [diff] [blame] | 749 | if (status == media::PIPELINE_OK) { |
[email protected] | 57653784 | 2009-08-12 23:52:05 | [diff] [blame] | 750 | GetClient()->timeChanged(); |
| 751 | } |
| 752 | } |
| 753 | |
[email protected] | a9590c2 | 2011-03-16 16:57:02 | [diff] [blame] | 754 | void WebMediaPlayerImpl::OnPipelineError(PipelineStatus error) { |
[email protected] | db190487d | 2009-07-30 18:51:52 | [diff] [blame] | 755 | DCHECK(MessageLoop::current() == main_loop_); |
[email protected] | a9590c2 | 2011-03-16 16:57:02 | [diff] [blame] | 756 | switch (error) { |
[email protected] | db190487d | 2009-07-30 18:51:52 | [diff] [blame] | 757 | case media::PIPELINE_OK: |
[email protected] | a9590c2 | 2011-03-16 16:57:02 | [diff] [blame] | 758 | LOG(DFATAL) << "PIPELINE_OK isn't an error!"; |
| 759 | break; |
| 760 | |
[email protected] | e4064fd | 2011-08-04 16:15:51 | [diff] [blame] | 761 | case media::PIPELINE_ERROR_NETWORK: |
| 762 | SetNetworkState(WebMediaPlayer::NetworkError); |
| 763 | break; |
| 764 | |
[email protected] | db190487d | 2009-07-30 18:51:52 | [diff] [blame] | 765 | case media::PIPELINE_ERROR_INITIALIZATION_FAILED: |
| 766 | case media::PIPELINE_ERROR_REQUIRED_FILTER_MISSING: |
| 767 | case media::PIPELINE_ERROR_COULD_NOT_RENDER: |
[email protected] | db190487d | 2009-07-30 18:51:52 | [diff] [blame] | 768 | case media::PIPELINE_ERROR_URL_NOT_FOUND: |
[email protected] | db190487d | 2009-07-30 18:51:52 | [diff] [blame] | 769 | case media::PIPELINE_ERROR_READ: |
[email protected] | db190487d | 2009-07-30 18:51:52 | [diff] [blame] | 770 | case media::DEMUXER_ERROR_COULD_NOT_OPEN: |
| 771 | case media::DEMUXER_ERROR_COULD_NOT_PARSE: |
| 772 | case media::DEMUXER_ERROR_NO_SUPPORTED_STREAMS: |
| 773 | case media::DEMUXER_ERROR_COULD_NOT_CREATE_THREAD: |
[email protected] | b6c2955 | 2011-03-14 15:56:29 | [diff] [blame] | 774 | case media::DATASOURCE_ERROR_URL_NOT_SUPPORTED: |
[email protected] | 9c4e77ab | 2009-07-31 00:17:08 | [diff] [blame] | 775 | // Format error. |
| 776 | SetNetworkState(WebMediaPlayer::FormatError); |
| 777 | break; |
| 778 | |
| 779 | case media::PIPELINE_ERROR_DECODE: |
| 780 | case media::PIPELINE_ERROR_ABORT: |
| 781 | case media::PIPELINE_ERROR_OUT_OF_MEMORY: |
| 782 | case media::PIPELINE_ERROR_AUDIO_HARDWARE: |
[email protected] | 641c9abc | 2011-01-05 18:44:10 | [diff] [blame] | 783 | case media::PIPELINE_ERROR_OPERATION_PENDING: |
| 784 | case media::PIPELINE_ERROR_INVALID_STATE: |
[email protected] | db190487d | 2009-07-30 18:51:52 | [diff] [blame] | 785 | // Decode error. |
| 786 | SetNetworkState(WebMediaPlayer::DecodeError); |
| 787 | break; |
| 788 | } |
[email protected] | bb2c1f3 | 2009-08-14 04:14:50 | [diff] [blame] | 789 | |
| 790 | // Repaint to trigger UI update. |
| 791 | Repaint(); |
[email protected] | db190487d | 2009-07-30 18:51:52 | [diff] [blame] | 792 | } |
| 793 | |
[email protected] | a9590c2 | 2011-03-16 16:57:02 | [diff] [blame] | 794 | void WebMediaPlayerImpl::OnNetworkEvent(PipelineStatus status) { |
[email protected] | 4f92fbc | 2009-10-16 01:29:50 | [diff] [blame] | 795 | DCHECK(MessageLoop::current() == main_loop_); |
[email protected] | a9590c2 | 2011-03-16 16:57:02 | [diff] [blame] | 796 | if (status == media::PIPELINE_OK) { |
[email protected] | 7b5ce7d6d | 2011-08-17 14:07:47 | [diff] [blame] | 797 | if (pipeline_->IsNetworkActive()) |
[email protected] | 4f92fbc | 2009-10-16 01:29:50 | [diff] [blame] | 798 | SetNetworkState(WebKit::WebMediaPlayer::Loading); |
[email protected] | 7b5ce7d6d | 2011-08-17 14:07:47 | [diff] [blame] | 799 | else |
[email protected] | 4f92fbc | 2009-10-16 01:29:50 | [diff] [blame] | 800 | SetNetworkState(WebKit::WebMediaPlayer::Idle); |
| 801 | } |
| 802 | } |
| 803 | |
[email protected] | 81bb332 | 2011-07-21 15:55:50 | [diff] [blame] | 804 | void WebMediaPlayerImpl::OnDemuxerOpened() { |
| 805 | DCHECK(MessageLoop::current() == main_loop_); |
| 806 | |
| 807 | // TODO(acolwell): Uncomment once WebKit changes are checked in. |
| 808 | // https://bugs.webkit.org/show_bug.cgi?id=64731 |
| 809 | //GetClient()->sourceOpened(); |
| 810 | } |
| 811 | |
[email protected] | 8931c41a | 2009-07-07 17:31:49 | [diff] [blame] | 812 | void WebMediaPlayerImpl::SetNetworkState( |
| 813 | WebKit::WebMediaPlayer::NetworkState state) { |
| 814 | DCHECK(MessageLoop::current() == main_loop_); |
[email protected] | 867e5927 | 2009-08-25 18:08:16 | [diff] [blame] | 815 | // Always notify to ensure client has the latest value. |
| 816 | network_state_ = state; |
| 817 | GetClient()->networkStateChanged(); |
[email protected] | 8931c41a | 2009-07-07 17:31:49 | [diff] [blame] | 818 | } |
| 819 | |
| 820 | void WebMediaPlayerImpl::SetReadyState( |
| 821 | WebKit::WebMediaPlayer::ReadyState state) { |
| 822 | DCHECK(MessageLoop::current() == main_loop_); |
[email protected] | 867e5927 | 2009-08-25 18:08:16 | [diff] [blame] | 823 | // Always notify to ensure client has the latest value. |
| 824 | ready_state_ = state; |
| 825 | GetClient()->readyStateChanged(); |
[email protected] | 8931c41a | 2009-07-07 17:31:49 | [diff] [blame] | 826 | } |
| 827 | |
| 828 | void WebMediaPlayerImpl::Destroy() { |
| 829 | DCHECK(MessageLoop::current() == main_loop_); |
| 830 | |
[email protected] | 5b5bb9d | 2010-10-22 19:57:36 | [diff] [blame] | 831 | // Tell the data source to abort any pending reads so that the pipeline is |
| 832 | // not blocked when issuing stop commands to the other filters. |
[email protected] | 81bb332 | 2011-07-21 15:55:50 | [diff] [blame] | 833 | if (proxy_) { |
[email protected] | f63760a | 2011-02-16 04:59:10 | [diff] [blame] | 834 | proxy_->AbortDataSources(); |
[email protected] | 81bb332 | 2011-07-21 15:55:50 | [diff] [blame] | 835 | proxy_->DemuxerShutdown(); |
| 836 | } |
[email protected] | 020fba3 | 2011-06-29 16:37:46 | [diff] [blame] | 837 | |
[email protected] | 8931c41a | 2009-07-07 17:31:49 | [diff] [blame] | 838 | // Make sure to kill the pipeline so there's no more media threads running. |
[email protected] | 5badb08 | 2010-06-11 17:40:15 | [diff] [blame] | 839 | // Note: stopping the pipeline might block for a long time. |
[email protected] | a8e24d52 | 2010-12-01 07:13:58 | [diff] [blame] | 840 | if (pipeline_) { |
[email protected] | ea431e5 | 2011-03-17 22:03:12 | [diff] [blame] | 841 | media::PipelineStatusNotification note; |
| 842 | pipeline_->Stop(note.Callback()); |
| 843 | note.Wait(); |
[email protected] | 38aefc31 | 2011-09-20 05:06:37 | [diff] [blame^] | 844 | |
| 845 | // Let V8 know we are not using extra resources anymore. |
| 846 | if (destructor_or_task_had_run_.get() != NULL) { |
| 847 | if (destructor_or_task_had_run_->value()) |
| 848 | v8::V8::AdjustAmountOfExternalAllocatedMemory(-kPlayerExtraMemory); |
| 849 | else |
| 850 | destructor_or_task_had_run_->set_value(true); |
| 851 | } |
| 852 | destructor_or_task_had_run_ = NULL; |
[email protected] | a8e24d52 | 2010-12-01 07:13:58 | [diff] [blame] | 853 | } |
[email protected] | 5df5165 | 2009-01-17 00:03:00 | [diff] [blame] | 854 | |
[email protected] | f78d1dfc | 2011-01-15 07:09:27 | [diff] [blame] | 855 | message_loop_factory_.reset(); |
| 856 | |
[email protected] | 8931c41a | 2009-07-07 17:31:49 | [diff] [blame] | 857 | // And then detach the proxy, it may live on the render thread for a little |
| 858 | // longer until all the tasks are finished. |
| 859 | if (proxy_) { |
| 860 | proxy_->Detach(); |
| 861 | proxy_ = NULL; |
[email protected] | a728102 | 2009-06-17 17:58:04 | [diff] [blame] | 862 | } |
[email protected] | 5df5165 | 2009-01-17 00:03:00 | [diff] [blame] | 863 | } |
| 864 | |
[email protected] | 8931c41a | 2009-07-07 17:31:49 | [diff] [blame] | 865 | WebKit::WebMediaPlayerClient* WebMediaPlayerImpl::GetClient() { |
| 866 | DCHECK(MessageLoop::current() == main_loop_); |
| 867 | DCHECK(client_); |
| 868 | return client_; |
[email protected] | 5df5165 | 2009-01-17 00:03:00 | [diff] [blame] | 869 | } |
[email protected] | add5177 | 2009-06-11 18:25:17 | [diff] [blame] | 870 | |
[email protected] | 38aefc31 | 2011-09-20 05:06:37 | [diff] [blame^] | 871 | void WebMediaPlayerImpl::UsesExtraMemoryTask( |
| 872 | scoped_refptr<DestructorOrTaskHadRun> destructor_or_task_had_run) { |
| 873 | if (!destructor_or_task_had_run->value()) { |
| 874 | v8::V8::AdjustAmountOfExternalAllocatedMemory(kPlayerExtraMemory); |
| 875 | destructor_or_task_had_run->set_value(true); |
| 876 | } |
| 877 | } |
| 878 | |
[email protected] | add5177 | 2009-06-11 18:25:17 | [diff] [blame] | 879 | } // namespace webkit_glue |