Skip to content

Commit 9f219b7

Browse files
committed
feat(hls): add segment ticks in header
1 parent 03e2322 commit 9f219b7

File tree

2 files changed

+16
-7
lines changed

2 files changed

+16
-7
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ reload: ## Update containers if needed and restart all liquidsoaps
2828
@docker compose restart \
2929
liquidsoap-myradio \
3030
liquidsoap-myradiosurround \
31-
source-mystreamersurround \
31+
source-mystreamersurround
3232
@docker compose ps
3333
@docker compose logs -f
3434

scripts/transcoder/outputs/hls.liq

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,15 @@ end
4646
## HLS segments
4747

4848
def segment_name(metadata) =
49-
let {position, duration, extname, stream_name} = metadata
49+
let {position, duration, extname, stream_name, ticks} = metadata
5050
segment_duration = int_of_float(duration)
5151
segment_timestamp = int_of_float(time())
5252

5353
# Add the codec to the segment name because it's expected by segment-forwarder
5454
segment_prefix = string.replace(pattern="_", fun (_) -> "_aac_", stream_name)
55-
"#{segment_prefix}_#{segment_duration}_#{position}_#{segment_timestamp}.ts"
55+
"#{ticks}_#{segment_prefix}_#{segment_duration}_#{position}_#{
56+
segment_timestamp
57+
}.ts"
5658
end
5759

5860
def on_file_change(~state, fname) =
@@ -71,17 +73,24 @@ def on_file_change(~state, fname) =
7173
"Uploading #{fname} to #{target}/#{path.basename(fname)}"
7274
)
7375
file = file.contents(fname)
76+
let [ticks, ...segment_name] = string.split(separator="_", fname)
77+
target_fname = string.concat(separator="_", segment_name)
7478
uploadsegment =
7579
http.post(
76-
headers=[("Origin", hls_segments_http_post_origin)],
80+
headers=
81+
[
82+
("X-Origin-Transcoder", hls_segments_http_post_origin),
83+
("X-Duration-Ticks", ticks)
84+
],
7785
data=file,
7886
timeout=2.,
79-
target ^ "/#{path.basename(fname)}"
87+
target ^ "/#{path.basename(target_fname)}"
8088
)
8189
log.important(
8290
label="hlssegmentpush",
83-
'{"timestamp": "#{time()}", "request": "/#{path.basename(fname)}", \
84-
"response": "#{uploadsegment.status_code}", "protocol": "#{
91+
'{"timestamp": "#{time()}", "request": "/#{
92+
path.basename(target_fname)
93+
}", "response": "#{uploadsegment.status_code}", "protocol": "#{
8594
uploadsegment.http_version
8695
}", "target": "' ^
8796
target ^

0 commit comments

Comments
 (0)