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(#54): period baseUrl isn't used #55

Merged
merged 2 commits into from
Feb 15, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
31 changes: 31 additions & 0 deletions src/manifests/utils/dashManifestUtils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,37 @@ describe('dashManifestTools', () => {
const expected: string = builder.buildObject(DASH_JSON);
expect(proxyManifest).toEqual(expected);
});

it('should use the period baseUrl if it exists', async () => {
// Arrange
const mockManifestPath =
'../../testvectors/dash/dash_period_baseurl/manifest.xml';
const mockDashManifest = fs.readFileSync(
path.join(__dirname, mockManifestPath),
'utf8'
);
const manifestUtils = dashManifestUtils();
const proxyManifest: string = manifestUtils.createProxyDASHManifest(
mockDashManifest,
new URLSearchParams(
'url=https://mock.mock.com/stream/dash/period_base_url/manifest.mpd'
)
);
const proxyManifestPath =
'../../testvectors/dash/dash_period_baseurl/proxy-manifest.xml';
const dashFile: string = fs.readFileSync(
path.join(__dirname, proxyManifestPath),
'utf8'
);
let DASH_JSON;
const parser = new xml2js.Parser();
const builder = new xml2js.Builder();
parser.parseString(dashFile, function (err, result) {
DASH_JSON = result;
});
const expected: string = builder.buildObject(DASH_JSON);
expect(proxyManifest).toEqual(expected);
});
});
});

Expand Down
12 changes: 9 additions & 3 deletions src/manifests/utils/dashManifestUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,17 +63,23 @@
DASH_JSON = result;
});

let baseUrl;
let globalBaseUrl;
if (DASH_JSON.MPD.BaseURL) {
// There should only ever be one baseurl according to schema
baseUrl = DASH_JSON.MPD.BaseURL[0];
// Remove base url from manifest since we are using relative paths for proxy
globalBaseUrl = DASH_JSON.MPD.BaseURL[0];
}
// Remove base url from manifest since we are using relative paths for proxy
delete DASH_JSON.MPD.BaseURL;

let staticQueryUrl: URLSearchParams;

DASH_JSON.MPD.Period.map((period) => {
let baseUrl = globalBaseUrl;
if (period.BaseURL?.[0]) {
baseUrl = period.BaseURL[0];
// Remove base url from manifest since we are using relative paths for proxy
delete period.BaseURL;
}
period.AdaptationSet.map((adaptationSet) => {
// If there is a SegmentTemplate directly in the adaptationSet there should only be one
// But if it has no media property it is invalid and we should try the Representation instead
Expand Down Expand Up @@ -174,8 +180,8 @@
}

function convertRelativeToAbsoluteSegmentOffsets(
mpd: any,

Check warning on line 183 in src/manifests/utils/dashManifestUtils.ts

View workflow job for this annotation

GitHub Actions / lint

Unexpected any. Specify a different type
segmentTemplate: any,

Check warning on line 184 in src/manifests/utils/dashManifestUtils.ts

View workflow job for this annotation

GitHub Actions / lint

Unexpected any. Specify a different type
originalUrlQuery: URLSearchParams,
segmentTemplateTimelineFormat: boolean
): [URLSearchParams, boolean] {
Expand Down
32 changes: 32 additions & 0 deletions src/testvectors/dash/dash_period_baseurl/manifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<MPD xmlns="urn:mpeg:DASH:schema:MPD:2011" minBufferTime="PT1.500S" type="static" mediaPresentationDuration="PT0H0M10.000S" maxSegmentDuration="PT0H0M1.000S" profiles="urn:mpeg:dash:profile:isoff-on-demand:2011" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="urn:mpeg:DASH:schema:MPD:2011 DASH-MPD.xsd">
<Period id="0" start="PT0H0M0.000S">
<BaseURL>http://vm2.dashif.org/livesim-dev/periods_60/</BaseURL>
<AdaptationSet mimeType="video/mp4" codecs="avc1.4D401E" frameRate="30000/1001" lang="und">
<SegmentTemplate timescale="1000" media="video_$Number$.mp4" initialization="video_init.mp4" startNumber="1" presentationTimeOffset="0">
<SegmentTimeline>
<S t="0" d="10000"/>
<S t="10000" d="10000"/>
<S t="20000" d="10000"/>
<S t="30000" d="10000"/>
<S t="40000" d="10000"/>
<S t="50000" d="10000"/>
<S t="60000" d="10000"/>
<S t="70000" d="10000"/>
<S t="80000" d="10000"/>
<S t="90000" d="10000"/>
</SegmentTimeline>
</SegmentTemplate>
</AdaptationSet>
<AdaptationSet mimeType="audio/mp4" lang="und">
<SegmentTemplate timescale="1000" media="audio_$Number$.mp4" initialization="audio_init.mp4" startNumber="1" presentationTimeOffset="0">
<SegmentTimeline>
<S t="0" d="10000"/>
<S t="10000" d="10000"/>
<S t="20000" d="10000"/>
<S t="30000" d="10000"/>
</SegmentTimeline>
</SegmentTemplate>

</AdaptationSet>
</Period>
</MPD>
31 changes: 31 additions & 0 deletions src/testvectors/dash/dash_period_baseurl/proxy-manifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<MPD xmlns="urn:mpeg:DASH:schema:MPD:2011" minBufferTime="PT1.500S" type="static" mediaPresentationDuration="PT0H0M10.000S" maxSegmentDuration="PT0H0M1.000S" profiles="urn:mpeg:dash:profile:isoff-on-demand:2011" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="urn:mpeg:DASH:schema:MPD:2011 DASH-MPD.xsd">
<Period id="0" start="PT0H0M0.000S">
<AdaptationSet mimeType="video/mp4" codecs="avc1.4D401E" frameRate="30000/1001" lang="und">
<SegmentTemplate timescale="1000" media="proxy-segment/segment_$Number$_$RepresentationID$_$Bandwidth$?url=http%3A%2F%2Fvm2.dashif.org%2Flivesim-dev%2Fperiods_60%2Fvideo_%24Number%24.mp4" initialization="http://vm2.dashif.org/livesim-dev/periods_60/video_init.mp4" startNumber="1" presentationTimeOffset="0">
<SegmentTimeline>
<S t="0" d="10000"/>
<S t="10000" d="10000"/>
<S t="20000" d="10000"/>
<S t="30000" d="10000"/>
<S t="40000" d="10000"/>
<S t="50000" d="10000"/>
<S t="60000" d="10000"/>
<S t="70000" d="10000"/>
<S t="80000" d="10000"/>
<S t="90000" d="10000"/>
</SegmentTimeline>
</SegmentTemplate>
</AdaptationSet>
<AdaptationSet mimeType="audio/mp4" lang="und">
<SegmentTemplate timescale="1000" media="proxy-segment/segment_$Number$_$RepresentationID$_$Bandwidth$?url=http%3A%2F%2Fvm2.dashif.org%2Flivesim-dev%2Fperiods_60%2Faudio_%24Number%24.mp4" initialization="http://vm2.dashif.org/livesim-dev/periods_60/audio_init.mp4" startNumber="1" presentationTimeOffset="0">
<SegmentTimeline>
<S t="0" d="10000"/>
<S t="10000" d="10000"/>
<S t="20000" d="10000"/>
<S t="30000" d="10000"/>
</SegmentTimeline>
</SegmentTemplate>

</AdaptationSet>
</Period>
</MPD>
Loading