Commit be012631 authored by Matt Wolenetz's avatar Matt Wolenetz Committed by Commit Bot

MSE-in-Workers: Use enums or strings instead of thread-specific AtomicStrings

AtomicString statics are bound to the thread where they were
initialized. This change switches MSE implementation to instead use
enums or non-thread-specific strings, in anticipation of upcoming usage
of MSE in either the main thread or dedicated worker threads. Longer
term, similar will be needed for core/html/track objects, though we may
instead switch to using prepopulated, valid-everywhere, AtomicStrings at
that point (when the cross-thread MSE implementation has stabilized enough to
get AudioVideoTracks feature working fully when using MSE in worker).

BUG=878133

Change-Id: I37f973d5175deb7bce6b96106e0a30bd6fa15ceb
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2417452Reviewed-by: default avatarWill Cassella <cassew@google.com>
Commit-Queue: Matthew Wolenetz <wolenetz@chromium.org>
Cr-Commit-Position: refs/heads/master@{#808549}
parent 4e687e01
...@@ -54,6 +54,23 @@ enum class MseExecutionContext { ...@@ -54,6 +54,23 @@ enum class MseExecutionContext {
}; };
} // namespace } // namespace
static AtomicString ReadyStateToString(MediaSource::ReadyState state) {
AtomicString result;
switch (state) {
case MediaSource::ReadyState::kOpen:
result = "open";
break;
case MediaSource::ReadyState::kClosed:
result = "closed";
break;
case MediaSource::ReadyState::kEnded:
result = "ended";
break;
}
return result;
}
static bool ThrowExceptionIfClosed(bool is_open, static bool ThrowExceptionIfClosed(bool is_open,
ExceptionState& exception_state) { ExceptionState& exception_state) {
if (!is_open) { if (!is_open) {
...@@ -83,28 +100,13 @@ static bool ThrowExceptionIfClosedOrUpdating(bool is_open, ...@@ -83,28 +100,13 @@ static bool ThrowExceptionIfClosedOrUpdating(bool is_open,
return false; return false;
} }
const AtomicString& MediaSource::OpenKeyword() {
DEFINE_STATIC_LOCAL(const AtomicString, open, ("open"));
return open;
}
const AtomicString& MediaSource::ClosedKeyword() {
DEFINE_STATIC_LOCAL(const AtomicString, closed, ("closed"));
return closed;
}
const AtomicString& MediaSource::EndedKeyword() {
DEFINE_STATIC_LOCAL(const AtomicString, ended, ("ended"));
return ended;
}
MediaSource* MediaSource::Create(ExecutionContext* context) { MediaSource* MediaSource::Create(ExecutionContext* context) {
return MakeGarbageCollected<MediaSource>(context); return MakeGarbageCollected<MediaSource>(context);
} }
MediaSource::MediaSource(ExecutionContext* context) MediaSource::MediaSource(ExecutionContext* context)
: ExecutionContextLifecycleObserver(context), : ExecutionContextLifecycleObserver(context),
ready_state_(ClosedKeyword()), ready_state_(ReadyState::kClosed),
async_event_queue_( async_event_queue_(
MakeGarbageCollected<EventQueue>(context, MakeGarbageCollected<EventQueue>(context,
TaskType::kMediaElementEvent)), TaskType::kMediaElementEvent)),
...@@ -271,14 +273,14 @@ void MediaSource::removeSourceBuffer(SourceBuffer* buffer, ...@@ -271,14 +273,14 @@ void MediaSource::removeSourceBuffer(SourceBuffer* buffer,
// SourceBuffer::removedFromMediaSource (steps 2-8) above. // SourceBuffer::removedFromMediaSource (steps 2-8) above.
} }
void MediaSource::OnReadyStateChange(const AtomicString& old_state, void MediaSource::OnReadyStateChange(const ReadyState old_state,
const AtomicString& new_state) { const ReadyState new_state) {
if (IsOpen()) { if (IsOpen()) {
ScheduleEvent(event_type_names::kSourceopen); ScheduleEvent(event_type_names::kSourceopen);
return; return;
} }
if (old_state == OpenKeyword() && new_state == EndedKeyword()) { if (old_state == ReadyState::kOpen && new_state == ReadyState::kEnded) {
ScheduleEvent(event_type_names::kSourceended); ScheduleEvent(event_type_names::kSourceended);
return; return;
} }
...@@ -408,7 +410,7 @@ void MediaSource::CompleteAttachingToMediaElement( ...@@ -408,7 +410,7 @@ void MediaSource::CompleteAttachingToMediaElement(
DCHECK(attachment_tracer_); DCHECK(attachment_tracer_);
web_media_source_ = std::move(web_media_source); web_media_source_ = std::move(web_media_source);
SetReadyState(OpenKeyword()); SetReadyState(ReadyState::kOpen);
} }
double MediaSource::duration() const { double MediaSource::duration() const {
...@@ -449,7 +451,7 @@ WebTimeRanges MediaSource::BufferedInternal() const { ...@@ -449,7 +451,7 @@ WebTimeRanges MediaSource::BufferedInternal() const {
// 5. For each SourceBuffer object in activeSourceBuffers run the following // 5. For each SourceBuffer object in activeSourceBuffers run the following
// steps: // steps:
bool ended = readyState() == EndedKeyword(); bool ended = ready_state_ == ReadyState::kEnded;
// 5.1 Let source ranges equal the ranges returned by the buffered attribute // 5.1 Let source ranges equal the ranges returned by the buffered attribute
// on the current SourceBuffer. // on the current SourceBuffer.
for (WebTimeRanges& source_ranges : ranges) { for (WebTimeRanges& source_ranges : ranges) {
...@@ -649,15 +651,16 @@ void MediaSource::DurationChangeAlgorithm(double new_duration, ...@@ -649,15 +651,16 @@ void MediaSource::DurationChangeAlgorithm(double new_duration,
new_duration); new_duration);
} }
void MediaSource::SetReadyState(const AtomicString& state) { void MediaSource::SetReadyState(const ReadyState state) {
DCHECK(state == OpenKeyword() || state == ClosedKeyword() || DCHECK(state == ReadyState::kOpen || state == ReadyState::kClosed ||
state == EndedKeyword()); state == ReadyState::kEnded);
AtomicString old_state = readyState(); ReadyState old_state = ready_state_;
DVLOG(3) << __func__ << " this=" << this << " : " << old_state << " -> " DVLOG(3) << __func__ << " this=" << this << " : "
<< state; << ReadyStateToString(old_state) << " -> "
<< ReadyStateToString(state);
if (state == ClosedKeyword()) { if (state == ReadyState::kClosed) {
web_media_source_.reset(); web_media_source_.reset();
} }
...@@ -669,11 +672,12 @@ void MediaSource::SetReadyState(const AtomicString& state) { ...@@ -669,11 +672,12 @@ void MediaSource::SetReadyState(const AtomicString& state) {
OnReadyStateChange(old_state, state); OnReadyStateChange(old_state, state);
} }
AtomicString MediaSource::readyState() const {
return ReadyStateToString(ready_state_);
}
void MediaSource::endOfStream(const AtomicString& error, void MediaSource::endOfStream(const AtomicString& error,
ExceptionState& exception_state) { ExceptionState& exception_state) {
DEFINE_STATIC_LOCAL(const AtomicString, network, ("network"));
DEFINE_STATIC_LOCAL(const AtomicString, decode, ("decode"));
DVLOG(3) << __func__ << " this=" << this << " : error=" << error; DVLOG(3) << __func__ << " this=" << this << " : error=" << error;
// https://www.w3.org/TR/media-source/#dom-mediasource-endofstream // https://www.w3.org/TR/media-source/#dom-mediasource-endofstream
...@@ -686,9 +690,9 @@ void MediaSource::endOfStream(const AtomicString& error, ...@@ -686,9 +690,9 @@ void MediaSource::endOfStream(const AtomicString& error,
return; return;
// 3. Run the end of stream algorithm with the error parameter set to error. // 3. Run the end of stream algorithm with the error parameter set to error.
if (error == network) if (error == "network")
EndOfStreamAlgorithm(WebMediaSource::kEndOfStreamStatusNetworkError); EndOfStreamAlgorithm(WebMediaSource::kEndOfStreamStatusNetworkError);
else if (error == decode) else if (error == "decode")
EndOfStreamAlgorithm(WebMediaSource::kEndOfStreamStatusDecodeError); EndOfStreamAlgorithm(WebMediaSource::kEndOfStreamStatusDecodeError);
else // "" is allowed internally but not by IDL bindings. else // "" is allowed internally but not by IDL bindings.
EndOfStreamAlgorithm(WebMediaSource::kEndOfStreamStatusNoError); EndOfStreamAlgorithm(WebMediaSource::kEndOfStreamStatusNoError);
...@@ -753,7 +757,7 @@ void MediaSource::clearLiveSeekableRange(ExceptionState& exception_state) { ...@@ -753,7 +757,7 @@ void MediaSource::clearLiveSeekableRange(ExceptionState& exception_state) {
} }
bool MediaSource::IsOpen() const { bool MediaSource::IsOpen() const {
return readyState() == OpenKeyword(); return ready_state_ == ReadyState::kOpen;
} }
void MediaSource::SetSourceBufferActive(SourceBuffer* source_buffer, void MediaSource::SetSourceBufferActive(SourceBuffer* source_buffer,
...@@ -803,7 +807,7 @@ void MediaSource::EndOfStreamAlgorithm( ...@@ -803,7 +807,7 @@ void MediaSource::EndOfStreamAlgorithm(
// 1. Change the readyState attribute value to "ended". // 1. Change the readyState attribute value to "ended".
// 2. Queue a task to fire a simple event named sourceended at the // 2. Queue a task to fire a simple event named sourceended at the
// MediaSource. // MediaSource.
SetReadyState(EndedKeyword()); SetReadyState(ReadyState::kEnded);
// 3. Do various steps based on |eos_status|. // 3. Do various steps based on |eos_status|.
web_media_source_->MarkEndOfStream(eos_status); web_media_source_->MarkEndOfStream(eos_status);
...@@ -833,11 +837,11 @@ void MediaSource::EndOfStreamAlgorithm( ...@@ -833,11 +837,11 @@ void MediaSource::EndOfStreamAlgorithm(
} }
bool MediaSource::IsClosed() const { bool MediaSource::IsClosed() const {
return readyState() == ClosedKeyword(); return ready_state_ == ReadyState::kClosed;
} }
void MediaSource::Close() { void MediaSource::Close() {
SetReadyState(ClosedKeyword()); SetReadyState(ReadyState::kClosed);
} }
MediaSourceTracer* MediaSource::StartAttachingToMediaElement( MediaSourceTracer* MediaSource::StartAttachingToMediaElement(
...@@ -864,10 +868,10 @@ MediaSourceTracer* MediaSource::StartAttachingToMediaElement( ...@@ -864,10 +868,10 @@ MediaSourceTracer* MediaSource::StartAttachingToMediaElement(
} }
void MediaSource::OpenIfInEndedState() { void MediaSource::OpenIfInEndedState() {
if (ready_state_ != EndedKeyword()) if (ready_state_ != ReadyState::kEnded)
return; return;
SetReadyState(OpenKeyword()); SetReadyState(ReadyState::kOpen);
web_media_source_->UnmarkEndOfStream(); web_media_source_->UnmarkEndOfStream();
} }
...@@ -887,7 +891,7 @@ void MediaSource::ContextDestroyed() { ...@@ -887,7 +891,7 @@ void MediaSource::ContextDestroyed() {
if (media_source_attachment_) if (media_source_attachment_)
media_source_attachment_->OnMediaSourceContextDestroyed(); media_source_attachment_->OnMediaSourceContextDestroyed();
if (!IsClosed()) if (!IsClosed())
SetReadyState(ClosedKeyword()); SetReadyState(ReadyState::kClosed);
web_media_source_.reset(); web_media_source_.reset();
} }
......
...@@ -46,9 +46,7 @@ class MediaSource final : public EventTargetWithInlineData, ...@@ -46,9 +46,7 @@ class MediaSource final : public EventTargetWithInlineData,
DEFINE_WRAPPERTYPEINFO(); DEFINE_WRAPPERTYPEINFO();
public: public:
static const AtomicString& OpenKeyword(); enum class ReadyState { kOpen, kClosed, kEnded };
static const AtomicString& ClosedKeyword();
static const AtomicString& EndedKeyword();
static MediaSource* Create(ExecutionContext*); static MediaSource* Create(ExecutionContext*);
...@@ -73,7 +71,7 @@ class MediaSource final : public EventTargetWithInlineData, ...@@ -73,7 +71,7 @@ class MediaSource final : public EventTargetWithInlineData,
DEFINE_ATTRIBUTE_EVENT_LISTENER(sourceended, kSourceended) DEFINE_ATTRIBUTE_EVENT_LISTENER(sourceended, kSourceended)
DEFINE_ATTRIBUTE_EVENT_LISTENER(sourceclose, kSourceclose) DEFINE_ATTRIBUTE_EVENT_LISTENER(sourceclose, kSourceclose)
const AtomicString& readyState() const { return ready_state_; } AtomicString readyState() const;
void endOfStream(const AtomicString& error, ExceptionState&); void endOfStream(const AtomicString& error, ExceptionState&);
void endOfStream(ExceptionState&); void endOfStream(ExceptionState&);
void setLiveSeekableRange(double start, double end, ExceptionState&); void setLiveSeekableRange(double start, double end, ExceptionState&);
...@@ -117,8 +115,9 @@ class MediaSource final : public EventTargetWithInlineData, ...@@ -117,8 +115,9 @@ class MediaSource final : public EventTargetWithInlineData,
void Trace(Visitor*) const override; void Trace(Visitor*) const override;
private: private:
void SetReadyState(const AtomicString&); void SetReadyState(const ReadyState state);
void OnReadyStateChange(const AtomicString&, const AtomicString&); void OnReadyStateChange(const ReadyState old_state,
const ReadyState new_state);
bool IsUpdating() const; bool IsUpdating() const;
...@@ -135,7 +134,7 @@ class MediaSource final : public EventTargetWithInlineData, ...@@ -135,7 +134,7 @@ class MediaSource final : public EventTargetWithInlineData,
void DurationChangeAlgorithm(double new_duration, ExceptionState&); void DurationChangeAlgorithm(double new_duration, ExceptionState&);
std::unique_ptr<WebMediaSource> web_media_source_; std::unique_ptr<WebMediaSource> web_media_source_;
AtomicString ready_state_; ReadyState ready_state_;
Member<EventQueue> async_event_queue_; Member<EventQueue> async_event_queue_;
// Keep the attached element (via attachment_tracer_), |source_buffers_|, // Keep the attached element (via attachment_tracer_), |source_buffers_|,
......
...@@ -146,14 +146,12 @@ void SourceBuffer::Dispose() { ...@@ -146,14 +146,12 @@ void SourceBuffer::Dispose() {
web_source_buffer_.reset(); web_source_buffer_.reset();
} }
const AtomicString& SourceBuffer::SegmentsKeyword() { AtomicString SourceBuffer::SegmentsKeyword() {
DEFINE_STATIC_LOCAL(const AtomicString, segments, ("segments")); return "segments";
return segments;
} }
const AtomicString& SourceBuffer::SequenceKeyword() { AtomicString SourceBuffer::SequenceKeyword() {
DEFINE_STATIC_LOCAL(const AtomicString, sequence, ("sequence")); return "sequence";
return sequence;
} }
void SourceBuffer::setMode(const AtomicString& new_mode, void SourceBuffer::setMode(const AtomicString& new_mode,
......
...@@ -62,8 +62,8 @@ class SourceBuffer final : public EventTargetWithInlineData, ...@@ -62,8 +62,8 @@ class SourceBuffer final : public EventTargetWithInlineData,
USING_PRE_FINALIZER(SourceBuffer, Dispose); USING_PRE_FINALIZER(SourceBuffer, Dispose);
public: public:
static const AtomicString& SegmentsKeyword(); static AtomicString SegmentsKeyword();
static const AtomicString& SequenceKeyword(); static AtomicString SequenceKeyword();
SourceBuffer(std::unique_ptr<WebSourceBuffer>, MediaSource*, EventQueue*); SourceBuffer(std::unique_ptr<WebSourceBuffer>, MediaSource*, EventQueue*);
~SourceBuffer() override; ~SourceBuffer() override;
......
...@@ -13,19 +13,16 @@ ...@@ -13,19 +13,16 @@
namespace blink { namespace blink {
const AtomicString& TrackDefault::AudioKeyword() { AtomicString TrackDefault::AudioKeyword() {
DEFINE_STATIC_LOCAL(const AtomicString, audio, ("audio")); return "audio";
return audio;
} }
const AtomicString& TrackDefault::VideoKeyword() { AtomicString TrackDefault::VideoKeyword() {
DEFINE_STATIC_LOCAL(const AtomicString, video, ("video")); return "video";
return video;
} }
const AtomicString& TrackDefault::TextKeyword() { AtomicString TrackDefault::TextKeyword() {
DEFINE_STATIC_LOCAL(const AtomicString, text, ("text")); return "text";
return text;
} }
ScriptValue TrackDefault::kinds(ScriptState* script_state) const { ScriptValue TrackDefault::kinds(ScriptState* script_state) const {
......
...@@ -18,9 +18,9 @@ class TrackDefault final : public ScriptWrappable { ...@@ -18,9 +18,9 @@ class TrackDefault final : public ScriptWrappable {
DEFINE_WRAPPERTYPEINFO(); DEFINE_WRAPPERTYPEINFO();
public: public:
static const AtomicString& AudioKeyword(); static AtomicString AudioKeyword();
static const AtomicString& VideoKeyword(); static AtomicString VideoKeyword();
static const AtomicString& TextKeyword(); static AtomicString TextKeyword();
static TrackDefault* Create(const AtomicString& type, static TrackDefault* Create(const AtomicString& type,
const String& language, const String& language,
......
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