Skip to content

Commit 1e5cbc3

Browse files
committed
Adapt avoptions implementation to iter API.
1 parent 7d5b396 commit 1e5cbc3

File tree

6 files changed

+120
-83
lines changed

6 files changed

+120
-83
lines changed

av/av_stubs.c

+14-13
Original file line numberDiff line numberDiff line change
@@ -576,7 +576,8 @@ CAMLprim value caml_av_input_io_finalise(value _avio) {
576576

577577
/***** AVInputFormat *****/
578578

579-
void value_of_inputFormat(AVInputFormat *inputFormat, value *p_value) {
579+
void value_of_inputFormat(avioformat_const AVInputFormat *inputFormat,
580+
value *p_value) {
580581
if (!inputFormat)
581582
Fail("Empty input format");
582583

@@ -594,7 +595,7 @@ CAMLprim value ocaml_av_find_input_format(value _short_name) {
594595
caml_raise_out_of_memory();
595596

596597
caml_release_runtime_system();
597-
AVInputFormat *format = av_find_input_format(short_name);
598+
avioformat_const AVInputFormat *format = av_find_input_format(short_name);
598599
caml_acquire_runtime_system();
599600

600601
free(short_name);
@@ -619,7 +620,7 @@ CAMLprim value ocaml_av_input_format_get_long_name(value _format) {
619620
CAMLreturn(caml_copy_string(n ? n : ""));
620621
}
621622

622-
static av_t *open_input(char *url, AVInputFormat *format,
623+
static av_t *open_input(char *url, avioformat_const AVInputFormat *format,
623624
AVFormatContext *format_context, value _interrupt,
624625
AVDictionary **options) {
625626
int err;
@@ -691,7 +692,7 @@ CAMLprim value ocaml_av_open_input(value _url, value _format, value _interrupt,
691692
CAMLparam4(_url, _format, _interrupt, _opts);
692693
CAMLlocal3(ret, ans, unused);
693694
char *url = NULL;
694-
AVInputFormat *format = NULL;
695+
avioformat_const AVInputFormat *format = NULL;
695696
int ulen = caml_string_length(_url);
696697
AVDictionary *options = NULL;
697698
char *key, *val;
@@ -756,7 +757,7 @@ CAMLprim value ocaml_av_open_input_stream(value _avio, value _format,
756757
CAMLparam3(_avio, _format, _opts);
757758
CAMLlocal3(ret, ans, unused);
758759
avio_t *avio = Avio_val(_avio);
759-
AVInputFormat *format = NULL;
760+
avioformat_const AVInputFormat *format = NULL;
760761
AVDictionary *options = NULL;
761762
char *key, *val;
762763
int len = Wosize_val(_opts);
@@ -1275,7 +1276,7 @@ CAMLprim value ocaml_av_seek_bytecode(value *argv, int argn) {
12751276

12761277
/***** AVOutputFormat *****/
12771278

1278-
value value_of_outputFormat(AVOutputFormat *outputFormat) {
1279+
value value_of_outputFormat(avioformat_const AVOutputFormat *outputFormat) {
12791280
value v;
12801281
if (!outputFormat)
12811282
Fail("Empty output format");
@@ -1293,7 +1294,7 @@ CAMLprim value ocaml_av_output_format_guess(value _short_name, value _filename,
12931294
char *short_name = NULL;
12941295
char *filename = NULL;
12951296
char *mime = NULL;
1296-
AVOutputFormat *guessed;
1297+
avioformat_const AVOutputFormat *guessed;
12971298

12981299
if (caml_string_length(_short_name) > 0) {
12991300
short_name =
@@ -1371,9 +1372,9 @@ ocaml_av_output_format_get_subtitle_codec_id(value _output_format) {
13711372
Val_SubtitleCodecID(OutputFormat_val(_output_format)->subtitle_codec));
13721373
}
13731374

1374-
static av_t *open_output(AVOutputFormat *format, char *file_name,
1375-
AVIOContext *avio_context, value _interrupt,
1376-
AVDictionary **options) {
1375+
static av_t *open_output(avioformat_const AVOutputFormat *format,
1376+
char *file_name, AVIOContext *avio_context,
1377+
value _interrupt, AVDictionary **options) {
13771378
int ret;
13781379
AVIOInterruptCB interrupt_cb = {ocaml_av_interrupt_callback, NULL};
13791380
AVIOInterruptCB *interrupt_cb_ptr = NULL;
@@ -1487,7 +1488,7 @@ CAMLprim value ocaml_av_open_output(value _interrupt, value _format,
14871488
CAMLlocal3(ans, ret, unused);
14881489
char *filename =
14891490
strndup(String_val(_filename), caml_string_length(_filename));
1490-
AVOutputFormat *format = NULL;
1491+
avioformat_const AVOutputFormat *format = NULL;
14911492
AVDictionary *options = NULL;
14921493
char *key, *val;
14931494
int len = Wosize_val(_opts);
@@ -1554,7 +1555,7 @@ CAMLprim value ocaml_av_open_output_format(value _format, value _opts) {
15541555
}
15551556
}
15561557

1557-
AVOutputFormat *format = OutputFormat_val(_format);
1558+
avioformat_const AVOutputFormat *format = OutputFormat_val(_format);
15581559

15591560
// open output format
15601561
av_t *av = open_output(format, NULL, NULL, Val_none, &options);
@@ -1588,7 +1589,7 @@ CAMLprim value ocaml_av_open_output_stream(value _format, value _avio,
15881589
value _opts) {
15891590
CAMLparam3(_format, _avio, _opts);
15901591
CAMLlocal3(ans, ret, unused);
1591-
AVOutputFormat *format = OutputFormat_val(_format);
1592+
avioformat_const AVOutputFormat *format = OutputFormat_val(_format);
15921593
avio_t *avio = Avio_val(_avio);
15931594
AVDictionary *options = NULL;
15941595
char *key, *val;

av/av_stubs.h

+10-7
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,25 @@
55

66
#include <libavformat/avformat.h>
77

8+
AVFormatContext *ocaml_av_get_format_context(value *p_av);
89

9-
AVFormatContext * ocaml_av_get_format_context(value *p_av);
10+
#if AV_VERSION_INT(59, 0, 100) < LIBAVFORMAT_VERSION_INT
11+
#define avioformat_const const
12+
#else
13+
#define avioformat_const
14+
#endif
1015

1116
/***** AVInputFormat *****/
1217

13-
#define InputFormat_val(v) (*(struct AVInputFormat**)Data_abstract_val(v))
14-
15-
void value_of_inputFormat(AVInputFormat *inputFormat, value * p_value);
18+
#define InputFormat_val(v) (*(avioformat_const AVInputFormat**)Data_abstract_val(v))
1619

20+
void value_of_inputFormat(avioformat_const AVInputFormat *inputFormat, value * p_value);
1721

1822
/***** AVOutputFormat *****/
1923

20-
#define OutputFormat_val(v) (*(struct AVOutputFormat**)Data_abstract_val(v))
21-
22-
value value_of_outputFormat(AVOutputFormat *outputFormat);
24+
#define OutputFormat_val(v) (*(avioformat_const AVOutputFormat**)Data_abstract_val(v))
2325

26+
value value_of_outputFormat(avioformat_const AVOutputFormat *outputFormat);
2427

2528
/***** Control message *****/
2629
value * ocaml_av_get_control_message_callback(struct AVFormatContext *ctx);

avdevice/avdevice_stubs.c

+6-7
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@ CAMLprim value ocaml_avdevice_init(value unit) {
1919
CAMLreturn(Val_unit);
2020
}
2121

22-
static value
23-
get_input_devices(AVInputFormat *(*input_device_next)(AVInputFormat *)) {
22+
static value get_input_devices(avioformat_const AVInputFormat *(
23+
*input_device_next)(avioformat_const AVInputFormat *)) {
2424
CAMLparam0();
2525
CAMLlocal2(v, ans);
26-
AVInputFormat *fmt = NULL;
26+
avioformat_const AVInputFormat *fmt = NULL;
2727
int len = 0;
2828

2929
while ((fmt = input_device_next(fmt)))
@@ -54,11 +54,11 @@ CAMLprim value ocaml_avdevice_get_video_input_formats(value unit) {
5454
CAMLreturn(get_input_devices(av_input_video_device_next));
5555
}
5656

57-
static value
58-
get_output_devices(AVOutputFormat *(*output_device_next)(AVOutputFormat *)) {
57+
static value get_output_devices(avioformat_const AVOutputFormat *(
58+
*output_device_next)(avioformat_const AVOutputFormat *)) {
5959
CAMLparam0();
6060
CAMLlocal1(ans);
61-
AVOutputFormat *fmt = NULL;
61+
avioformat_const AVOutputFormat *fmt = NULL;
6262
int len = 0;
6363

6464
while ((fmt = output_device_next(fmt)))
@@ -70,7 +70,6 @@ get_output_devices(AVOutputFormat *(*output_device_next)(AVOutputFormat *)) {
7070
fmt = NULL;
7171

7272
while ((fmt = output_device_next(fmt))) {
73-
7473
Store_field(ans, i, value_of_outputFormat(fmt));
7574
i++;
7675
}

avfilter/avfilter_stubs.c

+14-2
Original file line numberDiff line numberDiff line change
@@ -109,10 +109,22 @@ CAMLprim value ocaml_avfilter_get_all_filters(value unit) {
109109
Store_field(cur, 1, caml_copy_string(f->description));
110110
Store_field(cur, 2,
111111
ocaml_avfilter_alloc_pads(
112-
f->inputs, avfilter_pad_count(f->inputs), f->name));
112+
#if LIBAVFILTER_VERSION_INT < AV_VERSION_INT(8, 3, 100)
113+
f->inputs, avfilter_pad_count(f->inputs), f->name
114+
#else
115+
f->inputs, avfilter_filter_pad_count(f, 0), f->name
116+
#endif
117+
)
118+
);
113119
Store_field(cur, 3,
114120
ocaml_avfilter_alloc_pads(
115-
f->outputs, avfilter_pad_count(f->outputs), f->name));
121+
#if LIBAVFILTER_VERSION_INT < AV_VERSION_INT(8, 3, 100)
122+
f->outputs, avfilter_pad_count(f->outputs), f->name
123+
#else
124+
f->outputs, avfilter_filter_pad_count(f, 0), f->name
125+
#endif
126+
)
127+
);
116128
Store_field(cur, 4, value_of_avclass(tmp, f->priv_class));
117129
Store_field(cur, 5, Val_int(f->flags));
118130

avutil/avutil.ml

+3-3
Original file line numberDiff line numberDiff line change
@@ -422,8 +422,8 @@ module Options = struct
422422
_cursor : _cursor option;
423423
}
424424

425-
external av_opt_next : _cursor option -> t -> _opt option
426-
= "ocaml_avutil_av_opt_next"
425+
external av_opt_iter : _cursor option -> t -> _opt option
426+
= "ocaml_avutil_av_opt_iter"
427427

428428
let constant_of_opt opt (name, { _default; _ }) =
429429
let append fn l = (name, fn (Option.get _default)) :: l in
@@ -576,7 +576,7 @@ module Options = struct
576576
in
577577

578578
let rec f _cursor _opts =
579-
match av_opt_next _cursor v with
579+
match av_opt_iter _cursor v with
580580
| None -> List.map opt_of_opt _opts
581581
| Some { _name; _spec = `Constant s; _cursor; _unit; _ } ->
582582
Hashtbl.add constants (Option.get _unit) (_name, s);

0 commit comments

Comments
 (0)