Skip to content

Commit

Permalink
Fix shoutcast v2 metadata update when sid <> 1. Fixes #320.
Browse files Browse the repository at this point in the history
  • Loading branch information
toots committed Apr 16, 2016
1 parent 01a5bf4 commit 9197f6f
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 20 deletions.
7 changes: 7 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
1.2.1 ()
========

Bugfixes:

- Fix metadata update for shoutcast v2 when sid <> 1 (#320).

1.2.0 (12-01-2016)
==================

Expand Down
2 changes: 1 addition & 1 deletion configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ fi
# Cry
#

AC_CHECK_OCAML_BINDING([cry],[0.3.0])
AC_CHECK_OCAML_BINDING([cry],[0.4.0])

# ocaml-mm
#
Expand Down
11 changes: 10 additions & 1 deletion src/lang/builtins_cry.ml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,10 @@ let () =
"port", Lang.int_t, Some (Lang.int 8000), None;
"user", Lang.string_t, Some (Lang.string "source"), None;
"password", Lang.string_t, Some (Lang.string "hackme"), None;
"mount", Lang.string_t, None , None;
"mount", Lang.string_t, Some (Lang.string ""),
Some "Source mount point. Mandatory when streaming to icecast.";
"icy_id", Lang.int_t, Some (Lang.int 1),
Some "Shoutcast source ID. Only supported by Shoutcast v2.";
"protocol", Lang.string_t, Some (Lang.string "http"),
Some "Protocol to use. One of: \"icy\" or \"http\"";
"encoding", Lang.string_t, Some (Lang.string ""),
Expand All @@ -49,6 +52,7 @@ let () =
let user = Lang.to_string (List.assoc "user" p) in
let password = Lang.to_string (List.assoc "password" p) in
let mount = Lang.to_string (List.assoc "mount" p) in
let icy_id = Lang.to_int (List.assoc "icy_id" p) in
let metas = Lang.to_metadata (Lang.assoc "" 1 p) in
let out_enc =
match Lang.to_string (List.assoc "encoding" p) with
Expand Down Expand Up @@ -86,6 +90,11 @@ let () =
raise (Lang.Invalid_value (v, "protocol should be one of: \
'icy' or 'http'."))
in
let mount =
match protocol with
| Cry.Icy -> Cry.Icy_id icy_id
| _ -> Cry.Icecast_mount mount
in
begin
try
Cry.manual_update_metadata
Expand Down
32 changes: 14 additions & 18 deletions src/outputs/icecast2.ml
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ module M = Icecast_utils.Icecast_v(Icecast)

open M

let no_mount = "Use [name] with .ogg extension if relevant"
let no_mount = "Use [name]"
let no_name = "Use [mount]"

let user_agent = Lang.product (Lang.string "User-Agent")
Expand Down Expand Up @@ -294,14 +294,6 @@ class output ~kind p =
please specify either 'true' or 'false'."))
in

let ogg =
match data.format with
| x when x = Cry.ogg_application -> true
| x when x = Cry.ogg_audio -> true
| x when x = Cry.ogg_video -> true
| _ -> false
in

let out_enc =
match Lang.to_string (List.assoc "encoding" p) with
| "" ->
Expand All @@ -319,22 +311,26 @@ class output ~kind p =
in

let mount = s "mount" in

let name = s "name" in
let name =
let display_mount, name =
match protocol, name, mount with
| Cry.Http _, name, mount when name = no_name && mount = no_mount ->
raise (Lang.Invalid_value
(List.assoc "mount" p,
"Either name or mount must be defined for icecast sources."))
| Cry.Icy, name, _ when name = no_name -> Printf.sprintf "sc#%i" icy_id
| _, name, mount when name = no_name -> mount
| _ -> name
| Cry.Icy, name, _ when name = no_name ->
let name = Printf.sprintf "sc#%i" icy_id in
name, name
| _, name, mount when name = no_name -> mount, mount
| _ -> mount, name
in

let mount =
if mount = no_mount then
if ogg then name ^ ".ogg" else name
Cry.Icy_id icy_id
else
mount
Cry.Icecast_mount mount
in

let autostart = Lang.to_bool (List.assoc "start" p) in
Expand Down Expand Up @@ -388,7 +384,7 @@ object (self)
inherit Output.encoded
~content_kind:kind ~output_kind:"output.icecast"
~infallible ~autostart ~on_start ~on_stop
~name:mount source
~name:display_mount source

(** In this operator, we don't exactly follow the start/stop
* mechanism of Output.encoded because we want to control
Expand Down Expand Up @@ -531,7 +527,7 @@ object (self)
| Some f -> dump <- Some (open_out_bin f)
| None -> ()
end ;
self#log#f 3 "Connecting mount %s for %s@%s..." mount user host ;
self#log#f 3 "Connecting mount %s for %s@%s..." display_mount user host ;
let audio_info = Hashtbl.create 10 in
let f x y z =
match x with
Expand All @@ -551,7 +547,7 @@ object (self)
let source =
Cry.connection ~host ~port ~user ~password
~genre ~url ~description ~name
~public ~protocol ~mount ~icy_id ~chunked
~public ~protocol ~mount ~chunked
~audio_info ~user_agent ~content_type:data.format ()
in
List.iter (fun (x,y) ->
Expand Down

0 comments on commit 9197f6f

Please sign in to comment.