FFmpeg
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
eac3enc.c
Go to the documentation of this file.
1 /*
2  * E-AC-3 encoder
3  * Copyright (c) 2011 Justin Ruggles <justin.ruggles@gmail.com>
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 /**
23  * @file
24  * E-AC-3 encoder
25  */
26 
27 #define CONFIG_AC3ENC_FLOAT 1
28 
29 #include "libavutil/attributes.h"
30 #include "ac3enc.h"
31 #include "eac3enc.h"
32 #include "eac3_data.h"
33 
34 
35 #define AC3ENC_TYPE AC3ENC_TYPE_EAC3
36 #include "ac3enc_opts_template.c"
37 
38 static const AVClass eac3enc_class = {
39  .class_name = "E-AC-3 Encoder",
40  .item_name = av_default_item_name,
41  .option = ac3_options,
42  .version = LIBAVUTIL_VERSION_INT,
43 };
44 
45 /**
46  * LUT for finding a matching frame exponent strategy index from a set of
47  * exponent strategies for a single channel across all 6 blocks.
48  */
49 static int8_t eac3_frame_expstr_index_tab[3][4][4][4][4][4];
50 
51 
53 {
54  int i;
55 
57  for (i = 0; i < 32; i++) {
59  [ff_eac3_frm_expstr[i][1]]
60  [ff_eac3_frm_expstr[i][2]]
61  [ff_eac3_frm_expstr[i][3]]
62  [ff_eac3_frm_expstr[i][4]]
63  [ff_eac3_frm_expstr[i][5]] = i;
64  }
65 }
66 
67 
69 {
70  int ch;
71 
72  if (s->num_blocks < 6) {
74  return;
75  }
76 
78  for (ch = !s->cpl_on; ch <= s->fbw_channels; ch++) {
79  int expstr = eac3_frame_expstr_index_tab[s->exp_strategy[ch][0]-1]
80  [s->exp_strategy[ch][1]]
81  [s->exp_strategy[ch][2]]
82  [s->exp_strategy[ch][3]]
83  [s->exp_strategy[ch][4]]
84  [s->exp_strategy[ch][5]];
85  if (expstr < 0) {
87  break;
88  }
89  s->frame_exp_strategy[ch] = expstr;
90  }
91 }
92 
93 
94 
96 {
97  int ch, blk;
98  int first_cpl_coords[AC3_MAX_CHANNELS];
99 
100  /* set first cpl coords */
101  for (ch = 1; ch <= s->fbw_channels; ch++)
102  first_cpl_coords[ch] = 1;
103  for (blk = 0; blk < s->num_blocks; blk++) {
104  AC3Block *block = &s->blocks[blk];
105  for (ch = 1; ch <= s->fbw_channels; ch++) {
106  if (block->channel_in_cpl[ch]) {
107  if (first_cpl_coords[ch]) {
108  block->new_cpl_coords[ch] = 2;
109  first_cpl_coords[ch] = 0;
110  }
111  } else {
112  first_cpl_coords[ch] = 1;
113  }
114  }
115  }
116 
117  /* set first cpl leak */
118  for (blk = 0; blk < s->num_blocks; blk++) {
119  AC3Block *block = &s->blocks[blk];
120  if (block->cpl_in_use) {
121  block->new_cpl_leak = 2;
122  break;
123  }
124  }
125 }
126 
127 
129 {
130  int blk, ch;
131  AC3EncOptions *opt = &s->options;
132 
133  put_bits(&s->pb, 16, 0x0b77); /* sync word */
134 
135  /* BSI header */
136  put_bits(&s->pb, 2, 0); /* stream type = independent */
137  put_bits(&s->pb, 3, 0); /* substream id = 0 */
138  put_bits(&s->pb, 11, (s->frame_size / 2) - 1); /* frame size */
139  if (s->bit_alloc.sr_shift) {
140  put_bits(&s->pb, 2, 0x3); /* fscod2 */
141  put_bits(&s->pb, 2, s->bit_alloc.sr_code); /* sample rate code */
142  } else {
143  put_bits(&s->pb, 2, s->bit_alloc.sr_code); /* sample rate code */
144  put_bits(&s->pb, 2, s->num_blks_code); /* number of blocks */
145  }
146  put_bits(&s->pb, 3, s->channel_mode); /* audio coding mode */
147  put_bits(&s->pb, 1, s->lfe_on); /* LFE channel indicator */
148  put_bits(&s->pb, 5, s->bitstream_id); /* bitstream id (EAC3=16) */
149  put_bits(&s->pb, 5, -opt->dialogue_level); /* dialogue normalization level */
150  put_bits(&s->pb, 1, 0); /* no compression gain */
151  /* mixing metadata*/
152  put_bits(&s->pb, 1, opt->eac3_mixing_metadata);
153  if (opt->eac3_mixing_metadata) {
155  put_bits(&s->pb, 2, opt->preferred_stereo_downmix);
156  if (s->has_center) {
157  put_bits(&s->pb, 3, s->ltrt_center_mix_level);
158  put_bits(&s->pb, 3, s->loro_center_mix_level);
159  }
160  if (s->has_surround) {
161  put_bits(&s->pb, 3, s->ltrt_surround_mix_level);
162  put_bits(&s->pb, 3, s->loro_surround_mix_level);
163  }
164  if (s->lfe_on)
165  put_bits(&s->pb, 1, 0);
166  put_bits(&s->pb, 1, 0); /* no program scale */
167  put_bits(&s->pb, 1, 0); /* no ext program scale */
168  put_bits(&s->pb, 2, 0); /* no mixing parameters */
170  put_bits(&s->pb, 1, 0); /* no pan info */
171  put_bits(&s->pb, 1, 0); /* no frame mix config info */
172  }
173  /* info metadata*/
174  put_bits(&s->pb, 1, opt->eac3_info_metadata);
175  if (opt->eac3_info_metadata) {
176  put_bits(&s->pb, 3, s->bitstream_mode);
177  put_bits(&s->pb, 1, opt->copyright);
178  put_bits(&s->pb, 1, opt->original);
179  if (s->channel_mode == AC3_CHMODE_STEREO) {
180  put_bits(&s->pb, 2, opt->dolby_surround_mode);
181  put_bits(&s->pb, 2, opt->dolby_headphone_mode);
182  }
183  if (s->channel_mode >= AC3_CHMODE_2F2R)
184  put_bits(&s->pb, 2, opt->dolby_surround_ex_mode);
185  put_bits(&s->pb, 1, opt->audio_production_info);
186  if (opt->audio_production_info) {
187  put_bits(&s->pb, 5, opt->mixing_level - 80);
188  put_bits(&s->pb, 2, opt->room_type);
189  put_bits(&s->pb, 1, opt->ad_converter_type);
190  }
191  put_bits(&s->pb, 1, 0);
192  }
193  if (s->num_blocks != 6)
194  put_bits(&s->pb, 1, !(s->avctx->frame_number % 6)); /* converter sync flag */
195  put_bits(&s->pb, 1, 0); /* no additional bit stream info */
196 
197  /* frame header */
198  if (s->num_blocks == 6) {
199  put_bits(&s->pb, 1, !s->use_frame_exp_strategy);/* exponent strategy syntax */
200  put_bits(&s->pb, 1, 0); /* aht enabled = no */
201  }
202  put_bits(&s->pb, 2, 0); /* snr offset strategy = 1 */
203  put_bits(&s->pb, 1, 0); /* transient pre-noise processing enabled = no */
204  put_bits(&s->pb, 1, 0); /* block switch syntax enabled = no */
205  put_bits(&s->pb, 1, 0); /* dither flag syntax enabled = no */
206  put_bits(&s->pb, 1, 0); /* bit allocation model syntax enabled = no */
207  put_bits(&s->pb, 1, 0); /* fast gain codes enabled = no */
208  put_bits(&s->pb, 1, 0); /* dba syntax enabled = no */
209  put_bits(&s->pb, 1, 0); /* skip field syntax enabled = no */
210  put_bits(&s->pb, 1, 0); /* spx enabled = no */
211  /* coupling strategy use flags */
212  if (s->channel_mode > AC3_CHMODE_MONO) {
213  put_bits(&s->pb, 1, s->blocks[0].cpl_in_use);
214  for (blk = 1; blk < s->num_blocks; blk++) {
215  AC3Block *block = &s->blocks[blk];
216  put_bits(&s->pb, 1, block->new_cpl_strategy);
217  if (block->new_cpl_strategy)
218  put_bits(&s->pb, 1, block->cpl_in_use);
219  }
220  }
221  /* exponent strategy */
222  if (s->use_frame_exp_strategy) {
223  for (ch = !s->cpl_on; ch <= s->fbw_channels; ch++)
224  put_bits(&s->pb, 5, s->frame_exp_strategy[ch]);
225  } else {
226  for (blk = 0; blk < s->num_blocks; blk++)
227  for (ch = !s->blocks[blk].cpl_in_use; ch <= s->fbw_channels; ch++)
228  put_bits(&s->pb, 2, s->exp_strategy[ch][blk]);
229  }
230  if (s->lfe_on) {
231  for (blk = 0; blk < s->num_blocks; blk++)
232  put_bits(&s->pb, 1, s->exp_strategy[s->lfe_channel][blk]);
233  }
234  /* E-AC-3 to AC-3 converter exponent strategy (not optional when num blocks == 6) */
235  if (s->num_blocks != 6) {
236  put_bits(&s->pb, 1, 0);
237  } else {
238  for (ch = 1; ch <= s->fbw_channels; ch++) {
239  if (s->use_frame_exp_strategy)
240  put_bits(&s->pb, 5, s->frame_exp_strategy[ch]);
241  else
242  put_bits(&s->pb, 5, 0);
243  }
244  }
245  /* snr offsets */
246  put_bits(&s->pb, 6, s->coarse_snr_offset);
247  put_bits(&s->pb, 4, s->fine_snr_offset[1]);
248  /* block start info */
249  if (s->num_blocks > 1)
250  put_bits(&s->pb, 1, 0);
251 }
252 
253 
255  .name = "eac3",
256  .long_name = NULL_IF_CONFIG_SMALL("ATSC A/52 E-AC-3"),
257  .type = AVMEDIA_TYPE_AUDIO,
258  .id = AV_CODEC_ID_EAC3,
259  .priv_data_size = sizeof(AC3EncodeContext),
261  .encode2 = ff_ac3_float_encode_frame,
262  .close = ff_ac3_encode_close,
263  .sample_fmts = (const enum AVSampleFormat[]){ AV_SAMPLE_FMT_FLTP,
265  .priv_class = &eac3enc_class,
266  .channel_layouts = ff_ac3_channel_layouts,
267  .defaults = ac3_defaults,
268 };
float, planar
Definition: samplefmt.h:69
uint8_t exp_strategy[AC3_MAX_CHANNELS][AC3_MAX_BLOCKS]
exponent strategies
Definition: ac3enc.h:251
int eac3_mixing_metadata
Definition: ac3enc.h:120
const char * s
Definition: avisynth_c.h:768
int dialogue_level
Definition: ac3enc.h:100
Encoding Options used by AVOption.
Definition: ac3enc.h:98
static void put_bits(Jpeg2000EncoderContext *s, int val, int n)
put n times val bit
Definition: j2kenc.c:207
int dolby_surround_ex_mode
Definition: ac3enc.h:117
#define LIBAVUTIL_VERSION_INT
Definition: version.h:85
static av_cold int init(AVCodecContext *avctx)
Definition: avrndec.c:35
const char * av_default_item_name(void *ptr)
Return the context name.
Definition: log.c:191
static const AVClass eac3enc_class
Definition: eac3enc.c:38
void ff_eac3_set_cpl_states(AC3EncodeContext *s)
Set coupling states.
Definition: eac3enc.c:95
PutBitContext pb
bitstream writer context
Definition: ac3enc.h:166
#define blk(i)
Definition: sha.c:185
AVCodec.
Definition: avcodec.h:3408
AC3BitAllocParameters bit_alloc
bit allocation parameters
Definition: ac3enc.h:228
Macro definitions for various function/variable attributes.
int ff_ac3_float_encode_frame(AVCodecContext *avctx, AVPacket *avpkt, const AVFrame *frame, int *got_packet_ptr)
int new_cpl_leak
send new coupling leak info
Definition: ac3enc.h:155
void ff_eac3_get_frame_exp_strategy(AC3EncodeContext *s)
Determine frame exponent strategy use and indices.
Definition: eac3enc.c:68
static int16_t block[64]
Definition: dct.c:115
int ff_ac3_float_encode_init(AVCodecContext *avctx)
Definition: ac3enc_float.c:132
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
Definition: log.h:72
int channel_mode
channel mode (acmod)
Definition: ac3enc.h:199
#define av_cold
Definition: attributes.h:82
int fbw_channels
number of full-bandwidth channels (nfchans)
Definition: ac3enc.h:193
uint8_t new_cpl_coords[AC3_MAX_CHANNELS]
send new coupling coordinates (cplcoe)
Definition: ac3enc.h:152
av_cold int ff_ac3_encode_close(AVCodecContext *avctx)
Finalize encoding and free any memory allocated by the encoder.
Definition: ac3enc.c:2017
int loro_center_mix_level
Lo/Ro center mix level code.
Definition: ac3enc.h:206
int lfe_channel
channel index of the LFE channel
Definition: ac3enc.h:196
static int8_t eac3_frame_expstr_index_tab[3][4][4][4][4][4]
LUT for finding a matching frame exponent strategy index from a set of exponent strategies for a sing...
Definition: eac3enc.c:49
int loro_surround_mix_level
Lo/Ro surround mix level code.
Definition: ac3enc.h:207
uint8_t channel_in_cpl[AC3_MAX_CHANNELS]
channel in coupling (chincpl)
Definition: ac3enc.h:150
int eac3_info_metadata
Definition: ac3enc.h:121
int mixing_level
Definition: ac3enc.h:106
int num_blks_code
number of blocks code (numblkscod)
Definition: ac3enc.h:184
const uint64_t ff_ac3_channel_layouts[19]
List of supported channel layouts.
Definition: ac3enc.c:81
AC3EncOptions options
encoding options
Definition: ac3enc.h:164
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
Definition: internal.h:186
#define AC3_MAX_CHANNELS
maximum number of channels, including coupling channel
Definition: ac3.h:32
int cpl_on
coupling turned on for this frame
Definition: ac3enc.h:214
const char * name
Name of the codec implementation.
Definition: avcodec.h:3415
int ltrt_surround_mix_level
Lt/Rt surround mix level code.
Definition: ac3enc.h:205
int new_cpl_strategy
send new coupling strategy
Definition: ac3enc.h:148
int cpl_in_use
coupling in use for this block (cplinu)
Definition: ac3enc.h:149
Data for a single audio block.
Definition: ac3enc.h:133
int bitstream_mode
bitstream mode (bsmod)
Definition: ac3enc.h:179
int has_surround
indicates if there are one or more surround channels
Definition: ac3enc.h:198
uint8_t frame_exp_strategy[AC3_MAX_CHANNELS]
frame exp strategy index
Definition: ac3enc.h:252
int ad_converter_type
Definition: ac3enc.h:119
int coarse_snr_offset
coarse SNR offsets (csnroffst)
Definition: ac3enc.h:229
void ff_eac3_output_frame_header(AC3EncodeContext *s)
Write the E-AC-3 frame header to the output bitstream.
Definition: eac3enc.c:128
int audio_production_info
Definition: ac3enc.h:105
AVSampleFormat
Audio sample formats.
Definition: samplefmt.h:58
int dolby_surround_mode
Definition: ac3enc.h:104
int has_center
indicates if there is a center channel
Definition: ac3enc.h:197
Describe the class of an AVClass context structure.
Definition: log.h:67
int ltrt_center_mix_level
Lt/Rt center mix level code.
Definition: ac3enc.h:204
static const AVCodecDefault ac3_defaults[]
av_cold void ff_eac3_exponent_init(void)
Initialize E-AC-3 exponent tables.
Definition: eac3enc.c:52
AC-3 encoder private context.
Definition: ac3enc.h:162
AC3Block blocks[AC3_MAX_BLOCKS]
per-block info
Definition: ac3enc.h:174
int preferred_stereo_downmix
Definition: ac3enc.h:111
int num_blocks
number of blocks per frame
Definition: ac3enc.h:185
int frame_size
current frame size in bytes
Definition: ac3enc.h:187
int room_type
Definition: ac3enc.h:107
const uint8_t ff_eac3_frm_expstr[32][6]
Table E2.14 Frame Exponent Strategy Combinations.
Definition: eac3_data.c:1062
static const AVOption ac3_options[]
int bitstream_id
bitstream id (bsid)
Definition: ac3enc.h:178
int dolby_headphone_mode
Definition: ac3enc.h:118
AVCodecContext * avctx
parent AVCodecContext
Definition: ac3enc.h:165
int original
Definition: ac3enc.h:109
AC-3 encoder & E-AC-3 encoder common header.
static enum AVSampleFormat sample_fmts[]
Definition: adpcmenc.c:701
int frame_number
Frame counter, set by libavcodec.
Definition: avcodec.h:2204
int use_frame_exp_strategy
indicates use of frame exp strategy
Definition: ac3enc.h:253
E-AC-3 encoder.
int lfe_on
indicates if there is an LFE channel (lfeon)
Definition: ac3enc.h:195
int fine_snr_offset[AC3_MAX_CHANNELS]
fine SNR offsets (fsnroffst)
Definition: ac3enc.h:231
int copyright
Definition: ac3enc.h:108
uint8_t pi<< 24) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_U8,(uint64_t)((*(constuint8_t *) pi-0x80U))<< 56) CONV_FUNC(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8,(*(constuint8_t *) pi-0x80)*(1.0f/(1<< 7))) CONV_FUNC(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8,(*(constuint8_t *) pi-0x80)*(1.0/(1<< 7))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16,(*(constint16_t *) pi >>8)+0x80) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_S16,(uint64_t)(*(constint16_t *) pi)<< 48) CONV_FUNC(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16,*(constint16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16,*(constint16_t *) pi *(1.0/(1<< 15))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32,(*(constint32_t *) pi >>24)+0x80) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_S32,(uint64_t)(*(constint32_t *) pi)<< 32) CONV_FUNC(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32,*(constint32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32,*(constint32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S64,(*(constint64_t *) pi >>56)+0x80) CONV_FUNC(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S64,*(constint64_t *) pi *(1.0f/(INT64_C(1)<< 63))) CONV_FUNC(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S64,*(constint64_t *) pi *(1.0/(INT64_C(1)<< 63))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, av_clip_uint8(lrintf(*(constfloat *) pi *(1<< 7))+0x80)) CONV_FUNC(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, av_clip_int16(lrintf(*(constfloat *) pi *(1<< 15)))) CONV_FUNC(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, av_clipl_int32(llrintf(*(constfloat *) pi *(1U<< 31)))) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_FLT, llrintf(*(constfloat *) pi *(INT64_C(1)<< 63))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, av_clip_uint8(lrint(*(constdouble *) pi *(1<< 7))+0x80)) CONV_FUNC(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, av_clip_int16(lrint(*(constdouble *) pi *(1<< 15)))) CONV_FUNC(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, av_clipl_int32(llrint(*(constdouble *) pi *(1U<< 31)))) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_DBL, llrint(*(constdouble *) pi *(INT64_C(1)<< 63)))#defineFMT_PAIR_FUNC(out, in) staticconv_func_type *constfmt_pair_to_conv_functions[AV_SAMPLE_FMT_NB *AV_SAMPLE_FMT_NB]={FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S64, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_S16), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_S16), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_S16), FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_S16), FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_S16), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S64, AV_SAMPLE_FMT_S16), FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_S32), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_S32), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_S32), FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_S32), FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_S32), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S64, AV_SAMPLE_FMT_S32), FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_FLT), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_FLT), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_FLT), FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_FLT), FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_FLT), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S64, AV_SAMPLE_FMT_FLT), FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S64, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_S64), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_S64), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_S64), FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_S64), FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_S64), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S64, AV_SAMPLE_FMT_S64),};staticvoidcpy1(uint8_t **dst, constuint8_t **src, intlen){memcpy(*dst,*src, len);}staticvoidcpy2(uint8_t **dst, constuint8_t **src, intlen){memcpy(*dst,*src, 2 *len);}staticvoidcpy4(uint8_t **dst, constuint8_t **src, intlen){memcpy(*dst,*src, 4 *len);}staticvoidcpy8(uint8_t **dst, constuint8_t **src, intlen){memcpy(*dst,*src, 8 *len);}AudioConvert *swri_audio_convert_alloc(enumAVSampleFormatout_fmt, enumAVSampleFormatin_fmt, intchannels, constint *ch_map, intflags){AudioConvert *ctx;conv_func_type *f=fmt_pair_to_conv_functions[av_get_packed_sample_fmt(out_fmt)+AV_SAMPLE_FMT_NB *av_get_packed_sample_fmt(in_fmt)];if(!f) returnNULL;ctx=av_mallocz(sizeof(*ctx));if(!ctx) returnNULL;if(channels==1){in_fmt=av_get_planar_sample_fmt(in_fmt);out_fmt=av_get_planar_sample_fmt(out_fmt);}ctx->channels=channels;ctx->conv_f=f;ctx->ch_map=ch_map;if(in_fmt==AV_SAMPLE_FMT_U8||in_fmt==AV_SAMPLE_FMT_U8P) memset(ctx->silence, 0x80, sizeof(ctx->silence));if(out_fmt==in_fmt &&!ch_map){switch(av_get_bytes_per_sample(in_fmt)){case1:ctx->simd_f=cpy1;break;case2:ctx->simd_f=cpy2;break;case4:ctx->simd_f=cpy4;break;case8:ctx->simd_f=cpy8;break;}}if(HAVE_X86ASM &&1) swri_audio_convert_init_x86(ctx, out_fmt, in_fmt, channels);if(ARCH_ARM) swri_audio_convert_init_arm(ctx, out_fmt, in_fmt, channels);if(ARCH_AARCH64) swri_audio_convert_init_aarch64(ctx, out_fmt, in_fmt, channels);returnctx;}voidswri_audio_convert_free(AudioConvert **ctx){av_freep(ctx);}intswri_audio_convert(AudioConvert *ctx, AudioData *out, AudioData *in, intlen){intch;intoff=0;constintos=(out->planar?1:out->ch_count)*out->bps;unsignedmisaligned=0;av_assert0(ctx->channels==out->ch_count);if(ctx->in_simd_align_mask){intplanes=in->planar?in->ch_count:1;unsignedm=0;for(ch=0;ch< planes;ch++) m|=(intptr_t) in->ch[ch];misaligned|=m &ctx->in_simd_align_mask;}if(ctx->out_simd_align_mask){intplanes=out->planar?out->ch_count:1;unsignedm=0;for(ch=0;ch< planes;ch++) m|=(intptr_t) out->ch[ch];misaligned|=m &ctx->out_simd_align_mask;}if(ctx->simd_f &&!ctx->ch_map &&!misaligned){off=len &~15;av_assert1(off >=0);av_assert1(off<=len);av_assert2(ctx->channels==SWR_CH_MAX||!in->ch[ctx->channels]);if(off >0){if(out->planar==in->planar){intplanes=out->planar?out->ch_count:1;for(ch=0;ch< planes;ch++){ctx->simd_f(out-> ch ch
Definition: audioconvert.c:56
AVCodec ff_eac3_encoder
Definition: eac3enc.c:254