OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/glue/webmediaplayer_impl.h" | 5 #include "webkit/glue/webmediaplayer_impl.h" |
6 | 6 |
7 #include <limits> | 7 #include <limits> |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/callback.h" | 10 #include "base/callback.h" |
(...skipping 322 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
333 new media::CompositeDataSourceFactory()); | 333 new media::CompositeDataSourceFactory()); |
334 | 334 |
335 if (use_simple_data_source) { | 335 if (use_simple_data_source) { |
336 data_source_factory->AddFactory(simple_data_source_factory.release()); | 336 data_source_factory->AddFactory(simple_data_source_factory.release()); |
337 data_source_factory->AddFactory(buffered_data_source_factory.release()); | 337 data_source_factory->AddFactory(buffered_data_source_factory.release()); |
338 } else { | 338 } else { |
339 data_source_factory->AddFactory(buffered_data_source_factory.release()); | 339 data_source_factory->AddFactory(buffered_data_source_factory.release()); |
340 data_source_factory->AddFactory(simple_data_source_factory.release()); | 340 data_source_factory->AddFactory(simple_data_source_factory.release()); |
341 } | 341 } |
342 | 342 |
343 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kEnableAdaptive)) { | |
344 chunk_demuxer_factory_.reset(new media::ChunkDemuxerFactory( | |
345 data_source_factory->Clone())); | |
346 } | |
347 | |
343 scoped_ptr<media::DemuxerFactory> demuxer_factory( | 348 scoped_ptr<media::DemuxerFactory> demuxer_factory( |
344 new media::FFmpegDemuxerFactory(data_source_factory.release(), | 349 new media::FFmpegDemuxerFactory(data_source_factory.release(), |
345 pipeline_message_loop)); | 350 pipeline_message_loop)); |
346 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kEnableAdaptive)) { | 351 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kEnableAdaptive)) { |
347 demuxer_factory.reset(new media::AdaptiveDemuxerFactory( | 352 demuxer_factory.reset(new media::AdaptiveDemuxerFactory( |
348 demuxer_factory.release())); | 353 demuxer_factory.release())); |
349 } | 354 } |
350 filter_collection_->SetDemuxerFactory(demuxer_factory.release()); | 355 filter_collection_->SetDemuxerFactory(demuxer_factory.release()); |
351 | 356 |
352 // Add in the default filter factories. | 357 // Add in the default filter factories. |
(...skipping 24 matching lines...) Expand all Loading... | |
377 // Remove the default decoder | 382 // Remove the default decoder |
378 scoped_refptr<media::VideoDecoder> old_videodecoder; | 383 scoped_refptr<media::VideoDecoder> old_videodecoder; |
379 filter_collection_->SelectVideoDecoder(&old_videodecoder); | 384 filter_collection_->SelectVideoDecoder(&old_videodecoder); |
380 media::RTCVideoDecoder* rtc_video_decoder = | 385 media::RTCVideoDecoder* rtc_video_decoder = |
381 new media::RTCVideoDecoder( | 386 new media::RTCVideoDecoder( |
382 message_loop_factory_->GetMessageLoop("VideoDecoderThread"), | 387 message_loop_factory_->GetMessageLoop("VideoDecoderThread"), |
383 url.spec()); | 388 url.spec()); |
384 filter_collection_->AddVideoDecoder(rtc_video_decoder); | 389 filter_collection_->AddVideoDecoder(rtc_video_decoder); |
385 } | 390 } |
386 | 391 |
392 if (chunk_demuxer_factory_.get() && | |
393 chunk_demuxer_factory_->IsUrlSupported(url.spec())) { | |
394 media_data_sink_.reset(chunk_demuxer_factory_->CreateMediaDataSink()); | |
scherkus (not reviewing)
2011/06/22 17:31:09
what if chunk_demuxer_factory_ passed a ref to a m
acolwell GONE FROM CHROMIUM
2011/06/23 16:51:29
No can do. WebMediaPlayerImpl needs to be able to
| |
395 filter_collection_->SetDemuxerFactory(chunk_demuxer_factory_.release()); | |
396 } | |
397 | |
387 // Handle any volume changes that occured before load(). | 398 // Handle any volume changes that occured before load(). |
388 setVolume(GetClient()->volume()); | 399 setVolume(GetClient()->volume()); |
389 // Get the preload value. | 400 // Get the preload value. |
390 setPreload(GetClient()->preload()); | 401 setPreload(GetClient()->preload()); |
391 | 402 |
392 // Initialize the pipeline. | 403 // Initialize the pipeline. |
393 SetNetworkState(WebKit::WebMediaPlayer::Loading); | 404 SetNetworkState(WebKit::WebMediaPlayer::Loading); |
394 SetReadyState(WebKit::WebMediaPlayer::HaveNothing); | 405 SetReadyState(WebKit::WebMediaPlayer::HaveNothing); |
395 pipeline_->Start( | 406 pipeline_->Start( |
396 filter_collection_.release(), | 407 filter_collection_.release(), |
(...skipping 14 matching lines...) Expand all Loading... | |
411 } | 422 } |
412 | 423 |
413 void WebMediaPlayerImpl::pause() { | 424 void WebMediaPlayerImpl::pause() { |
414 DCHECK(MessageLoop::current() == main_loop_); | 425 DCHECK(MessageLoop::current() == main_loop_); |
415 | 426 |
416 paused_ = true; | 427 paused_ = true; |
417 pipeline_->SetPlaybackRate(0.0f); | 428 pipeline_->SetPlaybackRate(0.0f); |
418 paused_time_ = pipeline_->GetCurrentTime(); | 429 paused_time_ = pipeline_->GetCurrentTime(); |
419 } | 430 } |
420 | 431 |
432 bool WebMediaPlayerImpl::addData(const unsigned char* data, unsigned length) { | |
433 DCHECK(MessageLoop::current() == main_loop_); | |
434 | |
435 if (!media_data_sink_.get()) | |
436 return false; | |
437 | |
438 return media_data_sink_->AddData(data, length); | |
439 } | |
440 | |
421 bool WebMediaPlayerImpl::supportsFullscreen() const { | 441 bool WebMediaPlayerImpl::supportsFullscreen() const { |
422 DCHECK(MessageLoop::current() == main_loop_); | 442 DCHECK(MessageLoop::current() == main_loop_); |
423 return true; | 443 return true; |
424 } | 444 } |
425 | 445 |
426 bool WebMediaPlayerImpl::supportsSave() const { | 446 bool WebMediaPlayerImpl::supportsSave() const { |
427 DCHECK(MessageLoop::current() == main_loop_); | 447 DCHECK(MessageLoop::current() == main_loop_); |
428 return true; | 448 return true; |
429 } | 449 } |
430 | 450 |
(...skipping 14 matching lines...) Expand all Loading... | |
445 | 465 |
446 base::TimeDelta seek_time = ConvertSecondsToTimestamp(seconds); | 466 base::TimeDelta seek_time = ConvertSecondsToTimestamp(seconds); |
447 | 467 |
448 // Update our paused time. | 468 // Update our paused time. |
449 if (paused_) { | 469 if (paused_) { |
450 paused_time_ = seek_time; | 470 paused_time_ = seek_time; |
451 } | 471 } |
452 | 472 |
453 seeking_ = true; | 473 seeking_ = true; |
454 | 474 |
475 if (media_data_sink_.get()) | |
476 media_data_sink_->Flush(); | |
477 | |
455 // Kick off the asynchronous seek! | 478 // Kick off the asynchronous seek! |
456 pipeline_->Seek( | 479 pipeline_->Seek( |
457 seek_time, | 480 seek_time, |
458 NewCallback(proxy_.get(), | 481 NewCallback(proxy_.get(), |
459 &WebMediaPlayerImpl::Proxy::PipelineSeekCallback)); | 482 &WebMediaPlayerImpl::Proxy::PipelineSeekCallback)); |
460 } | 483 } |
461 | 484 |
462 void WebMediaPlayerImpl::setEndTime(float seconds) { | 485 void WebMediaPlayerImpl::setEndTime(float seconds) { |
463 DCHECK(MessageLoop::current() == main_loop_); | 486 DCHECK(MessageLoop::current() == main_loop_); |
464 | 487 |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
555 | 578 |
556 return seeking_; | 579 return seeking_; |
557 } | 580 } |
558 | 581 |
559 float WebMediaPlayerImpl::duration() const { | 582 float WebMediaPlayerImpl::duration() const { |
560 DCHECK(MessageLoop::current() == main_loop_); | 583 DCHECK(MessageLoop::current() == main_loop_); |
561 | 584 |
562 base::TimeDelta duration = pipeline_->GetMediaDuration(); | 585 base::TimeDelta duration = pipeline_->GetMediaDuration(); |
563 if (duration.InMicroseconds() == media::Limits::kMaxTimeInMicroseconds) | 586 if (duration.InMicroseconds() == media::Limits::kMaxTimeInMicroseconds) |
564 return std::numeric_limits<float>::infinity(); | 587 return std::numeric_limits<float>::infinity(); |
565 return static_cast<float>(duration.InSecondsF()); | 588 float ret = static_cast<float>(duration.InSecondsF()); |
589 | |
590 //LOG(ERROR) << "duration() : " << ret; | |
scherkus (not reviewing)
2011/06/22 17:31:09
?
acolwell GONE FROM CHROMIUM
2011/06/23 16:51:29
reverted
| |
591 | |
592 return ret; | |
566 } | 593 } |
567 | 594 |
568 float WebMediaPlayerImpl::currentTime() const { | 595 float WebMediaPlayerImpl::currentTime() const { |
569 DCHECK(MessageLoop::current() == main_loop_); | 596 DCHECK(MessageLoop::current() == main_loop_); |
570 | 597 float ret = -1; |
571 if (paused_) { | 598 if (paused_) { |
572 return static_cast<float>(paused_time_.InSecondsF()); | 599 ret = static_cast<float>(paused_time_.InSecondsF()); |
scherkus (not reviewing)
2011/06/22 17:31:09
revert the changes here?
acolwell GONE FROM CHROMIUM
2011/06/23 16:51:29
Done.
| |
600 } else { | |
601 ret = static_cast<float>(pipeline_->GetCurrentTime().InSecondsF()); | |
573 } | 602 } |
574 return static_cast<float>(pipeline_->GetCurrentTime().InSecondsF()); | 603 //LOG(ERROR) << "currentTime() : " << ret; |
scherkus (not reviewing)
2011/06/22 17:31:09
?
acolwell GONE FROM CHROMIUM
2011/06/23 16:51:29
reverted
| |
604 return ret; | |
575 } | 605 } |
576 | 606 |
577 int WebMediaPlayerImpl::dataRate() const { | 607 int WebMediaPlayerImpl::dataRate() const { |
578 DCHECK(MessageLoop::current() == main_loop_); | 608 DCHECK(MessageLoop::current() == main_loop_); |
579 | 609 |
580 // TODO(hclam): Add this method call if pipeline has it in the interface. | 610 // TODO(hclam): Add this method call if pipeline has it in the interface. |
581 return 0; | 611 return 0; |
582 } | 612 } |
583 | 613 |
584 WebKit::WebMediaPlayer::NetworkState WebMediaPlayerImpl::networkState() const { | 614 WebKit::WebMediaPlayer::NetworkState WebMediaPlayerImpl::networkState() const { |
585 return network_state_; | 615 return network_state_; |
586 } | 616 } |
587 | 617 |
588 WebKit::WebMediaPlayer::ReadyState WebMediaPlayerImpl::readyState() const { | 618 WebKit::WebMediaPlayer::ReadyState WebMediaPlayerImpl::readyState() const { |
589 return ready_state_; | 619 return ready_state_; |
590 } | 620 } |
591 | 621 |
592 const WebKit::WebTimeRanges& WebMediaPlayerImpl::buffered() { | 622 const WebKit::WebTimeRanges& WebMediaPlayerImpl::buffered() { |
593 DCHECK(MessageLoop::current() == main_loop_); | 623 DCHECK(MessageLoop::current() == main_loop_); |
594 | 624 |
595 // Update buffered_ with the most recent buffered time. | 625 // Update buffered_ with the most recent buffered time. |
596 if (buffered_.size() > 0) { | 626 if (buffered_.size() > 0) { |
597 float buffered_time = static_cast<float>( | 627 float buffered_time = static_cast<float>( |
598 pipeline_->GetBufferedTime().InSecondsF()); | 628 pipeline_->GetBufferedTime().InSecondsF()); |
599 if (buffered_time >= buffered_[0].start) | 629 if (buffered_time >= buffered_[0].start) |
600 buffered_[0].end = buffered_time; | 630 buffered_[0].end = buffered_time; |
631 | |
632 //LOG(ERROR) << "buffered() : " << buffered_[0].start | |
633 // << " - " << buffered_[0].end; | |
scherkus (not reviewing)
2011/06/22 17:31:09
?
acolwell GONE FROM CHROMIUM
2011/06/23 16:51:29
reverted
| |
601 } | 634 } |
602 | 635 |
603 return buffered_; | 636 return buffered_; |
604 } | 637 } |
605 | 638 |
606 float WebMediaPlayerImpl::maxTimeSeekable() const { | 639 float WebMediaPlayerImpl::maxTimeSeekable() const { |
607 DCHECK(MessageLoop::current() == main_loop_); | 640 DCHECK(MessageLoop::current() == main_loop_); |
608 | 641 |
609 // If we are performing streaming, we report that we cannot seek at all. | 642 // If we are performing streaming, we report that we cannot seek at all. |
610 // We are using this flag to indicate if the data source supports seeking | 643 // We are using this flag to indicate if the data source supports seeking |
611 // or not. We should be able to seek even if we are performing streaming. | 644 // or not. We should be able to seek even if we are performing streaming. |
612 // TODO(hclam): We need to update this when we have better caching. | 645 // TODO(hclam): We need to update this when we have better caching. |
613 if (pipeline_->IsStreaming()) | 646 if (pipeline_->IsStreaming()) |
614 return 0.0f; | 647 return 0.0f; |
615 return static_cast<float>(pipeline_->GetMediaDuration().InSecondsF()); | 648 float ret = static_cast<float>(pipeline_->GetMediaDuration().InSecondsF()); |
649 | |
650 LOG(ERROR) << "maxTimeSeekable() : " << ret; | |
acolwell GONE FROM CHROMIUM
2011/06/23 16:51:29
reverted
| |
651 return ret; | |
616 } | 652 } |
617 | 653 |
618 unsigned long long WebMediaPlayerImpl::bytesLoaded() const { | 654 unsigned long long WebMediaPlayerImpl::bytesLoaded() const { |
619 DCHECK(MessageLoop::current() == main_loop_); | 655 DCHECK(MessageLoop::current() == main_loop_); |
620 | 656 |
621 return pipeline_->GetBufferedBytes(); | 657 return pipeline_->GetBufferedBytes(); |
622 } | 658 } |
623 | 659 |
624 unsigned long long WebMediaPlayerImpl::totalBytes() const { | 660 unsigned long long WebMediaPlayerImpl::totalBytes() const { |
625 DCHECK(MessageLoop::current() == main_loop_); | 661 DCHECK(MessageLoop::current() == main_loop_); |
(...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
901 } | 937 } |
902 | 938 |
903 void WebMediaPlayerImpl::Destroy() { | 939 void WebMediaPlayerImpl::Destroy() { |
904 DCHECK(MessageLoop::current() == main_loop_); | 940 DCHECK(MessageLoop::current() == main_loop_); |
905 | 941 |
906 // Tell the data source to abort any pending reads so that the pipeline is | 942 // Tell the data source to abort any pending reads so that the pipeline is |
907 // not blocked when issuing stop commands to the other filters. | 943 // not blocked when issuing stop commands to the other filters. |
908 if (proxy_) | 944 if (proxy_) |
909 proxy_->AbortDataSources(); | 945 proxy_->AbortDataSources(); |
910 | 946 |
947 if (media_data_sink_.get()) | |
948 media_data_sink_->Shutdown(); | |
949 | |
911 // Make sure to kill the pipeline so there's no more media threads running. | 950 // Make sure to kill the pipeline so there's no more media threads running. |
912 // Note: stopping the pipeline might block for a long time. | 951 // Note: stopping the pipeline might block for a long time. |
913 if (pipeline_) { | 952 if (pipeline_) { |
914 media::PipelineStatusNotification note; | 953 media::PipelineStatusNotification note; |
915 pipeline_->Stop(note.Callback()); | 954 pipeline_->Stop(note.Callback()); |
916 note.Wait(); | 955 note.Wait(); |
917 } | 956 } |
918 | 957 |
919 message_loop_factory_.reset(); | 958 message_loop_factory_.reset(); |
920 | 959 |
921 // And then detach the proxy, it may live on the render thread for a little | 960 // And then detach the proxy, it may live on the render thread for a little |
922 // longer until all the tasks are finished. | 961 // longer until all the tasks are finished. |
923 if (proxy_) { | 962 if (proxy_) { |
924 proxy_->Detach(); | 963 proxy_->Detach(); |
925 proxy_ = NULL; | 964 proxy_ = NULL; |
926 } | 965 } |
927 } | 966 } |
928 | 967 |
929 WebKit::WebMediaPlayerClient* WebMediaPlayerImpl::GetClient() { | 968 WebKit::WebMediaPlayerClient* WebMediaPlayerImpl::GetClient() { |
930 DCHECK(MessageLoop::current() == main_loop_); | 969 DCHECK(MessageLoop::current() == main_loop_); |
931 DCHECK(client_); | 970 DCHECK(client_); |
932 return client_; | 971 return client_; |
933 } | 972 } |
934 | 973 |
935 } // namespace webkit_glue | 974 } // namespace webkit_glue |
OLD | NEW |