28 #define UNCHECKED_BITSTREAM_READER 1
30 #include "libavutil/attributes.h"
43 int next_avc= h->
is_avc ? 0 : buf_size;
53 for (i = 0; i < buf_size; i++) {
58 nalsize = (nalsize << 8) | buf[i++];
59 if (nalsize <= 0 || nalsize > buf_size - i) {
63 next_avc = i + nalsize;
71 }
else if (state <= 2) {
78 }
else if (state <= 5) {
79 int v = buf[i] & 0x1F;
80 if (v == 6 || v == 7 || v == 8 || v == 9) {
85 }
else if (v == 1 || v == 2 || v == 5) {
120 return i - (state & 5) - 3 * (state > 7);
137 for (list = 0; list < h->
list_count; list++) {
140 for (index = 0; ; index++) {
143 if (reordering_of_pic_nums_idc < 3)
145 else if (reordering_of_pic_nums_idc > 3) {
147 "illegal reordering_of_pic_nums_idc %d\n",
148 reordering_of_pic_nums_idc);
172 "illegal memory management control operation %d\n",
205 const uint8_t *buf_end = buf + buf_size;
207 unsigned int slice_type;
208 int state = -1, got_reset = 0;
210 int q264 = buf_size >=4 && !memcmp(
"Q264", buf, 4);
226 int src_length, dst_length, consumed, nalsize = 0;
232 nalsize = (nalsize << 8) | *buf++;
233 if (nalsize <= 0 || nalsize > buf_end - buf) {
237 src_length = nalsize;
243 src_length = buf_end -
buf;
245 switch (state & 0x1f) {
249 if ((state & 0x1f) ==
NAL_IDR_SLICE || ((state >> 5) & 0x3) == 0) {
256 if (src_length > 1000)
262 if (ptr == NULL || dst_length < 0)
295 "pps_id out of range\n");
300 "non-existing PPS referenced\n");
306 "non-existing SPS referenced\n");
349 field_poc[0] = field_poc[1] = INT_MAX;
422 if (field_poc[0] < field_poc[1])
424 else if (field_poc[0] > field_poc[1])
439 buf += h->
is_avc ? nalsize : consumed;
450 const uint8_t **poutbuf,
int *poutbuf_size,
505 *poutbuf_size = buf_size;
516 for (i = 0; i <= buf_size; i++) {
517 if ((state & 0xFFFFFF1F) == 0x107)
524 if ((state & 0xFFFFFF00) == 0x100 && (state & 0xFFFFFF1F) != 0x107 &&
525 (state & 0xFFFFFF1F) != 0x108 && (state & 0xFFFFFF1F) != 0x109) {
527 while (i > 4 && buf[i - 5] == 0)
533 state = (state << 8) | buf[i];
561 .parser_close =
close,
#define PICT_BOTTOM_FIELD
int ff_h264_decode_seq_parameter_set(H264Context *h)
Decode SPS.
5: top field, bottom field, top field repeated, in that order
int sei_cpb_removal_delay
cpb_removal_delay in picture timing SEI message, see H.264 C.1.2
int(* h264_find_start_code_candidate)(const uint8_t *buf, int size)
Search buf from the start for up to size bytes.
static int get_se_golomb(GetBitContext *gb)
read signed exp golomb code.
3: top field, bottom field, in that order
const uint8_t * ff_h264_decode_nal(H264Context *h, const uint8_t *src, int *dst_length, int *consumed, int length)
Decode a network abstraction layer unit.
static unsigned int get_bits(GetBitContext *s, int n)
Read 1-25 bits.
enum AVFieldOrder field_order
unsigned int ref_count[2]
num_ref_idx_l0/1_active_minus1 + 1
static int scan_mmco_reset(AVCodecParserContext *s)
void av_log(void *avcl, int level, const char *fmt,...) av_printf_format(3
Send the specified message to the log if the level is less than or equal to the current av_log_level...
int is_avc
Used to parse AVC variant of h264.
MMCOOpcode
Memory management control operation opcode.
int ff_h264_get_profile(SPS *sps)
Compute profile from profile_idc and constraint_set?_flags.
int prev_poc_msb
poc_msb of the last reference pic for POC type 0
int dts_ref_dts_delta
Offset of the current timestamp against last timestamp sync point in units of AVCodecContext.time_base.
4: bottom field, top field, in that order
int slice_type_nos
S free slice type (SI/SP are remapped to I/P)
uint8_t * extradata
some codecs need / can use extradata like Huffman tables.
static const uint8_t golomb_to_pict_type[5]
enum AVPictureStructure picture_structure
Indicate whether a picture is coded as a frame, top field or bottom field.
int prev_frame_num_offset
for POC type 2
void ff_h264_reset_sei(H264Context *h)
Reset SEI values at the beginning of the frame.
static int h264_find_frame_end(H264Context *h, const uint8_t *buf, int buf_size)
unsigned int ref_count[2]
num_ref_idx_l0/1_active_minus1 + 1
int redundant_pic_cnt_present
redundant_pic_cnt_present_flag
const uint8_t * avpriv_find_start_code(const uint8_t *p, const uint8_t *end, uint32_t *state)
int got_first
this flag is != 0 if we've parsed a 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.
void av_free(void *ptr)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc(). ...
static int get_ue_golomb(GetBitContext *gb)
read unsigned exp golomb code.
int poc_type
pic_order_cnt_type
ParseContext parse_context
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_init_poc(H264Context *h, int pic_field_poc[2], int *pic_poc)
#define PARSER_FLAG_COMPLETE_FRAMES
int weighted_pred
weighted_pred_flag
int delta_pic_order_always_zero_flag
static char * split(char *message, char delim)
int ff_pred_weight_table(H264Context *h)
int nal_length_size
Number of bytes used for nal length (1, 2 or 4)
int ref_frame_count
num_ref_frames
int frame_num_offset
for POC type 2
av_cold void ff_h264dsp_init(H264DSPContext *c, const int bit_depth, const int chroma_format_idc)
static int parse_nal_units(AVCodecParserContext *s, AVCodecContext *avctx, const uint8_t *buf, int buf_size)
Parse NAL units of found picture and decode some basic information.
PPS * pps_buffers[MAX_PPS_COUNT]
int ff_h264_decode_picture_parameter_set(H264Context *h, int bit_length)
Decode PPS.
int ff_set_ref_count(H264Context *h)
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
SPS * sps_buffers[MAX_SPS_COUNT]
struct H264Context * thread_context[MAX_THREADS]
int pts_dts_delta
Presentation delay of current frame in units of AVCodecContext.time_base.
H264 / AVC / MPEG4 part10 codec data table
static int get_ue_golomb_31(GetBitContext *gb)
read unsigned exp golomb code, constraint to a max of 31.
int prev_frame_num
frame_num of the last pic for POC type 1/2
int ff_h264_decode_sei(H264Context *h)
Decode SEI.
main external API structure.
static void close(AVCodecParserContext *s)
uint32_t state
contains the last few bytes in MSB order
static unsigned int get_bits1(GetBitContext *s)
SEI_PicStructType sei_pic_struct
pic_struct in picture timing SEI message
static int h264_split(AVCodecContext *avctx, const uint8_t *buf, int buf_size)
static int init_get_bits(GetBitContext *s, const uint8_t *buffer, int bit_size)
Initialize GetBitContext.
int frame_packing_arrangement_cancel_flag
is previous arrangement canceled, -1 if never received
int log2_max_poc_lsb
log2_max_pic_order_cnt_lsb_minus4
6: bottom field, top field, bottom field repeated, in that order
int sei_buffering_period_present
Buffering period SEI flag.
#define av_assert1(cond)
assert() equivalent, that does not lie in speed critical code.
int output_picture_number
Picture number incremented in presentation or output order.
int pic_struct_present_flag
av_cold void ff_h264_free_context(H264Context *h)
Free any data that may have been allocated in the H264 context like SPS, PPS etc. ...
common internal api header.
int ff_h264_decode_extradata(H264Context *h, const uint8_t *buf, int size)
int log2_max_frame_num
log2_max_frame_num_minus4 + 4
static av_cold int init(AVCodecParserContext *s)
int prev_poc_lsb
poc_lsb of the last reference pic for POC type 0
#define AVERROR_INVALIDDATA
int repeat_pict
This field is used for proper frame duration computation in lavf.
static int h264_parse(AVCodecParserContext *s, AVCodecContext *avctx, const uint8_t **poutbuf, int *poutbuf_size, const uint8_t *buf, int buf_size)
int key_frame
Set by parser to 1 for key frames and 0 for non-key frames.
int sei_recovery_frame_cnt
recovery_frame_cnt from SEI message
int dts_sync_point
Synchronization point for start of timestamp generation.
int sei_dpb_output_delay
dpb_output_delay in picture timing SEI message, see H.264 C.2.2