Mercurial > libavcodec.hg
comparison oggvorbis.c @ 2676:0975710cf7f4 libavcodec
change extradata format for vorbis
author | mru |
---|---|
date | Fri, 13 May 2005 18:10:23 +0000 |
parents | ef44d24680d1 |
children | 040b965f2cd0 |
comparison
equal
deleted
inserted
replaced
2675:c6aa5585954f | 2676:0975710cf7f4 |
---|---|
47 | 47 |
48 static int oggvorbis_encode_init(AVCodecContext *avccontext) { | 48 static int oggvorbis_encode_init(AVCodecContext *avccontext) { |
49 OggVorbisContext *context = avccontext->priv_data ; | 49 OggVorbisContext *context = avccontext->priv_data ; |
50 ogg_packet header, header_comm, header_code; | 50 ogg_packet header, header_comm, header_code; |
51 uint8_t *p; | 51 uint8_t *p; |
52 unsigned int offset, len; | |
52 | 53 |
53 vorbis_info_init(&context->vi) ; | 54 vorbis_info_init(&context->vi) ; |
54 if(oggvorbis_init_encoder(&context->vi, avccontext) < 0) { | 55 if(oggvorbis_init_encoder(&context->vi, avccontext) < 0) { |
55 av_log(avccontext, AV_LOG_ERROR, "oggvorbis_encode_init: init_encoder failed") ; | 56 av_log(avccontext, AV_LOG_ERROR, "oggvorbis_encode_init: init_encoder failed") ; |
56 return -1 ; | 57 return -1 ; |
62 vorbis_comment_add_tag(&context->vc, "encoder", LIBAVCODEC_IDENT) ; | 63 vorbis_comment_add_tag(&context->vc, "encoder", LIBAVCODEC_IDENT) ; |
63 | 64 |
64 vorbis_analysis_headerout(&context->vd, &context->vc, &header, | 65 vorbis_analysis_headerout(&context->vd, &context->vc, &header, |
65 &header_comm, &header_code); | 66 &header_comm, &header_code); |
66 | 67 |
67 avccontext->extradata_size= 3*2 + header.bytes + header_comm.bytes + header_code.bytes; | 68 len = header.bytes + header_comm.bytes + header_code.bytes; |
68 p= avccontext->extradata= av_mallocz(avccontext->extradata_size); | 69 avccontext->extradata_size= 64 + len + len/255; |
69 | 70 p = avccontext->extradata= av_mallocz(avccontext->extradata_size); |
70 *(p++) = header.bytes>>8; | 71 p[0] = 2; |
71 *(p++) = header.bytes&0xFF; | 72 offset = 1; |
72 memcpy(p, header.packet, header.bytes); | 73 offset += av_xiphlacing(&p[offset], header.bytes); |
73 p += header.bytes; | 74 offset += av_xiphlacing(&p[offset], header_comm.bytes); |
74 | 75 memcpy(&p[offset], header.packet, header.bytes); |
75 *(p++) = header_comm.bytes>>8; | 76 offset += header.bytes; |
76 *(p++) = header_comm.bytes&0xFF; | 77 memcpy(&p[offset], header_comm.packet, header_comm.bytes); |
77 memcpy(p, header_comm.packet, header_comm.bytes); | 78 offset += header_comm.bytes; |
78 p += header_comm.bytes; | 79 memcpy(&p[offset], header_code.packet, header_code.bytes); |
79 | 80 offset += header_code.bytes; |
80 *(p++) = header_code.bytes>>8; | 81 avccontext->extradata_size = offset; |
81 *(p++) = header_code.bytes&0xFF; | 82 avccontext->extradata= av_realloc(avccontext->extradata, avccontext->extradata_size); |
82 memcpy(p, header_code.packet, header_code.bytes); | |
83 | 83 |
84 /* vorbis_block_clear(&context->vb); | 84 /* vorbis_block_clear(&context->vb); |
85 vorbis_dsp_clear(&context->vd); | 85 vorbis_dsp_clear(&context->vd); |
86 vorbis_info_clear(&context->vi);*/ | 86 vorbis_info_clear(&context->vi);*/ |
87 vorbis_comment_clear(&context->vc); | 87 vorbis_comment_clear(&context->vc); |
182 | 182 |
183 | 183 |
184 static int oggvorbis_decode_init(AVCodecContext *avccontext) { | 184 static int oggvorbis_decode_init(AVCodecContext *avccontext) { |
185 OggVorbisContext *context = avccontext->priv_data ; | 185 OggVorbisContext *context = avccontext->priv_data ; |
186 uint8_t *p= avccontext->extradata; | 186 uint8_t *p= avccontext->extradata; |
187 int i; | 187 int i, hsizes[3]; |
188 unsigned char *headers[3], *extradata = avccontext->extradata; | |
189 unsigned int offset; | |
188 | 190 |
189 vorbis_info_init(&context->vi) ; | 191 vorbis_info_init(&context->vi) ; |
190 vorbis_comment_init(&context->vc) ; | 192 vorbis_comment_init(&context->vc) ; |
191 | 193 |
194 if(! avccontext->extradata_size || ! p) { | |
195 av_log(avccontext, AV_LOG_ERROR, "vorbis extradata absent\n"); | |
196 return -1; | |
197 } | |
198 if(*p != 2) { | |
199 av_log(avccontext, AV_LOG_ERROR, | |
200 "vorbis initial header len is wrong: %d\n", *p); | |
201 return -1; | |
202 } | |
203 offset = 1; | |
204 p++; | |
205 for(i=0; i<2; i++) { | |
206 hsizes[i] = 0; | |
207 while((*p == 0xFF) && (offset < avccontext->extradata_size)) { | |
208 hsizes[i] += 0xFF; | |
209 offset++; | |
210 p++; | |
211 } | |
212 if(offset >= avccontext->extradata_size - 1) { | |
213 av_log(avccontext, AV_LOG_ERROR, "vorbis header sizes damaged\n"); | |
214 return -1; | |
215 } | |
216 hsizes[i] += *p; | |
217 offset++; | |
218 p++; | |
219 } | |
220 hsizes[2] = avccontext->extradata_size - hsizes[0] - hsizes[1] - offset; | |
221 #if 0 | |
222 av_log(avccontext, AV_LOG_DEBUG, | |
223 "vorbis header sizes: %d, %d, %d, / extradata_len is %d \n", | |
224 hsizes[0], hsizes[1], hsizes[2], avccontext->extradata_size); | |
225 #endif | |
226 headers[0] = extradata + offset; | |
227 headers[1] = extradata + offset + hsizes[0]; | |
228 headers[2] = extradata + offset + hsizes[0] + hsizes[1]; | |
229 | |
192 for(i=0; i<3; i++){ | 230 for(i=0; i<3; i++){ |
193 context->op.b_o_s= i==0; | 231 context->op.b_o_s= i==0; |
194 context->op.bytes= *(p++)<<8; | 232 context->op.bytes = hsizes[i]; |
195 context->op.bytes+=*(p++); | 233 context->op.packet = headers[i]; |
196 context->op.packet= p; | 234 if(vorbis_synthesis_headerin(&context->vi, &context->vc, &context->op)<0){ |
197 p += context->op.bytes; | |
198 | |
199 if(vorbis_synthesis_headerin(&context->vi, &context->vc, &context->op)<0){ | |
200 av_log(avccontext, AV_LOG_ERROR, "%d. vorbis header damaged\n", i+1); | 235 av_log(avccontext, AV_LOG_ERROR, "%d. vorbis header damaged\n", i+1); |
201 return -1; | 236 return -1; |
202 } | 237 } |
203 } | 238 } |
204 avccontext->channels = context->vi.channels; | 239 avccontext->channels = context->vi.channels; |