Skip to content

Commit

Permalink
fix(dash): handle case if no period base url, add unique track id
Browse files Browse the repository at this point in the history
  • Loading branch information
vitalygashkov committed Apr 4, 2024
1 parent 06f9b2c commit cac7469
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 5 deletions.
2 changes: 2 additions & 0 deletions lib/audio.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ const checkIsDescriptive = (accessibilities = []) => {
};

const createAudioTrack = ({
id,
codec,
channels,
bitrate,
Expand All @@ -77,6 +78,7 @@ const createAudioTrack = ({
}) => {
const parsedBitrate = parseBitrate(Number(bitrate));
return {
id,
codec,
bitrate: parsedBitrate,
segments,
Expand Down
28 changes: 24 additions & 4 deletions lib/dash.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,11 @@ const parseBaseUrl = (manifestUrl, mpd, period, representation) => {
if (!manifestBaseUrl) manifestBaseUrl = manifestUrl;
else if (!manifestBaseUrl.startsWith('https://'))
manifestBaseUrl = new URL(manifestBaseUrl, manifestUrl).toString();
const periodBaseUrl = new URL(period.getBaseUrl(), manifestBaseUrl).toString();
const representationBaseUrl = new URL(representation.getBaseUrl(), periodBaseUrl).toString();
const periodBaseUrl = new URL(period.getBaseUrl() || '', manifestBaseUrl).toString();
const representationBaseUrl = new URL(
representation.getBaseUrl() || '',
periodBaseUrl
).toString();
return representationBaseUrl;
};

Expand All @@ -79,15 +82,16 @@ const parseCodecs = (representation, contentType, mimeType) => {
const parseLanguage = (representation, adaptationSet, fallbackLanguage) => {
let language = '';
const options = [];
const lang = representation.get('lang');
const id = representation.get('id');
if (representation) {
const { lang, id } = representation.attributes;
options.push(lang);
if (id) {
const m = id.match(/\w+_(\w+)=\d+/);
if (m) options.push(m.group(1));
}
}
options.push(adaptationSet.attributes.lang);
options.push(adaptationSet.get('lang'));
if (fallbackLanguage) options.push(fallbackLanguage);
for (const option of options) {
const value = (option || '').trim();
Expand Down Expand Up @@ -269,9 +273,23 @@ const parseManifest = async (text, url, fallbackLanguage) => {
const accessibilities = adaptationSet.getAll('Accessibility');
const roles = adaptationSet.getAll('Role');

const id = [
get('id'),
get('audioTrackId'),
period.get('id'),
mpd.get('id'),
bitrate,
codecs,
language,
new URL(baseUrl).hostname,
]
.filter(Boolean)
.join('-');

switch (contentType) {
case 'video': {
const track = createVideoTrack({
id,
codec: parseVideoCodec(codecs),
dynamicRange: parseDynamicRange(codecs, supplementalProps, essentialProps),
bitrate,
Expand All @@ -286,6 +304,7 @@ const parseManifest = async (text, url, fallbackLanguage) => {
}
case 'audio': {
const track = createAudioTrack({
id,
codec: parseAudioCodec(codecs),
channels: get('AudioChannelConfiguration').get('value'),
jointObjectCoding: getDolbyDigitalPlusComplexityIndex(supplementalProps),
Expand All @@ -299,6 +318,7 @@ const parseManifest = async (text, url, fallbackLanguage) => {
}
case 'text': {
const track = createSubtitleTrack({
id,
codec: parseSubtitleCodec(codecs || 'vtt'),
isClosedCaption: checkIsClosedCaption(roles),
isSdh: checkIsSdh(accessibilities),
Expand Down
11 changes: 10 additions & 1 deletion lib/subtitle.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,17 @@ const checkIsForced = (roles = []) => {
return false;
};

const createSubtitleTrack = ({ codec, isClosedCaption, isSdh, isForced, language, segments }) => {
const createSubtitleTrack = ({
id,
codec,
isClosedCaption,
isSdh,
isForced,
language,
segments,
}) => {
return {
id,
codec,
isClosedCaption,
isSdh,
Expand Down
2 changes: 2 additions & 0 deletions lib/video.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ const parseDynamicRangeFromCicp = (primaries, transfer, matrix) => {
};

const createVideoTrack = ({
id,
codec,
dynamicRange,
bitrate,
Expand All @@ -95,6 +96,7 @@ const createVideoTrack = ({
const parsedWidth = Number(width);
const parsedHeight = Number(height);
return {
id,
codec,
bitrate: parsedBitrate,
segments,
Expand Down

0 comments on commit cac7469

Please sign in to comment.