diff mbox series

[FFmpeg-devel,v2,2/4] avcodec: add support for hevc ambient viewing environment SEI message

Message ID 1648471271-22016-2-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>
---
 libavcodec/hevc_sei.c      | 19 +++++++++++++++++++
 libavcodec/hevc_sei.h      |  8 ++++++++
 libavcodec/hevcdec.c       | 10 ++++++++++
 tests/ref/fate/hevc-dv-rpu |  6 ++++++
 4 files changed, 43 insertions(+)

Comments

Michael Niedermayer March 28, 2022, 2:30 p.m. UTC | #1
On Mon, Mar 28, 2022 at 08:41:09PM +0800, lance.lmwang@gmail.com wrote:
> From: Limin Wang <lance.lmwang@gmail.com>
> 
> Signed-off-by: Limin Wang <lance.lmwang@gmail.com>
> ---
>  libavcodec/hevc_sei.c      | 19 +++++++++++++++++++
>  libavcodec/hevc_sei.h      |  8 ++++++++
>  libavcodec/hevcdec.c       | 10 ++++++++++
>  tests/ref/fate/hevc-dv-rpu |  6 ++++++
>  4 files changed, 43 insertions(+)
> 
> diff --git a/libavcodec/hevc_sei.c b/libavcodec/hevc_sei.c
> index ec3036f..d94df4e 100644
> --- a/libavcodec/hevc_sei.c
> +++ b/libavcodec/hevc_sei.c
> @@ -497,6 +497,23 @@ static int decode_film_grain_characteristics(HEVCSEIFilmGrainCharacteristics *h,
>      return 0;
>  }
>  
> +static int decode_ambient_viewing_env(HEVCSEIAmbientViewingEnvironment *s, GetBitContext *gb, int size)
> +{
> +    if (size < 8)
> +        return AVERROR_INVALIDDATA;
> +
> +    s->ambient_illuminance  = get_bits(gb, 32);

get_bits_long

thx

[...]
Limin Wang March 28, 2022, 11:09 p.m. UTC | #2
On Mon, Mar 28, 2022 at 04:30:49PM +0200, Michael Niedermayer wrote:
> On Mon, Mar 28, 2022 at 08:41:09PM +0800, lance.lmwang@gmail.com wrote:
> > From: Limin Wang <lance.lmwang@gmail.com>
> > 
> > Signed-off-by: Limin Wang <lance.lmwang@gmail.com>
> > ---
> >  libavcodec/hevc_sei.c      | 19 +++++++++++++++++++
> >  libavcodec/hevc_sei.h      |  8 ++++++++
> >  libavcodec/hevcdec.c       | 10 ++++++++++
> >  tests/ref/fate/hevc-dv-rpu |  6 ++++++
> >  4 files changed, 43 insertions(+)
> > 
> > diff --git a/libavcodec/hevc_sei.c b/libavcodec/hevc_sei.c
> > index ec3036f..d94df4e 100644
> > --- a/libavcodec/hevc_sei.c
> > +++ b/libavcodec/hevc_sei.c
> > @@ -497,6 +497,23 @@ static int decode_film_grain_characteristics(HEVCSEIFilmGrainCharacteristics *h,
> >      return 0;
> >  }
> >  
> > +static int decode_ambient_viewing_env(HEVCSEIAmbientViewingEnvironment *s, GetBitContext *gb, int size)
> > +{
> > +    if (size < 8)
> > +        return AVERROR_INVALIDDATA;
> > +
> > +    s->ambient_illuminance  = get_bits(gb, 32);
> 
> get_bits_long

thanks, fixed it locally.

> 
> thx
> 
> [...]
> 
> -- 
> Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
> 
> Its not that you shouldnt use gotos but rather that you should write
> readable code and code with gotos often but not always is less readable



> _______________________________________________
> 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/libavcodec/hevc_sei.c b/libavcodec/hevc_sei.c
index ec3036f..d94df4e 100644
--- a/libavcodec/hevc_sei.c
+++ b/libavcodec/hevc_sei.c
@@ -497,6 +497,23 @@  static int decode_film_grain_characteristics(HEVCSEIFilmGrainCharacteristics *h,
     return 0;
 }
 
+static int decode_ambient_viewing_env(HEVCSEIAmbientViewingEnvironment *s, GetBitContext *gb, int size)
+{
+    if (size < 8)
+        return AVERROR_INVALIDDATA;
+
+    s->ambient_illuminance  = get_bits(gb, 32);
+    s->ambient_light_x      = get_bits(gb, 16);
+    s->ambient_light_y      = get_bits(gb, 16);
+    size -= 8;
+
+    s->present = 1;
+
+    skip_bits_long(gb, 8 * size);
+    return  0;
+}
+
+
 static int decode_nal_sei_prefix(GetBitContext *gb, void *logctx, HEVCSEI *s,
                                  const HEVCParamSets *ps, int type, int size)
 {
@@ -525,6 +542,8 @@  static int decode_nal_sei_prefix(GetBitContext *gb, void *logctx, HEVCSEI *s,
         return decode_nal_sei_timecode(&s->timecode, gb);
     case SEI_TYPE_FILM_GRAIN_CHARACTERISTICS:
         return decode_film_grain_characteristics(&s->film_grain_characteristics, gb);
+    case SEI_TYPE_AMBIENT_VIEWING_ENVIRONMENT:
+        return decode_ambient_viewing_env(&s->ambient_viewing_env, gb, size);
     default:
         av_log(logctx, AV_LOG_DEBUG, "Skipped PREFIX SEI %d\n", type);
         skip_bits_long(gb, 8 * size);
diff --git a/libavcodec/hevc_sei.h b/libavcodec/hevc_sei.h
index f198402..c7623f5 100644
--- a/libavcodec/hevc_sei.h
+++ b/libavcodec/hevc_sei.h
@@ -134,6 +134,13 @@  typedef struct HEVCSEIFilmGrainCharacteristics {
     int persistence_flag;
 } HEVCSEIFilmGrainCharacteristics;
 
+typedef struct HEVCSEIAmbientViewingEnvironment {
+    int present;
+    uint32_t ambient_illuminance;
+    uint16_t ambient_light_x;
+    uint16_t ambient_light_y;
+} HEVCSEIAmbientViewingEnvironment;
+
 typedef struct HEVCSEI {
     HEVCSEIPictureHash picture_hash;
     HEVCSEIFramePacking frame_packing;
@@ -149,6 +156,7 @@  typedef struct HEVCSEI {
     HEVCSEIAlternativeTransfer alternative_transfer;
     HEVCSEITimeCode timecode;
     HEVCSEIFilmGrainCharacteristics film_grain_characteristics;
+    HEVCSEIAmbientViewingEnvironment ambient_viewing_env;
 } HEVCSEI;
 
 struct HEVCParamSets;
diff --git a/libavcodec/hevcdec.c b/libavcodec/hevcdec.c
index 09c07ac..13c6642 100644
--- a/libavcodec/hevcdec.c
+++ b/libavcodec/hevcdec.c
@@ -2998,6 +2998,15 @@  static int set_side_data(HEVCContext *s)
         }
     }
 
+    if (s->sei.ambient_viewing_env.present > 0) {
+        AVAmbientViewingEnvMetadata *metadata = av_ambient_viewing_env_metadata_create_side_data(out);
+        if (!metadata)
+            return AVERROR(ENOMEM);
+        metadata->ambient_illuminance = s->sei.ambient_viewing_env.ambient_illuminance;
+        metadata->ambient_light_x = s->sei.ambient_viewing_env.ambient_light_x;
+        metadata->ambient_light_y = s->sei.ambient_viewing_env.ambient_light_y;
+    }
+
     return 0;
 }
 
@@ -3800,6 +3809,7 @@  static int hevc_update_thread_context(AVCodecContext *dst,
     s->sei.mastering_display    = s0->sei.mastering_display;
     s->sei.content_light        = s0->sei.content_light;
     s->sei.alternative_transfer = s0->sei.alternative_transfer;
+    s->sei.ambient_viewing_env  = s0->sei.ambient_viewing_env;
 
     ret = export_stream_params_from_sei(s);
     if (ret < 0)
diff --git a/tests/ref/fate/hevc-dv-rpu b/tests/ref/fate/hevc-dv-rpu
index 1980ab1..6879f71 100644
--- a/tests/ref/fate/hevc-dv-rpu
+++ b/tests/ref/fate/hevc-dv-rpu
@@ -117,6 +117,9 @@  source_min_pq=0
 source_max_pq=3079
 source_diagonal=42
 [/SIDE_DATA]
+[SIDE_DATA]
+side_data_type=Ambient Viewing Environment
+[/SIDE_DATA]
 [/FRAME]
 [FRAME]
 [SIDE_DATA]
@@ -234,4 +237,7 @@  source_min_pq=0
 source_max_pq=3079
 source_diagonal=42
 [/SIDE_DATA]
+[SIDE_DATA]
+side_data_type=Ambient Viewing Environment
+[/SIDE_DATA]
 [/FRAME]