Skip to content
This repository was archived by the owner on Apr 3, 2020. It is now read-only.

Commit 515ae25

Browse files
boliuCommit bot
boliu
authored and
Commit bot
committed
Revert of Clean up WebMediaPlayerAndroid needs_establish_peer_ (patchset #7 id:120001 of https://codereview.chromium.org/557593002/)
Reason for revert: Suspected to break tough_video_cases. See crbug.com/412897 for details. BUG=412897 Original issue's description: > Clean up WebMediaPlayerAndroid needs_establish_peer_ > > needs_establish_peer_ has been used to skip actual estalishing a surface > texture peer based on many conditions. Not all places that modify > actually checks all these conditions so there are bound to be some bugs. > > This CL aims to tease out all these different conditions and put them in > a single function EstablishSurfaceTexturePeerIfNeeded. This function > should be called any time these conditions are changed. Makes for much > saner reading. > > BUG=412578 > > Committed: https://crrev.com/701cb640efb326aa107b5b0c25dcf91766fe765f > Cr-Commit-Position: refs/heads/master@{#294068} [email protected],[email protected],[email protected] NOTREECHECKS=true NOTRY=true BUG=412578 Review URL: https://codereview.chromium.org/562803002 Cr-Commit-Position: refs/heads/master@{#294271}
1 parent f004ba6 commit 515ae25

File tree

2 files changed

+67
-49
lines changed

2 files changed

+67
-49
lines changed

content/renderer/media/android/webmediaplayer_android.cc

Lines changed: 61 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,6 @@ WebMediaPlayerAndroid::WebMediaPlayerAndroid(
135135
stream_id_(0),
136136
is_playing_(false),
137137
needs_establish_peer_(true),
138-
in_fullscreen_(false),
139138
stream_texture_proxy_initialized_(false),
140139
has_size_info_(false),
141140
stream_texture_factory_(factory),
@@ -164,7 +163,7 @@ WebMediaPlayerAndroid::WebMediaPlayerAndroid(
164163
if (force_use_overlay_embedded_video_ ||
165164
player_manager_->ShouldUseVideoOverlayForEmbeddedEncryptedVideo()) {
166165
// Defer stream texture creation until we are sure it's necessary.
167-
needs_external_surface_ = true;
166+
needs_establish_peer_ = false;
168167
current_frame_ = VideoFrame::CreateBlackFrame(gfx::Size(1, 1));
169168
}
170169
#endif // defined(VIDEO_HOLE)
@@ -305,11 +304,18 @@ void WebMediaPlayerAndroid::play() {
305304
#if defined(VIDEO_HOLE)
306305
if ((hasVideo() || IsHLSStream()) && needs_external_surface_ &&
307306
!player_manager_->IsInFullscreen(frame_)) {
307+
DCHECK(!needs_establish_peer_);
308308
player_manager_->RequestExternalSurface(player_id_, last_computed_rect_);
309309
}
310310
#endif // defined(VIDEO_HOLE)
311311

312312
TryCreateStreamTextureProxyIfNeeded();
313+
// There is no need to establish the surface texture peer for fullscreen
314+
// video.
315+
if ((hasVideo() || IsHLSStream()) && needs_establish_peer_ &&
316+
!player_manager_->IsInFullscreen(frame_)) {
317+
EstablishSurfaceTexturePeer();
318+
}
313319

314320
if (paused())
315321
player_manager_->Start(player_id_);
@@ -753,6 +759,7 @@ void WebMediaPlayerAndroid::OnPlaybackComplete() {
753759
// process are sequential, the OnSeekComplete() will only occur
754760
// once OnPlaybackComplete() is done. As the playback can only be executed
755761
// upon completion of OnSeekComplete(), the request needs to be saved.
762+
is_playing_ = false;
756763
if (seeking_ && seek_time_ == base::TimeDelta())
757764
pending_playback_ = true;
758765
}
@@ -818,18 +825,25 @@ void WebMediaPlayerAndroid::OnVideoSizeChanged(int width, int height) {
818825
if (force_use_overlay_embedded_video_ ||
819826
(media_source_delegate_ && media_source_delegate_->IsVideoEncrypted() &&
820827
player_manager_->ShouldUseVideoOverlayForEmbeddedEncryptedVideo())) {
828+
needs_external_surface_ = true;
821829
if (!paused() && !player_manager_->IsInFullscreen(frame_))
822830
player_manager_->RequestExternalSurface(player_id_, last_computed_rect_);
823-
} else {
824-
needs_external_surface_ = false;
831+
} else if (stream_texture_proxy_ && !stream_id_) {
832+
// Do deferred stream texture creation finally.
833+
DoCreateStreamTexture();
834+
SetNeedsEstablishPeer(true);
825835
}
826836
#endif // defined(VIDEO_HOLE)
827837
natural_size_.width = width;
828838
natural_size_.height = height;
829839

830-
// hasVideo() might have changed since play was called, so need to possibly
831-
// estlibash peer here.
832-
EstablishSurfaceTexturePeerIfNeeded();
840+
// When play() gets called, |natural_size_| may still be empty and
841+
// EstablishSurfaceTexturePeer() will not get called. As a result, the video
842+
// may play without a surface texture. When we finally get the valid video
843+
// size here, we should call EstablishSurfaceTexturePeer() if it has not been
844+
// previously called.
845+
if (!paused() && needs_establish_peer_)
846+
EstablishSurfaceTexturePeer();
833847

834848
ReallocateVideoFrame();
835849

@@ -867,15 +881,16 @@ void WebMediaPlayerAndroid::OnConnectedToRemoteDevice(
867881
DCHECK(!media_source_delegate_);
868882
DrawRemotePlaybackText(remote_playback_message);
869883
is_remote_ = true;
870-
needs_establish_peer_ = true;
871-
EstablishSurfaceTexturePeerIfNeeded();
884+
SetNeedsEstablishPeer(false);
872885
}
873886

874887
void WebMediaPlayerAndroid::OnDisconnectedFromRemoteDevice() {
875888
DCHECK(main_thread_checker_.CalledOnValidThread());
876889
DCHECK(!media_source_delegate_);
890+
SetNeedsEstablishPeer(true);
891+
if (!paused())
892+
EstablishSurfaceTexturePeer();
877893
is_remote_ = false;
878-
EstablishSurfaceTexturePeerIfNeeded();
879894
ReallocateVideoFrame();
880895
}
881896

@@ -885,8 +900,13 @@ void WebMediaPlayerAndroid::OnDidEnterFullscreen() {
885900
}
886901

887902
void WebMediaPlayerAndroid::OnDidExitFullscreen() {
888-
in_fullscreen_ = false;
889-
EstablishSurfaceTexturePeerIfNeeded();
903+
// |needs_external_surface_| is always false on non-TV devices.
904+
if (!needs_external_surface_)
905+
SetNeedsEstablishPeer(true);
906+
// We had the fullscreen surface connected to Android MediaPlayer,
907+
// so reconnect our surface texture for embedded playback.
908+
if (!paused() && needs_establish_peer_)
909+
EstablishSurfaceTexturePeer();
890910

891911
#if defined(VIDEO_HOLE)
892912
if (!paused() && needs_external_surface_)
@@ -948,7 +968,9 @@ void WebMediaPlayerAndroid::UpdateReadyState(
948968
}
949969

950970
void WebMediaPlayerAndroid::OnPlayerReleased() {
951-
needs_establish_peer_ = true; // Established when this plays.
971+
// |needs_external_surface_| is always false on non-TV devices.
972+
if (!needs_external_surface_)
973+
needs_establish_peer_ = true;
952974

953975
if (is_playing_)
954976
OnMediaPlayerPause();
@@ -978,7 +1000,8 @@ void WebMediaPlayerAndroid::ReleaseMediaResources() {
9781000
break;
9791001
}
9801002
player_manager_->ReleaseResources(player_id_);
981-
needs_establish_peer_ = true; // Established when this plays.
1003+
if (!needs_external_surface_)
1004+
SetNeedsEstablishPeer(true);
9821005
}
9831006

9841007
void WebMediaPlayerAndroid::OnDestruct() {
@@ -1221,51 +1244,52 @@ void WebMediaPlayerAndroid::TryCreateStreamTextureProxyIfNeeded() {
12211244
if (!stream_texture_factory_)
12221245
return;
12231246

1224-
if (needs_external_surface_)
1225-
return;
1226-
12271247
stream_texture_proxy_.reset(stream_texture_factory_->CreateProxy());
1228-
if (stream_texture_proxy_) {
1248+
if (needs_establish_peer_ && stream_texture_proxy_) {
12291249
DoCreateStreamTexture();
12301250
ReallocateVideoFrame();
1231-
1232-
if (video_frame_provider_client_)
1233-
stream_texture_proxy_->SetClient(video_frame_provider_client_);
12341251
}
1235-
}
12361252

1237-
void WebMediaPlayerAndroid::DoCreateStreamTexture() {
1238-
DCHECK(main_thread_checker_.CalledOnValidThread());
1239-
DCHECK(!stream_id_);
1240-
DCHECK(!texture_id_);
1241-
stream_id_ = stream_texture_factory_->CreateStreamTexture(
1242-
kGLTextureExternalOES, &texture_id_, &texture_mailbox_);
1253+
if (stream_texture_proxy_ && video_frame_provider_client_)
1254+
stream_texture_proxy_->SetClient(video_frame_provider_client_);
12431255
}
12441256

1245-
void WebMediaPlayerAndroid::EstablishSurfaceTexturePeerIfNeeded() {
1257+
void WebMediaPlayerAndroid::EstablishSurfaceTexturePeer() {
12461258
DCHECK(main_thread_checker_.CalledOnValidThread());
1247-
if (!needs_establish_peer_ || in_fullscreen_ || needs_external_surface_ ||
1248-
is_remote_ || !is_playing_ || !stream_texture_proxy_ ||
1249-
(!hasVideo() && !IsHLSStream())) {
1259+
if (!stream_texture_proxy_)
12501260
return;
1251-
}
12521261

1253-
stream_texture_factory_->EstablishPeer(stream_id_, player_id_);
1254-
if (cached_stream_texture_size_ != natural_size_) {
1262+
if (stream_texture_factory_.get() && stream_id_)
1263+
stream_texture_factory_->EstablishPeer(stream_id_, player_id_);
1264+
1265+
// Set the deferred size because the size was changed in remote mode.
1266+
if (!is_remote_ && cached_stream_texture_size_ != natural_size_) {
12551267
stream_texture_factory_->SetStreamTextureSize(
12561268
stream_id_, gfx::Size(natural_size_.width, natural_size_.height));
12571269
cached_stream_texture_size_ = natural_size_;
12581270
}
1271+
12591272
needs_establish_peer_ = false;
12601273
}
12611274

1275+
void WebMediaPlayerAndroid::DoCreateStreamTexture() {
1276+
DCHECK(main_thread_checker_.CalledOnValidThread());
1277+
DCHECK(!stream_id_);
1278+
DCHECK(!texture_id_);
1279+
stream_id_ = stream_texture_factory_->CreateStreamTexture(
1280+
kGLTextureExternalOES, &texture_id_, &texture_mailbox_);
1281+
}
1282+
1283+
void WebMediaPlayerAndroid::SetNeedsEstablishPeer(bool needs_establish_peer) {
1284+
needs_establish_peer_ = needs_establish_peer;
1285+
}
1286+
12621287
void WebMediaPlayerAndroid::setPoster(const blink::WebURL& poster) {
12631288
player_manager_->SetPoster(player_id_, poster);
12641289
}
12651290

12661291
void WebMediaPlayerAndroid::UpdatePlayingState(bool is_playing) {
12671292
is_playing_ = is_playing;
1268-
EstablishSurfaceTexturePeerIfNeeded();
12691293
if (!delegate_)
12701294
return;
12711295
if (is_playing)
@@ -1735,10 +1759,8 @@ void WebMediaPlayerAndroid::SetDecryptorReadyCB(
17351759
void WebMediaPlayerAndroid::enterFullscreen() {
17361760
if (player_manager_->CanEnterFullscreen(frame_)) {
17371761
player_manager_->EnterFullscreen(player_id_, frame_);
1762+
SetNeedsEstablishPeer(false);
17381763
}
1739-
in_fullscreen_ = true;
1740-
needs_establish_peer_ = true;
1741-
EstablishSurfaceTexturePeerIfNeeded();
17421764
}
17431765

17441766
bool WebMediaPlayerAndroid::canEnterFullscreen() const {

content/renderer/media/android/webmediaplayer_android.h

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -266,9 +266,12 @@ class WebMediaPlayerAndroid : public blink::WebMediaPlayer,
266266
void TryCreateStreamTextureProxyIfNeeded();
267267
void DoCreateStreamTexture();
268268

269-
// This method is meant to be idempotent. Should be called whenever any of
270-
// conditions changes and it is ok to establish peer.
271-
void EstablishSurfaceTexturePeerIfNeeded();
269+
// Helper method to reestablish the surface texture peer for android
270+
// media player.
271+
void EstablishSurfaceTexturePeer();
272+
273+
// Requesting whether the surface texture peer needs to be reestablished.
274+
void SetNeedsEstablishPeer(bool needs_establish_peer);
272275

273276
private:
274277
void InitializePlayer(const GURL& url,
@@ -405,15 +408,8 @@ class WebMediaPlayerAndroid : public blink::WebMediaPlayer,
405408
bool is_playing_;
406409

407410
// Whether media player needs to re-establish the surface texture peer.
408-
// This should be unset in EstablishSurfaceTexturePeerIfNeeded() only, and set
409-
// we believe peer is disconnected that we need to establish it again.
410-
// Setting this should not be conditioned on additional state, eg playing
411-
// or full screen.
412411
bool needs_establish_peer_;
413412

414-
// This is a helper state used in EstablishSurfaceTexturePeerIfNeeded().
415-
bool in_fullscreen_;
416-
417413
// Whether |stream_texture_proxy_| is initialized.
418414
bool stream_texture_proxy_initialized_;
419415

0 commit comments

Comments
 (0)