File: interrupt.ml

package info (click to toggle)
ocaml-ffmpeg 1.2.7-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 908 kB
  • sloc: ansic: 6,412; ml: 6,166; makefile: 3
file content (43 lines) | stat: -rw-r--r-- 1,028 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
let () = Printexc.record_backtrace true
let () = if Sys.getenv_opt "GITHUB_ACTIONS" <> None then exit 0

let () =
  Avutil.Log.set_callback (fun _ -> ());

  let interrupt_m = Mutex.create () in
  let should_interrupt = ref false in

  ignore
    (Thread.create
       (fun () ->
         Unix.sleepf 0.1;
         Mutex.lock interrupt_m;
         should_interrupt := true;
         Mutex.unlock interrupt_m)
       ());

  let interrupt () =
    Mutex.lock interrupt_m;
    let b = !should_interrupt in
    Mutex.unlock interrupt_m;
    b
  in

  let opts = Hashtbl.create 1 in
  Hashtbl.replace opts "listen" (`Int 1);

  let sock = Filename.temp_file "ocaml-ffmpeg" "sock" in
  (try
     ignore
       (Av.open_input ~interrupt ~opts
          (Printf.sprintf "unix://%s?listen=1" sock));
     assert false
   with Avutil.Error `Exit -> Unix.unlink sock);

  (try
     ignore (Av.open_output ~interrupt "http://localhost/foo.mp3");
     assert false
   with Avutil.Error `Exit -> ());

  Gc.full_major ();
  Gc.full_major ()