comparison oggparsevorbis.c @ 760:c72bba158baa libavformat

change extradata format for vorbis
author mru
date Fri, 13 May 2005 18:10:23 +0000
parents 9372cd60d25d
children feca73904e67
comparison
equal deleted inserted replaced
759:6418c3b8d8ec 760:c72bba158baa
124 * [blocksize_0] = read 4 bits as unsigned integer | Not Used 124 * [blocksize_0] = read 4 bits as unsigned integer | Not Used
125 * [blocksize_1] = read 4 bits as unsigned integer | Not Used 125 * [blocksize_1] = read 4 bits as unsigned integer | Not Used
126 * [framing_flag] = read one bit | Not Used 126 * [framing_flag] = read one bit | Not Used
127 * */ 127 * */
128 128
129 typedef struct {
130 unsigned int len[3];
131 unsigned char *packet[3];
132 } oggvorbis_private_t;
133
134
135 static unsigned int
136 fixup_vorbis_headers(AVFormatContext * as, oggvorbis_private_t *priv,
137 void **buf)
138 {
139 int i,offset, len;
140 unsigned char *ptr;
141
142 len = priv->len[0] + priv->len[1] + priv->len[2];
143 ptr = *buf = av_mallocz(len + len/255 + 64);
144
145 ptr[0] = 2;
146 offset = 1;
147 offset += av_xiphlacing(&ptr[offset], priv->len[0]);
148 offset += av_xiphlacing(&ptr[offset], priv->len[1]);
149 for(i = 0; i < 3; i++) {
150 memcpy(&ptr[offset], priv->packet[i], priv->len[i]);
151 offset += priv->len[i];
152 }
153 *buf = av_realloc(*buf, offset);
154 return offset;
155 }
156
157
129 static int 158 static int
130 vorbis_header (AVFormatContext * s, int idx) 159 vorbis_header (AVFormatContext * s, int idx)
131 { 160 {
132 ogg_t *ogg = s->priv_data; 161 ogg_t *ogg = s->priv_data;
133 ogg_stream_t *os = ogg->streams + idx; 162 ogg_stream_t *os = ogg->streams + idx;
134 AVStream *st = s->streams[idx]; 163 AVStream *st = s->streams[idx];
135 int cds = st->codec.extradata_size + os->psize + 2; 164 oggvorbis_private_t *priv;
136 uint8_t *cdp;
137 165
138 if (os->seq > 2) 166 if (os->seq > 2)
139 return 0; 167 return 0;
140 168
141 st->codec.extradata = av_realloc (st->codec.extradata, cds); 169 if(os->seq == 0) {
142 cdp = st->codec.extradata + st->codec.extradata_size; 170 os->private = av_mallocz(sizeof(oggvorbis_private_t));
143 *cdp++ = os->psize >> 8; 171 if(!os->private)
144 *cdp++ = os->psize & 0xff; 172 return 0;
145 memcpy (cdp, os->buf + os->pstart, os->psize); 173 }
146 st->codec.extradata_size = cds; 174
147 175 priv = os->private;
176 priv->len[os->seq] = os->psize;
177 priv->packet[os->seq] = av_mallocz(os->psize);
178 memcpy(priv->packet[os->seq], os->buf + os->pstart, os->psize);
148 if (os->buf[os->pstart] == 1) { 179 if (os->buf[os->pstart] == 1) {
149 uint8_t *p = os->buf + os->pstart + 11; //skip up to the audio channels 180 uint8_t *p = os->buf + os->pstart + 11; //skip up to the audio channels
150 st->codec.channels = *p++; 181 st->codec.channels = *p++;
151 st->codec.sample_rate = le2me_32 (unaligned32 (p)); 182 st->codec.sample_rate = le2me_32 (unaligned32 (p));
152 p += 8; //skip maximum and and nominal bitrate 183 p += 8; //skip maximum and and nominal bitrate
155 st->codec.codec_type = CODEC_TYPE_AUDIO; 186 st->codec.codec_type = CODEC_TYPE_AUDIO;
156 st->codec.codec_id = CODEC_ID_VORBIS; 187 st->codec.codec_id = CODEC_ID_VORBIS;
157 188
158 } else if (os->buf[os->pstart] == 3) { 189 } else if (os->buf[os->pstart] == 3) {
159 vorbis_comment (s, os->buf + os->pstart + 7, os->psize - 8); 190 vorbis_comment (s, os->buf + os->pstart + 7, os->psize - 8);
191 } else {
192 st->codec.extradata_size =
193 fixup_vorbis_headers(s, priv, &st->codec.extradata);
160 } 194 }
161 195
162 return os->seq < 3; 196 return os->seq < 3;
163 } 197 }
164 198