Commit 26653ee7 authored by Matt Wolenetz's avatar Matt Wolenetz Committed by Commit Bot

MSE-in-Workers: Introduce MediaSourceTracer

In preparation for moving the MediaSource core interface into the
MediaSourceAttachment interface, this change factors out a necessary
class for retaining the existing same-thread Oilpan collection of idle
unreferenced attached HTMLMediaElement+MediaSource object groups.

Specifically, adds MediaSourceTracer to specialize further in later
changes in modules concrete implementations how to handle Oilpan tracing
of an HTMLMediaElement and a MediaSource in same- versus cross-thread
attachments. Includes same-thread concrete specialization in this
change. Having this as a separate entity reduces complexity and
fragility on both of those sides of the attachment. Note that a same
thread non-oilpan concrete attachment cannot use "Member" since the
attachment class is unmanaged. Hence the need for this MediaSourceTracer
to encapsulate that "Member" linkage.

BUG=878133

Change-Id: I4153ade37a1d4303af2604c2c2e18f701a79834d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2363703Reviewed-by: default avatarPhilip Jägenstedt <foolip@chromium.org>
Commit-Queue: Matthew Wolenetz <wolenetz@chromium.org>
Cr-Commit-Position: refs/heads/master@{#800166}
parent e723d21d
...@@ -500,6 +500,8 @@ blink_core_sources("html") { ...@@ -500,6 +500,8 @@ blink_core_sources("html") {
"media/media_source_attachment.cc", "media/media_source_attachment.cc",
"media/media_source_attachment.h", "media/media_source_attachment.h",
"media/media_source_registry.h", "media/media_source_registry.h",
"media/media_source_tracer.cc",
"media/media_source_tracer.h",
"media/picture_in_picture_interstitial.cc", "media/picture_in_picture_interstitial.cc",
"media/picture_in_picture_interstitial.h", "media/picture_in_picture_interstitial.h",
"media/remote_playback_controller.cc", "media/remote_playback_controller.cc",
......
...@@ -76,6 +76,7 @@ ...@@ -76,6 +76,7 @@
#include "third_party/blink/renderer/core/html/media/media_fragment_uri_parser.h" #include "third_party/blink/renderer/core/html/media/media_fragment_uri_parser.h"
#include "third_party/blink/renderer/core/html/media/media_source.h" #include "third_party/blink/renderer/core/html/media/media_source.h"
#include "third_party/blink/renderer/core/html/media/media_source_attachment.h" #include "third_party/blink/renderer/core/html/media/media_source_attachment.h"
#include "third_party/blink/renderer/core/html/media/media_source_tracer.h"
#include "third_party/blink/renderer/core/html/time_ranges.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.h"
#include "third_party/blink/renderer/core/html/track/audio_track_list.h" #include "third_party/blink/renderer/core/html/track/audio_track_list.h"
...@@ -1196,12 +1197,14 @@ void HTMLMediaElement::LoadResource(const WebMediaPlayerSource& source, ...@@ -1196,12 +1197,14 @@ void HTMLMediaElement::LoadResource(const WebMediaPlayerSource& source,
SetPlayerPreload(); SetPlayerPreload();
DCHECK(!media_source_); DCHECK(!media_source_);
DCHECK(!media_source_tracer_);
bool attempt_load = true; bool attempt_load = true;
media_source_ = MediaSourceAttachment::LookupMediaSource(url.GetString()); media_source_ = MediaSourceAttachment::LookupMediaSource(url.GetString());
if (media_source_) { if (media_source_) {
if (media_source_->StartAttachingToMediaElement(this)) { media_source_tracer_ = media_source_->StartAttachingToMediaElement(this);
if (media_source_tracer_) {
// 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
...@@ -2633,6 +2636,7 @@ void HTMLMediaElement::CloseMediaSource() { ...@@ -2633,6 +2636,7 @@ void HTMLMediaElement::CloseMediaSource() {
media_source_->Close(); media_source_->Close();
media_source_ = nullptr; media_source_ = nullptr;
media_source_tracer_ = nullptr;
} }
bool HTMLMediaElement::Loop() const { bool HTMLMediaElement::Loop() const {
...@@ -4057,6 +4061,7 @@ void HTMLMediaElement::Trace(Visitor* visitor) const { ...@@ -4057,6 +4061,7 @@ void HTMLMediaElement::Trace(Visitor* visitor) const {
visitor->Trace(current_source_node_); visitor->Trace(current_source_node_);
visitor->Trace(next_child_node_to_consider_); visitor->Trace(next_child_node_to_consider_);
visitor->Trace(media_source_); visitor->Trace(media_source_);
visitor->Trace(media_source_tracer_);
visitor->Trace(audio_tracks_); visitor->Trace(audio_tracks_);
visitor->Trace(video_tracks_); visitor->Trace(video_tracks_);
visitor->Trace(cue_timeline_); visitor->Trace(cue_timeline_);
......
...@@ -66,6 +66,7 @@ class EventQueue; ...@@ -66,6 +66,7 @@ class EventQueue;
class ExceptionState; class ExceptionState;
class HTMLMediaElementControlsList; class HTMLMediaElementControlsList;
class MediaSource; class MediaSource;
class MediaSourceTracer;
class HTMLSourceElement; class HTMLSourceElement;
class HTMLTrackElement; class HTMLTrackElement;
class MediaError; class MediaError;
...@@ -631,6 +632,7 @@ class CORE_EXPORT HTMLMediaElement ...@@ -631,6 +632,7 @@ class CORE_EXPORT HTMLMediaElement
cc::Layer* cc_layer_; cc::Layer* cc_layer_;
Member<MediaSource> media_source_; Member<MediaSource> media_source_;
Member<MediaSourceTracer> media_source_tracer_;
// Stores "official playback position", updated periodically from "current // Stores "official playback position", updated periodically from "current
// playback position". Official playback position should not change while // playback position". Official playback position should not change while
......
...@@ -34,6 +34,7 @@ ...@@ -34,6 +34,7 @@
#include <memory> #include <memory>
#include "third_party/blink/public/platform/web_time_range.h" #include "third_party/blink/public/platform/web_time_range.h"
#include "third_party/blink/renderer/core/core_export.h" #include "third_party/blink/renderer/core/core_export.h"
#include "third_party/blink/renderer/core/html/media/media_source_tracer.h"
#include "third_party/blink/renderer/platform/heap/handle.h" #include "third_party/blink/renderer/platform/heap/handle.h"
#include "third_party/blink/renderer/platform/wtf/forward.h" #include "third_party/blink/renderer/platform/wtf/forward.h"
...@@ -61,9 +62,11 @@ class CORE_EXPORT MediaSource : public GarbageCollectedMixin { ...@@ -61,9 +62,11 @@ class CORE_EXPORT MediaSource : public GarbageCollectedMixin {
// attempting to attach to this object. The WebMediaSource is not available // attempting to attach to this object. The WebMediaSource is not available
// to the element initially, so between the two calls, the attachment could be // to the element initially, so between the two calls, the attachment could be
// considered partially setup. // considered partially setup.
// If already attached, StartAttachingToMediaElement() returns false. // If already attached, StartAttachingToMediaElement() returns nullptr.
// Otherwise, must be in 'closed' state, and returns true to indicate // Otherwise, must be in 'closed' state, and indicates success by returning a
// attachment success. // tracer object useful in at least same-thread attachments for enabling
// automatic idle unreferenced same-thread attachment object garbage
// collection.
// CompleteAttachingToMediaElement() provides the MediaSource with the // CompleteAttachingToMediaElement() provides the MediaSource with the
// underlying WebMediaSource, enabling parsing of media provided by the // underlying WebMediaSource, enabling parsing of media provided by the
// application for playback, for example. // application for playback, for example.
...@@ -71,7 +74,8 @@ class CORE_EXPORT MediaSource : public GarbageCollectedMixin { ...@@ -71,7 +74,8 @@ class CORE_EXPORT MediaSource : public GarbageCollectedMixin {
// '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 StartAttachingToMediaElement(HTMLMediaElement*) = 0; virtual MediaSourceTracer* StartAttachingToMediaElement(
HTMLMediaElement*) = 0;
virtual void CompleteAttachingToMediaElement( virtual void CompleteAttachingToMediaElement(
std::unique_ptr<WebMediaSource>) = 0; std::unique_ptr<WebMediaSource>) = 0;
......
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "third_party/blink/renderer/core/html/media/media_source_tracer.h"
namespace blink {
void MediaSourceTracer::Trace(Visitor* visitor) const {}
} // namespace blink
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef THIRD_PARTY_BLINK_RENDERER_CORE_HTML_MEDIA_MEDIA_SOURCE_TRACER_H_
#define THIRD_PARTY_BLINK_RENDERER_CORE_HTML_MEDIA_MEDIA_SOURCE_TRACER_H_
#include "third_party/blink/renderer/core/core_export.h"
#include "third_party/blink/renderer/platform/heap/handle.h"
namespace blink {
// Interface that encapsulates the Oilpan tracing of either same-thread or
// cross-thread attachment of an HTMLMediaElement and MediaSource, necessary
// since MediaSourceAttachments themselves are not managed by Oilpan. See
// concrete implementation(s) in modules/mediasource.
class CORE_EXPORT MediaSourceTracer
: public GarbageCollected<MediaSourceTracer> {
public:
virtual ~MediaSourceTracer() = default;
virtual void Trace(Visitor*) const;
};
} // namespace blink
#endif // THIRD_PARTY_BLINK_RENDERER_CORE_HTML_MEDIA_MEDIA_SOURCE_TRACER_H_
...@@ -12,6 +12,8 @@ blink_modules_sources("mediasource") { ...@@ -12,6 +12,8 @@ blink_modules_sources("mediasource") {
"media_source_impl.h", "media_source_impl.h",
"media_source_registry_impl.cc", "media_source_registry_impl.cc",
"media_source_registry_impl.h", "media_source_registry_impl.h",
"media_source_tracer_impl.cc",
"media_source_tracer_impl.h",
"source_buffer.cc", "source_buffer.cc",
"source_buffer.h", "source_buffer.h",
"source_buffer_list.cc", "source_buffer_list.cc",
......
...@@ -43,6 +43,7 @@ ...@@ -43,6 +43,7 @@
#include "third_party/blink/renderer/core/html/media/html_media_element.h" #include "third_party/blink/renderer/core/html/media/html_media_element.h"
#include "third_party/blink/renderer/core/html/track/audio_track_list.h" #include "third_party/blink/renderer/core/html/track/audio_track_list.h"
#include "third_party/blink/renderer/core/html/track/video_track_list.h" #include "third_party/blink/renderer/core/html/track/video_track_list.h"
#include "third_party/blink/renderer/modules/mediasource/media_source_tracer_impl.h"
#include "third_party/blink/renderer/modules/mediasource/source_buffer_track_base_supplement.h" #include "third_party/blink/renderer/modules/mediasource/source_buffer_track_base_supplement.h"
#include "third_party/blink/renderer/platform/bindings/exception_messages.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/bindings/exception_state.h"
...@@ -831,9 +832,10 @@ void MediaSourceImpl::Close() { ...@@ -831,9 +832,10 @@ void MediaSourceImpl::Close() {
SetReadyState(ClosedKeyword()); SetReadyState(ClosedKeyword());
} }
bool MediaSourceImpl::StartAttachingToMediaElement(HTMLMediaElement* element) { MediaSourceTracer* MediaSourceImpl::StartAttachingToMediaElement(
HTMLMediaElement* element) {
if (attached_element_) if (attached_element_)
return false; return nullptr;
DCHECK(IsClosed()); DCHECK(IsClosed());
...@@ -841,7 +843,7 @@ bool MediaSourceImpl::StartAttachingToMediaElement(HTMLMediaElement* element) { ...@@ -841,7 +843,7 @@ bool MediaSourceImpl::StartAttachingToMediaElement(HTMLMediaElement* element) {
"media", "MediaSourceImpl::StartAttachingToMediaElement", "media", "MediaSourceImpl::StartAttachingToMediaElement",
TRACE_ID_LOCAL(this)); TRACE_ID_LOCAL(this));
attached_element_ = element; attached_element_ = element;
return true; return MakeGarbageCollected<MediaSourceTracerImpl>(element, this);
} }
void MediaSourceImpl::OpenIfInEndedState() { void MediaSourceImpl::OpenIfInEndedState() {
......
...@@ -37,6 +37,7 @@ ...@@ -37,6 +37,7 @@
#include "third_party/blink/renderer/bindings/core/v8/active_script_wrappable.h" #include "third_party/blink/renderer/bindings/core/v8/active_script_wrappable.h"
#include "third_party/blink/renderer/core/execution_context/execution_context_lifecycle_observer.h" #include "third_party/blink/renderer/core/execution_context/execution_context_lifecycle_observer.h"
#include "third_party/blink/renderer/core/html/media/media_source.h" #include "third_party/blink/renderer/core/html/media/media_source.h"
#include "third_party/blink/renderer/core/html/media/media_source_tracer.h"
#include "third_party/blink/renderer/core/html/time_ranges.h" #include "third_party/blink/renderer/core/html/time_ranges.h"
#include "third_party/blink/renderer/modules/event_target_modules.h" #include "third_party/blink/renderer/modules/event_target_modules.h"
#include "third_party/blink/renderer/modules/mediasource/source_buffer.h" #include "third_party/blink/renderer/modules/mediasource/source_buffer.h"
...@@ -92,7 +93,7 @@ class MediaSourceImpl final : public EventTargetWithInlineData, ...@@ -92,7 +93,7 @@ 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 StartAttachingToMediaElement(HTMLMediaElement*) override; MediaSourceTracer* StartAttachingToMediaElement(HTMLMediaElement*) override;
void CompleteAttachingToMediaElement( void CompleteAttachingToMediaElement(
std::unique_ptr<WebMediaSource>) override; std::unique_ptr<WebMediaSource>) override;
void Close() override; void Close() override;
......
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "third_party/blink/renderer/modules/mediasource/media_source_tracer_impl.h"
#include "third_party/blink/renderer/core/html/media/html_media_element.h"
#include "third_party/blink/renderer/modules/mediasource/media_source_impl.h"
namespace blink {
MediaSourceTracerImpl::MediaSourceTracerImpl(HTMLMediaElement* media_element,
MediaSourceImpl* media_source)
: media_element_(media_element), media_source_(media_source) {}
void MediaSourceTracerImpl::Trace(Visitor* visitor) const {
visitor->Trace(media_element_);
visitor->Trace(media_source_);
MediaSourceTracer::Trace(visitor);
}
} // namespace blink
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef THIRD_PARTY_BLINK_RENDERER_MODULES_MEDIASOURCE_MEDIA_SOURCE_TRACER_IMPL_H_
#define THIRD_PARTY_BLINK_RENDERER_MODULES_MEDIASOURCE_MEDIA_SOURCE_TRACER_IMPL_H_
#include "third_party/blink/renderer/core/html/media/media_source_tracer.h"
#include "third_party/blink/renderer/platform/heap/handle.h"
namespace blink {
class HTMLMediaElement;
class MediaSourceImpl;
// Concrete MediaSourceTracer that enables an HTMLMediaElement and its attached
// MediaSourceImpl on the same (main) thread to trace into each other. This
// enables garbage collection to automatically detect and collect idle
// attachments of these objects that have no other strong references.
class MediaSourceTracerImpl final : public MediaSourceTracer {
public:
MediaSourceTracerImpl(HTMLMediaElement* media_element,
MediaSourceImpl* media_source);
~MediaSourceTracerImpl() override = default;
void Trace(Visitor* visitor) const override;
private:
Member<HTMLMediaElement> media_element_;
Member<MediaSourceImpl> media_source_;
};
} // namespace blink
#endif // THIRD_PARTY_BLINK_RENDERER_MODULES_MEDIASOURCE_MEDIA_SOURCE_TRACER_IMPL_H_
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