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