Commit 51d8725a authored by Anton Khirnov's avatar Anton Khirnov

h264: use the main H264Context as the parent for all slice contexts

There is now no need to have per-slice copies of the H264Context.
parent 92e0b734
...@@ -655,7 +655,7 @@ av_cold int ff_h264_decode_init(AVCodecContext *avctx) ...@@ -655,7 +655,7 @@ av_cold int ff_h264_decode_init(AVCodecContext *avctx)
h->thread_context[0] = h; h->thread_context[0] = h;
for (i = 0; i < h->nb_slice_ctx; i++) for (i = 0; i < h->nb_slice_ctx; i++)
h->slice_ctx[i].h264 = h->thread_context[0]; h->slice_ctx[i].h264 = h;
h->outputed_poc = h->next_outputed_poc = INT_MIN; h->outputed_poc = h->next_outputed_poc = INT_MIN;
for (i = 0; i < MAX_DELAYED_PIC_COUNT; i++) for (i = 0; i < MAX_DELAYED_PIC_COUNT; i++)
...@@ -1422,7 +1422,6 @@ static int decode_nal_units(H264Context *h, const uint8_t *buf, int buf_size, ...@@ -1422,7 +1422,6 @@ static int decode_nal_units(H264Context *h, const uint8_t *buf, int buf_size,
int parse_extradata) int parse_extradata)
{ {
AVCodecContext *const avctx = h->avctx; AVCodecContext *const avctx = h->avctx;
H264Context *hx; ///< thread context
H264SliceContext *sl; H264SliceContext *sl;
int buf_index; int buf_index;
unsigned context_count; unsigned context_count;
...@@ -1468,10 +1467,9 @@ static int decode_nal_units(H264Context *h, const uint8_t *buf, int buf_size, ...@@ -1468,10 +1467,9 @@ static int decode_nal_units(H264Context *h, const uint8_t *buf, int buf_size,
continue; continue;
} }
hx = h->thread_context[context_count];
sl = &h->slice_ctx[context_count]; sl = &h->slice_ctx[context_count];
ptr = ff_h264_decode_nal(hx, sl, buf + buf_index, &dst_length, ptr = ff_h264_decode_nal(h, sl, buf + buf_index, &dst_length,
&consumed, next_avc - buf_index); &consumed, next_avc - buf_index);
if (!ptr || dst_length < 0) { if (!ptr || dst_length < 0) {
ret = -1; ret = -1;
...@@ -1484,7 +1482,7 @@ static int decode_nal_units(H264Context *h, const uint8_t *buf, int buf_size, ...@@ -1484,7 +1482,7 @@ static int decode_nal_units(H264Context *h, const uint8_t *buf, int buf_size,
if (h->avctx->debug & FF_DEBUG_STARTCODE) if (h->avctx->debug & FF_DEBUG_STARTCODE)
av_log(h->avctx, AV_LOG_DEBUG, av_log(h->avctx, AV_LOG_DEBUG,
"NAL %d at %d/%d length %d\n", "NAL %d at %d/%d length %d\n",
hx->nal_unit_type, buf_index, buf_size, dst_length); h->nal_unit_type, buf_index, buf_size, dst_length);
if (h->is_avc && (nalsize != consumed) && nalsize) if (h->is_avc && (nalsize != consumed) && nalsize)
av_log(h->avctx, AV_LOG_DEBUG, av_log(h->avctx, AV_LOG_DEBUG,
...@@ -1505,17 +1503,17 @@ again: ...@@ -1505,17 +1503,17 @@ again:
* with frame-mt */ * with frame-mt */
if (parse_extradata && HAVE_THREADS && if (parse_extradata && HAVE_THREADS &&
(h->avctx->active_thread_type & FF_THREAD_FRAME) && (h->avctx->active_thread_type & FF_THREAD_FRAME) &&
(hx->nal_unit_type != NAL_PPS && (h->nal_unit_type != NAL_PPS &&
hx->nal_unit_type != NAL_SPS)) { h->nal_unit_type != NAL_SPS)) {
if (hx->nal_unit_type < NAL_AUD || if (h->nal_unit_type < NAL_AUD ||
hx->nal_unit_type > NAL_AUXILIARY_SLICE) h->nal_unit_type > NAL_AUXILIARY_SLICE)
av_log(avctx, AV_LOG_INFO, av_log(avctx, AV_LOG_INFO,
"Ignoring NAL unit %d during extradata parsing\n", "Ignoring NAL unit %d during extradata parsing\n",
hx->nal_unit_type); h->nal_unit_type);
hx->nal_unit_type = NAL_FF_IGNORE; h->nal_unit_type = NAL_FF_IGNORE;
} }
err = 0; err = 0;
switch (hx->nal_unit_type) { switch (h->nal_unit_type) {
case NAL_IDR_SLICE: case NAL_IDR_SLICE:
if (h->nal_unit_type != NAL_IDR_SLICE) { if (h->nal_unit_type != NAL_IDR_SLICE) {
av_log(h->avctx, AV_LOG_ERROR, av_log(h->avctx, AV_LOG_ERROR,
...@@ -1527,7 +1525,7 @@ again: ...@@ -1527,7 +1525,7 @@ again:
case NAL_SLICE: case NAL_SLICE:
init_get_bits(&sl->gb, ptr, bit_length); init_get_bits(&sl->gb, ptr, bit_length);
if ((err = ff_h264_decode_slice_header(hx, sl, h))) if ((err = ff_h264_decode_slice_header(h, sl)))
break; break;
if (h->sei_recovery_frame_cnt >= 0 && h->recovery_frame < 0) { if (h->sei_recovery_frame_cnt >= 0 && h->recovery_frame < 0) {
...@@ -1536,17 +1534,17 @@ again: ...@@ -1536,17 +1534,17 @@ again:
} }
h->cur_pic_ptr->f.key_frame |= h->cur_pic_ptr->f.key_frame |=
(hx->nal_unit_type == NAL_IDR_SLICE) || (h->nal_unit_type == NAL_IDR_SLICE) ||
(h->sei_recovery_frame_cnt >= 0); (h->sei_recovery_frame_cnt >= 0);
if (hx->nal_unit_type == NAL_IDR_SLICE || if (h->nal_unit_type == NAL_IDR_SLICE ||
h->recovery_frame == h->frame_num) { h->recovery_frame == h->frame_num) {
h->recovery_frame = -1; h->recovery_frame = -1;
h->cur_pic_ptr->recovered = 1; h->cur_pic_ptr->recovered = 1;
} }
// If we have an IDR, all frames after it in decoded order are // If we have an IDR, all frames after it in decoded order are
// "recovered". // "recovered".
if (hx->nal_unit_type == NAL_IDR_SLICE) if (h->nal_unit_type == NAL_IDR_SLICE)
h->frame_recovered |= FRAME_RECOVERED_IDR; h->frame_recovered |= FRAME_RECOVERED_IDR;
h->cur_pic_ptr->recovered |= !!(h->frame_recovered & FRAME_RECOVERED_IDR); h->cur_pic_ptr->recovered |= !!(h->frame_recovered & FRAME_RECOVERED_IDR);
...@@ -1561,7 +1559,7 @@ again: ...@@ -1561,7 +1559,7 @@ again:
if (sl->redundant_pic_count == 0 && if (sl->redundant_pic_count == 0 &&
(avctx->skip_frame < AVDISCARD_NONREF || (avctx->skip_frame < AVDISCARD_NONREF ||
hx->nal_ref_idc) && h->nal_ref_idc) &&
(avctx->skip_frame < AVDISCARD_BIDIR || (avctx->skip_frame < AVDISCARD_BIDIR ||
sl->slice_type_nos != AV_PICTURE_TYPE_B) && sl->slice_type_nos != AV_PICTURE_TYPE_B) &&
(avctx->skip_frame < AVDISCARD_NONKEY || (avctx->skip_frame < AVDISCARD_NONKEY ||
...@@ -1623,7 +1621,7 @@ again: ...@@ -1623,7 +1621,7 @@ again:
break; break;
default: default:
av_log(avctx, AV_LOG_DEBUG, "Unknown NAL code: %d (%d bits)\n", av_log(avctx, AV_LOG_DEBUG, "Unknown NAL code: %d (%d bits)\n",
hx->nal_unit_type, bit_length); h->nal_unit_type, bit_length);
} }
if (context_count == h->max_contexts) { if (context_count == h->max_contexts) {
...@@ -1637,13 +1635,9 @@ again: ...@@ -1637,13 +1635,9 @@ again:
av_log(h->avctx, AV_LOG_ERROR, "decode_slice_header error\n"); av_log(h->avctx, AV_LOG_ERROR, "decode_slice_header error\n");
sl->ref_count[0] = sl->ref_count[1] = sl->list_count = 0; sl->ref_count[0] = sl->ref_count[1] = sl->list_count = 0;
} else if (err == 1) { } else if (err == 1) {
/* Slice could not be decoded in parallel mode, copy down /* Slice could not be decoded in parallel mode, restart. Note
* NAL unit stuff to context 0 and restart. Note that * that rbsp_buffer is not transferred, but since we no longer
* rbsp_buffer is not transferred, but since we no longer
* run in parallel mode this should not be an issue. */ * run in parallel mode this should not be an issue. */
h->nal_unit_type = hx->nal_unit_type;
h->nal_ref_idc = hx->nal_ref_idc;
hx = h;
sl = &h->slice_ctx[0]; sl = &h->slice_ctx[0];
goto again; goto again;
} }
......
...@@ -1070,7 +1070,7 @@ int ff_init_poc(H264Context *h, int pic_field_poc[2], int *pic_poc); ...@@ -1070,7 +1070,7 @@ int ff_init_poc(H264Context *h, int pic_field_poc[2], int *pic_poc);
int ff_pred_weight_table(H264Context *h, H264SliceContext *sl); int ff_pred_weight_table(H264Context *h, H264SliceContext *sl);
int ff_set_ref_count(H264Context *h, H264SliceContext *sl); int ff_set_ref_count(H264Context *h, H264SliceContext *sl);
int ff_h264_decode_slice_header(H264Context *h, H264SliceContext *sl, H264Context *h0); int ff_h264_decode_slice_header(H264Context *h, H264SliceContext *sl);
int ff_h264_execute_decode_slices(H264Context *h, unsigned context_count); int ff_h264_execute_decode_slices(H264Context *h, unsigned context_count);
int ff_h264_update_thread_context(AVCodecContext *dst, int ff_h264_update_thread_context(AVCodecContext *dst,
const AVCodecContext *src); const AVCodecContext *src);
......
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment