Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(DNS) Add extra logging for DecoderBufferAllocator #4955

Draft
wants to merge 1 commit into
base: 25.lts.1+
Choose a base branch
from
Draft
Show file tree
Hide file tree
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
62 changes: 47 additions & 15 deletions cobalt/media/decoder_buffer_allocator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ namespace media {

namespace {

const bool kEnableAllocationLog = false;
const bool kEnableAllocationLog = true;

// Used to determine if the memory allocated is large. The underlying logic can
// be different.
Expand All @@ -43,8 +43,18 @@ DecoderBufferAllocator::DecoderBufferAllocator()
SbMediaIsBufferPoolAllocateOnDemand()),
initial_capacity_(SbMediaGetInitialBufferCapacity()),
allocation_unit_(SbMediaGetBufferAllocationUnit()) {
LOG(INFO) << "DecoderBufferAllocator ctor initial_capacity:"
<< initial_capacity_ << " allocation_unit: " << allocation_unit_
<< " audio_buffer_budget:" << GetAudioBufferBudget()
<< " buffer_alignment:" << GetBufferAlignment()
<< " buffer_padding:" << GetBufferPadding()
<< " small_allocation_threshold:" << kSmallAllocationThreshold
<< " on_demand:" << is_memory_pool_allocated_on_demand_
<< " gc_duration_threshold:"
<< GetBufferGarbageCollectionDurationThreshold();

if (is_memory_pool_allocated_on_demand_) {
DLOG(INFO) << "Allocated media buffer pool on demand.";
LOG(INFO) << "Allocated media buffer pool on demand.";
Allocator::Set(this);
return;
}
Expand All @@ -55,6 +65,10 @@ DecoderBufferAllocator::DecoderBufferAllocator()
}

DecoderBufferAllocator::~DecoderBufferAllocator() {
LOG_IF(INFO, kEnableAllocationLog)
<< "DecoderBufferAllocator dtor max_capacity"
<< GetMaximumMemoryCapacity();

Allocator::Set(nullptr);

base::AutoLock scoped_lock(mutex_);
Expand All @@ -65,6 +79,11 @@ DecoderBufferAllocator::~DecoderBufferAllocator() {
}
}

// static
bool DecoderBufferAllocator::AllocationLogEnabled() {
return kEnableAllocationLog;
}

void DecoderBufferAllocator::Suspend() {
if (is_memory_pool_allocated_on_demand_) {
return;
Expand All @@ -73,8 +92,8 @@ void DecoderBufferAllocator::Suspend() {
base::AutoLock scoped_lock(mutex_);

if (reuse_allocator_ && reuse_allocator_->GetAllocated() == 0) {
DLOG(INFO) << "Freed " << reuse_allocator_->GetCapacity()
<< " bytes of media buffer pool `on suspend`.";
LOG(INFO) << "Freed " << reuse_allocator_->GetCapacity()
<< " bytes of media buffer pool `on suspend`.";
reuse_allocator_.reset();
}
}
Expand All @@ -96,8 +115,8 @@ void* DecoderBufferAllocator::Allocate(size_t size, size_t alignment) {
void* p = reuse_allocator_->Allocate(size, alignment);
CHECK(p);

LOG_IF(INFO, kEnableAllocationLog)
<< "Media Allocation Log " << p << " " << size << " " << alignment << " ";
LOG_IF(INFO, kEnableAllocationLog) << "DecoderBufferAllocator allocate " << p
<< " " << size << " " << alignment;
return p;
}

Expand All @@ -111,13 +130,14 @@ void DecoderBufferAllocator::Free(void* p, size_t size) {

DCHECK(reuse_allocator_);

LOG_IF(INFO, kEnableAllocationLog) << "Media Allocation Log " << p;
LOG_IF(INFO, kEnableAllocationLog) << "DecoderBufferAllocator free " << p;

reuse_allocator_->Free(p);
if (is_memory_pool_allocated_on_demand_) {
if (reuse_allocator_->GetAllocated() == 0) {
DLOG(INFO) << "Freed " << reuse_allocator_->GetCapacity()
<< " bytes of media buffer pool `on demand`.";
LOG(INFO) << "DecoderBufferAllocator freed "
<< reuse_allocator_->GetCapacity()
<< " bytes of media buffer pool `on demand`.";
reuse_allocator_.reset();
}
}
Expand Down Expand Up @@ -148,16 +168,28 @@ DecoderBufferAllocator::GetBufferGarbageCollectionDurationThreshold() const {
int DecoderBufferAllocator::GetProgressiveBufferBudget(
SbMediaVideoCodec codec, int resolution_width, int resolution_height,
int bits_per_pixel) const {
return SbMediaGetProgressiveBufferBudget(codec, resolution_width,
resolution_height, bits_per_pixel);
auto budget = SbMediaGetProgressiveBufferBudget(
codec, resolution_width, resolution_height, bits_per_pixel);
LOG_IF(INFO, kEnableAllocationLog)
<< "DecoderBufferAllocator progressive budget codec:" << codec
<< " resolution_width:" << resolution_width
<< " resolution_height:" << resolution_height
<< " bits_per_pixel:" << bits_per_pixel << " budget:" << budget;
return budget;
}

int DecoderBufferAllocator::GetVideoBufferBudget(SbMediaVideoCodec codec,
int resolution_width,
int resolution_height,
int bits_per_pixel) const {
return SbMediaGetVideoBufferBudget(codec, resolution_width, resolution_height,
bits_per_pixel);
auto budget = SbMediaGetVideoBufferBudget(codec, resolution_width,
resolution_height, bits_per_pixel);
LOG_IF(INFO, kEnableAllocationLog)
<< "DecoderBufferAllocator video budget codec:" << codec
<< " resolution_width:" << resolution_width
<< " resolution_height:" << resolution_height
<< " bits_per_pixel:" << bits_per_pixel << " budget:" << budget;
return budget;
}

size_t DecoderBufferAllocator::GetAllocatedMemory() const {
Expand Down Expand Up @@ -188,8 +220,8 @@ void DecoderBufferAllocator::EnsureReuseAllocatorIsCreated() {
reuse_allocator_.reset(new BidirectionalFitReuseAllocator(
&fallback_allocator_, initial_capacity_, kSmallAllocationThreshold,
allocation_unit_, 0));
DLOG(INFO) << "Allocated " << initial_capacity_
<< " bytes for media buffer pool.";
LOG(INFO) << "Allocated " << initial_capacity_
<< " bytes for media buffer pool.";
}

} // namespace media
Expand Down
2 changes: 2 additions & 0 deletions cobalt/media/decoder_buffer_allocator.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ class DecoderBufferAllocator : public ::media::DecoderBuffer::Allocator,
DecoderBufferAllocator();
~DecoderBufferAllocator() override;

static bool AllocationLogEnabled();

void Suspend();
void Resume();

Expand Down
1 change: 1 addition & 0 deletions media/base/decoder_buffer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ void DecoderBuffer::Initialize() {
int alignment = s_allocator->GetBufferAlignment();
int padding = s_allocator->GetBufferPadding();
allocated_size_ = size_ + padding;

data_ = static_cast<uint8_t*>(s_allocator->Allocate(allocated_size_,
alignment));
memset(data_ + size_, 0, padding);
Expand Down
9 changes: 8 additions & 1 deletion media/base/stream_parser_buffer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <algorithm>

#include "base/check_op.h"
#include "base/logging.h"
#include "base/memory/ptr_util.h"
#include "media/base/timestamp_constants.h"

Expand Down Expand Up @@ -101,7 +102,13 @@ StreamParserBuffer::StreamParserBuffer(const uint8_t* data,
set_is_key_frame(true);
}

StreamParserBuffer::~StreamParserBuffer() = default;
StreamParserBuffer::~StreamParserBuffer() {
if (end_of_stream()) {
LOG(INFO) << "StreamParserBuffer dtor " << " type:" << type() << " end_of_stream";
} else {
LOG(INFO) << "StreamParserBuffer dtor " << static_cast<const void*>(data()) << " type:" << type() << " timestamp:" << timestamp().InMicroseconds();
}
}

int StreamParserBuffer::GetConfigId() const {
return config_id_;
Expand Down
Loading