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
47 shine_set_config_mpeg_defaults(&
s->config.mpeg);
49 s->config.mpeg.bitr = avctx->
bit_rate / 1000;
53 if (shine_check_config(
s->config.wave.samplerate,
s->config.mpeg.bitr) < 0) {
56 }
57 s->shine = shine_initialise(&
s->config);
60 avctx->
frame_size = shine_samples_per_pass(
s->shine);
62 return 0;
63 }
64
67 {
71 int written;
73
75 data = shine_encode_buffer(
s->shine, (int16_t **)
frame->
data, &written);
76 else
77 data = shine_flush(
s->shine, &written);
78 if (written < 0)
79 return -1;
80 if (written > 0) {
84 }
85 memcpy(
s->buffer +
s->buffer_index,
data, written);
86 s->buffer_index += written;
87 }
91 }
92
93 if (
s->buffer_index < 4 || !
s->afq.frame_count)
94 return 0;
97 return -1;
98 }
99
100 len = hdr.frame_size;
101 if (len <= s->buffer_index) {
104 memcpy(avpkt->
data,
s->buffer,
len);
105 s->buffer_index -=
len;
106 memmove(
s->buffer,
s->buffer +
len,
s->buffer_index);
107
110
111 *got_packet_ptr = 1;
112 }
113 return 0;
114 }
115
117 {
119
121 shine_close(
s->shine);
122 return 0;
123 }
124
126 44100, 48000, 32000, 0
127 };
128
130 .
p.
name =
"libshine",
145 { 0 },
146 },
147 .p.wrapper_name = "libshine",
148 };