History

avcodec/ac3enc: Use common encode_frame function

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

Andreas Rheinhardt committed 2 years ago

Commit 6244ecf1 parent fee093a6 files · +19 −20Browse files

Showing the changes to libavcodec (6 of 6 files). Show all

Unified · Split

6 files
  1. libavcodec/ac3enc.c +6 −2
  2. libavcodec/ac3enc.h +5 −11
  3. libavcodec/ac3enc_fixed.c +2 −1
  4. libavcodec/ac3enc_float.c +3 −1
  5. libavcodec/ac3enc_template.c +2 −4
  6. libavcodec/eac3enc.c +1 −1
libavcodec/ac3enc.c+6−2
@@ -1769,12 +1769,16 @@ static void ac3_output_frame(AC3EncodeContext *s, unsigned char *frame) · 1768 unmodified lines
17691769 output_frame_end(s);
17701770 }
17711771
1772−int ff_ac3_encode_frame_common_end(AVCodecContext *avctx, AVPacket *avpkt,
1773− const AVFrame *frame, int *got_packet_ptr)
1772+int ff_ac3_encode_frame(AVCodecContext *avctx, AVPacket *avpkt,
1773+ const AVFrame *frame, int *got_packet_ptr)
17741774 {
17751775 AC3EncodeContext *const s = avctx->priv_data;
17761776 int ret;
17771777
1778+ ret = s->encode_frame(s, frame);
1779+ if (ret < 0)
1780+ return ret;
1781+
17781782 ac3_apply_rematrixing(s);
17791783
17801784 ac3_process_exponents(s);
libavcodec/ac3enc.h+5−11
@@ -49,7 +49,6 @@ · 48 unmodified lines
4949
5050 #if AC3ENC_FLOAT
5151 #include "libavutil/float_dsp.h"
52−#define AC3_NAME(x) ff_ac3_float_ ## x
5352 #define MAC_COEF(d,a,b) ((d)+=(a)*(b))
5453 #define COEF_MIN (-16777215.0/16777216.0)
5554 #define COEF_MAX ( 16777215.0/16777216.0)
@@ -59,7 +58,6 @@ typedef float CoefType; · 3 unmodified lines
5958 typedef float CoefSumType;
6059 #else
6160 #include "libavutil/fixed_dsp.h"
62−#define AC3_NAME(x) ff_ac3_fixed_ ## x
6361 #define MAC_COEF(d,a,b) MAC64(d,a,b)
6462 #define COEF_MIN -16777215
6563 #define COEF_MAX 16777215
@@ -256,6 +254,9 @@ typedef struct AC3EncodeContext { · 190 unmodified lines
256254 uint8_t *ref_bap [AC3_MAX_CHANNELS][AC3_MAX_BLOCKS]; ///< bit allocation pointers (bap)
257255 int ref_bap_set; ///< indicates if ref_bap pointers have been set
258256
257+ /** fixed vs. float function pointers */
258+ int (*encode_frame)(struct AC3EncodeContext *s, const AVFrame *frame);
259+
259260 /* fixed vs. float function pointers */
260261 int (*mdct_init)(struct AC3EncodeContext *s);
261262
@@ -282,14 +283,7 @@ void ff_ac3_adjust_frame_size(AC3EncodeContext *s); · 20 unmodified lines
282283
283284 void ff_ac3_compute_coupling_strategy(AC3EncodeContext *s);
284285
285−int ff_ac3_encode_frame_common_end(AVCodecContext *avctx, AVPacket *avpkt,
286− const AVFrame *frame, int *got_packet_ptr);
287−
288−/* prototypes for functions in ac3enc_template.c */
289−
290−int ff_ac3_fixed_encode_frame(AVCodecContext *avctx, AVPacket *avpkt,
291− const AVFrame *frame, int *got_packet_ptr);
292−int ff_ac3_float_encode_frame(AVCodecContext *avctx, AVPacket *avpkt,
293− const AVFrame *frame, int *got_packet_ptr);
286+int ff_ac3_encode_frame(AVCodecContext *avctx, AVPacket *avpkt,
287+ const AVFrame *frame, int *got_packet_ptr);
294288
295289 #endif /* AVCODEC_AC3ENC_H */
libavcodec/ac3enc_fixed.c+2−1
@@ -102,6 +102,7 @@ static av_cold int ac3_fixed_encode_init(AVCodecContext *avctx) · 101 unmodified lines
102102 {
103103 AC3EncodeContext *s = avctx->priv_data;
104104 s->fixed_point = 1;
105+ s->encode_frame = encode_frame;
105106 s->mdct_init = ac3_fixed_mdct_init;
106107 s->allocate_sample_buffers = allocate_sample_buffers;
107108 return ff_ac3_encode_init(avctx);
@@ -116,7 +117,7 @@ const FFCodec ff_ac3_fixed_encoder = { · 8 unmodified lines
116117 .p.capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_ENCODER_REORDERED_OPAQUE,
117118 .priv_data_size = sizeof(AC3EncodeContext),
118119 .init = ac3_fixed_encode_init,
119− FF_CODEC_ENCODE_CB(ff_ac3_fixed_encode_frame),
120+ FF_CODEC_ENCODE_CB(ff_ac3_encode_frame),
120121 .close = ff_ac3_encode_close,
121122 .p.sample_fmts = (const enum AVSampleFormat[]){ AV_SAMPLE_FMT_S32P,
122123 AV_SAMPLE_FMT_NONE },
libavcodec/ac3enc_float.c+3−1
@@ -104,6 +104,8 @@ static av_cold int ac3_float_mdct_init(AC3EncodeContext *s) · 103 unmodified lines
104104 av_cold int ff_ac3_float_encode_init(AVCodecContext *avctx)
105105 {
106106 AC3EncodeContext *s = avctx->priv_data;
107+
108+ s->encode_frame = encode_frame;
107109 s->mdct_init = ac3_float_mdct_init;
108110 s->allocate_sample_buffers = allocate_sample_buffers;
109111 s->fdsp = avpriv_float_dsp_alloc(avctx->flags & AV_CODEC_FLAG_BITEXACT);
@@ -120,7 +122,7 @@ const FFCodec ff_ac3_encoder = { · 10 unmodified lines
120122 .p.capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_ENCODER_REORDERED_OPAQUE,
121123 .priv_data_size = sizeof(AC3EncodeContext),
122124 .init = ff_ac3_float_encode_init,
123− FF_CODEC_ENCODE_CB(ff_ac3_float_encode_frame),
125+ FF_CODEC_ENCODE_CB(ff_ac3_encode_frame),
124126 .close = ff_ac3_encode_close,
125127 .p.sample_fmts = (const enum AVSampleFormat[]){ AV_SAMPLE_FMT_FLTP,
126128 AV_SAMPLE_FMT_NONE },
libavcodec/ac3enc_template.c+2−4
@@ -371,10 +371,8 @@ static void compute_rematrixing_strategy(AC3EncodeContext *s) · 370 unmodified lines
371371 }
372372
373373
374−int AC3_NAME(encode_frame)(AVCodecContext *avctx, AVPacket *avpkt,
375− const AVFrame *frame, int *got_packet_ptr)
374+static int encode_frame(AC3EncodeContext *s, const AVFrame *frame)
376375 {
377− AC3EncodeContext *s = avctx->priv_data;
378376 int ret;
379377
380378 if (s->options.allow_per_frame_metadata) {
@@ -402,5 +400,5 @@ int AC3_NAME(encode_frame)(AVCodecContext *avctx, AVPacket *avpkt, · 21 unmodified lines
402400 scale_coefficients(s);
403401 #endif
404402
405− return ff_ac3_encode_frame_common_end(avctx, avpkt, frame, got_packet_ptr);
403+ return 0;
406404 }
libavcodec/eac3enc.c+1−1
@@ -252,7 +252,7 @@ const FFCodec ff_eac3_encoder = { · 251 unmodified lines
252252 .p.capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_ENCODER_REORDERED_OPAQUE,
253253 .priv_data_size = sizeof(AC3EncodeContext),
254254 .init = ff_ac3_float_encode_init,
255− FF_CODEC_ENCODE_CB(ff_ac3_float_encode_frame),
255+ FF_CODEC_ENCODE_CB(ff_ac3_encode_frame),
256256 .close = ff_ac3_encode_close,
257257 .p.sample_fmts = (const enum AVSampleFormat[]){ AV_SAMPLE_FMT_FLTP,
258258 AV_SAMPLE_FMT_NONE },

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t