annotate libmpcodecs/ae_toolame.c @ 37171:29802bb119f6

Add new FFmpeg AMVF tag for AMV video.
author reimar
date Sat, 06 Sep 2014 19:51:59 +0000
parents 389d43c448b3
children
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
15234
e84a6ae9d51e audio encoding reworked
nicodvb
parents: 14550
diff changeset
19 #include <stdio.h>
e84a6ae9d51e audio encoding reworked
nicodvb
parents: 14550
diff changeset
20 #include <stdlib.h>
e84a6ae9d51e audio encoding reworked
nicodvb
parents: 14550
diff changeset
21 #include <inttypes.h>
15238
2cc48c37a7eb FreeBSD fix
nexus
parents: 15234
diff changeset
22 #include <unistd.h>
15234
e84a6ae9d51e audio encoding reworked
nicodvb
parents: 14550
diff changeset
23 #include <string.h>
35903
389d43c448b3 Add missing strings.h #includes for strcasecmp().
diego
parents: 32121
diff changeset
24 #include <strings.h>
15240
6d6792c02b6f macosx compilation fix
nicodvb
parents: 15238
diff changeset
25 #include <sys/types.h>
31436
bc52a219f741 Move mpae_toolame_ctx structure to ae_toolame.c.
diego
parents: 30955
diff changeset
26 #include <toolame.h>
bc52a219f741 Move mpae_toolame_ctx structure to ae_toolame.c.
diego
parents: 30955
diff changeset
27
13425
a87f1a948a24 encoding to mp2 with libtoolame - only cbr atm
nicodvb
parents:
diff changeset
28 #include "m_option.h"
17012
6ff3379a0862 Unify include path handling, -I.. is in CFLAGS.
diego
parents: 16482
diff changeset
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
6ff3379a0862 Unify include path handling, -I.. is in CFLAGS.
diego
parents: 16482
diff changeset
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"
13425
a87f1a948a24 encoding to mp2 with libtoolame - only cbr atm
nicodvb
parents:
diff changeset
35 #include "ae_toolame.h"
17012
6ff3379a0862 Unify include path handling, -I.. is in CFLAGS.
diego
parents: 16482
diff changeset
36 #include "libmpdemux/mp3_hdr.h"
13425
a87f1a948a24 encoding to mp2 with libtoolame - only cbr atm
nicodvb
parents:
diff changeset
37
a87f1a948a24 encoding to mp2 with libtoolame - only cbr atm
nicodvb
parents:
diff changeset
38
31436
bc52a219f741 Move mpae_toolame_ctx structure to ae_toolame.c.
diego
parents: 30955
diff changeset
39 typedef struct {
bc52a219f741 Move mpae_toolame_ctx structure to ae_toolame.c.
diego
parents: 30955
diff changeset
40 toolame_options *toolame_ctx;
bc52a219f741 Move mpae_toolame_ctx structure to ae_toolame.c.
diego
parents: 30955
diff changeset
41 int channels, srate, bitrate;
bc52a219f741 Move mpae_toolame_ctx structure to ae_toolame.c.
diego
parents: 30955
diff changeset
42 int vbr;
bc52a219f741 Move mpae_toolame_ctx structure to ae_toolame.c.
diego
parents: 30955
diff changeset
43 int16_t left_pcm[1152], right_pcm[1152];
bc52a219f741 Move mpae_toolame_ctx structure to ae_toolame.c.
diego
parents: 30955
diff changeset
44 } mpae_toolame_ctx;
bc52a219f741 Move mpae_toolame_ctx structure to ae_toolame.c.
diego
parents: 30955
diff changeset
45
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 22601
diff changeset
46 static int
13425
a87f1a948a24 encoding to mp2 with libtoolame - only cbr atm
nicodvb
parents:
diff changeset
47 param_bitrate = 192,
a87f1a948a24 encoding to mp2 with libtoolame - only cbr atm
nicodvb
parents:
diff changeset
48 param_psy = 3,
15265
92772475ed8d toolame now works in vbr mode, too
nicodvb
parents: 15240
diff changeset
49 param_maxvbr = 0,
13425
a87f1a948a24 encoding to mp2 with libtoolame - only cbr atm
nicodvb
parents:
diff changeset
50 param_errprot = 0,
a87f1a948a24 encoding to mp2 with libtoolame - only cbr atm
nicodvb
parents:
diff changeset
51 param_debug = 0;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 22601
diff changeset
52
15362
4ff00aa141ef updated psycho model range; made a parameter file-static in ae_toolame.c
nicodvb
parents: 15281
diff changeset
53 static float param_vbr = 0;
13425
a87f1a948a24 encoding to mp2 with libtoolame - only cbr atm
nicodvb
parents:
diff changeset
54 static char *param_mode = "stereo";
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 22601
diff changeset
55
30955
4e59a7aebadb Mark encoder-related m_option_t struct arrays as const.
diego
parents: 30743
diff changeset
56 const m_option_t toolameopts_conf[] = {
13425
a87f1a948a24 encoding to mp2 with libtoolame - only cbr atm
nicodvb
parents:
diff changeset
57 {"br", &param_bitrate, CONF_TYPE_INT, 0, 0, 0, NULL},
a87f1a948a24 encoding to mp2 with libtoolame - only cbr atm
nicodvb
parents:
diff changeset
58 {"mode", &param_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: 15281
diff changeset
59 {"psy", &param_psy, CONF_TYPE_INT, CONF_RANGE, -1, 4, NULL},
15281
dcf97e9eb7e8 fixed variability range
nicodvb
parents: 15265
diff changeset
60 {"vbr", &param_vbr, CONF_TYPE_FLOAT, CONF_RANGE, -50, 50, NULL},
13425
a87f1a948a24 encoding to mp2 with libtoolame - only cbr atm
nicodvb
parents:
diff changeset
61 {"maxvbr", &param_maxvbr, CONF_TYPE_INT, 0, 0, 0, NULL},
a87f1a948a24 encoding to mp2 with libtoolame - only cbr atm
nicodvb
parents:
diff changeset
62 {"errprot", &param_errprot, CONF_TYPE_INT, CONF_RANGE, 0, 1, NULL},
a87f1a948a24 encoding to mp2 with libtoolame - only cbr atm
nicodvb
parents:
diff changeset
63 {"debug", &param_debug, CONF_TYPE_INT, CONF_RANGE, 0, 100000000, NULL},
a87f1a948a24 encoding to mp2 with libtoolame - only cbr atm
nicodvb
parents:
diff changeset
64 {NULL, NULL, 0, 0, 0, 0, NULL}
a87f1a948a24 encoding to mp2 with libtoolame - only cbr atm
nicodvb
parents:
diff changeset
65 };
a87f1a948a24 encoding to mp2 with libtoolame - only cbr atm
nicodvb
parents:
diff changeset
66
a87f1a948a24 encoding to mp2 with libtoolame - only cbr atm
nicodvb
parents:
diff changeset
67
15234
e84a6ae9d51e audio encoding reworked
nicodvb
parents: 14550
diff changeset
68 static int bind_toolame(audio_encoder_t *encoder, muxer_stream_t *mux_a)
e84a6ae9d51e audio encoding reworked
nicodvb
parents: 14550
diff changeset
69 {
15265
92772475ed8d toolame now works in vbr mode, too
nicodvb
parents: 15240
diff changeset
70 mpae_toolame_ctx *ctx = (mpae_toolame_ctx *) encoder->priv;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 22601
diff changeset
71
32121
d332ea379205 Replace sizeof(WAVEFORMATEX) occurrences.
reimar
parents: 31436
diff changeset
72 mux_a->wf = malloc(sizeof(*mux_a->wf)+256);
15234
e84a6ae9d51e audio encoding reworked
nicodvb
parents: 14550
diff changeset
73 mux_a->wf->wFormatTag = 0x50;
e84a6ae9d51e audio encoding reworked
nicodvb
parents: 14550
diff changeset
74 mux_a->wf->nChannels = encoder->params.channels;
e84a6ae9d51e audio encoding reworked
nicodvb
parents: 14550
diff changeset
75 mux_a->wf->nSamplesPerSec = encoder->params.sample_rate;
e84a6ae9d51e audio encoding reworked
nicodvb
parents: 14550
diff changeset
76 mux_a->wf->nAvgBytesPerSec = 125 * encoder->params.bitrate;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 22601
diff changeset
77
15265
92772475ed8d toolame now works in vbr mode, too
nicodvb
parents: 15240
diff changeset
78 if(ctx->vbr || ((mux_a->wf->nAvgBytesPerSec * encoder->params.samples_per_frame) % mux_a->wf->nSamplesPerSec))
15234
e84a6ae9d51e audio encoding reworked
nicodvb
parents: 14550
diff changeset
79 {
e84a6ae9d51e audio encoding reworked
nicodvb
parents: 14550
diff changeset
80 mux_a->h.dwScale = encoder->params.samples_per_frame;
e84a6ae9d51e audio encoding reworked
nicodvb
parents: 14550
diff changeset
81 mux_a->h.dwRate = encoder->params.sample_rate;
e84a6ae9d51e audio encoding reworked
nicodvb
parents: 14550
diff changeset
82 mux_a->h.dwSampleSize = 0; // Blocksize not constant
15265
92772475ed8d toolame now works in vbr mode, too
nicodvb
parents: 15240
diff changeset
83 }
92772475ed8d toolame now works in vbr mode, too
nicodvb
parents: 15240
diff changeset
84 else
15234
e84a6ae9d51e audio encoding reworked
nicodvb
parents: 14550
diff changeset
85 {
15265
92772475ed8d toolame now works in vbr mode, too
nicodvb
parents: 15240
diff changeset
86 mux_a->h.dwScale = (mux_a->wf->nAvgBytesPerSec * encoder->params.samples_per_frame)/ mux_a->wf->nSamplesPerSec; /* for cbr */
92772475ed8d toolame now works in vbr mode, too
nicodvb
parents: 15240
diff changeset
87 mux_a->h.dwRate = mux_a->wf->nAvgBytesPerSec;
15234
e84a6ae9d51e audio encoding reworked
nicodvb
parents: 14550
diff changeset
88 mux_a->h.dwSampleSize = mux_a->h.dwScale;
e84a6ae9d51e audio encoding reworked
nicodvb
parents: 14550
diff changeset
89 }
e84a6ae9d51e audio encoding reworked
nicodvb
parents: 14550
diff changeset
90 mux_a->wf->nBlockAlign = mux_a->h.dwScale;
e84a6ae9d51e audio encoding reworked
nicodvb
parents: 14550
diff changeset
91 mux_a->h.dwSuggestedBufferSize = (encoder->params.audio_preload*mux_a->wf->nAvgBytesPerSec)/1000;
e84a6ae9d51e audio encoding reworked
nicodvb
parents: 14550
diff changeset
92 mux_a->h.dwSuggestedBufferSize -= mux_a->h.dwSuggestedBufferSize % mux_a->wf->nBlockAlign;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 22601
diff changeset
93
15265
92772475ed8d toolame now works in vbr mode, too
nicodvb
parents: 15240
diff changeset
94 mux_a->wf->cbSize = 0; //12;
15234
e84a6ae9d51e audio encoding reworked
nicodvb
parents: 14550
diff changeset
95 mux_a->wf->wBitsPerSample = 0; /* does not apply */
e84a6ae9d51e audio encoding reworked
nicodvb
parents: 14550
diff changeset
96 ((MPEGLAYER3WAVEFORMAT *) (mux_a->wf))->wID = 1;
e84a6ae9d51e audio encoding reworked
nicodvb
parents: 14550
diff changeset
97 ((MPEGLAYER3WAVEFORMAT *) (mux_a->wf))->fdwFlags = 2;
e84a6ae9d51e audio encoding reworked
nicodvb
parents: 14550
diff changeset
98 ((MPEGLAYER3WAVEFORMAT *) (mux_a->wf))->nBlockSize = mux_a->wf->nBlockAlign;
e84a6ae9d51e audio encoding reworked
nicodvb
parents: 14550
diff changeset
99 ((MPEGLAYER3WAVEFORMAT *) (mux_a->wf))->nFramesPerBlock = 1;
e84a6ae9d51e audio encoding reworked
nicodvb
parents: 14550
diff changeset
100 ((MPEGLAYER3WAVEFORMAT *) (mux_a->wf))->nCodecDelay = 0;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 22601
diff changeset
101
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 22601
diff changeset
102 // Fix allocation
32121
d332ea379205 Replace sizeof(WAVEFORMATEX) occurrences.
reimar
parents: 31436
diff changeset
103 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: 22601
diff changeset
104
15234
e84a6ae9d51e audio encoding reworked
nicodvb
parents: 14550
diff changeset
105 encoder->input_format = AF_FORMAT_S16_NE;
e84a6ae9d51e audio encoding reworked
nicodvb
parents: 14550
diff changeset
106 encoder->min_buffer_size = mux_a->h.dwSuggestedBufferSize;
e84a6ae9d51e audio encoding reworked
nicodvb
parents: 14550
diff changeset
107 encoder->max_buffer_size = mux_a->h.dwSuggestedBufferSize*2;
e84a6ae9d51e audio encoding reworked
nicodvb
parents: 14550
diff changeset
108
e84a6ae9d51e audio encoding reworked
nicodvb
parents: 14550
diff changeset
109 return 1;
e84a6ae9d51e audio encoding reworked
nicodvb
parents: 14550
diff changeset
110 }
e84a6ae9d51e audio encoding reworked
nicodvb
parents: 14550
diff changeset
111
e84a6ae9d51e audio encoding reworked
nicodvb
parents: 14550
diff changeset
112 static int encode_toolame(audio_encoder_t *encoder, uint8_t *dest, void *src, int len, int max_size)
e84a6ae9d51e audio encoding reworked
nicodvb
parents: 14550
diff changeset
113 {
e84a6ae9d51e audio encoding reworked
nicodvb
parents: 14550
diff changeset
114 mpae_toolame_ctx *ctx = (mpae_toolame_ctx *)encoder->priv;
15265
92772475ed8d toolame now works in vbr mode, too
nicodvb
parents: 15240
diff changeset
115 int ret_size = 0, r2, i, nsamples;
15234
e84a6ae9d51e audio encoding reworked
nicodvb
parents: 14550
diff changeset
116 int16_t *buffer;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 22601
diff changeset
117
15234
e84a6ae9d51e audio encoding reworked
nicodvb
parents: 14550
diff changeset
118 nsamples = len / (2*encoder->params.channels);
e84a6ae9d51e audio encoding reworked
nicodvb
parents: 14550
diff changeset
119 buffer = (uint16_t *) src;
e84a6ae9d51e audio encoding reworked
nicodvb
parents: 14550
diff changeset
120 for(i = 0; i < nsamples; i++)
e84a6ae9d51e audio encoding reworked
nicodvb
parents: 14550
diff changeset
121 {
e84a6ae9d51e audio encoding reworked
nicodvb
parents: 14550
diff changeset
122 ctx->left_pcm[i] = buffer[ctx->channels * i];
e84a6ae9d51e audio encoding reworked
nicodvb
parents: 14550
diff changeset
123 ctx->right_pcm[i] = buffer[(ctx->channels * i) + (ctx->channels - 1)];
e84a6ae9d51e audio encoding reworked
nicodvb
parents: 14550
diff changeset
124 }
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 22601
diff changeset
125
15234
e84a6ae9d51e audio encoding reworked
nicodvb
parents: 14550
diff changeset
126 toolame_encode_buffer(ctx->toolame_ctx, ctx->left_pcm, ctx->right_pcm, nsamples, dest, max_size, &ret_size);
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 22601
diff changeset
127 r2 = mp_decode_mp3_header(dest);
16482
82698fb46c73 reduced verbosity
nicodvb
parents: 15362
diff changeset
128 mp_msg(MSGT_MENCODER, MSGL_DBG2, "\nSIZE: %d, max: %d, r2: %d\n", ret_size, max_size, r2);
15265
92772475ed8d toolame now works in vbr mode, too
nicodvb
parents: 15240
diff changeset
129 if(r2 > 0)
92772475ed8d toolame now works in vbr mode, too
nicodvb
parents: 15240
diff changeset
130 ret_size = r2;
15234
e84a6ae9d51e audio encoding reworked
nicodvb
parents: 14550
diff changeset
131 return ret_size;
e84a6ae9d51e audio encoding reworked
nicodvb
parents: 14550
diff changeset
132 }
e84a6ae9d51e audio encoding reworked
nicodvb
parents: 14550
diff changeset
133
30743
b08fb4b8cfab Make close_toolame() static, only used in ae_toolame.c.
cehoyos
parents: 30702
diff changeset
134 static int close_toolame(audio_encoder_t *encoder)
15234
e84a6ae9d51e audio encoding reworked
nicodvb
parents: 14550
diff changeset
135 {
e84a6ae9d51e audio encoding reworked
nicodvb
parents: 14550
diff changeset
136 free(encoder->priv);
e84a6ae9d51e audio encoding reworked
nicodvb
parents: 14550
diff changeset
137 return 1;
e84a6ae9d51e audio encoding reworked
nicodvb
parents: 14550
diff changeset
138 }
e84a6ae9d51e audio encoding reworked
nicodvb
parents: 14550
diff changeset
139
e84a6ae9d51e audio encoding reworked
nicodvb
parents: 14550
diff changeset
140 static int get_frame_size(audio_encoder_t *encoder)
e84a6ae9d51e audio encoding reworked
nicodvb
parents: 14550
diff changeset
141 {
e84a6ae9d51e audio encoding reworked
nicodvb
parents: 14550
diff changeset
142 int sz;
e84a6ae9d51e audio encoding reworked
nicodvb
parents: 14550
diff changeset
143 if(encoder->stream->buffer_len < 4)
e84a6ae9d51e audio encoding reworked
nicodvb
parents: 14550
diff changeset
144 return 0;
e84a6ae9d51e audio encoding reworked
nicodvb
parents: 14550
diff changeset
145 sz = mp_decode_mp3_header(encoder->stream->buffer);
e84a6ae9d51e audio encoding reworked
nicodvb
parents: 14550
diff changeset
146 if(sz <= 0)
e84a6ae9d51e audio encoding reworked
nicodvb
parents: 14550
diff changeset
147 return 0;
e84a6ae9d51e audio encoding reworked
nicodvb
parents: 14550
diff changeset
148 return sz;
e84a6ae9d51e audio encoding reworked
nicodvb
parents: 14550
diff changeset
149 }
e84a6ae9d51e audio encoding reworked
nicodvb
parents: 14550
diff changeset
150
e84a6ae9d51e audio encoding reworked
nicodvb
parents: 14550
diff changeset
151
e84a6ae9d51e audio encoding reworked
nicodvb
parents: 14550
diff changeset
152 int mpae_init_toolame(audio_encoder_t *encoder)
13425
a87f1a948a24 encoding to mp2 with libtoolame - only cbr atm
nicodvb
parents:
diff changeset
153 {
a87f1a948a24 encoding to mp2 with libtoolame - only cbr atm
nicodvb
parents:
diff changeset
154 int mode;
a87f1a948a24 encoding to mp2 with libtoolame - only cbr atm
nicodvb
parents:
diff changeset
155 mpae_toolame_ctx *ctx = NULL;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 22601
diff changeset
156
15234
e84a6ae9d51e audio encoding reworked
nicodvb
parents: 14550
diff changeset
157 if(encoder->params.channels == 1)
13425
a87f1a948a24 encoding to mp2 with libtoolame - only cbr atm
nicodvb
parents:
diff changeset
158 {
a87f1a948a24 encoding to mp2 with libtoolame - only cbr atm
nicodvb
parents:
diff changeset
159 mp_msg(MSGT_MENCODER, MSGL_INFO, "ae_toolame, 1 audio channel, forcing mono mode\n");
a87f1a948a24 encoding to mp2 with libtoolame - only cbr atm
nicodvb
parents:
diff changeset
160 mode = MPG_MD_MONO;
a87f1a948a24 encoding to mp2 with libtoolame - only cbr atm
nicodvb
parents:
diff changeset
161 }
15234
e84a6ae9d51e audio encoding reworked
nicodvb
parents: 14550
diff changeset
162 else if(encoder->params.channels == 2)
13425
a87f1a948a24 encoding to mp2 with libtoolame - only cbr atm
nicodvb
parents:
diff changeset
163 {
a87f1a948a24 encoding to mp2 with libtoolame - only cbr atm
nicodvb
parents:
diff changeset
164 if(! strcasecmp(param_mode, "dual"))
a87f1a948a24 encoding to mp2 with libtoolame - only cbr atm
nicodvb
parents:
diff changeset
165 mode = MPG_MD_DUAL_CHANNEL;
a87f1a948a24 encoding to mp2 with libtoolame - only cbr atm
nicodvb
parents:
diff changeset
166 else if(! strcasecmp(param_mode, "jstereo"))
a87f1a948a24 encoding to mp2 with libtoolame - only cbr atm
nicodvb
parents:
diff changeset
167 mode = MPG_MD_JOINT_STEREO;
a87f1a948a24 encoding to mp2 with libtoolame - only cbr atm
nicodvb
parents:
diff changeset
168 else if(! strcasecmp(param_mode, "stereo"))
a87f1a948a24 encoding to mp2 with libtoolame - only cbr atm
nicodvb
parents:
diff changeset
169 mode = MPG_MD_STEREO;
a87f1a948a24 encoding to mp2 with libtoolame - only cbr atm
nicodvb
parents:
diff changeset
170 else
a87f1a948a24 encoding to mp2 with libtoolame - only cbr atm
nicodvb
parents:
diff changeset
171 {
a87f1a948a24 encoding to mp2 with libtoolame - only cbr atm
nicodvb
parents:
diff changeset
172 mp_msg(MSGT_MENCODER, MSGL_ERR, "ae_toolame, unknown mode %s, exiting\n", param_mode);
a87f1a948a24 encoding to mp2 with libtoolame - only cbr atm
nicodvb
parents:
diff changeset
173 }
a87f1a948a24 encoding to mp2 with libtoolame - only cbr atm
nicodvb
parents:
diff changeset
174 }
a87f1a948a24 encoding to mp2 with libtoolame - only cbr atm
nicodvb
parents:
diff changeset
175 else
a87f1a948a24 encoding to mp2 with libtoolame - only cbr atm
nicodvb
parents:
diff changeset
176 mp_msg(MSGT_MENCODER, MSGL_ERR, "ae_toolame, Toolame can't encode > 2 channels, exiting\n");
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 22601
diff changeset
177
30702
9fc9d1e788aa Do not cast the results of malloc/calloc/realloc.
diego
parents: 30633
diff changeset
178 ctx = calloc(1, sizeof(mpae_toolame_ctx));
13425
a87f1a948a24 encoding to mp2 with libtoolame - only cbr atm
nicodvb
parents:
diff changeset
179 if(ctx == NULL)
a87f1a948a24 encoding to mp2 with libtoolame - only cbr atm
nicodvb
parents:
diff changeset
180 {
a87f1a948a24 encoding to mp2 with libtoolame - only cbr atm
nicodvb
parents:
diff changeset
181 mp_msg(MSGT_MENCODER, MSGL_ERR, "ae_toolame, couldn't alloc a %d bytes context, exiting\n", sizeof(mpae_toolame_ctx));
15234
e84a6ae9d51e audio encoding reworked
nicodvb
parents: 14550
diff changeset
182 return 0;
13425
a87f1a948a24 encoding to mp2 with libtoolame - only cbr atm
nicodvb
parents:
diff changeset
183 }
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 22601
diff changeset
184
13425
a87f1a948a24 encoding to mp2 with libtoolame - only cbr atm
nicodvb
parents:
diff changeset
185 ctx->toolame_ctx = toolame_init();
a87f1a948a24 encoding to mp2 with libtoolame - only cbr atm
nicodvb
parents:
diff changeset
186 if(ctx->toolame_ctx == NULL)
a87f1a948a24 encoding to mp2 with libtoolame - only cbr atm
nicodvb
parents:
diff changeset
187 {
a87f1a948a24 encoding to mp2 with libtoolame - only cbr atm
nicodvb
parents:
diff changeset
188 mp_msg(MSGT_MENCODER, MSGL_ERR, "ae_toolame, couldn't initial parameters from libtoolame, exiting\n");
a87f1a948a24 encoding to mp2 with libtoolame - only cbr atm
nicodvb
parents:
diff changeset
189 free(ctx);
15234
e84a6ae9d51e audio encoding reworked
nicodvb
parents: 14550
diff changeset
190 return 0;
13425
a87f1a948a24 encoding to mp2 with libtoolame - only cbr atm
nicodvb
parents:
diff changeset
191 }
15265
92772475ed8d toolame now works in vbr mode, too
nicodvb
parents: 15240
diff changeset
192 ctx->vbr = 0;
15234
e84a6ae9d51e audio encoding reworked
nicodvb
parents: 14550
diff changeset
193 ctx->channels = encoder->params.channels;
e84a6ae9d51e audio encoding reworked
nicodvb
parents: 14550
diff changeset
194 ctx->srate = encoder->params.sample_rate;
13425
a87f1a948a24 encoding to mp2 with libtoolame - only cbr atm
nicodvb
parents:
diff changeset
195
a87f1a948a24 encoding to mp2 with libtoolame - only cbr atm
nicodvb
parents:
diff changeset
196 if(toolame_setMode(ctx->toolame_ctx, mode) != 0)
15234
e84a6ae9d51e audio encoding reworked
nicodvb
parents: 14550
diff changeset
197 return 0;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 22601
diff changeset
198
13425
a87f1a948a24 encoding to mp2 with libtoolame - only cbr atm
nicodvb
parents:
diff changeset
199 if(toolame_setPsymodel(ctx->toolame_ctx, param_psy) != 0)
15234
e84a6ae9d51e audio encoding reworked
nicodvb
parents: 14550
diff changeset
200 return 0;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 22601
diff changeset
201
15234
e84a6ae9d51e audio encoding reworked
nicodvb
parents: 14550
diff changeset
202 if(toolame_setSampleFreq(ctx->toolame_ctx, encoder->params.sample_rate) != 0)
e84a6ae9d51e audio encoding reworked
nicodvb
parents: 14550
diff changeset
203 return 0;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 22601
diff changeset
204
13425
a87f1a948a24 encoding to mp2 with libtoolame - only cbr atm
nicodvb
parents:
diff changeset
205 if(toolame_setBitrate(ctx->toolame_ctx, param_bitrate) != 0)
15234
e84a6ae9d51e audio encoding reworked
nicodvb
parents: 14550
diff changeset
206 return 0;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 22601
diff changeset
207
13425
a87f1a948a24 encoding to mp2 with libtoolame - only cbr atm
nicodvb
parents:
diff changeset
208 if(param_errprot)
a87f1a948a24 encoding to mp2 with libtoolame - only cbr atm
nicodvb
parents:
diff changeset
209 if(toolame_setErrorProtection(ctx->toolame_ctx, TRUE) != 0)
15234
e84a6ae9d51e audio encoding reworked
nicodvb
parents: 14550
diff changeset
210 return 0;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 22601
diff changeset
211
15281
dcf97e9eb7e8 fixed variability range
nicodvb
parents: 15265
diff changeset
212 if(param_vbr != 0)
13425
a87f1a948a24 encoding to mp2 with libtoolame - only cbr atm
nicodvb
parents:
diff changeset
213 {
a87f1a948a24 encoding to mp2 with libtoolame - only cbr atm
nicodvb
parents:
diff changeset
214 if(toolame_setVBR(ctx->toolame_ctx, TRUE) != 0)
15234
e84a6ae9d51e audio encoding reworked
nicodvb
parents: 14550
diff changeset
215 return 0;
15265
92772475ed8d toolame now works in vbr mode, too
nicodvb
parents: 15240
diff changeset
216 if(toolame_setVBRLevel(ctx->toolame_ctx, param_vbr) != 0)
15234
e84a6ae9d51e audio encoding reworked
nicodvb
parents: 14550
diff changeset
217 return 0;
13425
a87f1a948a24 encoding to mp2 with libtoolame - only cbr atm
nicodvb
parents:
diff changeset
218 if(toolame_setPadding(ctx->toolame_ctx, FALSE) != 0)
15234
e84a6ae9d51e audio encoding reworked
nicodvb
parents: 14550
diff changeset
219 return 0;
15265
92772475ed8d toolame now works in vbr mode, too
nicodvb
parents: 15240
diff changeset
220 if(param_maxvbr)
92772475ed8d toolame now works in vbr mode, too
nicodvb
parents: 15240
diff changeset
221 {
92772475ed8d toolame now works in vbr mode, too
nicodvb
parents: 15240
diff changeset
222 if(toolame_setVBRUpperBitrate(ctx->toolame_ctx, param_maxvbr) != 0)
92772475ed8d toolame now works in vbr mode, too
nicodvb
parents: 15240
diff changeset
223 return 0;
92772475ed8d toolame now works in vbr mode, too
nicodvb
parents: 15240
diff changeset
224 }
92772475ed8d toolame now works in vbr mode, too
nicodvb
parents: 15240
diff changeset
225 ctx->vbr = 1;
13425
a87f1a948a24 encoding to mp2 with libtoolame - only cbr atm
nicodvb
parents:
diff changeset
226 }
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 22601
diff changeset
227
13425
a87f1a948a24 encoding to mp2 with libtoolame - only cbr atm
nicodvb
parents:
diff changeset
228 if(toolame_setVerbosity(ctx->toolame_ctx, param_debug) != 0)
15234
e84a6ae9d51e audio encoding reworked
nicodvb
parents: 14550
diff changeset
229 return 0;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 22601
diff changeset
230
13425
a87f1a948a24 encoding to mp2 with libtoolame - only cbr atm
nicodvb
parents:
diff changeset
231 if(toolame_init_params(ctx->toolame_ctx) != 0)
15234
e84a6ae9d51e audio encoding reworked
nicodvb
parents: 14550
diff changeset
232 return 0;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 22601
diff changeset
233
13425
a87f1a948a24 encoding to mp2 with libtoolame - only cbr atm
nicodvb
parents:
diff changeset
234 ctx->bitrate = param_bitrate;
15234
e84a6ae9d51e audio encoding reworked
nicodvb
parents: 14550
diff changeset
235 encoder->params.bitrate = ctx->bitrate;
e84a6ae9d51e audio encoding reworked
nicodvb
parents: 14550
diff changeset
236 encoder->params.samples_per_frame = 1152;
e84a6ae9d51e audio encoding reworked
nicodvb
parents: 14550
diff changeset
237 encoder->priv = ctx;
e84a6ae9d51e audio encoding reworked
nicodvb
parents: 14550
diff changeset
238 encoder->decode_buffer_size = 1152 * 2 * encoder->params.channels;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 22601
diff changeset
239
15234
e84a6ae9d51e audio encoding reworked
nicodvb
parents: 14550
diff changeset
240 encoder->bind = bind_toolame;
e84a6ae9d51e audio encoding reworked
nicodvb
parents: 14550
diff changeset
241 encoder->get_frame_size = get_frame_size;
e84a6ae9d51e audio encoding reworked
nicodvb
parents: 14550
diff changeset
242 encoder->encode = encode_toolame;
e84a6ae9d51e audio encoding reworked
nicodvb
parents: 14550
diff changeset
243 encoder->close = close_toolame;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 22601
diff changeset
244
15234
e84a6ae9d51e audio encoding reworked
nicodvb
parents: 14550
diff changeset
245 return 1;
13425
a87f1a948a24 encoding to mp2 with libtoolame - only cbr atm
nicodvb
parents:
diff changeset
246 }