From 5778837143a59378546deb24c31a84f8bcff7b6b Mon Sep 17 00:00:00 2001 From: LemonBoy Date: Thu, 22 Feb 2018 17:16:46 +0100 Subject: [PATCH 1/2] Add Pixel_format.{of_string,to_string,planes} --- src/avutil.ml | 14 +++++++++++++- src/avutil.mli | 9 +++++++++ src/avutil_stubs.c | 36 +++++++++++++++++++++++++++++++----- 3 files changed, 53 insertions(+), 6 deletions(-) diff --git a/src/avutil.ml b/src/avutil.ml index 76249703..10830316 100644 --- a/src/avutil.ml +++ b/src/avutil.ml @@ -26,12 +26,24 @@ 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 (* TODO: when padding is true we should add the padding *) n + + let planes fmt = + planes fmt + + let to_string fmt = + to_string fmt + + let of_string str = + of_string str end module Time_format = struct diff --git a/src/avutil.mli b/src/avutil.mli index 0ff7d7fd..58a460f5 100644 --- a/src/avutil.mli +++ b/src/avutil.mli @@ -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 diff --git a/src/avutil_stubs.c b/src/avutil_stubs.c index aceb69f9..288dcc0c 100644 --- a/src/avutil_stubs.c +++ b/src/avutil_stubs.c @@ -7,9 +7,11 @@ #include #include +#include + #include #include -#include "libavutil/avstring.h" +#include #include "avutil_stubs.h" #include "pixel_format_stubs.h" @@ -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) From ea9fc2fb2255e65bf3ebed3cd8e9f646487d647b Mon Sep 17 00:00:00 2001 From: LemonBoy Date: Sun, 25 Feb 2018 10:50:08 +0100 Subject: [PATCH 2/2] Remove unnecessary stub functions --- src/avutil.ml | 9 --------- 1 file changed, 9 deletions(-) diff --git a/src/avutil.ml b/src/avutil.ml index 10830316..fce8ba2a 100644 --- a/src/avutil.ml +++ b/src/avutil.ml @@ -35,15 +35,6 @@ module Pixel_format = struct let n = bits p in (* TODO: when padding is true we should add the padding *) n - - let planes fmt = - planes fmt - - let to_string fmt = - to_string fmt - - let of_string str = - of_string str end module Time_format = struct