83 while (i[0] < len || i[1] < len) {
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))))
104 int len,
int limit,
int dir)
110 best_poc = dir ? INT_MIN : INT_MAX;
112 for (i = 0; i <
len; i++) {
113 const int poc = src[i]->
poc;
114 if (((poc > limit) ^ dir) && ((poc < best_poc) ^ dir)) {
116 sorted[out_i] = src[i];
119 if (best_poc == (dir ? INT_MIN : INT_MAX))
121 limit = sorted[out_i++]->
poc - dir;
149 for (list = 0; list < 2; list++) {
161 if (len < sl->ref_count[list])
166 if (lens[0] == lens[1] && lens[1] > 1) {
167 for (i = 0; i < lens[0] &&
182 if (len < sl->ref_count[0])
240 for (i = 0; i < 16; i++) {
275 int list,
index, pic_structure;
282 for (list = 0; list < sl->
list_count; list++) {
286 for (index = 0; ; index++) {
292 if (modification_of_pic_nums_idc == 3)
300 switch (modification_of_pic_nums_idc) {
308 "abs_diff_pic_num overflow\n");
312 if (modification_of_pic_nums_idc == 0)
313 pred -= abs_diff_pic_num;
315 pred += abs_diff_pic_num;
338 if (long_idx > 31
U) {
340 "long_term_pic_idx overflow\n");
356 "illegal modification_of_pic_nums_idc %u\n",
357 modification_of_pic_nums_idc);
363 "reference picture missing during reorder\n");
366 for (i = index; i + 1 < sl->
ref_count[list]; i++) {
372 for (; i >
index; i--) {
383 for (list = 0; list < sl->
list_count; list++) {
384 for (index = 0; index < sl->
ref_count[list]; index++) {
407 for (list = 0; list < sl->
list_count; list++) {
408 for (i = 0; i < sl->
ref_count[list]; i++) {
414 for (j = 0; j < 3; j++)
415 field[0].linesize[j] <<= 1;
421 for (j = 0; j < 3; j++)
428 for (j = 0; j < 2; j++) {
494 assert(i >= 0 && i < h->short_ref_count);
547 for (i = 0; i < 16; i++) {
576 for (i = 0; i < n_mmcos; i++) {
577 if (mmco1[i].opcode != mmco2[i].opcode) {
579 mmco1[i].opcode, mmco2[i].opcode, i);
590 int mmco_index = 0, i = 0;
608 }
else if (!first_slice && mmco_index >= 0 &&
612 "Inconsistent MMCO state between slices [%d, %d]\n",
622 int pps_ref_count[2] = {0};
623 int current_ref_assigned = 0, err = 0;
629 for (i = 0; i < mmco_count; i++) {
650 switch (mmco[i].opcode) {
693 if (j != mmco[i].long_arg)
710 current_ref_assigned = 1;
713 assert(mmco[i].long_arg <= 16);
715 for (j = mmco[i].long_arg; j < 16; j++) {
723 for (j = 0; j < 16; j++) {
736 if (!current_ref_assigned) {
748 "assignment for second field "
749 "in complementary field pair "
750 "(first field is long term)\n");
776 "number of reference frames (%d+%d) exceeds max (%d; probably "
777 "corrupt input), discarding one\n",
782 for (i = 0; i < 16; ++i)
796 if (pic->invalid_gap) {
856 "illegal short ref in memory management control "
857 "operation %d\n", mmco);
865 if (long_arg >= 32 ||
870 "illegal long ref in memory management control "
871 "operation %d\n", opcode);
879 "illegal memory management control operation %d\n",
897 if (first_slice && mmco_index != -1) {
898 memcpy(h->
mmco, mmco_temp,
sizeof(h->
mmco));
900 }
else if (!first_slice && mmco_index >= 0 &&
904 "Inconsistent MMCO state between slices [%d, %d]\n",
static int split_field_copy(H264Ref *dest, H264Picture *src, int parity, int id_add)
void ff_h264_unref_picture(H264Context *h, H264Picture *pic)
static int add_sorted(H264Picture **sorted, H264Picture *const *src, int len, int limit, int dir)
Memory management control operation.
int long_ref
1->long term reference 0->short term reference
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
This structure describes decoded (raw) audio or video data.
ptrdiff_t const GLvoid * data
static H264Picture * remove_short(H264Context *h, int frame_num, int ref_mask)
AVBufferRef * buf[AV_NUM_DATA_POINTERS]
AVBuffer references backing the data for this frame.
static int check_opcodes(MMCO *mmco1, MMCO *mmco2, int n_mmcos)
MMCO mmco[MAX_MMCO_COUNT]
memory management control operations buffer.
int chroma_weight[48][2][2][2]
unsigned int ref_count[2]
num_ref_idx_l0/1_active_minus1 + 1
#define DELAYED_PIC_REF
Value of Picture.reference when Picture is not a reference picture, but is held for delayed output...
H264Picture * delayed_pic[MAX_DELAYED_PIC_COUNT+2]
MMCOOpcode
Memory management control operation opcode.
H264Picture * long_ref[32]
static int mismatches_ref(const H264Context *h, const H264Picture *pic)
unsigned int ref_count[2]
num_ref_idx_l0/1_active_minus1 + 1
void ff_h264_remove_all_refs(H264Context *h)
#define av_assert0(cond)
assert() equivalent, that is always enabled.
int short_pic_num
pic_num without wrapping (pic_num & max_pic_num)
static void print_short_term(const H264Context *h)
print short term list
int ff_h264_decode_ref_pic_marking(H264Context *h, GetBitContext *gb, int first_slice)
int frame_recovered
Initial frame has been completely recovered.
#define PICT_BOTTOM_FIELD
#define MAX_DELAYED_PIC_COUNT
int luma_weight[48][2][2]
int recovered
picture at IDR or recovery point + recovery count
int ff_generate_sliding_window_mmcos(H264Context *h, int first_slice)
int last_pocs[MAX_DELAYED_PIC_COUNT]
H.264 / AVC / MPEG-4 part10 codec.
int width
width and height of the video frame
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
int has_b_frames
Size of the frame reordering buffer in the decoder.
static int get_ue_golomb(GetBitContext *gb)
Read an unsigned Exp-Golomb code in the range 0 to 8190.
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
simple assert() macros that are a bit more flexible than ISO C assert().
int frame_num
frame_num (raw frame_num from slice header)
int slice_type_nos
S free slice type (SI/SP are remapped to I/P)
static int unreference_pic(H264Context *h, H264Picture *pic, int refmask)
Mark a picture as no longer needed for reference.
int ref_frame_count
num_ref_frames
enum AVPictureType pict_type
Picture type of the frame.
int err_recognition
Error recognition; may misdetect some more or less valid parts as errors.
int long_ref_count
number of actual long term references
int ff_h264_ref_picture(H264Context *h, H264Picture *dst, H264Picture *src)
H264SliceContext * slice_ctx
#define AV_EF_EXPLODE
abort decoding on minor error detection
int max_pic_num
max_frame_num or 2 * max_frame_num for field pics.
int curr_pic_num
frame_num for frames or 2 * frame_num + 1 for field pics.
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 void ref_from_h264pic(H264Ref *dst, H264Picture *src)
#define FF_ARRAY_ELEMS(a)
static H264Picture * find_short(H264Context *h, int frame_num, int *idx)
Find a H264Picture in the short term reference list by frame number.
static const float pred[4]
static unsigned get_ue_golomb_long(GetBitContext *gb)
Read an unsigned Exp-Golomb code in the range 0 to UINT32_MAX-1.
int format
format of the frame, -1 if unknown or unset Values correspond to enum AVPixelFormat for video frames...
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 ...
int ff_h264_execute_ref_pic_marking(H264Context *h, MMCO *mmco, int mmco_count)
Execute the reference picture marking (memory management control operations).
Libavcodec external API header.
AVBufferRef * pps_list[MAX_PPS_COUNT]
static int get_ue_golomb_31(GetBitContext *gb)
read unsigned exp golomb code, constraint to a max of 31.
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
H264Picture * short_ref[32]
int field_poc[2]
top/bottom POC
uint8_t * data
The data buffer.
static void print_long_term(const H264Context *h)
print long term list
int av_buffer_get_ref_count(const AVBufferRef *buf)
uint8_t pi<< 24) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8, uint8_t,(*(constuint8_t *) pi-0x80)*(1.0f/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8, uint8_t,(*(constuint8_t *) pi-0x80)*(1.0/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16, int16_t,(*(constint16_t *) pi >>8)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16, int16_t,*(constint16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16, int16_t,*(constint16_t *) pi *(1.0/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32, int32_t,(*(constint32_t *) pi >>24)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32, int32_t,*(constint32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32, int32_t,*(constint32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, float, av_clip_uint8(lrintf(*(constfloat *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, float, av_clip_int16(lrintf(*(constfloat *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, float, av_clipl_int32(llrintf(*(constfloat *) pi *(1U<< 31)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, double, av_clip_uint8(lrint(*(constdouble *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, double, av_clip_int16(lrint(*(constdouble *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, double, av_clipl_int32(llrint(*(constdouble *) pi *(1U<< 31))))#defineSET_CONV_FUNC_GROUP(ofmt, ifmt) staticvoidset_generic_function(AudioConvert *ac){}voidff_audio_convert_free(AudioConvert **ac){if(!*ac) return;ff_dither_free(&(*ac) ->dc);av_freep(ac);}AudioConvert *ff_audio_convert_alloc(AVAudioResampleContext *avr, enumAVSampleFormatout_fmt, enumAVSampleFormatin_fmt, intchannels, intsample_rate, intapply_map){AudioConvert *ac;intin_planar, out_planar;ac=av_mallocz(sizeof(*ac));if(!ac) returnNULL;ac->avr=avr;ac->out_fmt=out_fmt;ac->in_fmt=in_fmt;ac->channels=channels;ac->apply_map=apply_map;if(avr->dither_method!=AV_RESAMPLE_DITHER_NONE &&av_get_packed_sample_fmt(out_fmt)==AV_SAMPLE_FMT_S16 &&av_get_bytes_per_sample(in_fmt)>2){ac->dc=ff_dither_alloc(avr, out_fmt, in_fmt, channels, sample_rate, apply_map);if(!ac->dc){av_free(ac);returnNULL;}returnac;}in_planar=ff_sample_fmt_is_planar(in_fmt, channels);out_planar=ff_sample_fmt_is_planar(out_fmt, channels);if(in_planar==out_planar){ac->func_type=CONV_FUNC_TYPE_FLAT;ac->planes=in_planar?ac->channels:1;}elseif(in_planar) ac->func_type=CONV_FUNC_TYPE_INTERLEAVE;elseac->func_type=CONV_FUNC_TYPE_DEINTERLEAVE;set_generic_function(ac);if(ARCH_AARCH64) ff_audio_convert_init_aarch64(ac);if(ARCH_ARM) ff_audio_convert_init_arm(ac);if(ARCH_X86) ff_audio_convert_init_x86(ac);returnac;}intff_audio_convert(AudioConvert *ac, AudioData *out, AudioData *in){intuse_generic=1;intlen=in->nb_samples;intp;if(ac->dc){av_log(ac->avr, AV_LOG_TRACE,"%dsamples-audio_convert:%sto%s(dithered)\n", len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt));returnff_convert_dither(ac-> in
static unsigned int get_bits1(GetBitContext *s)
static void skip_bits1(GetBitContext *s)
int mmco_reset
MMCO_RESET set this 1.
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.
H264Picture * cur_pic_ptr
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
int pic_id
pic_num (short -> no wrap version of pic_num, pic_num & max_pic_num; long -> long_pic_num) ...
static void pic_as_field(H264Ref *pic, const int parity)
common internal api header.
static int ref[MAX_W *MAX_W]
#define FRAME_RECOVERED_SEI
Sufficient number of frames have been decoded since a SEI recovery point, so all the following frames...
int log2_max_frame_num
log2_max_frame_num_minus4 + 4
int long_arg
index, pic_num, or num long refs depending on opcode
void ff_h264_fill_mbaff_ref_list(H264SliceContext *sl)
static void h264_initialise_ref_list(H264Context *h, H264SliceContext *sl)
static int build_def_list(H264Ref *def, int def_len, H264Picture *const *in, int len, int is_long, int sel)
int ff_h264_decode_ref_pic_list_reordering(H264Context *h, H264SliceContext *sl)
H264Ref ref_list[2][48]
0..15: frame refs, 16..47: mbaff field refs.
H264Picture last_pic_for_ec
#define FFSWAP(type, a, b)
int short_ref_count
number of actual short term references