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

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: review 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,
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_ &&
(...skipping 18 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_ = !needs_external_surface_ && !is_remote_ &&
1252 !player_manager_->IsInFullscreen(frame_) &&
1253 (hasVideo() || IsHLSStream());
1254 stream_texture_proxy_initialized_ = false;
1255
1256 TryCreateStreamTextureProxyIfNeeded();
1257 if (needs_establish_peer_ && is_playing_)
1258 EstablishSurfaceTexturePeer();
1259 }
1260
1237 void WebMediaPlayerAndroid::TryCreateStreamTextureProxyIfNeeded() { 1261 void WebMediaPlayerAndroid::TryCreateStreamTextureProxyIfNeeded() {
1238 DCHECK(main_thread_checker_.CalledOnValidThread()); 1262 DCHECK(main_thread_checker_.CalledOnValidThread());
1239 // Already created. 1263 // Already created.
1240 if (stream_texture_proxy_) 1264 if (stream_texture_proxy_)
1241 return; 1265 return;
1242 1266
1243 // No factory to create proxy. 1267 // No factory to create proxy.
1244 if (!stream_texture_factory_) 1268 if (!stream_texture_factory_)
1245 return; 1269 return;
1246 1270
1247 stream_texture_proxy_.reset(stream_texture_factory_->CreateProxy()); 1271 stream_texture_proxy_.reset(stream_texture_factory_->CreateProxy());
1248 if (needs_establish_peer_ && stream_texture_proxy_) { 1272 if (needs_establish_peer_ && stream_texture_proxy_) {
1249 DoCreateStreamTexture(); 1273 DoCreateStreamTexture();
1250 ReallocateVideoFrame(); 1274 ReallocateVideoFrame();
1275
1276 base::WaitableEvent completion(true, false);
boliu 2014/09/12 20:22:47 what if I add a "if (video_frame_provider_client_)
1277 RenderThreadImpl::current()->compositor_message_loop_proxy()->PostTask(
1278 FROM_HERE,
1279 base::Bind(
1280 &WebMediaPlayerAndroid::BindStreamTextureProxyOnCompositorThread,
1281 base::Unretained(this),
1282 &completion));
1283 completion.Wait();
1251 } 1284 }
1285 }
1252 1286
1253 if (stream_texture_proxy_ && video_frame_provider_client_) 1287 void WebMediaPlayerAndroid::BindStreamTextureProxyOnCompositorThread(
1254 stream_texture_proxy_->SetClient(video_frame_provider_client_); 1288 base::WaitableEvent* completion) {
1289 if (video_frame_provider_client_)
1290 SetVideoFrameProviderClient(video_frame_provider_client_);
1291 completion->Signal();
1255 } 1292 }
1256 1293
1257 void WebMediaPlayerAndroid::EstablishSurfaceTexturePeer() { 1294 void WebMediaPlayerAndroid::EstablishSurfaceTexturePeer() {
1258 DCHECK(main_thread_checker_.CalledOnValidThread()); 1295 DCHECK(main_thread_checker_.CalledOnValidThread());
1259 if (!stream_texture_proxy_) 1296 if (!stream_texture_proxy_)
1260 return; 1297 return;
1261 1298
1262 if (stream_texture_factory_.get() && stream_id_) 1299 if (stream_texture_factory_.get() && stream_id_)
1263 stream_texture_factory_->EstablishPeer(stream_id_, player_id_); 1300 stream_texture_factory_->EstablishPeer(stream_id_, player_id_);
1264 1301
(...skipping 505 matching lines...) Expand 10 before | Expand all | Expand 10 after
1770 1807
1771 bool WebMediaPlayerAndroid::IsHLSStream() const { 1808 bool WebMediaPlayerAndroid::IsHLSStream() const {
1772 std::string mime; 1809 std::string mime;
1773 GURL url = redirected_url_.is_empty() ? url_ : redirected_url_; 1810 GURL url = redirected_url_.is_empty() ? url_ : redirected_url_;
1774 if (!net::GetMimeTypeFromFile(base::FilePath(url.path()), &mime)) 1811 if (!net::GetMimeTypeFromFile(base::FilePath(url.path()), &mime))
1775 return false; 1812 return false;
1776 return !mime.compare("application/x-mpegurl"); 1813 return !mime.compare("application/x-mpegurl");
1777 } 1814 }
1778 1815
1779 } // namespace content 1816 } // 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