write: Fix type size for mdcv luminance
[L-SMASH.git] / codecs / nalu.h
blob2c9d813b47cbf76448befee8725f23e82b2036f6
1 /*****************************************************************************
2 * nalu.h
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 */
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 int nalu_import_rbsp_from_ebsp
52 lsmash_bits_t *bits,
53 uint8_t *rbsp_buffer,
54 uint64_t *rbsp_size,
55 uint8_t *ebsp,
56 uint64_t ebsp_size
59 int nalu_check_more_rbsp_data
61 lsmash_bits_t *bits
64 int nalu_get_max_ps_length
66 lsmash_entry_list_t *ps_list,
67 uint32_t *max_ps_length
70 int nalu_get_ps_count
72 lsmash_entry_list_t *ps_list,
73 uint32_t *ps_count
76 int nalu_check_same_ps_existence
78 lsmash_entry_list_t *ps_list,
79 void *ps_data,
80 uint32_t ps_length
83 int nalu_get_dcr_ps
85 lsmash_bs_t *bs,
86 lsmash_entry_list_t *list,
87 uint8_t entry_count
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
94 lsmash_bs_t *bs
97 uint64_t nalu_get_codeNum
99 lsmash_bits_t *bits
102 static inline uint64_t nalu_decode_exp_golomb_ue
104 uint64_t codeNum
107 return codeNum;
110 static inline int64_t nalu_decode_exp_golomb_se
112 uint64_t codeNum
115 if( codeNum & 1 )
116 return (int64_t)((codeNum >> 1) + 1);
117 return -1 * (int64_t)(codeNum >> 1);
120 static inline uint64_t nalu_get_exp_golomb_ue
122 lsmash_bits_t *bits
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
131 lsmash_bits_t *bits
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
140 uint8_t *buf_pos,
141 uint8_t *buf_end
144 return ((buf_pos + 2) < buf_end) && !buf_pos[0] && !buf_pos[1] && (buf_pos[2] == 0x01);