Skip to content
This repository has been archived by the owner on Jan 12, 2019. It is now read-only.

Fixed codecs to mimetype conversion to take into account all possible scenarios #1099

Merged
merged 2 commits into from
Apr 27, 2017

Conversation

imbcmdth
Copy link
Member

@imbcmdth imbcmdth commented Apr 26, 2017

Description

There are 4 possible predicates that influence how to generate mimetypes from codec strings:

  • Video codec specified
  • Audio codec specified
  • Are there multiple audio tracks (audio media-groups)
  • If so, is the primary media demuxed (lacking audio)

This PR adds complete unit testing of all 24 possible combinations and fixes issues around the function that caused audio-only streams with multiple audio tracks present.

Requirements Checklist

  • Feature implemented / Bug fixed
  • If necessary, more likely in a feature request than a bug fix
    • Unit Tests updated or fixed
  • Reviewed by Two Core Contributors

@@ -14,6 +14,13 @@ import Decrypter from './decrypter-worker';

let Hls;

// Default codec parameters if non were provided for video and/or audio
Copy link
Contributor

Choose a reason for hiding this comment

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

none

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

// Default codec parameters if non were provided for video and/or audio
const defaultCodecs = {
videoCodec: 'avc1',
videoObjectTypeIndicator: '.4d400d',
Copy link
Contributor

Choose a reason for hiding this comment

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

Might be worth adding a comment why this is default

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm not sure there is a reason other than "This was a common configuration when we started writing this project..." which is a crappy comment 🥇

};

const getContainerType = function(media) {
// An initialization segment means the media playlists is an iframe
Copy link
Contributor

Choose a reason for hiding this comment

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

playlist


if (!media) {
// not enough information, return an error
// Not enough information, return an error
Copy link
Contributor

Choose a reason for hiding this comment

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

Since this is being modified, it's not really returning an error. Might be worth leaving it at // Not enough information

// HLS with multiple-audio tracks must always get an audio codec.
// Put another way, there is no way to have a video-only multiple-audio HLS!
if (isMaat && !codecInfo.audioProfile) {
codecInfo.audioProfile = defaultCodecs.audioProfile;
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we log a warning or info here? Although I agree that we have to default to some kind of codec, the codec should be specified in the manifest in a case like this, and not including it is potentially dangerous.

Copy link
Member Author

Choose a reason for hiding this comment

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

I don't know.. It seems like a fairly common configuration with MAAT unfortunately.. I add a warning log.

];
}
previousGroup = audioGroup[groupId];
return [
bothVideoAudio,
Copy link
Contributor

Choose a reason for hiding this comment

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

If someone provides the CODECS attribute, but only sets the audio codec, then bothVideoAudio could end up with something like: 'video/mp2t; codecs=mp4a.40.2'. Would that be valid for when we need to play both video and audio?

EDIT: Noticed there is a test for this case, so I'm assuming it's valid, but just wanted to make sure.

@@ -19,6 +19,40 @@ import { Hls } from '../src/videojs-contrib-hls';
/* eslint-enable no-unused-vars */
import Playlist from '../src/playlist';

const generateMedia = function(isMaat, isMuxed, hasVideoCodec, hasAudioCodec) {
const codec = (hasVideoCodec ? 'avc1.4d400d' : '') +
Copy link
Contributor

Choose a reason for hiding this comment

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

Would be good to use different codecs from the defaults when testing provided codecs

Copy link
Member Author

Choose a reason for hiding this comment

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

Good point.

@gesinger
Copy link
Contributor

We should also have tests for video/mp4 and audio/mp4


assert.deepEqual(mimeTypesForPlaylist_.apply(null,
generateMedia(true, false, false, true, isFMP4)),
[`${videoMime}; codecs="mp4a.40.E"`,
Copy link
Contributor

Choose a reason for hiding this comment

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

This still seems so odd to me.

// types
if (previousGroup && previousGroup.uri) {

// If there is ano video codec at all, always just return a single
Copy link
Contributor

Choose a reason for hiding this comment

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

ano

@imbcmdth imbcmdth merged commit 4daa28f into master Apr 27, 2017
@imbcmdth imbcmdth deleted the codec-string-fix branch April 27, 2017 22:18
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants