1 /*
2 * Interface to libshine for mp3 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 #include <shine/layer3.h>
23
32
33 #define BUFFER_SIZE (4096 * 20)
34
42
44 {
46
50 }
51
52 shine_set_config_mpeg_defaults(&
s->config.mpeg);
54 s->config.mpeg.bitr = avctx->
bit_rate / 1000;
58 if (shine_check_config(
s->config.wave.samplerate,
s->config.mpeg.bitr) < 0) {
61 }
62 s->shine = shine_initialise(&
s->config);
65 avctx->
frame_size = shine_samples_per_pass(
s->shine);
67 return 0;
68 }
69
72 {
76 int written;
78
80 data = shine_encode_buffer(
s->shine, (int16_t **)
frame->data, &written);
81 else
82 data = shine_flush(
s->shine, &written);
83 if (written < 0)
84 return -1;
85 if (written > 0) {
89 }
90 memcpy(
s->buffer +
s->buffer_index,
data, written);
91 s->buffer_index += written;
92 }
96 }
97
98 if (
s->buffer_index < 4 || !
s->afq.frame_count)
99 return 0;
102 return -1;
103 }
104
105 len = hdr.frame_size;
106 if (len <= s->buffer_index) {
109 memcpy(avpkt->
data,
s->buffer,
len);
110 s->buffer_index -=
len;
111 memmove(
s->buffer,
s->buffer +
len,
s->buffer_index);
112
115
116 *got_packet_ptr = 1;
117 }
118 return 0;
119 }
120
122 {
124
126 shine_close(
s->shine);
127 return 0;
128 }
129
131 44100, 48000, 32000, 0
132 };
133
135 .
p.
name =
"libshine",
147 #if FF_API_OLD_CHANNEL_LAYOUT
150 0 },
151 #endif
154 { 0 },
155 },
156 .p.wrapper_name = "libshine",
157 };