Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(7)

Side by Side Diff: webkit/media/webmediaplayer_impl.cc

Issue 12388039: Use base::MessageLoopProxy instead of MessageLoop* in webkit/media/. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « webkit/media/webmediaplayer_impl.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "webkit/media/webmediaplayer_impl.h" 5 #include "webkit/media/webmediaplayer_impl.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <limits> 8 #include <limits>
9 #include <string> 9 #include <string>
10 #include <vector> 10 #include <vector>
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
89 #define COMPILE_ASSERT_MATCHING_ENUM(name) \ 89 #define COMPILE_ASSERT_MATCHING_ENUM(name) \
90 COMPILE_ASSERT(static_cast<int>(WebMediaPlayer::CORSMode ## name) == \ 90 COMPILE_ASSERT(static_cast<int>(WebMediaPlayer::CORSMode ## name) == \
91 static_cast<int>(BufferedResourceLoader::k ## name), \ 91 static_cast<int>(BufferedResourceLoader::k ## name), \
92 mismatching_enums) 92 mismatching_enums)
93 COMPILE_ASSERT_MATCHING_ENUM(Unspecified); 93 COMPILE_ASSERT_MATCHING_ENUM(Unspecified);
94 COMPILE_ASSERT_MATCHING_ENUM(Anonymous); 94 COMPILE_ASSERT_MATCHING_ENUM(Anonymous);
95 COMPILE_ASSERT_MATCHING_ENUM(UseCredentials); 95 COMPILE_ASSERT_MATCHING_ENUM(UseCredentials);
96 #undef COMPILE_ASSERT_MATCHING_ENUM 96 #undef COMPILE_ASSERT_MATCHING_ENUM
97 97
98 #define BIND_TO_RENDER_LOOP(function) \ 98 #define BIND_TO_RENDER_LOOP(function) \
99 media::BindToLoop(main_loop_->message_loop_proxy(), base::Bind( \ 99 media::BindToLoop(main_loop_, base::Bind(function, AsWeakPtr()))
100 function, AsWeakPtr()))
101 100
102 #define BIND_TO_RENDER_LOOP_2(function, arg1, arg2) \ 101 #define BIND_TO_RENDER_LOOP_2(function, arg1, arg2) \
103 media::BindToLoop(main_loop_->message_loop_proxy(), base::Bind( \ 102 media::BindToLoop(main_loop_, base::Bind(function, AsWeakPtr(), arg1, arg2))
104 function, AsWeakPtr(), arg1, arg2))
105 103
106 static WebKit::WebTimeRanges ConvertToWebTimeRanges( 104 static WebKit::WebTimeRanges ConvertToWebTimeRanges(
107 const media::Ranges<base::TimeDelta>& ranges) { 105 const media::Ranges<base::TimeDelta>& ranges) {
108 WebKit::WebTimeRanges result(ranges.size()); 106 WebKit::WebTimeRanges result(ranges.size());
109 for (size_t i = 0; i < ranges.size(); i++) { 107 for (size_t i = 0; i < ranges.size(); i++) {
110 result[i].start = ranges.start(i).InSecondsF(); 108 result[i].start = ranges.start(i).InSecondsF();
111 result[i].end = ranges.end(i).InSecondsF(); 109 result[i].end = ranges.end(i).InSecondsF();
112 } 110 }
113 return result; 111 return result;
114 } 112 }
115 113
116 static void LogMediaSourceError(const scoped_refptr<media::MediaLog>& media_log, 114 static void LogMediaSourceError(const scoped_refptr<media::MediaLog>& media_log,
117 const std::string& error) { 115 const std::string& error) {
118 media_log->AddEvent(media_log->CreateMediaSourceErrorEvent(error)); 116 media_log->AddEvent(media_log->CreateMediaSourceErrorEvent(error));
119 } 117 }
120 118
121 WebMediaPlayerImpl::WebMediaPlayerImpl( 119 WebMediaPlayerImpl::WebMediaPlayerImpl(
122 WebKit::WebFrame* frame, 120 WebKit::WebFrame* frame,
123 WebKit::WebMediaPlayerClient* client, 121 WebKit::WebMediaPlayerClient* client,
124 base::WeakPtr<WebMediaPlayerDelegate> delegate, 122 base::WeakPtr<WebMediaPlayerDelegate> delegate,
125 const WebMediaPlayerParams& params) 123 const WebMediaPlayerParams& params)
126 : frame_(frame), 124 : frame_(frame),
127 network_state_(WebMediaPlayer::NetworkStateEmpty), 125 network_state_(WebMediaPlayer::NetworkStateEmpty),
128 ready_state_(WebMediaPlayer::ReadyStateHaveNothing), 126 ready_state_(WebMediaPlayer::ReadyStateHaveNothing),
129 main_loop_(MessageLoop::current()), 127 main_loop_(base::MessageLoopProxy::current()),
130 filter_collection_(new media::FilterCollection()), 128 filter_collection_(new media::FilterCollection()),
131 media_thread_("MediaPipeline"), 129 media_thread_("MediaPipeline"),
132 paused_(true), 130 paused_(true),
133 seeking_(false), 131 seeking_(false),
134 playback_rate_(0.0f), 132 playback_rate_(0.0f),
135 pending_seek_(false), 133 pending_seek_(false),
136 pending_seek_seconds_(0.0f), 134 pending_seek_seconds_(0.0f),
137 client_(client), 135 client_(client),
138 proxy_(new WebMediaPlayerProxy(main_loop_->message_loop_proxy(), this)), 136 proxy_(new WebMediaPlayerProxy(main_loop_, this)),
139 delegate_(delegate), 137 delegate_(delegate),
140 media_stream_client_(params.media_stream_client()), 138 media_stream_client_(params.media_stream_client()),
141 media_log_(params.media_log()), 139 media_log_(params.media_log()),
142 accelerated_compositing_reported_(false), 140 accelerated_compositing_reported_(false),
143 incremented_externally_allocated_memory_(false), 141 incremented_externally_allocated_memory_(false),
144 is_local_source_(false), 142 is_local_source_(false),
145 supports_save_(true), 143 supports_save_(true),
146 starting_(false) { 144 starting_(false) {
147 media_log_->AddEvent( 145 media_log_->AddEvent(
148 media_log_->CreateEvent(media::MediaLogEvent::WEBMEDIAPLAYER_CREATED)); 146 media_log_->CreateEvent(media::MediaLogEvent::WEBMEDIAPLAYER_CREATED));
149 147
150 CHECK(media_thread_.Start()); 148 CHECK(media_thread_.Start());
151 pipeline_ = new media::Pipeline( 149 pipeline_ = new media::Pipeline(
152 media_thread_.message_loop_proxy(), media_log_); 150 media_thread_.message_loop_proxy(), media_log_);
153 151
154 // Let V8 know we started new thread if we did not do it yet. 152 // Let V8 know we started new thread if we did not do it yet.
155 // Made separate task to avoid deletion of player currently being created. 153 // Made separate task to avoid deletion of player currently being created.
156 // Also, delaying GC until after player starts gets rid of starting lag -- 154 // Also, delaying GC until after player starts gets rid of starting lag --
157 // collection happens in parallel with playing. 155 // collection happens in parallel with playing.
158 // 156 //
159 // TODO(enal): remove when we get rid of per-audio-stream thread. 157 // TODO(enal): remove when we get rid of per-audio-stream thread.
160 MessageLoop::current()->PostTask( 158 main_loop_->PostTask(
161 FROM_HERE, 159 FROM_HERE,
162 base::Bind(&WebMediaPlayerImpl::IncrementExternallyAllocatedMemory, 160 base::Bind(&WebMediaPlayerImpl::IncrementExternallyAllocatedMemory,
163 AsWeakPtr())); 161 AsWeakPtr()));
164 162
165 // Also we want to be notified of |main_loop_| destruction. 163 // Also we want to be notified of |main_loop_| destruction.
166 main_loop_->AddDestructionObserver(this); 164 MessageLoop::current()->AddDestructionObserver(this);
167 165
168 media::SetDecryptorReadyCB set_decryptor_ready_cb; 166 media::SetDecryptorReadyCB set_decryptor_ready_cb;
169 if (WebKit::WebRuntimeFeatures::isEncryptedMediaEnabled()) { 167 if (WebKit::WebRuntimeFeatures::isEncryptedMediaEnabled()) {
170 decryptor_.reset(new ProxyDecryptor( 168 decryptor_.reset(new ProxyDecryptor(
171 client, 169 client,
172 frame, 170 frame,
173 BIND_TO_RENDER_LOOP(&WebMediaPlayerImpl::OnKeyAdded), 171 BIND_TO_RENDER_LOOP(&WebMediaPlayerImpl::OnKeyAdded),
174 BIND_TO_RENDER_LOOP(&WebMediaPlayerImpl::OnKeyError), 172 BIND_TO_RENDER_LOOP(&WebMediaPlayerImpl::OnKeyError),
175 BIND_TO_RENDER_LOOP(&WebMediaPlayerImpl::OnKeyMessage), 173 BIND_TO_RENDER_LOOP(&WebMediaPlayerImpl::OnKeyMessage),
176 BIND_TO_RENDER_LOOP(&WebMediaPlayerImpl::OnNeedKey))); 174 BIND_TO_RENDER_LOOP(&WebMediaPlayerImpl::OnNeedKey)));
(...skipping 25 matching lines...) Expand all
202 new media::NullAudioSink()); 200 new media::NullAudioSink());
203 scoped_ptr<media::AudioRenderer> audio_renderer( 201 scoped_ptr<media::AudioRenderer> audio_renderer(
204 new media::AudioRendererImpl( 202 new media::AudioRendererImpl(
205 media_thread_.message_loop_proxy(), 203 media_thread_.message_loop_proxy(),
206 audio_source_provider_, 204 audio_source_provider_,
207 set_decryptor_ready_cb)); 205 set_decryptor_ready_cb));
208 filter_collection_->SetAudioRenderer(audio_renderer.Pass()); 206 filter_collection_->SetAudioRenderer(audio_renderer.Pass());
209 } 207 }
210 208
211 WebMediaPlayerImpl::~WebMediaPlayerImpl() { 209 WebMediaPlayerImpl::~WebMediaPlayerImpl() {
212 DCHECK_EQ(main_loop_, MessageLoop::current()); 210 DCHECK(main_loop_->BelongsToCurrentThread());
213 Destroy(); 211 Destroy();
214 media_log_->AddEvent( 212 media_log_->AddEvent(
215 media_log_->CreateEvent(media::MediaLogEvent::WEBMEDIAPLAYER_DESTROYED)); 213 media_log_->CreateEvent(media::MediaLogEvent::WEBMEDIAPLAYER_DESTROYED));
216 214
217 if (delegate_) 215 if (delegate_)
218 delegate_->PlayerGone(this); 216 delegate_->PlayerGone(this);
219 217
220 // Finally tell the |main_loop_| we don't want to be notified of destruction 218 // Remove descrution observer if we're being destroyed but the main thread is
221 // event. 219 // still running.
222 if (main_loop_) { 220 if (MessageLoop::current())
scherkus (not reviewing) 2013/03/01 00:44:01 this is NULL after WillDestroyCurrentMessageLoop()
223 main_loop_->RemoveDestructionObserver(this); 221 MessageLoop::current()->RemoveDestructionObserver(this);
224 }
225 } 222 }
226 223
227 namespace { 224 namespace {
228 225
229 // Helper enum for reporting scheme histograms. 226 // Helper enum for reporting scheme histograms.
230 enum URLSchemeForHistogram { 227 enum URLSchemeForHistogram {
231 kUnknownURLScheme, 228 kUnknownURLScheme,
232 kMissingURLScheme, 229 kMissingURLScheme,
233 kHttpURLScheme, 230 kHttpURLScheme,
234 kHttpsURLScheme, 231 kHttpsURLScheme,
(...skipping 17 matching lines...) Expand all
252 if (url.SchemeIs("file")) return kFileURLScheme; 249 if (url.SchemeIs("file")) return kFileURLScheme;
253 if (url.SchemeIs("blob")) return kBlobURLScheme; 250 if (url.SchemeIs("blob")) return kBlobURLScheme;
254 if (url.SchemeIs("data")) return kDataURLScheme; 251 if (url.SchemeIs("data")) return kDataURLScheme;
255 if (url.SchemeIs("filesystem")) return kFileSystemScheme; 252 if (url.SchemeIs("filesystem")) return kFileSystemScheme;
256 return kUnknownURLScheme; 253 return kUnknownURLScheme;
257 } 254 }
258 255
259 } // anonymous namespace 256 } // anonymous namespace
260 257
261 void WebMediaPlayerImpl::load(const WebKit::WebURL& url, CORSMode cors_mode) { 258 void WebMediaPlayerImpl::load(const WebKit::WebURL& url, CORSMode cors_mode) {
262 DCHECK_EQ(main_loop_, MessageLoop::current()); 259 DCHECK(main_loop_->BelongsToCurrentThread());
263 260
264 GURL gurl(url); 261 GURL gurl(url);
265 UMA_HISTOGRAM_ENUMERATION("Media.URLScheme", URLScheme(gurl), kMaxURLScheme); 262 UMA_HISTOGRAM_ENUMERATION("Media.URLScheme", URLScheme(gurl), kMaxURLScheme);
266 263
267 // Handle any volume/preload changes that occured before load(). 264 // Handle any volume/preload changes that occured before load().
268 setVolume(GetClient()->volume()); 265 setVolume(GetClient()->volume());
269 setPreload(GetClient()->preload()); 266 setPreload(GetClient()->preload());
270 267
271 SetNetworkState(WebMediaPlayer::NetworkStateLoading); 268 SetNetworkState(WebMediaPlayer::NetworkStateLoading);
272 SetReadyState(WebMediaPlayer::ReadyStateHaveNothing); 269 SetReadyState(WebMediaPlayer::ReadyStateHaveNothing);
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
308 AsWeakPtr(), gurl)); 305 AsWeakPtr(), gurl));
309 306
310 is_local_source_ = !gurl.SchemeIs("http") && !gurl.SchemeIs("https"); 307 is_local_source_ = !gurl.SchemeIs("http") && !gurl.SchemeIs("https");
311 308
312 BuildDefaultCollection(proxy_->data_source(), 309 BuildDefaultCollection(proxy_->data_source(),
313 media_thread_.message_loop_proxy(), 310 media_thread_.message_loop_proxy(),
314 filter_collection_.get()); 311 filter_collection_.get());
315 } 312 }
316 313
317 void WebMediaPlayerImpl::cancelLoad() { 314 void WebMediaPlayerImpl::cancelLoad() {
318 DCHECK_EQ(main_loop_, MessageLoop::current()); 315 DCHECK(main_loop_->BelongsToCurrentThread());
319 } 316 }
320 317
321 void WebMediaPlayerImpl::play() { 318 void WebMediaPlayerImpl::play() {
322 DCHECK_EQ(main_loop_, MessageLoop::current()); 319 DCHECK(main_loop_->BelongsToCurrentThread());
323 320
324 paused_ = false; 321 paused_ = false;
325 pipeline_->SetPlaybackRate(playback_rate_); 322 pipeline_->SetPlaybackRate(playback_rate_);
326 323
327 media_log_->AddEvent(media_log_->CreateEvent(media::MediaLogEvent::PLAY)); 324 media_log_->AddEvent(media_log_->CreateEvent(media::MediaLogEvent::PLAY));
328 325
329 if (delegate_) 326 if (delegate_)
330 delegate_->DidPlay(this); 327 delegate_->DidPlay(this);
331 } 328 }
332 329
333 void WebMediaPlayerImpl::pause() { 330 void WebMediaPlayerImpl::pause() {
334 DCHECK_EQ(main_loop_, MessageLoop::current()); 331 DCHECK(main_loop_->BelongsToCurrentThread());
335 332
336 paused_ = true; 333 paused_ = true;
337 pipeline_->SetPlaybackRate(0.0f); 334 pipeline_->SetPlaybackRate(0.0f);
338 paused_time_ = pipeline_->GetMediaTime(); 335 paused_time_ = pipeline_->GetMediaTime();
339 336
340 media_log_->AddEvent(media_log_->CreateEvent(media::MediaLogEvent::PAUSE)); 337 media_log_->AddEvent(media_log_->CreateEvent(media::MediaLogEvent::PAUSE));
341 338
342 if (delegate_) 339 if (delegate_)
343 delegate_->DidPause(this); 340 delegate_->DidPause(this);
344 } 341 }
345 342
346 bool WebMediaPlayerImpl::supportsFullscreen() const { 343 bool WebMediaPlayerImpl::supportsFullscreen() const {
347 DCHECK_EQ(main_loop_, MessageLoop::current()); 344 DCHECK(main_loop_->BelongsToCurrentThread());
348 return true; 345 return true;
349 } 346 }
350 347
351 bool WebMediaPlayerImpl::supportsSave() const { 348 bool WebMediaPlayerImpl::supportsSave() const {
352 DCHECK_EQ(main_loop_, MessageLoop::current()); 349 DCHECK(main_loop_->BelongsToCurrentThread());
353 return supports_save_; 350 return supports_save_;
354 } 351 }
355 352
356 void WebMediaPlayerImpl::seek(float seconds) { 353 void WebMediaPlayerImpl::seek(float seconds) {
357 DCHECK_EQ(main_loop_, MessageLoop::current()); 354 DCHECK(main_loop_->BelongsToCurrentThread());
358 355
359 if (starting_ || seeking_) { 356 if (starting_ || seeking_) {
360 pending_seek_ = true; 357 pending_seek_ = true;
361 pending_seek_seconds_ = seconds; 358 pending_seek_seconds_ = seconds;
362 if (chunk_demuxer_) 359 if (chunk_demuxer_)
363 chunk_demuxer_->CancelPendingSeek(); 360 chunk_demuxer_->CancelPendingSeek();
364 return; 361 return;
365 } 362 }
366 363
367 media_log_->AddEvent(media_log_->CreateSeekEvent(seconds)); 364 media_log_->AddEvent(media_log_->CreateSeekEvent(seconds));
368 365
369 base::TimeDelta seek_time = ConvertSecondsToTimestamp(seconds); 366 base::TimeDelta seek_time = ConvertSecondsToTimestamp(seconds);
370 367
371 // Update our paused time. 368 // Update our paused time.
372 if (paused_) 369 if (paused_)
373 paused_time_ = seek_time; 370 paused_time_ = seek_time;
374 371
375 seeking_ = true; 372 seeking_ = true;
376 373
377 if (chunk_demuxer_) 374 if (chunk_demuxer_)
378 chunk_demuxer_->StartWaitingForSeek(); 375 chunk_demuxer_->StartWaitingForSeek();
379 376
380 // Kick off the asynchronous seek! 377 // Kick off the asynchronous seek!
381 pipeline_->Seek( 378 pipeline_->Seek(
382 seek_time, 379 seek_time,
383 BIND_TO_RENDER_LOOP(&WebMediaPlayerImpl::OnPipelineSeek)); 380 BIND_TO_RENDER_LOOP(&WebMediaPlayerImpl::OnPipelineSeek));
384 } 381 }
385 382
386 void WebMediaPlayerImpl::setEndTime(float seconds) { 383 void WebMediaPlayerImpl::setEndTime(float seconds) {
387 DCHECK_EQ(main_loop_, MessageLoop::current()); 384 DCHECK(main_loop_->BelongsToCurrentThread());
388 385
389 // TODO(hclam): add method call when it has been implemented. 386 // TODO(hclam): add method call when it has been implemented.
390 return; 387 return;
391 } 388 }
392 389
393 void WebMediaPlayerImpl::setRate(float rate) { 390 void WebMediaPlayerImpl::setRate(float rate) {
394 DCHECK_EQ(main_loop_, MessageLoop::current()); 391 DCHECK(main_loop_->BelongsToCurrentThread());
395 392
396 // TODO(kylep): Remove when support for negatives is added. Also, modify the 393 // TODO(kylep): Remove when support for negatives is added. Also, modify the
397 // following checks so rewind uses reasonable values also. 394 // following checks so rewind uses reasonable values also.
398 if (rate < 0.0f) 395 if (rate < 0.0f)
399 return; 396 return;
400 397
401 // Limit rates to reasonable values by clamping. 398 // Limit rates to reasonable values by clamping.
402 if (rate != 0.0f) { 399 if (rate != 0.0f) {
403 if (rate < kMinRate) 400 if (rate < kMinRate)
404 rate = kMinRate; 401 rate = kMinRate;
405 else if (rate > kMaxRate) 402 else if (rate > kMaxRate)
406 rate = kMaxRate; 403 rate = kMaxRate;
407 } 404 }
408 405
409 playback_rate_ = rate; 406 playback_rate_ = rate;
410 if (!paused_) { 407 if (!paused_) {
411 pipeline_->SetPlaybackRate(rate); 408 pipeline_->SetPlaybackRate(rate);
412 } 409 }
413 } 410 }
414 411
415 void WebMediaPlayerImpl::setVolume(float volume) { 412 void WebMediaPlayerImpl::setVolume(float volume) {
416 DCHECK_EQ(main_loop_, MessageLoop::current()); 413 DCHECK(main_loop_->BelongsToCurrentThread());
417 414
418 pipeline_->SetVolume(volume); 415 pipeline_->SetVolume(volume);
419 } 416 }
420 417
421 void WebMediaPlayerImpl::setVisible(bool visible) { 418 void WebMediaPlayerImpl::setVisible(bool visible) {
422 DCHECK_EQ(main_loop_, MessageLoop::current()); 419 DCHECK(main_loop_->BelongsToCurrentThread());
423 420
424 // TODO(hclam): add appropriate method call when pipeline has it implemented. 421 // TODO(hclam): add appropriate method call when pipeline has it implemented.
425 return; 422 return;
426 } 423 }
427 424
428 #define COMPILE_ASSERT_MATCHING_ENUM(webkit_name, chromium_name) \ 425 #define COMPILE_ASSERT_MATCHING_ENUM(webkit_name, chromium_name) \
429 COMPILE_ASSERT(static_cast<int>(WebMediaPlayer::webkit_name) == \ 426 COMPILE_ASSERT(static_cast<int>(WebMediaPlayer::webkit_name) == \
430 static_cast<int>(webkit_media::chromium_name), \ 427 static_cast<int>(webkit_media::chromium_name), \
431 mismatching_enums) 428 mismatching_enums)
432 COMPILE_ASSERT_MATCHING_ENUM(PreloadNone, NONE); 429 COMPILE_ASSERT_MATCHING_ENUM(PreloadNone, NONE);
433 COMPILE_ASSERT_MATCHING_ENUM(PreloadMetaData, METADATA); 430 COMPILE_ASSERT_MATCHING_ENUM(PreloadMetaData, METADATA);
434 COMPILE_ASSERT_MATCHING_ENUM(PreloadAuto, AUTO); 431 COMPILE_ASSERT_MATCHING_ENUM(PreloadAuto, AUTO);
435 #undef COMPILE_ASSERT_MATCHING_ENUM 432 #undef COMPILE_ASSERT_MATCHING_ENUM
436 433
437 void WebMediaPlayerImpl::setPreload(WebMediaPlayer::Preload preload) { 434 void WebMediaPlayerImpl::setPreload(WebMediaPlayer::Preload preload) {
438 DCHECK_EQ(main_loop_, MessageLoop::current()); 435 DCHECK(main_loop_->BelongsToCurrentThread());
439 436
440 if (proxy_ && proxy_->data_source()) { 437 if (proxy_ && proxy_->data_source()) {
441 // XXX: Why do I need to use webkit_media:: prefix? clang complains! 438 // XXX: Why do I need to use webkit_media:: prefix? clang complains!
442 proxy_->data_source()->SetPreload( 439 proxy_->data_source()->SetPreload(
443 static_cast<webkit_media::Preload>(preload)); 440 static_cast<webkit_media::Preload>(preload));
444 } 441 }
445 } 442 }
446 443
447 bool WebMediaPlayerImpl::totalBytesKnown() { 444 bool WebMediaPlayerImpl::totalBytesKnown() {
448 DCHECK_EQ(main_loop_, MessageLoop::current()); 445 DCHECK(main_loop_->BelongsToCurrentThread());
449 446
450 return pipeline_->GetTotalBytes() != 0; 447 return pipeline_->GetTotalBytes() != 0;
451 } 448 }
452 449
453 bool WebMediaPlayerImpl::hasVideo() const { 450 bool WebMediaPlayerImpl::hasVideo() const {
454 DCHECK_EQ(main_loop_, MessageLoop::current()); 451 DCHECK(main_loop_->BelongsToCurrentThread());
455 452
456 return pipeline_->HasVideo(); 453 return pipeline_->HasVideo();
457 } 454 }
458 455
459 bool WebMediaPlayerImpl::hasAudio() const { 456 bool WebMediaPlayerImpl::hasAudio() const {
460 DCHECK_EQ(main_loop_, MessageLoop::current()); 457 DCHECK(main_loop_->BelongsToCurrentThread());
461 458
462 return pipeline_->HasAudio(); 459 return pipeline_->HasAudio();
463 } 460 }
464 461
465 WebKit::WebSize WebMediaPlayerImpl::naturalSize() const { 462 WebKit::WebSize WebMediaPlayerImpl::naturalSize() const {
466 DCHECK_EQ(main_loop_, MessageLoop::current()); 463 DCHECK(main_loop_->BelongsToCurrentThread());
467 464
468 gfx::Size size; 465 gfx::Size size;
469 pipeline_->GetNaturalVideoSize(&size); 466 pipeline_->GetNaturalVideoSize(&size);
470 return WebKit::WebSize(size); 467 return WebKit::WebSize(size);
471 } 468 }
472 469
473 bool WebMediaPlayerImpl::paused() const { 470 bool WebMediaPlayerImpl::paused() const {
474 DCHECK_EQ(main_loop_, MessageLoop::current()); 471 DCHECK(main_loop_->BelongsToCurrentThread());
475 472
476 return pipeline_->GetPlaybackRate() == 0.0f; 473 return pipeline_->GetPlaybackRate() == 0.0f;
477 } 474 }
478 475
479 bool WebMediaPlayerImpl::seeking() const { 476 bool WebMediaPlayerImpl::seeking() const {
480 DCHECK_EQ(main_loop_, MessageLoop::current()); 477 DCHECK(main_loop_->BelongsToCurrentThread());
481 478
482 if (ready_state_ == WebMediaPlayer::ReadyStateHaveNothing) 479 if (ready_state_ == WebMediaPlayer::ReadyStateHaveNothing)
483 return false; 480 return false;
484 481
485 return seeking_; 482 return seeking_;
486 } 483 }
487 484
488 float WebMediaPlayerImpl::duration() const { 485 float WebMediaPlayerImpl::duration() const {
489 DCHECK_EQ(main_loop_, MessageLoop::current()); 486 DCHECK(main_loop_->BelongsToCurrentThread());
490 487
491 if (ready_state_ == WebMediaPlayer::ReadyStateHaveNothing) 488 if (ready_state_ == WebMediaPlayer::ReadyStateHaveNothing)
492 return std::numeric_limits<float>::quiet_NaN(); 489 return std::numeric_limits<float>::quiet_NaN();
493 490
494 double duration; 491 double duration;
495 if (chunk_demuxer_) { 492 if (chunk_demuxer_) {
496 duration = chunk_demuxer_->GetDuration(); 493 duration = chunk_demuxer_->GetDuration();
497 } else { 494 } else {
498 duration = GetPipelineDuration(); 495 duration = GetPipelineDuration();
499 } 496 }
500 497
501 // Make sure super small durations don't get truncated to 0 and 498 // Make sure super small durations don't get truncated to 0 and
502 // large durations don't get converted to infinity by the double -> float 499 // large durations don't get converted to infinity by the double -> float
503 // conversion. 500 // conversion.
504 // 501 //
505 // TODO(acolwell): Remove when WebKit is changed to report duration as a 502 // TODO(acolwell): Remove when WebKit is changed to report duration as a
506 // double. 503 // double.
507 if (duration > 0.0 && duration < std::numeric_limits<double>::infinity()) { 504 if (duration > 0.0 && duration < std::numeric_limits<double>::infinity()) {
508 duration = std::max(duration, 505 duration = std::max(duration,
509 static_cast<double>(std::numeric_limits<float>::min())); 506 static_cast<double>(std::numeric_limits<float>::min()));
510 duration = std::min(duration, 507 duration = std::min(duration,
511 static_cast<double>(std::numeric_limits<float>::max())); 508 static_cast<double>(std::numeric_limits<float>::max()));
512 } 509 }
513 510
514 return static_cast<float>(duration); 511 return static_cast<float>(duration);
515 } 512 }
516 513
517 float WebMediaPlayerImpl::currentTime() const { 514 float WebMediaPlayerImpl::currentTime() const {
518 DCHECK_EQ(main_loop_, MessageLoop::current()); 515 DCHECK(main_loop_->BelongsToCurrentThread());
519 if (paused_) 516 if (paused_)
520 return static_cast<float>(paused_time_.InSecondsF()); 517 return static_cast<float>(paused_time_.InSecondsF());
521 return static_cast<float>(pipeline_->GetMediaTime().InSecondsF()); 518 return static_cast<float>(pipeline_->GetMediaTime().InSecondsF());
522 } 519 }
523 520
524 int WebMediaPlayerImpl::dataRate() const { 521 int WebMediaPlayerImpl::dataRate() const {
525 DCHECK_EQ(main_loop_, MessageLoop::current()); 522 DCHECK(main_loop_->BelongsToCurrentThread());
526 523
527 // TODO(hclam): Add this method call if pipeline has it in the interface. 524 // TODO(hclam): Add this method call if pipeline has it in the interface.
528 return 0; 525 return 0;
529 } 526 }
530 527
531 WebMediaPlayer::NetworkState WebMediaPlayerImpl::networkState() const { 528 WebMediaPlayer::NetworkState WebMediaPlayerImpl::networkState() const {
532 DCHECK_EQ(main_loop_, MessageLoop::current()); 529 DCHECK(main_loop_->BelongsToCurrentThread());
533 return network_state_; 530 return network_state_;
534 } 531 }
535 532
536 WebMediaPlayer::ReadyState WebMediaPlayerImpl::readyState() const { 533 WebMediaPlayer::ReadyState WebMediaPlayerImpl::readyState() const {
537 DCHECK_EQ(main_loop_, MessageLoop::current()); 534 DCHECK(main_loop_->BelongsToCurrentThread());
538 return ready_state_; 535 return ready_state_;
539 } 536 }
540 537
541 const WebKit::WebTimeRanges& WebMediaPlayerImpl::buffered() { 538 const WebKit::WebTimeRanges& WebMediaPlayerImpl::buffered() {
542 DCHECK_EQ(main_loop_, MessageLoop::current()); 539 DCHECK(main_loop_->BelongsToCurrentThread());
543 WebKit::WebTimeRanges web_ranges( 540 WebKit::WebTimeRanges web_ranges(
544 ConvertToWebTimeRanges(pipeline_->GetBufferedTimeRanges())); 541 ConvertToWebTimeRanges(pipeline_->GetBufferedTimeRanges()));
545 buffered_.swap(web_ranges); 542 buffered_.swap(web_ranges);
546 return buffered_; 543 return buffered_;
547 } 544 }
548 545
549 float WebMediaPlayerImpl::maxTimeSeekable() const { 546 float WebMediaPlayerImpl::maxTimeSeekable() const {
550 DCHECK_EQ(main_loop_, MessageLoop::current()); 547 DCHECK(main_loop_->BelongsToCurrentThread());
551 548
552 // If we haven't even gotten to ReadyStateHaveMetadata yet then just 549 // If we haven't even gotten to ReadyStateHaveMetadata yet then just
553 // return 0 so that the seekable range is empty. 550 // return 0 so that the seekable range is empty.
554 if (ready_state_ < WebMediaPlayer::ReadyStateHaveMetadata) 551 if (ready_state_ < WebMediaPlayer::ReadyStateHaveMetadata)
555 return 0.0f; 552 return 0.0f;
556 553
557 // We don't support seeking in streaming media. 554 // We don't support seeking in streaming media.
558 if (proxy_ && proxy_->data_source() && proxy_->data_source()->IsStreaming()) 555 if (proxy_ && proxy_->data_source() && proxy_->data_source()->IsStreaming())
559 return 0.0f; 556 return 0.0f;
560 return duration(); 557 return duration();
561 } 558 }
562 559
563 bool WebMediaPlayerImpl::didLoadingProgress() const { 560 bool WebMediaPlayerImpl::didLoadingProgress() const {
564 DCHECK_EQ(main_loop_, MessageLoop::current()); 561 DCHECK(main_loop_->BelongsToCurrentThread());
565 return pipeline_->DidLoadingProgress(); 562 return pipeline_->DidLoadingProgress();
566 } 563 }
567 564
568 unsigned long long WebMediaPlayerImpl::totalBytes() const { 565 unsigned long long WebMediaPlayerImpl::totalBytes() const {
569 DCHECK_EQ(main_loop_, MessageLoop::current()); 566 DCHECK(main_loop_->BelongsToCurrentThread());
570 567
571 return pipeline_->GetTotalBytes(); 568 return pipeline_->GetTotalBytes();
572 } 569 }
573 570
574 void WebMediaPlayerImpl::setSize(const WebSize& size) { 571 void WebMediaPlayerImpl::setSize(const WebSize& size) {
575 DCHECK_EQ(main_loop_, MessageLoop::current()); 572 DCHECK(main_loop_->BelongsToCurrentThread());
576 573
577 // Don't need to do anything as we use the dimensions passed in via paint(). 574 // Don't need to do anything as we use the dimensions passed in via paint().
578 } 575 }
579 576
580 void WebMediaPlayerImpl::paint(WebCanvas* canvas, 577 void WebMediaPlayerImpl::paint(WebCanvas* canvas,
581 const WebRect& rect, 578 const WebRect& rect,
582 uint8_t alpha) { 579 uint8_t alpha) {
583 DCHECK_EQ(main_loop_, MessageLoop::current()); 580 DCHECK(main_loop_->BelongsToCurrentThread());
584 DCHECK(proxy_); 581 DCHECK(proxy_);
585 582
586 if (!accelerated_compositing_reported_) { 583 if (!accelerated_compositing_reported_) {
587 accelerated_compositing_reported_ = true; 584 accelerated_compositing_reported_ = true;
588 // Normally paint() is only called in non-accelerated rendering, but there 585 // Normally paint() is only called in non-accelerated rendering, but there
589 // are exceptions such as webgl where compositing is used in the WebView but 586 // are exceptions such as webgl where compositing is used in the WebView but
590 // video frames are still rendered to a canvas. 587 // video frames are still rendered to a canvas.
591 UMA_HISTOGRAM_BOOLEAN( 588 UMA_HISTOGRAM_BOOLEAN(
592 "Media.AcceleratedCompositingActive", 589 "Media.AcceleratedCompositingActive",
593 frame_->view()->isAcceleratedCompositingActive()); 590 frame_->view()->isAcceleratedCompositingActive());
594 } 591 }
595 592
596 proxy_->Paint(canvas, rect, alpha); 593 proxy_->Paint(canvas, rect, alpha);
597 } 594 }
598 595
599 bool WebMediaPlayerImpl::hasSingleSecurityOrigin() const { 596 bool WebMediaPlayerImpl::hasSingleSecurityOrigin() const {
600 if (proxy_) 597 if (proxy_)
601 return proxy_->HasSingleOrigin(); 598 return proxy_->HasSingleOrigin();
602 return true; 599 return true;
603 } 600 }
604 601
605 bool WebMediaPlayerImpl::didPassCORSAccessCheck() const { 602 bool WebMediaPlayerImpl::didPassCORSAccessCheck() const {
606 return proxy_ && proxy_->DidPassCORSAccessCheck(); 603 return proxy_ && proxy_->DidPassCORSAccessCheck();
607 } 604 }
608 605
609 WebMediaPlayer::MovieLoadType WebMediaPlayerImpl::movieLoadType() const { 606 WebMediaPlayer::MovieLoadType WebMediaPlayerImpl::movieLoadType() const {
610 DCHECK_EQ(main_loop_, MessageLoop::current()); 607 DCHECK(main_loop_->BelongsToCurrentThread());
611 608
612 // Disable seeking while streaming. 609 // Disable seeking while streaming.
613 if (proxy_ && proxy_->data_source() && proxy_->data_source()->IsStreaming()) 610 if (proxy_ && proxy_->data_source() && proxy_->data_source()->IsStreaming())
614 return WebMediaPlayer::MovieLoadTypeLiveStream; 611 return WebMediaPlayer::MovieLoadTypeLiveStream;
615 return WebMediaPlayer::MovieLoadTypeUnknown; 612 return WebMediaPlayer::MovieLoadTypeUnknown;
616 } 613 }
617 614
618 float WebMediaPlayerImpl::mediaTimeForTimeValue(float timeValue) const { 615 float WebMediaPlayerImpl::mediaTimeForTimeValue(float timeValue) const {
619 return ConvertSecondsToTimestamp(timeValue).InSecondsF(); 616 return ConvertSecondsToTimestamp(timeValue).InSecondsF();
620 } 617 }
621 618
622 unsigned WebMediaPlayerImpl::decodedFrameCount() const { 619 unsigned WebMediaPlayerImpl::decodedFrameCount() const {
623 DCHECK_EQ(main_loop_, MessageLoop::current()); 620 DCHECK(main_loop_->BelongsToCurrentThread());
624 621
625 media::PipelineStatistics stats = pipeline_->GetStatistics(); 622 media::PipelineStatistics stats = pipeline_->GetStatistics();
626 return stats.video_frames_decoded; 623 return stats.video_frames_decoded;
627 } 624 }
628 625
629 unsigned WebMediaPlayerImpl::droppedFrameCount() const { 626 unsigned WebMediaPlayerImpl::droppedFrameCount() const {
630 DCHECK_EQ(main_loop_, MessageLoop::current()); 627 DCHECK(main_loop_->BelongsToCurrentThread());
631 628
632 media::PipelineStatistics stats = pipeline_->GetStatistics(); 629 media::PipelineStatistics stats = pipeline_->GetStatistics();
633 return stats.video_frames_dropped; 630 return stats.video_frames_dropped;
634 } 631 }
635 632
636 unsigned WebMediaPlayerImpl::audioDecodedByteCount() const { 633 unsigned WebMediaPlayerImpl::audioDecodedByteCount() const {
637 DCHECK_EQ(main_loop_, MessageLoop::current()); 634 DCHECK(main_loop_->BelongsToCurrentThread());
638 635
639 media::PipelineStatistics stats = pipeline_->GetStatistics(); 636 media::PipelineStatistics stats = pipeline_->GetStatistics();
640 return stats.audio_bytes_decoded; 637 return stats.audio_bytes_decoded;
641 } 638 }
642 639
643 unsigned WebMediaPlayerImpl::videoDecodedByteCount() const { 640 unsigned WebMediaPlayerImpl::videoDecodedByteCount() const {
644 DCHECK_EQ(main_loop_, MessageLoop::current()); 641 DCHECK(main_loop_->BelongsToCurrentThread());
645 642
646 media::PipelineStatistics stats = pipeline_->GetStatistics(); 643 media::PipelineStatistics stats = pipeline_->GetStatistics();
647 return stats.video_bytes_decoded; 644 return stats.video_bytes_decoded;
648 } 645 }
649 646
650 WebKit::WebVideoFrame* WebMediaPlayerImpl::getCurrentFrame() { 647 WebKit::WebVideoFrame* WebMediaPlayerImpl::getCurrentFrame() {
651 scoped_refptr<media::VideoFrame> video_frame; 648 scoped_refptr<media::VideoFrame> video_frame;
652 proxy_->GetCurrentFrame(&video_frame); 649 proxy_->GetCurrentFrame(&video_frame);
653 if (video_frame.get()) 650 if (video_frame.get())
654 return new WebVideoFrameImpl(video_frame); 651 return new WebVideoFrameImpl(video_frame);
(...skipping 16 matching lines...) Expand all
671 mismatching_status_enums) 668 mismatching_status_enums)
672 COMPILE_ASSERT_MATCHING_STATUS_ENUM(AddIdStatusOk, kOk); 669 COMPILE_ASSERT_MATCHING_STATUS_ENUM(AddIdStatusOk, kOk);
673 COMPILE_ASSERT_MATCHING_STATUS_ENUM(AddIdStatusNotSupported, kNotSupported); 670 COMPILE_ASSERT_MATCHING_STATUS_ENUM(AddIdStatusNotSupported, kNotSupported);
674 COMPILE_ASSERT_MATCHING_STATUS_ENUM(AddIdStatusReachedIdLimit, kReachedIdLimit); 671 COMPILE_ASSERT_MATCHING_STATUS_ENUM(AddIdStatusReachedIdLimit, kReachedIdLimit);
675 #undef COMPILE_ASSERT_MATCHING_ENUM 672 #undef COMPILE_ASSERT_MATCHING_ENUM
676 673
677 WebMediaPlayer::AddIdStatus WebMediaPlayerImpl::sourceAddId( 674 WebMediaPlayer::AddIdStatus WebMediaPlayerImpl::sourceAddId(
678 const WebKit::WebString& id, 675 const WebKit::WebString& id,
679 const WebKit::WebString& type, 676 const WebKit::WebString& type,
680 const WebKit::WebVector<WebKit::WebString>& codecs) { 677 const WebKit::WebVector<WebKit::WebString>& codecs) {
681 DCHECK_EQ(main_loop_, MessageLoop::current()); 678 DCHECK(main_loop_->BelongsToCurrentThread());
682 std::vector<std::string> new_codecs(codecs.size()); 679 std::vector<std::string> new_codecs(codecs.size());
683 for (size_t i = 0; i < codecs.size(); ++i) 680 for (size_t i = 0; i < codecs.size(); ++i)
684 new_codecs[i] = codecs[i].utf8().data(); 681 new_codecs[i] = codecs[i].utf8().data();
685 682
686 return static_cast<WebMediaPlayer::AddIdStatus>( 683 return static_cast<WebMediaPlayer::AddIdStatus>(
687 chunk_demuxer_->AddId(id.utf8().data(), type.utf8().data(), new_codecs)); 684 chunk_demuxer_->AddId(id.utf8().data(), type.utf8().data(), new_codecs));
688 } 685 }
689 686
690 bool WebMediaPlayerImpl::sourceRemoveId(const WebKit::WebString& id) { 687 bool WebMediaPlayerImpl::sourceRemoveId(const WebKit::WebString& id) {
691 DCHECK(!id.isEmpty()); 688 DCHECK(!id.isEmpty());
692 chunk_demuxer_->RemoveId(id.utf8().data()); 689 chunk_demuxer_->RemoveId(id.utf8().data());
693 return true; 690 return true;
694 } 691 }
695 692
696 WebKit::WebTimeRanges WebMediaPlayerImpl::sourceBuffered( 693 WebKit::WebTimeRanges WebMediaPlayerImpl::sourceBuffered(
697 const WebKit::WebString& id) { 694 const WebKit::WebString& id) {
698 return ConvertToWebTimeRanges( 695 return ConvertToWebTimeRanges(
699 chunk_demuxer_->GetBufferedRanges(id.utf8().data())); 696 chunk_demuxer_->GetBufferedRanges(id.utf8().data()));
700 } 697 }
701 698
702 bool WebMediaPlayerImpl::sourceAppend(const WebKit::WebString& id, 699 bool WebMediaPlayerImpl::sourceAppend(const WebKit::WebString& id,
703 const unsigned char* data, 700 const unsigned char* data,
704 unsigned length) { 701 unsigned length) {
705 DCHECK_EQ(main_loop_, MessageLoop::current()); 702 DCHECK(main_loop_->BelongsToCurrentThread());
706 703
707 if (!chunk_demuxer_->AppendData(id.utf8().data(), data, length)) 704 if (!chunk_demuxer_->AppendData(id.utf8().data(), data, length))
708 return false; 705 return false;
709 706
710 return true; 707 return true;
711 } 708 }
712 709
713 bool WebMediaPlayerImpl::sourceAbort(const WebKit::WebString& id) { 710 bool WebMediaPlayerImpl::sourceAbort(const WebKit::WebString& id) {
714 chunk_demuxer_->Abort(id.utf8().data()); 711 chunk_demuxer_->Abort(id.utf8().data());
715 return true; 712 return true;
716 } 713 }
717 714
718 void WebMediaPlayerImpl::sourceSetDuration(double new_duration) { 715 void WebMediaPlayerImpl::sourceSetDuration(double new_duration) {
719 DCHECK_GE(new_duration, 0); 716 DCHECK_GE(new_duration, 0);
720 chunk_demuxer_->SetDuration(new_duration); 717 chunk_demuxer_->SetDuration(new_duration);
721 } 718 }
722 719
723 void WebMediaPlayerImpl::sourceEndOfStream( 720 void WebMediaPlayerImpl::sourceEndOfStream(
724 WebMediaPlayer::EndOfStreamStatus status) { 721 WebMediaPlayer::EndOfStreamStatus status) {
725 DCHECK_EQ(main_loop_, MessageLoop::current()); 722 DCHECK(main_loop_->BelongsToCurrentThread());
726 media::PipelineStatus pipeline_status = media::PIPELINE_OK; 723 media::PipelineStatus pipeline_status = media::PIPELINE_OK;
727 724
728 switch (status) { 725 switch (status) {
729 case WebMediaPlayer::EndOfStreamStatusNoError: 726 case WebMediaPlayer::EndOfStreamStatusNoError:
730 break; 727 break;
731 case WebMediaPlayer::EndOfStreamStatusNetworkError: 728 case WebMediaPlayer::EndOfStreamStatusNetworkError:
732 pipeline_status = media::PIPELINE_ERROR_NETWORK; 729 pipeline_status = media::PIPELINE_ERROR_NETWORK;
733 break; 730 break;
734 case WebMediaPlayer::EndOfStreamStatusDecodeError: 731 case WebMediaPlayer::EndOfStreamStatusDecodeError:
735 pipeline_status = media::PIPELINE_ERROR_DECODE; 732 pipeline_status = media::PIPELINE_ERROR_DECODE;
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
887 884
888 if (current_key_system_.isEmpty() || key_system != current_key_system_) 885 if (current_key_system_.isEmpty() || key_system != current_key_system_)
889 return WebMediaPlayer::MediaKeyExceptionInvalidPlayerState; 886 return WebMediaPlayer::MediaKeyExceptionInvalidPlayerState;
890 887
891 decryptor_->CancelKeyRequest(key_system.utf8(), session_id.utf8()); 888 decryptor_->CancelKeyRequest(key_system.utf8(), session_id.utf8());
892 return WebMediaPlayer::MediaKeyExceptionNoError; 889 return WebMediaPlayer::MediaKeyExceptionNoError;
893 } 890 }
894 891
895 void WebMediaPlayerImpl::WillDestroyCurrentMessageLoop() { 892 void WebMediaPlayerImpl::WillDestroyCurrentMessageLoop() {
896 Destroy(); 893 Destroy();
897 main_loop_ = NULL;
898 } 894 }
899 895
900 void WebMediaPlayerImpl::Repaint() { 896 void WebMediaPlayerImpl::Repaint() {
901 DCHECK_EQ(main_loop_, MessageLoop::current()); 897 DCHECK(main_loop_->BelongsToCurrentThread());
902 GetClient()->repaint(); 898 GetClient()->repaint();
903 } 899 }
904 900
905 void WebMediaPlayerImpl::OnPipelineSeek(PipelineStatus status) { 901 void WebMediaPlayerImpl::OnPipelineSeek(PipelineStatus status) {
906 DCHECK_EQ(main_loop_, MessageLoop::current()); 902 DCHECK(main_loop_->BelongsToCurrentThread());
907 starting_ = false; 903 starting_ = false;
908 seeking_ = false; 904 seeking_ = false;
909 if (pending_seek_) { 905 if (pending_seek_) {
910 pending_seek_ = false; 906 pending_seek_ = false;
911 seek(pending_seek_seconds_); 907 seek(pending_seek_seconds_);
912 return; 908 return;
913 } 909 }
914 910
915 if (status != media::PIPELINE_OK) { 911 if (status != media::PIPELINE_OK) {
916 OnPipelineError(status); 912 OnPipelineError(status);
917 return; 913 return;
918 } 914 }
919 915
920 // Update our paused time. 916 // Update our paused time.
921 if (paused_) 917 if (paused_)
922 paused_time_ = pipeline_->GetMediaTime(); 918 paused_time_ = pipeline_->GetMediaTime();
923 919
924 GetClient()->timeChanged(); 920 GetClient()->timeChanged();
925 } 921 }
926 922
927 void WebMediaPlayerImpl::OnPipelineEnded() { 923 void WebMediaPlayerImpl::OnPipelineEnded() {
928 DCHECK_EQ(main_loop_, MessageLoop::current()); 924 DCHECK(main_loop_->BelongsToCurrentThread());
929 GetClient()->timeChanged(); 925 GetClient()->timeChanged();
930 } 926 }
931 927
932 void WebMediaPlayerImpl::OnPipelineError(PipelineStatus error) { 928 void WebMediaPlayerImpl::OnPipelineError(PipelineStatus error) {
933 DCHECK_EQ(main_loop_, MessageLoop::current()); 929 DCHECK(main_loop_->BelongsToCurrentThread());
934 930
935 if (ready_state_ == WebMediaPlayer::ReadyStateHaveNothing) { 931 if (ready_state_ == WebMediaPlayer::ReadyStateHaveNothing) {
936 // Any error that occurs before reaching ReadyStateHaveMetadata should 932 // Any error that occurs before reaching ReadyStateHaveMetadata should
937 // be considered a format error. 933 // be considered a format error.
938 SetNetworkState(WebMediaPlayer::NetworkStateFormatError); 934 SetNetworkState(WebMediaPlayer::NetworkStateFormatError);
939 Repaint(); 935 Repaint();
940 return; 936 return;
941 } 937 }
942 938
943 switch (error) { 939 switch (error) {
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
1002 case media::Pipeline::kPrerollCompleted: 998 case media::Pipeline::kPrerollCompleted:
1003 SetReadyState(WebMediaPlayer::ReadyStateHaveEnoughData); 999 SetReadyState(WebMediaPlayer::ReadyStateHaveEnoughData);
1004 break; 1000 break;
1005 } 1001 }
1006 1002
1007 // Repaint to trigger UI update. 1003 // Repaint to trigger UI update.
1008 Repaint(); 1004 Repaint();
1009 } 1005 }
1010 1006
1011 void WebMediaPlayerImpl::OnDemuxerOpened() { 1007 void WebMediaPlayerImpl::OnDemuxerOpened() {
1012 DCHECK_EQ(main_loop_, MessageLoop::current()); 1008 DCHECK(main_loop_->BelongsToCurrentThread());
1013 GetClient()->sourceOpened(); 1009 GetClient()->sourceOpened();
1014 } 1010 }
1015 1011
1016 void WebMediaPlayerImpl::OnKeyAdded(const std::string& key_system, 1012 void WebMediaPlayerImpl::OnKeyAdded(const std::string& key_system,
1017 const std::string& session_id) { 1013 const std::string& session_id) {
1018 DCHECK_EQ(main_loop_, MessageLoop::current()); 1014 DCHECK(main_loop_->BelongsToCurrentThread());
1019 1015
1020 base::Histogram::FactoryGet( 1016 base::Histogram::FactoryGet(
1021 kMediaEme + KeySystemNameForUMA(key_system) + ".KeyAdded", 1017 kMediaEme + KeySystemNameForUMA(key_system) + ".KeyAdded",
1022 1, 1000000, 50, 1018 1, 1000000, 50,
1023 base::Histogram::kUmaTargetedHistogramFlag)->Add(1); 1019 base::Histogram::kUmaTargetedHistogramFlag)->Add(1);
1024 1020
1025 GetClient()->keyAdded(WebString::fromUTF8(key_system), 1021 GetClient()->keyAdded(WebString::fromUTF8(key_system),
1026 WebString::fromUTF8(session_id)); 1022 WebString::fromUTF8(session_id));
1027 } 1023 }
1028 1024
1029 void WebMediaPlayerImpl::OnNeedKey(const std::string& key_system, 1025 void WebMediaPlayerImpl::OnNeedKey(const std::string& key_system,
1030 const std::string& session_id, 1026 const std::string& session_id,
1031 const std::string& type, 1027 const std::string& type,
1032 scoped_array<uint8> init_data, 1028 scoped_array<uint8> init_data,
1033 int init_data_size) { 1029 int init_data_size) {
1034 DCHECK_EQ(main_loop_, MessageLoop::current()); 1030 DCHECK(main_loop_->BelongsToCurrentThread());
1035 1031
1036 // Do not fire NeedKey event if encrypted media is not enabled. 1032 // Do not fire NeedKey event if encrypted media is not enabled.
1037 if (!decryptor_) 1033 if (!decryptor_)
1038 return; 1034 return;
1039 1035
1040 UMA_HISTOGRAM_COUNTS(kMediaEme + std::string("NeedKey"), 1); 1036 UMA_HISTOGRAM_COUNTS(kMediaEme + std::string("NeedKey"), 1);
1041 1037
1042 DCHECK(init_data_type_.empty() || type.empty() || type == init_data_type_); 1038 DCHECK(init_data_type_.empty() || type.empty() || type == init_data_type_);
1043 if (init_data_type_.empty()) 1039 if (init_data_type_.empty())
1044 init_data_type_ = type; 1040 init_data_type_ = type;
(...skipping 13 matching lines...) Expand all
1058 COMPILE_ASSERT_MATCHING_ENUM(ServiceError); 1054 COMPILE_ASSERT_MATCHING_ENUM(ServiceError);
1059 COMPILE_ASSERT_MATCHING_ENUM(OutputError); 1055 COMPILE_ASSERT_MATCHING_ENUM(OutputError);
1060 COMPILE_ASSERT_MATCHING_ENUM(HardwareChangeError); 1056 COMPILE_ASSERT_MATCHING_ENUM(HardwareChangeError);
1061 COMPILE_ASSERT_MATCHING_ENUM(DomainError); 1057 COMPILE_ASSERT_MATCHING_ENUM(DomainError);
1062 #undef COMPILE_ASSERT_MATCHING_ENUM 1058 #undef COMPILE_ASSERT_MATCHING_ENUM
1063 1059
1064 void WebMediaPlayerImpl::OnKeyError(const std::string& key_system, 1060 void WebMediaPlayerImpl::OnKeyError(const std::string& key_system,
1065 const std::string& session_id, 1061 const std::string& session_id,
1066 media::Decryptor::KeyError error_code, 1062 media::Decryptor::KeyError error_code,
1067 int system_code) { 1063 int system_code) {
1068 DCHECK_EQ(main_loop_, MessageLoop::current()); 1064 DCHECK(main_loop_->BelongsToCurrentThread());
1069 1065
1070 base::LinearHistogram::FactoryGet( 1066 base::LinearHistogram::FactoryGet(
1071 kMediaEme + KeySystemNameForUMA(key_system) + ".KeyError", 1, 1067 kMediaEme + KeySystemNameForUMA(key_system) + ".KeyError", 1,
1072 media::Decryptor::kMaxKeyError, media::Decryptor::kMaxKeyError + 1, 1068 media::Decryptor::kMaxKeyError, media::Decryptor::kMaxKeyError + 1,
1073 base::Histogram::kUmaTargetedHistogramFlag)->Add(error_code); 1069 base::Histogram::kUmaTargetedHistogramFlag)->Add(error_code);
1074 1070
1075 GetClient()->keyError( 1071 GetClient()->keyError(
1076 WebString::fromUTF8(key_system), 1072 WebString::fromUTF8(key_system),
1077 WebString::fromUTF8(session_id), 1073 WebString::fromUTF8(session_id),
1078 static_cast<WebKit::WebMediaPlayerClient::MediaKeyErrorCode>(error_code), 1074 static_cast<WebKit::WebMediaPlayerClient::MediaKeyErrorCode>(error_code),
1079 system_code); 1075 system_code);
1080 } 1076 }
1081 1077
1082 void WebMediaPlayerImpl::OnKeyMessage(const std::string& key_system, 1078 void WebMediaPlayerImpl::OnKeyMessage(const std::string& key_system,
1083 const std::string& session_id, 1079 const std::string& session_id,
1084 const std::string& message, 1080 const std::string& message,
1085 const std::string& default_url) { 1081 const std::string& default_url) {
1086 DCHECK_EQ(main_loop_, MessageLoop::current()); 1082 DCHECK(main_loop_->BelongsToCurrentThread());
1087 1083
1088 const GURL default_url_gurl(default_url); 1084 const GURL default_url_gurl(default_url);
1089 DLOG_IF(WARNING, !default_url.empty() && !default_url_gurl.is_valid()) 1085 DLOG_IF(WARNING, !default_url.empty() && !default_url_gurl.is_valid())
1090 << "Invalid URL in default_url: " << default_url; 1086 << "Invalid URL in default_url: " << default_url;
1091 1087
1092 GetClient()->keyMessage(WebString::fromUTF8(key_system), 1088 GetClient()->keyMessage(WebString::fromUTF8(key_system),
1093 WebString::fromUTF8(session_id), 1089 WebString::fromUTF8(session_id),
1094 reinterpret_cast<const uint8*>(message.data()), 1090 reinterpret_cast<const uint8*>(message.data()),
1095 message.size(), 1091 message.size(),
1096 default_url_gurl); 1092 default_url_gurl);
1097 } 1093 }
1098 1094
1099 void WebMediaPlayerImpl::SetOpaque(bool opaque) { 1095 void WebMediaPlayerImpl::SetOpaque(bool opaque) {
1100 DCHECK_EQ(main_loop_, MessageLoop::current()); 1096 DCHECK(main_loop_->BelongsToCurrentThread());
1101 1097
1102 GetClient()->setOpaque(opaque); 1098 GetClient()->setOpaque(opaque);
1103 } 1099 }
1104 1100
1105 void WebMediaPlayerImpl::DataSourceInitialized(const GURL& gurl, bool success) { 1101 void WebMediaPlayerImpl::DataSourceInitialized(const GURL& gurl, bool success) {
1106 DCHECK_EQ(main_loop_, MessageLoop::current()); 1102 DCHECK(main_loop_->BelongsToCurrentThread());
1107 1103
1108 if (!success) { 1104 if (!success) {
1109 SetNetworkState(WebMediaPlayer::NetworkStateFormatError); 1105 SetNetworkState(WebMediaPlayer::NetworkStateFormatError);
1110 Repaint(); 1106 Repaint();
1111 return; 1107 return;
1112 } 1108 }
1113 1109
1114 StartPipeline(); 1110 StartPipeline();
1115 } 1111 }
1116 1112
(...skipping 13 matching lines...) Expand all
1130 pipeline_->Start( 1126 pipeline_->Start(
1131 filter_collection_.Pass(), 1127 filter_collection_.Pass(),
1132 BIND_TO_RENDER_LOOP(&WebMediaPlayerImpl::OnPipelineEnded), 1128 BIND_TO_RENDER_LOOP(&WebMediaPlayerImpl::OnPipelineEnded),
1133 BIND_TO_RENDER_LOOP(&WebMediaPlayerImpl::OnPipelineError), 1129 BIND_TO_RENDER_LOOP(&WebMediaPlayerImpl::OnPipelineError),
1134 BIND_TO_RENDER_LOOP(&WebMediaPlayerImpl::OnPipelineSeek), 1130 BIND_TO_RENDER_LOOP(&WebMediaPlayerImpl::OnPipelineSeek),
1135 BIND_TO_RENDER_LOOP(&WebMediaPlayerImpl::OnPipelineBufferingState), 1131 BIND_TO_RENDER_LOOP(&WebMediaPlayerImpl::OnPipelineBufferingState),
1136 BIND_TO_RENDER_LOOP(&WebMediaPlayerImpl::OnDurationChange)); 1132 BIND_TO_RENDER_LOOP(&WebMediaPlayerImpl::OnDurationChange));
1137 } 1133 }
1138 1134
1139 void WebMediaPlayerImpl::SetNetworkState(WebMediaPlayer::NetworkState state) { 1135 void WebMediaPlayerImpl::SetNetworkState(WebMediaPlayer::NetworkState state) {
1140 DCHECK_EQ(main_loop_, MessageLoop::current()); 1136 DCHECK(main_loop_->BelongsToCurrentThread());
1141 DVLOG(1) << "SetNetworkState: " << state; 1137 DVLOG(1) << "SetNetworkState: " << state;
1142 network_state_ = state; 1138 network_state_ = state;
1143 // Always notify to ensure client has the latest value. 1139 // Always notify to ensure client has the latest value.
1144 GetClient()->networkStateChanged(); 1140 GetClient()->networkStateChanged();
1145 } 1141 }
1146 1142
1147 void WebMediaPlayerImpl::SetReadyState(WebMediaPlayer::ReadyState state) { 1143 void WebMediaPlayerImpl::SetReadyState(WebMediaPlayer::ReadyState state) {
1148 DCHECK_EQ(main_loop_, MessageLoop::current()); 1144 DCHECK(main_loop_->BelongsToCurrentThread());
1149 DVLOG(1) << "SetReadyState: " << state; 1145 DVLOG(1) << "SetReadyState: " << state;
1150 1146
1151 if (ready_state_ == WebMediaPlayer::ReadyStateHaveNothing && 1147 if (ready_state_ == WebMediaPlayer::ReadyStateHaveNothing &&
1152 state >= WebMediaPlayer::ReadyStateHaveMetadata) { 1148 state >= WebMediaPlayer::ReadyStateHaveMetadata) {
1153 if (!hasVideo()) 1149 if (!hasVideo())
1154 GetClient()->disableAcceleratedCompositing(); 1150 GetClient()->disableAcceleratedCompositing();
1155 } else if (state == WebMediaPlayer::ReadyStateHaveEnoughData) { 1151 } else if (state == WebMediaPlayer::ReadyStateHaveEnoughData) {
1156 if (is_local_source_ && 1152 if (is_local_source_ &&
1157 network_state_ == WebMediaPlayer::NetworkStateLoading) { 1153 network_state_ == WebMediaPlayer::NetworkStateLoading) {
1158 SetNetworkState(WebMediaPlayer::NetworkStateLoaded); 1154 SetNetworkState(WebMediaPlayer::NetworkStateLoaded);
1159 } 1155 }
1160 } 1156 }
1161 1157
1162 ready_state_ = state; 1158 ready_state_ = state;
1163 // Always notify to ensure client has the latest value. 1159 // Always notify to ensure client has the latest value.
1164 GetClient()->readyStateChanged(); 1160 GetClient()->readyStateChanged();
1165 } 1161 }
1166 1162
1167 void WebMediaPlayerImpl::Destroy() { 1163 void WebMediaPlayerImpl::Destroy() {
1168 DCHECK_EQ(main_loop_, MessageLoop::current()); 1164 DCHECK(main_loop_->BelongsToCurrentThread());
1169 1165
1170 // Tell the data source to abort any pending reads so that the pipeline is 1166 // Tell the data source to abort any pending reads so that the pipeline is
1171 // not blocked when issuing stop commands to the other filters. 1167 // not blocked when issuing stop commands to the other filters.
1172 if (proxy_) { 1168 if (proxy_) {
1173 proxy_->AbortDataSource(); 1169 proxy_->AbortDataSource();
1174 if (chunk_demuxer_) { 1170 if (chunk_demuxer_) {
1175 chunk_demuxer_->Shutdown(); 1171 chunk_demuxer_->Shutdown();
1176 chunk_demuxer_ = NULL; 1172 chunk_demuxer_ = NULL;
1177 } 1173 }
1178 } 1174 }
(...skipping 15 matching lines...) Expand all
1194 1190
1195 // And then detach the proxy, it may live on the render thread for a little 1191 // And then detach the proxy, it may live on the render thread for a little
1196 // longer until all the tasks are finished. 1192 // longer until all the tasks are finished.
1197 if (proxy_) { 1193 if (proxy_) {
1198 proxy_->Detach(); 1194 proxy_->Detach();
1199 proxy_ = NULL; 1195 proxy_ = NULL;
1200 } 1196 }
1201 } 1197 }
1202 1198
1203 WebKit::WebMediaPlayerClient* WebMediaPlayerImpl::GetClient() { 1199 WebKit::WebMediaPlayerClient* WebMediaPlayerImpl::GetClient() {
1204 DCHECK_EQ(main_loop_, MessageLoop::current()); 1200 DCHECK(main_loop_->BelongsToCurrentThread());
1205 DCHECK(client_); 1201 DCHECK(client_);
1206 return client_; 1202 return client_;
1207 } 1203 }
1208 1204
1209 WebKit::WebAudioSourceProvider* WebMediaPlayerImpl::audioSourceProvider() { 1205 WebKit::WebAudioSourceProvider* WebMediaPlayerImpl::audioSourceProvider() {
1210 return audio_source_provider_; 1206 return audio_source_provider_;
1211 } 1207 }
1212 1208
1213 void WebMediaPlayerImpl::IncrementExternallyAllocatedMemory() { 1209 void WebMediaPlayerImpl::IncrementExternallyAllocatedMemory() {
1214 DCHECK_EQ(main_loop_, MessageLoop::current()); 1210 DCHECK(main_loop_->BelongsToCurrentThread());
1215 incremented_externally_allocated_memory_ = true; 1211 incremented_externally_allocated_memory_ = true;
1216 v8::V8::AdjustAmountOfExternalAllocatedMemory(kPlayerExtraMemory); 1212 v8::V8::AdjustAmountOfExternalAllocatedMemory(kPlayerExtraMemory);
1217 } 1213 }
1218 1214
1219 double WebMediaPlayerImpl::GetPipelineDuration() const { 1215 double WebMediaPlayerImpl::GetPipelineDuration() const {
1220 base::TimeDelta duration = pipeline_->GetMediaDuration(); 1216 base::TimeDelta duration = pipeline_->GetMediaDuration();
1221 1217
1222 // Return positive infinity if the resource is unbounded. 1218 // Return positive infinity if the resource is unbounded.
1223 // http://www.whatwg.org/specs/web-apps/current-work/multipage/video.html#dom- media-duration 1219 // http://www.whatwg.org/specs/web-apps/current-work/multipage/video.html#dom- media-duration
1224 if (duration == media::kInfiniteDuration()) 1220 if (duration == media::kInfiniteDuration())
1225 return std::numeric_limits<double>::infinity(); 1221 return std::numeric_limits<double>::infinity();
1226 1222
1227 return duration.InSecondsF(); 1223 return duration.InSecondsF();
1228 } 1224 }
1229 1225
1230 void WebMediaPlayerImpl::OnDurationChange() { 1226 void WebMediaPlayerImpl::OnDurationChange() {
1231 if (ready_state_ == WebMediaPlayer::ReadyStateHaveNothing) 1227 if (ready_state_ == WebMediaPlayer::ReadyStateHaveNothing)
1232 return; 1228 return;
1233 1229
1234 GetClient()->durationChanged(); 1230 GetClient()->durationChanged();
1235 } 1231 }
1236 1232
1237 } // namespace webkit_media 1233 } // namespace webkit_media
OLDNEW
« no previous file with comments | « webkit/media/webmediaplayer_impl.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698