OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "content/renderer/media/android/webmediaplayer_android.h" | 5 #include "content/renderer/media/android/webmediaplayer_android.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <limits> | 9 #include <limits> |
10 | 10 |
(...skipping 832 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
843 | 843 |
844 if (need_to_signal_duration_changed) | 844 if (need_to_signal_duration_changed) |
845 client_->durationChanged(); | 845 client_->durationChanged(); |
846 } | 846 } |
847 | 847 |
848 void WebMediaPlayerAndroid::OnPlaybackComplete() { | 848 void WebMediaPlayerAndroid::OnPlaybackComplete() { |
849 // When playback is about to finish, android media player often stops | 849 // When playback is about to finish, android media player often stops |
850 // at a time which is smaller than the duration. This makes webkit never | 850 // at a time which is smaller than the duration. This makes webkit never |
851 // know that the playback has finished. To solve this, we set the | 851 // know that the playback has finished. To solve this, we set the |
852 // current time to media duration when OnPlaybackComplete() get called. | 852 // current time to media duration when OnPlaybackComplete() get called. |
853 interpolator_.SetBounds(duration_, duration_); | 853 interpolator_.SetBounds(duration_, duration_, default_tick_clock_.NowTicks()); |
854 client_->timeChanged(); | 854 client_->timeChanged(); |
855 | 855 |
856 // If the loop attribute is set, timeChanged() will update the current time | 856 // If the loop attribute is set, timeChanged() will update the current time |
857 // to 0. It will perform a seek to 0. Issue a command to the player to start | 857 // to 0. It will perform a seek to 0. Issue a command to the player to start |
858 // playing after seek completes. | 858 // playing after seek completes. |
859 if (is_playing_ && seeking_ && seek_time_.is_zero()) | 859 if (is_playing_ && seeking_ && seek_time_.is_zero()) |
860 player_manager_->Start(player_id_); | 860 player_manager_->Start(player_id_); |
861 else | 861 else |
862 playback_completed_ = true; | 862 playback_completed_ = true; |
863 } | 863 } |
(...skipping 16 matching lines...) Expand all Loading... |
880 | 880 |
881 void WebMediaPlayerAndroid::OnSeekComplete( | 881 void WebMediaPlayerAndroid::OnSeekComplete( |
882 const base::TimeDelta& current_time) { | 882 const base::TimeDelta& current_time) { |
883 DCHECK(main_thread_checker_.CalledOnValidThread()); | 883 DCHECK(main_thread_checker_.CalledOnValidThread()); |
884 seeking_ = false; | 884 seeking_ = false; |
885 if (pending_seek_) { | 885 if (pending_seek_) { |
886 pending_seek_ = false; | 886 pending_seek_ = false; |
887 seek(pending_seek_time_.InSecondsF()); | 887 seek(pending_seek_time_.InSecondsF()); |
888 return; | 888 return; |
889 } | 889 } |
890 interpolator_.SetBounds(current_time, current_time); | 890 interpolator_.SetBounds(current_time, current_time, |
| 891 default_tick_clock_.NowTicks()); |
891 | 892 |
892 UpdateReadyState(WebMediaPlayer::ReadyStateHaveEnoughData); | 893 UpdateReadyState(WebMediaPlayer::ReadyStateHaveEnoughData); |
893 | 894 |
894 client_->timeChanged(); | 895 client_->timeChanged(); |
895 } | 896 } |
896 | 897 |
897 void WebMediaPlayerAndroid::OnMediaError(int error_type) { | 898 void WebMediaPlayerAndroid::OnMediaError(int error_type) { |
898 switch (error_type) { | 899 switch (error_type) { |
899 case MediaPlayerAndroid::MEDIA_ERROR_FORMAT: | 900 case MediaPlayerAndroid::MEDIA_ERROR_FORMAT: |
900 UpdateNetworkState(WebMediaPlayer::NetworkStateFormatError); | 901 UpdateNetworkState(WebMediaPlayer::NetworkStateFormatError); |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
974 } | 975 } |
975 | 976 |
976 void WebMediaPlayerAndroid::OnTimeUpdate(base::TimeDelta current_timestamp, | 977 void WebMediaPlayerAndroid::OnTimeUpdate(base::TimeDelta current_timestamp, |
977 base::TimeTicks current_time_ticks) { | 978 base::TimeTicks current_time_ticks) { |
978 DCHECK(main_thread_checker_.CalledOnValidThread()); | 979 DCHECK(main_thread_checker_.CalledOnValidThread()); |
979 | 980 |
980 if (seeking()) | 981 if (seeking()) |
981 return; | 982 return; |
982 | 983 |
983 // Compensate the current_timestamp with the IPC latency. | 984 // Compensate the current_timestamp with the IPC latency. |
| 985 base::TimeTicks now_ticks = default_tick_clock_.NowTicks(); |
984 base::TimeDelta lower_bound = | 986 base::TimeDelta lower_bound = |
985 base::TimeTicks::Now() - current_time_ticks + current_timestamp; | 987 now_ticks - current_time_ticks + current_timestamp; |
| 988 |
986 base::TimeDelta upper_bound = lower_bound; | 989 base::TimeDelta upper_bound = lower_bound; |
987 // We should get another time update in about |kTimeUpdateInterval| | 990 // We should get another time update in about |kTimeUpdateInterval| |
988 // milliseconds. | 991 // milliseconds. |
989 if (is_playing_) { | 992 if (is_playing_) { |
990 upper_bound += base::TimeDelta::FromMilliseconds( | 993 upper_bound += base::TimeDelta::FromMilliseconds( |
991 media::kTimeUpdateInterval); | 994 media::kTimeUpdateInterval); |
992 } | 995 } |
993 // if the lower_bound is smaller than the current time, just use the current | 996 // if the lower_bound is smaller than the current time, just use the current |
994 // time so that the timer is always progressing. | 997 // time so that the timer is always progressing. |
995 lower_bound = | 998 lower_bound = |
996 std::max(lower_bound, base::TimeDelta::FromSecondsD(currentTime())); | 999 std::max(lower_bound, base::TimeDelta::FromSecondsD(currentTime())); |
997 if (lower_bound > upper_bound) | 1000 if (lower_bound > upper_bound) |
998 upper_bound = lower_bound; | 1001 upper_bound = lower_bound; |
999 interpolator_.SetBounds(lower_bound, upper_bound); | 1002 interpolator_.SetBounds(lower_bound, upper_bound, now_ticks); |
1000 } | 1003 } |
1001 | 1004 |
1002 void WebMediaPlayerAndroid::OnConnectedToRemoteDevice( | 1005 void WebMediaPlayerAndroid::OnConnectedToRemoteDevice( |
1003 const std::string& remote_playback_message) { | 1006 const std::string& remote_playback_message) { |
1004 DCHECK(main_thread_checker_.CalledOnValidThread()); | 1007 DCHECK(main_thread_checker_.CalledOnValidThread()); |
1005 DrawRemotePlaybackText(remote_playback_message); | 1008 DrawRemotePlaybackText(remote_playback_message); |
1006 is_remote_ = true; | 1009 is_remote_ = true; |
1007 SetNeedsEstablishPeer(false); | 1010 SetNeedsEstablishPeer(false); |
1008 client_->connectedToRemoteDevice(); | 1011 client_->connectedToRemoteDevice(); |
1009 } | 1012 } |
(...skipping 699 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1709 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | 1712 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
1710 switches::kDisableMediaSuspend)) { | 1713 switches::kDisableMediaSuspend)) { |
1711 return false; | 1714 return false; |
1712 } | 1715 } |
1713 | 1716 |
1714 return base::FeatureList::IsEnabled(media::kResumeBackgroundVideo) && | 1717 return base::FeatureList::IsEnabled(media::kResumeBackgroundVideo) && |
1715 hasAudio() && !isRemote() && delegate_ && delegate_->IsHidden(); | 1718 hasAudio() && !isRemote() && delegate_ && delegate_->IsHidden(); |
1716 } | 1719 } |
1717 | 1720 |
1718 } // namespace content | 1721 } // namespace content |
OLD | NEW |