Skip to content

Commit

Permalink
Use ffmpeg provided function.
Browse files Browse the repository at this point in the history
  • Loading branch information
toots committed Nov 30, 2024
1 parent 1b72beb commit f5371d7
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 10 deletions.
13 changes: 7 additions & 6 deletions av/av_stubs.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include <libavutil/opt.h>
#include <libavutil/parseutils.h>
#include <libavutil/timestamp.h>
#include <libavutil/mem.h>

#include "av_stubs.h"
#include "avcodec_stubs.h"
Expand Down Expand Up @@ -644,7 +645,7 @@ CAMLprim value ocaml_av_find_input_format(value _short_name) {
CAMLparam1(_short_name);
CAMLlocal1(ret);
char *short_name =
strndup(String_val(_short_name), caml_string_length(_short_name));
av_strndup(String_val(_short_name), caml_string_length(_short_name));

if (!short_name)
caml_raise_out_of_memory();
Expand Down Expand Up @@ -776,7 +777,7 @@ CAMLprim value ocaml_av_open_input(value _url, value _format, value _interrupt,
}

if (ulen > 0)
url = strndup(String_val(_url), ulen);
url = av_strndup(String_val(_url), ulen);

if (_format != Val_none)
format = InputFormat_val(Some_val(_format));
Expand Down Expand Up @@ -1351,13 +1352,13 @@ CAMLprim value ocaml_av_output_format_guess(value _short_name, value _filename,

if (caml_string_length(_short_name) > 0) {
short_name =
strndup(String_val(_short_name), caml_string_length(_short_name));
av_strndup(String_val(_short_name), caml_string_length(_short_name));
if (!short_name)
caml_raise_out_of_memory();
};

if (caml_string_length(_filename) > 0) {
filename = strndup(String_val(_filename), caml_string_length(_filename));
filename = av_strndup(String_val(_filename), caml_string_length(_filename));
if (!filename) {
if (short_name)
free(short_name);
Expand All @@ -1366,7 +1367,7 @@ CAMLprim value ocaml_av_output_format_guess(value _short_name, value _filename,
}

if (caml_string_length(_mime) > 0) {
mime = strndup(String_val(_mime), caml_string_length(_mime));
mime = av_strndup(String_val(_mime), caml_string_length(_mime));
if (!mime) {
if (short_name)
free(short_name);
Expand Down Expand Up @@ -1553,7 +1554,7 @@ CAMLprim value ocaml_av_open_output(value _interrupt, value _format,
CAMLparam3(_interrupt, _filename, _opts);
CAMLlocal3(ans, ret, unused);
char *filename =
strndup(String_val(_filename), caml_string_length(_filename));
av_strndup(String_val(_filename), caml_string_length(_filename));
avioformat_const AVOutputFormat *format = NULL;
AVDictionary *options = NULL;
char *key, *val;
Expand Down
7 changes: 4 additions & 3 deletions avfilter/avfilter_stubs.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include <libavfilter/avfilter.h>
#include <libavfilter/buffersink.h>
#include <libavfilter/buffersrc.h>
#include <libavutil/mem.h>

#define AvFilterContext_val(v) (*(AVFilterContext **)Data_abstract_val(v))

Expand Down Expand Up @@ -178,12 +179,12 @@ CAMLprim value ocaml_avfilter_create_filter(value _args, value _instance_name,
caml_raise_not_found();

name =
strndup(String_val(_instance_name), caml_string_length(_instance_name));
av_strndup(String_val(_instance_name), caml_string_length(_instance_name));
if (!name)
caml_raise_out_of_memory();

if (_args != Val_none) {
args = strndup(String_val(Some_val(_args)),
args = av_strndup(String_val(Some_val(_args)),
caml_string_length(Some_val(_args)));

if (!args) {
Expand Down Expand Up @@ -309,7 +310,7 @@ CAMLprim value ocaml_avfilter_parse(value _inputs, value _outputs,
append_avfilter_in_out(&outputs, name, filter_ctx, idx);
}

filters = strndup(String_val(_filters), caml_string_length(_filters));
filters = av_strndup(String_val(_filters), caml_string_length(_filters));

if (!filters) {
if (inputs)
Expand Down
3 changes: 2 additions & 1 deletion avutil/avutil_stubs.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include <libavutil/avstring.h>
#include <libavutil/pixdesc.h>
#include <libavutil/pixfmt.h>
#include <libavutil/mem.h>

#include "avutil_stubs.h"
#include "channel_layout_stubs.h"
Expand Down Expand Up @@ -512,7 +513,7 @@ enum caml_ba_kind bigarray_kind_of_AVSampleFormat(enum AVSampleFormat sf) {
CAMLprim value ocaml_avutil_find_sample_fmt(value _name) {
CAMLparam1(_name);
CAMLlocal1(ans);
char *name = strndup(String_val(_name), caml_string_length(_name));
char *name = av_strndup(String_val(_name), caml_string_length(_name));
if (!name)
caml_raise_out_of_memory();

Expand Down

0 comments on commit f5371d7

Please sign in to comment.