| OLD | NEW |
| 1 /** | 1 /** |
| 2 * @file | 2 * @file |
| 3 * VP5 and VP6 compatible video decoder (common features) | 3 * VP5 and VP6 compatible video decoder (common features) |
| 4 * | 4 * |
| 5 * Copyright (C) 2006 Aurelien Jacobs <aurel@gnuage.org> | 5 * Copyright (C) 2006 Aurelien Jacobs <aurel@gnuage.org> |
| 6 * | 6 * |
| 7 * This file is part of FFmpeg. | 7 * This file is part of FFmpeg. |
| 8 * | 8 * |
| 9 * FFmpeg is free software; you can redistribute it and/or | 9 * FFmpeg is free software; you can redistribute it and/or |
| 10 * modify it under the terms of the GNU Lesser General Public | 10 * modify it under the terms of the GNU Lesser General Public |
| (...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 187 static av_always_inline unsigned int vp56_rac_renorm(VP56RangeCoder *c) | 187 static av_always_inline unsigned int vp56_rac_renorm(VP56RangeCoder *c) |
| 188 { | 188 { |
| 189 int shift = ff_vp56_norm_shift[c->high]; | 189 int shift = ff_vp56_norm_shift[c->high]; |
| 190 int bits = c->bits; | 190 int bits = c->bits; |
| 191 unsigned int code_word = c->code_word; | 191 unsigned int code_word = c->code_word; |
| 192 | 192 |
| 193 c->high <<= shift; | 193 c->high <<= shift; |
| 194 code_word <<= shift; | 194 code_word <<= shift; |
| 195 bits += shift; | 195 bits += shift; |
| 196 if(bits >= 0 && c->buffer < c->end) { | 196 if(bits >= 0 && c->buffer < c->end) { |
| 197 code_word |= *c->buffer++ << bits; | 197 code_word |= bytestream_get_be16(&c->buffer) << bits; |
| 198 bits -= 8; | 198 bits -= 16; |
| 199 } | 199 } |
| 200 c->bits = bits; | 200 c->bits = bits; |
| 201 return code_word; | 201 return code_word; |
| 202 } | 202 } |
| 203 | 203 |
| 204 #if ARCH_X86 | 204 #if ARCH_X86 |
| 205 #include "x86/vp56_arith.h" | 205 #include "x86/vp56_arith.h" |
| 206 #endif | 206 #endif |
| 207 | 207 |
| 208 #ifndef vp56_rac_get_prob | 208 #ifndef vp56_rac_get_prob |
| 209 #define vp56_rac_get_prob vp56_rac_get_prob | 209 #define vp56_rac_get_prob vp56_rac_get_prob |
| 210 static av_always_inline int vp56_rac_get_prob(VP56RangeCoder *c, uint8_t prob) | 210 static av_always_inline int vp56_rac_get_prob(VP56RangeCoder *c, uint8_t prob) |
| 211 { | 211 { |
| 212 unsigned int code_word = vp56_rac_renorm(c); | 212 unsigned int code_word = vp56_rac_renorm(c); |
| 213 unsigned int low = 1 + (((c->high - 1) * prob) >> 8); | 213 unsigned int low = 1 + (((c->high - 1) * prob) >> 8); |
| 214 unsigned int low_shift = low << 8; | 214 unsigned int low_shift = low << 16; |
| 215 int bit = code_word >= low_shift; | 215 int bit = code_word >= low_shift; |
| 216 | 216 |
| 217 c->high = bit ? c->high - low : low; | 217 c->high = bit ? c->high - low : low; |
| 218 c->code_word = bit ? code_word - low_shift : code_word; | 218 c->code_word = bit ? code_word - low_shift : code_word; |
| 219 | 219 |
| 220 return bit; | 220 return bit; |
| 221 } | 221 } |
| 222 #endif | 222 #endif |
| 223 | 223 |
| 224 // branchy variant, to be used where there's a branch based on the bit decoded | 224 // branchy variant, to be used where there's a branch based on the bit decoded |
| 225 static av_always_inline int vp56_rac_get_prob_branchy(VP56RangeCoder *c, int pro
b) | 225 static av_always_inline int vp56_rac_get_prob_branchy(VP56RangeCoder *c, int pro
b) |
| 226 { | 226 { |
| 227 unsigned long code_word = vp56_rac_renorm(c); | 227 unsigned long code_word = vp56_rac_renorm(c); |
| 228 unsigned low = 1 + (((c->high - 1) * prob) >> 8); | 228 unsigned low = 1 + (((c->high - 1) * prob) >> 8); |
| 229 unsigned low_shift = low << 8; | 229 unsigned low_shift = low << 16; |
| 230 | 230 |
| 231 if (code_word >= low_shift) { | 231 if (code_word >= low_shift) { |
| 232 c->high -= low; | 232 c->high -= low; |
| 233 c->code_word = code_word - low_shift; | 233 c->code_word = code_word - low_shift; |
| 234 return 1; | 234 return 1; |
| 235 } | 235 } |
| 236 | 236 |
| 237 c->high = low; | 237 c->high = low; |
| 238 c->code_word = code_word; | 238 c->code_word = code_word; |
| 239 return 0; | 239 return 0; |
| 240 } | 240 } |
| 241 | 241 |
| 242 static av_always_inline int vp56_rac_get(VP56RangeCoder *c) | 242 static av_always_inline int vp56_rac_get(VP56RangeCoder *c) |
| 243 { | 243 { |
| 244 unsigned int code_word = vp56_rac_renorm(c); | 244 unsigned int code_word = vp56_rac_renorm(c); |
| 245 /* equiprobable */ | 245 /* equiprobable */ |
| 246 int low = (c->high + 1) >> 1; | 246 int low = (c->high + 1) >> 1; |
| 247 unsigned int low_shift = low << 8; | 247 unsigned int low_shift = low << 16; |
| 248 int bit = code_word >= low_shift; | 248 int bit = code_word >= low_shift; |
| 249 if (bit) { | 249 if (bit) { |
| 250 c->high -= low; | 250 c->high -= low; |
| 251 code_word -= low_shift; | 251 code_word -= low_shift; |
| 252 } else { | 252 } else { |
| 253 c->high = low; | 253 c->high = low; |
| 254 } | 254 } |
| 255 | 255 |
| 256 c->code_word = code_word; | 256 c->code_word = code_word; |
| 257 return bit; | 257 return bit; |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 359 int v = 0; | 359 int v = 0; |
| 360 | 360 |
| 361 do { | 361 do { |
| 362 v = (v<<1) + vp56_rac_get_prob(c, *prob++); | 362 v = (v<<1) + vp56_rac_get_prob(c, *prob++); |
| 363 } while (*prob); | 363 } while (*prob); |
| 364 | 364 |
| 365 return v; | 365 return v; |
| 366 } | 366 } |
| 367 | 367 |
| 368 #endif /* AVCODEC_VP56_H */ | 368 #endif /* AVCODEC_VP56_H */ |
| OLD | NEW |