Skip to content

Commit

Permalink
wip: variable handling
Browse files Browse the repository at this point in the history
  • Loading branch information
zapfire88 authored and bwallberg committed Feb 22, 2024
1 parent 3333ec2 commit 7582384
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 10 deletions.
11 changes: 10 additions & 1 deletion src/manifests/handlers/dash/segment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,13 @@ export default async function dashSegmentHandler(
const urlSearchParams = new URLSearchParams(event.queryStringParameters);
const pathStem = path.basename(event.path).replace('.mp4', '');
// Get the number part after "segment_"
const [, reqSegmentIndexOrTimeStr, representationIdStr, bitrateStr] =
// eslint-disable-next-line prefer-const
const [, reqSegmentIndexOrTimeStr, bitrateStr, ...representationIdStrList] =
pathStem.split('_');
let representationIdStr = representationIdStrList.join('-');
// Build correct Source Segment url
// segment templates may contain a width parameter "$Number%0[width]d$", and then we need to zero-pad them to that length

let segmentUrl = url;

if (segmentUrl.includes('$Time$')) {
Expand All @@ -54,6 +57,12 @@ export default async function dashSegmentHandler(
}
const reqSegmentIndexInt = parseInt(reqSegmentIndexOrTimeStr);

const possibleId = pathStem.match(
/(audio|video)_track_\d+_\d+_[a-zA-Z]{3}=\d+_\d+/
);
if (possibleId) {
representationIdStr = possibleId[0];
}
// Replace RepresentationID in url if present
if (representationIdStr) {
segmentUrl = segmentUrl.replace(
Expand Down
4 changes: 2 additions & 2 deletions src/manifests/utils/dashManifestUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,8 @@ export default function (): DASHManifestTools {
mediaUrl.match(/^http/) ? mediaUrl : baseUrl + mediaUrl,
urlQuery,
hasTime
? 'proxy-segment/segment_$Time$_$RepresentationID$_$Bandwidth$'
: 'proxy-segment/segment_$Number$_$RepresentationID$_$Bandwidth$'
? 'proxy-segment/segment_$Time$_$Bandwidth$_$RepresentationID$'
: 'proxy-segment/segment_$Number$_$Bandwidth$_$RepresentationID$'
);
segmentTemplate.$.media = proxy;
// Initialization attr.
Expand Down
7 changes: 4 additions & 3 deletions src/shared/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -188,8 +188,10 @@ type ProxyBasenames =
| '../../segments/proxy-segment'
| 'proxy-segment/segment_$Number$.mp4'
| 'proxy-segment/segment_$Time$.mp4'
| 'proxy-segment/segment_$Number$_$RepresentationID$_$Bandwidth$'
| 'proxy-segment/segment_$Time$_$RepresentationID$_$Bandwidth$';
| 'proxy-segment/segment_$Number$_$RepresentationID$'
| 'proxy-segment/segment_$Time$_$RepresentationID$'
| 'proxy-segment/segment_$Number$_$Bandwidth$_$RepresentationID$'
| 'proxy-segment/segment_$Time$_$Bandwidth$_$RepresentationID$';

/**
* Adjust paths based on directory navigation
Expand Down Expand Up @@ -225,7 +227,6 @@ export function proxyPathBuilder(
if (!urlSearchParams) {
return '';
}
itemUri.replace('-', '/');
const allQueries = new URLSearchParams(urlSearchParams);
let sourceItemURL = '';
// Do not build an absolute source url If ItemUri is already an absolut url.
Expand Down
4 changes: 2 additions & 2 deletions src/testvectors/dash/dash1_compressed/proxy-manifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
<SegmentTemplate
timescale="48000"
initialization="https://mock.mock.com/stream/relative_base/audiotrack/init/$RepresentationID$.m4s"
media="proxy-segment/segment_$Time$_$RepresentationID$_$Bandwidth$?url=https%3A%2F%2Fmock.mock.com%2Fstream%2Frelative_base%2Faudiotrack%2F%24RepresentationID%24%2F%24Time%24.m4s&amp;statusCode=%5B%7Bi%3A0%2Ccode%3A404%7D%2C%7Bi%3A2%2Ccode%3A401%7D%5D&amp;timeout=%5B%7Bi%3A3%7D%5D&amp;delay=%5B%7Bi%3A2%2Cms%3A2000%7D%5D">
media="proxy-segment/segment_$Time$_$Bandwidth$_$RepresentationID$?url=https%3A%2F%2Fmock.mock.com%2Fstream%2Frelative_base%2Faudiotrack%2F%24RepresentationID%24%2F%24Time%24.m4s&amp;statusCode=%5B%7Bi%3A0%2Ccode%3A404%7D%2C%7Bi%3A2%2Ccode%3A401%7D%5D&amp;timeout=%5B%7Bi%3A3%7D%5D&amp;delay=%5B%7Bi%3A2%2Cms%3A2000%7D%5D">
<SegmentTimeline>
<S t="80746389121167" d="184320" r="78" />
</SegmentTimeline>
Expand Down Expand Up @@ -62,7 +62,7 @@
<SegmentTemplate
timescale="600"
initialization="https://mock.mock.com/stream/relative_base/videotrack/init/$RepresentationID$.m4s"
media="proxy-segment/segment_$Time$_$RepresentationID$_$Bandwidth$?url=https%3A%2F%2Fmock.mock.com%2Fstream%2Frelative_base%2Fvideotrack%2F%24RepresentationID%24%2F%24Time%24.m4s&amp;statusCode=%5B%7Bi%3A0%2Ccode%3A404%7D%2C%7Bi%3A2%2Ccode%3A401%7D%5D&amp;timeout=%5B%7Bi%3A3%7D%5D&amp;delay=%5B%7Bi%3A2%2Cms%3A2000%7D%5D">
media="proxy-segment/segment_$Time$_$Bandwidth$_$RepresentationID$?url=https%3A%2F%2Fmock.mock.com%2Fstream%2Frelative_base%2Fvideotrack%2F%24RepresentationID%24%2F%24Time%24.m4s&amp;statusCode=%5B%7Bi%3A0%2Ccode%3A404%7D%2C%7Bi%3A2%2Ccode%3A401%7D%5D&amp;timeout=%5B%7Bi%3A3%7D%5D&amp;delay=%5B%7Bi%3A2%2Cms%3A2000%7D%5D">
<SegmentTimeline>
<S t="1009329864060" d="2304" r="78" />
</SegmentTimeline>
Expand Down
4 changes: 2 additions & 2 deletions src/testvectors/dash/dash_period_baseurl/proxy-manifest.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<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">
<SegmentTemplate timescale="1000" media="proxy-segment/segment_$Number$_$Bandwidth$_$RepresentationID$?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"/>
Expand All @@ -17,7 +17,7 @@
</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">
<SegmentTemplate timescale="1000" media="proxy-segment/segment_$Number$_$Bandwidth$_$RepresentationID$?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"/>
Expand Down

0 comments on commit 7582384

Please sign in to comment.