From: Andreas Rheinhardt <andreas.rheinhardt@outlook.com> To: ffmpeg-devel@ffmpeg.org Cc: Andreas Rheinhardt <andreas.rheinhardt@outlook.com> Subject: [FFmpeg-devel] [PATCH 08/17] avcodec/ac3enc: Use common encode_frame function Date: Sun, 7 Apr 2024 23:09:06 +0200 Message-ID: <GV1P250MB07378384BB12F4D73975ABE48F012@GV1P250MB0737.EURP250.PROD.OUTLOOK.COM> (raw) In-Reply-To: <GV1P250MB073758D71A50C11C0A3C26CE8F012@GV1P250MB0737.EURP250.PROD.OUTLOOK.COM> This is in preparation for sharing even more stuff common to the fixed and floating-point encoders. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com> --- 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 12bd3b25f3..c19837e88f 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 }, -- 2.40.1 _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
next prev parent reply other threads:[~2024-04-07 21:10 UTC|newest] Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top 2024-04-07 20:39 [FFmpeg-devel] [PATCH 01/17] avcodec/ac3enc: Don't presume ch_layout to be AV_CHANNEL_ORDER_NATIVE Andreas Rheinhardt 2024-04-07 20:51 ` James Almer 2024-04-07 21:53 ` Andreas Rheinhardt 2024-04-07 22:21 ` James Almer 2024-04-07 22:26 ` Andreas Rheinhardt 2024-04-07 22:35 ` James Almer 2024-04-07 21:09 ` [FFmpeg-devel] [PATCH 02/17] avcodec/ac3enc: Don't overwrite AVCodecContext.ch_layout Andreas Rheinhardt 2024-04-07 21:09 ` [FFmpeg-devel] [PATCH 03/17] avcodec/ac3enc: Remove redundant channel layout checks Andreas Rheinhardt 2024-04-07 21:09 ` [FFmpeg-devel] [PATCH 04/17] avcodec/ac3enc: Use bit-operations for bit-mask Andreas Rheinhardt 2024-04-07 21:09 ` [FFmpeg-devel] [PATCH 05/17] avcodec/ac3enc: Avoid copying strings Andreas Rheinhardt 2024-04-07 21:09 ` [FFmpeg-devel] [PATCH 06/17] avcodec/ac3enc: Remove always-false sample rate check Andreas Rheinhardt 2024-04-07 21:09 ` [FFmpeg-devel] [PATCH 07/17] avcodec/ac3enc: Remove disabled code for RealAudio variant of AC-3 Andreas Rheinhardt 2024-04-07 21:09 ` Andreas Rheinhardt [this message] 2024-04-07 21:09 ` [FFmpeg-devel] [PATCH 09/17] avcodec/ac3enc: Move ff_ac3_validate_metadate() upwards Andreas Rheinhardt 2024-04-07 21:09 ` [FFmpeg-devel] [PATCH 10/17] avcodec/ac3enc: Share more code between fixed/float encoders Andreas Rheinhardt 2024-04-07 21:09 ` [FFmpeg-devel] [PATCH 11/17] avcodec/ac3enc: Deduplicate allocating buffers Andreas Rheinhardt 2024-04-07 21:09 ` [FFmpeg-devel] [PATCH 12/17] avcodec/ac3enc: Deduplicate copying input samples Andreas Rheinhardt 2024-04-07 21:09 ` [FFmpeg-devel] [PATCH 13/17] avcodec/ac3enc_float: Remove uninformative error message Andreas Rheinhardt 2024-04-07 21:09 ` [FFmpeg-devel] [PATCH 14/17] avcodec/ac3enc: Avoid function pointers to initialize MDCT Andreas Rheinhardt 2024-04-07 21:09 ` [FFmpeg-devel] [PATCH 15/17] avcodec/ac3enc: Move EAC-3 specific initialization to eac3enc.c Andreas Rheinhardt 2024-04-07 21:09 ` [FFmpeg-devel] [PATCH 16/17] avcodec/flacenc: Avoid shift where possible Andreas Rheinhardt 2024-04-07 21:09 ` [FFmpeg-devel] [PATCH 17/17] avformat/img2: Avoid relocations for ff_img_tags Andreas Rheinhardt 2024-04-08 0:56 ` [FFmpeg-devel] [PATCH 18/18] avcodec/ac3enc: Avoid calculating the CRC multiple times Andreas Rheinhardt 2024-04-10 6:16 ` [FFmpeg-devel] [PATCH 01/17] avcodec/ac3enc: Don't presume ch_layout to be AV_CHANNEL_ORDER_NATIVE Andreas Rheinhardt
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=GV1P250MB07378384BB12F4D73975ABE48F012@GV1P250MB0737.EURP250.PROD.OUTLOOK.COM \ --to=andreas.rheinhardt@outlook.com \ --cc=ffmpeg-devel@ffmpeg.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: link
Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel This inbox may be cloned and mirrored by anyone: git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git # If you have public-inbox 1.1+ installed, you may # initialize and index your mirror using the following commands: public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \ ffmpegdev@gitmailbox.com public-inbox-index ffmpegdev Example config snippet for mirrors. AGPL code for this site: git clone https://public-inbox.org/public-inbox.git