Mercurial > mplayer.hg
annotate libmpcodecs/ae_twolame.c @ 37151:c63629427fde
Apply skin defaults in Win32 GUI.
The starting defaults for volume, balance and movie position are defined
in the skin used by the GUI. So far, the Win32 GUI has completely ignored
these.
Based on a patch by Stephen Sheldon, sfsheldo gmail com.
author | ib |
---|---|
date | Wed, 06 Aug 2014 16:35:38 +0000 |
parents | 5a59a2cfcc80 |
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 |
15359 | 19 #include <stdio.h> |
20 #include <stdlib.h> | |
21 #include <inttypes.h> | |
22 #include <unistd.h> | |
23 #include <string.h> | |
35903 | 24 #include <strings.h> |
15359 | 25 #include <sys/types.h> |
31437 | 26 #include <twolame.h> |
27 | |
15359 | 28 #include "m_option.h" |
17012 | 29 #include "mp_msg.h" |
22601
ed8f90096c65
Add explicit location for headers from the libmpdemux/ directory.
diego
parents:
22600
diff
changeset
|
30 #include "libmpdemux/aviheader.h" |
17012 | 31 #include "libaf/af_format.h" |
22601
ed8f90096c65
Add explicit location for headers from the libmpdemux/ directory.
diego
parents:
22600
diff
changeset
|
32 #include "libmpdemux/ms_hdr.h" |
22600
3c2b4a866c6a
Add explicit location for headers from the stream/ directory.
diego
parents:
21660
diff
changeset
|
33 #include "stream/stream.h" |
22601
ed8f90096c65
Add explicit location for headers from the libmpdemux/ directory.
diego
parents:
22600
diff
changeset
|
34 #include "libmpdemux/muxer.h" |
15359 | 35 #include "ae_twolame.h" |
17012 | 36 #include "libmpdemux/mp3_hdr.h" |
15359 | 37 |
38 | |
31437 | 39 typedef struct { |
40 twolame_options *twolame_ctx; | |
41 int vbr; | |
42 } mpae_twolame_ctx; | |
43 | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
27843
diff
changeset
|
44 static int |
15359 | 45 param_bitrate = 192, |
46 param_psy = 3, | |
47 param_maxvbr = 0, | |
48 param_errprot = 0, | |
49 param_debug = 0; | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
27843
diff
changeset
|
50 |
15359 | 51 static float param_vbr = 0; |
52 static char *param_mode = "stereo"; | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
27843
diff
changeset
|
53 |
30955
4e59a7aebadb
Mark encoder-related m_option_t struct arrays as const.
diego
parents:
30741
diff
changeset
|
54 const m_option_t twolameopts_conf[] = { |
15359 | 55 {"br", ¶m_bitrate, CONF_TYPE_INT, 0, 0, 0, NULL}, |
56 {"mode", ¶m_mode, CONF_TYPE_STRING, 0, 0, 0, NULL}, | |
15362
4ff00aa141ef
updated psycho model range; made a parameter file-static in ae_toolame.c
nicodvb
parents:
15359
diff
changeset
|
57 {"psy", ¶m_psy, CONF_TYPE_INT, CONF_RANGE, -1, 4, NULL}, |
15359 | 58 {"vbr", ¶m_vbr, CONF_TYPE_FLOAT, CONF_RANGE, -50, 50, NULL}, |
59 {"maxvbr", ¶m_maxvbr, CONF_TYPE_INT, 0, 0, 0, NULL}, | |
60 {"errprot", ¶m_errprot, CONF_TYPE_INT, CONF_RANGE, 0, 1, NULL}, | |
61 {"debug", ¶m_debug, CONF_TYPE_INT, CONF_RANGE, 0, 100000000, NULL}, | |
62 {NULL, NULL, 0, 0, 0, 0, NULL} | |
63 }; | |
64 | |
65 | |
66 static int bind_twolame(audio_encoder_t *encoder, muxer_stream_t *mux_a) | |
67 { | |
27843 | 68 mpae_twolame_ctx *ctx = encoder->priv; |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
27843
diff
changeset
|
69 |
32121 | 70 mux_a->wf = malloc(sizeof(*mux_a->wf)+256); |
15359 | 71 mux_a->wf->wFormatTag = 0x50; |
72 mux_a->wf->nChannels = encoder->params.channels; | |
73 mux_a->wf->nSamplesPerSec = encoder->params.sample_rate; | |
74 mux_a->wf->nAvgBytesPerSec = encoder->params.bitrate / 8; | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
27843
diff
changeset
|
75 |
15359 | 76 if(ctx->vbr || ((mux_a->wf->nAvgBytesPerSec * encoder->params.samples_per_frame) % mux_a->wf->nSamplesPerSec)) |
77 { | |
78 mux_a->h.dwScale = encoder->params.samples_per_frame; | |
79 mux_a->h.dwRate = encoder->params.sample_rate; | |
80 mux_a->h.dwSampleSize = 0; // Blocksize not constant | |
81 } | |
82 else | |
83 { | |
84 mux_a->h.dwScale = (mux_a->wf->nAvgBytesPerSec * encoder->params.samples_per_frame)/ mux_a->wf->nSamplesPerSec; /* for cbr */ | |
85 mux_a->h.dwRate = mux_a->wf->nAvgBytesPerSec; | |
86 mux_a->h.dwSampleSize = mux_a->h.dwScale; | |
87 } | |
88 mux_a->wf->nBlockAlign = mux_a->h.dwScale; | |
89 mux_a->h.dwSuggestedBufferSize = (encoder->params.audio_preload*mux_a->wf->nAvgBytesPerSec)/1000; | |
90 mux_a->h.dwSuggestedBufferSize -= mux_a->h.dwSuggestedBufferSize % mux_a->wf->nBlockAlign; | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
27843
diff
changeset
|
91 |
15359 | 92 mux_a->wf->cbSize = 0; //12; |
93 mux_a->wf->wBitsPerSample = 0; /* does not apply */ | |
94 ((MPEGLAYER3WAVEFORMAT *) (mux_a->wf))->wID = 1; | |
95 ((MPEGLAYER3WAVEFORMAT *) (mux_a->wf))->fdwFlags = 2; | |
96 ((MPEGLAYER3WAVEFORMAT *) (mux_a->wf))->nBlockSize = mux_a->wf->nBlockAlign; | |
97 ((MPEGLAYER3WAVEFORMAT *) (mux_a->wf))->nFramesPerBlock = 1; | |
98 ((MPEGLAYER3WAVEFORMAT *) (mux_a->wf))->nCodecDelay = 0; | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
27843
diff
changeset
|
99 |
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
27843
diff
changeset
|
100 // Fix allocation |
32121 | 101 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:
27843
diff
changeset
|
102 |
15359 | 103 encoder->input_format = AF_FORMAT_S16_NE; |
104 encoder->min_buffer_size = mux_a->h.dwSuggestedBufferSize; | |
105 encoder->max_buffer_size = mux_a->h.dwSuggestedBufferSize*2; | |
106 | |
107 return 1; | |
108 } | |
109 | |
110 static int encode_twolame(audio_encoder_t *encoder, uint8_t *dest, void *src, int len, int max_size) | |
111 { | |
27843 | 112 mpae_twolame_ctx *ctx = encoder->priv; |
15359 | 113 int ret_size = 0, r2; |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
27843
diff
changeset
|
114 |
37099
5a59a2cfcc80
mencoder: Support flushing audio encoders at end of stream.
reimar
parents:
37035
diff
changeset
|
115 if (!src) |
5a59a2cfcc80
mencoder: Support flushing audio encoders at end of stream.
reimar
parents:
37035
diff
changeset
|
116 return twolame_encode_flush(ctx->twolame_ctx, dest, max_size); |
5a59a2cfcc80
mencoder: Support flushing audio encoders at end of stream.
reimar
parents:
37035
diff
changeset
|
117 |
15359 | 118 len /= (2*encoder->params.channels); |
119 ret_size = twolame_encode_buffer_interleaved(ctx->twolame_ctx, src, len, dest, max_size); | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
27843
diff
changeset
|
120 r2 = mp_decode_mp3_header(dest); |
16482 | 121 mp_msg(MSGT_MENCODER, MSGL_DBG2, "\nSIZE: %d, max: %d, r2: %d\n", ret_size, max_size, r2); |
15359 | 122 if(r2 > 0) |
123 ret_size = r2; | |
124 return ret_size; | |
125 } | |
126 | |
30741
3cf4f49c2e87
Make close_twolame() static, only used in ae_twolame.c.
cehoyos
parents:
30633
diff
changeset
|
127 static int close_twolame(audio_encoder_t *encoder) |
15359 | 128 { |
129 free(encoder->priv); | |
130 return 1; | |
131 } | |
132 | |
133 static int get_frame_size(audio_encoder_t *encoder) | |
134 { | |
135 int sz; | |
136 if(encoder->stream->buffer_len < 4) | |
137 return 0; | |
138 sz = mp_decode_mp3_header(encoder->stream->buffer); | |
139 if(sz <= 0) | |
140 return 0; | |
141 return sz; | |
142 } | |
143 | |
144 | |
145 int mpae_init_twolame(audio_encoder_t *encoder) | |
146 { | |
147 int mode; | |
148 mpae_twolame_ctx *ctx = NULL; | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
27843
diff
changeset
|
149 |
15359 | 150 if(encoder->params.channels == 1) |
151 { | |
152 mp_msg(MSGT_MENCODER, MSGL_INFO, "ae_twolame, 1 audio channel, forcing mono mode\n"); | |
153 mode = TWOLAME_MONO; | |
154 } | |
155 else if(encoder->params.channels == 2) | |
156 { | |
157 if(! strcasecmp(param_mode, "dual")) | |
158 mode = TWOLAME_DUAL_CHANNEL; | |
159 else if(! strcasecmp(param_mode, "jstereo")) | |
160 mode = TWOLAME_JOINT_STEREO; | |
161 else if(! strcasecmp(param_mode, "stereo")) | |
162 mode = TWOLAME_STEREO; | |
163 else | |
164 { | |
165 mp_msg(MSGT_MENCODER, MSGL_ERR, "ae_twolame, unknown mode %s, exiting\n", param_mode); | |
166 } | |
167 } | |
168 else | |
169 mp_msg(MSGT_MENCODER, MSGL_ERR, "ae_twolame, Twolame can't encode > 2 channels, exiting\n"); | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
27843
diff
changeset
|
170 |
27843 | 171 ctx = calloc(1, sizeof(mpae_twolame_ctx)); |
15359 | 172 if(ctx == NULL) |
173 { | |
37035 | 174 mp_msg(MSGT_MENCODER, MSGL_ERR, "ae_twolame, couldn't alloc context, exiting\n"); |
15359 | 175 return 0; |
176 } | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
27843
diff
changeset
|
177 |
15359 | 178 ctx->twolame_ctx = twolame_init(); |
179 if(ctx->twolame_ctx == NULL) | |
180 { | |
181 mp_msg(MSGT_MENCODER, MSGL_ERR, "ae_twolame, couldn't initial parameters from libtwolame, exiting\n"); | |
182 free(ctx); | |
183 return 0; | |
184 } | |
185 ctx->vbr = 0; | |
186 | |
187 if(twolame_set_num_channels(ctx->twolame_ctx, encoder->params.channels) != 0) | |
188 return 0; | |
189 if(twolame_set_mode(ctx->twolame_ctx, mode) != 0) | |
190 return 0; | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
27843
diff
changeset
|
191 |
15359 | 192 if(twolame_set_in_samplerate(ctx->twolame_ctx, encoder->params.sample_rate) != 0) |
193 return 0; | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
27843
diff
changeset
|
194 |
15359 | 195 if(twolame_set_out_samplerate(ctx->twolame_ctx, encoder->params.sample_rate) != 0) |
196 return 0; | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
27843
diff
changeset
|
197 |
15359 | 198 if(encoder->params.sample_rate < 32000) |
199 twolame_set_version(ctx->twolame_ctx, TWOLAME_MPEG2); | |
200 else | |
201 twolame_set_version(ctx->twolame_ctx, TWOLAME_MPEG1); | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
27843
diff
changeset
|
202 |
15359 | 203 if(twolame_set_psymodel(ctx->twolame_ctx, param_psy) != 0) |
204 return 0; | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
27843
diff
changeset
|
205 |
15359 | 206 if(twolame_set_bitrate(ctx->twolame_ctx, param_bitrate) != 0) |
207 return 0; | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
27843
diff
changeset
|
208 |
15359 | 209 if(param_errprot) |
210 if(twolame_set_error_protection(ctx->twolame_ctx, TRUE) != 0) | |
211 return 0; | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
27843
diff
changeset
|
212 |
15359 | 213 if(param_vbr != 0) |
214 { | |
215 if(twolame_set_VBR(ctx->twolame_ctx, TRUE) != 0) | |
216 return 0; | |
217 if(twolame_set_VBR_q(ctx->twolame_ctx, param_vbr) != 0) | |
218 return 0; | |
219 if(twolame_set_padding(ctx->twolame_ctx, FALSE) != 0) | |
220 return 0; | |
221 if(param_maxvbr) | |
222 { | |
223 if(twolame_set_VBR_max_bitrate_kbps(ctx->twolame_ctx, param_maxvbr) != 0) | |
224 return 0; | |
225 } | |
226 ctx->vbr = 1; | |
227 } | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
27843
diff
changeset
|
228 |
15359 | 229 if(twolame_set_verbosity(ctx->twolame_ctx, param_debug) != 0) |
230 return 0; | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
27843
diff
changeset
|
231 |
15359 | 232 if(twolame_init_params(ctx->twolame_ctx) != 0) |
233 return 0; | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
27843
diff
changeset
|
234 |
15359 | 235 encoder->params.bitrate = param_bitrate * 1000; |
236 encoder->params.samples_per_frame = 1152; | |
237 encoder->priv = ctx; | |
238 encoder->decode_buffer_size = 1152 * 2 * encoder->params.channels; | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
27843
diff
changeset
|
239 |
15359 | 240 encoder->bind = bind_twolame; |
241 encoder->get_frame_size = get_frame_size; | |
242 encoder->encode = encode_twolame; | |
243 encoder->close = close_twolame; | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
27843
diff
changeset
|
244 |
15359 | 245 return 1; |
246 } |