Mercurial > mplayer.hg
annotate libmpcodecs/ae_faac.c @ 32404:2f42741403a8
ignore debhelper generated debug logfiles
author | siretart |
---|---|
date | Thu, 14 Oct 2010 08:43:19 +0000 |
parents | d332ea379205 |
children | 14b18f6659d7 |
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 | 19 #include <stdio.h> |
20 #include <stdlib.h> | |
21 #include <inttypes.h> | |
22 #include <unistd.h> | |
23 #include <string.h> | |
24 #include <sys/types.h> | |
25 #include "m_option.h" | |
17012 | 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 | 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 | 33 #include <faac.h> |
34 #include "ae.h" | |
35 | |
36 | |
37 static faacEncHandle faac; | |
38 static faacEncConfigurationPtr config = NULL; | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
25315
diff
changeset
|
39 static int |
15259 | 40 param_bitrate = 128, |
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 | 43 param_mpeg = 2, |
44 param_tns = 0, | |
45 param_raw = 0, | |
46 param_cutoff = 0, | |
47 param_format = 16, | |
48 param_debug = 0; | |
49 | |
50 static int enc_frame_size = 0, divisor; | |
51 static unsigned long samples_input, max_bytes_output; | |
52 static unsigned char *decoder_specific_buffer = NULL; | |
53 static unsigned long decoder_specific_len = 0; | |
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 | 56 {"br", ¶m_bitrate, CONF_TYPE_INT, 0, 0, 0, NULL}, |
57 {"quality", ¶m_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", ¶m_object_type, CONF_TYPE_INT, CONF_RANGE, 1, 4, NULL}, |
15259 | 59 {"mpeg", ¶m_mpeg, CONF_TYPE_INT, CONF_RANGE, 2, 4, NULL}, |
60 {"tns", ¶m_tns, CONF_TYPE_FLAG, 0, 0, 1, NULL}, | |
61 {"cutoff", ¶m_cutoff, CONF_TYPE_INT, 0, 0, 0, NULL}, | |
62 {"format", ¶m_format, CONF_TYPE_INT, 0, 0, 0, NULL}, | |
63 {"raw", ¶m_raw, CONF_TYPE_FLAG, 0, 0, 1, NULL}, | |
64 {"debug", ¶m_debug, CONF_TYPE_INT, CONF_RANGE, 0, 100000000, NULL}, | |
65 {NULL, NULL, 0, 0, 0, 0, NULL} | |
66 }; | |
67 | |
68 | |
69 static int bind_faac(audio_encoder_t *encoder, muxer_stream_t *mux_a) | |
70 { | |
32121 | 71 mux_a->wf = calloc(1, sizeof(*mux_a->wf) + decoder_specific_len + 256); |
15259 | 72 mux_a->wf->wFormatTag = 0x706D; |
73 mux_a->wf->nChannels = encoder->params.channels; | |
74 mux_a->h.dwSampleSize=0; // VBR | |
75 mux_a->h.dwRate=encoder->params.sample_rate; | |
76 mux_a->h.dwScale=encoder->params.samples_per_frame; | |
77 mux_a->wf->nSamplesPerSec=mux_a->h.dwRate; | |
15276 | 78 mux_a->wf->nAvgBytesPerSec = encoder->params.bitrate / 8; |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
25315
diff
changeset
|
79 |
15259 | 80 mux_a->wf->nBlockAlign = mux_a->h.dwScale; |
81 mux_a->h.dwSuggestedBufferSize = (encoder->params.audio_preload*mux_a->wf->nAvgBytesPerSec)/1000; | |
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 | 84 mux_a->wf->cbSize = decoder_specific_len; |
85 mux_a->wf->wBitsPerSample = 0; /* does not apply */ | |
86 ((MPEGLAYER3WAVEFORMAT *) (mux_a->wf))->wID = 1; | |
87 ((MPEGLAYER3WAVEFORMAT *) (mux_a->wf))->fdwFlags = 2; | |
88 ((MPEGLAYER3WAVEFORMAT *) (mux_a->wf))->nBlockSize = mux_a->wf->nBlockAlign; | |
89 ((MPEGLAYER3WAVEFORMAT *) (mux_a->wf))->nFramesPerBlock = 1; | |
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 |
32121 | 93 mux_a->wf = realloc(mux_a->wf, sizeof(*mux_a->wf)+mux_a->wf->cbSize); |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
25315
diff
changeset
|
94 |
15259 | 95 if(config->inputFormat == FAAC_INPUT_FLOAT) |
96 encoder->input_format = AF_FORMAT_FLOAT_NE; | |
97 else if(config->inputFormat == FAAC_INPUT_32BIT) | |
98 encoder->input_format = AF_FORMAT_S32_NE; | |
99 else | |
100 encoder->input_format = AF_FORMAT_S16_NE; | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
25315
diff
changeset
|
101 |
15259 | 102 encoder->min_buffer_size = mux_a->h.dwSuggestedBufferSize; |
103 encoder->max_buffer_size = mux_a->h.dwSuggestedBufferSize*2; | |
104 | |
105 if(decoder_specific_buffer && decoder_specific_len) | |
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 | 108 return 1; |
109 } | |
110 | |
111 static int get_frame_size(audio_encoder_t *encoder) | |
112 { | |
113 int sz = enc_frame_size; | |
114 enc_frame_size = 0; | |
115 return sz; | |
116 } | |
117 | |
118 static int encode_faac(audio_encoder_t *encoder, uint8_t *dest, void *src, int len, int max_size) | |
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 | 126 // len is divided by the number of bytes per sample |
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 | 129 return enc_frame_size; |
130 } | |
131 | |
132 int close_faac(audio_encoder_t *encoder) | |
133 { | |
134 return 1; | |
135 } | |
136 | |
137 int mpae_init_faac(audio_encoder_t *encoder) | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
25315
diff
changeset
|
138 { |
15259 | 139 if(encoder->params.channels < 1 || encoder->params.channels > 6 || (param_mpeg != 2 && param_mpeg != 4)) |
140 { | |
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); | |
142 return 0; | |
143 } | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
25315
diff
changeset
|
144 |
15259 | 145 faac = faacEncOpen(encoder->params.sample_rate, encoder->params.channels, &samples_input, &max_bytes_output); |
146 if(!faac) | |
147 { | |
148 mp_msg(MSGT_MENCODER, MSGL_FATAL, "AE_FAAC, couldn't init, exit\n"); | |
149 return 0; | |
150 } | |
17366 | 151 mp_msg(MSGT_MENCODER, MSGL_V, "AE_FAAC, sample_input: %lu, max_bytes_output: %lu\n", samples_input, max_bytes_output); |
15259 | 152 config = faacEncGetCurrentConfiguration(faac); |
153 if(!config) | |
154 { | |
155 mp_msg(MSGT_MENCODER, MSGL_FATAL, "AE_FAAC, couldn't get init configuration, exit\n"); | |
156 return 0; | |
157 } | |
158 | |
159 param_bitrate *= 1000; | |
160 if(param_quality) | |
161 config->quantqual = param_quality; | |
162 else | |
163 config->bitRate = param_bitrate / encoder->params.channels; | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
25315
diff
changeset
|
164 |
15259 | 165 if(param_format==33) |
166 { | |
167 config->inputFormat = FAAC_INPUT_FLOAT; | |
168 divisor = 4; | |
169 } | |
170 else if(param_format==32) | |
171 { | |
172 config->inputFormat = FAAC_INPUT_32BIT; | |
173 divisor = 4; | |
174 } | |
175 else | |
176 { | |
177 config->inputFormat = FAAC_INPUT_16BIT; | |
178 divisor = 2; | |
179 } | |
180 config->outputFormat = param_raw ? 0 : 1; // 1 is ADTS | |
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 | 183 config->mpegVersion = (param_mpeg == 4 ? MPEG4 : MPEG2); |
184 config->useTns = param_tns; | |
185 config->allowMidside = 1; | |
186 config->shortctl = SHORTCTL_NORMAL; | |
187 param_cutoff = param_cutoff ? param_cutoff : encoder->params.sample_rate / 2; | |
188 if(param_cutoff > encoder->params.sample_rate / 2) | |
189 param_cutoff = encoder->params.sample_rate / 2; | |
190 config->bandWidth = param_cutoff; | |
191 if(encoder->params.channels == 6) | |
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 | 195 { |
196 mp_msg(MSGT_MENCODER, MSGL_FATAL, "AE_FAAC, counldn't set specified parameters, exiting\n"); | |
197 return 0; | |
198 } | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
25315
diff
changeset
|
199 |
15259 | 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 | 202 else |
203 decoder_specific_len = 0; | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
25315
diff
changeset
|
204 |
15259 | 205 encoder->params.bitrate = param_bitrate; |
206 encoder->params.samples_per_frame = 1024; | |
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 | 209 encoder->bind = bind_faac; |
210 encoder->get_frame_size = get_frame_size; | |
211 encoder->encode = encode_faac; | |
212 encoder->close = close_faac; | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
25315
diff
changeset
|
213 |
15259 | 214 return 1; |
215 } |