Skip to content

Commit

Permalink
Merge pull request ocaml-community#16 from LemonBoy/pixfmt
Browse files Browse the repository at this point in the history
Add Pixel_format.{of_string,to_string,planes}
  • Loading branch information
gndl authored Feb 25, 2018
2 parents 8c0f717 + ea9fc2f commit a9578e6
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 6 deletions.
5 changes: 4 additions & 1 deletion src/avutil.ml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@ let () =
module Pixel_format = struct
type t = Pixel_format.t

external bits : t -> int = "ocaml_avutil_bits_per_pixel"
external bits : t -> int = "ocaml_avutil_pixelformat_bits_per_pixel"
external planes : t -> int = "ocaml_avutil_pixelformat_planes"
external to_string : t -> string = "ocaml_avutil_pixelformat_to_string"
external of_string : string -> t = "ocaml_avutil_pixelformat_of_string"

let bits (*?(padding=true)*) p =
let n = bits p in
Expand Down
9 changes: 9 additions & 0 deletions src/avutil.mli
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,15 @@ module Pixel_format : sig

(** Return the number of bits of the pixel format. *)
val bits : (*?padding:bool ->*) t -> int

(** Return the number of planes of the pixel format. *)
val planes : t -> int

(** [Pixel_format.to_string f] Return a string representation of the pixel format [f]. *)
val to_string : t -> string

(** [Pixel_format.of_string s] Convert the string [s] into a [Pixel_format.t]. @raise Failure if [s] is not a valid format. *)
val of_string : string -> t
end

module Video : sig
Expand Down
36 changes: 31 additions & 5 deletions src/avutil_stubs.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@
#include <caml/bigarray.h>
#include <caml/threads.h>

#include <assert.h>

#include <libavutil/pixfmt.h>
#include <libavutil/pixdesc.h>
#include "libavutil/avstring.h"
#include <libavutil/avstring.h>

#include "avutil_stubs.h"
#include "pixel_format_stubs.h"
Expand All @@ -19,17 +21,41 @@
char ocaml_av_error_msg[ERROR_MSG_SIZE + 1];
char ocaml_av_exn_msg[ERROR_MSG_SIZE + 1];

CAMLprim value ocaml_avutil_bits_per_pixel(value pixel)
CAMLprim value ocaml_avutil_pixelformat_bits_per_pixel(value pixel)
{
CAMLparam1(pixel);
enum AVPixelFormat p = PixelFormat_val(pixel);

CAMLreturn(Val_int(av_get_bits_per_pixel(av_pix_fmt_desc_get(p))));
}

CAMLprim value ocaml_avutil_pixelformat_planes(value pixel)
{
CAMLparam1(pixel);
enum AVPixelFormat p = PixelFormat_val(pixel);
int ans;

ans = av_get_bits_per_pixel(av_pix_fmt_desc_get(p));
CAMLreturn(Val_int(av_pix_fmt_count_planes(p)));
}

CAMLprim value ocaml_avutil_pixelformat_to_string(value pixel)
{
CAMLparam1(pixel);
enum AVPixelFormat p = PixelFormat_val(pixel);

CAMLreturn(Val_int(ans));
CAMLreturn(caml_copy_string(av_get_pix_fmt_name(p)));
}

CAMLprim value ocaml_avutil_pixelformat_of_string(value name)
{
CAMLparam1(name);
enum AVPixelFormat p;

p = av_get_pix_fmt(String_val(name));
if (p != AV_PIX_FMT_NONE)
CAMLreturn(Val_PixelFormat(p));

Raise(EXN_FAILURE, "Invalid format name");
}

/**** Time format ****/
int64_t second_fractions_of_time_format(value time_format)
Expand Down

0 comments on commit a9578e6

Please sign in to comment.