Skip to content
This repository
Browse code

Done more administrative stuff.

  • Loading branch information...
commit 8e31d8abf20b206ce1349ebc528d104ae5d3b92c 1 parent 3daa94b
Romain Beauxis authored November 09, 2012
37  src/encoder/encoder.ml
@@ -425,12 +425,36 @@ end
425 425
 module GStreamer =
426 426
 struct
427 427
   type t = {
428  
-    (* TODO: ... *)
429  
-    dummy : unit;
  428
+    channels       : int;
  429
+    audio_pipeline : string option;
  430
+    video_pipeline : string option
430 431
   }
431 432
 
432  
-  (* TODO *)
433  
-  let to_string m = "%%gstreamer"
  433
+  let audio_channels m =
  434
+    if m.audio_pipeline = None then
  435
+      0
  436
+    else
  437
+      m.channels
  438
+
  439
+  let video_channels m =
  440
+    if m.video_pipeline = None then
  441
+      0
  442
+    else
  443
+      1
  444
+
  445
+  let to_string m =
  446
+    let pipeline l name value = 
  447
+      Stdlib.some_or l
  448
+        (Stdlib.maybe
  449
+          (fun value -> (Printf.sprintf "%s=%S" name value)::l)
  450
+            value)
  451
+    in
  452
+    Printf.sprintf "%%gstreamer(%s)"
  453
+      (String.concat ","
  454
+        (pipeline
  455
+         (pipeline [Printf.sprintf "channels=%d" m.channels] 
  456
+           "audio_pipeline" m.audio_pipeline)
  457
+           "video_pipeline" m.video_pipeline))
434 458
 end
435 459
 
436 460
 module Theora =
@@ -589,8 +613,9 @@ let kind_of_format = function
589 613
       { Frame.audio = e.External.channels ;
590 614
         Frame.video = 0 ; Frame.midi = 0 }
591 615
   | GStreamer e ->
592  
-    (* TODO: fill this! *)
593  
-    { Frame.audio = 2; Frame.video = 1; Frame.midi = 0 }
  616
+    { Frame.audio = GStreamer.audio_channels e;
  617
+      Frame.video = GStreamer.video_channels e;
  618
+      Frame.midi = 0 }
594 619
 
595 620
 let kind_of_format f =
596 621
   let k = kind_of_format f in
28  src/encoder/gstreamer_encoder.ml
@@ -37,8 +37,7 @@ type gst =
37 37
 
38 38
 let encoder id ext =
39 39
   GU.init ();
40  
-  let channels = 2 in
41  
-
  40
+  let channels = ext.channels in
42 41
   let mutex = Mutex.create () in
43 42
   let samples = ref 0 in
44 43
   let decr_samples =
@@ -58,19 +57,23 @@ let encoder id ext =
58 57
 
59 58
   let gst =
60 59
     let audio_pipeline =
61  
-      Printf.sprintf "%s ! queue ! %s ! lamemp3enc ! muxer."
62  
-        (GU.Pipeline.audio_src ~channels ~block:false "audio_src")
63  
-        (GU.Pipeline.convert_audio ())
  60
+      Stdlib.maybe (fun pipeline ->
  61
+        Printf.sprintf "%s ! queue ! %s ! %s ! muxer."
  62
+          (GU.Pipeline.audio_src ~channels ~block:false "audio_src")
  63
+          (GU.Pipeline.convert_audio ())
  64
+          pipeline) ext.audio_pipeline
64 65
     in
65 66
     let video_pipeline =
66  
-      Printf.sprintf "%s ! queue ! %s ! x264enc ! muxer."
67  
-        (GU.Pipeline.video_src ~block:true "video_src")
68  
-        (GU.Pipeline.convert_video ())
  67
+      Stdlib.maybe (fun pipeline ->
  68
+        Printf.sprintf "%s ! queue ! %s ! %s ! muxer."
  69
+          (GU.Pipeline.video_src ~block:true "video_src")
  70
+          (GU.Pipeline.convert_video ())
  71
+          pipeline) ext.video_pipeline
69 72
     in
70 73
     let pipeline =
71 74
       Printf.sprintf "%s %s avimux name=muxer ! appsink name=sink sync=false emit-signals=true"
72  
-        audio_pipeline
73  
-        video_pipeline
  75
+        (Stdlib.some_or "" audio_pipeline)
  76
