annotate ogg.c @ 702:23f12cd0dc53 libavformat

dont link with libavcodec twice on win32
author michael
date Tue, 15 Mar 2005 12:37:39 +0000
parents 0b52743104ac
children 17178af951b4
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
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
11 #include <ogg/ogg.h>
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
12
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
13 #include "avformat.h"
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
14
406
ea22a438ca79 fix obnoxious ogg_packet passing from encoder to muxer
michael
parents: 405
diff changeset
15 #undef NDEBUG
ea22a438ca79 fix obnoxious ogg_packet passing from encoder to muxer
michael
parents: 405
diff changeset
16 #include <assert.h>
ea22a438ca79 fix obnoxious ogg_packet passing from encoder to muxer
michael
parents: 405
diff changeset
17
0
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 ;
406
ea22a438ca79 fix obnoxious ogg_packet passing from encoder to muxer
michael
parents: 405
diff changeset
25 ogg_packet op;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
26
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
27 /* input */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
28 ogg_sync_state oy ;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
29 } OggContext ;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
30
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
31
277
a313e1080322 disable encoders where appropriate (patch courtesy of BERO
melanson
parents: 68
diff changeset
32 #ifdef CONFIG_ENCODERS
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;
407
b9d16c18ee18 remove function call from muxer->encoder and cleanly pass global headers
michael
parents: 406
diff changeset
36 ogg_packet *op= &context->op;
b9d16c18ee18 remove function call from muxer->encoder and cleanly pass global headers
michael
parents: 406
diff changeset
37 int n, i;
406
ea22a438ca79 fix obnoxious ogg_packet passing from encoder to muxer
michael
parents: 405
diff changeset
38
404
6579fe3ade40 remove spyware from ogg*.c
michael
parents: 327
diff changeset
39 ogg_stream_init(&context->os, 31415);
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
40
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
41 for(n = 0 ; n < avfcontext->nb_streams ; n++) {
407
b9d16c18ee18 remove function call from muxer->encoder and cleanly pass global headers
michael
parents: 406
diff changeset
42 AVCodecContext *codec = &avfcontext->streams[n]->codec;
b9d16c18ee18 remove function call from muxer->encoder and cleanly pass global headers
michael
parents: 406
diff changeset
43 uint8_t *p= codec->extradata;
b9d16c18ee18 remove function call from muxer->encoder and cleanly pass global headers
michael
parents: 406
diff changeset
44
462
b69898ffc92a move time_base (pts_num/pts_den) from AVFormatContext -> AVStream
michael
parents: 454
diff changeset
45 av_set_pts_info(avfcontext->streams[n], 60, 1, AV_TIME_BASE);
b69898ffc92a move time_base (pts_num/pts_den) from AVFormatContext -> AVStream
michael
parents: 454
diff changeset
46
407
b9d16c18ee18 remove function call from muxer->encoder and cleanly pass global headers
michael
parents: 406
diff changeset
47 for(i=0; i < codec->extradata_size; i+= op->bytes){
b9d16c18ee18 remove function call from muxer->encoder and cleanly pass global headers
michael
parents: 406
diff changeset
48 op->bytes = p[i++]<<8;
b9d16c18ee18 remove function call from muxer->encoder and cleanly pass global headers
michael
parents: 406
diff changeset
49 op->bytes+= p[i++];
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
50
407
b9d16c18ee18 remove function call from muxer->encoder and cleanly pass global headers
michael
parents: 406
diff changeset
51 op->packet= &p[i];
b9d16c18ee18 remove function call from muxer->encoder and cleanly pass global headers
michael
parents: 406
diff changeset
52 op->b_o_s= op->packetno==0;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
53
407
b9d16c18ee18 remove function call from muxer->encoder and cleanly pass global headers
michael
parents: 406
diff changeset
54 ogg_stream_packetin(&context->os, op);
b9d16c18ee18 remove function call from muxer->encoder and cleanly pass global headers
michael
parents: 406
diff changeset
55
b9d16c18ee18 remove function call from muxer->encoder and cleanly pass global headers
michael
parents: 406
diff changeset
56 op->packetno++; //FIXME multiple streams
b9d16c18ee18 remove function call from muxer->encoder and cleanly pass global headers
michael
parents: 406
diff changeset
57 }
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
58
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
59 context->header_handled = 0 ;
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 return 0 ;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
63 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
64
468
60f897e8dd2d pass AVPacket into av_write_frame()
michael
parents: 462
diff changeset
65 static int ogg_write_packet(AVFormatContext *avfcontext, AVPacket *pkt)
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
66 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
67 OggContext *context = avfcontext->priv_data ;
468
60f897e8dd2d pass AVPacket into av_write_frame()
michael
parents: 462
diff changeset
68 AVCodecContext *avctx= &avfcontext->streams[pkt->stream_index]->codec;
406
ea22a438ca79 fix obnoxious ogg_packet passing from encoder to muxer
michael
parents: 405
diff changeset
69 ogg_packet *op= &context->op;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
70 ogg_page og ;
468
60f897e8dd2d pass AVPacket into av_write_frame()
michael
parents: 462
diff changeset
71 int64_t pts;
406
ea22a438ca79 fix obnoxious ogg_packet passing from encoder to muxer
michael
parents: 405
diff changeset
72
468
60f897e8dd2d pass AVPacket into av_write_frame()
michael
parents: 462
diff changeset
73 pts= av_rescale(pkt->pts, avctx->sample_rate, AV_TIME_BASE);
406
ea22a438ca79 fix obnoxious ogg_packet passing from encoder to muxer
michael
parents: 405
diff changeset
74
ea22a438ca79 fix obnoxious ogg_packet passing from encoder to muxer
michael
parents: 405
diff changeset
75 // av_log(avfcontext, AV_LOG_DEBUG, "M%d\n", size);
ea22a438ca79 fix obnoxious ogg_packet passing from encoder to muxer
michael
parents: 405
diff changeset
76
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
77 /* flush header packets so audio starts on a new page */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
78
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
79 if(!context->header_handled) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
80 while(ogg_stream_flush(&context->os, &og)) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
81 put_buffer(&avfcontext->pb, og.header, og.header_len) ;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
82 put_buffer(&avfcontext->pb, og.body, og.body_len) ;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
83 put_flush_packet(&avfcontext->pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
84 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
85 context->header_handled = 1 ;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
86 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
87
468
60f897e8dd2d pass AVPacket into av_write_frame()
michael
parents: 462
diff changeset
88 op->packet = (uint8_t*) pkt->data;
60f897e8dd2d pass AVPacket into av_write_frame()
michael
parents: 462
diff changeset
89 op->bytes = pkt->size;
406
ea22a438ca79 fix obnoxious ogg_packet passing from encoder to muxer
michael
parents: 405
diff changeset
90 op->b_o_s = op->packetno == 0;
ea22a438ca79 fix obnoxious ogg_packet passing from encoder to muxer
michael
parents: 405
diff changeset
91 op->granulepos= pts;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
92
406
ea22a438ca79 fix obnoxious ogg_packet passing from encoder to muxer
michael
parents: 405
diff changeset
93 /* correct the fields in the packet -- essential for streaming */
ea22a438ca79 fix obnoxious ogg_packet passing from encoder to muxer
michael
parents: 405
diff changeset
94
ea22a438ca79 fix obnoxious ogg_packet passing from encoder to muxer
michael
parents: 405
diff changeset
95 ogg_stream_packetin(&context->os, op);
ea22a438ca79 fix obnoxious ogg_packet passing from encoder to muxer
michael
parents: 405
diff changeset
96
ea22a438ca79 fix obnoxious ogg_packet passing from encoder to muxer
michael
parents: 405
diff changeset
97 while(ogg_stream_pageout(&context->os, &og)) {
ea22a438ca79 fix obnoxious ogg_packet passing from encoder to muxer
michael
parents: 405
diff changeset
98 put_buffer(&avfcontext->pb, og.header, og.header_len);
ea22a438ca79 fix obnoxious ogg_packet passing from encoder to muxer
michael
parents: 405
diff changeset
99 put_buffer(&avfcontext->pb, og.body, og.body_len);
ea22a438ca79 fix obnoxious ogg_packet passing from encoder to muxer
michael
parents: 405
diff changeset
100 put_flush_packet(&avfcontext->pb);
ea22a438ca79 fix obnoxious ogg_packet passing from encoder to muxer
michael
parents: 405
diff changeset
101 }
ea22a438ca79 fix obnoxious ogg_packet passing from encoder to muxer
michael
parents: 405
diff changeset
102 op->packetno++;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
103
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
104 return 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
105 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
106
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
107
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
108 static int ogg_write_trailer(AVFormatContext *avfcontext) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
109 OggContext *context = avfcontext->priv_data ;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
110 ogg_page og ;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
111
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
112 while(ogg_stream_flush(&context->os, &og)) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
113 put_buffer(&avfcontext->pb, og.header, og.header_len) ;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
114 put_buffer(&avfcontext->pb, og.body, og.body_len) ;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
115 put_flush_packet(&avfcontext->pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
116 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
117
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
118 ogg_stream_clear(&context->os) ;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
119 return 0 ;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
120 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
121
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
122
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
123 static AVOutputFormat ogg_oformat = {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
124 "ogg",
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
125 "Ogg Vorbis",
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
126 "audio/x-vorbis",
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
127 "ogg",
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
128 sizeof(OggContext),
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
129 CODEC_ID_VORBIS,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
130 0,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
131 ogg_write_header,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
132 ogg_write_packet,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
133 ogg_write_trailer,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
134 } ;
277
a313e1080322 disable encoders where appropriate (patch courtesy of BERO
melanson
parents: 68
diff changeset
135 #endif //CONFIG_ENCODERS
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 static int next_packet(AVFormatContext *avfcontext, ogg_packet *op) {
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 char *buf ;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
142
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
143 while(ogg_stream_packetout(&context->os, op) != 1) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
144
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
145 /* while no pages are available, read in more data to the sync */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
146 while(ogg_sync_pageout(&context->oy, &og) != 1) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
147 buf = ogg_sync_buffer(&context->oy, DECODER_BUFFER_SIZE) ;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
148 if(get_buffer(&avfcontext->pb, buf, DECODER_BUFFER_SIZE) <= 0)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
149 return 1 ;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
150 ogg_sync_wrote(&context->oy, DECODER_BUFFER_SIZE) ;
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 /* got a page. Feed it into the stream and get the packet */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
154 if(ogg_stream_pagein(&context->os, &og) != 0)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
155 return 1 ;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
156 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
157
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
158 return 0 ;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
159 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
160
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
161
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
162 static int ogg_read_header(AVFormatContext *avfcontext, AVFormatParameters *ap)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
163 {
35
a16ccdf4a87c removed unneeded mallocs
bellard
parents: 0
diff changeset
164 OggContext *context = avfcontext->priv_data;
408
237eeeb50fb8 fix global header passing from demuxer to decoder
michael
parents: 407
diff changeset
165 ogg_packet op ;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
166 char *buf ;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
167 ogg_page og ;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
168 AVStream *ast ;
408
237eeeb50fb8 fix global header passing from demuxer to decoder
michael
parents: 407
diff changeset
169 AVCodecContext *codec;
237eeeb50fb8 fix global header passing from demuxer to decoder
michael
parents: 407
diff changeset
170 uint8_t *p;
237eeeb50fb8 fix global header passing from demuxer to decoder
michael
parents: 407
diff changeset
171 int i;
404
6579fe3ade40 remove spyware from ogg*.c
michael
parents: 327
diff changeset
172
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
173 ogg_sync_init(&context->oy) ;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
174 buf = ogg_sync_buffer(&context->oy, DECODER_BUFFER_SIZE) ;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
175
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
176 if(get_buffer(&avfcontext->pb, buf, DECODER_BUFFER_SIZE) <= 0)
482
0fdc96c2f2fe sweeping change from -EIO -> AVERROR_IO
melanson
parents: 468
diff changeset
177 return AVERROR_IO ;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
178
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 ogg_sync_pageout(&context->oy, &og) ;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
181 ogg_stream_init(&context->os, ogg_page_serialno(&og)) ;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
182 ogg_stream_pagein(&context->os, &og) ;
408
237eeeb50fb8 fix global header passing from demuxer to decoder
michael
parents: 407
diff changeset
183
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
184 /* currently only one vorbis stream supported */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
185
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
186 ast = av_new_stream(avfcontext, 0) ;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
187 if(!ast)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
188 return AVERROR_NOMEM ;
462
b69898ffc92a move time_base (pts_num/pts_den) from AVFormatContext -> AVStream
michael
parents: 454
diff changeset
189 av_set_pts_info(ast, 60, 1, AV_TIME_BASE);
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
190
408
237eeeb50fb8 fix global header passing from demuxer to decoder
michael
parents: 407
diff changeset
191 codec= &ast->codec;
237eeeb50fb8 fix global header passing from demuxer to decoder
michael
parents: 407
diff changeset
192 codec->codec_type = CODEC_TYPE_AUDIO;
237eeeb50fb8 fix global header passing from demuxer to decoder
michael
parents: 407
diff changeset
193 codec->codec_id = CODEC_ID_VORBIS;
237eeeb50fb8 fix global header passing from demuxer to decoder
michael
parents: 407
diff changeset
194 for(i=0; i<3; i++){
237eeeb50fb8 fix global header passing from demuxer to decoder
michael
parents: 407
diff changeset
195 if(next_packet(avfcontext, &op)){
237eeeb50fb8 fix global header passing from demuxer to decoder
michael
parents: 407
diff changeset
196 return -1;
237eeeb50fb8 fix global header passing from demuxer to decoder
michael
parents: 407
diff changeset
197 }
639
0b52743104ac integer overflows, heap corruption
michael
parents: 587
diff changeset
198 if(op.bytes >= (1<<16) || op.bytes < 0)
0b52743104ac integer overflows, heap corruption
michael
parents: 587
diff changeset
199 return -1;
408
237eeeb50fb8 fix global header passing from demuxer to decoder
michael
parents: 407
diff changeset
200 codec->extradata_size+= 2 + op.bytes;
587
fe24632a577b allocate a few bytes more for extradata so the bitstream reader if its used by the codec for parsing extardata, doesnt read over the end
michael
parents: 486
diff changeset
201 codec->extradata= av_realloc(codec->extradata, codec->extradata_size + FF_INPUT_BUFFER_PADDING_SIZE);
408
237eeeb50fb8 fix global header passing from demuxer to decoder
michael
parents: 407
diff changeset
202 p= codec->extradata + codec->extradata_size - 2 - op.bytes;
237eeeb50fb8 fix global header passing from demuxer to decoder
michael
parents: 407
diff changeset
203 *(p++)= op.bytes>>8;
237eeeb50fb8 fix global header passing from demuxer to decoder
michael
parents: 407
diff changeset
204 *(p++)= op.bytes&0xFF;
237eeeb50fb8 fix global header passing from demuxer to decoder
michael
parents: 407
diff changeset
205 memcpy(p, op.packet, op.bytes);
237eeeb50fb8 fix global header passing from demuxer to decoder
michael
parents: 407
diff changeset
206 }
237eeeb50fb8 fix global header passing from demuxer to decoder
michael
parents: 407
diff changeset
207
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
208 return 0 ;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
209 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
210
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
211
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
212 static int ogg_read_packet(AVFormatContext *avfcontext, AVPacket *pkt) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
213 ogg_packet op ;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
214
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
215 if(next_packet(avfcontext, &op))
482
0fdc96c2f2fe sweeping change from -EIO -> AVERROR_IO
melanson
parents: 468
diff changeset
216 return AVERROR_IO ;
405
04d7dda7ccd5 kill obnoxious ogg_packet passing from demuxer to decoder
michael
parents: 404
diff changeset
217 if(av_new_packet(pkt, op.bytes) < 0)
482
0fdc96c2f2fe sweeping change from -EIO -> AVERROR_IO
melanson
parents: 468
diff changeset
218 return AVERROR_IO ;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
219 pkt->stream_index = 0 ;
405
04d7dda7ccd5 kill obnoxious ogg_packet passing from demuxer to decoder
michael
parents: 404
diff changeset
220 memcpy(pkt->data, op.packet, op.bytes);
454
7fa377b2f533 export pts if available
michael
parents: 409
diff changeset
221 if(avfcontext->streams[0]->codec.sample_rate && op.granulepos!=-1)
7fa377b2f533 export pts if available
michael
parents: 409
diff changeset
222 pkt->pts= av_rescale(op.granulepos, AV_TIME_BASE, avfcontext->streams[0]->codec.sample_rate);
7fa377b2f533 export pts if available
michael
parents: 409
diff changeset
223 // printf("%lld %d %d\n", pkt->pts, (int)op.granulepos, avfcontext->streams[0]->codec.sample_rate);
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
224
405
04d7dda7ccd5 kill obnoxious ogg_packet passing from demuxer to decoder
michael
parents: 404
diff changeset
225 return op.bytes;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
226 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
227
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
228
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
229 static int ogg_read_close(AVFormatContext *avfcontext) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
230 OggContext *context = avfcontext->priv_data ;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
231
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
232 ogg_stream_clear(&context->os) ;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
233 ogg_sync_clear(&context->oy) ;
408
237eeeb50fb8 fix global header passing from demuxer to decoder
michael
parents: 407
diff changeset
234 av_freep(&avfcontext->streams[0]->codec.extradata);
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
235
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
236 return 0 ;
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
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
240 static AVInputFormat ogg_iformat = {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
241 "ogg",
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
242 "Ogg Vorbis",
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
243 sizeof(OggContext),
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
244 NULL,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
245 ogg_read_header,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
246 ogg_read_packet,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
247 ogg_read_close,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
248 .extensions = "ogg",
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
249 } ;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
250
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
251
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
252 int ogg_init(void) {
277
a313e1080322 disable encoders where appropriate (patch courtesy of BERO
melanson
parents: 68
diff changeset
253 #ifdef CONFIG_ENCODERS
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
254 av_register_output_format(&ogg_oformat) ;
277
a313e1080322 disable encoders where appropriate (patch courtesy of BERO
melanson
parents: 68
diff changeset
255 #endif
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
256 av_register_input_format(&ogg_iformat);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
257 return 0 ;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
258 }