]> git.sesse.net Git - ffmpeg/blobdiff - libavcodec/aacenc_utils.h
Merge commit '458e53f51fc75d08df884f8e9eb3d7ded23e97b3'
[ffmpeg] / libavcodec / aacenc_utils.h
index 40e174663908352963f035ff35dfad4b33691721..736e4a06dadea0732390aeec14a99043002e61ac 100644 (file)
@@ -183,12 +183,65 @@ static av_always_inline float bval2bmax(float b)
 }
 
 /*
- * linear congruential pseudorandom number generator, copied from the decoder
+ * Compute a nextband map to be used with SF delta constraint utilities.
+ * The nextband array should contain 128 elements, and positions that don't
+ * map to valid, nonzero bands of the form w*16+g (with w being the initial
+ * window of the window group, only) are left indetermined.
  */
-static inline int lcg_random(unsigned previous_val)
+static inline void ff_init_nextband_map(const SingleChannelElement *sce, uint8_t *nextband)
 {
-    union { unsigned u; int s; } v = { previous_val * 1664525u + 1013904223 };
-    return v.s;
+    unsigned char prevband = 0;
+    int w, g;
+    /** Just a safe default */
+    for (g = 0; g < 128; g++)
+        nextband[g] = g;
+
+    /** Now really navigate the nonzero band chain */
+    for (w = 0; w < sce->ics.num_windows; w += sce->ics.group_len[w]) {
+        for (g = 0; g < sce->ics.num_swb; g++) {
+            if (!sce->zeroes[w*16+g] && sce->band_type[w*16+g] < RESERVED_BT)
+                prevband = nextband[prevband] = w*16+g;
+        }
+    }
+    nextband[prevband] = prevband; /* terminate */
+}
+
+/*
+ * Updates nextband to reflect a removed band (equivalent to
+ * calling ff_init_nextband_map after marking a band as zero)
+ */
+static inline void ff_nextband_remove(uint8_t *nextband, int prevband, int band)
+{
+    nextband[prevband] = nextband[band];
+}
+
+/*
+ * Checks whether the specified band could be removed without inducing
+ * scalefactor delta that violates SF delta encoding constraints.
+ * prev_sf has to be the scalefactor of the previous nonzero, nonspecial
+ * band, in encoding order, or negative if there was no such band.
+ */
+static inline int ff_sfdelta_can_remove_band(const SingleChannelElement *sce,
+    const uint8_t *nextband, int prev_sf, int band)
+{
+    return prev_sf >= 0
+        && sce->sf_idx[nextband[band]] >= (prev_sf - SCALE_MAX_DIFF)
+        && sce->sf_idx[nextband[band]] <= (prev_sf + SCALE_MAX_DIFF);
+}
+
+/*
+ * Checks whether the specified band's scalefactor could be replaced
+ * with another one without violating SF delta encoding constraints.
+ * prev_sf has to be the scalefactor of the previous nonzero, nonsepcial
+ * band, in encoding order, or negative if there was no such band.
+ */
+static inline int ff_sfdelta_can_replace(const SingleChannelElement *sce,
+    const uint8_t *nextband, int prev_sf, int new_sf, int band)
+{
+    return new_sf >= (prev_sf - SCALE_MAX_DIFF)
+        && new_sf <= (prev_sf + SCALE_MAX_DIFF)
+        && sce->sf_idx[nextband[band]] >= (new_sf - SCALE_MAX_DIFF)
+        && sce->sf_idx[nextband[band]] <= (new_sf + SCALE_MAX_DIFF);
 }
 
 #define ERROR_IF(cond, ...) \