diff --git a/src/core/builtins/builtins_ffmpeg_filters.ml b/src/core/builtins/builtins_ffmpeg_filters.ml index 6c5b489365..2ecb6f2863 100644 --- a/src/core/builtins/builtins_ffmpeg_filters.ml +++ b/src/core/builtins/builtins_ffmpeg_filters.ml @@ -92,7 +92,9 @@ let initialized graph = let is_ready graph = (not graph.failed) - && Queue.fold (fun cur s -> cur && s#is_ready) true graph.graph_inputs + && Queue.fold + (fun cur (s : Source.source) -> cur && s#is_ready ()) + true graph.graph_inputs let pull graph = (Clock.get (Queue.peek graph.graph_inputs)#clock)#end_tick diff --git a/src/core/builtins/builtins_source.ml b/src/core/builtins/builtins_source.ml index c16d65ec2c..c1d962ea0a 100644 --- a/src/core/builtins/builtins_source.ml +++ b/src/core/builtins/builtins_source.ml @@ -84,7 +84,7 @@ let _ = available), or currently streaming." [("", Lang.source_t (Lang.univ_t ()), None, None)] Lang.bool_t - (fun p -> Lang.bool (Lang.to_source (List.assoc "" p))#is_ready) + (fun p -> Lang.bool ((Lang.to_source (List.assoc "" p))#is_ready ())) let _ = Lang.add_builtin ~base:source "is_up" ~category:`System @@ -211,7 +211,7 @@ let _ = Clock.unify ~pos:fo#pos fo#clock (Clock.create_known clock); ignore (clock#start_outputs (fun _ -> true) ()); log#info "Start dumping source (ratio: %.02fx)" ratio; - while (not (Atomic.get should_stop)) && fo#is_ready do + while (not (Atomic.get should_stop)) && fo#is_ready () do let start_time = Time.time () in clock#end_tick; sleep_until (start_time |+| latency) @@ -252,7 +252,7 @@ let _ = Clock.unify ~pos:o#pos o#clock (Clock.create_known clock); ignore (clock#start_outputs (fun _ -> true) ()); log#info "Start dropping source (ratio: %.02fx)" ratio; - while (not (Atomic.get should_stop)) && o#is_ready do + while (not (Atomic.get should_stop)) && o#is_ready () do let start_time = Time.time () in clock#end_tick; sleep_until (start_time |+| latency) diff --git a/src/core/clock.ml b/src/core/clock.ml index f2bb578c37..bdb45219cc 100644 --- a/src/core/clock.ml +++ b/src/core/clock.ml @@ -208,8 +208,8 @@ module MkClock (Time : Liq_time.T) = struct match sync with | `Auto -> List.exists - (fun (state, s) -> - state = `Active && snd s#self_sync && s#is_ready) + (fun (state, (s : Source.active_source)) -> + state = `Active && snd s#self_sync && s#is_ready ()) outputs | `CPU -> false | `None -> true diff --git a/src/core/conversions/conversion.ml b/src/core/conversions/conversion.ml index 4d9db863d7..29807b2bae 100644 --- a/src/core/conversions/conversion.ml +++ b/src/core/conversions/conversion.ml @@ -26,7 +26,7 @@ class base ?(audio = false) ?(video = false) ?(midi = false) ~converter (source : Source.source) = object (self) method stype = source#stype - method is_ready = source#is_ready + method private _is_ready = source#is_ready method abort_track = source#abort_track method remaining = source#remaining method seek = source#seek diff --git a/src/core/conversions/swap.ml b/src/core/conversions/swap.ml index 4e3f52c491..5d02f9c1cb 100644 --- a/src/core/conversions/swap.ml +++ b/src/core/conversions/swap.ml @@ -26,7 +26,7 @@ class swap ~field (source : source) = object inherit operator [source] ~name:"swap" method stype = source#stype - method is_ready = source#is_ready + method private _is_ready = source#is_ready method remaining = source#remaining method abort_track = source#abort_track method seek = source#seek diff --git a/src/core/io/ffmpeg_filter_io.ml b/src/core/io/ffmpeg_filter_io.ml index c9011c936b..27275ec419 100644 --- a/src/core/io/ffmpeg_filter_io.ml +++ b/src/core/io/ffmpeg_filter_io.ml @@ -103,7 +103,7 @@ class virtual ['a] base_output ~pass_metadata ~name ~frame_t ~field source = method stop = () method! reset = () val mutable is_up = false - method! is_ready = is_up && super#is_ready + method! is_ready ?frame () = is_up && super#is_ready ?frame () method! wake_up l = is_up <- true; @@ -247,7 +247,7 @@ class virtual ['a] input_base ~name ~pass_metadata ~self_sync_type ~self_sync f () with Not_ready -> () - method is_ready = + method private _is_ready ?frame:_ _ = Generator.length self#buffer >= Lazy.force Frame.size || is_ready () method private get_frame frame = diff --git a/src/core/io/ffmpeg_io.ml b/src/core/io/ffmpeg_io.ml index 3df0a4a799..726400c029 100644 --- a/src/core/io/ffmpeg_io.ml +++ b/src/core/io/ffmpeg_io.ml @@ -75,7 +75,7 @@ class input ?(name = "input.ffmpeg") ~autostart ~self_sync ~poll_delay ~debug method remaining = -1 method abort_track = Generator.add_track_mark self#buffer method private is_connected = Atomic.get container <> None - method! is_ready = super#is_ready && self#is_connected + method! is_ready ?frame () = super#is_ready ?frame () && self#is_connected method private get_self_sync = match self_sync () with Some v -> v | None -> false diff --git a/src/core/io/gstreamer_io.ml b/src/core/io/gstreamer_io.ml index f06b33642c..4b3c32f66b 100644 --- a/src/core/io/gstreamer_io.ml +++ b/src/core/io/gstreamer_io.ml @@ -487,7 +487,7 @@ class audio_video_input p (pipeline, audio_pipeline, video_pipeline) = (* Source is ready when ready = true and gst has some audio or some video. *) val mutable ready = true - method is_ready = + method private _is_ready = let pending = function | Some sink -> sink.pending () > 0 | None -> false diff --git a/src/core/io/srt_io.ml b/src/core/io/srt_io.ml index 33b9f4f7d0..0c9c170205 100644 --- a/src/core/io/srt_io.ml +++ b/src/core/io/srt_io.ml @@ -681,8 +681,8 @@ class virtual input_base ~max ~clock_safe ~on_connect ~on_disconnect method remaining = -1 method abort_track = Generator.add_track_mark self#buffer - method! is_ready = - super#is_ready && (not self#should_stop) && self#is_connected + method! is_ready ?frame () = + super#is_ready ?frame () && (not self#should_stop) && self#is_connected method self_sync = (`Dynamic, self#is_connected) diff --git a/src/core/lang_source.ml b/src/core/lang_source.ml index 6f1d40426e..9c7aa40669 100644 --- a/src/core/lang_source.ml +++ b/src/core/lang_source.ml @@ -66,7 +66,7 @@ let source_methods = "Indicate if a source is ready to stream. This does not mean that the \ source is currently streaming, just that its resources are all properly \ initialized.", - fun s -> val_fun [] (fun _ -> bool s#is_ready) ); + fun (s : Source.source) -> val_fun [] (fun _ -> bool (s#is_ready ())) ); ( "buffered", ([], fun_t [] (list_t (product_t string_t float_t))), "Length of buffered data.", diff --git a/src/core/operators/accelerate.ml b/src/core/operators/accelerate.ml index 9a7ac709f5..754ff234d1 100644 --- a/src/core/operators/accelerate.ml +++ b/src/core/operators/accelerate.ml @@ -47,7 +47,7 @@ class accelerate ~ratio ~randomize source_val = source#get_ready [(self :> source)] method! private sleep = source#leave (self :> source) - method is_ready = source#is_ready + method private _is_ready = source#is_ready (** Filled ticks. *) val mutable filled = 0 @@ -75,13 +75,13 @@ class accelerate ~ratio ~randomize source_val = let pos = ref 1 in (* Drop frames if we are late. *) (* TODO: we could also duplicate if we are in advance. *) - while !pos > 0 && self#must_drop && source#is_ready do + while !pos > 0 && self#must_drop && source#is_ready ~frame () do Frame.clear null; self#child_on_output (fun () -> source#get null); pos := Frame.position null; skipped <- skipped + !pos done; - if source#is_ready then ( + if source#is_ready ~frame () then ( let before = Frame.position frame in if !pos > 0 then self#child_on_output (fun () -> source#get frame); let after = Frame.position frame in diff --git a/src/core/operators/add.ml b/src/core/operators/add.ml index 86e549682b..6a293fba06 100644 --- a/src/core/operators/add.ml +++ b/src/core/operators/add.ml @@ -51,10 +51,13 @@ class virtual base ~name tracks = List.fold_left f (-1) (List.map (fun s -> s#remaining) - (List.filter (fun s -> s#is_ready) sources)) + (List.filter (fun (s : Source.source) -> s#is_ready ()) sources)) method abort_track = List.iter (fun s -> s#abort_track) sources - method is_ready = List.exists (fun s -> s#is_ready) sources + + method private _is_ready ?frame () = + List.exists (fun s -> s#is_ready ?frame ()) sources + method seek n = match sources with [s] -> s#seek n | _ -> 0 method seek_source = @@ -89,7 +92,7 @@ class virtual base ~name tracks = match List.fold_left (fun cur { fields; source } -> - if not source#is_ready then cur + if not (source#is_ready ~frame:buf ()) then cur else List.fold_left (fun cur { position; _ } -> @@ -136,8 +139,8 @@ class audio_add ~renorm ~power ~field tracks = (0., []) fields in ( total_weight +. source_weight, - if source#is_ready then { source; fields } :: tracks else tracks - )) + if source#is_ready ~frame:buf () then { source; fields } :: tracks + else tracks )) (0., []) tracks in let total_weight = if power then sqrt total_weight else total_weight in @@ -171,7 +174,8 @@ class video_add ~field ~add tracks = let tracks = List.fold_left (fun tracks track -> - if track.source#is_ready then track :: tracks else tracks) + if track.source#is_ready ~frame:buf () then track :: tracks + else tracks) [] tracks in let offset = Frame.position buf in diff --git a/src/core/operators/amplify.ml b/src/core/operators/amplify.ml index 3d75e77464..32cbc30db1 100644 --- a/src/core/operators/amplify.ml +++ b/src/core/operators/amplify.ml @@ -28,7 +28,7 @@ class amplify ~field (source : source) override_field coeff = inherit operator ~name:"track.audio.amplify" [source] val mutable override = None method stype = source#stype - method is_ready = source#is_ready + method private _is_ready = source#is_ready method remaining = source#remaining method abort_track = source#abort_track method seek = source#seek diff --git a/src/core/operators/available.ml b/src/core/operators/available.ml index 18986766dd..263096f507 100644 --- a/src/core/operators/available.ml +++ b/src/core/operators/available.ml @@ -33,9 +33,9 @@ class available ~track_sensitive ~override p (source : source) = method self_sync = source#self_sync val mutable ready = p () - method is_ready = + method private _is_ready ?frame () = if not (track_sensitive () && ready) then ready <- p (); - ready && (override || source#is_ready) + ready && (override || source#is_ready ?frame ()) method private get_frame buf = source#get buf; diff --git a/src/core/operators/biquad_filter.ml b/src/core/operators/biquad_filter.ml index 67d38f2ca5..6b0da64e97 100644 --- a/src/core/operators/biquad_filter.ml +++ b/src/core/operators/biquad_filter.ml @@ -123,7 +123,7 @@ class biquad (source : source) filter_type freq q gain = method seek = source#seek method seek_source = source method self_sync = source#self_sync - method is_ready = source#is_ready + method private _is_ready = source#is_ready method abort_track = source#abort_track method! wake_up a = diff --git a/src/core/operators/chord.ml b/src/core/operators/chord.ml index c1ee728047..96484886e5 100644 --- a/src/core/operators/chord.ml +++ b/src/core/operators/chord.ml @@ -48,7 +48,7 @@ class chord metadata_name (source : source) = inherit operator ~name:"chord" [source] method stype = source#stype method remaining = source#remaining - method is_ready = source#is_ready + method private _is_ready = source#is_ready method abort_track = source#abort_track method seek = source#seek method seek_source = source diff --git a/src/core/operators/clip.ml b/src/core/operators/clip.ml index 94771261d2..7300c73bee 100644 --- a/src/core/operators/clip.ml +++ b/src/core/operators/clip.ml @@ -30,7 +30,7 @@ class clip ~field (source : source) = method remaining = source#remaining method seek = source#seek method seek_source = source - method is_ready = source#is_ready + method private _is_ready = source#is_ready method abort_track = source#abort_track method self_sync = source#self_sync diff --git a/src/core/operators/comb.ml b/src/core/operators/comb.ml index 9ae4e0a58f..fa17a50a38 100644 --- a/src/core/operators/comb.ml +++ b/src/core/operators/comb.ml @@ -34,7 +34,7 @@ class comb ~field (source : source) delay feedback = method seek = source#seek method seek_source = source method self_sync = source#self_sync - method is_ready = source#is_ready + method private _is_ready = source#is_ready method abort_track = source#abort_track val mutable past = Audio.make 0 0 0. diff --git a/src/core/operators/compand.ml b/src/core/operators/compand.ml index 18b14dd8bb..ac603ba18f 100644 --- a/src/core/operators/compand.ml +++ b/src/core/operators/compand.ml @@ -30,7 +30,7 @@ class compand ~field (source : source) mu = method seek = source#seek method seek_source = source method self_sync = source#self_sync - method is_ready = source#is_ready + method private _is_ready = source#is_ready method abort_track = source#abort_track method private get_frame buf = diff --git a/src/core/operators/compress.ml b/src/core/operators/compress.ml index 2f892e50d7..a0f5705a9b 100644 --- a/src/core/operators/compress.ml +++ b/src/core/operators/compress.ml @@ -40,7 +40,7 @@ class compress ~attack ~release ~threshold ~ratio ~knee ~track_sensitive method seek = source#seek method seek_source = source method self_sync = source#self_sync - method is_ready = source#is_ready + method private _is_ready = source#is_ready method abort_track = source#abort_track (* Current gain in dB. *) diff --git a/src/core/operators/compress_exp.ml b/src/core/operators/compress_exp.ml index 925181392c..77d6e66928 100644 --- a/src/core/operators/compress_exp.ml +++ b/src/core/operators/compress_exp.ml @@ -27,7 +27,7 @@ class compress ~field (source : source) mu = inherit operator ~name:"compress" [source] method stype = source#stype method remaining = source#remaining - method is_ready = source#is_ready + method private _is_ready = source#is_ready method abort_track = source#abort_track method seek = source#seek method seek_source = source diff --git a/src/core/operators/cross.ml b/src/core/operators/cross.ml index 83d08b8cc5..2313a75dd1 100644 --- a/src/core/operators/cross.ml +++ b/src/core/operators/cross.ml @@ -205,16 +205,17 @@ class cross val_source ~duration_getter ~override_duration ~persist_override | `Limit -> (* The track finished. * We compute rms_after and launch the transition. *) - if source#is_ready then self#analyze_after; + if source#is_ready ~frame () then self#analyze_after; self#create_transition; (* Check if the new source is ready *) - if (Option.get transition_source)#is_ready then self#get_frame frame + if (Option.get transition_source)#is_ready ~frame () then + self#get_frame frame else (* If not, finish this track, which requires our callers * to wait that we become ready again. *) Frame.add_break frame (Frame.position frame) - | `After when (Option.get transition_source)#is_ready -> + | `After when (Option.get transition_source)#is_ready ~frame () -> self#child_get (Option.get transition_source) frame; if Generator.length pending_after = 0 && Frame.is_partial frame then ( @@ -225,7 +226,7 @@ class cross val_source ~duration_getter ~override_duration ~persist_override * using it. Each call to [get_frame] must add exactly one break so * call it again and then remove the intermediate break that was just * added. *) - if source#is_ready then ( + if source#is_ready ~frame () then ( self#get_frame frame; Frame.set_breaks frame (match List.rev (Frame.breaks frame) with @@ -294,8 +295,10 @@ class cross val_source ~duration_getter ~override_duration ~persist_override rmsi_after <- rmsi_after + len); self#save_last_metadata `After buf_frame; self#update_cross_length buf_frame start; - if AFrame.is_partial buf_frame && not source#is_ready then - Generator.add_track_mark gen_after + if + AFrame.is_partial buf_frame + && not (source#is_ready ~frame:buf_frame ()) + then Generator.add_track_mark gen_after else ( if not (Frame.is_partial buf_frame) then Frame.clear buf_frame; if after_len < before_len then f ()) @@ -396,14 +399,16 @@ class cross val_source ~duration_getter ~override_duration ~persist_override | `After -> Option.get transition_source | _ -> (self :> Source.source) - method is_ready = + method private _is_ready ?frame () = match status with - | `Idle | `Before -> source#is_ready + | `Idle | `Before -> source#is_ready ?frame () | `Limit -> true - | `After -> (Option.get transition_source)#is_ready || source#is_ready + | `After -> + (Option.get transition_source)#is_ready ?frame () + || source#is_ready ?frame () method abort_track = - if status = `After && (Option.get transition_source)#is_ready then + if status = `After && (Option.get transition_source)#is_ready () then (Option.get transition_source)#abort_track else source#abort_track end diff --git a/src/core/operators/cuepoint.ml b/src/core/operators/cuepoint.ml index 01241d3ce0..3b17080ba9 100644 --- a/src/core/operators/cuepoint.ml +++ b/src/core/operators/cuepoint.ml @@ -43,7 +43,7 @@ class cue_cut ~m_cue_in ~m_cue_out ~on_cue_in ~on_cue_out source_val = inherit! Child_support.base ~check_self_sync:true [source_val] val mutable track_state : state = `Idle method stype = source#stype - method is_ready = source#is_ready + method private _is_ready = source#is_ready method abort_track = source#abort_track method self_sync = source#self_sync method seek = source#seek diff --git a/src/core/operators/defer.ml b/src/core/operators/defer.ml index 54d910ad0a..7a4b495a12 100644 --- a/src/core/operators/defer.ml +++ b/src/core/operators/defer.ml @@ -97,7 +97,7 @@ class defer ~delay ~overhead ~field source = let tmp_frame = self#tmp_frame in Frame.clear tmp_frame; - while Frame.is_partial tmp_frame && source#is_ready do + while Frame.is_partial tmp_frame && source#is_ready ~frame:tmp_frame () do source#get tmp_frame done; let gen_len = Frame.position tmp_frame in @@ -138,7 +138,7 @@ class defer ~delay ~overhead ~field source = method private queue_output = let clock = Source.Clock_variables.get self#clock in clock#on_output (fun () -> - if source#is_ready then self#buffer_data; + if source#is_ready () then self#buffer_data; if should_queue then clock#on_before_output (fun () -> self#queue_output)) @@ -148,7 +148,9 @@ class defer ~delay ~overhead ~field source = self#queue_output); self#on_sleep (fun () -> should_queue <- false) - method is_ready = (not deferred) && Generator.length self#generator > 0 + method private _is_ready ?frame:_ _ = + (not deferred) && Generator.length self#generator > 0 + method private get_frame buf = Generator.fill self#generator buf end diff --git a/src/core/operators/delay.ml b/src/core/operators/delay.ml index f0dfe529e3..bf4914695a 100644 --- a/src/core/operators/delay.ml +++ b/src/core/operators/delay.ml @@ -46,8 +46,8 @@ class delay ~initial (source : source) delay = in_track <- false; last <- Unix.time () - method is_ready = - let is_ready = source#is_ready in + method private _is_ready ?frame () = + let is_ready = source#is_ready ?frame () in if in_track && not is_ready then self#end_track; self#delay_ok && is_ready diff --git a/src/core/operators/delay_line.ml b/src/core/operators/delay_line.ml index 50849302be..377243b6eb 100644 --- a/src/core/operators/delay_line.ml +++ b/src/core/operators/delay_line.ml @@ -29,7 +29,7 @@ class delay (source : source) duration = inherit operator ~name:"amplify" [source] as super val mutable override = None method stype = source#stype - method is_ready = source#is_ready + method private _is_ready = source#is_ready method remaining = source#remaining method abort_track = source#abort_track method seek = source#seek diff --git a/src/core/operators/dtmf.ml b/src/core/operators/dtmf.ml index aecc1fdd0a..957c0be740 100644 --- a/src/core/operators/dtmf.ml +++ b/src/core/operators/dtmf.ml @@ -159,7 +159,7 @@ class dtmf ~duration ~bands ~threshold ~smoothing ~debug callback method remaining = source#remaining method seek = source#seek method seek_source = source - method is_ready = source#is_ready + method private _is_ready = source#is_ready method abort_track = source#abort_track method self_sync = source#self_sync @@ -297,7 +297,7 @@ class detect ~duration ~bands ~threshold ~smoothing ~debug ~frequencies callback method remaining = source#remaining method seek = source#seek method seek_source = source - method is_ready = source#is_ready + method private _is_ready = source#is_ready method abort_track = source#abort_track method self_sync = source#self_sync val bands = Bands.make ~size:nbands ~samplerate frequencies diff --git a/src/core/operators/dyn_op.ml b/src/core/operators/dyn_op.ml index ca874d483a..ad78490e4e 100644 --- a/src/core/operators/dyn_op.ml +++ b/src/core/operators/dyn_op.ml @@ -83,10 +83,10 @@ class dyn ~init ~track_sensitive ~infallible ~resurection_time f = f; self#unregister_source ~already_locked:false - method is_ready = + method private _is_ready ?frame () = if (not track_sensitive) || source = None then self#select; match source with - | Some s when s#is_ready -> true + | Some s when s#is_ready ?frame () -> true | _ -> if track_sensitive && resurection_time <> None diff --git a/src/core/operators/echo.ml b/src/core/operators/echo.ml index 17586e9e5a..9b1ea476ad 100644 --- a/src/core/operators/echo.ml +++ b/src/core/operators/echo.ml @@ -31,7 +31,7 @@ class echo (source : source) delay feedback ping_pong = method seek = source#seek method seek_source = source method self_sync = source#self_sync - method is_ready = source#is_ready + method private _is_ready = source#is_ready method abort_track = source#abort_track val mutable effect = None diff --git a/src/core/operators/filter.ml b/src/core/operators/filter.ml index aa9f26b87b..19c3e194f6 100644 --- a/src/core/operators/filter.ml +++ b/src/core/operators/filter.ml @@ -32,7 +32,7 @@ class filter (source : source) freq q wet mode = method remaining = source#remaining method seek = source#seek method seek_source = source - method is_ready = source#is_ready + method private _is_ready = source#is_ready method abort_track = source#abort_track method self_sync = source#self_sync val mutable low = [||] diff --git a/src/core/operators/filter_rc.ml b/src/core/operators/filter_rc.ml index fa96cc7c50..1c882dc411 100644 --- a/src/core/operators/filter_rc.ml +++ b/src/core/operators/filter_rc.ml @@ -34,7 +34,7 @@ class filter (source : source) freq wet mode = method seek = source#seek method seek_source = source method self_sync = source#self_sync - method is_ready = source#is_ready + method private _is_ready = source#is_ready method abort_track = source#abort_track val mutable prev = [||] val mutable prev_in = [||] diff --git a/src/core/operators/fir_filter.ml b/src/core/operators/fir_filter.ml index 0986d0e521..a30bb7cc83 100644 --- a/src/core/operators/fir_filter.ml +++ b/src/core/operators/fir_filter.ml @@ -123,7 +123,7 @@ class fir (source : source) freq beta numcoeffs = (* Digital filter based on mkfilter/mkshape/gencode by A.J. Fisher *) method stype = source#stype method remaining = source#remaining - method is_ready = source#is_ready + method private _is_ready = source#is_ready method seek = source#seek method seek_source = source method abort_track = source#abort_track diff --git a/src/core/operators/flanger.ml b/src/core/operators/flanger.ml index 5c86ecf6c4..4b0005820f 100644 --- a/src/core/operators/flanger.ml +++ b/src/core/operators/flanger.ml @@ -34,7 +34,7 @@ class flanger (source : source) delay freq feedback phase = method seek = source#seek method seek_source = source method self_sync = source#self_sync - method is_ready = source#is_ready + method private _is_ready = source#is_ready method abort_track = source#abort_track val mutable past = Audio.make 0 0 0. diff --git a/src/core/operators/frei0r_op.ml b/src/core/operators/frei0r_op.ml index b5c4966513..c0a5413ec7 100644 --- a/src/core/operators/frei0r_op.ml +++ b/src/core/operators/frei0r_op.ml @@ -51,7 +51,7 @@ class frei0r_filter ~name bgra instance params (source : source) = method remaining = source#remaining method seek = source#seek method seek_source = (self :> Source.source) - method is_ready = source#is_ready + method private _is_ready = source#is_ready method self_sync = source#self_sync method abort_track = source#abort_track val mutable t = 0. @@ -95,7 +95,8 @@ class frei0r_mixer ~name bgra instance params (source : source) source2 = | -1, x | x, -1 -> x | x, y -> min x y - method is_ready = source#is_ready && source2#is_ready + method private _is_ready ?frame () = + source#is_ready ?frame () && source2#is_ready ?frame () method self_sync = match (source#self_sync, source2#self_sync) with @@ -164,7 +165,7 @@ class frei0r_source ~name bgra instance params = inherit Source.no_seek method seek_source = (self :> Source.source) method stype = `Infallible - method is_ready = true + method private _is_ready ?frame:_ _ = true method self_sync = (`Static, false) val mutable must_fail = false method abort_track = must_fail <- true diff --git a/src/core/operators/gate.ml b/src/core/operators/gate.ml index 32db48e390..639646dda2 100644 --- a/src/core/operators/gate.ml +++ b/src/core/operators/gate.ml @@ -30,7 +30,7 @@ class gate ~threshold ~attack ~release ~hold ~range ~window (source : source) = method remaining = source#remaining method seek = source#seek method seek_source = source - method is_ready = source#is_ready + method private _is_ready = source#is_ready method abort_track = source#abort_track method self_sync = source#self_sync diff --git a/src/core/operators/iir_filter.ml b/src/core/operators/iir_filter.ml index 905d250c3f..e5dd3ac976 100644 --- a/src/core/operators/iir_filter.ml +++ b/src/core/operators/iir_filter.ml @@ -416,7 +416,7 @@ class iir (source : source) filter_family filter_type order freq1 freq2 qfactor method seek = source#seek method seek_source = source method self_sync = source#self_sync - method is_ready = source#is_ready + method private _is_ready = source#is_ready method abort_track = source#abort_track val mutable v_offs = 0 diff --git a/src/core/operators/insert_metadata.ml b/src/core/operators/insert_metadata.ml index 5eb3b70de3..40c07e29b7 100644 --- a/src/core/operators/insert_metadata.ml +++ b/src/core/operators/insert_metadata.ml @@ -29,7 +29,7 @@ class insert_metadata source = object (self) inherit operator ~name:"insert_metadata" [source] method stype = source#stype - method is_ready = source#is_ready + method private _is_ready = source#is_ready method remaining = source#remaining method seek = source#seek method seek_source = source @@ -122,7 +122,7 @@ class replay meta src = inherit operator ~name:"replay_metadata" [src] val mutable first = true method stype = src#stype - method is_ready = src#is_ready + method private _is_ready = src#is_ready method abort_track = src#abort_track method remaining = src#remaining method self_sync = src#self_sync diff --git a/src/core/operators/ladspa_op.ml b/src/core/operators/ladspa_op.ml index c2c159b2f7..9758252839 100644 --- a/src/core/operators/ladspa_op.ml +++ b/src/core/operators/ladspa_op.ml @@ -64,7 +64,7 @@ class virtual base source = method remaining = source#remaining method seek = source#seek method seek_source = (self :> Source.source) - method is_ready = source#is_ready + method private _is_ready = source#is_ready method self_sync = source#self_sync method abort_track = source#abort_track end @@ -75,7 +75,7 @@ class virtual base_nosource = inherit Source.no_seek method seek_source = (self :> Source.source) method stype = `Infallible - method is_ready = true + method private _is_ready ?frame:_ _ = true method self_sync = (`Static, false) val mutable must_fail = false method abort_track = must_fail <- true diff --git a/src/core/operators/lilv_op.ml b/src/core/operators/lilv_op.ml index 2d27feee60..4a5e588e21 100644 --- a/src/core/operators/lilv_op.ml +++ b/src/core/operators/lilv_op.ml @@ -40,7 +40,7 @@ class virtual base source = method remaining = source#remaining method seek = source#seek method seek_source = source - method is_ready = source#is_ready + method private _is_ready = source#is_ready method self_sync = source#self_sync method abort_track = source#abort_track end @@ -51,7 +51,7 @@ class virtual base_nosource = inherit Source.no_seek method seek_source = (self :> Source.source) method stype = `Infallible - method is_ready = true + method private _is_ready ?frame:_ _ = true val mutable must_fail = false method abort_track = must_fail <- true method remaining = -1 diff --git a/src/core/operators/lufs.ml b/src/core/operators/lufs.ml index 67f4b7b183..c9d4467d53 100644 --- a/src/core/operators/lufs.ml +++ b/src/core/operators/lufs.ml @@ -107,7 +107,7 @@ class lufs window source = object (self) inherit operator [source] ~name:"lufs" as super method stype = source#stype - method is_ready = source#is_ready + method private _is_ready = source#is_ready method remaining = source#remaining method seek = source#seek method seek_source = source diff --git a/src/core/operators/map_metadata.ml b/src/core/operators/map_metadata.ml index 8cbc6e3cea..09400fb259 100644 --- a/src/core/operators/map_metadata.ml +++ b/src/core/operators/map_metadata.ml @@ -27,7 +27,7 @@ class map_metadata source rewrite_f insert_missing update strip = inherit operator ~name:"metadata.map" [source] initializer Typing.(self#frame_type <: Lang.unit_t) method stype = source#stype - method is_ready = source#is_ready + method private _is_ready = source#is_ready method remaining = source#remaining method abort_track = source#abort_track method seek n = source#seek n diff --git a/src/core/operators/map_op.ml b/src/core/operators/map_op.ml index dde3499eb3..e7d207c9f5 100644 --- a/src/core/operators/map_op.ml +++ b/src/core/operators/map_op.ml @@ -30,7 +30,7 @@ class map ~field source f = method seek = source#seek method seek_source = source method self_sync = source#self_sync - method is_ready = source#is_ready + method private _is_ready = source#is_ready method abort_track = source#abort_track method private get_frame buf = diff --git a/src/core/operators/max_duration.ml b/src/core/operators/max_duration.ml index 858097bef5..353969c33c 100644 --- a/src/core/operators/max_duration.ml +++ b/src/core/operators/max_duration.ml @@ -38,7 +38,7 @@ class max_duration ~override_meta ~duration source = method! private sleep = s#leave (self :> Source.operator) method stype = `Fallible - method is_ready = remaining > 0 && s#is_ready + method private _is_ready ?frame () = remaining > 0 && s#is_ready ?frame () method abort_track = s#abort_track method remaining = diff --git a/src/core/operators/midi_routing.ml b/src/core/operators/midi_routing.ml index 6c582b920e..5748203abd 100644 --- a/src/core/operators/midi_routing.ml +++ b/src/core/operators/midi_routing.ml @@ -31,7 +31,7 @@ class virtual base ~name (source : source) = method seek = source#seek method seek_source = source method self_sync = source#self_sync - method is_ready = source#is_ready + method private _is_ready = source#is_ready method abort_track = source#abort_track end diff --git a/src/core/operators/ms_stereo.ml b/src/core/operators/ms_stereo.ml index 386fc1c887..76c683547d 100644 --- a/src/core/operators/ms_stereo.ml +++ b/src/core/operators/ms_stereo.ml @@ -28,7 +28,7 @@ class msstereo ~field (source : source) mode width = object inherit operator ~name:"stereo.ms.encode" [source] method stype = source#stype - method is_ready = source#is_ready + method private _is_ready = source#is_ready method remaining = source#remaining method seek = source#seek method seek_source = source @@ -91,7 +91,7 @@ class spatializer ~field ~width (source : source) = object inherit operator ~name:"stereo.width" [source] method stype = source#stype - method is_ready = source#is_ready + method private _is_ready = source#is_ready method remaining = source#remaining method seek = source#seek method seek_source = source diff --git a/src/core/operators/muxer.ml b/src/core/operators/muxer.ml index c3e8a0976c..6960f42a90 100644 --- a/src/core/operators/muxer.ml +++ b/src/core/operators/muxer.ml @@ -57,8 +57,12 @@ class muxer tracks = (Lazy.force self_sync_type, List.exists (fun s -> snd s#self_sync) sources) method abort_track = List.iter (fun s -> s#abort_track) sources - method private sources_ready = List.for_all (fun s -> s#is_ready) sources - method is_ready = Generator.length self#buffer > 0 || self#sources_ready + + method private sources_ready ?frame () = + List.for_all (fun s -> s#is_ready ?frame ()) sources + + method private _is_ready ?frame () = + Generator.length self#buffer > 0 || self#sources_ready ?frame () method seek len = let gen_len = min (Generator.length self#buffer) len in @@ -90,7 +94,7 @@ class muxer tracks = List.fold_left (fun r s -> if r = -1 then s#remaining else min r s#remaining) (-1) - (List.filter (fun s -> s#is_ready) sources) ) + (List.filter (fun (s : Source.source) -> s#is_ready ()) sources) ) with | -1, r -> r | r, _ -> r @@ -118,7 +122,7 @@ class muxer tracks = method private feed_fields ~filled { fields; source } = let tmp = self#track_frame source in let start = Frame.position tmp in - if Frame.is_partial tmp && source#is_ready then ( + 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) @@ -131,7 +135,7 @@ class muxer tracks = method private feed ~force buf = let filled = Frame.position buf in if - self#sources_ready + self#sources_ready () && (force || Generator.remaining self#buffer = -1 && filled + Generator.length self#buffer < Lazy.force Frame.size) diff --git a/src/core/operators/noblank.ml b/src/core/operators/noblank.ml index a4e6048f91..cd06c6cd2d 100644 --- a/src/core/operators/noblank.ml +++ b/src/core/operators/noblank.ml @@ -87,7 +87,7 @@ class detect ~start_blank ~max_blank ~min_noise ~threshold ~track_sensitive inherit operator ~name:"blank.detect" [source] inherit base ~track_sensitive ~start_blank ~max_blank ~min_noise ~threshold method stype = source#stype - method is_ready = source#is_ready + method private _is_ready = source#is_ready method abort_track = source#abort_track method remaining = source#remaining method seek = source#seek @@ -117,7 +117,10 @@ 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 stype = `Fallible - method is_ready = (not self#is_blank) && source#is_ready + + method private _is_ready ?frame () = + (not self#is_blank) && source#is_ready ?frame () + method remaining = if self#is_blank then 0 else source#remaining method seek n = if self#is_blank then 0 else source#seek n @@ -145,8 +148,11 @@ class strip ~start_blank ~max_blank ~min_noise ~threshold ~track_sensitive * the track ends, the beginning of the next track won't be lost. (Because * of granularity issues, the change of #is_ready only takes effect at the * end of the clock cycle). *) - if source#is_ready && self#is_blank && AFrame.is_partial self#memo then - self#get_frame self#memo + if + source#is_ready ~frame:self#memo () + && self#is_blank + && AFrame.is_partial self#memo + then self#get_frame self#memo method reset = () end @@ -166,7 +172,7 @@ class eat ~track_sensitive ~at_beginning ~start_blank ~max_blank ~min_noise val mutable stripping = false val mutable beginning = true method stype = `Fallible - method is_ready = source#is_ready + method private _is_ready = source#is_ready method remaining = source#remaining method seek = source#seek method seek_source = source diff --git a/src/core/operators/normalize.ml b/src/core/operators/normalize.ml index d484007e74..53f0c9b036 100644 --- a/src/core/operators/normalize.ml +++ b/src/core/operators/normalize.ml @@ -66,7 +66,7 @@ class normalize ~track_sensitive (source : source) (* RMS target. *) rmst method seek = source#seek method seek_source = source method self_sync = source#self_sync - method is_ready = source#is_ready + method private _is_ready = source#is_ready method abort_track = source#abort_track method private get_frame buf = diff --git a/src/core/operators/on_end.ml b/src/core/operators/on_end.ml index 747d1a5117..3ebc90b6d1 100644 --- a/src/core/operators/on_end.ml +++ b/src/core/operators/on_end.ml @@ -26,7 +26,7 @@ class on_end ~delay f s = inherit Latest_metadata.source val mutable executed = false method stype = s#stype - method is_ready = s#is_ready + method private _is_ready = s#is_ready method remaining = s#remaining method abort_track = s#abort_track method seek n = s#seek n diff --git a/src/core/operators/on_frame.ml b/src/core/operators/on_frame.ml index 6c00e57b63..0a0b21507e 100644 --- a/src/core/operators/on_frame.ml +++ b/src/core/operators/on_frame.ml @@ -24,7 +24,7 @@ class on_frame f s = object inherit Source.operator ~name:"on_frame" [s] method stype = s#stype - method is_ready = s#is_ready + method private _is_ready = s#is_ready method abort_track = s#abort_track method remaining = s#remaining method seek n = s#seek n @@ -60,7 +60,7 @@ class frame_op ~name f default s = object inherit Source.operator ~name [s] method stype = s#stype - method is_ready = s#is_ready + method private _is_ready = s#is_ready method abort_track = s#abort_track method remaining = s#remaining method seek n = s#seek n diff --git a/src/core/operators/on_metadata.ml b/src/core/operators/on_metadata.ml index 18751297d8..4d68eb7362 100644 --- a/src/core/operators/on_metadata.ml +++ b/src/core/operators/on_metadata.ml @@ -24,7 +24,7 @@ class on_metadata f s = object (self) inherit Source.operator ~name:"on_metadata" [s] method stype = s#stype - method is_ready = s#is_ready + method private _is_ready = s#is_ready method abort_track = s#abort_track method remaining = s#remaining method seek n = s#seek n diff --git a/src/core/operators/on_offset.ml b/src/core/operators/on_offset.ml index 782ad120c2..bf37b85e0d 100644 --- a/src/core/operators/on_offset.ml +++ b/src/core/operators/on_offset.ml @@ -33,7 +33,7 @@ class on_offset ~force ~offset f s = inherit Source.operator ~name:"on_offset" [s] inherit Latest_metadata.source method stype = s#stype - method is_ready = s#is_ready + method private _is_ready = s#is_ready method remaining = s#remaining method abort_track = s#abort_track method seek n = s#seek n diff --git a/src/core/operators/on_track.ml b/src/core/operators/on_track.ml index f5b34c71f9..7986ac44d0 100644 --- a/src/core/operators/on_track.ml +++ b/src/core/operators/on_track.ml @@ -24,7 +24,7 @@ class on_track f s = object inherit Source.operator ~name:"on_track" [s] method stype = s#stype - method is_ready = s#is_ready + method private _is_ready = s#is_ready method abort_track = s#abort_track method remaining = s#remaining method seek n = s#seek n diff --git a/src/core/operators/pan.ml b/src/core/operators/pan.ml index 86256ca2d9..272fe3fb05 100644 --- a/src/core/operators/pan.ml +++ b/src/core/operators/pan.ml @@ -27,7 +27,7 @@ class pan ~field (source : source) phi phi_0 = object inherit operator ~name:"pan" [source] method stype = source#stype - method is_ready = source#is_ready + method private _is_ready = source#is_ready method remaining = source#remaining method seek = source#seek method seek_source = source diff --git a/src/core/operators/pipe.ml b/src/core/operators/pipe.ml index bde8331ed8..3dba45a8fe 100644 --- a/src/core/operators/pipe.ml +++ b/src/core/operators/pipe.ml @@ -153,7 +153,7 @@ class pipe ~replay_delay ~data_len ~process ~bufferize ~max ~restart t method private get_to_write = - if source#is_ready then ( + if source#is_ready ~frame:self#tmp () then ( Frame.clear self#tmp; self#child_on_output (fun () -> source#get self#tmp); let buf = AFrame.pcm self#tmp in diff --git a/src/core/operators/pitch.ml b/src/core/operators/pitch.ml index 42a7553dbc..b16b03973d 100644 --- a/src/core/operators/pitch.ml +++ b/src/core/operators/pitch.ml @@ -81,7 +81,7 @@ class pitch every length freq_min freq_max (source : source) = method remaining = source#remaining method seek = source#seek method seek_source = source - method is_ready = source#is_ready + method private _is_ready = source#is_ready method abort_track = source#abort_track method self_sync = source#self_sync diff --git a/src/core/operators/replaygain_op.ml b/src/core/operators/replaygain_op.ml index 15af82247f..5875192cd4 100644 --- a/src/core/operators/replaygain_op.ml +++ b/src/core/operators/replaygain_op.ml @@ -28,7 +28,7 @@ class replaygain (source : source) = inherit operator ~name:"source.replaygain.compute" [source] val mutable override = None method stype = source#stype - method is_ready = source#is_ready + method private _is_ready = source#is_ready method remaining = source#remaining method abort_track = source#abort_track method seek = source#seek diff --git a/src/core/operators/resample.ml b/src/core/operators/resample.ml index e3bee51146..ed058a56f4 100644 --- a/src/core/operators/resample.ml +++ b/src/core/operators/resample.ml @@ -51,7 +51,7 @@ class resample ~field ~ratio source = else int_of_float (float (rem + Generator.length self#buffer) *. ratio ()) method abort_track = source#abort_track - method is_ready = source#is_ready + method private _is_ready = source#is_ready val mutable converter = None method! wake_up a = @@ -84,7 +84,8 @@ class resample ~field ~ratio source = method private get_frame frame = consumer#set_output_enabled true; while - Generator.length self#buffer < Lazy.force Frame.size && source#is_ready + Generator.length self#buffer < Lazy.force Frame.size + && source#is_ready ~frame:self#buffer () do self#child_tick done; diff --git a/src/core/operators/rms_smooth.ml b/src/core/operators/rms_smooth.ml index 039459ba78..e10343f329 100644 --- a/src/core/operators/rms_smooth.ml +++ b/src/core/operators/rms_smooth.ml @@ -27,7 +27,7 @@ class rms ~tau source = object (self) inherit operator [source] ~name:"rms" as super method stype = source#stype - method is_ready = source#is_ready + method private _is_ready = source#is_ready method remaining = source#remaining method seek = source#seek method seek_source = source diff --git a/src/core/operators/sequence.ml b/src/core/operators/sequence.ml index bf39e3d443..fcd756ca9c 100644 --- a/src/core/operators/sequence.ml +++ b/src/core/operators/sequence.ml @@ -59,8 +59,8 @@ class sequence ?(merge = false) sources = * inserted an end of track automatically instead of calling #get_frame. *) val mutable head_ready = false - method is_ready = - head_ready || List.exists (fun s -> s#is_ready) seq_sources + method private _is_ready ?frame () = + head_ready || List.exists (fun s -> s#is_ready ?frame ()) seq_sources method remaining = if merge then ( @@ -88,7 +88,7 @@ class sequence ?(merge = false) sources = head_ready <- false; if List.length seq_sources > 1 then ( seq_sources <- List.tl seq_sources; - if merge && self#is_ready then ( + if merge && self#is_ready ~frame:buf () then ( let pos = Frame.position buf in self#get_frame buf; Frame.set_breaks buf @@ -96,10 +96,11 @@ class sequence ?(merge = false) sources = else ( match seq_sources with | a :: (_ :: _ as tl) -> - if a#is_ready then head_ready <- true else seq_sources <- tl; + if a#is_ready ~frame:buf () then head_ready <- true + else seq_sources <- tl; self#get_frame buf | [a] -> - assert a#is_ready; + assert (a#is_ready ~frame:buf ()); (* Our #is_ready ensures that. *) head_ready <- true; @@ -111,7 +112,7 @@ class merge_tracks source = object (self) inherit operator ~name:"sequence" [source] method stype = source#stype - method is_ready = source#is_ready + method private _is_ready = source#is_ready method abort_track = source#abort_track method remaining = -1 method self_sync = source#self_sync @@ -120,7 +121,7 @@ class merge_tracks source = method private get_frame buf = source#get buf; - if Frame.is_partial buf && source#is_ready then ( + if Frame.is_partial buf && source#is_ready ~frame:buf () then ( self#log#info "End of track: merging."; self#get_frame buf; Frame.set_breaks buf diff --git a/src/core/operators/soundtouch_op.ml b/src/core/operators/soundtouch_op.ml index 98d34c89c2..f3b3bb7206 100644 --- a/src/core/operators/soundtouch_op.ml +++ b/src/core/operators/soundtouch_op.ml @@ -41,7 +41,7 @@ class soundtouch source_val rate tempo pitch = val mutable st = None method stype = source#stype method self_sync = source#self_sync - method is_ready = source#is_ready + method private _is_ready = source#is_ready method seek = source#seek method seek_source = source method remaining = -1 @@ -77,7 +77,8 @@ class soundtouch source_val rate tempo pitch = method private get_frame buf = consumer#set_output_enabled true; while - Generator.length self#buffer < Lazy.force Frame.size && source#is_ready + Generator.length self#buffer < Lazy.force Frame.size + && source#is_ready ~frame:self#buffer () do self#child_tick done; diff --git a/src/core/operators/st_bpm.ml b/src/core/operators/st_bpm.ml index 5478094c7c..e96f4eb28b 100644 --- a/src/core/operators/st_bpm.ml +++ b/src/core/operators/st_bpm.ml @@ -26,7 +26,7 @@ class bpm (source : source) = object (self) inherit operator ~name:"bpm" [source] as super method stype = source#stype - method is_ready = source#is_ready + method private _is_ready = source#is_ready method self_sync = source#self_sync method remaining = source#remaining method seek = source#seek diff --git a/src/core/operators/stereotool_op.ml b/src/core/operators/stereotool_op.ml index b5c57b74a8..e3beb88dfc 100644 --- a/src/core/operators/stereotool_op.ml +++ b/src/core/operators/stereotool_op.ml @@ -76,7 +76,7 @@ class stereotool ~field ~handler source = method remaining = source#remaining method seek = source#seek method seek_source = source - method is_ready = source#is_ready + method private _is_ready = source#is_ready method abort_track = source#abort_track method self_sync = source#self_sync diff --git a/src/core/operators/still_frame.ml b/src/core/operators/still_frame.ml index 2c59225e72..657afd6f4b 100644 --- a/src/core/operators/still_frame.ml +++ b/src/core/operators/still_frame.ml @@ -34,7 +34,7 @@ class still_frame ~name (source : source) = method seek = source#seek method seek_source = source method self_sync = source#self_sync - method is_ready = source#is_ready + method private _is_ready = source#is_ready method abort_track = source#abort_track val mutable fname = None diff --git a/src/core/operators/switch.ml b/src/core/operators/switch.ml index 42dd84e256..99b998c03a 100644 --- a/src/core/operators/switch.ml +++ b/src/core/operators/switch.ml @@ -114,7 +114,8 @@ class virtual switch ~name ~override_meta ~transition_length if self#is_selected_generated then (Option.get selected).effective_source#leave (self :> source) - method is_ready = need_eot || selected <> None || self#cached_select <> None + method private _is_ready ?frame:_ _ = + need_eot || selected <> None || self#cached_select <> None (* This one is tricky. We do not want to call #cached_select as this requires some run-time info from underlying sources @@ -317,7 +318,7 @@ class lang_switch ~override_meta ~all_predicates ~transition_length mode (fun (d, single, s) -> (* Check single constraints *) (if selected s then not single else true) - && satisfied d && s.source#is_ready) + && satisfied d && s.source#is_ready ()) children)) with Not_found -> None diff --git a/src/core/operators/time_warp.ml b/src/core/operators/time_warp.ml index fcf17672fd..821b8eacc6 100644 --- a/src/core/operators/time_warp.ml +++ b/src/core/operators/time_warp.ml @@ -127,7 +127,8 @@ module Buffer = struct method remaining = proceed c (fun () -> Generator.remaining (Lazy.force c.generator)) - method is_ready = proceed c (fun () -> not c.buffering) + method private _is_ready ?frame:_ _ = + proceed c (fun () -> not c.buffering) method seek len = let len = min (Generator.length (Lazy.force c.generator)) len in @@ -303,7 +304,10 @@ module AdaptativeBuffer = struct method stype = `Fallible method self_sync = (`Static, false) method remaining = proceed c (fun () -> MG.remaining c.mg) - method is_ready = proceed c (fun () -> not c.buffering) + + method private _is_ready ?frame:_ _ = + proceed c (fun () -> not c.buffering) + method ratio = proceed c (fun () -> c.rb_length /. prebuf) method buffer_duration = diff --git a/src/core/operators/track/merge_metadata.ml b/src/core/operators/track/merge_metadata.ml index c11a609384..ef22fc931d 100644 --- a/src/core/operators/track/merge_metadata.ml +++ b/src/core/operators/track/merge_metadata.ml @@ -36,8 +36,10 @@ class merge_metadata tracks = (Lazy.force self_sync_type, List.exists (fun s -> snd s#self_sync) sources) method abort_track = List.iter (fun s -> s#abort_track) sources - method private sources_ready = List.for_all (fun s -> s#is_ready) sources - method is_ready = List.for_all (fun s -> s#is_ready) sources + + method private _is_ready ?frame () = + List.for_all (fun s -> s#is_ready ?frame ()) sources + method seek len = len method seek_source = (self :> Source.source) method remaining = -1 @@ -54,9 +56,10 @@ class merge_metadata tracks = let pos = Frame.position buf in let max_pos = List.fold_left - (fun max_pos source -> + (fun max_pos (source : Source.source) -> let tmp_frame = self#track_frame source in - if source#is_ready && Frame.is_partial tmp_frame then ( + if source#is_ready ~frame:tmp_frame () && Frame.is_partial tmp_frame + then ( source#get tmp_frame; List.iter (fun (p, m) -> diff --git a/src/core/operators/track_map.ml b/src/core/operators/track_map.ml index e5401a287c..1c00299fb2 100644 --- a/src/core/operators/track_map.ml +++ b/src/core/operators/track_map.ml @@ -31,7 +31,7 @@ class track_map ~name ~field ~fn s = method seek = s#seek method seek_source = s method self_sync = s#self_sync - method is_ready = s#is_ready + method private _is_ready = s#is_ready val mutable tmp_frame = None method tmp_frame = diff --git a/src/core/operators/video_effects.ml b/src/core/operators/video_effects.ml index 1c4890c65c..08d43be4c5 100644 --- a/src/core/operators/video_effects.ml +++ b/src/core/operators/video_effects.ml @@ -75,7 +75,7 @@ class virtual base ~name (source : source) f = method seek = source#seek method seek_source = source method self_sync = source#self_sync - method is_ready = source#is_ready + method private _is_ready = source#is_ready method abort_track = source#abort_track method private get_frame buf = diff --git a/src/core/operators/video_fade.ml b/src/core/operators/video_fade.ml index 67a4e5e7c8..99d0aa998b 100644 --- a/src/core/operators/video_fade.ml +++ b/src/core/operators/video_fade.ml @@ -31,7 +31,7 @@ class fade_in ?(meta = "liq_video_fade_in") duration fader fadefun source = object inherit operator ~name:"video.fade.in" [source] method stype = source#stype - method is_ready = source#is_ready + method private _is_ready = source#is_ready method abort_track = source#abort_track method remaining = source#remaining method self_sync = source#self_sync @@ -96,7 +96,7 @@ class fade_out ?(meta = "liq_video_fade_out") duration fader fadefun source = * The value is set at the beginning of every track, depending on metadata. *) val mutable cur_length = None method remaining = source#remaining - method is_ready = source#is_ready + method private _is_ready = source#is_ready method private get_frame ab = let n = Frame.video_of_main source#remaining in diff --git a/src/core/operators/window_op.ml b/src/core/operators/window_op.ml index cfc26b3570..486235200c 100644 --- a/src/core/operators/window_op.ml +++ b/src/core/operators/window_op.ml @@ -30,7 +30,7 @@ class window mode duration source = operator [source] ~name:(match mode with RMS -> "rms" | Peak -> "peak") as super method stype = source#stype - method is_ready = source#is_ready + method private _is_ready = source#is_ready method remaining = source#remaining method seek = source#seek method seek_source = source diff --git a/src/core/outputs/output.ml b/src/core/outputs/output.ml index 815f2a8233..d4e00ef7f6 100644 --- a/src/core/outputs/output.ml +++ b/src/core/outputs/output.ml @@ -96,11 +96,11 @@ class virtual output ~output_kind ?(name = "") ~infallible let t = Frame.seconds_of_main r in Printf.sprintf "%.2f" t))) - method is_ready = + method private _is_ready ?frame () = if infallible then ( - assert source#is_ready; + assert (source#is_ready ?frame ()); true) - else source#is_ready + else source#is_ready ?frame () method remaining = source#remaining method abort_track = source#abort_track @@ -129,7 +129,7 @@ class virtual output ~output_kind ?(name = "") ~infallible etc). *) source#get_ready ((self :> operator) :: activation); if infallible then - while not source#is_ready do + while not (source#is_ready ()) do self#log#important "Waiting for %S to be ready..." source#id; Thread.delay 1. done; @@ -160,12 +160,12 @@ class virtual output ~output_kind ?(name = "") ~infallible method private output = self#has_ticked; - if self#is_ready && state <> `Stopped then + if self#is_ready ~frame:self#memo () && state <> `Stopped then start_stop#transition_to `Started; if start_stop#state = `Started then ( (* Complete filling of the frame *) let get_count = ref 0 in - while Frame.is_partial self#memo && self#is_ready do + while Frame.is_partial self#memo && self#is_ready ~frame:self#memo () do incr get_count; if !get_count > Lazy.force Frame.size then self#log#severe diff --git a/src/core/outputs/output.mli b/src/core/outputs/output.mli index cb2707504f..6dcd2f858e 100644 --- a/src/core/outputs/output.mli +++ b/src/core/outputs/output.mli @@ -41,7 +41,7 @@ class virtual output : method output : unit method private get_frame : Frame.t -> unit method abort_track : unit - method is_ready : bool + method private _is_ready : ?frame:Frame.t -> unit -> bool method state : Start_stop.state method transition_to : Start_stop.state -> unit method seek : int -> int diff --git a/src/core/source.ml b/src/core/source.ml index 06326aa5dd..d740b197de 100644 --- a/src/core/source.ml +++ b/src/core/source.ml @@ -599,10 +599,17 @@ class virtual operator ?pos ?(name = "src") sources = source. *) method virtual seek_source : source - (* Is there some data available for the next [get]? - Must always be true while playing a track, i.e. all tracks - must be properly ended. *) - method virtual is_ready : bool + (* Underlying source implementation for [is_ready]. + should return [true] when the source can produce + fresh data. *) + method virtual private _is_ready : ?frame:Frame.t -> unit -> bool + + method is_ready ?frame () = + match frame with + | None -> self#_is_ready ?frame () + | Some frame -> + (caching && Frame.position frame < Frame.position self#memo) + || self#_is_ready ~frame () (* If possible, end the current track. Typically, that signal is just re-routed, or makes the next file @@ -758,7 +765,7 @@ class virtual operator ?pos ?(name = "src") sources = track, otherwise the track will be ended without the source noticing! *) let silent_end_track () = Frame.add_break buf (Frame.position buf) in if not caching then - if not self#is_ready then silent_end_track () + if not (self#_is_ready ~frame:buf ()) then silent_end_track () else ( let b = Frame.breaks buf in self#instrumented_get_frame buf; @@ -773,7 +780,7 @@ class virtual operator ?pos ?(name = "src") sources = let memo = self#memo in try Frame.get_chunk buf memo with Frame.No_chunk -> - if not self#is_ready then silent_end_track () + if not (self#_is_ready ~frame:buf ()) then silent_end_track () else ( (* [memo] has nothing new for [buf]. Feed [memo] and try again *) let b = Frame.breaks memo in diff --git a/src/core/source.mli b/src/core/source.mli index 3af986630e..a2b8ba95b2 100644 --- a/src/core/source.mli +++ b/src/core/source.mli @@ -191,8 +191,17 @@ class virtual source : source. *) method virtual seek_source : source - (** [is_ready] tells you if [get] can be called. *) - method virtual is_ready : bool + (** [is_ready] tells you if [get] can be called. + Frame argument is optional. With no frame, the + function tells you if the source can produce + fresh data. With a frame, it tells you if the + source can fill the frame from its current position, + potentially using cached data when the source is + caching. *) + method is_ready : ?frame:Frame.t -> unit -> bool + + (* Internal implementation of [is_ready]. *) + method virtual private _is_ready : ?frame:Frame.t -> unit -> bool (** [get buf] asks the source to fill the buffer [buf] if possible. The [get] call is partial when the buffer is not completely filled. diff --git a/src/core/sources/blank.ml b/src/core/sources/blank.ml index e14ea5f9a5..1544d93c47 100644 --- a/src/core/sources/blank.ml +++ b/src/core/sources/blank.ml @@ -33,7 +33,7 @@ class blank duration = method remaining = remaining method stype = `Infallible - method is_ready = true + method private _is_ready ?frame:_ _ = true method self_sync = (`Static, false) method seek x = x method seek_source = (self :> Source.source) diff --git a/src/core/sources/debug_sources.ml b/src/core/sources/debug_sources.ml index 056060c31a..9d4c379af5 100644 --- a/src/core/sources/debug_sources.ml +++ b/src/core/sources/debug_sources.ml @@ -26,7 +26,7 @@ class fail name = inherit Source.no_seek method seek_source = (self :> Source.source) method stype = `Fallible - method is_ready = false + method private _is_ready ?frame:_ _ = false method self_sync = (`Static, false) method remaining = 0 method abort_track = () diff --git a/src/core/sources/generated.ml b/src/core/sources/generated.ml index cd23d7ef45..aa3484fc51 100644 --- a/src/core/sources/generated.ml +++ b/src/core/sources/generated.ml @@ -50,7 +50,7 @@ class virtual source ?(seek = false) ?(replay_meta = false) ~bufferize method private length = Generator.length self#buffer val mutable last_buffering_warning = -1 - method is_ready = + method private _is_ready ?frame:_ _ = let r = self#length in if buffering then ( (* We have some data, but not enough for safely starting to play it. *) diff --git a/src/core/sources/harbor_input.ml b/src/core/sources/harbor_input.ml index 3e1fe097d5..07e83d11af 100644 --- a/src/core/sources/harbor_input.ml +++ b/src/core/sources/harbor_input.ml @@ -60,7 +60,8 @@ class http_input_server ~pos ~transport ~dumpfile ~logfile ~bufferize ~max ~icy | None -> "no source client connected" method private output = - if self#is_ready && AFrame.is_partial self#memo then self#get self#memo + if self#is_ready ~frame:self#memo () && AFrame.is_partial self#memo then + self#get self#memo method reset = self#disconnect ~lock:true method buffer_length_cmd = Frame.seconds_of_audio self#length diff --git a/src/core/sources/request_simple.ml b/src/core/sources/request_simple.ml index faa998989e..25fa94deeb 100644 --- a/src/core/sources/request_simple.ml +++ b/src/core/sources/request_simple.ml @@ -148,8 +148,8 @@ class dynamic ~retry_delay ~available (f : Lang.value) prefetch timeout = val mutable retry_status = None - method! is_ready = - match (super#is_ready, retry_status) with + method! _is_ready ?frame () = + match (super#_is_ready ?frame (), retry_status) with | true, _ -> true | false, Some d when Unix.gettimeofday () < d -> false | false, _ -> diff --git a/src/core/sources/request_source.ml b/src/core/sources/request_source.ml index 577507e1a7..4e168f821c 100644 --- a/src/core/sources/request_source.ml +++ b/src/core/sources/request_source.ml @@ -102,7 +102,7 @@ class once ~name ~timeout request = remaining <- 0; if forced then must_fail <- true else over <- true) - method is_ready = not over + method private _is_ready ?frame:_ _ = not over method private get_frame buf = if must_fail then ( @@ -222,7 +222,7 @@ class virtual unqueued ~name = (** Now we can write the source's methods. *) - method is_ready = + method private _is_ready ?frame:_ _ = Tutils.mutexify plock (fun () -> current <> None || must_fail || try self#begin_track with _ -> false) diff --git a/src/core/sources/request_source.mli b/src/core/sources/request_source.mli index ec3b02972b..db1c01b1c7 100644 --- a/src/core/sources/request_source.mli +++ b/src/core/sources/request_source.mli @@ -37,7 +37,7 @@ class once : inherit Source.source method stype : [ `Fallible | `Infallible ] method self_sync : Source.self_sync - method is_ready : bool + method private _is_ready : ?frame:Frame.t -> unit -> bool method request : Request.t method remaining : int method private get_frame : Frame.t -> unit @@ -56,7 +56,7 @@ class virtual unqueued : [ `Empty | `Request of Request.t | `Retry of unit -> float ] inherit Source.source - method is_ready : bool + method private _is_ready : ?frame:Frame.t -> unit -> bool method private get_frame : Frame.t -> unit method abort_track : unit method remaining : int diff --git a/src/core/sources/synthesized.ml b/src/core/sources/synthesized.ml index 430135626c..766f9988fb 100644 --- a/src/core/sources/synthesized.ml +++ b/src/core/sources/synthesized.ml @@ -30,7 +30,7 @@ class virtual source ?name ~seek duration = inherit Source.source ?name () method stype = if track_size = None then `Infallible else `Fallible val mutable remaining = track_size - method is_ready = remaining <> Some 0 + method private _is_ready ?frame:_ _ = remaining <> Some 0 method seek x = if seek then x else 0 method seek_source = (self :> Source.source) method self_sync = (`Static, false) diff --git a/src/core/synth/dssi_op.ml b/src/core/synth/dssi_op.ml index ae6d16de6c..417d907996 100644 --- a/src/core/synth/dssi_op.ml +++ b/src/core/synth/dssi_op.ml @@ -55,7 +55,7 @@ class dssi ?chan plugin descr outputs params source = method seek_source = source method stype = source#stype method remaining = source#remaining - method is_ready = source#is_ready + method private _is_ready = source#is_ready method self_sync = source#self_sync method abort_track = source#abort_track diff --git a/src/core/synth/keyboard.ml b/src/core/synth/keyboard.ml index 67340ea4d9..34c0d0d24a 100644 --- a/src/core/synth/keyboard.ml +++ b/src/core/synth/keyboard.ml @@ -58,13 +58,14 @@ class keyboard = inherit Source.no_seek method seek_source = (self :> Source.source) method stype = `Infallible - method is_ready = true + method private _is_ready ?frame:_ _ = true method remaining = -1 method abort_track = () method self_sync = (`Static, false) method output = - if self#is_ready && AFrame.is_partial self#memo then self#get self#memo + if self#is_ready ~frame:self#memo () && AFrame.is_partial self#memo then + self#get self#memo val mutable ev = MIDI.create (MFrame.size ()) val ev_m = Mutex.create () diff --git a/src/core/synth/keyboard_sdl.ml b/src/core/synth/keyboard_sdl.ml index 7735e60e9e..018fefeabd 100644 --- a/src/core/synth/keyboard_sdl.ml +++ b/src/core/synth/keyboard_sdl.ml @@ -89,13 +89,14 @@ class keyboard velocity = inherit Source.no_seek method seek_source = (self :> Source.source) method stype = `Infallible - method is_ready = true + method private _is_ready ?frame:_ _ = true method remaining = -1 method abort_track = () method self_sync = (`Static, false) method output = - if self#is_ready && AFrame.is_partial self#memo then self#get self#memo + if self#is_ready ~frame:self#memo () && AFrame.is_partial self#memo then + self#get self#memo val mutable window = None diff --git a/src/core/synth/synth_op.ml b/src/core/synth/synth_op.ml index dd903e22de..8c75e1c694 100644 --- a/src/core/synth/synth_op.ml +++ b/src/core/synth/synth_op.ml @@ -30,7 +30,7 @@ class synth (synth : Synth.synth) (source : source) chan volume = method stype = source#stype method self_sync = source#self_sync method remaining = source#remaining - method is_ready = source#is_ready + method private _is_ready = source#is_ready method abort_track = source#abort_track method seek = source#seek method seek_source = source diff --git a/src/core/tools/producer_consumer.ml b/src/core/tools/producer_consumer.ml index 2d61b4108a..b7958750ab 100644 --- a/src/core/tools/producer_consumer.ml +++ b/src/core/tools/producer_consumer.ml @@ -54,8 +54,8 @@ class consumer ?(always_enabled = false) ~write_frame ~name ~source () = method start = () method stop = write_frame producer_buffer `Flush - method! is_ready = - super#is_ready + method! _is_ready ?frame () = + super#_is_ready ?frame () && (Clock.get self#clock)#is_attached (self :> Source.active_source) method! output = if always_enabled || output_enabled then super#output @@ -99,7 +99,8 @@ class producer ?pos ?create_known_clock ~check_self_sync ~consumers ~name () = | -1, r -> r | r, _ -> r - method is_ready = List.for_all (fun c -> c#is_ready) consumers + method private _is_ready ?frame () = + List.for_all (fun c -> c#is_ready ?frame ()) consumers method! wake_up a = super#wake_up a; @@ -120,7 +121,8 @@ class producer ?pos ?create_known_clock ~check_self_sync ~consumers ~name () = let b = Frame.breaks buf in List.iter (fun c -> c#set_output_enabled true) consumers; while - Generator.length self#buffer < Lazy.force Frame.size && self#is_ready + Generator.length self#buffer < Lazy.force Frame.size + && self#is_ready ~frame:self#buffer () do self#child_tick done; diff --git a/src/core/tools/start_stop.ml b/src/core/tools/start_stop.ml index 7b673f01d8..86b7d4c0c2 100644 --- a/src/core/tools/start_stop.ml +++ b/src/core/tools/start_stop.ml @@ -78,7 +78,7 @@ class virtual active_source ?get_clock ~name ~clock_safe method stype = if fallible then `Fallible else `Infallible method! private wake_up _ = if autostart then base#transition_to `Started method! private sleep = base#transition_to `Stopped - method is_ready = state = `Started + method private _is_ready ?frame:_ _ = state = `Started val mutable clock = None method private get_clock = @@ -99,7 +99,8 @@ class virtual active_source ?get_clock ~name ~clock_safe method virtual private memo : Frame.t method private output = - if self#is_ready && AFrame.is_partial self#memo then self#get self#memo + if self#is_ready ~frame:self#memo () && AFrame.is_partial self#memo then + self#get self#memo end let base_proto ~label = diff --git a/src/core/visualization/midimeter.ml b/src/core/visualization/midimeter.ml index 877d2d8633..5aea29c149 100644 --- a/src/core/visualization/midimeter.ml +++ b/src/core/visualization/midimeter.ml @@ -27,7 +27,7 @@ class midimeter source = object inherit operator ~name:"midi.inspect" [source] method stype = source#stype - method is_ready = source#is_ready + method private _is_ready = source#is_ready method remaining = source#remaining method abort_track = source#abort_track method self_sync = source#self_sync diff --git a/src/core/visualization/video_volume.ml b/src/core/visualization/video_volume.ml index ba96713869..73e05cab1f 100644 --- a/src/core/visualization/video_volume.ml +++ b/src/core/visualization/video_volume.ml @@ -33,7 +33,7 @@ class visu source = object (self) inherit operator ~name:"video.volume" [source] as super method stype = source#stype - method is_ready = source#is_ready + method private _is_ready = source#is_ready method remaining = source#remaining method abort_track = source#abort_track method self_sync = source#self_sync diff --git a/src/core/visualization/vis_volume.ml b/src/core/visualization/vis_volume.ml index bc9169bffa..de3ef72bf9 100644 --- a/src/core/visualization/vis_volume.ml +++ b/src/core/visualization/vis_volume.ml @@ -33,7 +33,7 @@ class vumeter ~kind source = inherit operator ~name:"visu.volume" kind [source] as super inherit no_seek method stype = source#stype - method is_ready = source#is_ready + method private _is_ready = source#is_ready method remaining = source#remaining method abort_track = source#abort_track method self_sync = source#self_sync diff --git a/tests/core/output_test.ml b/tests/core/output_test.ml index b5a41ddd38..bca49d1bab 100644 --- a/tests/core/output_test.ml +++ b/tests/core/output_test.ml @@ -9,7 +9,7 @@ class dummy ~autostart ~on_start source = method test_wake_up = self#wake_up [] val mutable test_is_ready = false method test_set_is_ready = test_is_ready <- true - method! is_ready = test_is_ready + method! is_ready ?frame:_ _ = test_is_ready method test_output = self#output end @@ -31,12 +31,12 @@ let () = let o = new dummy ~on_start ~autostart:true failed in let clock = Clock.clock ~start:false "source" in Clock.unify ~pos:o#pos o#clock (Clock.create_known clock); - assert (not o#is_ready); + assert (not (o#is_ready ())); o#content_type_computation_allowed; o#test_wake_up; assert (not !started); o#test_set_is_ready; - assert o#is_ready; + assert (o#is_ready ()); o#test_output; assert !started; ()