[FFmpeg-devel] [PATCH v3 2/5] avcodec: add support for hevc ambient viewing environment SEI message

lance.lmwang at gmail.com lance.lmwang at gmail.com
Tue Apr 5 16:47:04 EEST 2022


From: Limin Wang <lance.lmwang at gmail.com>

Signed-off-by: Limin Wang <lance.lmwang at 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..8c6daf5 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_long(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..21ed579 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) {
+        AVAmbientViewingEnv *metadata = av_ambient_viewing_env_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]
-- 
1.8.3.1



More information about the ffmpeg-devel mailing list