[FFmpeg-cvslog] avcodec/ac3enc: Share more code between fixed/float encoders

Andreas Rheinhardt git at videolan.org
Thu Apr 11 14:00:22 EEST 2024


ffmpeg | branch: master | Andreas Rheinhardt <andreas.rheinhardt at outlook.com> | Sun Apr  7 16:52:52 2024 +0200| [2fcc50d1f536a76978d39396afb43f885cc89667] | committer: Andreas Rheinhardt

avcodec/ac3enc: Share more code between fixed/float encoders

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt at outlook.com>

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=2fcc50d1f536a76978d39396afb43f885cc89667
---

 libavcodec/ac3enc.c          | 19 +++++++++++++------
 libavcodec/ac3enc.h          |  5 +----
 libavcodec/ac3enc_template.c | 15 +--------------
 3 files changed, 15 insertions(+), 24 deletions(-)

diff --git a/libavcodec/ac3enc.c b/libavcodec/ac3enc.c
index c1ac5dd884..e5b0be0969 100644
--- a/libavcodec/ac3enc.c
+++ b/libavcodec/ac3enc.c
@@ -315,7 +315,7 @@ static void validate_mix_level(void *log_ctx, const char *opt_name,
  *
  * @param s  AC-3 encoder private context
  */
-int ff_ac3_validate_metadata(AC3EncodeContext *s)
+static int ac3_validate_metadata(AC3EncodeContext *s)
 {
     AVCodecContext *avctx = s->avctx;
     AC3EncOptions *opt = &s->options;
@@ -488,7 +488,7 @@ int ff_ac3_validate_metadata(AC3EncodeContext *s)
  *
  * @param s  AC-3 encoder private context
  */
-void ff_ac3_adjust_frame_size(AC3EncodeContext *s)
+static void ac3_adjust_frame_size(AC3EncodeContext *s)
 {
     while (s->bits_written >= s->bit_rate && s->samples_written >= s->sample_rate) {
         s->bits_written    -= s->bit_rate;
@@ -1984,9 +1984,16 @@ int ff_ac3_encode_frame(AVCodecContext *avctx, AVPacket *avpkt,
     AC3EncodeContext *const s = avctx->priv_data;
     int ret;
 
-    ret = s->encode_frame(s, frame);
-    if (ret < 0)
-        return ret;
+    if (s->options.allow_per_frame_metadata) {
+        ret = ac3_validate_metadata(s);
+        if (ret)
+            return ret;
+    }
+
+    if (s->bit_alloc.sr_code == 1 || s->eac3)
+        ac3_adjust_frame_size(s);
+
+    s->encode_frame(s, frame);
 
     ac3_apply_rematrixing(s);
 
@@ -2328,7 +2335,7 @@ static av_cold int validate_options(AC3EncodeContext *s)
     if (s->cutoff > (s->sample_rate >> 1))
         s->cutoff = s->sample_rate >> 1;
 
-    ret = ff_ac3_validate_metadata(s);
+    ret = ac3_validate_metadata(s);
     if (ret)
         return ret;
 
diff --git a/libavcodec/ac3enc.h b/libavcodec/ac3enc.h
index 1a51423ac1..3dc8acfd91 100644
--- a/libavcodec/ac3enc.h
+++ b/libavcodec/ac3enc.h
@@ -255,7 +255,7 @@ typedef struct AC3EncodeContext {
     int ref_bap_set;                                         ///< indicates if ref_bap pointers have been set
 
     /** fixed vs. float function pointers */
-    int (*encode_frame)(struct AC3EncodeContext *s, const AVFrame *frame);
+    void (*encode_frame)(struct AC3EncodeContext *s, const AVFrame *frame);
 
     /* fixed vs. float function pointers */
     int  (*mdct_init)(struct AC3EncodeContext *s);
@@ -277,9 +277,6 @@ int ff_ac3_float_encode_init(AVCodecContext *avctx);
 
 int ff_ac3_encode_close(AVCodecContext *avctx);
 
-int ff_ac3_validate_metadata(AC3EncodeContext *s);
-
-void ff_ac3_adjust_frame_size(AC3EncodeContext *s);
 
 void ff_ac3_compute_coupling_strategy(AC3EncodeContext *s);
 
diff --git a/libavcodec/ac3enc_template.c b/libavcodec/ac3enc_template.c
index 2e0fb9e85a..56ce36c012 100644
--- a/libavcodec/ac3enc_template.c
+++ b/libavcodec/ac3enc_template.c
@@ -371,19 +371,8 @@ static void compute_rematrixing_strategy(AC3EncodeContext *s)
 }
 
 
-static int encode_frame(AC3EncodeContext *s, const AVFrame *frame)
+static void encode_frame(AC3EncodeContext *s, const AVFrame *frame)
 {
-    int ret;
-
-    if (s->options.allow_per_frame_metadata) {
-        ret = ff_ac3_validate_metadata(s);
-        if (ret)
-            return ret;
-    }
-
-    if (s->bit_alloc.sr_code == 1 || (AC3ENC_FLOAT && s->eac3))
-        ff_ac3_adjust_frame_size(s);
-
     copy_input_samples(s, (SampleType **)frame->extended_data);
 
     apply_mdct(s);
@@ -399,6 +388,4 @@ static int encode_frame(AC3EncodeContext *s, const AVFrame *frame)
 #if AC3ENC_FLOAT
     scale_coefficients(s);
 #endif
-
-    return 0;
 }



More information about the ffmpeg-cvslog mailing list