[libav-devel] [PATCH 029/264] lavc: add codec parameters

Vittorio Giovara vittorio.giovara at gmail.com
Sat Dec 12 21:58:23 CET 2015


On Sat, Dec 12, 2015 at 3:49 PM, Anton Khirnov <anton at khirnov.net> wrote:
> ---
>  libavcodec/avcodec.h | 163 +++++++++++++++++++++++++++++++++++++++++++++++++++
>  libavcodec/utils.c   | 151 +++++++++++++++++++++++++++++++++++++++++++++++
>  2 files changed, 314 insertions(+)

version bump or are we still abi unstable?

> diff --git a/libavcodec/utils.c b/libavcodec/utils.c
> index 29ba85f..b2008b1 100644
> --- a/libavcodec/utils.c
> +++ b/libavcodec/utils.c
> @@ -2417,3 +2417,154 @@ AVCPBProperties *ff_add_cpb_side_data(AVCodecContext *avctx)
>
>      return props;
>  }
> +
> +static void codec_parameters_reset(AVCodecParameters *par)
> +{
> +    av_freep(&par->extradata);
> +
> +    memset(par, 0, sizeof(*par));
> +
> +    par->codec_type          = AVMEDIA_TYPE_UNKNOWN;
> +    par->codec_id            = AV_CODEC_ID_NONE;
> +    par->format              = -1;
> +    par->field_order         = AV_FIELD_UNKNOWN;
> +    par->color_range         = AVCOL_RANGE_UNSPECIFIED;
> +    par->color_primaries     = AVCOL_PRI_UNSPECIFIED;
> +    par->color_trc           = AVCOL_TRC_UNSPECIFIED;
> +    par->color_space         = AVCOL_SPC_UNSPECIFIED;
> +    par->chroma_location     = AVCHROMA_LOC_UNSPECIFIED;
> +    par->sample_aspect_ratio = (AVRational){ 0, 1 };
> +}
> +
> +AVCodecParameters *avcodec_parameters_alloc(void)
> +{
> +    AVCodecParameters *par = av_mallocz(sizeof(*par));

since there is a memset in _reset here a simple av_malloc could be enough

> +    if (!par)
> +        return NULL;
> +    codec_parameters_reset(par);
> +    return par;
> +}
> +
> +void avcodec_parameters_free(AVCodecParameters **ppar)
> +{
> +    AVCodecParameters *par = *ppar;
> +
> +    if (!par)
> +        return;
> +    codec_parameters_reset(par);
> +
> +    av_freep(ppar);
> +}
> +
> +int avcodec_parameters_copy(AVCodecParameters *dst, const AVCodecParameters *src)
> +{
> +    codec_parameters_reset(dst);
> +    memcpy(dst, src, sizeof(*dst));
> +
> +    dst->extradata      = NULL;
> +    dst->extradata_size = 0;
> +    if (src->extradata) {
> +        dst->extradata = av_mallocz(src->extradata_size + FF_INPUT_BUFFER_PADDING_SIZE);

AV_INPUT

> +        if (!dst->extradata)
> +            return AVERROR(ENOMEM);
> +        memcpy(dst->extradata, src->extradata, src->extradata_size);
> +        dst->extradata_size = src->extradata_size;
> +    }
> +
> +    return 0;
> +}
> +

> +    if (codec->extradata) {
> +        par->extradata = av_mallocz(codec->extradata_size + FF_INPUT_BUFFER_PADDING_SIZE);

AV_INPUT

> +        if (!par->extradata)
> +            return AVERROR(ENOMEM);
> +        memcpy(par->extradata, codec->extradata, codec->extradata_size);
> +        par->extradata_size = codec->extradata_size;
> +    }
> +
> +    return 0;
> +}
> +
> +
> +    if (par->extradata) {
> +        codec->extradata = av_mallocz(par->extradata_size + FF_INPUT_BUFFER_PADDING_SIZE);

AV_INPUT

> +        if (!codec->extradata)
> +            return AVERROR(ENOMEM);
> +        memcpy(codec->extradata, par->extradata, par->extradata_size);
> +        codec->extradata_size = par->extradata_size;
> +    }
> +
> +    return 0;
> +}

I think ok otherwise
-- 
Vittorio


More information about the libav-devel mailing list