Mercurial > libavcodec.hg
annotate vorbis_enc.c @ 3809:500d86b68542 libavcodec
Original Commit: r3 | ods15 | 2006-09-16 11:49:07 +0300 (Sat, 16 Sep 2006) | 2 lines
cosmetics
author | ods15 |
---|---|
date | Mon, 02 Oct 2006 05:55:14 +0000 |
parents | 5551768b5a4f |
children | a8bebf3e9cb7 |
rev | line source |
---|---|
3808 | 1 /* |
2 * copyright (c) 2006 Oded Shimon <ods15@ods15.dyndns.org> | |
3 * | |
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. | |
8 * | |
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. | |
13 * | |
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 | |
17 */ | |
18 | |
19 /** | |
20 * @file vorbis_enc.c | |
21 * Native Vorbis encoder. | |
22 * @author Oded Shimon <ods15@ods15.dyndns.org> | |
23 */ | |
24 | |
25 #include "avcodec.h" | |
26 | |
27 #undef NDEBUG | |
28 #include <assert.h> | |
29 | |
30 #define VORBIS_FRAME_SIZE 64 | |
31 | |
32 #define BUFFER_SIZE (1024*64) | |
33 | |
34 typedef struct { | |
35 uint8_t buffer[BUFFER_SIZE]; | |
36 int buffer_index; | |
37 } venc_context_t; | |
38 | |
3809
500d86b68542
Original Commit: r3 | ods15 | 2006-09-16 11:49:07 +0300 (Sat, 16 Sep 2006) | 2 lines
ods15
parents:
3808
diff
changeset
|
39 static int vorbis_encode_init(AVCodecContext * avccontext) |
500d86b68542
Original Commit: r3 | ods15 | 2006-09-16 11:49:07 +0300 (Sat, 16 Sep 2006) | 2 lines
ods15
parents:
3808
diff
changeset
|
40 { |
3808 | 41 venc_context_t * venc = avccontext->priv_data; |
42 uint8_t *p; | |
43 unsigned int offset, len; | |
44 | |
45 avccontext->channels; | |
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; | |
49 | |
50 len = header.bytes + header_comm.bytes + header_code.bytes; | |
51 avccontext->extradata_size = 64 + len + len/255; | |
52 | |
53 p = avccontext->extradata = av_mallocz(avccontext->extradata_size); | |
54 p[0] = 2; | |
55 offset = 1; | |
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); | |
66 | |
3809
500d86b68542
Original Commit: r3 | ods15 | 2006-09-16 11:49:07 +0300 (Sat, 16 Sep 2006) | 2 lines
ods15
parents:
3808
diff
changeset
|
67 avccontext->frame_size = VORBIS_FRAME_SIZE; |
3808 | 68 |
69 avccontext->coded_frame = avcodec_alloc_frame(); | |
70 avccontext->coded_frame->key_frame = 1; | |
71 | |
72 return 0; | |
73 } | |
74 | |
75 | |
76 static int vorbis_encode_frame(AVCodecContext * avccontext, unsigned char * packets, int buf_size, void *data) | |
77 { | |
78 venc_context_t * venc = avccontext->priv_data; | |
79 signed short * audio = data; | |
80 int l, samples = data ? VORBIS_FRAME_SIZE : 0; | |
81 | |
82 | |
83 | |
84 if (!l) return 0; | |
85 | |
86 avccontext->coded_frame->pts = av_rescale_q(op2->granulepos, (AVRational){1, avccontext->sample_rate}, avccontext->time_base); | |
87 memcpy(packets, compressed_frame, l); | |
88 return l; | |
89 } | |
90 | |
91 | |
92 static int vorbis_encode_close(AVCodecContext * avccontext) | |
93 { | |
94 venc_context_t * venc = avccontext->priv_data; | |
95 | |
96 av_freep(&avccontext->coded_frame); | |
97 av_freep(&avccontext->extradata); | |
98 | |
99 return 0 ; | |
100 } | |
101 | |
102 AVCodec oggvorbis_encoder = { | |
103 "vorbis", | |
104 CODEC_TYPE_AUDIO, | |
105 CODEC_ID_VORBIS, | |
106 sizeof(venc_context_t), | |
107 vorbis_encode_init, | |
108 vorbis_encode_frame, | |
109 vorbis_encode_close, | |
110 .capabilities= CODEC_CAP_DELAY, | |
111 }; |