[FFmpeg-devel] [PATCH v5 4/6] lavc: Implement Dolby Vision RPU parsing

Anton Khirnov anton at khirnov.net
Mon Dec 20 12:13:15 EET 2021


Quoting Niklas Haas (2021-12-12 12:55:44)
> +void ff_dovi_ctx_unref(DOVIContext *s)
> +{
> +    for (int i = 0; i < DOVI_MAX_DM_ID; i++)

nit: FF_ARRAY_ELEMS(s->vdr_ref) is considered better

> +        av_buffer_unref(&s->vdr_ref[i]);
> +
> +    /* Preserve the user-provided fields explicitly, reset everything else */
> +    *s = (DOVIContext) {
> +        .avctx = s->avctx,
> +        .config = s->config,
> +    };
> +}
> +
> +int ff_dovi_ctx_replace(DOVIContext *s, const DOVIContext *s0)
> +{
> +    int ret;
> +    s->avctx = s0->avctx;
> +    s->config = s0->config;
> +    s->mapping = s0->mapping;
> +    s->color = s0->color;
> +    for (int i = 0; i < DOVI_MAX_DM_ID; i++) {
> +        if ((ret = av_buffer_replace(&s->vdr_ref[i], s0->vdr_ref[i])) < 0)
> +            goto fail;
> +    }
> +
> +    return 0;
> +
> +fail:
> +    /* clean up any potentially invalid pointers */

Would not calling ff_dovi_ctx_unref() be safer here?

> +    s->mapping = NULL;
> +    s->color = NULL;
> +    return ret;
> +}
> [...]
> diff --git a/libavcodec/dovi_rpu.h b/libavcodec/dovi_rpu.h
> new file mode 100644
> index 0000000000..8cabff2718
> --- /dev/null
> +++ b/libavcodec/dovi_rpu.h
> @@ -0,0 +1,71 @@
> +/*
> + * Dolby Vision RPU decoder
> + *
> + * Copyright (C) 2021 Jan Ekström
> + * Copyright (C) 2021 Niklas Haas
> + *
> + * This file is part of FFmpeg.
> + *
> + * 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.
> + *
> + * 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 FFmpeg; if not, write to the Free Software
> + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
> + */
> +
> +#ifndef AVCODEC_DOVI_RPU_H
> +#define AVCODEC_DOVI_RPU_H
> +
> +#include "libavutil/dovi_meta.h"
> +#include "avcodec.h"
> +
> +#define DOVI_MAX_DM_ID 15
> +typedef struct DOVIContext {
> +    AVCodecContext *avctx;

This is only used for logging (as it should be), so you can make this
void *logctx and drop the avcodec.h #include.

-- 
Anton Khirnov


More information about the ffmpeg-devel mailing list