diff --git a/CHANGES.md b/CHANGES.md index 34e642fbdb..e6bdda0518 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -29,6 +29,7 @@ Fixed: - Fixed source `last_metadata` not being properly updated (#4262) - Convert all ICY (icecast) metadata from `input.http` to `utf8`. - Fixed `inotify` unwatching due to GC cleanup (#4275) +- Fixed `delay` initial conditions (#4281) --- diff --git a/src/core/operators/delay.ml b/src/core/operators/delay.ml index a80b909c54..00c44ee43a 100644 --- a/src/core/operators/delay.ml +++ b/src/core/operators/delay.ml @@ -38,11 +38,13 @@ class delay ~initial (source : source) delay = method seek_source = source#seek_source method self_sync = source#self_sync - method private delay_ok = Unix.time () -. last_track >= delay () + method private delay_ok = delay () <= Unix.time () -. last_track method private can_generate_frame = self#delay_ok && source#is_ready method private generate_frame = - match self#split_frame source#get_frame with + let frame = source#get_frame in + match self#split_frame frame with + | buf, Some _ when last_track = 0. && Frame.position buf = 0 -> frame | buf, Some _ -> last_track <- Unix.time (); buf diff --git a/tests/regression/GH4281-2.liq b/tests/regression/GH4281-2.liq new file mode 100644 index 0000000000..ff9f663ea0 --- /dev/null +++ b/tests/regression/GH4281-2.liq @@ -0,0 +1,31 @@ +d = sine() +d = metadata.map(update=false, (fun (_) -> [("title", "delay")]), d) + +f = sine() +f = metadata.map(update=false, (fun (_) -> [("title", "fallback")]), f) + +s = fallback([delay(initial=true, 60.0, d), f]) + +is_done = ref(false) + +s.on_metadata( + fun (m) -> + begin + if + not is_done() + then + if + m["title"] == "fallback" + then + begin + is_done := true + test.pass() + end + else + test.fail() + end + end + end +) + +output.dummy(s) diff --git a/tests/regression/GH4281.liq b/tests/regression/GH4281.liq new file mode 100644 index 0000000000..e70cf51838 --- /dev/null +++ b/tests/regression/GH4281.liq @@ -0,0 +1,31 @@ +d = sine() +d = metadata.map(update=false, (fun (_) -> [("title", "delay")]), d) + +f = sine() +f = metadata.map(update=false, (fun (_) -> [("title", "fallback")]), f) + +s = fallback([delay(60.0, d), f]) + +is_done = ref(false) + +s.on_metadata( + fun (m) -> + begin + if + not is_done() + then + if + m["title"] == "delay" + then + begin + is_done := true + test.pass() + end + else + test.fail() + end + end + end +) + +output.dummy(s) diff --git a/tests/regression/dune.inc b/tests/regression/dune.inc index 8e5e3d264a..dc606c4403 100644 --- a/tests/regression/dune.inc +++ b/tests/regression/dune.inc @@ -783,6 +783,38 @@ (:run_test ../run_test.exe)) (action (run %{run_test} GH4246.liq liquidsoap %{test_liq} GH4246.liq))) +(rule + (alias citest) + (package liquidsoap) + (deps + GH4281-2.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} GH4281-2.liq liquidsoap %{test_liq} GH4281-2.liq))) + +(rule + (alias citest) + (package liquidsoap) + (deps + GH4281.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} GH4281.liq liquidsoap %{test_liq} GH4281.liq))) + (rule (alias citest) (package liquidsoap)