Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix append #4153

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 16 additions & 3 deletions src/core/operators/dyn_op.ml
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,26 @@ class dyn ~init ~track_sensitive ~infallible ~resurection_time ~self_sync f =
val proposed = Atomic.make None
method propose s = Atomic.set proposed (Some s)

method private no_source =
if infallible then
Lang.raise_error ~pos:[]
~message:
(Printf.sprintf
"Infallible source.dynamic %s was not able to prepare a source \
in time! Make sure to eithe define infallible sources in the \
source's dynamic function or mark the source as fallible.."
self#id)
"failure";
None

method private prepare s =
Typing.(s#frame_type <: self#frame_type);
Clock.unify ~pos:self#pos s#clock self#clock;
s#wake_up;
(match Atomic.exchange source (Some s) with
| Some s -> s#sleep
| None -> ());
if s#is_ready then Some s else None
if s#is_ready then Some s else self#no_source

method private get_next reselect =
self#mutexify
Expand All @@ -66,13 +78,14 @@ class dyn ~init ~track_sensitive ~infallible ~resurection_time ~self_sync f =
| v -> v)
s ->
Some s
| _ -> None)
| _ -> self#no_source)
| Some s -> self#prepare s))
()

method private get_source ~reselect () =
match (Atomic.get source, reselect) with
| None, _ | _, `Force -> self#get_next reselect
| None, _ | _, `Force | Some _, `After_position _ ->
self#get_next reselect
| Some s, _ when self#can_reselect ~reselect s -> Some s
| Some _, _ when Unix.gettimeofday () -. last_select < resurection_time
->
Expand Down
3 changes: 2 additions & 1 deletion src/libs/source.liq
Original file line number Diff line number Diff line change
Expand Up @@ -194,13 +194,14 @@ def append(~id=null("append"), ~insert_missing=true, ~merge=false, s, f) =
p = pending()
pending := null()
last_meta := null()

if
null.defined(p)
then
p = null.get(p)
sequence(merge=merge, [p, s])
else
s
null()
end
end

Expand Down
30 changes: 30 additions & 0 deletions tests/regression/append-merge.liq
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
music = chop(every=1., metadata=[("source", "s1")], sine(amplitude=0.1, 440.))

def next(_) =
s = sine(amplitude=0.1, duration=.5, 880.)
metadata.map(insert_missing=true, fun (_) -> [("source", "s2")], s)
end

s = append(merge=true, music, next)

count_s1 = ref(0)
count_s2 = ref(0)

s.on_metadata(
fun (m) ->
begin
s = m["source"]
if
s == "s1"
then
ref.incr(count_s1)
elsif s == "s2" then ref.incr(count_s2)
end

if count_s1() > 2 and count_s2() > 2 then test.pass() end
end
)

s.on_track(fun (m) -> if m["source"] == "s2" then test.fail() end)

output.dummy(s)
26 changes: 26 additions & 0 deletions tests/regression/append.liq
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
music = chop(every=1., metadata=[("source", "s1")], sine(amplitude=0.1, 440.))

def next(_) =
s = sine(amplitude=0.1, duration=.5, 880.)
metadata.map(insert_missing=true, fun (_) -> [("source", "s2")], s)
end

s = append(music, next)

count_s1 = ref(0)
count_s2 = ref(0)

s.on_metadata(fun (m) -> begin
s = m["source"]
if s == "s1" then
ref.incr(count_s1)
elsif s == "s2" then
ref.incr(count_s2)
end

if count_s1() > 2 and count_s2() > 2 then
test.pass()
end
end)

output.dummy(s)
32 changes: 32 additions & 0 deletions tests/regression/dune.inc
Original file line number Diff line number Diff line change
Expand Up @@ -815,6 +815,38 @@
(:run_test ../run_test.exe))
(action (run %{run_test} LS503.liq liquidsoap %{test_liq} LS503.liq)))

(rule
(alias citest)
(package liquidsoap)
(deps
append-merge.liq
../media/all_media_files
../../src/bin/liquidsoap.exe
../streams/file1.png
../streams/file1.mp3
./theora-test.mp4
(package liquidsoap)
(source_tree ../../src/libs)
(:test_liq ../test.liq)
(:run_test ../run_test.exe))
(action (run %{run_test} append-merge.liq liquidsoap %{test_liq} append-merge.liq)))

(rule
(alias citest)
(package liquidsoap)
(deps
append.liq
../media/all_media_files
../../src/bin/liquidsoap.exe
../streams/file1.png
../streams/file1.mp3
./theora-test.mp4
(package liquidsoap)
(source_tree ../../src/libs)
(:test_liq ../test.liq)
(:run_test ../run_test.exe))
(action (run %{run_test} append.liq liquidsoap %{test_liq} append.liq)))

(rule
(alias citest)
(package liquidsoap)
Expand Down
Loading