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 int nalu_import_rbsp_from_ebsp
59 int nalu_check_more_rbsp_data
64 int nalu_get_max_ps_length
66 lsmash_entry_list_t
*ps_list
,
67 uint32_t *max_ps_length
72 lsmash_entry_list_t
*ps_list
,
76 int nalu_check_same_ps_existence
78 lsmash_entry_list_t
*ps_list
,
86 lsmash_entry_list_t
*list
,
90 /* Return the offset from the beginning of stream if a start code is found.
91 * Return NALU_NO_START_CODE_FOUND otherwise. */
92 uint64_t nalu_find_first_start_code
97 uint64_t nalu_get_codeNum
102 static inline uint64_t nalu_decode_exp_golomb_ue
110 static inline int64_t nalu_decode_exp_golomb_se
116 return (int64_t)((codeNum
>> 1) + 1);
117 return -1 * (int64_t)(codeNum
>> 1);
120 static inline uint64_t nalu_get_exp_golomb_ue
125 uint64_t codeNum
= nalu_get_codeNum( bits
);
126 return nalu_decode_exp_golomb_ue( codeNum
);
129 static inline uint64_t nalu_get_exp_golomb_se
134 uint64_t codeNum
= nalu_get_codeNum( bits
);
135 return nalu_decode_exp_golomb_se( codeNum
);
138 static inline int nalu_check_next_short_start_code
144 return ((buf_pos
+ 2) < buf_end
) && !buf_pos
[0] && !buf_pos
[1] && (buf_pos
[2] == 0x01);