patch-libavcodec_aacenc_quantization_misc_h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. $OpenBSD: patch-libavcodec_aacenc_quantization_misc_h,v 1.2 2016/03/09 17:29:36 ajacoutot Exp $
  2. AAC encoder: memoize quantize_band_cost
  3. aacenc: use generational cache instead of resetting.
  4. --- libavcodec/aacenc_quantization_misc.h.orig Tue Mar 8 19:20:55 2016
  5. +++ libavcodec/aacenc_quantization_misc.h Tue Mar 8 19:23:47 2016
  6. @@ -0,0 +1,53 @@
  7. +/*
  8. + * AAC encoder quantization
  9. + * Copyright (C) 2015 Claudio Freire
  10. + *
  11. + * This file is part of FFmpeg.
  12. + *
  13. + * FFmpeg is free software; you can redistribute it and/or
  14. + * modify it under the terms of the GNU Lesser General Public
  15. + * License as published by the Free Software Foundation; either
  16. + * version 2.1 of the License, or (at your option) any later version.
  17. + *
  18. + * FFmpeg is distributed in the hope that it will be useful,
  19. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  20. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  21. + * Lesser General Public License for more details.
  22. + *
  23. + * You should have received a copy of the GNU Lesser General Public
  24. + * License along with FFmpeg; if not, write to the Free Software
  25. + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  26. + */
  27. +
  28. +/**
  29. + * @file
  30. + * AAC encoder quantization misc reusable function templates
  31. + * @author Claudio Freire ( klaussfreire gmail com )
  32. + */
  33. +
  34. +#ifndef AVCODEC_AACENC_QUANTIZATION_MISC_H
  35. +#define AVCODEC_AACENC_QUANTIZATION_MISC_H
  36. +
  37. +static inline float quantize_band_cost_cached(struct AACEncContext *s, int w, int g, const float *in,
  38. + const float *scaled, int size, int scale_idx,
  39. + int cb, const float lambda, const float uplim,
  40. + int *bits, float *energy, int rtz)
  41. +{
  42. + AACQuantizeBandCostCacheEntry *entry;
  43. + av_assert1(scale_idx >= 0 && scale_idx < 256);
  44. + entry = &s->quantize_band_cost_cache[scale_idx][w*16+g];
  45. + if (entry->generation != s->quantize_band_cost_cache_generation || entry->cb != cb || entry->rtz != rtz) {
  46. + entry->rd = quantize_band_cost(s, in, scaled, size, scale_idx,
  47. + cb, lambda, uplim, &entry->bits, &entry->energy, rtz);
  48. + entry->cb = cb;
  49. + entry->rtz = rtz;
  50. + entry->generation = s->quantize_band_cost_cache_generation;
  51. + }
  52. + if (bits)
  53. + *bits = entry->bits;
  54. + if (energy)
  55. + *energy = entry->energy;
  56. + return entry->rd;
  57. +}
  58. +
  59. +#endif /* AVCODEC_AACENC_QUANTIZATION_MISC_H */