+        (Stdlib.some_or "" video_pipeline)
74 77
     in
75 78
     Printf.printf "pipeline: %s\n%!" pipeline;
76 79
     let bin = Gstreamer.Pipeline.parse_launch pipeline in
@@ -88,14 +91,13 @@ let encoder id ext =
88 91
 
89 92
   let stop gst () =
90 93
     let ans = ref "" in
91  
-    (* TODO: send EOS on both appsrc *)
92  
-    ignore (Gstreamer.Element.set_state gst.bin Gstreamer.Element.State_paused);
  94
+    ignore (Gstreamer.Element.set_state gst.bin Gstreamer.Element.State_null);
  95
+    ignore (Gstreamer.Element.get_state gst.bin);
93 96
     while !samples > 0 do
94 97
       let b = Gstreamer.App_sink.pull_buffer_string gst.sink in
95 98
       decr_samples ();
96 99
       ans := !ans ^ b
97 100
     done;
98  
-    ignore (Gstreamer.Element.set_state gst.bin Gstreamer.Element.State_null);
99 101
     !ans
100 102
   in
101 103
 
24  src/lang/lang_encoders.ml
@@ -799,7 +799,27 @@ let mk_speex params =
799 799
 let mk_gstreamer params =
800 800
   let defaults =
801 801
     { Encoder.GStreamer.
802  
-      dummy = ();
  802
+       channels = 2;
  803
+       audio_pipeline = Some "lamemp3enc";
  804
+       video_pipeline = Some "x264enc"
803 805
     }
804 806
   in
805  
-   mk (Encoder (Encoder.GStreamer defaults))
  807
+  let gstreamer =
  808
+    let perhaps = function
  809
+      | "" -> None
  810
+      | s  -> Some s
  811
+    in
  812
+    List.fold_left
  813
+      (fun f ->
  814
+        function
  815
+          | ("channels",{ term = Int i }) ->
  816
+              { f with Encoder.GStreamer.channels = i }
  817
+          | ("audio_pipeline",{ term = String s }) ->
  818
+              { f with Encoder.GStreamer.audio_pipeline = perhaps s }
  819
+          | ("video_pipeline",{ term = String s }) ->
  820
+              { f with Encoder.GStreamer.video_pipeline = perhaps s }
  821
+          | (_,t) -> raise (generic_error t))
  822
+      defaults params
  823
+  in
  824
+    mk (Encoder (Encoder.GStreamer gstreamer))
  825
+
6  src/outputs/icecast2.ml
@@ -100,6 +100,12 @@ struct
100 100
               samplerate = Some m.Encoder.External.samplerate ;
101 101
               channels = Some m.Encoder.External.channels
102 102
             }
  103
+        | Encoder.GStreamer m ->
  104
+            { quality    = None ;
  105
+              bitrate    = None ;
  106
+              samplerate = None ;
  107
+              channels   = Some (Encoder.GStreamer.audio_channels m)
  108
+            }
103 109
         | Encoder.Flac m ->
104 110
             { quality = Some (string_of_int m.Encoder.Flac.compression) ;
105 111
               bitrate = None ;
2  src/outputs/pipe_output.ml
@@ -147,7 +147,7 @@ object (self)
147 147
          (Unix.gettimeofday () > reload_delay +. open_date &&
148 148
           (Lang.to_bool (Lang.apply ~t:Lang.bool_t reload_predicate []))) then
149 149
           begin
150  
-            self#log#f 3 "Re-opening output file..." ;
  150
+            self#log#f 3 "Re-opening output pipe..." ;
151 151
             (* #output_stop can trigger #send,
152 152
              * the [reopening] flag avoids loops *)
153 153
             reopening <- true ;
1  src/tools/icecast_utils.ml
@@ -89,6 +89,7 @@ struct
89 89
       | Encoder.AACPlus _ -> Some aac
90 90
       | Encoder.VoAacEnc _ -> Some aac
91 91
       | Encoder.External _ -> None
  92
+      | Encoder.GStreamer _ -> None
92 93
       | Encoder.Flac _ -> Some flac
93 94
       | Encoder.WAV _ -> Some wav
94 95
       | Encoder.Ogg _ -> Some ogg

0 notes on commit 8e31d8a

Please sign in to comment.
Something went wrong with that request. Please try again.