Unified · Split
| @@ -44,6 +44,8 @@ · 43 unmodified lines | ||
| 44 | 44 | #include "libavutil/imgutils.h" |
| 45 | 45 | #include "libavutil/avassert.h" |
| 46 | 46 | |
| 47 | +#define ZIMG_ALIGNMENT 32 | |
| 48 | + | |
| 47 | 49 | static const char *const var_names[] = { |
| 48 | 50 | "in_w", "iw", |
| 49 | 51 | "in_h", "ih", |
| @@ -502,6 +504,44 @@ static int graph_build(zimg_filter_graph **graph, zimg_graph_builder_params *par · 452 unmodified lines | ||
| 502 | 504 | return 0; |
| 503 | 505 | } |
| 504 | 506 | |
| 507 | +static int realign_frame(const AVPixFmtDescriptor *desc, AVFrame **frame) | |
| 508 | +{ | |
| 509 | + AVFrame *aligned = NULL; | |
| 510 | + int ret = 0, plane; | |
| 511 | + | |
| 512 | + /* Realign any unaligned input frame. */ | |
| 513 | + for (plane = 0; plane < 3; plane++) { | |
| 514 | + int p = desc->comp[plane].plane; | |
| 515 | + if ((uintptr_t)(*frame)->data[p] % ZIMG_ALIGNMENT || (*frame)->linesize[p] % ZIMG_ALIGNMENT) { | |
| 516 | + if (!(aligned = av_frame_alloc())) { | |
| 517 | + ret = AVERROR(ENOMEM); | |
| 518 | + goto fail; | |
| 519 | + } | |
| 520 | + | |
| 521 | + aligned->format = (*frame)->format; | |
| 522 | + aligned->width = (*frame)->width; | |
| 523 | + aligned->height = (*frame)->height; | |
| 524 | + | |
| 525 | + if ((ret = av_frame_get_buffer(aligned, ZIMG_ALIGNMENT)) < 0) | |
| 526 | + goto fail; | |
| 527 | + | |
| 528 | + if ((ret = av_frame_copy(aligned, *frame)) < 0) | |
| 529 | + goto fail; | |
| 530 | + | |
| 531 | + if ((ret = av_frame_copy_props(aligned, *frame)) < 0) | |
| 532 | + goto fail; | |
| 533 | + | |
| 534 | + av_frame_free(frame); | |
| 535 | + *frame = aligned; | |
| 536 | + return 0; | |
| 537 | + } | |
| 538 | + } | |
| 539 | + | |
| 540 | +fail: | |
| 541 | + av_frame_free(&aligned); | |
| 542 | + return ret; | |
| 543 | +} | |
| 544 | + | |
| 505 | 545 | static int filter_frame(AVFilterLink *link, AVFrame *in) |
| 506 | 546 | { |
| 507 | 547 | ZScaleContext *s = link->dst->priv; |
| @@ -512,12 +552,14 @@ static int filter_frame(AVFilterLink *link, AVFrame *in) · 4 unmodified lines | ||
| 512 | 552 | zimg_image_buffer dst_buf = { ZIMG_API_VERSION }; |
| 513 | 553 | char buf[32]; |
| 514 | 554 | int ret = 0, plane; |
| 515 | − AVFrame *out; | |
| 555 | + AVFrame *out = NULL; | |
| 516 | 556 | |
| 517 | − out = ff_get_video_buffer(outlink, outlink->w, outlink->h); | |
| 518 | − if (!out) { | |
| 519 | − av_frame_free(&in); | |
| 520 | − return AVERROR(ENOMEM); | |
| 557 | + if ((ret = realign_frame(desc, &in)) < 0) | |
| 558 | + goto fail; | |
| 559 | + | |
| 560 | + if (!(out = ff_get_video_buffer(outlink, outlink->w, outlink->h))) { | |
| 561 | + ret = AVERROR(ENOMEM); | |
| 562 | + goto fail; | |
| 521 | 563 | } |
| 522 | 564 | |
| 523 | 565 | av_frame_copy_props(out, in); |
| @@ -546,11 +588,8 @@ static int filter_frame(AVFilterLink *link, AVFrame *in) · 22 unmodified lines | ||
| 546 | 588 | link->dst->inputs[0]->w = in->width; |
| 547 | 589 | link->dst->inputs[0]->h = in->height; |
| 548 | 590 | |
| 549 | − if ((ret = config_props(outlink)) < 0) { | |
| 550 | − av_frame_free(&in); | |
| 551 | − av_frame_free(&out); | |
| 552 | − return ret; | |
| 553 | − } | |
| 591 | + if ((ret = config_props(outlink)) < 0) | |
| 592 | + goto fail; | |
| 554 | 593 | |
| 555 | 594 | zimg_image_format_default(&s->src_format, ZIMG_API_VERSION); |
| 556 | 595 | zimg_image_format_default(&s->dst_format, ZIMG_API_VERSION); |