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 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
115 RendererMediaPlayerManager* player_manager, | 115 RendererMediaPlayerManager* player_manager, |
116 RendererCdmManager* cdm_manager, | 116 RendererCdmManager* cdm_manager, |
117 scoped_refptr<StreamTextureFactory> factory, | 117 scoped_refptr<StreamTextureFactory> factory, |
118 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner, | 118 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner, |
119 media::MediaLog* media_log) | 119 media::MediaLog* media_log) |
120 : RenderFrameObserver(RenderFrame::FromWebFrame(frame)), | 120 : RenderFrameObserver(RenderFrame::FromWebFrame(frame)), |
121 frame_(frame), | 121 frame_(frame), |
122 client_(client), | 122 client_(client), |
123 delegate_(delegate), | 123 delegate_(delegate), |
124 buffered_(static_cast<size_t>(1)), | 124 buffered_(static_cast<size_t>(1)), |
125 stream_texture_proxy_initialized_(false), | |
125 media_task_runner_(task_runner), | 126 media_task_runner_(task_runner), |
126 ignore_metadata_duration_change_(false), | 127 ignore_metadata_duration_change_(false), |
127 pending_seek_(false), | 128 pending_seek_(false), |
128 seeking_(false), | 129 seeking_(false), |
129 did_loading_progress_(false), | 130 did_loading_progress_(false), |
130 player_manager_(player_manager), | 131 player_manager_(player_manager), |
131 cdm_manager_(cdm_manager), | 132 cdm_manager_(cdm_manager), |
132 network_state_(WebMediaPlayer::NetworkStateEmpty), | 133 network_state_(WebMediaPlayer::NetworkStateEmpty), |
133 ready_state_(WebMediaPlayer::ReadyStateHaveNothing), | 134 ready_state_(WebMediaPlayer::ReadyStateHaveNothing), |
134 texture_id_(0), | 135 texture_id_(0), |
135 stream_id_(0), | 136 stream_id_(0), |
136 is_playing_(false), | 137 is_playing_(false), |
137 needs_establish_peer_(true), | 138 needs_establish_peer_(true), |
138 stream_texture_proxy_initialized_(false), | |
139 has_size_info_(false), | 139 has_size_info_(false), |
140 stream_texture_factory_(factory), | 140 stream_texture_factory_(factory), |
141 needs_external_surface_(false), | 141 needs_external_surface_(false), |
142 video_frame_provider_client_(NULL), | 142 video_frame_provider_client_(NULL), |
143 pending_playback_(false), | 143 pending_playback_(false), |
144 player_type_(MEDIA_PLAYER_TYPE_URL), | 144 player_type_(MEDIA_PLAYER_TYPE_URL), |
145 current_time_(0), | 145 current_time_(0), |
146 is_remote_(false), | 146 is_remote_(false), |
147 media_log_(media_log), | 147 media_log_(media_log), |
148 web_cdm_(NULL), | 148 web_cdm_(NULL), |
149 allow_stored_credentials_(false), | 149 allow_stored_credentials_(false), |
150 is_local_resource_(false), | 150 is_local_resource_(false), |
151 weak_factory_(this) { | 151 weak_factory_(this) { |
152 DCHECK(player_manager_); | 152 DCHECK(player_manager_); |
153 DCHECK(cdm_manager_); | 153 DCHECK(cdm_manager_); |
154 | 154 |
155 DCHECK(main_thread_checker_.CalledOnValidThread()); | 155 DCHECK(main_thread_checker_.CalledOnValidThread()); |
156 stream_texture_factory_->AddObserver(this); | |
156 | 157 |
157 player_id_ = player_manager_->RegisterMediaPlayer(this); | 158 player_id_ = player_manager_->RegisterMediaPlayer(this); |
158 | 159 |
159 #if defined(VIDEO_HOLE) | 160 #if defined(VIDEO_HOLE) |
160 force_use_overlay_embedded_video_ = CommandLine::ForCurrentProcess()-> | 161 force_use_overlay_embedded_video_ = CommandLine::ForCurrentProcess()-> |
161 HasSwitch(switches::kForceUseOverlayEmbeddedVideo); | 162 HasSwitch(switches::kForceUseOverlayEmbeddedVideo); |
162 if (force_use_overlay_embedded_video_ || | 163 if (force_use_overlay_embedded_video_ || |
163 player_manager_->ShouldUseVideoOverlayForEmbeddedEncryptedVideo()) { | 164 player_manager_->ShouldUseVideoOverlayForEmbeddedEncryptedVideo()) { |
164 // Defer stream texture creation until we are sure it's necessary. | 165 // Defer stream texture creation until we are sure it's necessary. |
165 needs_establish_peer_ = false; | 166 needs_establish_peer_ = false; |
(...skipping 21 matching lines...) Expand all Loading... | |
187 stream_id_ = 0; | 188 stream_id_ = 0; |
188 } | 189 } |
189 | 190 |
190 { | 191 { |
191 base::AutoLock auto_lock(current_frame_lock_); | 192 base::AutoLock auto_lock(current_frame_lock_); |
192 current_frame_ = NULL; | 193 current_frame_ = NULL; |
193 } | 194 } |
194 | 195 |
195 if (player_type_ == MEDIA_PLAYER_TYPE_MEDIA_SOURCE && delegate_) | 196 if (player_type_ == MEDIA_PLAYER_TYPE_MEDIA_SOURCE && delegate_) |
196 delegate_->PlayerGone(this); | 197 delegate_->PlayerGone(this); |
198 | |
199 stream_texture_factory_->RemoveObserver(this); | |
197 } | 200 } |
198 | 201 |
199 void WebMediaPlayerAndroid::load(LoadType load_type, | 202 void WebMediaPlayerAndroid::load(LoadType load_type, |
200 const blink::WebURL& url, | 203 const blink::WebURL& url, |
201 CORSMode cors_mode) { | 204 CORSMode cors_mode) { |
202 DCHECK(main_thread_checker_.CalledOnValidThread()); | 205 DCHECK(main_thread_checker_.CalledOnValidThread()); |
203 media::ReportMediaSchemeUma(GURL(url)); | 206 media::ReportMediaSchemeUma(GURL(url)); |
204 | 207 |
205 switch (load_type) { | 208 switch (load_type) { |
206 case LoadTypeURL: | 209 case LoadTypeURL: |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
315 !player_manager_->IsInFullscreen(frame_)) { | 318 !player_manager_->IsInFullscreen(frame_)) { |
316 EstablishSurfaceTexturePeer(); | 319 EstablishSurfaceTexturePeer(); |
317 } | 320 } |
318 | 321 |
319 if (paused()) | 322 if (paused()) |
320 player_manager_->Start(player_id_); | 323 player_manager_->Start(player_id_); |
321 UpdatePlayingState(true); | 324 UpdatePlayingState(true); |
322 UpdateNetworkState(WebMediaPlayer::NetworkStateLoading); | 325 UpdateNetworkState(WebMediaPlayer::NetworkStateLoading); |
323 } | 326 } |
324 | 327 |
328 void WebMediaPlayerAndroid::ResetStreamTextureProxy() { | |
329 DCHECK(main_thread_checker_.CalledOnValidThread()); | |
330 | |
331 if (stream_id_) { | |
332 GLES2Interface* gl = stream_texture_factory_->ContextGL(); | |
333 gl->DeleteTextures(1, &texture_id_); | |
334 texture_id_ = 0; | |
335 texture_mailbox_ = gpu::Mailbox(); | |
336 stream_id_ = 0; | |
337 } | |
338 stream_texture_proxy_.reset(); | |
339 SetNeedsEstablishPeer(true); | |
340 | |
341 TryCreateStreamTextureProxyIfNeeded(); | |
342 if (hasVideo() && needs_establish_peer_ && | |
343 !player_manager_->IsInFullscreen(frame_)) { | |
344 EstablishSurfaceTexturePeer(); | |
345 } | |
346 | |
347 { | |
348 base::AutoLock auto_lock(current_frame_lock_); | |
349 if (!stream_texture_proxy_initialized_) | |
350 return; | |
351 | |
352 stream_texture_proxy_initialized_ = false; | |
353 DCHECK(client_bound_loop_.get()); | |
354 client_bound_loop_->PostTask( | |
355 FROM_HERE, | |
356 base::Bind(&WebMediaPlayerAndroid::UpdateFrameOnClientThread, | |
357 weak_factory_.GetWeakPtr())); | |
358 } | |
359 } | |
360 | |
361 void WebMediaPlayerAndroid::UpdateFrameOnClientThread() { | |
362 if (video_frame_provider_client_) | |
363 video_frame_provider_client_->DidReceiveFrame(); | |
364 } | |
365 | |
325 void WebMediaPlayerAndroid::pause() { | 366 void WebMediaPlayerAndroid::pause() { |
326 DCHECK(main_thread_checker_.CalledOnValidThread()); | 367 DCHECK(main_thread_checker_.CalledOnValidThread()); |
327 Pause(true); | 368 Pause(true); |
328 } | 369 } |
329 | 370 |
330 void WebMediaPlayerAndroid::seek(double seconds) { | 371 void WebMediaPlayerAndroid::seek(double seconds) { |
331 DCHECK(main_thread_checker_.CalledOnValidThread()); | 372 DCHECK(main_thread_checker_.CalledOnValidThread()); |
332 DVLOG(1) << __FUNCTION__ << "(" << seconds << ")"; | 373 DVLOG(1) << __FUNCTION__ << "(" << seconds << ")"; |
333 | 374 |
334 base::TimeDelta new_seek_time = media::ConvertSecondsToTimestamp(seconds); | 375 base::TimeDelta new_seek_time = media::ConvertSecondsToTimestamp(seconds); |
(...skipping 861 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1196 | 1237 |
1197 // Set the callback target when a frame is produced. | 1238 // Set the callback target when a frame is produced. |
1198 if (stream_texture_proxy_) { | 1239 if (stream_texture_proxy_) { |
1199 stream_texture_proxy_->SetClient(client); | 1240 stream_texture_proxy_->SetClient(client); |
1200 // If client exists, the compositor thread calls it. At that time, | 1241 // If client exists, the compositor thread calls it. At that time, |
1201 // stream_id_, needs_external_surface_, is_remote_ can be accessed because | 1242 // stream_id_, needs_external_surface_, is_remote_ can be accessed because |
1202 // the main thread is blocked. | 1243 // the main thread is blocked. |
1203 if (client && !stream_texture_proxy_initialized_ && stream_id_ && | 1244 if (client && !stream_texture_proxy_initialized_ && stream_id_ && |
1204 !needs_external_surface_ && !is_remote_) { | 1245 !needs_external_surface_ && !is_remote_) { |
1205 stream_texture_proxy_->BindToCurrentThread(stream_id_); | 1246 stream_texture_proxy_->BindToCurrentThread(stream_id_); |
1206 stream_texture_proxy_initialized_ = true; | 1247 stream_texture_proxy_initialized_ = true; |
boliu
2014/09/08 15:31:10
This is not thread safe yet..
| |
1207 } | 1248 } |
1208 } | 1249 } |
1209 } | 1250 } |
1210 | 1251 |
1211 void WebMediaPlayerAndroid::SetCurrentFrameInternal( | 1252 void WebMediaPlayerAndroid::SetCurrentFrameInternal( |
1212 scoped_refptr<media::VideoFrame>& video_frame) { | 1253 scoped_refptr<media::VideoFrame>& video_frame) { |
1213 DCHECK(main_thread_checker_.CalledOnValidThread()); | 1254 DCHECK(main_thread_checker_.CalledOnValidThread()); |
1214 base::AutoLock auto_lock(current_frame_lock_); | 1255 base::AutoLock auto_lock(current_frame_lock_); |
1215 current_frame_ = video_frame; | 1256 current_frame_ = video_frame; |
1216 } | 1257 } |
1217 | 1258 |
1218 scoped_refptr<media::VideoFrame> WebMediaPlayerAndroid::GetCurrentFrame() { | 1259 scoped_refptr<media::VideoFrame> WebMediaPlayerAndroid::GetCurrentFrame() { |
1219 scoped_refptr<VideoFrame> video_frame; | 1260 scoped_refptr<VideoFrame> video_frame; |
1261 bool proxy_initialized = true; | |
1220 { | 1262 { |
1221 base::AutoLock auto_lock(current_frame_lock_); | 1263 base::AutoLock auto_lock(current_frame_lock_); |
1222 video_frame = current_frame_; | 1264 video_frame = current_frame_; |
1265 proxy_initialized = stream_texture_proxy_initialized_; | |
1266 } | |
1267 | |
1268 if (!proxy_initialized) { | |
1269 SetVideoFrameProviderClient(video_frame_provider_client_); | |
boliu
2014/09/08 15:31:10
Back in m37 days, we used to call BindToThread her
| |
1270 base::AutoLock auto_lock(current_frame_lock_); | |
1271 stream_texture_proxy_initialized_ = true; | |
1223 } | 1272 } |
1224 | 1273 |
1225 return video_frame; | 1274 return video_frame; |
1226 } | 1275 } |
1227 | 1276 |
1228 void WebMediaPlayerAndroid::PutCurrentFrame( | 1277 void WebMediaPlayerAndroid::PutCurrentFrame( |
1229 const scoped_refptr<media::VideoFrame>& frame) { | 1278 const scoped_refptr<media::VideoFrame>& frame) { |
1230 } | 1279 } |
1231 | 1280 |
1232 void WebMediaPlayerAndroid::TryCreateStreamTextureProxyIfNeeded() { | 1281 void WebMediaPlayerAndroid::TryCreateStreamTextureProxyIfNeeded() { |
(...skipping 531 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1764 | 1813 |
1765 bool WebMediaPlayerAndroid::IsHLSStream() const { | 1814 bool WebMediaPlayerAndroid::IsHLSStream() const { |
1766 std::string mime; | 1815 std::string mime; |
1767 GURL url = redirected_url_.is_empty() ? url_ : redirected_url_; | 1816 GURL url = redirected_url_.is_empty() ? url_ : redirected_url_; |
1768 if (!net::GetMimeTypeFromFile(base::FilePath(url.path()), &mime)) | 1817 if (!net::GetMimeTypeFromFile(base::FilePath(url.path()), &mime)) |
1769 return false; | 1818 return false; |
1770 return !mime.compare("application/x-mpegurl"); | 1819 return !mime.compare("application/x-mpegurl"); |
1771 } | 1820 } |
1772 | 1821 |
1773 } // namespace content | 1822 } // namespace content |
OLD | NEW |