avcodec/cbs_h265: add support for Alpha Channel Info SEI messages
authorJames Almer <jamrial@gmail.com>
Fri, 21 Jun 2019 01:21:26 +0000 (22:21 -0300)
committerJames Almer <jamrial@gmail.com>
Sat, 20 Jul 2019 14:28:09 +0000 (11:28 -0300)
As defined in sections F.14.2.8 and F.14.3.8

Reviewed-by: Mark Thompson <sw@jkqxz.net>
Signed-off-by: James Almer <jamrial@gmail.com>
libavcodec/cbs_h2645.c
libavcodec/cbs_h265.h
libavcodec/cbs_h265_syntax_template.c
libavcodec/hevc_sei.h

index b09845b..c95f130 100644 (file)
@@ -531,6 +531,7 @@ static void cbs_h265_free_sei_payload(H265RawSEIPayload *payload)
     case HEVC_SEI_TYPE_MASTERING_DISPLAY_INFO:
     case HEVC_SEI_TYPE_CONTENT_LIGHT_LEVEL_INFO:
     case HEVC_SEI_TYPE_ALTERNATIVE_TRANSFER_CHARACTERISTICS:
+    case HEVC_SEI_TYPE_ALPHA_CHANNEL_INFO:
         break;
     case HEVC_SEI_TYPE_USER_DATA_REGISTERED_ITU_T_T35:
         av_buffer_unref(&payload->payload.user_data_registered.data_ref);
index c9bc901..ad746bf 100644 (file)
@@ -679,6 +679,17 @@ typedef struct H265RawSEIAlternativeTransferCharacteristics {
     uint8_t preferred_transfer_characteristics;
 } H265RawSEIAlternativeTransferCharacteristics;
 
+typedef struct H265RawSEIAlphaChannelInfo {
+    uint8_t  alpha_channel_cancel_flag;
+    uint8_t  alpha_channel_use_idc;
+    uint8_t  alpha_channel_bit_depth_minus8;
+    uint16_t alpha_transparent_value;
+    uint16_t alpha_opaque_value;
+    uint8_t  alpha_channel_incr_flag;
+    uint8_t  alpha_channel_clip_flag;
+    uint8_t  alpha_channel_clip_type_flag;
+} H265RawSEIAlphaChannelInfo;
+
 typedef struct H265RawSEIPayload {
     uint32_t payload_type;
     uint32_t payload_size;
@@ -697,6 +708,7 @@ typedef struct H265RawSEIPayload {
         H265RawSEIContentLightLevelInfo content_light_level;
         H265RawSEIAlternativeTransferCharacteristics
             alternative_transfer_characteristics;
+        H265RawSEIAlphaChannelInfo alpha_channel_info;
         struct {
             uint8_t *data;
             size_t data_length;
index f279d28..5457092 100644 (file)
@@ -2028,6 +2028,34 @@ static int FUNC(sei_alternative_transfer_characteristics)(CodedBitstreamContext
     return 0;
 }
 
+static int FUNC(sei_alpha_channel_info)(CodedBitstreamContext *ctx,
+                                        RWContext *rw,
+                                        H265RawSEIAlphaChannelInfo *current)
+{
+    int err, length;
+
+    HEADER("Alpha Channel Information");
+
+    flag(alpha_channel_cancel_flag);
+    if (!current->alpha_channel_cancel_flag) {
+        ub(3, alpha_channel_use_idc);
+        ub(3, alpha_channel_bit_depth_minus8);
+        length = current->alpha_channel_bit_depth_minus8 + 9;
+        ub(length, alpha_transparent_value);
+        ub(length, alpha_opaque_value);
+        flag(alpha_channel_incr_flag);
+        flag(alpha_channel_clip_flag);
+        if (current->alpha_channel_clip_flag)
+            flag(alpha_channel_clip_type_flag);
+    } else {
+       infer(alpha_channel_use_idc,   2);
+       infer(alpha_channel_incr_flag, 0);
+       infer(alpha_channel_clip_flag, 0);
+    }
+
+    return 0;
+}
+
 static int FUNC(sei_payload)(CodedBitstreamContext *ctx, RWContext *rw,
                              H265RawSEIPayload *current, int prefix)
 {
@@ -2080,6 +2108,7 @@ static int FUNC(sei_payload)(CodedBitstreamContext *ctx, RWContext *rw,
         SEI_TYPE_N(CONTENT_LIGHT_LEVEL_INFO, 1, 0, content_light_level);
         SEI_TYPE_N(ALTERNATIVE_TRANSFER_CHARACTERISTICS,
                                              1, 0, alternative_transfer_characteristics);
+        SEI_TYPE_N(ALPHA_CHANNEL_INFO,       1, 0, alpha_channel_info);
 
 #undef SEI_TYPE
     default:
index 2fec00a..f6516ae 100644 (file)
@@ -56,6 +56,7 @@ typedef enum {
     HEVC_SEI_TYPE_MASTERING_DISPLAY_INFO               = 137,
     HEVC_SEI_TYPE_CONTENT_LIGHT_LEVEL_INFO             = 144,
     HEVC_SEI_TYPE_ALTERNATIVE_TRANSFER_CHARACTERISTICS = 147,
+    HEVC_SEI_TYPE_ALPHA_CHANNEL_INFO                   = 165,
 } HEVC_SEI_Type;
 
 typedef struct HEVCSEIPictureHash {