Commit 40539898 authored by Clément Bœsch's avatar Clément Bœsch

Merge commit 'b77fffa1'

* commit 'b77fffa1':
  h264: make slice threading work with deblocking_filter=1

again label, and SLICE_SINGLETHREAD error handling are preserved as that
SLICE_SINGLETHREAD can be raised on a remaining case.

slice_context_count is also kept since it's still in use.
Merged-by: 's avatarClément Bœsch <clement@stupeflix.com>
parents c8f7a233 b77fffa1
...@@ -407,7 +407,6 @@ typedef struct H264SliceContext { ...@@ -407,7 +407,6 @@ typedef struct H264SliceContext {
H264Ref ref_list[2][48]; /**< 0..15: frame refs, 16..47: mbaff field refs. H264Ref ref_list[2][48]; /**< 0..15: frame refs, 16..47: mbaff field refs.
* Reordered version of default_ref_list * Reordered version of default_ref_list
* according to picture reordering in slice header */ * according to picture reordering in slice header */
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; const uint8_t *intra_pcm_ptr;
int16_t *dc_val_base; int16_t *dc_val_base;
...@@ -494,6 +493,11 @@ typedef struct H264Context { ...@@ -494,6 +493,11 @@ typedef struct H264Context {
int context_initialized; int context_initialized;
int flags; int flags;
int workaround_bugs; int workaround_bugs;
/* Set when slice threading is used and at least one slice uses deblocking
* mode 1 (i.e. across slice boundaries). Then we disable the loop filter
* during normal MB decoding and execute it serially at the end.
*/
int postpone_filter;
int8_t(*intra4x4_pred_mode); int8_t(*intra4x4_pred_mode);
H264PredContext hpc; H264PredContext hpc;
...@@ -685,6 +689,7 @@ typedef struct H264Context { ...@@ -685,6 +689,7 @@ typedef struct H264Context {
AVBufferPool *mb_type_pool; AVBufferPool *mb_type_pool;
AVBufferPool *motion_val_pool; AVBufferPool *motion_val_pool;
AVBufferPool *ref_index_pool; AVBufferPool *ref_index_pool;
int ref2frm[MAX_SLICES][2][64]; ///< reference to frame number lists, used in the loop filter, the first 2 are for -2,-1
} H264Context; } H264Context;
extern const uint16_t ff_h264_mb_sizes[4]; extern const uint16_t ff_h264_mb_sizes[4];
......
...@@ -551,6 +551,8 @@ static int h264_frame_start(H264Context *h) ...@@ -551,6 +551,8 @@ static int h264_frame_start(H264Context *h)
h->next_output_pic = NULL; h->next_output_pic = NULL;
h->postpone_filter = 0;
assert(h->cur_pic_ptr->long_ref == 0); assert(h->cur_pic_ptr->long_ref == 0);
return 0; return 0;
...@@ -1040,7 +1042,7 @@ static enum AVPixelFormat non_j_pixfmt(enum AVPixelFormat a) ...@@ -1040,7 +1042,7 @@ static enum AVPixelFormat non_j_pixfmt(enum AVPixelFormat a)
* *
* @param h h264context * @param h h264context
* *
* @return 0 if okay, <0 if an error occurred, 1 if decoding must not be multithreaded * @return 0 if okay, <0 if an error occurred
*/ */
int ff_h264_decode_slice_header(H264Context *h, H264SliceContext *sl) int ff_h264_decode_slice_header(H264Context *h, H264SliceContext *sl)
{ {
...@@ -1742,20 +1744,7 @@ int ff_h264_decode_slice_header(H264Context *h, H264SliceContext *sl) ...@@ -1742,20 +1744,7 @@ int ff_h264_decode_slice_header(H264Context *h, H264SliceContext *sl)
* Do not bother to deblock across slices. */ * Do not bother to deblock across slices. */
sl->deblocking_filter = 2; sl->deblocking_filter = 2;
} else { } else {
h->max_contexts = 1; h->postpone_filter = 1;
if (!h->single_decode_warning) {
av_log(h->avctx, AV_LOG_INFO,
"Cannot parallelize slice decoding with deblocking filter type 1, decoding such frames in sequential order\n"
"To parallelize slice decoding you need video encoded with disable_deblocking_filter_idc set to 2 (deblock only edges that do not cross slices).\n"
"Setting the flags2 libavcodec option to +fast (-flags2 +fast) will disable deblocking across slices and enable parallel slice decoding "
"but will generate non-standard-compliant output.\n");
h->single_decode_warning = 1;
}
if (sl != h->slice_ctx) {
av_log(h->avctx, AV_LOG_ERROR,
"Deblocking switched inside frame.\n");
return SLICE_SINGLETHREAD;
}
} }
} }
sl->qp_thresh = 15 - sl->qp_thresh = 15 -
...@@ -1778,7 +1767,7 @@ int ff_h264_decode_slice_header(H264Context *h, H264SliceContext *sl) ...@@ -1778,7 +1767,7 @@ int ff_h264_decode_slice_header(H264Context *h, H264SliceContext *sl)
for (j = 0; j < 2; j++) { for (j = 0; j < 2; j++) {
int id_list[16]; int id_list[16];
int *ref2frm = sl->ref2frm[sl->slice_num & (MAX_SLICES - 1)][j]; int *ref2frm = h->ref2frm[sl->slice_num & (MAX_SLICES - 1)][j];
for (i = 0; i < 16; i++) { for (i = 0; i < 16; i++) {
id_list[i] = 60; id_list[i] = 60;
if (j < sl->list_count && i < sl->ref_count[j] && if (j < sl->list_count && i < sl->ref_count[j] &&
...@@ -1869,7 +1858,7 @@ static av_always_inline void fill_filter_caches_inter(const H264Context *h, ...@@ -1869,7 +1858,7 @@ static av_always_inline void fill_filter_caches_inter(const H264Context *h,
if (USES_LIST(top_type, list)) { if (USES_LIST(top_type, list)) {
const int b_xy = h->mb2b_xy[top_xy] + 3 * b_stride; const int b_xy = h->mb2b_xy[top_xy] + 3 * b_stride;
const int b8_xy = 4 * top_xy + 2; const int b8_xy = 4 * top_xy + 2;
int *ref2frm = sl->ref2frm[h->slice_table[top_xy] & (MAX_SLICES - 1)][list] + (MB_MBAFF(sl) ? 20 : 2); int *ref2frm = h->ref2frm[h->slice_table[top_xy] & (MAX_SLICES - 1)][list] + (MB_MBAFF(sl) ? 20 : 2);
AV_COPY128(mv_dst - 1 * 8, h->cur_pic.motion_val[list][b_xy + 0]); AV_COPY128(mv_dst - 1 * 8, h->cur_pic.motion_val[list][b_xy + 0]);
ref_cache[0 - 1 * 8] = ref_cache[0 - 1 * 8] =
ref_cache[1 - 1 * 8] = ref2frm[h->cur_pic.ref_index[list][b8_xy + 0]]; ref_cache[1 - 1 * 8] = ref2frm[h->cur_pic.ref_index[list][b8_xy + 0]];
...@@ -1884,7 +1873,7 @@ static av_always_inline void fill_filter_caches_inter(const H264Context *h, ...@@ -1884,7 +1873,7 @@ static av_always_inline void fill_filter_caches_inter(const H264Context *h,
if (USES_LIST(left_type[LTOP], list)) { if (USES_LIST(left_type[LTOP], list)) {
const int b_xy = h->mb2b_xy[left_xy[LTOP]] + 3; const int b_xy = h->mb2b_xy[left_xy[LTOP]] + 3;
const int b8_xy = 4 * left_xy[LTOP] + 1; const int b8_xy = 4 * left_xy[LTOP] + 1;
int *ref2frm = sl->ref2frm[h->slice_table[left_xy[LTOP]] & (MAX_SLICES - 1)][list] + (MB_MBAFF(sl) ? 20 : 2); int *ref2frm = h->ref2frm[h->slice_table[left_xy[LTOP]] & (MAX_SLICES - 1)][list] + (MB_MBAFF(sl) ? 20 : 2);
AV_COPY32(mv_dst - 1 + 0, h->cur_pic.motion_val[list][b_xy + b_stride * 0]); AV_COPY32(mv_dst - 1 + 0, h->cur_pic.motion_val[list][b_xy + b_stride * 0]);
AV_COPY32(mv_dst - 1 + 8, h->cur_pic.motion_val[list][b_xy + b_stride * 1]); AV_COPY32(mv_dst - 1 + 8, h->cur_pic.motion_val[list][b_xy + b_stride * 1]);
AV_COPY32(mv_dst - 1 + 16, h->cur_pic.motion_val[list][b_xy + b_stride * 2]); AV_COPY32(mv_dst - 1 + 16, h->cur_pic.motion_val[list][b_xy + b_stride * 2]);
...@@ -1917,7 +1906,7 @@ static av_always_inline void fill_filter_caches_inter(const H264Context *h, ...@@ -1917,7 +1906,7 @@ static av_always_inline void fill_filter_caches_inter(const H264Context *h,
{ {
int8_t *ref = &h->cur_pic.ref_index[list][4 * mb_xy]; int8_t *ref = &h->cur_pic.ref_index[list][4 * mb_xy];
int *ref2frm = sl->ref2frm[sl->slice_num & (MAX_SLICES - 1)][list] + (MB_MBAFF(sl) ? 20 : 2); int *ref2frm = h->ref2frm[sl->slice_num & (MAX_SLICES - 1)][list] + (MB_MBAFF(sl) ? 20 : 2);
uint32_t ref01 = (pack16to32(ref2frm[ref[0]], ref2frm[ref[1]]) & 0x00FF00FF) * 0x0101; uint32_t ref01 = (pack16to32(ref2frm[ref[0]], ref2frm[ref[1]]) & 0x00FF00FF) * 0x0101;
uint32_t ref23 = (pack16to32(ref2frm[ref[2]], ref2frm[ref[3]]) & 0x00FF00FF) * 0x0101; uint32_t ref23 = (pack16to32(ref2frm[ref[2]], ref2frm[ref[3]]) & 0x00FF00FF) * 0x0101;
AV_WN32A(&ref_cache[0 * 8], ref01); AV_WN32A(&ref_cache[0 * 8], ref01);
...@@ -2092,6 +2081,9 @@ static void loop_filter(const H264Context *h, H264SliceContext *sl, int start_x, ...@@ -2092,6 +2081,9 @@ static void loop_filter(const H264Context *h, H264SliceContext *sl, int start_x,
const int pixel_shift = h->pixel_shift; const int pixel_shift = h->pixel_shift;
const int block_h = 16 >> h->chroma_y_shift; const int block_h = 16 >> h->chroma_y_shift;
if (h->postpone_filter)
return;
if (sl->deblocking_filter) { if (sl->deblocking_filter) {
for (mb_x = start_x; mb_x < end_x; mb_x++) for (mb_x = start_x; mb_x < end_x; mb_x++)
for (mb_y = end_mb_y - FRAME_MBAFF(h); mb_y <= end_mb_y; mb_y++) { for (mb_y = end_mb_y - FRAME_MBAFF(h); mb_y <= end_mb_y; mb_y++) {
...@@ -2215,6 +2207,7 @@ static int decode_slice(struct AVCodecContext *avctx, void *arg) ...@@ -2215,6 +2207,7 @@ static int decode_slice(struct AVCodecContext *avctx, void *arg)
H264SliceContext *sl = arg; H264SliceContext *sl = arg;
const H264Context *h = sl->h264; const H264Context *h = sl->h264;
int lf_x_start = sl->mb_x; int lf_x_start = sl->mb_x;
int orig_deblock = sl->deblocking_filter;
int ret; int ret;
sl->linesize = h->cur_pic_ptr->f->linesize[0]; sl->linesize = h->cur_pic_ptr->f->linesize[0];
...@@ -2228,6 +2221,9 @@ static int decode_slice(struct AVCodecContext *avctx, void *arg) ...@@ -2228,6 +2221,9 @@ static int decode_slice(struct AVCodecContext *avctx, void *arg)
av_assert0(h->block_offset[15] == (4 * ((scan8[15] - scan8[0]) & 7) << h->pixel_shift) + 4 * sl->linesize * ((scan8[15] - scan8[0]) >> 3)); av_assert0(h->block_offset[15] == (4 * ((scan8[15] - scan8[0]) & 7) << h->pixel_shift) + 4 * sl->linesize * ((scan8[15] - scan8[0]) >> 3));
if (h->postpone_filter)
sl->deblocking_filter = 0;
sl->is_complex = FRAME_MBAFF(h) || h->picture_structure != PICT_FRAME || sl->is_complex = FRAME_MBAFF(h) || h->picture_structure != PICT_FRAME ||
avctx->codec_id != AV_CODEC_ID_H264 || avctx->codec_id != AV_CODEC_ID_H264 ||
(CONFIG_GRAY && (h->flags & AV_CODEC_FLAG_GRAY)); (CONFIG_GRAY && (h->flags & AV_CODEC_FLAG_GRAY));
...@@ -2290,7 +2286,7 @@ static int decode_slice(struct AVCodecContext *avctx, void *arg) ...@@ -2290,7 +2286,7 @@ static int decode_slice(struct AVCodecContext *avctx, void *arg)
sl->mb_y, ER_MB_END); sl->mb_y, ER_MB_END);
if (sl->mb_x >= lf_x_start) if (sl->mb_x >= lf_x_start)
loop_filter(h, sl, lf_x_start, sl->mb_x + 1); loop_filter(h, sl, lf_x_start, sl->mb_x + 1);
return 0; goto finish;
} }
if (sl->cabac.bytestream > sl->cabac.bytestream_end + 2 ) if (sl->cabac.bytestream > sl->cabac.bytestream_end + 2 )
av_log(h->avctx, AV_LOG_DEBUG, "bytestream overread %"PTRDIFF_SPECIFIER"\n", sl->cabac.bytestream_end - sl->cabac.bytestream); av_log(h->avctx, AV_LOG_DEBUG, "bytestream overread %"PTRDIFF_SPECIFIER"\n", sl->cabac.bytestream_end - sl->cabac.bytestream);
...@@ -2323,7 +2319,7 @@ static int decode_slice(struct AVCodecContext *avctx, void *arg) ...@@ -2323,7 +2319,7 @@ static int decode_slice(struct AVCodecContext *avctx, void *arg)
sl->mb_y, ER_MB_END); sl->mb_y, ER_MB_END);
if (sl->mb_x > lf_x_start) if (sl->mb_x > lf_x_start)
loop_filter(h, sl, lf_x_start, sl->mb_x); loop_filter(h, sl, lf_x_start, sl->mb_x);
return 0; goto finish;
} }
} }
} else { } else {
...@@ -2380,7 +2376,7 @@ static int decode_slice(struct AVCodecContext *avctx, void *arg) ...@@ -2380,7 +2376,7 @@ static int decode_slice(struct AVCodecContext *avctx, void *arg)
er_add_slice(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); sl->mb_x - 1, sl->mb_y, ER_MB_END);
return 0; goto finish;
} else { } else {
er_add_slice(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); sl->mb_x, sl->mb_y, ER_MB_END);
...@@ -2400,7 +2396,7 @@ static int decode_slice(struct AVCodecContext *avctx, void *arg) ...@@ -2400,7 +2396,7 @@ static int decode_slice(struct AVCodecContext *avctx, void *arg)
if (sl->mb_x > lf_x_start) if (sl->mb_x > lf_x_start)
loop_filter(h, sl, lf_x_start, sl->mb_x); loop_filter(h, sl, lf_x_start, sl->mb_x);
return 0; goto finish;
} else { } else {
er_add_slice(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); sl->mb_y, ER_MB_ERROR);
...@@ -2410,6 +2406,10 @@ static int decode_slice(struct AVCodecContext *avctx, void *arg) ...@@ -2410,6 +2406,10 @@ static int decode_slice(struct AVCodecContext *avctx, void *arg)
} }
} }
} }
finish:
sl->deblocking_filter = orig_deblock;
return 0;
} }
/** /**
...@@ -2438,6 +2438,7 @@ int ff_h264_execute_decode_slices(H264Context *h, unsigned context_count) ...@@ -2438,6 +2438,7 @@ int ff_h264_execute_decode_slices(H264Context *h, unsigned context_count)
int ret; int ret;
h->slice_ctx[0].next_slice_idx = h->mb_width * h->mb_height; h->slice_ctx[0].next_slice_idx = h->mb_width * h->mb_height;
h->postpone_filter = 0;
ret = decode_slice(avctx, &h->slice_ctx[0]); ret = decode_slice(avctx, &h->slice_ctx[0]);
h->mb_y = h->slice_ctx[0].mb_y; h->mb_y = h->slice_ctx[0].mb_y;
...@@ -2476,6 +2477,24 @@ int ff_h264_execute_decode_slices(H264Context *h, unsigned context_count) ...@@ -2476,6 +2477,24 @@ int ff_h264_execute_decode_slices(H264Context *h, unsigned context_count)
for (i = 1; i < context_count; i++) for (i = 1; i < context_count; i++)
h->slice_ctx[0].er.error_count += h->slice_ctx[i].er.error_count; h->slice_ctx[0].er.error_count += h->slice_ctx[i].er.error_count;
} }
if (h->postpone_filter) {
h->postpone_filter = 0;
for (i = 0; i < context_count; i++) {
int y_end, x_end;
sl = &h->slice_ctx[i];
y_end = FFMIN(sl->mb_y + 1, h->mb_height);
x_end = (sl->mb_y >= h->mb_height) ? h->mb_width : sl->mb_x;
for (j = sl->resync_mb_y; j < y_end; j += 1 + FIELD_OR_MBAFF_PICTURE(h)) {
sl->mb_y = j;
loop_filter(h, sl, j > sl->resync_mb_y ? 0 : sl->resync_mb_x,
j == y_end - 1 ? x_end : h->mb_width);
}
}
}
} }
return 0; return 0;
......
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