Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(318)

Side by Side Diff: content/renderer/media/android/webmediaplayer_android.cc

Issue 532993002: work-in-progress patch to fix context lost black video (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: block on compositor Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « content/renderer/media/android/webmediaplayer_android.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
147 is_remote_(false), 147 is_remote_(false),
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 weak_factory_(this) { 152 weak_factory_(this) {
153 DCHECK(player_manager_); 153 DCHECK(player_manager_);
154 DCHECK(cdm_manager_); 154 DCHECK(cdm_manager_);
155 155
156 DCHECK(main_thread_checker_.CalledOnValidThread()); 156 DCHECK(main_thread_checker_.CalledOnValidThread());
157 stream_texture_factory_->AddObserver(this);
157 158
158 player_id_ = player_manager_->RegisterMediaPlayer(this); 159 player_id_ = player_manager_->RegisterMediaPlayer(this);
159 160
160 #if defined(VIDEO_HOLE) 161 #if defined(VIDEO_HOLE)
161 force_use_overlay_embedded_video_ = CommandLine::ForCurrentProcess()-> 162 force_use_overlay_embedded_video_ = CommandLine::ForCurrentProcess()->
162 HasSwitch(switches::kForceUseOverlayEmbeddedVideo); 163 HasSwitch(switches::kForceUseOverlayEmbeddedVideo);
163 if (force_use_overlay_embedded_video_ || 164 if (force_use_overlay_embedded_video_ ||
164 player_manager_->ShouldUseVideoOverlayForEmbeddedEncryptedVideo()) { 165 player_manager_->ShouldUseVideoOverlayForEmbeddedEncryptedVideo()) {
165 // Defer stream texture creation until we are sure it's necessary. 166 // Defer stream texture creation until we are sure it's necessary.
166 needs_establish_peer_ = false; 167 needs_establish_peer_ = false;
(...skipping 21 matching lines...) Expand all
188 stream_id_ = 0; 189 stream_id_ = 0;
189 } 190 }
190 191
191 { 192 {
192 base::AutoLock auto_lock(current_frame_lock_); 193 base::AutoLock auto_lock(current_frame_lock_);
193 current_frame_ = NULL; 194 current_frame_ = NULL;
194 } 195 }
195 196
196 if (player_type_ == MEDIA_PLAYER_TYPE_MEDIA_SOURCE && delegate_) 197 if (player_type_ == MEDIA_PLAYER_TYPE_MEDIA_SOURCE && delegate_)
197 delegate_->PlayerGone(this); 198 delegate_->PlayerGone(this);
199
200 stream_texture_factory_->RemoveObserver(this);
198 } 201 }
199 202
200 void WebMediaPlayerAndroid::load(LoadType load_type, 203 void WebMediaPlayerAndroid::load(LoadType load_type,
201 const blink::WebURL& url, 204 const blink::WebURL& url,
202 CORSMode cors_mode) { 205 CORSMode cors_mode) {
203 DCHECK(main_thread_checker_.CalledOnValidThread()); 206 DCHECK(main_thread_checker_.CalledOnValidThread());
204 media::ReportMediaSchemeUma(GURL(url)); 207 media::ReportMediaSchemeUma(GURL(url));
205 208
206 switch (load_type) { 209 switch (load_type) {
207 case LoadTypeURL: 210 case LoadTypeURL:
(...skipping 980 matching lines...) Expand 10 before | Expand all | Expand 10 after
1188 base::TimeDelta(), 1191 base::TimeDelta(),
1189 VideoFrame::ReadPixelsCB()); 1192 VideoFrame::ReadPixelsCB());
1190 SetCurrentFrameInternal(new_frame); 1193 SetCurrentFrameInternal(new_frame);
1191 } 1194 }
1192 } 1195 }
1193 1196
1194 void WebMediaPlayerAndroid::SetVideoFrameProviderClient( 1197 void WebMediaPlayerAndroid::SetVideoFrameProviderClient(
1195 cc::VideoFrameProvider::Client* client) { 1198 cc::VideoFrameProvider::Client* client) {
1196 // This is called from both the main renderer thread and the compositor 1199 // This is called from both the main renderer thread and the compositor
1197 // thread (when the main thread is blocked). 1200 // thread (when the main thread is blocked).
1198 if (video_frame_provider_client_) 1201 if (video_frame_provider_client_ && video_frame_provider_client_ != client)
1199 video_frame_provider_client_->StopUsingProvider(); 1202 video_frame_provider_client_->StopUsingProvider();
1200 video_frame_provider_client_ = client; 1203 video_frame_provider_client_ = client;
1201 1204
1202 // Set the callback target when a frame is produced. 1205 // Set the callback target when a frame is produced.
1203 if (stream_texture_proxy_) { 1206 if (stream_texture_proxy_) {
1204 stream_texture_proxy_->SetClient(client); 1207 stream_texture_proxy_->SetClient(client);
1205 // If client exists, the compositor thread calls it. At that time, 1208 // If client exists, the compositor thread calls it. At that time,
no sievers 2014/09/11 22:52:33 This is really just based on probably what the cur
boliu 2014/09/11 22:56:17 Yep. It's a requirement that main thread is blocke
boliu 2014/09/11 22:57:35 Ehh, update in a follow up since that's in cc. Or
no sievers 2014/09/11 23:06:24 I was more worried about SetVideoFrameProviderClie
1206 // stream_id_, needs_external_surface_, is_remote_ can be accessed because 1209 // stream_id_, needs_external_surface_, is_remote_ can be accessed because
1207 // the main thread is blocked. 1210 // the main thread is blocked.
1208 if (client && !stream_texture_proxy_initialized_ && stream_id_ && 1211 if (client && !stream_texture_proxy_initialized_ && stream_id_ &&
1209 !needs_external_surface_ && !is_remote_) { 1212 !needs_external_surface_ && !is_remote_) {
1210 stream_texture_proxy_->BindToCurrentThread(stream_id_); 1213 stream_texture_proxy_->BindToCurrentThread(stream_id_);
1211 stream_texture_proxy_initialized_ = true; 1214 stream_texture_proxy_initialized_ = true;
1212 } 1215 }
1213 } 1216 }
1214 } 1217 }
1215 1218
(...skipping 11 matching lines...) Expand all
1227 video_frame = current_frame_; 1230 video_frame = current_frame_;
1228 } 1231 }
1229 1232
1230 return video_frame; 1233 return video_frame;
1231 } 1234 }
1232 1235
1233 void WebMediaPlayerAndroid::PutCurrentFrame( 1236 void WebMediaPlayerAndroid::PutCurrentFrame(
1234 const scoped_refptr<media::VideoFrame>& frame) { 1237 const scoped_refptr<media::VideoFrame>& frame) {
1235 } 1238 }
1236 1239
1240 void WebMediaPlayerAndroid::ResetStreamTextureProxy() {
1241 DCHECK(main_thread_checker_.CalledOnValidThread());
1242
1243 if (stream_id_) {
1244 GLES2Interface* gl = stream_texture_factory_->ContextGL();
1245 gl->DeleteTextures(1, &texture_id_);
1246 texture_id_ = 0;
1247 texture_mailbox_ = gpu::Mailbox();
1248 stream_id_ = 0;
1249 }
1250 stream_texture_proxy_.reset();
1251 needs_establish_peer_ =
qinmin 2014/09/11 23:26:41 need to check fullscreen status
boliu 2014/09/12 16:38:25 Done using player_manager_->IsInFullscreen(frame_)
1252 !needs_external_surface_ && !is_remote_ && (hasVideo() || IsHLSStream());
boliu 2014/09/11 17:08:33 Min, please double check this line. Unfortunately
1253 stream_texture_proxy_initialized_ = false;
1254
1255 TryCreateStreamTextureProxyIfNeeded();
1256 EstablishSurfaceTexturePeer();
qinmin 2014/09/11 23:26:41 shouldn't this be: if (needs_establish_peer_ && i
boliu 2014/09/12 16:38:25 Yes done. If only the refactor wasn't reverted...
1257 }
1258
1237 void WebMediaPlayerAndroid::TryCreateStreamTextureProxyIfNeeded() { 1259 void WebMediaPlayerAndroid::TryCreateStreamTextureProxyIfNeeded() {
1238 DCHECK(main_thread_checker_.CalledOnValidThread()); 1260 DCHECK(main_thread_checker_.CalledOnValidThread());
1239 // Already created. 1261 // Already created.
1240 if (stream_texture_proxy_) 1262 if (stream_texture_proxy_)
1241 return; 1263 return;
1242 1264
1243 // No factory to create proxy. 1265 // No factory to create proxy.
1244 if (!stream_texture_factory_) 1266 if (!stream_texture_factory_)
1245 return; 1267 return;
1246 1268
1247 stream_texture_proxy_.reset(stream_texture_factory_->CreateProxy()); 1269 stream_texture_proxy_.reset(stream_texture_factory_->CreateProxy());
1248 if (needs_establish_peer_ && stream_texture_proxy_) { 1270 if (needs_establish_peer_ && stream_texture_proxy_) {
1249 DoCreateStreamTexture(); 1271 DoCreateStreamTexture();
1250 ReallocateVideoFrame(); 1272 ReallocateVideoFrame();
1273
1274 base::WaitableEvent completion(true, false);
1275 RenderThreadImpl::current()->compositor_message_loop_proxy()->PostTask(
1276 FROM_HERE,
1277 base::Bind(
1278 &WebMediaPlayerAndroid::BindStreamTextureProxyOnCompositorThread,
1279 base::Unretained(this),
no sievers 2014/09/11 22:28:34 Do we need to do this or can we just invalidate an
boliu 2014/09/11 22:30:56 That's fine in m37. But that code doesn't exist an
1280 &completion));
1281 completion.Wait();
qinmin 2014/09/11 23:26:41 blocking the main thread? I don't feel like this i
boliu 2014/09/12 16:38:25 Blink thread blocks on compositor thread all the t
qinmin 2014/09/12 17:01:58 SetVideoFrameProviderClient uses a lock inside, so
boliu 2014/09/12 17:08:07 By render thread, you mean blink main thread, righ
boliu 2014/09/12 17:10:14 Also I'm floating the idea that WMPA should do mor
qinmin 2014/09/12 17:19:48 But why cannot we just use a callback and don't bl
boliu 2014/09/12 17:26:22 Calling SetVideoFrameProviderClient without the ma
qinmin 2014/09/12 17:31:09 I don't see that's a valid reason to block main th
boliu 2014/09/12 17:36:34 That is way too complex, it's a super invasive cha
1251 } 1282 }
1283 }
1252 1284
1253 if (stream_texture_proxy_ && video_frame_provider_client_) 1285 void WebMediaPlayerAndroid::BindStreamTextureProxyOnCompositorThread(
1254 stream_texture_proxy_->SetClient(video_frame_provider_client_); 1286 base::WaitableEvent* completion) {
1287 if (video_frame_provider_client_) {
1288 SetVideoFrameProviderClient(video_frame_provider_client_);
qinmin 2014/09/11 23:26:41 nit: no {}
boliu 2014/09/12 16:38:25 Done.
1289 }
1290 completion->Signal();
1255 } 1291 }
1256 1292
1257 void WebMediaPlayerAndroid::EstablishSurfaceTexturePeer() { 1293 void WebMediaPlayerAndroid::EstablishSurfaceTexturePeer() {
1258 DCHECK(main_thread_checker_.CalledOnValidThread()); 1294 DCHECK(main_thread_checker_.CalledOnValidThread());
1259 if (!stream_texture_proxy_) 1295 if (!stream_texture_proxy_)
1260 return; 1296 return;
1261 1297
1262 if (stream_texture_factory_.get() && stream_id_) 1298 if (stream_texture_factory_.get() && stream_id_)
1263 stream_texture_factory_->EstablishPeer(stream_id_, player_id_); 1299 stream_texture_factory_->EstablishPeer(stream_id_, player_id_);
1264 1300
(...skipping 504 matching lines...) Expand 10 before | Expand all | Expand 10 after
1769 1805
1770 bool WebMediaPlayerAndroid::IsHLSStream() const { 1806 bool WebMediaPlayerAndroid::IsHLSStream() const {
1771 std::string mime; 1807 std::string mime;
1772 GURL url = redirected_url_.is_empty() ? url_ : redirected_url_; 1808 GURL url = redirected_url_.is_empty() ? url_ : redirected_url_;
1773 if (!net::GetMimeTypeFromFile(base::FilePath(url.path()), &mime)) 1809 if (!net::GetMimeTypeFromFile(base::FilePath(url.path()), &mime))
1774 return false; 1810 return false;
1775 return !mime.compare("application/x-mpegurl"); 1811 return !mime.compare("application/x-mpegurl");
1776 } 1812 }
1777 1813
1778 } // namespace content 1814 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/media/android/webmediaplayer_android.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698