Fix alignment in get_out_frame. Fixes #3233. If width % 32 then we can't use the more efficient 32 aligned scaling.

This commit is contained in:
Isaac Connor 2021-05-21 10:37:51 -04:00
parent 797a4adf70
commit 4fcdeb7287
1 changed files with 8 additions and 6 deletions

View File

@ -107,7 +107,7 @@ ZMPacket::~ZMPacket() {
int ZMPacket::decode(AVCodecContext *ctx) { int ZMPacket::decode(AVCodecContext *ctx) {
Debug(4, "about to decode video, image_index is (%d)", image_index); Debug(4, "about to decode video, image_index is (%d)", image_index);
if ( in_frame ) { if (in_frame) {
Error("Already have a frame?"); Error("Already have a frame?");
} else { } else {
in_frame = zm_av_frame_alloc(); in_frame = zm_av_frame_alloc();
@ -117,8 +117,8 @@ int ZMPacket::decode(AVCodecContext *ctx) {
//av_packet_rescale_ts(&packet, AV_TIME_BASE_Q, ctx->time_base); //av_packet_rescale_ts(&packet, AV_TIME_BASE_Q, ctx->time_base);
int ret = zm_send_packet_receive_frame(ctx, in_frame, packet); int ret = zm_send_packet_receive_frame(ctx, in_frame, packet);
if ( ret < 0 ) { if (ret < 0) {
if ( AVERROR(EAGAIN) != ret ) { if (AVERROR(EAGAIN) != ret) {
Warning("Unable to receive frame : code %d %s.", Warning("Unable to receive frame : code %d %s.",
ret, av_make_error_string(ret).c_str()); ret, av_make_error_string(ret).c_str());
} }
@ -126,7 +126,7 @@ int ZMPacket::decode(AVCodecContext *ctx) {
return 0; return 0;
} }
int bytes_consumed = ret; int bytes_consumed = ret;
if ( ret > 0 ) { if (ret > 0) {
zm_dump_video_frame(in_frame, "got frame"); zm_dump_video_frame(in_frame, "got frame");
#if HAVE_LIBAVUTIL_HWCONTEXT_H #if HAVE_LIBAVUTIL_HWCONTEXT_H
@ -258,9 +258,11 @@ AVFrame *ZMPacket::get_out_frame(int width, int height, AVPixelFormat format) {
} }
#if LIBAVUTIL_VERSION_CHECK(54, 6, 0, 6, 0) #if LIBAVUTIL_VERSION_CHECK(54, 6, 0, 6, 0)
int alignment = 32;
if (width%alignment) alignment = 1;
codec_imgsize = av_image_get_buffer_size( codec_imgsize = av_image_get_buffer_size(
format, width, height, 32); format, width, height, alignment);
Debug(1, "buffer size %u from %s %dx%d", codec_imgsize, av_get_pix_fmt_name(format), width, height); Debug(1, "buffer size %u from %s %dx%d", codec_imgsize, av_get_pix_fmt_name(format), width, height);
buffer = (uint8_t *)av_malloc(codec_imgsize); buffer = (uint8_t *)av_malloc(codec_imgsize);
int ret; int ret;
@ -271,7 +273,7 @@ AVFrame *ZMPacket::get_out_frame(int width, int height, AVPixelFormat format) {
format, format,
width, width,
height, height,
32))<0) { alignment))<0) {
Error("Failed to fill_arrays %s", av_make_error_string(ret).c_str()); Error("Failed to fill_arrays %s", av_make_error_string(ret).c_str());
av_frame_free(&out_frame); av_frame_free(&out_frame);
return nullptr; return nullptr;