Bug Summary

File:root/firefox-clang/media/ffvpx/libavcodec/get_bits.h
Warning:line 342, column 5
Access to field 'l' results in a dereference of a null pointer

Annotated Source Code

Press '?' to see keyboard shortcuts

clang -cc1 -cc1 -triple x86_64-pc-linux-gnu -O2 -analyze -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name aac_adtstoasc.c -analyzer-checker=core -analyzer-checker=apiModeling -analyzer-checker=unix -analyzer-checker=deadcode -analyzer-checker=security.insecureAPI.UncheckedReturn -analyzer-checker=security.insecureAPI.getpw -analyzer-checker=security.insecureAPI.gets -analyzer-checker=security.insecureAPI.mktemp -analyzer-checker=security.insecureAPI.mkstemp -analyzer-checker=security.insecureAPI.vfork -analyzer-checker=nullability.NullPassedToNonnull -analyzer-checker=nullability.NullReturnedFromNonnull -analyzer-output plist -w -setup-static-analyzer -analyzer-config-compatibility-mode=true -mrelocation-model pic -pic-level 2 -fhalf-no-semantic-interposition -mframe-pointer=all -relaxed-aliasing -ffp-contract=off -fno-rounding-math -mconstructor-aliases -funwind-tables=2 -target-cpu x86-64 -tune-cpu generic -debugger-tuning=gdb -fdebug-compilation-dir=/root/firefox-clang/obj-x86_64-pc-linux-gnu/media/ffvpx/libavcodec/bsf -fcoverage-compilation-dir=/root/firefox-clang/obj-x86_64-pc-linux-gnu/media/ffvpx/libavcodec/bsf -resource-dir /usr/lib/llvm-23/lib/clang/23 -include /root/firefox-clang/config/gcc_hidden.h -include /root/firefox-clang/obj-x86_64-pc-linux-gnu/mozilla-config.h -include libavutil_visibility.h -I /root/firefox-clang/obj-x86_64-pc-linux-gnu/dist/system_wrappers -U _FORTIFY_SOURCE -D _FORTIFY_SOURCE=2 -D DEBUG=1 -D HAVE_AV_CONFIG_H -D ASSERT_LEVEL=2 -I /root/firefox-clang/media/ffvpx/libavcodec/bsf -I /root/firefox-clang/obj-x86_64-pc-linux-gnu/media/ffvpx/libavcodec/bsf -I /root/firefox-clang/media/ffvpx/libavcodec -I /root/firefox-clang/media/ffvpx -I /root/firefox-clang/obj-x86_64-pc-linux-gnu/dist/include -I /root/firefox-clang/obj-x86_64-pc-linux-gnu/dist/include/nspr -I /root/firefox-clang/obj-x86_64-pc-linux-gnu/dist/include/nss -D MOZILLA_CLIENT -internal-isystem /usr/lib/llvm-23/lib/clang/23/include -internal-isystem /usr/local/include -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/16/../../../../x86_64-linux-gnu/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -Wno-error=tautological-type-limit-compare -Wno-range-loop-analysis -Wno-error=deprecated-declarations -Wno-error=array-bounds -Wno-error=free-nonheap-object -Wno-error=atomic-alignment -Wno-error=deprecated-builtins -Wno-psabi -Wno-error=builtin-macro-redefined -Wno-unknown-warning-option -Wno-character-conversion -Wno-parentheses -Wno-pointer-sign -Wno-sign-compare -Wno-switch -Wno-type-limits -Wno-unused-function -Wno-deprecated-declarations -Wno-absolute-value -Wno-incompatible-pointer-types -Wno-string-conversion -Wno-visibility -ferror-limit 19 -fstrict-flex-arrays=1 -stack-protector 2 -fstack-clash-protection -ftrivial-auto-var-init=pattern -fgnuc-version=4.2.1 -fskip-odr-check-in-gmf -fdiagnostics-absolute-paths -vectorize-loops -vectorize-slp -analyzer-checker optin.performance.Padding -analyzer-output=html -analyzer-config stable-report-filename=true -mllvm -dwarf-linkage-names=Abstract -faddrsig -fdwarf2-cfi-asm -o /tmp/scan-build-2026-09-01-224014-2642839-1 -x c /root/firefox-clang/media/ffvpx/libavcodec/bsf/aac_adtstoasc.c

/root/firefox-clang/media/ffvpx/libavcodec/bsf/aac_adtstoasc.c

