1 /*****************************************************************************
3 *****************************************************************************
4 * Copyright (C) 2013-2017 L-SMASH project
6 * Authors: Yusuke Nakamura <muken.the.vfrmaniac@gmail.com>
8 * Permission to use, copy, modify, and/or distribute this software for any
9 * purpose with or without fee is hereby granted, provided that the above
10 * copyright notice and this permission notice appear in all copies.
12 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
13 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
14 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
15 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
16 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
17 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
18 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
19 *****************************************************************************/
21 /* This file is available under an ISC license. */
23 #define NALU_DEFAULT_BUFFER_SIZE (1<<16)
24 #define NALU_DEFAULT_NALU_LENGTH_SIZE 4 /* We always use 4 bytes length. */
25 #define NALU_SHORT_START_CODE_LENGTH 3
26 #define NALU_LONG_START_CODE_LENGTH 4
27 #define NALU_IO_ERROR UINT64_MAX - 1
28 #define NALU_NO_START_CODE_FOUND UINT64_MAX
30 /* Parameter Set Entry within AVC/HEVC Decoder Configuration Record */
33 uint16_t nalUnitLength
;
37 } isom_dcr_ps_entry_t
;
39 isom_dcr_ps_entry_t
*isom_create_ps_entry
45 void isom_remove_dcr_ps
47 isom_dcr_ps_entry_t
*ps
50 /* Convert EBSP (Encapsulated Byte Sequence Packets) to RBSP (Raw Byte Sequence Packets). */
51 uint8_t *nalu_remove_emulation_prevention
58 int nalu_import_rbsp_from_ebsp
66 int nalu_check_more_rbsp_data
71 int nalu_get_max_ps_length
73 lsmash_entry_list_t
*ps_list
,
74 uint32_t *max_ps_length
79 lsmash_entry_list_t
*ps_list
,
83 int nalu_check_same_ps_existence
85 lsmash_entry_list_t
*ps_list
,
93 lsmash_entry_list_t
*list
,
97 /* Return the offset from the beginning of stream if a start code is found.
98 * Return NALU_NO_START_CODE_FOUND otherwise. */
99 uint64_t nalu_find_first_start_code
104 uint64_t nalu_get_codeNum
109 static inline uint64_t nalu_decode_exp_golomb_ue
117 static inline int64_t nalu_decode_exp_golomb_se
123 return (int64_t)((codeNum
>> 1) + 1);
124 return -1 * (int64_t)(codeNum
>> 1);
127 static inline uint64_t nalu_get_exp_golomb_ue
132 uint64_t codeNum
= nalu_get_codeNum( bits
);
133 return nalu_decode_exp_golomb_ue( codeNum
);
136 static inline uint64_t nalu_get_exp_golomb_se
141 uint64_t codeNum
= nalu_get_codeNum( bits
);
142 return nalu_decode_exp_golomb_se( codeNum
);
145 static inline int nalu_check_next_short_start_code
151 return ((buf_pos
+ 2) < buf_end
) && !buf_pos
[0] && !buf_pos
[1] && (buf_pos
[2] == 0x01);