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

Don't clear the buffer. #3719

Merged
merged 1 commit into from
Feb 7, 2024
Merged
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
25 changes: 13 additions & 12 deletions src/core/operators/muxer.ml
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ class muxer tracks =
track_frames := (source, f) :: !track_frames;
f

method private feed_track ~tmp ~filled ~start ~stop
method private feed_track ~tmp ~generator_length ~start ~stop
{ source_field; target_field; processor } =
let c = Content.sub (Frame.get tmp source_field) start (stop - start) in
match source_field with
Expand All @@ -111,31 +111,34 @@ class muxer tracks =
(Content.Metadata.get_data c)
| f when f = Frame.Fields.track_marks ->
if Frame.is_partial tmp then
Generator.add_track_mark ~pos:(stop - filled) self#buffer
Generator.add_track_mark
~pos:(generator_length + stop - start)
self#buffer
| _ -> Generator.put self#buffer target_field (processor c)

method private feed_fields ~filled { fields; source } =
method private feed_fields ~generator_length { fields; source } =
let tmp = self#track_frame source in
let start = Frame.position tmp in
if Frame.is_partial tmp && source#is_ready ~frame:tmp () then (
source#get tmp;
let stop = Frame.position tmp in
List.iter (self#feed_track ~tmp ~filled ~start ~stop) fields)
List.iter (self#feed_track ~tmp ~generator_length ~start ~stop) fields)

(* In the current streaming model, we might still need to force
a source#get to get the next break/metadata at the beginning of
a track.

TODO: get rid of this! *)
method private feed ~force buf =
let filled = Frame.position buf in
let position = Frame.position buf in
let generator_length = Generator.length self#buffer in
if
self#sources_ready
&& (force
|| Generator.remaining self#buffer = -1
&& filled + Generator.length self#buffer < Lazy.force Frame.size)
&& position + generator_length < Lazy.force Frame.size)
then (
List.iter (self#feed_fields ~filled) tracks;
List.iter (self#feed_fields ~generator_length) tracks;
self#feed ~force:false buf)

(* There are two situations here:
Expand All @@ -157,13 +160,11 @@ class muxer tracks =
while streaming, we end all tracks when this source drops
off. *)
method get_frame buf =
self#feed ~force:true buf;
let rem = Lazy.force Frame.size - Frame.position buf in
if Generator.length self#buffer < rem then self#feed ~force:true buf;
Generator.fill self#buffer buf

initializer
self#on_after_output (fun () ->
clear_track_frames ();
Generator.clear self#buffer)
initializer self#on_after_output (fun () -> clear_track_frames ())
end

let muxer_operator p =
Expand Down