Hi all !

One feature I'm really missing in liquidsoap now is the possibility to execute 
a command when input.harbor is connected and disconnected to a source.

You may for instance think of starting a stream dump for means of archive, or 
relay or ...

I've implemented it, I think it's quite simple but I'd like to have your 
opinion on it. If you are ok, I'd like to commit such a change for next 
release.


Also, I've noticed a bug metadata propagation bug with strip_blankon which 
I'll be working ASAP..



Romain
Index: sources/harbor_input.ml
===================================================================
--- sources/harbor_input.ml	(révision 4564)
+++ sources/harbor_input.ml	(copie de travail)
@@ -28,7 +28,7 @@
 
 exception Internal
 
-class http_input_server ~bufferize ~max =
+class http_input_server ~bufferize ~max ~on_connect ~on_disconnect =
 let playlist_mode = Http_source.Normal in
 let autostart = false in
 let url  = "" in
@@ -38,6 +38,9 @@
   val mutable socket = None
   val mutable content_type = ""
 
+  method exec f = 
+    ignore(Lang.apply f [])
+
   (* Called when we get a client *)
   method set_socket c s =
     socket <- Some s ;
@@ -60,9 +63,9 @@
         in
           self#log#f 3 "Decoding..." ;
           self#feeding dec s false None ;
-          relaying <- false
+	  self#disconnect
     with
-      | Not_found -> relaying <- false
+      | Not_found -> self#disconnect
 
   (* Take care of (re)starting the decoding *)
   method poll =
@@ -82,9 +85,15 @@
     ignore (Tutils.create (fun () -> self#poll) () "harbor polling") ;
 
   method relay = 
+    self#exec on_connect ;
     (* This one is for Http_source.http *and* for me *)
     relaying <- true 
 
+  method disconnect = 
+    if relaying then
+      self#exec on_disconnect ;
+    relaying <- false
+
   method is_taken = relaying
 
 end
@@ -98,6 +107,10 @@
          Some "Duration of the pre-buffered data." ;
         "max", Lang.float_t, Some (Lang.float 10.),
         Some "Maximum duration of the buffered data.";
+        "on_connect", Lang.fun_t [] Lang.unit_t,  Some (Lang.val_fun [] Lang.unit),
+        Some "Functions to excecute when a source is connected";
+        "on_disconnect",Lang.fun_t [] Lang.unit_t, Some (Lang.val_fun [] Lang.unit),
+        Some "Functions to excecute when a source is disconnected";
         "", Lang.string_t, None,
         Some "Mountpoint to look for." ]
       (fun p ->
@@ -109,12 +122,14 @@
          in
          let bufferize = Lang.to_float (List.assoc "buffer" p) in
          let max = Lang.to_float (List.assoc "max" p) in
+	 let on_connect = List.assoc "on_connect" p in
+	 let on_disconnect = List.assoc "on_disconnect" p in
            try
              ((Harbor.find_source mount):>Source.source)
            with
              | Not_found ->
                (
-                 Harbor.add_source mount ((new http_input_server ~bufferize ~max):>Harbor.source) ;
+                 Harbor.add_source mount ((new http_input_server ~bufferize ~max ~on_connect ~on_disconnect):>Harbor.source) ;
                  ((Harbor.find_source mount):>Source.source)
                )
       )

Répondre à