]> git.sesse.net Git - ffmpeg/blobdiff - libavcodec/h2645_parse.c
avcodec/avcodec: Remove unnecessary forward declaration
[ffmpeg] / libavcodec / h2645_parse.c
index 0f3343004f9f393a7ec234ffd2c1290b85d2a3e4..6fbe97ad4aac237f01a6b8f629212be6c2d1fb27 100644 (file)
@@ -146,7 +146,7 @@ nsc:
     return si;
 }
 
-static const char *hevc_nal_type_name[64] = {
+static const char *const hevc_nal_type_name[64] = {
     "TRAIL_N", // HEVC_NAL_TRAIL_N
     "TRAIL_R", // HEVC_NAL_TRAIL_R
     "TSA_N", // HEVC_NAL_TSA_N
@@ -169,8 +169,8 @@ static const char *hevc_nal_type_name[64] = {
     "IDR_W_RADL", // HEVC_NAL_IDR_W_RADL
     "IDR_N_LP", // HEVC_NAL_IDR_N_LP
     "CRA_NUT", // HEVC_NAL_CRA_NUT
-    "IRAP_IRAP_VCL22", // HEVC_NAL_IRAP_VCL22
-    "IRAP_IRAP_VCL23", // HEVC_NAL_IRAP_VCL23
+    "RSV_IRAP_VCL22", // HEVC_NAL_RSV_IRAP_VCL22
+    "RSV_IRAP_VCL23", // HEVC_NAL_RSV_IRAP_VCL23
     "RSV_VCL24", // HEVC_NAL_RSV_VCL24
     "RSV_VCL25", // HEVC_NAL_RSV_VCL25
     "RSV_VCL26", // HEVC_NAL_RSV_VCL26
@@ -219,7 +219,7 @@ static const char *hevc_nal_unit_name(int nal_type)
     return hevc_nal_type_name[nal_type];
 }
 
-static const char *h264_nal_type_name[32] = {
+static const char *const h264_nal_type_name[32] = {
     "Unspecified 0", //H264_NAL_UNSPECIFIED
     "Coded slice of a non-IDR picture", // H264_NAL_SLICE
     "Coded slice data partition A", // H264_NAL_DPA
@@ -287,7 +287,7 @@ static int get_bit_length(H2645NAL *nal, int skip_trailing_zeros)
 
 /**
  * @return AVERROR_INVALIDDATA if the packet is not a valid NAL unit,
- * 0 if the unit should be skipped, 1 otherwise
+ * 0 otherwise
  */
 static int hevc_parse_nal_header(H2645NAL *nal, void *logctx)
 {
@@ -307,7 +307,7 @@ static int hevc_parse_nal_header(H2645NAL *nal, void *logctx)
            "nal_unit_type: %d(%s), nuh_layer_id: %d, temporal_id: %d\n",
            nal->type, hevc_nal_unit_name(nal->type), nal->nuh_layer_id, nal->temporal_id);
 
-    return 1;
+    return 0;
 }
 
 static int h264_parse_nal_header(H2645NAL *nal, void *logctx)
@@ -324,7 +324,7 @@ static int h264_parse_nal_header(H2645NAL *nal, void *logctx)
            "nal_unit_type: %d(%s), nal_ref_idc: %d\n",
            nal->type, h264_nal_unit_name(nal->type), nal->ref_idc);
 
-    return 1;
+    return 0;
 }
 
 static int find_next_start_code(const uint8_t *buf, const uint8_t *next_avc)
@@ -467,7 +467,7 @@ int ff_h2645_packet_split(H2645Packet *pkt, const uint8_t *buf, int length,
             memset(pkt->nals + pkt->nals_allocated, 0, sizeof(*pkt->nals));
 
             nal = &pkt->nals[pkt->nb_nals];
-            nal->skipped_bytes_pos_size = 1024; // initial buffer size
+            nal->skipped_bytes_pos_size = FFMIN(1024, extract_length/3+1); // initial buffer size
             nal->skipped_bytes_pos = av_malloc_array(nal->skipped_bytes_pos_size, sizeof(*nal->skipped_bytes_pos));
             if (!nal->skipped_bytes_pos)
                 return AVERROR(ENOMEM);
@@ -485,8 +485,6 @@ int ff_h2645_packet_split(H2645Packet *pkt, const uint8_t *buf, int length,
                    "NALFF: Consumed only %d bytes instead of %d\n",
                    consumed, extract_length);
 
-        pkt->nb_nals++;
-
         bytestream2_skip(&bc, consumed);
 
         /* see commit 3566042a0 */
@@ -496,21 +494,27 @@ int ff_h2645_packet_split(H2645Packet *pkt, const uint8_t *buf, int length,
 
         nal->size_bits = get_bit_length(nal, skip_trailing_zeros);
 
+        if (nal->size <= 0 || nal->size_bits <= 0)
+            continue;
+
         ret = init_get_bits(&nal->gb, nal->data, nal->size_bits);
         if (ret < 0)
             return ret;
 
+        /* Reset type in case it contains a stale value from a previously parsed NAL */
+        nal->type = 0;
+
         if (codec_id == AV_CODEC_ID_HEVC)
             ret = hevc_parse_nal_header(nal, logctx);
         else
             ret = h264_parse_nal_header(nal, logctx);
-        if (ret <= 0 || nal->size <= 0 || nal->size_bits <= 0) {
-            if (ret < 0) {
-                av_log(logctx, AV_LOG_WARNING, "Invalid NAL unit %d, skipping.\n",
-                       nal->type);
-            }
-            pkt->nb_nals--;
+        if (ret < 0) {
+            av_log(logctx, AV_LOG_WARNING, "Invalid NAL unit %d, skipping.\n",
+                   nal->type);
+            continue;
         }
+
+        pkt->nb_nals++;
     }
 
     return 0;