Mercurial > mplayer.hg
annotate libmpcodecs/ae_faac.c @ 25813:ba7bd4f7e322
Add global ass_force_reload flag.
If it is set, renderer is reconfigured before the next frame.
author | eugeni |
---|---|
date | Wed, 23 Jan 2008 21:18:30 +0000 |
parents | dfa8a510c81c |
children | 0f1b5b68af32 |
rev | line source |
---|---|
15259 | 1 #include <stdio.h> |
2 #include <stdlib.h> | |
3 #include <inttypes.h> | |
4 #include <unistd.h> | |
5 #include <string.h> | |
6 #include <sys/types.h> | |
7 #include "m_option.h" | |
17012 | 8 #include "mp_msg.h" |
22601
ed8f90096c65
Add explicit location for headers from the libmpdemux/ directory.
diego
parents:
22600
diff
changeset
|
9 #include "libmpdemux/aviheader.h" |
17012 | 10 #include "libaf/af_format.h" |
25315
dfa8a510c81c
Fix all current known multi-channel wrong order problems by adding
ulion
parents:
22601
diff
changeset
|
11 #include "libaf/reorder_ch.h" |
22601
ed8f90096c65
Add explicit location for headers from the libmpdemux/ directory.
diego
parents:
22600
diff
changeset
|
12 #include "libmpdemux/ms_hdr.h" |
22600
3c2b4a866c6a
Add explicit location for headers from the stream/ directory.
diego
parents:
21660
diff
changeset
|
13 #include "stream/stream.h" |
22601
ed8f90096c65
Add explicit location for headers from the libmpdemux/ directory.
diego
parents:
22600
diff
changeset
|
14 #include "libmpdemux/muxer.h" |
15259 | 15 #include <faac.h> |
16 #include "ae.h" | |
17 | |
18 | |
19 static faacEncHandle faac; | |
20 static faacEncConfigurationPtr config = NULL; | |
21 static int | |
22 param_bitrate = 128, | |
23 param_quality = 0, | |
20080
5aab07acf0b5
workaround redefinition of object_type as prev(object_type)+1
nicodvb
parents:
17366
diff
changeset
|
24 param_object_type = 1, |
15259 | 25 param_mpeg = 2, |
26 param_tns = 0, | |
27 param_raw = 0, | |
28 param_cutoff = 0, | |
29 param_format = 16, | |
30 param_debug = 0; | |
31 | |
32 static int enc_frame_size = 0, divisor; | |
33 static unsigned long samples_input, max_bytes_output; | |
34 static unsigned char *decoder_specific_buffer = NULL; | |
35 static unsigned long decoder_specific_len = 0; | |
36 | |
37 m_option_t faacopts_conf[] = { | |
38 {"br", ¶m_bitrate, CONF_TYPE_INT, 0, 0, 0, NULL}, | |
39 {"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
|
40 {"object", ¶m_object_type, CONF_TYPE_INT, CONF_RANGE, 1, 4, NULL}, |
15259 | 41 {"mpeg", ¶m_mpeg, CONF_TYPE_INT, CONF_RANGE, 2, 4, NULL}, |
42 {"tns", ¶m_tns, CONF_TYPE_FLAG, 0, 0, 1, NULL}, | |
43 {"cutoff", ¶m_cutoff, CONF_TYPE_INT, 0, 0, 0, NULL}, | |
44 {"format", ¶m_format, CONF_TYPE_INT, 0, 0, 0, NULL}, | |
45 {"raw", ¶m_raw, CONF_TYPE_FLAG, 0, 0, 1, NULL}, | |
46 {"debug", ¶m_debug, CONF_TYPE_INT, CONF_RANGE, 0, 100000000, NULL}, | |
47 {NULL, NULL, 0, 0, 0, 0, NULL} | |
48 }; | |
49 | |
50 | |
51 static int bind_faac(audio_encoder_t *encoder, muxer_stream_t *mux_a) | |
52 { | |
53 mux_a->wf = calloc(1, sizeof(WAVEFORMATEX) + decoder_specific_len + 256); | |
54 mux_a->wf->wFormatTag = 0x706D; | |
55 mux_a->wf->nChannels = encoder->params.channels; | |
56 mux_a->h.dwSampleSize=0; // VBR | |
57 mux_a->h.dwRate=encoder->params.sample_rate; | |
58 mux_a->h.dwScale=encoder->params.samples_per_frame; | |
59 mux_a->wf->nSamplesPerSec=mux_a->h.dwRate; | |
15276 | 60 mux_a->wf->nAvgBytesPerSec = encoder->params.bitrate / 8; |
15259 | 61 |
62 mux_a->wf->nBlockAlign = mux_a->h.dwScale; | |
63 mux_a->h.dwSuggestedBufferSize = (encoder->params.audio_preload*mux_a->wf->nAvgBytesPerSec)/1000; | |
64 mux_a->h.dwSuggestedBufferSize -= mux_a->h.dwSuggestedBufferSize % mux_a->wf->nBlockAlign; | |
65 | |
66 mux_a->wf->cbSize = decoder_specific_len; | |
67 mux_a->wf->wBitsPerSample = 0; /* does not apply */ | |
68 ((MPEGLAYER3WAVEFORMAT *) (mux_a->wf))->wID = 1; | |
69 ((MPEGLAYER3WAVEFORMAT *) (mux_a->wf))->fdwFlags = 2; | |
70 ((MPEGLAYER3WAVEFORMAT *) (mux_a->wf))->nBlockSize = mux_a->wf->nBlockAlign; | |
71 ((MPEGLAYER3WAVEFORMAT *) (mux_a->wf))->nFramesPerBlock = 1; | |
72 ((MPEGLAYER3WAVEFORMAT *) (mux_a->wf))->nCodecDelay = 0; | |
73 | |
74 // Fix allocation | |
75 mux_a->wf = realloc(mux_a->wf, sizeof(WAVEFORMATEX)+mux_a->wf->cbSize); | |
76 | |
77 if(config->inputFormat == FAAC_INPUT_FLOAT) | |
78 encoder->input_format = AF_FORMAT_FLOAT_NE; | |
79 else if(config->inputFormat == FAAC_INPUT_32BIT) | |
80 encoder->input_format = AF_FORMAT_S32_NE; | |
81 else | |
82 encoder->input_format = AF_FORMAT_S16_NE; | |
83 | |
84 encoder->min_buffer_size = mux_a->h.dwSuggestedBufferSize; | |
85 encoder->max_buffer_size = mux_a->h.dwSuggestedBufferSize*2; | |
86 | |
87 if(decoder_specific_buffer && decoder_specific_len) | |
88 memcpy(mux_a->wf + 1, decoder_specific_buffer, decoder_specific_len); | |
89 | |
90 return 1; | |
91 } | |
92 | |
93 static int get_frame_size(audio_encoder_t *encoder) | |
94 { | |
95 int sz = enc_frame_size; | |
96 enc_frame_size = 0; | |
97 return sz; | |
98 } | |
99 | |
100 static int encode_faac(audio_encoder_t *encoder, uint8_t *dest, void *src, int len, int max_size) | |
101 { | |
25315
dfa8a510c81c
Fix all current known multi-channel wrong order problems by adding
ulion
parents:
22601
diff
changeset
|
102 if (encoder->params.channels >= 5) |
dfa8a510c81c
Fix all current known multi-channel wrong order problems by adding
ulion
parents:
22601
diff
changeset
|
103 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
|
104 AF_CHANNEL_LAYOUT_AAC_DEFAULT, |
dfa8a510c81c
Fix all current known multi-channel wrong order problems by adding
ulion
parents:
22601
diff
changeset
|
105 encoder->params.channels, |
dfa8a510c81c
Fix all current known multi-channel wrong order problems by adding
ulion
parents:
22601
diff
changeset
|
106 len / divisor, divisor); |
dfa8a510c81c
Fix all current known multi-channel wrong order problems by adding
ulion
parents:
22601
diff
changeset
|
107 |
15259 | 108 // len is divided by the number of bytes per sample |
109 enc_frame_size = faacEncEncode(faac, (int32_t*) src, len / divisor, dest, max_size); | |
110 | |
111 return enc_frame_size; | |
112 } | |
113 | |
114 int close_faac(audio_encoder_t *encoder) | |
115 { | |
116 return 1; | |
117 } | |
118 | |
119 int mpae_init_faac(audio_encoder_t *encoder) | |
120 { | |
121 if(encoder->params.channels < 1 || encoder->params.channels > 6 || (param_mpeg != 2 && param_mpeg != 4)) | |
122 { | |
123 mp_msg(MSGT_MENCODER, MSGL_FATAL, "AE_FAAC, unsupported number of channels: %d, or mpeg version: %d, exit\n", encoder->params.channels, param_mpeg); | |
124 return 0; | |
125 } | |
126 | |
127 faac = faacEncOpen(encoder->params.sample_rate, encoder->params.channels, &samples_input, &max_bytes_output); | |
128 if(!faac) | |
129 { | |
130 mp_msg(MSGT_MENCODER, MSGL_FATAL, "AE_FAAC, couldn't init, exit\n"); | |
131 return 0; | |
132 } | |
17366 | 133 mp_msg(MSGT_MENCODER, MSGL_V, "AE_FAAC, sample_input: %lu, max_bytes_output: %lu\n", samples_input, max_bytes_output); |
15259 | 134 config = faacEncGetCurrentConfiguration(faac); |
135 if(!config) | |
136 { | |
137 mp_msg(MSGT_MENCODER, MSGL_FATAL, "AE_FAAC, couldn't get init configuration, exit\n"); | |
138 return 0; | |
139 } | |
140 | |
141 param_bitrate *= 1000; | |
142 if(param_quality) | |
143 config->quantqual = param_quality; | |
144 else | |
145 config->bitRate = param_bitrate / encoder->params.channels; | |
146 | |
147 if(param_format==33) | |
148 { | |
149 config->inputFormat = FAAC_INPUT_FLOAT; | |
150 divisor = 4; | |
151 } | |
152 else if(param_format==32) | |
153 { | |
154 config->inputFormat = FAAC_INPUT_32BIT; | |
155 divisor = 4; | |
156 } | |
157 else | |
158 { | |
159 config->inputFormat = FAAC_INPUT_16BIT; | |
160 divisor = 2; | |
161 } | |
162 config->outputFormat = param_raw ? 0 : 1; // 1 is ADTS | |
163 config->aacObjectType = param_object_type; | |
20080
5aab07acf0b5
workaround redefinition of object_type as prev(object_type)+1
nicodvb
parents:
17366
diff
changeset
|
164 if(MAIN==0) config->aacObjectType--; |
15259 | 165 config->mpegVersion = (param_mpeg == 4 ? MPEG4 : MPEG2); |
166 config->useTns = param_tns; | |
167 config->allowMidside = 1; | |
168 config->shortctl = SHORTCTL_NORMAL; | |
169 param_cutoff = param_cutoff ? param_cutoff : encoder->params.sample_rate / 2; | |
170 if(param_cutoff > encoder->params.sample_rate / 2) | |
171 param_cutoff = encoder->params.sample_rate / 2; | |
172 config->bandWidth = param_cutoff; | |
173 if(encoder->params.channels == 6) | |
174 config->useLfe = 1; | |
175 | |
176 if(!faacEncSetConfiguration(faac, config)) | |
177 { | |
178 mp_msg(MSGT_MENCODER, MSGL_FATAL, "AE_FAAC, counldn't set specified parameters, exiting\n"); | |
179 return 0; | |
180 } | |
181 | |
182 if(param_raw) | |
183 faacEncGetDecoderSpecificInfo(faac, &decoder_specific_buffer, &decoder_specific_len); | |
184 else | |
185 decoder_specific_len = 0; | |
186 | |
187 encoder->params.bitrate = param_bitrate; | |
188 encoder->params.samples_per_frame = 1024; | |
189 encoder->decode_buffer_size = divisor * samples_input; //samples * 16 bits_per_sample | |
190 | |
191 encoder->bind = bind_faac; | |
192 encoder->get_frame_size = get_frame_size; | |
193 encoder->encode = encode_faac; | |
194 encoder->close = close_faac; | |
195 | |
196 return 1; | |
197 } |