Skip to content

Commit

Permalink
Fix delay initial conditions. (#4289)
Browse files Browse the repository at this point in the history
  • Loading branch information
toots authored Dec 28, 2024
1 parent 3e6205e commit 1dce369
Show file tree
Hide file tree
Showing 5 changed files with 99 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

---

Expand Down
6 changes: 4 additions & 2 deletions src/core/operators/delay.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
31 changes: 31 additions & 0 deletions tests/regression/GH4281-2.liq
Original file line number Diff line number Diff line change
@@ -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)
31 changes: 31 additions & 0 deletions tests/regression/GH4281.liq
Original file line number Diff line number Diff line change
@@ -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)
32 changes: 32 additions & 0 deletions tests/regression/dune.inc
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 1dce369

Please sign in to comment.