Skip to content

Commit

Permalink
Use vhs-utils codec parsing functions for EME setup
Browse files Browse the repository at this point in the history
  • Loading branch information
gesinger committed Mar 15, 2021
1 parent 77186f2 commit 49d90e6
Showing 1 changed file with 10 additions and 21 deletions.
31 changes: 10 additions & 21 deletions src/videojs-http-streaming.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,12 @@ import {
comparePlaylistBandwidth,
comparePlaylistResolution
} from './playlist-selectors.js';
import {isAudioCodec, isVideoCodec, browserSupportsCodec} from '@videojs/vhs-utils/es/codecs.js';
import {
browserSupportsCodec,
getMimeForCodec,
parseCodecs
} from '@videojs/vhs-utils/es/codecs.js';
import { unwrapCodecList } from './util/codecs.js';
import logger from './util/logger';
import {SAFE_TIME_DELTA} from './ranges';

Expand Down Expand Up @@ -132,34 +137,18 @@ const emeKeySystems = (keySystemOptions, mainPlaylist, audioPlaylist) => {
return keySystemOptions;
}

const codecs = {};
let codecs = {};

if (mainPlaylist && mainPlaylist.attributes && mainPlaylist.attributes.CODECS) {
const mainCodecs = mainPlaylist.attributes.CODECS;

if (mainCodecs.split(',').length > 1) {
mainCodecs.split(',').forEach(function(codec) {
codec = codec.trim();

if (isAudioCodec(codec)) {
codecs.audio = codec;
} else if (isVideoCodec(codec)) {
codecs.video = codec;
}
});
} else if (isAudioCodec(mainCodecs)) {
codecs.audio = mainCodecs;
} else {
codecs.video = mainCodecs;
}
codecs = unwrapCodecList(parseCodecs(mainPlaylist.attributes.CODECS));
}

if (audioPlaylist && audioPlaylist.attributes && audioPlaylist.attributes.CODECS) {
codecs.audio = audioPlaylist.attributes.CODECS;
}

const videoContentType = codecs.video ? `video/mp4;codecs="${codecs.video}"` : null;
const audioContentType = codecs.audio ? `audio/mp4;codecs="${codecs.audio}"` : null;
const videoContentType = getMimeForCodec(codecs.video);
const audioContentType = getMimeForCodec(codecs.audio);

// upsert the content types based on the selected playlist
const keySystemContentTypes = {};
Expand Down

0 comments on commit 49d90e6

Please sign in to comment.