diff --git a/media/starboard/starboard_renderer.cc b/media/starboard/starboard_renderer.cc index 4f110ab1a1c..b9ddf268b38 100644 --- a/media/starboard/starboard_renderer.cc +++ b/media/starboard/starboard_renderer.cc @@ -28,11 +28,13 @@ #include "media/starboard/decoder_buffer_allocator.h" #include "starboard/common/media.h" #include "starboard/common/player.h" +#include "starboard/common/string.h" namespace media { namespace { +using ::starboard::FormatWithDigitSeparators; using ::starboard::GetMediaAudioConnectorName; using ::starboard::GetPlayerStateName; @@ -119,40 +121,48 @@ void ConfigureDecoderBufferAllocator(bool use_external_allocator) { if (use_external_allocator) { if (instance) { - LOG(INFO) << "DecoderBufferAllocator is already configured. Keeping " - "current instance."; + auto allocator = static_cast(instance); + LOG(INFO) << __func__ + << " > DecoderBufferAllocator is already configured. Keeping " + "current instance. allocated_memory=" + << FormatWithDigitSeparators(allocator->GetAllocatedMemory()) + << ", current_memory_capacity=" + << FormatWithDigitSeparators( + allocator->GetCurrentMemoryCapacity()); } else { - LOG(INFO) << "Creating and setting new DecoderBufferAllocator."; + LOG(INFO) << __func__ + << " > Switching from default allocator(partition_alloc) to " + "new DecoderBufferAllocator."; *g_external_allocator = std::make_unique(); DecoderBuffer::Allocator::Set(g_external_allocator->get()); } } else { if (instance) { - LOG(INFO) << "Destroying DecoderBufferAllocator instance. Using " - "default allocator from now on."; - // NOTE: The use_external_allocator flag, controlled by the YouTube - // experimentation tooling, changes when a new Kabuki app is loaded. - // A change in this flag signifies a new app load, making it safe - // to destroy the DecoderBufferAllocator from the previous session. - g_external_allocator->reset(); - DecoderBuffer::Allocator::Set(nullptr); + auto allocator = static_cast(instance); + if (allocator->GetAllocatedMemory() != 0) { + LOG(WARNING) + << __func__ + << " > Cannot switch to default allocator(partition_alloc), since " + "current DecoderBufferAllocator instance holds allocated " + "memory: allocated_memory=" + << FormatWithDigitSeparators(allocator->GetAllocatedMemory()) + << ", current_memory_capacity=" + << FormatWithDigitSeparators(allocator->GetCurrentMemoryCapacity()); + } else { + LOG(INFO) + << __func__ + << " > Destroying DecoderBufferAllocator instance. Switching to " + "default allocator(partition_alloc) from now on."; + DecoderBuffer::Allocator::Set(nullptr); + g_external_allocator->reset(); + } } else { - LOG(INFO) << "Keeping current default DecoderBufferAllocator."; + LOG(INFO) + << __func__ + << " > Already using default allocator(partition_alloc). Keeping it."; } } } - -bool ShouldUseExternalAllocator( - const std::map& h5vcc_settings) { - auto it = h5vcc_settings.find("Media.DisableExternalAllocator"); - if (it != h5vcc_settings.end()) { - if (const int64_t* value_ptr = std::get_if(&it->second)) { - return *value_ptr != 1; - } - } - return true; -} - } // namespace StarboardRenderer::StarboardRenderer( @@ -172,7 +182,8 @@ StarboardRenderer::StarboardRenderer( audio_write_duration_local_(audio_write_duration_local), audio_write_duration_remote_(audio_write_duration_remote), max_video_capabilities_(max_video_capabilities), - use_external_allocator_(ShouldUseExternalAllocator(h5vcc_settings)) { + // For YTS test, we explicitly disable external allocator. + use_external_allocator_(false) { DCHECK(task_runner_); DCHECK(media_log_); DCHECK(set_bounds_helper_);