X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=libavcodec%2Fh264.c;h=a61379cc9fa7df7b9b669284b48b62bf5b6762e9;hb=b95534bb674acfe7689ca03cb4fa215c28f8f44f;hp=aea6f4955c05f911d9ef9c27bcde1a35be626003;hpb=c3afe64d0cbe7141a1d90bd1b89895316913e1ea;p=ffmpeg diff --git a/libavcodec/h264.c b/libavcodec/h264.c index aea6f4955c0..a61379cc9fa 100644 --- a/libavcodec/h264.c +++ b/libavcodec/h264.c @@ -21,7 +21,7 @@ /** * @file - * H.264 / AVC / MPEG4 part10 codec. + * H.264 / AVC / MPEG-4 part10 codec. * @author Michael Niedermayer */ @@ -180,7 +180,7 @@ void ff_h264_free_tables(H264Context *h) int ff_h264_alloc_tables(H264Context *h) { const int big_mb_num = h->mb_stride * (h->mb_height + 1); - const int row_mb_num = 2*h->mb_stride*FFMAX(h->avctx->thread_count, 1); + const int row_mb_num = 2*h->mb_stride*FFMAX(h->nb_slice_ctx, 1); int x, y; FF_ALLOCZ_ARRAY_OR_GOTO(h->avctx, h->intra4x4_pred_mode, @@ -312,7 +312,6 @@ static int h264_init_context(AVCodecContext *avctx, H264Context *h) h->cur_chroma_format_idc = -1; h->picture_structure = PICT_FRAME; - h->slice_context_count = 1; h->workaround_bugs = avctx->workaround_bugs; h->flags = avctx->flags; h->poc.prev_poc_msb = 1 << 16; @@ -330,7 +329,7 @@ static int h264_init_context(AVCodecContext *avctx, H264Context *h) avctx->chroma_sample_location = AVCHROMA_LOC_LEFT; - h->nb_slice_ctx = (avctx->active_thread_type & FF_THREAD_SLICE) ? H264_MAX_THREADS : 1; + h->nb_slice_ctx = (avctx->active_thread_type & FF_THREAD_SLICE) ? avctx->thread_count : 1; h->slice_ctx = av_mallocz_array(h->nb_slice_ctx, sizeof(*h->slice_ctx)); if (!h->slice_ctx) { h->nb_slice_ctx = 0; @@ -357,6 +356,38 @@ static int h264_init_context(AVCodecContext *avctx, H264Context *h) return 0; } +static av_cold int h264_decode_end(AVCodecContext *avctx) +{ + H264Context *h = avctx->priv_data; + int i; + + ff_h264_remove_all_refs(h); + ff_h264_free_tables(h); + + for (i = 0; i < H264_MAX_PICTURE_COUNT; i++) { + ff_h264_unref_picture(h, &h->DPB[i]); + av_frame_free(&h->DPB[i].f); + } + memset(h->delayed_pic, 0, sizeof(h->delayed_pic)); + + h->cur_pic_ptr = NULL; + + av_freep(&h->slice_ctx); + h->nb_slice_ctx = 0; + + ff_h264_sei_uninit(&h->sei); + ff_h264_ps_uninit(&h->ps); + + ff_h2645_packet_uninit(&h->pkt); + + ff_h264_unref_picture(h, &h->cur_pic); + av_frame_free(&h->cur_pic.f); + ff_h264_unref_picture(h, &h->last_pic_for_ec); + av_frame_free(&h->last_pic_for_ec.f); + + return 0; +} + static AVOnce h264_vlc_init = AV_ONCE_INIT; av_cold int ff_h264_decode_init(AVCodecContext *avctx) @@ -368,10 +399,6 @@ av_cold int ff_h264_decode_init(AVCodecContext *avctx) if (ret < 0) return ret; - /* set defaults */ - if (!avctx->has_b_frames) - h->low_delay = 1; - ret = ff_thread_once(&h264_vlc_init, ff_h264_decode_init_vlc); if (ret != 0) { av_log(avctx, AV_LOG_ERROR, "pthread_once has failed."); @@ -401,7 +428,6 @@ av_cold int ff_h264_decode_init(AVCodecContext *avctx) if (h->ps.sps && h->ps.sps->bitstream_restriction_flag && h->avctx->has_b_frames < h->ps.sps->num_reorder_frames) { h->avctx->has_b_frames = h->ps.sps->num_reorder_frames; - h->low_delay = 0; } avctx->internal->allocate_progress = 1; @@ -456,8 +482,6 @@ static void decode_postinit(H264Context *h, int setup_finished) H264Picture *cur = h->cur_pic_ptr; int i, pics, out_of_order, out_idx; - h->cur_pic_ptr->f->pict_type = h->pict_type; - if (h->next_output_pic) return; @@ -631,7 +655,6 @@ static void decode_postinit(H264Context *h, int setup_finished) h->avctx->strict_std_compliance >= FF_COMPLIANCE_STRICT) { h->avctx->has_b_frames = FFMAX(h->avctx->has_b_frames, sps->num_reorder_frames); } - h->low_delay = !h->avctx->has_b_frames; for (i = 0; 1; i++) { if(i == MAX_DELAYED_PIC_COUNT || cur->poc < h->last_pocs[i]){ @@ -655,7 +678,6 @@ static void decode_postinit(H264Context *h, int setup_finished) } else if(h->avctx->has_b_frames < out_of_order && !sps->bitstream_restriction_flag){ av_log(h->avctx, AV_LOG_INFO, "Increasing reorder buffer to %d\n", out_of_order); h->avctx->has_b_frames = out_of_order; - h->low_delay = 0; } pics = 0; @@ -860,9 +882,7 @@ static int decode_nal_units(H264Context *h, const uint8_t *buf, int buf_size) h->nal_unit_type= 0; - if(!h->slice_context_count) - h->slice_context_count= 1; - h->max_contexts = h->slice_context_count; + h->max_contexts = h->nb_slice_ctx; if (!(avctx->flags2 & AV_CODEC_FLAG2_CHUNKS)) { h->current_slice = 0; if (!h->first_field) @@ -1073,9 +1093,7 @@ FF_ENABLE_DEPRECATION_WARNINGS goto end; context_count = 0; } - /* Slice could not be decoded in parallel mode, restart. Note - * that rbsp_buffer is not transferred, but since we no longer - * run in parallel mode this should not be an issue. */ + /* Slice could not be decoded in parallel mode, restart. */ sl = &h->slice_ctx[0]; goto again; } @@ -1353,7 +1371,7 @@ static int h264_decode_frame(AVCodecContext *avctx, void *data, h->next_output_pic->mb_type, h->next_output_pic->qscale_table, h->next_output_pic->motion_val, - &h->low_delay, + NULL, h->mb_width, h->mb_height, h->mb_stride, 1); } } @@ -1366,54 +1384,6 @@ static int h264_decode_frame(AVCodecContext *avctx, void *data, return get_consumed_bytes(buf_index, buf_size); } -av_cold void ff_h264_free_context(H264Context *h) -{ - int i; - - ff_h264_free_tables(h); - - for (i = 0; i < H264_MAX_PICTURE_COUNT; i++) { - ff_h264_unref_picture(h, &h->DPB[i]); - av_frame_free(&h->DPB[i].f); - } - memset(h->delayed_pic, 0, sizeof(h->delayed_pic)); - - h->cur_pic_ptr = NULL; - - for (i = 0; i < h->nb_slice_ctx; i++) - av_freep(&h->slice_ctx[i].rbsp_buffer); - av_freep(&h->slice_ctx); - h->nb_slice_ctx = 0; - - ff_h264_sei_uninit(&h->sei); - - for (i = 0; i < MAX_SPS_COUNT; i++) - av_buffer_unref(&h->ps.sps_list[i]); - - for (i = 0; i < MAX_PPS_COUNT; i++) - av_buffer_unref(&h->ps.pps_list[i]); - - av_buffer_unref(&h->ps.sps_ref); - av_buffer_unref(&h->ps.pps_ref); - - ff_h2645_packet_uninit(&h->pkt); -} - -static av_cold int h264_decode_end(AVCodecContext *avctx) -{ - H264Context *h = avctx->priv_data; - - ff_h264_remove_all_refs(h); - ff_h264_free_context(h); - - ff_h264_unref_picture(h, &h->cur_pic); - av_frame_free(&h->cur_pic.f); - ff_h264_unref_picture(h, &h->last_pic_for_ec); - av_frame_free(&h->last_pic_for_ec.f); - - return 0; -} - #define OFFSET(x) offsetof(H264Context, x) #define VD AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_DECODING_PARAM static const AVOption h264_options[] = {