diff mbox series

[FFmpeg-devel,v3,1/5] avutil: add ambient viewing environment metadata side data

Message ID 1649166427-9667-1-git-send-email-lance.lmwang@gmail.com
State New
Headers show
Series [FFmpeg-devel,v3,1/5] avutil: add ambient viewing environment metadata side data | expand

Checks

Context Check Description
andriy/make_x86 success Make finished
andriy/make_fate_x86 success Make fate finished

Commit Message

Limin Wang April 5, 2022, 1:47 p.m. UTC
From: Limin Wang <lance.lmwang@gmail.com>

Signed-off-by: Limin Wang <lance.lmwang@gmail.com>
---
 libavutil/frame.c                      |  1 +
 libavutil/frame.h                      |  6 +++++
 libavutil/mastering_display_metadata.c | 23 +++++++++++++++++
 libavutil/mastering_display_metadata.h | 45 ++++++++++++++++++++++++++++++++++
 libavutil/version.h                    |  2 +-
 5 files changed, 76 insertions(+), 1 deletion(-)

Comments

Andreas Rheinhardt April 5, 2022, 3:32 p.m. UTC | #1
lance.lmwang@gmail.com:
> From: Limin Wang <lance.lmwang@gmail.com>
> 
> Signed-off-by: Limin Wang <lance.lmwang@gmail.com>
> ---
>  libavutil/frame.c                      |  1 +
>  libavutil/frame.h                      |  6 +++++
>  libavutil/mastering_display_metadata.c | 23 +++++++++++++++++
>  libavutil/mastering_display_metadata.h | 45 ++++++++++++++++++++++++++++++++++
>  libavutil/version.h                    |  2 +-
>  5 files changed, 76 insertions(+), 1 deletion(-)
> 
> diff --git a/libavutil/frame.c b/libavutil/frame.c
> index fbb869f..8882da2 100644
> --- a/libavutil/frame.c
> +++ b/libavutil/frame.c
> @@ -815,6 +815,7 @@ const char *av_frame_side_data_name(enum AVFrameSideDataType type)
>      case AV_FRAME_DATA_DETECTION_BBOXES:            return "Bounding boxes for object detection and classification";
>      case AV_FRAME_DATA_DOVI_RPU_BUFFER:             return "Dolby Vision RPU Data";
>      case AV_FRAME_DATA_DOVI_METADATA:               return "Dolby Vision Metadata";
> +    case AV_FRAME_DATA_AMBIENT_VIEWING_ENV:         return "Ambient Viewing Environment";
>      }
>      return NULL;
>  }
> diff --git a/libavutil/frame.h b/libavutil/frame.h
> index 33fac20..92413c9 100644
> --- a/libavutil/frame.h
> +++ b/libavutil/frame.h
> @@ -209,6 +209,12 @@ enum AVFrameSideDataType {
>       * volume transform - CUVA 005.1-2021.
>       */
>      AV_FRAME_DATA_DYNAMIC_HDR_VIVID,
> +
> +    /**
> +     * ambient viewing environment for a video frame, as described by
> +     * the AVAmbientViewingEnv
> +     */
> +    AV_FRAME_DATA_AMBIENT_VIEWING_ENV,
>  };
>  
>  enum AVActiveFormatDescription {
> diff --git a/libavutil/mastering_display_metadata.c b/libavutil/mastering_display_metadata.c
> index 6069347..f094eab 100644
> --- a/libavutil/mastering_display_metadata.c
> +++ b/libavutil/mastering_display_metadata.c
> @@ -64,3 +64,26 @@ AVContentLightMetadata *av_content_light_metadata_create_side_data(AVFrame *fram
>  
>      return (AVContentLightMetadata *)side_data->data;
>  }
> +
> +AVAmbientViewingEnv *av_ambient_viewing_env_alloc(size_t *size)
> +{
> +    AVAmbientViewingEnv *metadata = av_mallocz(sizeof(*metadata));
> +
> +    if (size)
> +        *size = sizeof(*metadata);
> +
> +    return metadata;
> +}
> +
> +AVAmbientViewingEnv *av_ambient_viewing_env_create_side_data(AVFrame *frame)
> +{
> +    AVFrameSideData *side_data = av_frame_new_side_data(frame,
> +            AV_FRAME_DATA_AMBIENT_VIEWING_ENV,
> +            sizeof(AVAmbientViewingEnv));
> +    if (!side_data)
> +        return NULL;
> +
> +    memset(side_data->data, 0, sizeof(AVAmbientViewingEnv));
> +
> +    return (AVAmbientViewingEnv *)side_data->data;
> +}
> diff --git a/libavutil/mastering_display_metadata.h b/libavutil/mastering_display_metadata.h
> index c23b07c..c1ba659 100644
> --- a/libavutil/mastering_display_metadata.h
> +++ b/libavutil/mastering_display_metadata.h
> @@ -125,4 +125,49 @@ AVContentLightMetadata *av_content_light_metadata_alloc(size_t *size);
>   */
>  AVContentLightMetadata *av_content_light_metadata_create_side_data(AVFrame *frame);
>  
> +/**
> + * The characteristics of the nominal ambient viewing environment for
> + * the display of the associated video content.
> + * To be used as payload of a AVFrameSideData the appropriate type.
> + *
> + * @note The struct should be allocated with av_ambient_viewing_env_alloc()
> + *       and its size is not a part of the public ABI.
> + */
> +typedef struct AVAmbientViewingEnv {
> +    /**
> +     * specifies the environmental illuminance of the ambient viewing
> +     * environment in units of 0.0001 lux.
> +     * ambient_illuminance shall not be equal to 0.
> +     */
> +    uint32_t ambient_illuminance;
> +    /**
> +     * specify the normalized x and y chromaticity coordinates, respectively,
> +     * of the environmental ambient light in the nominal viewing environment,
> +     * according to the CIE 1931 definition of x and y as specified in ISO
> +     * 11664-1 (see also ISO 11664-3 and CIE 15), in normalized increments of
> +     * 0.00002. The values of ambient_light_x and ambient_light_y shall be in
> +     * the range of 0 to 50000
> +     */
> +    uint16_t ambient_light_x;
> +    uint16_t ambient_light_y;
> +} AVAmbientViewingEnv;
> +
> +/**
> + * Allocate an AVAmbientViewingEnv structure and set its fields to
> + * default values. The resulting struct can be freed using av_freep().
> + *
> + * @return An AVAmbientViewingEnv filled with default values or NULL
> + *         on failure.
> + */
> +AVAmbientViewingEnv *av_ambient_viewing_env_alloc(size_t *size);
> +
> +/**
> + * Allocate a complete AVAmbientViewingEnv and add it to the frame.
> + *
> + * @param frame The frame which side data is added to.
> + *
> + * @return The AVAmbientViewingEnv structure to be filled by caller.
> + */
> +AVAmbientViewingEnv *av_ambient_viewing_env_create_side_data(AVFrame *frame);

All this boilerplate code for the various side-data--types makes me
wonder whether they should not be replaced by something like
void *av_frame_side_data_alloc(enum AVFrameSideDataType, size_t *size)
and a corresponding av_frame_create_side_data(AVFrame *frame, enum
AVFrameSideDataType).
These functions would return an error in case it doesn't make sense to
create a side data this way (because there is no struct associated to
this side data type or because the size of this struct depends upon
other parameters, too).

> +
>  #endif /* AVUTIL_MASTERING_DISPLAY_METADATA_H */
> diff --git a/libavutil/version.h b/libavutil/version.h
> index 6735c20..998202f 100644
> --- a/libavutil/version.h
> +++ b/libavutil/version.h
> @@ -79,7 +79,7 @@
>   */
>  
>  #define LIBAVUTIL_VERSION_MAJOR  57
> -#define LIBAVUTIL_VERSION_MINOR  24
> +#define LIBAVUTIL_VERSION_MINOR  25
>  #define LIBAVUTIL_VERSION_MICRO 101

Micro needs to be reset when minor is bumped.

>  
>  #define LIBAVUTIL_VERSION_INT   AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \
Lynne April 5, 2022, 7 p.m. UTC | #2
5 Apr 2022, 17:32 by andreas.rheinhardt@outlook.com:

> lance.lmwang@gmail.com:
>
>> From: Limin Wang <lance.lmwang@gmail.com>
>>
>> Signed-off-by: Limin Wang <lance.lmwang@gmail.com>
>> ---
>>  libavutil/frame.c                      |  1 +
>>  libavutil/frame.h                      |  6 +++++
>>  libavutil/mastering_display_metadata.c | 23 +++++++++++++++++
>>  libavutil/mastering_display_metadata.h | 45 ++++++++++++++++++++++++++++++++++
>>  libavutil/version.h                    |  2 +-
>>  5 files changed, 76 insertions(+), 1 deletion(-)
>>
>> diff --git a/libavutil/frame.c b/libavutil/frame.c
>> index fbb869f..8882da2 100644
>> --- a/libavutil/frame.c
>> +++ b/libavutil/frame.c
>> @@ -815,6 +815,7 @@ const char *av_frame_side_data_name(enum AVFrameSideDataType type)
>>  case AV_FRAME_DATA_DETECTION_BBOXES:            return "Bounding boxes for object detection and classification";
>>  case AV_FRAME_DATA_DOVI_RPU_BUFFER:             return "Dolby Vision RPU Data";
>>  case AV_FRAME_DATA_DOVI_METADATA:               return "Dolby Vision Metadata";
>> +    case AV_FRAME_DATA_AMBIENT_VIEWING_ENV:         return "Ambient Viewing Environment";
>>  }
>>  return NULL;
>>  }
>> diff --git a/libavutil/frame.h b/libavutil/frame.h
>> index 33fac20..92413c9 100644
>> --- a/libavutil/frame.h
>> +++ b/libavutil/frame.h
>> @@ -209,6 +209,12 @@ enum AVFrameSideDataType {
>>  * volume transform - CUVA 005.1-2021.
>>  */
>>  AV_FRAME_DATA_DYNAMIC_HDR_VIVID,
>> +
>> +    /**
>> +     * ambient viewing environment for a video frame, as described by
>> +     * the AVAmbientViewingEnv
>> +     */
>> +    AV_FRAME_DATA_AMBIENT_VIEWING_ENV,
>>  };
>>  
>>  enum AVActiveFormatDescription {
>> diff --git a/libavutil/mastering_display_metadata.c b/libavutil/mastering_display_metadata.c
>> index 6069347..f094eab 100644
>> --- a/libavutil/mastering_display_metadata.c
>> +++ b/libavutil/mastering_display_metadata.c
>> @@ -64,3 +64,26 @@ AVContentLightMetadata *av_content_light_metadata_create_side_data(AVFrame *fram
>>  
>>  return (AVContentLightMetadata *)side_data->data;
>>  }
>> +
>> +AVAmbientViewingEnv *av_ambient_viewing_env_alloc(size_t *size)
>> +{
>> +    AVAmbientViewingEnv *metadata = av_mallocz(sizeof(*metadata));
>> +
>> +    if (size)
>> +        *size = sizeof(*metadata);
>> +
>> +    return metadata;
>> +}
>> +
>> +AVAmbientViewingEnv *av_ambient_viewing_env_create_side_data(AVFrame *frame)
>> +{
>> +    AVFrameSideData *side_data = av_frame_new_side_data(frame,
>> +            AV_FRAME_DATA_AMBIENT_VIEWING_ENV,
>> +            sizeof(AVAmbientViewingEnv));
>> +    if (!side_data)
>> +        return NULL;
>> +
>> +    memset(side_data->data, 0, sizeof(AVAmbientViewingEnv));
>> +
>> +    return (AVAmbientViewingEnv *)side_data->data;
>> +}
>> diff --git a/libavutil/mastering_display_metadata.h b/libavutil/mastering_display_metadata.h
>> index c23b07c..c1ba659 100644
>> --- a/libavutil/mastering_display_metadata.h
>> +++ b/libavutil/mastering_display_metadata.h
>> @@ -125,4 +125,49 @@ AVContentLightMetadata *av_content_light_metadata_alloc(size_t *size);
>>  */
>>  AVContentLightMetadata *av_content_light_metadata_create_side_data(AVFrame *frame);
>>  
>> +/**
>> + * The characteristics of the nominal ambient viewing environment for
>> + * the display of the associated video content.
>> + * To be used as payload of a AVFrameSideData the appropriate type.
>> + *
>> + * @note The struct should be allocated with av_ambient_viewing_env_alloc()
>> + *       and its size is not a part of the public ABI.
>> + */
>> +typedef struct AVAmbientViewingEnv {
>> +    /**
>> +     * specifies the environmental illuminance of the ambient viewing
>> +     * environment in units of 0.0001 lux.
>> +     * ambient_illuminance shall not be equal to 0.
>> +     */
>> +    uint32_t ambient_illuminance;
>> +    /**
>> +     * specify the normalized x and y chromaticity coordinates, respectively,
>> +     * of the environmental ambient light in the nominal viewing environment,
>> +     * according to the CIE 1931 definition of x and y as specified in ISO
>> +     * 11664-1 (see also ISO 11664-3 and CIE 15), in normalized increments of
>> +     * 0.00002. The values of ambient_light_x and ambient_light_y shall be in
>> +     * the range of 0 to 50000
>> +     */
>> +    uint16_t ambient_light_x;
>> +    uint16_t ambient_light_y;
>> +} AVAmbientViewingEnv;
>> +
>> +/**
>> + * Allocate an AVAmbientViewingEnv structure and set its fields to
>> + * default values. The resulting struct can be freed using av_freep().
>> + *
>> + * @return An AVAmbientViewingEnv filled with default values or NULL
>> + *         on failure.
>> + */
>> +AVAmbientViewingEnv *av_ambient_viewing_env_alloc(size_t *size);
>> +
>> +/**
>> + * Allocate a complete AVAmbientViewingEnv and add it to the frame.
>> + *
>> + * @param frame The frame which side data is added to.
>> + *
>> + * @return The AVAmbientViewingEnv structure to be filled by caller.
>> + */
>> +AVAmbientViewingEnv *av_ambient_viewing_env_create_side_data(AVFrame *frame);
>>
>
> All this boilerplate code for the various side-data--types makes me
> wonder whether they should not be replaced by something like
> void *av_frame_side_data_alloc(enum AVFrameSideDataType, size_t *size)
> and a corresponding av_frame_create_side_data(AVFrame *frame, enum
> AVFrameSideDataType).
> These functions would return an error in case it doesn't make sense to
> create a side data this way (because there is no struct associated to
> this side data type or because the size of this struct depends upon
> other parameters, too).
>

Why is this side data type allocated, rather than what used to be
the standard, making the side data struct size const? Copy-paste?

Are new fields expected to be added in the future? HDR mastering
metadata is also allocated, but we've never added any fields since
it was merged.
Anton Khirnov April 5, 2022, 7:13 p.m. UTC | #3
Quoting Lynne (2022-04-05 21:00:24)
> 5 Apr 2022, 17:32 by andreas.rheinhardt@outlook.com:
> Why is this side data type allocated, rather than what used to be
> the standard, making the side data struct size const? Copy-paste?
> 
> Are new fields expected to be added in the future? HDR mastering
> metadata is also allocated, but we've never added any fields since
> it was merged.

Better to have the option and not use it than the converse.
Andreas Rheinhardt April 5, 2022, 7:42 p.m. UTC | #4
Lynne:
> 5 Apr 2022, 17:32 by andreas.rheinhardt@outlook.com:
> 
>> lance.lmwang@gmail.com:
>>
>>> From: Limin Wang <lance.lmwang@gmail.com>
>>>
>>> Signed-off-by: Limin Wang <lance.lmwang@gmail.com>
>>> ---
>>>  libavutil/frame.c                      |  1 +
>>>  libavutil/frame.h                      |  6 +++++
>>>  libavutil/mastering_display_metadata.c | 23 +++++++++++++++++
>>>  libavutil/mastering_display_metadata.h | 45 ++++++++++++++++++++++++++++++++++
>>>  libavutil/version.h                    |  2 +-
>>>  5 files changed, 76 insertions(+), 1 deletion(-)
>>>
>>> diff --git a/libavutil/frame.c b/libavutil/frame.c
>>> index fbb869f..8882da2 100644
>>> --- a/libavutil/frame.c
>>> +++ b/libavutil/frame.c
>>> @@ -815,6 +815,7 @@ const char *av_frame_side_data_name(enum AVFrameSideDataType type)
>>>  case AV_FRAME_DATA_DETECTION_BBOXES:            return "Bounding boxes for object detection and classification";
>>>  case AV_FRAME_DATA_DOVI_RPU_BUFFER:             return "Dolby Vision RPU Data";
>>>  case AV_FRAME_DATA_DOVI_METADATA:               return "Dolby Vision Metadata";
>>> +    case AV_FRAME_DATA_AMBIENT_VIEWING_ENV:         return "Ambient Viewing Environment";
>>>  }
>>>  return NULL;
>>>  }
>>> diff --git a/libavutil/frame.h b/libavutil/frame.h
>>> index 33fac20..92413c9 100644
>>> --- a/libavutil/frame.h
>>> +++ b/libavutil/frame.h
>>> @@ -209,6 +209,12 @@ enum AVFrameSideDataType {
>>>  * volume transform - CUVA 005.1-2021.
>>>  */
>>>  AV_FRAME_DATA_DYNAMIC_HDR_VIVID,
>>> +
>>> +    /**
>>> +     * ambient viewing environment for a video frame, as described by
>>> +     * the AVAmbientViewingEnv
>>> +     */
>>> +    AV_FRAME_DATA_AMBIENT_VIEWING_ENV,
>>>  };
>>>  
>>>  enum AVActiveFormatDescription {
>>> diff --git a/libavutil/mastering_display_metadata.c b/libavutil/mastering_display_metadata.c
>>> index 6069347..f094eab 100644
>>> --- a/libavutil/mastering_display_metadata.c
>>> +++ b/libavutil/mastering_display_metadata.c
>>> @@ -64,3 +64,26 @@ AVContentLightMetadata *av_content_light_metadata_create_side_data(AVFrame *fram
>>>  
>>>  return (AVContentLightMetadata *)side_data->data;
>>>  }
>>> +
>>> +AVAmbientViewingEnv *av_ambient_viewing_env_alloc(size_t *size)
>>> +{
>>> +    AVAmbientViewingEnv *metadata = av_mallocz(sizeof(*metadata));
>>> +
>>> +    if (size)
>>> +        *size = sizeof(*metadata);
>>> +
>>> +    return metadata;
>>> +}
>>> +
>>> +AVAmbientViewingEnv *av_ambient_viewing_env_create_side_data(AVFrame *frame)
>>> +{
>>> +    AVFrameSideData *side_data = av_frame_new_side_data(frame,
>>> +            AV_FRAME_DATA_AMBIENT_VIEWING_ENV,
>>> +            sizeof(AVAmbientViewingEnv));
>>> +    if (!side_data)
>>> +        return NULL;
>>> +
>>> +    memset(side_data->data, 0, sizeof(AVAmbientViewingEnv));
>>> +
>>> +    return (AVAmbientViewingEnv *)side_data->data;
>>> +}
>>> diff --git a/libavutil/mastering_display_metadata.h b/libavutil/mastering_display_metadata.h
>>> index c23b07c..c1ba659 100644
>>> --- a/libavutil/mastering_display_metadata.h
>>> +++ b/libavutil/mastering_display_metadata.h
>>> @@ -125,4 +125,49 @@ AVContentLightMetadata *av_content_light_metadata_alloc(size_t *size);
>>>  */
>>>  AVContentLightMetadata *av_content_light_metadata_create_side_data(AVFrame *frame);
>>>  
>>> +/**
>>> + * The characteristics of the nominal ambient viewing environment for
>>> + * the display of the associated video content.
>>> + * To be used as payload of a AVFrameSideData the appropriate type.
>>> + *
>>> + * @note The struct should be allocated with av_ambient_viewing_env_alloc()
>>> + *       and its size is not a part of the public ABI.
>>> + */
>>> +typedef struct AVAmbientViewingEnv {
>>> +    /**
>>> +     * specifies the environmental illuminance of the ambient viewing
>>> +     * environment in units of 0.0001 lux.
>>> +     * ambient_illuminance shall not be equal to 0.
>>> +     */
>>> +    uint32_t ambient_illuminance;
>>> +    /**
>>> +     * specify the normalized x and y chromaticity coordinates, respectively,
>>> +     * of the environmental ambient light in the nominal viewing environment,
>>> +     * according to the CIE 1931 definition of x and y as specified in ISO
>>> +     * 11664-1 (see also ISO 11664-3 and CIE 15), in normalized increments of
>>> +     * 0.00002. The values of ambient_light_x and ambient_light_y shall be in
>>> +     * the range of 0 to 50000
>>> +     */
>>> +    uint16_t ambient_light_x;
>>> +    uint16_t ambient_light_y;
>>> +} AVAmbientViewingEnv;
>>> +
>>> +/**
>>> + * Allocate an AVAmbientViewingEnv structure and set its fields to
>>> + * default values. The resulting struct can be freed using av_freep().
>>> + *
>>> + * @return An AVAmbientViewingEnv filled with default values or NULL
>>> + *         on failure.
>>> + */
>>> +AVAmbientViewingEnv *av_ambient_viewing_env_alloc(size_t *size);
>>> +
>>> +/**
>>> + * Allocate a complete AVAmbientViewingEnv and add it to the frame.
>>> + *
>>> + * @param frame The frame which side data is added to.
>>> + *
>>> + * @return The AVAmbientViewingEnv structure to be filled by caller.
>>> + */
>>> +AVAmbientViewingEnv *av_ambient_viewing_env_create_side_data(AVFrame *frame);
>>>
>>
>> All this boilerplate code for the various side-data--types makes me
>> wonder whether they should not be replaced by something like
>> void *av_frame_side_data_alloc(enum AVFrameSideDataType, size_t *size)
>> and a corresponding av_frame_create_side_data(AVFrame *frame, enum
>> AVFrameSideDataType).
>> These functions would return an error in case it doesn't make sense to
>> create a side data this way (because there is no struct associated to
>> this side data type or because the size of this struct depends upon
>> other parameters, too).
>>
> 
> Why is this side data type allocated, rather than what used to be
> the standard, making the side data struct size const? Copy-paste?
> 
> Are new fields expected to be added in the future? HDR mastering
> metadata is also allocated, but we've never added any fields since
> it was merged.

With "const" you mean make the size part of the ABI? Well, given that
side-data is always allocated, it doesn't really hurt to make the size
of these fields not part of the ABI.
(There are cases where this is not so: sizeof(AVBufferRef) not being
part of the public ABI means that every av_buffer_ref() has an
allocation and therefore needs to be checked. No addition to AVBufferRef
has ever been made.)

- Andreas
Limin Wang April 5, 2022, 11:11 p.m. UTC | #5
On Tue, Apr 05, 2022 at 05:32:12PM +0200, Andreas Rheinhardt wrote:
> lance.lmwang@gmail.com:
> > From: Limin Wang <lance.lmwang@gmail.com>
> > 
> > Signed-off-by: Limin Wang <lance.lmwang@gmail.com>
> > ---
> >  libavutil/frame.c                      |  1 +
> >  libavutil/frame.h                      |  6 +++++
> >  libavutil/mastering_display_metadata.c | 23 +++++++++++++++++
> >  libavutil/mastering_display_metadata.h | 45 ++++++++++++++++++++++++++++++++++
> >  libavutil/version.h                    |  2 +-
> >  5 files changed, 76 insertions(+), 1 deletion(-)
> > 
> > diff --git a/libavutil/frame.c b/libavutil/frame.c
> > index fbb869f..8882da2 100644
> > --- a/libavutil/frame.c
> > +++ b/libavutil/frame.c
> > @@ -815,6 +815,7 @@ const char *av_frame_side_data_name(enum AVFrameSideDataType type)
> >      case AV_FRAME_DATA_DETECTION_BBOXES:            return "Bounding boxes for object detection and classification";
> >      case AV_FRAME_DATA_DOVI_RPU_BUFFER:             return "Dolby Vision RPU Data";
> >      case AV_FRAME_DATA_DOVI_METADATA:               return "Dolby Vision Metadata";
> > +    case AV_FRAME_DATA_AMBIENT_VIEWING_ENV:         return "Ambient Viewing Environment";
> >      }
> >      return NULL;
> >  }
> > diff --git a/libavutil/frame.h b/libavutil/frame.h
> > index 33fac20..92413c9 100644
> > --- a/libavutil/frame.h
> > +++ b/libavutil/frame.h
> > @@ -209,6 +209,12 @@ enum AVFrameSideDataType {
> >       * volume transform - CUVA 005.1-2021.
> >       */
> >      AV_FRAME_DATA_DYNAMIC_HDR_VIVID,
> > +
> > +    /**
> > +     * ambient viewing environment for a video frame, as described by
> > +     * the AVAmbientViewingEnv
> > +     */
> > +    AV_FRAME_DATA_AMBIENT_VIEWING_ENV,
> >  };
> >  
> >  enum AVActiveFormatDescription {
> > diff --git a/libavutil/mastering_display_metadata.c b/libavutil/mastering_display_metadata.c
> > index 6069347..f094eab 100644
> > --- a/libavutil/mastering_display_metadata.c
> > +++ b/libavutil/mastering_display_metadata.c
> > @@ -64,3 +64,26 @@ AVContentLightMetadata *av_content_light_metadata_create_side_data(AVFrame *fram
> >  
> >      return (AVContentLightMetadata *)side_data->data;
> >  }
> > +
> > +AVAmbientViewingEnv *av_ambient_viewing_env_alloc(size_t *size)
> > +{
> > +    AVAmbientViewingEnv *metadata = av_mallocz(sizeof(*metadata));
> > +
> > +    if (size)
> > +        *size = sizeof(*metadata);
> > +
> > +    return metadata;
> > +}
> > +
> > +AVAmbientViewingEnv *av_ambient_viewing_env_create_side_data(AVFrame *frame)
> > +{
> > +    AVFrameSideData *side_data = av_frame_new_side_data(frame,
> > +            AV_FRAME_DATA_AMBIENT_VIEWING_ENV,
> > +            sizeof(AVAmbientViewingEnv));
> > +    if (!side_data)
> > +        return NULL;
> > +
> > +    memset(side_data->data, 0, sizeof(AVAmbientViewingEnv));
> > +
> > +    return (AVAmbientViewingEnv *)side_data->data;
> > +}
> > diff --git a/libavutil/mastering_display_metadata.h b/libavutil/mastering_display_metadata.h
> > index c23b07c..c1ba659 100644
> > --- a/libavutil/mastering_display_metadata.h
> > +++ b/libavutil/mastering_display_metadata.h
> > @@ -125,4 +125,49 @@ AVContentLightMetadata *av_content_light_metadata_alloc(size_t *size);
> >   */
> >  AVContentLightMetadata *av_content_light_metadata_create_side_data(AVFrame *frame);
> >  
> > +/**
> > + * The characteristics of the nominal ambient viewing environment for
> > + * the display of the associated video content.
> > + * To be used as payload of a AVFrameSideData the appropriate type.
> > + *
> > + * @note The struct should be allocated with av_ambient_viewing_env_alloc()
> > + *       and its size is not a part of the public ABI.
> > + */
> > +typedef struct AVAmbientViewingEnv {
> > +    /**
> > +     * specifies the environmental illuminance of the ambient viewing
> > +     * environment in units of 0.0001 lux.
> > +     * ambient_illuminance shall not be equal to 0.
> > +     */
> > +    uint32_t ambient_illuminance;
> > +    /**
> > +     * specify the normalized x and y chromaticity coordinates, respectively,
> > +     * of the environmental ambient light in the nominal viewing environment,
> > +     * according to the CIE 1931 definition of x and y as specified in ISO
> > +     * 11664-1 (see also ISO 11664-3 and CIE 15), in normalized increments of
> > +     * 0.00002. The values of ambient_light_x and ambient_light_y shall be in
> > +     * the range of 0 to 50000
> > +     */
> > +    uint16_t ambient_light_x;
> > +    uint16_t ambient_light_y;
> > +} AVAmbientViewingEnv;
> > +
> > +/**
> > + * Allocate an AVAmbientViewingEnv structure and set its fields to
> > + * default values. The resulting struct can be freed using av_freep().
> > + *
> > + * @return An AVAmbientViewingEnv filled with default values or NULL
> > + *         on failure.
> > + */
> > +AVAmbientViewingEnv *av_ambient_viewing_env_alloc(size_t *size);
> > +
> > +/**
> > + * Allocate a complete AVAmbientViewingEnv and add it to the frame.
> > + *
> > + * @param frame The frame which side data is added to.
> > + *
> > + * @return The AVAmbientViewingEnv structure to be filled by caller.
> > + */
> > +AVAmbientViewingEnv *av_ambient_viewing_env_create_side_data(AVFrame *frame);
> 
> All this boilerplate code for the various side-data--types makes me
> wonder whether they should not be replaced by something like
> void *av_frame_side_data_alloc(enum AVFrameSideDataType, size_t *size)
> and a corresponding av_frame_create_side_data(AVFrame *frame, enum
> AVFrameSideDataType).

It's good idea to have them? please add them anyway, I'll pending the patch
until it's ready to use.

> These functions would return an error in case it doesn't make sense to
> create a side data this way (because there is no struct associated to
> this side data type or because the size of this struct depends upon
> other parameters, too).
> 
> > +
> >  #endif /* AVUTIL_MASTERING_DISPLAY_METADATA_H */
> > diff --git a/libavutil/version.h b/libavutil/version.h
> > index 6735c20..998202f 100644
> > --- a/libavutil/version.h
> > +++ b/libavutil/version.h
> > @@ -79,7 +79,7 @@
> >   */
> >  
> >  #define LIBAVUTIL_VERSION_MAJOR  57
> > -#define LIBAVUTIL_VERSION_MINOR  24
> > +#define LIBAVUTIL_VERSION_MINOR  25
> >  #define LIBAVUTIL_VERSION_MICRO 101
> 
> Micro needs to be reset when minor is bumped.

OK, forgot to reset it.

> 
> >  
> >  #define LIBAVUTIL_VERSION_INT   AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \
> 
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
> 
> To unsubscribe, visit link above, or email
> ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
diff mbox series

Patch

diff --git a/libavutil/frame.c b/libavutil/frame.c
index fbb869f..8882da2 100644
--- a/libavutil/frame.c
+++ b/libavutil/frame.c
@@ -815,6 +815,7 @@  const char *av_frame_side_data_name(enum AVFrameSideDataType type)
     case AV_FRAME_DATA_DETECTION_BBOXES:            return "Bounding boxes for object detection and classification";
     case AV_FRAME_DATA_DOVI_RPU_BUFFER:             return "Dolby Vision RPU Data";
     case AV_FRAME_DATA_DOVI_METADATA:               return "Dolby Vision Metadata";
+    case AV_FRAME_DATA_AMBIENT_VIEWING_ENV:         return "Ambient Viewing Environment";
     }
     return NULL;
 }
