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