[FFmpeg-cvslog] avcodec/ac3enc: Use common encode_frame function

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


ffmpeg | branch: master | Andreas Rheinhardt <andreas.rheinhardt at outlook.com> | Sun Apr  7 16:39:59 2024 +0200| [6244ecf8ec6dabecea6ee7ee885e6ab827abf6cb] | committer: Andreas Rheinhardt

avcodec/ac3enc: Use common encode_frame function

This is in preparation for sharing even more stuff
common to the fixed and floating-point encoders.

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

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

 libavcodec/ac3enc.c          |  8 ++++++--
 libavcodec/ac3enc.h          | 16 +++++-----------
 libavcodec/ac3enc_fixed.c    |  3 ++-
 libavcodec/ac3enc_float.c    |  4 +++-
 libavcodec/ac3enc_template.c |  6 ++----
 libavcodec/eac3enc.c         |  2 +-
 6 files changed, 19 insertions(+), 20 deletions(-)

diff --git a/libavcodec/ac3enc.c b/libavcodec/ac3enc.c
index d26b52e9b9..22ec9e308e 100644
--- a/libavcodec/ac3enc.c
+++ b/libavcodec/ac3enc.c
@@ -1769,12 +1769,16 @@ static void ac3_output_frame(AC3EncodeContext *s, unsigned char *frame)
     output_frame_end(s);
 }
 
