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

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

Issue 8399023: Fire canplaythrough event at the proper time for audio/video (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Responses to CR Created 9 years, 1 month 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
OLDNEW
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/bind.h" 10 #include "base/bind.h"
(...skipping 24 matching lines...) Expand all
35 #include "webkit/glue/media/media_stream_client.h" 35 #include "webkit/glue/media/media_stream_client.h"
36 #include "webkit/glue/media/video_renderer_impl.h" 36 #include "webkit/glue/media/video_renderer_impl.h"
37 #include "webkit/glue/media/web_video_renderer.h" 37 #include "webkit/glue/media/web_video_renderer.h"
38 #include "webkit/glue/webmediaplayer_delegate.h" 38 #include "webkit/glue/webmediaplayer_delegate.h"
39 #include "webkit/glue/webmediaplayer_proxy.h" 39 #include "webkit/glue/webmediaplayer_proxy.h"
40 #include "webkit/glue/webvideoframe_impl.h" 40 #include "webkit/glue/webvideoframe_impl.h"
41 41
42 using WebKit::WebCanvas; 42 using WebKit::WebCanvas;
43 using WebKit::WebRect; 43 using WebKit::WebRect;
44 using WebKit::WebSize; 44 using WebKit::WebSize;
45 using media::NetworkEvent;
45 using media::PipelineStatus; 46 using media::PipelineStatus;
46 47
47 namespace { 48 namespace {
48 49
49 // Amount of extra memory used by each player instance reported to V8. 50 // Amount of extra memory used by each player instance reported to V8.
50 // It is not exact number -- first, it differs on different platforms, 51 // It is not exact number -- first, it differs on different platforms,
51 // and second, it is very hard to calculate. Instead, use some arbitrary 52 // and second, it is very hard to calculate. Instead, use some arbitrary
52 // value that will cause garbage collection from time to time. We don't want 53 // value that will cause garbage collection from time to time. We don't want
53 // it to happen on every allocation, but don't want 5k players to sit in memory 54 // it to happen on every allocation, but don't want 5k players to sit in memory
54 // either. Looks that chosen constant achieves both goals, at least for audio 55 // either. Looks that chosen constant achieves both goals, at least for audio
(...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after
335 pending_seek_ = true; 336 pending_seek_ = true;
336 pending_seek_seconds_ = seconds; 337 pending_seek_seconds_ = seconds;
337 return; 338 return;
338 } 339 }
339 340
340 media_log_->AddEvent(media_log_->CreateSeekEvent(seconds)); 341 media_log_->AddEvent(media_log_->CreateSeekEvent(seconds));
341 342
342 base::TimeDelta seek_time = ConvertSecondsToTimestamp(seconds); 343 base::TimeDelta seek_time = ConvertSecondsToTimestamp(seconds);
343 344
344 // Update our paused time. 345 // Update our paused time.
345 if (paused_) { 346 if (paused_)
346 paused_time_ = seek_time; 347 paused_time_ = seek_time;
347 }
348 348
349 seeking_ = true; 349 seeking_ = true;
350 350
351 proxy_->DemuxerFlush(); 351 proxy_->DemuxerFlush();
352 352
353 // Kick off the asynchronous seek! 353 // Kick off the asynchronous seek!
354 pipeline_->Seek( 354 pipeline_->Seek(
355 seek_time, 355 seek_time,
356 base::Bind(&WebMediaPlayerProxy::PipelineSeekCallback, 356 base::Bind(&WebMediaPlayerProxy::PipelineSeekCallback,
357 proxy_.get())); 357 proxy_.get()));
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
458 DCHECK_EQ(main_loop_, MessageLoop::current()); 458 DCHECK_EQ(main_loop_, MessageLoop::current());
459 459
460 base::TimeDelta duration = pipeline_->GetMediaDuration(); 460 base::TimeDelta duration = pipeline_->GetMediaDuration();
461 if (duration.InMicroseconds() == media::Limits::kMaxTimeInMicroseconds) 461 if (duration.InMicroseconds() == media::Limits::kMaxTimeInMicroseconds)
462 return std::numeric_limits<float>::infinity(); 462 return std::numeric_limits<float>::infinity();
463 return static_cast<float>(duration.InSecondsF()); 463 return static_cast<float>(duration.InSecondsF());
464 } 464 }
465 465
466 float WebMediaPlayerImpl::currentTime() const { 466 float WebMediaPlayerImpl::currentTime() const {
467 DCHECK_EQ(main_loop_, MessageLoop::current()); 467 DCHECK_EQ(main_loop_, MessageLoop::current());
468 if (paused_) { 468 if (paused_)
469 return static_cast<float>(paused_time_.InSecondsF()); 469 return static_cast<float>(paused_time_.InSecondsF());
470 }
471 return static_cast<float>(pipeline_->GetCurrentTime().InSecondsF()); 470 return static_cast<float>(pipeline_->GetCurrentTime().InSecondsF());
472 } 471 }
473 472
474 int WebMediaPlayerImpl::dataRate() const { 473 int WebMediaPlayerImpl::dataRate() const {
475 DCHECK_EQ(main_loop_, MessageLoop::current()); 474 DCHECK_EQ(main_loop_, MessageLoop::current());
476 475
477 // TODO(hclam): Add this method call if pipeline has it in the interface. 476 // TODO(hclam): Add this method call if pipeline has it in the interface.
478 return 0; 477 return 0;
479 } 478 }
480 479
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after
701 void WebMediaPlayerImpl::OnPipelineInitialize(PipelineStatus status) { 700 void WebMediaPlayerImpl::OnPipelineInitialize(PipelineStatus status) {
702 DCHECK_EQ(main_loop_, MessageLoop::current()); 701 DCHECK_EQ(main_loop_, MessageLoop::current());
703 if (status == media::PIPELINE_OK) { 702 if (status == media::PIPELINE_OK) {
704 // Only keep one time range starting from 0. 703 // Only keep one time range starting from 0.
705 WebKit::WebTimeRanges new_buffered(static_cast<size_t>(1)); 704 WebKit::WebTimeRanges new_buffered(static_cast<size_t>(1));
706 new_buffered[0].start = 0.0f; 705 new_buffered[0].start = 0.0f;
707 new_buffered[0].end = 706 new_buffered[0].end =
708 static_cast<float>(pipeline_->GetMediaDuration().InSecondsF()); 707 static_cast<float>(pipeline_->GetMediaDuration().InSecondsF());
709 buffered_.swap(new_buffered); 708 buffered_.swap(new_buffered);
710 709
711 if (pipeline_->IsLoaded()) { 710 if (pipeline_->IsLoaded())
712 SetNetworkState(WebKit::WebMediaPlayer::Loaded); 711 SetNetworkState(WebKit::WebMediaPlayer::Loaded);
713 }
714 712
715 // Since we have initialized the pipeline, say we have everything otherwise
716 // we'll remain either loading/idle.
717 // TODO(hclam): change this to report the correct status.
718 SetReadyState(WebKit::WebMediaPlayer::HaveMetadata); 713 SetReadyState(WebKit::WebMediaPlayer::HaveMetadata);
719 SetReadyState(WebKit::WebMediaPlayer::HaveEnoughData); 714 SetReadyState(WebKit::WebMediaPlayer::HaveFutureData);
720 } else { 715 } else {
721 // TODO(hclam): should use |status| to determine the state 716 // TODO(hclam): should use |status| to determine the state
722 // properly and reports error using MediaError. 717 // properly and reports error using MediaError.
723 // WebKit uses FormatError to indicate an error for bogus URL or bad file. 718 // WebKit uses FormatError to indicate an error for bogus URL or bad file.
724 // Since we are at the initialization stage we can safely treat every error 719 // Since we are at the initialization stage we can safely treat every error
725 // as format error. Should post a task to call to |webmediaplayer_|. 720 // as format error. Should post a task to call to |webmediaplayer_|.
726 SetNetworkState(WebKit::WebMediaPlayer::FormatError); 721 SetNetworkState(WebKit::WebMediaPlayer::FormatError);
727 } 722 }
728 723
729 // Repaint to trigger UI update. 724 // Repaint to trigger UI update.
730 Repaint(); 725 Repaint();
731 } 726 }
732 727
733 void WebMediaPlayerImpl::OnPipelineSeek(PipelineStatus status) { 728 void WebMediaPlayerImpl::OnPipelineSeek(PipelineStatus status) {
734 DCHECK_EQ(main_loop_, MessageLoop::current()); 729 DCHECK_EQ(main_loop_, MessageLoop::current());
735 seeking_ = false; 730 seeking_ = false;
736 if (pending_seek_) { 731 if (pending_seek_) {
737 pending_seek_ = false; 732 pending_seek_ = false;
738 seek(pending_seek_seconds_); 733 seek(pending_seek_seconds_);
739 return; 734 return;
740 } 735 }
741 736
742 if (status == media::PIPELINE_OK) { 737 if (status == media::PIPELINE_OK) {
743 // Update our paused time. 738 // Update our paused time.
744 if (paused_) { 739 if (paused_)
745 paused_time_ = pipeline_->GetCurrentTime(); 740 paused_time_ = pipeline_->GetCurrentTime();
746 }
747 741
748 SetReadyState(WebKit::WebMediaPlayer::HaveEnoughData);
749 GetClient()->timeChanged(); 742 GetClient()->timeChanged();
750 } 743 }
751 } 744 }
752 745
753 void WebMediaPlayerImpl::OnPipelineEnded(PipelineStatus status) { 746 void WebMediaPlayerImpl::OnPipelineEnded(PipelineStatus status) {
754 DCHECK_EQ(main_loop_, MessageLoop::current()); 747 DCHECK_EQ(main_loop_, MessageLoop::current());
755 if (status == media::PIPELINE_OK) { 748 if (status == media::PIPELINE_OK)
756 GetClient()->timeChanged(); 749 GetClient()->timeChanged();
757 }
758 } 750 }
759 751
760 void WebMediaPlayerImpl::OnPipelineError(PipelineStatus error) { 752 void WebMediaPlayerImpl::OnPipelineError(PipelineStatus error) {
761 DCHECK_EQ(main_loop_, MessageLoop::current()); 753 DCHECK_EQ(main_loop_, MessageLoop::current());
762 switch (error) { 754 switch (error) {
763 case media::PIPELINE_OK: 755 case media::PIPELINE_OK:
764 LOG(DFATAL) << "PIPELINE_OK isn't an error!"; 756 LOG(DFATAL) << "PIPELINE_OK isn't an error!";
765 break; 757 break;
766 758
767 case media::PIPELINE_ERROR_NETWORK: 759 case media::PIPELINE_ERROR_NETWORK:
(...skipping 23 matching lines...) Expand all
791 case media::PIPELINE_ERROR_INVALID_STATE: 783 case media::PIPELINE_ERROR_INVALID_STATE:
792 // Decode error. 784 // Decode error.
793 SetNetworkState(WebMediaPlayer::DecodeError); 785 SetNetworkState(WebMediaPlayer::DecodeError);
794 break; 786 break;
795 } 787 }
796 788
797 // Repaint to trigger UI update. 789 // Repaint to trigger UI update.
798 Repaint(); 790 Repaint();
799 } 791 }
800 792
801 void WebMediaPlayerImpl::OnNetworkEvent(bool is_downloading_data) { 793 void WebMediaPlayerImpl::OnNetworkEvent(NetworkEvent type) {
802 DCHECK_EQ(main_loop_, MessageLoop::current()); 794 DCHECK_EQ(main_loop_, MessageLoop::current());
803 if (is_downloading_data) 795 switch(type) {
804 SetNetworkState(WebKit::WebMediaPlayer::Loading); 796 case media::DOWNLOAD_CONTINUED:
805 else 797 SetNetworkState(WebKit::WebMediaPlayer::Loading);
806 SetNetworkState(WebKit::WebMediaPlayer::Idle); 798 break;
799 case media::DOWNLOAD_PAUSED:
800 SetNetworkState(WebKit::WebMediaPlayer::Idle);
801 break;
802 case media::CAN_PLAY_THROUGH:
803 SetReadyState(WebKit::WebMediaPlayer::HaveEnoughData);
804 break;
805 default:
scherkus (not reviewing) 2011/11/16 02:15:17 indentation
806 NOTREACHED();
807 }
807 } 808 }
808 809
809 void WebMediaPlayerImpl::OnDemuxerOpened() { 810 void WebMediaPlayerImpl::OnDemuxerOpened() {
810 DCHECK_EQ(main_loop_, MessageLoop::current()); 811 DCHECK_EQ(main_loop_, MessageLoop::current());
811 812
812 GetClient()->sourceOpened(); 813 GetClient()->sourceOpened();
813 } 814 }
814 815
815 void WebMediaPlayerImpl::SetNetworkState( 816 void WebMediaPlayerImpl::SetNetworkState(
816 WebKit::WebMediaPlayer::NetworkState state) { 817 WebKit::WebMediaPlayer::NetworkState state) {
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
868 return client_; 869 return client_;
869 } 870 }
870 871
871 void WebMediaPlayerImpl::IncrementExternallyAllocatedMemory() { 872 void WebMediaPlayerImpl::IncrementExternallyAllocatedMemory() {
872 DCHECK_EQ(main_loop_, MessageLoop::current()); 873 DCHECK_EQ(main_loop_, MessageLoop::current());
873 incremented_externally_allocated_memory_ = true; 874 incremented_externally_allocated_memory_ = true;
874 v8::V8::AdjustAmountOfExternalAllocatedMemory(kPlayerExtraMemory); 875 v8::V8::AdjustAmountOfExternalAllocatedMemory(kPlayerExtraMemory);
875 } 876 }
876 877
877 } // namespace webkit_glue 878 } // namespace webkit_glue
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698