Skip to content

Commit

Permalink
feat: improve serviceLocation for content steering
Browse files Browse the repository at this point in the history
  • Loading branch information
wseymour15 committed Aug 21, 2023
1 parent 5493dda commit 2211fa4
Show file tree
Hide file tree
Showing 7 changed files with 520 additions and 9 deletions.
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 = finalBaseUrl.serviceLocation || reference.serviceLocation;
}

return finalBaseUrl;
});
}));
};
Expand Down
4 changes: 3 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 All @@ -172,6 +173,7 @@ export const segmentsFromTemplate = (attributes, segmentTimeline) => {
timeline: segment.timeline,
duration: segment.duration,
resolvedUri: resolveUrl(attributes.baseUrl || '', uri),
serviceLocation: attributes.serviceLocation,
map: mapSegment,
number: segment.number,
presentationTime
Expand Down
7 changes: 5 additions & 2 deletions src/segment/urlType.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,16 @@ 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)
resolvedUri: resolveUrl(baseUrl || '', source),
serviceLocation
};

if (range || indexRange) {
Expand Down
2 changes: 2 additions & 0 deletions src/toM3u8.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ export const formatVttPlaylist = ({
timeline: attributes.periodStart,
resolvedUri: attributes.baseUrl || '',
duration: attributes.sourceDuration,
serviceLocation: attributes.serviceLocation,
number: 0
}];
// targetDuration should be the same duration as the only segment
Expand All @@ -161,6 +162,7 @@ export const formatVttPlaylist = ({
targetDuration: attributes.duration,
timelineStarts: attributes.timelineStarts,
discontinuityStarts,
serviceLocation: attributes.serviceLocation,
discontinuitySequence,
mediaSequence,
segments
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

0 comments on commit 2211fa4

Please sign in to comment.