Commit a03cbe5f authored by Michael Niedermayer's avatar Michael Niedermayer

fix global header passing from demuxer to decoder

Originally committed as revision 2958 to svn://svn.ffmpeg.org/ffmpeg/trunk
parent 3f4993f1
...@@ -200,10 +200,29 @@ AVCodec oggvorbis_encoder = { ...@@ -200,10 +200,29 @@ AVCodec oggvorbis_encoder = {
static int oggvorbis_decode_init(AVCodecContext *avccontext) { static int oggvorbis_decode_init(AVCodecContext *avccontext) {
OggVorbisContext *context = avccontext->priv_data ; OggVorbisContext *context = avccontext->priv_data ;
uint8_t *p= avccontext->extradata;
int i;
vorbis_info_init(&context->vi) ; vorbis_info_init(&context->vi) ;
vorbis_comment_init(&context->vc) ; vorbis_comment_init(&context->vc) ;
context->op.packetno= 0;
for(i=0; i<3; i++){
context->op.b_o_s= i==0;
context->op.bytes= *(p++)<<8;
context->op.bytes+=*(p++);
context->op.packet= p;
p += context->op.bytes;
if(vorbis_synthesis_headerin(&context->vi, &context->vc, &context->op)<0){
av_log(avccontext, AV_LOG_ERROR, "%d. vorbis header damaged\n", i+1);
return -1;
}
}
avccontext->channels = context->vi.channels;
avccontext->sample_rate = context->vi.rate;
vorbis_synthesis_init(&context->vd, &context->vi);
vorbis_block_init(&context->vd, &context->vb);
return 0 ; return 0 ;
} }
...@@ -251,31 +270,12 @@ static int oggvorbis_decode_frame(AVCodecContext *avccontext, ...@@ -251,31 +270,12 @@ static int oggvorbis_decode_frame(AVCodecContext *avccontext,
op->packet = buf; op->packet = buf;
op->bytes = buf_size; op->bytes = buf_size;
op->b_o_s = op->packetno == 0;
// av_log(avccontext, AV_LOG_DEBUG, "%d %d %d %lld %lld %d %d\n", op->bytes, op->b_o_s, op->e_o_s, op->granulepos, op->packetno, buf_size, context->vi.rate); // av_log(avccontext, AV_LOG_DEBUG, "%d %d %d %lld %lld %d %d\n", op->bytes, op->b_o_s, op->e_o_s, op->granulepos, op->packetno, buf_size, context->vi.rate);
/* for(i=0; i<op->bytes; i++) /* for(i=0; i<op->bytes; i++)
av_log(avccontext, AV_LOG_DEBUG, "%02X ", op->packet[i]); av_log(avccontext, AV_LOG_DEBUG, "%02X ", op->packet[i]);
av_log(avccontext, AV_LOG_DEBUG, "\n");*/ av_log(avccontext, AV_LOG_DEBUG, "\n");*/
if(op->packetno < 3) {
if(vorbis_synthesis_headerin(&context->vi, &context->vc, op)<0){
av_log(avccontext, AV_LOG_ERROR, "%lld. vorbis header damaged\n", op->packetno+1);
return -1;
}
avccontext->channels = context->vi.channels ;
avccontext->sample_rate = context->vi.rate ;
op->packetno++;
return buf_size ;
}
if(op->packetno == 3) {
// av_log(avccontext, AV_LOG_INFO, "vorbis_decode: %d channel, %ldHz, encoder `%s'\n",
// context->vi.channels, context->vi.rate, context->vc.vendor);
vorbis_synthesis_init(&context->vd, &context->vi) ;
vorbis_block_init(&context->vd, &context->vb);
}
if(vorbis_synthesis(&context->vb, op) == 0) if(vorbis_synthesis(&context->vb, op) == 0)
vorbis_synthesis_blockin(&context->vd, &context->vb) ; vorbis_synthesis_blockin(&context->vd, &context->vb) ;
...@@ -290,7 +290,6 @@ static int oggvorbis_decode_frame(AVCodecContext *avccontext, ...@@ -290,7 +290,6 @@ static int oggvorbis_decode_frame(AVCodecContext *avccontext,
vorbis_synthesis_read(&context->vd, samples) ; vorbis_synthesis_read(&context->vd, samples) ;
} }
op->packetno++;
*data_size = total_bytes ; *data_size = total_bytes ;
return buf_size ; return buf_size ;
} }
......
...@@ -167,9 +167,13 @@ static int next_packet(AVFormatContext *avfcontext, ogg_packet *op) { ...@@ -167,9 +167,13 @@ static int next_packet(AVFormatContext *avfcontext, ogg_packet *op) {
static int ogg_read_header(AVFormatContext *avfcontext, AVFormatParameters *ap) static int ogg_read_header(AVFormatContext *avfcontext, AVFormatParameters *ap)
{ {
OggContext *context = avfcontext->priv_data; OggContext *context = avfcontext->priv_data;
ogg_packet op ;
char *buf ; char *buf ;
ogg_page og ; ogg_page og ;
AVStream *ast ; AVStream *ast ;
AVCodecContext *codec;
uint8_t *p;
int i;
avfcontext->ctx_flags |= AVFMTCTX_NOHEADER; avfcontext->ctx_flags |= AVFMTCTX_NOHEADER;
...@@ -183,16 +187,28 @@ static int ogg_read_header(AVFormatContext *avfcontext, AVFormatParameters *ap) ...@@ -183,16 +187,28 @@ static int ogg_read_header(AVFormatContext *avfcontext, AVFormatParameters *ap)
ogg_sync_pageout(&context->oy, &og) ; ogg_sync_pageout(&context->oy, &og) ;
ogg_stream_init(&context->os, ogg_page_serialno(&og)) ; ogg_stream_init(&context->os, ogg_page_serialno(&og)) ;
ogg_stream_pagein(&context->os, &og) ; ogg_stream_pagein(&context->os, &og) ;
/* currently only one vorbis stream supported */ /* currently only one vorbis stream supported */
ast = av_new_stream(avfcontext, 0) ; ast = av_new_stream(avfcontext, 0) ;
if(!ast) if(!ast)
return AVERROR_NOMEM ; return AVERROR_NOMEM ;
ast->codec.codec_type = CODEC_TYPE_AUDIO ; codec= &ast->codec;
ast->codec.codec_id = CODEC_ID_VORBIS ; codec->codec_type = CODEC_TYPE_AUDIO;
codec->codec_id = CODEC_ID_VORBIS;
for(i=0; i<3; i++){
if(next_packet(avfcontext, &op)){
return -1;
}
codec->extradata_size+= 2 + op.bytes;
codec->extradata= av_realloc(codec->extradata, codec->extradata_size);
p= codec->extradata + codec->extradata_size - 2 - op.bytes;
*(p++)= op.bytes>>8;
*(p++)= op.bytes&0xFF;
memcpy(p, op.packet, op.bytes);
}
return 0 ; return 0 ;
} }
...@@ -216,6 +232,7 @@ static int ogg_read_close(AVFormatContext *avfcontext) { ...@@ -216,6 +232,7 @@ static int ogg_read_close(AVFormatContext *avfcontext) {
ogg_stream_clear(&context->os) ; ogg_stream_clear(&context->os) ;
ogg_sync_clear(&context->oy) ; ogg_sync_clear(&context->oy) ;
av_freep(&avfcontext->streams[0]->codec.extradata);
return 0 ; return 0 ;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment