28 #include "libavutil/attributes.h"
49 for (i = 0; i < buf_size; i++) {
54 }
else if (state <= 2) {
61 }
else if (state <= 5) {
62 int nalu_type = buf[i] & 0x1F;
90 return i - (state & 5);
107 for (list = 0; list < h->
list_count; list++) {
110 for (index = 0; ; index++) {
113 if (reordering_of_pic_nums_idc < 3)
115 else if (reordering_of_pic_nums_idc > 3) {
117 "illegal reordering_of_pic_nums_idc %d\n",
118 reordering_of_pic_nums_idc);
125 "reference count %d overflow\n", index);
143 "illegal memory management control operation %d\n",
173 const uint8_t *buf,
int buf_size)
176 const uint8_t *buf_end = buf + buf_size;
178 unsigned int slice_type;
179 int state = -1, got_reset = 0;
195 int src_length, dst_length, consumed;
200 src_length = buf_end - buf;
201 switch (state & 0x1f) {
205 if ((state & 0x1f) ==
NAL_IDR_SLICE || ((state >> 5) & 0x3) == 0) {
212 if (src_length > 1000)
218 if (!ptr || dst_length < 0)
251 "pps_id %u out of range\n", pps_id);
256 "non-existing PPS %u referenced\n", pps_id);
262 "non-existing SPS %u referenced\n", h->
pps.
sps_id);
302 field_poc[0] = field_poc[1] = INT_MAX;
375 if (field_poc[0] < field_poc[1])
377 else if (field_poc[0] > field_poc[1])
401 const uint8_t **poutbuf,
int *poutbuf_size,
402 const uint8_t *buf,
int buf_size)
457 *poutbuf_size = buf_size;
462 const uint8_t *buf,
int buf_size)
468 for (i = 0; i <= buf_size; i++) {
469 if ((state & 0xFFFFFF1F) == 0x107)
476 if ((state & 0xFFFFFF00) == 0x100 && (state & 0xFFFFFF1F) != 0x107 &&
477 (state & 0xFFFFFF1F) != 0x108 && (state & 0xFFFFFF1F) != 0x109) {
479 while (i > 4 && buf[i - 5] == 0)
485 state = (state << 8) | buf[i];
513 .parser_close =
close,
int ff_h264_decode_seq_parameter_set(H264Context *h)
Decode SPS.
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
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
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
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...
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)
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
#define PICT_BOTTOM_FIELD
int redundant_pic_cnt_present
redundant_pic_cnt_present_flag
int(* startcode_find_candidate)(const uint8_t *buf, int size)
Search buf from the start for up to size bytes.
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 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
int pic_order_present
pic_order_present_flag
struct H264Context * thread_context[H264_MAX_THREADS]
SPS * sps_buffers[MAX_SPS_COUNT]
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 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.
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. ...
const uint8_t * avpriv_find_start_code(const uint8_t *restrict p, const uint8_t *end, uint32_t *restrict state)
common internal api header.
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
int ff_h264_decode_extradata(H264Context *h)
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