Skip to content

Commit 41ed163

Browse files
committed
Fix delay initial conditions. (#4289)
1 parent 2c1ffa5 commit 41ed163

File tree

5 files changed

+99
-2
lines changed

5 files changed

+99
-2
lines changed

CHANGES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ Fixed:
2929
- Fixed source `last_metadata` not being properly updated (#4262)
3030
- Convert all ICY (icecast) metadata from `input.http` to `utf8`.
3131
- Fixed `inotify` unwatching due to GC cleanup (#4275)
32+
- Fixed `delay` initial conditions (#4281)
3233

3334
---
3435

src/core/operators/delay.ml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,13 @@ class delay ~initial (source : source) delay =
3838

3939
method seek_source = source#seek_source
4040
method self_sync = source#self_sync
41-
method private delay_ok = Unix.time () -. last_track >= delay ()
41+
method private delay_ok = delay () <= Unix.time () -. last_track
4242
method private can_generate_frame = self#delay_ok && source#is_ready
4343

4444
method private generate_frame =
45-
match self#split_frame source#get_frame with
45+
let frame = source#get_frame in
46+
match self#split_frame frame with
47+
| buf, Some _ when last_track = 0. && Frame.position buf = 0 -> frame
4648
| buf, Some _ ->
4749
last_track <- Unix.time ();
4850
buf

tests/regression/GH4281-2.liq

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
d = sine()
2+
d = metadata.map(update=false, (fun (_) -> [("title", "delay")]), d)
3+
4+
f = sine()
5+
f = metadata.map(update=false, (fun (_) -> [("title", "fallback")]), f)
6+
7+
s = fallback([delay(initial=true, 60.0, d), f])
8+
9+
is_done = ref(false)
10+
11+
s.on_metadata(
12+
fun (m) ->
13+
begin
14+
if
15+
not is_done()
16+
then
17+
if
18+
m["title"] == "fallback"
19+
then
20+
begin
21+
is_done := true
22+
test.pass()
23+
end
24+
else
25+
test.fail()
26+
end
27+
end
28+
end
29+
)
30+
31+
output.dummy(s)

tests/regression/GH4281.liq

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
d = sine()
2+
d = metadata.map(update=false, (fun (_) -> [("title", "delay")]), d)
3+
4+
f = sine()
5+
f = metadata.map(update=false, (fun (_) -> [("title", "fallback")]), f)
6+
7+
s = fallback([delay(60.0, d), f])
8+
9+
is_done = ref(false)
10+
11+
s.on_metadata(
12+
fun (m) ->
13+
begin
14+
if
15+
not is_done()
16+
then
17+
if
18+
m["title"] == "delay"
19+
then
20+
begin
21+
is_done := true
22+
test.pass()
23+
end
24+
else
25+
test.fail()
26+
end
27+
end
28+
end
29+
)
30+
31+
output.dummy(s)

tests/regression/dune.inc

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -783,6 +783,38 @@
783783
(:run_test ../run_test.exe))
784784
(action (run %{run_test} GH4246.liq liquidsoap %{test_liq} GH4246.liq)))
785785

786+
(rule
787+
(alias citest)
788+
(package liquidsoap)
789+
(deps
790+
GH4281-2.liq
791+
../media/all_media_files
792+
../../src/bin/liquidsoap.exe
793+
../streams/file1.png
794+
../streams/file1.mp3
795+
./theora-test.mp4
796+
(package liquidsoap)
797+
(source_tree ../../src/libs)
798+
(:test_liq ../test.liq)
799+
(:run_test ../run_test.exe))
800+
(action (run %{run_test} GH4281-2.liq liquidsoap %{test_liq} GH4281-2.liq)))
801+
802+
(rule
803+
(alias citest)
804+
(package liquidsoap)
805+
(deps
806+
GH4281.liq
807+
../media/all_media_files
808+
../../src/bin/liquidsoap.exe
809+
../streams/file1.png
810+
../streams/file1.mp3
811+
./theora-test.mp4
812+
(package liquidsoap)
813+
(source_tree ../../src/libs)
814+
(:test_liq ../test.liq)
815+
(:run_test ../run_test.exe))
816+
(action (run %{run_test} GH4281.liq liquidsoap %{test_liq} GH4281.liq)))
817+
786818
(rule
787819
(alias citest)
788820
(package liquidsoap)

0 commit comments

Comments
 (0)