1 /*
2 * Interface to libtwolame for mp2 encoding
3 * Copyright (c) 2012 Paul B Mahol
4 *
5 * This file is part of FFmpeg.
6 *
7 * FFmpeg is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
12 * FFmpeg is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with FFmpeg; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 */
21
22 /**
23 * @file
24 * Interface to libtwolame for mp2 encoding.
25 */
26
27 #include <twolame.h>
28
33
42
46
48 {
51 return 0;
52 }
53
55 {
58
60
61 s->
glopts = twolame_init();
64
65 twolame_set_verbosity(s->
glopts, 0);
72
80 } else {
82 }
83
84 if ((ret = twolame_init_params(s->
glopts)))
85 goto error;
86
87 return 0;
88 error:
91 }
92
95 {
98
101
102 if (frame) {
105 ret = twolame_encode_buffer_float32_interleaved(s->
glopts,
109 break;
111 ret = twolame_encode_buffer_float32(s->
glopts,
115 break;
117 ret = twolame_encode_buffer_interleaved(s->
glopts,
121 break;
123 ret = twolame_encode_buffer(s->
glopts,
127 break;
128 default:
130 }
131 } else {
133 }
134
135 if (ret > 0) {
137 if (frame) {
140 } else {
142 }
145
147 *got_packet_ptr = 1;
148 return 0;
149 }
150
152 }
153
154 #define OFFSET(x) offsetof(TWOLAMEContext, x)
155 #define AE AV_OPT_FLAG_AUDIO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
160 {
"joint_stereo", NULL, 0,
AV_OPT_TYPE_CONST, { .i64 = TWOLAME_JOINT_STEREO }, 0, 0,
AE,
"mode" },
161 {
"dual_channel", NULL, 0,
AV_OPT_TYPE_CONST, { .i64 = TWOLAME_DUAL_CHANNEL }, 0, 0,
AE,
"mode" },
165 {
"error_protection",
"enable CRC error protection",
OFFSET(error_protection),
AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 1,
AE},
168 { NULL },
169 };
170
176 };
177
179 .
name =
"libtwolame",
194 0 },
195 .supported_samplerates = (const int[]){ 16000, 22050, 24000, 32000, 44100, 48000, 0 },
198 };