Skip to content

Commit 45adb47

Browse files
committed
feat(streamer): backport autofallback from transcoder
1 parent 7a3a963 commit 45adb47

4 files changed

Lines changed: 84 additions & 18 deletions

File tree

example/liquidsoap/mystreamer.liq

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,33 +4,30 @@ streamer_name = "mystreamer"
44
harbor_http_port = 7020
55
prometheus_server_port = 9021
66
liquidsoap_log_level = 3
7-
8-
# tmp
9-
input_playlist_file = "/audio/lib/#{streamer_name}.m3u"
7+
livesource_state_path = "/state/#{streamer_name}.livesourcestate"
108

119
input_list =
1210
[
1311
{
1412
name="voieA",
15-
kind=fun (input_kinds) -> input_kinds.restream,
13+
kind="restream",
1614
input="udp://228.0.6.102:1026",
17-
is_autofallback=true,
18-
priority=100
15+
playlist_file="",
16+
is_autofallback=true
1917
},
2018
{
2119
name="voieB",
22-
kind=fun (input_kinds) -> input_kinds.restream,
20+
kind="restream",
2321
input="./example/liquidsoap/mystreamer-voieB.sdp",
2422
input_options="protocol_whitelist='file,udp,rtp'",
25-
is_autofallback=true,
26-
priority=101
23+
playlist_file="",
24+
is_autofallback=true
2725
},
2826
{
2927
name="localPlaylist",
30-
kind=fun (input_kinds) -> input_kinds.playlist,
28+
kind="playlist",
3129
playlist_file="/audio/lib/#{streamer_name}.m3u",
32-
is_autofallback=true,
33-
priority=102
30+
is_autofallback=true
3431
}
3532
]
3633

scripts/streamer/00-live.liq

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
#!/usr/bin/liquidsoap
22

33
%include "10-settings.liq"
4-
%include "20-prometheus.liq"
54

6-
%include "inputs/playlist.liq"
5+
# We define the default preferred_live_source (for the switch "live" defined
6+
# later on) as being the first input in the input_list. We need to do that here,
7+
# so we can define update_source_metrics callback in 20-prometheus.liq
8+
preferred_live_source = ref(list.nth(input_list, 0).name)
79

10+
%include "20-prometheus.liq"
11+
%include "50-inputs.liq"
812
%include "80-outputs.liq"
913
%include "90-http.liq"

scripts/streamer/50-inputs.liq

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# Inputs
2+
3+
input_sources = []
4+
5+
%include "inputs/playlist.liq"
6+
7+
def is_playing(n) =
8+
fun () -> n == preferred_live_source()
9+
end
10+
11+
def mk_switch_source(s) =
12+
(is_playing(s.name), s.source)
13+
end
14+
15+
def mk_fallback_source(result, s) =
16+
if
17+
s.is_autofallback
18+
then
19+
[...result, (s.source : source(audio=pcm))]
20+
else
21+
result
22+
end
23+
end
24+
25+
# get the livesourcestate on disk if it exist
26+
if
27+
file.exists(livesource_state_path)
28+
then
29+
content = file.contents(livesource_state_path)
30+
31+
# check that the livesource exist in input list
32+
if
33+
list.exists(fun (s) -> s.name == content, input_sources)
34+
then
35+
preferred_live_source := content
36+
end
37+
end
38+
39+
real_live_source = ref("")
40+
41+
live =
42+
switch(
43+
id="switch_live",
44+
track_sensitive=false,
45+
list.map(mk_switch_source, input_sources)
46+
)
47+
48+
radio =
49+
fallback(
50+
id="fallback_prod",
51+
track_sensitive=false,
52+
[
53+
(live : source(audio=pcm)),
54+
...list.fold(mk_fallback_source, [], input_sources)
55+
]
56+
)
Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,13 @@
1-
# Build the playlist
2-
radio = playlist(input_playlist_file)
3-
radio = mksafe(id="playlist", radio)
4-
radio = crossfade(fade_out=3., fade_in=3., duration=5., radio)
1+
# Build inputs of kind playlist
2+
3+
def mk_playlist_source(s) =
4+
let {name, playlist_file} = s
5+
radio = playlist(playlist_file)
6+
radio = mksafe(id="#{name}", radio)
7+
radio = crossfade(fade_out=3., fade_in=3., duration=5., radio)
8+
radio
9+
end
10+
11+
input_list_playlists = list.filter(fun (i) -> i.kind == "playlist", input_list)
12+
13+
list.append(input_sources, list.map(mk_playlist_source, input_list_playlists))

0 commit comments

Comments
 (0)