diff options
Diffstat (limited to 'libavcodec/libkvazaar.c')
-rw-r--r-- | libavcodec/libkvazaar.c | 55 |
1 files changed, 34 insertions, 21 deletions
diff --git a/libavcodec/libkvazaar.c b/libavcodec/libkvazaar.c index fa64bf5..a89ca7f 100644 --- a/libavcodec/libkvazaar.c +++ b/libavcodec/libkvazaar.c @@ -3,20 +3,20 @@ * * Copyright (c) 2015 Tampere University of Technology * - * This file is part of Libav. + * This file is part of FFmpeg. * - * Libav is free software; you can redistribute it and/or + * FFmpeg is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * - * Libav is distributed in the hope that it will be useful, + * FFmpeg is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public - * License along with Libav; if not, write to the Free Software + * License along with FFmpeg; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ @@ -25,6 +25,7 @@ #include <string.h> #include "libavutil/attributes.h" +#include "libavutil/avassert.h" #include "libavutil/dict.h" #include "libavutil/error.h" #include "libavutil/imgutils.h" @@ -54,12 +55,6 @@ static av_cold int libkvazaar_init(AVCodecContext *avctx) kvz_config *cfg = NULL; kvz_encoder *enc = NULL; - if (avctx->strict_std_compliance > FF_COMPLIANCE_EXPERIMENTAL) { - av_log(avctx, AV_LOG_ERROR, - "Set -strict experimental to use this encoder.\n"); - return AVERROR_EXPERIMENTAL; - } - /* Kvazaar requires width and height to be multiples of eight. */ if (avctx->width % 8 || avctx->height % 8) { av_log(avctx, AV_LOG_ERROR, @@ -84,8 +79,23 @@ static av_cold int libkvazaar_init(AVCodecContext *avctx) cfg->width = avctx->width; cfg->height = avctx->height; - cfg->framerate_num = avctx->time_base.den; - cfg->framerate_denom = avctx->time_base.num * avctx->ticks_per_frame; + if (avctx->framerate.num > 0 && avctx->framerate.den > 0) { + if (avctx->ticks_per_frame > INT_MAX / avctx->framerate.den) { + av_log(avctx, AV_LOG_ERROR, + "Could not set framerate for kvazaar: integer overflow\n"); + return AVERROR(EINVAL); + } + cfg->framerate_num = avctx->framerate.num; + cfg->framerate_denom = avctx->time_base.den * avctx->ticks_per_frame; + } else { + if (avctx->ticks_per_frame > INT_MAX / avctx->time_base.num) { + av_log(avctx, AV_LOG_ERROR, + "Could not set framerate for kvazaar: integer overflow\n"); + return AVERROR(EINVAL); + } + cfg->framerate_num = avctx->time_base.den; + cfg->framerate_denom = avctx->time_base.num * avctx->ticks_per_frame; + } cfg->target_bitrate = avctx->bit_rate; cfg->vui.sar_width = avctx->sample_aspect_ratio.num; cfg->vui.sar_height = avctx->sample_aspect_ratio.den; @@ -143,8 +153,8 @@ static av_cold int libkvazaar_close(AVCodecContext *avctx) LibkvazaarContext *ctx = avctx->priv_data; if (ctx->api) { - ctx->api->encoder_close(ctx->encoder); - ctx->api->config_destroy(ctx->config); + ctx->api->encoder_close(ctx->encoder); + ctx->api->config_destroy(ctx->config); } if (avctx->extradata) @@ -166,9 +176,11 @@ static int libkvazaar_encode(AVCodecContext *avctx, uint32_t len_out = 0; int retval = 0; + *got_packet_ptr = 0; + if (frame) { if (frame->width != ctx->config->width || - frame->height != ctx->config->height) { + frame->height != ctx->config->height) { av_log(avctx, AV_LOG_ERROR, "Changing video dimensions during encoding is not supported. " "(changed from %dx%d to %dx%d)\n", @@ -205,7 +217,7 @@ static int libkvazaar_encode(AVCodecContext *avctx, 0 }; av_image_copy(input_pic->data, dst_linesizes, - frame->data, frame->linesize, + (const uint8_t **)frame->data, frame->linesize, frame->format, frame->width, frame->height); } @@ -221,19 +233,21 @@ static int libkvazaar_encode(AVCodecContext *avctx, av_log(avctx, AV_LOG_ERROR, "Failed to encode frame.\n"); retval = AVERROR_INVALIDDATA; goto done; - } + } else + retval = 0; /* kvazaar returns 1 on success */ if (data_out) { kvz_data_chunk *chunk = NULL; uint64_t written = 0; - retval = ff_alloc_packet(avpkt, len_out); + retval = ff_alloc_packet2(avctx, avpkt, len_out, len_out); if (retval < 0) { av_log(avctx, AV_LOG_ERROR, "Failed to allocate output packet.\n"); goto done; } for (chunk = data_out; chunk != NULL; chunk = chunk->next) { + av_assert0(written + chunk->len <= len_out); memcpy(avpkt->data + written, chunk->data, chunk->len); written += chunk->len; } @@ -244,7 +258,7 @@ static int libkvazaar_encode(AVCodecContext *avctx, // IRAP VCL NAL unit types span the range // [BLA_W_LP (16), RSV_IRAP_VCL23 (23)]. if (frame_info.nal_unit_type >= KVZ_NAL_BLA_W_LP && - frame_info.nal_unit_type <= KVZ_NAL_RSV_IRAP_VCL23) { + frame_info.nal_unit_type <= KVZ_NAL_RSV_IRAP_VCL23) { avpkt->flags |= AV_PKT_FLAG_KEY; } @@ -268,7 +282,6 @@ static const enum AVPixelFormat pix_fmts[] = { static const AVOption options[] = { { "kvazaar-params", "Set kvazaar parameters as a comma-separated list of key=value pairs.", OFFSET(kvz_params), AV_OPT_TYPE_STRING, { .str = NULL }, 0, 0, VE }, - { NULL }, }; @@ -289,7 +302,7 @@ AVCodec ff_libkvazaar_encoder = { .long_name = NULL_IF_CONFIG_SMALL("libkvazaar H.265 / HEVC"), .type = AVMEDIA_TYPE_VIDEO, .id = AV_CODEC_ID_HEVC, - .capabilities = AV_CODEC_CAP_DELAY, + .capabilities = AV_CODEC_CAP_DELAY | AV_CODEC_CAP_AUTO_THREADS, .pix_fmts = pix_fmts, .priv_class = &class, |