Skip to content

Commit

Permalink
Remote video pauses when screen is locked or when tab is switched.
Browse files Browse the repository at this point in the history
The root cause is due to the media resources being released when the screen
is locked or the tab is switched, which subsequently calls pause() on all
the players. Modified WebMediaPlayerAndroid to indicate if the player is
being paused due to a user action.

For the downstream change: https://gerrit-int.chromium.org/#/c/44201/

BUG=284472
NOTRY=true

Review URL: https://chromiumcodereview.appspot.com/23757047

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@223711 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
maybelle@chromium.org committed Sep 17, 2013
1 parent dfffbcb commit 2f66c26
Show file tree
Hide file tree
Showing 13 changed files with 33 additions and 17 deletions.
8 changes: 5 additions & 3 deletions content/browser/media/android/browser_media_player_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ void BrowserMediaPlayerManager::FullscreenPlayerPlay() {
void BrowserMediaPlayerManager::FullscreenPlayerPause() {
MediaPlayerAndroid* player = GetFullscreenPlayer();
if (player) {
player->Pause();
player->Pause(true);
Send(new MediaPlayerMsg_DidMediaPlayerPause(
routing_id(), fullscreen_player_id_));
}
Expand Down Expand Up @@ -411,10 +411,12 @@ void BrowserMediaPlayerManager::OnSeek(int player_id, base::TimeDelta time) {
player->SeekTo(time);
}

void BrowserMediaPlayerManager::OnPause(int player_id) {
void BrowserMediaPlayerManager::OnPause(
int player_id,
bool is_media_related_action) {
MediaPlayerAndroid* player = GetPlayer(player_id);
if (player)
player->Pause();
player->Pause(is_media_related_action);
}

void BrowserMediaPlayerManager::OnSetVolume(int player_id, double volume) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ class CONTENT_EXPORT BrowserMediaPlayerManager
const GURL& first_party_for_cookies);
virtual void OnStart(int player_id);
virtual void OnSeek(int player_id, base::TimeDelta time);
virtual void OnPause(int player_id);
virtual void OnPause(int player_id, bool is_media_related_action);
virtual void OnSetVolume(int player_id, double volume);
virtual void OnReleaseResources(int player_id);
virtual void OnDestroyPlayer(int player_id);
Expand Down
4 changes: 3 additions & 1 deletion content/common/media/media_player_messages_android.h
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,9 @@ IPC_MESSAGE_ROUTED4(
GURL /* first_party_for_cookies */)

// Pause the player.
IPC_MESSAGE_ROUTED1(MediaPlayerHostMsg_Pause, int /* player_id */)
IPC_MESSAGE_ROUTED2(MediaPlayerHostMsg_Pause,
int /* player_id */,
bool /* is_media_related_action */)

// Release player resources, but keep the object for future usage.
IPC_MESSAGE_ROUTED1(MediaPlayerHostMsg_Release, int /* player_id */)
Expand Down
8 changes: 6 additions & 2 deletions content/renderer/media/android/webmediaplayer_android.cc
Original file line number Diff line number Diff line change
Expand Up @@ -321,11 +321,15 @@ void WebMediaPlayerAndroid::play() {
}

void WebMediaPlayerAndroid::pause() {
pause(true);
}

void WebMediaPlayerAndroid::pause(bool is_media_related_action) {
#if defined(GOOGLE_TV)
if (audio_renderer_ && !paused())
audio_renderer_->Pause();
#endif
proxy_->Pause(player_id_);
proxy_->Pause(player_id_, is_media_related_action);
UpdatePlayingState(false);
}

Expand Down Expand Up @@ -773,7 +777,7 @@ void WebMediaPlayerAndroid::ReleaseMediaResources() {
case WebMediaPlayer::NetworkStateIdle:
case WebMediaPlayer::NetworkStateLoading:
case WebMediaPlayer::NetworkStateLoaded:
pause();
pause(false);
client_->playbackStateChanged();
break;
// If a WebMediaPlayer instance has entered into one of these states,
Expand Down
1 change: 1 addition & 0 deletions content/renderer/media/android/webmediaplayer_android.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ class WebMediaPlayerAndroid
// Playback controls.
virtual void play();
virtual void pause();
virtual void pause(bool is_media_related_action);
virtual void seek(double seconds);
virtual bool supportsFullscreen() const;
virtual bool supportsSave() const;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,11 @@ void WebMediaPlayerProxyAndroid::Start(int player_id) {
Send(new MediaPlayerHostMsg_Start(routing_id(), player_id));
}

void WebMediaPlayerProxyAndroid::Pause(int player_id) {
Send(new MediaPlayerHostMsg_Pause(routing_id(), player_id));
void WebMediaPlayerProxyAndroid::Pause(
int player_id,
bool is_media_related_action) {
Send(new MediaPlayerHostMsg_Pause(
routing_id(), player_id, is_media_related_action));
}

void WebMediaPlayerProxyAndroid::Seek(int player_id, base::TimeDelta time) {
Expand Down
8 changes: 6 additions & 2 deletions content/renderer/media/android/webmediaplayer_proxy_android.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,12 @@ class WebMediaPlayerProxyAndroid : public RenderViewObserver {
// Starts the player.
void Start(int player_id);

// Pausees the player.
void Pause(int player_id);
// Pauses the player.
// is_media_related_action should be true if this pause is coming from an
// an action that explicitly pauses the video (user pressing pause, JS, etc.)
// Otherwise it should be false if Pause is being called due to other reasons
// (cleanup, freeing resources, etc.)
void Pause(int player_id, bool is_media_related_action);

// Performs seek on the player.
void Seek(int player_id, base::TimeDelta time);
Expand Down
2 changes: 1 addition & 1 deletion media/base/android/media_player_android.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class MEDIA_EXPORT MediaPlayerAndroid {
virtual void Start() = 0;

// Pause the media.
virtual void Pause() = 0;
virtual void Pause(bool is_media_related_action) = 0;

// Seek to a particular position. When succeeds, OnSeekComplete() will be
// called. Otherwise, nothing will happen.
Expand Down
2 changes: 1 addition & 1 deletion media/base/android/media_player_bridge.cc
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ void MediaPlayerBridge::Start() {
}
}

void MediaPlayerBridge::Pause() {
void MediaPlayerBridge::Pause(bool is_media_related_action) {
if (j_media_player_bridge_.is_null()) {
pending_play_ = false;
} else {
Expand Down
2 changes: 1 addition & 1 deletion media/base/android/media_player_bridge.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class MEDIA_EXPORT MediaPlayerBridge : public MediaPlayerAndroid {
// MediaPlayerAndroid implementation.
virtual void SetVideoSurface(gfx::ScopedJavaSurface surface) OVERRIDE;
virtual void Start() OVERRIDE;
virtual void Pause() OVERRIDE;
virtual void Pause(bool is_media_related_action ALLOW_UNUSED) OVERRIDE;
virtual void SeekTo(base::TimeDelta time) OVERRIDE;
virtual void Release() OVERRIDE;
virtual void SetVolume(double volume) OVERRIDE;
Expand Down
2 changes: 1 addition & 1 deletion media/base/android/media_source_player.cc
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ void MediaSourcePlayer::Start() {
StartInternal();
}

void MediaSourcePlayer::Pause() {
void MediaSourcePlayer::Pause(bool is_media_related_action) {
DVLOG(1) << __FUNCTION__;

// Since decoder jobs have their own thread, decoding is not fully paused
Expand Down
2 changes: 1 addition & 1 deletion media/base/android/media_source_player.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class MEDIA_EXPORT MediaSourcePlayer : public MediaPlayerAndroid,
// MediaPlayerAndroid implementation.
virtual void SetVideoSurface(gfx::ScopedJavaSurface surface) OVERRIDE;
virtual void Start() OVERRIDE;
virtual void Pause() OVERRIDE;
virtual void Pause(bool is_media_related_action ALLOW_UNUSED) OVERRIDE;
virtual void SeekTo(base::TimeDelta timestamp) OVERRIDE;
virtual void Release() OVERRIDE;
virtual void SetVolume(double volume) OVERRIDE;
Expand Down
2 changes: 1 addition & 1 deletion media/base/android/media_source_player_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@ TEST_F(MediaSourcePlayerTest, StartImmediatelyAfterPause) {

// Decoder job will not immediately stop after Pause() since it is
// running on another thread.
player_.Pause();
player_.Pause(true);
EXPECT_TRUE(GetMediaDecoderJob(true)->is_decoding());

// Nothing happens when calling Start() again.
Expand Down

0 comments on commit 2f66c26

Please sign in to comment.