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 (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 577 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
798 // size here, we should call EstablishSurfaceTexturePeer() if it has not been | 796 // size here, we should call EstablishSurfaceTexturePeer() if it has not been |
799 // previously called. | 797 // previously called. |
800 if (!paused() && needs_establish_peer_) | 798 if (!paused() && needs_establish_peer_) |
801 EstablishSurfaceTexturePeer(); | 799 EstablishSurfaceTexturePeer(); |
802 | 800 |
803 ReallocateVideoFrame(); | 801 ReallocateVideoFrame(); |
804 | 802 |
805 // For hidden video element (with style "display:none"), ensure the texture | 803 // For hidden video element (with style "display:none"), ensure the texture |
806 // size is set. | 804 // size is set. |
807 if (!is_remote_ && cached_stream_texture_size_ != natural_size_) { | 805 if (!is_remote_ && cached_stream_texture_size_ != natural_size_) { |
808 stream_texture_factory_->SetStreamTextureSize( | 806 stream_texture_proxy_->SetStreamTextureSize( |
809 stream_id_, gfx::Size(natural_size_.width, natural_size_.height)); | 807 gfx::Size(natural_size_.width, natural_size_.height)); |
810 cached_stream_texture_size_ = natural_size_; | 808 cached_stream_texture_size_ = natural_size_; |
811 } | 809 } |
812 | 810 |
813 // Lazily allocate compositing layer. | 811 // Lazily allocate compositing layer. |
814 if (!video_weblayer_) { | 812 if (!video_weblayer_) { |
815 video_weblayer_.reset(new cc_blink::WebLayerImpl( | 813 video_weblayer_.reset(new cc_blink::WebLayerImpl( |
816 cc::VideoLayer::Create(this, media::VIDEO_ROTATION_0))); | 814 cc::VideoLayer::Create(this, media::VIDEO_ROTATION_0))); |
817 client_->setWebLayer(video_weblayer_.get()); | 815 client_->setWebLayer(video_weblayer_.get()); |
818 | 816 |
819 // If we're paused after we receive metadata for the first time, tell the | 817 // 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... |
1101 | 1099 |
1102 return video_frame; | 1100 return video_frame; |
1103 } | 1101 } |
1104 | 1102 |
1105 void WebMediaPlayerAndroid::PutCurrentFrame() { | 1103 void WebMediaPlayerAndroid::PutCurrentFrame() { |
1106 } | 1104 } |
1107 | 1105 |
1108 void WebMediaPlayerAndroid::RemoveSurfaceTextureAndProxy() { | 1106 void WebMediaPlayerAndroid::RemoveSurfaceTextureAndProxy() { |
1109 DCHECK(main_thread_checker_.CalledOnValidThread()); | 1107 DCHECK(main_thread_checker_.CalledOnValidThread()); |
1110 | 1108 |
1111 if (stream_id_) { | 1109 if (texture_id_) { |
1112 GLES2Interface* gl = stream_texture_factory_->ContextGL(); | 1110 GLES2Interface* gl = stream_texture_factory_->ContextGL(); |
1113 gl->DeleteTextures(1, &texture_id_); | 1111 gl->DeleteTextures(1, &texture_id_); |
1114 // Flush to ensure that the stream texture gets deleted in a timely fashion. | 1112 // Flush to ensure that the stream texture gets deleted in a timely fashion. |
1115 gl->ShallowFlushCHROMIUM(); | 1113 gl->ShallowFlushCHROMIUM(); |
1116 texture_id_ = 0; | 1114 texture_id_ = 0; |
1117 texture_mailbox_ = gpu::Mailbox(); | 1115 texture_mailbox_ = gpu::Mailbox(); |
1118 stream_id_ = 0; | |
1119 } | 1116 } |
1120 stream_texture_proxy_.reset(); | 1117 stream_texture_proxy_.reset(); |
1121 needs_establish_peer_ = | 1118 needs_establish_peer_ = |
1122 !is_remote_ && !is_fullscreen_ && (hasVideo() || IsHLSStream()); | 1119 !is_remote_ && !is_fullscreen_ && (hasVideo() || IsHLSStream()); |
1123 } | 1120 } |
1124 | 1121 |
1125 void WebMediaPlayerAndroid::UpdateStreamTextureProxyCallback( | 1122 void WebMediaPlayerAndroid::UpdateStreamTextureProxyCallback( |
1126 cc::VideoFrameProvider::Client* client) { | 1123 cc::VideoFrameProvider::Client* client) { |
1127 base::Closure frame_received_cb; | 1124 base::Closure frame_received_cb; |
1128 | 1125 |
1129 if (client) { | 1126 if (client) { |
1130 // Unretained is safe here because: | 1127 // Unretained is safe here because: |
1131 // - |client| is valid until we receive a call to | 1128 // - |client| is valid until we receive a call to |
1132 // SetVideoFrameProviderClient(nullptr). | 1129 // SetVideoFrameProviderClient(nullptr). |
1133 // - SetVideoFrameProviderClient(nullptr) clears proxy's callback | 1130 // - SetVideoFrameProviderClient(nullptr) clears proxy's callback |
1134 // guaranteeing it will no longer be run. | 1131 // guaranteeing it will no longer be run. |
1135 frame_received_cb = | 1132 frame_received_cb = |
1136 base::Bind(&cc::VideoFrameProvider::Client::DidReceiveFrame, | 1133 base::Bind(&cc::VideoFrameProvider::Client::DidReceiveFrame, |
1137 base::Unretained(client)); | 1134 base::Unretained(client)); |
1138 } | 1135 } |
1139 | 1136 |
1140 stream_texture_proxy_->BindToTaskRunner(stream_id_, frame_received_cb, | 1137 stream_texture_proxy_->BindToTaskRunner(frame_received_cb, |
1141 compositor_task_runner_); | 1138 compositor_task_runner_); |
1142 } | 1139 } |
1143 | 1140 |
1144 void WebMediaPlayerAndroid::TryCreateStreamTextureProxyIfNeeded() { | 1141 void WebMediaPlayerAndroid::TryCreateStreamTextureProxyIfNeeded() { |
1145 DCHECK(main_thread_checker_.CalledOnValidThread()); | 1142 DCHECK(main_thread_checker_.CalledOnValidThread()); |
1146 // Already created. | 1143 // Already created. |
1147 if (stream_texture_proxy_) | 1144 if (stream_texture_proxy_) |
1148 return; | 1145 return; |
1149 | 1146 |
1150 // No factory to create proxy. | 1147 // No factory to create proxy. |
1151 if (!stream_texture_factory_.get()) | 1148 if (!stream_texture_factory_.get()) |
1152 return; | 1149 return; |
1153 | 1150 |
1154 // Not needed for hole punching. | 1151 // Not needed for hole punching. |
1155 if (!needs_establish_peer_) | 1152 if (!needs_establish_peer_) |
1156 return; | 1153 return; |
1157 | 1154 |
1158 stream_texture_proxy_.reset(stream_texture_factory_->CreateProxy()); | 1155 DCHECK(!texture_id_); |
1159 if (stream_texture_proxy_) { | 1156 stream_texture_proxy_.reset(stream_texture_factory_->CreateProxy( |
1160 DoCreateStreamTexture(); | 1157 kGLTextureExternalOES, &texture_id_, &texture_mailbox_)); |
1161 ReallocateVideoFrame(); | 1158 if (!stream_texture_proxy_) |
1162 if (video_frame_provider_client_) | 1159 return; |
1163 UpdateStreamTextureProxyCallback(video_frame_provider_client_); | 1160 ReallocateVideoFrame(); |
1164 } | 1161 if (video_frame_provider_client_) |
| 1162 UpdateStreamTextureProxyCallback(video_frame_provider_client_); |
1165 } | 1163 } |
1166 | 1164 |
1167 void WebMediaPlayerAndroid::EstablishSurfaceTexturePeer() { | 1165 void WebMediaPlayerAndroid::EstablishSurfaceTexturePeer() { |
1168 DCHECK(main_thread_checker_.CalledOnValidThread()); | 1166 DCHECK(main_thread_checker_.CalledOnValidThread()); |
1169 if (!stream_texture_proxy_) | 1167 if (!stream_texture_proxy_) |
1170 return; | 1168 return; |
1171 | 1169 |
1172 if (stream_texture_factory_.get() && stream_id_) | 1170 stream_texture_proxy_->EstablishPeer(player_id_, frame_id_); |
1173 stream_texture_factory_->EstablishPeer(stream_id_, player_id_, frame_id_); | |
1174 | 1171 |
1175 // Set the deferred size because the size was changed in remote mode. | 1172 // Set the deferred size because the size was changed in remote mode. |
1176 if (!is_remote_ && cached_stream_texture_size_ != natural_size_) { | 1173 if (!is_remote_ && cached_stream_texture_size_ != natural_size_) { |
1177 stream_texture_factory_->SetStreamTextureSize( | 1174 stream_texture_proxy_->SetStreamTextureSize( |
1178 stream_id_, gfx::Size(natural_size_.width, natural_size_.height)); | 1175 gfx::Size(natural_size_.width, natural_size_.height)); |
1179 cached_stream_texture_size_ = natural_size_; | 1176 cached_stream_texture_size_ = natural_size_; |
1180 } | 1177 } |
1181 | 1178 |
1182 needs_establish_peer_ = false; | 1179 needs_establish_peer_ = false; |
1183 } | 1180 } |
1184 | 1181 |
1185 void WebMediaPlayerAndroid::DoCreateStreamTexture() { | |
1186 DCHECK(main_thread_checker_.CalledOnValidThread()); | |
1187 DCHECK(!stream_id_); | |
1188 DCHECK(!texture_id_); | |
1189 stream_id_ = stream_texture_factory_->CreateStreamTexture( | |
1190 kGLTextureExternalOES, &texture_id_, &texture_mailbox_); | |
1191 } | |
1192 | |
1193 void WebMediaPlayerAndroid::SetNeedsEstablishPeer(bool needs_establish_peer) { | 1182 void WebMediaPlayerAndroid::SetNeedsEstablishPeer(bool needs_establish_peer) { |
1194 needs_establish_peer_ = needs_establish_peer; | 1183 needs_establish_peer_ = needs_establish_peer; |
1195 } | 1184 } |
1196 | 1185 |
1197 void WebMediaPlayerAndroid::setPoster(const blink::WebURL& poster) { | 1186 void WebMediaPlayerAndroid::setPoster(const blink::WebURL& poster) { |
1198 player_manager_->SetPoster(player_id_, poster); | 1187 player_manager_->SetPoster(player_id_, poster); |
1199 } | 1188 } |
1200 | 1189 |
1201 void WebMediaPlayerAndroid::UpdatePlayingState(bool is_playing) { | 1190 void WebMediaPlayerAndroid::UpdatePlayingState(bool is_playing) { |
1202 if (is_playing == is_playing_) | 1191 if (is_playing == is_playing_) |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1333 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | 1322 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
1334 switches::kDisableMediaSuspend)) { | 1323 switches::kDisableMediaSuspend)) { |
1335 return false; | 1324 return false; |
1336 } | 1325 } |
1337 | 1326 |
1338 return base::FeatureList::IsEnabled(media::kResumeBackgroundVideo) && | 1327 return base::FeatureList::IsEnabled(media::kResumeBackgroundVideo) && |
1339 hasAudio() && !isRemote() && delegate_ && delegate_->IsHidden(); | 1328 hasAudio() && !isRemote() && delegate_ && delegate_->IsHidden(); |
1340 } | 1329 } |
1341 | 1330 |
1342 } // namespace content | 1331 } // namespace content |
OLD | NEW |