28 #define UNCHECKED_BITSTREAM_READER 1
65 int buf_size,
void *logctx)
71 int next_avc = p->
is_avc ? 0 : buf_size;
80 for (i = 0; i < buf_size; i++) {
85 nalsize = (nalsize << 8) | buf[i++];
86 if (nalsize <= 0 || nalsize > buf_size - i) {
87 av_log(logctx,
AV_LOG_ERROR,
"AVC-parser: nal size %d remaining %d\n", nalsize, buf_size - i);
90 next_avc = i + nalsize;
98 }
else if (state <= 2) {
105 }
else if (state <= 5) {
106 int nalu_type = buf[i] & 0x1F;
148 return i - (state & 5) - 5 * (state > 7);
157 int list_count, ref_count[2];
172 for (list = 0; list < list_count; list++) {
175 for (index = 0; ; index++) {
178 if (reordering_of_pic_nums_idc < 3)
180 else if (reordering_of_pic_nums_idc > 3) {
182 "illegal reordering_of_pic_nums_idc %d\n",
183 reordering_of_pic_nums_idc);
188 if (index >= ref_count[list]) {
190 "reference count %d overflow\n", index);
209 "illegal memory management control operation %d\n",
230 int buf_size,
int *buf_index,
void *logctx)
240 nalsize = ((
unsigned)nalsize << 8) | buf[(*buf_index)++];
241 if (nalsize <= 0 || nalsize > buf_size - *buf_index) {
243 "AVC: nal size %d\n", nalsize);
263 int buf_index, next_avc;
265 unsigned int slice_type;
266 int state = -1, got_reset = 0;
267 int q264 = buf_size >=4 && !memcmp(
"Q264", buf, 4);
283 next_avc = p->
is_avc ? 0 : buf_size;
286 int src_length, consumed, nalsize = 0;
288 if (buf_index >= next_avc) {
292 next_avc = buf_index + nalsize;
295 if (buf_index >= buf_size)
297 if (buf_index >= next_avc)
300 src_length = next_avc - buf_index;
302 state = buf[buf_index];
303 switch (state & 0x1f) {
307 if ((state & 0x1f) ==
NAL_IDR_SLICE || ((state >> 5) & 0x3) == 0) {
314 if (src_length > 1000)
323 buf_index += consumed;
362 "pps_id %u out of range\n", pps_id);
367 "non-existing PPS %u referenced\n", pps_id);
373 "non-existing SPS %u referenced\n", p->
ps.
pps->
sps_id);
449 field_poc[0] = field_poc[1] = INT_MAX;
523 if (field_poc[0] < field_poc[1])
525 else if (field_poc[0] > field_poc[1])
547 av_log(avctx,
AV_LOG_ERROR,
"missing picture in access unit with size %d\n", buf_size);
555 const uint8_t **poutbuf,
int *poutbuf_size,
592 if (p->sei.picture_timing.cpb_removal_delay >= 0) {
593 s->dts_sync_point = p->sei.buffering_period.present;
594 s->dts_ref_dts_delta = p->sei.picture_timing.cpb_removal_delay;
595 s->pts_dts_delta = p->sei.picture_timing.dpb_output_delay;
597 s->dts_sync_point = INT_MIN;
598 s->dts_ref_dts_delta = INT_MIN;
599 s->pts_dts_delta = INT_MIN;
607 *poutbuf_size = buf_size;
622 if ((state & 0xFFFFFF00) != 0x100)
624 nalu_type = state & 0x1F;
627 }
else if (nalu_type ==
NAL_PPS)
634 else if ((nalu_type !=
NAL_SEI || has_pps) &&
638 while (ptr - 4 > buf && ptr[-5] == 0)
640 return ptr - 4 -
buf;
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
int recovery_frame_cnt
recovery_frame_cnt
static int get_se_golomb(GetBitContext *gb)
read signed exp golomb code.
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
static unsigned int get_bits(GetBitContext *s, int n)
Read 1-25 bits.
memory handling functions
AVBufferRef * sps_list[MAX_SPS_COUNT]
int frame_packing_arrangement_cancel_flag
is previous arrangement canceled, -1 if never received
int width
Dimensions of the decoded video intended for presentation.
enum AVFieldOrder field_order
unsigned int ref_count[2]
num_ref_idx_l0/1_active_minus1 + 1
int ff_h264_init_poc(int pic_field_poc[2], int *pic_poc, const SPS *sps, H264POCContext *pc, int picture_structure, int nal_ref_idc)
int coded_width
Dimensions of the coded video.
3: top field, bottom field, in that order
MMCOOpcode
Memory management control operation opcode.
void ff_h264_sei_uninit(H264SEIContext *h)
Reset SEI values at the beginning of the frame.
static int parse_nal_units(AVCodecParserContext *s, AVCodecContext *avctx, const uint8_t *const buf, int buf_size)
Parse NAL units of found picture and decode some basic information.
int size_bits
Size, in bits, of just the data, excluding the stop bit and any trailing padding. ...
AVRational time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented...
unsigned int crop_top
frame_cropping_rect_top_offset
enum AVPictureStructure picture_structure
Indicate whether a picture is coded as a frame, top field or bottom field.
unsigned int crop_left
frame_cropping_rect_left_offset
int frame_num_offset
for POC type 2
static av_cold int end(AVCodecContext *avctx)
static int get_avc_nalsize(H264ParseContext *p, const uint8_t *buf, int buf_size, int *buf_index, void *logctx)
static int find_start_code(const uint8_t *buf, int buf_size, int buf_index, int next_avc)
unsigned int crop_right
frame_cropping_rect_right_offset
uint8_t * extradata
some codecs need / can use extradata like Huffman tables.
int ff_h264_decode_extradata(const uint8_t *data, int size, H264ParamSets *ps, int *is_avc, int *nal_length_size, int err_recognition, void *logctx)
#define PICT_BOTTOM_FIELD
AVRational av_mul_q(AVRational b, AVRational c)
Multiply two rationals.
int redundant_pic_cnt_present
redundant_pic_cnt_present_flag
bitstream reader API header.
const uint8_t * avpriv_find_start_code(const uint8_t *p, const uint8_t *end, uint32_t *state)
H.264 / AVC / MPEG-4 part10 codec.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
static int get_ue_golomb(GetBitContext *gb)
Read an unsigned Exp-Golomb code in the range 0 to 8190.
int poc_type
pic_order_cnt_type
int ff_combine_frame(ParseContext *pc, int next, const uint8_t **buf, int *buf_size)
Combine the (truncated) bitstream to a complete frame.
int ff_h264_get_profile(const SPS *sps)
Compute profile from profile_idc and constraint_set?_flags.
int weighted_pred
weighted_pred_flag
#define AV_PIX_FMT_YUV444P10
const uint8_t ff_h264_golomb_to_pict_type[5]
int delta_pic_order_always_zero_flag
static char * split(char *message, char delim)
planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
int ff_h264_parse_ref_count(int *plist_count, int ref_count[2], GetBitContext *gb, const PPS *pps, int slice_type_nos, int picture_structure, void *logctx)
int ff_h264_pred_weight_table(GetBitContext *gb, const SPS *sps, const int *ref_count, int slice_type_nos, H264PredWeightTable *pwt, void *logctx)
#define AV_PIX_FMT_YUV422P9
int prev_poc_msb
poc_msb of the last reference pic for POC type 0
Context for storing H.264 DSP functions.
int ref_frame_count
num_ref_frames
int err_recognition
Error recognition; may misdetect some more or less valid parts as errors.
#define av_assert1(cond)
assert() equivalent, that does not lie in speed critical code.
av_cold void ff_h264dsp_init(H264DSPContext *c, const int bit_depth, const int chroma_format_idc)
int(* startcode_find_candidate)(const uint8_t *buf, int size)
Search buf from the start for up to size bytes.
int ticks_per_frame
For some codecs, the time base is closer to the field rate than the frame rate.
int ref_idc
H.264 only, nal_ref_idc.
#define AV_PIX_FMT_YUV444P9
AVCodecParser ff_h264_parser
static unsigned get_ue_golomb_long(GetBitContext *gb)
Read an unsigned Exp-Golomb code in the range 0 to UINT32_MAX-1.
int pic_order_present
pic_order_present_flag
static void h264_close(AVCodecParserContext *s)
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.
static int init_get_bits8(GetBitContext *s, const uint8_t *buffer, int byte_size)
Initialize GetBitContext.
SEI_PicStructType pic_struct
main external API structure.
uint8_t * data
The data buffer.
uint32_t state
contains the last few bytes in MSB order
static unsigned int get_bits1(GetBitContext *s)
#define AV_PIX_FMT_YUV420P10
int prev_frame_num
frame_num of the last pic for POC type 1/2
static int h264_split(AVCodecContext *avctx, const uint8_t *buf, int buf_size)
5: top field, bottom field, top field repeated, in that order
rational number numerator/denominator
static int init_get_bits(GetBitContext *s, const uint8_t *buffer, int bit_size)
Initialize GetBitContext.
#define AV_PIX_FMT_YUV420P9
H264SEIPictureTiming picture_timing
int log2_max_poc_lsb
log2_max_pic_order_cnt_lsb_minus4
H264SEIRecoveryPoint recovery_point
int output_picture_number
Picture number incremented in presentation or output order.
#define AV_PIX_FMT_YUV422P10
static av_always_inline AVRational av_inv_q(AVRational q)
Invert a rational.
int pic_struct_present_flag
int prev_poc_lsb
poc_lsb of the last reference pic for POC type 0
int ff_h264_decode_picture_parameter_set(GetBitContext *gb, AVCodecContext *avctx, H264ParamSets *ps, int bit_length)
Decode PPS.
int mb_height
pic_height_in_map_units_minus1 + 1
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
common internal api header.
int log2_max_frame_num
log2_max_frame_num_minus4 + 4
H264SEIFramePacking frame_packing
#define PARSER_FLAG_COMPLETE_FRAMES
static av_cold int init(AVCodecParserContext *s)
int bit_depth_luma
bit_depth_luma_minus8 + 8
int ff_h264_decode_seq_parameter_set(GetBitContext *gb, AVCodecContext *avctx, H264ParamSets *ps, int ignore_truncation)
Decode SPS.
static int h264_find_frame_end(H264ParseContext *p, const uint8_t *buf, int buf_size, void *logctx)
4: bottom field, top field, in that order
int format
The format of the coded data, corresponds to enum AVPixelFormat for video and for enum AVSampleFormat...
int mb_width
pic_width_in_mbs_minus1 + 1
int repeat_pict
This field is used for proper frame duration computation in lavf.
void ff_h264_ps_uninit(H264ParamSets *ps)
Uninit H264 param sets structure.
int ff_h264_sei_decode(H264SEIContext *h, GetBitContext *gb, const H264ParamSets *ps, void *logctx)
int prev_frame_num_offset
for POC type 2
int ff_h2645_extract_rbsp(const uint8_t *src, int length, H2645NAL *nal)
Extract the raw (unescaped) bitstream.
static int h264_parse(AVCodecParserContext *s, AVCodecContext *avctx, const uint8_t **poutbuf, int *poutbuf_size, const uint8_t *buf, int buf_size)
unsigned int crop_bottom
frame_cropping_rect_bottom_offset
int key_frame
Set by parser to 1 for key frames and 0 for non-key frames.
static int scan_mmco_reset(AVCodecParserContext *s, GetBitContext *gb, void *logctx)
6: bottom field, top field, bottom field repeated, in that order