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

Native sleeper operator. #2899

Merged
merged 4 commits into from
Feb 14, 2023
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
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ Changed:
- Added `settings.protocol.youtube_dl.timeout` to specify timeout when using
`youtube-dl` protocol (#2827). Use `yt-dlp` as default binary for the
protocol.
- The `sleeper` operator is now scripted (#2899).

Fixed:

Expand Down
1 change: 0 additions & 1 deletion src/core/dune
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,6 @@
sha1
shebang
shine_format
sleeper
source
speex_format
srt_decoder
Expand Down
87 changes: 0 additions & 87 deletions src/core/operators/sleeper.ml

This file was deleted.

1 change: 1 addition & 0 deletions src/libs/stdlib.liq
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
%include "profiler.liq"
%include "io.liq"
%include "runtime.liq"
%include "testing.liq"
%include "liquidsoap.liq"

set_settings_ref(settings)
24 changes: 24 additions & 0 deletions src/libs/testing.liq
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Sleep regularly, thus inducing delays in the sound production. This is mainly
# useful for emulating network delays or sources which are slow to produce data,
# and thus test bufferization and robustness of scripts.
# @category Source / Testing
# @flag experimental
# @param ~every How often we should sleep (in seconds, 0 means every frame).
# @param ~delay Delay introduced (in seconds).
# @param ~delay_random Maximum amount of time randomly added to the delay (in seconds).
# @param s Source in which the delays should be introduced.
# @method frozen The stream production is frozen while set to `true`.
def sleeper(~every=0.5, ~delay=0.1, ~delay_random=0., s)
last = ref(0.)
frozen = ref(false)
def f()
now = source.time(s)
while frozen() do sleep(0.1) end
if now + every >= last() then
last := now
sleep(delay + random.float(max=delay_random))
end
end
s = source.on_frame(s,f)
s.{frozen = frozen}
end