]> git.sesse.net Git - ffmpeg/blobdiff - libavcodec/cbs_h264_syntax_template.c
avcodec/cbs_av1: use the new signed value read/write functions
[ffmpeg] / libavcodec / cbs_h264_syntax_template.c
index 1a9fb9cfeb20b962cdedbe57e3b60ca30539ea00..07b4cddb5e6e554ea2d22f2babb32952742475ce 100644 (file)
@@ -513,6 +513,8 @@ static int FUNC(sei_buffering_period)(CodedBitstreamContext *ctx, RWContext *rw,
     const H264RawSPS *sps;
     int err, i, length;
 
+    HEADER("Buffering Period");
+
     ue(seq_parameter_set_id, 0, 31);
 
     sps = h264->sps[current->seq_parameter_set_id];
@@ -551,10 +553,9 @@ static int FUNC(sei_buffering_period)(CodedBitstreamContext *ctx, RWContext *rw,
 }
 
 static int FUNC(sei_pic_timestamp)(CodedBitstreamContext *ctx, RWContext *rw,
-                                   H264RawSEIPicTimestamp *current)
+                                   H264RawSEIPicTimestamp *current,
+                                   const H264RawSPS *sps)
 {
-    CodedBitstreamH264Context *h264 = ctx->priv_data;
-    const H264RawSPS *sps;
     uint8_t time_offset_length;
     int err;
 
@@ -583,13 +584,6 @@ static int FUNC(sei_pic_timestamp)(CodedBitstreamContext *ctx, RWContext *rw,
         }
     }
 
-    sps = h264->active_sps;
-    if (!sps) {
-        av_log(ctx->log_ctx, AV_LOG_ERROR,
-               "No active SPS for pic_timestamp.\n");
-        return AVERROR_INVALIDDATA;
-    }
-
     if (sps->vui.nal_hrd_parameters_present_flag)
         time_offset_length = sps->vui.nal_hrd_parameters.time_offset_length;
     else if (sps->vui.vcl_hrd_parameters_present_flag)
@@ -598,8 +592,9 @@ static int FUNC(sei_pic_timestamp)(CodedBitstreamContext *ctx, RWContext *rw,
         time_offset_length = 24;
 
     if (time_offset_length > 0)
-        u(time_offset_length, time_offset,
-          0, MAX_UINT_BITS(time_offset_length));
+        i(time_offset_length, time_offset,
+          MIN_INT_BITS(time_offset_length),
+          MAX_INT_BITS(time_offset_length));
     else
         infer(time_offset, 0);
 
@@ -613,6 +608,8 @@ static int FUNC(sei_pic_timing)(CodedBitstreamContext *ctx, RWContext *rw,
     const H264RawSPS *sps;
     int err;
 
+    HEADER("Picture Timing");
+
     sps = h264->active_sps;
     if (!sps) {
         // If there is exactly one possible SPS but it is not yet active
@@ -669,7 +666,8 @@ static int FUNC(sei_pic_timing)(CodedBitstreamContext *ctx, RWContext *rw,
         for (i = 0; i < num_clock_ts[current->pic_struct]; i++) {
             flags(clock_timestamp_flag[i], 1, i);
             if (current->clock_timestamp_flag[i])
-                CHECK(FUNC(sei_pic_timestamp)(ctx, rw, &current->timestamp[i]));
+                CHECK(FUNC(sei_pic_timestamp)(ctx, rw,
+                                              &current->timestamp[i], sps));
         }
     }
 
@@ -681,6 +679,8 @@ static int FUNC(sei_pan_scan_rect)(CodedBitstreamContext *ctx, RWContext *rw,
 {
     int err, i;
 
+    HEADER("Pan-Scan Rectangle");
+
     ue(pan_scan_rect_id, 0, UINT32_MAX - 1);
     flag(pan_scan_rect_cancel_flag);
 
@@ -706,6 +706,8 @@ static int FUNC(sei_user_data_registered)(CodedBitstreamContext *ctx, RWContext
 {
     int err, i, j;
 
+    HEADER("User Data Registered ITU-T T.35");
+
     u(8, itu_t_t35_country_code, 0x00, 0xff);
     if (current->itu_t_t35_country_code != 0xff)
         i = 1;
@@ -725,7 +727,7 @@ static int FUNC(sei_user_data_registered)(CodedBitstreamContext *ctx, RWContext
     *payload_size = i + current->data_length;
 #endif
 
-    allocate(current->data, current->data_length + AV_INPUT_BUFFER_PADDING_SIZE);
+    allocate(current->data, current->data_length);
     for (j = 0; j < current->data_length; j++)
         xu(8, itu_t_t35_payload_byte[i], current->data[j], 0x00, 0xff, 1, i + j);
 
@@ -738,6 +740,8 @@ static int FUNC(sei_user_data_unregistered)(CodedBitstreamContext *ctx, RWContex
 {
     int err, i;
 
+    HEADER("User Data Unregistered");
+
 #ifdef READ
     if (*payload_size < 16) {
         av_log(ctx->log_ctx, AV_LOG_ERROR,
@@ -765,6 +769,8 @@ static int FUNC(sei_recovery_point)(CodedBitstreamContext *ctx, RWContext *rw,
 {
     int err;
 
+    HEADER("Recovery Point");
+
     ue(recovery_frame_cnt, 0, 65535);
     flag(exact_match_flag);
     flag(broken_link_flag);
@@ -778,6 +784,8 @@ static int FUNC(sei_display_orientation)(CodedBitstreamContext *ctx, RWContext *
 {
     int err;
 
+    HEADER("Display Orientation");
+
     flag(display_orientation_cancel_flag);
     if (!current->display_orientation_cancel_flag) {
         flag(hor_flip);
@@ -795,6 +803,8 @@ static int FUNC(sei_mastering_display_colour_volume)(CodedBitstreamContext *ctx,
 {
     int err, c;
 
+    HEADER("Mastering Display Colour Volume");
+
     for (c = 0; c < 3; c++) {
         us(16, display_primaries_x[c], 0, 50000, 1, c);
         us(16, display_primaries_y[c], 0, 50000, 1, c);
@@ -1181,11 +1191,10 @@ static int FUNC(slice_header)(CodedBitstreamContext *ctx, RWContext *rw,
                    "in the same access unit.\n");
             return AVERROR_INVALIDDATA;
         }
+        idr_pic_flag = h264->last_slice_nal_unit_type == H264_NAL_IDR_SLICE;
     } else {
-        h264->last_slice_nal_unit_type =
-            current->nal_unit_header.nal_unit_type;
+        idr_pic_flag = current->nal_unit_header.nal_unit_type == H264_NAL_IDR_SLICE;
     }
-    idr_pic_flag = h264->last_slice_nal_unit_type == H264_NAL_IDR_SLICE;
 
     ue(first_mb_in_slice, 0, H264_MAX_MB_PIC_SIZE - 1);
     ue(slice_type, 0, 9);
@@ -1263,6 +1272,13 @@ static int FUNC(slice_header)(CodedBitstreamContext *ctx, RWContext *rw,
 
     if (pps->redundant_pic_cnt_present_flag)
         ue(redundant_pic_cnt, 0, 127);
+    else
+        infer(redundant_pic_cnt, 0);
+
+    if (current->nal_unit_header.nal_unit_type != H264_NAL_AUXILIARY_SLICE
+        && !current->redundant_pic_cnt)
+        h264->last_slice_nal_unit_type =
+            current->nal_unit_header.nal_unit_type;
 
     if (slice_type_b)
         flag(direct_spatial_mv_pred_flag);