Chromium Code Reviews| Index: media/gpu/android_video_decode_accelerator.cc |
| diff --git a/media/gpu/android_video_decode_accelerator.cc b/media/gpu/android_video_decode_accelerator.cc |
| index d9e9b48d3c9d8ce6d2adfdaf018734fe17d8b5a8..42e8cecad9c6d002bb5a88a8e94486767c6c7cb3 100644 |
| --- a/media/gpu/android_video_decode_accelerator.cc |
| +++ b/media/gpu/android_video_decode_accelerator.cc |
| @@ -112,8 +112,7 @@ constexpr base::TimeDelta IdleTimerTimeOut = base::TimeDelta::FromSeconds(1); |
| // software fallback exists. |
| bool ShouldDeferSurfaceCreation( |
| AVDACodecAllocator* codec_allocator, |
| - int surface_id, |
| - base::Optional<base::UnguessableToken> overlay_routing_token, |
| + const OverlayInfo& overlay_info, |
| VideoCodec codec, |
| const AndroidVideoDecodeAccelerator::PlatformConfig& platform_config) { |
| if (platform_config.force_deferred_surface_creation) |
| @@ -121,7 +120,7 @@ bool ShouldDeferSurfaceCreation( |
| // TODO(liberato): We might still want to defer if we've got a routing |
| // token. It depends on whether we want to use it right away or not. |
| - if (surface_id != SurfaceManager::kNoSurfaceID || overlay_routing_token) |
| + if (overlay_info.HasValidSurfaceId() || overlay_info.HasValidRoutingToken()) |
| return false; |
| return codec == kCodecH264 && codec_allocator->IsAnyRegisteredAVDA() && |
| @@ -358,12 +357,11 @@ bool AndroidVideoDecodeAccelerator::Initialize(const Config& config, |
| // If we're low on resources, we may decide to defer creation of the surface |
| // until the codec is actually used. |
| - if (ShouldDeferSurfaceCreation(codec_allocator_, config_.surface_id, |
| - config_.overlay_routing_token, |
| + if (ShouldDeferSurfaceCreation(codec_allocator_, config_.overlay_info, |
| codec_config_->codec, platform_config_)) { |
| // We should never be here if a SurfaceView is required. |
| // TODO(liberato): This really isn't true with AndroidOverlay. |
| - DCHECK_EQ(config_.surface_id, SurfaceManager::kNoSurfaceID); |
| + DCHECK(!config_.overlay_info.HasValidSurfaceId()); |
| defer_surface_creation_ = true; |
| } |
| @@ -415,18 +413,24 @@ void AndroidVideoDecodeAccelerator::StartSurfaceChooser() { |
| // surface creation for other reasons, in which case the sync path with just |
| // signal success optimistically. |
| if (during_initialize_ && !deferred_initialization_pending_) { |
| - DCHECK_EQ(config_.surface_id, SurfaceManager::kNoSurfaceID); |
| - DCHECK(!config_.overlay_routing_token); |
| + DCHECK(!config_.overlay_info.HasValidSurfaceId()); |
| + DCHECK(!config_.overlay_info.HasValidRoutingToken()); |
| OnSurfaceTransition(nullptr); |
| return; |
| } |
| - // If we have a surface, then notify |surface_chooser_| about it. |
| + // If we have a surface, then notify |surface_chooser_| about it. If we were |
| + // told not to use an overlay (kNoSurfaceID or a null routing token), then we |
| + // leave the factory blank. |
| AndroidOverlayFactoryCB factory; |
| - if (config_.surface_id != SurfaceManager::kNoSurfaceID) |
| - factory = base::Bind(&CreateContentVideoViewOverlay, config_.surface_id); |
| - else if (config_.overlay_routing_token && overlay_factory_cb_) |
| - factory = base::Bind(overlay_factory_cb_, *config_.overlay_routing_token); |
| + if (config_.overlay_info.HasValidSurfaceId()) { |
| + factory = base::Bind(&CreateContentVideoViewOverlay, |
| + *config_.overlay_info.surface_id); |
| + } else if (config_.overlay_info.HasValidRoutingToken() && |
| + overlay_factory_cb_) { |
| + factory = |
| + base::Bind(overlay_factory_cb_, **config_.overlay_info.routing_token); |
| + } |
| // Notify |surface_chooser_| that we've started. This guarantees that we'll |
| // get a callback. It might not be a synchronous callback, but we're not in |
| @@ -1249,9 +1253,8 @@ void AndroidVideoDecodeAccelerator::Reset() { |
| StartCodecDrain(DRAIN_FOR_RESET); |
| } |
| -void AndroidVideoDecodeAccelerator::SetSurface( |
| - int32_t surface_id, |
| - const base::Optional<base::UnguessableToken>& routing_token) { |
| +void AndroidVideoDecodeAccelerator::SetOverlayInfo( |
| + const OverlayInfo& overlay_info) { |
| DVLOG(1) << __func__; |
| DCHECK(thread_checker_.CalledOnValidThread()); |
| @@ -1260,17 +1263,28 @@ void AndroidVideoDecodeAccelerator::SetSurface( |
| // signal success to WMPI before initializing it. WMPI is free to change the |
| // surface. In this case, just pretend that |surface_id| is the initial one. |
|
watk
2017/05/25 18:09:36
"surface_id"
liberato (no reviews please)
2017/05/25 21:26:56
done, reworked the comment a bit.
|
| if (state_ == BEFORE_OVERLAY_INIT) { |
| - config_.surface_id = surface_id; |
| - config_.overlay_routing_token = routing_token; |
| + config_.overlay_info.MergeWith(overlay_info); |
| return; |
| } |
| + int32_t surface_id = SurfaceManager::kNoSurfaceID; |
| + OverlayInfo::RoutingToken routing_token; |
| + |
| + // Note that these may be present, but still not OverlayInfo::HasValid...(), |
| + // since they may be set to kNoSurfaceID / no token. In those cases, we still |
| + // want to continue, and revoke the factory. |
| + if (overlay_info.surface_id) |
| + surface_id = *overlay_info.surface_id; |
| + else if (overlay_info.routing_token) |
| + routing_token = *overlay_info.routing_token; |
| + else |
| + return; |
| + |
| AndroidOverlayFactoryCB factory; |
| - if (routing_token && overlay_factory_cb_) { |
| + if (routing_token && overlay_factory_cb_) |
| factory = base::Bind(overlay_factory_cb_, *routing_token); |
| - } else if (surface_id != SurfaceManager::kNoSurfaceID) { |
| + else if (surface_id != SurfaceManager::kNoSurfaceID) |
| factory = base::Bind(&CreateContentVideoViewOverlay, surface_id); |
| - } |
| surface_chooser_->ReplaceOverlayFactory(std::move(factory)); |
| } |