-int ff_ac3_encode_frame_common_end(AVCodecContext *avctx, AVPacket *avpkt,
-                                   const AVFrame *frame, int *got_packet_ptr)
+int ff_ac3_encode_frame(AVCodecContext *avctx, AVPacket *avpkt,
+                        const AVFrame *frame, int *got_packet_ptr)
 {
     AC3EncodeContext *const s = avctx->priv_data;
     int ret;
 
+    ret = s->encode_frame(s, frame);
+    if (ret < 0)
+        return ret;
+
     ac3_apply_rematrixing(s);
 
     ac3_process_exponents(s);
diff --git a/libavcodec/ac3enc.h b/libavcodec/ac3enc.h
index dad53cc4bb..1a51423ac1 100644
--- a/libavcodec/ac3enc.h
+++ b/libavcodec/ac3enc.h
@@ -49,7 +49,6 @@
 
 #if AC3ENC_FLOAT
 #include "libavutil/float_dsp.h"
-#define AC3_NAME(x) ff_ac3_float_ ## x
 #define MAC_COEF(d,a,b) ((d)+=(a)*(b))
 #define COEF_MIN (-16777215.0/16777216.0)
 #define COEF_MAX ( 16777215.0/16777216.0)
@@ -59,7 +58,6 @@ typedef float CoefType;
 typedef float CoefSumType;
 #else
 #include "libavutil/fixed_dsp.h"
-#define AC3_NAME(x) ff_ac3_fixed_ ## x
 #define MAC_COEF(d,a,b) MAC64(d,a,b)
 #define COEF_MIN -16777215
 #define COEF_MAX  16777215
@@ -256,6 +254,9 @@ typedef struct AC3EncodeContext {
     uint8_t *ref_bap     [AC3_MAX_CHANNELS][AC3_MAX_BLOCKS]; ///< bit allocation pointers (bap)
     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);
+
     /* fixed vs. float function pointers */
     int  (*mdct_init)(struct AC3EncodeContext *s);
 
@@ -282,14 +283,7 @@ void ff_ac3_adjust_frame_size(AC3EncodeContext *s);
 
 void ff_ac3_compute_coupling_strategy(AC3EncodeContext *s);
 
-int ff_ac3_encode_frame_common_end(AVCodecContext *avctx, AVPacket *avpkt,
-                                   const AVFrame *frame, int *got_packet_ptr);
-
-/* prototypes for functions in ac3enc_template.c */
-
-int ff_ac3_fixed_encode_frame(AVCodecContext *avctx, AVPacket *avpkt,
-                              const AVFrame *frame, int *got_packet_ptr);
-int ff_ac3_float_encode_frame(AVCodecContext *avctx, AVPacket *avpkt,
-                              const AVFrame *frame, int *got_packet_ptr);
+int ff_ac3_encode_frame(AVCodecContext *avctx, AVPacket *avpkt,
+                        const AVFrame *frame, int *got_packet_ptr);
 
 #endif /* AVCODEC_AC3ENC_H */
diff --git a/libavcodec/ac3enc_fixed.c b/libavcodec/ac3enc_fixed.c
index c399d6cd09..4a24cce833 100644
--- a/libavcodec/ac3enc_fixed.c
+++ b/libavcodec/ac3enc_fixed.c
@@ -102,6 +102,7 @@ static av_cold int ac3_fixed_encode_init(AVCodecContext *avctx)
 {
     AC3EncodeContext *s = avctx->priv_data;
     s->fixed_point = 1;
+    s->encode_frame            = encode_frame;
     s->mdct_init               = ac3_fixed_mdct_init;
     s->allocate_sample_buffers = allocate_sample_buffers;
     return ff_ac3_encode_init(avctx);
@@ -116,7 +117,7 @@ const FFCodec ff_ac3_fixed_encoder = {
     .p.capabilities  = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_ENCODER_REORDERED_OPAQUE,
     .priv_data_size  = sizeof(AC3EncodeContext),
     .init            = ac3_fixed_encode_init,
-    FF_CODEC_ENCODE_CB(ff_ac3_fixed_encode_frame),
+    FF_CODEC_ENCODE_CB(ff_ac3_encode_frame),
     .close           = ff_ac3_encode_close,
     .p.sample_fmts   = (const enum AVSampleFormat[]){ AV_SAMPLE_FMT_S32P,
                                                       AV_SAMPLE_FMT_NONE },
diff --git a/libavcodec/ac3enc_float.c b/libavcodec/ac3enc_float.c
index 24960f318b..e0907fed05 100644
--- a/libavcodec/ac3enc_float.c
+++ b/libavcodec/ac3enc_float.c
@@ -104,6 +104,8 @@ static av_cold int ac3_float_mdct_init(AC3EncodeContext *s)
 av_cold int ff_ac3_float_encode_init(AVCodecContext *avctx)
 {
     AC3EncodeContext *s = avctx->priv_data;
+
+    s->encode_frame            = encode_frame;
     s->mdct_init               = ac3_float_mdct_init;
     s->allocate_sample_buffers = allocate_sample_buffers;
     s->fdsp = avpriv_float_dsp_alloc(avctx->flags & AV_CODEC_FLAG_BITEXACT);
@@ -120,7 +122,7 @@ const FFCodec ff_ac3_encoder = {
     .p.capabilities  = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_ENCODER_REORDERED_OPAQUE,
     .priv_data_size  = sizeof(AC3EncodeContext),
     .init            = ff_ac3_float_encode_init,
-    FF_CODEC_ENCODE_CB(ff_ac3_float_encode_frame),
+    FF_CODEC_ENCODE_CB(ff_ac3_encode_frame),
     .close           = ff_ac3_encode_close,
     .p.sample_fmts   = (const enum AVSampleFormat[]){ AV_SAMPLE_FMT_FLTP,
                                                       AV_SAMPLE_FMT_NONE },
diff --git a/libavcodec/ac3enc_template.c b/libavcodec/ac3enc_template.c
index 45dbc98804..2e0fb9e85a 100644
--- a/libavcodec/ac3enc_template.c
+++ b/libavcodec/ac3enc_template.c
@@ -371,10 +371,8 @@ static void compute_rematrixing_strategy(AC3EncodeContext *s)
 }
 
 
-int AC3_NAME(encode_frame)(AVCodecContext *avctx, AVPacket *avpkt,
-                           const AVFrame *frame, int *got_packet_ptr)
+static int encode_frame(AC3EncodeContext *s, const AVFrame *frame)
 {
-    AC3EncodeContext *s = avctx->priv_data;
     int ret;
 
     if (s->options.allow_per_frame_metadata) {
@@ -402,5 +400,5 @@ int AC3_NAME(encode_frame)(AVCodecContext *avctx, AVPacket *avpkt,
     scale_coefficients(s);
 #endif
 
-    return ff_ac3_encode_frame_common_end(avctx, avpkt, frame, got_packet_ptr);
+    return 0;
 }
diff --git a/libavcodec/eac3enc.c b/libavcodec/eac3enc.c
index 5deda083c3..1ee140f13a 100644
--- a/libavcodec/eac3enc.c
+++ b/libavcodec/eac3enc.c
@@ -252,7 +252,7 @@ const FFCodec ff_eac3_encoder = {
     .p.capabilities  = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_ENCODER_REORDERED_OPAQUE,
     .priv_data_size  = sizeof(AC3EncodeContext),
     .init            = ff_ac3_float_encode_init,
-    FF_CODEC_ENCODE_CB(ff_ac3_float_encode_frame),
+    FF_CODEC_ENCODE_CB(ff_ac3_encode_frame),
     .close           = ff_ac3_encode_close,
     .p.sample_fmts   = (const enum AVSampleFormat[]){ AV_SAMPLE_FMT_FLTP,
                                                       AV_SAMPLE_FMT_NONE },



More information about the ffmpeg-cvslog mailing list