Chromium Code Reviews| 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 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 144 defer_load_cb_(params.defer_load_cb()), | 144 defer_load_cb_(params.defer_load_cb()), |
| 145 buffered_(static_cast<size_t>(1)), | 145 buffered_(static_cast<size_t>(1)), |
| 146 media_task_runner_(params.media_task_runner()), | 146 media_task_runner_(params.media_task_runner()), |
| 147 pending_seek_(false), | 147 pending_seek_(false), |
| 148 seeking_(false), | 148 seeking_(false), |
| 149 did_loading_progress_(false), | 149 did_loading_progress_(false), |
| 150 player_manager_(player_manager), | 150 player_manager_(player_manager), |
| 151 network_state_(WebMediaPlayer::NetworkStateEmpty), | 151 network_state_(WebMediaPlayer::NetworkStateEmpty), |
| 152 ready_state_(WebMediaPlayer::ReadyStateHaveNothing), | 152 ready_state_(WebMediaPlayer::ReadyStateHaveNothing), |
| 153 texture_id_(0), | 153 texture_id_(0), |
| 154 stream_id_(0), | |
| 155 is_player_initialized_(false), | 154 is_player_initialized_(false), |
| 156 is_playing_(false), | 155 is_playing_(false), |
| 157 is_play_pending_(false), | 156 is_play_pending_(false), |
| 158 needs_establish_peer_(true), | 157 needs_establish_peer_(true), |
| 159 has_size_info_(false), | 158 has_size_info_(false), |
| 160 // Threaded compositing isn't enabled universally yet. | 159 // Threaded compositing isn't enabled universally yet. |
| 161 compositor_task_runner_(params.compositor_task_runner() | 160 compositor_task_runner_(params.compositor_task_runner() |
| 162 ? params.compositor_task_runner() | 161 ? params.compositor_task_runner() |
| 163 : base::ThreadTaskRunnerHandle::Get()), | 162 : base::ThreadTaskRunnerHandle::Get()), |
| 164 stream_texture_factory_(factory), | 163 stream_texture_factory_(factory), |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 193 WebMediaPlayerAndroid::~WebMediaPlayerAndroid() { | 192 WebMediaPlayerAndroid::~WebMediaPlayerAndroid() { |
| 194 DCHECK(main_thread_checker_.CalledOnValidThread()); | 193 DCHECK(main_thread_checker_.CalledOnValidThread()); |
| 195 SetVideoFrameProviderClient(NULL); | 194 SetVideoFrameProviderClient(NULL); |
| 196 client_->setWebLayer(NULL); | 195 client_->setWebLayer(NULL); |
| 197 | 196 |
| 198 if (is_player_initialized_) | 197 if (is_player_initialized_) |
| 199 player_manager_->DestroyPlayer(player_id_); | 198 player_manager_->DestroyPlayer(player_id_); |
| 200 | 199 |
| 201 player_manager_->UnregisterMediaPlayer(player_id_); | 200 player_manager_->UnregisterMediaPlayer(player_id_); |
| 202 | 201 |
| 203 if (stream_id_) { | 202 if (stream_texture_proxy_.get() && texture_id_) { |
| 204 GLES2Interface* gl = stream_texture_factory_->ContextGL(); | 203 GLES2Interface* gl = stream_texture_factory_->ContextGL(); |
| 205 gl->DeleteTextures(1, &texture_id_); | 204 gl->DeleteTextures(1, &texture_id_); |
| 206 // Flush to ensure that the stream texture gets deleted in a timely fashion. | 205 // Flush to ensure that the stream texture gets deleted in a timely fashion. |
| 207 gl->ShallowFlushCHROMIUM(); | 206 gl->ShallowFlushCHROMIUM(); |
| 208 texture_id_ = 0; | 207 texture_id_ = 0; |
| 209 texture_mailbox_ = gpu::Mailbox(); | 208 texture_mailbox_ = gpu::Mailbox(); |
| 210 stream_id_ = 0; | |
| 211 } | 209 } |
| 212 | 210 |
| 213 { | 211 { |
| 214 base::AutoLock auto_lock(current_frame_lock_); | 212 base::AutoLock auto_lock(current_frame_lock_); |
| 215 current_frame_ = NULL; | 213 current_frame_ = NULL; |
| 216 } | 214 } |
| 217 | 215 |
| 218 if (delegate_) { | 216 if (delegate_) { |
| 219 delegate_->PlayerGone(delegate_id_); | 217 delegate_->PlayerGone(delegate_id_); |
| 220 delegate_->RemoveObserver(delegate_id_); | 218 delegate_->RemoveObserver(delegate_id_); |
| (...skipping 580 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 801 // size here, we should call EstablishSurfaceTexturePeer() if it has not been | 799 // size here, we should call EstablishSurfaceTexturePeer() if it has not been |
| 802 // previously called. | 800 // previously called. |
| 803 if (!paused() && needs_establish_peer_) | 801 if (!paused() && needs_establish_peer_) |
| 804 EstablishSurfaceTexturePeer(); | 802 EstablishSurfaceTexturePeer(); |
| 805 | 803 |
| 806 ReallocateVideoFrame(); | 804 ReallocateVideoFrame(); |
| 807 | 805 |
| 808 // For hidden video element (with style "display:none"), ensure the texture | 806 // For hidden video element (with style "display:none"), ensure the texture |
| 809 // size is set. | 807 // size is set. |
| 810 if (!is_remote_ && cached_stream_texture_size_ != natural_size_) { | 808 if (!is_remote_ && cached_stream_texture_size_ != natural_size_) { |
| 811 stream_texture_factory_->SetStreamTextureSize( | 809 stream_texture_proxy_->SetStreamTextureSize( |
| 812 stream_id_, gfx::Size(natural_size_.width, natural_size_.height)); | 810 gfx::Size(natural_size_.width, natural_size_.height)); |
| 813 cached_stream_texture_size_ = natural_size_; | 811 cached_stream_texture_size_ = natural_size_; |
| 814 } | 812 } |
| 815 | 813 |
| 816 // Lazily allocate compositing layer. | 814 // Lazily allocate compositing layer. |
| 817 if (!video_weblayer_) { | 815 if (!video_weblayer_) { |
| 818 video_weblayer_.reset(new cc_blink::WebLayerImpl( | 816 video_weblayer_.reset(new cc_blink::WebLayerImpl( |
| 819 cc::VideoLayer::Create(this, media::VIDEO_ROTATION_0))); | 817 cc::VideoLayer::Create(this, media::VIDEO_ROTATION_0))); |
| 820 client_->setWebLayer(video_weblayer_.get()); | 818 client_->setWebLayer(video_weblayer_.get()); |
| 821 | 819 |
| 822 // If we're paused after we receive metadata for the first time, tell the | 820 // If we're paused after we receive metadata for the first time, tell the |
| (...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1104 | 1102 |
| 1105 return video_frame; | 1103 return video_frame; |
| 1106 } | 1104 } |
| 1107 | 1105 |
| 1108 void WebMediaPlayerAndroid::PutCurrentFrame() { | 1106 void WebMediaPlayerAndroid::PutCurrentFrame() { |
| 1109 } | 1107 } |
| 1110 | 1108 |
| 1111 void WebMediaPlayerAndroid::RemoveSurfaceTextureAndProxy() { | 1109 void WebMediaPlayerAndroid::RemoveSurfaceTextureAndProxy() { |
| 1112 DCHECK(main_thread_checker_.CalledOnValidThread()); | 1110 DCHECK(main_thread_checker_.CalledOnValidThread()); |
| 1113 | 1111 |
| 1114 if (stream_id_) { | 1112 if (stream_texture_proxy_.get() && texture_id_) { |
| 1115 GLES2Interface* gl = stream_texture_factory_->ContextGL(); | 1113 GLES2Interface* gl = stream_texture_factory_->ContextGL(); |
| 1116 gl->DeleteTextures(1, &texture_id_); | 1114 gl->DeleteTextures(1, &texture_id_); |
| 1117 // Flush to ensure that the stream texture gets deleted in a timely fashion. | 1115 // Flush to ensure that the stream texture gets deleted in a timely fashion. |
| 1118 gl->ShallowFlushCHROMIUM(); | 1116 gl->ShallowFlushCHROMIUM(); |
| 1119 texture_id_ = 0; | 1117 texture_id_ = 0; |
| 1120 texture_mailbox_ = gpu::Mailbox(); | 1118 texture_mailbox_ = gpu::Mailbox(); |
| 1121 stream_id_ = 0; | |
| 1122 } | 1119 } |
| 1123 stream_texture_proxy_.reset(); | 1120 stream_texture_proxy_.reset(); |
| 1124 needs_establish_peer_ = | 1121 needs_establish_peer_ = |
| 1125 !is_remote_ && !is_fullscreen_ && (hasVideo() || IsHLSStream()); | 1122 !is_remote_ && !is_fullscreen_ && (hasVideo() || IsHLSStream()); |
| 1126 } | 1123 } |
| 1127 | 1124 |
| 1128 void WebMediaPlayerAndroid::UpdateStreamTextureProxyCallback( | 1125 void WebMediaPlayerAndroid::UpdateStreamTextureProxyCallback( |
| 1129 cc::VideoFrameProvider::Client* client) { | 1126 cc::VideoFrameProvider::Client* client) { |
| 1130 base::Closure frame_received_cb; | 1127 base::Closure frame_received_cb; |
| 1131 | 1128 |
| 1132 if (client) { | 1129 if (client) { |
| 1133 // Unretained is safe here because: | 1130 // Unretained is safe here because: |
| 1134 // - |client| is valid until we receive a call to | 1131 // - |client| is valid until we receive a call to |
| 1135 // SetVideoFrameProviderClient(nullptr). | 1132 // SetVideoFrameProviderClient(nullptr). |
| 1136 // - SetVideoFrameProviderClient(nullptr) clears proxy's callback | 1133 // - SetVideoFrameProviderClient(nullptr) clears proxy's callback |
| 1137 // guaranteeing it will no longer be run. | 1134 // guaranteeing it will no longer be run. |
| 1138 frame_received_cb = | 1135 frame_received_cb = |
| 1139 base::Bind(&cc::VideoFrameProvider::Client::DidReceiveFrame, | 1136 base::Bind(&cc::VideoFrameProvider::Client::DidReceiveFrame, |
| 1140 base::Unretained(client)); | 1137 base::Unretained(client)); |
| 1141 } | 1138 } |
| 1142 | 1139 |
| 1143 stream_texture_proxy_->BindToTaskRunner(stream_id_, frame_received_cb, | 1140 stream_texture_proxy_->BindToTaskRunner(frame_received_cb, |
| 1144 compositor_task_runner_); | 1141 compositor_task_runner_); |
| 1145 } | 1142 } |
| 1146 | 1143 |
| 1147 void WebMediaPlayerAndroid::TryCreateStreamTextureProxyIfNeeded() { | 1144 void WebMediaPlayerAndroid::TryCreateStreamTextureProxyIfNeeded() { |
| 1148 DCHECK(main_thread_checker_.CalledOnValidThread()); | 1145 DCHECK(main_thread_checker_.CalledOnValidThread()); |
| 1149 // Already created. | 1146 // Already created. |
| 1150 if (stream_texture_proxy_) | 1147 if (stream_texture_proxy_) |
| 1151 return; | 1148 return; |
| 1152 | 1149 |
| 1153 // No factory to create proxy. | 1150 // No factory to create proxy. |
| 1154 if (!stream_texture_factory_.get()) | 1151 if (!stream_texture_factory_.get()) |
| 1155 return; | 1152 return; |
| 1156 | 1153 |
| 1157 // Not needed for hole punching. | 1154 // Not needed for hole punching. |
| 1158 if (!needs_establish_peer_) | 1155 if (!needs_establish_peer_) |
| 1159 return; | 1156 return; |
| 1160 | 1157 |
| 1161 stream_texture_proxy_.reset(stream_texture_factory_->CreateProxy()); | 1158 int32_t route_id = DoCreateStreamTexture(); |
|
liberato (no reviews please)
2016/10/07 20:01:26
can this fail?
sivag
2016/10/10 11:06:52
Done.
| |
| 1159 stream_texture_proxy_.reset(stream_texture_factory_->CreateProxy(route_id)); | |
|
liberato (no reviews please)
2016/10/07 20:01:26
perhaps this can be folded into DoCreateStreamText
sivag
2016/10/10 11:06:52
Done.
| |
| 1162 if (stream_texture_proxy_) { | 1160 if (stream_texture_proxy_) { |
| 1163 DoCreateStreamTexture(); | |
| 1164 ReallocateVideoFrame(); | 1161 ReallocateVideoFrame(); |
| 1165 if (video_frame_provider_client_) | 1162 if (video_frame_provider_client_) |
| 1166 UpdateStreamTextureProxyCallback(video_frame_provider_client_); | 1163 UpdateStreamTextureProxyCallback(video_frame_provider_client_); |
| 1167 } | 1164 } |
| 1168 } | 1165 } |
| 1169 | 1166 |
| 1170 void WebMediaPlayerAndroid::EstablishSurfaceTexturePeer() { | 1167 void WebMediaPlayerAndroid::EstablishSurfaceTexturePeer() { |
| 1171 DCHECK(main_thread_checker_.CalledOnValidThread()); | 1168 DCHECK(main_thread_checker_.CalledOnValidThread()); |
| 1172 if (!stream_texture_proxy_) | 1169 if (!stream_texture_proxy_) |
| 1173 return; | 1170 return; |
| 1174 | 1171 |
| 1175 if (stream_texture_factory_.get() && stream_id_) | 1172 stream_texture_proxy_->EstablishPeer(player_id_, frame_id_); |
| 1176 stream_texture_factory_->EstablishPeer(stream_id_, player_id_, frame_id_); | |
| 1177 | 1173 |
| 1178 // Set the deferred size because the size was changed in remote mode. | 1174 // Set the deferred size because the size was changed in remote mode. |
| 1179 if (!is_remote_ && cached_stream_texture_size_ != natural_size_) { | 1175 if (!is_remote_ && cached_stream_texture_size_ != natural_size_) { |
| 1180 stream_texture_factory_->SetStreamTextureSize( | 1176 stream_texture_proxy_->SetStreamTextureSize( |
| 1181 stream_id_, gfx::Size(natural_size_.width, natural_size_.height)); | 1177 gfx::Size(natural_size_.width, natural_size_.height)); |
| 1182 cached_stream_texture_size_ = natural_size_; | 1178 cached_stream_texture_size_ = natural_size_; |
| 1183 } | 1179 } |
| 1184 | 1180 |
| 1185 needs_establish_peer_ = false; | 1181 needs_establish_peer_ = false; |
| 1186 } | 1182 } |
| 1187 | 1183 |
| 1188 void WebMediaPlayerAndroid::DoCreateStreamTexture() { | 1184 int32_t WebMediaPlayerAndroid::DoCreateStreamTexture() { |
| 1189 DCHECK(main_thread_checker_.CalledOnValidThread()); | 1185 DCHECK(main_thread_checker_.CalledOnValidThread()); |
| 1190 DCHECK(!stream_id_); | |
| 1191 DCHECK(!texture_id_); | 1186 DCHECK(!texture_id_); |
| 1192 stream_id_ = stream_texture_factory_->CreateStreamTexture( | 1187 return stream_texture_factory_->CreateStreamTexture( |
| 1193 kGLTextureExternalOES, &texture_id_, &texture_mailbox_); | 1188 kGLTextureExternalOES, &texture_id_, &texture_mailbox_); |
| 1194 } | 1189 } |
| 1195 | 1190 |
| 1196 void WebMediaPlayerAndroid::SetNeedsEstablishPeer(bool needs_establish_peer) { | 1191 void WebMediaPlayerAndroid::SetNeedsEstablishPeer(bool needs_establish_peer) { |
| 1197 needs_establish_peer_ = needs_establish_peer; | 1192 needs_establish_peer_ = needs_establish_peer; |
| 1198 } | 1193 } |
| 1199 | 1194 |
| 1200 void WebMediaPlayerAndroid::setPoster(const blink::WebURL& poster) { | 1195 void WebMediaPlayerAndroid::setPoster(const blink::WebURL& poster) { |
| 1201 player_manager_->SetPoster(player_id_, poster); | 1196 player_manager_->SetPoster(player_id_, poster); |
| 1202 } | 1197 } |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1336 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | 1331 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 1337 switches::kDisableMediaSuspend)) { | 1332 switches::kDisableMediaSuspend)) { |
| 1338 return false; | 1333 return false; |
| 1339 } | 1334 } |
| 1340 | 1335 |
| 1341 return base::FeatureList::IsEnabled(media::kResumeBackgroundVideo) && | 1336 return base::FeatureList::IsEnabled(media::kResumeBackgroundVideo) && |
| 1342 hasAudio() && !isRemote() && delegate_ && delegate_->IsHidden(); | 1337 hasAudio() && !isRemote() && delegate_ && delegate_->IsHidden(); |
| 1343 } | 1338 } |
| 1344 | 1339 |
| 1345 } // namespace content | 1340 } // namespace content |
| OLD | NEW |