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 <limits> | 7 #include <limits> |
8 | 8 |
9 #include "base/android/build_info.h" | 9 #include "base/android/build_info.h" |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
129 seeking_(false), | 129 seeking_(false), |
130 did_loading_progress_(false), | 130 did_loading_progress_(false), |
131 player_manager_(player_manager), | 131 player_manager_(player_manager), |
132 cdm_manager_(cdm_manager), | 132 cdm_manager_(cdm_manager), |
133 network_state_(WebMediaPlayer::NetworkStateEmpty), | 133 network_state_(WebMediaPlayer::NetworkStateEmpty), |
134 ready_state_(WebMediaPlayer::ReadyStateHaveNothing), | 134 ready_state_(WebMediaPlayer::ReadyStateHaveNothing), |
135 texture_id_(0), | 135 texture_id_(0), |
136 stream_id_(0), | 136 stream_id_(0), |
137 is_playing_(false), | 137 is_playing_(false), |
138 needs_establish_peer_(true), | 138 needs_establish_peer_(true), |
139 stream_texture_proxy_initialized_(false), | |
140 has_size_info_(false), | 139 has_size_info_(false), |
| 140 compositor_loop_( |
| 141 RenderThreadImpl::current()->compositor_message_loop_proxy()), |
141 stream_texture_factory_(factory), | 142 stream_texture_factory_(factory), |
142 needs_external_surface_(false), | 143 needs_external_surface_(false), |
143 has_valid_metadata_(false), | 144 has_valid_metadata_(false), |
144 video_frame_provider_client_(NULL), | 145 video_frame_provider_client_(NULL), |
145 pending_playback_(false), | 146 pending_playback_(false), |
146 player_type_(MEDIA_PLAYER_TYPE_URL), | 147 player_type_(MEDIA_PLAYER_TYPE_URL), |
147 is_remote_(false), | 148 is_remote_(false), |
148 media_log_(media_log), | 149 media_log_(media_log), |
149 web_cdm_(NULL), | 150 web_cdm_(NULL), |
150 allow_stored_credentials_(false), | 151 allow_stored_credentials_(false), |
151 is_local_resource_(false), | 152 is_local_resource_(false), |
152 interpolator_(&default_tick_clock_), | 153 interpolator_(&default_tick_clock_), |
153 weak_factory_(this) { | 154 weak_factory_(this) { |
154 DCHECK(player_manager_); | 155 DCHECK(player_manager_); |
155 DCHECK(cdm_manager_); | 156 DCHECK(cdm_manager_); |
156 | 157 |
157 DCHECK(main_thread_checker_.CalledOnValidThread()); | 158 DCHECK(main_thread_checker_.CalledOnValidThread()); |
| 159 stream_texture_factory_->AddObserver(this); |
158 | 160 |
159 player_id_ = player_manager_->RegisterMediaPlayer(this); | 161 player_id_ = player_manager_->RegisterMediaPlayer(this); |
160 | 162 |
161 #if defined(VIDEO_HOLE) | 163 #if defined(VIDEO_HOLE) |
162 force_use_overlay_embedded_video_ = CommandLine::ForCurrentProcess()-> | 164 force_use_overlay_embedded_video_ = CommandLine::ForCurrentProcess()-> |
163 HasSwitch(switches::kForceUseOverlayEmbeddedVideo); | 165 HasSwitch(switches::kForceUseOverlayEmbeddedVideo); |
164 if (force_use_overlay_embedded_video_ || | 166 if (force_use_overlay_embedded_video_ || |
165 player_manager_->ShouldUseVideoOverlayForEmbeddedEncryptedVideo()) { | 167 player_manager_->ShouldUseVideoOverlayForEmbeddedEncryptedVideo()) { |
166 // Defer stream texture creation until we are sure it's necessary. | 168 // Defer stream texture creation until we are sure it's necessary. |
167 needs_establish_peer_ = false; | 169 needs_establish_peer_ = false; |
(...skipping 22 matching lines...) Expand all Loading... |
190 stream_id_ = 0; | 192 stream_id_ = 0; |
191 } | 193 } |
192 | 194 |
193 { | 195 { |
194 base::AutoLock auto_lock(current_frame_lock_); | 196 base::AutoLock auto_lock(current_frame_lock_); |
195 current_frame_ = NULL; | 197 current_frame_ = NULL; |
196 } | 198 } |
197 | 199 |
198 if (player_type_ == MEDIA_PLAYER_TYPE_MEDIA_SOURCE && delegate_) | 200 if (player_type_ == MEDIA_PLAYER_TYPE_MEDIA_SOURCE && delegate_) |
199 delegate_->PlayerGone(this); | 201 delegate_->PlayerGone(this); |
| 202 |
| 203 stream_texture_factory_->RemoveObserver(this); |
200 } | 204 } |
201 | 205 |
202 void WebMediaPlayerAndroid::load(LoadType load_type, | 206 void WebMediaPlayerAndroid::load(LoadType load_type, |
203 const blink::WebURL& url, | 207 const blink::WebURL& url, |
204 CORSMode cors_mode) { | 208 CORSMode cors_mode) { |
205 DCHECK(main_thread_checker_.CalledOnValidThread()); | 209 DCHECK(main_thread_checker_.CalledOnValidThread()); |
206 media::ReportMediaSchemeUma(GURL(url)); | 210 media::ReportMediaSchemeUma(GURL(url)); |
207 | 211 |
208 switch (load_type) { | 212 switch (load_type) { |
209 case LoadTypeURL: | 213 case LoadTypeURL: |
(...skipping 997 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1207 base::TimeDelta(), | 1211 base::TimeDelta(), |
1208 VideoFrame::ReadPixelsCB()); | 1212 VideoFrame::ReadPixelsCB()); |
1209 SetCurrentFrameInternal(new_frame); | 1213 SetCurrentFrameInternal(new_frame); |
1210 } | 1214 } |
1211 } | 1215 } |
1212 | 1216 |
1213 void WebMediaPlayerAndroid::SetVideoFrameProviderClient( | 1217 void WebMediaPlayerAndroid::SetVideoFrameProviderClient( |
1214 cc::VideoFrameProvider::Client* client) { | 1218 cc::VideoFrameProvider::Client* client) { |
1215 // This is called from both the main renderer thread and the compositor | 1219 // This is called from both the main renderer thread and the compositor |
1216 // thread (when the main thread is blocked). | 1220 // thread (when the main thread is blocked). |
1217 if (video_frame_provider_client_) | 1221 |
| 1222 // Set the callback target when a frame is produced. Need to do this before |
| 1223 // StopUsingProvider to ensure we really stop using the client. |
| 1224 if (stream_texture_proxy_) |
| 1225 stream_texture_proxy_->BindToLoop(stream_id_, client, compositor_loop_); |
| 1226 |
| 1227 if (video_frame_provider_client_ && video_frame_provider_client_ != client) |
1218 video_frame_provider_client_->StopUsingProvider(); | 1228 video_frame_provider_client_->StopUsingProvider(); |
1219 video_frame_provider_client_ = client; | 1229 video_frame_provider_client_ = client; |
1220 | |
1221 // Set the callback target when a frame is produced. | |
1222 if (stream_texture_proxy_) { | |
1223 stream_texture_proxy_->SetClient(client); | |
1224 // If client exists, the compositor thread calls it. At that time, | |
1225 // stream_id_, needs_external_surface_, is_remote_ can be accessed because | |
1226 // the main thread is blocked. | |
1227 if (client && !stream_texture_proxy_initialized_ && stream_id_ && | |
1228 !needs_external_surface_ && !is_remote_) { | |
1229 stream_texture_proxy_->BindToCurrentThread(stream_id_); | |
1230 stream_texture_proxy_initialized_ = true; | |
1231 } | |
1232 } | |
1233 } | 1230 } |
1234 | 1231 |
1235 void WebMediaPlayerAndroid::SetCurrentFrameInternal( | 1232 void WebMediaPlayerAndroid::SetCurrentFrameInternal( |
1236 scoped_refptr<media::VideoFrame>& video_frame) { | 1233 scoped_refptr<media::VideoFrame>& video_frame) { |
1237 DCHECK(main_thread_checker_.CalledOnValidThread()); | 1234 DCHECK(main_thread_checker_.CalledOnValidThread()); |
1238 base::AutoLock auto_lock(current_frame_lock_); | 1235 base::AutoLock auto_lock(current_frame_lock_); |
1239 current_frame_ = video_frame; | 1236 current_frame_ = video_frame; |
1240 } | 1237 } |
1241 | 1238 |
1242 scoped_refptr<media::VideoFrame> WebMediaPlayerAndroid::GetCurrentFrame() { | 1239 scoped_refptr<media::VideoFrame> WebMediaPlayerAndroid::GetCurrentFrame() { |
1243 scoped_refptr<VideoFrame> video_frame; | 1240 scoped_refptr<VideoFrame> video_frame; |
1244 { | 1241 { |
1245 base::AutoLock auto_lock(current_frame_lock_); | 1242 base::AutoLock auto_lock(current_frame_lock_); |
1246 video_frame = current_frame_; | 1243 video_frame = current_frame_; |
1247 } | 1244 } |
1248 | 1245 |
1249 return video_frame; | 1246 return video_frame; |
1250 } | 1247 } |
1251 | 1248 |
1252 void WebMediaPlayerAndroid::PutCurrentFrame( | 1249 void WebMediaPlayerAndroid::PutCurrentFrame( |
1253 const scoped_refptr<media::VideoFrame>& frame) { | 1250 const scoped_refptr<media::VideoFrame>& frame) { |
1254 } | 1251 } |
1255 | 1252 |
| 1253 void WebMediaPlayerAndroid::ResetStreamTextureProxy() { |
| 1254 DCHECK(main_thread_checker_.CalledOnValidThread()); |
| 1255 |
| 1256 if (stream_id_) { |
| 1257 GLES2Interface* gl = stream_texture_factory_->ContextGL(); |
| 1258 gl->DeleteTextures(1, &texture_id_); |
| 1259 texture_id_ = 0; |
| 1260 texture_mailbox_ = gpu::Mailbox(); |
| 1261 stream_id_ = 0; |
| 1262 } |
| 1263 stream_texture_proxy_.reset(); |
| 1264 needs_establish_peer_ = !needs_external_surface_ && !is_remote_ && |
| 1265 !player_manager_->IsInFullscreen(frame_) && |
| 1266 (hasVideo() || IsHLSStream()); |
| 1267 |
| 1268 TryCreateStreamTextureProxyIfNeeded(); |
| 1269 if (needs_establish_peer_ && is_playing_) |
| 1270 EstablishSurfaceTexturePeer(); |
| 1271 } |
| 1272 |
1256 void WebMediaPlayerAndroid::TryCreateStreamTextureProxyIfNeeded() { | 1273 void WebMediaPlayerAndroid::TryCreateStreamTextureProxyIfNeeded() { |
1257 DCHECK(main_thread_checker_.CalledOnValidThread()); | 1274 DCHECK(main_thread_checker_.CalledOnValidThread()); |
1258 // Already created. | 1275 // Already created. |
1259 if (stream_texture_proxy_) | 1276 if (stream_texture_proxy_) |
1260 return; | 1277 return; |
1261 | 1278 |
1262 // No factory to create proxy. | 1279 // No factory to create proxy. |
1263 if (!stream_texture_factory_) | 1280 if (!stream_texture_factory_) |
1264 return; | 1281 return; |
1265 | 1282 |
| 1283 // Not needed for hole punching. |
| 1284 if (!needs_establish_peer_) |
| 1285 return; |
| 1286 |
1266 stream_texture_proxy_.reset(stream_texture_factory_->CreateProxy()); | 1287 stream_texture_proxy_.reset(stream_texture_factory_->CreateProxy()); |
1267 if (needs_establish_peer_ && stream_texture_proxy_) { | 1288 if (stream_texture_proxy_) { |
1268 DoCreateStreamTexture(); | 1289 DoCreateStreamTexture(); |
1269 ReallocateVideoFrame(); | 1290 ReallocateVideoFrame(); |
| 1291 if (video_frame_provider_client_) { |
| 1292 stream_texture_proxy_->BindToLoop( |
| 1293 stream_id_, video_frame_provider_client_, compositor_loop_); |
| 1294 } |
1270 } | 1295 } |
1271 | |
1272 if (stream_texture_proxy_ && video_frame_provider_client_) | |
1273 stream_texture_proxy_->SetClient(video_frame_provider_client_); | |
1274 } | 1296 } |
1275 | 1297 |
1276 void WebMediaPlayerAndroid::EstablishSurfaceTexturePeer() { | 1298 void WebMediaPlayerAndroid::EstablishSurfaceTexturePeer() { |
1277 DCHECK(main_thread_checker_.CalledOnValidThread()); | 1299 DCHECK(main_thread_checker_.CalledOnValidThread()); |
1278 if (!stream_texture_proxy_) | 1300 if (!stream_texture_proxy_) |
1279 return; | 1301 return; |
1280 | 1302 |
1281 if (stream_texture_factory_.get() && stream_id_) | 1303 if (stream_texture_factory_.get() && stream_id_) |
1282 stream_texture_factory_->EstablishPeer(stream_id_, player_id_); | 1304 stream_texture_factory_->EstablishPeer(stream_id_, player_id_); |
1283 | 1305 |
(...skipping 509 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1793 | 1815 |
1794 bool WebMediaPlayerAndroid::IsHLSStream() const { | 1816 bool WebMediaPlayerAndroid::IsHLSStream() const { |
1795 std::string mime; | 1817 std::string mime; |
1796 GURL url = redirected_url_.is_empty() ? url_ : redirected_url_; | 1818 GURL url = redirected_url_.is_empty() ? url_ : redirected_url_; |
1797 if (!net::GetMimeTypeFromFile(base::FilePath(url.path()), &mime)) | 1819 if (!net::GetMimeTypeFromFile(base::FilePath(url.path()), &mime)) |
1798 return false; | 1820 return false; |
1799 return !mime.compare("application/x-mpegurl"); | 1821 return !mime.compare("application/x-mpegurl"); |
1800 } | 1822 } |
1801 | 1823 |
1802 } // namespace content | 1824 } // namespace content |
OLD | NEW |