21 #include <vorbis/vorbisenc.h>
38 #define OGGVORBIS_FRAME_SIZE 64
40 #define BUFFER_SIZE (1024 * 64)
77 case OV_EINVAL:
return AVERROR(EINVAL);
78 case OV_EIMPL:
return AVERROR(EINVAL);
99 if ((ret = vorbis_encode_setup_vbr(vi, avctx->
channels,
108 if ((ret = vorbis_encode_setup_managed(vi, avctx->
channels,
114 if (minrate == -1 && maxrate == -1)
115 if ((ret = vorbis_encode_ctl(vi, OV_ECTL_RATEMANAGE2_SET, NULL)))
121 cfreq = avctx->
cutoff / 1000.0;
122 if ((ret = vorbis_encode_ctl(vi, OV_ECTL_LOWPASS_SET, &cfreq)))
128 if ((ret = vorbis_encode_ctl(vi, OV_ECTL_IBLOCK_SET, &s->
iblock)))
152 "output stream will have incorrect "
153 "channel layout.\n", name);
156 "will use Vorbis channel layout for "
161 if ((ret = vorbis_encode_setup_init(vi)))
172 return 1 + l / 255 + l;
181 vorbis_analysis_wrote(&s->
vd, 0);
183 vorbis_block_clear(&s->
vb);
184 vorbis_dsp_clear(&s->
vd);
185 vorbis_info_clear(&s->
vi);
202 vorbis_info_init(&s->
vi);
207 if ((ret = vorbis_analysis_init(&s->
vd, &s->
vi))) {
213 if ((ret = vorbis_block_init(&s->
vd, &s->
vb))) {
219 vorbis_comment_init(&s->
vc);
223 if ((ret = vorbis_analysis_headerout(&s->
vd, &s->
vc, &header, &header_comm,
242 memcpy(&p[offset], header.packet, header.bytes);
243 offset += header.bytes;
244 memcpy(&p[offset], header_comm.packet, header_comm.bytes);
245 offset += header_comm.bytes;
246 memcpy(&p[offset], header_code.packet, header_code.bytes);
247 offset += header_code.bytes;
255 vorbis_comment_clear(&s->
vc);
283 int c, channels = s->
vi.channels;
285 buffer = vorbis_analysis_buffer(&s->
vd, samples);
286 for (c = 0; c < channels; c++) {
287 int co = (channels > 8) ? c :
290 samples *
sizeof(*buffer[c]));
292 if ((ret = vorbis_analysis_wrote(&s->
vd, samples)) < 0) {
300 if ((ret = vorbis_analysis_wrote(&s->
vd, 0)) < 0) {
308 while ((ret = vorbis_analysis_blockout(&s->
vd, &s->
vb)) == 1) {
309 if ((ret = vorbis_analysis(&s->
vb, NULL)) < 0)
311 if ((ret = vorbis_bitrate_addblock(&s->
vb)) < 0)
315 while ((ret = vorbis_bitrate_flushpacket(&s->
vd, &op)) == 1) {