Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: improve serviceLocation for content steering #177

Merged
merged 7 commits into from
Aug 30, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion src/inheritAttributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,21 @@ export const buildBaseUrls = (references, baseUrlElements) => {

return flatten(references.map(function(reference) {
return baseUrlElements.map(function(baseUrlElement) {
return merge(parseAttributes(baseUrlElement), { baseUrl: resolveUrl(reference.baseUrl, getContent(baseUrlElement)) });
const initialBaseUrl = getContent(baseUrlElement);
const resolvedBaseUrl = resolveUrl(reference.baseUrl, initialBaseUrl);

const finalBaseUrl = merge(
parseAttributes(baseUrlElement),
{ baseUrl: resolvedBaseUrl }
);

// If the URL is resolved, we want to get the serviceLocation from the reference
// assuming there is no serviceLocation on the initialBaseUrl
if (resolvedBaseUrl !== initialBaseUrl && !finalBaseUrl.serviceLocation && reference.serviceLocation) {
finalBaseUrl.serviceLocation = reference.serviceLocation;
}

return finalBaseUrl;
});
}));
};
Expand Down
7 changes: 6 additions & 1 deletion src/segment/segmentTemplate.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,8 @@ export const segmentsFromTemplate = (attributes, segmentTimeline) => {
const mapSegment = urlTypeToSegment({
baseUrl: attributes.baseUrl,
source: constructTemplateUrl(initialization.sourceURL, templateValues),
range: initialization.range
range: initialization.range,
serviceLocation: attributes.serviceLocation
});

const segments = parseTemplateInfo(attributes, segmentTimeline);
Expand Down Expand Up @@ -177,6 +178,10 @@ export const segmentsFromTemplate = (attributes, segmentTimeline) => {
presentationTime
};

if (attributes.serviceLocation) {
map.serviceLocation = attributes.serviceLocation;
}

return map;
});
};
8 changes: 7 additions & 1 deletion src/segment/urlType.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,21 @@ import window from 'global/window';
* @param {string} source - source url for segment
* @param {string} range - optional range used for range calls,
* follows RFC 2616, Clause 14.35.1
* @param {string} serviceLocation - optional serviceLocation provided by <BaseUrl> nodes
* used for content steering
* @return {SingleUri} full segment information transformed into a format similar
* to m3u8-parser
*/
export const urlTypeToSegment = ({ baseUrl = '', source = '', range = '', indexRange = '' }) => {
export const urlTypeToSegment = ({ baseUrl = '', source = '', range = '', serviceLocation = null, indexRange = '' }) => {
const segment = {
uri: source,
resolvedUri: resolveUrl(baseUrl || '', source)
};

if (serviceLocation) {
segment.serviceLocation = serviceLocation;
}

if (range || indexRange) {
const rangeStr = range ? range : indexRange;
const ranges = rangeStr.split('-');
Expand Down
9 changes: 8 additions & 1 deletion src/toM3u8.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ export const formatVttPlaylist = ({
duration: attributes.sourceDuration,
number: 0
}];

// targetDuration should be the same duration as the only segment
attributes.duration = attributes.sourceDuration;
}
Expand All @@ -152,7 +153,7 @@ export const formatVttPlaylist = ({
if (attributes.codecs) {
m3u8Attributes.CODECS = attributes.codecs;
}
return {
const vttPlaylist = {
attributes: m3u8Attributes,
uri: '',
endList: attributes.type === 'static',
Expand All @@ -165,6 +166,12 @@ export const formatVttPlaylist = ({
mediaSequence,
segments
};

if (attributes.serviceLocation) {
vttPlaylist.serviceLocation = attributes.serviceLocation;
}

return vttPlaylist;
};

export const organizeAudioPlaylists = (playlists, sidxMapping = {}, isAudioOnly = false) => {
Expand Down
13 changes: 8 additions & 5 deletions test/inheritAttributes.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -927,10 +927,11 @@ QUnit.test('end to end - content steering - resolvable base URLs', function(asse
id="test"
width="720">
</Representation>
<BaseURL>/video</BaseURL>
</AdaptationSet>
<AdaptationSet mimeType="text/vtt" lang="en">
<Representation bandwidth="256" id="en">
<BaseURL>/video</BaseURL>
<BaseURL>/vtt</BaseURL>
</Representation>
</AdaptationSet>
</Period>
Expand All @@ -957,7 +958,7 @@ QUnit.test('end to end - content steering - resolvable base URLs', function(asse
attributes: {
NOW,
bandwidth: 5000000,
baseUrl: 'https://cdn1.example.com/',
baseUrl: 'https://cdn1.example.com/video',
clientOffset: 0,
codecs: 'avc1.64001e',
height: 404,
Expand All @@ -980,7 +981,7 @@ QUnit.test('end to end - content steering - resolvable base URLs', function(asse
attributes: {
NOW,
bandwidth: 5000000,
baseUrl: 'https://cdn2.example.com/',
baseUrl: 'https://cdn2.example.com/video',
clientOffset: 0,
codecs: 'avc1.64001e',
height: 404,
Expand All @@ -1003,13 +1004,14 @@ QUnit.test('end to end - content steering - resolvable base URLs', function(asse
attributes: {
NOW,
bandwidth: 256,
baseUrl: 'https://cdn1.example.com/video',
baseUrl: 'https://cdn1.example.com/vtt',
clientOffset: 0,
id: 'en',
lang: 'en',
mimeType: 'text/vtt',
periodStart: 0,
role: {},
serviceLocation: 'alpha',
sourceDuration: 0,
type: 'dyanmic'
},
Expand All @@ -1019,13 +1021,14 @@ QUnit.test('end to end - content steering - resolvable base URLs', function(asse
attributes: {
NOW,
bandwidth: 256,
baseUrl: 'https://cdn2.example.com/video',
baseUrl: 'https://cdn2.example.com/vtt',
clientOffset: 0,
id: 'en',
lang: 'en',
mimeType: 'text/vtt',
periodStart: 0,
role: {},
serviceLocation: 'beta',
sourceDuration: 0,
type: 'dyanmic'
},
Expand Down
Loading