Permalink
Browse files

Use some mutexify.

  • Loading branch information...
1 parent f178d5f commit ca6ecdbdbe92d2c9be041c5c675c6469275504b2 @toots toots committed Oct 30, 2012
Showing with 41 additions and 44 deletions.
  1. +8 −7 src/encoder/gstreamer_encoder.ml
  2. +33 −37 src/io/gstreamer_io.ml
@@ -41,18 +41,19 @@ let encoder id ext =
let mutex = Mutex.create () in
let samples = ref 0 in
- let decr_samples () =
- Mutex.lock mutex;
- decr samples;
- Mutex.unlock mutex;
+ let decr_samples =
+ Tutils.mutexify mutex (fun () ->
+ decr samples)
+ in
+ let incr_samples =
+ Tutils.mutexify mutex (fun () ->
+ incr samples)
in
let on_sample () =
Printf.printf "Got sample!\n%!";
(* Will we finally get there????....... *)
exit (-1);
- Mutex.lock mutex;
- incr samples;
- Mutex.unlock mutex
+ incr_samples();
in
let gst =
View
@@ -291,36 +291,34 @@ object (self)
method feed_audio n =
let bin, audio_src, video_src = self#get_gst in
- Mutex.lock audio_buffer_mutex;
- while Queue.is_empty audio_buffer do
- Condition.wait audio_buffer_condition audio_buffer_mutex
- done;
- let data = Queue.pop audio_buffer in
- let len = String.length data in
- let nanolen = Int64.of_float (Frame.seconds_of_audio (len / (2 * channels)) *. 1000000000.) in
- let gstbuf = Gstreamer.Buffer.of_string data 0 len in
- Gstreamer.Buffer.set_presentation_time gstbuf audio_now;
- Gstreamer.Buffer.set_duration gstbuf nanolen;
- Gstreamer.App_src.push_buffer audio_src gstbuf;
- audio_now <- Int64.add audio_now nanolen;
- Mutex.unlock audio_buffer_mutex
+ Tutils.mutexify audio_buffer_mutex (fun () ->
+ while Queue.is_empty audio_buffer do
+ Condition.wait audio_buffer_condition audio_buffer_mutex
+ done;
+ let data = Queue.pop audio_buffer in
+ let len = String.length data in
+ let nanolen = Int64.of_float (Frame.seconds_of_audio (len / (2 * channels)) *. 1000000000.) in
+ let gstbuf = Gstreamer.Buffer.of_string data 0 len in
+ Gstreamer.Buffer.set_presentation_time gstbuf audio_now;
+ Gstreamer.Buffer.set_duration gstbuf nanolen;
+ Gstreamer.App_src.push_buffer audio_src gstbuf;
+ audio_now <- Int64.add audio_now nanolen) ()
method feed_video n =
let bin, audio_src, video_src = self#get_gst in
- Mutex.lock video_buffer_mutex;
- while Queue.is_empty video_buffer do
- Condition.wait video_buffer_condition video_buffer_mutex
- done;
- let img = Queue.pop video_buffer in
- let data = Img.data img in
- let len = Bigarray.Array1.dim data in
- let nanolen = Int64.of_float (Frame.seconds_of_video 1 *. 1000000000.) in
- let gstbuf = Gstreamer.Buffer.of_data data 0 len in
- Gstreamer.Buffer.set_presentation_time gstbuf video_now;
- Gstreamer.Buffer.set_duration gstbuf nanolen;
- Gstreamer.App_src.push_buffer video_src gstbuf;
- video_now <- Int64.add video_now nanolen;
- Mutex.unlock video_buffer_mutex
+ Tutils.mutexify video_buffer_mutex (fun () ->
+ while Queue.is_empty video_buffer do
+ Condition.wait video_buffer_condition video_buffer_mutex
+ done;
+ let img = Queue.pop video_buffer in
+ let data = Img.data img in
+ let len = Bigarray.Array1.dim data in
+ let nanolen = Int64.of_float (Frame.seconds_of_video 1 *. 1000000000.) in
+ let gstbuf = Gstreamer.Buffer.of_data data 0 len in
+ Gstreamer.Buffer.set_presentation_time gstbuf video_now;
+ Gstreamer.Buffer.set_duration gstbuf nanolen;
+ Gstreamer.App_src.push_buffer video_src gstbuf;
+ video_now <- Int64.add video_now nanolen) ()
method output_send frame =
if not (Frame.is_partial frame) then
@@ -333,19 +331,17 @@ object (self)
let len = Frame.audio_of_master len in
let data = String.create (2*channels*len) in
Audio.S16LE.of_audio pcm 0 data 0 len;
- Mutex.lock audio_buffer_mutex;
- Queue.push data audio_buffer;
- Condition.signal audio_buffer_condition;
- Mutex.unlock audio_buffer_mutex;
+ Tutils.mutexify audio_buffer_mutex (fun () ->
+ Queue.push data audio_buffer;
+ Condition.signal audio_buffer_condition) ();
(* Read video. *)
let buf = content.Frame.video.(0) in
- Mutex.lock video_buffer_mutex;
- for i = 0 to Array.length buf - 1 do
- Queue.push buf.(i) video_buffer
- done;
- Condition.signal video_buffer_condition;
- Mutex.unlock video_buffer_mutex
+ Tutils.mutexify video_buffer_mutex (fun () ->
+ for i = 0 to Array.length buf - 1 do
+ Queue.push buf.(i) video_buffer
+ done;
+ Condition.signal video_buffer_condition) ()
method output_reset = ()
end

0 comments on commit ca6ecdb

Please sign in to comment.