28 #define UNCHECKED_BITSTREAM_READER 1
52 int next_avc= h->
is_avc ? 0 : buf_size;
61 for (i = 0; i < buf_size; i++) {
66 nalsize = (nalsize << 8) | buf[i++];
67 if (nalsize <= 0 || nalsize > buf_size - i) {
71 next_avc = i + nalsize;
79 }
else if (state <= 2) {
86 }
else if (state <= 5) {
87 int nalu_type = buf[i] & 0x1F;
129 return i - (state & 5) - 5 * (state > 7);
148 for (list = 0; list < sl->
list_count; list++) {
151 for (index = 0; ; index++) {
154 if (reordering_of_pic_nums_idc < 3)
156 else if (reordering_of_pic_nums_idc > 3) {
158 "illegal reordering_of_pic_nums_idc %d\n",
159 reordering_of_pic_nums_idc);
166 "reference count %d overflow\n", index);
184 "illegal memory management control operation %d\n",
219 int buf_index, next_avc;
221 unsigned int slice_type;
222 int state = -1, got_reset = 0;
224 int q264 = buf_size >=4 && !memcmp(
"Q264", buf, 4);
240 next_avc = h->
is_avc ? 0 : buf_size;
242 int src_length, dst_length, consumed, nalsize = 0;
244 if (buf_index >= next_avc) {
248 next_avc = buf_index + nalsize;
251 if (buf_index >= buf_size)
253 if (buf_index >= next_avc)
256 src_length = next_avc - buf_index;
258 state = buf[buf_index];
259 switch (state & 0x1f) {
263 if ((state & 0x1f) ==
NAL_IDR_SLICE || ((state >> 5) & 0x3) == 0) {
270 if (src_length > 1000)
276 &consumed, src_length);
277 if (!ptr || dst_length < 0)
280 buf_index += consumed;
313 "pps_id %u out of range\n", pps_id);
318 "non-existing PPS %u referenced\n", pps_id);
324 "non-existing SPS %u referenced\n", h->
pps.
sps_id);
396 field_poc[0] = field_poc[1] = INT_MAX;
469 if (field_poc[0] < field_poc[1])
471 else if (field_poc[0] > field_poc[1])
496 const uint8_t **poutbuf,
int *poutbuf_size,
539 if (
h->sei_cpb_removal_delay >= 0) {
540 s->dts_sync_point =
h->sei_buffering_period_present;
541 s->dts_ref_dts_delta =
h->sei_cpb_removal_delay;
542 s->pts_dts_delta =
h->sei_dpb_output_delay;
544 s->dts_sync_point = INT_MIN;
545 s->dts_ref_dts_delta = INT_MIN;
546 s->pts_dts_delta = INT_MIN;
554 *poutbuf_size = buf_size;
569 if ((state & 0xFFFFFF00) != 0x100)
571 nalu_type = state & 0x1F;
574 }
else if (nalu_type ==
NAL_PPS)
581 else if ((nalu_type !=
NAL_SEI || has_pps) &&
585 while (ptr - 4 > buf && ptr[-5] == 0)
587 return ptr - 4 -
buf;
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
5: top field, bottom field, top field repeated, in that order
static int get_se_golomb(GetBitContext *gb)
read signed exp golomb code.
3: top field, bottom field, in that order
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.
const uint8_t * ff_h264_decode_nal(H264Context *h, H264SliceContext *sl, const uint8_t *src, int *dst_length, int *consumed, int length)
Decode a network abstraction layer unit.
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
static int scan_mmco_reset(AVCodecParserContext *s)
int coded_width
Dimensions of the coded video.
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
4: bottom field, top field, in that order
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.
unsigned int ref_count[2]
num_ref_idx_l0/1_active_minus1 + 1
int ff_set_ref_count(H264Context *h, H264SliceContext *sl)
Macro definitions for various function/variable attributes.
AVRational time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented...
static const uint8_t golomb_to_pict_type[5]
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.
int prev_frame_num_offset
for POC type 2
unsigned int crop_left
frame_cropping_rect_left_offset
void ff_h264_reset_sei(H264Context *h)
Reset SEI values at the beginning of the frame.
static av_cold int end(AVCodecContext *avctx)
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.
#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
const uint8_t * avpriv_find_start_code(const uint8_t *p, const uint8_t *end, uint32_t *state)
#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 unsigned exp golomb code.
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.
#define PARSER_FLAG_COMPLETE_FRAMES
int ff_init_poc(H264Context *h, int pic_field_poc[2], int *pic_poc)
int ff_pred_weight_table(H264Context *h, H264SliceContext *sl)
int weighted_pred
weighted_pred_flag
#define AV_PIX_FMT_YUV444P10
int delta_pic_order_always_zero_flag
int slice_type_nos
S free slice type (SI/SP are remapped to I/P)
static char * split(char *message, char delim)
planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
int nal_length_size
Number of bytes used for nal length (1, 2 or 4)
#define AV_PIX_FMT_YUV422P9
int ref_frame_count
num_ref_frames
int frame_num_offset
for POC type 2
#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.
PPS * pps_buffers[MAX_PPS_COUNT]
int ff_h264_decode_picture_parameter_set(H264Context *h, int bit_length)
Decode PPS.
H264SliceContext * slice_ctx
int ticks_per_frame
For some codecs, the time base is closer to the field rate than the frame rate.
static int h264_find_frame_end(H264ParseContext *p, const uint8_t *buf, int buf_size)
#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
SPS * sps_buffers[MAX_SPS_COUNT]
static void h264_close(AVCodecParserContext *s)
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.
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
#define AV_PIX_FMT_YUV420P10
static int get_avc_nalsize(H264Context *h, const uint8_t *buf, int buf_size, int *buf_index)
static int h264_split(AVCodecContext *avctx, const uint8_t *buf, int buf_size)
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
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 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
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. ...
int ff_h264_decode_seq_parameter_set(H264Context *h, int ignore_truncation)
Decode SPS.
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 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 bit_depth_luma
bit_depth_luma_minus8 + 8
int prev_poc_lsb
poc_lsb of the last reference pic for POC type 0
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.
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.
int sei_recovery_frame_cnt
recovery_frame_cnt from SEI message
void * av_mallocz(size_t size)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...