X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=libavcodec%2Fencode.c;h=9ed2cf0f5908b72772094d6aa21046edc3418d31;hb=a11aa5f3ed7ee4d2385a7b725d43f6070d790b4c;hp=d12c42526be5b94eac158752a8041f06aaa61278;hpb=d91370e0f12a3fedd477616011566d9f2fb5e3e5;p=ffmpeg diff --git a/libavcodec/encode.c b/libavcodec/encode.c index d12c42526be..9ed2cf0f590 100644 --- a/libavcodec/encode.c +++ b/libavcodec/encode.c @@ -174,8 +174,14 @@ int attribute_align_arg avcodec_encode_audio2(AVCodecContext *avctx, goto end; } } else if (!(avctx->codec->capabilities & AV_CODEC_CAP_VARIABLE_FRAME_SIZE)) { - if (frame->nb_samples < avctx->frame_size && - !avctx->internal->last_audio_frame) { + /* if we already got an undersized frame, that must have been the last */ + if (avctx->internal->last_audio_frame) { + av_log(avctx, AV_LOG_ERROR, "frame_size (%d) was not respected for a non-last frame (avcodec_encode_audio2)\n", avctx->frame_size); + ret = AVERROR(EINVAL); + goto end; + } + + if (frame->nb_samples < avctx->frame_size) { ret = pad_last_frame(avctx, &padded_frame, frame); if (ret < 0) goto end; @@ -422,9 +428,15 @@ int attribute_align_arg avcodec_receive_packet(AVCodecContext *avctx, AVPacket * return AVERROR(EINVAL); if (avctx->codec->receive_packet) { + int ret; if (avctx->internal->draining && !(avctx->codec->capabilities & AV_CODEC_CAP_DELAY)) return AVERROR_EOF; - return avctx->codec->receive_packet(avctx, avpkt); + ret = avctx->codec->receive_packet(avctx, avpkt); + if (!ret) + // Encoders must always return ref-counted buffers. + // Side-data only packets have no data and can be not ref-counted. + av_assert0(!avpkt->data || avpkt->buf); + return ret; } // Emulation via old API.