You've already forked FFmpeg
mirror of
https://github.com/FFmpeg/FFmpeg.git
synced 2025-08-15 14:13:16 +02:00
aacenc: use generational cache instead of resetting.
Approximately 11% faster transcoding from mp3 with default settings. Signed-off-by: Reimar Döffinger <Reimar.Doeffinger@gmx.de>
This commit is contained in:
@@ -78,11 +78,10 @@ static void put_audio_specific_config(AVCodecContext *avctx)
|
|||||||
|
|
||||||
void ff_quantize_band_cost_cache_init(struct AACEncContext *s)
|
void ff_quantize_band_cost_cache_init(struct AACEncContext *s)
|
||||||
{
|
{
|
||||||
int sf, g;
|
++s->quantize_band_cost_cache_generation;
|
||||||
for (sf = 0; sf < 256; sf++) {
|
if (s->quantize_band_cost_cache_generation == 0) {
|
||||||
for (g = 0; g < 128; g++) {
|
memset(s->quantize_band_cost_cache, 0, sizeof(s->quantize_band_cost_cache));
|
||||||
s->quantize_band_cost_cache[sf][g].bits = -1;
|
s->quantize_band_cost_cache_generation = 1;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -84,10 +84,10 @@ extern AACCoefficientsEncoder ff_aac_coders[];
|
|||||||
typedef struct AACQuantizeBandCostCacheEntry {
|
typedef struct AACQuantizeBandCostCacheEntry {
|
||||||
float rd;
|
float rd;
|
||||||
float energy;
|
float energy;
|
||||||
int bits; ///< -1 means uninitialized entry
|
int bits;
|
||||||
char cb;
|
char cb;
|
||||||
char rtz;
|
char rtz;
|
||||||
char padding[2]; ///< Keeps the entry size a multiple of 32 bits
|
uint16_t generation;
|
||||||
} AACQuantizeBandCostCacheEntry;
|
} AACQuantizeBandCostCacheEntry;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -126,6 +126,7 @@ typedef struct AACEncContext {
|
|||||||
DECLARE_ALIGNED(16, int, qcoefs)[96]; ///< quantized coefficients
|
DECLARE_ALIGNED(16, int, qcoefs)[96]; ///< quantized coefficients
|
||||||
DECLARE_ALIGNED(32, float, scoefs)[1024]; ///< scaled coefficients
|
DECLARE_ALIGNED(32, float, scoefs)[1024]; ///< scaled coefficients
|
||||||
|
|
||||||
|
uint16_t quantize_band_cost_cache_generation;
|
||||||
AACQuantizeBandCostCacheEntry quantize_band_cost_cache[256][128]; ///< memoization area for quantize_band_cost
|
AACQuantizeBandCostCacheEntry quantize_band_cost_cache[256][128]; ///< memoization area for quantize_band_cost
|
||||||
|
|
||||||
struct {
|
struct {
|
||||||
|
@@ -36,11 +36,12 @@ static inline float quantize_band_cost_cached(struct AACEncContext *s, int w, in
|
|||||||
AACQuantizeBandCostCacheEntry *entry;
|
AACQuantizeBandCostCacheEntry *entry;
|
||||||
av_assert1(scale_idx >= 0 && scale_idx < 256);
|
av_assert1(scale_idx >= 0 && scale_idx < 256);
|
||||||
entry = &s->quantize_band_cost_cache[scale_idx][w*16+g];
|
entry = &s->quantize_band_cost_cache[scale_idx][w*16+g];
|
||||||
if (entry->bits < 0 || entry->cb != cb || entry->rtz != rtz) {
|
if (entry->generation != s->quantize_band_cost_cache_generation || entry->cb != cb || entry->rtz != rtz) {
|
||||||
entry->rd = quantize_band_cost(s, in, scaled, size, scale_idx,
|
entry->rd = quantize_band_cost(s, in, scaled, size, scale_idx,
|
||||||
cb, lambda, uplim, &entry->bits, &entry->energy, rtz);
|
cb, lambda, uplim, &entry->bits, &entry->energy, rtz);
|
||||||
entry->cb = cb;
|
entry->cb = cb;
|
||||||
entry->rtz = rtz;
|
entry->rtz = rtz;
|
||||||
|
entry->generation = s->quantize_band_cost_cache_generation;
|
||||||
}
|
}
|
||||||
if (bits)
|
if (bits)
|
||||||
*bits = entry->bits;
|
*bits = entry->bits;
|
||||||
|
Reference in New Issue
Block a user