]> git.sesse.net Git - ffmpeg/blobdiff - libavcodec/h264dec.c
avcodec/ffv1: template functions to allow data types different from int16_t
[ffmpeg] / libavcodec / h264dec.c
index 91bc38dcc1571aff00ce4a2ac032b3d63a69af40..904ae558d6a701381d346c28064c2f5d6d28e971 100644 (file)
@@ -406,15 +406,13 @@ av_cold int ff_h264_decode_init(AVCodecContext *avctx)
         return AVERROR_UNKNOWN;
     }
 
-    if (avctx->codec_id == AV_CODEC_ID_H264) {
-        if (avctx->ticks_per_frame == 1) {
-            if(h->avctx->time_base.den < INT_MAX/2) {
-                h->avctx->time_base.den *= 2;
-            } else
-                h->avctx->time_base.num /= 2;
-        }
-        avctx->ticks_per_frame = 2;
+    if (avctx->ticks_per_frame == 1) {
+        if(h->avctx->time_base.den < INT_MAX/2) {
+            h->avctx->time_base.den *= 2;
+        } else
+            h->avctx->time_base.num /= 2;
     }
+    avctx->ticks_per_frame = 2;
 
     if (avctx->extradata_size > 0 && avctx->extradata) {
         ret = ff_h264_decode_extradata(avctx->extradata, avctx->extradata_size,
@@ -674,13 +672,13 @@ static int get_last_needed_nal(H264Context *h)
          * which splits NALs strangely if so, when frame threading we
          * can't start the next thread until we've read all of them */
         switch (nal->type) {
-        case NAL_SPS:
-        case NAL_PPS:
+        case H264_NAL_SPS:
+        case H264_NAL_PPS:
             nals_needed = i;
             break;
-        case NAL_DPA:
-        case NAL_IDR_SLICE:
-        case NAL_SLICE:
+        case H264_NAL_DPA:
+        case H264_NAL_IDR_SLICE:
+        case H264_NAL_SLICE:
             ret = init_get_bits8(&gb, nal->data + 1, (nal->size - 1));
             if (ret < 0)
                 return ret;
@@ -768,7 +766,7 @@ static int decode_nal_units(H264Context *h, const uint8_t *buf, int buf_size)
         int err;
 
         if (avctx->skip_frame >= AVDISCARD_NONREF &&
-            nal->ref_idc == 0 && nal->type != NAL_SEI)
+            nal->ref_idc == 0 && nal->type != H264_NAL_SEI)
             continue;
 
 again:
@@ -778,19 +776,13 @@ again:
 
         err = 0;
         switch (nal->type) {
-        case NAL_IDR_SLICE:
+        case H264_NAL_IDR_SLICE:
             if ((nal->data[1] & 0xFC) == 0x98) {
                 av_log(h->avctx, AV_LOG_ERROR, "Invalid inter IDR frame\n");
                 h->next_outputed_poc = INT_MIN;
                 ret = -1;
                 goto end;
             }
-            if (nal->type != NAL_IDR_SLICE) {
-                av_log(h->avctx, AV_LOG_ERROR,
-                       "Invalid mix of idr and non-idr slices\n");
-                ret = -1;
-                goto end;
-            }
             if(!idr_cleared) {
                 if (h->current_slice && (avctx->active_thread_type & FF_THREAD_SLICE)) {
                     av_log(h, AV_LOG_ERROR, "invalid mixed IDR / non IDR frames cannot be decoded in slice multithreading mode\n");
@@ -801,43 +793,14 @@ again:
             }
             idr_cleared = 1;
             h->has_recovery_point = 1;
-        case NAL_SLICE:
+        case H264_NAL_SLICE:
             sl->gb = nal->gb;
 
             if ((err = ff_h264_decode_slice_header(h, sl, nal)))
                 break;
 
-            if (h->sei.recovery_point.recovery_frame_cnt >= 0) {
-                const int sei_recovery_frame_cnt = h->sei.recovery_point.recovery_frame_cnt;
-
-                if (h->poc.frame_num != sei_recovery_frame_cnt || sl->slice_type_nos != AV_PICTURE_TYPE_I)
-                    h->valid_recovery_point = 1;
-
-                if (   h->recovery_frame < 0
-                    || av_mod_uintp2(h->recovery_frame - h->poc.frame_num, h->ps.sps->log2_max_frame_num) > sei_recovery_frame_cnt) {
-                    h->recovery_frame = av_mod_uintp2(h->poc.frame_num + sei_recovery_frame_cnt, h->ps.sps->log2_max_frame_num);
-
-                    if (!h->valid_recovery_point)
-                        h->recovery_frame = h->poc.frame_num;
-                }
-            }
-
-            h->cur_pic_ptr->f->key_frame |= (nal->type == NAL_IDR_SLICE);
-
-            if (nal->type == NAL_IDR_SLICE ||
-                (h->recovery_frame == h->poc.frame_num && nal->ref_idc)) {
-                h->recovery_frame         = -1;
-                h->cur_pic_ptr->recovered = 1;
-            }
-            // If we have an IDR, all frames after it in decoded order are
-            // "recovered".
-            if (nal->type == NAL_IDR_SLICE)
-                h->frame_recovered |= FRAME_RECOVERED_IDR;
-#if 1
-            h->cur_pic_ptr->recovered |= h->frame_recovered;
-#else
-            h->cur_pic_ptr->recovered |= !!(h->frame_recovered & FRAME_RECOVERED_IDR);
-#endif
+            if (sl->redundant_pic_count > 0)
+                break;
 
             if (h->current_slice == 1) {
                 if (!(avctx->flags2 & AV_CODEC_FLAG2_CHUNKS))
@@ -853,33 +816,31 @@ again:
 #endif
             }
 
-            if (sl->redundant_pic_count == 0) {
-                if (avctx->hwaccel) {
-                    ret = avctx->hwaccel->decode_slice(avctx,
-                                                       nal->raw_data,
-                                                       nal->raw_size);
-                    if (ret < 0)
-                        goto end;
+            if (avctx->hwaccel) {
+                ret = avctx->hwaccel->decode_slice(avctx,
+                                                   nal->raw_data,
+                                                   nal->raw_size);
+                if (ret < 0)
+                    goto end;
 #if FF_API_CAP_VDPAU
-                } else if (CONFIG_H264_VDPAU_DECODER &&
-                           h->avctx->codec->capabilities & AV_CODEC_CAP_HWACCEL_VDPAU) {
-                    ff_vdpau_add_data_chunk(h->cur_pic_ptr->f->data[0],
-                                            start_code,
-                                            sizeof(start_code));
-                    ff_vdpau_add_data_chunk(h->cur_pic_ptr->f->data[0],
-                                            nal->raw_data,
-                                            nal->raw_size);
+            } else if (CONFIG_H264_VDPAU_DECODER &&
+                       h->avctx->codec->capabilities & AV_CODEC_CAP_HWACCEL_VDPAU) {
+                ff_vdpau_add_data_chunk(h->cur_pic_ptr->f->data[0],
+                                        start_code,
+                                        sizeof(start_code));
+                ff_vdpau_add_data_chunk(h->cur_pic_ptr->f->data[0],
+                                        nal->raw_data,
+                                        nal->raw_size);
 #endif
-                } else
-                    context_count++;
-            }
+            } else
+                context_count++;
             break;
-        case NAL_DPA:
-        case NAL_DPB:
-        case NAL_DPC:
+        case H264_NAL_DPA:
+        case H264_NAL_DPB:
+        case H264_NAL_DPC:
             avpriv_request_sample(avctx, "data partitioning");
             break;
-        case NAL_SEI:
+        case H264_NAL_SEI:
             ret = ff_h264_sei_decode(&h->sei, &nal->gb, &h->ps, avctx);
             h->has_recovery_point = h->has_recovery_point || h->sei.recovery_point.recovery_frame_cnt != -1;
             if (avctx->debug & FF_DEBUG_GREEN_MD)
@@ -892,7 +853,7 @@ FF_ENABLE_DEPRECATION_WARNINGS
             if (ret < 0 && (h->avctx->err_recognition & AV_EF_EXPLODE))
                 goto end;
             break;
-        case NAL_SPS: {
+        case H264_NAL_SPS: {
             GetBitContext tmp_gb = nal->gb;
             if (ff_h264_decode_seq_parameter_set(&tmp_gb, avctx, &h->ps, 0) >= 0)
                 break;
@@ -904,18 +865,18 @@ FF_ENABLE_DEPRECATION_WARNINGS
             ff_h264_decode_seq_parameter_set(&nal->gb, avctx, &h->ps, 1);
             break;
         }
-        case NAL_PPS:
+        case H264_NAL_PPS:
             ret = ff_h264_decode_picture_parameter_set(&nal->gb, avctx, &h->ps,
                                                        nal->size_bits);
             if (ret < 0 && (h->avctx->err_recognition & AV_EF_EXPLODE))
                 goto end;
             break;
-        case NAL_AUD:
-        case NAL_END_SEQUENCE:
-        case NAL_END_STREAM:
-        case NAL_FILLER_DATA:
-        case NAL_SPS_EXT:
-        case NAL_AUXILIARY_SLICE:
+        case H264_NAL_AUD:
+        case H264_NAL_END_SEQUENCE:
+        case H264_NAL_END_STREAM:
+        case H264_NAL_FILLER_DATA:
+        case H264_NAL_SPS_EXT:
+        case H264_NAL_AUXILIARY_SLICE:
             break;
         default:
             av_log(avctx, AV_LOG_DEBUG, "Unknown NAL code: %d (%d bits)\n",
@@ -1157,7 +1118,7 @@ static int h264_decode_frame(AVCodecContext *avctx, void *data,
     if (buf_index < 0)
         return AVERROR_INVALIDDATA;
 
-    if (!h->cur_pic_ptr && h->nal_unit_type == NAL_END_SEQUENCE) {
+    if (!h->cur_pic_ptr && h->nal_unit_type == H264_NAL_END_SEQUENCE) {
         av_assert0(buf_index <= buf_size);
         goto out;
     }