annotate ogg.c @ 358:d18a2b1fc182 libavformat

initial commit for Quicktime Animation (RLE) video decoder; bit depths 32, 24, and 16 are working; 8bpp is partially working; 4, 2, and 1 bpp are not supported yet
author melanson
date Thu, 05 Feb 2004 05:22:44 +0000
parents 741c56c608bb
children 6579fe3ade40
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
277
a313e1080322 disable encoders where appropriate (patch courtesy of BERO
melanson
parents: 68
diff changeset
33 #ifdef CONFIG_ENCODERS
35
a16ccdf4a87c removed unneeded mallocs
bellard
parents: 0
diff changeset
34 static int ogg_write_header(AVFormatContext *avfcontext)
a16ccdf4a87c removed unneeded mallocs
bellard
parents: 0
diff changeset
35 {
a16ccdf4a87c removed unneeded mallocs
bellard
parents: 0
diff changeset
36 OggContext *context = avfcontext->priv_data;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
37 AVCodecContext *avccontext ;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
38 vorbis_info vi ;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
39 vorbis_dsp_state vd ;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
40 vorbis_comment vc ;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
41 vorbis_block vb ;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
42 ogg_packet header, header_comm, header_code ;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
43 int n ;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
44
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
45 srand(time(NULL));
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
46 ogg_stream_init(&context->os, rand());
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
47
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
48 for(n = 0 ; n < avfcontext->nb_streams ; n++) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
49 avccontext = &avfcontext->streams[n]->codec ;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
50
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
51 /* begin vorbis specific code */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
52
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
53 vorbis_info_init(&vi) ;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
54
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
55 /* code copied from libavcodec/oggvorbis.c */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
56
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
57 if(oggvorbis_init_encoder(&vi, avccontext) < 0) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
58 fprintf(stderr, "ogg_write_header: init_encoder failed") ;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
59 return -1 ;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
60 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
61
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
62 vorbis_analysis_init(&vd, &vi) ;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
63 vorbis_block_init(&vd, &vb) ;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
64
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
65 vorbis_comment_init(&vc) ;
327
741c56c608bb using LIBAVFORMAT_IDENT
alex
parents: 290
diff changeset
66 vorbis_comment_add_tag(&vc, "encoder", LIBAVFORMAT_IDENT) ;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
67 if(*avfcontext->title)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
68 vorbis_comment_add_tag(&vc, "title", avfcontext->title) ;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
69
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
70 vorbis_analysis_headerout(&vd, &vc, &header,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
71 &header_comm, &header_code) ;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
72 ogg_stream_packetin(&context->os, &header) ;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
73 ogg_stream_packetin(&context->os, &header_comm) ;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
74 ogg_stream_packetin(&context->os, &header_code) ;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
75
68
1e2f55eced38 ogg deallocate patch by (Mark Hills <mark at pogo dot org dot uk>)
michaelni
parents: 35
diff changeset
76 vorbis_block_clear(&vb) ;
1e2f55eced38 ogg deallocate patch by (Mark Hills <mark at pogo dot org dot uk>)
michaelni
parents: 35
diff changeset
77 vorbis_dsp_clear(&vd) ;
1e2f55eced38 ogg deallocate patch by (Mark Hills <mark at pogo dot org dot uk>)
michaelni
parents: 35
diff changeset
78 vorbis_info_clear(&vi) ;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
79 vorbis_comment_clear(&vc) ;
68
1e2f55eced38 ogg deallocate patch by (Mark Hills <mark at pogo dot org dot uk>)
michaelni
parents: 35
diff changeset
80
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
81 /* end of vorbis specific code */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
82
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
83 context->header_handled = 0 ;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
84 context->base_packet_no = 0 ;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
85 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
86
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
87 return 0 ;
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
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
91 static int ogg_write_packet(AVFormatContext *avfcontext,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
92 int stream_index,
290
7a3ed84008ec GCC 3.3.2 warnings patch by (Panagiotis Issaris <takis at lumumba dot luc dot ac dot be>)
michael
parents: 277
diff changeset
93 const uint8_t *buf, int size, int64_t force_pts)
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
94 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
95 OggContext *context = avfcontext->priv_data ;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
96 ogg_packet *op ;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
97 ogg_page og ;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
98 int l = 0 ;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
99
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
100 /* flush header packets so audio starts on a new page */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
101
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
102 if(!context->header_handled) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
103 while(ogg_stream_flush(&context->os, &og)) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
104 put_buffer(&avfcontext->pb, og.header, og.header_len) ;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
105 put_buffer(&avfcontext->pb, og.body, og.body_len) ;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
106 put_flush_packet(&avfcontext->pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
107 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
108 context->header_handled = 1 ;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
109 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
110
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
111 while(l < size) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
112 op = (ogg_packet*)(buf + l) ;
290
7a3ed84008ec GCC 3.3.2 warnings patch by (Panagiotis Issaris <takis at lumumba dot luc dot ac dot be>)
michael
parents: 277
diff changeset
113 op->packet = (uint8_t*) buf + l + sizeof( ogg_packet) ; /* fix data pointer */
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
114
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
115 if(!context->base_packet_no) { /* this is the first packet */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
116 context->base_packet_no = op->packetno ;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
117 context->base_granule_pos = op->granulepos ;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
118 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
119
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
120 /* correct the fields in the packet -- essential for streaming */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
121
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
122 op->packetno -= context->base_packet_no ;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
123 op->granulepos -= context->base_granule_pos ;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
124
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
125 ogg_stream_packetin(&context->os, op) ;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
126 l += sizeof(ogg_packet) + op->bytes ;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
127
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
128 while(ogg_stream_pageout(&context->os, &og)) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
129 put_buffer(&avfcontext->pb, og.header, og.header_len) ;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
130 put_buffer(&avfcontext->pb, og.body, og.body_len) ;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
131 put_flush_packet(&avfcontext->pb);
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
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
135 return 0;
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
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
139 static int ogg_write_trailer(AVFormatContext *avfcontext) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
140 OggContext *context = avfcontext->priv_data ;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
141 ogg_page og ;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
142
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
143 while(ogg_stream_flush(&context->os, &og)) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
144 put_buffer(&avfcontext->pb, og.header, og.header_len) ;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
145 put_buffer(&avfcontext->pb, og.body, og.body_len) ;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
146 put_flush_packet(&avfcontext->pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
147 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
148
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
149 ogg_stream_clear(&context->os) ;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
150 return 0 ;
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
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
154 static AVOutputFormat ogg_oformat = {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
155 "ogg",
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
156 "Ogg Vorbis",
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
157 "audio/x-vorbis",
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
158 "ogg",
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
159 sizeof(OggContext),
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
160 CODEC_ID_VORBIS,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
161 0,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
162 ogg_write_header,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
163 ogg_write_packet,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
164 ogg_write_trailer,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
165 } ;
277
a313e1080322 disable encoders where appropriate (patch courtesy of BERO
melanson
parents: 68
diff changeset
166 #endif //CONFIG_ENCODERS
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
167
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
168
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
169 static int next_packet(AVFormatContext *avfcontext, ogg_packet *op) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
170 OggContext *context = avfcontext->priv_data ;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
171 ogg_page og ;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
172 char *buf ;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
173
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
174 while(ogg_stream_packetout(&context->os, op) != 1) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
175
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
176 /* while no pages are available, read in more data to the sync */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
177 while(ogg_sync_pageout(&context->oy, &og) != 1) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
178 buf = ogg_sync_buffer(&context->oy, DECODER_BUFFER_SIZE) ;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
179 if(get_buffer(&avfcontext->pb, buf, DECODER_BUFFER_SIZE) <= 0)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
180 return 1 ;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
181 ogg_sync_wrote(&context->oy, DECODER_BUFFER_SIZE) ;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
182 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
183
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
184 /* got a page. Feed it into the stream and get the packet */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
185 if(ogg_stream_pagein(&context->os, &og) != 0)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
186 return 1 ;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
187 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
188
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
189 return 0 ;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
190 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
191
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
192
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
193 static int ogg_read_header(AVFormatContext *avfcontext, AVFormatParameters *ap)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
194 {
35
a16ccdf4a87c removed unneeded mallocs
bellard
parents: 0
diff changeset
195 OggContext *context = avfcontext->priv_data;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
196 char *buf ;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
197 ogg_page og ;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
198 AVStream *ast ;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
199
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
200 ogg_sync_init(&context->oy) ;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
201 buf = ogg_sync_buffer(&context->oy, DECODER_BUFFER_SIZE) ;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
202
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
203 if(get_buffer(&avfcontext->pb, buf, DECODER_BUFFER_SIZE) <= 0)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
204 return -EIO ;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
205
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
206 ogg_sync_wrote(&context->oy, DECODER_BUFFER_SIZE) ;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
207 ogg_sync_pageout(&context->oy, &og) ;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
208 ogg_stream_init(&context->os, ogg_page_serialno(&og)) ;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
209 ogg_stream_pagein(&context->os, &og) ;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
210
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
211 /* currently only one vorbis stream supported */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
212
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
213 ast = av_new_stream(avfcontext, 0) ;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
214 if(!ast)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
215 return AVERROR_NOMEM ;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
216
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
217 ast->codec.codec_type = CODEC_TYPE_AUDIO ;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
218 ast->codec.codec_id = CODEC_ID_VORBIS ;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
219
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
220 return 0 ;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
221 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
222
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
223
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
224 static int ogg_read_packet(AVFormatContext *avfcontext, AVPacket *pkt) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
225 ogg_packet op ;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
226
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
227 if(next_packet(avfcontext, &op))
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
228 return -EIO ;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
229 if(av_new_packet(pkt, sizeof(ogg_packet) + op.bytes) < 0)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
230 return -EIO ;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
231 pkt->stream_index = 0 ;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
232 memcpy(pkt->data, &op, sizeof(ogg_packet)) ;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
233 memcpy(pkt->data + sizeof(ogg_packet), op.packet, op.bytes) ;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
234
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
235 return sizeof(ogg_packet) + op.bytes ;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
236 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
237
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
238
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
239 static int ogg_read_close(AVFormatContext *avfcontext) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
240 OggContext *context = avfcontext->priv_data ;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
241
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
242 ogg_stream_clear(&context->os) ;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
243 ogg_sync_clear(&context->oy) ;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
244
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
245 return 0 ;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
246 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
247
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
248
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
249 static AVInputFormat ogg_iformat = {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
250 "ogg",
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
251 "Ogg Vorbis",
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
252 sizeof(OggContext),
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
253 NULL,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
254 ogg_read_header,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
255 ogg_read_packet,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
256 ogg_read_close,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
257 .extensions = "ogg",
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
258 } ;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
259
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
260
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
261 int ogg_init(void) {
277
a313e1080322 disable encoders where appropriate (patch courtesy of BERO
melanson
parents: 68
diff changeset
262 #ifdef CONFIG_ENCODERS
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
263 av_register_output_format(&ogg_oformat) ;
277
a313e1080322 disable encoders where appropriate (patch courtesy of BERO
melanson
parents: 68
diff changeset
264 #endif
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
265 av_register_input_format(&ogg_iformat);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
266 return 0 ;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
267 }