52 memcpy(
dst->data,
src->f->data,
sizeof(
dst->data));
53 memcpy(
dst->linesize,
src->f->linesize,
sizeof(
dst->linesize));
54 dst->reference =
src->reference;
84 while (
i[0] <
len && !(in[
i[0]] && (in[
i[0]]->reference & sel)))
86 while (
i[1] <
len && !(in[
i[1]] && (in[
i[1]]->reference & (sel ^ 3))))
109 int best_poc = dir ? INT_MIN : INT_MAX;
111 for (
int i = 0;
i <
len;
i++) {
112 const int poc =
src[
i]->poc;
113 if (((poc >
limit) ^ dir) && ((poc < best_poc) ^ dir)) {
115 sorted[out_i] =
src[
i];
118 if (best_poc == (dir ? INT_MIN : INT_MAX))
128 return (
h->cur_pic_ptr->f->width !=
f->width ||
129 h->cur_pic_ptr->f->height !=
f->height ||
130 h->cur_pic_ptr->f->format !=
f->format);
145 cur_poc =
h->cur_pic_ptr->poc;
147 for (
int list = 0; list < 2; list++) {
148 len =
add_sorted(sorted,
h->short_ref,
h->short_ref_count, cur_poc, 1 ^ list);
153 sorted,
len, 0,
h->picture_structure);
156 h->long_ref, 16, 1,
h->picture_structure);
163 if (lens[0] == lens[1] && lens[1] > 1) {
165 for (
i = 0;
i < lens[0] &&
174 h->short_ref,
h->short_ref_count, 0,
h->picture_structure);
177 h-> long_ref, 16, 1,
h->picture_structure);
184 ff_tlog(
h->avctx,
"List0: %s fn:%d 0x%p\n",
191 ff_tlog(
h->avctx,
"List1: %s fn:%d 0x%p\n",
220 for (uint32_t
i = 0;
i <
h->short_ref_count;
i++) {
235 for (uint32_t
i = 0;
i < 16;
i++) {
257 *structure =
h->picture_structure;
270 for (
int list = 0; list < sl->
list_count; list++) {
277 for (
int j = 0; j < 3; j++)
278 field[0].linesize[j] <<= 1;
284 for (
int j = 0; j < 3; j++)
285 field[1].
data[j] +=
frame->parent->f->linesize[j];
299 for (
int list = 0; list < sl->
list_count; list++) {
306 int i, pic_structure;
309 switch (modification_of_pic_nums_idc) {
312 const unsigned int abs_diff_pic_num =
val + 1;
317 "abs_diff_pic_num overflow\n");
321 if (modification_of_pic_nums_idc == 0)
322 pred -= abs_diff_pic_num;
324 pred += abs_diff_pic_num;
329 for (
i =
h->short_ref_count - 1;
i >= 0;
i--) {
330 ref =
h->short_ref[
i];
331 assert(
ref->reference);
332 assert(!
ref->long_ref);
333 if (
ref->frame_num == frame_num &&
334 (
ref->reference & pic_structure))
347 if (long_idx > 31U) {
349 "long_term_pic_idx overflow\n");
352 ref =
h->long_ref[long_idx];
353 assert(!(
ref && !
ref->reference));
354 if (
ref && (
ref->reference & pic_structure)) {
355 assert(
ref->long_ref);
368 i < 0 ?
"reference picture missing during reorder\n" :
369 "mismatching reference\n"
392 for (
int list = 0; list < sl->
list_count; list++) {
400 av_log(
h->avctx,
AV_LOG_ERROR,
"Missing reference picture, default is %d\n",
h->default_ref[list].poc);
403 h->last_pocs[
i] = INT_MIN;
404 if (
h->default_ref[list].parent
412 int list2 = (list+j)&1;
413 if (
h->default_ref[list2].parent && !
h->default_ref[list2].parent->gray
436 for (
int list = 0; list < sl->
list_count; list++) {
451 "illegal modification_of_pic_nums_idc %u\n",
480 for (
int i = 0;
h->delayed_pic[
i];
i++)
481 if(pic ==
h->delayed_pic[
i]){
499 for (
int i = 0;
i <
h->short_ref_count;
i++) {
519 assert(
i >= 0 &&
i < h->short_ref_count);
521 if (--
h->short_ref_count)
522 memmove(&
h->short_ref[
i], &
h->short_ref[
i + 1],
555 pic =
h->long_ref[
i];
558 assert(
h->long_ref[
i]->long_ref == 1);
559 h->long_ref[
i]->long_ref = 0;
570 for (
int i = 0;
i < 16;
i++)
572 assert(
h->long_ref_count == 0);
574 if (
h->short_ref_count && !
h->last_pic_for_ec.f->data[0]) {
579 for (
int i = 0;
i <
h->short_ref_count;
i++) {
583 h->short_ref_count = 0;
585 memset(
h->default_ref, 0,
sizeof(
h->default_ref));
590 MMCO *mmco =
h->mmco;
593 if (
h->short_ref_count &&
594 h->long_ref_count +
h->short_ref_count >=
h->ps.sps->ref_frame_count &&
597 mmco[0].
short_pic_num =
h->short_ref[
h->short_ref_count - 1]->frame_num;
607 h->nb_mmco = nb_mmco;
612 MMCO *mmco =
h->mmco;
614 int pps_ref_count[2] = {0};
615 int current_ref_assigned = 0, err = 0;
623 if (!
h->explicit_ref_marking)
625 mmco_count =
h->nb_mmco;
630 for (
int i = 0;
i < mmco_count;
i++) {
633 h->mmco[
i].short_pic_num,
h->mmco[
i].long_arg);
635 switch (mmco[
i].opcode) {
645 h->long_ref[mmco[
i].
long_arg]->frame_num != frame_num) {
654 h->mmco[
i].short_pic_num,
h->short_ref_count);
686 if (
h->short_ref[0] ==
h->cur_pic_ptr) {
687 av_log(
h->avctx,
AV_LOG_ERROR,
"mmco: cannot assign current picture to short and long at the same time\n");
692 if (
h->cur_pic_ptr->long_ref) {
694 if (
h->long_ref[j] ==
h->cur_pic_ptr) {
695 if (j != mmco[
i].long_arg)
696 av_log(
h->avctx,
AV_LOG_ERROR,
"mmco: cannot assign current picture to 2 long term references\n");
702 if (
h->long_ref[mmco[
i].
long_arg] !=
h->cur_pic_ptr) {
711 h->cur_pic_ptr->reference |=
h->picture_structure;
712 current_ref_assigned = 1;
715 assert(mmco[
i].long_arg <= 16);
717 for (
int j = mmco[
i].long_arg; j < 16; j++)
721 while (
h->short_ref_count) {
724 for (
int j = 0; j < 16; j++)
726 h->poc.frame_num =
h->cur_pic_ptr->frame_num = 0;
728 h->cur_pic_ptr->mmco_reset = 1;
730 h->last_pocs[j] = INT_MIN;
736 if (!current_ref_assigned) {
743 if (
h->short_ref_count &&
h->short_ref[0] ==
h->cur_pic_ptr) {
745 h->cur_pic_ptr->reference |=
h->picture_structure;
746 }
else if (
h->cur_pic_ptr->long_ref) {
748 "assignment for second field "
749 "in complementary field pair "
750 "(first field is long term)\n");
759 if (
h->short_ref_count)
760 memmove(&
h->short_ref[1], &
h->short_ref[0],
763 h->short_ref[0] =
h->cur_pic_ptr;
764 h->short_ref_count++;
765 h->cur_pic_ptr->reference |=
h->picture_structure;
769 if (
h->long_ref_count +
h->short_ref_count >
FFMAX(
h->ps.sps->ref_frame_count, 1)) {
776 "number of reference frames (%d+%d) exceeds max (%d; probably "
777 "corrupt input), discarding one\n",
778 h->long_ref_count,
h->short_ref_count,
h->ps.sps->ref_frame_count);
781 if (
h->long_ref_count && !
h->short_ref_count) {
783 for (
i = 0;
i < 16; ++
i)
795 for (
int i = 0;
i <
h->short_ref_count;
i++) {
799 if (d >
h->ps.sps->ref_frame_count)
808 if (
h->ps.pps_list[
i]) {
810 pps_ref_count[0] =
FFMAX(pps_ref_count[0],
pps->ref_count[0]);
811 pps_ref_count[1] =
FFMAX(pps_ref_count[1],
pps->ref_count[1]);
817 &&
h->long_ref_count==0
818 && (
h->short_ref_count<=2
819 || pps_ref_count[0] <= 2 && pps_ref_count[1] <= 1 &&
h->avctx->has_b_frames
820 || pps_ref_count[0] <= 1 + (
h->picture_structure !=
PICT_FRAME) && pps_ref_count[1] <= 1)
821 && pps_ref_count[0]<=2 + (
h->picture_structure !=
PICT_FRAME) + (2*!
h->has_recovery_point)
824 if(!
h->avctx->has_b_frames)
862 if (long_arg >= 32 ||
867 "illegal long ref in memory management control "
868 "operation %d\n", opcode);
877 "illegal memory management control operation %d\n",
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t intptr_t int int16_t * dst
static double val(void *priv, double ch)
simple assert() macros that are a bit more flexible than ISO C assert().
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Libavcodec external API header.
#define i(width, name, range_min, range_max)
static int FUNC nal(CodedBitstreamContext *ctx, RWContext *rw, LCEVCRawNAL *current, int nal_unit_type)
#define AV_EF_EXPLODE
abort decoding on minor error detection
static unsigned int get_bits1(GetBitContext *s)
static void skip_bits1(GetBitContext *s)
static int get_ue_golomb_31(GetBitContext *gb)
read unsigned exp golomb code, constraint to a max of 31.
static unsigned get_ue_golomb_long(GetBitContext *gb)
Read an unsigned Exp-Golomb code in the range 0 to UINT32_MAX-1.
int av_buffer_get_ref_count(const AVBufferRef *buf)
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
@ AV_PICTURE_TYPE_I
Intra.
@ AV_PICTURE_TYPE_B
Bi-dir predicted.
H.264 common definitions.
MMCOOpcode
Memory management control operation opcode.
void ff_h264_unref_picture(H264Picture *pic)
int ff_h264_ref_picture(H264Picture *dst, const H264Picture *src)
static void pic_as_field(H264Ref *pic, const int parity)
static H264Picture * remove_short(H264Context *h, int frame_num, int ref_mask)
int ff_h264_decode_ref_pic_list_reordering(H264SliceContext *sl, void *logctx)
int ff_h264_decode_ref_pic_marking(H264SliceContext *sl, GetBitContext *gb, const H2645NAL *nal, void *logctx)
static int split_field_copy(H264Ref *dest, const H264Picture *src, int parity, int id_add)
static void h264_fill_mbaff_ref_list(H264SliceContext *sl)
static int mismatches_ref(const H264Context *h, const H264Picture *pic)
void ff_h264_remove_all_refs(H264Context *h)
static void generate_sliding_window_mmcos(H264Context *h)
static void ref_from_h264pic(H264Ref *dst, const H264Picture *src)
static H264Picture * remove_long(H264Context *h, int i, int ref_mask)
Remove a picture from the long term reference list by its index in that list.
int ff_h264_execute_ref_pic_marking(H264Context *h)
Execute the reference picture marking (memory management control operations).
static int add_sorted(H264Picture **sorted, H264Picture *const *src, int len, int limit, int dir)
static void remove_short_at_index(H264Context *h, int i)
Remove a picture from the short term reference list by its index in that list.
static int pic_num_extract(const H264Context *h, int pic_num, int *structure)
Extract structure information about the picture described by pic_num in the current decoding context ...
static void print_long_term(const H264Context *h)
print long term list
int ff_h264_build_ref_list(H264Context *h, H264SliceContext *sl)
static int unreference_pic(H264Context *h, H264Picture *pic, int refmask)
Mark a picture as no longer needed for reference.
static int build_def_list(H264Ref *def, int def_len, H264Picture *const *in, int len, int is_long, int sel)
static void h264_initialise_ref_list(H264Context *h, H264SliceContext *sl)
static H264Picture * find_short(H264Context *h, int frame_num, int *idx)
Find a H264Picture in the short term reference list by frame number.
static void print_short_term(const H264Context *h)
print short term list
H.264 / AVC / MPEG-4 part10 codec.
#define FRAME_RECOVERED_HEURISTIC
Recovery point detected by heuristic.
static int op(uint8_t **dst, const uint8_t *dst_end, GetByteContext *gb, int pixel, int count, int *x, int width, int linesize)
Perform decode operation.
#define DELAYED_PIC_REF
Value of Picture.reference when Picture is not a reference picture, but is held for delayed output.
#define FFSWAP(type, a, b)
#define PICT_BOTTOM_FIELD
#define FF_ARRAY_ELEMS(a)
static const float pred[4]
This structure describes decoded (raw) audio or video data.
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
AVBufferRef * buf[AV_NUM_DATA_POINTERS]
AVBuffer references backing the data for this frame.
int pic_id
pic_num (short -> no wrap version of pic_num, pic_num & max_pic_num; long -> long_pic_num)
int frame_num
frame_num (raw frame_num from slice header)
int long_ref
1->long term reference 0->short term reference
int field_poc[2]
top/bottom POC
const H264Picture * parent
int nb_ref_modifications[2]
int slice_type_nos
S free slice type (SI/SP are remapped to I/P)
H264Ref ref_list[2][48]
0..15: frame refs, 16..47: mbaff field refs.
struct H264SliceContext::@124061371101161022054012115351023212223223305145 ref_modifications[2][32]
unsigned int ref_count[2]
num_ref_idx_l0/1_active_minus1 + 1
MMCO mmco[H264_MAX_MMCO_COUNT]
Memory management control operation.
int long_arg
index, pic_num, or num long refs depending on opcode
int short_pic_num
pic_num without wrapping (pic_num & max_pic_num)
static int ref[MAX_W *MAX_W]
static double limit(double x)