|
17 | 17 | stream_id = get_env("STREAM_ID") |
18 | 18 | api_base = get_env("STREAM_API_BASE") |
19 | 19 | api_token = get_env("STREAM_API_TOKEN") |
| 20 | +control_port = int_of_string(get_env("PORT")) |
20 | 21 |
|
21 | 22 | def notify_ready() = |
22 | 23 | # the endpoint doesn't need any request body values, but liquidsoap json.stringify serialises {} as an empty array |
|
34 | 35 |
|
35 | 36 | in = input.jack(id="streamer_#{stream_id}") |
36 | 37 |
|
| 38 | +source = ref(2) |
| 39 | + |
| 40 | +starting = amplify(0.5, single("/opt/radio-tx/starting.mp3")) |
| 41 | +ended = amplify(0.5, single("/opt/radio-tx/ended.mp3")) |
| 42 | +techdiff = amplify(0.5, single("/opt/radio-tx/techdiff.mp3")) |
| 43 | + |
| 44 | +def handle_set_source(request, response) = |
| 45 | + response.status_code(200) |
| 46 | + new_source = int_of_string(request.query["source"]) |
| 47 | + if (new_source >= 1 and new_source <= 4 and new_source != source()) then |
| 48 | + source.set(new_source) |
| 49 | + if (new_source == 2) then |
| 50 | + starting.skip() |
| 51 | + elsif (new_source == 3) then |
| 52 | + ended.skip() |
| 53 | + elsif (new_source == 4) then |
| 54 | + techdiff.skip() |
| 55 | + end |
| 56 | + response.json({source=source()}) |
| 57 | + else |
| 58 | + response.json({source=source()}) |
| 59 | + end |
| 60 | +end |
| 61 | + |
| 62 | +def handle_get_source(request, response) = |
| 63 | + response.status_code(200) |
| 64 | + response.json({source=source()}) |
| 65 | +end |
| 66 | + |
| 67 | +harbor.http.register(port=control_port, method="POST", "/source/:source", handle_set_source) |
| 68 | +harbor.http.register(port=control_port, method="GET", "/source", handle_get_source) |
| 69 | + |
| 70 | +stream = switch( |
| 71 | + [ |
| 72 | + ({source() == 1}, in), |
| 73 | + ({source() == 2}, starting), |
| 74 | + ({source() == 3}, ended), |
| 75 | + ({source() == 4}, techdiff), |
| 76 | + ({true}, techdiff), |
| 77 | + ], |
| 78 | + track_sensitive=false |
| 79 | + # transitions=[ |
| 80 | + # do_nice_fade, do_nice_fade, do_nice_fade, do_nice_fade, do_nice_fade |
| 81 | + # ] |
| 82 | +) |
| 83 | + |
37 | 84 | aac_high = |
38 | 85 | %ffmpeg( |
39 | 86 | format = "mpegts", |
@@ -96,5 +143,5 @@ output.file.hls( |
96 | 143 | persist_at="./hls.state", |
97 | 144 | "/var/www/hls/#{stream_id}/", |
98 | 145 | streams, |
99 | | - in |
| 146 | + stream |
100 | 147 | ) |
0 commit comments