Commit a12d3188 authored by Anton Khirnov's avatar Anton Khirnov

h264: use a smaller struct for the ref lists

There is no need to store a whole H264Picture, with a full AVFrame
embedded in it. This should allow getting rid of the embedded AVFrame
later.
parent 94295106
...@@ -240,7 +240,7 @@ static void fill_slice_long(AVCodecContext *avctx, DXVA_Slice_H264_Long *slice, ...@@ -240,7 +240,7 @@ static void fill_slice_long(AVCodecContext *avctx, DXVA_Slice_H264_Long *slice,
unsigned i; unsigned i;
for (i = 0; i < FF_ARRAY_ELEMS(slice->RefPicList[list]); i++) { for (i = 0; i < FF_ARRAY_ELEMS(slice->RefPicList[list]); i++) {
if (list < sl->list_count && i < sl->ref_count[list]) { if (list < sl->list_count && i < sl->ref_count[list]) {
const H264Picture *r = &sl->ref_list[list][i]; const H264Picture *r = sl->ref_list[list][i].parent;
unsigned plane; unsigned plane;
unsigned index; unsigned index;
if (ctx->workaround & FF_DXVA2_WORKAROUND_INTEL_CLEARVIDEO) if (ctx->workaround & FF_DXVA2_WORKAROUND_INTEL_CLEARVIDEO)
......
...@@ -296,6 +296,17 @@ typedef struct H264Picture { ...@@ -296,6 +296,17 @@ typedef struct H264Picture {
int recovered; ///< picture at IDR or recovery point + recovery count int recovered; ///< picture at IDR or recovery point + recovery count
} H264Picture; } H264Picture;
typedef struct H264Ref {
uint8_t *data[3];
int linesize[3];
int reference;
int poc;
int pic_id;
H264Picture *parent;
} H264Ref;
typedef struct H264SliceContext { typedef struct H264SliceContext {
struct H264Context *h264; struct H264Context *h264;
GetBitContext gb; GetBitContext gb;
...@@ -393,7 +404,7 @@ typedef struct H264SliceContext { ...@@ -393,7 +404,7 @@ typedef struct H264SliceContext {
*/ */
unsigned int ref_count[2]; ///< counts frames or fields, depending on current mb mode unsigned int ref_count[2]; ///< counts frames or fields, depending on current mb mode
unsigned int list_count; unsigned int list_count;
H264Picture 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 int ref2frm[MAX_SLICES][2][64]; ///< reference to frame number lists, used in the loop filter, the first 2 are for -2,-1
...@@ -585,7 +596,7 @@ typedef struct H264Context { ...@@ -585,7 +596,7 @@ typedef struct H264Context {
*/ */
int max_pic_num; int max_pic_num;
H264Picture default_ref_list[2][32]; ///< base reference list for all slices of a coded picture H264Ref default_ref_list[2][32]; ///< base reference list for all slices of a coded picture
H264Picture *short_ref[32]; H264Picture *short_ref[32];
H264Picture *long_ref[32]; H264Picture *long_ref[32];
H264Picture *delayed_pic[MAX_DELAYED_PIC_COUNT + 2]; // FIXME size? H264Picture *delayed_pic[MAX_DELAYED_PIC_COUNT + 2]; // FIXME size?
......
This diff is collapsed.
...@@ -60,12 +60,12 @@ static inline void get_lowest_part_y(const H264Context *h, H264SliceContext *sl, ...@@ -60,12 +60,12 @@ static inline void get_lowest_part_y(const H264Context *h, H264SliceContext *sl,
if (list0) { if (list0) {
int ref_n = sl->ref_cache[0][scan8[n]]; int ref_n = sl->ref_cache[0][scan8[n]];
H264Picture *ref = &sl->ref_list[0][ref_n]; H264Ref *ref = &sl->ref_list[0][ref_n];
// Error resilience puts the current picture in the ref list. // Error resilience puts the current picture in the ref list.
// Don't try to wait on these as it will cause a deadlock. // Don't try to wait on these as it will cause a deadlock.
// Fields can wait on each other, though. // Fields can wait on each other, though.
if (ref->tf.progress->data != h->cur_pic.tf.progress->data || if (ref->parent->tf.progress->data != h->cur_pic.tf.progress->data ||
(ref->reference & 3) != h->picture_structure) { (ref->reference & 3) != h->picture_structure) {
my = get_lowest_part_list_y(sl, n, height, y_offset, 0); my = get_lowest_part_list_y(sl, n, height, y_offset, 0);
if (refs[0][ref_n] < 0) if (refs[0][ref_n] < 0)
...@@ -76,9 +76,9 @@ static inline void get_lowest_part_y(const H264Context *h, H264SliceContext *sl, ...@@ -76,9 +76,9 @@ static inline void get_lowest_part_y(const H264Context *h, H264SliceContext *sl,
if (list1) { if (list1) {
int ref_n = sl->ref_cache[1][scan8[n]]; int ref_n = sl->ref_cache[1][scan8[n]];
H264Picture *ref = &sl->ref_list[1][ref_n]; H264Ref *ref = &sl->ref_list[1][ref_n];
if (ref->tf.progress->data != h->cur_pic.tf.progress->data || if (ref->parent->tf.progress->data != h->cur_pic.tf.progress->data ||
(ref->reference & 3) != h->picture_structure) { (ref->reference & 3) != h->picture_structure) {
my = get_lowest_part_list_y(sl, n, height, y_offset, 1); my = get_lowest_part_list_y(sl, n, height, y_offset, 1);
if (refs[1][ref_n] < 0) if (refs[1][ref_n] < 0)
...@@ -167,33 +167,33 @@ static void await_references(const H264Context *h, H264SliceContext *sl) ...@@ -167,33 +167,33 @@ static void await_references(const H264Context *h, H264SliceContext *sl)
for (ref = 0; ref < 48 && nrefs[list]; ref++) { for (ref = 0; ref < 48 && nrefs[list]; ref++) {
int row = refs[list][ref]; int row = refs[list][ref];
if (row >= 0) { if (row >= 0) {
H264Picture *ref_pic = &sl->ref_list[list][ref]; H264Ref *ref_pic = &sl->ref_list[list][ref];
int ref_field = ref_pic->reference - 1; int ref_field = ref_pic->reference - 1;
int ref_field_picture = ref_pic->field_picture; int ref_field_picture = ref_pic->parent->field_picture;
int pic_height = 16 * h->mb_height >> ref_field_picture; int pic_height = 16 * h->mb_height >> ref_field_picture;
row <<= MB_MBAFF(sl); row <<= MB_MBAFF(sl);
nrefs[list]--; nrefs[list]--;
if (!FIELD_PICTURE(h) && ref_field_picture) { // frame referencing two fields if (!FIELD_PICTURE(h) && ref_field_picture) { // frame referencing two fields
ff_thread_await_progress(&ref_pic->tf, ff_thread_await_progress(&ref_pic->parent->tf,
FFMIN((row >> 1) - !(row & 1), FFMIN((row >> 1) - !(row & 1),
pic_height - 1), pic_height - 1),
1); 1);
ff_thread_await_progress(&ref_pic->tf, ff_thread_await_progress(&ref_pic->parent->tf,
FFMIN((row >> 1), pic_height - 1), FFMIN((row >> 1), pic_height - 1),
0); 0);
} else if (FIELD_PICTURE(h) && !ref_field_picture) { // field referencing one field of a frame } else if (FIELD_PICTURE(h) && !ref_field_picture) { // field referencing one field of a frame
ff_thread_await_progress(&ref_pic->tf, ff_thread_await_progress(&ref_pic->parent->tf,
FFMIN(row * 2 + ref_field, FFMIN(row * 2 + ref_field,
pic_height - 1), pic_height - 1),
0); 0);
} else if (FIELD_PICTURE(h)) { } else if (FIELD_PICTURE(h)) {
ff_thread_await_progress(&ref_pic->tf, ff_thread_await_progress(&ref_pic->parent->tf,
FFMIN(row, pic_height - 1), FFMIN(row, pic_height - 1),
ref_field); ref_field);
} else { } else {
ff_thread_await_progress(&ref_pic->tf, ff_thread_await_progress(&ref_pic->parent->tf,
FFMIN(row, pic_height - 1), FFMIN(row, pic_height - 1),
0); 0);
} }
...@@ -202,7 +202,7 @@ static void await_references(const H264Context *h, H264SliceContext *sl) ...@@ -202,7 +202,7 @@ static void await_references(const H264Context *h, H264SliceContext *sl)
} }
static av_always_inline void mc_dir_part(const H264Context *h, H264SliceContext *sl, static av_always_inline void mc_dir_part(const H264Context *h, H264SliceContext *sl,
H264Picture *pic, H264Ref *pic,
int n, int square, int height, int n, int square, int height,
int delta, int list, int delta, int list,
uint8_t *dest_y, uint8_t *dest_cb, uint8_t *dest_y, uint8_t *dest_cb,
...@@ -216,7 +216,7 @@ static av_always_inline void mc_dir_part(const H264Context *h, H264SliceContext ...@@ -216,7 +216,7 @@ static av_always_inline void mc_dir_part(const H264Context *h, H264SliceContext
int my = sl->mv_cache[list][scan8[n]][1] + src_y_offset * 8; int my = sl->mv_cache[list][scan8[n]][1] + src_y_offset * 8;
const int luma_xy = (mx & 3) + ((my & 3) << 2); const int luma_xy = (mx & 3) + ((my & 3) << 2);
ptrdiff_t offset = ((mx >> 2) << pixel_shift) + (my >> 2) * sl->mb_linesize; ptrdiff_t offset = ((mx >> 2) << pixel_shift) + (my >> 2) * sl->mb_linesize;
uint8_t *src_y = pic->f.data[0] + offset; uint8_t *src_y = pic->data[0] + offset;
uint8_t *src_cb, *src_cr; uint8_t *src_cb, *src_cr;
int extra_width = 0; int extra_width = 0;
int extra_height = 0; int extra_height = 0;
...@@ -253,7 +253,7 @@ static av_always_inline void mc_dir_part(const H264Context *h, H264SliceContext ...@@ -253,7 +253,7 @@ static av_always_inline void mc_dir_part(const H264Context *h, H264SliceContext
return; return;
if (chroma_idc == 3 /* yuv444 */) { if (chroma_idc == 3 /* yuv444 */) {
src_cb = pic->f.data[1] + offset; src_cb = pic->data[1] + offset;
if (emu) { if (emu) {
h->vdsp.emulated_edge_mc(sl->edge_emu_buffer, h->vdsp.emulated_edge_mc(sl->edge_emu_buffer,
src_cb - (2 << pixel_shift) - 2 * sl->mb_linesize, src_cb - (2 << pixel_shift) - 2 * sl->mb_linesize,
...@@ -267,7 +267,7 @@ static av_always_inline void mc_dir_part(const H264Context *h, H264SliceContext ...@@ -267,7 +267,7 @@ static av_always_inline void mc_dir_part(const H264Context *h, H264SliceContext
if (!square) if (!square)
qpix_op[luma_xy](dest_cb + delta, src_cb + delta, sl->mb_linesize); qpix_op[luma_xy](dest_cb + delta, src_cb + delta, sl->mb_linesize);
src_cr = pic->f.data[2] + offset; src_cr = pic->data[2] + offset;
if (emu) { if (emu) {
h->vdsp.emulated_edge_mc(sl->edge_emu_buffer, h->vdsp.emulated_edge_mc(sl->edge_emu_buffer,
src_cr - (2 << pixel_shift) - 2 * sl->mb_linesize, src_cr - (2 << pixel_shift) - 2 * sl->mb_linesize,
...@@ -290,9 +290,9 @@ static av_always_inline void mc_dir_part(const H264Context *h, H264SliceContext ...@@ -290,9 +290,9 @@ static av_always_inline void mc_dir_part(const H264Context *h, H264SliceContext
emu |= (my >> 3) < 0 || (my >> 3) + 8 >= (pic_height >> 1); emu |= (my >> 3) < 0 || (my >> 3) + 8 >= (pic_height >> 1);
} }
src_cb = pic->f.data[1] + ((mx >> 3) << pixel_shift) + src_cb = pic->data[1] + ((mx >> 3) << pixel_shift) +
(my >> ysh) * sl->mb_uvlinesize; (my >> ysh) * sl->mb_uvlinesize;
src_cr = pic->f.data[2] + ((mx >> 3) << pixel_shift) + src_cr = pic->data[2] + ((mx >> 3) << pixel_shift) +
(my >> ysh) * sl->mb_uvlinesize; (my >> ysh) * sl->mb_uvlinesize;
if (emu) { if (emu) {
...@@ -348,7 +348,7 @@ static av_always_inline void mc_part_std(const H264Context *h, H264SliceContext ...@@ -348,7 +348,7 @@ static av_always_inline void mc_part_std(const H264Context *h, H264SliceContext
y_offset += 8 * (sl->mb_y >> MB_FIELD(sl)); y_offset += 8 * (sl->mb_y >> MB_FIELD(sl));
if (list0) { if (list0) {
H264Picture *ref = &sl->ref_list[0][sl->ref_cache[0][scan8[n]]]; H264Ref *ref = &sl->ref_list[0][sl->ref_cache[0][scan8[n]]];
mc_dir_part(h, sl, ref, n, square, height, delta, 0, mc_dir_part(h, sl, ref, n, square, height, delta, 0,
dest_y, dest_cb, dest_cr, x_offset, y_offset, dest_y, dest_cb, dest_cr, x_offset, y_offset,
qpix_op, chroma_op, pixel_shift, chroma_idc); qpix_op, chroma_op, pixel_shift, chroma_idc);
...@@ -358,7 +358,7 @@ static av_always_inline void mc_part_std(const H264Context *h, H264SliceContext ...@@ -358,7 +358,7 @@ static av_always_inline void mc_part_std(const H264Context *h, H264SliceContext
} }
if (list1) { if (list1) {
H264Picture *ref = &sl->ref_list[1][sl->ref_cache[1][scan8[n]]]; H264Ref *ref = &sl->ref_list[1][sl->ref_cache[1][scan8[n]]];
mc_dir_part(h, sl, ref, n, square, height, delta, 1, mc_dir_part(h, sl, ref, n, square, height, delta, 1,
dest_y, dest_cb, dest_cr, x_offset, y_offset, dest_y, dest_cb, dest_cr, x_offset, y_offset,
qpix_op, chroma_op, pixel_shift, chroma_idc); qpix_op, chroma_op, pixel_shift, chroma_idc);
...@@ -451,7 +451,7 @@ static av_always_inline void mc_part_weighted(const H264Context *h, H264SliceCon ...@@ -451,7 +451,7 @@ static av_always_inline void mc_part_weighted(const H264Context *h, H264SliceCon
} else { } else {
int list = list1 ? 1 : 0; int list = list1 ? 1 : 0;
int refn = sl->ref_cache[list][scan8[n]]; int refn = sl->ref_cache[list][scan8[n]];
H264Picture *ref = &sl->ref_list[list][refn]; H264Ref *ref = &sl->ref_list[list][refn];
mc_dir_part(h, sl, ref, n, square, height, delta, list, mc_dir_part(h, sl, ref, n, square, height, delta, list,
dest_y, dest_cb, dest_cr, x_offset, y_offset, dest_y, dest_cb, dest_cr, x_offset, y_offset,
qpix_put, chroma_put, pixel_shift, chroma_idc); qpix_put, chroma_put, pixel_shift, chroma_idc);
...@@ -483,7 +483,7 @@ static av_always_inline void prefetch_motion(const H264Context *h, H264SliceCont ...@@ -483,7 +483,7 @@ static av_always_inline void prefetch_motion(const H264Context *h, H264SliceCont
if (refn >= 0) { if (refn >= 0) {
const int mx = (sl->mv_cache[list][scan8[0]][0] >> 2) + 16 * sl->mb_x + 8; const int mx = (sl->mv_cache[list][scan8[0]][0] >> 2) + 16 * sl->mb_x + 8;
const int my = (sl->mv_cache[list][scan8[0]][1] >> 2) + 16 * sl->mb_y; const int my = (sl->mv_cache[list][scan8[0]][1] >> 2) + 16 * sl->mb_y;
uint8_t **src = sl->ref_list[list][refn].f.data; uint8_t **src = sl->ref_list[list][refn].data;
int off = (mx << pixel_shift) + int off = (mx << pixel_shift) +
(my + (sl->mb_x & 3) * 4) * sl->mb_linesize + (my + (sl->mb_x & 3) * 4) * sl->mb_linesize +
(64 << pixel_shift); (64 << pixel_shift);
......
...@@ -187,9 +187,9 @@ int ff_h264_field_end(H264Context *h, H264SliceContext *sl, int in_setup) ...@@ -187,9 +187,9 @@ int ff_h264_field_end(H264Context *h, H264SliceContext *sl, int in_setup)
if (!FIELD_PICTURE(h)) { if (!FIELD_PICTURE(h)) {
h264_set_erpic(&sl->er.cur_pic, h->cur_pic_ptr); h264_set_erpic(&sl->er.cur_pic, h->cur_pic_ptr);
h264_set_erpic(&sl->er.last_pic, h264_set_erpic(&sl->er.last_pic,
sl->ref_count[0] ? &sl->ref_list[0][0] : NULL); sl->ref_count[0] ? sl->ref_list[0][0].parent : NULL);
h264_set_erpic(&sl->er.next_pic, h264_set_erpic(&sl->er.next_pic,
sl->ref_count[1] ? &sl->ref_list[1][0] : NULL); sl->ref_count[1] ? sl->ref_list[1][0].parent : NULL);
ff_er_frame_end(&sl->er); ff_er_frame_end(&sl->er);
} }
#endif /* CONFIG_ERROR_RESILIENCE */ #endif /* CONFIG_ERROR_RESILIENCE */
......
...@@ -35,31 +35,34 @@ ...@@ -35,31 +35,34 @@
#include <assert.h> #include <assert.h>
#define COPY_PICTURE(dst, src) \ static void pic_as_field(H264Ref *pic, const int parity)
do {\ {
*(dst) = *(src);\
(dst)->f.extended_data = (dst)->f.data;\
(dst)->tf.f = &(dst)->f;\
} while (0)
static void pic_as_field(H264Picture *pic, const int parity){
int i; int i;
for (i = 0; i < 4; ++i) { for (i = 0; i < FF_ARRAY_ELEMS(pic->data); ++i) {
if (parity == PICT_BOTTOM_FIELD) if (parity == PICT_BOTTOM_FIELD)
pic->f.data[i] += pic->f.linesize[i]; pic->data[i] += pic->linesize[i];
pic->reference = parity; pic->reference = parity;
pic->f.linesize[i] *= 2; pic->linesize[i] *= 2;
} }
pic->poc= pic->field_poc[parity == PICT_BOTTOM_FIELD]; pic->poc = pic->parent->field_poc[parity == PICT_BOTTOM_FIELD];
}
static void ref_from_h264pic(H264Ref *dst, H264Picture *src)
{
memcpy(dst->data, src->f.data, sizeof(dst->data));
memcpy(dst->linesize, src->f.linesize, sizeof(dst->linesize));
dst->reference = src->reference;
dst->poc = src->poc;
dst->pic_id = src->pic_id;
dst->parent = src;
} }
static int split_field_copy(H264Picture *dest, H264Picture *src, int parity, int id_add) static int split_field_copy(H264Ref *dest, H264Picture *src, int parity, int id_add)
{ {
int match = !!(src->reference & parity); int match = !!(src->reference & parity);
if (match) { if (match) {
COPY_PICTURE(dest, src); ref_from_h264pic(dest, src);
if (parity != PICT_FRAME) { if (parity != PICT_FRAME) {
pic_as_field(dest, parity); pic_as_field(dest, parity);
dest->pic_id *= 2; dest->pic_id *= 2;
...@@ -70,7 +73,7 @@ static int split_field_copy(H264Picture *dest, H264Picture *src, int parity, int ...@@ -70,7 +73,7 @@ static int split_field_copy(H264Picture *dest, H264Picture *src, int parity, int
return match; return match;
} }
static int build_def_list(H264Picture *def, int def_len, static int build_def_list(H264Ref *def, int def_len,
H264Picture **in, int len, int is_long, int sel) H264Picture **in, int len, int is_long, int sel)
{ {
int i[2] = { 0 }; int i[2] = { 0 };
...@@ -142,19 +145,16 @@ int ff_h264_fill_default_ref_list(H264Context *h, H264SliceContext *sl) ...@@ -142,19 +145,16 @@ int ff_h264_fill_default_ref_list(H264Context *h, H264SliceContext *sl)
h->long_ref, 16, 1, h->picture_structure); h->long_ref, 16, 1, h->picture_structure);
if (len < sl->ref_count[list]) if (len < sl->ref_count[list])
memset(&h->default_ref_list[list][len], 0, sizeof(H264Picture) * (sl->ref_count[list] - len)); memset(&h->default_ref_list[list][len], 0, sizeof(H264Ref) * (sl->ref_count[list] - len));
lens[list] = len; lens[list] = len;
} }
if (lens[0] == lens[1] && lens[1] > 1) { if (lens[0] == lens[1] && lens[1] > 1) {
for (i = 0; i < lens[0] && for (i = 0; i < lens[0] &&
h->default_ref_list[0][i].f.buf[0]->buffer == h->default_ref_list[0][i].parent->f.buf[0]->buffer ==
h->default_ref_list[1][i].f.buf[0]->buffer; i++); h->default_ref_list[1][i].parent->f.buf[0]->buffer; i++);
if (i == lens[0]) { if (i == lens[0]) {
H264Picture tmp; FFSWAP(H264Ref, h->default_ref_list[1][0], h->default_ref_list[1][1]);
COPY_PICTURE(&tmp, &h->default_ref_list[1][0]);
COPY_PICTURE(&h->default_ref_list[1][0], &h->default_ref_list[1][1]);
COPY_PICTURE(&h->default_ref_list[1][1], &tmp);
} }
} }
} else { } else {
...@@ -165,7 +165,7 @@ int ff_h264_fill_default_ref_list(H264Context *h, H264SliceContext *sl) ...@@ -165,7 +165,7 @@ int ff_h264_fill_default_ref_list(H264Context *h, H264SliceContext *sl)
h-> long_ref, 16, 1, h->picture_structure); h-> long_ref, 16, 1, h->picture_structure);
if (len < sl->ref_count[0]) if (len < sl->ref_count[0])
memset(&h->default_ref_list[0][len], 0, sizeof(H264Picture) * (sl->ref_count[0] - len)); memset(&h->default_ref_list[0][len], 0, sizeof(H264Ref) * (sl->ref_count[0] - len));
} }
#ifdef TRACE #ifdef TRACE
for (i = 0; i < sl->ref_count[0]; i++) { for (i = 0; i < sl->ref_count[0]; i++) {
...@@ -214,14 +214,13 @@ static int pic_num_extract(H264Context *h, int pic_num, int *structure) ...@@ -214,14 +214,13 @@ static int pic_num_extract(H264Context *h, int pic_num, int *structure)
int ff_h264_decode_ref_pic_list_reordering(H264Context *h, H264SliceContext *sl) int ff_h264_decode_ref_pic_list_reordering(H264Context *h, H264SliceContext *sl)
{ {
int list, index, pic_structure, i; int list, index, pic_structure;
print_short_term(h); print_short_term(h);
print_long_term(h); print_long_term(h);
for (list = 0; list < sl->list_count; list++) { for (list = 0; list < sl->list_count; list++) {
for (i = 0; i < sl->ref_count[list]; i++) memcpy(sl->ref_list[list], h->default_ref_list[list], sl->ref_count[list] * sizeof(sl->ref_list[0][0]));
COPY_PICTURE(&sl->ref_list[list][i], &h->default_ref_list[list][i]);
if (get_bits1(&sl->gb)) { // ref_pic_list_modification_flag_l[01] if (get_bits1(&sl->gb)) { // ref_pic_list_modification_flag_l[01]
int pred = h->curr_pic_num; int pred = h->curr_pic_num;
...@@ -304,17 +303,18 @@ int ff_h264_decode_ref_pic_list_reordering(H264Context *h, H264SliceContext *sl) ...@@ -304,17 +303,18 @@ int ff_h264_decode_ref_pic_list_reordering(H264Context *h, H264SliceContext *sl)
if (i < 0) { if (i < 0) {
av_log(h->avctx, AV_LOG_ERROR, av_log(h->avctx, AV_LOG_ERROR,
"reference picture missing during reorder\n"); "reference picture missing during reorder\n");
memset(&sl->ref_list[list][index], 0, sizeof(H264Picture)); // FIXME memset(&sl->ref_list[list][index], 0, sizeof(sl->ref_list[0][0])); // FIXME
} else { } else {
for (i = index; i + 1 < sl->ref_count[list]; i++) { for (i = index; i + 1 < sl->ref_count[list]; i++) {
if (ref->long_ref == sl->ref_list[list][i].long_ref && if (sl->ref_list[list][i].parent &&
ref->long_ref == sl->ref_list[list][i].parent->long_ref &&
ref->pic_id == sl->ref_list[list][i].pic_id) ref->pic_id == sl->ref_list[list][i].pic_id)
break; break;
} }
for (; i > index; i--) { for (; i > index; i--) {
COPY_PICTURE(&sl->ref_list[list][i], &sl->ref_list[list][i - 1]); sl->ref_list[list][i] = sl->ref_list[list][i - 1];
} }
COPY_PICTURE(&sl->ref_list[list][index], ref); ref_from_h264pic(&sl->ref_list[list][index], ref);
if (FIELD_PICTURE(h)) { if (FIELD_PICTURE(h)) {
pic_as_field(&sl->ref_list[list][index], pic_structure); pic_as_field(&sl->ref_list[list][index], pic_structure);
} }
...@@ -324,10 +324,10 @@ int ff_h264_decode_ref_pic_list_reordering(H264Context *h, H264SliceContext *sl) ...@@ -324,10 +324,10 @@ int ff_h264_decode_ref_pic_list_reordering(H264Context *h, H264SliceContext *sl)
} }
for (list = 0; list < sl->list_count; list++) { for (list = 0; list < sl->list_count; list++) {
for (index = 0; index < sl->ref_count[list]; index++) { for (index = 0; index < sl->ref_count[list]; index++) {
if (!sl->ref_list[list][index].f.buf[0]) { if (!sl->ref_list[list][index].parent) {
av_log(h->avctx, AV_LOG_ERROR, "Missing reference picture\n"); av_log(h->avctx, AV_LOG_ERROR, "Missing reference picture\n");
if (h->default_ref_list[list][0].f.buf[0]) if (h->default_ref_list[list][0].parent)
COPY_PICTURE(&sl->ref_list[list][index], &h->default_ref_list[list][0]); sl->ref_list[list][index] = h->default_ref_list[list][0];
else else
return -1; return -1;
} }
...@@ -340,20 +340,24 @@ int ff_h264_decode_ref_pic_list_reordering(H264Context *h, H264SliceContext *sl) ...@@ -340,20 +340,24 @@ int ff_h264_decode_ref_pic_list_reordering(H264Context *h, H264SliceContext *sl)
void ff_h264_fill_mbaff_ref_list(H264Context *h, H264SliceContext *sl) void ff_h264_fill_mbaff_ref_list(H264Context *h, H264SliceContext *sl)
{ {
int list, i, j; int list, i, j;
for (list = 0; list < 2; list++) { //FIXME try list_count for (list = 0; list < sl->list_count; list++) { //FIXME try list_count
for (i = 0; i < sl->ref_count[list]; i++) { for (i = 0; i < sl->ref_count[list]; i++) {
H264Picture *frame = &sl->ref_list[list][i]; H264Ref *frame = &sl->ref_list[list][i];
H264Picture *field = &sl->ref_list[list][16 + 2 * i]; H264Ref *field = &sl->ref_list[list][16 + 2 * i];
COPY_PICTURE(field, frame);
field[0] = *frame;
for (j = 0; j < 3; j++) for (j = 0; j < 3; j++)
field[0].f.linesize[j] <<= 1; field[0].linesize[j] <<= 1;
field[0].reference = PICT_TOP_FIELD; field[0].reference = PICT_TOP_FIELD;
field[0].poc = field[0].field_poc[0]; field[0].poc = field[0].parent->field_poc[0];
COPY_PICTURE(field + 1, field);
field[1] = field[0];
for (j = 0; j < 3; j++) for (j = 0; j < 3; j++)
field[1].f.data[j] += frame->f.linesize[j]; field[1].data[j] += frame->parent->f.linesize[j];
field[1].reference = PICT_BOTTOM_FIELD; field[1].reference = PICT_BOTTOM_FIELD;
field[1].poc = field[1].field_poc[1]; field[1].poc = field[1].parent->field_poc[1];
sl->luma_weight[16 + 2 * i][list][0] = sl->luma_weight[16 + 2 * i + 1][list][0] = sl->luma_weight[i][list][0]; sl->luma_weight[16 + 2 * i][list][0] = sl->luma_weight[16 + 2 * i + 1][list][0] = sl->luma_weight[i][list][0];
sl->luma_weight[16 + 2 * i][list][1] = sl->luma_weight[16 + 2 * i + 1][list][1] = sl->luma_weight[i][list][1]; sl->luma_weight[16 + 2 * i][list][1] = sl->luma_weight[16 + 2 * i + 1][list][1] = sl->luma_weight[i][list][1];
......
...@@ -819,7 +819,7 @@ static void implicit_weight_table(const H264Context *h, H264SliceContext *sl, in ...@@ -819,7 +819,7 @@ static void implicit_weight_table(const H264Context *h, H264SliceContext *sl, in
int poc0 = sl->ref_list[0][ref0].poc; int poc0 = sl->ref_list[0][ref0].poc;
for (ref1 = ref_start; ref1 < ref_count1; ref1++) { for (ref1 = ref_start; ref1 < ref_count1; ref1++) {
int w = 32; int w = 32;
if (!sl->ref_list[0][ref0].long_ref && !sl->ref_list[1][ref1].long_ref) { if (!sl->ref_list[0][ref0].parent->long_ref && !sl->ref_list[1][ref1].parent->long_ref) {
int poc1 = sl->ref_list[1][ref1].poc; int poc1 = sl->ref_list[1][ref1].poc;
int td = av_clip_int8(poc1 - poc0); int td = av_clip_int8(poc1 - poc0);
if (td) { if (td) {
...@@ -1652,9 +1652,9 @@ int ff_h264_decode_slice_header(H264Context *h, H264SliceContext *sl) ...@@ -1652,9 +1652,9 @@ int ff_h264_decode_slice_header(H264Context *h, H264SliceContext *sl)
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] &&
sl->ref_list[j][i].f.buf[0]) { sl->ref_list[j][i].parent->f.buf[0]) {
int k; int k;
AVBuffer *buf = sl->ref_list[j][i].f.buf[0]->buffer; AVBuffer *buf = sl->ref_list[j][i].parent->f.buf[0]->buffer;
for (k = 0; k < h->short_ref_count; k++) for (k = 0; k < h->short_ref_count; k++)
if (h->short_ref[k]->f.buf[0]->buffer == buf) { if (h->short_ref[k]->f.buf[0]->buffer == buf) {
id_list[i] = k; id_list[i] = k;
......
...@@ -156,13 +156,13 @@ static int fill_vaapi_ReferenceFrames(VAPictureParameterBufferH264 *pic_param, ...@@ -156,13 +156,13 @@ static int fill_vaapi_ReferenceFrames(VAPictureParameterBufferH264 *pic_param,
* @param[in] ref_count The number of reference pictures in ref_list * @param[in] ref_count The number of reference pictures in ref_list
*/ */
static void fill_vaapi_RefPicList(VAPictureH264 RefPicList[32], static void fill_vaapi_RefPicList(VAPictureH264 RefPicList[32],
H264Picture *ref_list, H264Ref *ref_list,
unsigned int ref_count) unsigned int ref_count)
{ {
unsigned int i, n = 0; unsigned int i, n = 0;
for (i = 0; i < ref_count; i++) for (i = 0; i < ref_count; i++)
if (ref_list[i].reference) if (ref_list[i].reference)
fill_vaapi_pic(&RefPicList[n++], &ref_list[i], 0); fill_vaapi_pic(&RefPicList[n++], ref_list[i].parent, 0);
for (; n < 32; n++) for (; n < 32; n++)
init_vaapi_pic(&RefPicList[n]); init_vaapi_pic(&RefPicList[n]);
......
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