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

Side by Side Diff: media/gpu/android_video_decode_accelerator.cc

Issue 2890033002: Use AndroidOverlay in AVDA. (Closed)
Patch Set: Created 3 years, 7 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 | « no previous file | 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 (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 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 "media/gpu/android_video_decode_accelerator.h" 5 #include "media/gpu/android_video_decode_accelerator.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <memory> 9 #include <memory>
10 10
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
106 constexpr base::TimeDelta NoWaitTimeOut = base::TimeDelta::FromMicroseconds(0); 106 constexpr base::TimeDelta NoWaitTimeOut = base::TimeDelta::FromMicroseconds(0);
107 107
108 constexpr base::TimeDelta IdleTimerTimeOut = base::TimeDelta::FromSeconds(1); 108 constexpr base::TimeDelta IdleTimerTimeOut = base::TimeDelta::FromSeconds(1);
109 109
110 // On low end devices (< KitKat is always low-end due to buggy MediaCodec), 110 // On low end devices (< KitKat is always low-end due to buggy MediaCodec),
111 // defer the surface creation until the codec is actually used if we know no 111 // defer the surface creation until the codec is actually used if we know no
112 // software fallback exists. 112 // software fallback exists.
113 bool ShouldDeferSurfaceCreation( 113 bool ShouldDeferSurfaceCreation(
114 AVDACodecAllocator* codec_allocator, 114 AVDACodecAllocator* codec_allocator,
115 int surface_id, 115 int surface_id,
116 base::Optional<base::UnguessableToken> overlay_routing_token,
116 VideoCodec codec, 117 VideoCodec codec,
117 const AndroidVideoDecodeAccelerator::PlatformConfig& platform_config) { 118 const AndroidVideoDecodeAccelerator::PlatformConfig& platform_config) {
118 return platform_config.force_deferred_surface_creation || 119 if (platform_config.force_deferred_surface_creation)
119 (surface_id == SurfaceManager::kNoSurfaceID && codec == kCodecH264 && 120 return true;
120 codec_allocator->IsAnyRegisteredAVDA() && 121
121 platform_config.sdk_int <= 18); 122 // TODO(liberato): We might still want to defer if we've got a routing
123 // token. It depends on whether we want to use it right away or not.
124 if (surface_id != SurfaceManager::kNoSurfaceID || overlay_routing_token)
125 return false;
126
127 return codec == kCodecH264 && codec_allocator->IsAnyRegisteredAVDA() &&
128 platform_config.sdk_int <= 18;
122 } 129 }
123 130
124 std::unique_ptr<AndroidOverlay> CreateContentVideoViewOverlay( 131 std::unique_ptr<AndroidOverlay> CreateContentVideoViewOverlay(
125 int32_t surface_id, 132 int32_t surface_id,
126 AndroidOverlayConfig config) { 133 AndroidOverlayConfig config) {
127 return base::MakeUnique<ContentVideoViewOverlay>(surface_id, 134 return base::MakeUnique<ContentVideoViewOverlay>(surface_id,
128 std::move(config)); 135 std::move(config));
129 } 136 }
130 137
131 } // namespace 138 } // namespace
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after
345 // surface ID from the codec configuration. 352 // surface ID from the codec configuration.
346 DCHECK(!pending_surface_id_); 353 DCHECK(!pending_surface_id_);
347 354
348 // We signaled that we support deferred initialization, so see if the client 355 // We signaled that we support deferred initialization, so see if the client
349 // does also. 356 // does also.
350 deferred_initialization_pending_ = config.is_deferred_initialization_allowed; 357 deferred_initialization_pending_ = config.is_deferred_initialization_allowed;
351 358
352 // If we're low on resources, we may decide to defer creation of the surface 359 // If we're low on resources, we may decide to defer creation of the surface
353 // until the codec is actually used. 360 // until the codec is actually used.
354 if (ShouldDeferSurfaceCreation(codec_allocator_, config_.surface_id, 361 if (ShouldDeferSurfaceCreation(codec_allocator_, config_.surface_id,
362 config_.overlay_routing_token,
355 codec_config_->codec, platform_config_)) { 363 codec_config_->codec, platform_config_)) {
356 // We should never be here if a SurfaceView is required. 364 // We should never be here if a SurfaceView is required.
357 // TODO(liberato): This really isn't true with AndroidOverlay. 365 // TODO(liberato): This really isn't true with AndroidOverlay.
358 DCHECK_EQ(config_.surface_id, SurfaceManager::kNoSurfaceID); 366 DCHECK_EQ(config_.surface_id, SurfaceManager::kNoSurfaceID);
359 defer_surface_creation_ = true; 367 defer_surface_creation_ = true;
360 } 368 }
361 369
362 if (!codec_allocator_->StartThread(this)) { 370 if (!codec_allocator_->StartThread(this)) {
363 LOG(ERROR) << "Unable to start thread"; 371 LOG(ERROR) << "Unable to start thread";
364 return false; 372 return false;
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
401 // Also note that we might choose to defer surface creation for the sync path, 409 // Also note that we might choose to defer surface creation for the sync path,
402 // which won't get here. We'll exit above, successfully, during init, and 410 // which won't get here. We'll exit above, successfully, during init, and
403 // will fall through to the below when Decode calls us back. That's okay. 411 // will fall through to the below when Decode calls us back. That's okay.
404 // We only handle this case specially since |surface_chooser_| is allowed to 412 // We only handle this case specially since |surface_chooser_| is allowed to
405 // post callbacks to us. Here, we guarantee that the sync case is actually 413 // post callbacks to us. Here, we guarantee that the sync case is actually
406 // resolved synchronously. The only exception will be if we need to defer 414 // resolved synchronously. The only exception will be if we need to defer
407 // surface creation for other reasons, in which case the sync path with just 415 // surface creation for other reasons, in which case the sync path with just
408 // signal success optimistically. 416 // signal success optimistically.
409 if (during_initialize_ && !deferred_initialization_pending_) { 417 if (during_initialize_ && !deferred_initialization_pending_) {
410 DCHECK_EQ(config_.surface_id, SurfaceManager::kNoSurfaceID); 418 DCHECK_EQ(config_.surface_id, SurfaceManager::kNoSurfaceID);
419 DCHECK(!config_.overlay_routing_token);
411 OnSurfaceTransition(nullptr); 420 OnSurfaceTransition(nullptr);
412 return; 421 return;
413 } 422 }
414 423
415 // If we have a surface, then notify |surface_chooser_| about it. 424 // If we have a surface, then notify |surface_chooser_| about it.
416 AndroidOverlayFactoryCB factory; 425 AndroidOverlayFactoryCB factory;
417 if (config_.surface_id != SurfaceManager::kNoSurfaceID) 426 if (config_.surface_id != SurfaceManager::kNoSurfaceID)
418 factory = base::Bind(&CreateContentVideoViewOverlay, config_.surface_id); 427 factory = base::Bind(&CreateContentVideoViewOverlay, config_.surface_id);
428 else if (config_.overlay_routing_token && overlay_factory_cb_)
429 factory = base::Bind(overlay_factory_cb_, *config_.overlay_routing_token);
419 430
420 // Notify |surface_chooser_| that we've started. This guarantees that we'll 431 // Notify |surface_chooser_| that we've started. This guarantees that we'll
421 // get a callback. It might not be a synchronous callback, but we're not in 432 // get a callback. It might not be a synchronous callback, but we're not in
422 // the synchronous case. It will be soon, though. For pre-M, we rely on the 433 // the synchronous case. It will be soon, though. For pre-M, we rely on the
423 // fact that |surface_chooser_| won't tell us to use a SurfaceTexture while 434 // fact that |surface_chooser_| won't tell us to use a SurfaceTexture while
424 // waiting for an overlay to become ready, for example. 435 // waiting for an overlay to become ready, for example.
425 surface_chooser_->Initialize( 436 surface_chooser_->Initialize(
426 base::Bind(&AndroidVideoDecodeAccelerator::OnSurfaceTransition, 437 base::Bind(&AndroidVideoDecodeAccelerator::OnSurfaceTransition,
427 weak_this_factory_.GetWeakPtr()), 438 weak_this_factory_.GetWeakPtr()),
428 base::Bind(&AndroidVideoDecodeAccelerator::OnSurfaceTransition, 439 base::Bind(&AndroidVideoDecodeAccelerator::OnSurfaceTransition,
(...skipping 819 matching lines...) Expand 10 before | Expand all | Expand 10 after
1248 const base::Optional<base::UnguessableToken>& routing_token) { 1259 const base::Optional<base::UnguessableToken>& routing_token) {
1249 DVLOG(1) << __func__; 1260 DVLOG(1) << __func__;
1250 DCHECK(thread_checker_.CalledOnValidThread()); 1261 DCHECK(thread_checker_.CalledOnValidThread());
1251 1262
1252 // It's possible that we'll receive a SetSurface before initializing the 1263 // It's possible that we'll receive a SetSurface before initializing the
1253 // surface chooser. For example, if we defer surface creation, then we'll 1264 // surface chooser. For example, if we defer surface creation, then we'll
1254 // signal success to WMPI before initializing it. WMPI is free to change the 1265 // signal success to WMPI before initializing it. WMPI is free to change the
1255 // surface. In this case, just pretend that |surface_id| is the initial one. 1266 // surface. In this case, just pretend that |surface_id| is the initial one.
1256 if (state_ == BEFORE_OVERLAY_INIT) { 1267 if (state_ == BEFORE_OVERLAY_INIT) {
1257 config_.surface_id = surface_id; 1268 config_.surface_id = surface_id;
1269 config_.overlay_routing_token = routing_token;
1258 return; 1270 return;
1259 } 1271 }
1260 1272
1261 AndroidOverlayFactoryCB factory; 1273 AndroidOverlayFactoryCB factory;
1262 if (routing_token) { 1274 if (routing_token && overlay_factory_cb_) {
1263 // TODO(liberato): do something 1275 factory = base::Bind(overlay_factory_cb_, *routing_token);
1264 } else if (surface_id != SurfaceManager::kNoSurfaceID) { 1276 } else if (surface_id != SurfaceManager::kNoSurfaceID) {
1265 factory = base::Bind(&CreateContentVideoViewOverlay, surface_id); 1277 factory = base::Bind(&CreateContentVideoViewOverlay, surface_id);
1266 } 1278 }
1267 1279
1268 surface_chooser_->ReplaceOverlayFactory(std::move(factory)); 1280 surface_chooser_->ReplaceOverlayFactory(std::move(factory));
1269 } 1281 }
1270 1282
1271 void AndroidVideoDecodeAccelerator::Destroy() { 1283 void AndroidVideoDecodeAccelerator::Destroy() {
1272 DVLOG(1) << __func__; 1284 DVLOG(1) << __func__;
1273 DCHECK(thread_checker_.CalledOnValidThread()); 1285 DCHECK(thread_checker_.CalledOnValidThread());
(...skipping 411 matching lines...) Expand 10 before | Expand all | Expand 10 after
1685 codec_allocator_->ReleaseMediaCodec(std::move(media_codec_), 1697 codec_allocator_->ReleaseMediaCodec(std::move(media_codec_),
1686 codec_config_->surface_bundle); 1698 codec_config_->surface_bundle);
1687 } 1699 }
1688 1700
1689 void AndroidVideoDecodeAccelerator::ReleaseCodecAndBundle() { 1701 void AndroidVideoDecodeAccelerator::ReleaseCodecAndBundle() {
1690 ReleaseCodec(); 1702 ReleaseCodec();
1691 codec_config_->surface_bundle = nullptr; 1703 codec_config_->surface_bundle = nullptr;
1692 } 1704 }
1693 1705
1694 } // namespace media 1706 } // namespace media
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698