]> git.sesse.net Git - ffmpeg/blob - libavcodec/aacenc.h
Merge commit '458e53f51fc75d08df884f8e9eb3d7ded23e97b3'
[ffmpeg] / libavcodec / aacenc.h
1 /*
2  * AAC encoder
3  * Copyright (C) 2008 Konstantin Shishkov
4  *
5  * This file is part of FFmpeg.
6  *
7  * FFmpeg is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * FFmpeg is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with FFmpeg; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20  */
21
22 #ifndef AVCODEC_AACENC_H
23 #define AVCODEC_AACENC_H
24
25 #include "libavutil/float_dsp.h"
26 #include "libavutil/lfg.h"
27 #include "avcodec.h"
28 #include "put_bits.h"
29
30 #include "aac.h"
31 #include "audio_frame_queue.h"
32 #include "psymodel.h"
33
34 #include "lpc.h"
35
36 typedef enum AACCoder {
37     AAC_CODER_FAAC = 0,
38     AAC_CODER_ANMR,
39     AAC_CODER_TWOLOOP,
40     AAC_CODER_FAST,
41
42     AAC_CODER_NB,
43 }AACCoder;
44
45 typedef struct AACEncOptions {
46     int coder;
47     int pns;
48     int tns;
49     int ltp;
50     int pred;
51     int mid_side;
52     int intensity_stereo;
53 } AACEncOptions;
54
55 struct AACEncContext;
56
57 typedef struct AACCoefficientsEncoder {
58     void (*search_for_quantizers)(AVCodecContext *avctx, struct AACEncContext *s,
59                                   SingleChannelElement *sce, const float lambda);
60     void (*encode_window_bands_info)(struct AACEncContext *s, SingleChannelElement *sce,
61                                      int win, int group_len, const float lambda);
62     void (*quantize_and_encode_band)(struct AACEncContext *s, PutBitContext *pb, const float *in, float *out, int size,
63                                      int scale_idx, int cb, const float lambda, int rtz);
64     void (*encode_tns_info)(struct AACEncContext *s, SingleChannelElement *sce);
65     void (*encode_ltp_info)(struct AACEncContext *s, SingleChannelElement *sce, int common_window);
66     void (*encode_main_pred)(struct AACEncContext *s, SingleChannelElement *sce);
67     void (*adjust_common_pred)(struct AACEncContext *s, ChannelElement *cpe);
68     void (*adjust_common_ltp)(struct AACEncContext *s, ChannelElement *cpe);
69     void (*apply_main_pred)(struct AACEncContext *s, SingleChannelElement *sce);
70     void (*apply_tns_filt)(struct AACEncContext *s, SingleChannelElement *sce);
71     void (*update_ltp)(struct AACEncContext *s, SingleChannelElement *sce);
72     void (*ltp_insert_new_frame)(struct AACEncContext *s);
73     void (*set_special_band_scalefactors)(struct AACEncContext *s, SingleChannelElement *sce);
74     void (*search_for_pns)(struct AACEncContext *s, AVCodecContext *avctx, SingleChannelElement *sce);
75     void (*mark_pns)(struct AACEncContext *s, AVCodecContext *avctx, SingleChannelElement *sce);
76     void (*search_for_tns)(struct AACEncContext *s, SingleChannelElement *sce);
77     void (*search_for_ltp)(struct AACEncContext *s, SingleChannelElement *sce, int common_window);
78     void (*search_for_ms)(struct AACEncContext *s, ChannelElement *cpe);
79     void (*search_for_is)(struct AACEncContext *s, AVCodecContext *avctx, ChannelElement *cpe);
80     void (*search_for_pred)(struct AACEncContext *s, SingleChannelElement *sce);
81 } AACCoefficientsEncoder;
82
83 extern AACCoefficientsEncoder ff_aac_coders[];
84
85 typedef struct AACQuantizeBandCostCacheEntry {
86     float rd;
87     float energy;
88     int bits; ///< -1 means uninitialized entry
89     char cb;
90     char rtz;
91     char padding[2]; ///< Keeps the entry size a multiple of 32 bits
92 } AACQuantizeBandCostCacheEntry;
93
94 /**
95  * AAC encoder context
96  */
97 typedef struct AACEncContext {
98     AVClass *av_class;
99     AACEncOptions options;                       ///< encoding options
100     PutBitContext pb;
101     FFTContext mdct1024;                         ///< long (1024 samples) frame transform context
102     FFTContext mdct128;                          ///< short (128 samples) frame transform context
103     AVFloatDSPContext *fdsp;
104     AVLFG lfg;                                   ///< PRNG needed for PNS
105     float *planar_samples[8];                    ///< saved preprocessed input
106
107     int profile;                                 ///< copied from avctx
108     LPCContext lpc;                              ///< used by TNS
109     int samplerate_index;                        ///< MPEG-4 samplerate index
110     int channels;                                ///< channel count
111     const uint8_t *chan_map;                     ///< channel configuration map
112
113     ChannelElement *cpe;                         ///< channel elements
114     FFPsyContext psy;
115     struct FFPsyPreprocessContext* psypp;
116     AACCoefficientsEncoder *coder;
117     int cur_channel;                             ///< current channel for coder context
118     int last_frame;
119     int random_state;
120     float lambda;
121     float lambda_sum;                            ///< sum(lambda), for Qvg reporting
122     int lambda_count;                            ///< count(lambda), for Qvg reporting
123     enum RawDataBlockType cur_type;              ///< channel group type cur_channel belongs to
124
125     AudioFrameQueue afq;
126     DECLARE_ALIGNED(16, int,   qcoefs)[96];      ///< quantized coefficients
127     DECLARE_ALIGNED(32, float, scoefs)[1024];    ///< scaled coefficients
128
129     AACQuantizeBandCostCacheEntry quantize_band_cost_cache[256][128]; ///< memoization area for quantize_band_cost
130
131     struct {
132         float *samples;
133     } buffer;
134 } AACEncContext;
135
136 void ff_aac_coder_init_mips(AACEncContext *c);
137 void ff_quantize_band_cost_cache_init(struct AACEncContext *s);
138
139
140 #endif /* AVCODEC_AACENC_H */