Truly independent web browser
LibWeb+LibMediaClient: Implement MediaSource’s live seekable range
sideshowbarker6ed8a54b6427
diff --git a/Libraries/LibMediaClient/RemotePlaybackManager.cpp b/Libraries/LibMediaClient/RemotePlaybackManager.cppindex ff42fcba9c0..5be3bf03f5d 100644--- a/Libraries/LibMediaClient/RemotePlaybackManager.cpp+++ b/Libraries/LibMediaClient/RemotePlaybackManager.cpp@@ -72,6 +72,7 @@ void RemotePlaybackManager::set_duration(AK::Duration duration)m_duration = duration;if (can_send())m_client->async_set_duration(m_session_id, duration);+ dispatch_seekable_ranges_change();}AK::Duration RemotePlaybackManager::current_time() const@@ -220,6 +221,13 @@ void RemotePlaybackManager::dispatch_buffered_ranges_change() const{if (on_buffered_ranges_change)on_buffered_ranges_change();+ dispatch_seekable_ranges_change();+}++void RemotePlaybackManager::dispatch_seekable_ranges_change() const+{+ if (on_seekable_ranges_change)+ on_seekable_ranges_change();}bool RemotePlaybackManager::source_has_enabled_track(ReadonlySpan<Media::Track> audio_tracks, ReadonlySpan<Media::Track> video_tracks) const@@ -251,6 +259,50 @@ Media::BufferedRanges RemotePlaybackManager::buffered_time_ranges() constreturn Media::DemuxerScanState::buffered_ranges_of_sources(active_sources);}+// https://w3c.github.io/media-source/#htmlmediaelement-extensions-seekable+// NB: The spec defines these ranges for a media element with a MediaSource attached; they apply to every source alike.+Optional<Media::TimeRanges::Range> RemotePlaybackManager::seekable_time_ranges() const+{+ // -> If recent duration equals positive Infinity:+ if (m_duration == AK::Duration::max()) {+ auto buffered = buffered_time_ranges().time_ranges;++ // 1. If recent live seekable range is not empty:+ if (m_live_seekable_range.has_value()) {+ // 1. Let union ranges be the union of recent live seekable range and the HTMLMediaElement's buffered+ // attribute.+ // 2. Return a single range with a start time equal to the earliest start time in union ranges and an end+ // time equal to the highest end time in union ranges and abort these steps.+ auto start = m_live_seekable_range->start;+ auto end = m_live_seekable_range->end;+ if (!buffered.is_empty()) {+ start = min(start, buffered[0].start);+ end = max(end, buffered.highest_end_time());+ }+ return Media::TimeRanges::Range { start, end };+ }++ // 2. If the HTMLMediaElement's buffered attribute returns an empty TimeRanges object, then return an empty+ // TimeRanges object and abort these steps.+ if (buffered.is_empty())+ return {};++ // 3. Return a single range with a start time of 0 and an end time equal to the highest end time reported by the+ // HTMLMediaElement's buffered attribute.+ return Media::TimeRanges::Range { AK::Duration::zero(), buffered.highest_end_time() };+ }++ // -> Otherwise:+ // Return a single range with a start time of 0 and an end time equal to recent duration.+ return Media::TimeRanges::Range { AK::Duration::zero(), m_duration };+}++void RemotePlaybackManager::set_live_seekable_range(Optional<Media::TimeRanges::Range> range)+{+ m_live_seekable_range = range;+ dispatch_seekable_ranges_change();+}+Media::CombinedScanState RemotePlaybackManager::scan_state_for_enabled_tracks(Media::DemuxerScanState const& state, ReadonlySpan<Media::Track> audio_tracks, ReadonlySpan<Media::Track> video_tracks) const{return state.combined_scan_state([&](u64 identifier) {@@ -341,6 +393,7 @@ void RemotePlaybackManager::duration_changed(Badge<Client>, AK::Duration duratiom_duration = duration;if (on_duration_change)on_duration_change(duration);+ dispatch_seekable_ranges_change();}void RemotePlaybackManager::state_changed(Badge<Client>, u64 applied_seek_request_id, Media::PlaybackState state, bool is_playing, Media::AvailableData available_data, AK::Duration current_time)diff --git a/Libraries/LibMediaClient/RemotePlaybackManager.h b/Libraries/LibMediaClient/RemotePlaybackManager.hindex fdd0ae19e03..653dd85942a 100644--- a/Libraries/LibMediaClient/RemotePlaybackManager.h+++ b/Libraries/LibMediaClient/RemotePlaybackManager.h@@ -87,6 +87,11 @@ public:Media::PlaybackState state() const { return m_state; }Media::AvailableData available_data() const { return m_available_data; }Media::BufferedRanges buffered_time_ranges() const;+ // The range playback can seek to, if any. AK::Duration::max() as the duration means it's unbounded, as a live+ // stream's is. NB: This is never more than one range, and that range may start and end at the same time.+ Optional<Media::TimeRanges::Range> seekable_time_ranges() const;+ // The range a live stream's player says can be sought to, besides the buffered ranges.+ void set_live_seekable_range(Optional<Media::TimeRanges::Range>);void set_volume(double);void set_playback_rate(float);@@ -95,6 +100,9 @@ public:Function<void()> on_playback_state_change;Function<void(AK::Duration)> on_duration_change;Function<void()> on_buffered_ranges_change;+ // Called whenever an input of the seekable ranges changes: the duration, the buffered ranges, or the live seekable+ // range.+ Function<void()> on_seekable_ranges_change;Function<void(Media::DecoderError&&)> on_error;void register_source_buffer(Badge<RemoteSourceBuffer>, RemoteSourceBuffer&);@@ -142,6 +150,7 @@ private:RemoteSourceBuffer* find_source_buffer(u64 source_buffer_id);void dispatch_state_change() const;void dispatch_buffered_ranges_change() const;+ void dispatch_seekable_ranges_change() const;bool source_has_enabled_track(ReadonlySpan<Media::Track> audio_tracks, ReadonlySpan<Media::Track> video_tracks) const;Media::CombinedScanState scan_state_for_enabled_tracks(Media::DemuxerScanState const&, ReadonlySpan<Media::Track> audio_tracks, ReadonlySpan<Media::Track> video_tracks) const;@@ -151,6 +160,7 @@ private:Optional<Media::MediaTimeReader> m_time_reader;AK::Duration m_duration;bool m_duration_was_provided { false };+ Optional<Media::TimeRanges::Range> m_live_seekable_range;Optional<AK::UnixDateTime> m_start_time_realtime;bool m_is_in_error_state { false };Vector<Media::Track> m_audio_tracks;diff --git a/Libraries/LibWeb/HTML/HTMLMediaElement.cpp b/Libraries/LibWeb/HTML/HTMLMediaElement.cppindex ac63efae713..9beca541a99 100644--- a/Libraries/LibWeb/HTML/HTMLMediaElement.cpp+++ b/Libraries/LibWeb/HTML/HTMLMediaElement.cpp@@ -288,6 +288,7 @@ void HTMLMediaElement::finalize()if (m_playback_manager) {m_playback_manager->on_playback_state_change = nullptr;m_playback_manager->on_buffered_ranges_change = nullptr;+ m_playback_manager->on_seekable_ranges_change = nullptr;}release_active_video_sink();@@ -561,9 +562,20 @@ GC::Ref<TimeRanges> HTMLMediaElement::seekable() const{// The seekable attribute must return a new static normalized TimeRanges object that represents the ranges of the media resource, if any, that the// user agent is able to seek to, at the time the attribute is evaluated.- // FIXME: Implement the seekable steps from the Media Source Extensions spec to handle unbounded resources.auto time_ranges = TimeRanges::create();- time_ranges->add_range(0, m_duration);++ // https://w3c.github.io/media-source/#htmlmediaelement-extensions-seekable+ // If recent duration equals NaN:+ // Return an empty TimeRanges object.+ if (isnan(m_duration))+ return time_ranges;++ if (!m_playback_manager) {+ time_ranges->add_range(0, m_duration);+ return time_ranges;+ }+ if (auto range = m_playback_manager->seekable_time_ranges(); range.has_value())+ time_ranges->add_range(range->start.to_seconds_f64(), range->end.to_seconds_f64());return time_ranges;}@@ -720,7 +732,7 @@ bool HTMLMediaElement::ended() const}// https://html.spec.whatwg.org/multipage/media.html#durationChange-void HTMLMediaElement::set_duration(double duration)+void HTMLMediaElement::set_duration(double duration, Optional<double> playback_position_before_the_change){// When the length of the media resource changes to a known value (e.g. from being unknown to known, or from a previously established length to a new// length), the user agent must queue a media element task given the media element to fire an event named durationchange at the media element. (The event@@ -731,7 +743,7 @@ void HTMLMediaElement::set_duration(double duration)self.dispatch_event(DOM::Event::create(HTML::relevant_global_object(self), HTML::EventNames::durationchange));}));- if (current_playback_position() > duration)+ if (playback_position_before_the_change.value_or(current_playback_position()) > duration)seek_element(duration);}@@ -2499,6 +2511,11 @@ void HTMLMediaElement::set_up_playback_manager_for_remote()self.update_ready_state();}));});++ m_playback_manager->on_seekable_ranges_change = GC::weak_callback(*this, [](auto& self) {+ if (self.m_controls.has_value())+ self.m_controls->seekable_ranges_changed();+ });}// https://html.spec.whatwg.org/multipage/media.html#media-data-processing-steps-list@@ -2575,6 +2592,11 @@ void HTMLMediaElement::set_up_playback_manager_for_local(GC::Ref<GC::Function<voself.update_ready_state();}));});++ m_playback_manager->on_seekable_ranges_change = GC::weak_callback(*this, [](auto& self) {+ if (self.m_controls.has_value())+ self.m_controls->seekable_ranges_changed();+ });}void HTMLMediaElement::queue_interrupted_fetch_steps()diff --git a/Libraries/LibWeb/HTML/HTMLMediaElement.h b/Libraries/LibWeb/HTML/HTMLMediaElement.hindex e5187ab865d..663c40074f7 100644--- a/Libraries/LibWeb/HTML/HTMLMediaElement.h+++ b/Libraries/LibWeb/HTML/HTMLMediaElement.h@@ -186,7 +186,7 @@ public:void update_ready_state();- void set_duration(Badge<MediaSourceExtensions::MediaSource>, double duration) { set_duration(duration); }+ void set_duration(Badge<MediaSourceExtensions::MediaSource>, double duration, double playback_position_before_the_change) { set_duration(duration, playback_position_before_the_change); }void media_source_metadata_available(Badge<MediaSourceExtensions::SourceBuffer>) { on_metadata_parsed(SourceType::Local); }MediaClient::RemotePlaybackManager& playback_manager()@@ -321,7 +321,7 @@ private:void update_audio_play_state();void set_show_poster(bool);void set_paused(bool);- void set_duration(double);+ void set_duration(double, Optional<double> playback_position_before_the_change = {});void set_ended(bool);void update_ended_attribute();diff --git a/Libraries/LibWeb/HTML/MediaControls.h b/Libraries/LibWeb/HTML/MediaControls.hindex 73f578cd399..fe14c91639e 100644--- a/Libraries/LibWeb/HTML/MediaControls.h+++ b/Libraries/LibWeb/HTML/MediaControls.h@@ -29,6 +29,8 @@ public:void update_visibility();void set_picture_in_picture_window_controls_in_use(bool);+ // No event announces a change of the seekable ranges alone, so whoever changes them says so.+ void seekable_ranges_changed() { update_timeline(); }private:void create_shadow_tree();diff --git a/Libraries/LibWeb/MediaSourceExtensions/MediaSource.cpp b/Libraries/LibWeb/MediaSourceExtensions/MediaSource.cppindex e48fc6f094e..0f5bd7d72e1 100644--- a/Libraries/LibWeb/MediaSourceExtensions/MediaSource.cpp+++ b/Libraries/LibWeb/MediaSourceExtensions/MediaSource.cpp@@ -100,6 +100,11 @@ void MediaSource::set_ready_state_to_open_and_fire_sourceopen_event(){m_ready_state = ReadyState::Open;+ // NB: [[live seekable range]] outlives an attachment, so a MediaSource attached again hands it to its new media+ // element's playback manager.+ if (m_live_seekable_range.has_value() && m_media_element_assigned_to)+ m_media_element_assigned_to->playback_manager().set_live_seekable_range(m_live_seekable_range);+// AD-HOC: Notify all demuxers that we have new data coming in and cannot consider the end of the buffer to be// the end of the stream.for (size_t i = 0; i < m_source_buffers->length(); i++) {@@ -424,6 +429,39 @@ double MediaSource::duration() constreturn m_duration;}+// https://w3c.github.io/media-source/#dom-mediasource-duration+// https://w3c.github.io/media-source/#dom-mediasource-setliveseekablerange+WebIDL::ExceptionOr<void> MediaSource::set_live_seekable_range(double start, double end)+{+ // 1. If the readyState attribute is not "open" then throw an InvalidStateError exception and abort these steps.+ if (m_ready_state != ReadyState::Open)+ return WebIDL::InvalidStateError::create("MediaSource is not open"_utf16);++ // 2. If start is negative or greater than end, then throw a TypeError exception and abort these steps.+ if (start < 0 || start > end)+ return WebIDL::SimpleException { WebIDL::SimpleExceptionType::TypeError, "start must not be negative or greater than end"_utf16 };++ // 3. Set [[live seekable range]] to be a new normalized TimeRanges object containing a single range whose start+ // position is start and end position is end.+ m_live_seekable_range = Media::TimeRanges::Range { AK::Duration::from_seconds_f64(start), AK::Duration::from_seconds_f64(end) };+ media_element_assigned_to()->playback_manager().set_live_seekable_range(m_live_seekable_range);+ return {};+}++// https://w3c.github.io/media-source/#dom-mediasource-clearliveseekablerange+WebIDL::ExceptionOr<void> MediaSource::clear_live_seekable_range()+{+ // 1. If the readyState attribute is not "open" then throw an InvalidStateError exception and abort these steps.+ if (m_ready_state != ReadyState::Open)+ return WebIDL::InvalidStateError::create("MediaSource is not open"_utf16);++ // 2. If [[live seekable range]] contains a range, then set [[live seekable range]] to be a new empty TimeRanges+ // object.+ m_live_seekable_range.clear();+ media_element_assigned_to()->playback_manager().set_live_seekable_range({});+ return {};+}+// https://w3c.github.io/media-source/#dom-mediasource-durationWebIDL::ExceptionOr<void> MediaSource::set_duration(double new_duration){@@ -495,8 +533,14 @@ void MediaSource::assign_duration_change(double new_duration)// FIXME: Mirror to the Window when workers are supported.// Update the media element's duration to new duration.// Run the HTMLMediaElement duration change algorithm.- media_element_assigned_to()->set_duration({}, new_duration);- media_element_assigned_to()->playback_manager().set_duration(AK::Duration::from_seconds_f64(new_duration));+ // NB: The element seeks if its playback position is past the new duration, and that seek reads the seekable ranges,+ // which the playback manager computes from the duration. So the playback manager gets the new duration first,+ // but the element compares the position from before the change: The playback manager caps a pending seek's+ // target at its duration. An infinite duration, a live stream's, is unbounded for the playback manager.+ auto& media_element = *media_element_assigned_to();+ auto playback_position = media_element.current_playback_position();+ media_element.playback_manager().set_duration(isinf(new_duration) ? AK::Duration::max() : AK::Duration::from_seconds_f64(new_duration));+ media_element.set_duration({}, new_duration, playback_position);}// https://w3c.github.io/media-source/#dom-mediasource-istypesupporteddiff --git a/Libraries/LibWeb/MediaSourceExtensions/MediaSource.h b/Libraries/LibWeb/MediaSourceExtensions/MediaSource.hindex 5690ba7aea6..cdbe6db3497 100644--- a/Libraries/LibWeb/MediaSourceExtensions/MediaSource.h+++ b/Libraries/LibWeb/MediaSourceExtensions/MediaSource.h@@ -7,6 +7,7 @@#pragma once#include <LibJS/Forward.h>+#include <LibMedia/TimeRanges.h>#include <LibMediaCodecs/DecoderCapabilities.h>#include <LibWeb/Bindings/MediaSource.h>#include <LibWeb/DOM/EventTarget.h>@@ -66,6 +67,12 @@ public:WebIDL::ExceptionOr<GC::Ref<SourceBuffer>> add_source_buffer(Utf16String const& type);WebIDL::ExceptionOr<void> end_of_stream(Optional<EndOfStreamError> const& error = {});++ // https://w3c.github.io/media-source/#dom-mediasource-setliveseekablerange+ WebIDL::ExceptionOr<void> set_live_seekable_range(double start, double end);++ // https://w3c.github.io/media-source/#dom-mediasource-clearliveseekablerange+ WebIDL::ExceptionOr<void> clear_live_seekable_range();void run_end_of_stream_algorithm(Badge<SourceBuffer>, Optional<EndOfStreamError> const& error) { run_end_of_stream_algorithm(error); }// https://w3c.github.io/media-source/#dom-mediasource-duration@@ -101,6 +108,11 @@ private:double m_duration { NAN };+ // https://w3c.github.io/media-source/#dfn-live-seekable-range+ // NB: The one range [[live seekable range]] holds, if any. The media element's playback manager gets a copy of it+ // whenever this MediaSource opens, since it computes the seekable ranges.+ Optional<Media::TimeRanges::Range> m_live_seekable_range;+u64 m_next_track_id = 1;GC::Ref<DOM::EventTarget> m_global_object;diff --git a/Libraries/LibWeb/MediaSourceExtensions/MediaSource.idl b/Libraries/LibWeb/MediaSourceExtensions/MediaSource.idlindex 20cf11882d6..9efe19f209e 100644--- a/Libraries/LibWeb/MediaSourceExtensions/MediaSource.idl+++ b/Libraries/LibWeb/MediaSourceExtensions/MediaSource.idl@@ -32,7 +32,7 @@ interface MediaSource : EventTarget {SourceBuffer addSourceBuffer(DOMString type);[FIXME] undefined removeSourceBuffer(SourceBuffer sourceBuffer);[ImplementedAs=end_of_stream] undefined endOfStream(optional EndOfStreamError error);- [FIXME] undefined setLiveSeekableRange(double start, double end);- [FIXME] undefined clearLiveSeekableRange();+ undefined setLiveSeekableRange(double start, double end);+ undefined clearLiveSeekableRange();static boolean isTypeSupported(DOMString type);};diff --git a/Tests/LibWeb/TestConfig.ini b/Tests/LibWeb/TestConfig.iniindex 6a647afd4d0..55ac277cbe1 100644--- a/Tests/LibWeb/TestConfig.ini+++ b/Tests/LibWeb/TestConfig.ini@@ -241,6 +241,7 @@ Text/input/HTML/media-source-mismatched-codec-configuration.htmlText/input/wpt-import/media-source/mediasource-activesourcebuffers.htmlText/input/wpt-import/media-source/mediasource-appendwindow.htmlText/input/wpt-import/media-source/mediasource-invalid-codec.html+Text/input/wpt-import/media-source/mediasource-liveseekable.htmlText/input/wpt-import/media-source/SourceBuffer-abort.htmlText/input/wpt-import/media-source/SourceBuffer-appendWindowEnd-rounding.htmlText/input/HTML/HTMLMediaElement-load-overrides-preload-none.htmldiff --git a/Tests/LibWeb/Text/expected/HTML/media-source-live-seekable-range-edge-cases.txt b/Tests/LibWeb/Text/expected/HTML/media-source-live-seekable-range-edge-cases.txtnew file mode 100644index 00000000000..d18fb552763--- /dev/null+++ b/Tests/LibWeb/Text/expected/HTML/media-source-live-seekable-range-edge-cases.txt@@ -0,0 +1,3 @@+live range [1, 1], nothing buffered: [1, 1]+duration 0: [0, 0]+after reattaching: [1, 1]diff --git a/Tests/LibWeb/Text/expected/wpt-import/media-source/mediasource-liveseekable.txt b/Tests/LibWeb/Text/expected/wpt-import/media-source/mediasource-liveseekable.txtnew file mode 100644index 00000000000..ae60d6d90ac--- /dev/null+++ b/Tests/LibWeb/Text/expected/wpt-import/media-source/mediasource-liveseekable.txt@@ -0,0 +1,15 @@+Harness status: OK++Found 10 tests++10 Pass+Pass setLiveSeekableRange throws an InvalidStateError exception if the readyState attribute is not 'open'+Pass clearLiveSeekableRange throws an InvalidStateError exception if the readyState attribute is not 'open'+Pass setLiveSeekableRange does not restrict to not currently updating+Pass clearLiveSeekableRange does not restrict to not currently updating+Pass setLiveSeekableRange throws a TypeError if start is negative+Pass setLiveSeekableRange throws a TypeError if start is greater than end+Pass setLiveSeekableRange returns with no error when conditions are correct+Pass clearLiveSeekableRange returns with no error when conditions are correct+Pass HTMLMediaElement.seekable returns the live seekable range or an empty range if that range was cleared when nothing is buffered+Pass HTMLMediaElement.seekable returns the union of the buffered range and the live seekable range, when set\ No newline at end of filediff --git a/Tests/LibWeb/Text/input/HTML/media-source-live-seekable-range-edge-cases.html b/Tests/LibWeb/Text/input/HTML/media-source-live-seekable-range-edge-cases.htmlnew file mode 100644index 00000000000..c359a1f6321--- /dev/null+++ b/Tests/LibWeb/Text/input/HTML/media-source-live-seekable-range-edge-cases.html@@ -0,0 +1,39 @@+<!DOCTYPE html>+<video id="first"></video>+<script src="../include.js"></script>+<script>+ function rangesOf(timeRanges) {+ const ranges = [];+ for (let i = 0; i < timeRanges.length; ++i)+ ranges.push(`[${timeRanges.start(i)}, ${timeRanges.end(i)}]`);+ return ranges.join(" ") || "none";+ }++ function attach(video, mediaSource) {+ return new Promise(resolve => {+ mediaSource.addEventListener("sourceopen", resolve, { once: true });+ video.src = URL.createObjectURL(mediaSource);+ });+ }++ asyncTest(async done => {+ // A live range may start and end at the same time, and so may a seekable range for a duration of 0.+ const first = document.getElementById("first");+ const mediaSource = new MediaSource();+ await attach(first, mediaSource);+ mediaSource.duration = Infinity;+ mediaSource.setLiveSeekableRange(1, 1);+ println(`live range [1, 1], nothing buffered: ${rangesOf(first.seekable)}`);+ mediaSource.duration = 0;+ println(`duration 0: ${rangesOf(first.seekable)}`);++ // The live range belongs to the MediaSource, so it outlasts a detach and applies again when it's reattached.+ first.removeAttribute("src");+ first.load();+ await attach(first, mediaSource);+ mediaSource.duration = Infinity;+ println(`after reattaching: ${rangesOf(first.seekable)}`);++ done();+ });+</script>diff --git a/Tests/LibWeb/Text/input/wpt-import/media-source/mediasource-liveseekable.html b/Tests/LibWeb/Text/input/wpt-import/media-source/mediasource-liveseekable.htmlnew file mode 100644index 00000000000..4c4bfdc49e6--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/media-source/mediasource-liveseekable.html@@ -0,0 +1,137 @@+<!DOCTYPE html>+<!-- Copyright © 2016 Chromium authors and World Wide Web Consortium, (Massachusetts Institute of Technology, ERCIM, Keio University, Beihang). -->+<meta charset="utf-8">+<title>Checks setting/clearing the live seekable range and HTMLMediaElement.seekable</title>+<script src="../resources/testharness.js"></script>+<script src="../resources/testharnessreport.js"></script>+<script src="mediasource-util.js"></script>+<script>+test(function(test)+{+ var mediaSource = new MediaSource();+ assert_equals(mediaSource.readyState, "closed", "media source is closed.");+ assert_throws_dom("InvalidStateError", function() { mediaSource.setLiveSeekableRange(0, 1); });+}, "setLiveSeekableRange throws an InvalidStateError exception if the readyState attribute is not 'open'");+++test(function(test)+{+ var mediaSource = new MediaSource();+ assert_equals(mediaSource.readyState, "closed", "media source is closed.");+ assert_throws_dom("InvalidStateError", function() { mediaSource.clearLiveSeekableRange(); });+}, "clearLiveSeekableRange throws an InvalidStateError exception if the readyState attribute is not 'open'");+++mediasource_test(function(test, mediaElement, mediaSource)+{+ mediaElement.addEventListener('error', test.unreached_func("Unexpected event 'error'"));+ var mimetype = MediaSourceUtil.AUDIO_VIDEO_TYPE;+ var sourceBuffer = mediaSource.addSourceBuffer(mimetype);+ sourceBuffer.appendBuffer(new Uint8Array(0));+ assert_true(sourceBuffer.updating, "Updating set when a buffer is appended.");+ mediaSource.setLiveSeekableRange(0, 1);+ test.done();+}, "setLiveSeekableRange does not restrict to not currently updating");+++mediasource_test(function(test, mediaElement, mediaSource)+{+ mediaElement.addEventListener('error', test.unreached_func("Unexpected event 'error'"));+ var mimetype = MediaSourceUtil.AUDIO_VIDEO_TYPE;+ var sourceBuffer = mediaSource.addSourceBuffer(mimetype);+ sourceBuffer.appendBuffer(new Uint8Array(0));+ assert_true(sourceBuffer.updating, "Updating set when a buffer is appended.");+ mediaSource.clearLiveSeekableRange();+ test.done();+}, "clearLiveSeekableRange does not restrict to not currently updating");+++mediasource_test(function(test, mediaElement, mediaSource)+{+ mediaElement.addEventListener('error', test.unreached_func("Unexpected event 'error'"));+ assert_throws_js(TypeError, function() { mediaSource.setLiveSeekableRange(-1, 1); });+ test.done();+}, "setLiveSeekableRange throws a TypeError if start is negative");+++mediasource_test(function(test, mediaElement, mediaSource)+{+ mediaElement.addEventListener('error', test.unreached_func("Unexpected event 'error'"));+ assert_throws_js(TypeError, function() { mediaSource.setLiveSeekableRange(2, 1); });+ test.done();+}, "setLiveSeekableRange throws a TypeError if start is greater than end");+++mediasource_test(function(test, mediaElement, mediaSource)+{+ mediaElement.addEventListener('error', test.unreached_func("Unexpected event 'error'"));+ mediaSource.setLiveSeekableRange(0, 1);+ test.done();+}, "setLiveSeekableRange returns with no error when conditions are correct");+++mediasource_test(function(test, mediaElement, mediaSource)+{+ mediaElement.addEventListener('error', test.unreached_func("Unexpected event 'error'"));+ mediaSource.clearLiveSeekableRange();+ test.done();+}, "clearLiveSeekableRange returns with no error when conditions are correct");+++mediasource_test(function(test, mediaElement, mediaSource)+{+ mediaSource.duration = +Infinity;+ mediaSource.setLiveSeekableRange(1, 2);+ assert_equals(mediaElement.seekable.length, 1,+ 'The seekable attribute contains a single range.');+ assertSeekableEquals(mediaElement, '{ [1.000, 2.000) }',+ 'The seekable attribute returns the correct range.');++ mediaSource.clearLiveSeekableRange();+ assertSeekableEquals(mediaElement, '{ }',+ 'The seekable attribute now returns an empty range.');+ test.done();+}, "HTMLMediaElement.seekable returns the live seekable range or an empty range if that range was cleared when nothing is buffered");+++mediasource_testafterdataloaded(function(test, mediaElement, mediaSource, segmentInfo, sourceBuffer, mediaData)+{+ var initSegment = MediaSourceUtil.extractSegmentData(mediaData, segmentInfo.init);+ test.expectEvent(sourceBuffer, 'updateend', 'Init segment appended to SourceBuffer.');+ sourceBuffer.appendBuffer(initSegment);+ test.waitForExpectedEvents(function()+ {+ mediaSource.duration = +Infinity;+ mediaSource.setLiveSeekableRange(40, 42);++ // Append a segment that starts after 1s to ensure seekable+ // won't use 0 as starting point.+ var midSegment = MediaSourceUtil.extractSegmentData(mediaData, segmentInfo.media[5]);+ test.expectEvent(sourceBuffer, 'updateend');+ sourceBuffer.appendBuffer(midSegment);+ test.waitForExpectedEvents(function()+ {+ assert_equals(mediaElement.seekable.length, 1,+ 'The seekable attribute contains a single range.');+ assert_equals(mediaElement.buffered.length, 1,+ 'The buffered attribute contains a single range.');+ assert_not_equals(mediaElement.seekable.start(0), 0,+ 'The range starts after 0.');+ assert_equals(mediaElement.seekable.start(0), mediaElement.buffered.start(0),+ 'The start time is the start time of the buffered range.');+ assert_equals(mediaElement.seekable.end(0), 42,+ 'The end time is the end time of the seekable range.');++ mediaSource.clearLiveSeekableRange();+ assert_equals(mediaElement.seekable.length, 1,+ 'The seekable attribute contains a single range.');+ assert_equals(mediaElement.seekable.start(0), 0,+ 'The start time is now 0.');+ assert_equals(mediaElement.seekable.end(0), mediaElement.buffered.end(0),+ 'The end time is now the end time of the buffered range.');++ test.done();+ });+ });+}, 'HTMLMediaElement.seekable returns the union of the buffered range and the live seekable range, when set');+</script>