diff mbox series

[FFmpeg-devel,10/17] avcodec/ac3enc: Share more code between fixed/float encoders

Message ID GV1P250MB0737DBC80CBAF0860BCC907B8F012@GV1P250MB0737.EURP250.PROD.OUTLOOK.COM
State Accepted
Commit 2fcc50d1f536a76978d39396afb43f885cc89667
Headers show
Series [FFmpeg-devel,01/17] avcodec/ac3enc: Don't presume ch_layout to be AV_CHANNEL_ORDER_NATIVE | expand

Checks

Context Check Description
yinshiyou/make_loongarch64 success Make finished
yinshiyou/make_fate_loongarch64 success Make fate finished
andriy/make_x86 success Make finished
andriy/make_fate_x86 success Make fate finished

Commit Message

Andreas Rheinhardt April 7, 2024, 9:09 p.m. UTC
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
 libavcodec/ac3enc.c          | 19 +++++++++++++------
 libavcodec/ac3enc.h          |  5 +----
 libavcodec/ac3enc_template.c | 15 +--------------
 3 files changed, 15 insertions(+), 24 deletions(-)
diff mbox series

Patch

diff --git a/libavcodec/ac3enc.c b/libavcodec/ac3enc.c
index 1f05436720..ef1ac381c1 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);
 
@@ -2327,7 +2334,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;
 }