Skip to content

Commit

Permalink
feat: Allow customization of HLS Live behavior (shaka-project#4578)
Browse files Browse the repository at this point in the history
  • Loading branch information
avelad authored Oct 16, 2022
1 parent 65903aa commit 4914201
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 2 deletions.
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
9 changes: 8 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,12 @@ shaka.extern.DashManifestConfiguration;
* format this value.
* <i>Defaults to
* <code>'video/mp2t; codecs="avc1.42E01E, mp4a.40.2"'</code>.</i>
* @property {boolean} useSafariBehaviorForLive
* 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.
* <i>Defaults to <code>true</code>.</i>
* @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

0 comments on commit 4914201

Please sign in to comment.