annotate libmpcodecs/ae_faac.c @ 31918:3103448dcf28

Make sure we return an "empty" line on eof, to make sure we get no buffer overflows in case some code fails to check the return value.
author reimar
date Sat, 21 Aug 2010 10:08:29 +0000
parents 4e59a7aebadb
children d332ea379205
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
30421
bbb6ebec87a0 Add missing license headers to all files in the libmpcodecs directory.
diego
parents: 29263
diff changeset
1 /*
bbb6ebec87a0 Add missing license headers to all files in the libmpcodecs directory.
diego
parents: 29263
diff changeset
2 * This file is part of MPlayer.
bbb6ebec87a0 Add missing license headers to all files in the libmpcodecs directory.
diego
parents: 29263
diff changeset
3 *
bbb6ebec87a0 Add missing license headers to all files in the libmpcodecs directory.
diego
parents: 29263
diff changeset
4 * MPlayer is free software; you can redistribute it and/or modify
bbb6ebec87a0 Add missing license headers to all files in the libmpcodecs directory.
diego
parents: 29263
diff changeset
5 * it under the terms of the GNU General Public License as published by
bbb6ebec87a0 Add missing license headers to all files in the libmpcodecs directory.
diego
parents: 29263
diff changeset
6 * the Free Software Foundation; either version 2 of the License, or
bbb6ebec87a0 Add missing license headers to all files in the libmpcodecs directory.
diego
parents: 29263
diff changeset
7 * (at your option) any later version.
bbb6ebec87a0 Add missing license headers to all files in the libmpcodecs directory.
diego
parents: 29263
diff changeset
8 *
bbb6ebec87a0 Add missing license headers to all files in the libmpcodecs directory.
diego
parents: 29263
diff changeset
9 * MPlayer is distributed in the hope that it will be useful,
bbb6ebec87a0 Add missing license headers to all files in the libmpcodecs directory.
diego
parents: 29263
diff changeset
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
bbb6ebec87a0 Add missing license headers to all files in the libmpcodecs directory.
diego
parents: 29263
diff changeset
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
bbb6ebec87a0 Add missing license headers to all files in the libmpcodecs directory.
diego
parents: 29263
diff changeset
12 * GNU General Public License for more details.
bbb6ebec87a0 Add missing license headers to all files in the libmpcodecs directory.
diego
parents: 29263
diff changeset
13 *
bbb6ebec87a0 Add missing license headers to all files in the libmpcodecs directory.
diego
parents: 29263
diff changeset
14 * You should have received a copy of the GNU General Public License along
bbb6ebec87a0 Add missing license headers to all files in the libmpcodecs directory.
diego
parents: 29263
diff changeset
15 * with MPlayer; if not, write to the Free Software Foundation, Inc.,
bbb6ebec87a0 Add missing license headers to all files in the libmpcodecs directory.
diego
parents: 29263
diff changeset
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
bbb6ebec87a0 Add missing license headers to all files in the libmpcodecs directory.
diego
parents: 29263
diff changeset
17 */
bbb6ebec87a0 Add missing license headers to all files in the libmpcodecs directory.
diego
parents: 29263
diff changeset
18
15259
854990f357ee added faac audio encoder
nicodvb
parents:
diff changeset
19 #include <stdio.h>
854990f357ee added faac audio encoder
nicodvb
parents:
diff changeset
20 #include <stdlib.h>
854990f357ee added faac audio encoder
nicodvb
parents:
diff changeset
21 #include <inttypes.h>
854990f357ee added faac audio encoder
nicodvb
parents:
diff changeset
22 #include <unistd.h>
854990f357ee added faac audio encoder
nicodvb
parents:
diff changeset
23 #include <string.h>
854990f357ee added faac audio encoder
nicodvb
parents:
diff changeset
24 #include <sys/types.h>
854990f357ee added faac audio encoder
nicodvb
parents:
diff changeset
25 #include "m_option.h"
17012
6ff3379a0862 Unify include path handling, -I.. is in CFLAGS.
diego
parents: 15276
diff changeset
26 #include "mp_msg.h"
22601
ed8f90096c65 Add explicit location for headers from the libmpdemux/ directory.
diego
parents: 22600
diff changeset
27 #include "libmpdemux/aviheader.h"
17012
6ff3379a0862 Unify include path handling, -I.. is in CFLAGS.
diego
parents: 15276
diff changeset
28 #include "libaf/af_format.h"
25315
dfa8a510c81c Fix all current known multi-channel wrong order problems by adding
ulion
parents: 22601
diff changeset
29 #include "libaf/reorder_ch.h"
22601
ed8f90096c65 Add explicit location for headers from the libmpdemux/ directory.
diego
parents: 22600
diff changeset
30 #include "libmpdemux/ms_hdr.h"
22600
3c2b4a866c6a Add explicit location for headers from the stream/ directory.
diego
parents: 21660
diff changeset
31 #include "stream/stream.h"
22601
ed8f90096c65 Add explicit location for headers from the libmpdemux/ directory.
diego
parents: 22600
diff changeset
32 #include "libmpdemux/muxer.h"
15259
854990f357ee added faac audio encoder
nicodvb
parents:
diff changeset
33 #include <faac.h>
854990f357ee added faac audio encoder
nicodvb
parents:
diff changeset
34 #include "ae.h"
854990f357ee added faac audio encoder
nicodvb
parents:
diff changeset
35
854990f357ee added faac audio encoder
nicodvb
parents:
diff changeset
36
854990f357ee added faac audio encoder
nicodvb
parents:
diff changeset
37 static faacEncHandle faac;
854990f357ee added faac audio encoder
nicodvb
parents:
diff changeset
38 static faacEncConfigurationPtr config = NULL;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 25315
diff changeset
39 static int
15259
854990f357ee added faac audio encoder
nicodvb
parents:
diff changeset
40 param_bitrate = 128,
854990f357ee added faac audio encoder
nicodvb
parents:
diff changeset
41 param_quality = 0,
20080
5aab07acf0b5 workaround redefinition of object_type as prev(object_type)+1
nicodvb
parents: 17366
diff changeset
42 param_object_type = 1,
15259
854990f357ee added faac audio encoder
nicodvb
parents:
diff changeset
43 param_mpeg = 2,
854990f357ee added faac audio encoder
nicodvb
parents:
diff changeset
44 param_tns = 0,
854990f357ee added faac audio encoder
nicodvb
parents:
diff changeset
45 param_raw = 0,
854990f357ee added faac audio encoder
nicodvb
parents:
diff changeset
46 param_cutoff = 0,
854990f357ee added faac audio encoder
nicodvb
parents:
diff changeset
47 param_format = 16,
854990f357ee added faac audio encoder
nicodvb
parents:
diff changeset
48 param_debug = 0;
854990f357ee added faac audio encoder
nicodvb
parents:
diff changeset
49
854990f357ee added faac audio encoder
nicodvb
parents:
diff changeset
50 static int enc_frame_size = 0, divisor;
854990f357ee added faac audio encoder
nicodvb
parents:
diff changeset
51 static unsigned long samples_input, max_bytes_output;
854990f357ee added faac audio encoder
nicodvb
parents:
diff changeset
52 static unsigned char *decoder_specific_buffer = NULL;
854990f357ee added faac audio encoder
nicodvb
parents:
diff changeset
53 static unsigned long decoder_specific_len = 0;
854990f357ee added faac audio encoder
nicodvb
parents:
diff changeset
54
30955
4e59a7aebadb Mark encoder-related m_option_t struct arrays as const.
diego
parents: 30421
diff changeset
55 const m_option_t faacopts_conf[] = {
15259
854990f357ee added faac audio encoder
nicodvb
parents:
diff changeset
56 {"br", &param_bitrate, CONF_TYPE_INT, 0, 0, 0, NULL},
854990f357ee added faac audio encoder
nicodvb
parents:
diff changeset
57 {"quality", &param_quality, CONF_TYPE_INT, CONF_RANGE, 0, 1000, NULL},
20080
5aab07acf0b5 workaround redefinition of object_type as prev(object_type)+1
nicodvb
parents: 17366
diff changeset
58 {"object", &param_object_type, CONF_TYPE_INT, CONF_RANGE, 1, 4, NULL},
15259
854990f357ee added faac audio encoder
nicodvb
parents:
diff changeset
59 {"mpeg", &param_mpeg, CONF_TYPE_INT, CONF_RANGE, 2, 4, NULL},
854990f357ee added faac audio encoder
nicodvb
parents:
diff changeset
60 {"tns", &param_tns, CONF_TYPE_FLAG, 0, 0, 1, NULL},
854990f357ee added faac audio encoder
nicodvb
parents:
diff changeset
61 {"cutoff", &param_cutoff, CONF_TYPE_INT, 0, 0, 0, NULL},
854990f357ee added faac audio encoder
nicodvb
parents:
diff changeset
62 {"format", &param_format, CONF_TYPE_INT, 0, 0, 0, NULL},
854990f357ee added faac audio encoder
nicodvb
parents:
diff changeset
63 {"raw", &param_raw, CONF_TYPE_FLAG, 0, 0, 1, NULL},
854990f357ee added faac audio encoder
nicodvb
parents:
diff changeset
64 {"debug", &param_debug, CONF_TYPE_INT, CONF_RANGE, 0, 100000000, NULL},
854990f357ee added faac audio encoder
nicodvb
parents:
diff changeset
65 {NULL, NULL, 0, 0, 0, 0, NULL}
854990f357ee added faac audio encoder
nicodvb
parents:
diff changeset
66 };
854990f357ee added faac audio encoder
nicodvb
parents:
diff changeset
67
854990f357ee added faac audio encoder
nicodvb
parents:
diff changeset
68
854990f357ee added faac audio encoder
nicodvb
parents:
diff changeset
69 static int bind_faac(audio_encoder_t *encoder, muxer_stream_t *mux_a)
854990f357ee added faac audio encoder
nicodvb
parents:
diff changeset
70 {
854990f357ee added faac audio encoder
nicodvb
parents:
diff changeset
71 mux_a->wf = calloc(1, sizeof(WAVEFORMATEX) + decoder_specific_len + 256);
854990f357ee added faac audio encoder
nicodvb
parents:
diff changeset
72 mux_a->wf->wFormatTag = 0x706D;
854990f357ee added faac audio encoder
nicodvb
parents:
diff changeset
73 mux_a->wf->nChannels = encoder->params.channels;
854990f357ee added faac audio encoder
nicodvb
parents:
diff changeset
74 mux_a->h.dwSampleSize=0; // VBR
854990f357ee added faac audio encoder
nicodvb
parents:
diff changeset
75 mux_a->h.dwRate=encoder->params.sample_rate;
854990f357ee added faac audio encoder
nicodvb
parents:
diff changeset
76 mux_a->h.dwScale=encoder->params.samples_per_frame;
854990f357ee added faac audio encoder
nicodvb
parents:
diff changeset
77 mux_a->wf->nSamplesPerSec=mux_a->h.dwRate;
15276
f331ff9ff453 10l, fix wrong byterate in waveformat
nicodvb
parents: 15259
diff changeset
78 mux_a->wf->nAvgBytesPerSec = encoder->params.bitrate / 8;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 25315
diff changeset
79
15259
854990f357ee added faac audio encoder
nicodvb
parents:
diff changeset
80 mux_a->wf->nBlockAlign = mux_a->h.dwScale;
854990f357ee added faac audio encoder
nicodvb
parents:
diff changeset
81 mux_a->h.dwSuggestedBufferSize = (encoder->params.audio_preload*mux_a->wf->nAvgBytesPerSec)/1000;
854990f357ee added faac audio encoder
nicodvb
parents:
diff changeset
82 mux_a->h.dwSuggestedBufferSize -= mux_a->h.dwSuggestedBufferSize % mux_a->wf->nBlockAlign;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 25315
diff changeset
83
15259
854990f357ee added faac audio encoder
nicodvb
parents:
diff changeset
84 mux_a->wf->cbSize = decoder_specific_len;
854990f357ee added faac audio encoder
nicodvb
parents:
diff changeset
85 mux_a->wf->wBitsPerSample = 0; /* does not apply */
854990f357ee added faac audio encoder
nicodvb
parents:
diff changeset
86 ((MPEGLAYER3WAVEFORMAT *) (mux_a->wf))->wID = 1;
854990f357ee added faac audio encoder
nicodvb
parents:
diff changeset
87 ((MPEGLAYER3WAVEFORMAT *) (mux_a->wf))->fdwFlags = 2;
854990f357ee added faac audio encoder
nicodvb
parents:
diff changeset
88 ((MPEGLAYER3WAVEFORMAT *) (mux_a->wf))->nBlockSize = mux_a->wf->nBlockAlign;
854990f357ee added faac audio encoder
nicodvb
parents:
diff changeset
89 ((MPEGLAYER3WAVEFORMAT *) (mux_a->wf))->nFramesPerBlock = 1;
854990f357ee added faac audio encoder
nicodvb
parents:
diff changeset
90 ((MPEGLAYER3WAVEFORMAT *) (mux_a->wf))->nCodecDelay = 0;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 25315
diff changeset
91
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 25315
diff changeset
92 // Fix allocation
15259
854990f357ee added faac audio encoder
nicodvb
parents:
diff changeset
93 mux_a->wf = realloc(mux_a->wf, sizeof(WAVEFORMATEX)+mux_a->wf->cbSize);
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 25315
diff changeset
94
15259
854990f357ee added faac audio encoder
nicodvb
parents:
diff changeset
95 if(config->inputFormat == FAAC_INPUT_FLOAT)
854990f357ee added faac audio encoder
nicodvb
parents:
diff changeset
96 encoder->input_format = AF_FORMAT_FLOAT_NE;
854990f357ee added faac audio encoder
nicodvb
parents:
diff changeset
97 else if(config->inputFormat == FAAC_INPUT_32BIT)
854990f357ee added faac audio encoder
nicodvb
parents:
diff changeset
98 encoder->input_format = AF_FORMAT_S32_NE;
854990f357ee added faac audio encoder
nicodvb
parents:
diff changeset
99 else
854990f357ee added faac audio encoder
nicodvb
parents:
diff changeset
100 encoder->input_format = AF_FORMAT_S16_NE;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 25315
diff changeset
101
15259
854990f357ee added faac audio encoder
nicodvb
parents:
diff changeset
102 encoder->min_buffer_size = mux_a->h.dwSuggestedBufferSize;
854990f357ee added faac audio encoder
nicodvb
parents:
diff changeset
103 encoder->max_buffer_size = mux_a->h.dwSuggestedBufferSize*2;
854990f357ee added faac audio encoder
nicodvb
parents:
diff changeset
104
854990f357ee added faac audio encoder
nicodvb
parents:
diff changeset
105 if(decoder_specific_buffer && decoder_specific_len)
854990f357ee added faac audio encoder
nicodvb
parents:
diff changeset
106 memcpy(mux_a->wf + 1, decoder_specific_buffer, decoder_specific_len);
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 25315
diff changeset
107
15259
854990f357ee added faac audio encoder
nicodvb
parents:
diff changeset
108 return 1;
854990f357ee added faac audio encoder
nicodvb
parents:
diff changeset
109 }
854990f357ee added faac audio encoder
nicodvb
parents:
diff changeset
110
854990f357ee added faac audio encoder
nicodvb
parents:
diff changeset
111 static int get_frame_size(audio_encoder_t *encoder)
854990f357ee added faac audio encoder
nicodvb
parents:
diff changeset
112 {
854990f357ee added faac audio encoder
nicodvb
parents:
diff changeset
113 int sz = enc_frame_size;
854990f357ee added faac audio encoder
nicodvb
parents:
diff changeset
114 enc_frame_size = 0;
854990f357ee added faac audio encoder
nicodvb
parents:
diff changeset
115 return sz;
854990f357ee added faac audio encoder
nicodvb
parents:
diff changeset
116 }
854990f357ee added faac audio encoder
nicodvb
parents:
diff changeset
117
854990f357ee added faac audio encoder
nicodvb
parents:
diff changeset
118 static int encode_faac(audio_encoder_t *encoder, uint8_t *dest, void *src, int len, int max_size)
854990f357ee added faac audio encoder
nicodvb
parents:
diff changeset
119 {
25315
dfa8a510c81c Fix all current known multi-channel wrong order problems by adding
ulion
parents: 22601
diff changeset
120 if (encoder->params.channels >= 5)
dfa8a510c81c Fix all current known multi-channel wrong order problems by adding
ulion
parents: 22601
diff changeset
121 reorder_channel_nch(src, AF_CHANNEL_LAYOUT_MPLAYER_DEFAULT,
dfa8a510c81c Fix all current known multi-channel wrong order problems by adding
ulion
parents: 22601
diff changeset
122 AF_CHANNEL_LAYOUT_AAC_DEFAULT,
dfa8a510c81c Fix all current known multi-channel wrong order problems by adding
ulion
parents: 22601
diff changeset
123 encoder->params.channels,
dfa8a510c81c Fix all current known multi-channel wrong order problems by adding
ulion
parents: 22601
diff changeset
124 len / divisor, divisor);
dfa8a510c81c Fix all current known multi-channel wrong order problems by adding
ulion
parents: 22601
diff changeset
125
15259
854990f357ee added faac audio encoder
nicodvb
parents:
diff changeset
126 // len is divided by the number of bytes per sample
854990f357ee added faac audio encoder
nicodvb
parents:
diff changeset
127 enc_frame_size = faacEncEncode(faac, (int32_t*) src, len / divisor, dest, max_size);
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 25315
diff changeset
128
15259
854990f357ee added faac audio encoder
nicodvb
parents:
diff changeset
129 return enc_frame_size;
854990f357ee added faac audio encoder
nicodvb
parents:
diff changeset
130 }
854990f357ee added faac audio encoder
nicodvb
parents:
diff changeset
131
854990f357ee added faac audio encoder
nicodvb
parents:
diff changeset
132 int close_faac(audio_encoder_t *encoder)
854990f357ee added faac audio encoder
nicodvb
parents:
diff changeset
133 {
854990f357ee added faac audio encoder
nicodvb
parents:
diff changeset
134 return 1;
854990f357ee added faac audio encoder
nicodvb
parents:
diff changeset
135 }
854990f357ee added faac audio encoder
nicodvb
parents:
diff changeset
136
854990f357ee added faac audio encoder
nicodvb
parents:
diff changeset
137 int mpae_init_faac(audio_encoder_t *encoder)
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 25315
diff changeset
138 {
15259
854990f357ee added faac audio encoder
nicodvb
parents:
diff changeset
139 if(encoder->params.channels < 1 || encoder->params.channels > 6 || (param_mpeg != 2 && param_mpeg != 4))
854990f357ee added faac audio encoder
nicodvb
parents:
diff changeset
140 {
854990f357ee added faac audio encoder
nicodvb
parents:
diff changeset
141 mp_msg(MSGT_MENCODER, MSGL_FATAL, "AE_FAAC, unsupported number of channels: %d, or mpeg version: %d, exit\n", encoder->params.channels, param_mpeg);
854990f357ee added faac audio encoder
nicodvb
parents:
diff changeset
142 return 0;
854990f357ee added faac audio encoder
nicodvb
parents:
diff changeset
143 }
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 25315
diff changeset
144
15259
854990f357ee added faac audio encoder
nicodvb
parents:
diff changeset
145 faac = faacEncOpen(encoder->params.sample_rate, encoder->params.channels, &samples_input, &max_bytes_output);
854990f357ee added faac audio encoder
nicodvb
parents:
diff changeset
146 if(!faac)
854990f357ee added faac audio encoder
nicodvb
parents:
diff changeset
147 {
854990f357ee added faac audio encoder
nicodvb
parents:
diff changeset
148 mp_msg(MSGT_MENCODER, MSGL_FATAL, "AE_FAAC, couldn't init, exit\n");
854990f357ee added faac audio encoder
nicodvb
parents:
diff changeset
149 return 0;
854990f357ee added faac audio encoder
nicodvb
parents:
diff changeset
150 }
17366
934380353fd6 massive attack: mp_msg printf format fixes
rathann
parents: 17012
diff changeset
151 mp_msg(MSGT_MENCODER, MSGL_V, "AE_FAAC, sample_input: %lu, max_bytes_output: %lu\n", samples_input, max_bytes_output);
15259
854990f357ee added faac audio encoder
nicodvb
parents:
diff changeset
152 config = faacEncGetCurrentConfiguration(faac);
854990f357ee added faac audio encoder
nicodvb
parents:
diff changeset
153 if(!config)
854990f357ee added faac audio encoder
nicodvb
parents:
diff changeset
154 {
854990f357ee added faac audio encoder
nicodvb
parents:
diff changeset
155 mp_msg(MSGT_MENCODER, MSGL_FATAL, "AE_FAAC, couldn't get init configuration, exit\n");
854990f357ee added faac audio encoder
nicodvb
parents:
diff changeset
156 return 0;
854990f357ee added faac audio encoder
nicodvb
parents:
diff changeset
157 }
854990f357ee added faac audio encoder
nicodvb
parents:
diff changeset
158
854990f357ee added faac audio encoder
nicodvb
parents:
diff changeset
159 param_bitrate *= 1000;
854990f357ee added faac audio encoder
nicodvb
parents:
diff changeset
160 if(param_quality)
854990f357ee added faac audio encoder
nicodvb
parents:
diff changeset
161 config->quantqual = param_quality;
854990f357ee added faac audio encoder
nicodvb
parents:
diff changeset
162 else
854990f357ee added faac audio encoder
nicodvb
parents:
diff changeset
163 config->bitRate = param_bitrate / encoder->params.channels;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 25315
diff changeset
164
15259
854990f357ee added faac audio encoder
nicodvb
parents:
diff changeset
165 if(param_format==33)
854990f357ee added faac audio encoder
nicodvb
parents:
diff changeset
166 {
854990f357ee added faac audio encoder
nicodvb
parents:
diff changeset
167 config->inputFormat = FAAC_INPUT_FLOAT;
854990f357ee added faac audio encoder
nicodvb
parents:
diff changeset
168 divisor = 4;
854990f357ee added faac audio encoder
nicodvb
parents:
diff changeset
169 }
854990f357ee added faac audio encoder
nicodvb
parents:
diff changeset
170 else if(param_format==32)
854990f357ee added faac audio encoder
nicodvb
parents:
diff changeset
171 {
854990f357ee added faac audio encoder
nicodvb
parents:
diff changeset
172 config->inputFormat = FAAC_INPUT_32BIT;
854990f357ee added faac audio encoder
nicodvb
parents:
diff changeset
173 divisor = 4;
854990f357ee added faac audio encoder
nicodvb
parents:
diff changeset
174 }
854990f357ee added faac audio encoder
nicodvb
parents:
diff changeset
175 else
854990f357ee added faac audio encoder
nicodvb
parents:
diff changeset
176 {
854990f357ee added faac audio encoder
nicodvb
parents:
diff changeset
177 config->inputFormat = FAAC_INPUT_16BIT;
854990f357ee added faac audio encoder
nicodvb
parents:
diff changeset
178 divisor = 2;
854990f357ee added faac audio encoder
nicodvb
parents:
diff changeset
179 }
854990f357ee added faac audio encoder
nicodvb
parents:
diff changeset
180 config->outputFormat = param_raw ? 0 : 1; // 1 is ADTS
854990f357ee added faac audio encoder
nicodvb
parents:
diff changeset
181 config->aacObjectType = param_object_type;
20080
5aab07acf0b5 workaround redefinition of object_type as prev(object_type)+1
nicodvb
parents: 17366
diff changeset
182 if(MAIN==0) config->aacObjectType--;
15259
854990f357ee added faac audio encoder
nicodvb
parents:
diff changeset
183 config->mpegVersion = (param_mpeg == 4 ? MPEG4 : MPEG2);
854990f357ee added faac audio encoder
nicodvb
parents:
diff changeset
184 config->useTns = param_tns;
854990f357ee added faac audio encoder
nicodvb
parents:
diff changeset
185 config->allowMidside = 1;
854990f357ee added faac audio encoder
nicodvb
parents:
diff changeset
186 config->shortctl = SHORTCTL_NORMAL;
854990f357ee added faac audio encoder
nicodvb
parents:
diff changeset
187 param_cutoff = param_cutoff ? param_cutoff : encoder->params.sample_rate / 2;
854990f357ee added faac audio encoder
nicodvb
parents:
diff changeset
188 if(param_cutoff > encoder->params.sample_rate / 2)
854990f357ee added faac audio encoder
nicodvb
parents:
diff changeset
189 param_cutoff = encoder->params.sample_rate / 2;
854990f357ee added faac audio encoder
nicodvb
parents:
diff changeset
190 config->bandWidth = param_cutoff;
854990f357ee added faac audio encoder
nicodvb
parents:
diff changeset
191 if(encoder->params.channels == 6)
854990f357ee added faac audio encoder
nicodvb
parents:
diff changeset
192 config->useLfe = 1;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 25315
diff changeset
193
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 25315
diff changeset
194 if(!faacEncSetConfiguration(faac, config))
15259
854990f357ee added faac audio encoder
nicodvb
parents:
diff changeset
195 {
854990f357ee added faac audio encoder
nicodvb
parents:
diff changeset
196 mp_msg(MSGT_MENCODER, MSGL_FATAL, "AE_FAAC, counldn't set specified parameters, exiting\n");
854990f357ee added faac audio encoder
nicodvb
parents:
diff changeset
197 return 0;
854990f357ee added faac audio encoder
nicodvb
parents:
diff changeset
198 }
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 25315
diff changeset
199
15259
854990f357ee added faac audio encoder
nicodvb
parents:
diff changeset
200 if(param_raw)
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 25315
diff changeset
201 faacEncGetDecoderSpecificInfo(faac, &decoder_specific_buffer, &decoder_specific_len);
15259
854990f357ee added faac audio encoder
nicodvb
parents:
diff changeset
202 else
854990f357ee added faac audio encoder
nicodvb
parents:
diff changeset
203 decoder_specific_len = 0;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 25315
diff changeset
204
15259
854990f357ee added faac audio encoder
nicodvb
parents:
diff changeset
205 encoder->params.bitrate = param_bitrate;
854990f357ee added faac audio encoder
nicodvb
parents:
diff changeset
206 encoder->params.samples_per_frame = 1024;
854990f357ee added faac audio encoder
nicodvb
parents:
diff changeset
207 encoder->decode_buffer_size = divisor * samples_input; //samples * 16 bits_per_sample
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 25315
diff changeset
208
15259
854990f357ee added faac audio encoder
nicodvb
parents:
diff changeset
209 encoder->bind = bind_faac;
854990f357ee added faac audio encoder
nicodvb
parents:
diff changeset
210 encoder->get_frame_size = get_frame_size;
854990f357ee added faac audio encoder
nicodvb
parents:
diff changeset
211 encoder->encode = encode_faac;
854990f357ee added faac audio encoder
nicodvb
parents:
diff changeset
212 encoder->close = close_faac;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 25315
diff changeset
213
15259
854990f357ee added faac audio encoder
nicodvb
parents:
diff changeset
214 return 1;
854990f357ee added faac audio encoder
nicodvb
parents:
diff changeset
215 }