From 309a501dc3fe81792274660072f46d2c053652a4 Mon Sep 17 00:00:00 2001 From: Romain Beauxis Date: Fri, 3 Jan 2025 08:45:05 -0600 Subject: [PATCH] Fix delay initial conditions again. --- src/core/operators/delay.ml | 5 ++++- tests/regression/GH4281-2.liq | 24 ++++++++---------------- tests/regression/GH4281.liq | 24 ++++++++---------------- 3 files changed, 20 insertions(+), 33 deletions(-) diff --git a/src/core/operators/delay.ml b/src/core/operators/delay.ml index 00c44ee43a..bfa240e5c8 100644 --- a/src/core/operators/delay.ml +++ b/src/core/operators/delay.ml @@ -29,6 +29,7 @@ class delay ~initial (source : source) delay = object (self) inherit operator ~name:"delay" [source] val mutable last_track = if initial then Unix.time () else 0. + val mutable first_track = true method fallible = true method remaining = source#remaining @@ -44,7 +45,9 @@ class delay ~initial (source : source) delay = method private generate_frame = 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 _ when first_track && Frame.position buf = 0 -> + first_track <- false; + frame | buf, Some _ -> last_track <- Unix.time (); buf diff --git a/tests/regression/GH4281-2.liq b/tests/regression/GH4281-2.liq index ff9f663ea0..5a0176c02f 100644 --- a/tests/regression/GH4281-2.liq +++ b/tests/regression/GH4281-2.liq @@ -1,31 +1,23 @@ -d = sine() +d = sequence([sine(duration=3.), sine(duration=3.)]) d = metadata.map(update=false, (fun (_) -> [("title", "delay")]), d) -f = sine() +f = sequence([sine(duration=3.), sine(duration=3.)]) f = metadata.map(update=false, (fun (_) -> [("title", "fallback")]), f) -s = fallback([delay(initial=true, 60.0, d), f]) +s = fallback([delay(initial=true, 1., d), f]) -is_done = ref(false) +meta = ref([]) s.on_metadata( fun (m) -> begin + meta := [...meta(), m["title"]] if - not is_done() + meta() == ["fallback", "delay", "fallback", "delay"] then - if - m["title"] == "fallback" - then - begin - is_done := true - test.pass() - end - else - test.fail() - end + test.pass() end end ) -output.dummy(s) +output.dummy(fallible=true, s) diff --git a/tests/regression/GH4281.liq b/tests/regression/GH4281.liq index e70cf51838..3b0dade11b 100644 --- a/tests/regression/GH4281.liq +++ b/tests/regression/GH4281.liq @@ -1,31 +1,23 @@ -d = sine() +d = sequence([sine(duration=3.), sine(duration=3.)]) d = metadata.map(update=false, (fun (_) -> [("title", "delay")]), d) -f = sine() +f = sequence([sine(duration=3.), sine(duration=3.)]) f = metadata.map(update=false, (fun (_) -> [("title", "fallback")]), f) -s = fallback([delay(60.0, d), f]) +s = fallback([delay(1., d), f]) -is_done = ref(false) +meta = ref([]) s.on_metadata( fun (m) -> begin + meta := [...meta(), m["title"]] if - not is_done() + meta() == ["delay", "fallback", "delay", "fallback"] then - if - m["title"] == "delay" - then - begin - is_done := true - test.pass() - end - else - test.fail() - end + test.pass() end end ) -output.dummy(s) +output.dummy(fallible=true, s)