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..8ecda1ba5076b9f3cc7c0eeac5559a2d08919239 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,8 +120,11 @@ 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.surface_id && |
| + *overlay_info.surface_id != SurfaceManager::kNoSurfaceID) || |
| + (overlay_info.routing_token && *overlay_info.routing_token)) { |
| return false; |
| + } |
| return codec == kCodecH264 && codec_allocator->IsAnyRegisteredAVDA() && |
| platform_config.sdk_int <= 18; |
| @@ -358,12 +360,12 @@ 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.surface_id || |
|
tguilbert
2017/05/24 19:14:54
NIT: How do you feel about adding syntactic sugar
liberato (no reviews please)
2017/05/24 21:21:07
i think that it's a good idea. Done.
|
| + *config_.overlay_info.surface_id == SurfaceManager::kNoSurfaceID); |
| defer_surface_creation_ = true; |
| } |
| @@ -415,18 +417,27 @@ 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.surface_id || |
| + *config_.overlay_info.surface_id == SurfaceManager::kNoSurfaceID); |
| + DCHECK(!config_.overlay_info.routing_token || |
| + !(*config_.overlay_info.routing_token)); |
| 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.surface_id && |
| + *config_.overlay_info.surface_id != SurfaceManager::kNoSurfaceID) { |
| + factory = base::Bind(&CreateContentVideoViewOverlay, |
| + *config_.overlay_info.surface_id); |
| + } else if (config_.overlay_info.routing_token && |
| + *config_.overlay_info.routing_token && overlay_factory_cb_) { |
|
tguilbert
2017/05/24 19:14:54
NIT: Same/Similar comment as above for "overlay_in
liberato (no reviews please)
2017/05/24 21:21:07
Done.
|
| + 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 +1260,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,11 +1270,20 @@ 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. |
| if (state_ == BEFORE_OVERLAY_INIT) { |
| - config_.surface_id = surface_id; |
| - config_.overlay_routing_token = routing_token; |
| + config_.overlay_info |= overlay_info; |
| return; |
| } |
| + int32_t surface_id = SurfaceManager::kNoSurfaceID; |
| + OverlayInfo::RoutingToken routing_token; |
| + |
| + 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_) { |
| factory = base::Bind(overlay_factory_cb_, *routing_token); |