Permalink
Browse files

NEVER TRUST YOUR COMPILER! :-)

  • Loading branch information...
1 parent a26c1fe commit ef50490dff4cb5d9f92f8a59f032b958965adeca @toots toots committed Nov 24, 2012
@@ -149,7 +149,7 @@ module Make (Generator : Generator.S_Asio) = struct
let _, state, _ = Gstreamer.Element.get_state gst.bin in
if state <> Gstreamer.Element.State_playing then
failwith "Not in playing state!";
- let b = Gstreamer.App_sink.pull_buffer_string (get_some gst.audio_sink) in
+ let b = Gstreamer.App_sink.pull_buffer_string (Utils.get_some gst.audio_sink) in
let len = String.length b / (2*channels) in
let buf = Audio.create channels len in
Audio.S16LE.to_audio b 0 buf 0 len;
@@ -160,7 +160,7 @@ module Make (Generator : Generator.S_Asio) = struct
let _, state, _ = Gstreamer.Element.get_state gst.bin in
if state <> Gstreamer.Element.State_playing then
failwith "Not in playing state!";
- let b = Gstreamer.App_sink.pull_buffer_data (get_some gst.video_sink) in
+ let b = Gstreamer.App_sink.pull_buffer_data (Utils.get_some gst.video_sink) in
let img = Img.make width height b in
let stream = [|img|] in
Generator.put_video buffer [|stream|] 0 (Array.length stream)
View
@@ -445,8 +445,8 @@ struct
let to_string m =
let pipeline l name value =
- Stdlib.some_or l
- (Stdlib.maybe
+ Utils.some_or l
+ (Utils.maybe
(fun value -> (Printf.sprintf "%s=%S" name value)::l)
value)
in
@@ -30,8 +30,8 @@ module Img = Image.RGBA32
type gst =
{
bin : Gstreamer.Pipeline.t;
- audio_src : Gstreamer.App_src.t;
- video_src : Gstreamer.App_src.t;
+ audio_src : Gstreamer.App_src.t option;
+ video_src : Gstreamer.App_src.t option;
sink : Gstreamer.App_sink.t;
}
@@ -55,39 +55,50 @@ let encoder id ext =
in
let gst =
- let muxer = if ext.muxer <> None then "! muxer." else "" in
+ let muxer =
+ if ext.audio <> None && ext.video <> None then
+ "muxer."
+ else
+ ""
+ in
let audio_pipeline =
- Stdlib.maybe (fun pipeline ->
- Printf.sprintf "%s ! queue ! %s ! %s %s"
+ Utils.maybe (fun pipeline ->
+ Printf.sprintf "%s ! queue ! %s ! %s ! %s"
(GU.Pipeline.audio_src ~channels ~block:true "audio_src")
(GU.Pipeline.convert_audio ())
pipeline
muxer) ext.audio
in
let video_pipeline =
- Stdlib.maybe (fun pipeline ->
- Printf.sprintf "%s ! queue ! %s ! %s %s"
+ Utils.maybe (fun pipeline ->
+ Printf.sprintf "%s ! queue ! %s ! %s ! %s"
(GU.Pipeline.video_src ~block:true "video_src")
(GU.Pipeline.convert_video ())
pipeline
muxer) ext.video
in
let muxer_pipeline = match ext.muxer with
- | Some muxer -> Printf.sprintf "%s name=muxer" muxer
+ | Some muxer -> Printf.sprintf "%s name=muxer !" muxer
| None -> ""
in
let pipeline =
- Printf.sprintf "%s %s %s ! appsink name=sink sync=false emit-signals=true"
- (Stdlib.some_or "" audio_pipeline)
- (Stdlib.some_or "" video_pipeline)
+ Printf.sprintf "%s %s %s appsink name=sink sync=false emit-signals=true"
+ (Utils.some_or "" audio_pipeline)
+ (Utils.some_or "" video_pipeline)
muxer_pipeline
in
let bin = Gstreamer.Pipeline.parse_launch pipeline in
let audio_src =
- Gstreamer.App_src.of_element (Gstreamer.Bin.get_by_name bin "audio_src")
+ Utils.maybe (fun _ ->
+ Gstreamer.App_src.of_element
+ (Gstreamer.Bin.get_by_name bin "audio_src"))
+ audio_pipeline
in
let video_src =
- Gstreamer.App_src.of_element (Gstreamer.Bin.get_by_name bin "video_src")
+ Utils.maybe (fun _ ->
+ Gstreamer.App_src.of_element
+ (Gstreamer.Bin.get_by_name bin "video_src"))
+ video_pipeline
in
let sink = Gstreamer.App_sink.of_element (Gstreamer.Bin.get_by_name bin "sink") in
Gstreamer.App_sink.on_new_sample sink on_sample;
@@ -118,7 +129,15 @@ let encoder id ext =
let encode h frame start len =
let nanolen = Int64.of_float (Frame.seconds_of_master len *. nano) in
- let content = Frame.content_of_type frame start { Frame.audio = channels; video = 1; midi = 0 } in
+ let videochans = if gst.video_src <> None then 1 else 0 in
+ let content =
+ Frame.content_of_type frame start
+ {Frame.
+ audio = channels;
+ video = videochans;
+ midi = 0
+ }
+ in
if channels > 0 then
begin
(* Put audio. *)
@@ -130,15 +149,15 @@ let encoder id ext =
let gstbuf = Gstreamer.Buffer.of_string data 0 (String.length data) in
Gstreamer.Buffer.set_presentation_time gstbuf !now;
Gstreamer.Buffer.set_duration gstbuf nanolen;
- Gstreamer.App_src.push_buffer gst.audio_src gstbuf;
+ Gstreamer.App_src.push_buffer (Utils.get_some gst.audio_src) gstbuf;
end;
- (* Put video. *)
- let vbuf = content.Frame.video in
- let vbuf = vbuf.(0) in
- let vstart = Frame.video_of_master start in
- let vlen = Frame.video_of_master len in
- if vlen > 0 then
+ if videochans > 0 then
begin
+ (* Put video. *)
+ let vbuf = content.Frame.video in
+ let vbuf = vbuf.(0) in
+ let vstart = Frame.video_of_master start in
+ let vlen = Frame.video_of_master len in
for i = vstart to vstart+vlen-1 do
let data = Img.data vbuf.(i) in
let gstbuf = Gstreamer.Buffer.of_data data 0 (Bigarray.Array1.dim data) in
@@ -147,7 +166,7 @@ let encoder id ext =
in
Gstreamer.Buffer.set_presentation_time gstbuf ptime;
Gstreamer.Buffer.set_duration gstbuf vduration;
- Gstreamer.App_src.push_buffer gst.video_src gstbuf;
+ Gstreamer.App_src.push_buffer (Utils.get_some gst.video_src) gstbuf;
done;
end;
(* Return result. *)
View
@@ -67,9 +67,9 @@ object (self)
method output_stop =
let bin,audio_src,video_src = self#get_gst in
if has_audio then
- App_src.end_of_stream (get_some audio_src);
+ App_src.end_of_stream (Utils.get_some audio_src);
if has_video then
- App_src.end_of_stream (get_some video_src);
+ App_src.end_of_stream (Utils.get_some video_src);
ignore (Element.set_state bin Element.State_null);
if clock_safe then (gst_clock ())#unregister_blocking_source
@@ -135,7 +135,7 @@ object (self)
let gstbuf = Gstreamer.Buffer.of_string data 0 (String.length data) in
Gstreamer.Buffer.set_presentation_time gstbuf now;
Gstreamer.Buffer.set_duration gstbuf nanolen;
- Gstreamer.App_src.push_buffer (get_some audio_src) gstbuf
+ Gstreamer.App_src.push_buffer (Utils.get_some audio_src) gstbuf
);
if has_video then
(
@@ -145,7 +145,7 @@ object (self)
let gstbuf = Gstreamer.Buffer.of_data data 0 (Bigarray.Array1.dim data) in
Gstreamer.Buffer.set_presentation_time gstbuf now;
Gstreamer.Buffer.set_duration gstbuf nanolen;
- Gstreamer.App_src.push_buffer (get_some video_src) gstbuf
+ Gstreamer.App_src.push_buffer (Utils.get_some video_src) gstbuf
done;
);
now <- Int64.add now nanolen
@@ -583,7 +583,7 @@ object (self)
in
log#f 5 "GStreamer pipeline: %s" pipeline;
bin <- Some (Pipeline.parse_launch pipeline);
- let bin = get_some bin in
+ let bin = Utils.get_some bin in
let audio_sink = App_sink.of_element (Bin.get_by_name bin "audio_sink") in
let video_sink =
if has_video then
@@ -47,7 +47,7 @@ let create_encoder ~opus ~comments () =
end;
let maybe name = fun value ->
ignore
- (Stdlib.maybe
+ (Utils.maybe
(fun value -> Opus.Encoder.apply_control (name value) x)
value)
in
@@ -361,8 +361,7 @@ class output ~kind p =
let login user
password =
let (user,
- password)
- =
+ password) =
let f =
Configure.
recode_tag
@@ -565,8 +564,7 @@ class output ~kind p =
s) in
let
(metaint,
- icyheader)
- =
+ icyheader) =
try
(assert
(((List.
@@ -907,8 +905,7 @@ class output ~kind p =
(acc, 0) in
let
(data,
- pos)
- =
+ pos) =
f [] 0
(b ::
(List.rev
@@ -1076,8 +1073,7 @@ class output ~kind p =
"^(.+)\\?(.+)$" in
let
(base_uri,
- args)
- =
+ args) =
try
let sub
=
View
@@ -1,17 +1,5 @@
let id x = x
-let get_some = function
- | Some x -> x
- | None -> assert false
-
-let maybe f = function
- | Some x -> Some (f x)
- | None -> None
-
-let some_or none = function
- | Some x -> x
- | None -> none
-
module List = struct
include List
View
@@ -20,7 +20,17 @@
*****************************************************************************)
-let get_some = function Some x -> x | None -> assert false
+let get_some = function
+ | Some x -> x
+ | None -> assert false
+
+let maybe f = function
+ | Some x -> Some (f x)
+ | None -> None
+
+let some_or none = function
+ | Some x -> x
+ | None -> none
(* Force locale to C *)
external force_locale : unit -> unit = "liquidsoap_set_locale"

2 comments on commit ef50490

Owner

smimram replied Nov 24, 2012

Could you explain how moving functions from one module to another solved your problem?

Owner

toots replied Nov 24, 2012

Please sign in to comment.