Skip to content

Commit

Permalink
Fix mutual recursion between autocue and replaygain metadata resolver…
Browse files Browse the repository at this point in the history
…s. (#4246)
  • Loading branch information
toots authored Dec 8, 2024
1 parent 7d777ed commit 6e83321
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 5 deletions.
4 changes: 3 additions & 1 deletion CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@ Changed:
is also passed. Add a configuration key to disable this mechanism.
(#4235, #2676)

Changed:
Fixed:

- Fixed request resolution loop when enabling both `autcue`
and `replaygain` metadata resolvers (#4245, fixed in #4246)
- Convert all ICY (icecast) metadata from `input.http` to `utf8`.

---
Expand Down
16 changes: 16 additions & 0 deletions src/core/builtins/builtins_resolvers.ml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@
*****************************************************************************)

let decoder_metadata = Lang.add_module ~base:Modules.decoder "metadata"
let reentrant_decoders = ref []

let _ =
Lang.add_builtin ~base:decoder_metadata "reentrant" ~category:`Liquidsoap
~descr:"Return the list of reentrant decoders." []
(Lang.list_t Lang.string_t) (fun _ ->
Lang.list (List.map Lang.string !reentrant_decoders))

let _ =
let resolver_t =
Expand All @@ -47,6 +54,13 @@ let _ =
Some
"Decode files that have the file extensions in this list. Accept any \
file if `null`." );
( "reentrant",
Lang.bool_t,
Some (Lang.bool false),
Some
"Set to `true` to indicate that the decoder needs to resolve a \
request. Such decoders need to be mutually exclusive to avoid \
request resolution loops!" );
("", Lang.string_t, None, Some "Format/resolver's name.");
( "",
resolver_t,
Expand All @@ -70,6 +84,7 @@ let _ =
(List.assoc "file_extensions" p)
in
let log = Log.make ["decoder"; "metadata"] in
let reentrant = Lang.to_bool (List.assoc "reentrant" p) in
let priority = Lang.to_int_getter (List.assoc "priority" p) in
let resolver ~metadata ~extension ~mime fname =
if
Expand All @@ -88,6 +103,7 @@ let _ =
in
Plug.register Request.mresolvers format ~doc:""
{ Request.priority; resolver };
if reentrant then reentrant_decoders := format :: !reentrant_decoders;
Lang.unit)

let add_playlist_parser ~format name (parser : Playlist_parser.parser) =
Expand Down
8 changes: 6 additions & 2 deletions src/libs/autocue.liq
Original file line number Diff line number Diff line change
Expand Up @@ -775,7 +775,7 @@ def autocue.internal.implementation(
fade_out_type?: string,
fade_out_curve?: float,
start_next?: float,
extra_metadata?: [(string * string)]
extra_metadata?: [(string*string)]
}
)
end
Expand Down Expand Up @@ -823,7 +823,10 @@ def file.autocue.metadata(~request_metadata, uri) =
)
end

r = request.create(excluded_metadata_resolvers=["autocue"], uri)
r =
request.create(
excluded_metadata_resolvers=decoder.metadata.reentrant(), uri
)

if
not request.resolve(r)
Expand Down Expand Up @@ -1059,6 +1062,7 @@ def enable_autocue_metadata() =
mime_types=mime_types,
file_extensions=file_extensions,
priority=settings.autocue.metadata.priority,
reentrant=true,
"autocue",
autocue_metadata
)
Expand Down
6 changes: 4 additions & 2 deletions src/libs/replaygain.liq
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def replaces file.replaygain(~id=null(), ~compute=true, ~ratio=50., file_name) =
id = string.id.default(default="file.replaygain", id)
file_name_quoted = string.quote(file_name)

_metadata = file.metadata(exclude=["replaygain_track_gain"], file_name)
_metadata = file.metadata(exclude=decoder.metadata.reentrant(), file_name)
gain = metadata.replaygain(_metadata)

if
Expand Down Expand Up @@ -138,5 +138,7 @@ def enable_replaygain_metadata(~compute=true, ~ratio=50.) =
end
end

decoder.metadata.add("replaygain_track_gain", replaygain_metadata)
decoder.metadata.add(
reentrant=true, "replaygain_track_gain", replaygain_metadata
)
end
6 changes: 6 additions & 0 deletions tests/regression/GH4246.liq
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
enable_replaygain_metadata()
enable_autocue_metadata()

audio = once(single("../media/@shine[channels=2].mp3"))

output.dummy(fallible=true, on_start=test.pass, audio)
16 changes: 16 additions & 0 deletions tests/regression/dune.inc
Original file line number Diff line number Diff line change
Expand Up @@ -767,6 +767,22 @@
(:run_test ../run_test.exe))
(action (run %{run_test} GH4163.liq liquidsoap %{test_liq} GH4163.liq)))

(rule
(alias citest)
(package liquidsoap)
(deps
GH4246.liq
../media/all_media_files
../../src/bin/liquidsoap.exe
../streams/file1.png
../streams/file1.mp3
./theora-test.mp4
(package liquidsoap)
(source_tree ../../src/libs)
(:test_liq ../test.liq)
(:run_test ../run_test.exe))
(action (run %{run_test} GH4246.liq liquidsoap %{test_liq} GH4246.liq)))

(rule
(alias citest)
(package liquidsoap)
Expand Down

0 comments on commit 6e83321

Please sign in to comment.