This is in preparation for sharing even more stuff common to the fixed and floating-point encoders.
Showing the changes to libavcodec (6 of 6 files). Show all
Unified · Split
| @@ -1769,12 +1769,16 @@ static void ac3_output_frame(AC3EncodeContext *s, unsigned char *frame) · 1768 unmodified lines | |||
| 1769 | output_frame_end(s); | 1769 | output_frame_end(s); |
| 1770 | } | 1770 | } |
| 1771 | 1771 | ||
| 1772 | int ff_ac3_encode_frame_common_end(AVCodecContext *avctx, AVPacket *avpkt, | 1772 | int ff_ac3_encode_frame(AVCodecContext *avctx, AVPacket *avpkt, |
| 1773 | const AVFrame *frame, int *got_packet_ptr) | 1773 | const AVFrame *frame, int *got_packet_ptr) |
| 1774 | { | 1774 | { |
| 1775 | AC3EncodeContext *const s = avctx->priv_data; | 1775 | AC3EncodeContext *const s = avctx->priv_data; |
| 1776 | int ret; | 1776 | int ret; |
| 1777 | 1777 | ||
| 1778 | ret = s->encode_frame(s, frame); | ||
| 1779 | if (ret < 0) | ||
| 1780 | return ret; | ||
| 1781 | |||
| 1778 | ac3_apply_rematrixing(s); | 1782 | ac3_apply_rematrixing(s); |
| 1779 | 1783 | ||
| 1780 | ac3_process_exponents(s); | 1784 | ac3_process_exponents(s); |
| @@ -49,7 +49,6 @@ · 48 unmodified lines | |||
| 49 | 49 | ||
| 50 | #if AC3ENC_FLOAT | 50 | #if AC3ENC_FLOAT |
| 51 | #include "libavutil/float_dsp.h" | 51 | #include "libavutil/float_dsp.h" |
| 52 | #define AC3_NAME(x) ff_ac3_float_ ## x | ||
| 53 | #define MAC_COEF(d,a,b) ((d)+=(a)*(b)) | 52 | #define MAC_COEF(d,a,b) ((d)+=(a)*(b)) |
| 54 | #define COEF_MIN (-16777215.0/16777216.0) | 53 | #define COEF_MIN (-16777215.0/16777216.0) |
| 55 | #define COEF_MAX ( 16777215.0/16777216.0) | 54 | #define COEF_MAX ( 16777215.0/16777216.0) |
| @@ -59,7 +58,6 @@ typedef float CoefType; · 3 unmodified lines | |||
| 59 | typedef float CoefSumType; | 58 | typedef float CoefSumType; |
| 60 | #else | 59 | #else |
| 61 | #include "libavutil/fixed_dsp.h" | 60 | #include "libavutil/fixed_dsp.h" |
| 62 | #define AC3_NAME(x) ff_ac3_fixed_ ## x | ||
| 63 | #define MAC_COEF(d,a,b) MAC64(d,a,b) | 61 | #define MAC_COEF(d,a,b) MAC64(d,a,b) |
| 64 | #define COEF_MIN -16777215 | 62 | #define COEF_MIN -16777215 |
| 65 | #define COEF_MAX 16777215 | 63 | #define COEF_MAX 16777215 |
| @@ -256,6 +254,9 @@ typedef struct AC3EncodeContext { · 190 unmodified lines | |||
| 256 | uint8_t *ref_bap [AC3_MAX_CHANNELS][AC3_MAX_BLOCKS]; ///< bit allocation pointers (bap) | 254 | uint8_t *ref_bap [AC3_MAX_CHANNELS][AC3_MAX_BLOCKS]; ///< bit allocation pointers (bap) |
| 257 | int ref_bap_set; ///< indicates if ref_bap pointers have been set | 255 | int ref_bap_set; ///< indicates if ref_bap pointers have been set |
| 258 | 256 | ||
| 257 | /** fixed vs. float function pointers */ | ||
| 258 | int (*encode_frame)(struct AC3EncodeContext *s, const AVFrame *frame); | ||
| 259 | |||
| 259 | /* fixed vs. float function pointers */ | 260 | /* fixed vs. float function pointers */ |
| 260 | int (*mdct_init)(struct AC3EncodeContext *s); | 261 | int (*mdct_init)(struct AC3EncodeContext *s); |
| 261 | 262 | ||
| @@ -282,14 +283,7 @@ void ff_ac3_adjust_frame_size(AC3EncodeContext *s); · 20 unmodified lines | |||
| 282 | 283 | ||
| 283 | void ff_ac3_compute_coupling_strategy(AC3EncodeContext *s); | 284 | void ff_ac3_compute_coupling_strategy(AC3EncodeContext *s); |
| 284 | 285 | ||
| 285 | int ff_ac3_encode_frame_common_end(AVCodecContext *avctx, AVPacket *avpkt, | 286 | int ff_ac3_encode_frame(AVCodecContext *avctx, AVPacket *avpkt, |
| 286 | const AVFrame *frame, int *got_packet_ptr); | 287 | 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); | ||
| 294 | 288 | ||
| 295 | #endif /* AVCODEC_AC3ENC_H */ | 289 | #endif /* AVCODEC_AC3ENC_H */ |
| @@ -102,6 +102,7 @@ static av_cold int ac3_fixed_encode_init(AVCodecContext *avctx) · 101 unmodified lines | |||
| 102 | { | 102 | { |
| 103 | AC3EncodeContext *s = avctx->priv_data; | 103 | AC3EncodeContext *s = avctx->priv_data; |
| 104 | s->fixed_point = 1; | 104 | s->fixed_point = 1; |
| 105 | s->encode_frame = encode_frame; | ||
| 105 | s->mdct_init = ac3_fixed_mdct_init; | 106 | s->mdct_init = ac3_fixed_mdct_init; |
| 106 | s->allocate_sample_buffers = allocate_sample_buffers; | 107 | s->allocate_sample_buffers = allocate_sample_buffers; |
| 107 | return ff_ac3_encode_init(avctx); | 108 | return ff_ac3_encode_init(avctx); |
| @@ -116,7 +117,7 @@ const FFCodec ff_ac3_fixed_encoder = { · 8 unmodified lines | |||
| 116 | .p.capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_ENCODER_REORDERED_OPAQUE, | 117 | .p.capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_ENCODER_REORDERED_OPAQUE, |
| 117 | .priv_data_size = sizeof(AC3EncodeContext), | 118 | .priv_data_size = sizeof(AC3EncodeContext), |
| 118 | .init = ac3_fixed_encode_init, | 119 | .init = ac3_fixed_encode_init, |
| 119 | FF_CODEC_ENCODE_CB(ff_ac3_fixed_encode_frame), | 120 | FF_CODEC_ENCODE_CB(ff_ac3_encode_frame), |
| 120 | .close = ff_ac3_encode_close, | 121 | .close = ff_ac3_encode_close, |
| 121 | .p.sample_fmts = (const enum AVSampleFormat[]){ AV_SAMPLE_FMT_S32P, | 122 | .p.sample_fmts = (const enum AVSampleFormat[]){ AV_SAMPLE_FMT_S32P, |
| 122 | AV_SAMPLE_FMT_NONE }, | 123 | AV_SAMPLE_FMT_NONE }, |
| @@ -104,6 +104,8 @@ static av_cold int ac3_float_mdct_init(AC3EncodeContext *s) · 103 unmodified lines | |||
| 104 | av_cold int ff_ac3_float_encode_init(AVCodecContext *avctx) | 104 | av_cold int ff_ac3_float_encode_init(AVCodecContext *avctx) |
| 105 | { | 105 | { |
| 106 | AC3EncodeContext *s = avctx->priv_data; | 106 | AC3EncodeContext *s = avctx->priv_data; |
| 107 | |||
| 108 | s->encode_frame = encode_frame; | ||
| 107 | s->mdct_init = ac3_float_mdct_init; | 109 | s->mdct_init = ac3_float_mdct_init; |
| 108 | s->allocate_sample_buffers = allocate_sample_buffers; | 110 | s->allocate_sample_buffers = allocate_sample_buffers; |
| 109 | s->fdsp = avpriv_float_dsp_alloc(avctx->flags & AV_CODEC_FLAG_BITEXACT); | 111 | s->fdsp = avpriv_float_dsp_alloc(avctx->flags & AV_CODEC_FLAG_BITEXACT); |
| @@ -120,7 +122,7 @@ const FFCodec ff_ac3_encoder = { · 10 unmodified lines | |||
| 120 | .p.capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_ENCODER_REORDERED_OPAQUE, | 122 | .p.capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_ENCODER_REORDERED_OPAQUE, |
| 121 | .priv_data_size = sizeof(AC3EncodeContext), | 123 | .priv_data_size = sizeof(AC3EncodeContext), |
| 122 | .init = ff_ac3_float_encode_init, | 124 | .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), |
| 124 | .close = ff_ac3_encode_close, | 126 | .close = ff_ac3_encode_close, |
| 125 | .p.sample_fmts = (const enum AVSampleFormat[]){ AV_SAMPLE_FMT_FLTP, | 127 | .p.sample_fmts = (const enum AVSampleFormat[]){ AV_SAMPLE_FMT_FLTP, |
| 126 | AV_SAMPLE_FMT_NONE }, | 128 | AV_SAMPLE_FMT_NONE }, |
| @@ -371,10 +371,8 @@ static void compute_rematrixing_strategy(AC3EncodeContext *s) · 370 unmodified lines | |||
| 371 | } | 371 | } |
| 372 | 372 | ||
| 373 | 373 | ||
| 374 | int AC3_NAME(encode_frame)(AVCodecContext *avctx, AVPacket *avpkt, | 374 | static int encode_frame(AC3EncodeContext *s, const AVFrame *frame) |
| 375 | const AVFrame *frame, int *got_packet_ptr) | ||
| 376 | { | 375 | { |
| 377 | AC3EncodeContext *s = avctx->priv_data; | ||
| 378 | int ret; | 376 | int ret; |
| 379 | 377 | ||
| 380 | if (s->options.allow_per_frame_metadata) { | 378 | if (s->options.allow_per_frame_metadata) { |
| @@ -402,5 +400,5 @@ int AC3_NAME(encode_frame)(AVCodecContext *avctx, AVPacket *avpkt, · 21 unmodified lines | |||
| 402 | scale_coefficients(s); | 400 | scale_coefficients(s); |
| 403 | #endif | 401 | #endif |
| 404 | 402 | ||
| 405 | return ff_ac3_encode_frame_common_end(avctx, avpkt, frame, got_packet_ptr); | 403 | return 0; |
| 406 | } | 404 | } |
| @@ -252,7 +252,7 @@ const FFCodec ff_eac3_encoder = { · 251 unmodified lines | |||
| 252 | .p.capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_ENCODER_REORDERED_OPAQUE, | 252 | .p.capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_ENCODER_REORDERED_OPAQUE, |
| 253 | .priv_data_size = sizeof(AC3EncodeContext), | 253 | .priv_data_size = sizeof(AC3EncodeContext), |
| 254 | .init = ff_ac3_float_encode_init, | 254 | .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), |
| 256 | .close = ff_ac3_encode_close, | 256 | .close = ff_ac3_encode_close, |
| 257 | .p.sample_fmts = (const enum AVSampleFormat[]){ AV_SAMPLE_FMT_FLTP, | 257 | .p.sample_fmts = (const enum AVSampleFormat[]){ AV_SAMPLE_FMT_FLTP, |
| 258 | AV_SAMPLE_FMT_NONE }, | 258 | AV_SAMPLE_FMT_NONE }, |