| 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 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 126 }; | 126 }; |
| 127 | 127 |
| 128 } // namespace | 128 } // namespace |
| 129 | 129 |
| 130 namespace content { | 130 namespace content { |
| 131 | 131 |
| 132 WebMediaPlayerAndroid::WebMediaPlayerAndroid( | 132 WebMediaPlayerAndroid::WebMediaPlayerAndroid( |
| 133 blink::WebFrame* frame, | 133 blink::WebFrame* frame, |
| 134 blink::WebMediaPlayerClient* client, | 134 blink::WebMediaPlayerClient* client, |
| 135 blink::WebMediaPlayerEncryptedMediaClient* encrypted_client, | 135 blink::WebMediaPlayerEncryptedMediaClient* encrypted_client, |
| 136 base::WeakPtr<media::WebMediaPlayerDelegate> delegate, | 136 media::WebMediaPlayerDelegate* delegate, |
| 137 RendererMediaPlayerManager* player_manager, | 137 RendererMediaPlayerManager* player_manager, |
| 138 scoped_refptr<StreamTextureFactory> factory, | 138 scoped_refptr<StreamTextureFactory> factory, |
| 139 int frame_id, | 139 int frame_id, |
| 140 bool enable_texture_copy, | 140 bool enable_texture_copy, |
| 141 const media::WebMediaPlayerParams& params) | 141 const media::WebMediaPlayerParams& params) |
| 142 : frame_(frame), | 142 : frame_(frame), |
| 143 client_(client), | 143 client_(client), |
| 144 delegate_(delegate), | 144 delegate_(delegate), |
| 145 delegate_id_(0), | 145 delegate_id_(0), |
| 146 defer_load_cb_(params.defer_load_cb()), | 146 defer_load_cb_(params.defer_load_cb()), |
| (...skipping 25 matching lines...) Expand all Loading... |
| 172 is_local_resource_(false), | 172 is_local_resource_(false), |
| 173 interpolator_(&default_tick_clock_), | 173 interpolator_(&default_tick_clock_), |
| 174 frame_id_(frame_id), | 174 frame_id_(frame_id), |
| 175 enable_texture_copy_(enable_texture_copy), | 175 enable_texture_copy_(enable_texture_copy), |
| 176 suppress_deleting_texture_(false), | 176 suppress_deleting_texture_(false), |
| 177 playback_completed_(false), | 177 playback_completed_(false), |
| 178 volume_(1.0), | 178 volume_(1.0), |
| 179 volume_multiplier_(1.0), | 179 volume_multiplier_(1.0), |
| 180 weak_factory_(this) { | 180 weak_factory_(this) { |
| 181 DCHECK(player_manager_); | 181 DCHECK(player_manager_); |
| 182 DCHECK(delegate_); |
| 182 | 183 |
| 183 DCHECK(main_thread_checker_.CalledOnValidThread()); | 184 DCHECK(main_thread_checker_.CalledOnValidThread()); |
| 184 | 185 |
| 185 if (delegate_) { | 186 delegate_id_ = delegate_->AddObserver(this); |
| 186 delegate_id_ = delegate_->AddObserver(this); | 187 delegate_->SetIdle(delegate_id_, true); |
| 187 delegate_->SetIdle(delegate_id_, true); | |
| 188 } | |
| 189 | 188 |
| 190 player_id_ = player_manager_->RegisterMediaPlayer(this); | 189 player_id_ = player_manager_->RegisterMediaPlayer(this); |
| 191 | 190 |
| 192 TryCreateStreamTextureProxyIfNeeded(); | 191 TryCreateStreamTextureProxyIfNeeded(); |
| 193 interpolator_.SetUpperBound(base::TimeDelta()); | 192 interpolator_.SetUpperBound(base::TimeDelta()); |
| 194 } | 193 } |
| 195 | 194 |
| 196 WebMediaPlayerAndroid::~WebMediaPlayerAndroid() { | 195 WebMediaPlayerAndroid::~WebMediaPlayerAndroid() { |
| 197 DCHECK(main_thread_checker_.CalledOnValidThread()); | 196 DCHECK(main_thread_checker_.CalledOnValidThread()); |
| 198 SetVideoFrameProviderClient(NULL); | 197 SetVideoFrameProviderClient(NULL); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 210 gl->ShallowFlushCHROMIUM(); | 209 gl->ShallowFlushCHROMIUM(); |
| 211 texture_id_ = 0; | 210 texture_id_ = 0; |
| 212 texture_mailbox_ = gpu::Mailbox(); | 211 texture_mailbox_ = gpu::Mailbox(); |
| 213 } | 212 } |
| 214 | 213 |
| 215 { | 214 { |
| 216 base::AutoLock auto_lock(current_frame_lock_); | 215 base::AutoLock auto_lock(current_frame_lock_); |
| 217 current_frame_ = NULL; | 216 current_frame_ = NULL; |
| 218 } | 217 } |
| 219 | 218 |
| 220 if (delegate_) { | 219 delegate_->PlayerGone(delegate_id_); |
| 221 delegate_->PlayerGone(delegate_id_); | 220 delegate_->RemoveObserver(delegate_id_); |
| 222 delegate_->RemoveObserver(delegate_id_); | |
| 223 } | |
| 224 } | 221 } |
| 225 | 222 |
| 226 void WebMediaPlayerAndroid::load(LoadType load_type, | 223 void WebMediaPlayerAndroid::load(LoadType load_type, |
| 227 const blink::WebMediaPlayerSource& source, | 224 const blink::WebMediaPlayerSource& source, |
| 228 CORSMode cors_mode) { | 225 CORSMode cors_mode) { |
| 229 // Only URL or MSE blob URL is supported. | 226 // Only URL or MSE blob URL is supported. |
| 230 DCHECK(source.isURL()); | 227 DCHECK(source.isURL()); |
| 231 blink::WebURL url = source.getAsURL(); | 228 blink::WebURL url = source.getAsURL(); |
| 232 if (!defer_load_cb_.is_null()) { | 229 if (!defer_load_cb_.is_null()) { |
| 233 defer_load_cb_.Run(base::Bind(&WebMediaPlayerAndroid::DoLoad, | 230 defer_load_cb_.Run(base::Bind(&WebMediaPlayerAndroid::DoLoad, |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 290 return false; | 287 return false; |
| 291 } | 288 } |
| 292 | 289 |
| 293 void WebMediaPlayerAndroid::play() { | 290 void WebMediaPlayerAndroid::play() { |
| 294 DCHECK(main_thread_checker_.CalledOnValidThread()); | 291 DCHECK(main_thread_checker_.CalledOnValidThread()); |
| 295 | 292 |
| 296 if (hasVideo() && player_manager_->render_frame()->IsHidden()) { | 293 if (hasVideo() && player_manager_->render_frame()->IsHidden()) { |
| 297 bool can_video_play_in_background = | 294 bool can_video_play_in_background = |
| 298 base::CommandLine::ForCurrentProcess()->HasSwitch( | 295 base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 299 switches::kDisableMediaSuspend) || | 296 switches::kDisableMediaSuspend) || |
| 300 (IsBackgroundVideoCandidate() && delegate_ && | 297 (IsBackgroundVideoCandidate() && |
| 301 delegate_->IsBackgroundVideoPlaybackUnlocked()); | 298 delegate_->IsBackgroundVideoPlaybackUnlocked()); |
| 302 if (!can_video_play_in_background) { | 299 if (!can_video_play_in_background) { |
| 303 is_play_pending_ = true; | 300 is_play_pending_ = true; |
| 304 return; | 301 return; |
| 305 } | 302 } |
| 306 } | 303 } |
| 307 is_play_pending_ = false; | 304 is_play_pending_ = false; |
| 308 | 305 |
| 309 TryCreateStreamTextureProxyIfNeeded(); | 306 TryCreateStreamTextureProxyIfNeeded(); |
| 310 // There is no need to establish the surface texture peer for fullscreen | 307 // There is no need to establish the surface texture peer for fullscreen |
| (...skipping 512 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 823 | 820 |
| 824 // Lazily allocate compositing layer. | 821 // Lazily allocate compositing layer. |
| 825 if (!video_weblayer_) { | 822 if (!video_weblayer_) { |
| 826 video_weblayer_.reset(new cc_blink::WebLayerImpl( | 823 video_weblayer_.reset(new cc_blink::WebLayerImpl( |
| 827 cc::VideoLayer::Create(this, media::VIDEO_ROTATION_0))); | 824 cc::VideoLayer::Create(this, media::VIDEO_ROTATION_0))); |
| 828 client_->setWebLayer(video_weblayer_.get()); | 825 client_->setWebLayer(video_weblayer_.get()); |
| 829 | 826 |
| 830 // If we're paused after we receive metadata for the first time, tell the | 827 // If we're paused after we receive metadata for the first time, tell the |
| 831 // delegate we can now be safely suspended due to inactivity if a subsequent | 828 // delegate we can now be safely suspended due to inactivity if a subsequent |
| 832 // play event does not occur. | 829 // play event does not occur. |
| 833 if (paused() && delegate_) { | 830 if (paused()) { |
| 834 delegate_->DidPause(delegate_id_); | 831 delegate_->DidPause(delegate_id_); |
| 835 delegate_->SetIdle(delegate_id_, true); | 832 delegate_->SetIdle(delegate_id_, true); |
| 836 } | 833 } |
| 837 } | 834 } |
| 838 } | 835 } |
| 839 | 836 |
| 840 void WebMediaPlayerAndroid::OnTimeUpdate(base::TimeDelta current_timestamp, | 837 void WebMediaPlayerAndroid::OnTimeUpdate(base::TimeDelta current_timestamp, |
| 841 base::TimeTicks current_time_ticks) { | 838 base::TimeTicks current_time_ticks) { |
| 842 DCHECK(main_thread_checker_.CalledOnValidThread()); | 839 DCHECK(main_thread_checker_.CalledOnValidThread()); |
| 843 | 840 |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 951 ready_state_ = state; | 948 ready_state_ = state; |
| 952 client_->readyStateChanged(); | 949 client_->readyStateChanged(); |
| 953 } | 950 } |
| 954 | 951 |
| 955 void WebMediaPlayerAndroid::OnPlayerReleased() { | 952 void WebMediaPlayerAndroid::OnPlayerReleased() { |
| 956 needs_establish_peer_ = true; | 953 needs_establish_peer_ = true; |
| 957 | 954 |
| 958 if (is_playing_) | 955 if (is_playing_) |
| 959 OnMediaPlayerPause(); | 956 OnMediaPlayerPause(); |
| 960 | 957 |
| 961 if (delegate_) | 958 delegate_->PlayerGone(delegate_id_); |
| 962 delegate_->PlayerGone(delegate_id_); | |
| 963 } | 959 } |
| 964 | 960 |
| 965 void WebMediaPlayerAndroid::SuspendAndReleaseResources() { | 961 void WebMediaPlayerAndroid::SuspendAndReleaseResources() { |
| 966 switch (network_state_) { | 962 switch (network_state_) { |
| 967 // Pause the media player and inform WebKit if the player is in a good | 963 // Pause the media player and inform WebKit if the player is in a good |
| 968 // shape. | 964 // shape. |
| 969 case WebMediaPlayer::NetworkStateIdle: | 965 case WebMediaPlayer::NetworkStateIdle: |
| 970 case WebMediaPlayer::NetworkStateLoading: | 966 case WebMediaPlayer::NetworkStateLoading: |
| 971 case WebMediaPlayer::NetworkStateLoaded: | 967 case WebMediaPlayer::NetworkStateLoaded: |
| 972 Pause(false); | 968 Pause(false); |
| 973 client_->playbackStateChanged(); | 969 client_->playbackStateChanged(); |
| 974 if (delegate_) | 970 delegate_->PlayerGone(delegate_id_); |
| 975 delegate_->PlayerGone(delegate_id_); | |
| 976 break; | 971 break; |
| 977 // If a WebMediaPlayer instance has entered into one of these states, | 972 // If a WebMediaPlayer instance has entered into one of these states, |
| 978 // the internal network state in HTMLMediaElement could be set to empty. | 973 // the internal network state in HTMLMediaElement could be set to empty. |
| 979 // And calling playbackStateChanged() could get this object deleted. | 974 // And calling playbackStateChanged() could get this object deleted. |
| 980 case WebMediaPlayer::NetworkStateEmpty: | 975 case WebMediaPlayer::NetworkStateEmpty: |
| 981 case WebMediaPlayer::NetworkStateFormatError: | 976 case WebMediaPlayer::NetworkStateFormatError: |
| 982 case WebMediaPlayer::NetworkStateNetworkError: | 977 case WebMediaPlayer::NetworkStateNetworkError: |
| 983 case WebMediaPlayer::NetworkStateDecodeError: | 978 case WebMediaPlayer::NetworkStateDecodeError: |
| 984 break; | 979 break; |
| 985 } | 980 } |
| (...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1195 if (is_playing == is_playing_) | 1190 if (is_playing == is_playing_) |
| 1196 return; | 1191 return; |
| 1197 | 1192 |
| 1198 is_playing_ = is_playing; | 1193 is_playing_ = is_playing; |
| 1199 | 1194 |
| 1200 if (is_playing) | 1195 if (is_playing) |
| 1201 interpolator_.StartInterpolating(); | 1196 interpolator_.StartInterpolating(); |
| 1202 else | 1197 else |
| 1203 interpolator_.StopInterpolating(); | 1198 interpolator_.StopInterpolating(); |
| 1204 | 1199 |
| 1205 if (delegate_) { | 1200 if (is_playing) { |
| 1206 if (is_playing) { | 1201 // We must specify either video or audio to the delegate, but neither may |
| 1207 // We must specify either video or audio to the delegate, but neither may | 1202 // be known at this point -- there are no video only containers, so only |
| 1208 // be known at this point -- there are no video only containers, so only | 1203 // send audio if we know for sure its audio. The browser side player will |
| 1209 // send audio if we know for sure its audio. The browser side player will | 1204 // fill in the correct value later for media sessions. |
| 1210 // fill in the correct value later for media sessions. | 1205 if (isRemote()) { |
| 1211 if (isRemote()) { | 1206 delegate_->PlayerGone(delegate_id_); |
| 1212 delegate_->PlayerGone(delegate_id_); | |
| 1213 } else { | |
| 1214 delegate_->DidPlay(delegate_id_, hasVideo(), !hasVideo(), | |
| 1215 media::DurationToMediaContentType(duration_)); | |
| 1216 } | |
| 1217 delegate_->SetIdle(delegate_id_, false); | |
| 1218 } else { | 1207 } else { |
| 1219 // Even if OnPlaybackComplete() has not been called yet, Blink may have | 1208 delegate_->DidPlay(delegate_id_, hasVideo(), !hasVideo(), |
| 1220 // already fired the ended event based on current time relative to | 1209 media::DurationToMediaContentType(duration_)); |
| 1221 // duration -- so we need to check both possibilities here. | |
| 1222 if (playback_completed_ || currentTime() >= duration()) { | |
| 1223 delegate_->PlayerGone(delegate_id_); | |
| 1224 } else { | |
| 1225 delegate_->DidPause(delegate_id_); | |
| 1226 } | |
| 1227 delegate_->SetIdle(delegate_id_, true); | |
| 1228 } | 1210 } |
| 1211 delegate_->SetIdle(delegate_id_, false); |
| 1212 } else { |
| 1213 // Even if OnPlaybackComplete() has not been called yet, Blink may have |
| 1214 // already fired the ended event based on current time relative to |
| 1215 // duration -- so we need to check both possibilities here. |
| 1216 if (playback_completed_ || currentTime() >= duration()) { |
| 1217 delegate_->PlayerGone(delegate_id_); |
| 1218 } else { |
| 1219 delegate_->DidPause(delegate_id_); |
| 1220 } |
| 1221 delegate_->SetIdle(delegate_id_, true); |
| 1229 } | 1222 } |
| 1230 } | 1223 } |
| 1231 | 1224 |
| 1232 void WebMediaPlayerAndroid::OnFrameHidden() { | 1225 void WebMediaPlayerAndroid::OnFrameHidden() { |
| 1233 // Pause audible video preserving its session. | 1226 // Pause audible video preserving its session. |
| 1234 if (hasVideo() && IsBackgroundVideoCandidate() && !paused()) { | 1227 if (hasVideo() && IsBackgroundVideoCandidate() && !paused()) { |
| 1235 Pause(false); | 1228 Pause(false); |
| 1236 is_play_pending_ = true; | 1229 is_play_pending_ = true; |
| 1237 return; | 1230 return; |
| 1238 } | 1231 } |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1339 switches::kDisableMediaSuspend)) { | 1332 switches::kDisableMediaSuspend)) { |
| 1340 return false; | 1333 return false; |
| 1341 } | 1334 } |
| 1342 | 1335 |
| 1343 return base::FeatureList::IsEnabled(media::kResumeBackgroundVideo) && | 1336 return base::FeatureList::IsEnabled(media::kResumeBackgroundVideo) && |
| 1344 hasAudio() && !isRemote() && delegate_ && delegate_->IsFrameHidden() && | 1337 hasAudio() && !isRemote() && delegate_ && delegate_->IsFrameHidden() && |
| 1345 !delegate_->IsFrameClosed(); | 1338 !delegate_->IsFrameClosed(); |
| 1346 } | 1339 } |
| 1347 | 1340 |
| 1348 } // namespace content | 1341 } // namespace content |
| OLD | NEW |