summaryrefslogtreecommitdiff
path: root/chromium/third_party/blink/renderer/modules/mediasource
diff options
context:
space:
mode:
authorAllan Sandfeld Jensen <allan.jensen@qt.io>2019-02-13 16:23:34 +0100
committerAllan Sandfeld Jensen <allan.jensen@qt.io>2019-02-14 10:37:21 +0000
commit38a9a29f4f9436cace7f0e7abf9c586057df8a4e (patch)
treec4e8c458dc595bc0ddb435708fa2229edfd00bd4 /chromium/third_party/blink/renderer/modules/mediasource
parente684a3455bcc29a6e3e66a004e352dea4e1141e7 (diff)
downloadqtwebengine-chromium-38a9a29f4f9436cace7f0e7abf9c586057df8a4e.tar.gz
BASELINE: Update Chromium to 73.0.3683.37
Change-Id: I08c9af2948b645f671e5d933aca1f7a90ea372f2 Reviewed-by: Michael BrĂ¼ning <michael.bruning@qt.io>
Diffstat (limited to 'chromium/third_party/blink/renderer/modules/mediasource')
-rw-r--r--chromium/third_party/blink/renderer/modules/mediasource/media_source.cc26
-rw-r--r--chromium/third_party/blink/renderer/modules/mediasource/media_source.h14
-rw-r--r--chromium/third_party/blink/renderer/modules/mediasource/source_buffer.cc66
-rw-r--r--chromium/third_party/blink/renderer/modules/mediasource/source_buffer.h31
-rw-r--r--chromium/third_party/blink/renderer/modules/mediasource/source_buffer_list.h19
5 files changed, 99 insertions, 57 deletions
diff --git a/chromium/third_party/blink/renderer/modules/mediasource/media_source.cc b/chromium/third_party/blink/renderer/modules/mediasource/media_source.cc
index 3224fbd5f7c..0262fe6209f 100644
--- a/chromium/third_party/blink/renderer/modules/mediasource/media_source.cc
+++ b/chromium/third_party/blink/renderer/modules/mediasource/media_source.cc
@@ -128,7 +128,6 @@ MediaSource::MediaSource(ExecutionContext* context)
MediaSource::~MediaSource() {
BLINK_MSLOG << __func__ << " this=" << this;
- DCHECK(IsClosed());
}
void MediaSource::LogAndThrowDOMException(ExceptionState& exception_state,
@@ -432,6 +431,9 @@ TimeRanges* MediaSource::Buffered() const {
}
TimeRanges* MediaSource::Seekable() const {
+ DCHECK(attached_element_)
+ << "Seekable should only be used when attached to HTMLMediaElement";
+
// Implements MediaSource algorithm for HTMLMediaElement.seekable.
// http://w3c.github.io/media-source/#htmlmediaelement-extensions
@@ -442,7 +444,7 @@ TimeRanges* MediaSource::Seekable() const {
// If duration equals positive Infinity:
if (source_duration == std::numeric_limits<double>::infinity()) {
- TimeRanges* buffered = attached_element_->buffered();
+ TimeRanges* buffered = Buffered();
// 1. If live seekable range is not empty:
if (live_seekable_range_->length() != 0) {
@@ -503,6 +505,8 @@ void MediaSource::OnTrackChanged(TrackBase* track) {
void MediaSource::setDuration(double duration,
ExceptionState& exception_state) {
+ BLINK_MSLOG << __func__ << " this=" << this << " : duration=" << duration;
+
// 2.1 https://www.w3.org/TR/media-source/#widl-MediaSource-duration
// 1. If the value being set is negative or NaN then throw a TypeError
// exception and abort these steps.
@@ -624,6 +628,8 @@ void MediaSource::endOfStream(const AtomicString& error,
DEFINE_STATIC_LOCAL(const AtomicString, network, ("network"));
DEFINE_STATIC_LOCAL(const AtomicString, decode, ("decode"));
+ BLINK_MSLOG << __func__ << " this=" << this << " : error=" << error;
+
// https://www.w3.org/TR/media-source/#dom-mediasource-endofstream
// 1. If the readyState attribute is not in the "open" state then throw an
// InvalidStateError exception and abort these steps.
@@ -649,6 +655,9 @@ void MediaSource::endOfStream(ExceptionState& exception_state) {
void MediaSource::setLiveSeekableRange(double start,
double end,
ExceptionState& exception_state) {
+ BLINK_MSLOG << __func__ << " this=" << this << " : start=" << start
+ << ", end=" << end;
+
// http://w3c.github.io/media-source/#widl-MediaSource-setLiveSeekableRange-void-double-start-double-end
// 1. If the readyState attribute is not "open" then throw an
// InvalidStateError exception and abort these steps.
@@ -678,6 +687,8 @@ void MediaSource::setLiveSeekableRange(double start,
}
void MediaSource::clearLiveSeekableRange(ExceptionState& exception_state) {
+ BLINK_MSLOG << __func__ << " this=" << this;
+
// http://w3c.github.io/media-source/#widl-MediaSource-clearLiveSeekableRange-void
// 1. If the readyState attribute is not "open" then throw an
// InvalidStateError exception and abort these steps.
@@ -795,8 +806,15 @@ void MediaSource::OpenIfInEndedState() {
}
bool MediaSource::HasPendingActivity() const {
- return attached_element_ || web_media_source_ ||
- async_event_queue_->HasPendingEvents() ||
+ // Note that an unrevoked MediaSource objectUrl for an otherwise inactive,
+ // unreferenced HTMLME with MSE still attached will prevent GC of the whole
+ // group of objects. This is unfortunate, because it's conceivable that the
+ // app may actually still have a "reference" to the underlying MediaSource if
+ // it has the objectUrl in a string somewhere, for example. This is yet
+ // further motivation for apps to properly revokeObjectUrl and for the MSE
+ // spec, implementations and API users to transition to using HTMLME srcObject
+ // for MSE attachment instead of objectUrl.
+ return async_event_queue_->HasPendingEvents() ||
added_to_registry_counter_ > 0;
}
diff --git a/chromium/third_party/blink/renderer/modules/mediasource/media_source.h b/chromium/third_party/blink/renderer/modules/mediasource/media_source.h
index 5cb42cf9b8b..bee9642de32 100644
--- a/chromium/third_party/blink/renderer/modules/mediasource/media_source.h
+++ b/chromium/third_party/blink/renderer/modules/mediasource/media_source.h
@@ -43,6 +43,7 @@
#include "third_party/blink/renderer/modules/mediasource/source_buffer.h"
#include "third_party/blink/renderer/modules/mediasource/source_buffer_list.h"
#include "third_party/blink/renderer/platform/bindings/exception_code.h"
+#include "third_party/blink/renderer/platform/bindings/trace_wrapper_member.h"
namespace blink {
@@ -147,10 +148,17 @@ class MediaSource final : public EventTargetWithInlineData,
std::unique_ptr<WebMediaSource> web_media_source_;
AtomicString ready_state_;
Member<EventQueue> async_event_queue_;
- Member<HTMLMediaElement> attached_element_;
- Member<SourceBufferList> source_buffers_;
- Member<SourceBufferList> active_source_buffers_;
+ // Here, using TraceWrapperMember, instead of Member, to keep
+ // |attached_element_|, |source_buffers_|, |active_source_buffers_|, and their
+ // wrappers from being collected if we are alive or traceable from a GC root.
+ // Activity by this MediaSource or on references to objects returned by
+ // exercising this MediaSource (such as an app manipulating a SourceBuffer
+ // retrieved via activeSourceBuffers()) may cause events to be dispatched by
+ // these other objects.
+ TraceWrapperMember<HTMLMediaElement> attached_element_;
+ TraceWrapperMember<SourceBufferList> source_buffers_;
+ TraceWrapperMember<SourceBufferList> active_source_buffers_;
Member<TimeRanges> live_seekable_range_;
diff --git a/chromium/third_party/blink/renderer/modules/mediasource/source_buffer.cc b/chromium/third_party/blink/renderer/modules/mediasource/source_buffer.cc
index c265d3370ba..3dadf5628df 100644
--- a/chromium/third_party/blink/renderer/modules/mediasource/source_buffer.cc
+++ b/chromium/third_party/blink/renderer/modules/mediasource/source_buffer.cc
@@ -56,6 +56,7 @@
#include "third_party/blink/renderer/platform/instrumentation/tracing/trace_event.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/functional.h"
#include "third_party/blink/renderer/platform/wtf/math_extras.h"
#ifndef BLINK_SBLOG
@@ -108,16 +109,14 @@ SourceBuffer* SourceBuffer::Create(
std::unique_ptr<WebSourceBuffer> web_source_buffer,
MediaSource* source,
EventQueue* async_event_queue) {
- SourceBuffer* source_buffer = MakeGarbageCollected<SourceBuffer>(
- std::move(web_source_buffer), source, async_event_queue);
- source_buffer->PauseIfNeeded();
- return source_buffer;
+ return MakeGarbageCollected<SourceBuffer>(std::move(web_source_buffer),
+ source, async_event_queue);
}
SourceBuffer::SourceBuffer(std::unique_ptr<WebSourceBuffer> web_source_buffer,
MediaSource* source,
EventQueue* async_event_queue)
- : PausableObject(source->GetExecutionContext()),
+ : ContextLifecycleObserver(source->GetExecutionContext()),
web_source_buffer_(std::move(web_source_buffer)),
source_(source),
track_defaults_(TrackDefaultList::Create()),
@@ -129,16 +128,8 @@ SourceBuffer::SourceBuffer(std::unique_ptr<WebSourceBuffer> web_source_buffer,
append_window_end_(std::numeric_limits<double>::infinity()),
first_initialization_segment_received_(false),
pending_append_data_offset_(0),
- append_buffer_async_part_runner_(AsyncMethodRunner<SourceBuffer>::Create(
- this,
- &SourceBuffer::AppendBufferAsyncPart,
- GetExecutionContext()->GetTaskRunner(TaskType::kMediaElementEvent))),
pending_remove_start_(-1),
- pending_remove_end_(-1),
- remove_async_part_runner_(AsyncMethodRunner<SourceBuffer>::Create(
- this,
- &SourceBuffer::RemoveAsyncPart,
- GetExecutionContext()->GetTaskRunner(TaskType::kMediaElementEvent))) {
+ pending_remove_end_(-1) {
BLINK_SBLOG << __func__ << " this=" << this;
DCHECK(web_source_buffer_);
@@ -171,7 +162,7 @@ const AtomicString& SourceBuffer::SequenceKeyword() {
void SourceBuffer::setMode(const AtomicString& new_mode,
ExceptionState& exception_state) {
- BLINK_SBLOG << __func__ << " this=" << this << " newMode=" << new_mode;
+ BLINK_SBLOG << __func__ << " this=" << this << " new_mode=" << new_mode;
// Section 3.1 On setting mode attribute steps.
// https://www.w3.org/TR/media-source/#dom-sourcebuffer-mode
// 1. If this object has been removed from the sourceBuffers attribute of the
@@ -514,7 +505,10 @@ void SourceBuffer::remove(double start,
// asynchronously.
pending_remove_start_ = start;
pending_remove_end_ = end;
- remove_async_part_runner_->RunAsync();
+ remove_async_task_handle_ = PostCancellableTask(
+ *GetExecutionContext()->GetTaskRunner(TaskType::kMediaElementEvent),
+ FROM_HERE,
+ WTF::Bind(&SourceBuffer::RemoveAsyncPart, WrapPersistent(this)));
}
void SourceBuffer::changeType(const String& type,
@@ -604,7 +598,7 @@ void SourceBuffer::setTrackDefaults(TrackDefaultList* track_defaults,
void SourceBuffer::CancelRemove() {
DCHECK(updating_);
DCHECK_NE(pending_remove_start_, -1);
- remove_async_part_runner_->Stop();
+ remove_async_task_handle_.Cancel();
pending_remove_start_ = -1;
pending_remove_end_ = -1;
updating_ = false;
@@ -630,7 +624,7 @@ void SourceBuffer::AbortIfUpdating() {
// 4.1. Abort the buffer append and stream append loop algorithms if they are
// running.
- append_buffer_async_part_runner_->Stop();
+ append_buffer_async_task_handle_.Cancel();
pending_append_data_.clear();
pending_append_data_offset_ = 0;
@@ -1152,26 +1146,19 @@ void SourceBuffer::NotifyParseWarning(const ParseWarning warning) {
}
bool SourceBuffer::HasPendingActivity() const {
- return source_;
-}
-
-void SourceBuffer::Pause() {
- append_buffer_async_part_runner_->Pause();
- remove_async_part_runner_->Pause();
-}
-
-void SourceBuffer::Unpause() {
- append_buffer_async_part_runner_->Unpause();
- remove_async_part_runner_->Unpause();
+ return updating_ || append_buffer_async_task_handle_.IsActive() ||
+ remove_async_task_handle_.IsActive() ||
+ (async_event_queue_ && async_event_queue_->HasPendingEvents());
}
void SourceBuffer::ContextDestroyed(ExecutionContext*) {
- append_buffer_async_part_runner_->Stop();
- remove_async_part_runner_->Stop();
+ append_buffer_async_task_handle_.Cancel();
+ remove_async_task_handle_.Cancel();
+ updating_ = false;
}
ExecutionContext* SourceBuffer::GetExecutionContext() const {
- return PausableObject::GetExecutionContext();
+ return ContextLifecycleObserver::GetExecutionContext();
}
const AtomicString& SourceBuffer::InterfaceName() const {
@@ -1297,7 +1284,10 @@ void SourceBuffer::AppendBufferInternal(double media_time,
ScheduleEvent(event_type_names::kUpdatestart);
// 5. Asynchronously run the buffer append algorithm.
- append_buffer_async_part_runner_->RunAsync();
+ append_buffer_async_task_handle_ = PostCancellableTask(
+ *GetExecutionContext()->GetTaskRunner(TaskType::kMediaElementEvent),
+ FROM_HERE,
+ WTF::Bind(&SourceBuffer::AppendBufferAsyncPart, WrapPersistent(this)));
TRACE_EVENT_ASYNC_STEP_INTO0("media", "SourceBuffer::appendBuffer", this,
"initialDelay");
@@ -1346,7 +1336,11 @@ void SourceBuffer::AppendBufferAsyncPart() {
pending_append_data_offset_ += append_size;
if (pending_append_data_offset_ < pending_append_data_.size()) {
- append_buffer_async_part_runner_->RunAsync();
+ append_buffer_async_task_handle_ = PostCancellableTask(
+ *GetExecutionContext()->GetTaskRunner(TaskType::kMediaElementEvent),
+ FROM_HERE,
+ WTF::Bind(&SourceBuffer::AppendBufferAsyncPart,
+ WrapPersistent(this)));
TRACE_EVENT_ASYNC_STEP_INTO0("media", "SourceBuffer::appendBuffer", this,
"nextPieceDelay");
return;
@@ -1427,12 +1421,10 @@ void SourceBuffer::Trace(blink::Visitor* visitor) {
visitor->Trace(source_);
visitor->Trace(track_defaults_);
visitor->Trace(async_event_queue_);
- visitor->Trace(append_buffer_async_part_runner_);
- visitor->Trace(remove_async_part_runner_);
visitor->Trace(audio_tracks_);
visitor->Trace(video_tracks_);
EventTargetWithInlineData::Trace(visitor);
- PausableObject::Trace(visitor);
+ ContextLifecycleObserver::Trace(visitor);
}
} // namespace blink
diff --git a/chromium/third_party/blink/renderer/modules/mediasource/source_buffer.h b/chromium/third_party/blink/renderer/modules/mediasource/source_buffer.h
index dcf697403ee..56117420814 100644
--- a/chromium/third_party/blink/renderer/modules/mediasource/source_buffer.h
+++ b/chromium/third_party/blink/renderer/modules/mediasource/source_buffer.h
@@ -34,11 +34,12 @@
#include <memory>
#include "third_party/blink/public/platform/web_source_buffer_client.h"
#include "third_party/blink/renderer/bindings/core/v8/active_script_wrappable.h"
-#include "third_party/blink/renderer/core/dom/pausable_object.h"
+#include "third_party/blink/renderer/core/dom/context_lifecycle_observer.h"
#include "third_party/blink/renderer/core/typed_arrays/array_buffer_view_helpers.h"
#include "third_party/blink/renderer/modules/event_target_modules.h"
#include "third_party/blink/renderer/modules/mediasource/track_default_list.h"
-#include "third_party/blink/renderer/platform/async_method_runner.h"
+#include "third_party/blink/renderer/platform/bindings/trace_wrapper_member.h"
+#include "third_party/blink/renderer/platform/scheduler/public/post_cancellable_task.h"
#include "third_party/blink/renderer/platform/weborigin/kurl.h"
#include "third_party/blink/renderer/platform/wtf/text/wtf_string.h"
@@ -56,7 +57,7 @@ class WebSourceBuffer;
class SourceBuffer final : public EventTargetWithInlineData,
public ActiveScriptWrappable<SourceBuffer>,
- public PausableObject,
+ public ContextLifecycleObserver,
public WebSourceBufferClient {
USING_GARBAGE_COLLECTED_MIXIN(SourceBuffer);
DEFINE_WRAPPERTYPEINFO();
@@ -105,9 +106,7 @@ class SourceBuffer final : public EventTargetWithInlineData,
// ScriptWrappable
bool HasPendingActivity() const final;
- // PausableObject
- void Pause() override;
- void Unpause() override;
+ // ContextLifecycleObserver
void ContextDestroyed(ExecutionContext*) override;
// EventTarget interface
@@ -157,26 +156,34 @@ class SourceBuffer final : public EventTargetWithInlineData,
const AtomicString& byte_stream_track_id) const;
std::unique_ptr<WebSourceBuffer> web_source_buffer_;
- Member<MediaSource> source_;
- Member<TrackDefaultList> track_defaults_;
+
+ // If any portion of an attached HTMLMediaElement (HTMLME) and the MediaSource
+ // Extensions (MSE) API is alive (having pending activity or traceable from a
+ // GC root), the whole group is not GC'ed. Here, using TraceWrapperMember,
+ // instead of Member, because |source_|'s and |track_defaults_|'s wrappers
+ // need to remain alive at least to successfully dispatch any events enqueued
+ // by the behavior of the HTMLME+MSE API. It makes those wrappers remain alive
+ // as long as this SourceBuffer's wrapper is alive.
+ TraceWrapperMember<MediaSource> source_;
+ TraceWrapperMember<TrackDefaultList> track_defaults_;
Member<EventQueue> async_event_queue_;
AtomicString mode_;
bool updating_;
double timestamp_offset_;
- Member<AudioTrackList> audio_tracks_;
- Member<VideoTrackList> video_tracks_;
+ TraceWrapperMember<AudioTrackList> audio_tracks_;
+ TraceWrapperMember<VideoTrackList> video_tracks_;
double append_window_start_;
double append_window_end_;
bool first_initialization_segment_received_;
Vector<unsigned char> pending_append_data_;
wtf_size_t pending_append_data_offset_;
- Member<AsyncMethodRunner<SourceBuffer>> append_buffer_async_part_runner_;
+ TaskHandle append_buffer_async_task_handle_;
double pending_remove_start_;
double pending_remove_end_;
- Member<AsyncMethodRunner<SourceBuffer>> remove_async_part_runner_;
+ TaskHandle remove_async_task_handle_;
};
} // namespace blink
diff --git a/chromium/third_party/blink/renderer/modules/mediasource/source_buffer_list.h b/chromium/third_party/blink/renderer/modules/mediasource/source_buffer_list.h
index 658138513c1..d011c0564dc 100644
--- a/chromium/third_party/blink/renderer/modules/mediasource/source_buffer_list.h
+++ b/chromium/third_party/blink/renderer/modules/mediasource/source_buffer_list.h
@@ -33,6 +33,7 @@
#include "third_party/blink/renderer/core/execution_context/execution_context.h"
#include "third_party/blink/renderer/modules/event_target_modules.h"
+#include "third_party/blink/renderer/platform/bindings/trace_wrapper_member.h"
#include "third_party/blink/renderer/platform/heap/handle.h"
namespace blink {
@@ -85,7 +86,23 @@ class SourceBufferList final : public EventTargetWithInlineData,
Member<EventQueue> async_event_queue_;
- HeapVector<Member<SourceBuffer>> list_;
+ // If any portion of an attached HTMLMediaElement (HTMLME) and the MediaSource
+ // Extensions (MSE) API is alive (having pending activity or traceable from a
+ // GC root), the whole group is not GC'ed. Here, using TraceWrapperMember,
+ // instead of Member, because the |list_|'s SourceBuffers' wrappers need to
+ // remain alive at least to successfully dispatch any events enqueued by
+ // behavior of the HTMLME+MSE API. TraceWrapperMember usage here keeps the
+ // SourceBuffers in |list_|, and their wrappers, from being collected if we
+ // are alive or traceable from a GC root.
+ // For instance, suppose the only reference to the group of HTMLME+MSE API
+ // objects is one held by the app to the wrapper of this SourceBufferList.
+ // The app could do any of a number of actions on any of the SourceBuffers in
+ // |list_|, such as appending more media, causing events to be enqueued for
+ // later dispatch on at least those SourceBuffers. None of the app's event
+ // listeners on objects in HTMLME+MSE are counted as references, but events
+ // pending for dispatch to them must keep the HTML+MSE group of objects alive
+ // through at least their dispatch.
+ HeapVector<TraceWrapperMember<SourceBuffer>> list_;
};
} // namespace blink