2 * copyright (c) 2006 Oded Shimon <ods15@ods15.dyndns.org>
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21 * Native Vorbis encoder.
22 * @author Oded Shimon <ods15@ods15.dyndns.org>
30 #define VORBIS_FRAME_SIZE 64
32 #define BUFFER_SIZE (1024*64)
35 uint8_t buffer[BUFFER_SIZE];
39 static int vorbis_encode_init(AVCodecContext * avccontext)
41 venc_context_t * venc = avccontext->priv_data;
43 unsigned int offset, len;
46 avccontext->sample_rate;
47 //if (avccontext->flags & CODEC_FLAG_QSCALE) avccontext->global_quality / (float)FF_QP2LAMBDA); else avccontext->bit_rate;
48 //if(avccontext->cutoff > 0) cfreq = avccontext->cutoff / 1000.0;
50 len = header.bytes + header_comm.bytes + header_code.bytes;
51 avccontext->extradata_size = 64 + len + len/255;
53 p = avccontext->extradata = av_mallocz(avccontext->extradata_size);
56 offset += av_xiphlacing(&p[offset], header.bytes);
57 offset += av_xiphlacing(&p[offset], header_comm.bytes);
58 memcpy(&p[offset], header.packet, header.bytes);
59 offset += header.bytes;
60 memcpy(&p[offset], header_comm.packet, header_comm.bytes);
61 offset += header_comm.bytes;
62 memcpy(&p[offset], header_code.packet, header_code.bytes);
63 offset += header_code.bytes;
64 avccontext->extradata_size = offset;
65 avccontext->extradata = av_realloc(avccontext->extradata, avccontext->extradata_size);
67 avccontext->frame_size = VORBIS_FRAME_SIZE;
69 avccontext->coded_frame = avcodec_alloc_frame();
70 avccontext->coded_frame->key_frame = 1;
76 static int vorbis_encode_frame(AVCodecContext * avccontext, unsigned char * packets, int buf_size, void *data)
78 venc_context_t * venc = avccontext->priv_data;
79 signed short * audio = data;
80 int l, samples = data ? VORBIS_FRAME_SIZE : 0;
86 avccontext->coded_frame->pts = av_rescale_q(op2->granulepos, (AVRational){1, avccontext->sample_rate}, avccontext->time_base);
87 memcpy(packets, compressed_frame, l);
92 static int vorbis_encode_close(AVCodecContext * avccontext)
94 venc_context_t * venc = avccontext->priv_data;
96 av_freep(&avccontext->coded_frame);
97 av_freep(&avccontext->extradata);
102 AVCodec oggvorbis_encoder = {
106 sizeof(venc_context_t),
110 .capabilities= CODEC_CAP_DELAY,