Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Allow to customize HLS Live behavior #4578

Merged
merged 3 commits into from
Oct 16, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/workflows/build-and-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ jobs:
- os: ubuntu-latest
browser: Firefox
extra_flags: "--use-xvfb"
- os: ubuntu-latest
browser: Edge
extra_flags: "--use-xvfb"

- os: macos-latest
browser: Chrome
Expand Down
1 change: 1 addition & 0 deletions demo/common/message_ids.js
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,7 @@ shakaDemo.MessageIds = {
USE_HEADERS: 'DEMO_USE_HEADERS',
USE_NATIVE_HLS_SAFARI: 'DEMO_USE_NATIVE_HLS_SAFARI',
USE_PERSISTENT_LICENSES: 'DEMO_USE_PERSISTENT_LICENSES',
USE_SAFARI_BEHAVIOR_FOR_LIVE: 'DEMO_USE_SAFARI_BEHAVIOR_FOR_LIVE',
VIDEO_ROBUSTNESS: 'DEMO_VIDEO_ROBUSTNESS',
VNOVA: 'DEMO_VNOVA',
XLINK_FAIL_GRACEFULLY: 'DEMO_XLINK_FAIL_GRACEFULLY',
Expand Down
2 changes: 2 additions & 0 deletions demo/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,8 @@ shakaDemo.Config = class {
'manifest.hls.defaultVideoCodec')
.addBoolInput_(MessageIds.IGNORE_MANIFEST_PROGRAM_DATE_TIME,
'manifest.hls.ignoreManifestProgramDateTime')
.addBoolInput_(MessageIds.USE_SAFARI_BEHAVIOR_FOR_LIVE,
'manifest.hls.useSafariBehaviorForLive')
.addNumberInput_(MessageIds.AVAILABILITY_WINDOW_OVERRIDE,
'manifest.availabilityWindowOverride',
/* canBeDecimal= */ true,
Expand Down
1 change: 1 addition & 0 deletions demo/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,7 @@
"DEMO_USE_HEADERS": "Use Headers",
"DEMO_USE_NATIVE_HLS_SAFARI": "Use native HLS on Safari",
"DEMO_USE_PERSISTENT_LICENSES": "Use Persistent Licenses",
"DEMO_USE_SAFARI_BEHAVIOR_FOR_LIVE": "Use Safari behavior for live",
"DEMO_VIDEO_ROBUSTNESS": "Video Robustness",
"DEMO_VISUALIZER_AUTO_SCREENSHOT_TOGGLE": "Take Screenshot On Stall",
"DEMO_VISUALIZER_BUTTON": "Buffer Visualizer",
Expand Down
4 changes: 4 additions & 0 deletions demo/locales/source.json
Original file line number Diff line number Diff line change
Expand Up @@ -979,6 +979,10 @@
"description": "The name of a configuration value.",
"message": "Use Persistent Licenses"
},
"DEMO_USE_SAFARI_BEHAVIOR_FOR_LIVE": {
"description": "The name of a configuration value.",
"message": "Use Safari behavior for live"
},
"DEMO_VIDEO_ROBUSTNESS": {
"description": "The name of a configuration value.",
"message": "Video Robustness"
Expand Down
10 changes: 9 additions & 1 deletion externs/shaka/player.js
Original file line number Diff line number Diff line change
Expand Up @@ -827,7 +827,8 @@ shaka.extern.DashManifestConfiguration;
* defaultAudioCodec: string,
* defaultVideoCodec: string,
* ignoreManifestProgramDateTime: boolean,
* mediaPlaylistFullMimeType: string
* mediaPlaylistFullMimeType: string,
* useSafariBehaviorForLive: boolean
* }}
*
* @property {boolean} ignoreTextStreamFailures
Expand Down Expand Up @@ -858,6 +859,13 @@ shaka.extern.DashManifestConfiguration;
* format this value.
* <i>Defaults to
* <code>'video/mp2t; codecs="avc1.42E01E, mp4a.40.2"'</code>.</i>
* @property {boolean} useSafariBehaviorForLive
* The spec says nothing much about seeking in live content, but Safari's
* built-in HLS implementation does not allow it. Therefore we will set
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The wording in the second sentence here is confusing. It isn't clear it's describing the effect of this configuration value.
I would explicitly describe it in terms of what happens if it's set to true, vs if it's set to false. Something like:

If this is true, playback will set the availability window to the presentation delay. The player will be able to buffer ahead three segments, but the seek window will be zero-sized, to be consistent with Safari.
If this is false, the seek window will be the entire duration.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

* the availability window equal to the presentation delay. The player
* will be able to buffer ahead three segments, but the seek window will
* be zero-sized.
* <i>Defaults to <code>truecode>.</i>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The closing code tag is broken.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed!

* @exportDoc
*/
shaka.extern.HlsManifestConfiguration;
Expand Down
6 changes: 5 additions & 1 deletion lib/hls/hls_parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -756,10 +756,14 @@ shaka.hls.HlsParser = class {
const PresentationType = shaka.hls.HlsParser.PresentationType_;

if (this.presentationType_ == PresentationType.LIVE) {
let segmentAvailabilityDuration = this.getMinDuration_();

// This defaults to the presentation delay, which has the effect of
// making the live stream unseekable. This is consistent with Apple's
// HLS implementation.
let segmentAvailabilityDuration = this.presentationTimeline_.getDelay();
if (this.config_.hls.useSafariBehaviorForLive) {
segmentAvailabilityDuration = this.presentationTimeline_.getDelay();
}

// The app can override that with a longer duration, to allow seeking.
if (!isNaN(this.config_.availabilityWindowOverride)) {
Expand Down
1 change: 1 addition & 0 deletions lib/util/player_configuration.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ shaka.util.PlayerConfiguration = class {
ignoreManifestProgramDateTime: false,
mediaPlaylistFullMimeType:
'video/mp2t; codecs="avc1.42E01E, mp4a.40.2"',
useSafariBehaviorForLive: true,
},
};

Expand Down