#include "third_party/blink/renderer/modules/mediasource/source_buffer.h"
#include <limits>
#include <memory>
#include <sstream>
#include <tuple>
#include <utility>
#include "base/numerics/checked_math.h"
#include "media/base/logging_override_if_enabled.h"
#include "media/base/stream_parser_buffer.h"
#include "partition_alloc/partition_alloc.h"
#include "third_party/blink/public/platform/task_type.h"
#include "third_party/blink/public/platform/web_source_buffer.h"
#include "third_party/blink/renderer/bindings/core/v8/script_promise_resolver.h"
#include "third_party/blink/renderer/bindings/core/v8/v8_throw_dom_exception.h"
#include "third_party/blink/renderer/bindings/modules/v8/v8_audio_decoder_config.h"
#include "third_party/blink/renderer/bindings/modules/v8/v8_encoded_audio_chunk.h"
#include "third_party/blink/renderer/bindings/modules/v8/v8_encoded_video_chunk.h"
#include "third_party/blink/renderer/bindings/modules/v8/v8_source_buffer_config.h"
#include "third_party/blink/renderer/bindings/modules/v8/v8_union_encodedaudiochunk_encodedaudiochunkorencodedvideochunksequence_encodedvideochunk.h"
#include "third_party/blink/renderer/bindings/modules/v8/v8_union_encodedaudiochunk_encodedvideochunk.h"
#include "third_party/blink/renderer/bindings/modules/v8/v8_video_decoder_config.h"
#include "third_party/blink/renderer/core/dom/document.h"
#include "third_party/blink/renderer/core/dom/dom_exception.h"
#include "third_party/blink/renderer/core/dom/events/event.h"
#include "third_party/blink/renderer/core/dom/events/event_queue.h"
#include "third_party/blink/renderer/core/execution_context/execution_context.h"
#include "third_party/blink/renderer/core/frame/deprecation/deprecation.h"
#include "third_party/blink/renderer/core/html/media/html_media_element.h"
#include "third_party/blink/renderer/core/html/time_ranges.h"
#include "third_party/blink/renderer/core/html/track/audio_track.h"
#include "third_party/blink/renderer/core/html/track/audio_track_list.h"
#include "third_party/blink/renderer/core/html/track/video_track.h"
#include "third_party/blink/renderer/core/html/track/video_track_list.h"
#include "third_party/blink/renderer/core/typed_arrays/dom_array_buffer.h"
#include "third_party/blink/renderer/core/typed_arrays/dom_array_buffer_view.h"
#include "third_party/blink/renderer/modules/mediasource/media_source.h"
#include "third_party/blink/renderer/modules/mediasource/source_buffer_track_base_supplement.h"
#include "third_party/blink/renderer/modules/webcodecs/encoded_audio_chunk.h"
#include "third_party/blink/renderer/modules/webcodecs/encoded_video_chunk.h"
#include "third_party/blink/renderer/platform/bindings/exception_messages.h"
#include "third_party/blink/renderer/platform/bindings/exception_state.h"
#include "third_party/blink/renderer/platform/heap/garbage_collected.h"
#include "third_party/blink/renderer/platform/instrumentation/tracing/trace_event.h"
#include "third_party/blink/renderer/platform/instrumentation/use_counter.h"
#include "third_party/blink/renderer/platform/network/mime/content_type.h"
#include "third_party/blink/renderer/platform/runtime_enabled_features.h"
#include "third_party/blink/renderer/platform/wtf/allocator/partition_allocator.h"
#include "third_party/blink/renderer/platform/wtf/allocator/partitions.h"
#include "third_party/blink/renderer/platform/wtf/functional.h"
#include "third_party/blink/renderer/platform/wtf/math_extras.h"
#include "third_party/blink/renderer/platform/wtf/text/string_builder.h"
WebSourceBuffer;
namespace blink {
namespace {
static bool ThrowExceptionIfRemovedOrUpdating(bool is_removed,
bool is_updating,
ExceptionState& exception_state) { … }
WTF::String WebTimeRangesToString(const WebTimeRanges& ranges) { … }
constexpr media::StreamParser::TrackId kWebCodecsAudioTrackId = …;
constexpr media::StreamParser::TrackId kWebCodecsVideoTrackId = …;
scoped_refptr<media::StreamParserBuffer> MakeAudioStreamParserBuffer(
const EncodedAudioChunk& audio_chunk) { … }
scoped_refptr<media::StreamParserBuffer> MakeVideoStreamParserBuffer(
const EncodedVideoChunk& video_chunk) { … }
}
SourceBuffer::SourceBuffer(std::unique_ptr<WebSourceBuffer> web_source_buffer,
MediaSource* source,
EventQueue* async_event_queue)
: … { … }
SourceBuffer::~SourceBuffer() { … }
void SourceBuffer::Dispose() { … }
AtomicString SourceBuffer::SegmentsKeyword() { … }
AtomicString SourceBuffer::SequenceKeyword() { … }
void SourceBuffer::setMode(const AtomicString& new_mode,
ExceptionState& exception_state) { … }
void SourceBuffer::SetMode_Locked(
AtomicString new_mode,
ExceptionState* exception_state,
MediaSourceAttachmentSupplement::ExclusiveKey ) { … }
TimeRanges* SourceBuffer::buffered(ExceptionState& exception_state) const { … }
void SourceBuffer::GetBuffered_Locked(
WebTimeRanges* ranges ,
MediaSourceAttachmentSupplement::ExclusiveKey ) const { … }
double SourceBuffer::timestampOffset() const { … }
void SourceBuffer::setTimestampOffset(double offset,
ExceptionState& exception_state) { … }
void SourceBuffer::SetTimestampOffset_Locked(
double offset,
ExceptionState* exception_state,
MediaSourceAttachmentSupplement::ExclusiveKey ) { … }
AudioTrackList& SourceBuffer::audioTracks() { … }
VideoTrackList& SourceBuffer::videoTracks() { … }
double SourceBuffer::appendWindowStart() const { … }
void SourceBuffer::setAppendWindowStart(double start,
ExceptionState& exception_state) { … }
void SourceBuffer::SetAppendWindowStart_Locked(
double start,
MediaSourceAttachmentSupplement::ExclusiveKey ) { … }
double SourceBuffer::appendWindowEnd() const { … }
void SourceBuffer::setAppendWindowEnd(double end,
ExceptionState& exception_state) { … }
void SourceBuffer::SetAppendWindowEnd_Locked(
double end,
MediaSourceAttachmentSupplement::ExclusiveKey ) { … }
void SourceBuffer::appendBuffer(DOMArrayBuffer* data,
ExceptionState& exception_state) { … }
void SourceBuffer::appendBuffer(NotShared<DOMArrayBufferView> data,
ExceptionState& exception_state) { … }
ScriptPromise<IDLUndefined> SourceBuffer::appendEncodedChunks(
ScriptState* script_state,
const V8EncodedChunks* chunks,
ExceptionState& exception_state) { … }
void SourceBuffer::AppendEncodedChunks_Locked(
std::unique_ptr<media::StreamParser::BufferQueue> buffer_queue,
size_t size,
ExceptionState* exception_state,
MediaSourceAttachmentSupplement::ExclusiveKey ) { … }
void SourceBuffer::abort(ExceptionState& exception_state) { … }
void SourceBuffer::Abort_Locked(
MediaSourceAttachmentSupplement::ExclusiveKey pass_key) { … }
void SourceBuffer::remove(double start,
double end,
ExceptionState& exception_state) { … }
void SourceBuffer::Remove_Locked(
double start,
double end,
ExceptionState* exception_state,
MediaSourceAttachmentSupplement::ExclusiveKey pass_key) { … }
void SourceBuffer::changeType(const String& type,
ExceptionState& exception_state) { … }
void SourceBuffer::ChangeTypeUsingConfig(ExecutionContext* execution_context,
const SourceBufferConfig* config,
ExceptionState& exception_state) { … }
void SourceBuffer::ChangeType_Locked(
const String& type,
ExceptionState* exception_state,
MediaSourceAttachmentSupplement::ExclusiveKey pass_key) { … }
void SourceBuffer::setTrackDefaults(TrackDefaultList* track_defaults,
ExceptionState& exception_state) { … }
void SourceBuffer::CancelRemove() { … }
void SourceBuffer::AbortIfUpdating() { … }
void SourceBuffer::RemovedFromMediaSource() { … }
double SourceBuffer::HighestPresentationTimestamp() { … }
void SourceBuffer::RemoveMediaTracks() { … }
double SourceBuffer::GetMediaTime() { … }
template <class T>
T* FindExistingTrackById(const TrackListBase<T>& track_list, const String& id) { … }
const TrackDefault* SourceBuffer::GetTrackDefault(
const AtomicString& track_type,
const AtomicString& byte_stream_track_id) const { … }
AtomicString SourceBuffer::DefaultTrackLabel(
const AtomicString& track_type,
const AtomicString& byte_stream_track_id) const { … }
AtomicString SourceBuffer::DefaultTrackLanguage(
const AtomicString& track_type,
const AtomicString& byte_stream_track_id) const { … }
void SourceBuffer::AddPlaceholderCrossThreadTracks(
const WebVector<MediaTrackInfo>& new_tracks,
scoped_refptr<MediaSourceAttachmentSupplement> attachment) { … }
void SourceBuffer::RemovePlaceholderCrossThreadTracks(
scoped_refptr<MediaSourceAttachmentSupplement> attachment,
MediaSourceTracer* tracer) { … }
bool SourceBuffer::InitializationSegmentReceived(
const WebVector<MediaTrackInfo>& new_tracks) { … }
void SourceBuffer::NotifyParseWarning(const ParseWarning warning) { … }
bool SourceBuffer::HasPendingActivity() const { … }
void SourceBuffer::ContextDestroyed() { … }
ExecutionContext* SourceBuffer::GetExecutionContext() const { … }
const AtomicString& SourceBuffer::InterfaceName() const { … }
bool SourceBuffer::IsRemoved() const { … }
void SourceBuffer::ScheduleEvent(const AtomicString& event_name) { … }
bool SourceBuffer::PrepareAppend(double media_time,
size_t new_data_size,
ExceptionState& exception_state) { … }
bool SourceBuffer::EvictCodedFrames(double media_time, size_t new_data_size) { … }
void SourceBuffer::AppendBufferInternal(base::span<const unsigned char> data,
ExceptionState& exception_state) { … }
void SourceBuffer::AppendBufferInternal_Locked(
base::span<const unsigned char> data,
ExceptionState* exception_state,
MediaSourceAttachmentSupplement::ExclusiveKey ) { … }
void SourceBuffer::AppendEncodedChunksAsyncPart() { … }
void SourceBuffer::AppendBufferAsyncPart() { … }
void SourceBuffer::AppendEncodedChunksAsyncPart_Locked(
MediaSourceAttachmentSupplement::ExclusiveKey pass_key) { … }
void SourceBuffer::AppendBufferAsyncPart_Locked(
MediaSourceAttachmentSupplement::ExclusiveKey pass_key) { … }
void SourceBuffer::RemoveAsyncPart() { … }
void SourceBuffer::RemoveAsyncPart_Locked(
MediaSourceAttachmentSupplement::ExclusiveKey ) { … }
void SourceBuffer::AppendError(
MediaSourceAttachmentSupplement::ExclusiveKey pass_key) { … }
void SourceBuffer::Trace(Visitor* visitor) const { … }
}