21 #include <vorbis/vorbisenc.h>
38 #define LIBVORBIS_FRAME_SIZE 64
40 #define BUFFER_SIZE (1024 * 64)
77 case OV_EINVAL:
return AVERROR(EINVAL);
78 case OV_EIMPL:
return AVERROR(EINVAL);
98 if ((ret = vorbis_encode_setup_vbr(vi, avctx->
channels,
107 if ((ret = vorbis_encode_setup_managed(vi, avctx->
channels,
113 if (minrate == -1 && maxrate == -1)
114 if ((ret = vorbis_encode_ctl(vi, OV_ECTL_RATEMANAGE2_SET, NULL)))
120 cfreq = avctx->
cutoff / 1000.0;
121 if ((ret = vorbis_encode_ctl(vi, OV_ECTL_LOWPASS_SET, &cfreq)))
127 if ((ret = vorbis_encode_ctl(vi, OV_ECTL_IBLOCK_SET, &s->
iblock)))
151 "output stream will have incorrect "
152 "channel layout.\n", name);
155 "will use Vorbis channel layout for "
160 if ((ret = vorbis_encode_setup_init(vi)))
171 return 1 + l / 255 + l;
180 vorbis_analysis_wrote(&s->
vd, 0);
182 vorbis_block_clear(&s->
vb);
183 vorbis_dsp_clear(&s->
vd);
184 vorbis_info_clear(&s->
vi);
201 vorbis_info_init(&s->
vi);
206 if ((ret = vorbis_analysis_init(&s->
vd, &s->
vi))) {
212 if ((ret = vorbis_block_init(&s->
vd, &s->
vb))) {
218 vorbis_comment_init(&s->
vc);
222 if ((ret = vorbis_analysis_headerout(&s->
vd, &s->
vc, &header, &header_comm,
241 memcpy(&p[offset], header.packet, header.bytes);
242 offset += header.bytes;
243 memcpy(&p[offset], header_comm.packet, header_comm.bytes);
244 offset += header_comm.bytes;
245 memcpy(&p[offset], header_code.packet, header_code.bytes);
246 offset += header_code.bytes;
254 vorbis_comment_clear(&s->
vc);
282 int c, channels = s->
vi.channels;
284 buffer = vorbis_analysis_buffer(&s->
vd, samples);
285 for (c = 0; c < channels; c++) {
286 int co = (channels > 8) ? c :
289 samples *
sizeof(*buffer[c]));
291 if ((ret = vorbis_analysis_wrote(&s->
vd, samples)) < 0) {
299 if ((ret = vorbis_analysis_wrote(&s->
vd, 0)) < 0) {
307 while ((ret = vorbis_analysis_blockout(&s->
vd, &s->
vb)) == 1) {
308 if ((ret = vorbis_analysis(&s->
vb, NULL)) < 0)
310 if ((ret = vorbis_bitrate_addblock(&s->
vb)) < 0)
314 while ((ret = vorbis_bitrate_flushpacket(&s->
vd, &op)) == 1) {