Mercurial > mplayer.hg
annotate libmpcodecs/ae_faac.c @ 34757:da38eb1e2069
subassconvert: handle "\r\n" line ends
Previously the code converting text subtitles to ASS format converted newline
characters, and only those, to ASS "new line" markup. If the subtitles
contained "\r\n", the "\r" was thus left in the text. In previous libass
versions the "\r" was not visible, but in the current one it produces an empty
box. Improve the conversion to remove the "\r" in that case. Also treat a lone
"\r" as a newline.
Picked from mplayer2/3e0a2705
author | cboesch |
---|---|
date | Sat, 07 Apr 2012 11:17:09 +0000 |
parents | 14b18f6659d7 |
children |
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" | |
33847
14b18f6659d7
ae_faac: mark a function as static; add missing ae_faac.h #include
diego
parents:
32121
diff
changeset
|
35 #include "ae_faac.h" |
15259 | 36 |
37 | |
38 static faacEncHandle faac; | |
39 static faacEncConfigurationPtr config = NULL; | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
25315
diff
changeset
|
40 static int |
15259 | 41 param_bitrate = 128, |
42 param_quality = 0, | |
20080
5aab07acf0b5
workaround redefinition of object_type as prev(object_type)+1
nicodvb
parents:
17366
diff
changeset
|
43 param_object_type = 1, |
15259 | 44 param_mpeg = 2, |
45 param_tns = 0, | |
46 param_raw = 0, | |
47 param_cutoff = 0, | |
48 param_format = 16, | |
49 param_debug = 0; | |
50 | |
51 static int enc_frame_size = 0, divisor; | |
52 static unsigned long samples_input, max_bytes_output; | |
53 static unsigned char *decoder_specific_buffer = NULL; | |
54 static unsigned long decoder_specific_len = 0; | |
55 | |
30955
4e59a7aebadb
Mark encoder-related m_option_t struct arrays as const.
diego
parents:
30421
diff
changeset
|
56 const m_option_t faacopts_conf[] = { |
15259 | 57 {"br", ¶m_bitrate, CONF_TYPE_INT, 0, 0, 0, NULL}, |
58 {"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
|
59 {"object", ¶m_object_type, CONF_TYPE_INT, CONF_RANGE, 1, 4, NULL}, |
15259 | 60 {"mpeg", ¶m_mpeg, CONF_TYPE_INT, CONF_RANGE, 2, 4, NULL}, |
61 {"tns", ¶m_tns, CONF_TYPE_FLAG, 0, 0, 1, NULL}, | |
62 {"cutoff", ¶m_cutoff, CONF_TYPE_INT, 0, 0, 0, NULL}, | |
63 {"format", ¶m_format, CONF_TYPE_INT, 0, 0, 0, NULL}, | |
64 {"raw", ¶m_raw, CONF_TYPE_FLAG, 0, 0, 1, NULL}, | |
65 {"debug", ¶m_debug, CONF_TYPE_INT, CONF_RANGE, 0, 100000000, NULL}, | |
66 {NULL, NULL, 0, 0, 0, 0, NULL} | |
67 }; | |
68 | |
69 | |
70 static int bind_faac(audio_encoder_t *encoder, muxer_stream_t *mux_a) | |
71 { | |
32121 | 72 mux_a->wf = calloc(1, sizeof(*mux_a->wf) + decoder_specific_len + 256); |
15259 | 73 mux_a->wf->wFormatTag = 0x706D; |
74 mux_a->wf->nChannels = encoder->params.channels; | |
75 mux_a->h.dwSampleSize=0; // VBR | |
76 mux_a->h.dwRate=encoder->params.sample_rate; | |
77 mux_a->h.dwScale=encoder->params.samples_per_frame; | |
78 mux_a->wf->nSamplesPerSec=mux_a->h.dwRate; | |
15276 | 79 mux_a->wf->nAvgBytesPerSec = encoder->params.bitrate / 8; |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
25315
diff
changeset
|
80 |
15259 | 81 mux_a->wf->nBlockAlign = mux_a->h.dwScale; |
82 mux_a->h.dwSuggestedBufferSize = (encoder->params.audio_preload*mux_a->wf->nAvgBytesPerSec)/1000; | |
83 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
|
84 |
15259 | 85 mux_a->wf->cbSize = decoder_specific_len; |
86 mux_a->wf->wBitsPerSample = 0; /* does not apply */ | |
87 ((MPEGLAYER3WAVEFORMAT *) (mux_a->wf))->wID = 1; | |
88 ((MPEGLAYER3WAVEFORMAT *) (mux_a->wf))->fdwFlags = 2; | |
89 ((MPEGLAYER3WAVEFORMAT *) (mux_a->wf))->nBlockSize = mux_a->wf->nBlockAlign; | |
90 ((MPEGLAYER3WAVEFORMAT *) (mux_a->wf))->nFramesPerBlock = 1; | |
91 ((MPEGLAYER3WAVEFORMAT *) (mux_a->wf))->nCodecDelay = 0; | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
25315
diff
changeset
|
92 |
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
25315
diff
changeset
|
93 // Fix allocation |
32121 | 94 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
|
95 |
15259 | 96 if(config->inputFormat == FAAC_INPUT_FLOAT) |
97 encoder->input_format = AF_FORMAT_FLOAT_NE; | |
98 else if(config->inputFormat == FAAC_INPUT_32BIT) | |
99 encoder->input_format = AF_FORMAT_S32_NE; | |
100 else | |
101 encoder->input_format = AF_FORMAT_S16_NE; | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
25315
diff
changeset
|
102 |
15259 | 103 encoder->min_buffer_size = mux_a->h.dwSuggestedBufferSize; |
104 encoder->max_buffer_size = mux_a->h.dwSuggestedBufferSize*2; | |
105 | |
106 if(decoder_specific_buffer && decoder_specific_len) | |
107 memcpy(mux_a->wf + 1, decoder_specific_buffer, decoder_specific_len); | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
25315
diff
changeset
|
108 |
15259 | 109 return 1; |
110 } | |
111 | |
112 static int get_frame_size(audio_encoder_t *encoder) | |
113 { | |
114 int sz = enc_frame_size; | |
115 enc_frame_size = 0; | |
116 return sz; | |
117 } | |
118 | |
119 static int encode_faac(audio_encoder_t *encoder, uint8_t *dest, void *src, int len, int max_size) | |
120 { | |
25315
dfa8a510c81c
Fix all current known multi-channel wrong order problems by adding
ulion
parents:
22601
diff
changeset
|
121 if (encoder->params.channels >= 5) |
dfa8a510c81c
Fix all current known multi-channel wrong order problems by adding
ulion
parents:
22601
diff
changeset
|
122 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
|
123 AF_CHANNEL_LAYOUT_AAC_DEFAULT, |
dfa8a510c81c
Fix all current known multi-channel wrong order problems by adding
ulion
parents:
22601
diff
changeset
|
124 encoder->params.channels, |
dfa8a510c81c
Fix all current known multi-channel wrong order problems by adding
ulion
parents:
22601
diff
changeset
|
125 len / divisor, divisor); |
dfa8a510c81c
Fix all current known multi-channel wrong order problems by adding
ulion
parents:
22601
diff
changeset
|
126 |
15259 | 127 // len is divided by the number of bytes per sample |
128 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
|
129 |
15259 | 130 return enc_frame_size; |
131 } | |
132 | |
33847
14b18f6659d7
ae_faac: mark a function as static; add missing ae_faac.h #include
diego
parents:
32121
diff
changeset
|
133 static int close_faac(audio_encoder_t *encoder) |
15259 | 134 { |
135 return 1; | |
136 } | |
137 | |
138 int mpae_init_faac(audio_encoder_t *encoder) | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
25315
diff
changeset
|
139 { |
15259 | 140 if(encoder->params.channels < 1 || encoder->params.channels > 6 || (param_mpeg != 2 && param_mpeg != 4)) |
141 { | |
142 mp_msg(MSGT_MENCODER, MSGL_FATAL, "AE_FAAC, unsupported number of channels: %d, or mpeg version: %d, exit\n", encoder->params.channels, param_mpeg); | |
143 return 0; | |
144 } | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
25315
diff
changeset
|
145 |
15259 | 146 faac = faacEncOpen(encoder->params.sample_rate, encoder->params.channels, &samples_input, &max_bytes_output); |
147 if(!faac) | |
148 { | |
149 mp_msg(MSGT_MENCODER, MSGL_FATAL, "AE_FAAC, couldn't init, exit\n"); | |
150 return 0; | |
151 } | |
17366 | 152 mp_msg(MSGT_MENCODER, MSGL_V, "AE_FAAC, sample_input: %lu, max_bytes_output: %lu\n", samples_input, max_bytes_output); |
15259 | 153 config = faacEncGetCurrentConfiguration(faac); |
154 if(!config) | |
155 { | |
156 mp_msg(MSGT_MENCODER, MSGL_FATAL, "AE_FAAC, couldn't get init configuration, exit\n"); | |
157 return 0; | |
158 } | |
159 | |
160 param_bitrate *= 1000; | |
161 if(param_quality) | |
162 config->quantqual = param_quality; | |
163 else | |
164 config->bitRate = param_bitrate / encoder->params.channels; | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
25315
diff
changeset
|
165 |
15259 | 166 if(param_format==33) |
167 { | |
168 config->inputFormat = FAAC_INPUT_FLOAT; | |
169 divisor = 4; | |
170 } | |
171 else if(param_format==32) | |
172 { | |
173 config->inputFormat = FAAC_INPUT_32BIT; | |
174 divisor = 4; | |
175 } | |
176 else | |
177 { | |
178 config->inputFormat = FAAC_INPUT_16BIT; | |
179 divisor = 2; | |
180 } | |
181 config->outputFormat = param_raw ? 0 : 1; // 1 is ADTS | |
182 config->aacObjectType = param_object_type; | |
20080
5aab07acf0b5
workaround redefinition of object_type as prev(object_type)+1
nicodvb
parents:
17366
diff
changeset
|
183 if(MAIN==0) config->aacObjectType--; |
15259 | 184 config->mpegVersion = (param_mpeg == 4 ? MPEG4 : MPEG2); |
185 config->useTns = param_tns; | |
186 config->allowMidside = 1; | |
187 config->shortctl = SHORTCTL_NORMAL; | |
188 param_cutoff = param_cutoff ? param_cutoff : encoder->params.sample_rate / 2; | |
189 if(param_cutoff > encoder->params.sample_rate / 2) | |
190 param_cutoff = encoder->params.sample_rate / 2; | |
191 config->bandWidth = param_cutoff; | |
192 if(encoder->params.channels == 6) | |
193 config->useLfe = 1; | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
25315
diff
changeset
|
194 |
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
25315
diff
changeset
|
195 if(!faacEncSetConfiguration(faac, config)) |
15259 | 196 { |
197 mp_msg(MSGT_MENCODER, MSGL_FATAL, "AE_FAAC, counldn't set specified parameters, exiting\n"); | |
198 return 0; | |
199 } | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
25315
diff
changeset
|
200 |
15259 | 201 if(param_raw) |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
25315
diff
changeset
|
202 faacEncGetDecoderSpecificInfo(faac, &decoder_specific_buffer, &decoder_specific_len); |
15259 | 203 else |
204 decoder_specific_len = 0; | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
25315
diff
changeset
|
205 |
15259 | 206 encoder->params.bitrate = param_bitrate; |
207 encoder->params.samples_per_frame = 1024; | |
208 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
|
209 |
15259 | 210 encoder->bind = bind_faac; |
211 encoder->get_frame_size = get_frame_size; | |
212 encoder->encode = encode_faac; | |
213 encoder->close = close_faac; | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
25315
diff
changeset
|
214 |
15259 | 215 return 1; |
216 } |