1/*
2 * MPEG-2/4 AAC ADTS to MPEG-4 Audio Specific Configuration bitstream filter
3 * Copyright (c) 2009 Alex Converse <alex.converse@gmail.com>
4 *
5 * This file is part of FFmpeg.
6 *
7 * FFmpeg is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
12 * FFmpeg is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with FFmpeg; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 */
21
22#include "adts_header.h"
23#include "adts_parser.h"
24#include "bsf.h"
25#include "bsf_internal.h"
26#include "put_bits.h"
27#include "get_bits.h"
28#include "mpeg4audio.h"
29#include "mpeg4audio_copy_pce.h"
30
31typedef struct AACBSFContext {
32 int first_frame_done;
33} AACBSFContext;
34
35/**
36 * This filter creates an MPEG-4 AudioSpecificConfig from an MPEG-2/4
37 * ADTS header and removes the ADTS header.
38 */
39static int aac_adtstoasc_filter(AVBSFContext *bsfc, AVPacket *pkt)
40{
41 AACBSFContext *ctx = bsfc->priv_data;
42
43 PutBitContext pb;
44 AACADTSHeaderInfo hdr;
45 int ret;
46
47 ret = ff_bsf_get_packet_ref(bsfc, pkt);
48 if (ret < 0)
1
Assuming 'ret' is >= 0
49 return ret;
50
51 if (bsfc->par_in->extradata && pkt->size >= 2 && (AV_RB16(pkt->data)av_bswap16((((const union unaligned_16 *) (pkt->data))->
l))
>> 4) != 0xfff)
2
Assuming field 'extradata' is null
52 return 0;
53
54 if (pkt->size < AV_AAC_ADTS_HEADER_SIZE7)
3
Assuming field 'size' is >= AV_AAC_ADTS_HEADER_SIZE
4
Taking false branch
55 goto packet_too_small;
56
57 if (ff_adts_header_parse_buf(pkt->data, &hdr) < 0) {
5
Assuming the condition is false
58 av_log(bsfc, AV_LOG_ERROR16, "Error parsing ADTS frame header!\n");
59 ret = AVERROR_INVALIDDATA(-(int)(('I') | (('N') << 8) | (('D') << 16) | ((
unsigned)('A') << 24)))
;
60 goto fail;
61 }
62
63 if (!hdr.crc_absent && hdr.num_aac_frames > 1) {
6
Assuming field 'crc_absent' is not equal to 0
64 avpriv_report_missing_feature(bsfc,
65 "Multiple RDBs per frame with CRC");
66 ret = AVERROR_PATCHWELCOME(-(int)(('P') | (('A') << 8) | (('W') << 16) | ((
unsigned)('E') << 24)))
;
67 goto fail;
68 }
69
70 pkt->size -= AV_AAC_ADTS_HEADER_SIZE7 + 2 * !hdr.crc_absent
6.1
Field 'crc_absent' is not equal to 0
6.1
Field 'crc_absent' is not equal to 0
;
71 if (pkt->size <= 0)
7
Assuming field 'size' is > 0
8
Taking false branch
72 goto packet_too_small;
73 pkt->data += AV_AAC_ADTS_HEADER_SIZE7 + 2 * !hdr.crc_absent
8.1
Field 'crc_absent' is not equal to 0
8.1
Field 'crc_absent' is not equal to 0
;
74
75 if (!ctx->first_frame_done) {
9
Assuming field 'first_frame_done' is 0
10
Taking true branch
76 int pce_size = 0;
77 uint8_t pce_data[MAX_PCE_SIZE320];
78 uint8_t *extradata;
79
80 if (!hdr.chan_config) {
11
Assuming field 'chan_config' is 0
12
Taking true branch
81 GetBitContext gb;
82 init_get_bits(&gb, pkt->data, pkt->size * 8);
13
Calling 'init_get_bits'
20
Returning from 'init_get_bits'
83 if (get_bits(&gb, 3) != 5) {
21
Calling 'get_bits'
84 avpriv_report_missing_feature(bsfc,
85 "PCE-based channel configuration "
86 "without PCE as first syntax "
87 "element");
88 ret = AVERROR_PATCHWELCOME(-(int)(('P') | (('A') << 8) | (('W') << 16) | ((
unsigned)('E') << 24)))
;
89 goto fail;
90 }
91 init_put_bits(&pb, pce_data, MAX_PCE_SIZE320);
92 pce_size = ff_copy_pce_data(&pb, &gb) / 8;
93 flush_put_bits(&pb);
94 pkt->size -= get_bits_count(&gb)/8;
95 pkt->data += get_bits_count(&gb)/8;
96 }
97
98 extradata = av_packet_new_side_data(pkt, AV_PKT_DATA_NEW_EXTRADATA,
99 2 + pce_size);
100 if (!extradata) {
101 ret = AVERROR(ENOMEM)(-(12));
102 goto fail;
103 }
104
105 init_put_bits(&pb, extradata, 2 + pce_size);
106 put_bits(&pb, 5, hdr.object_type);
107 put_bits(&pb, 4, hdr.sampling_index);
108 put_bits(&pb, 4, hdr.chan_config);
109 put_bits(&pb, 1, 0); //frame length - 1024 samples
110 put_bits(&pb, 1, 0); //does not depend on core coder
111 put_bits(&pb, 1, 0); //is not extension
112 flush_put_bits(&pb);
113 if (pce_size) {
114 memcpy(extradata + 2, pce_data, pce_size);
115 }
116
117 ctx->first_frame_done = 1;
118 }
119
120 return 0;
121
122packet_too_small:
123 av_log(bsfc, AV_LOG_ERROR16, "Input packet too small\n");
124 ret = AVERROR_INVALIDDATA(-(int)(('I') | (('N') << 8) | (('D') << 16) | ((
unsigned)('A') << 24)))
;
125fail:
126 av_packet_unref(pkt);
127 return ret;
128}
129
130static int aac_adtstoasc_init(AVBSFContext *ctx)
131{
132 /* Validate the extradata if the stream is already MPEG-4 AudioSpecificConfig */
133 if (ctx->par_in->extradata) {
134 MPEG4AudioConfig mp4ac;
135 int ret = avpriv_mpeg4audio_get_config2(&mp4ac, ctx->par_in->extradata,
136 ctx->par_in->extradata_size, 1, ctx);
137 if (ret < 0) {
138 av_log(ctx, AV_LOG_ERROR16, "Error parsing AudioSpecificConfig extradata!\n");
139 return ret;
140 }
141 }
142
143 return 0;
144}
145
146static const enum AVCodecID codec_ids[] = {
147 AV_CODEC_ID_AAC, AV_CODEC_ID_NONE,
148};
149
150const FFBitStreamFilter ff_aac_adtstoasc_bsf = {
151 .p.name = "aac_adtstoasc",
152 .p.codec_ids = codec_ids,
153 .priv_data_size = sizeof(AACBSFContext),
154 .init = aac_adtstoasc_init,
155 .filter = aac_adtstoasc_filter,
156};

/root/firefox-clang/media/ffvpx/libavcodec/get_bits.h

