* commit 'c50241080d7599c90fc8b4e74c5f8d62a4caae52':
vf_hqdn3d: fix uninitialized variable use
lzo: fix overflow checking in copy_backptr()
flacdec: simplify bounds checking in flac_probe()
atrac3: avoid oversized shifting in decode_bytes()
shorten: use the unsigned type where needed
shorten: report meaningful errors
shorten: K&R formatting cosmetics
shorten: set invalid channels count to 0
Conflicts:
libavcodec/shorten.c
libavformat/flacdec.c
Merged-by: Michael Niedermayer <michaelni@gmx.at>
... | ... |
@@ -165,7 +165,10 @@ static int decode_bytes(const uint8_t *input, uint8_t *out, int bytes) |
165 | 165 |
|
166 | 166 |
off = (intptr_t)input & 3; |
167 | 167 |
buf = (const uint32_t *)(input - off); |
168 |
- c = av_be2ne32((0x537F6103 >> (off * 8)) | (0x537F6103 << (32 - (off * 8)))); |
|
168 |
+ if (off) |
|
169 |
+ c = av_be2ne32((0x537F6103U >> (off * 8)) | (0x537F6103U << (32 - (off * 8)))); |
|
170 |
+ else |
|
171 |
+ c = av_be2ne32(0x537F6103U); |
|
169 | 172 |
bytes += 3 + off; |
170 | 173 |
for (i = 0; i < bytes / 4; i++) |
171 | 174 |
output[i] = c ^ buf[i]; |
... | ... |
@@ -88,7 +88,7 @@ typedef struct ShortenContext { |
88 | 88 |
GetBitContext gb; |
89 | 89 |
|
90 | 90 |
int min_framesize, max_framesize; |
91 |
- int channels; |
|
91 |
+ unsigned channels; |
|
92 | 92 |
|
93 | 93 |
int32_t *decoded[MAX_CHANNELS]; |
94 | 94 |
int32_t *decoded_base[MAX_CHANNELS]; |
... | ... |
@@ -113,10 +113,10 @@ typedef struct ShortenContext { |
113 | 113 |
int got_quit_command; |
114 | 114 |
} ShortenContext; |
115 | 115 |
|
116 |
-static av_cold int shorten_decode_init(AVCodecContext * avctx) |
|
116 |
+static av_cold int shorten_decode_init(AVCodecContext *avctx) |
|
117 | 117 |
{ |
118 | 118 |
ShortenContext *s = avctx->priv_data; |
119 |
- s->avctx = avctx; |
|
119 |
+ s->avctx = avctx; |
|
120 | 120 |
|
121 | 121 |
avcodec_get_frame_defaults(&s->frame); |
122 | 122 |
avctx->coded_frame = &s->frame; |
... | ... |
@@ -130,17 +130,20 @@ static int allocate_buffers(ShortenContext *s) |
130 | 130 |
int *coeffs; |
131 | 131 |
void *tmp_ptr; |
132 | 132 |
|
133 |
- for (chan=0; chan<s->channels; chan++) { |
|
134 |
- if(FFMAX(1, s->nmean) >= UINT_MAX/sizeof(int32_t)){ |
|
133 |
+ for (chan = 0; chan < s->channels; chan++) { |
|
134 |
+ if (FFMAX(1, s->nmean) >= UINT_MAX / sizeof(int32_t)) { |
|
135 | 135 |
av_log(s->avctx, AV_LOG_ERROR, "nmean too large\n"); |
136 | 136 |
return AVERROR_INVALIDDATA; |
137 | 137 |
} |
138 |
- if(s->blocksize + s->nwrap >= UINT_MAX/sizeof(int32_t) || s->blocksize + s->nwrap <= (unsigned)s->nwrap){ |
|
139 |
- av_log(s->avctx, AV_LOG_ERROR, "s->blocksize + s->nwrap too large\n"); |
|
138 |
+ if (s->blocksize + s->nwrap >= UINT_MAX / sizeof(int32_t) || |
|
139 |
+ s->blocksize + s->nwrap <= (unsigned)s->nwrap) { |
|
140 |
+ av_log(s->avctx, AV_LOG_ERROR, |
|
141 |
+ "s->blocksize + s->nwrap too large\n"); |
|
140 | 142 |
return AVERROR_INVALIDDATA; |
141 | 143 |
} |
142 | 144 |
|
143 |
- tmp_ptr = av_realloc(s->offset[chan], sizeof(int32_t)*FFMAX(1, s->nmean)); |
|
145 |
+ tmp_ptr = |
|
146 |
+ av_realloc(s->offset[chan], sizeof(int32_t) * FFMAX(1, s->nmean)); |
|
144 | 147 |
if (!tmp_ptr) |
145 | 148 |
return AVERROR(ENOMEM); |
146 | 149 |
s->offset[chan] = tmp_ptr; |
... | ... |
@@ -150,7 +153,7 @@ static int allocate_buffers(ShortenContext *s) |
150 | 150 |
if (!tmp_ptr) |
151 | 151 |
return AVERROR(ENOMEM); |
152 | 152 |
s->decoded_base[chan] = tmp_ptr; |
153 |
- for (i=0; i<s->nwrap; i++) |
|
153 |
+ for (i = 0; i < s->nwrap; i++) |
|
154 | 154 |
s->decoded_base[chan][i] = 0; |
155 | 155 |
s->decoded[chan] = s->decoded_base[chan] + s->nwrap; |
156 | 156 |
} |
... | ... |
@@ -163,7 +166,6 @@ static int allocate_buffers(ShortenContext *s) |
163 | 163 |
return 0; |
164 | 164 |
} |
165 | 165 |
|
166 |
- |
|
167 | 166 |
static inline unsigned int get_uint(ShortenContext *s, int k) |
168 | 167 |
{ |
169 | 168 |
if (s->version != 0) |
... | ... |
@@ -171,7 +173,6 @@ static inline unsigned int get_uint(ShortenContext *s, int k) |
171 | 171 |
return get_ur_golomb_shorten(&s->gb, k); |
172 | 172 |
} |
173 | 173 |
|
174 |
- |
|
175 | 174 |
static void fix_bitshift(ShortenContext *s, int32_t *buffer) |
176 | 175 |
{ |
177 | 176 |
int i; |
... | ... |
@@ -181,26 +182,24 @@ static void fix_bitshift(ShortenContext *s, int32_t *buffer) |
181 | 181 |
buffer[i] <<= s->bitshift; |
182 | 182 |
} |
183 | 183 |
|
184 |
- |
|
185 | 184 |
static int init_offset(ShortenContext *s) |
186 | 185 |
{ |
187 | 186 |
int32_t mean = 0; |
188 |
- int chan, i; |
|
187 |
+ int chan, i; |
|
189 | 188 |
int nblock = FFMAX(1, s->nmean); |
190 | 189 |
/* initialise offset */ |
191 |
- switch (s->internal_ftype) |
|
192 |
- { |
|
193 |
- case TYPE_U8: |
|
194 |
- s->avctx->sample_fmt = AV_SAMPLE_FMT_U8P; |
|
195 |
- mean = 0x80; |
|
196 |
- break; |
|
197 |
- case TYPE_S16HL: |
|
198 |
- case TYPE_S16LH: |
|
199 |
- s->avctx->sample_fmt = AV_SAMPLE_FMT_S16P; |
|
200 |
- break; |
|
201 |
- default: |
|
202 |
- av_log(s->avctx, AV_LOG_ERROR, "unknown audio type\n"); |
|
203 |
- return AVERROR_PATCHWELCOME; |
|
190 |
+ switch (s->internal_ftype) { |
|
191 |
+ case TYPE_U8: |
|
192 |
+ s->avctx->sample_fmt = AV_SAMPLE_FMT_U8P; |
|
193 |
+ mean = 0x80; |
|
194 |
+ break; |
|
195 |
+ case TYPE_S16HL: |
|
196 |
+ case TYPE_S16LH: |
|
197 |
+ s->avctx->sample_fmt = AV_SAMPLE_FMT_S16P; |
|
198 |
+ break; |
|
199 |
+ default: |
|
200 |
+ av_log(s->avctx, AV_LOG_ERROR, "unknown audio type\n"); |
|
201 |
+ return AVERROR_PATCHWELCOME; |
|
204 | 202 |
} |
205 | 203 |
|
206 | 204 |
for (chan = 0; chan < s->channels; chan++) |
... | ... |
@@ -216,21 +215,21 @@ static int decode_wave_header(AVCodecContext *avctx, const uint8_t *header, |
216 | 216 |
short wave_format; |
217 | 217 |
const uint8_t *end= header + header_size; |
218 | 218 |
|
219 |
- if (bytestream_get_le32(&header) != MKTAG('R','I','F','F')) { |
|
219 |
+ if (bytestream_get_le32(&header) != MKTAG('R', 'I', 'F', 'F')) { |
|
220 | 220 |
av_log(avctx, AV_LOG_ERROR, "missing RIFF tag\n"); |
221 | 221 |
return AVERROR_INVALIDDATA; |
222 | 222 |
} |
223 | 223 |
|
224 |
- header += 4; /* chunk size */; |
|
224 |
+ header += 4; /* chunk size */ |
|
225 | 225 |
|
226 |
- if (bytestream_get_le32(&header) != MKTAG('W','A','V','E')) { |
|
226 |
+ if (bytestream_get_le32(&header) != MKTAG('W', 'A', 'V', 'E')) { |
|
227 | 227 |
av_log(avctx, AV_LOG_ERROR, "missing WAVE tag\n"); |
228 | 228 |
return AVERROR_INVALIDDATA; |
229 | 229 |
} |
230 | 230 |
|
231 |
- while (bytestream_get_le32(&header) != MKTAG('f','m','t',' ')) { |
|
232 |
- len = bytestream_get_le32(&header); |
|
233 |
- if(len<0 || end - header - 8 < len) |
|
231 |
+ while (bytestream_get_le32(&header) != MKTAG('f', 'm', 't', ' ')) { |
|
232 |
+ len = bytestream_get_le32(&header); |
|
233 |
+ if (len<0 || end - header - 8 < len) |
|
234 | 234 |
return AVERROR_INVALIDDATA; |
235 | 235 |
header += len; |
236 | 236 |
} |
... | ... |
@@ -244,11 +243,11 @@ static int decode_wave_header(AVCodecContext *avctx, const uint8_t *header, |
244 | 244 |
wave_format = bytestream_get_le16(&header); |
245 | 245 |
|
246 | 246 |
switch (wave_format) { |
247 |
- case WAVE_FORMAT_PCM: |
|
248 |
- break; |
|
249 |
- default: |
|
250 |
- av_log(avctx, AV_LOG_ERROR, "unsupported wave format\n"); |
|
251 |
- return AVERROR_PATCHWELCOME; |
|
247 |
+ case WAVE_FORMAT_PCM: |
|
248 |
+ break; |
|
249 |
+ default: |
|
250 |
+ av_log(avctx, AV_LOG_ERROR, "unsupported wave format\n"); |
|
251 |
+ return AVERROR(ENOSYS); |
|
252 | 252 |
} |
253 | 253 |
|
254 | 254 |
header += 2; // skip channels (already got from shorten header) |
... | ... |
@@ -260,7 +259,7 @@ static int decode_wave_header(AVCodecContext *avctx, const uint8_t *header, |
260 | 260 |
|
261 | 261 |
if (bps != 16 && bps != 8) { |
262 | 262 |
av_log(avctx, AV_LOG_ERROR, "unsupported number of bits per sample: %d\n", bps); |
263 |
- return AVERROR_INVALIDDATA; |
|
263 |
+ return AVERROR(ENOSYS); |
|
264 | 264 |
} |
265 | 265 |
|
266 | 266 |
len -= 16; |
... | ... |
@@ -286,11 +285,12 @@ static int decode_subframe_lpc(ShortenContext *s, int command, int channel, |
286 | 286 |
/* read/validate prediction order */ |
287 | 287 |
pred_order = get_ur_golomb_shorten(&s->gb, LPCQSIZE); |
288 | 288 |
if (pred_order > s->nwrap) { |
289 |
- av_log(s->avctx, AV_LOG_ERROR, "invalid pred_order %d\n", pred_order); |
|
289 |
+ av_log(s->avctx, AV_LOG_ERROR, "invalid pred_order %d\n", |
|
290 |
+ pred_order); |
|
290 | 291 |
return AVERROR(EINVAL); |
291 | 292 |
} |
292 | 293 |
/* read LPC coefficients */ |
293 |
- for (i=0; i<pred_order; i++) |
|
294 |
+ for (i = 0; i < pred_order; i++) |
|
294 | 295 |
s->coeffs[i] = get_sr_golomb_shorten(&s->gb, LPCQUANT); |
295 | 296 |
coeffs = s->coeffs; |
296 | 297 |
|
... | ... |
@@ -298,7 +298,7 @@ static int decode_subframe_lpc(ShortenContext *s, int command, int channel, |
298 | 298 |
} else { |
299 | 299 |
/* fixed LPC coeffs */ |
300 | 300 |
pred_order = command; |
301 |
- coeffs = fixed_coeffs[pred_order-1]; |
|
301 |
+ coeffs = fixed_coeffs[pred_order - 1]; |
|
302 | 302 |
qshift = 0; |
303 | 303 |
} |
304 | 304 |
|
... | ... |
@@ -309,11 +309,12 @@ static int decode_subframe_lpc(ShortenContext *s, int command, int channel, |
309 | 309 |
|
310 | 310 |
/* decode residual and do LPC prediction */ |
311 | 311 |
init_sum = pred_order ? (command == FN_QLPC ? s->lpcqoffset : 0) : coffset; |
312 |
- for (i=0; i < s->blocksize; i++) { |
|
312 |
+ for (i = 0; i < s->blocksize; i++) { |
|
313 | 313 |
sum = init_sum; |
314 |
- for (j=0; j<pred_order; j++) |
|
315 |
- sum += coeffs[j] * s->decoded[channel][i-j-1]; |
|
316 |
- s->decoded[channel][i] = get_sr_golomb_shorten(&s->gb, residual_size) + (sum >> qshift); |
|
314 |
+ for (j = 0; j < pred_order; j++) |
|
315 |
+ sum += coeffs[j] * s->decoded[channel][i - j - 1]; |
|
316 |
+ s->decoded[channel][i] = get_sr_golomb_shorten(&s->gb, residual_size) + |
|
317 |
+ (sum >> qshift); |
|
317 | 318 |
} |
318 | 319 |
|
319 | 320 |
/* add offset to current samples */ |
... | ... |
@@ -334,14 +335,18 @@ static int read_header(ShortenContext *s) |
334 | 334 |
return AVERROR_INVALIDDATA; |
335 | 335 |
} |
336 | 336 |
|
337 |
- s->lpcqoffset = 0; |
|
338 |
- s->blocksize = DEFAULT_BLOCK_SIZE; |
|
339 |
- s->nmean = -1; |
|
340 |
- s->version = get_bits(&s->gb, 8); |
|
337 |
+ s->lpcqoffset = 0; |
|
338 |
+ s->blocksize = DEFAULT_BLOCK_SIZE; |
|
339 |
+ s->nmean = -1; |
|
340 |
+ s->version = get_bits(&s->gb, 8); |
|
341 | 341 |
s->internal_ftype = get_uint(s, TYPESIZE); |
342 | 342 |
|
343 | 343 |
s->channels = get_uint(s, CHANSIZE); |
344 |
- if (s->channels <= 0 || s->channels > MAX_CHANNELS) { |
|
344 |
+ if (!s->channels) { |
|
345 |
+ av_log(s->avctx, AV_LOG_ERROR, "No channels reported\n"); |
|
346 |
+ return AVERROR_INVALIDDATA; |
|
347 |
+ } |
|
348 |
+ if (s->channels > MAX_CHANNELS) { |
|
345 | 349 |
av_log(s->avctx, AV_LOG_ERROR, "too many channels: %d\n", s->channels); |
346 | 350 |
s->channels = 0; |
347 | 351 |
return AVERROR_INVALIDDATA; |
... | ... |
@@ -350,23 +355,24 @@ static int read_header(ShortenContext *s) |
350 | 350 |
|
351 | 351 |
/* get blocksize if version > 0 */ |
352 | 352 |
if (s->version > 0) { |
353 |
- int skip_bytes, blocksize; |
|
353 |
+ int skip_bytes; |
|
354 |
+ unsigned blocksize; |
|
354 | 355 |
|
355 | 356 |
blocksize = get_uint(s, av_log2(DEFAULT_BLOCK_SIZE)); |
356 | 357 |
if (!blocksize || blocksize > MAX_BLOCKSIZE) { |
357 |
- av_log(s->avctx, AV_LOG_ERROR, "invalid or unsupported block size: %d\n", |
|
358 |
+ av_log(s->avctx, AV_LOG_ERROR, |
|
359 |
+ "invalid or unsupported block size: %d\n", |
|
358 | 360 |
blocksize); |
359 | 361 |
return AVERROR(EINVAL); |
360 | 362 |
} |
361 | 363 |
s->blocksize = blocksize; |
362 | 364 |
|
363 |
- maxnlpc = get_uint(s, LPCQSIZE); |
|
365 |
+ maxnlpc = get_uint(s, LPCQSIZE); |
|
364 | 366 |
s->nmean = get_uint(s, 0); |
365 | 367 |
|
366 | 368 |
skip_bytes = get_uint(s, NSKIPSIZE); |
367 |
- for (i=0; i<skip_bytes; i++) { |
|
369 |
+ for (i = 0; i < skip_bytes; i++) |
|
368 | 370 |
skip_bits(&s->gb, 8); |
369 |
- } |
|
370 | 371 |
} |
371 | 372 |
s->nwrap = FFMAX(NWRAP, maxnlpc); |
372 | 373 |
|
... | ... |
@@ -380,17 +386,20 @@ static int read_header(ShortenContext *s) |
380 | 380 |
s->lpcqoffset = V2LPCQOFFSET; |
381 | 381 |
|
382 | 382 |
if (get_ur_golomb_shorten(&s->gb, FNSIZE) != FN_VERBATIM) { |
383 |
- av_log(s->avctx, AV_LOG_ERROR, "missing verbatim section at beginning of stream\n"); |
|
383 |
+ av_log(s->avctx, AV_LOG_ERROR, |
|
384 |
+ "missing verbatim section at beginning of stream\n"); |
|
384 | 385 |
return AVERROR_INVALIDDATA; |
385 | 386 |
} |
386 | 387 |
|
387 | 388 |
s->header_size = get_ur_golomb_shorten(&s->gb, VERBATIM_CKSIZE_SIZE); |
388 |
- if (s->header_size >= OUT_BUFFER_SIZE || s->header_size < CANONICAL_HEADER_SIZE) { |
|
389 |
- av_log(s->avctx, AV_LOG_ERROR, "header is wrong size: %d\n", s->header_size); |
|
389 |
+ if (s->header_size >= OUT_BUFFER_SIZE || |
|
390 |
+ s->header_size < CANONICAL_HEADER_SIZE) { |
|
391 |
+ av_log(s->avctx, AV_LOG_ERROR, "header is wrong size: %d\n", |
|
392 |
+ s->header_size); |
|
390 | 393 |
return AVERROR_INVALIDDATA; |
391 | 394 |
} |
392 | 395 |
|
393 |
- for (i=0; i<s->header_size; i++) |
|
396 |
+ for (i = 0; i < s->header_size; i++) |
|
394 | 397 |
s->header[i] = (char)get_ur_golomb_shorten(&s->gb, VERBATIM_BYTE_SIZE); |
395 | 398 |
|
396 | 399 |
if ((ret = decode_wave_header(s->avctx, s->header, s->header_size)) < 0) |
... | ... |
@@ -408,15 +417,15 @@ static int shorten_decode_frame(AVCodecContext *avctx, void *data, |
408 | 408 |
int *got_frame_ptr, AVPacket *avpkt) |
409 | 409 |
{ |
410 | 410 |
const uint8_t *buf = avpkt->data; |
411 |
- int buf_size = avpkt->size; |
|
412 |
- ShortenContext *s = avctx->priv_data; |
|
411 |
+ int buf_size = avpkt->size; |
|
412 |
+ ShortenContext *s = avctx->priv_data; |
|
413 | 413 |
int i, input_buf_size = 0; |
414 | 414 |
int ret; |
415 | 415 |
|
416 | 416 |
/* allocate internal bitstream buffer */ |
417 |
- if(s->max_framesize == 0){ |
|
417 |
+ if (s->max_framesize == 0) { |
|
418 | 418 |
void *tmp_ptr; |
419 |
- s->max_framesize= 8192; // should hopefully be enough for the first header |
|
419 |
+ s->max_framesize = 8192; // should hopefully be enough for the first header |
|
420 | 420 |
tmp_ptr = av_fast_realloc(s->bitstream, &s->allocated_bitstream_size, |
421 | 421 |
s->max_framesize); |
422 | 422 |
if (!tmp_ptr) { |
... | ... |
@@ -427,29 +436,32 @@ static int shorten_decode_frame(AVCodecContext *avctx, void *data, |
427 | 427 |
} |
428 | 428 |
|
429 | 429 |
/* append current packet data to bitstream buffer */ |
430 |
- if(1 && s->max_framesize){//FIXME truncated |
|
431 |
- buf_size= FFMIN(buf_size, s->max_framesize - s->bitstream_size); |
|
432 |
- input_buf_size= buf_size; |
|
433 |
- |
|
434 |
- if(s->bitstream_index + s->bitstream_size + buf_size > s->allocated_bitstream_size){ |
|
435 |
- memmove(s->bitstream, &s->bitstream[s->bitstream_index], s->bitstream_size); |
|
436 |
- s->bitstream_index=0; |
|
430 |
+ if (1 && s->max_framesize) { //FIXME truncated |
|
431 |
+ buf_size = FFMIN(buf_size, s->max_framesize - s->bitstream_size); |
|
432 |
+ input_buf_size = buf_size; |
|
433 |
+ |
|
434 |
+ if (s->bitstream_index + s->bitstream_size + buf_size > |
|
435 |
+ s->allocated_bitstream_size) { |
|
436 |
+ memmove(s->bitstream, &s->bitstream[s->bitstream_index], |
|
437 |
+ s->bitstream_size); |
|
438 |
+ s->bitstream_index = 0; |
|
437 | 439 |
} |
438 | 440 |
if (buf) |
439 |
- memcpy(&s->bitstream[s->bitstream_index + s->bitstream_size], buf, buf_size); |
|
440 |
- buf= &s->bitstream[s->bitstream_index]; |
|
441 |
- buf_size += s->bitstream_size; |
|
442 |
- s->bitstream_size= buf_size; |
|
441 |
+ memcpy(&s->bitstream[s->bitstream_index + s->bitstream_size], buf, |
|
442 |
+ buf_size); |
|
443 |
+ buf = &s->bitstream[s->bitstream_index]; |
|
444 |
+ buf_size += s->bitstream_size; |
|
445 |
+ s->bitstream_size = buf_size; |
|
443 | 446 |
|
444 | 447 |
/* do not decode until buffer has at least max_framesize bytes or |
445 |
- the end of the file has been reached */ |
|
448 |
+ * the end of the file has been reached */ |
|
446 | 449 |
if (buf_size < s->max_framesize && avpkt->data) { |
447 | 450 |
*got_frame_ptr = 0; |
448 | 451 |
return input_buf_size; |
449 | 452 |
} |
450 | 453 |
} |
451 | 454 |
/* init and position bitstream reader */ |
452 |
- init_get_bits(&s->gb, buf, buf_size*8); |
|
455 |
+ init_get_bits(&s->gb, buf, buf_size * 8); |
|
453 | 456 |
skip_bits(&s->gb, s->bitindex); |
454 | 457 |
|
455 | 458 |
/* process header or next subblock */ |
... | ... |
@@ -471,7 +483,7 @@ static int shorten_decode_frame(AVCodecContext *avctx, void *data, |
471 | 471 |
unsigned int cmd; |
472 | 472 |
int len; |
473 | 473 |
|
474 |
- if (get_bits_left(&s->gb) < 3+FNSIZE) { |
|
474 |
+ if (get_bits_left(&s->gb) < 3 + FNSIZE) { |
|
475 | 475 |
*got_frame_ptr = 0; |
476 | 476 |
break; |
477 | 477 |
} |
... | ... |
@@ -487,32 +499,32 @@ static int shorten_decode_frame(AVCodecContext *avctx, void *data, |
487 | 487 |
if (!is_audio_command[cmd]) { |
488 | 488 |
/* process non-audio command */ |
489 | 489 |
switch (cmd) { |
490 |
- case FN_VERBATIM: |
|
491 |
- len = get_ur_golomb_shorten(&s->gb, VERBATIM_CKSIZE_SIZE); |
|
492 |
- while (len--) { |
|
493 |
- get_ur_golomb_shorten(&s->gb, VERBATIM_BYTE_SIZE); |
|
494 |
- } |
|
495 |
- break; |
|
496 |
- case FN_BITSHIFT: |
|
497 |
- s->bitshift = get_ur_golomb_shorten(&s->gb, BITSHIFTSIZE); |
|
498 |
- break; |
|
499 |
- case FN_BLOCKSIZE: { |
|
500 |
- int blocksize = get_uint(s, av_log2(s->blocksize)); |
|
501 |
- if (blocksize > s->blocksize) { |
|
502 |
- av_log(avctx, AV_LOG_ERROR, "Increasing block size is not supported\n"); |
|
503 |
- return AVERROR_PATCHWELCOME; |
|
504 |
- } |
|
505 |
- if (!blocksize || blocksize > MAX_BLOCKSIZE) { |
|
506 |
- av_log(avctx, AV_LOG_ERROR, "invalid or unsupported " |
|
507 |
- "block size: %d\n", blocksize); |
|
508 |
- return AVERROR(EINVAL); |
|
509 |
- } |
|
510 |
- s->blocksize = blocksize; |
|
511 |
- break; |
|
490 |
+ case FN_VERBATIM: |
|
491 |
+ len = get_ur_golomb_shorten(&s->gb, VERBATIM_CKSIZE_SIZE); |
|
492 |
+ while (len--) |
|
493 |
+ get_ur_golomb_shorten(&s->gb, VERBATIM_BYTE_SIZE); |
|
494 |
+ break; |
|
495 |
+ case FN_BITSHIFT: |
|
496 |
+ s->bitshift = get_ur_golomb_shorten(&s->gb, BITSHIFTSIZE); |
|
497 |
+ break; |
|
498 |
+ case FN_BLOCKSIZE: { |
|
499 |
+ unsigned blocksize = get_uint(s, av_log2(s->blocksize)); |
|
500 |
+ if (blocksize > s->blocksize) { |
|
501 |
+ av_log(avctx, AV_LOG_ERROR, |
|
502 |
+ "Increasing block size is not supported\n"); |
|
503 |
+ return AVERROR_PATCHWELCOME; |
|
504 |
+ } |
|
505 |
+ if (!blocksize || blocksize > MAX_BLOCKSIZE) { |
|
506 |
+ av_log(avctx, AV_LOG_ERROR, "invalid or unsupported " |
|
507 |
+ "block size: %d\n", blocksize); |
|
508 |
+ return AVERROR(EINVAL); |
|
512 | 509 |
} |
513 |
- case FN_QUIT: |
|
514 |
- s->got_quit_command = 1; |
|
515 |
- break; |
|
510 |
+ s->blocksize = blocksize; |
|
511 |
+ break; |
|
512 |
+ } |
|
513 |
+ case FN_QUIT: |
|
514 |
+ s->got_quit_command = 1; |
|
515 |
+ break; |
|
516 | 516 |
} |
517 | 517 |
if (cmd == FN_BLOCKSIZE || cmd == FN_QUIT) { |
518 | 518 |
*got_frame_ptr = 0; |
... | ... |
@@ -538,7 +550,7 @@ static int shorten_decode_frame(AVCodecContext *avctx, void *data, |
538 | 538 |
coffset = s->offset[channel][0]; |
539 | 539 |
else { |
540 | 540 |
int32_t sum = (s->version < 2) ? 0 : s->nmean / 2; |
541 |
- for (i=0; i<s->nmean; i++) |
|
541 |
+ for (i = 0; i < s->nmean; i++) |
|
542 | 542 |
sum += s->offset[channel][i]; |
543 | 543 |
coffset = sum / s->nmean; |
544 | 544 |
if (s->version >= 2) |
... | ... |
@@ -547,21 +559,22 @@ static int shorten_decode_frame(AVCodecContext *avctx, void *data, |
547 | 547 |
|
548 | 548 |
/* decode samples for this channel */ |
549 | 549 |
if (cmd == FN_ZERO) { |
550 |
- for (i=0; i<s->blocksize; i++) |
|
550 |
+ for (i = 0; i < s->blocksize; i++) |
|
551 | 551 |
s->decoded[channel][i] = 0; |
552 | 552 |
} else { |
553 |
- if ((ret = decode_subframe_lpc(s, cmd, channel, residual_size, coffset)) < 0) |
|
553 |
+ if ((ret = decode_subframe_lpc(s, cmd, channel, |
|
554 |
+ residual_size, coffset)) < 0) |
|
554 | 555 |
return ret; |
555 | 556 |
} |
556 | 557 |
|
557 | 558 |
/* update means with info from the current block */ |
558 | 559 |
if (s->nmean > 0) { |
559 | 560 |
int32_t sum = (s->version < 2) ? 0 : s->blocksize / 2; |
560 |
- for (i=0; i<s->blocksize; i++) |
|
561 |
+ for (i = 0; i < s->blocksize; i++) |
|
561 | 562 |
sum += s->decoded[channel][i]; |
562 | 563 |
|
563 |
- for (i=1; i<s->nmean; i++) |
|
564 |
- s->offset[channel][i-1] = s->offset[channel][i]; |
|
564 |
+ for (i = 1; i < s->nmean; i++) |
|
565 |
+ s->offset[channel][i - 1] = s->offset[channel][i]; |
|
565 | 566 |
|
566 | 567 |
if (s->version < 2) |
567 | 568 |
s->offset[channel][s->nmean - 1] = sum / s->blocksize; |
... | ... |
@@ -570,11 +583,11 @@ static int shorten_decode_frame(AVCodecContext *avctx, void *data, |
570 | 570 |
} |
571 | 571 |
|
572 | 572 |
/* copy wrap samples for use with next block */ |
573 |
- for (i=-s->nwrap; i<0; i++) |
|
573 |
+ for (i = -s->nwrap; i < 0; i++) |
|
574 | 574 |
s->decoded[channel][i] = s->decoded[channel][i + s->blocksize]; |
575 | 575 |
|
576 | 576 |
/* shift samples to add in unused zero bits which were removed |
577 |
- during encoding */ |
|
577 |
+ * during encoding */ |
|
578 | 578 |
fix_bitshift(s, s->decoded[channel]); |
579 | 579 |
|
580 | 580 |
/* if this is the last channel in the block, output the samples */ |
... | ... |
@@ -617,12 +630,12 @@ static int shorten_decode_frame(AVCodecContext *avctx, void *data, |
617 | 617 |
*got_frame_ptr = 0; |
618 | 618 |
|
619 | 619 |
finish_frame: |
620 |
- s->bitindex = get_bits_count(&s->gb) - 8*((get_bits_count(&s->gb))/8); |
|
621 |
- i= (get_bits_count(&s->gb))/8; |
|
620 |
+ s->bitindex = get_bits_count(&s->gb) - 8 * (get_bits_count(&s->gb) / 8); |
|
621 |
+ i = get_bits_count(&s->gb) / 8; |
|
622 | 622 |
if (i > buf_size) { |
623 | 623 |
av_log(s->avctx, AV_LOG_ERROR, "overread: %d\n", i - buf_size); |
624 |
- s->bitstream_size=0; |
|
625 |
- s->bitstream_index=0; |
|
624 |
+ s->bitstream_size = 0; |
|
625 |
+ s->bitstream_index = 0; |
|
626 | 626 |
return AVERROR_INVALIDDATA; |
627 | 627 |
} |
628 | 628 |
if (s->bitstream_size) { |
... | ... |
@@ -327,12 +327,13 @@ static int filter_frame(AVFilterLink *inlink, AVFilterBufferRef *in) |
327 | 327 |
AVFilterLink *outlink = inlink->dst->outputs[0]; |
328 | 328 |
|
329 | 329 |
AVFilterBufferRef *out; |
330 |
- int direct = 0, c; |
|
330 |
+ int direct, c; |
|
331 | 331 |
|
332 | 332 |
if (in->perms & AV_PERM_WRITE) { |
333 | 333 |
direct = 1; |
334 | 334 |
out = in; |
335 | 335 |
} else { |
336 |
+ direct = 0; |
|
336 | 337 |
out = ff_get_video_buffer(outlink, AV_PERM_WRITE, outlink->w, outlink->h); |
337 | 338 |
if (!out) { |
338 | 339 |
avfilter_unref_bufferp(&in); |
... | ... |
@@ -277,11 +277,9 @@ fail: |
277 | 277 |
|
278 | 278 |
static int flac_probe(AVProbeData *p) |
279 | 279 |
{ |
280 |
- const uint8_t *bufptr = p->buf; |
|
281 |
- const uint8_t *end = p->buf + p->buf_size; |
|
282 |
- |
|
283 |
- if(bufptr > end-4 || memcmp(bufptr, "fLaC", 4)) return 0; |
|
284 |
- else return AVPROBE_SCORE_MAX/2; |
|
280 |
+ if (p->buf_size < 4 || memcmp(p->buf, "fLaC", 4)) |
|
281 |
+ return 0; |
|
282 |
+ return AVPROBE_SCORE_MAX/2; |
|
285 | 283 |
} |
286 | 284 |
|
287 | 285 |
AVInputFormat ff_flac_demuxer = { |
... | ... |
@@ -110,9 +110,8 @@ static inline void copy(LZOContext *c, int cnt) |
110 | 110 |
*/ |
111 | 111 |
static inline void copy_backptr(LZOContext *c, int back, int cnt) |
112 | 112 |
{ |
113 |
- register const uint8_t *src = &c->out[-back]; |
|
114 | 113 |
register uint8_t *dst = c->out; |
115 |
- if (src < c->out_start || src > dst) { |
|
114 |
+ if (dst - c->out_start < back) { |
|
116 | 115 |
c->error |= AV_LZO_INVALID_BACKPTR; |
117 | 116 |
return; |
118 | 117 |
} |