Skip to content

Commit

Permalink
first commit port from liquidsoap 1.4 to 2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
mp3butcher committed Nov 27, 2023
1 parent 618996c commit 23f8200
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 61 deletions.
51 changes: 26 additions & 25 deletions playout/libretime_playout/liquidsoap/2.0/ls_lib.liq
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
def gateway(args)
command = "timeout --signal=KILL 45 libretime-playout-notify #{args} &"
log(command)
system(command)
process.run(command)
end

def notify(m)
Expand All @@ -12,6 +12,7 @@ def notify_queue(m)
f = !dynamic_metadata_callback
ignore(f(m))
notify(m)
m
end

def notify_stream(m)
Expand Down Expand Up @@ -55,9 +56,9 @@ def transition(a,b) =
[
sequence([
blank(duration=0.01),
fade.initial(duration=input_fade_transition(), b)
fade.in(duration=input_fade_transition(), b)
]),
fade.final(duration=input_fade_transition(), a)
fade.out(duration=input_fade_transition(), a)
]
)
end
Expand All @@ -74,9 +75,9 @@ def transition_default(a,b) =
[
sequence([
blank(duration=0.01),
fade.initial(duration=input_fade_transition(), b)
fade.in(duration=input_fade_transition(), b)
]),
fade.final(duration=input_fade_transition(), a)
fade.out(duration=input_fade_transition(), a)
]
)
else
Expand All @@ -89,7 +90,7 @@ end
# new source
def to_live(old,new) =
# Fade out old source
old = fade.final(old)
old = fade.out(old)
# Compose this in sequence with the new source
sequence([old,new])
end
Expand Down Expand Up @@ -130,10 +131,10 @@ end
# Flushing the buffer on restart could be a good idea, but
# it would also create an interruptions while the buffer is
# refilling... on the other hand, this would avoid having to
# fade using both cross() and switch().
# fade using both cross() and switch().buffer=5.,max=15.,,autostart=false
def input.http_restart(~id,~initial_url="http://dummy/url")

source = audio_to_stereo(input.http(buffer=5.,max=15.,id=id,autostart=false,initial_url))
source = audio_to_stereo( mksafe(input.http(id=id,initial_url)))

def stopped()
"stopped" == list.hd(server.execute("#{id}.status"), default="")
Expand Down Expand Up @@ -161,56 +162,56 @@ end

# Transitions between URL changes in HTTP streams.
def cross_http(~debug=true,~http_input_id,source)

id = http_input_id
last_url = ref ""
change = ref false
last_url = ref ("")
change = ref (false)

def on_m(m)
def on_m(m) =
notify_stream(m)
changed = m["source_url"] != !last_url
log("URL now #{m['source_url']} (change: #{changed})")
if changed then
if !last_url != "" then change := true end
last_url := m["source_url"]
end
m
end

# We use both metadata and status to know about the current URL.
# Using only metadata may be more precise is crazy corner cases,
# but it's also asking too much: the metadata may not pass through
# before the crosser is instantiated.
# Using only status in crosser misses some info, eg. on first URL.
source = on_metadata(on_m,source)
source = map_metadata(on_m,source)

cross_d = 3.

def crosser(a,b,ma,mb,sa,sb)
def crosser(ending, starting)
url = list.hd(server.execute("#{id}.url"), default="")
status = list.hd(server.execute("#{id}.status"))
on_m([("source_url",url)])
if debug then
log("New track inside HTTP stream")
log(" status: #{status}")
log(" need to cross: #{!change}")
log(" remaining #{source.remaining(sa)} sec before, \
#{source.remaining(sb)} sec after")
#log(" remaining #{source.remaining(ending.source)} sec before, \
# #{source.remaining(starting.source)} sec after")
end
if !change then
change := false
# In principle one should avoid crossing on a live stream
# it'd be okay to do it here (eg. use add instead of sequence)
# because it's only once per URL, but be cautious.
sequence([fade.out(duration=cross_d,sa),fade.in(sb)])
sequence([fade.out(duration=cross_d,ending.source),fade.in(starting.source)])
else
# This is done on tracks inside a single stream.
# Do NOT cross here or you'll gradually empty the buffer!
sequence([sa,sb])
sequence([ending.source,starting.source])
end
end

# Setting conservative=true would mess with the delayed switch below
# Setting conservative=true would mess with the delayed switch below
cross(duration=cross_d,conservative=false,crosser,source)

end

# Custom fallback between http and default source with fading of
Expand All @@ -228,12 +229,12 @@ def http_fallback(~http_input_id,~http,~default)
# we use gracetime below.

def gracetime(~delay=3.,f)
last_true = ref 0.
last_true = ref(0.)
{ if f() then
last_true := gettimeofday()
last_true := time()
true
else
gettimeofday() < !last_true+delay
time() < !last_true+delay
end }
end

