.gitignore: Add version script.
[L-SMASH.git] / codecs / nalu.h
blob0f8f0c62f54a6f6b574fed02443da9103cd7920e
1 /*****************************************************************************
2 * nalu.h:
3 *****************************************************************************
4 * Copyright (C) 2013-2015 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 */
31 typedef struct
33 uint16_t nalUnitLength;
34 uint8_t *nalUnit;
35 /* */
36 int unused;
37 } isom_dcr_ps_entry_t;
39 isom_dcr_ps_entry_t *isom_create_ps_entry
41 uint8_t *ps,
42 uint32_t ps_size
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
53 uint8_t *src,
54 uint64_t src_length,
55 uint8_t *dst
58 int nalu_import_rbsp_from_ebsp
60 lsmash_bits_t *bits,
61 uint8_t *rbsp_buffer,
62 uint8_t *ebsp,
63 uint64_t ebsp_size
66 int nalu_check_more_rbsp_data
68 lsmash_bits_t *bits
71 int nalu_get_max_ps_length
73 lsmash_entry_list_t *ps_list,
74 uint32_t *max_ps_length
77 int nalu_get_ps_count
79 lsmash_entry_list_t *ps_list,
80 uint32_t *ps_count
83 int nalu_check_same_ps_existence
85 lsmash_entry_list_t *ps_list,
86 void *ps_data,
87 uint32_t ps_length
90 int nalu_get_dcr_ps
92 lsmash_bs_t *bs,
93 lsmash_entry_list_t *list,
94 uint8_t entry_count
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
101 lsmash_bs_t *bs
104 uint64_t nalu_get_codeNum
106 lsmash_bits_t *bits
109 static inline uint64_t nalu_decode_exp_golomb_ue
111 uint64_t codeNum
114 return codeNum;
117 static inline int64_t nalu_decode_exp_golomb_se
119 uint64_t codeNum
122 if( codeNum & 1 )
123 return (int64_t)((codeNum >> 1) + 1);
124 return -1 * (int64_t)(codeNum >> 1);
127 static inline uint64_t nalu_get_exp_golomb_ue
129 lsmash_bits_t *bits
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
138 lsmash_bits_t *bits
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
147 uint8_t *buf_pos,
148 uint8_t *buf_end
151 return ((buf_pos + 2) < buf_end) && !buf_pos[0] && !buf_pos[1] && (buf_pos[2] == 0x01);