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 <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 995 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1205 base::TimeDelta(), | 1209 base::TimeDelta(), |
| 1206 VideoFrame::ReadPixelsCB()); | 1210 VideoFrame::ReadPixelsCB()); |
| 1207 SetCurrentFrameInternal(new_frame); | 1211 SetCurrentFrameInternal(new_frame); |
| 1208 } | 1212 } |
| 1209 } | 1213 } |
| 1210 | 1214 |
| 1211 void WebMediaPlayerAndroid::SetVideoFrameProviderClient( | 1215 void WebMediaPlayerAndroid::SetVideoFrameProviderClient( |
| 1212 cc::VideoFrameProvider::Client* client) { | 1216 cc::VideoFrameProvider::Client* client) { |
| 1213 // This is called from both the main renderer thread and the compositor | 1217 // This is called from both the main renderer thread and the compositor |
| 1214 // thread (when the main thread is blocked). | 1218 // thread (when the main thread is blocked). |
| 1215 if (video_frame_provider_client_) | 1219 |
| 1220 // Set the callback target when a frame is produced. Need to do this before | |
| 1221 // StopUsingProvider to ensure we really stop using the client. | |
| 1222 if (stream_texture_proxy_) | |
| 1223 stream_texture_proxy_->BindToLoop(stream_id_, client, compositor_loop_); | |
| 1224 | |
| 1225 if (video_frame_provider_client_ && video_frame_provider_client_ != client) | |
| 1216 video_frame_provider_client_->StopUsingProvider(); | 1226 video_frame_provider_client_->StopUsingProvider(); |
| 1217 video_frame_provider_client_ = client; | 1227 video_frame_provider_client_ = client; |
| 1218 | |
| 1219 // Set the callback target when a frame is produced. | |
| 1220 if (stream_texture_proxy_) { | |
| 1221 stream_texture_proxy_->SetClient(client); | |
| 1222 // If client exists, the compositor thread calls it. At that time, | |
| 1223 // stream_id_, needs_external_surface_, is_remote_ can be accessed because | |
| 1224 // the main thread is blocked. | |
| 1225 if (client && !stream_texture_proxy_initialized_ && stream_id_ && | |
| 1226 !needs_external_surface_ && !is_remote_) { | |
| 1227 stream_texture_proxy_->BindToCurrentThread(stream_id_); | |
| 1228 stream_texture_proxy_initialized_ = true; | |
| 1229 } | |
| 1230 } | |
| 1231 } | 1228 } |
| 1232 | 1229 |
| 1233 void WebMediaPlayerAndroid::SetCurrentFrameInternal( | 1230 void WebMediaPlayerAndroid::SetCurrentFrameInternal( |
| 1234 scoped_refptr<media::VideoFrame>& video_frame) { | 1231 scoped_refptr<media::VideoFrame>& video_frame) { |
| 1235 DCHECK(main_thread_checker_.CalledOnValidThread()); | 1232 DCHECK(main_thread_checker_.CalledOnValidThread()); |
| 1236 base::AutoLock auto_lock(current_frame_lock_); | 1233 base::AutoLock auto_lock(current_frame_lock_); |
| 1237 current_frame_ = video_frame; | 1234 current_frame_ = video_frame; |
| 1238 } | 1235 } |
| 1239 | 1236 |
| 1240 scoped_refptr<media::VideoFrame> WebMediaPlayerAndroid::GetCurrentFrame() { | 1237 scoped_refptr<media::VideoFrame> WebMediaPlayerAndroid::GetCurrentFrame() { |
| 1241 scoped_refptr<VideoFrame> video_frame; | 1238 scoped_refptr<VideoFrame> video_frame; |
| 1242 { | 1239 { |
| 1243 base::AutoLock auto_lock(current_frame_lock_); | 1240 base::AutoLock auto_lock(current_frame_lock_); |
| 1244 video_frame = current_frame_; | 1241 video_frame = current_frame_; |
| 1245 } | 1242 } |
| 1246 | 1243 |
| 1247 return video_frame; | 1244 return video_frame; |
| 1248 } | 1245 } |
| 1249 | 1246 |
| 1250 void WebMediaPlayerAndroid::PutCurrentFrame( | 1247 void WebMediaPlayerAndroid::PutCurrentFrame( |
| 1251 const scoped_refptr<media::VideoFrame>& frame) { | 1248 const scoped_refptr<media::VideoFrame>& frame) { |
| 1252 } | 1249 } |
| 1253 | 1250 |
| 1251 void WebMediaPlayerAndroid::ResetStreamTextureProxy() { | |
| 1252 DCHECK(main_thread_checker_.CalledOnValidThread()); | |
| 1253 | |
| 1254 if (stream_id_) { | |
| 1255 GLES2Interface* gl = stream_texture_factory_->ContextGL(); | |
| 1256 gl->DeleteTextures(1, &texture_id_); | |
| 1257 texture_id_ = 0; | |
| 1258 texture_mailbox_ = gpu::Mailbox(); | |
| 1259 stream_id_ = 0; | |
| 1260 } | |
| 1261 stream_texture_proxy_.reset(); | |
| 1262 needs_establish_peer_ = !needs_external_surface_ && !is_remote_ && | |
| 1263 !player_manager_->IsInFullscreen(frame_) && | |
| 1264 (hasVideo() || IsHLSStream()); | |
| 1265 | |
| 1266 TryCreateStreamTextureProxyIfNeeded(); | |
| 1267 if (needs_establish_peer_ && is_playing_) | |
| 1268 EstablishSurfaceTexturePeer(); | |
| 1269 } | |
| 1270 | |
| 1254 void WebMediaPlayerAndroid::TryCreateStreamTextureProxyIfNeeded() { | 1271 void WebMediaPlayerAndroid::TryCreateStreamTextureProxyIfNeeded() { |
| 1255 DCHECK(main_thread_checker_.CalledOnValidThread()); | 1272 DCHECK(main_thread_checker_.CalledOnValidThread()); |
| 1256 // Already created. | 1273 // Already created. |
| 1257 if (stream_texture_proxy_) | 1274 if (stream_texture_proxy_) |
| 1258 return; | 1275 return; |
| 1259 | 1276 |
| 1260 // No factory to create proxy. | 1277 // No factory to create proxy. |
| 1261 if (!stream_texture_factory_) | 1278 if (!stream_texture_factory_) |
| 1262 return; | 1279 return; |
| 1263 | 1280 |
| 1281 // Not needed for hole punching. | |
| 1282 if (!needs_establish_peer_) | |
| 1283 return; | |
| 1284 | |
| 1264 stream_texture_proxy_.reset(stream_texture_factory_->CreateProxy()); | 1285 stream_texture_proxy_.reset(stream_texture_factory_->CreateProxy()); |
| 1265 if (needs_establish_peer_ && stream_texture_proxy_) { | 1286 if (stream_texture_proxy_) { |
| 1266 DoCreateStreamTexture(); | 1287 DoCreateStreamTexture(); |
|
boliu
2014/09/15 20:41:53
I accidentally dropped these two lines, although a
| |
| 1267 ReallocateVideoFrame(); | 1288 ReallocateVideoFrame(); |
| 1289 if (video_frame_provider_client_) { | |
| 1290 stream_texture_proxy_->BindToLoop( | |
| 1291 stream_id_, video_frame_provider_client_, compositor_loop_); | |
| 1292 } | |
| 1268 } | 1293 } |
| 1269 | |
| 1270 if (stream_texture_proxy_ && video_frame_provider_client_) | |
| 1271 stream_texture_proxy_->SetClient(video_frame_provider_client_); | |
| 1272 } | 1294 } |
| 1273 | 1295 |
| 1274 void WebMediaPlayerAndroid::EstablishSurfaceTexturePeer() { | 1296 void WebMediaPlayerAndroid::EstablishSurfaceTexturePeer() { |
| 1275 DCHECK(main_thread_checker_.CalledOnValidThread()); | 1297 DCHECK(main_thread_checker_.CalledOnValidThread()); |
| 1276 if (!stream_texture_proxy_) | 1298 if (!stream_texture_proxy_) |
| 1277 return; | 1299 return; |
| 1278 | 1300 |
| 1279 if (stream_texture_factory_.get() && stream_id_) | 1301 if (stream_texture_factory_.get() && stream_id_) |
| 1280 stream_texture_factory_->EstablishPeer(stream_id_, player_id_); | 1302 stream_texture_factory_->EstablishPeer(stream_id_, player_id_); |
| 1281 | 1303 |
| (...skipping 509 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1791 | 1813 |
| 1792 bool WebMediaPlayerAndroid::IsHLSStream() const { | 1814 bool WebMediaPlayerAndroid::IsHLSStream() const { |
| 1793 std::string mime; | 1815 std::string mime; |
| 1794 GURL url = redirected_url_.is_empty() ? url_ : redirected_url_; | 1816 GURL url = redirected_url_.is_empty() ? url_ : redirected_url_; |
| 1795 if (!net::GetMimeTypeFromFile(base::FilePath(url.path()), &mime)) | 1817 if (!net::GetMimeTypeFromFile(base::FilePath(url.path()), &mime)) |
| 1796 return false; | 1818 return false; |
| 1797 return !mime.compare("application/x-mpegurl"); | 1819 return !mime.compare("application/x-mpegurl"); |
| 1798 } | 1820 } |
| 1799 | 1821 |
| 1800 } // namespace content | 1822 } // namespace content |
| OLD | NEW |