Skip to content

Commit

Permalink
Enable TS Assets in demo asset list
Browse files Browse the repository at this point in the history
The Transport Stream assets (Art of Motion(HLS,TS) and Sintel(HLS,TS,4k))
were disabled in the demo app, because the assets were only filtered by
native platform support.

Backported to v2.3.x

Closes #1214.

Change-Id: I03b60df291813b4669889fc8f8500627d206b28a
  • Loading branch information
michellezhuogg authored and joeyparrish committed Mar 21, 2018
1 parent 12c771b commit d987557
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 13 deletions.
20 changes: 20 additions & 0 deletions demo/common/demo_utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,23 @@ ShakaDemoUtils.addLicenseRequestHeaders_ =
request.headers[k] = headers[k];
}
};


/**
* Return true if the current content is Transport Stream.
* Used to decide if caption button is shown all the time in the demo,
* and whether to show 'Default Text' as a Text Track option.
*
* @param {shaka.Player} player
* @return {boolean}
*/
ShakaDemoUtils.isTsContent = function(player) {
var activeTracks = player.getVariantTracks().filter(function(track) {
return track.active == true;
});
var activeTrack = activeTracks[0];
if (activeTrack) {
return activeTrack.mimeType == 'video/mp2t';
}
return false;
};
12 changes: 6 additions & 6 deletions lib/media/media_source_engine.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,8 @@ shaka.media.MediaSourceEngine.isStreamSupported = function(stream) {
stream.mimeType, stream.codecs);
var extendedMimeType = shaka.util.MimeUtils.getExtendedType(stream);
return shaka.text.TextEngine.isTypeSupported(fullMimeType) ||
MediaSource.isTypeSupported(extendedMimeType) ||
shaka.media.Transmuxer.isSupported(stream.type, fullMimeType);
MediaSource.isTypeSupported(extendedMimeType) ||
shaka.media.Transmuxer.isSupported(fullMimeType, stream.type);
};


Expand Down Expand Up @@ -172,9 +172,9 @@ shaka.media.MediaSourceEngine.probeSupport = function() {
];

testMimeTypes.forEach(function(type) {
support[type] =
shaka.text.TextEngine.isTypeSupported(type) ||
MediaSource.isTypeSupported(type);
support[type] = shaka.text.TextEngine.isTypeSupported(type) ||
MediaSource.isTypeSupported(type) ||
shaka.media.Transmuxer.isSupported(type);
var basicType = type.split(';')[0];
support[basicType] = support[basicType] || support[type];
});
Expand Down Expand Up @@ -271,7 +271,7 @@ shaka.media.MediaSourceEngine.prototype.init = function(streamsByType) {
this.reinitText(mimeType);
} else {
if (!MediaSource.isTypeSupported(mimeType) &&
shaka.media.Transmuxer.isSupported(contentType, mimeType)) {
shaka.media.Transmuxer.isSupported(mimeType, contentType)) {
this.transmuxers_[contentType] = new shaka.media.Transmuxer();
mimeType =
shaka.media.Transmuxer.convertTsCodecs(contentType, mimeType);
Expand Down
18 changes: 13 additions & 5 deletions lib/media/transmuxer.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,22 @@ shaka.media.Transmuxer.prototype.destroy = function() {

/**
* Check if the content type is Transport Stream, and if muxjs is loaded.
* @param {string} contentType
* @param {string} mimeType
* @param {string=} contentType
* @return {boolean}
*/
shaka.media.Transmuxer.isSupported = function(contentType, mimeType) {
return window.muxjs && shaka.media.Transmuxer.isTsContainer(mimeType) &&
MediaSource.isTypeSupported(
shaka.media.Transmuxer.convertTsCodecs(contentType, mimeType));
shaka.media.Transmuxer.isSupported = function(mimeType, contentType) {
if (!window.muxjs || !shaka.media.Transmuxer.isTsContainer(mimeType)) {
return false;
}
var convertTsCodecs = shaka.media.Transmuxer.convertTsCodecs;
if (contentType) {
return MediaSource.isTypeSupported(convertTsCodecs(contentType, mimeType));
}
const ContentType = shaka.util.ManifestParserUtils.ContentType;
return MediaSource.isTypeSupported(
convertTsCodecs(ContentType.AUDIO, mimeType)) ||
MediaSource.isTypeSupported(convertTsCodecs(ContentType.VIDEO, mimeType));
};


Expand Down
3 changes: 3 additions & 0 deletions test/media/media_source_engine_unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ describe('MediaSourceEngine', function() {
};

shaka.text.TextEngine = createMockTextEngineCtor();
shaka.media.Transmuxer.isSupported = function(mimeType, contentType) {
return mimeType == 'tsMimetype';
};
});

afterAll(function() {
Expand Down
4 changes: 2 additions & 2 deletions test/media/transmuxer_integration.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ describe('Transmuxer', function() {
describe('isSupported', function() {
var isSupported = shaka.media.Transmuxer.isSupported;
it('returns whether the content type is supported', function() {
expect(isSupported(ContentType.VIDEO, mp4MimeType)).toBeFalsy();
expect(isSupported(ContentType.VIDEO, transportStreamVideoMimeType))
expect(isSupported(mp4MimeType, ContentType.VIDEO)).toBeFalsy();
expect(isSupported(transportStreamVideoMimeType, ContentType.VIDEO))
.toBeTruthy();
});
});
Expand Down

0 comments on commit d987557

Please sign in to comment.