annotate libogg.c @ 2722:65dcef6d93e1 libavformat

Split out the packet parsing from the main function body in rmdec.c into its own function Patch by Ronald S. Bultje: rsbultje gmail com Original thread: Re: [FFmpeg-devel] [PATCH 2/6] rmdec.c: ff_rm_parse_frame() Date: 11/05/2007 09:23 PM
author benoit
date Thu, 08 Nov 2007 15:07:34 +0000
parents 0c8ec988645c
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2720
0c8ec988645c Give Ogg muxer a lib prefix in the name like we do with all other formats
diego
parents:
diff changeset
1 /*
0c8ec988645c Give Ogg muxer a lib prefix in the name like we do with all other formats
diego
parents:
diff changeset
2 * Ogg bitstream support
0c8ec988645c Give Ogg muxer a lib prefix in the name like we do with all other formats
diego
parents:
diff changeset
3 * Mark Hills <mark@pogo.org.uk>
0c8ec988645c Give Ogg muxer a lib prefix in the name like we do with all other formats
diego
parents:
diff changeset
4 *
0c8ec988645c Give Ogg muxer a lib prefix in the name like we do with all other formats
diego
parents:
diff changeset
5 * Uses libogg, but requires libvorbisenc to construct correct headers
0c8ec988645c Give Ogg muxer a lib prefix in the name like we do with all other formats
diego
parents:
diff changeset
6 * when containing Vorbis stream -- currently the only format supported
0c8ec988645c Give Ogg muxer a lib prefix in the name like we do with all other formats
diego
parents:
diff changeset
7 *
0c8ec988645c Give Ogg muxer a lib prefix in the name like we do with all other formats
diego
parents:
diff changeset
8 * This file is part of FFmpeg.
0c8ec988645c Give Ogg muxer a lib prefix in the name like we do with all other formats
diego
parents:
diff changeset
9 *
0c8ec988645c Give Ogg muxer a lib prefix in the name like we do with all other formats
diego
parents:
diff changeset
10 * FFmpeg is free software; you can redistribute it and/or
0c8ec988645c Give Ogg muxer a lib prefix in the name like we do with all other formats
diego
parents:
diff changeset
11 * modify it under the terms of the GNU Lesser General Public
0c8ec988645c Give Ogg muxer a lib prefix in the name like we do with all other formats
diego
parents:
diff changeset
12 * License as published by the Free Software Foundation; either
0c8ec988645c Give Ogg muxer a lib prefix in the name like we do with all other formats
diego
parents:
diff changeset
13 * version 2.1 of the License, or (at your option) any later version.
0c8ec988645c Give Ogg muxer a lib prefix in the name like we do with all other formats
diego
parents:
diff changeset
14 *
0c8ec988645c Give Ogg muxer a lib prefix in the name like we do with all other formats
diego
parents:
diff changeset
15 * FFmpeg is distributed in the hope that it will be useful,
0c8ec988645c Give Ogg muxer a lib prefix in the name like we do with all other formats
diego
parents:
diff changeset
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
0c8ec988645c Give Ogg muxer a lib prefix in the name like we do with all other formats
diego
parents:
diff changeset
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
0c8ec988645c Give Ogg muxer a lib prefix in the name like we do with all other formats
diego
parents:
diff changeset
18 * Lesser General Public License for more details.
0c8ec988645c Give Ogg muxer a lib prefix in the name like we do with all other formats
diego
parents:
diff changeset
19 *
0c8ec988645c Give Ogg muxer a lib prefix in the name like we do with all other formats
diego
parents:
diff changeset
20 * You should have received a copy of the GNU Lesser General Public
0c8ec988645c Give Ogg muxer a lib prefix in the name like we do with all other formats
diego
parents:
diff changeset
21 * License along with FFmpeg; if not, write to the Free Software
0c8ec988645c Give Ogg muxer a lib prefix in the name like we do with all other formats
diego
parents:
diff changeset
22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
0c8ec988645c Give Ogg muxer a lib prefix in the name like we do with all other formats
diego
parents:
diff changeset
23 */
0c8ec988645c Give Ogg muxer a lib prefix in the name like we do with all other formats
diego
parents:
diff changeset
24
0c8ec988645c Give Ogg muxer a lib prefix in the name like we do with all other formats
diego
parents:
diff changeset
25 #include <stdio.h>
0c8ec988645c Give Ogg muxer a lib prefix in the name like we do with all other formats
diego
parents:
diff changeset
26
0c8ec988645c Give Ogg muxer a lib prefix in the name like we do with all other formats
diego
parents:
diff changeset
27 #include <ogg/ogg.h>
0c8ec988645c Give Ogg muxer a lib prefix in the name like we do with all other formats
diego
parents:
diff changeset
28
0c8ec988645c Give Ogg muxer a lib prefix in the name like we do with all other formats
diego
parents:
diff changeset
29 #include "avformat.h"
0c8ec988645c Give Ogg muxer a lib prefix in the name like we do with all other formats
diego
parents:
diff changeset
30
0c8ec988645c Give Ogg muxer a lib prefix in the name like we do with all other formats
diego
parents:
diff changeset
31
0c8ec988645c Give Ogg muxer a lib prefix in the name like we do with all other formats
diego
parents:
diff changeset
32 #define DECODER_BUFFER_SIZE 4096
0c8ec988645c Give Ogg muxer a lib prefix in the name like we do with all other formats
diego
parents:
diff changeset
33
0c8ec988645c Give Ogg muxer a lib prefix in the name like we do with all other formats
diego
parents:
diff changeset
34
0c8ec988645c Give Ogg muxer a lib prefix in the name like we do with all other formats
diego
parents:
diff changeset
35 typedef struct OggContext {
0c8ec988645c Give Ogg muxer a lib prefix in the name like we do with all other formats
diego
parents:
diff changeset
36 /* output */
0c8ec988645c Give Ogg muxer a lib prefix in the name like we do with all other formats
diego
parents:
diff changeset
37 ogg_stream_state os ;
0c8ec988645c Give Ogg muxer a lib prefix in the name like we do with all other formats
diego
parents:
diff changeset
38 int header_handled ;
0c8ec988645c Give Ogg muxer a lib prefix in the name like we do with all other formats
diego
parents:
diff changeset
39 ogg_packet op;
0c8ec988645c Give Ogg muxer a lib prefix in the name like we do with all other formats
diego
parents:
diff changeset
40
0c8ec988645c Give Ogg muxer a lib prefix in the name like we do with all other formats
diego
parents:
diff changeset
41 /* input */
0c8ec988645c Give Ogg muxer a lib prefix in the name like we do with all other formats
diego
parents:
diff changeset
42 ogg_sync_state oy ;
0c8ec988645c Give Ogg muxer a lib prefix in the name like we do with all other formats
diego
parents:
diff changeset
43 } OggContext ;
0c8ec988645c Give Ogg muxer a lib prefix in the name like we do with all other formats
diego
parents:
diff changeset
44
0c8ec988645c Give Ogg muxer a lib prefix in the name like we do with all other formats
diego
parents:
diff changeset
45
0c8ec988645c Give Ogg muxer a lib prefix in the name like we do with all other formats
diego
parents:
diff changeset
46 #ifdef CONFIG_MUXERS
0c8ec988645c Give Ogg muxer a lib prefix in the name like we do with all other formats
diego
parents:
diff changeset
47 static int ogg_write_header(AVFormatContext *avfcontext)
0c8ec988645c Give Ogg muxer a lib prefix in the name like we do with all other formats
diego
parents:
diff changeset
48 {
0c8ec988645c Give Ogg muxer a lib prefix in the name like we do with all other formats
diego
parents:
diff changeset
49 OggContext *context = avfcontext->priv_data;
0c8ec988645c Give Ogg muxer a lib prefix in the name like we do with all other formats
diego
parents:
diff changeset
50 ogg_packet *op= &context->op;
0c8ec988645c Give Ogg muxer a lib prefix in the name like we do with all other formats
diego
parents:
diff changeset
51 int n;
0c8ec988645c Give Ogg muxer a lib prefix in the name like we do with all other formats
diego
parents:
diff changeset
52
0c8ec988645c Give Ogg muxer a lib prefix in the name like we do with all other formats
diego
parents:
diff changeset
53 ogg_stream_init(&context->os, 31415);
0c8ec988645c Give Ogg muxer a lib prefix in the name like we do with all other formats
diego
parents:
diff changeset
54
0c8ec988645c Give Ogg muxer a lib prefix in the name like we do with all other formats
diego
parents:
diff changeset
55 for(n = 0 ; n < avfcontext->nb_streams ; n++) {
0c8ec988645c Give Ogg muxer a lib prefix in the name like we do with all other formats
diego
parents:
diff changeset
56 AVCodecContext *codec = avfcontext->streams[n]->codec;
0c8ec988645c Give Ogg muxer a lib prefix in the name like we do with all other formats
diego
parents:
diff changeset
57 uint8_t *headers = codec->extradata;
0c8ec988645c Give Ogg muxer a lib prefix in the name like we do with all other formats
diego
parents:
diff changeset
58 int headers_len = codec->extradata_size;
0c8ec988645c Give Ogg muxer a lib prefix in the name like we do with all other formats
diego
parents:
diff changeset
59 uint8_t *header_start[3];
0c8ec988645c Give Ogg muxer a lib prefix in the name like we do with all other formats
diego
parents:
diff changeset
60 int header_len[3];
0c8ec988645c Give Ogg muxer a lib prefix in the name like we do with all other formats
diego
parents:
diff changeset
61 int i, j;
0c8ec988645c Give Ogg muxer a lib prefix in the name like we do with all other formats
diego
parents:
diff changeset
62
0c8ec988645c Give Ogg muxer a lib prefix in the name like we do with all other formats
diego
parents:
diff changeset
63 av_set_pts_info(avfcontext->streams[n], 60, 1, AV_TIME_BASE);
0c8ec988645c Give Ogg muxer a lib prefix in the name like we do with all other formats
diego
parents:
diff changeset
64
0c8ec988645c Give Ogg muxer a lib prefix in the name like we do with all other formats
diego
parents:
diff changeset
65 for(j=1,i=0;i<2;++i, ++j) {
0c8ec988645c Give Ogg muxer a lib prefix in the name like we do with all other formats
diego
parents:
diff changeset
66 header_len[i]=0;
0c8ec988645c Give Ogg muxer a lib prefix in the name like we do with all other formats
diego
parents:
diff changeset
67 while(j<headers_len && headers[j]==0xff) {
0c8ec988645c Give Ogg muxer a lib prefix in the name like we do with all other formats
diego
parents:
diff changeset
68 header_len[i]+=0xff;
0c8ec988645c Give Ogg muxer a lib prefix in the name like we do with all other formats
diego
parents:
diff changeset
69 ++j;
0c8ec988645c Give Ogg muxer a lib prefix in the name like we do with all other formats
diego
parents:
diff changeset
70 }
0c8ec988645c Give Ogg muxer a lib prefix in the name like we do with all other formats
diego
parents:
diff changeset
71 header_len[i]+=headers[j];
0c8ec988645c Give Ogg muxer a lib prefix in the name like we do with all other formats
diego
parents:
diff changeset
72 }
0c8ec988645c Give Ogg muxer a lib prefix in the name like we do with all other formats
diego
parents:
diff changeset
73 header_len[2]=headers_len-header_len[0]-header_len[1]-j;
0c8ec988645c Give Ogg muxer a lib prefix in the name like we do with all other formats
diego
parents:
diff changeset
74 headers+=j;
0c8ec988645c Give Ogg muxer a lib prefix in the name like we do with all other formats
diego
parents:
diff changeset
75 header_start[0] = headers;
0c8ec988645c Give Ogg muxer a lib prefix in the name like we do with all other formats
diego
parents:
diff changeset
76 header_start[1] = header_start[0] + header_len[0];
0c8ec988645c Give Ogg muxer a lib prefix in the name like we do with all other formats
diego
parents:
diff changeset
77 header_start[2] = header_start[1] + header_len[1];
0c8ec988645c Give Ogg muxer a lib prefix in the name like we do with all other formats
diego
parents:
diff changeset
78
0c8ec988645c Give Ogg muxer a lib prefix in the name like we do with all other formats
diego
parents:
diff changeset
79 for(i=0; i < 3; ++i){
0c8ec988645c Give Ogg muxer a lib prefix in the name like we do with all other formats
diego
parents:
diff changeset
80 op->bytes = header_len[i];
0c8ec988645c Give Ogg muxer a lib prefix in the name like we do with all other formats
diego
parents:
diff changeset
81
0c8ec988645c Give Ogg muxer a lib prefix in the name like we do with all other formats
diego
parents:
diff changeset
82 op->packet= header_start[i];
0c8ec988645c Give Ogg muxer a lib prefix in the name like we do with all other formats
diego
parents:
diff changeset
83 op->b_o_s= op->packetno==0;
0c8ec988645c Give Ogg muxer a lib prefix in the name like we do with all other formats
diego
parents:
diff changeset
84
0c8ec988645c Give Ogg muxer a lib prefix in the name like we do with all other formats
diego
parents:
diff changeset
85 ogg_stream_packetin(&context->os, op);
0c8ec988645c Give Ogg muxer a lib prefix in the name like we do with all other formats
diego
parents:
diff changeset
86
0c8ec988645c Give Ogg muxer a lib prefix in the name like we do with all other formats
diego
parents:
diff changeset
87 op->packetno++; //FIXME multiple streams
0c8ec988645c Give Ogg muxer a lib prefix in the name like we do with all other formats
diego
parents:
diff changeset
88 }
0c8ec988645c Give Ogg muxer a lib prefix in the name like we do with all other formats
diego
parents:
diff changeset
89
0c8ec988645c Give Ogg muxer a lib prefix in the name like we do with all other formats
diego
parents:
diff changeset
90 context->header_handled = 0 ;
0c8ec988645c Give Ogg muxer a lib prefix in the name like we do with all other formats
diego
parents:
diff changeset
91 }
0c8ec988645c Give Ogg muxer a lib prefix in the name like we do with all other formats
diego
parents:
diff changeset
92
0c8ec988645c Give Ogg muxer a lib prefix in the name like we do with all other formats
diego
parents:
diff changeset
93 return 0 ;
0c8ec988645c Give Ogg muxer a lib prefix in the name like we do with all other formats
diego
parents:
diff changeset
94 }
0c8ec988645c Give Ogg muxer a lib prefix in the name like we do with all other formats
diego
parents:
diff changeset
95
0c8ec988645c Give Ogg muxer a lib prefix in the name like we do with all other formats
diego
parents:
diff changeset
96 static int ogg_write_packet(AVFormatContext *avfcontext, AVPacket *pkt)
0c8ec988645c Give Ogg muxer a lib prefix in the name like we do with all other formats
diego
parents:
diff changeset
97 {
0c8ec988645c Give Ogg muxer a lib prefix in the name like we do with all other formats
diego
parents:
diff changeset
98 OggContext *context = avfcontext->priv_data ;
0c8ec988645c Give Ogg muxer a lib prefix in the name like we do with all other formats
diego
parents:
diff changeset
99 AVCodecContext *avctx= avfcontext->streams[pkt->stream_index]->codec;
0c8ec988645c Give Ogg muxer a lib prefix in the name like we do with all other formats
diego
parents:
diff changeset
100 ogg_packet *op= &context->op;
0c8ec988645c Give Ogg muxer a lib prefix in the name like we do with all other formats
diego
parents:
diff changeset
101 ogg_page og ;
0c8ec988645c Give Ogg muxer a lib prefix in the name like we do with all other formats
diego
parents:
diff changeset
102 int64_t pts;
0c8ec988645c Give Ogg muxer a lib prefix in the name like we do with all other formats
diego
parents:
diff changeset
103
0c8ec988645c Give Ogg muxer a lib prefix in the name like we do with all other formats
diego
parents:
diff changeset
104 pts= av_rescale(pkt->pts, avctx->sample_rate, AV_TIME_BASE);
0c8ec988645c Give Ogg muxer a lib prefix in the name like we do with all other formats
diego
parents:
diff changeset
105
0c8ec988645c Give Ogg muxer a lib prefix in the name like we do with all other formats
diego
parents:
diff changeset
106 // av_log(avfcontext, AV_LOG_DEBUG, "M%d\n", size);
0c8ec988645c Give Ogg muxer a lib prefix in the name like we do with all other formats
diego
parents:
diff changeset
107
0c8ec988645c Give Ogg muxer a lib prefix in the name like we do with all other formats
diego
parents:
diff changeset
108 /* flush header packets so audio starts on a new page */
0c8ec988645c Give Ogg muxer a lib prefix in the name like we do with all other formats
diego
parents:
diff changeset
109
0c8ec988645c Give Ogg muxer a lib prefix in the name like we do with all other formats
diego
parents:
diff changeset
110 if(!context->header_handled) {
0c8ec988645c Give Ogg muxer a lib prefix in the name like we do with all other formats
diego
parents:
diff changeset
111 while(ogg_stream_flush(&context->os, &og)) {
0c8ec988645c Give Ogg muxer a lib prefix in the name like we do with all other formats
diego
parents:
diff changeset
112 put_buffer(&avfcontext->pb, og.header, og.header_len) ;
0c8ec988645c Give Ogg muxer a lib prefix in the name like we do with all other formats
diego
parents:
diff changeset
113 put_buffer(&avfcontext->pb, og.body, og.body_len) ;
0c8ec988645c Give Ogg muxer a lib prefix in the name like we do with all other formats
diego
parents:
diff changeset
114 put_flush_packet(&avfcontext->pb);
0c8ec988645c Give Ogg muxer a lib prefix in the name like we do with all other formats
diego
parents:
diff changeset
115 }
0c8ec988645c Give Ogg muxer a lib prefix in the name like we do with all other formats
diego
parents:
diff changeset
116 context->header_handled = 1 ;
0c8ec988645c Give Ogg muxer a lib prefix in the name like we do with all other formats
diego
parents:
diff changeset
117 }
0c8ec988645c Give Ogg muxer a lib prefix in the name like we do with all other formats
diego
parents:
diff changeset
118
0c8ec988645c Give Ogg muxer a lib prefix in the name like we do with all other formats
diego
parents:
diff changeset
119 op->packet = (uint8_t*) pkt->data;
0c8ec988645c Give Ogg muxer a lib prefix in the name like we do with all other formats
diego
parents:
diff changeset
120 op->bytes = pkt->size;
0c8ec988645c Give Ogg muxer a lib prefix in the name like we do with all other formats
diego
parents:
diff changeset
121 op->b_o_s = op->packetno == 0;
0c8ec988645c Give Ogg muxer a lib prefix in the name like we do with all other formats
diego
parents:
diff changeset
122 op->granulepos= pts;
0c8ec988645c Give Ogg muxer a lib prefix in the name like we do with all other formats
diego
parents:
diff changeset
123
0c8ec988645c Give Ogg muxer a lib prefix in the name like we do with all other formats
diego
parents:
diff changeset
124 /* correct the fields in the packet -- essential for streaming */
0c8ec988645c Give Ogg muxer a lib prefix in the name like we do with all other formats
diego
parents:
diff changeset
125
0c8ec988645c Give Ogg muxer a lib prefix in the name like we do with all other formats
diego
parents:
diff changeset
126 ogg_stream_packetin(&context->os, op);
0c8ec988645c Give Ogg muxer a lib prefix in the name like we do with all other formats
diego
parents:
diff changeset
127
0c8ec988645c Give Ogg muxer a lib prefix in the name like we do with all other formats
diego
parents:
diff changeset
128 while(ogg_stream_pageout(&context->os, &og)) {
0c8ec988645c Give Ogg muxer a lib prefix in the name like we do with all other formats
diego
parents:
diff changeset
129 put_buffer(&avfcontext->pb, og.header, og.header_len);
0c8ec988645c Give Ogg muxer a lib prefix in the name like we do with all other formats
diego
parents:
diff changeset
130 put_buffer(&avfcontext->pb, og.body, og.body_len);
0c8ec988645c Give Ogg muxer a lib prefix in the name like we do with all other formats
diego
parents:
diff changeset
131 put_flush_packet(&avfcontext->pb);
0c8ec988645c Give Ogg muxer a lib prefix in the name like we do with all other formats
diego
parents:
diff changeset
132 }
0c8ec988645c Give Ogg muxer a lib prefix in the name like we do with all other formats
diego
parents:
diff changeset
133 op->packetno++;
0c8ec988645c Give Ogg muxer a lib prefix in the name like we do with all other formats
diego
parents:
diff changeset
134
0c8ec988645c Give Ogg muxer a lib prefix in the name like we do with all other formats
diego
parents:
diff changeset
135 return 0;
0c8ec988645c Give Ogg muxer a lib prefix in the name like we do with all other formats
diego
parents:
diff changeset
136 }
0c8ec988645c Give Ogg muxer a lib prefix in the name like we do with all other formats
diego
parents:
diff changeset
137
0c8ec988645c Give Ogg muxer a lib prefix in the name like we do with all other formats
diego
parents:
diff changeset
138
0c8ec988645c Give Ogg muxer a lib prefix in the name like we do with all other formats
diego
parents:
diff changeset
139 static int ogg_write_trailer(AVFormatContext *avfcontext) {
0c8ec988645c Give Ogg muxer a lib prefix in the name like we do with all other formats
diego
parents:
diff changeset
140 OggContext *context = avfcontext->priv_data ;
0c8ec988645c Give Ogg muxer a lib prefix in the name like we do with all other formats
diego
parents:
diff changeset
141 ogg_page og ;
0c8ec988645c Give Ogg muxer a lib prefix in the name like we do with all other formats
diego
parents:
diff changeset
142
0c8ec988645c Give Ogg muxer a lib prefix in the name like we do with all other formats
diego
parents:
diff changeset
143 while(ogg_stream_flush(&context->os, &og)) {
0c8ec988645c Give Ogg muxer a lib prefix in the name like we do with all other formats
diego
parents:
diff changeset
144 put_buffer(&avfcontext->pb, og.header, og.header_len) ;
0c8ec988645c Give Ogg muxer a lib prefix in the name like we do with all other formats
diego
parents:
diff changeset
145 put_buffer(&avfcontext->pb, og.body, og.body_len) ;
0c8ec988645c Give Ogg muxer a lib prefix in the name like we do with all other formats
diego
parents:
diff changeset
146 put_flush_packet(&avfcontext->pb);
0c8ec988645c Give Ogg muxer a lib prefix in the name like we do with all other formats
diego
parents:
diff changeset
147 }
0c8ec988645c Give Ogg muxer a lib prefix in the name like we do with all other formats
diego
parents:
diff changeset
148
0c8ec988645c Give Ogg muxer a lib prefix in the name like we do with all other formats
diego
parents:
diff changeset
149 ogg_stream_clear(&context->os) ;
0c8ec988645c Give Ogg muxer a lib prefix in the name like we do with all other formats
diego
parents:
diff changeset
150 return 0 ;
0c8ec988645c Give Ogg muxer a lib prefix in the name like we do with all other formats
diego
parents:
diff changeset
151 }
0c8ec988645c Give Ogg muxer a lib prefix in the name like we do with all other formats
diego
parents:
diff changeset
152
0c8ec988645c Give Ogg muxer a lib prefix in the name like we do with all other formats
diego
parents:
diff changeset
153
0c8ec988645c Give Ogg muxer a lib prefix in the name like we do with all other formats
diego
parents:
diff changeset
154 AVOutputFormat libogg_muxer = {
0c8ec988645c Give Ogg muxer a lib prefix in the name like we do with all other formats
diego
parents:
diff changeset
155 "libogg",
0c8ec988645c Give Ogg muxer a lib prefix in the name like we do with all other formats
diego
parents:
diff changeset
156 "Ogg format",
0c8ec988645c Give Ogg muxer a lib prefix in the name like we do with all other formats
diego
parents:
diff changeset
157 "application/ogg",
0c8ec988645c Give Ogg muxer a lib prefix in the name like we do with all other formats
diego
parents:
diff changeset
158 "ogg",
0c8ec988645c Give Ogg muxer a lib prefix in the name like we do with all other formats
diego
parents:
diff changeset
159 sizeof(OggContext),
0c8ec988645c Give Ogg muxer a lib prefix in the name like we do with all other formats
diego
parents:
diff changeset
160 CODEC_ID_VORBIS,
0c8ec988645c Give Ogg muxer a lib prefix in the name like we do with all other formats
diego
parents:
diff changeset
161 0,
0c8ec988645c Give Ogg muxer a lib prefix in the name like we do with all other formats
diego
parents:
diff changeset
162 ogg_write_header,
0c8ec988645c Give Ogg muxer a lib prefix in the name like we do with all other formats
diego
parents:
diff changeset
163 ogg_write_packet,
0c8ec988645c Give Ogg muxer a lib prefix in the name like we do with all other formats
diego
parents:
diff changeset
164 ogg_write_trailer,
0c8ec988645c Give Ogg muxer a lib prefix in the name like we do with all other formats
diego
parents:
diff changeset
165 } ;
0c8ec988645c Give Ogg muxer a lib prefix in the name like we do with all other formats
diego
parents:
diff changeset
166 #endif //CONFIG_MUXERS
0c8ec988645c Give Ogg muxer a lib prefix in the name like we do with all other formats
diego
parents:
diff changeset
167
0c8ec988645c Give Ogg muxer a lib prefix in the name like we do with all other formats
diego
parents:
diff changeset
168 #if 0
0c8ec988645c Give Ogg muxer a lib prefix in the name like we do with all other formats
diego
parents:
diff changeset
169 static int next_packet(AVFormatContext *avfcontext, ogg_packet *op) {
0c8ec988645c Give Ogg muxer a lib prefix in the name like we do with all other formats
diego
parents:
diff changeset
170 OggContext *context = avfcontext->priv_data ;
0c8ec988645c Give Ogg muxer a lib prefix in the name like we do with all other formats
diego
parents:
diff changeset
171 ogg_page og ;
0c8ec988645c Give Ogg muxer a lib prefix in the name like we do with all other formats
diego
parents:
diff changeset
172 char *buf ;
0c8ec988645c Give Ogg muxer a lib prefix in the name like we do with all other formats
diego
parents:
diff changeset
173
0c8ec988645c Give Ogg muxer a lib prefix in the name like we do with all other formats
diego
parents:
diff changeset
174 while(ogg_stream_packetout(&context->os, op) != 1) {
0c8ec988645c Give Ogg muxer a lib prefix in the name like we do with all other formats
diego
parents:
diff changeset
175
0c8ec988645c Give Ogg muxer a lib prefix in the name like we do with all other formats
diego
parents:
diff changeset
176 /* while no pages are available, read in more data to the sync */
0c8ec988645c Give Ogg muxer a lib prefix in the name like we do with all other formats
diego
parents:
diff changeset
177 while(ogg_sync_pageout(&context->oy, &og) != 1) {
0c8ec988645c Give Ogg muxer a lib prefix in the name like we do with all other formats
diego
parents:
diff changeset
178 buf = ogg_sync_buffer(&context->oy, DECODER_BUFFER_SIZE) ;
0c8ec988645c Give Ogg muxer a lib prefix in the name like we do with all other formats
diego
parents:
diff changeset
179 if(get_buffer(&avfcontext->pb, buf, DECODER_BUFFER_SIZE) <= 0)
0c8ec988645c Give Ogg muxer a lib prefix in the name like we do with all other formats
diego
parents:
diff changeset
180 return 1 ;
0c8ec988645c Give Ogg muxer a lib prefix in the name like we do with all other formats
diego
parents:
diff changeset
181 ogg_sync_wrote(&context->oy, DECODER_BUFFER_SIZE) ;
0c8ec988645c Give Ogg muxer a lib prefix in the name like we do with all other formats
diego
parents:
diff changeset
182 }
0c8ec988645c Give Ogg muxer a lib prefix in the name like we do with all other formats
diego
parents:
diff changeset
183
0c8ec988645c Give Ogg muxer a lib prefix in the name like we do with all other formats
diego
parents:
diff changeset
184 /* got a page. Feed it into the stream and get the packet */
0c8ec988645c Give Ogg muxer a lib prefix in the name like we do with all other formats
diego
parents:
diff changeset
185 if(ogg_stream_pagein(&context->os, &og) != 0)
0c8ec988645c Give Ogg muxer a lib prefix in the name like we do with all other formats
diego
parents:
diff changeset
186 return 1 ;
0c8ec988645c Give Ogg muxer a lib prefix in the name like we do with all other formats
diego
parents:
diff changeset
187 }
0c8ec988645c Give Ogg muxer a lib prefix in the name like we do with all other formats
diego
parents:
diff changeset
188
0c8ec988645c Give Ogg muxer a lib prefix in the name like we do with all other formats
diego
parents:
diff changeset
189 return 0 ;
0c8ec988645c Give Ogg muxer a lib prefix in the name like we do with all other formats
diego
parents:
diff changeset
190 }
0c8ec988645c Give Ogg muxer a lib prefix in the name like we do with all other formats
diego
parents:
diff changeset
191
0c8ec988645c Give Ogg muxer a lib prefix in the name like we do with all other formats
diego
parents:
diff changeset
192
0c8ec988645c Give Ogg muxer a lib prefix in the name like we do with all other formats
diego
parents:
diff changeset
193 static int ogg_read_header(AVFormatContext *avfcontext, AVFormatParameters *ap)
0c8ec988645c Give Ogg muxer a lib prefix in the name like we do with all other formats
diego
parents:
diff changeset
194 {
0c8ec988645c Give Ogg muxer a lib prefix in the name like we do with all other formats
diego
parents:
diff changeset
195 OggContext *context = avfcontext->priv_data;
0c8ec988645c Give Ogg muxer a lib prefix in the name like we do with all other formats
diego
parents:
diff changeset
196 ogg_packet op ;
0c8ec988645c Give Ogg muxer a lib prefix in the name like we do with all other formats
diego
parents:
diff changeset
197 char *buf ;
0c8ec988645c Give Ogg muxer a lib prefix in the name like we do with all other formats
diego
parents:
diff changeset
198 ogg_page og ;
0c8ec988645c Give Ogg muxer a lib prefix in the name like we do with all other formats
diego
parents:
diff changeset
199 AVStream *ast ;
0c8ec988645c Give Ogg muxer a lib prefix in the name like we do with all other formats
diego
parents:
diff changeset
200 AVCodecContext *codec;
0c8ec988645c Give Ogg muxer a lib prefix in the name like we do with all other formats
diego
parents:
diff changeset
201 uint8_t *p;
0c8ec988645c Give Ogg muxer a lib prefix in the name like we do with all other formats
diego
parents:
diff changeset
202 int i;
0c8ec988645c Give Ogg muxer a lib prefix in the name like we do with all other formats
diego
parents:
diff changeset
203
0c8ec988645c Give Ogg muxer a lib prefix in the name like we do with all other formats
diego
parents:
diff changeset
204 ogg_sync_init(&context->oy) ;
0c8ec988645c Give Ogg muxer a lib prefix in the name like we do with all other formats
diego
parents:
diff changeset
205 buf = ogg_sync_buffer(&context->oy, DECODER_BUFFER_SIZE) ;
0c8ec988645c Give Ogg muxer a lib prefix in the name like we do with all other formats
diego
parents:
diff changeset
206
0c8ec988645c Give Ogg muxer a lib prefix in the name like we do with all other formats
diego
parents:
diff changeset
207 if(get_buffer(&avfcontext->pb, buf, DECODER_BUFFER_SIZE) <= 0)
0c8ec988645c Give Ogg muxer a lib prefix in the name like we do with all other formats
diego
parents:
diff changeset
208 return AVERROR(EIO) ;
0c8ec988645c Give Ogg muxer a lib prefix in the name like we do with all other formats
diego
parents:
diff changeset
209
0c8ec988645c Give Ogg muxer a lib prefix in the name like we do with all other formats
diego
parents:
diff changeset
210 ogg_sync_wrote(&context->oy, DECODER_BUFFER_SIZE) ;
0c8ec988645c Give Ogg muxer a lib prefix in the name like we do with all other formats
diego
parents:
diff changeset
211 ogg_sync_pageout(&context->oy, &og) ;
0c8ec988645c Give Ogg muxer a lib prefix in the name like we do with all other formats
diego
parents:
diff changeset
212 ogg_stream_init(&context->os, ogg_page_serialno(&og)) ;
0c8ec988645c Give Ogg muxer a lib prefix in the name like we do with all other formats
diego
parents:
diff changeset
213 ogg_stream_pagein(&context->os, &og) ;
0c8ec988645c Give Ogg muxer a lib prefix in the name like we do with all other formats
diego
parents:
diff changeset
214
0c8ec988645c Give Ogg muxer a lib prefix in the name like we do with all other formats
diego
parents:
diff changeset
215 /* currently only one vorbis stream supported */
0c8ec988645c Give Ogg muxer a lib prefix in the name like we do with all other formats
diego
parents:
diff changeset
216
0c8ec988645c Give Ogg muxer a lib prefix in the name like we do with all other formats
diego
parents:
diff changeset
217 ast = av_new_stream(avfcontext, 0) ;
0c8ec988645c Give Ogg muxer a lib prefix in the name like we do with all other formats
diego
parents:
diff changeset
218 if(!ast)
0c8ec988645c Give Ogg muxer a lib prefix in the name like we do with all other formats
diego
parents:
diff changeset
219 return AVERROR(ENOMEM) ;
0c8ec988645c Give Ogg muxer a lib prefix in the name like we do with all other formats
diego
parents:
diff changeset
220 av_set_pts_info(ast, 60, 1, AV_TIME_BASE);
0c8ec988645c Give Ogg muxer a lib prefix in the name like we do with all other formats
diego
parents:
diff changeset
221
0c8ec988645c Give Ogg muxer a lib prefix in the name like we do with all other formats
diego
parents:
diff changeset
222 codec= &ast->codec;
0c8ec988645c Give Ogg muxer a lib prefix in the name like we do with all other formats
diego
parents:
diff changeset
223 codec->codec_type = CODEC_TYPE_AUDIO;
0c8ec988645c Give Ogg muxer a lib prefix in the name like we do with all other formats
diego
parents:
diff changeset
224 codec->codec_id = CODEC_ID_VORBIS;
0c8ec988645c Give Ogg muxer a lib prefix in the name like we do with all other formats
diego
parents:
diff changeset
225 for(i=0; i<3; i++){
0c8ec988645c Give Ogg muxer a lib prefix in the name like we do with all other formats
diego
parents:
diff changeset
226 if(next_packet(avfcontext, &op)){
0c8ec988645c Give Ogg muxer a lib prefix in the name like we do with all other formats
diego
parents:
diff changeset
227 return -1;
0c8ec988645c Give Ogg muxer a lib prefix in the name like we do with all other formats
diego
parents:
diff changeset
228 }
0c8ec988645c Give Ogg muxer a lib prefix in the name like we do with all other formats
diego
parents:
diff changeset
229 if(op.bytes >= (1<<16) || op.bytes < 0)
0c8ec988645c Give Ogg muxer a lib prefix in the name like we do with all other formats
diego
parents:
diff changeset
230 return -1;
0c8ec988645c Give Ogg muxer a lib prefix in the name like we do with all other formats
diego
parents:
diff changeset
231 codec->extradata_size+= 2 + op.bytes;
0c8ec988645c Give Ogg muxer a lib prefix in the name like we do with all other formats
diego
parents:
diff changeset
232 codec->extradata= av_realloc(codec->extradata, codec->extradata_size + FF_INPUT_BUFFER_PADDING_SIZE);
0c8ec988645c Give Ogg muxer a lib prefix in the name like we do with all other formats
diego
parents:
diff changeset
233 memset(codec->extradata + codec->extradata_size, 0, FF_INPUT_BUFFER_PADDING_SIZE);
0c8ec988645c Give Ogg muxer a lib prefix in the name like we do with all other formats
diego
parents:
diff changeset
234 p= codec->extradata + codec->extradata_size - 2 - op.bytes;
0c8ec988645c Give Ogg muxer a lib prefix in the name like we do with all other formats
diego
parents:
diff changeset
235 *(p++)= op.bytes>>8;
0c8ec988645c Give Ogg muxer a lib prefix in the name like we do with all other formats
diego
parents:
diff changeset
236 *(p++)= op.bytes&0xFF;
0c8ec988645c Give Ogg muxer a lib prefix in the name like we do with all other formats
diego
parents:
diff changeset
237 memcpy(p, op.packet, op.bytes);
0c8ec988645c Give Ogg muxer a lib prefix in the name like we do with all other formats
diego
parents:
diff changeset
238 }
0c8ec988645c Give Ogg muxer a lib prefix in the name like we do with all other formats
diego
parents:
diff changeset
239
0c8ec988645c Give Ogg muxer a lib prefix in the name like we do with all other formats
diego
parents:
diff changeset
240 return 0 ;
0c8ec988645c Give Ogg muxer a lib prefix in the name like we do with all other formats
diego
parents:
diff changeset
241 }
0c8ec988645c Give Ogg muxer a lib prefix in the name like we do with all other formats
diego
parents:
diff changeset
242
0c8ec988645c Give Ogg muxer a lib prefix in the name like we do with all other formats
diego
parents:
diff changeset
243
0c8ec988645c Give Ogg muxer a lib prefix in the name like we do with all other formats
diego
parents:
diff changeset
244 static int ogg_read_packet(AVFormatContext *avfcontext, AVPacket *pkt) {
0c8ec988645c Give Ogg muxer a lib prefix in the name like we do with all other formats
diego
parents:
diff changeset
245 ogg_packet op ;
0c8ec988645c Give Ogg muxer a lib prefix in the name like we do with all other formats
diego
parents:
diff changeset
246
0c8ec988645c Give Ogg muxer a lib prefix in the name like we do with all other formats
diego
parents:
diff changeset
247 if(next_packet(avfcontext, &op))
0c8ec988645c Give Ogg muxer a lib prefix in the name like we do with all other formats
diego
parents:
diff changeset
248 return AVERROR(EIO) ;
0c8ec988645c Give Ogg muxer a lib prefix in the name like we do with all other formats
diego
parents:
diff changeset
249 if(av_new_packet(pkt, op.bytes) < 0)
0c8ec988645c Give Ogg muxer a lib prefix in the name like we do with all other formats
diego
parents:
diff changeset
250 return AVERROR(EIO) ;
0c8ec988645c Give Ogg muxer a lib prefix in the name like we do with all other formats
diego
parents:
diff changeset
251 pkt->stream_index = 0 ;
0c8ec988645c Give Ogg muxer a lib prefix in the name like we do with all other formats
diego
parents:
diff changeset
252 memcpy(pkt->data, op.packet, op.bytes);
0c8ec988645c Give Ogg muxer a lib prefix in the name like we do with all other formats
diego
parents:
diff changeset
253 if(avfcontext->streams[0]->codec.sample_rate && op.granulepos!=-1)
0c8ec988645c Give Ogg muxer a lib prefix in the name like we do with all other formats
diego
parents:
diff changeset
254 pkt->pts= av_rescale(op.granulepos, AV_TIME_BASE, avfcontext->streams[0]->codec.sample_rate);
0c8ec988645c Give Ogg muxer a lib prefix in the name like we do with all other formats
diego
parents:
diff changeset
255 // printf("%"PRId64" %d %d\n", pkt->pts, (int)op.granulepos, avfcontext->streams[0]->codec.sample_rate);
0c8ec988645c Give Ogg muxer a lib prefix in the name like we do with all other formats
diego
parents:
diff changeset
256
0c8ec988645c Give Ogg muxer a lib prefix in the name like we do with all other formats
diego
parents:
diff changeset
257 return op.bytes;
0c8ec988645c Give Ogg muxer a lib prefix in the name like we do with all other formats
diego
parents:
diff changeset
258 }
0c8ec988645c Give Ogg muxer a lib prefix in the name like we do with all other formats
diego
parents:
diff changeset
259
0c8ec988645c Give Ogg muxer a lib prefix in the name like we do with all other formats
diego
parents:
diff changeset
260
0c8ec988645c Give Ogg muxer a lib prefix in the name like we do with all other formats
diego
parents:
diff changeset
261 static int ogg_read_close(AVFormatContext *avfcontext) {
0c8ec988645c Give Ogg muxer a lib prefix in the name like we do with all other formats
diego
parents:
diff changeset
262 OggContext *context = avfcontext->priv_data ;
0c8ec988645c Give Ogg muxer a lib prefix in the name like we do with all other formats
diego
parents:
diff changeset
263
0c8ec988645c Give Ogg muxer a lib prefix in the name like we do with all other formats
diego
parents:
diff changeset
264 ogg_stream_clear(&context->os) ;
0c8ec988645c Give Ogg muxer a lib prefix in the name like we do with all other formats
diego
parents:
diff changeset
265 ogg_sync_clear(&context->oy) ;
0c8ec988645c Give Ogg muxer a lib prefix in the name like we do with all other formats
diego
parents:
diff changeset
266
0c8ec988645c Give Ogg muxer a lib prefix in the name like we do with all other formats
diego
parents:
diff changeset
267 return 0 ;
0c8ec988645c Give Ogg muxer a lib prefix in the name like we do with all other formats
diego
parents:
diff changeset
268 }
0c8ec988645c Give Ogg muxer a lib prefix in the name like we do with all other formats
diego
parents:
diff changeset
269
0c8ec988645c Give Ogg muxer a lib prefix in the name like we do with all other formats
diego
parents:
diff changeset
270
0c8ec988645c Give Ogg muxer a lib prefix in the name like we do with all other formats
diego
parents:
diff changeset
271 static AVInputFormat ogg_iformat = {
0c8ec988645c Give Ogg muxer a lib prefix in the name like we do with all other formats
diego
parents:
diff changeset
272 "ogg",
0c8ec988645c Give Ogg muxer a lib prefix in the name like we do with all other formats
diego
parents:
diff changeset
273 "Ogg Vorbis",
0c8ec988645c Give Ogg muxer a lib prefix in the name like we do with all other formats
diego
parents:
diff changeset
274 sizeof(OggContext),
0c8ec988645c Give Ogg muxer a lib prefix in the name like we do with all other formats
diego
parents:
diff changeset
275 NULL,
0c8ec988645c Give Ogg muxer a lib prefix in the name like we do with all other formats
diego
parents:
diff changeset
276 ogg_read_header,
0c8ec988645c Give Ogg muxer a lib prefix in the name like we do with all other formats
diego
parents:
diff changeset
277 ogg_read_packet,
0c8ec988645c Give Ogg muxer a lib prefix in the name like we do with all other formats
diego
parents:
diff changeset
278 ogg_read_close,
0c8ec988645c Give Ogg muxer a lib prefix in the name like we do with all other formats
diego
parents:
diff changeset
279 .extensions = "ogg",
0c8ec988645c Give Ogg muxer a lib prefix in the name like we do with all other formats
diego
parents:
diff changeset
280 } ;
0c8ec988645c Give Ogg muxer a lib prefix in the name like we do with all other formats
diego
parents:
diff changeset
281 #endif