patch-libavcodec_aacenc_h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. $OpenBSD: patch-libavcodec_aacenc_h,v 1.9 2016/12/05 09:02:29 ajacoutot Exp $
  2. aacenc: copy PRNG from the decoder
  3. AAC encoder: tweak rate-distortion logic
  4. AAC encoder: Extensive improvements
  5. AAC encoder: memoize quantize_band_cost
  6. aacenc: add support for changing options based on a profile
  7. aacenc: increase size of s->planar_samples[] from 6 to 8
  8. aacenc: shorten name of ff_aac_adjust_common_prediction
  9. aacenc: add support for encoding files using Long Term Prediction
  10. aacenc: switch to using the RNG from libavutil
  11. acenc: remove deprecated avctx->frame_bits use
  12. aacenc: remove FAAC-like coder
  13. aacenc: use generational cache instead of resetting.
  14. aacenc: use the decoder's lcg PRNG
  15. aacenc: quit when the audio queue reaches 0 rather than keeping track of empty frames
  16. --- libavcodec/aacenc.h.orig Sat Aug 27 22:51:19 2016
  17. +++ libavcodec/aacenc.h Thu Nov 10 19:21:34 2016
  18. @@ -33,8 +33,7 @@
  19. #include "lpc.h"
  20. typedef enum AACCoder {
  21. - AAC_CODER_FAAC = 0,
  22. - AAC_CODER_ANMR,
  23. + AAC_CODER_ANMR = 0,
  24. AAC_CODER_TWOLOOP,
  25. AAC_CODER_FAST,
  26. @@ -42,11 +41,12 @@ typedef enum AACCoder {
  27. }AACCoder;
  28. typedef struct AACEncOptions {
  29. - int stereo_mode;
  30. - int aac_coder;
  31. + int coder;
  32. int pns;
  33. int tns;
  34. + int ltp;
  35. int pred;
  36. + int mid_side;
  37. int intensity_stereo;
  38. } AACEncOptions;
  39. @@ -60,13 +60,19 @@ typedef struct AACCoefficientsEncoder {
  40. void (*quantize_and_encode_band)(struct AACEncContext *s, PutBitContext *pb, const float *in, float *out, int size,
  41. int scale_idx, int cb, const float lambda, int rtz);
  42. void (*encode_tns_info)(struct AACEncContext *s, SingleChannelElement *sce);
  43. + void (*encode_ltp_info)(struct AACEncContext *s, SingleChannelElement *sce, int common_window);
  44. void (*encode_main_pred)(struct AACEncContext *s, SingleChannelElement *sce);
  45. - void (*adjust_common_prediction)(struct AACEncContext *s, ChannelElement *cpe);
  46. + void (*adjust_common_pred)(struct AACEncContext *s, ChannelElement *cpe);
  47. + void (*adjust_common_ltp)(struct AACEncContext *s, ChannelElement *cpe);
  48. void (*apply_main_pred)(struct AACEncContext *s, SingleChannelElement *sce);
  49. void (*apply_tns_filt)(struct AACEncContext *s, SingleChannelElement *sce);
  50. + void (*update_ltp)(struct AACEncContext *s, SingleChannelElement *sce);
  51. + void (*ltp_insert_new_frame)(struct AACEncContext *s);
  52. void (*set_special_band_scalefactors)(struct AACEncContext *s, SingleChannelElement *sce);
  53. void (*search_for_pns)(struct AACEncContext *s, AVCodecContext *avctx, SingleChannelElement *sce);
  54. + void (*mark_pns)(struct AACEncContext *s, AVCodecContext *avctx, SingleChannelElement *sce);
  55. void (*search_for_tns)(struct AACEncContext *s, SingleChannelElement *sce);
  56. + void (*search_for_ltp)(struct AACEncContext *s, SingleChannelElement *sce, int common_window);
  57. void (*search_for_ms)(struct AACEncContext *s, ChannelElement *cpe);
  58. void (*search_for_is)(struct AACEncContext *s, AVCodecContext *avctx, ChannelElement *cpe);
  59. void (*search_for_pred)(struct AACEncContext *s, SingleChannelElement *sce);
  60. @@ -74,6 +80,15 @@ typedef struct AACCoefficientsEncoder {
  61. extern AACCoefficientsEncoder ff_aac_coders[];
  62. +typedef struct AACQuantizeBandCostCacheEntry {
  63. + float rd;
  64. + float energy;
  65. + int bits;
  66. + char cb;
  67. + char rtz;
  68. + uint16_t generation;
  69. +} AACQuantizeBandCostCacheEntry;
  70. +
  71. /**
  72. * AAC encoder context
  73. */
  74. @@ -84,7 +99,7 @@ typedef struct AACEncContext {
  75. FFTContext mdct1024; ///< long (1024 samples) frame transform context
  76. FFTContext mdct128; ///< short (128 samples) frame transform context
  77. AVFloatDSPContext *fdsp;
  78. - float *planar_samples[6]; ///< saved preprocessed input
  79. + float *planar_samples[8]; ///< saved preprocessed input
  80. int profile; ///< copied from avctx
  81. LPCContext lpc; ///< used by TNS
  82. @@ -96,18 +111,28 @@ typedef struct AACEncContext {
  83. FFPsyContext psy;
  84. struct FFPsyPreprocessContext* psypp;
  85. AACCoefficientsEncoder *coder;
  86. - int cur_channel;
  87. - int last_frame;
  88. + int cur_channel; ///< current channel for coder context
  89. + int random_state;
  90. float lambda;
  91. + int last_frame_pb_count; ///< number of bits for the previous frame
  92. + float lambda_sum; ///< sum(lambda), for Qvg reporting
  93. + int lambda_count; ///< count(lambda), for Qvg reporting
  94. + enum RawDataBlockType cur_type; ///< channel group type cur_channel belongs to
  95. +
  96. AudioFrameQueue afq;
  97. DECLARE_ALIGNED(16, int, qcoefs)[96]; ///< quantized coefficients
  98. DECLARE_ALIGNED(32, float, scoefs)[1024]; ///< scaled coefficients
  99. + uint16_t quantize_band_cost_cache_generation;
  100. + AACQuantizeBandCostCacheEntry quantize_band_cost_cache[256][128]; ///< memoization area for quantize_band_cost
  101. +
  102. struct {
  103. float *samples;
  104. } buffer;
  105. } AACEncContext;
  106. void ff_aac_coder_init_mips(AACEncContext *c);
  107. +void ff_quantize_band_cost_cache_init(struct AACEncContext *s);
  108. +
  109. #endif /* AVCODEC_AACENC_H */