aboutsummaryrefslogtreecommitdiffstats
path: root/libavcodec
diff options
context:
space:
mode:
authorMichael Niedermayer <michaelni@gmx.at>2015-03-21 20:00:34 +0100
committerMichael Niedermayer <michaelni@gmx.at>2015-03-21 20:00:34 +0100
commit830e548b9ec32ad7ab02be056db15cbcf3c58346 (patch)
tree03ce45e4c52217252ae2fb8f960d75cd4f23d51c /libavcodec
parent44309dd29466bf2d9d9fa26ab6e73e7e64989c75 (diff)
parent582683b6ac798ed2a004a4e2121b7bd47892bbfd (diff)
downloadffmpeg-830e548b9ec32ad7ab02be056db15cbcf3c58346.tar.gz
Merge commit '582683b6ac798ed2a004a4e2121b7bd47892bbfd'
* commit '582683b6ac798ed2a004a4e2121b7bd47892bbfd': h264: move remaining ER stuff into the per-slice context Conflicts: libavcodec/h264.h libavcodec/h264_picture.c libavcodec/h264_slice.c Merged-by: Michael Niedermayer <michaelni@gmx.at>
Diffstat (limited to 'libavcodec')
-rw-r--r--libavcodec/h264.c37
-rw-r--r--libavcodec/h264.h6
-rw-r--r--libavcodec/h264_picture.c14
-rw-r--r--libavcodec/h264_slice.c49
4 files changed, 53 insertions, 53 deletions
diff --git a/libavcodec/h264.c b/libavcodec/h264.c
index f2d0a1069d..63f063a7f3 100644
--- a/libavcodec/h264.c
+++ b/libavcodec/h264.c
@@ -401,10 +401,6 @@ void ff_h264_free_tables(H264Context *h, int free_rbsp)
hx = h->thread_context[i];
if (!hx)
continue;
- av_freep(&hx->dc_val_base);
- av_freep(&hx->er.mb_index2xy);
- av_freep(&hx->er.error_status_table);
- av_freep(&hx->er.er_temp_buffer);
if (free_rbsp) {
av_freep(&hx->rbsp_buffer);
@@ -417,6 +413,11 @@ void ff_h264_free_tables(H264Context *h, int free_rbsp)
for (i = 0; i < h->nb_slice_ctx; i++) {
H264SliceContext *sl = &h->slice_ctx[i];
+ av_freep(&sl->dc_val_base);
+ av_freep(&sl->er.mb_index2xy);
+ av_freep(&sl->er.error_status_table);
+ av_freep(&sl->er.er_temp_buffer);
+
av_freep(&sl->bipred_scratchpad);
av_freep(&sl->edge_emu_buffer);
av_freep(&sl->top_borders[0]);
@@ -499,23 +500,21 @@ fail:
* Init context
* Allocate buffers which are not shared amongst multiple threads.
*/
-int ff_h264_context_init(H264Context *h)
+int ff_h264_slice_context_init(H264Context *h, H264SliceContext *sl)
{
- ERContext *er = &h->er;
+ ERContext *er = &sl->er;
int mb_array_size = h->mb_height * h->mb_stride;
int y_size = (2 * h->mb_width + 1) * (2 * h->mb_height + 1);
int c_size = h->mb_stride * (h->mb_height + 1);
int yc_size = y_size + 2 * c_size;
int x, y, i;
- for (i = 0; i < h->nb_slice_ctx; i++) {
- h->slice_ctx[i].ref_cache[0][scan8[5] + 1] =
- h->slice_ctx[i].ref_cache[0][scan8[7] + 1] =
- h->slice_ctx[i].ref_cache[0][scan8[13] + 1] =
- h->slice_ctx[i].ref_cache[1][scan8[5] + 1] =
- h->slice_ctx[i].ref_cache[1][scan8[7] + 1] =
- h->slice_ctx[i].ref_cache[1][scan8[13] + 1] = PART_NOT_AVAILABLE;
- }
+ sl->ref_cache[0][scan8[5] + 1] =
+ sl->ref_cache[0][scan8[7] + 1] =
+ sl->ref_cache[0][scan8[13] + 1] =
+ sl->ref_cache[1][scan8[5] + 1] =
+ sl->ref_cache[1][scan8[7] + 1] =
+ sl->ref_cache[1][scan8[13] + 1] = PART_NOT_AVAILABLE;
if (CONFIG_ERROR_RESILIENCE) {
/* init ER */
@@ -547,13 +546,13 @@ int ff_h264_context_init(H264Context *h)
FF_ALLOC_OR_GOTO(h->avctx, er->er_temp_buffer,
h->mb_height * h->mb_stride, fail);
- FF_ALLOCZ_OR_GOTO(h->avctx, h->dc_val_base,
+ FF_ALLOCZ_OR_GOTO(h->avctx, sl->dc_val_base,
yc_size * sizeof(int16_t), fail);
- er->dc_val[0] = h->dc_val_base + h->mb_width * 2 + 2;
- er->dc_val[1] = h->dc_val_base + y_size + h->mb_stride + 1;
+ er->dc_val[0] = sl->dc_val_base + h->mb_width * 2 + 2;
+ er->dc_val[1] = sl->dc_val_base + y_size + h->mb_stride + 1;
er->dc_val[2] = er->dc_val[1] + c_size;
for (i = 0; i < yc_size; i++)
- h->dc_val_base[i] = 1024;
+ sl->dc_val_base[i] = 1024;
}
return 0;
@@ -1906,7 +1905,7 @@ static int h264_decode_frame(AVCodecContext *avctx, void *data,
return ret;
*got_frame = 1;
if (CONFIG_MPEGVIDEO) {
- ff_print_debug_info2(h->avctx, pict, h->er.mbskip_table,
+ ff_print_debug_info2(h->avctx, pict, NULL,
h->next_output_pic->mb_type,
h->next_output_pic->qscale_table,
h->next_output_pic->motion_val,
diff --git a/libavcodec/h264.h b/libavcodec/h264.h
index f1fbbe4e91..5793f0e471 100644
--- a/libavcodec/h264.h
+++ b/libavcodec/h264.h
@@ -336,6 +336,7 @@ typedef struct H264Picture {
typedef struct H264SliceContext {
struct H264Context *h264;
GetBitContext gb;
+ ERContext er;
int slice_num;
int slice_type;
@@ -435,6 +436,7 @@ typedef struct H264SliceContext {
int ref2frm[MAX_SLICES][2][64]; ///< reference to frame number lists, used in the loop filter, the first 2 are for -2,-1
const uint8_t *intra_pcm_ptr;
+ int16_t *dc_val_base;
uint8_t *bipred_scratchpad;
uint8_t *edge_emu_buffer;
@@ -487,7 +489,6 @@ typedef struct H264Context {
H264ChromaContext h264chroma;
H264QpelContext h264qpel;
GetBitContext gb;
- ERContext er;
H264Picture *DPB;
H264Picture *cur_pic_ptr;
@@ -774,7 +775,6 @@ typedef struct H264Context {
uint8_t parse_history[6];
int parse_history_count;
int parse_last_mb;
- int16_t *dc_val_base;
AVBufferPool *qscale_table_pool;
AVBufferPool *mb_type_pool;
@@ -1161,7 +1161,7 @@ int ff_h264_field_end(H264Context *h, H264SliceContext *sl, int in_setup);
int ff_h264_ref_picture(H264Context *h, H264Picture *dst, H264Picture *src);
void ff_h264_unref_picture(H264Context *h, H264Picture *pic);
-int ff_h264_context_init(H264Context *h);
+int ff_h264_slice_context_init(H264Context *h, H264SliceContext *sl);
int ff_h264_set_parameter_from_sps(H264Context *h);
void ff_h264_draw_horiz_band(const H264Context *h, H264SliceContext *sl, int y, int height);
diff --git a/libavcodec/h264_picture.c b/libavcodec/h264_picture.c
index 65135e4922..d63a12e1f2 100644
--- a/libavcodec/h264_picture.c
+++ b/libavcodec/h264_picture.c
@@ -199,22 +199,22 @@ int ff_h264_field_end(H264Context *h, H264SliceContext *sl, int in_setup)
if (!FIELD_PICTURE(h) && h->current_slice && !h->sps.new) {
int use_last_pic = h->last_pic_for_ec.f.buf[0] && !sl->ref_count[0];
- ff_h264_set_erpic(&h->er.cur_pic, h->cur_pic_ptr);
+ ff_h264_set_erpic(&sl->er.cur_pic, h->cur_pic_ptr);
if (use_last_pic) {
- ff_h264_set_erpic(&h->er.last_pic, &h->last_pic_for_ec);
+ ff_h264_set_erpic(&sl->er.last_pic, &h->last_pic_for_ec);
COPY_PICTURE(&sl->ref_list[0][0], &h->last_pic_for_ec);
} else if (sl->ref_count[0]) {
- ff_h264_set_erpic(&h->er.last_pic, &sl->ref_list[0][0]);
+ ff_h264_set_erpic(&sl->er.last_pic, &sl->ref_list[0][0]);
} else
- ff_h264_set_erpic(&h->er.last_pic, NULL);
+ ff_h264_set_erpic(&sl->er.last_pic, NULL);
if (sl->ref_count[1])
- ff_h264_set_erpic(&h->er.next_pic, &sl->ref_list[1][0]);
+ ff_h264_set_erpic(&sl->er.next_pic, &sl->ref_list[1][0]);
- h->er.ref_count = sl->ref_count[0];
+ sl->er.ref_count = sl->ref_count[0];
- ff_er_frame_end(&h->er);
+ ff_er_frame_end(&sl->er);
if (use_last_pic)
memset(&sl->ref_list[0][0], 0, sizeof(h->last_pic_for_ec));
}
diff --git a/libavcodec/h264_slice.c b/libavcodec/h264_slice.c
index 8814635d92..2cce5547ea 100644
--- a/libavcodec/h264_slice.c
+++ b/libavcodec/h264_slice.c
@@ -545,12 +545,12 @@ int ff_h264_update_thread_context(AVCodecContext *dst,
memset(h->sps_buffers, 0, sizeof(h->sps_buffers));
memset(h->pps_buffers, 0, sizeof(h->pps_buffers));
- memset(&h->er, 0, sizeof(h->er));
memset(&h->cur_pic, 0, sizeof(h->cur_pic));
memset(&h->last_pic_for_ec, 0, sizeof(h->last_pic_for_ec));
h->slice_ctx = orig_slice_ctx;
+ memset(&h->slice_ctx[0].er, 0, sizeof(h->slice_ctx[0].er));
memset(&h->slice_ctx[0].mb, 0, sizeof(h->slice_ctx[0].mb));
memset(&h->slice_ctx[0].mb_luma_dc, 0, sizeof(h->slice_ctx[0].mb_luma_dc));
memset(&h->slice_ctx[0].mb_padding, 0, sizeof(h->slice_ctx[0].mb_padding));
@@ -587,7 +587,7 @@ int ff_h264_update_thread_context(AVCodecContext *dst,
av_log(dst, AV_LOG_ERROR, "Could not allocate memory\n");
return ret;
}
- ret = ff_h264_context_init(h);
+ ret = ff_h264_slice_context_init(h, &h->slice_ctx[0]);
if (ret < 0) {
av_log(dst, AV_LOG_ERROR, "context_init() failed.\n");
return ret;
@@ -741,16 +741,16 @@ static int h264_frame_start(H264Context *h)
h->cur_pic_ptr = pic;
ff_h264_unref_picture(h, &h->cur_pic);
if (CONFIG_ERROR_RESILIENCE) {
- ff_h264_set_erpic(&h->er.cur_pic, NULL);
+ ff_h264_set_erpic(&h->slice_ctx[0].er.cur_pic, NULL);
}
if ((ret = ff_h264_ref_picture(h, &h->cur_pic, h->cur_pic_ptr)) < 0)
return ret;
if (CONFIG_ERROR_RESILIENCE) {
- ff_er_frame_start(&h->er);
- ff_h264_set_erpic(&h->er.last_pic, NULL);
- ff_h264_set_erpic(&h->er.next_pic, NULL);
+ ff_er_frame_start(&h->slice_ctx[0].er);
+ ff_h264_set_erpic(&h->slice_ctx[0].er.last_pic, NULL);
+ ff_h264_set_erpic(&h->slice_ctx[0].er.next_pic, NULL);
}
assert(h->linesize && h->uvlinesize);
@@ -1202,7 +1202,7 @@ static int h264_slice_header_init(H264Context *h, int reinit)
h->slice_context_count = nb_slices;
if (!HAVE_THREADS || !(h->avctx->active_thread_type & FF_THREAD_SLICE)) {
- ret = ff_h264_context_init(h);
+ ret = ff_h264_slice_context_init(h, &h->slice_ctx[0]);
if (ret < 0) {
av_log(h->avctx, AV_LOG_ERROR, "context_init() failed.\n");
goto fail;
@@ -1248,7 +1248,7 @@ static int h264_slice_header_init(H264Context *h, int reinit)
}
for (i = 0; i < h->slice_context_count; i++)
- if ((ret = ff_h264_context_init(h->thread_context[i])) < 0) {
+ if ((ret = ff_h264_slice_context_init(h, &h->slice_ctx[i])) < 0) {
av_log(h->avctx, AV_LOG_ERROR, "context_init() failed.\n");
goto fail;
}
@@ -2371,19 +2371,19 @@ static void decode_finish_row(H264Context *h, H264SliceContext *sl)
ff_h264_draw_horiz_band(h, sl, top, height);
- if (h->droppable || h->er.error_occurred)
+ if (h->droppable || sl->er.error_occurred)
return;
ff_thread_report_progress(&h->cur_pic_ptr->tf, top + height - 1,
h->picture_structure == PICT_BOTTOM_FIELD);
}
-static void er_add_slice(H264Context *h, H264SliceContext *sl,
+static void er_add_slice(H264SliceContext *sl,
int startx, int starty,
int endx, int endy, int status)
{
if (CONFIG_ERROR_RESILIENCE) {
- ERContext *er = &h->er;
+ ERContext *er = &sl->er;
ff_er_add_slice(er, startx, starty, endx, endy, status);
}
@@ -2408,13 +2408,13 @@ static int decode_slice(struct AVCodecContext *avctx, void *arg)
avctx->codec_id != AV_CODEC_ID_H264 ||
(CONFIG_GRAY && (h->flags & CODEC_FLAG_GRAY));
- if (!(h->avctx->active_thread_type & FF_THREAD_SLICE) && h->picture_structure == PICT_FRAME && h->er.error_status_table) {
+ if (!(h->avctx->active_thread_type & FF_THREAD_SLICE) && h->picture_structure == PICT_FRAME && sl->er.error_status_table) {
const int start_i = av_clip(sl->resync_mb_x + sl->resync_mb_y * h->mb_width, 0, h->mb_num - 1);
if (start_i) {
- int prev_status = h->er.error_status_table[h->er.mb_index2xy[start_i - 1]];
+ int prev_status = sl->er.error_status_table[sl->er.mb_index2xy[start_i - 1]];
prev_status &= ~ VP_START;
if (prev_status != (ER_MV_END | ER_DC_END | ER_AC_END))
- h->er.error_occurred = 1;
+ sl->er.error_occurred = 1;
}
}
@@ -2452,7 +2452,7 @@ static int decode_slice(struct AVCodecContext *avctx, void *arg)
if ((h->workaround_bugs & FF_BUG_TRUNCATED) &&
sl->cabac.bytestream > sl->cabac.bytestream_end + 2) {
- er_add_slice(h, sl, sl->resync_mb_x, sl->resync_mb_y, sl->mb_x - 1,
+ er_add_slice(sl, sl->resync_mb_x, sl->resync_mb_y, sl->mb_x - 1,
sl->mb_y, ER_MB_END);
if (sl->mb_x >= lf_x_start)
loop_filter(h, sl, lf_x_start, sl->mb_x + 1);
@@ -2465,7 +2465,7 @@ static int decode_slice(struct AVCodecContext *avctx, void *arg)
"error while decoding MB %d %d, bytestream %"PTRDIFF_SPECIFIER"\n",
sl->mb_x, sl->mb_y,
sl->cabac.bytestream_end - sl->cabac.bytestream);
- er_add_slice(h, sl, sl->resync_mb_x, sl->resync_mb_y, sl->mb_x,
+ er_add_slice(sl, sl->resync_mb_x, sl->resync_mb_y, sl->mb_x,
sl->mb_y, ER_MB_ERROR);
return AVERROR_INVALIDDATA;
}
@@ -2485,7 +2485,7 @@ static int decode_slice(struct AVCodecContext *avctx, void *arg)
if (eos || sl->mb_y >= h->mb_height) {
tprintf(h->avctx, "slice end %d %d\n",
get_bits_count(&sl->gb), sl->gb.size_in_bits);
- er_add_slice(h, sl, sl->resync_mb_x, sl->resync_mb_y, sl->mb_x - 1,
+ er_add_slice(sl, sl->resync_mb_x, sl->resync_mb_y, sl->mb_x - 1,
sl->mb_y, ER_MB_END);
if (sl->mb_x > lf_x_start)
loop_filter(h, sl, lf_x_start, sl->mb_x);
@@ -2512,7 +2512,7 @@ static int decode_slice(struct AVCodecContext *avctx, void *arg)
if (ret < 0) {
av_log(h->avctx, AV_LOG_ERROR,
"error while decoding MB %d %d\n", sl->mb_x, sl->mb_y);
- er_add_slice(h, sl, sl->resync_mb_x, sl->resync_mb_y, sl->mb_x,
+ er_add_slice(sl, sl->resync_mb_x, sl->resync_mb_y, sl->mb_x,
sl->mb_y, ER_MB_ERROR);
return ret;
}
@@ -2533,12 +2533,12 @@ static int decode_slice(struct AVCodecContext *avctx, void *arg)
if ( get_bits_left(&sl->gb) == 0
|| get_bits_left(&sl->gb) > 0 && !(h->avctx->err_recognition & AV_EF_AGGRESSIVE)) {
- er_add_slice(h, sl, sl->resync_mb_x, sl->resync_mb_y,
+ er_add_slice(sl, sl->resync_mb_x, sl->resync_mb_y,
sl->mb_x - 1, sl->mb_y, ER_MB_END);
return 0;
} else {
- er_add_slice(h, sl, sl->resync_mb_x, sl->resync_mb_y,
+ er_add_slice(sl, sl->resync_mb_x, sl->resync_mb_y,
sl->mb_x, sl->mb_y, ER_MB_END);
return AVERROR_INVALIDDATA;
@@ -2551,14 +2551,14 @@ static int decode_slice(struct AVCodecContext *avctx, void *arg)
get_bits_count(&sl->gb), sl->gb.size_in_bits);
if (get_bits_left(&sl->gb) == 0) {
- er_add_slice(h, sl, sl->resync_mb_x, sl->resync_mb_y,
+ er_add_slice(sl, sl->resync_mb_x, sl->resync_mb_y,
sl->mb_x - 1, sl->mb_y, ER_MB_END);
if (sl->mb_x > lf_x_start)
loop_filter(h, sl, lf_x_start, sl->mb_x);
return 0;
} else {
- er_add_slice(h, sl, sl->resync_mb_x, sl->resync_mb_y, sl->mb_x,
+ er_add_slice(sl, sl->resync_mb_x, sl->resync_mb_y, sl->mb_x,
sl->mb_y, ER_MB_ERROR);
return AVERROR_INVALIDDATA;
@@ -2594,8 +2594,9 @@ int ff_h264_execute_decode_slices(H264Context *h, unsigned context_count)
av_assert0(context_count > 0);
for (i = 1; i < context_count; i++) {
hx = h->thread_context[i];
+ sl = &h->slice_ctx[i];
if (CONFIG_ERROR_RESILIENCE) {
- hx->er.error_count = 0;
+ sl->er.error_count = 0;
}
hx->x264_build = h->x264_build;
}
@@ -2611,7 +2612,7 @@ int ff_h264_execute_decode_slices(H264Context *h, unsigned context_count)
h->picture_structure = hx->picture_structure;
if (CONFIG_ERROR_RESILIENCE) {
for (i = 1; i < context_count; i++)
- h->er.error_count += h->thread_context[i]->er.error_count;
+ h->slice_ctx[0].er.error_count += h->slice_ctx[i].er.error_count;
}
}