35 uint8_t *buf, *end, *start;
36 uint8_t *
sps, *
pps, *sps_ext;
37 uint32_t sps_size = 0, pps_size = 0, sps_ext_size = 0;
38 int ret, nb_sps = 0, nb_pps = 0, nb_sps_ext = 0;
67 while (end - buf > 4) {
72 nal_type = buf[0] & 0x1f;
82 }
else if (nal_type == 8) {
90 }
else if (nal_type == 13) {
92 if (
size > UINT16_MAX || nb_sps_ext >= 256) {
106 if (sps_size < 6 || !pps_size) {
122 if (
sps[3] != 66 &&
sps[3] != 77 &&
sps[3] != 88) {
147 uint16_t sps_size, pps_size;
154 if (*
size < 11 || in[0] != 1)
158 if (11 + sps_size > *
size)
160 pps_size =
AV_RB16(&in[9 + sps_size]);
161 if (11 + sps_size + pps_size > *
size)
168 memcpy(
out + 4, &in[8], sps_size);
170 memcpy(
out + 8 + sps_size, &in[11 + sps_size], pps_size);
198 int i, j, ret, rbsp_size, aspect_ratio_idc, pic_order_cnt_type;
199 int num_ref_frames_in_pic_order_cnt_cycle;
200 int delta_scale, lastScale = 8, nextScale = 8;
201 int sizeOfScalingList;
213 memset(
sps, 0,
sizeof(*
sps));
226 if (
sps->profile_idc == 100 ||
sps->profile_idc == 110 ||
227 sps->profile_idc == 122 ||
sps->profile_idc == 244 ||
sps->profile_idc == 44 ||
228 sps->profile_idc == 83 ||
sps->profile_idc == 86 ||
sps->profile_idc == 118 ||
229 sps->profile_idc == 128 ||
sps->profile_idc == 138 ||
sps->profile_idc == 139 ||
230 sps->profile_idc == 134) {
232 if (
sps->chroma_format_idc == 3) {
239 for (
i = 0;
i < ((
sps->chroma_format_idc != 3) ? 8 : 12);
i++) {
244 sizeOfScalingList =
i < 6 ? 16 : 64;
245 for (j = 0; j < sizeOfScalingList; j++) {
246 if (nextScale != 0) {
248 nextScale = (lastScale + delta_scale) & 0xff;
250 lastScale = nextScale == 0 ? lastScale : nextScale;
255 sps->chroma_format_idc = 1;
256 sps->bit_depth_luma = 8;
257 sps->bit_depth_chroma = 8;
263 if (pic_order_cnt_type == 0) {
265 }
else if (pic_order_cnt_type == 1) {
270 for (
i = 0;
i < num_ref_frames_in_pic_order_cnt_cycle;
i++)
280 if (!
sps->frame_mbs_only_flag)
294 aspect_ratio_idc =
get_bits(&gb, 8);
295 if (aspect_ratio_idc == 0xff) {
static const AVRational avc_sample_aspect_ratio[17]
int ff_avc_decode_sps(H264SPS *sps, const uint8_t *buf, int buf_size)
int ff_isom_write_avcc(AVIOContext *pb, const uint8_t *data, int len)
int ff_avc_write_annexb_extradata(const uint8_t *in, uint8_t **buf, int *size)
void avio_w8(AVIOContext *s, int b)
void avio_wb16(AVIOContext *s, unsigned int val)
void avio_write(AVIOContext *s, const unsigned char *buf, int size)
int avio_open_dyn_buf(AVIOContext **s)
Open a write only memory stream.
int avio_get_dyn_buf(AVIOContext *s, uint8_t **pbuffer)
Return the written size and a pointer to the buffer.
void ffio_free_dyn_buf(AVIOContext **s)
Free a dynamic buffer.
#define i(width, name, range_min, range_max)
static int FUNC sps(CodedBitstreamContext *ctx, RWContext *rw, H264RawSPS *current)
bitstream reader API header.
static unsigned int get_bits1(GetBitContext *s)
static void skip_bits(GetBitContext *s, int n)
static int init_get_bits8(GetBitContext *s, const uint8_t *buffer, int byte_size)
Initialize GetBitContext.
static void skip_bits1(GetBitContext *s)
static unsigned int get_bits(GetBitContext *s, int n)
Read 1-25 bits.
static int get_se_golomb_long(GetBitContext *gb)
static unsigned get_ue_golomb_long(GetBitContext *gb)
Read an unsigned Exp-Golomb code in the range 0 to UINT32_MAX-1.
#define AV_INPUT_BUFFER_PADDING_SIZE
Required number of additionally allocated bytes at the end of the input bitstream for decoding.
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
H.264 common definitions.
Memory handling functions.
int ff_nal_parse_units_buf(const uint8_t *buf_in, uint8_t **buf, int *size)
uint8_t * ff_nal_unit_extract_rbsp(const uint8_t *src, uint32_t src_len, uint32_t *dst_len, int header_len)
#define FF_ARRAY_ELEMS(a)
Rational number (pair of numerator and denominator).
uint8_t chroma_format_idc