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