21 #include <vorbis/vorbisenc.h>
38 #define OGGVORBIS_FRAME_SIZE 64
40 #define BUFFER_SIZE (1024 * 64)
78 case OV_EINVAL:
return AVERROR(EINVAL);
79 case OV_EIMPL:
return AVERROR(EINVAL);
100 if ((ret = vorbis_encode_setup_vbr(vi, avctx->
channels,
109 if ((ret = vorbis_encode_setup_managed(vi, avctx->
channels,
115 if (minrate == -1 && maxrate == -1)
116 if ((ret = vorbis_encode_ctl(vi, OV_ECTL_RATEMANAGE2_SET, NULL)))
122 cfreq = avctx->
cutoff / 1000.0;
123 if ((ret = vorbis_encode_ctl(vi, OV_ECTL_LOWPASS_SET, &cfreq)))
129 if ((ret = vorbis_encode_ctl(vi, OV_ECTL_IBLOCK_SET, &s->
iblock)))
153 "output stream will have incorrect "
154 "channel layout.\n", name);
157 "will use Vorbis channel layout for "
162 if ((ret = vorbis_encode_setup_init(vi)))
173 return 1 + l / 255 + l;
182 vorbis_analysis_wrote(&s->
vd, 0);
184 vorbis_block_clear(&s->
vb);
185 vorbis_dsp_clear(&s->
vd);
186 vorbis_info_clear(&s->
vi);
203 vorbis_info_init(&s->
vi);
208 if ((ret = vorbis_analysis_init(&s->
vd, &s->
vi))) {
214 if ((ret = vorbis_block_init(&s->
vd, &s->
vb))) {
220 vorbis_comment_init(&s->
vc);
224 if ((ret = vorbis_analysis_headerout(&s->
vd, &s->
vc, &header, &header_comm,
243 memcpy(&p[offset], header.packet, header.bytes);
244 offset += header.bytes;
245 memcpy(&p[offset], header_comm.packet, header_comm.bytes);
246 offset += header_comm.bytes;
247 memcpy(&p[offset], header_code.packet, header_code.bytes);
248 offset += header_code.bytes;
256 vorbis_comment_clear(&s->
vc);
284 int c, channels = s->
vi.channels;
286 buffer = vorbis_analysis_buffer(&s->
vd, samples);
287 for (c = 0; c < channels; c++) {
288 int co = (channels > 8) ? c :
291 samples *
sizeof(*buffer[c]));
293 if ((ret = vorbis_analysis_wrote(&s->
vd, samples)) < 0) {
301 if ((ret = vorbis_analysis_wrote(&s->
vd, 0)) < 0) {
309 while ((ret = vorbis_analysis_blockout(&s->
vd, &s->
vb)) == 1) {
310 if ((ret = vorbis_analysis(&s->
vb, NULL)) < 0)
312 if ((ret = vorbis_bitrate_addblock(&s->
vb)) < 0)
316 while ((ret = vorbis_bitrate_flushpacket(&s->
vd, &op)) == 1) {