1/*
2 * Copyright (c) 2004 Michael Niedermayer <michaelni@gmx.at>
3 *
4 * This file is part of FFmpeg.
5 *
6 * FFmpeg is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * FFmpeg is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with FFmpeg; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
21/**
22 * @file
23 * bitstream reader API header.
24 */
25
26#ifndef AVCODEC_GET_BITS_H
27#define AVCODEC_GET_BITS_H
28
29#include <stdint.h>
30
31#include "libavutil/common.h"
32#include "libavutil/intreadwrite.h"
33#include "libavutil/avassert.h"
34
35#include "defs.h"
36#include "mathops.h"
37#include "vlc.h"
38
39/*
40 * Safe bitstream reading:
41 * optionally, the get_bits API can check to ensure that we
42 * don't read past input buffer boundaries. This is protected
43 * with CONFIG_SAFE_BITSTREAM_READER at the global level, and
44 * then below that with UNCHECKED_BITSTREAM_READER at the per-
45 * decoder level. This means that decoders that check internally
46 * can "#define UNCHECKED_BITSTREAM_READER 1" to disable
47 * overread checks.
48 * Boundary checking causes a minor performance penalty so for
49 * applications that won't want/need this, it can be disabled
50 * globally using "#define CONFIG_SAFE_BITSTREAM_READER 0".
51 */
52#ifndef UNCHECKED_BITSTREAM_READER!1
53#define UNCHECKED_BITSTREAM_READER!1 !CONFIG_SAFE_BITSTREAM_READER1
54#endif
55
56#ifndef CACHED_BITSTREAM_READER0
57#define CACHED_BITSTREAM_READER0 0
58#endif
59
60#if CACHED_BITSTREAM_READER0
61
62// we always want the LE implementation, to provide get_bits_le()
63#define BITSTREAM_LE
64
65#ifndef BITSTREAM_READER_LE
66# define BITSTREAM_BE
67# define BITSTREAM_DEFAULT_BE
68#endif
69
70#include "bitstream.h"
71
72#undef BITSTREAM_LE
73#undef BITSTREAM_BE
74#undef BITSTREAM_DEFAULT_BE
75
76typedef BitstreamContext GetBitContext;
77
78#define get_bits_count bits_tell
79#define get_bits_bytesize bits_bytesize
80#define get_bits_left bits_left
81#define skip_bits_long bits_skip
82#define skip_bits bits_skip
83#define get_bits bits_read_nz
84#define get_bitsz bits_read
85#define get_bits_long bits_read
86#define get_bits1 bits_read_bit
87#define get_bits64 bits_read_64
88#define get_xbits bits_read_xbits
89#define get_sbits bits_read_signed_nz
90#define get_sbits_long bits_read_signed
91#define show_bits bits_peek
92#define show_bits_long bits_peek
93#define init_get_bits bits_init
94#define init_get_bits8 bits_init8
95#define align_get_bits bits_align
96#define get_vlc2 bits_read_vlc
97#define get_vlc_multi bits_read_vlc_multi
98
99#define init_get_bits8_le(s, buffer, byte_size) bits_init8_le((BitstreamContextLE*)s, buffer, byte_size)
100#define get_bits_le(s, n) bits_read_le((BitstreamContextLE*)s, n)
101
102#define show_bits1(s) bits_peek(s, 1)
103#define skip_bits1(s) bits_skip(s, 1)
104
105#define skip_1stop_8data_bits bits_skip_1stop_8data
106
107#else // CACHED_BITSTREAM_READER
108
109typedef struct GetBitContext {
110 const uint8_t *buffer;
111 int index;
112 int size_in_bits;
113 int size_in_bits_plus8;
114} GetBitContext;
115
116static inline unsigned int get_bits(GetBitContext *s, int n);
117static inline void skip_bits(GetBitContext *s, int n);
118static inline unsigned int show_bits(GetBitContext *s, int n);
119
120/* Bitstream reader API docs:
121 * name
122 * arbitrary name which is used as prefix for the internal variables
123 *
124 * gb
125 * getbitcontext
126 *
127 * OPEN_READER(name, gb)
128 * load gb into local variables
129 *
130 * CLOSE_READER(name, gb)
131 * store local vars in gb
132 *
133 * UPDATE_CACHE(name, gb)
134 * Refill the internal cache from the bitstream.
135 * After this call at least MIN_CACHE_BITS will be available.
136 *
137 * GET_CACHE(name, gb)
138 * Will output the contents of the internal cache,
139 * next bit is MSB of 32 or 64 bits (FIXME 64 bits).
140 *
141 * SHOW_UBITS(name, gb, num)
142 * Will return the next num bits.
143 *
144 * SHOW_SBITS(name, gb, num)
145 * Will return the next num bits and do sign extension.
146 *
147 * SKIP_BITS(name, gb, num)
148 * Will skip over the next num bits.
149 * Note, this is equivalent to SKIP_CACHE; SKIP_COUNTER.
150 *
151 * SKIP_CACHE(name, gb, num)
152 * Will remove the next num bits from the cache (note SKIP_COUNTER
153 * MUST be called before UPDATE_CACHE / CLOSE_READER).
154 *
155 * SKIP_COUNTER(name, gb, num)
156 * Will increment the internal bit counter (see SKIP_CACHE & SKIP_BITS).
157 *
158 * LAST_SKIP_BITS(name, gb, num)
159 * Like SKIP_BITS, to be used if next call is UPDATE_CACHE or CLOSE_READER.
160 *
161 * BITS_LEFT(name, gb)
162 * Return the number of bits left
163 *
164 * For examples see get_bits, show_bits, skip_bits, get_vlc.
165 */
166
167#define MIN_CACHE_BITS25 25
168
169#define OPEN_READER_NOSIZE_NOCACHE(name, gb)unsigned int name_index = (gb)->index \
170 unsigned int name ## _index = (gb)->index
171
172#define OPEN_READER_NOSIZE(name, gb)unsigned int name_index = (gb)->index; unsigned int name_cache \
173 OPEN_READER_NOSIZE_NOCACHE(name, gb)unsigned int name_index = (gb)->index; \
174 unsigned int name ## _cache
175
176#if UNCHECKED_BITSTREAM_READER!1
177#define OPEN_READER(name, gb)unsigned int name_index = (gb)->index; unsigned int name_cache
; unsigned int name_size_plus8 = (gb)->size_in_bits_plus8
OPEN_READER_NOSIZE(name, gb)unsigned int name_index = (gb)->index; unsigned int name_cache
178#define OPEN_READER_SIZE(name, gb)unsigned int name_size_plus8 = (gb)->size_in_bits_plus8 ((void)0)
179#define BITS_AVAILABLE(name, gb)name_index < name_size_plus8 1
180#else
181#define OPEN_READER_SIZE(name, gb)unsigned int name_size_plus8 = (gb)->size_in_bits_plus8 unsigned int name ## _size_plus8 = (gb)->size_in_bits_plus8
182#define OPEN_READER(name, gb)unsigned int name_index = (gb)->index; unsigned int name_cache
; unsigned int name_size_plus8 = (gb)->size_in_bits_plus8
\
183 OPEN_READER_NOSIZE(name, gb)unsigned int name_index = (gb)->index; unsigned int name_cache; \
184 OPEN_READER_SIZE(name, gb)unsigned int name_size_plus8 = (gb)->size_in_bits_plus8
185
186#define BITS_AVAILABLE(name, gb)name_index < name_size_plus8 name ## _index < name ## _size_plus8
187#endif
188
189#define CLOSE_READER(name, gb)(gb)->index = name_index (gb)->index = name ## _index
190
191#define UPDATE_CACHE_BE_EXT(name, gb, bits, dst_bits)name_cache = AV_RBbits((gb)->buffer + (name_index >>
3)) << (name_index & 7) >> (bits - dst_bits)
name ## _cache = \
192 AV_RB ## bits((gb)->buffer + (name ## _index >> 3)) << (name ## _index & 7) >> (bits - dst_bits)
193
194#define UPDATE_CACHE_LE_EXT(name, gb, bits, dst_bits)name_cache = (uintdst_bits_t)(AV_RLbits((gb)->buffer + (name_index
>> 3)) >> (name_index & 7))
name ## _cache = \
195 (uint ## dst_bits ## _t)(AV_RL ## bits((gb)->buffer + (name ## _index >> 3)) >> (name ## _index & 7))
196
197/* Using these two macros ensures that 32 bits are available. */
198# define UPDATE_CACHE_LE_32(name, gb)name_cache = (uint32_t)((((const union unaligned_64 *) (((gb)
)->buffer + (name_index >> 3)))->l) >> (name_index
& 7))
UPDATE_CACHE_LE_EXT(name, (gb), 64, 32)name_cache = (uint32_t)((((const union unaligned_64 *) (((gb)
)->buffer + (name_index >> 3)))->l) >> (name_index
& 7))
199# define UPDATE_CACHE_BE_32(name, gb)name_cache = av_bswap64((((const union unaligned_64 *) (((gb)
)->buffer + (name_index >> 3)))->l)) << (name_index
& 7) >> (64 - 32)
UPDATE_CACHE_BE_EXT(name, (gb), 64, 32)name_cache = av_bswap64((((const union unaligned_64 *) (((gb)
)->buffer + (name_index >> 3)))->l)) << (name_index
& 7) >> (64 - 32)
200
201# define UPDATE_CACHE_LE(name, gb)name_cache = (uint32_t)((((const union unaligned_32 *) (((gb)
)->buffer + (name_index >> 3)))->l) >> (name_index
& 7))
UPDATE_CACHE_LE_EXT(name, (gb), 32, 32)name_cache = (uint32_t)((((const union unaligned_32 *) (((gb)
)->buffer + (name_index >> 3)))->l) >> (name_index
& 7))
202# define UPDATE_CACHE_BE(name, gb)name_cache = av_bswap32((((const union unaligned_32 *) (((gb)
)->buffer + (name_index >> 3)))->l)) << (name_index
& 7) >> (32 - 32)
UPDATE_CACHE_BE_EXT(name, (gb), 32, 32)name_cache = av_bswap32((((const union unaligned_32 *) (((gb)
)->buffer + (name_index >> 3)))->l)) << (name_index
& 7) >> (32 - 32)
203
204#ifdef BITSTREAM_READER_LE
205
206# define UPDATE_CACHE(name, gb)name_cache = av_bswap32((((const union unaligned_32 *) (((gb)
)->buffer + (name_index >> 3)))->l)) << (name_index
& 7) >> (32 - 32)
UPDATE_CACHE_LE(name, gb)name_cache = (uint32_t)((((const union unaligned_32 *) (((gb)
)->buffer + (name_index >> 3)))->l) >> (name_index
& 7))
207# define UPDATE_CACHE_32(name, gb)name_cache = av_bswap64((((const union unaligned_64 *) ((((gb
)))->buffer + (name_index >> 3)))->l)) << (
name_index & 7) >> (64 - 32)
UPDATE_CACHE_LE_32(name, (gb))name_cache = (uint32_t)((((const union unaligned_64 *) ((((gb
)))->buffer + (name_index >> 3)))->l) >> (name_index
& 7))
208
209# define SKIP_CACHE(name, gb, num)name_cache <<= (num) name ## _cache >>= (num)
210
211#else
212
213# define UPDATE_CACHE(name, gb)name_cache = av_bswap32((((const union unaligned_32 *) (((gb)
)->buffer + (name_index >> 3)))->l)) << (name_index
& 7) >> (32 - 32)
UPDATE_CACHE_BE(name, gb)name_cache = av_bswap32((((const union unaligned_32 *) (((gb)
)->buffer + (name_index >> 3)))->l)) << (name_index
& 7) >> (32 - 32)
214# define UPDATE_CACHE_32(name, gb)name_cache = av_bswap64((((const union unaligned_64 *) ((((gb
)))->buffer + (name_index >> 3)))->l)) << (
name_index & 7) >> (64 - 32)
UPDATE_CACHE_BE_32(name, (gb))name_cache = av_bswap64((((const union unaligned_64 *) ((((gb
)))->buffer + (name_index >> 3)))->l)) << (
name_index & 7) >> (64 - 32)
215
216# define SKIP_CACHE(name, gb, num)name_cache <<= (num) name ## _cache <<= (num)
217
218#endif
219
220#if UNCHECKED_BITSTREAM_READER!1
221# define SKIP_COUNTER(name, gb, num)name_index = ((name_size_plus8) > (name_index + (num)) ? (
name_index + (num)) : (name_size_plus8))
name ## _index += (num)
222#else
223# define SKIP_COUNTER(name, gb, num)name_index = ((name_size_plus8) > (name_index + (num)) ? (
name_index + (num)) : (name_size_plus8))
\
224 name ## _index = FFMIN(name ## _size_plus8, name ## _index + (num))((name ## _size_plus8) > (name ## _index + (num)) ? (name ##
_index + (num)) : (name ## _size_plus8))
225#endif
226
227#define BITS_LEFT(name, gb)((int)((gb)->size_in_bits - name_index)) ((int)((gb)->size_in_bits - name ## _index))
228
229#define SKIP_BITS(name, gb, num)do { name_cache <<= (num); name_index = ((name_size_plus8
) > (name_index + (num)) ? (name_index + (num)) : (name_size_plus8
)); } while (0)
\
230 do { \
231 SKIP_CACHE(name, gb, num)name_cache <<= (num); \
232 SKIP_COUNTER(name, gb, num)name_index = ((name_size_plus8) > (name_index + (num)) ? (
name_index + (num)) : (name_size_plus8))
; \
233 } while (0)
234
235#define LAST_SKIP_BITS(name, gb, num)name_index = ((name_size_plus8) > (name_index + (num)) ? (
name_index + (num)) : (name_size_plus8))
SKIP_COUNTER(name, gb, num)name_index = ((name_size_plus8) > (name_index + (num)) ? (
name_index + (num)) : (name_size_plus8))
236
237#define SHOW_UBITS_LE(name, gb, num)zero_extend(name_cache, num) zero_extend(name ## _cache, num)
238#define SHOW_SBITS_LE(name, gb, num)sign_extend(name_cache, num) sign_extend(name ## _cache, num)
239
240#define SHOW_UBITS_BE(name, gb, num)NEG_USR32(name_cache, num) NEG_USR32NEG_USR32(name ## _cache, num)
241#define SHOW_SBITS_BE(name, gb, num)NEG_SSR32(name_cache, num) NEG_SSR32NEG_SSR32(name ## _cache, num)
242
243#ifdef BITSTREAM_READER_LE
244# define SHOW_UBITS(name, gb, num)NEG_USR32(name_cache, num) SHOW_UBITS_LE(name, gb, num)zero_extend(name_cache, num)
245# define SHOW_SBITS(name, gb, num)NEG_SSR32(name_cache, num) SHOW_SBITS_LE(name, gb, num)sign_extend(name_cache, num)
246#else
247# define SHOW_UBITS(name, gb, num)NEG_USR32(name_cache, num) SHOW_UBITS_BE(name, gb, num)NEG_USR32(name_cache, num)
248# define SHOW_SBITS(name, gb, num)NEG_SSR32(name_cache, num) SHOW_SBITS_BE(name, gb, num)NEG_SSR32(name_cache, num)
249#endif
250
251#define GET_CACHE(name, gb)((uint32_t) name_cache) ((uint32_t) name ## _cache)
252
253
254static inline int get_bits_count(const GetBitContext *s)
255{
256 return s->index;
257}
258
259/**
260 * Get the size of the GetBitContext's buffer in bytes.
261 *
262 * @param s the GetBitContext
263 * @param round_up If set, the number of bits will be rounded up to full bytes;
264 * this does not matter if the number of bits is known to be
265 * a multiple of eight, e.g. if the GetBitContext has been
266 * initialized with init_get_bits8.
267 */
268static inline int get_bits_bytesize(const GetBitContext *s, int round_up)
269{
270 return (s->size_in_bits + (round_up ? 7 : 0)) >> 3;
271}
272
273/**
274 * Skips the specified number of bits.
275 * @param n the number of bits to skip,
276 * For the UNCHECKED_BITSTREAM_READER this must not cause the distance
277 * from the start to overflow int32_t. Staying within the bitstream + padding
278 * is sufficient, too.
279 */
280static inline void skip_bits_long(GetBitContext *s, int n)
281{
282#if UNCHECKED_BITSTREAM_READER!1
283 s->index += n;
284#else
285 s->index += av_clipav_clip_c(n, -s->index, s->size_in_bits_plus8 - s->index);
286#endif
287}
288
289/**
290 * Read MPEG-1 dc-style VLC (sign bit + mantissa with no MSB).
291 * if MSB not set it is negative
292 * @param n length in bits
293 */
294static inline int get_xbits(GetBitContext *s, int n)
295{
296 register int sign;
297 register int32_t cache;
298 OPEN_READER(re, s)unsigned int re_index = (s)->index; unsigned int re_cache;
unsigned int re_size_plus8 = (s)->size_in_bits_plus8
;
299 av_assert2(n>0 && n<=25)do { if (!(n>0 && n<=25)) { av_log(((void*)0), 0
, "Assertion %s failed at %s:%d\n", "n>0 && n<=25"
, "/root/firefox-clang/media/ffvpx/libavcodec/get_bits.h", 299
); abort(); } } while (0)
;
300 UPDATE_CACHE(re, s)re_cache = av_bswap32((((const union unaligned_32 *) (((s))->
buffer + (re_index >> 3)))->l)) << (re_index &
7) >> (32 - 32)
;
301 cache = GET_CACHE(re, s)((uint32_t) re_cache);
302 sign = ~cache >> 31;
303 LAST_SKIP_BITS(re, s, n)re_index = ((re_size_plus8) > (re_index + (n)) ? (re_index
+ (n)) : (re_size_plus8))
;
304 CLOSE_READER(re, s)(s)->index = re_index;
305 return (NEG_USR32NEG_USR32(sign ^ cache, n) ^ sign) - sign;
306}
307
308static inline int get_xbits_le(GetBitContext *s, int n)
309{
310 register int sign;
311 register int32_t cache;
312 OPEN_READER(re, s)unsigned int re_index = (s)->index; unsigned int re_cache;
unsigned int re_size_plus8 = (s)->size_in_bits_plus8
;
313 av_assert2(n>0 && n<=25)do { if (!(n>0 && n<=25)) { av_log(((void*)0), 0
, "Assertion %s failed at %s:%d\n", "n>0 && n<=25"
, "/root/firefox-clang/media/ffvpx/libavcodec/get_bits.h", 313
); abort(); } } while (0)
;
314 UPDATE_CACHE_LE(re, s)re_cache = (uint32_t)((((const union unaligned_32 *) (((s))->
buffer + (re_index >> 3)))->l) >> (re_index &
7))
;
315 cache = GET_CACHE(re, s)((uint32_t) re_cache);
316 sign = sign_extend(~cache, n) >> 31;
317 LAST_SKIP_BITS(re, s, n)re_index = ((re_size_plus8) > (re_index + (n)) ? (re_index
+ (n)) : (re_size_plus8))
;
318 CLOSE_READER(re, s)(s)->index = re_index;
319 return (zero_extend(sign ^ cache, n) ^ sign) - sign;
320}
321
322static inline int get_sbits(GetBitContext *s, int n)
323{
324 register int tmp;
325 OPEN_READER(re, s)unsigned int re_index = (s)->index; unsigned int re_cache;
unsigned int re_size_plus8 = (s)->size_in_bits_plus8
;
326 av_assert2(n>0 && n<=25)do { if (!(n>0 && n<=25)) { av_log(((void*)0), 0
, "Assertion %s failed at %s:%d\n", "n>0 && n<=25"
, "/root/firefox-clang/media/ffvpx/libavcodec/get_bits.h", 326
); abort(); } } while (0)
;
327 UPDATE_CACHE(re, s)re_cache = av_bswap32((((const union unaligned_32 *) (((s))->
buffer + (re_index >> 3)))->l)) << (re_index &
7) >> (32 - 32)
;
328 tmp = SHOW_SBITS(re, s, n)NEG_SSR32(re_cache, n);
329 LAST_SKIP_BITS(re, s, n)re_index = ((re_size_plus8) > (re_index + (n)) ? (re_index
+ (n)) : (re_size_plus8))
;
330 CLOSE_READER(re, s)(s)->index = re_index;
331 return tmp;
332}
333
334/**
335 * Read 1-25 bits.
336 */
337static inline unsigned int get_bits(GetBitContext *s, int n)
338{
339 register unsigned int tmp;
340 OPEN_READER(re, s)unsigned int re_index = (s)->index; unsigned int re_cache;
unsigned int re_size_plus8 = (s)->size_in_bits_plus8
;
341 av_assert2(n>0 && n<=25)do { if (!(n>0 && n<=25)) { av_log(((void*)0), 0
, "Assertion %s failed at %s:%d\n", "n>0 && n<=25"
, "/root/firefox-clang/media/ffvpx/libavcodec/get_bits.h", 341
); abort(); } } while (0)
;
22
Taking false branch
23
Loop condition is false. Exiting loop
342 UPDATE_CACHE(re, s)re_cache = av_bswap32((((const union unaligned_32 *) (((s))->
buffer + (re_index >> 3)))->l)) << (re_index &
7) >> (32 - 32)
;
24
Access to field 'l' results in a dereference of a null pointer
343 tmp = SHOW_UBITS(re, s, n)NEG_USR32(re_cache, n);
344 LAST_SKIP_BITS(re, s, n)re_index = ((re_size_plus8) > (re_index + (n)) ? (re_index
+ (n)) : (re_size_plus8))
;
345 CLOSE_READER(re, s)(s)->index = re_index;
346 av_assert2(tmp < UINT64_C(1) << n)do { if (!(tmp < 1UL << n)) { av_log(((void*)0), 0, "Assertion %s failed at %s:%d\n"
, "tmp < 1UL << n", "/root/firefox-clang/media/ffvpx/libavcodec/get_bits.h"
, 346); abort(); } } while (0)
;
347 return tmp;
348}
349
350/**
351 * Read 0-25 bits.
352 */
353static av_always_inline__attribute__((always_inline)) inline int get_bitsz(GetBitContext *s, int n)
354{
355 return n ? get_bits(s, n) : 0;
356}
357
358static inline unsigned int get_bits_le(GetBitContext *s, int n)
359{
360 register int tmp;
361 OPEN_READER(re, s)unsigned int re_index = (s)->index; unsigned int re_cache;
unsigned int re_size_plus8 = (s)->size_in_bits_plus8
;
362 av_assert2(n>0 && n<=25)do { if (!(n>0 && n<=25)) { av_log(((void*)0), 0
, "Assertion %s failed at %s:%d\n", "n>0 && n<=25"
, "/root/firefox-clang/media/ffvpx/libavcodec/get_bits.h", 362
); abort(); } } while (0)
;
363 UPDATE_CACHE_LE(re, s)re_cache = (uint32_t)((((const union unaligned_32 *) (((s))->
buffer + (re_index >> 3)))->l) >> (re_index &
7))
;
364 tmp = SHOW_UBITS_LE(re, s, n)zero_extend(re_cache, n);
365 LAST_SKIP_BITS(re, s, n)re_index = ((re_size_plus8) > (re_index + (n)) ? (re_index
+ (n)) : (re_size_plus8))
;
366 CLOSE_READER(re, s)(s)->index = re_index;
367 return tmp;
368}
369
370/**
371 * Show 1-25 bits.
372 */
373static inline unsigned int show_bits(GetBitContext *s, int n)
374{
375 register unsigned int tmp;
376 OPEN_READER_NOSIZE(re, s)unsigned int re_index = (s)->index; unsigned int re_cache;
377 av_assert2(n>0 && n<=25)do { if (!(n>0 && n<=25)) { av_log(((void*)0), 0
, "Assertion %s failed at %s:%d\n", "n>0 && n<=25"
, "/root/firefox-clang/media/ffvpx/libavcodec/get_bits.h", 377
); abort(); } } while (0)
;
378 UPDATE_CACHE(re, s)re_cache = av_bswap32((((const union unaligned_32 *) (((s))->
buffer + (re_index >> 3)))->l)) << (re_index &
7) >> (32 - 32)
;
379 tmp = SHOW_UBITS(re, s, n)NEG_USR32(re_cache, n);
380 return tmp;
381}
382
383static inline void skip_bits(GetBitContext *s, int n)
384{
385 OPEN_READER_NOSIZE_NOCACHE(re, s)unsigned int re_index = (s)->index;
386 OPEN_READER_SIZE(re, s)unsigned int re_size_plus8 = (s)->size_in_bits_plus8;
387 LAST_SKIP_BITS(re, s, n)re_index = ((re_size_plus8) > (re_index + (n)) ? (re_index
+ (n)) : (re_size_plus8))
;
388 CLOSE_READER(re, s)(s)->index = re_index;
389}
390
391static inline unsigned int get_bits1(GetBitContext *s)
392{
393 unsigned int index = s->index;
394 uint8_t result = s->buffer[index >> 3];
395#ifdef BITSTREAM_READER_LE
396 result >>= index & 7;
397 result &= 1;
398#else
399 result <<= index & 7;
400 result >>= 8 - 1;
401#endif
402#if !UNCHECKED_BITSTREAM_READER!1
403 if (s->index < s->size_in_bits_plus8)
404#endif
405 index++;
406 s->index = index;
407
408 return result;
409}
410
411static inline unsigned int show_bits1(GetBitContext *s)
412{
413 return show_bits(s, 1);
414}
415
416static inline void skip_bits1(GetBitContext *s)
417{
418 skip_bits(s, 1);
419}
420
421/**
422 * Read 0-32 bits.
423 */
424static inline unsigned int get_bits_long(GetBitContext *s, int n)
425{
426 av_assert2(n>=0 && n<=32)do { if (!(n>=0 && n<=32)) { av_log(((void*)0),
0, "Assertion %s failed at %s:%d\n", "n>=0 && n<=32"
, "/root/firefox-clang/media/ffvpx/libavcodec/get_bits.h", 426
); abort(); } } while (0)
;
427 if (!n) {
428 return 0;
429 } else if ((!HAVE_FAST_64BIT1 || av_builtin_constant_p__builtin_constant_p(n <= MIN_CACHE_BITS25))
430 && n <= MIN_CACHE_BITS25) {
431 return get_bits(s, n);
432 } else {
433#if HAVE_FAST_64BIT1
434 unsigned tmp;
435 OPEN_READER(re, s)unsigned int re_index = (s)->index; unsigned int re_cache;
unsigned int re_size_plus8 = (s)->size_in_bits_plus8
;
436 UPDATE_CACHE_32(re, s)re_cache = av_bswap64((((const union unaligned_64 *) ((((s)))
->buffer + (re_index >> 3)))->l)) << (re_index
& 7) >> (64 - 32)
;
437 tmp = SHOW_UBITS(re, s, n)NEG_USR32(re_cache, n);
438 LAST_SKIP_BITS(re, s, n)re_index = ((re_size_plus8) > (re_index + (n)) ? (re_index
+ (n)) : (re_size_plus8))
;
439 CLOSE_READER(re, s)(s)->index = re_index;
440 return tmp;
441#else
442#ifdef BITSTREAM_READER_LE
443 unsigned ret = get_bits(s, 16);
444 return ret | (get_bits(s, n - 16) << 16);
445#else
446 unsigned ret = get_bits(s, 16) << (n - 16);
447 return ret | get_bits(s, n - 16);
448#endif
449#endif
450 }
451}
452
453/**
454 * Read 0-64 bits.
455 */
456static inline uint64_t get_bits64(GetBitContext *s, int n)
457{
458 if (n <= 32) {
459 return get_bits_long(s, n);
460 } else {
461#ifdef BITSTREAM_READER_LE
462 uint64_t ret = get_bits_long(s, 32);
463 return ret | (uint64_t) get_bits_long(s, n - 32) << 32;
464#else
465 uint64_t ret = (uint64_t) get_bits_long(s, n - 32) << 32;
466 return ret | get_bits_long(s, 32);
467#endif
468 }
469}
470
471/**
472 * Read 0-32 bits as a signed integer.
473 */
474static inline int get_sbits_long(GetBitContext *s, int n)
475{
476 // sign_extend(x, 0) is undefined
477 if (!n)
478 return 0;
479
480 return sign_extend(get_bits_long(s, n), n);
481}
482
483/**
484 * Read 0-64 bits as a signed integer.
485 */
486static inline int64_t get_sbits64(GetBitContext *s, int n)
487{
488 // sign_extend(x, 0) is undefined
489 if (!n)
490 return 0;
491
492 return sign_extend64(get_bits64(s, n), n);
493}
494
495/**
496 * Show 0-32 bits.
497 */
498static inline unsigned int show_bits_long(GetBitContext *s, int n)
499{
500 if (n <= MIN_CACHE_BITS25) {
501 return show_bits(s, n);
502 } else {
503 GetBitContext gb = *s;
504 return get_bits_long(&gb, n);
505 }
506}
507
508
509/**
510 * Initialize GetBitContext.
511 * @param buffer bitstream buffer, must be AV_INPUT_BUFFER_PADDING_SIZE bytes
512 * larger than the actual read bits because some optimized bitstream
513 * readers read 32 or 64 bit at once and could read over the end
514 * @param bit_size the size of the buffer in bits
515 * @return 0 on success, AVERROR_INVALIDDATA if the buffer_size would overflow.
516 */
517static inline int init_get_bits(GetBitContext *s, const uint8_t *buffer,
518 int bit_size)
519{
520 int ret = 0;
521
522 if (bit_size >= INT_MAX2147483647 - FFMAX(7, AV_INPUT_BUFFER_PADDING_SIZE*8)((7) > (64*8) ? (7) : (64*8)) || bit_size < 0 || !buffer) {
14
Assuming the condition is false
15
Assuming 'bit_size' is >= 0
16
Assuming 'buffer' is null
17
Taking true branch
523 bit_size = 0;
524 buffer = NULL((void*)0);
18
Null pointer value stored to 'buffer'
525 ret = AVERROR_INVALIDDATA(-(int)(('I') | (('N') << 8) | (('D') << 16) | ((
unsigned)('A') << 24)))
;
526 }
527
528 s->buffer = buffer;
19
Null pointer value stored to 'gb.buffer'
529 s->size_in_bits = bit_size;
530 s->size_in_bits_plus8 = bit_size + 8;
531 s->index = 0;
532
533 return ret;
534}
535
536/**
537 * Initialize GetBitContext.
538 * @param buffer bitstream buffer, must be AV_INPUT_BUFFER_PADDING_SIZE bytes
539 * larger than the actual read bits because some optimized bitstream
540 * readers read 32 or 64 bit at once and could read over the end
541 * @param byte_size the size of the buffer in bytes
542 * @return 0 on success, AVERROR_INVALIDDATA if the buffer_size would overflow.
543 */
544static inline int init_get_bits8(GetBitContext *s, const uint8_t *buffer,
545 int byte_size)
546{
547 if (byte_size > INT_MAX2147483647 / 8 || byte_size < 0)
548 byte_size = -1;
549 return init_get_bits(s, buffer, byte_size * 8);
550}
551
552static inline int init_get_bits8_le(GetBitContext *s, const uint8_t *buffer,
553 int byte_size)
554{
555 if (byte_size > INT_MAX2147483647 / 8 || byte_size < 0)
556 byte_size = -1;
557 return init_get_bits(s, buffer, byte_size * 8);
558}
559
560static inline const uint8_t *align_get_bits(GetBitContext *s)
561{
562 int n = -get_bits_count(s) & 7;
563 if (n)
564 skip_bits(s, n);
565 return s->buffer + (s->index >> 3);
566}
567
568/**
569 * If the vlc code is invalid and max_depth=1, then no bits will be removed.
570 * If the vlc code is invalid and max_depth>1, then the number of bits removed
571 * is undefined.
572 */
573#define GET_VLC(code, name, gb, table, bits, max_depth)do { unsigned idx_ = NEG_USR32(name_cache, bits); code = table
[idx_].sym; int n_ = table[idx_].len; if (max_depth > 1 &&
n_ < 0) { name_index = ((name_size_plus8) > (name_index
+ (bits)) ? (name_index + (bits)) : (name_size_plus8)); name_cache
= av_bswap32((((const union unaligned_32 *) (((gb))->buffer
+ (name_index >> 3)))->l)) << (name_index &
7) >> (32 - 32); int nb__bits = -n_; idx_ = NEG_USR32(
name_cache, nb__bits) + code; code = table[idx_].sym; n_ = table
[idx_].len; if (max_depth > 2 && n_ < 0) { name_index
= ((name_size_plus8) > (name_index + (nb__bits)) ? (name_index
+ (nb__bits)) : (name_size_plus8)); name_cache = av_bswap32(
(((const union unaligned_32 *) (((gb))->buffer + (name_index
>> 3)))->l)) << (name_index & 7) >>
(32 - 32); nb__bits = -n_; idx_ = NEG_USR32(name_cache, nb__bits
) + code; code = table[idx_].sym; n_ = table[idx_].len; } } do
{ name_cache <<= (n_); name_index = ((name_size_plus8)
> (name_index + (n_)) ? (name_index + (n_)) : (name_size_plus8
)); } while (0); } while (0)
\
574 do { \
575 unsigned idx_ = SHOW_UBITS(name, gb, bits)NEG_USR32(name_cache, bits); \
576 code = table[idx_].sym; \
577 int n_ = table[idx_].len; \
578 \
579 if (max_depth > 1 && n_ < 0) { \
580 LAST_SKIP_BITS(name, gb, bits)name_index = ((name_size_plus8) > (name_index + (bits)) ? (
name_index + (bits)) : (name_size_plus8))
; \
581 UPDATE_CACHE(name, gb)name_cache = av_bswap32((((const union unaligned_32 *) (((gb)
)->buffer + (name_index >> 3)))->l)) << (name_index
& 7) >> (32 - 32)
; \
582 \
583 int nb__bits = -n_; \
584 \
585 idx_ = SHOW_UBITS(name, gb, nb__bits)NEG_USR32(name_cache, nb__bits) + code; \
586 code = table[idx_].sym; \
587 n_ = table[idx_].len; \
588 if (max_depth > 2 && n_ < 0) { \
589 LAST_SKIP_BITS(name, gb, nb__bits)name_index = ((name_size_plus8) > (name_index + (nb__bits)
) ? (name_index + (nb__bits)) : (name_size_plus8))
; \
590 UPDATE_CACHE(name, gb)name_cache = av_bswap32((((const union unaligned_32 *) (((gb)
)->buffer + (name_index >> 3)))->l)) << (name_index
& 7) >> (32 - 32)
; \
591 \
592 nb__bits = -n_; \
593 \
594 idx_ = SHOW_UBITS(name, gb, nb__bits)NEG_USR32(name_cache, nb__bits) + code; \
595 code = table[idx_].sym; \
596 n_ = table[idx_].len; \
597 } \
598 } \
599 SKIP_BITS(name, gb, n_)do { name_cache <<= (n_); name_index = ((name_size_plus8
) > (name_index + (n_)) ? (name_index + (n_)) : (name_size_plus8
)); } while (0)
; \
600 } while (0)
601
602#define GET_RL_VLC(level, run, name, gb, table, bits, \do { unsigned idx_ = NEG_USR32(name_cache, bits); level = table
[idx_].level; int n_ = table[idx_].len8; if (max_depth > 1
&& n_ < 0) { do { name_cache <<= (bits); name_index
= ((name_size_plus8) > (name_index + (bits)) ? (name_index
+ (bits)) : (name_size_plus8)); } while (0); if (need_update
) { name_cache = av_bswap32((((const union unaligned_32 *) ((
(gb))->buffer + (name_index >> 3)))->l)) <<
(name_index & 7) >> (32 - 32); } int nb__bits = -n_
; idx_ = NEG_USR32(name_cache, nb__bits) + level; level = table
[idx_].level; n_ = table[idx_].len8; if (max_depth > 2 &&
n_ < 0) { name_index = ((name_size_plus8) > (name_index
+ (nb__bits)) ? (name_index + (nb__bits)) : (name_size_plus8
)); if (need_update) { name_cache = av_bswap32((((const union
unaligned_32 *) (((gb))->buffer + (name_index >> 3)
))->l)) << (name_index & 7) >> (32 - 32); }
nb__bits = -n_; idx_ = NEG_USR32(name_cache, nb__bits) + level
; level = table[idx_].level; n_ = table[idx_].len8; } } run =
table[idx_].run; do { name_cache <<= (n_); name_index =
((name_size_plus8) > (name_index + (n_)) ? (name_index + (
n_)) : (name_size_plus8)); } while (0); } while (0)
603 max_depth, need_update)do { unsigned idx_ = NEG_USR32(name_cache, bits); level = table
[idx_].level; int n_ = table[idx_].len8; if (max_depth > 1
&& n_ < 0) { do { name_cache <<= (bits); name_index
= ((name_size_plus8) > (name_index + (bits)) ? (name_index
+ (bits)) : (name_size_plus8)); } while (0); if (need_update
) { name_cache = av_bswap32((((const union unaligned_32 *) ((
(gb))->buffer + (name_index >> 3)))->l)) <<
(name_index & 7) >> (32 - 32); } int nb__bits = -n_
; idx_ = NEG_USR32(name_cache, nb__bits) + level; level = table
[idx_].level; n_ = table[idx_].len8; if (max_depth > 2 &&
n_ < 0) { name_index = ((name_size_plus8) > (name_index
+ (nb__bits)) ? (name_index + (nb__bits)) : (name_size_plus8
)); if (need_update) { name_cache = av_bswap32((((const union
unaligned_32 *) (((gb))->buffer + (name_index >> 3)
))->l)) << (name_index & 7) >> (32 - 32); }
nb__bits = -n_; idx_ = NEG_USR32(name_cache, nb__bits) + level
; level = table[idx_].level; n_ = table[idx_].len8; } } run =
table[idx_].run; do { name_cache <<= (n_); name_index =
((name_size_plus8) > (name_index + (n_)) ? (name_index + (
n_)) : (name_size_plus8)); } while (0); } while (0)
\
604 do { \
605 unsigned idx_ = SHOW_UBITS(name, gb, bits)NEG_USR32(name_cache, bits); \
606 level = table[idx_].level; \
607 int n_ = table[idx_].len8; \
608 \
609 if (max_depth > 1 && n_ < 0) { \
610 SKIP_BITS(name, gb, bits)do { name_cache <<= (bits); name_index = ((name_size_plus8
) > (name_index + (bits)) ? (name_index + (bits)) : (name_size_plus8
)); } while (0)
; \
611 if (need_update) { \
612 UPDATE_CACHE(name, gb)name_cache = av_bswap32((((const union unaligned_32 *) (((gb)
)->buffer + (name_index >> 3)))->l)) << (name_index
& 7) >> (32 - 32)
; \
613 } \
614 \
615 int nb__bits = -n_; \
616 \
617 idx_ = SHOW_UBITS(name, gb, nb__bits)NEG_USR32(name_cache, nb__bits) + level; \
618 level = table[idx_].level; \
619 n_ = table[idx_].len8; \
620 if (max_depth > 2 && n_ < 0) { \
621 LAST_SKIP_BITS(name, gb, nb__bits)name_index = ((name_size_plus8) > (name_index + (nb__bits)
) ? (name_index + (nb__bits)) : (name_size_plus8))
; \
622 if (need_update) { \
623 UPDATE_CACHE(name, gb)name_cache = av_bswap32((((const union unaligned_32 *) (((gb)
)->buffer + (name_index >> 3)))->l)) << (name_index
& 7) >> (32 - 32)
; \
624 } \
625 nb__bits = -n_; \
626 \
627 idx_ = SHOW_UBITS(name, gb, nb__bits)NEG_USR32(name_cache, nb__bits) + level; \
628 level = table[idx_].level; \
629 n_ = table[idx_].len8; \
630 } \
631 } \
632 run = table[idx_].run; \
633 SKIP_BITS(name, gb, n_)do { name_cache <<= (n_); name_index = ((name_size_plus8
) > (name_index + (n_)) ? (name_index + (n_)) : (name_size_plus8
)); } while (0)
; \
634 } while (0)
635
636/**
637 * Parse a vlc code.
638 * @param bits is the number of bits which will be read at once, must be
639 * identical to nb_bits in vlc_init()
640 * @param max_depth is the number of times bits bits must be read to completely
641 * read the longest vlc code
642 * = (max_vlc_length + bits - 1) / bits
643 * @returns the code parsed or -1 if no vlc matches
644 */
645static av_always_inline__attribute__((always_inline)) inline int get_vlc2(GetBitContext *s, const VLCElem *table,
646 int bits, int max_depth)
647{
648 int code;
649
650 OPEN_READER(re, s)unsigned int re_index = (s)->index; unsigned int re_cache;
unsigned int re_size_plus8 = (s)->size_in_bits_plus8
;
651 UPDATE_CACHE(re, s)re_cache = av_bswap32((((const union unaligned_32 *) (((s))->
buffer + (re_index >> 3)))->l)) << (re_index &
7) >> (32 - 32)
;
652
653 GET_VLC(code, re, s, table, bits, max_depth)do { unsigned idx_ = NEG_USR32(re_cache, bits); code = table[
idx_].sym; int n_ = table[idx_].len; if (max_depth > 1 &&
n_ < 0) { re_index = ((re_size_plus8) > (re_index + (bits
)) ? (re_index + (bits)) : (re_size_plus8)); re_cache = av_bswap32
((((const union unaligned_32 *) (((s))->buffer + (re_index
>> 3)))->l)) << (re_index & 7) >> (
32 - 32); int nb__bits = -n_; idx_ = NEG_USR32(re_cache, nb__bits
) + code; code = table[idx_].sym; n_ = table[idx_].len; if (max_depth
> 2 && n_ < 0) { re_index = ((re_size_plus8) >
(re_index + (nb__bits)) ? (re_index + (nb__bits)) : (re_size_plus8
)); re_cache = av_bswap32((((const union unaligned_32 *) (((s
))->buffer + (re_index >> 3)))->l)) << (re_index
& 7) >> (32 - 32); nb__bits = -n_; idx_ = NEG_USR32
(re_cache, nb__bits) + code; code = table[idx_].sym; n_ = table
[idx_].len; } } do { re_cache <<= (n_); re_index = ((re_size_plus8
) > (re_index + (n_)) ? (re_index + (n_)) : (re_size_plus8
)); } while (0); } while (0)
;
654
655 CLOSE_READER(re, s)(s)->index = re_index;
656
657 return code;
658}
659
660static inline int get_vlc_multi(GetBitContext *s, uint8_t *dst,
661 av_unused__attribute__((unused)) const VLC_MULTI_ELEM *const Jtable,
662 const VLCElem *const table,
663 const int bits, const int max_depth,
664 av_unused__attribute__((unused)) const int symbols_size)
665{
666 dst[0] = get_vlc2(s, table, bits, max_depth);
667 return 1;
668}
669
670static inline int decode012(GetBitContext *gb)
671{
672 int n;
673 n = get_bits1(gb);
674 if (n == 0)
675 return 0;
676 else
677 return get_bits1(gb) + 1;
678}
679
680static inline int decode210(GetBitContext *gb)
681{
682 if (get_bits1(gb))
683 return 0;
684 else
685 return 2 - get_bits1(gb);
686}
687
688static inline int get_bits_left(GetBitContext *gb)
689{
690 return gb->size_in_bits - get_bits_count(gb);
691}
692
693static inline int skip_1stop_8data_bits(GetBitContext *gb)
694{
695 if (get_bits_left(gb) <= 0)
696 return AVERROR_INVALIDDATA(-(int)(('I') | (('N') << 8) | (('D') << 16) | ((
unsigned)('A') << 24)))
;
697
698 while (get_bits1(gb)) {
699 skip_bits(gb, 8);
700 if (get_bits_left(gb) <= 0)
701 return AVERROR_INVALIDDATA(-(int)(('I') | (('N') << 8) | (('D') << 16) | ((
unsigned)('A') << 24)))
;
702 }
703
704 return 0;
705}
706
707#endif // CACHED_BITSTREAM_READER
708
709#endif /* AVCODEC_GET_BITS_H */