vp89_rac.h 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. /*
  2. * Copyright (C) 2006 Aurelien Jacobs <aurel@gnuage.org>
  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. * @file
  22. * Range decoder functions common to VP8 and VP9
  23. */
  24. #ifndef AVCODEC_VP89_RAC_H
  25. #define AVCODEC_VP89_RAC_H
  26. #include <stdint.h>
  27. #include "libavutil/attributes.h"
  28. #include "vpx_rac.h"
  29. // rounding is different than vpx_rac_get, is vpx_rac_get wrong?
  30. static av_always_inline int vp89_rac_get(VPXRangeCoder *c)
  31. {
  32. return vpx_rac_get_prob(c, 128);
  33. }
  34. av_unused static int vp89_rac_get_uint(VPXRangeCoder *c, int bits)
  35. {
  36. int value = 0;
  37. while (bits--) {
  38. value = (value << 1) | vp89_rac_get(c);
  39. }
  40. return value;
  41. }
  42. // how probabilities are associated with decisions is different I think
  43. // well, the new scheme fits in the old but this way has one fewer branches per decision
  44. static av_always_inline int vp89_rac_get_tree(VPXRangeCoder *c, const int8_t (*tree)[2],
  45. const uint8_t *probs)
  46. {
  47. int i = 0;
  48. do {
  49. i = tree[i][vpx_rac_get_prob(c, probs[i])];
  50. } while (i > 0);
  51. return -i;
  52. }
  53. #endif /* AVCODEC_VP89_RAC_H */