#ifdef UNSAFE_BUFFERS_BUILD
#pragma allow_unsafe_buffers
#endif
#include "media/filters/source_buffer_stream.h"
#include <algorithm>
#include <map>
#include <memory>
#include <sstream>
#include <string>
#include "base/functional/bind.h"
#include "base/trace_event/trace_event.h"
#include "media/base/demuxer_memory_limit.h"
#include "media/base/media_switches.h"
#include "media/base/stream_parser_buffer.h"
#include "media/base/timestamp_constants.h"
namespace media {
namespace {
const int kMinimumInterbufferDistanceInMs = …;
const int kMaxTrackBufferGapWarningLogs = …;
const int kMaxGarbageCollectAlgorithmWarningLogs = …;
const int kMaxAudioSpliceLogs = …;
bool IsRangeListSorted(const SourceBufferStream::RangeList& ranges) { … }
base::TimeDelta ComputeFudgeRoom(base::TimeDelta approximate_duration) { … }
base::TimeDelta kSeekToStartFudgeRoom() { … }
std::string StatusToString(const SourceBufferStreamStatus& status) { … }
std::string RangeToString(const SourceBufferRange& range) { … }
std::string RangesToString(const SourceBufferStream::RangeList& ranges) { … }
std::string BufferQueueBuffersToLogString(
const SourceBufferStream::BufferQueue& buffers) { … }
std::string BufferQueueMetadataToLogString(
const SourceBufferStream::BufferQueue& buffers) { … }
}
SourceBufferStream::SourceBufferStream(const AudioDecoderConfig& audio_config,
MediaLog* media_log)
: … { … }
SourceBufferStream::SourceBufferStream(const VideoDecoderConfig& video_config,
MediaLog* media_log)
: … { … }
SourceBufferStream::~SourceBufferStream() = default;
void SourceBufferStream::OnStartOfCodedFrameGroup(
base::TimeDelta coded_frame_group_start_pts) { … }
void SourceBufferStream::Append(const BufferQueue& buffers) { … }
void SourceBufferStream::Remove(base::TimeDelta start,
base::TimeDelta end,
base::TimeDelta duration) { … }
base::TimeDelta SourceBufferStream::PotentialNextAppendTimestamp() const { … }
void SourceBufferStream::UpdateLastAppendStateForRemove(
base::TimeDelta remove_start,
base::TimeDelta remove_end,
bool exclude_start) { … }
void SourceBufferStream::RemoveInternal(base::TimeDelta start,
base::TimeDelta end,
bool exclude_start,
BufferQueue* deleted_buffers) { … }
void SourceBufferStream::ResetSeekState() { … }
void SourceBufferStream::ResetLastAppendedState() { … }
bool SourceBufferStream::ShouldSeekToStartOfBuffered(
base::TimeDelta seek_timestamp) const { … }
bool SourceBufferStream::IsDtsMonotonicallyIncreasing(
const BufferQueue& buffers) { … }
bool SourceBufferStream::OnlySelectedRangeIsSeeked() const { … }
bool SourceBufferStream::UpdateMaxInterbufferDtsDistance(
const BufferQueue& buffers) { … }
void SourceBufferStream::SetConfigIds(const BufferQueue& buffers) { … }
void SourceBufferStream::OnMemoryPressure(
base::TimeDelta media_time,
base::MemoryPressureListener::MemoryPressureLevel memory_pressure_level,
bool force_instant_gc) { … }
bool SourceBufferStream::GarbageCollectIfNeeded(base::TimeDelta media_time,
size_t newDataSize) { … }
size_t SourceBufferStream::FreeBuffersAfterLastAppended(
size_t total_bytes_to_free,
base::TimeDelta media_time) { … }
size_t SourceBufferStream::GetRemovalRange(
base::TimeDelta start_timestamp,
base::TimeDelta end_timestamp,
size_t total_bytes_to_free,
base::TimeDelta* removal_end_timestamp) { … }
size_t SourceBufferStream::FreeBuffers(size_t total_bytes_to_free,
base::TimeDelta media_time,
bool reverse_direction) { … }
void SourceBufferStream::TrimSpliceOverlap(const BufferQueue& new_buffers) { … }
void SourceBufferStream::PrepareRangesForNextAppend(
const BufferQueue& new_buffers,
BufferQueue* deleted_buffers) { … }
void SourceBufferStream::GetTimestampInterval(const BufferQueue& buffers,
base::TimeDelta* start,
base::TimeDelta* end) { … }
bool SourceBufferStream::IsNextGopAdjacentToEndOfCurrentAppendSequence(
base::TimeDelta next_gop_timestamp) const { … }
void SourceBufferStream::PruneTrackBuffer(const base::TimeDelta timestamp) { … }
void SourceBufferStream::MergeWithNextRangeIfNecessary(
const RangeList::iterator& range_with_new_buffers_itr) { … }
void SourceBufferStream::MergeAllAdjacentRanges() { … }
void SourceBufferStream::Seek(base::TimeDelta timestamp) { … }
bool SourceBufferStream::IsSeekPending() const { … }
void SourceBufferStream::OnSetDuration(base::TimeDelta duration) { … }
SourceBufferStreamStatus SourceBufferStream::GetNextBuffer(
scoped_refptr<StreamParserBuffer>* out_buffer) { … }
SourceBufferStreamStatus SourceBufferStream::HandleNextBufferWithPreroll(
scoped_refptr<StreamParserBuffer>* out_buffer) { … }
SourceBufferStreamStatus SourceBufferStream::GetNextBufferInternal(
scoped_refptr<StreamParserBuffer>* out_buffer) { … }
void SourceBufferStream::WarnIfTrackBufferExhaustionSkipsForward(
scoped_refptr<StreamParserBuffer> next_buffer) { … }
bool SourceBufferStream::IsNextBufferConfigChanged() { … }
base::TimeDelta SourceBufferStream::GetNextBufferTimestamp() { … }
SourceBufferStream::RangeList::iterator
SourceBufferStream::FindExistingRangeFor(base::TimeDelta start_timestamp) { … }
SourceBufferStream::RangeList::iterator SourceBufferStream::AddToRanges(
std::unique_ptr<SourceBufferRange> new_range) { … }
void SourceBufferStream::SeekAndSetSelectedRange(
SourceBufferRange* range,
base::TimeDelta seek_timestamp) { … }
void SourceBufferStream::SetSelectedRange(SourceBufferRange* range) { … }
Ranges<base::TimeDelta> SourceBufferStream::GetBufferedTime() const { … }
base::TimeDelta SourceBufferStream::GetLowestPresentationTimestamp() const { … }
base::TimeDelta SourceBufferStream::GetHighestPresentationTimestamp() const { … }
base::TimeDelta SourceBufferStream::GetBufferedDuration() const { … }
size_t SourceBufferStream::GetMemoryUsage() const { … }
void SourceBufferStream::MarkEndOfStream() { … }
void SourceBufferStream::UnmarkEndOfStream() { … }
bool SourceBufferStream::IsEndOfStreamReached() const { … }
const AudioDecoderConfig& SourceBufferStream::GetCurrentAudioDecoderConfig() { … }
const VideoDecoderConfig& SourceBufferStream::GetCurrentVideoDecoderConfig() { … }
base::TimeDelta SourceBufferStream::GetMaxInterbufferDistance() const { … }
bool SourceBufferStream::UpdateAudioConfig(const AudioDecoderConfig& config,
bool allow_codec_change) { … }
bool SourceBufferStream::UpdateVideoConfig(const VideoDecoderConfig& config,
bool allow_codec_change) { … }
void SourceBufferStream::CompleteConfigChange() { … }
void SourceBufferStream::SetSelectedRangeIfNeeded(
const base::TimeDelta timestamp) { … }
base::TimeDelta SourceBufferStream::FindNewSelectedRangeSeekTimestamp(
const base::TimeDelta start_timestamp) { … }
base::TimeDelta SourceBufferStream::FindKeyframeAfterTimestamp(
const base::TimeDelta timestamp) { … }
std::string SourceBufferStream::GetStreamTypeName() const { … }
SourceBufferStreamType SourceBufferStream::GetType() const { … }
void SourceBufferStream::DeleteAndRemoveRange(RangeList::iterator* itr) { … }
bool SourceBufferStream::SetPendingBuffer(
scoped_refptr<StreamParserBuffer>* out_buffer) { … }
}