summaryrefslogtreecommitdiff
path: root/libavcodec/vorbis_enc.c
diff options
context:
space:
mode:
authorOded Shimon <ods15@ods15.dyndns.org>2006-10-02 05:54:55 +0000
committerOded Shimon <ods15@ods15.dyndns.org>2006-10-02 05:54:55 +0000
commit504d195260ab9c089a2779af384d3963c298915a (patch)
tree91d8f10f9c1fcf26f8c62a46d94d70085cd9586e /libavcodec/vorbis_enc.c
parent2833fc46462abd841e3d69242be9919c98ad3696 (diff)
skeleton for vorbis_enc.c
Originally committed as revision 6413 to svn://svn.ffmpeg.org/ffmpeg/trunk
Diffstat (limited to 'libavcodec/vorbis_enc.c')
-rw-r--r--libavcodec/vorbis_enc.c110
1 files changed, 110 insertions, 0 deletions
diff --git a/libavcodec/vorbis_enc.c b/libavcodec/vorbis_enc.c
new file mode 100644
index 0000000000..dc6d088646
--- /dev/null
+++ b/libavcodec/vorbis_enc.c
@@ -0,0 +1,110 @@
+/*
+ * copyright (c) 2006 Oded Shimon <ods15@ods15.dyndns.org>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+/**
+ * @file vorbis_enc.c
+ * Native Vorbis encoder.
+ * @author Oded Shimon <ods15@ods15.dyndns.org>
+ */
+
+#include "avcodec.h"
+
+#undef NDEBUG
+#include <assert.h>
+
+#define VORBIS_FRAME_SIZE 64
+
+#define BUFFER_SIZE (1024*64)
+
+typedef struct {
+ uint8_t buffer[BUFFER_SIZE];
+ int buffer_index;
+} venc_context_t;
+
+static int vorbis_encode_init(AVCodecContext * avccontext) {
+ venc_context_t * venc = avccontext->priv_data;
+ uint8_t *p;
+ unsigned int offset, len;
+
+ avccontext->channels;
+ avccontext->sample_rate;
+ //if (avccontext->flags & CODEC_FLAG_QSCALE) avccontext->global_quality / (float)FF_QP2LAMBDA); else avccontext->bit_rate;
+ //if(avccontext->cutoff > 0) cfreq = avccontext->cutoff / 1000.0;
+
+ len = header.bytes + header_comm.bytes + header_code.bytes;
+ avccontext->extradata_size = 64 + len + len/255;
+
+ p = avccontext->extradata = av_mallocz(avccontext->extradata_size);
+ p[0] = 2;
+ offset = 1;
+ offset += av_xiphlacing(&p[offset], header.bytes);
+ offset += av_xiphlacing(&p[offset], header_comm.bytes);
+ memcpy(&p[offset], header.packet, header.bytes);
+ offset += header.bytes;
+ memcpy(&p[offset], header_comm.packet, header_comm.bytes);
+ offset += header_comm.bytes;
+ memcpy(&p[offset], header_code.packet, header_code.bytes);
+ offset += header_code.bytes;
+ avccontext->extradata_size = offset;
+ avccontext->extradata = av_realloc(avccontext->extradata, avccontext->extradata_size);
+
+ avccontext->frame_size = OGGVORBIS_FRAME_SIZE;
+
+ avccontext->coded_frame = avcodec_alloc_frame();
+ avccontext->coded_frame->key_frame = 1;
+
+ return 0;
+}
+
+
+static int vorbis_encode_frame(AVCodecContext * avccontext, unsigned char * packets, int buf_size, void *data)
+{
+ venc_context_t * venc = avccontext->priv_data;
+ signed short * audio = data;
+ int l, samples = data ? VORBIS_FRAME_SIZE : 0;
+
+
+
+ if (!l) return 0;
+
+ avccontext->coded_frame->pts = av_rescale_q(op2->granulepos, (AVRational){1, avccontext->sample_rate}, avccontext->time_base);
+ memcpy(packets, compressed_frame, l);
+ return l;
+}
+
+
+static int vorbis_encode_close(AVCodecContext * avccontext)
+{
+ venc_context_t * venc = avccontext->priv_data;
+
+ av_freep(&avccontext->coded_frame);
+ av_freep(&avccontext->extradata);
+
+ return 0 ;
+}
+
+AVCodec oggvorbis_encoder = {
+ "vorbis",
+ CODEC_TYPE_AUDIO,
+ CODEC_ID_VORBIS,
+ sizeof(venc_context_t),
+ vorbis_encode_init,
+ vorbis_encode_frame,
+ vorbis_encode_close,
+ .capabilities= CODEC_CAP_DELAY,
+};