Skip to content

Commit

Permalink
Add track marks when restarting external processes. (#2873)
Browse files Browse the repository at this point in the history
Fixes: #2872
  • Loading branch information
toots authored Feb 1, 2023
1 parent 4e3e281 commit 1a864e8
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 4 deletions.
10 changes: 7 additions & 3 deletions src/core/stream/generator.ml
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,7 @@ let fill gen =
in
let len = min (_frame_remaining frame) available in
let pos = _frame_position frame in
let new_pos = pos + len in
gen.content <-
Frame_base.Fields.mapi
(fun field content ->
Expand All @@ -266,10 +267,13 @@ let fill gen =
in
(* TODO: make this append after after switch to immutable content. *)
(match field with
(* Remove the first break in rem *)
(* Remove the track mark if it is was used to compute remaining and it's not
at frame boundaries. *)
| f when f = Frame_base.Fields.track_marks -> (
match Content.Track_marks.get_data rem with
| _ :: d -> Content.Track_marks.set_data rem d
| 0 :: d when new_pos <> Lazy.force Frame_settings.size
->
Content.Track_marks.set_data rem d
| _ -> ())
| f when f = Frame_base.Fields.metadata ->
(* For metadata, it is expected that we only add new metadata and do not replace
Expand All @@ -291,5 +295,5 @@ let fill gen =
pos len);
rem)
gen.content;
_add_track_mark ~pos:(pos + len) frame)
_add_track_mark ~pos:new_pos frame)
())
1 change: 1 addition & 0 deletions src/core/tools/external_input.ml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ class virtual base ~name ~restart ~restart_on_error ~on_data ?read_header
`Continue
in
let on_stop status =
Generator.add_track_mark self#buffer;
header_read <- false;
match status with
| `Status (Unix.WEXITED 0) -> restart
Expand Down
2 changes: 1 addition & 1 deletion tests/regression/GH2871.liq
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ def f() =
s = bpm(s)
clock.assign_new(sync="none",[s])
output.dummy(fallible=true, s)
thread.run(delay=0.1, {if s.bpm() != 0. then test.pass() else test.fail () end})
thread.run(delay=0.2, {if s.bpm() != 0. then test.pass() else test.fail () end})
end

test.check(f)
11 changes: 11 additions & 0 deletions tests/regression/GH2872.liq
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
def f() =
track_count = ref(0)
s = input.external.rawaudio("ffmpeg -re -f lavfi -i sine=frequency=1000 -t 1 -ac 2 -f s16le -", restart=true, buffer=1.)
s.on_track(fun (_) -> begin
track_count := !track_count + 1
if !track_count > 3 then test.pass() end
end)
output.dummy(fallible=true,s)
end

test.check(f)

0 comments on commit 1a864e8

Please sign in to comment.