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