Skip to content

Commit

Permalink
Recognize and reject raw AAC in HLS
Browse files Browse the repository at this point in the history
This makes the HLS parser recognize raw AAC, but refuse to play it.
It will not play correctly until we have full support for
containerless formats at the MediaSource level.

Closes #1083 (raw AAC, can't do anything more for this right now)
Issue #2337 (full support for containerless formats in general)

Backported to v2.5.x

Change-Id: I50c7f06a1aa08d515f4d9f74603954a6d015dc29
  • Loading branch information
joeyparrish committed Jan 15, 2020
1 parent 96c4e83 commit f3c4518
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 33 deletions.
2 changes: 2 additions & 0 deletions demo/common/assets.js
Expand Up @@ -999,6 +999,8 @@ shakaAssets.testAssets = [
/* iconUri= */ 'https://storage.googleapis.com/shaka-asset-icons/apple_test_pattern.png',
/* manifestUri= */ 'https://storage.googleapis.com/shaka-demo-assets/apple-advanced-stream-ts/master.m3u8',
/* source= */ shakaAssets.Source.APPLE)
// Disabled until we support raw AAC: https://github.com/google/shaka-player/issues/2337
.markAsDisabled()
.addFeature(shakaAssets.Feature.HLS)
.addFeature(shakaAssets.Feature.MP2TS)
.addFeature(shakaAssets.Feature.CAPTIONS)
Expand Down
55 changes: 22 additions & 33 deletions lib/hls/hls_parser.js
Expand Up @@ -1131,19 +1131,12 @@ shaka.hls.HlsParser.prototype.createStreamInfo_ = async function(
let absoluteMediaPlaylistUri = Utils.constructAbsoluteUri(
this.masterPlaylistUri_, verbatimMediaPlaylistUri);

/** @type {!shaka.hls.Playlist} */
let playlist;
/** @type {string} */
let codecs = '';
/** @type {string} */
let mimeType;

const response = await this.requestManifest_(absoluteMediaPlaylistUri);
// Record the final URI after redirects.
absoluteMediaPlaylistUri = response.uri;

// Record the redirected, final URI of this media playlist when we parse it.
playlist = this.manifestTextParser_.parsePlaylist(
/** @const {!shaka.hls.Playlist} */
const playlist = this.manifestTextParser_.parsePlaylist(
response.data, absoluteMediaPlaylistUri);

if (playlist.type != shaka.hls.PlaylistType.MEDIA) {
Expand Down Expand Up @@ -1213,10 +1206,14 @@ shaka.hls.HlsParser.prototype.createStreamInfo_ = async function(

this.determinePresentationType_(playlist);

codecs = this.guessCodecs_(type, allCodecs);
const mimeTypeArg = await this.guessMimeType_(type, codecs, playlist);
let codecs = this.guessCodecs_(type, allCodecs);
const mimeType = await this.guessMimeType_(type, codecs, playlist);

mimeType = mimeTypeArg;
// MediaSource expects no codec strings combined with raw formats.
// TODO(#2337): Replace with a flag indicating a raw format.
if (mimeType == 'audio/mpeg' || mimeType == 'audio/aac') {
codecs = '';
}

let mediaSequenceTag = Utils.getFirstTagWithName(playlist.tags,
'EXT-X-MEDIA-SEQUENCE');
Expand Down Expand Up @@ -1607,7 +1604,6 @@ shaka.hls.HlsParser.prototype.fetchPartialSegment_ = async function(reference) {
}
};


/**
* Gets the start time of a segment from the existing manifest (if possible) or
* by downloading it and parsing it otherwise.
Expand Down Expand Up @@ -1650,10 +1646,13 @@ shaka.hls.HlsParser.prototype.getStartTime_ = async function(

shaka.log.v1('Fetching segment to find start time');

if (mimeType == 'audio/mpeg') {
// There is no standard way to embed timestamps in mp3 files, so the
// start time is presumably 0.
return 0;

if (mimeType == 'audio/mpeg' || mimeType == 'audio/aac') {
// Raw MP3 and AAC files contain no timestamps.
// Don't return a false timestamp. We want to treat them as aligning to
// their corresponding video segments.
// TODO(#2337): Avoid trying to fetch timestamps for raw formats.
return null;
}

if (mimeType == 'video/mp4' || mimeType == 'audio/mp4') {
Expand Down Expand Up @@ -1688,22 +1687,11 @@ shaka.hls.HlsParser.prototype.getStartTime_ = async function(
return this.getStartTimeFromTextSegment_(mimeType, codecs, response.data);
}

if (mimeType == 'video/webm') {
shaka.log.warning(
'Hls+WebM combination is not supported at the moment. Skipping.');
return null;
}


// TODO(vaage): Add support for additional formats.
//
// Formats:
// - WebM
// - AAC
//
// Since we want to add more formats, how would a more general registry
// system work to allow additional formats to be "plugged-into" the
// parser.
if (mimeType == 'video/webm') {
shaka.log.warning(
'Hls+WebM combination is not supported at the moment. Skipping.');
return null;
}

throw new shaka.util.Error(
shaka.util.Error.Severity.CRITICAL,
Expand Down Expand Up @@ -2222,6 +2210,7 @@ shaka.hls.HlsParser.AUDIO_EXTENSIONS_TO_MIME_TYPES_ = {
'm4a': 'audio/mp4',
// MPEG2-TS also uses video/ for audio: https://bit.ly/TsMse
'ts': 'video/mp2t',
'aac': 'audio/aac',
};


Expand Down

0 comments on commit f3c4518

Please sign in to comment.