Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix plane size in swscale. #67

Merged
merged 1 commit into from
Oct 20, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 15 additions & 6 deletions swscale/swscale_stubs.c
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ struct video_t {
int nb_planes;
uint8_t *slice_tab[4];
int stride_tab[4];
size_t plane_sizes[4];
int sizes_tab[4];
uint8_t **slice;
int *stride;
Expand Down Expand Up @@ -308,7 +309,7 @@ static int alloc_out_ba(sws_t *sws, value *out_vect, value *tmp) {
for (i = 0; i < sws->out.nb_planes; i++) {
// Some filters and swscale can read up to 16 bytes beyond the planes, 16
// extra bytes must be allocated.
out_size = sws->out.stride[i] * sws->out.height + 16;
out_size = sws->out.plane_sizes[i] + 16;

*tmp = caml_alloc_tuple(2);
Store_field(
Expand Down Expand Up @@ -449,19 +450,27 @@ CAMLprim value ocaml_swscale_create(value flags_, value in_vector_kind_,
sws->alloc_out = alloc_out_ba;
}

caml_release_runtime_system();
int ret = av_image_fill_linesizes(sws->out.stride, sws->out.pixel_format,
sws->out.width);
caml_acquire_runtime_system();

if (ret < 0) {
swscale_free(sws);
Fail("Failed to create Swscale context");
}

for (sws->out.nb_planes = 0; sws->out.stride[sws->out.nb_planes];
sws->out.nb_planes++)
;
ptrdiff_t linesizes[4];
for (i = 0; i < 4; i++)
linesizes[i] = sws->out.stride[i];

ret = av_image_fill_plane_sizes(sws->out.plane_sizes, sws->out.pixel_format,
sws->out.height, linesizes);

if (ret < 0) {
swscale_free(sws);
Fail("Failed to create Swscale context");
}

sws->out.nb_planes = av_pix_fmt_count_planes(sws->out.pixel_format);

ans = caml_alloc_custom(&sws_ops, sizeof(sws_t *), 0, 1);
Sws_val(ans) = sws;
Expand Down
Loading