Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 36 additions & 25 deletions media/starboard/starboard_renderer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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<DecoderBufferAllocator*>(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<DecoderBufferAllocator>();
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<DecoderBufferAllocator*>(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<std::string, H5vccSettingValue>& h5vcc_settings) {
auto it = h5vcc_settings.find("Media.DisableExternalAllocator");
if (it != h5vcc_settings.end()) {
if (const int64_t* value_ptr = std::get_if<int64_t>(&it->second)) {
return *value_ptr != 1;
}
}
return true;
}

} // namespace

StarboardRenderer::StarboardRenderer(
Expand All @@ -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_);
Expand Down
Loading