Expand All @@ -246,11 +247,11 @@ def http_fallback(~http_input_id,~http,~default)
def to_live(a,b) =
log("TRANSITION to live")
add(normalize=false,
[fade.initial(b),fade.final(a)])
[fade.in(b),fade.out(a)])
end
def to_static(a,b) =
log("TRANSITION to static")
sequence([fade.out(a),fade.initial(b)])
sequence([fade.out(a),fade.in(b)])
end

switch(
Expand Down
60 changes: 24 additions & 36 deletions playout/libretime_playout/liquidsoap/2.0/ls_script.liq
Original file line number Diff line number Diff line change
@@ -1,23 +1,22 @@
boot_timestamp = string_of(gettimeofday())
boot_timestamp = string_of(time())

web_stream_enabled = ref false
web_stream_id = ref '-1'
web_stream_enabled = ref(false)
web_stream_id = ref( '-1')

show_name = interactive.string("show_name", "")

dynamic_metadata_callback = ref fun (~new_track=false, s) -> begin () end
dynamic_metadata_callback = ref (fun (~new_track=false, s) -> begin () end)

just_switched = ref false
just_switched = ref (false)

%include "ls_lib.liq"

sources = ref []
source_id = ref 0
sources = ref([])
source_id = ref (0)

def create_source()
this_source_id = !source_id

l = request.equeue(id="s#{this_source_id}", length=0.5)
l = request.queue(id="s#{this_source_id}")#, length=0.5

l = audio_to_stereo(id="queue_src", l)
l = cue_cut(l)
Expand All @@ -29,8 +28,8 @@ def create_source()
l = fade.in(l)
l = fade.out(l)

l = on_metadata(notify_queue, l)

l = map_metadata(notify_queue,l)
l =cross_http(http_input_id="http",l)
sources := list.append([l], !sources)
server.register(namespace="queues",
"s#{this_source_id}_skip",
Expand All @@ -46,15 +45,13 @@ create_source()
create_source()
create_source()

queue = add(!sources, normalize=false)
pair = insert_metadata(queue)
dynamic_metadata_callback := fst(pair)
queue = snd(pair)
queue = add(!sources)#, normalize=false)
queue = insert_metadata(queue)
dynamic_metadata_callback := queue.insert_metadata

output.dummy(fallible=true, queue)

http = input.http_restart(id="http")
http = cross_http(http_input_id="http",http)
output.dummy(fallible=true, http)
stream_queue = http_fallback(http_input_id="http", http=http, default=queue)
stream_queue = map_metadata(id="map_metadata:schedule", update=false, append_title, stream_queue)
Expand Down Expand Up @@ -100,9 +97,9 @@ end
default = map_metadata(id="map_metadata:offline", map_message_offline, default)
ignore(output.dummy(default, fallible=true))

input_main_streaming = ref false
input_show_streaming = ref false
schedule_streaming = ref false
input_main_streaming = ref (false)
input_show_streaming = ref (false)
schedule_streaming = ref (false)

def start_input_main() input_main_streaming := true end
def stop_input_main() input_main_streaming := false end
Expand All @@ -120,29 +117,22 @@ def input_main_on_disconnect() update_source_status("master_dj", false) end
def input_show_on_connect(header) update_source_status("live_dj", true) end
def input_show_on_disconnect() update_source_status("live_dj", false) end

def make_input_func(secure)
if secure then
input.harbor.ssl
else
input.harbor
end
end

def make_input_auth_handler(input_name)
def auth_handler(user, password)
log("user '#{user}' connected", label="#{input_name}_input")
def auth_handler(args)
log("user '#{args.user}' connected", label="#{input_name}_input")

# Check auth based on return value from auth script
ret = test_process("libretime-playout-notify live-auth '#{input_name}' '#{user}' '#{password}'")
ret = test_process("libretime-playout-notify live-auth '#{input_name}' '#{args.user}' '#{args.password}'")
if ret then
log("user '#{user}' authenticated", label="#{input_name}_input")
log("user '#{args.user}' authenticated", label="#{input_name}_input")
else
log("user '#{user}' auth failed", label="#{input_name}_input",level=2)
log("user '#{args.user}' auth failed", label="#{input_name}_input",level=2)
end

ret
end
auth_handler

end

s = switch(id="switch:blank+schedule",
Expand All @@ -152,10 +142,9 @@ s = switch(id="switch:blank+schedule",
)

s = if input_show_port != 0 and input_show_mount != "" then
input_show_func = make_input_func(input_show_secure)
input_show_source =
audio_to_stereo(
input_show_func(id="harbor:input_show",
input.harbor(id="harbor:input_show",
input_show_mount,
port=input_show_port,
auth=make_input_auth_handler("show"),
Expand All @@ -175,10 +164,9 @@ else
end

s = if input_main_port != 0 and input_main_mount != "" then
input_main_func = make_input_func(input_main_secure)
input_main_source =
audio_to_stereo(
input_main_func(id="harbor:input_main",
input.harbor(id="harbor:input_main",
input_main_mount,
port=input_main_port,
auth=make_input_auth_handler("main"),
Expand Down

0 comments on commit 23f8200

Please sign in to comment.