~siretart/libav/trusty

« back to all changes in this revision

Viewing changes to libavcodec/get_bits.h

  • Committer: Reinhard Tartler
  • Date: 2013-10-23 03:04:17 UTC
  • mfrom: (1.3.36 sid)
  • Revision ID: siretart@tauware.de-20131023030417-1o6mpkl1l0raifjt
mergeĀ fromĀ debian

Show diffs side-by-side

added added

removed removed

Lines of Context:
313
313
    }
314
314
}
315
315
 
 
316
/*
 
317
 * Read 0-64 bits.
 
318
 */
 
319
static inline uint64_t get_bits64(GetBitContext *s, int n)
 
320
{
 
321
    if (n <= 32) {
 
322
        return get_bits_long(s, n);
 
323
    } else {
 
324
#ifdef BITSTREAM_READER_LE
 
325
        uint64_t ret = get_bits_long(s, 32);
 
326
        return ret | (uint64_t)get_bits_long(s, n - 32) << 32;
 
327
#else
 
328
        uint64_t ret = (uint64_t)get_bits_long(s, n - 32) << 32;
 
329
        return ret | get_bits_long(s, 32);
 
330
#endif
 
331
    }
 
332
}
 
333
 
316
334
/**
317
335
 * Read 0-32 bits as a signed integer.
318
336
 */
344
362
}
345
363
 
346
364
/**
347
 
 * Inititalize GetBitContext.
348
 
 * @param buffer bitstream buffer, must be FF_INPUT_BUFFER_PADDING_SIZE bytes larger than the actual read bits
349
 
 * because some optimized bitstream readers read 32 or 64 bit at once and could read over the end
 
365
 * Initialize GetBitContext.
 
366
 * @param buffer bitstream buffer, must be FF_INPUT_BUFFER_PADDING_SIZE bytes
 
367
 *        larger than the actual read bits because some optimized bitstream
 
368
 *        readers read 32 or 64 bit at once and could read over the end
350
369
 * @param bit_size the size of the buffer in bits
 
370
 * @return 0 on success, AVERROR_INVALIDDATA if the buffer_size would overflow.
351
371
 */
352
 
static inline void init_get_bits(GetBitContext *s, const uint8_t *buffer,
353
 
                                 int bit_size)
 
372
static inline int init_get_bits(GetBitContext *s, const uint8_t *buffer,
 
373
                                int bit_size)
354
374
{
355
 
    int buffer_size = (bit_size+7)>>3;
356
 
    if (buffer_size < 0 || bit_size < 0) {
 
375
    int buffer_size;
 
376
    int ret = 0;
 
377
 
 
378
    if (bit_size > INT_MAX - 7 || bit_size < 0 || !buffer) {
357
379
        buffer_size = bit_size = 0;
358
380
        buffer = NULL;
 
381
        ret = AVERROR_INVALIDDATA;
359
382
    }
360
383
 
 
384
    buffer_size = (bit_size + 7) >> 3;
 
385
 
361
386
    s->buffer       = buffer;
362
387
    s->size_in_bits = bit_size;
363
388
#if !UNCHECKED_BITSTREAM_READER
365
390
#endif
366
391
    s->buffer_end   = buffer + buffer_size;
367
392
    s->index        = 0;
 
393
    return ret;
 
394
}
 
395
 
 
396
/**
 
397
 * Initialize GetBitContext.
 
398
 * @param buffer bitstream buffer, must be FF_INPUT_BUFFER_PADDING_SIZE bytes
 
399
 *        larger than the actual read bits because some optimized bitstream
 
400
 *        readers read 32 or 64 bit at once and could read over the end
 
401
 * @param byte_size the size of the buffer in bytes
 
402
 * @return 0 on success, AVERROR_INVALIDDATA if the buffer_size would overflow.
 
403
 */
 
404
static inline int init_get_bits8(GetBitContext *s, const uint8_t *buffer,
 
405
                                 int byte_size)
 
406
{
 
407
    if (byte_size > INT_MAX / 8)
 
408
        return AVERROR_INVALIDDATA;
 
409
    return init_get_bits(s, buffer, byte_size * 8);
368
410
}
369
411
 
370
412
static inline void align_get_bits(GetBitContext *s)
521
563
        av_log(NULL, AV_LOG_DEBUG, " ");
522
564
}
523
565
 
524
 
static inline int get_bits_trace(GetBitContext *s, int n, char *file,
 
566
static inline int get_bits_trace(GetBitContext *s, int n, const char *file,
525
567
                                 const char *func, int line)
526
568
{
527
569
    int r = get_bits(s, n);
532
574
    return r;
533
575
}
534
576
static inline int get_vlc_trace(GetBitContext *s, VLC_TYPE (*table)[2],
535
 
                                int bits, int max_depth, char *file,
 
577
                                int bits, int max_depth, const char *file,
536
578
                                const char *func, int line)
537
579
{
538
580
    int show  = show_bits(s, 24);
547
589
           bits2, len, r, pos, file, func, line);
548
590
    return r;
549
591
}
550
 
static inline int get_xbits_trace(GetBitContext *s, int n, char *file,
 
592
static inline int get_xbits_trace(GetBitContext *s, int n, const char *file,
551
593
                                  const char *func, int line)
552
594
{
553
595
    int show = show_bits(s, n);