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 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
148 media_log_(media_log), | 148 media_log_(media_log), |
149 web_cdm_(NULL), | 149 web_cdm_(NULL), |
150 allow_stored_credentials_(false), | 150 allow_stored_credentials_(false), |
151 is_local_resource_(false), | 151 is_local_resource_(false), |
152 interpolator_(&default_tick_clock_), | 152 interpolator_(&default_tick_clock_), |
153 weak_factory_(this) { | 153 weak_factory_(this) { |
154 DCHECK(player_manager_); | 154 DCHECK(player_manager_); |
155 DCHECK(cdm_manager_); | 155 DCHECK(cdm_manager_); |
156 | 156 |
157 DCHECK(main_thread_checker_.CalledOnValidThread()); | 157 DCHECK(main_thread_checker_.CalledOnValidThread()); |
158 stream_texture_factory_->AddObserver(this); | |
158 | 159 |
159 player_id_ = player_manager_->RegisterMediaPlayer(this); | 160 player_id_ = player_manager_->RegisterMediaPlayer(this); |
160 | 161 |
161 #if defined(VIDEO_HOLE) | 162 #if defined(VIDEO_HOLE) |
162 force_use_overlay_embedded_video_ = CommandLine::ForCurrentProcess()-> | 163 force_use_overlay_embedded_video_ = CommandLine::ForCurrentProcess()-> |
163 HasSwitch(switches::kForceUseOverlayEmbeddedVideo); | 164 HasSwitch(switches::kForceUseOverlayEmbeddedVideo); |
164 if (force_use_overlay_embedded_video_ || | 165 if (force_use_overlay_embedded_video_ || |
165 player_manager_->ShouldUseVideoOverlayForEmbeddedEncryptedVideo()) { | 166 player_manager_->ShouldUseVideoOverlayForEmbeddedEncryptedVideo()) { |
166 // Defer stream texture creation until we are sure it's necessary. | 167 // Defer stream texture creation until we are sure it's necessary. |
167 needs_establish_peer_ = false; | 168 needs_establish_peer_ = false; |
(...skipping 22 matching lines...) Expand all Loading... | |
190 stream_id_ = 0; | 191 stream_id_ = 0; |
191 } | 192 } |
192 | 193 |
193 { | 194 { |
194 base::AutoLock auto_lock(current_frame_lock_); | 195 base::AutoLock auto_lock(current_frame_lock_); |
195 current_frame_ = NULL; | 196 current_frame_ = NULL; |
196 } | 197 } |
197 | 198 |
198 if (player_type_ == MEDIA_PLAYER_TYPE_MEDIA_SOURCE && delegate_) | 199 if (player_type_ == MEDIA_PLAYER_TYPE_MEDIA_SOURCE && delegate_) |
199 delegate_->PlayerGone(this); | 200 delegate_->PlayerGone(this); |
201 | |
202 stream_texture_factory_->RemoveObserver(this); | |
200 } | 203 } |
201 | 204 |
202 void WebMediaPlayerAndroid::load(LoadType load_type, | 205 void WebMediaPlayerAndroid::load(LoadType load_type, |
203 const blink::WebURL& url, | 206 const blink::WebURL& url, |
204 CORSMode cors_mode) { | 207 CORSMode cors_mode) { |
205 DCHECK(main_thread_checker_.CalledOnValidThread()); | 208 DCHECK(main_thread_checker_.CalledOnValidThread()); |
206 media::ReportMediaSchemeUma(GURL(url)); | 209 media::ReportMediaSchemeUma(GURL(url)); |
207 | 210 |
208 switch (load_type) { | 211 switch (load_type) { |
209 case LoadTypeURL: | 212 case LoadTypeURL: |
(...skipping 995 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1205 base::TimeDelta(), | 1208 base::TimeDelta(), |
1206 VideoFrame::ReadPixelsCB()); | 1209 VideoFrame::ReadPixelsCB()); |
1207 SetCurrentFrameInternal(new_frame); | 1210 SetCurrentFrameInternal(new_frame); |
1208 } | 1211 } |
1209 } | 1212 } |
1210 | 1213 |
1211 void WebMediaPlayerAndroid::SetVideoFrameProviderClient( | 1214 void WebMediaPlayerAndroid::SetVideoFrameProviderClient( |
1212 cc::VideoFrameProvider::Client* client) { | 1215 cc::VideoFrameProvider::Client* client) { |
1213 // This is called from both the main renderer thread and the compositor | 1216 // This is called from both the main renderer thread and the compositor |
1214 // thread (when the main thread is blocked). | 1217 // thread (when the main thread is blocked). |
1215 if (video_frame_provider_client_) | 1218 if (video_frame_provider_client_ && video_frame_provider_client_ != client) |
1216 video_frame_provider_client_->StopUsingProvider(); | 1219 video_frame_provider_client_->StopUsingProvider(); |
1217 video_frame_provider_client_ = client; | 1220 video_frame_provider_client_ = client; |
1218 | 1221 |
1219 // Set the callback target when a frame is produced. | 1222 // Set the callback target when a frame is produced. |
1220 if (stream_texture_proxy_) { | 1223 if (stream_texture_proxy_ && client) { |
1221 stream_texture_proxy_->SetClient(client); | 1224 stream_texture_proxy_->BindToLoop( |
1222 // If client exists, the compositor thread calls it. At that time, | 1225 stream_id_, client, base::MessageLoopProxy::current()); |
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 } | 1226 } |
1231 } | 1227 } |
1232 | 1228 |
1233 void WebMediaPlayerAndroid::SetCurrentFrameInternal( | 1229 void WebMediaPlayerAndroid::SetCurrentFrameInternal( |
1234 scoped_refptr<media::VideoFrame>& video_frame) { | 1230 scoped_refptr<media::VideoFrame>& video_frame) { |
1235 DCHECK(main_thread_checker_.CalledOnValidThread()); | 1231 DCHECK(main_thread_checker_.CalledOnValidThread()); |
1236 base::AutoLock auto_lock(current_frame_lock_); | 1232 base::AutoLock auto_lock(current_frame_lock_); |
1237 current_frame_ = video_frame; | 1233 current_frame_ = video_frame; |
1238 } | 1234 } |
1239 | 1235 |
1240 scoped_refptr<media::VideoFrame> WebMediaPlayerAndroid::GetCurrentFrame() { | 1236 scoped_refptr<media::VideoFrame> WebMediaPlayerAndroid::GetCurrentFrame() { |
1241 scoped_refptr<VideoFrame> video_frame; | 1237 scoped_refptr<VideoFrame> video_frame; |
1242 { | 1238 { |
1243 base::AutoLock auto_lock(current_frame_lock_); | 1239 base::AutoLock auto_lock(current_frame_lock_); |
1244 video_frame = current_frame_; | 1240 video_frame = current_frame_; |
1245 } | 1241 } |
1246 | 1242 |
1247 return video_frame; | 1243 return video_frame; |
1248 } | 1244 } |
1249 | 1245 |
1250 void WebMediaPlayerAndroid::PutCurrentFrame( | 1246 void WebMediaPlayerAndroid::PutCurrentFrame( |
1251 const scoped_refptr<media::VideoFrame>& frame) { | 1247 const scoped_refptr<media::VideoFrame>& frame) { |
1252 } | 1248 } |
1253 | 1249 |
1250 void WebMediaPlayerAndroid::ResetStreamTextureProxy() { | |
1251 DCHECK(main_thread_checker_.CalledOnValidThread()); | |
1252 | |
1253 if (stream_id_) { | |
1254 GLES2Interface* gl = stream_texture_factory_->ContextGL(); | |
1255 gl->DeleteTextures(1, &texture_id_); | |
1256 texture_id_ = 0; | |
1257 texture_mailbox_ = gpu::Mailbox(); | |
1258 stream_id_ = 0; | |
1259 } | |
1260 stream_texture_proxy_.reset(); | |
1261 needs_establish_peer_ = !needs_external_surface_ && !is_remote_ && | |
1262 !player_manager_->IsInFullscreen(frame_) && | |
1263 (hasVideo() || IsHLSStream()); | |
1264 stream_texture_proxy_initialized_ = false; | |
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 |
1264 stream_texture_proxy_.reset(stream_texture_factory_->CreateProxy()); | 1281 stream_texture_proxy_.reset(stream_texture_factory_->CreateProxy()); |
qinmin
2014/09/15 17:16:26
Please do the following before this to fix the VID
boliu
2014/09/15 17:54:07
Done.
| |
1265 if (needs_establish_peer_ && stream_texture_proxy_) { | 1282 if (needs_establish_peer_ && stream_texture_proxy_ && |
1266 DoCreateStreamTexture(); | 1283 video_frame_provider_client_) { |
1267 ReallocateVideoFrame(); | 1284 stream_texture_proxy_->BindToLoop( |
1285 stream_id_, | |
1286 video_frame_provider_client_, | |
1287 RenderThreadImpl::current()->compositor_message_loop_proxy()); | |
1268 } | 1288 } |
1269 | |
1270 if (stream_texture_proxy_ && video_frame_provider_client_) | |
1271 stream_texture_proxy_->SetClient(video_frame_provider_client_); | |
1272 } | 1289 } |
1273 | 1290 |
1274 void WebMediaPlayerAndroid::EstablishSurfaceTexturePeer() { | 1291 void WebMediaPlayerAndroid::EstablishSurfaceTexturePeer() { |
1275 DCHECK(main_thread_checker_.CalledOnValidThread()); | 1292 DCHECK(main_thread_checker_.CalledOnValidThread()); |
1276 if (!stream_texture_proxy_) | 1293 if (!stream_texture_proxy_) |
1277 return; | 1294 return; |
1278 | 1295 |
1279 if (stream_texture_factory_.get() && stream_id_) | 1296 if (stream_texture_factory_.get() && stream_id_) |
1280 stream_texture_factory_->EstablishPeer(stream_id_, player_id_); | 1297 stream_texture_factory_->EstablishPeer(stream_id_, player_id_); |
1281 | 1298 |
(...skipping 509 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1791 | 1808 |
1792 bool WebMediaPlayerAndroid::IsHLSStream() const { | 1809 bool WebMediaPlayerAndroid::IsHLSStream() const { |
1793 std::string mime; | 1810 std::string mime; |
1794 GURL url = redirected_url_.is_empty() ? url_ : redirected_url_; | 1811 GURL url = redirected_url_.is_empty() ? url_ : redirected_url_; |
1795 if (!net::GetMimeTypeFromFile(base::FilePath(url.path()), &mime)) | 1812 if (!net::GetMimeTypeFromFile(base::FilePath(url.path()), &mime)) |
1796 return false; | 1813 return false; |
1797 return !mime.compare("application/x-mpegurl"); | 1814 return !mime.compare("application/x-mpegurl"); |
1798 } | 1815 } |
1799 | 1816 |
1800 } // namespace content | 1817 } // namespace content |
OLD | NEW |