Commit 7aa2d42d authored by Kostya Shishkov's avatar Kostya Shishkov

If custom sampling rate is set in WavPack file, parse first block to find

actual value.

This fixes issue 1518.

Originally committed as revision 20461 to svn://svn.ffmpeg.org/ffmpeg/trunk
parent aa926a48
...@@ -101,9 +101,30 @@ static int wv_read_block_header(AVFormatContext *ctx, ByteIOContext *pb) ...@@ -101,9 +101,30 @@ static int wv_read_block_header(AVFormatContext *ctx, ByteIOContext *pb)
bpp = ((wc->flags & 3) + 1) << 3; bpp = ((wc->flags & 3) + 1) << 3;
chan = 1 + !(wc->flags & WV_MONO); chan = 1 + !(wc->flags & WV_MONO);
rate = wv_rates[(wc->flags >> 23) & 0xF]; rate = wv_rates[(wc->flags >> 23) & 0xF];
if(rate == -1){ if(rate == -1 && !wc->block_parsed){
av_log(ctx, AV_LOG_ERROR, "Unknown sampling rate\n"); int64_t block_end = url_ftell(pb) + wc->blksize - 24;
return -1; if(url_is_streamed(pb)){
av_log(ctx, AV_LOG_ERROR, "Cannot determine custom sampling rate\n");
return -1;
}
while(url_ftell(pb) < block_end){
int id, size;
id = get_byte(pb);
size = (id & 0x80) ? get_le24(pb) : get_byte(pb);
size <<= 1;
if(id&0x40)
size--;
if((id&0x3F) == 0x27){
rate = get_le24(pb);
break;
}else{
url_fskip(pb, size);
}
}
if(rate == -1){
av_log(ctx, AV_LOG_ERROR, "Cannot determine custom sampling rate\n");
return -1;
}
} }
if(!wc->bpp) wc->bpp = bpp; if(!wc->bpp) wc->bpp = bpp;
if(!wc->chan) wc->chan = chan; if(!wc->chan) wc->chan = chan;
...@@ -117,7 +138,7 @@ static int wv_read_block_header(AVFormatContext *ctx, ByteIOContext *pb) ...@@ -117,7 +138,7 @@ static int wv_read_block_header(AVFormatContext *ctx, ByteIOContext *pb)
av_log(ctx, AV_LOG_ERROR, "Channels differ, this block: %i, header block: %i\n", chan, wc->chan); av_log(ctx, AV_LOG_ERROR, "Channels differ, this block: %i, header block: %i\n", chan, wc->chan);
return -1; return -1;
} }
if(wc->flags && rate != wc->rate){ if(wc->flags && rate != -1 && rate != wc->rate){
av_log(ctx, AV_LOG_ERROR, "Sampling rate differ, this block: %i, header block: %i\n", rate, wc->rate); av_log(ctx, AV_LOG_ERROR, "Sampling rate differ, this block: %i, header block: %i\n", rate, wc->rate);
return -1; return -1;
} }
......
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