Skip to content

Commit

Permalink
feat(hls): Make default HLS audio/video codecs configurable (shaka-pr…
Browse files Browse the repository at this point in the history
  • Loading branch information
Álvaro Velad Galván committed Sep 22, 2021
1 parent 3f822d8 commit 52d68a2
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 6 deletions.
2 changes: 2 additions & 0 deletions demo/common/message_ids.js
Expand Up @@ -158,7 +158,9 @@ shakaDemo.MessageIds = {
BUFFERING_GOAL: 'DEMO_BUFFERING_GOAL',
CLOCK_SYNC_URI: 'DEMO_CLOCK_SYNC_URI',
CONNECTION_TIMEOUT: 'DEMO_CONNECTION_TIMEOUT',
DEFAULT_AUDIO_CODEC: 'DEMO_DEFAULT_AUDIO_CODEC',
DEFAULT_PRESENTATION_DELAY: 'DEMO_DEFAULT_PRESENTATION_DELAY',
DEFAULT_VIDEO_CODEC: 'DEMO_DEFAULT_VIDEO_CODEC',
DELAY_LICENSE: 'DEMO_DELAY_LICENSE',
DISABLE_AUDIO: 'DEMO_DISABLE_AUDIO',
DISABLE_TEXT: 'DEMO_DISABLE_TEXT',
Expand Down
4 changes: 4 additions & 0 deletions demo/config.js
Expand Up @@ -210,6 +210,10 @@ shakaDemo.Config = class {
'manifest.hls.ignoreImageStreamFailures')
.addBoolInput_(MessageIds.USE_FULL_SEGMENTS_FOR_START_TIME,
'manifest.hls.useFullSegmentsForStartTime')
.addTextInput_(MessageIds.DEFAULT_AUDIO_CODEC,
'manifest.hls.defaultAudioCodec')
.addTextInput_(MessageIds.DEFAULT_VIDEO_CODEC,
'manifest.hls.defaultVideoCodec')
.addNumberInput_(MessageIds.AVAILABILITY_WINDOW_OVERRIDE,
'manifest.availabilityWindowOverride',
/* canBeDecimal= */ true,
Expand Down
2 changes: 2 additions & 0 deletions demo/locales/en.json
Expand Up @@ -45,7 +45,9 @@
"DEMO_CUSTOM_INTRO_TWO": "Press the button below to add a custom asset.",
"DEMO_DASH": "DASH",
"DEMO_DASH_IF": "DASH-IF",
"DEMO_DEFAULT_AUDIO_CODEC": "Default Audio Codec",
"DEMO_DEFAULT_PRESENTATION_DELAY": "Default Presentation Delay",
"DEMO_DEFAULT_VIDEO_CODEC": "Default Video Codec",
"DEMO_DELAY_LICENSE": "Delay License Request Until Played",
"DEMO_DELETE_CUSTOM": "Delete",
"DEMO_DELETE_CUSTOM_PROMPT": "Delete this custom asset?",
Expand Down
8 changes: 8 additions & 0 deletions demo/locales/source.json
Expand Up @@ -183,10 +183,18 @@
"description": "Text that describes an asset that comes from the Dash Industry Forum asset library.",
"message": "[PROPER_NAME:DASH-IF]"
},
"DEMO_DEFAULT_AUDIO_CODEC": {
"description": "The name of a configuration value.",
"message": "Default Audio Codec"
},
"DEMO_DEFAULT_PRESENTATION_DELAY": {
"description": "The name of a configuration value.",
"message": "Default Presentation Delay"
},
"DEMO_DEFAULT_VIDEO_CODEC": {
"description": "The name of a configuration value.",
"message": "Default Video Codec"
},
"DEMO_DELAY_LICENSE": {
"description": "The name of a configuration value.",
"message": "Delay License Request Until Played"
Expand Down
10 changes: 9 additions & 1 deletion externs/shaka/player.js
Expand Up @@ -698,7 +698,9 @@ shaka.extern.DashManifestConfiguration;
* @typedef {{
* ignoreTextStreamFailures: boolean,
* ignoreImageStreamFailures: boolean,
* useFullSegmentsForStartTime: boolean
* useFullSegmentsForStartTime: boolean,
* defaultAudioCodec: string,
* defaultVideoCodec: string
* }}
*
* @property {boolean} ignoreTextStreamFailures
Expand All @@ -710,6 +712,12 @@ shaka.extern.DashManifestConfiguration;
* @property {boolean} useFullSegmentsForStartTime
* If <code>true</code>, force HlsParser to use a full segment request for
* determining start time in case the server does not support partial requests
* @property {string} defaultAudioCodec
* The default audio codec if it is not specified in the HLS playlist.
* <i>Defaults to <code>'mp4a.40.2'</code>.</i>
* @property {string} defaultVideoCodec
* The default video codec if it is not specified in the HLS playlist.
* <i>Defaults to <code>'avc1.42E01E'</code>.</i>
* @exportDoc
*/
shaka.extern.HlsManifestConfiguration;
Expand Down
7 changes: 2 additions & 5 deletions lib/hls/hls_parser.js
Expand Up @@ -871,15 +871,12 @@ shaka.hls.HlsParser = class {
*/
getCodecsForVariantTag_(tag) {
// These are the default codecs to assume if none are specified.
// The video codec is H.264, with baseline profile and level 3.0.
// http://blog.pearce.org.nz/2013/11/what-does-h264avc1-codecs-parameters.html
// The audio codec is "low-complexity" AAC.
const defaultCodecsArray = [];
if (!this.config_.disableVideo) {
defaultCodecsArray.push('avc1.42E01E');
defaultCodecsArray.push(this.config_.hls.defaultVideoCodec);
}
if (!this.config_.disableAudio) {
defaultCodecsArray.push('mp4a.40.2');
defaultCodecsArray.push(this.config_.hls.defaultAudioCodec);
}
const defaultCodecs = defaultCodecsArray.join(',');

Expand Down
2 changes: 2 additions & 0 deletions lib/util/player_configuration.js
Expand Up @@ -120,6 +120,8 @@ shaka.util.PlayerConfiguration = class {
ignoreTextStreamFailures: false,
ignoreImageStreamFailures: false,
useFullSegmentsForStartTime: false,
defaultAudioCodec: 'mp4a.40.2',
defaultVideoCodec: 'avc1.42E01E',
},
};

Expand Down

0 comments on commit 52d68a2

Please sign in to comment.