[FFmpeg-devel] [PATCH 1/3 v2] avcodec/encode: restructure the core encoding code
James Almer
jamrial at gmail.com
Tue Mar 17 01:30:52 EET 2020
On 3/16/2020 6:30 PM, James Almer wrote:
> +static int encode_send_packet_internal(AVCodecContext *avctx, const AVFrame *src)
> +{
> + AVCodecInternal *avci = avctx->internal;
> + AVFrame *dst = avci->buffer_frame;
> + int ret;
> +
> + if (avctx->codec->type == AVMEDIA_TYPE_AUDIO) {
> + /* extract audio service type metadata */
> + AVFrameSideData *sd = av_frame_get_side_data(src, AV_FRAME_DATA_AUDIO_SERVICE_TYPE);
> + if (sd && sd->size >= sizeof(enum AVAudioServiceType))
> + avctx->audio_service_type = *(enum AVAudioServiceType*)sd->data;
> +
> + /* check for valid frame size */
> + if (avctx->codec->capabilities & AV_CODEC_CAP_SMALL_LAST_FRAME) {
> + if (src->nb_samples > avctx->frame_size) {
> + av_log(avctx, AV_LOG_ERROR, "more samples than frame size\n");
> + return AVERROR(EINVAL);
> + }
> + } else if (!(avctx->codec->capabilities & AV_CODEC_CAP_VARIABLE_FRAME_SIZE)) {
> + /* 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\n", avctx->frame_size);
> + return AVERROR(EINVAL);
> + }
> +
> + if (src->nb_samples < avctx->frame_size) {
> + ret = pad_last_frame(avctx, &dst, src);
> + if (ret < 0)
> + return ret;
> +
> + avctx->internal->last_audio_frame = 1;
> + } else if (src->nb_samples > avctx->frame_size) {
> + av_log(avctx, AV_LOG_ERROR, "nb_samples (%d) != frame_size (%d)\n", dst->nb_samples, avctx->frame_size);
Should be src->nb_samples. Changed locally.
> + ret = AVERROR(EINVAL);
> + goto end;
I guess i can remove this and the label below.
> + }
> + }
> + }
> +
> + if (!dst->data[0]) {
> + ret = av_frame_ref(dst, src);
> + if (ret < 0)
> + return ret;
> + }
> +
> + return 0;
> +
> +end:
> + av_frame_unref(dst);
> +
> return ret;
> }
More information about the ffmpeg-devel
mailing list