Commit 53940bd3 authored by mru's avatar mru

accept old extradata format


git-svn-id: file:///var/local/repositories/ffmpeg/trunk@4281 9553f0bf-9b14-0410-a0b8-cfaf0461ba5b
parent 65259cb0
...@@ -180,13 +180,11 @@ AVCodec oggvorbis_encoder = { ...@@ -180,13 +180,11 @@ AVCodec oggvorbis_encoder = {
.capabilities= CODEC_CAP_DELAY, .capabilities= CODEC_CAP_DELAY,
} ; } ;
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; uint8_t *p= avccontext->extradata;
int i, hsizes[3]; int i, hsizes[3];
unsigned char *headers[3], *extradata = avccontext->extradata; unsigned char *headers[3], *extradata = avccontext->extradata;
unsigned int offset;
vorbis_info_init(&context->vi) ; vorbis_info_init(&context->vi) ;
vorbis_comment_init(&context->vc) ; vorbis_comment_init(&context->vc) ;
...@@ -195,12 +193,16 @@ static int oggvorbis_decode_init(AVCodecContext *avccontext) { ...@@ -195,12 +193,16 @@ static int oggvorbis_decode_init(AVCodecContext *avccontext) {
av_log(avccontext, AV_LOG_ERROR, "vorbis extradata absent\n"); av_log(avccontext, AV_LOG_ERROR, "vorbis extradata absent\n");
return -1; return -1;
} }
if(*p != 2) {
av_log(avccontext, AV_LOG_ERROR, if(p[0] == 0 && p[1] == 30) {
"vorbis initial header len is wrong: %d\n", *p); for(i = 0; i < 3; i++){
return -1; hsizes[i] = *p++ << 8;
hsizes[i] += *p++;
headers[i] = p;
p += hsizes[i];
} }
offset = 1; } else if(*p == 2) {
unsigned int offset = 1;
p++; p++;
for(i=0; i<2; i++) { for(i=0; i<2; i++) {
hsizes[i] = 0; hsizes[i] = 0;
...@@ -210,14 +212,15 @@ static int oggvorbis_decode_init(AVCodecContext *avccontext) { ...@@ -210,14 +212,15 @@ static int oggvorbis_decode_init(AVCodecContext *avccontext) {
p++; p++;
} }
if(offset >= avccontext->extradata_size - 1) { if(offset >= avccontext->extradata_size - 1) {
av_log(avccontext, AV_LOG_ERROR, "vorbis header sizes damaged\n"); av_log(avccontext, AV_LOG_ERROR,
"vorbis header sizes damaged\n");
return -1; return -1;
} }
hsizes[i] += *p; hsizes[i] += *p;
offset++; offset++;
p++; p++;
} }
hsizes[2] = avccontext->extradata_size - hsizes[0] - hsizes[1] - offset; hsizes[2] = avccontext->extradata_size - hsizes[0]-hsizes[1]-offset;
#if 0 #if 0
av_log(avccontext, AV_LOG_DEBUG, av_log(avccontext, AV_LOG_DEBUG,
"vorbis header sizes: %d, %d, %d, / extradata_len is %d \n", "vorbis header sizes: %d, %d, %d, / extradata_len is %d \n",
...@@ -226,6 +229,11 @@ static int oggvorbis_decode_init(AVCodecContext *avccontext) { ...@@ -226,6 +229,11 @@ static int oggvorbis_decode_init(AVCodecContext *avccontext) {
headers[0] = extradata + offset; headers[0] = extradata + offset;
headers[1] = extradata + offset + hsizes[0]; headers[1] = extradata + offset + hsizes[0];
headers[2] = extradata + offset + hsizes[0] + hsizes[1]; headers[2] = extradata + offset + hsizes[0] + hsizes[1];
} else {
av_log(avccontext, AV_LOG_ERROR,
"vorbis initial header len is wrong: %d\n", *p);
return -1;
}
for(i=0; i<3; i++){ for(i=0; i<3; i++){
context->op.b_o_s= i==0; context->op.b_o_s= i==0;
...@@ -236,6 +244,7 @@ static int oggvorbis_decode_init(AVCodecContext *avccontext) { ...@@ -236,6 +244,7 @@ static int oggvorbis_decode_init(AVCodecContext *avccontext) {
return -1; return -1;
} }
} }
avccontext->channels = context->vi.channels; avccontext->channels = context->vi.channels;
avccontext->sample_rate = context->vi.rate; avccontext->sample_rate = context->vi.rate;
avccontext->time_base= (AVRational){1, avccontext->sample_rate}; avccontext->time_base= (AVRational){1, avccontext->sample_rate};
......
...@@ -759,17 +759,26 @@ static int vorbis_decode_init(AVCodecContext *avccontext) { ...@@ -759,17 +759,26 @@ static int vorbis_decode_init(AVCodecContext *avccontext) {
vorbis_context *vc = avccontext->priv_data ; vorbis_context *vc = avccontext->priv_data ;
uint8_t *headers = avccontext->extradata; uint8_t *headers = avccontext->extradata;
int headers_len=avccontext->extradata_size; int headers_len=avccontext->extradata_size;
uint8_t *header_start[3];
int header_len[3]; int header_len[3];
GetBitContext *gb = &(vc->gb); GetBitContext *gb = &(vc->gb);
int i, j, hdr_type; int i, j, hdr_type;
vc->avccontext = avccontext; vc->avccontext = avccontext;
if (!headers_len || headers[0]!=2) { if (!headers_len) {
av_log(avccontext, AV_LOG_ERROR, "Extradata corrupt.\n"); av_log(avccontext, AV_LOG_ERROR, "Extradata corrupt.\n");
return -1; return -1;
} }
if(headers[0] == 0 && headers[1] == 30) {
for(i = 0; i < 3; i++){
header_len[i] = *headers++ << 8;
header_len[i] += *headers++;
header_start[i] = headers;
headers += header_len[i];
}
} else if(headers[0] == 2) {
for(j=1,i=0;i<2;++i, ++j) { for(j=1,i=0;i<2;++i, ++j) {
header_len[i]=0; header_len[i]=0;
while(j<headers_len && headers[j]==0xff) { while(j<headers_len && headers[j]==0xff) {
...@@ -784,8 +793,15 @@ static int vorbis_decode_init(AVCodecContext *avccontext) { ...@@ -784,8 +793,15 @@ static int vorbis_decode_init(AVCodecContext *avccontext) {
} }
header_len[2]=headers_len-header_len[0]-header_len[1]-j; header_len[2]=headers_len-header_len[0]-header_len[1]-j;
headers+=j; headers+=j;
header_start[0] = headers;
header_start[1] = header_start[0] + header_len[0];
header_start[2] = header_start[1] + header_len[1];
} else {
av_log(avccontext, AV_LOG_ERROR, "Extradata corrupt.\n");
return -1;
}
init_get_bits(gb, headers, header_len[0]*8); init_get_bits(gb, header_start[0], header_len[0]*8);
hdr_type=get_bits(gb, 8); hdr_type=get_bits(gb, 8);
if (hdr_type!=1) { if (hdr_type!=1) {
av_log(avccontext, AV_LOG_ERROR, "First header is not the id header.\n"); av_log(avccontext, AV_LOG_ERROR, "First header is not the id header.\n");
...@@ -797,7 +813,7 @@ static int vorbis_decode_init(AVCodecContext *avccontext) { ...@@ -797,7 +813,7 @@ static int vorbis_decode_init(AVCodecContext *avccontext) {
return -1; return -1;
} }
init_get_bits(gb, headers+header_len[0]+header_len[1], header_len[2]*8); init_get_bits(gb, header_start[2], header_len[2]*8);
hdr_type=get_bits(gb, 8); hdr_type=get_bits(gb, 8);
if (hdr_type!=5) { if (hdr_type!=5) {
av_log(avccontext, AV_LOG_ERROR, "Third header is not the setup header.\n"); av_log(avccontext, AV_LOG_ERROR, "Third header is not the setup header.\n");
......
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