diff --git a/libavutil/frame.h b/libavutil/frame.h
index 33fac20..92413c9 100644
--- a/libavutil/frame.h
+++ b/libavutil/frame.h
@@ -209,6 +209,12 @@  enum AVFrameSideDataType {
      * volume transform - CUVA 005.1-2021.
      */
     AV_FRAME_DATA_DYNAMIC_HDR_VIVID,
+
+    /**
+     * ambient viewing environment for a video frame, as described by
+     * the AVAmbientViewingEnv
+     */
+    AV_FRAME_DATA_AMBIENT_VIEWING_ENV,
 };
 
 enum AVActiveFormatDescription {
diff --git a/libavutil/mastering_display_metadata.c b/libavutil/mastering_display_metadata.c
index 6069347..f094eab 100644
--- a/libavutil/mastering_display_metadata.c
+++ b/libavutil/mastering_display_metadata.c
@@ -64,3 +64,26 @@  AVContentLightMetadata *av_content_light_metadata_create_side_data(AVFrame *fram
 
     return (AVContentLightMetadata *)side_data->data;
 }
+
+AVAmbientViewingEnv *av_ambient_viewing_env_alloc(size_t *size)
+{
+    AVAmbientViewingEnv *metadata = av_mallocz(sizeof(*metadata));
+
+    if (size)
+        *size = sizeof(*metadata);
+
+    return metadata;
+}
+
+AVAmbientViewingEnv *av_ambient_viewing_env_create_side_data(AVFrame *frame)
+{
+    AVFrameSideData *side_data = av_frame_new_side_data(frame,
+            AV_FRAME_DATA_AMBIENT_VIEWING_ENV,
+            sizeof(AVAmbientViewingEnv));
+    if (!side_data)
+        return NULL;
+
+    memset(side_data->data, 0, sizeof(AVAmbientViewingEnv));
+
+    return (AVAmbientViewingEnv *)side_data->data;
+}
diff --git a/libavutil/mastering_display_metadata.h b/libavutil/mastering_display_metadata.h
index c23b07c..c1ba659 100644
--- a/libavutil/mastering_display_metadata.h
+++ b/libavutil/mastering_display_metadata.h
@@ -125,4 +125,49 @@  AVContentLightMetadata *av_content_light_metadata_alloc(size_t *size);
  */
 AVContentLightMetadata *av_content_light_metadata_create_side_data(AVFrame *frame);
 
+/**
+ * The characteristics of the nominal ambient viewing environment for
+ * the display of the associated video content.
+ * To be used as payload of a AVFrameSideData the appropriate type.
+ *
+ * @note The struct should be allocated with av_ambient_viewing_env_alloc()
+ *       and its size is not a part of the public ABI.
+ */
+typedef struct AVAmbientViewingEnv {
+    /**
+     * specifies the environmental illuminance of the ambient viewing
+     * environment in units of 0.0001 lux.
+     * ambient_illuminance shall not be equal to 0.
+     */
+    uint32_t ambient_illuminance;
+    /**
+     * specify the normalized x and y chromaticity coordinates, respectively,
+     * of the environmental ambient light in the nominal viewing environment,
+     * according to the CIE 1931 definition of x and y as specified in ISO
+     * 11664-1 (see also ISO 11664-3 and CIE 15), in normalized increments of
+     * 0.00002. The values of ambient_light_x and ambient_light_y shall be in
+     * the range of 0 to 50000
+     */
+    uint16_t ambient_light_x;
+    uint16_t ambient_light_y;
+} AVAmbientViewingEnv;
+
+/**
+ * Allocate an AVAmbientViewingEnv structure and set its fields to
+ * default values. The resulting struct can be freed using av_freep().
+ *
+ * @return An AVAmbientViewingEnv filled with default values or NULL
+ *         on failure.
+ */
+AVAmbientViewingEnv *av_ambient_viewing_env_alloc(size_t *size);
+
+/**
+ * Allocate a complete AVAmbientViewingEnv and add it to the frame.
+ *
+ * @param frame The frame which side data is added to.
+ *
+ * @return The AVAmbientViewingEnv structure to be filled by caller.
+ */
+AVAmbientViewingEnv *av_ambient_viewing_env_create_side_data(AVFrame *frame);
+
 #endif /* AVUTIL_MASTERING_DISPLAY_METADATA_H */
diff --git a/libavutil/version.h b/libavutil/version.h
index 6735c20..998202f 100644
--- a/libavutil/version.h
+++ b/libavutil/version.h
@@ -79,7 +79,7 @@ 
  */
 
 #define LIBAVUTIL_VERSION_MAJOR  57
-#define LIBAVUTIL_VERSION_MINOR  24
+#define LIBAVUTIL_VERSION_MINOR  25
 #define LIBAVUTIL_VERSION_MICRO 101
 
 #define LIBAVUTIL_VERSION_INT   AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \