diff mbox series

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

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

Commit Message

Limin Wang March 28, 2022, 12:41 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 ++++++++++++++++++++++++++++++++++
 4 files changed, 75 insertions(+)

Comments

Limin Wang April 5, 2022, 6:40 a.m. UTC | #1
On Mon, Mar 28, 2022 at 08:41:08PM +0800, lance.lmwang@gmail.com wrote:
> 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 ++++++++++++++++++++++++++++++++++
>  4 files changed, 75 insertions(+)
> 
> 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..f7b1d4e 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 AVAmbientViewingEnvMetadata.
> +     */
> +    AV_FRAME_DATA_AMBIENT_VIEWING_ENV,
>  };
>  
>  enum AVActiveFormatDescription {
> diff --git a/libavutil/mastering_display_metadata.c b/libavutil/mastering_display_metadata.c
> index 6069347..ba1c80f 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;
>  }
> +
> +AVAmbientViewingEnvMetadata *av_ambient_viewing_env_metadata_alloc(size_t *size)
> +{
> +    AVAmbientViewingEnvMetadata *metadata = av_mallocz(sizeof(*metadata));
> +
> +    if (size)
> +        *size = sizeof(*metadata);
> +
> +    return metadata;
> +}
> +
> +AVAmbientViewingEnvMetadata *av_ambient_viewing_env_metadata_create_side_data(AVFrame *frame)
> +{
> +    AVFrameSideData *side_data = av_frame_new_side_data(frame,
> +            AV_FRAME_DATA_AMBIENT_VIEWING_ENV,
> +            sizeof(AVAmbientViewingEnvMetadata));
> +    if (!side_data)
> +        return NULL;
> +
> +    memset(side_data->data, 0, sizeof(AVAmbientViewingEnvMetadata));
> +
> +    return (AVAmbientViewingEnvMetadata *)side_data->data;
> +}
> diff --git a/libavutil/mastering_display_metadata.h b/libavutil/mastering_display_metadata.h
> index c23b07c..d7598c1 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_metadata_alloc()
> + *       and its size is not a part of the public ABI.
> + */
> +typedef struct AVAmbientViewingEnvMetadata {
> +    /**
> +     * 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;
> +} AVAmbientViewingEnvMetadata;
> +
> +/**
> + * Allocate an AVAmbientViewingEnvMetadata structure and set its fields to
> + * default values. The resulting struct can be freed using av_freep().
> + *
> + * @return An AVAmbientViewingEnvMetadata filled with default values or NULL
> + *         on failure.
> + */
> +AVAmbientViewingEnvMetadata *av_ambient_viewing_env_metadata_alloc(size_t *size);
> +
> +/**
> + * Allocate a complete AVAmbientViewingEnvMetadata and add it to the frame.
> + *
> + * @param frame The frame which side data is added to.
> + *
> + * @return The AVAmbientViewingEnvMetadata structure to be filled by caller.
> + */
> +AVAmbientViewingEnvMetadata *av_ambient_viewing_env_metadata_create_side_data(AVFrame *frame);
> +
>  #endif /* AVUTIL_MASTERING_DISPLAY_METADATA_H */
> -- 
> 1.8.3.1
> 

will apply the patch set(with bump version and one local fixed for
get_bits_long) tomorrow if no more comments.
Anton Khirnov April 5, 2022, 9:13 a.m. UTC | #2
Quoting lance.lmwang@gmail.com (2022-03-28 14:41:08)
> 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 ++++++++++++++++++++++++++++++++++
>  4 files changed, 75 insertions(+)
> 
> 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..f7b1d4e 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 AVAmbientViewingEnvMetadata.
> +     */
> +    AV_FRAME_DATA_AMBIENT_VIEWING_ENV,
>  };
>  
>  enum AVActiveFormatDescription {
> diff --git a/libavutil/mastering_display_metadata.c b/libavutil/mastering_display_metadata.c
> index 6069347..ba1c80f 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;
>  }
> +
> +AVAmbientViewingEnvMetadata *av_ambient_viewing_env_metadata_alloc(size_t *size)
> +{
> +    AVAmbientViewingEnvMetadata *metadata = av_mallocz(sizeof(*metadata));
> +
> +    if (size)
> +        *size = sizeof(*metadata);
> +
> +    return metadata;
> +}
> +
> +AVAmbientViewingEnvMetadata *av_ambient_viewing_env_metadata_create_side_data(AVFrame *frame)
> +{
> +    AVFrameSideData *side_data = av_frame_new_side_data(frame,
> +            AV_FRAME_DATA_AMBIENT_VIEWING_ENV,
> +            sizeof(AVAmbientViewingEnvMetadata));
> +    if (!side_data)
> +        return NULL;
> +
> +    memset(side_data->data, 0, sizeof(AVAmbientViewingEnvMetadata));
> +
> +    return (AVAmbientViewingEnvMetadata *)side_data->data;
> +}
> diff --git a/libavutil/mastering_display_metadata.h b/libavutil/mastering_display_metadata.h
> index c23b07c..d7598c1 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 names are horribly long. I would suggest dropping 'metadata' from
the struct and function names, they'd be shorter and no information is
really lost.
Limin Wang April 5, 2022, 9:24 a.m. UTC | #3
On Tue, Apr 05, 2022 at 11:13:12AM +0200, Anton Khirnov wrote:
> Quoting lance.lmwang@gmail.com (2022-03-28 14:41:08)
> > 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 ++++++++++++++++++++++++++++++++++
> >  4 files changed, 75 insertions(+)
> > 
> > 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..f7b1d4e 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 AVAmbientViewingEnvMetadata.
> > +     */
> > +    AV_FRAME_DATA_AMBIENT_VIEWING_ENV,
> >  };
> >  
> >  enum AVActiveFormatDescription {
> > diff --git a/libavutil/mastering_display_metadata.c b/libavutil/mastering_display_metadata.c
> > index 6069347..ba1c80f 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;
> >  }
> > +
> > +AVAmbientViewingEnvMetadata *av_ambient_viewing_env_metadata_alloc(size_t *size)
> > +{
> > +    AVAmbientViewingEnvMetadata *metadata = av_mallocz(sizeof(*metadata));
> > +
> > +    if (size)
> > +        *size = sizeof(*metadata);
> > +
> > +    return metadata;
> > +}
> > +
> > +AVAmbientViewingEnvMetadata *av_ambient_viewing_env_metadata_create_side_data(AVFrame *frame)
> > +{
> > +    AVFrameSideData *side_data = av_frame_new_side_data(frame,
> > +            AV_FRAME_DATA_AMBIENT_VIEWING_ENV,
> > +            sizeof(AVAmbientViewingEnvMetadata));
> > +    if (!side_data)
> > +        return NULL;
> > +
> > +    memset(side_data->data, 0, sizeof(AVAmbientViewingEnvMetadata));
> > +
> > +    return (AVAmbientViewingEnvMetadata *)side_data->data;
> > +}
> > diff --git a/libavutil/mastering_display_metadata.h b/libavutil/mastering_display_metadata.h
> > index c23b07c..d7598c1 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 names are horribly long. I would suggest dropping 'metadata' from
> the struct and function names, they'd be shorter and no information is
> really lost.

I'm OK with the suggestion, will update the patch, thanks. 

> 
> -- 
> Anton Khirnov
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..f7b1d4e 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 AVAmbientViewingEnvMetadata.
+     */
+    AV_FRAME_DATA_AMBIENT_VIEWING_ENV,
 };
 
 enum AVActiveFormatDescription {
diff --git a/libavutil/mastering_display_metadata.c b/libavutil/mastering_display_metadata.c
index 6069347..ba1c80f 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;
 }
+
+AVAmbientViewingEnvMetadata *av_ambient_viewing_env_metadata_alloc(size_t *size)
+{
+    AVAmbientViewingEnvMetadata *metadata = av_mallocz(sizeof(*metadata));
+
+    if (size)
+        *size = sizeof(*metadata);
+
+    return metadata;
+}
+
+AVAmbientViewingEnvMetadata *av_ambient_viewing_env_metadata_create_side_data(AVFrame *frame)
+{
+    AVFrameSideData *side_data = av_frame_new_side_data(frame,
+            AV_FRAME_DATA_AMBIENT_VIEWING_ENV,
+            sizeof(AVAmbientViewingEnvMetadata));
+    if (!side_data)
+        return NULL;
+
+    memset(side_data->data, 0, sizeof(AVAmbientViewingEnvMetadata));
+
+    return (AVAmbientViewingEnvMetadata *)side_data->data;
+}
diff --git a/libavutil/mastering_display_metadata.h b/libavutil/mastering_display_metadata.h
index c23b07c..d7598c1 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_metadata_alloc()
+ *       and its size is not a part of the public ABI.
+ */
+typedef struct AVAmbientViewingEnvMetadata {
+    /**
+     * 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;
+} AVAmbientViewingEnvMetadata;
+
+/**
+ * Allocate an AVAmbientViewingEnvMetadata structure and set its fields to
+ * default values. The resulting struct can be freed using av_freep().
+ *
+ * @return An AVAmbientViewingEnvMetadata filled with default values or NULL
+ *         on failure.
+ */
+AVAmbientViewingEnvMetadata *av_ambient_viewing_env_metadata_alloc(size_t *size);
+
+/**
+ * Allocate a complete AVAmbientViewingEnvMetadata and add it to the frame.
+ *
+ * @param frame The frame which side data is added to.
+ *
+ * @return The AVAmbientViewingEnvMetadata structure to be filled by caller.
+ */
+AVAmbientViewingEnvMetadata *av_ambient_viewing_env_metadata_create_side_data(AVFrame *frame);
+
 #endif /* AVUTIL_MASTERING_DISPLAY_METADATA_H */