annotate ogg.c @ 184:2438e76dde67 libavformat

yuv4mpeg pipe reader for libavformat patch by (D Richard Felker III <dalias at aerifal dot cx>)
author michaelni
date Tue, 05 Aug 2003 09:32:31 +0000
parents 1e2f55eced38
children a313e1080322
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1 /*
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
2 * Ogg bitstream support
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
3 * Mark Hills <mark@pogo.org.uk>
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
4 *
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
5 * Uses libogg, but requires libvorbisenc to construct correct headers
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
6 * when containing Vorbis stream -- currently the only format supported
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
7 */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
8
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
9 #include <stdio.h>
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
10 #include <time.h>
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
11
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
12 #include <ogg/ogg.h>
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
13 #include <vorbis/vorbisenc.h>
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
14
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
15 #include "avformat.h"
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
16 #include "oggvorbis.h"
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
17
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
18 #define DECODER_BUFFER_SIZE 4096
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
19
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
20
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
21 typedef struct OggContext {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
22 /* output */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
23 ogg_stream_state os ;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
24 int header_handled ;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
25 ogg_int64_t base_packet_no ;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
26 ogg_int64_t base_granule_pos ;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
27
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
28 /* input */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
29 ogg_sync_state oy ;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
30 } OggContext ;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
31
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
32
35
a16ccdf4a87c removed unneeded mallocs
bellard
parents: 0
diff changeset
33 static int ogg_write_header(AVFormatContext *avfcontext)
a16ccdf4a87c removed unneeded mallocs
bellard
parents: 0
diff changeset
34 {
a16ccdf4a87c removed unneeded mallocs
bellard
parents: 0
diff changeset
35 OggContext *context = avfcontext->priv_data;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
36 AVCodecContext *avccontext ;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
37 vorbis_info vi ;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
38 vorbis_dsp_state vd ;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
39 vorbis_comment vc ;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
40 vorbis_block vb ;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
41 ogg_packet header, header_comm, header_code ;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
42 int n ;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
43
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
44 srand(time(NULL));
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
45 ogg_stream_init(&context->os, rand());
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
46
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
47 for(n = 0 ; n < avfcontext->nb_streams ; n++) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
48 avccontext = &avfcontext->streams[n]->codec ;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
49
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
50 /* begin vorbis specific code */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
51
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
52 vorbis_info_init(&vi) ;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
53
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
54 /* code copied from libavcodec/oggvorbis.c */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
55
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
56 if(oggvorbis_init_encoder(&vi, avccontext) < 0) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
57 fprintf(stderr, "ogg_write_header: init_encoder failed") ;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
58 return -1 ;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
59 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
60
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
61 vorbis_analysis_init(&vd, &vi) ;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
62 vorbis_block_init(&vd, &vb) ;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
63
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
64 vorbis_comment_init(&vc) ;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
65 vorbis_comment_add_tag(&vc, "encoder", "ffmpeg") ;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
66 if(*avfcontext->title)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
67 vorbis_comment_add_tag(&vc, "title", avfcontext->title) ;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
68
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
69 vorbis_analysis_headerout(&vd, &vc, &header,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
70 &header_comm, &header_code) ;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
71 ogg_stream_packetin(&context->os, &header) ;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
72 ogg_stream_packetin(&context->os, &header_comm) ;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
73 ogg_stream_packetin(&context->os, &header_code) ;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
74
68
1e2f55eced38 ogg deallocate patch by (Mark Hills <mark at pogo dot org dot uk>)
michaelni
parents: 35
diff changeset
75 vorbis_block_clear(&vb) ;
1e2f55eced38 ogg deallocate patch by (Mark Hills <mark at pogo dot org dot uk>)
michaelni
parents: 35
diff changeset
76 vorbis_dsp_clear(&vd) ;
1e2f55eced38 ogg deallocate patch by (Mark Hills <mark at pogo dot org dot uk>)
michaelni
parents: 35
diff changeset
77 vorbis_info_clear(&vi) ;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
78 vorbis_comment_clear(&vc) ;
68
1e2f55eced38 ogg deallocate patch by (Mark Hills <mark at pogo dot org dot uk>)
michaelni
parents: 35
diff changeset
79
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
80 /* end of vorbis specific code */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
81
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
82 context->header_handled = 0 ;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
83 context->base_packet_no = 0 ;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
84 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
85
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
86 return 0 ;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
87 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
88
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
89
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
90 static int ogg_write_packet(AVFormatContext *avfcontext,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
91 int stream_index,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
92 unsigned char *buf, int size, int force_pts)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
93 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
94 OggContext *context = avfcontext->priv_data ;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
95 ogg_packet *op ;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
96 ogg_page og ;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
97 int l = 0 ;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
98
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
99 /* flush header packets so audio starts on a new page */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
100
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
101 if(!context->header_handled) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
102 while(ogg_stream_flush(&context->os, &og)) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
103 put_buffer(&avfcontext->pb, og.header, og.header_len) ;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
104 put_buffer(&avfcontext->pb, og.body, og.body_len) ;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
105 put_flush_packet(&avfcontext->pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
106 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
107 context->header_handled = 1 ;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
108 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
109
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
110 while(l < size) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
111 op = (ogg_packet*)(buf + l) ;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
112 op->packet = buf + l + sizeof(ogg_packet) ; /* fix data pointer */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
113
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
114 if(!context->base_packet_no) { /* this is the first packet */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
115 context->base_packet_no = op->packetno ;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
116 context->base_granule_pos = op->granulepos ;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
117 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
118
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
119 /* correct the fields in the packet -- essential for streaming */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
120
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
121 op->packetno -= context->base_packet_no ;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
122 op->granulepos -= context->base_granule_pos ;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
123
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
124 ogg_stream_packetin(&context->os, op) ;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
125 l += sizeof(ogg_packet) + op->bytes ;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
126
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
127 while(ogg_stream_pageout(&context->os, &og)) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
128 put_buffer(&avfcontext->pb, og.header, og.header_len) ;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
129 put_buffer(&avfcontext->pb, og.body, og.body_len) ;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
130 put_flush_packet(&avfcontext->pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
131 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
132 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
133
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
134 return 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
135 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
136
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
137
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
138 static int ogg_write_trailer(AVFormatContext *avfcontext) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
139 OggContext *context = avfcontext->priv_data ;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
140 ogg_page og ;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
141
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
142 while(ogg_stream_flush(&context->os, &og)) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
143 put_buffer(&avfcontext->pb, og.header, og.header_len) ;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
144 put_buffer(&avfcontext->pb, og.body, og.body_len) ;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
145 put_flush_packet(&avfcontext->pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
146 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
147
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
148 ogg_stream_clear(&context->os) ;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
149 return 0 ;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
150 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
151
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
152
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
153 static AVOutputFormat ogg_oformat = {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
154 "ogg",
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
155 "Ogg Vorbis",
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
156 "audio/x-vorbis",
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
157 "ogg",
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
158 sizeof(OggContext),
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
159 CODEC_ID_VORBIS,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
160 0,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
161 ogg_write_header,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
162 ogg_write_packet,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
163 ogg_write_trailer,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
164 } ;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
165
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
166
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
167 static int next_packet(AVFormatContext *avfcontext, ogg_packet *op) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
168 OggContext *context = avfcontext->priv_data ;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
169 ogg_page og ;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
170 char *buf ;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
171
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
172 while(ogg_stream_packetout(&context->os, op) != 1) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
173
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
174 /* while no pages are available, read in more data to the sync */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
175 while(ogg_sync_pageout(&context->oy, &og) != 1) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
176 buf = ogg_sync_buffer(&context->oy, DECODER_BUFFER_SIZE) ;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
177 if(get_buffer(&avfcontext->pb, buf, DECODER_BUFFER_SIZE) <= 0)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
178 return 1 ;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
179 ogg_sync_wrote(&context->oy, DECODER_BUFFER_SIZE) ;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
180 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
181
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
182 /* got a page. Feed it into the stream and get the packet */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
183 if(ogg_stream_pagein(&context->os, &og) != 0)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
184 return 1 ;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
185 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
186
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
187 return 0 ;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
188 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
189
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
190
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
191 static int ogg_read_header(AVFormatContext *avfcontext, AVFormatParameters *ap)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
192 {
35
a16ccdf4a87c removed unneeded mallocs
bellard
parents: 0
diff changeset
193 OggContext *context = avfcontext->priv_data;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
194 char *buf ;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
195 ogg_page og ;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
196 AVStream *ast ;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
197
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
198 ogg_sync_init(&context->oy) ;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
199 buf = ogg_sync_buffer(&context->oy, DECODER_BUFFER_SIZE) ;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
200
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
201 if(get_buffer(&avfcontext->pb, buf, DECODER_BUFFER_SIZE) <= 0)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
202 return -EIO ;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
203
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
204 ogg_sync_wrote(&context->oy, DECODER_BUFFER_SIZE) ;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
205 ogg_sync_pageout(&context->oy, &og) ;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
206 ogg_stream_init(&context->os, ogg_page_serialno(&og)) ;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
207 ogg_stream_pagein(&context->os, &og) ;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
208
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
209 /* currently only one vorbis stream supported */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
210
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
211 ast = av_new_stream(avfcontext, 0) ;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
212 if(!ast)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
213 return AVERROR_NOMEM ;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
214
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
215 ast->codec.codec_type = CODEC_TYPE_AUDIO ;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
216 ast->codec.codec_id = CODEC_ID_VORBIS ;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
217
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
218 return 0 ;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
219 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
220
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
221
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
222 static int ogg_read_packet(AVFormatContext *avfcontext, AVPacket *pkt) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
223 ogg_packet op ;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
224
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
225 if(next_packet(avfcontext, &op))
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
226 return -EIO ;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
227 if(av_new_packet(pkt, sizeof(ogg_packet) + op.bytes) < 0)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
228 return -EIO ;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
229 pkt->stream_index = 0 ;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
230 memcpy(pkt->data, &op, sizeof(ogg_packet)) ;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
231 memcpy(pkt->data + sizeof(ogg_packet), op.packet, op.bytes) ;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
232
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
233 return sizeof(ogg_packet) + op.bytes ;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
234 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
235
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
236
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
237 static int ogg_read_close(AVFormatContext *avfcontext) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
238 OggContext *context = avfcontext->priv_data ;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
239
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
240 ogg_stream_clear(&context->os) ;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
241 ogg_sync_clear(&context->oy) ;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
242
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
243 return 0 ;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
244 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
245
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
246
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
247 static AVInputFormat ogg_iformat = {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
248 "ogg",
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
249 "Ogg Vorbis",
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
250 sizeof(OggContext),
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
251 NULL,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
252 ogg_read_header,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
253 ogg_read_packet,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
254 ogg_read_close,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
255 .extensions = "ogg",
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
256 } ;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
257
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
258
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
259 int ogg_init(void) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
260 av_register_output_format(&ogg_oformat) ;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
261 av_register_input_format(&ogg_iformat);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
262 return 0 ;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
263 }