39 #define STARTCODE_TEST \
40 if (i + 2 < length && src[i + 1] == 0 && src[i + 2] <= 3) { \
41 if (src[i + 2] != 3 && src[i + 2] != 0) { \
47 #if HAVE_FAST_UNALIGNED
48 #define FIND_FIRST_ZERO \
49 if (i > 0 && !src[i]) \
54 for (i = 0; i + 1 <
length; i += 9) {
56 (
AV_RN64A(src + i) - 0x0100010001000101ULL)) &
57 0x8000800080008080ULL))
64 for (i = 0; i + 1 <
length; i += 5) {
75 for (i = 0; i + 1 <
length; i += 2) {
78 if (i > 0 && src[i - 1] == 0)
84 if (i >= length - 1) {
101 while (si + 2 < length) {
103 if (src[si + 2] > 3) {
104 dst[di++] = src[si++];
105 dst[di++] = src[si++];
106 }
else if (src[si] == 0 && src[si + 1] == 0 && src[si + 2] != 0) {
107 if (src[si + 2] == 3) {
133 dst[di++] = src[si++];
136 dst[di++] = src[si++];
176 default :
return "?";
185 while (skip_trailing_zeros && size > 0 && nal->
data[size - 1] == 0)
191 v = nal->
data[size - 1];
193 if (size > INT_MAX / 8)
225 "nal_unit_type: %d(%s), nuh_layer_id: %d, temporal_id: %d\n",
228 return nuh_layer_id == 0;
242 "nal_unit_type: %d, nal_ref_idc: %d\n",
249 void *logctx,
int is_nalff,
int nal_length_size,
252 int consumed, ret = 0;
256 while (length >= 4) {
258 int extract_length = 0;
259 int skip_trailing_zeros = 1;
261 if (buf >= next_avc) {
263 for (i = 0; i < nal_length_size; i++)
264 extract_length = (extract_length << 8) | buf[i];
265 buf += nal_length_size;
266 length -= nal_length_size;
268 if (extract_length > length) {
272 next_avc = buf + extract_length;
275 while (buf[0] != 0 || buf[1] != 0 || buf[2] != 1) {
287 }
else if (buf >= (next_avc - 3))
295 if (buf >= next_avc) {
329 if (is_nalff && (extract_length != consumed) && extract_length)
331 "NALFF: Consumed only %d bytes instead of %d\n",
332 consumed, extract_length);
337 if (consumed < length - 3 &&
338 buf[consumed] == 0x00 && buf[consumed + 1] == 0x00 &&
339 buf[consumed + 2] == 0x01 && buf[consumed + 3] == 0xE0)
340 skip_trailing_zeros = 0;
352 if (ret <= 0 || nal->
size <= 0) {
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
static int get_bit_length(H2645NAL *nal, int skip_trailing_zeros)
static unsigned int get_bits(GetBitContext *s, int n)
Read 1-25 bits.
memory handling functions
static const char * nal_unit_name(int nal_type)
int ff_h2645_packet_split(H2645Packet *pkt, const uint8_t *buf, int length, void *logctx, int is_nalff, int nal_length_size, enum AVCodecID codec_id)
Split an input packet into NAL units.
int size_bits
Size, in bits, of just the data, excluding the stop bit and any trailing padding. ...
int skipped_bytes_pos_size
#define av_assert0(cond)
assert() equivalent, that is always enabled.
void ff_h2645_packet_uninit(H2645Packet *pkt)
Free all the allocated memory in the packet.
int av_reallocp_array(void *ptr, size_t nmemb, size_t size)
AVCodecID
Identify the syntax and semantics of the bitstream.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
static const uint8_t offset[127][2]
int ref_idc
H.264 only, nal_ref_idc.
static int hevc_parse_nal_header(H2645NAL *nal, void *logctx)
static int h264_parse_nal_header(H2645NAL *nal, void *logctx)
static unsigned int get_bits1(GetBitContext *s)
static int init_get_bits(GetBitContext *s, const uint8_t *buffer, int bit_size)
Initialize GetBitContext.
void av_fast_malloc(void *ptr, unsigned int *size, size_t min_size)
Allocate a buffer, reusing the given one if large enough.
void * av_realloc_array(void *ptr, size_t nmemb, size_t size)
#define AV_INPUT_BUFFER_PADDING_SIZE
Required number of additionally allocated bytes at the end of the input bitstream for decoding...
int temporal_id
HEVC only, nuh_temporal_id_plus_1 - 1.
#define av_malloc_array(a, b)
int ff_h2645_extract_rbsp(const uint8_t *src, int length, H2645NAL *nal)
Extract the raw (unescaped) bitstream.