| @@ -26,7 +26,7 @@ | |||||
| #include "bytestream.h" | #include "bytestream.h" | ||||
| #include "internal.h" | #include "internal.h" | ||||
| #include "get_bits.h" | #include "get_bits.h" | ||||
| #include "golomb.h" | |||||
| #include "golomb_legacy.h" | |||||
| #include "idctdsp.h" | #include "idctdsp.h" | ||||
| #include "thread.h" | #include "thread.h" | ||||
| #include "unary_legacy.h" | #include "unary_legacy.h" | ||||
| @@ -27,7 +27,7 @@ | |||||
| #include "avcodec.h" | #include "avcodec.h" | ||||
| #include "get_bits.h" | #include "get_bits.h" | ||||
| #include "golomb.h" | |||||
| #include "golomb_legacy.h" | |||||
| #include "h264chroma.h" | #include "h264chroma.h" | ||||
| #include "idctdsp.h" | #include "idctdsp.h" | ||||
| #include "internal.h" | #include "internal.h" | ||||
| @@ -27,7 +27,7 @@ | |||||
| #include "avcodec.h" | #include "avcodec.h" | ||||
| #include "get_bits.h" | #include "get_bits.h" | ||||
| #include "golomb.h" | |||||
| #include "golomb_legacy.h" | |||||
| #include "cavs.h" | #include "cavs.h" | ||||
| #include "internal.h" | #include "internal.h" | ||||
| #include "mpeg12data.h" | #include "mpeg12data.h" | ||||
| @@ -29,7 +29,7 @@ | |||||
| #include "avcodec.h" | #include "avcodec.h" | ||||
| #include "dirac.h" | #include "dirac.h" | ||||
| #include "golomb.h" | |||||
| #include "golomb_legacy.h" | |||||
| #include "internal.h" | #include "internal.h" | ||||
| #include "mpeg12data.h" | #include "mpeg12data.h" | ||||
| @@ -31,12 +31,13 @@ | |||||
| #include "libavutil/opt.h" | #include "libavutil/opt.h" | ||||
| #include "libavutil/imgutils.h" | #include "libavutil/imgutils.h" | ||||
| #include "libavutil/timer.h" | #include "libavutil/timer.h" | ||||
| #include "avcodec.h" | #include "avcodec.h" | ||||
| #include "golomb_legacy.h" | |||||
| #include "internal.h" | #include "internal.h" | ||||
| #include "get_bits.h" | #include "get_bits.h" | ||||
| #include "put_bits.h" | #include "put_bits.h" | ||||
| #include "rangecoder.h" | #include "rangecoder.h" | ||||
| #include "golomb.h" | |||||
| #include "mathops.h" | #include "mathops.h" | ||||
| #include "ffv1.h" | #include "ffv1.h" | ||||
| @@ -33,10 +33,10 @@ | |||||
| #include "libavutil/imgutils.h" | #include "libavutil/imgutils.h" | ||||
| #include "avcodec.h" | #include "avcodec.h" | ||||
| #include "golomb_legacy.h" | |||||
| #include "internal.h" | #include "internal.h" | ||||
| #include "put_bits.h" | #include "put_bits.h" | ||||
| #include "rangecoder.h" | #include "rangecoder.h" | ||||
| #include "golomb.h" | |||||
| #include "mathops.h" | #include "mathops.h" | ||||
| #include "ffv1.h" | #include "ffv1.h" | ||||
| @@ -22,10 +22,11 @@ | |||||
| */ | */ | ||||
| #include "libavutil/common.h" | #include "libavutil/common.h" | ||||
| #include "avcodec.h" | #include "avcodec.h" | ||||
| #include "golomb_legacy.h" | |||||
| #include "internal.h" | #include "internal.h" | ||||
| #include "get_bits.h" | #include "get_bits.h" | ||||
| #include "golomb.h" | |||||
| typedef struct FICThreadContext { | typedef struct FICThreadContext { | ||||
| DECLARE_ALIGNED(16, int16_t, block)[64]; | DECLARE_ALIGNED(16, int16_t, block)[64]; | ||||
| @@ -37,7 +37,7 @@ | |||||
| #include "internal.h" | #include "internal.h" | ||||
| #include "get_bits.h" | #include "get_bits.h" | ||||
| #include "bytestream.h" | #include "bytestream.h" | ||||
| #include "golomb.h" | |||||
| #include "golomb_legacy.h" | |||||
| #include "flac.h" | #include "flac.h" | ||||
| #include "flacdata.h" | #include "flacdata.h" | ||||
| #include "flacdsp.h" | #include "flacdsp.h" | ||||
| @@ -26,7 +26,7 @@ | |||||
| #include "avcodec.h" | #include "avcodec.h" | ||||
| #include "bswapdsp.h" | #include "bswapdsp.h" | ||||
| #include "golomb.h" | |||||
| #include "golomb_legacy.h" | |||||
| #include "internal.h" | #include "internal.h" | ||||
| #include "lpc.h" | #include "lpc.h" | ||||
| #include "flac.h" | #include "flac.h" | ||||
| @@ -32,7 +32,7 @@ | |||||
| #include <stdint.h> | #include <stdint.h> | ||||
| #include "get_bits.h" | |||||
| #include "bitstream.h" | |||||
| #include "put_bits.h" | #include "put_bits.h" | ||||
| #define INVALID_VLC 0x80000000 | #define INVALID_VLC 0x80000000 | ||||
| @@ -50,26 +50,22 @@ extern const uint8_t ff_interleaved_dirac_golomb_vlc_code[256]; | |||||
| /** | /** | ||||
| * read unsigned exp golomb code. | * read unsigned exp golomb code. | ||||
| */ | */ | ||||
| static inline int get_ue_golomb(GetBitContext *gb) | |||||
| static inline int get_ue_golomb(BitstreamContext *bc) | |||||
| { | { | ||||
| unsigned int buf; | unsigned int buf; | ||||
| OPEN_READER(re, gb); | |||||
| UPDATE_CACHE(re, gb); | |||||
| buf = GET_CACHE(re, gb); | |||||
| buf = bitstream_peek(bc, 32); | |||||
| if (buf >= (1 << 27)) { | if (buf >= (1 << 27)) { | ||||
| buf >>= 32 - 9; | buf >>= 32 - 9; | ||||
| LAST_SKIP_BITS(re, gb, ff_golomb_vlc_len[buf]); | |||||
| CLOSE_READER(re, gb); | |||||
| bitstream_skip(bc, ff_golomb_vlc_len[buf]); | |||||
| return ff_ue_golomb_vlc_code[buf]; | return ff_ue_golomb_vlc_code[buf]; | ||||
| } else { | } else { | ||||
| int log = 2 * av_log2(buf) - 31; | int log = 2 * av_log2(buf) - 31; | ||||
| buf >>= log; | buf >>= log; | ||||
| buf--; | buf--; | ||||
| LAST_SKIP_BITS(re, gb, 32 - log); | |||||
| CLOSE_READER(re, gb); | |||||
| bitstream_skip(bc, 32 - log); | |||||
| return buf; | return buf; | ||||
| } | } | ||||
| @@ -78,48 +74,42 @@ static inline int get_ue_golomb(GetBitContext *gb) | |||||
| /** | /** | ||||
| * Read an unsigned Exp-Golomb code in the range 0 to UINT32_MAX-1. | * Read an unsigned Exp-Golomb code in the range 0 to UINT32_MAX-1. | ||||
| */ | */ | ||||
| static inline unsigned get_ue_golomb_long(GetBitContext *gb) | |||||
| static inline unsigned get_ue_golomb_long(BitstreamContext *bc) | |||||
| { | { | ||||
| unsigned buf, log; | unsigned buf, log; | ||||
| buf = show_bits_long(gb, 32); | |||||
| buf = bitstream_peek(bc, 32); | |||||
| log = 31 - av_log2(buf); | log = 31 - av_log2(buf); | ||||
| skip_bits_long(gb, log); | |||||
| bitstream_skip(bc, log); | |||||
| return get_bits_long(gb, log + 1) - 1; | |||||
| return bitstream_read(bc, log + 1) - 1; | |||||
| } | } | ||||
| /** | /** | ||||
| * read unsigned exp golomb code, constraint to a max of 31. | * read unsigned exp golomb code, constraint to a max of 31. | ||||
| * the return value is undefined if the stored value exceeds 31. | * the return value is undefined if the stored value exceeds 31. | ||||
| */ | */ | ||||
| static inline int get_ue_golomb_31(GetBitContext *gb) | |||||
| static inline int get_ue_golomb_31(BitstreamContext *bc) | |||||
| { | { | ||||
| unsigned int buf; | unsigned int buf; | ||||
| OPEN_READER(re, gb); | |||||
| UPDATE_CACHE(re, gb); | |||||
| buf = GET_CACHE(re, gb); | |||||
| buf = bitstream_peek(bc, 32); | |||||
| buf >>= 32 - 9; | buf >>= 32 - 9; | ||||
| LAST_SKIP_BITS(re, gb, ff_golomb_vlc_len[buf]); | |||||
| CLOSE_READER(re, gb); | |||||
| bitstream_skip(bc, ff_golomb_vlc_len[buf]); | |||||
| return ff_ue_golomb_vlc_code[buf]; | return ff_ue_golomb_vlc_code[buf]; | ||||
| } | } | ||||
| static inline unsigned get_interleaved_ue_golomb(GetBitContext *gb) | |||||
| static inline unsigned get_interleaved_ue_golomb(BitstreamContext *bc) | |||||
| { | { | ||||
| uint32_t buf; | uint32_t buf; | ||||
| OPEN_READER(re, gb); | |||||
| UPDATE_CACHE(re, gb); | |||||
| buf = GET_CACHE(re, gb); | |||||
| buf = bitstream_peek(bc, 32); | |||||
| if (buf & 0xAA800000) { | if (buf & 0xAA800000) { | ||||
| buf >>= 32 - 8; | buf >>= 32 - 8; | ||||
| LAST_SKIP_BITS(re, gb, ff_interleaved_golomb_vlc_len[buf]); | |||||
| CLOSE_READER(re, gb); | |||||
| bitstream_skip(bc, ff_interleaved_golomb_vlc_len[buf]); | |||||
| return ff_interleaved_ue_golomb_vlc_code[buf]; | return ff_interleaved_ue_golomb_vlc_code[buf]; | ||||
| } else { | } else { | ||||
| @@ -127,8 +117,7 @@ static inline unsigned get_interleaved_ue_golomb(GetBitContext *gb) | |||||
| do { | do { | ||||
| buf >>= 32 - 8; | buf >>= 32 - 8; | ||||
| LAST_SKIP_BITS(re, gb, | |||||
| FFMIN(ff_interleaved_golomb_vlc_len[buf], 8)); | |||||
| bitstream_skip(bc, FFMIN(ff_interleaved_golomb_vlc_len[buf], 8)); | |||||
| if (ff_interleaved_golomb_vlc_len[buf] != 9) { | if (ff_interleaved_golomb_vlc_len[buf] != 9) { | ||||
| ret <<= (ff_interleaved_golomb_vlc_len[buf] - 1) >> 1; | ret <<= (ff_interleaved_golomb_vlc_len[buf] - 1) >> 1; | ||||
| @@ -136,11 +125,9 @@ static inline unsigned get_interleaved_ue_golomb(GetBitContext *gb) | |||||
| break; | break; | ||||
| } | } | ||||
| ret = (ret << 4) | ff_interleaved_dirac_golomb_vlc_code[buf]; | ret = (ret << 4) | ff_interleaved_dirac_golomb_vlc_code[buf]; | ||||
| UPDATE_CACHE(re, gb); | |||||
| buf = GET_CACHE(re, gb); | |||||
| } while (BITS_AVAILABLE(re, gb)); | |||||
| buf = bitstream_peek(bc, 32); | |||||
| } while (bitstream_bits_left(bc) > 0); | |||||
| CLOSE_READER(re, gb); | |||||
| return ret - 1; | return ret - 1; | ||||
| } | } | ||||
| } | } | ||||
| @@ -148,54 +135,50 @@ static inline unsigned get_interleaved_ue_golomb(GetBitContext *gb) | |||||
| /** | /** | ||||
| * read unsigned truncated exp golomb code. | * read unsigned truncated exp golomb code. | ||||
| */ | */ | ||||
| static inline int get_te0_golomb(GetBitContext *gb, int range) | |||||
| static inline int get_te0_golomb(BitstreamContext *bc, int range) | |||||
| { | { | ||||
| assert(range >= 1); | assert(range >= 1); | ||||
| if (range == 1) | if (range == 1) | ||||
| return 0; | return 0; | ||||
| else if (range == 2) | else if (range == 2) | ||||
| return get_bits1(gb) ^ 1; | |||||
| return bitstream_read_bit(bc) ^ 1; | |||||
| else | else | ||||
| return get_ue_golomb(gb); | |||||
| return get_ue_golomb(bc); | |||||
| } | } | ||||
| /** | /** | ||||
| * read unsigned truncated exp golomb code. | * read unsigned truncated exp golomb code. | ||||
| */ | */ | ||||
| static inline int get_te_golomb(GetBitContext *gb, int range) | |||||
| static inline int get_te_golomb(BitstreamContext *bc, int range) | |||||
| { | { | ||||
| assert(range >= 1); | assert(range >= 1); | ||||
| if (range == 2) | if (range == 2) | ||||
| return get_bits1(gb) ^ 1; | |||||
| return bitstream_read_bit(bc) ^ 1; | |||||
| else | else | ||||
| return get_ue_golomb(gb); | |||||
| return get_ue_golomb(bc); | |||||
| } | } | ||||
| /** | /** | ||||
| * read signed exp golomb code. | * read signed exp golomb code. | ||||
| */ | */ | ||||
| static inline int get_se_golomb(GetBitContext *gb) | |||||
| static inline int get_se_golomb(BitstreamContext *bc) | |||||
| { | { | ||||
| unsigned int buf; | unsigned int buf; | ||||
| OPEN_READER(re, gb); | |||||
| UPDATE_CACHE(re, gb); | |||||
| buf = GET_CACHE(re, gb); | |||||
| buf = bitstream_peek(bc, 32); | |||||
| if (buf >= (1 << 27)) { | if (buf >= (1 << 27)) { | ||||
| buf >>= 32 - 9; | buf >>= 32 - 9; | ||||
| LAST_SKIP_BITS(re, gb, ff_golomb_vlc_len[buf]); | |||||
| CLOSE_READER(re, gb); | |||||
| bitstream_skip(bc, ff_golomb_vlc_len[buf]); | |||||
| return ff_se_golomb_vlc_code[buf]; | return ff_se_golomb_vlc_code[buf]; | ||||
| } else { | } else { | ||||
| int log = 2 * av_log2(buf) - 31; | int log = 2 * av_log2(buf) - 31; | ||||
| buf >>= log; | buf >>= log; | ||||
| LAST_SKIP_BITS(re, gb, 32 - log); | |||||
| CLOSE_READER(re, gb); | |||||
| bitstream_skip(bc, 32 - log); | |||||
| if (buf & 1) | if (buf & 1) | ||||
| buf = -(buf >> 1); | buf = -(buf >> 1); | ||||
| @@ -206,9 +189,9 @@ static inline int get_se_golomb(GetBitContext *gb) | |||||
| } | } | ||||
| } | } | ||||
| static inline int get_se_golomb_long(GetBitContext *gb) | |||||
| static inline int get_se_golomb_long(BitstreamContext *bc) | |||||
| { | { | ||||
| unsigned int buf = get_ue_golomb_long(gb); | |||||
| unsigned int buf = get_ue_golomb_long(bc); | |||||
| if (buf & 1) | if (buf & 1) | ||||
| buf = (buf + 1) >> 1; | buf = (buf + 1) >> 1; | ||||
| @@ -218,25 +201,21 @@ static inline int get_se_golomb_long(GetBitContext *gb) | |||||
| return buf; | return buf; | ||||
| } | } | ||||
| static inline int get_interleaved_se_golomb(GetBitContext *gb) | |||||
| static inline int get_interleaved_se_golomb(BitstreamContext *bc) | |||||
| { | { | ||||
| unsigned int buf; | unsigned int buf; | ||||
| OPEN_READER(re, gb); | |||||
| UPDATE_CACHE(re, gb); | |||||
| buf = GET_CACHE(re, gb); | |||||
| buf = bitstream_peek(bc, 32); | |||||
| if (buf & 0xAA800000) { | if (buf & 0xAA800000) { | ||||
| buf >>= 32 - 8; | buf >>= 32 - 8; | ||||
| LAST_SKIP_BITS(re, gb, ff_interleaved_golomb_vlc_len[buf]); | |||||
| CLOSE_READER(re, gb); | |||||
| bitstream_skip(bc, ff_interleaved_golomb_vlc_len[buf]); | |||||
| return ff_interleaved_se_golomb_vlc_code[buf]; | return ff_interleaved_se_golomb_vlc_code[buf]; | ||||
| } else { | } else { | ||||
| int log; | int log; | ||||
| LAST_SKIP_BITS(re, gb, 8); | |||||
| UPDATE_CACHE(re, gb); | |||||
| buf |= 1 | (GET_CACHE(re, gb) >> 8); | |||||
| bitstream_skip(bc, 8); | |||||
| buf |= 1 | bitstream_peek(bc, 24); | |||||
| if ((buf & 0xAAAAAAAA) == 0) | if ((buf & 0xAAAAAAAA) == 0) | ||||
| return INVALID_VLC; | return INVALID_VLC; | ||||
| @@ -244,25 +223,20 @@ static inline int get_interleaved_se_golomb(GetBitContext *gb) | |||||
| for (log = 31; (buf & 0x80000000) == 0; log--) | for (log = 31; (buf & 0x80000000) == 0; log--) | ||||
| buf = (buf << 2) - ((buf << log) >> (log - 1)) + (buf >> 30); | buf = (buf << 2) - ((buf << log) >> (log - 1)) + (buf >> 30); | ||||
| LAST_SKIP_BITS(re, gb, 63 - 2 * log - 8); | |||||
| CLOSE_READER(re, gb); | |||||
| bitstream_skip(bc, 63 - 2 * log - 8); | |||||
| return (signed) (((((buf << log) >> log) - 1) ^ -(buf & 0x1)) + 1) >> 1; | return (signed) (((((buf << log) >> log) - 1) ^ -(buf & 0x1)) + 1) >> 1; | ||||
| } | } | ||||
| } | } | ||||
| static inline int dirac_get_se_golomb(GetBitContext *gb) | |||||
| static inline int dirac_get_se_golomb(BitstreamContext *bc) | |||||
| { | { | ||||
| uint32_t ret = get_interleaved_ue_golomb(gb); | |||||
| uint32_t ret = get_interleaved_ue_golomb(bc); | |||||
| if (ret) { | if (ret) { | ||||
| uint32_t buf; | uint32_t buf; | ||||
| OPEN_READER(re, gb); | |||||
| UPDATE_CACHE(re, gb); | |||||
| buf = SHOW_SBITS(re, gb, 1); | |||||
| LAST_SKIP_BITS(re, gb, 1); | |||||
| buf = bitstream_read_signed(bc, 1); | |||||
| ret = (ret ^ buf) - buf; | ret = (ret ^ buf) - buf; | ||||
| CLOSE_READER(re, gb); | |||||
| } | } | ||||
| return ret; | return ret; | ||||
| @@ -271,33 +245,25 @@ static inline int dirac_get_se_golomb(GetBitContext *gb) | |||||
| /** | /** | ||||
| * read unsigned golomb rice code (ffv1). | * read unsigned golomb rice code (ffv1). | ||||
| */ | */ | ||||
| static inline int get_ur_golomb(GetBitContext *gb, int k, int limit, | |||||
| static inline int get_ur_golomb(BitstreamContext *bc, int k, int limit, | |||||
| int esc_len) | int esc_len) | ||||
| { | { | ||||
| unsigned int buf; | unsigned int buf; | ||||
| int log; | int log; | ||||
| OPEN_READER(re, gb); | |||||
| UPDATE_CACHE(re, gb); | |||||
| buf = GET_CACHE(re, gb); | |||||
| buf = bitstream_peek(bc, 32); | |||||
| log = av_log2(buf); | log = av_log2(buf); | ||||
| if (log > 31 - limit) { | if (log > 31 - limit) { | ||||
| buf >>= log - k; | buf >>= log - k; | ||||
| buf += (30 - log) << k; | buf += (30 - log) << k; | ||||
| LAST_SKIP_BITS(re, gb, 32 + k - log); | |||||
| CLOSE_READER(re, gb); | |||||
| bitstream_skip(bc, 32 + k - log); | |||||
| return buf; | return buf; | ||||
| } else { | } else { | ||||
| LAST_SKIP_BITS(re, gb, limit); | |||||
| UPDATE_CACHE(re, gb); | |||||
| buf = SHOW_UBITS(re, gb, esc_len); | |||||
| LAST_SKIP_BITS(re, gb, esc_len); | |||||
| CLOSE_READER(re, gb); | |||||
| bitstream_skip(bc, limit); | |||||
| buf = bitstream_read(bc, esc_len); | |||||
| return buf + limit - 1; | return buf + limit - 1; | ||||
| } | } | ||||
| @@ -306,48 +272,38 @@ static inline int get_ur_golomb(GetBitContext *gb, int k, int limit, | |||||
| /** | /** | ||||
| * read unsigned golomb rice code (jpegls). | * read unsigned golomb rice code (jpegls). | ||||
| */ | */ | ||||
| static inline int get_ur_golomb_jpegls(GetBitContext *gb, int k, int limit, | |||||
| static inline int get_ur_golomb_jpegls(BitstreamContext *bc, int k, int limit, | |||||
| int esc_len) | int esc_len) | ||||
| { | { | ||||
| unsigned int buf; | unsigned int buf; | ||||
| int log; | int log; | ||||
| OPEN_READER(re, gb); | |||||
| UPDATE_CACHE(re, gb); | |||||
| buf = GET_CACHE(re, gb); | |||||
| buf = bitstream_peek(bc, 32); | |||||
| log = av_log2(buf); | log = av_log2(buf); | ||||
| if (log - k >= 32 - MIN_CACHE_BITS + (MIN_CACHE_BITS == 32) && | |||||
| 32 - log < limit) { | |||||
| if (log - k >= 1 && 32 - log < limit) { | |||||
| buf >>= log - k; | buf >>= log - k; | ||||
| buf += (30 - log) << k; | buf += (30 - log) << k; | ||||
| LAST_SKIP_BITS(re, gb, 32 + k - log); | |||||
| CLOSE_READER(re, gb); | |||||
| bitstream_skip(bc, 32 + k - log); | |||||
| return buf; | return buf; | ||||
| } else { | } else { | ||||
| int i; | int i; | ||||
| for (i = 0; i < limit && SHOW_UBITS(re, gb, 1) == 0 && BITS_AVAILABLE(re, gb); i++) { | |||||
| LAST_SKIP_BITS(re, gb, 1); | |||||
| UPDATE_CACHE(re, gb); | |||||
| } | |||||
| SKIP_BITS(re, gb, 1); | |||||
| for (i = 0; i < limit && bitstream_peek(bc, 1) == 0 && bitstream_bits_left(bc) > 0; i++) | |||||
| bitstream_skip(bc, 1); | |||||
| bitstream_skip(bc, 1); | |||||
| if (i < limit - 1) { | if (i < limit - 1) { | ||||
| if (k) { | if (k) { | ||||
| buf = SHOW_UBITS(re, gb, k); | |||||
| LAST_SKIP_BITS(re, gb, k); | |||||
| buf = bitstream_read(bc, k); | |||||
| } else { | } else { | ||||
| buf = 0; | buf = 0; | ||||
| } | } | ||||
| CLOSE_READER(re, gb); | |||||
| return buf + (i << k); | return buf + (i << k); | ||||
| } else if (i == limit - 1) { | } else if (i == limit - 1) { | ||||
| buf = SHOW_UBITS(re, gb, esc_len); | |||||
| LAST_SKIP_BITS(re, gb, esc_len); | |||||
| CLOSE_READER(re, gb); | |||||
| buf = bitstream_read(bc, esc_len); | |||||
| return buf + 1; | return buf + 1; | ||||
| } else | } else | ||||
| @@ -358,10 +314,10 @@ static inline int get_ur_golomb_jpegls(GetBitContext *gb, int k, int limit, | |||||
| /** | /** | ||||
| * read signed golomb rice code (ffv1). | * read signed golomb rice code (ffv1). | ||||
| */ | */ | ||||
| static inline int get_sr_golomb(GetBitContext *gb, int k, int limit, | |||||
| static inline int get_sr_golomb(BitstreamContext *bc, int k, int limit, | |||||
| int esc_len) | int esc_len) | ||||
| { | { | ||||
| int v = get_ur_golomb(gb, k, limit, esc_len); | |||||
| int v = get_ur_golomb(bc, k, limit, esc_len); | |||||
| v++; | v++; | ||||
| if (v & 1) | if (v & 1) | ||||
| @@ -375,27 +331,27 @@ static inline int get_sr_golomb(GetBitContext *gb, int k, int limit, | |||||
| /** | /** | ||||
| * read signed golomb rice code (flac). | * read signed golomb rice code (flac). | ||||
| */ | */ | ||||
| static inline int get_sr_golomb_flac(GetBitContext *gb, int k, int limit, | |||||
| static inline int get_sr_golomb_flac(BitstreamContext *bc, int k, int limit, | |||||
| int esc_len) | int esc_len) | ||||
| { | { | ||||
| int v = get_ur_golomb_jpegls(gb, k, limit, esc_len); | |||||
| int v = get_ur_golomb_jpegls(bc, k, limit, esc_len); | |||||
| return (v >> 1) ^ -(v & 1); | return (v >> 1) ^ -(v & 1); | ||||
| } | } | ||||
| /** | /** | ||||
| * read unsigned golomb rice code (shorten). | * read unsigned golomb rice code (shorten). | ||||
| */ | */ | ||||
| static inline unsigned int get_ur_golomb_shorten(GetBitContext *gb, int k) | |||||
| static inline unsigned int get_ur_golomb_shorten(BitstreamContext *bc, int k) | |||||
| { | { | ||||
| return get_ur_golomb_jpegls(gb, k, INT_MAX, 0); | |||||
| return get_ur_golomb_jpegls(bc, k, INT_MAX, 0); | |||||
| } | } | ||||
| /** | /** | ||||
| * read signed golomb rice code (shorten). | * read signed golomb rice code (shorten). | ||||
| */ | */ | ||||
| static inline int get_sr_golomb_shorten(GetBitContext *gb, int k) | |||||
| static inline int get_sr_golomb_shorten(BitstreamContext *bc, int k) | |||||
| { | { | ||||
| int uvar = get_ur_golomb_jpegls(gb, k + 1, INT_MAX, 0); | |||||
| int uvar = get_ur_golomb_jpegls(bc, k + 1, INT_MAX, 0); | |||||
| if (uvar & 1) | if (uvar & 1) | ||||
| return ~(uvar >> 1); | return ~(uvar >> 1); | ||||
| else | else | ||||
| @@ -404,13 +360,13 @@ static inline int get_sr_golomb_shorten(GetBitContext *gb, int k) | |||||
| #ifdef TRACE | #ifdef TRACE | ||||
| static inline int get_ue(GetBitContext *s, const char *file, const char *func, | |||||
| static inline int get_ue(BitstreamContext *s, const char *file, const char *func, | |||||
| int line) | int line) | ||||
| { | { | ||||
| int show = show_bits(s, 24); | |||||
| int pos = get_bits_count(s); | |||||
| int show = bitstream_peek(s, 24); | |||||
| int pos = bitstream_tell(s); | |||||
| int i = get_ue_golomb(s); | int i = get_ue_golomb(s); | ||||
| int len = get_bits_count(s) - pos; | |||||
| int len = bitstream_tell(s) - pos; | |||||
| int bits = show >> (24 - len); | int bits = show >> (24 - len); | ||||
| av_log(NULL, AV_LOG_DEBUG, "%5d %2d %3d ue @%5d in %s %s:%d\n", | av_log(NULL, AV_LOG_DEBUG, "%5d %2d %3d ue @%5d in %s %s:%d\n", | ||||
| @@ -419,13 +375,13 @@ static inline int get_ue(GetBitContext *s, const char *file, const char *func, | |||||
| return i; | return i; | ||||
| } | } | ||||
| static inline int get_se(GetBitContext *s, const char *file, const char *func, | |||||
| static inline int get_se(BitstreamContext *s, const char *file, const char *func, | |||||
| int line) | int line) | ||||
| { | { | ||||
| int show = show_bits(s, 24); | |||||
| int pos = get_bits_count(s); | |||||
| int show = bitstream_peek(s, 24); | |||||
| int pos = bitstream_tell(s); | |||||
| int i = get_se_golomb(s); | int i = get_se_golomb(s); | ||||
| int len = get_bits_count(s) - pos; | |||||
| int len = bitstream_tell(s) - pos; | |||||
| int bits = show >> (24 - len); | int bits = show >> (24 - len); | ||||
| av_log(NULL, AV_LOG_DEBUG, "%5d %2d %3d se @%5d in %s %s:%d\n", | av_log(NULL, AV_LOG_DEBUG, "%5d %2d %3d se @%5d in %s %s:%d\n", | ||||
| @@ -434,13 +390,13 @@ static inline int get_se(GetBitContext *s, const char *file, const char *func, | |||||
| return i; | return i; | ||||
| } | } | ||||
| static inline int get_te(GetBitContext *s, int r, char *file, const char *func, | |||||
| static inline int get_te(BitstreamContext *s, int r, char *file, const char *func, | |||||
| int line) | int line) | ||||
| { | { | ||||
| int show = show_bits(s, 24); | |||||
| int pos = get_bits_count(s); | |||||
| int show = bitstream_peek(s, 24); | |||||
| int pos = bitstream_tell(s); | |||||
| int i = get_te0_golomb(s, r); | int i = get_te0_golomb(s, r); | ||||
| int len = get_bits_count(s) - pos; | |||||
| int len = bitstream_tell(s) - pos; | |||||
| int bits = show >> (24 - len); | int bits = show >> (24 - len); | ||||
| av_log(NULL, AV_LOG_DEBUG, "%5d %2d %3d te @%5d in %s %s:%d\n", | av_log(NULL, AV_LOG_DEBUG, "%5d %2d %3d te @%5d in %s %s:%d\n", | ||||
| @@ -0,0 +1,573 @@ | |||||
| /* | |||||
| * exp golomb vlc stuff | |||||
| * Copyright (c) 2003 Michael Niedermayer <michaelni@gmx.at> | |||||
| * Copyright (c) 2004 Alex Beregszaszi | |||||
| * | |||||
| * This file is part of Libav. | |||||
| * | |||||
| * Libav is free software; you can redistribute it and/or | |||||
| * modify it under the terms of the GNU Lesser General Public | |||||
| * License as published by the Free Software Foundation; either | |||||
| * version 2.1 of the License, or (at your option) any later version. | |||||
| * | |||||
| * Libav is distributed in the hope that it will be useful, | |||||
| * but WITHOUT ANY WARRANTY; without even the implied warranty of | |||||
| * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |||||
| * Lesser General Public License for more details. | |||||
| * | |||||
| * You should have received a copy of the GNU Lesser General Public | |||||
| * License along with Libav; if not, write to the Free Software | |||||
| * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | |||||
| */ | |||||
| /** | |||||
| * @file | |||||
| * @brief | |||||
| * exp golomb vlc stuff | |||||
| * @author Michael Niedermayer <michaelni@gmx.at> and Alex Beregszaszi | |||||
| */ | |||||
| #ifndef AVCODEC_GOLOMB_H | |||||
| #define AVCODEC_GOLOMB_H | |||||
| #include <stdint.h> | |||||
| #include "get_bits.h" | |||||
| #include "put_bits.h" | |||||
| #define INVALID_VLC 0x80000000 | |||||
| extern const uint8_t ff_golomb_vlc_len[512]; | |||||
| extern const uint8_t ff_ue_golomb_vlc_code[512]; | |||||
| extern const int8_t ff_se_golomb_vlc_code[512]; | |||||
| extern const uint8_t ff_ue_golomb_len[256]; | |||||
| extern const uint8_t ff_interleaved_golomb_vlc_len[256]; | |||||
| extern const uint8_t ff_interleaved_ue_golomb_vlc_code[256]; | |||||
| extern const int8_t ff_interleaved_se_golomb_vlc_code[256]; | |||||
| extern const uint8_t ff_interleaved_dirac_golomb_vlc_code[256]; | |||||
| /** | |||||
| * read unsigned exp golomb code. | |||||
| */ | |||||
| static inline int get_ue_golomb(GetBitContext *gb) | |||||
| { | |||||
| unsigned int buf; | |||||
| OPEN_READER(re, gb); | |||||
| UPDATE_CACHE(re, gb); | |||||
| buf = GET_CACHE(re, gb); | |||||
| if (buf >= (1 << 27)) { | |||||
| buf >>= 32 - 9; | |||||
| LAST_SKIP_BITS(re, gb, ff_golomb_vlc_len[buf]); | |||||
| CLOSE_READER(re, gb); | |||||
| return ff_ue_golomb_vlc_code[buf]; | |||||
| } else { | |||||
| int log = 2 * av_log2(buf) - 31; | |||||
| buf >>= log; | |||||
| buf--; | |||||
| LAST_SKIP_BITS(re, gb, 32 - log); | |||||
| CLOSE_READER(re, gb); | |||||
| return buf; | |||||
| } | |||||
| } | |||||
| /** | |||||
| * Read an unsigned Exp-Golomb code in the range 0 to UINT32_MAX-1. | |||||
| */ | |||||
| static inline unsigned get_ue_golomb_long(GetBitContext *gb) | |||||
| { | |||||
| unsigned buf, log; | |||||
| buf = show_bits_long(gb, 32); | |||||
| log = 31 - av_log2(buf); | |||||
| skip_bits_long(gb, log); | |||||
| return get_bits_long(gb, log + 1) - 1; | |||||
| } | |||||
| /** | |||||
| * read unsigned exp golomb code, constraint to a max of 31. | |||||
| * the return value is undefined if the stored value exceeds 31. | |||||
| */ | |||||
| static inline int get_ue_golomb_31(GetBitContext *gb) | |||||
| { | |||||
| unsigned int buf; | |||||
| OPEN_READER(re, gb); | |||||
| UPDATE_CACHE(re, gb); | |||||
| buf = GET_CACHE(re, gb); | |||||
| buf >>= 32 - 9; | |||||
| LAST_SKIP_BITS(re, gb, ff_golomb_vlc_len[buf]); | |||||
| CLOSE_READER(re, gb); | |||||
| return ff_ue_golomb_vlc_code[buf]; | |||||
| } | |||||
| static inline unsigned get_interleaved_ue_golomb(GetBitContext *gb) | |||||
| { | |||||
| uint32_t buf; | |||||
| OPEN_READER(re, gb); | |||||
| UPDATE_CACHE(re, gb); | |||||
| buf = GET_CACHE(re, gb); | |||||
| if (buf & 0xAA800000) { | |||||
| buf >>= 32 - 8; | |||||
| LAST_SKIP_BITS(re, gb, ff_interleaved_golomb_vlc_len[buf]); | |||||
| CLOSE_READER(re, gb); | |||||
| return ff_interleaved_ue_golomb_vlc_code[buf]; | |||||
| } else { | |||||
| unsigned ret = 1; | |||||
| do { | |||||
| buf >>= 32 - 8; | |||||
| LAST_SKIP_BITS(re, gb, | |||||
| FFMIN(ff_interleaved_golomb_vlc_len[buf], 8)); | |||||
| if (ff_interleaved_golomb_vlc_len[buf] != 9) { | |||||
| ret <<= (ff_interleaved_golomb_vlc_len[buf] - 1) >> 1; | |||||
| ret |= ff_interleaved_dirac_golomb_vlc_code[buf]; | |||||
| break; | |||||
| } | |||||
| ret = (ret << 4) | ff_interleaved_dirac_golomb_vlc_code[buf]; | |||||
| UPDATE_CACHE(re, gb); | |||||
| buf = GET_CACHE(re, gb); | |||||
| } while (BITS_AVAILABLE(re, gb)); | |||||
| CLOSE_READER(re, gb); | |||||
| return ret - 1; | |||||
| } | |||||
| } | |||||
| /** | |||||
| * read unsigned truncated exp golomb code. | |||||
| */ | |||||
| static inline int get_te0_golomb(GetBitContext *gb, int range) | |||||
| { | |||||
| assert(range >= 1); | |||||
| if (range == 1) | |||||
| return 0; | |||||
| else if (range == 2) | |||||
| return get_bits1(gb) ^ 1; | |||||
| else | |||||
| return get_ue_golomb(gb); | |||||
| } | |||||
| /** | |||||
| * read unsigned truncated exp golomb code. | |||||
| */ | |||||
| static inline int get_te_golomb(GetBitContext *gb, int range) | |||||
| { | |||||
| assert(range >= 1); | |||||
| if (range == 2) | |||||
| return get_bits1(gb) ^ 1; | |||||
| else | |||||
| return get_ue_golomb(gb); | |||||
| } | |||||
| /** | |||||
| * read signed exp golomb code. | |||||
| */ | |||||
| static inline int get_se_golomb(GetBitContext *gb) | |||||
| { | |||||
| unsigned int buf; | |||||
| OPEN_READER(re, gb); | |||||
| UPDATE_CACHE(re, gb); | |||||
| buf = GET_CACHE(re, gb); | |||||
| if (buf >= (1 << 27)) { | |||||
| buf >>= 32 - 9; | |||||
| LAST_SKIP_BITS(re, gb, ff_golomb_vlc_len[buf]); | |||||
| CLOSE_READER(re, gb); | |||||
| return ff_se_golomb_vlc_code[buf]; | |||||
| } else { | |||||
| int log = 2 * av_log2(buf) - 31; | |||||
| buf >>= log; | |||||
| LAST_SKIP_BITS(re, gb, 32 - log); | |||||
| CLOSE_READER(re, gb); | |||||
| if (buf & 1) | |||||
| buf = -(buf >> 1); | |||||
| else | |||||
| buf = (buf >> 1); | |||||
| return buf; | |||||
| } | |||||
| } | |||||
| static inline int get_se_golomb_long(GetBitContext *gb) | |||||
| { | |||||
| unsigned int buf = get_ue_golomb_long(gb); | |||||
| if (buf & 1) | |||||
| buf = (buf + 1) >> 1; | |||||
| else | |||||
| buf = -(buf >> 1); | |||||
| return buf; | |||||
| } | |||||
| static inline int get_interleaved_se_golomb(GetBitContext *gb) | |||||
| { | |||||
| unsigned int buf; | |||||
| OPEN_READER(re, gb); | |||||
| UPDATE_CACHE(re, gb); | |||||
| buf = GET_CACHE(re, gb); | |||||
| if (buf & 0xAA800000) { | |||||
| buf >>= 32 - 8; | |||||
| LAST_SKIP_BITS(re, gb, ff_interleaved_golomb_vlc_len[buf]); | |||||
| CLOSE_READER(re, gb); | |||||
| return ff_interleaved_se_golomb_vlc_code[buf]; | |||||
| } else { | |||||
| int log; | |||||
| LAST_SKIP_BITS(re, gb, 8); | |||||
| UPDATE_CACHE(re, gb); | |||||
| buf |= 1 | (GET_CACHE(re, gb) >> 8); | |||||
| if ((buf & 0xAAAAAAAA) == 0) | |||||
| return INVALID_VLC; | |||||
| for (log = 31; (buf & 0x80000000) == 0; log--) | |||||
| buf = (buf << 2) - ((buf << log) >> (log - 1)) + (buf >> 30); | |||||
| LAST_SKIP_BITS(re, gb, 63 - 2 * log - 8); | |||||
| CLOSE_READER(re, gb); | |||||
| return (signed) (((((buf << log) >> log) - 1) ^ -(buf & 0x1)) + 1) >> 1; | |||||
| } | |||||
| } | |||||
| static inline int dirac_get_se_golomb(GetBitContext *gb) | |||||
| { | |||||
| uint32_t ret = get_interleaved_ue_golomb(gb); | |||||
| if (ret) { | |||||
| uint32_t buf; | |||||
| OPEN_READER(re, gb); | |||||
| UPDATE_CACHE(re, gb); | |||||
| buf = SHOW_SBITS(re, gb, 1); | |||||
| LAST_SKIP_BITS(re, gb, 1); | |||||
| ret = (ret ^ buf) - buf; | |||||
| CLOSE_READER(re, gb); | |||||
| } | |||||
| return ret; | |||||
| } | |||||
| /** | |||||
| * read unsigned golomb rice code (ffv1). | |||||
| */ | |||||
| static inline int get_ur_golomb(GetBitContext *gb, int k, int limit, | |||||
| int esc_len) | |||||
| { | |||||
| unsigned int buf; | |||||
| int log; | |||||
| OPEN_READER(re, gb); | |||||
| UPDATE_CACHE(re, gb); | |||||
| buf = GET_CACHE(re, gb); | |||||
| log = av_log2(buf); | |||||
| if (log > 31 - limit) { | |||||
| buf >>= log - k; | |||||
| buf += (30 - log) << k; | |||||
| LAST_SKIP_BITS(re, gb, 32 + k - log); | |||||
| CLOSE_READER(re, gb); | |||||
| return buf; | |||||
| } else { | |||||
| LAST_SKIP_BITS(re, gb, limit); | |||||
| UPDATE_CACHE(re, gb); | |||||
| buf = SHOW_UBITS(re, gb, esc_len); | |||||
| LAST_SKIP_BITS(re, gb, esc_len); | |||||
| CLOSE_READER(re, gb); | |||||
| return buf + limit - 1; | |||||
| } | |||||
| } | |||||
| /** | |||||
| * read unsigned golomb rice code (jpegls). | |||||
| */ | |||||
| static inline int get_ur_golomb_jpegls(GetBitContext *gb, int k, int limit, | |||||
| int esc_len) | |||||
| { | |||||
| unsigned int buf; | |||||
| int log; | |||||
| OPEN_READER(re, gb); | |||||
| UPDATE_CACHE(re, gb); | |||||
| buf = GET_CACHE(re, gb); | |||||
| log = av_log2(buf); | |||||
| if (log - k >= 32 - MIN_CACHE_BITS + (MIN_CACHE_BITS == 32) && | |||||
| 32 - log < limit) { | |||||
| buf >>= log - k; | |||||
| buf += (30 - log) << k; | |||||
| LAST_SKIP_BITS(re, gb, 32 + k - log); | |||||
| CLOSE_READER(re, gb); | |||||
| return buf; | |||||
| } else { | |||||
| int i; | |||||
| for (i = 0; i < limit && SHOW_UBITS(re, gb, 1) == 0 && BITS_AVAILABLE(re, gb); i++) { | |||||
| LAST_SKIP_BITS(re, gb, 1); | |||||
| UPDATE_CACHE(re, gb); | |||||
| } | |||||
| SKIP_BITS(re, gb, 1); | |||||
| if (i < limit - 1) { | |||||
| if (k) { | |||||
| buf = SHOW_UBITS(re, gb, k); | |||||
| LAST_SKIP_BITS(re, gb, k); | |||||
| } else { | |||||
| buf = 0; | |||||
| } | |||||
| CLOSE_READER(re, gb); | |||||
| return buf + (i << k); | |||||
| } else if (i == limit - 1) { | |||||
| buf = SHOW_UBITS(re, gb, esc_len); | |||||
| LAST_SKIP_BITS(re, gb, esc_len); | |||||
| CLOSE_READER(re, gb); | |||||
| return buf + 1; | |||||
| } else | |||||
| return -1; | |||||
| } | |||||
| } | |||||
| /** | |||||
| * read signed golomb rice code (ffv1). | |||||
| */ | |||||
| static inline int get_sr_golomb(GetBitContext *gb, int k, int limit, | |||||
| int esc_len) | |||||
| { | |||||
| int v = get_ur_golomb(gb, k, limit, esc_len); | |||||
| v++; | |||||
| if (v & 1) | |||||
| return v >> 1; | |||||
| else | |||||
| return -(v >> 1); | |||||
| // return (v>>1) ^ -(v&1); | |||||
| } | |||||
| /** | |||||
| * read signed golomb rice code (flac). | |||||
| */ | |||||
| static inline int get_sr_golomb_flac(GetBitContext *gb, int k, int limit, | |||||
| int esc_len) | |||||
| { | |||||
| int v = get_ur_golomb_jpegls(gb, k, limit, esc_len); | |||||
| return (v >> 1) ^ -(v & 1); | |||||
| } | |||||
| /** | |||||
| * read unsigned golomb rice code (shorten). | |||||
| */ | |||||
| static inline unsigned int get_ur_golomb_shorten(GetBitContext *gb, int k) | |||||
| { | |||||
| return get_ur_golomb_jpegls(gb, k, INT_MAX, 0); | |||||
| } | |||||
| /** | |||||
| * read signed golomb rice code (shorten). | |||||
| */ | |||||
| static inline int get_sr_golomb_shorten(GetBitContext *gb, int k) | |||||
| { | |||||
| int uvar = get_ur_golomb_jpegls(gb, k + 1, INT_MAX, 0); | |||||
| if (uvar & 1) | |||||
| return ~(uvar >> 1); | |||||
| else | |||||
| return uvar >> 1; | |||||
| } | |||||
| #ifdef TRACE | |||||
| static inline int get_ue(GetBitContext *s, const char *file, const char *func, | |||||
| int line) | |||||
| { | |||||
| int show = show_bits(s, 24); | |||||
| int pos = get_bits_count(s); | |||||
| int i = get_ue_golomb(s); | |||||
| int len = get_bits_count(s) - pos; | |||||
| int bits = show >> (24 - len); | |||||
| av_log(NULL, AV_LOG_DEBUG, "%5d %2d %3d ue @%5d in %s %s:%d\n", | |||||
| bits, len, i, pos, file, func, line); | |||||
| return i; | |||||
| } | |||||
| static inline int get_se(GetBitContext *s, const char *file, const char *func, | |||||
| int line) | |||||
| { | |||||
| int show = show_bits(s, 24); | |||||
| int pos = get_bits_count(s); | |||||
| int i = get_se_golomb(s); | |||||
| int len = get_bits_count(s) - pos; | |||||
| int bits = show >> (24 - len); | |||||
| av_log(NULL, AV_LOG_DEBUG, "%5d %2d %3d se @%5d in %s %s:%d\n", | |||||
| bits, len, i, pos, file, func, line); | |||||
| return i; | |||||
| } | |||||
| static inline int get_te(GetBitContext *s, int r, char *file, const char *func, | |||||
| int line) | |||||
| { | |||||
| int show = show_bits(s, 24); | |||||
| int pos = get_bits_count(s); | |||||
| int i = get_te0_golomb(s, r); | |||||
| int len = get_bits_count(s) - pos; | |||||
| int bits = show >> (24 - len); | |||||
| av_log(NULL, AV_LOG_DEBUG, "%5d %2d %3d te @%5d in %s %s:%d\n", | |||||
| bits, len, i, pos, file, func, line); | |||||
| return i; | |||||
| } | |||||
| #define get_ue_golomb(a) get_ue(a, __FILE__, __func__, __LINE__) | |||||
| #define get_se_golomb(a) get_se(a, __FILE__, __func__, __LINE__) | |||||
| #define get_te_golomb(a, r) get_te(a, r, __FILE__, __func__, __LINE__) | |||||
| #define get_te0_golomb(a, r) get_te(a, r, __FILE__, __func__, __LINE__) | |||||
| #endif /* TRACE */ | |||||
| /** | |||||
| * write unsigned exp golomb code. | |||||
| */ | |||||
| static inline void set_ue_golomb(PutBitContext *pb, int i) | |||||
| { | |||||
| assert(i >= 0); | |||||
| if (i < 256) | |||||
| put_bits(pb, ff_ue_golomb_len[i], i + 1); | |||||
| else { | |||||
| int e = av_log2(i + 1); | |||||
| put_bits(pb, 2 * e + 1, i + 1); | |||||
| } | |||||
| } | |||||
| /** | |||||
| * write truncated unsigned exp golomb code. | |||||
| */ | |||||
| static inline void set_te_golomb(PutBitContext *pb, int i, int range) | |||||
| { | |||||
| assert(range >= 1); | |||||
| assert(i <= range); | |||||
| if (range == 2) | |||||
| put_bits(pb, 1, i ^ 1); | |||||
| else | |||||
| set_ue_golomb(pb, i); | |||||
| } | |||||
| /** | |||||
| * write signed exp golomb code. 16 bits at most. | |||||
| */ | |||||
| static inline void set_se_golomb(PutBitContext *pb, int i) | |||||
| { | |||||
| i = 2 * i - 1; | |||||
| if (i < 0) | |||||
| i ^= -1; //FIXME check if gcc does the right thing | |||||
| set_ue_golomb(pb, i); | |||||
| } | |||||
| /** | |||||
| * write unsigned golomb rice code (ffv1). | |||||
| */ | |||||
| static inline void set_ur_golomb(PutBitContext *pb, int i, int k, int limit, | |||||
| int esc_len) | |||||
| { | |||||
| int e; | |||||
| assert(i >= 0); | |||||
| e = i >> k; | |||||
| if (e < limit) | |||||
| put_bits(pb, e + k + 1, (1 << k) + (i & ((1 << k) - 1))); | |||||
| else | |||||
| put_bits(pb, limit + esc_len, i - limit + 1); | |||||
| } | |||||
| /** | |||||
| * write unsigned golomb rice code (jpegls). | |||||
| */ | |||||
| static inline void set_ur_golomb_jpegls(PutBitContext *pb, int i, int k, | |||||
| int limit, int esc_len) | |||||
| { | |||||
| int e; | |||||
| assert(i >= 0); | |||||
| e = (i >> k) + 1; | |||||
| if (e < limit) { | |||||
| while (e > 31) { | |||||
| put_bits(pb, 31, 0); | |||||
| e -= 31; | |||||
| } | |||||
| put_bits(pb, e, 1); | |||||
| if (k) | |||||
| put_sbits(pb, k, i); | |||||
| } else { | |||||
| while (limit > 31) { | |||||
| put_bits(pb, 31, 0); | |||||
| limit -= 31; | |||||
| } | |||||
| put_bits(pb, limit, 1); | |||||
| put_bits(pb, esc_len, i - 1); | |||||
| } | |||||
| } | |||||
| /** | |||||
| * write signed golomb rice code (ffv1). | |||||
| */ | |||||
| static inline void set_sr_golomb(PutBitContext *pb, int i, int k, int limit, | |||||
| int esc_len) | |||||
| { | |||||
| int v; | |||||
| v = -2 * i - 1; | |||||
| v ^= (v >> 31); | |||||
| set_ur_golomb(pb, v, k, limit, esc_len); | |||||
| } | |||||
| /** | |||||
| * write signed golomb rice code (flac). | |||||
| */ | |||||
| static inline void set_sr_golomb_flac(PutBitContext *pb, int i, int k, | |||||
| int limit, int esc_len) | |||||
| { | |||||
| int v; | |||||
| v = -2 * i - 1; | |||||
| v ^= (v >> 31); | |||||
| set_ur_golomb_jpegls(pb, v, k, limit, esc_len); | |||||
| } | |||||
| #endif /* AVCODEC_GOLOMB_H */ | |||||
| @@ -32,7 +32,7 @@ | |||||
| #include "h264dec.h" | #include "h264dec.h" | ||||
| #include "h264_mvpred.h" | #include "h264_mvpred.h" | ||||
| #include "h264data.h" | #include "h264data.h" | ||||
| #include "golomb.h" | |||||
| #include "golomb_legacy.h" | |||||
| #include "mpegutils.h" | #include "mpegutils.h" | ||||
| #include <assert.h> | #include <assert.h> | ||||
| @@ -18,7 +18,7 @@ | |||||
| #include "bytestream.h" | #include "bytestream.h" | ||||
| #include "get_bits.h" | #include "get_bits.h" | ||||
| #include "golomb.h" | |||||
| #include "golomb_legacy.h" | |||||
| #include "h264.h" | #include "h264.h" | ||||
| #include "h264dec.h" | #include "h264dec.h" | ||||
| #include "h264_parse.h" | #include "h264_parse.h" | ||||
| @@ -36,7 +36,7 @@ | |||||
| #include "avcodec.h" | #include "avcodec.h" | ||||
| #include "get_bits.h" | #include "get_bits.h" | ||||
| #include "golomb.h" | |||||
| #include "golomb_legacy.h" | |||||
| #include "h264.h" | #include "h264.h" | ||||
| #include "h264_sei.h" | #include "h264_sei.h" | ||||
| #include "h264_ps.h" | #include "h264_ps.h" | ||||
| @@ -28,12 +28,13 @@ | |||||
| #include <inttypes.h> | #include <inttypes.h> | ||||
| #include "libavutil/imgutils.h" | #include "libavutil/imgutils.h" | ||||
| #include "golomb_legacy.h" | |||||
| #include "internal.h" | #include "internal.h" | ||||
| #include "mathops.h" | #include "mathops.h" | ||||
| #include "avcodec.h" | #include "avcodec.h" | ||||
| #include "h264data.h" | #include "h264data.h" | ||||
| #include "h264_ps.h" | #include "h264_ps.h" | ||||
| #include "golomb.h" | |||||
| #define MAX_LOG2_MAX_FRAME_NUM (12 + 4) | #define MAX_LOG2_MAX_FRAME_NUM (12 + 4) | ||||
| #define MIN_LOG2_MAX_FRAME_NUM 4 | #define MIN_LOG2_MAX_FRAME_NUM 4 | ||||
| @@ -27,11 +27,11 @@ | |||||
| #include <inttypes.h> | #include <inttypes.h> | ||||
| #include "golomb_legacy.h" | |||||
| #include "internal.h" | #include "internal.h" | ||||
| #include "avcodec.h" | #include "avcodec.h" | ||||
| #include "h264.h" | #include "h264.h" | ||||
| #include "h264dec.h" | #include "h264dec.h" | ||||
| #include "golomb.h" | |||||
| #include "mpegutils.h" | #include "mpegutils.h" | ||||
| #include <assert.h> | #include <assert.h> | ||||
| @@ -27,7 +27,7 @@ | |||||
| #include "avcodec.h" | #include "avcodec.h" | ||||
| #include "get_bits.h" | #include "get_bits.h" | ||||
| #include "golomb.h" | |||||
| #include "golomb_legacy.h" | |||||
| #include "h264_ps.h" | #include "h264_ps.h" | ||||
| #include "h264_sei.h" | #include "h264_sei.h" | ||||
| #include "internal.h" | #include "internal.h" | ||||
| @@ -34,6 +34,7 @@ | |||||
| #include "cabac.h" | #include "cabac.h" | ||||
| #include "cabac_functions.h" | #include "cabac_functions.h" | ||||
| #include "error_resilience.h" | #include "error_resilience.h" | ||||
| #include "golomb_legacy.h" | |||||
| #include "avcodec.h" | #include "avcodec.h" | ||||
| #include "h264.h" | #include "h264.h" | ||||
| #include "h264dec.h" | #include "h264dec.h" | ||||
| @@ -41,7 +42,6 @@ | |||||
| #include "h264chroma.h" | #include "h264chroma.h" | ||||
| #include "h264_mvpred.h" | #include "h264_mvpred.h" | ||||
| #include "h264_ps.h" | #include "h264_ps.h" | ||||
| #include "golomb.h" | |||||
| #include "mathops.h" | #include "mathops.h" | ||||
| #include "mpegutils.h" | #include "mpegutils.h" | ||||
| #include "rectangle.h" | #include "rectangle.h" | ||||
| @@ -36,6 +36,7 @@ | |||||
| #include "cabac_functions.h" | #include "cabac_functions.h" | ||||
| #include "error_resilience.h" | #include "error_resilience.h" | ||||
| #include "avcodec.h" | #include "avcodec.h" | ||||
| #include "golomb_legacy.h" | |||||
| #include "h264.h" | #include "h264.h" | ||||
| #include "h264dec.h" | #include "h264dec.h" | ||||
| #include "h2645_parse.h" | #include "h2645_parse.h" | ||||
| @@ -43,7 +44,6 @@ | |||||
| #include "h264chroma.h" | #include "h264chroma.h" | ||||
| #include "h264_mvpred.h" | #include "h264_mvpred.h" | ||||
| #include "h264_ps.h" | #include "h264_ps.h" | ||||
| #include "golomb.h" | |||||
| #include "mathops.h" | #include "mathops.h" | ||||
| #include "me_cmp.h" | #include "me_cmp.h" | ||||
| #include "mpegutils.h" | #include "mpegutils.h" | ||||
| @@ -22,7 +22,7 @@ | |||||
| #include "libavutil/common.h" | #include "libavutil/common.h" | ||||
| #include "golomb.h" | |||||
| #include "golomb_legacy.h" | |||||
| #include "hevc.h" | #include "hevc.h" | ||||
| #include "hevcdec.h" | #include "hevcdec.h" | ||||
| #include "h2645_parse.h" | #include "h2645_parse.h" | ||||
| @@ -25,7 +25,7 @@ | |||||
| #include "libavutil/imgutils.h" | #include "libavutil/imgutils.h" | ||||
| #include "golomb.h" | |||||
| #include "golomb_legacy.h" | |||||
| #include "hevc_data.h" | #include "hevc_data.h" | ||||
| #include "hevc_ps.h" | #include "hevc_ps.h" | ||||
| @@ -18,7 +18,7 @@ | |||||
| * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||||
| */ | */ | ||||
| #include "golomb.h" | |||||
| #include "golomb_legacy.h" | |||||
| #include "hevc_ps.h" | #include "hevc_ps.h" | ||||
| #include "put_bits.h" | #include "put_bits.h" | ||||
| @@ -22,7 +22,7 @@ | |||||
| * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||||
| */ | */ | ||||
| #include "golomb.h" | |||||
| #include "golomb_legacy.h" | |||||
| #include "hevcdec.h" | #include "hevcdec.h" | ||||
| enum HEVC_SEI_TYPE { | enum HEVC_SEI_TYPE { | ||||
| @@ -35,7 +35,7 @@ | |||||
| #include "bswapdsp.h" | #include "bswapdsp.h" | ||||
| #include "bytestream.h" | #include "bytestream.h" | ||||
| #include "cabac_functions.h" | #include "cabac_functions.h" | ||||
| #include "golomb.h" | |||||
| #include "golomb_legacy.h" | |||||
| #include "hevc.h" | #include "hevc.h" | ||||
| #include "hevc_data.h" | #include "hevc_data.h" | ||||
| #include "hevcdec.h" | #include "hevcdec.h" | ||||
| @@ -27,7 +27,7 @@ | |||||
| #include "avcodec.h" | #include "avcodec.h" | ||||
| #include "get_bits.h" | #include "get_bits.h" | ||||
| #include "golomb.h" | |||||
| #include "golomb_legacy.h" | |||||
| #include "internal.h" | #include "internal.h" | ||||
| #include "mathops.h" | #include "mathops.h" | ||||
| #include "mjpeg.h" | #include "mjpeg.h" | ||||
| @@ -27,7 +27,7 @@ | |||||
| #include "avcodec.h" | #include "avcodec.h" | ||||
| #include "get_bits.h" | #include "get_bits.h" | ||||
| #include "golomb.h" | |||||
| #include "golomb_legacy.h" | |||||
| #include "internal.h" | #include "internal.h" | ||||
| #include "mathops.h" | #include "mathops.h" | ||||
| #include "mjpeg.h" | #include "mjpeg.h" | ||||
| @@ -26,7 +26,7 @@ | |||||
| #include "avcodec.h" | #include "avcodec.h" | ||||
| #include "get_bits.h" | #include "get_bits.h" | ||||
| #include "golomb.h" | |||||
| #include "golomb_legacy.h" | |||||
| #include "internal.h" | #include "internal.h" | ||||
| #include "mathops.h" | #include "mathops.h" | ||||
| @@ -30,7 +30,7 @@ | |||||
| #include "libavutil/channel_layout.h" | #include "libavutil/channel_layout.h" | ||||
| #include "avcodec.h" | #include "avcodec.h" | ||||
| #include "get_bits.h" | #include "get_bits.h" | ||||
| #include "golomb.h" | |||||
| #include "golomb_legacy.h" | |||||
| #include "internal.h" | #include "internal.h" | ||||
| #include "unary_legacy.h" | #include "unary_legacy.h" | ||||
| #include "ralfdata.h" | #include "ralfdata.h" | ||||
| @@ -25,9 +25,9 @@ | |||||
| */ | */ | ||||
| #include "avcodec.h" | #include "avcodec.h" | ||||
| #include "golomb_legacy.h" | |||||
| #include "mpegutils.h" | #include "mpegutils.h" | ||||
| #include "mpegvideo.h" | #include "mpegvideo.h" | ||||
| #include "golomb.h" | |||||
| #include "rv34.h" | #include "rv34.h" | ||||
| #include "rv30data.h" | #include "rv30data.h" | ||||
| @@ -28,9 +28,9 @@ | |||||
| #include "avcodec.h" | #include "avcodec.h" | ||||
| #include "error_resilience.h" | #include "error_resilience.h" | ||||
| #include "golomb_legacy.h" | |||||
| #include "mpegutils.h" | #include "mpegutils.h" | ||||
| #include "mpegvideo.h" | #include "mpegvideo.h" | ||||
| #include "golomb.h" | |||||
| #include "internal.h" | #include "internal.h" | ||||
| #include "mathops.h" | #include "mathops.h" | ||||
| #include "mpeg_er.h" | #include "mpeg_er.h" | ||||
| @@ -27,9 +27,9 @@ | |||||
| #include "libavutil/imgutils.h" | #include "libavutil/imgutils.h" | ||||
| #include "avcodec.h" | #include "avcodec.h" | ||||
| #include "golomb_legacy.h" | |||||
| #include "mpegutils.h" | #include "mpegutils.h" | ||||
| #include "mpegvideo.h" | #include "mpegvideo.h" | ||||
| #include "golomb.h" | |||||
| #include "rv34.h" | #include "rv34.h" | ||||
| #include "rv40vlc2.h" | #include "rv40vlc2.h" | ||||
| @@ -29,7 +29,7 @@ | |||||
| #include "avcodec.h" | #include "avcodec.h" | ||||
| #include "bytestream.h" | #include "bytestream.h" | ||||
| #include "get_bits.h" | #include "get_bits.h" | ||||
| #include "golomb.h" | |||||
| #include "golomb_legacy.h" | |||||
| #include "internal.h" | #include "internal.h" | ||||
| #define MAX_CHANNELS 8 | #define MAX_CHANNELS 8 | ||||
| @@ -43,12 +43,13 @@ | |||||
| #include <inttypes.h> | #include <inttypes.h> | ||||
| #include "libavutil/attributes.h" | #include "libavutil/attributes.h" | ||||
| #include "golomb_legacy.h" | |||||
| #include "internal.h" | #include "internal.h" | ||||
| #include "avcodec.h" | #include "avcodec.h" | ||||
| #include "mpegutils.h" | #include "mpegutils.h" | ||||
| #include "h264dec.h" | #include "h264dec.h" | ||||
| #include "h264data.h" | #include "h264data.h" | ||||
| #include "golomb.h" | |||||
| #include "hpeldsp.h" | #include "hpeldsp.h" | ||||
| #include "mathops.h" | #include "mathops.h" | ||||
| #include "rectangle.h" | #include "rectangle.h" | ||||
| @@ -21,7 +21,7 @@ | |||||
| #include "libavutil/mem.h" | #include "libavutil/mem.h" | ||||
| #include "libavcodec/get_bits.h" | |||||
| #include "libavcodec/bitstream.h" | |||||
| #include "libavcodec/put_bits.h" | #include "libavcodec/put_bits.h" | ||||
| #include "libavcodec/golomb.h" | #include "libavcodec/golomb.h" | ||||
| @@ -33,7 +33,7 @@ int main(void) | |||||
| int i, ret = 0; | int i, ret = 0; | ||||
| uint8_t *temp; | uint8_t *temp; | ||||
| PutBitContext pb; | PutBitContext pb; | ||||
| GetBitContext gb; | |||||
| BitstreamContext bc; | |||||
| temp = av_malloc(SIZE); | temp = av_malloc(SIZE); | ||||
| if (!temp) | if (!temp) | ||||
| @@ -44,11 +44,11 @@ int main(void) | |||||
| set_ue_golomb(&pb, i); | set_ue_golomb(&pb, i); | ||||
| flush_put_bits(&pb); | flush_put_bits(&pb); | ||||
| init_get_bits(&gb, temp, 8 * SIZE); | |||||
| bitstream_init8(&bc, temp, SIZE); | |||||
| for (i = 0; i < COUNT; i++) { | for (i = 0; i < COUNT; i++) { | ||||
| int j, s = show_bits(&gb, 25); | |||||
| int j, s = bitstream_peek(&bc, 25); | |||||
| j = get_ue_golomb(&gb); | |||||
| j = get_ue_golomb(&bc); | |||||
| if (j != i) { | if (j != i) { | ||||
| fprintf(stderr, "get_ue_golomb: expected %d, got %d. bits: %7x\n", | fprintf(stderr, "get_ue_golomb: expected %d, got %d. bits: %7x\n", | ||||
| i, j, s); | i, j, s); | ||||
| @@ -62,11 +62,11 @@ int main(void) | |||||
| set_ue_golomb(&pb, EXTEND(i)); | set_ue_golomb(&pb, EXTEND(i)); | ||||
| flush_put_bits(&pb); | flush_put_bits(&pb); | ||||
| init_get_bits(&gb, temp, 8 * SIZE); | |||||
| bitstream_init8(&bc, temp, SIZE); | |||||
| for (i = 0; i < COUNT; i++) { | for (i = 0; i < COUNT; i++) { | ||||
| int j, s = show_bits_long(&gb, 32); | |||||
| int j, s = bitstream_peek(&bc, 32); | |||||
| j = get_ue_golomb_long(&gb); | |||||
| j = get_ue_golomb_long(&bc); | |||||
| if (j != EXTEND(i)) { | if (j != EXTEND(i)) { | ||||
| fprintf(stderr, "get_ue_golomb_long: expected %d, got %d. " | fprintf(stderr, "get_ue_golomb_long: expected %d, got %d. " | ||||
| "bits: %8x\n", EXTEND(i), j, s); | "bits: %8x\n", EXTEND(i), j, s); | ||||
| @@ -79,11 +79,11 @@ int main(void) | |||||
| set_se_golomb(&pb, i - COUNT / 2); | set_se_golomb(&pb, i - COUNT / 2); | ||||
| flush_put_bits(&pb); | flush_put_bits(&pb); | ||||
| init_get_bits(&gb, temp, 8 * SIZE); | |||||
| bitstream_init8(&bc, temp, SIZE); | |||||
| for (i = 0; i < COUNT; i++) { | for (i = 0; i < COUNT; i++) { | ||||
| int j, s = show_bits(&gb, 25); | |||||
| int j, s = bitstream_peek(&bc, 25); | |||||
| j = get_se_golomb(&gb); | |||||
| j = get_se_golomb(&bc); | |||||
| if (j != i - COUNT / 2) { | if (j != i - COUNT / 2) { | ||||
| fprintf(stderr, "get_se_golomb: expected %d, got %d. bits: %7x\n", | fprintf(stderr, "get_se_golomb: expected %d, got %d. bits: %7x\n", | ||||
| i - COUNT / 2, j, s); | i - COUNT / 2, j, s); | ||||
| @@ -20,7 +20,7 @@ | |||||
| #include "libavcodec/avcodec.h" | #include "libavcodec/avcodec.h" | ||||
| #include "libavcodec/get_bits.h" | #include "libavcodec/get_bits.h" | ||||
| #include "libavcodec/golomb.h" | |||||
| #include "libavcodec/golomb_legacy.h" | |||||
| #include "libavcodec/hevc.h" | #include "libavcodec/hevc.h" | ||||
| #include "libavutil/intreadwrite.h" | #include "libavutil/intreadwrite.h" | ||||
| #include "avc.h" | #include "avc.h" | ||||