Commit 1dc621e4 authored by Matt Wolenetz's avatar Matt Wolenetz Committed by Commit Bot

MSE: Rename and clarify the MediaSource attachment methods

AttachToElement() name was unclear: while it technically attaches the
MediaSource to the Element, the underlying MediaSource cannot be used
for appending media, etc. by the app until it is opened with a call to
SetWebMediaSourceAndOpen().

This change renames these two methods, respectively, to
{Start,Complete}AttachingToMediaElement(), along with some comment
updates. Actual function remains unchanged.

This clarification CL is expected to improve readability and review,
especially of the in-progress MSE-in-Workers CLs.

BUG=878133

Change-Id: Ic726cbee71d92e82a5a8c7d3be7d8d9185d1fb76
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2079384Reviewed-by: default avatarPhilip Jägenstedt <foolip@chromium.org>
Reviewed-by: default avatarMounir Lamouri <mlamouri@chromium.org>
Commit-Queue: Matthew Wolenetz <wolenetz@chromium.org>
Cr-Commit-Position: refs/heads/master@{#745588}
parent dbb1c14f
...@@ -1192,7 +1192,7 @@ void HTMLMediaElement::LoadResource(const WebMediaPlayerSource& source, ...@@ -1192,7 +1192,7 @@ void HTMLMediaElement::LoadResource(const WebMediaPlayerSource& source,
media_source_ = MediaSource::Lookup(url.GetString()); media_source_ = MediaSource::Lookup(url.GetString());
if (media_source_) { if (media_source_) {
if (media_source_->AttachToElement(this)) { if (media_source_->StartAttachingToMediaElement(this)) {
// If the associated feature is enabled, auto-revoke the MediaSource // If the associated feature is enabled, auto-revoke the MediaSource
// object URL that was used for attachment on successful (start of) // object URL that was used for attachment on successful (start of)
// attachment. This can help reduce memory bloat later if the app does not // attachment. This can help reduce memory bloat later if the app does not
...@@ -3992,7 +3992,8 @@ void HTMLMediaElement::SetCcLayer(cc::Layer* cc_layer) { ...@@ -3992,7 +3992,8 @@ void HTMLMediaElement::SetCcLayer(cc::Layer* cc_layer) {
void HTMLMediaElement::MediaSourceOpened(WebMediaSource* web_media_source) { void HTMLMediaElement::MediaSourceOpened(WebMediaSource* web_media_source) {
SetShouldDelayLoadEvent(false); SetShouldDelayLoadEvent(false);
media_source_->SetWebMediaSourceAndOpen(base::WrapUnique(web_media_source)); media_source_->CompleteAttachingToMediaElement(
base::WrapUnique(web_media_source));
} }
bool HTMLMediaElement::IsInteractiveContent() const { bool HTMLMediaElement::IsInteractiveContent() const {
......
...@@ -54,16 +54,24 @@ class CORE_EXPORT MediaSource : public URLRegistrable, ...@@ -54,16 +54,24 @@ class CORE_EXPORT MediaSource : public URLRegistrable,
: nullptr; : nullptr;
} }
// Called when an HTMLMediaElement is attempting to attach to this object, // These two methods are called in sequence when an HTMLMediaElement is
// and helps enforce attachment to at most one element at a time. // attempting to attach to this object. The WebMediaSource is not available
// If already attached, returns false. Otherwise, must be in // to the element initially, so between the two calls, the attachment could be
// 'closed' state, and returns true to indicate attachment success. // considered partially setup.
// If already attached, StartAttachingToMediaElement() returns false.
// Otherwise, must be in 'closed' state, and returns true to indicate
// attachment success.
// CompleteAttachingToMediaElement() provides the MediaSource with the
// underlying WebMediaSource, enabling parsing of media provided by the
// application for playback, for example.
// Reattachment allowed by first calling close() (even if already in // Reattachment allowed by first calling close() (even if already in
// 'closed'). // 'closed').
// Once attached, the source uses the element to synchronously service some // Once attached, the source uses the element to synchronously service some
// API operations like duration change that may need to initiate seek. // API operations like duration change that may need to initiate seek.
virtual bool AttachToElement(HTMLMediaElement*) = 0; virtual bool StartAttachingToMediaElement(HTMLMediaElement*) = 0;
virtual void SetWebMediaSourceAndOpen(std::unique_ptr<WebMediaSource>) = 0; virtual void CompleteAttachingToMediaElement(
std::unique_ptr<WebMediaSource>) = 0;
virtual void Close() = 0; virtual void Close() = 0;
virtual bool IsClosed() const = 0; virtual bool IsClosed() const = 0;
virtual double duration() const = 0; virtual double duration() const = 0;
......
...@@ -401,10 +401,11 @@ void MediaSourceImpl::Trace(Visitor* visitor) { ...@@ -401,10 +401,11 @@ void MediaSourceImpl::Trace(Visitor* visitor) {
ExecutionContextLifecycleObserver::Trace(visitor); ExecutionContextLifecycleObserver::Trace(visitor);
} }
void MediaSourceImpl::SetWebMediaSourceAndOpen( void MediaSourceImpl::CompleteAttachingToMediaElement(
std::unique_ptr<WebMediaSource> web_media_source) { std::unique_ptr<WebMediaSource> web_media_source) {
TRACE_EVENT_NESTABLE_ASYNC_END0("media", "MediaSourceImpl::attachToElement", TRACE_EVENT_NESTABLE_ASYNC_END0(
TRACE_ID_LOCAL(this)); "media", "MediaSourceImpl::StartAttachingToMediaElement",
TRACE_ID_LOCAL(this));
DCHECK(web_media_source); DCHECK(web_media_source);
DCHECK(!web_media_source_); DCHECK(!web_media_source_);
DCHECK(attached_element_); DCHECK(attached_element_);
...@@ -843,14 +844,15 @@ void MediaSourceImpl::Close() { ...@@ -843,14 +844,15 @@ void MediaSourceImpl::Close() {
SetReadyState(ClosedKeyword()); SetReadyState(ClosedKeyword());
} }
bool MediaSourceImpl::AttachToElement(HTMLMediaElement* element) { bool MediaSourceImpl::StartAttachingToMediaElement(HTMLMediaElement* element) {
if (attached_element_) if (attached_element_)
return false; return false;
DCHECK(IsClosed()); DCHECK(IsClosed());
TRACE_EVENT_NESTABLE_ASYNC_BEGIN0("media", "MediaSourceImpl::attachToElement", TRACE_EVENT_NESTABLE_ASYNC_BEGIN0(
TRACE_ID_LOCAL(this)); "media", "MediaSourceImpl::StartAttachingToMediaElement",
TRACE_ID_LOCAL(this));
attached_element_ = element; attached_element_ = element;
return true; return true;
} }
......
...@@ -94,8 +94,9 @@ class MediaSourceImpl final : public EventTargetWithInlineData, ...@@ -94,8 +94,9 @@ class MediaSourceImpl final : public EventTargetWithInlineData,
static bool isTypeSupported(const String& type); static bool isTypeSupported(const String& type);
// html/media/MediaSource interface implementation // html/media/MediaSource interface implementation
bool AttachToElement(HTMLMediaElement*) override; bool StartAttachingToMediaElement(HTMLMediaElement*) override;
void SetWebMediaSourceAndOpen(std::unique_ptr<WebMediaSource>) override; void CompleteAttachingToMediaElement(
std::unique_ptr<WebMediaSource>) override;
void Close() override; void Close() override;
bool IsClosed() const override; bool IsClosed() const override;
double duration() const override; double duration() const override;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment