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

Merge all request sources to a single core request.dynamic. #3547

Merged
merged 1 commit into from
Nov 29, 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
7 changes: 7 additions & 0 deletions src/core/builtins/builtins_request.ml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,13 @@

let request = Modules.request

let _ =
Lang.add_builtin ~base:request "is_static" ~category:`Liquidsoap
~descr:"`true` if the given URI is assumed to be static, e.g. a file."
[("", Lang.string_t, None, None)]
Lang.bool_t
(fun p -> Lang.bool (Request.is_static (Lang.to_string (List.assoc "" p))))

let _ =
Lang.add_builtin ~base:request "create" ~category:`Liquidsoap
~descr:"Create a request from an URI."
Expand Down
3 changes: 1 addition & 2 deletions src/core/dune
Original file line number Diff line number Diff line change
Expand Up @@ -207,8 +207,7 @@
raw_audio_decoder
replaygain_op
request
request_simple
request_source
request_dynamic
resample
rms_smooth
rqueue
Expand Down
61 changes: 46 additions & 15 deletions src/core/lang_source.ml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,10 @@ module Source_val = Liquidsoap_lang.Lang_core.MkAbstract (struct
type content = Source.source

let name = "source"
let descr s = Printf.sprintf "<source#%s>" s#id

let descr s =
Printf.sprintf "<source(id=%s, frame_type=%s>" s#id
(Type.to_string s#frame_type)

let to_json ~pos _ =
Runtime_error.raise ~pos
Expand Down Expand Up @@ -408,19 +411,47 @@ let check_content v t =
let _meth = meth

let check_arguments ~env ~return_t arguments =
let return_t, arguments =
let handler = Type.Fresh.init () in
let return_t = Type.Fresh.make handler return_t in
let arguments =
List.map
(fun (lbl, t, _, _) -> (lbl, Type.Fresh.make handler t))
arguments
in
let arguments =
List.stable_sort (fun (l, _) (l', _) -> Stdlib.compare l l') arguments
let handler = Type.Fresh.init () in
let return_t = Type.Fresh.make handler return_t in
let arguments =
List.map (fun (lbl, t, _, _) -> (lbl, Type.Fresh.make handler t)) arguments
in
let arguments =
List.stable_sort (fun (l, _) (l', _) -> Stdlib.compare l l') arguments
in
(* Generalize all terms inside the arguments *)
let map =
let open Liquidsoap_lang.Value in
let rec map { pos; value; methods } =
let value =
match value with
| Ground g -> Ground g
| List l -> List (List.map map l)
| Tuple l -> Tuple (List.map map l)
| Null -> Null
| Fun (args, lazy_env, ret) ->
Fun
( List.map (fun (l, l', v) -> (l, l', Option.map map v)) args,
lazy_env,
Term.fresh ~handler ret )
| FFI ffi ->
FFI
{
ffi_args =
List.map
(fun (l, l', v) -> (l, l', Option.map map v))
ffi.ffi_args;
ffi_fn =
(fun env ->
let v = ffi.ffi_fn env in
map v);
}
in
{ pos; value; methods = Liquidsoap_lang.Methods.map map methods }
in
(return_t, arguments)
map
in
let env = List.map (fun (lbl, v) -> (lbl, map v)) env in
(* Negotiate content for all sources and formats in the arguments. *)
let () =
let env =
Expand All @@ -436,7 +467,7 @@ let check_arguments ~env ~return_t arguments =
check_content v typ)
arguments env
in
return_t
(return_t, env)

let add_operator ~(category : Doc.Value.source) ~descr ?(flags = [])
?(meth = ([] : 'a operator_method list)) ?base name arguments ~return_t f =
Expand All @@ -460,7 +491,7 @@ let add_operator ~(category : Doc.Value.source) ~descr ?(flags = [])
| [] -> None
| p :: _ -> Some p
in
let return_t = check_arguments ~return_t ~env arguments in
let return_t, env = check_arguments ~return_t ~env arguments in
let src : < Source.source ; .. > = f env in
src#set_pos pos;
Typing.(src#frame_type <: return_t);
Expand Down Expand Up @@ -500,7 +531,7 @@ let add_track_operator ~(category : Doc.Value.source) ~descr ?(flags = [])
| [] -> None
| p :: _ -> Some p
in
let return_t = check_arguments ~return_t ~env arguments in
let return_t, env = check_arguments ~return_t ~env arguments in
let field, (src : < Source.source ; .. >) = f env in
src#set_pos pos;
(if field <> Frame.Fields.track_marks && field <> Frame.Fields.metadata then
Expand Down
18 changes: 15 additions & 3 deletions src/core/operators/dyn_op.ml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

*****************************************************************************)

class dyn ~init ~track_sensitive ~infallible ~resurection_time f =
class dyn ~init ~track_sensitive ~infallible ~resurection_time ~self_sync f =
object (self)
inherit Source.source ~name:"source.dynamic" ()
method stype = if infallible then `Infallible else `Fallible
Expand Down Expand Up @@ -112,7 +112,11 @@ class dyn ~init ~track_sensitive ~infallible ~resurection_time f =
| None -> (self :> Source.source)

method self_sync =
(`Dynamic, match source with Some s -> snd s#self_sync | None -> false)
match self_sync with
| Some v -> (`Static, v)
| None -> (
( `Dynamic,
match source with Some s -> snd s#self_sync | None -> false ))
end

let _ =
Expand All @@ -133,6 +137,10 @@ let _ =
Some
"Whether the source is infallible or not (be careful when setting \
this, it will not be checked by the typing system)." );
( "self_sync",
Lang.nullable_t Lang.bool_t,
Some Lang.null,
Some "For the source's `self_sync` property." );
( "resurection_time",
Lang.nullable_t Lang.float_t,
Some (Lang.float 1.),
Expand Down Expand Up @@ -174,5 +182,9 @@ let _ =
let resurection_time =
List.assoc "resurection_time" p |> Lang.to_valued_option Lang.to_float
in
let self_sync =
Lang.to_valued_option Lang.to_bool (List.assoc "self_sync" p)
in
let next = List.assoc "" p in
new dyn
~init ~track_sensitive ~infallible ~resurection_time (List.assoc "" p))
~init ~track_sensitive ~infallible ~resurection_time ~self_sync next)
4 changes: 3 additions & 1 deletion src/core/operators/muxer.ml
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,9 @@ let _ =
let arguments = [("", Lang.source_t ~methods:false frame_t, None, None)] in
Lang.add_builtin ~base:source "tracks" ~category:(`Source `Track)
~descr:"Return the tracks of a given source." arguments return_t (fun env ->
let return_t = Lang_source.check_arguments ~return_t ~env arguments in
let return_t, env =
Lang_source.check_arguments ~return_t ~env arguments
in
let return_t =
Type.filter_meths return_t (fun { Type.meth } ->
meth <> "metadata" && meth <> "track_marks")
Expand Down
Loading
Loading