Skip to content

Commit

Permalink
feat(hls): add segment ticks in header
Browse files Browse the repository at this point in the history
  • Loading branch information
uZer committed Jan 14, 2025
1 parent 03e2322 commit c53e3ba
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ reload: ## Update containers if needed and restart all liquidsoaps
@docker compose restart \
liquidsoap-myradio \
liquidsoap-myradiosurround \
source-mystreamersurround \
source-mystreamersurround
@docker compose ps
@docker compose logs -f

Expand Down
21 changes: 15 additions & 6 deletions scripts/transcoder/outputs/hls.liq
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,15 @@ end
## HLS segments

def segment_name(metadata) =
let {position, duration, extname, stream_name} = metadata
let {position, duration, extname, stream_name, ticks} = metadata
segment_duration = int_of_float(duration)
segment_timestamp = int_of_float(time())

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

def on_file_change(~state, fname) =
Expand All @@ -71,17 +73,24 @@ def on_file_change(~state, fname) =
"Uploading #{fname} to #{target}/#{path.basename(fname)}"
)
file = file.contents(fname)
let [ticks, ...segment_name] = string.split(separator="_", fname)
target_fname = string.concat(separator="_", segment_name)
uploadsegment =
http.post(
headers=[("Origin", hls_segments_http_post_origin)],
headers=
[
("Origin", hls_segments_http_post_origin),
("X-Duration-Ticks", ticks)
],
data=file,
timeout=2.,
target ^ "/#{path.basename(fname)}"
target ^ "/#{path.basename(target_fname)}"
)
log.important(
label="hlssegmentpush",
'{"timestamp": "#{time()}", "request": "/#{path.basename(fname)}", \
"response": "#{uploadsegment.status_code}", "protocol": "#{
'{"timestamp": "#{time()}", "request": "/#{
path.basename(target_fname)
}", "response": "#{uploadsegment.status_code}", "protocol": "#{
uploadsegment.http_version
}", "target": "' ^
target ^
Expand Down

0 comments on commit c53e3ba

Please sign in to comment.