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 blank.strip #4164

Merged
merged 1 commit into from
Oct 8, 2024
Merged
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
21 changes: 13 additions & 8 deletions src/core/operators/noblank.ml
Original file line number Diff line number Diff line change
Expand Up @@ -122,22 +122,24 @@ class strip ~start_blank ~max_blank ~min_noise ~threshold ~track_sensitive
inherit active_operator ~name:"blank.strip" [source]
inherit base ~track_sensitive ~start_blank ~max_blank ~min_noise ~threshold
method fallible = true
method private can_generate_frame = (not self#is_blank) && source#is_ready

method private can_generate_frame =
(* This needs to be computed at all times as it makes sure that the
source is ready to be ready from in [#output]. *)
let is_source_ready = source#is_ready in
(not self#is_blank) && is_source_ready

method remaining = if self#is_blank then 0 else source#remaining

method seek_source =
if self#is_blank then (self :> Source.source) else source#seek_source

method abort_track = source#abort_track
method self_sync = source#self_sync

method private generate_frame =
let buf = source#get_frame in
self#check_blank buf;
buf
method private generate_frame = source#get_frame

method private output =
if source#is_ready && self#is_blank then ignore self#get_frame
if source#is_ready then self#check_blank source#get_frame

method reset = ()
end
Expand Down Expand Up @@ -294,7 +296,10 @@ let _ =
in
Lang.add_operator ~base:Blank.blank "strip" ~return_t:frame_t ~meth:(meth ())
~category:`Track
~descr:"Make the source unavailable when it is streaming blank."
~descr:
"Make the source unavailable when it is streaming blank. This is an \
active operator, meaning that the source used in this operator will be \
consumed continuously, even when it is not actively used."
(proto frame_t) (fun p ->
let start_blank, max_blank, min_noise, threshold, track_sensitive, s =
extract p
Expand Down
42 changes: 42 additions & 0 deletions tests/regression/GH4163.liq
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
first_blank =
metadata.map(
id="first_blank", fun (_) -> [("title", "first_blank")], blank(duration=3.)
)

after_blank =
metadata.map(
id="after_blank", fun (_) -> [("title", "after_blank")], sine(duration=10.)
)

blank_sequence = sequence(id="blank_sequence", [first_blank, after_blank])

blank_strip =
blank.strip(id="blank_strip", max_blank=5., start_blank=true, blank_sequence)

fallback_sine =
metadata.map(id="fallback_sine", fun (_) -> [("title", "fallback")], sine())

s =
fallback(
id="main_source", track_sensitive=false, [blank_strip, fallback_sine]
)

# We want to make sure that blank.strip keeps eating the blank source before switching back:
expected_titles = ["fallback", "after_blank"]
seen_titles = ref([])

def on_metadata(m) =
seen_titles := [...seen_titles(), m["title"]]
if
seen_titles() == expected_titles
then
test.pass()
elsif list.length(seen_titles()) == 2 then test.fail()
end
end

s = source.on_metadata(id="on_meta", s, on_metadata)

clock.assign_new(sync='none', [s])

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

(rule
(alias citest)
(package liquidsoap)
(deps
GH4163.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} GH4163.liq liquidsoap %{test_liq} GH4163.liq)))

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