mirror of
https://git.ffmpeg.org/ffmpeg.git
synced 2025-01-30 19:34:43 +00:00
ape: calculate final packet size instead of guessing
Calculates based on total file size and wavetaillength from the header. Falls back to multiplying finalframeblocks by 8 instead of 4 so that it will at least be overestimating for 24-bit. Currently it can underestimate the final packet size, leading to decoding errors.
This commit is contained in:
parent
c2c316158f
commit
ac3f8d317c
@ -159,8 +159,8 @@ static int ape_read_header(AVFormatContext * s)
|
|||||||
AVStream *st;
|
AVStream *st;
|
||||||
uint32_t tag;
|
uint32_t tag;
|
||||||
int i;
|
int i;
|
||||||
int total_blocks;
|
int total_blocks, final_size = 0;
|
||||||
int64_t pts;
|
int64_t pts, file_size;
|
||||||
|
|
||||||
/* Skip any leading junk such as id3v2 tags */
|
/* Skip any leading junk such as id3v2 tags */
|
||||||
ape->junklength = avio_tell(pb);
|
ape->junklength = avio_tell(pb);
|
||||||
@ -289,8 +289,17 @@ static int ape_read_header(AVFormatContext * s)
|
|||||||
ape->frames[i - 1].size = ape->frames[i].pos - ape->frames[i - 1].pos;
|
ape->frames[i - 1].size = ape->frames[i].pos - ape->frames[i - 1].pos;
|
||||||
ape->frames[i].skip = (ape->frames[i].pos - ape->frames[0].pos) & 3;
|
ape->frames[i].skip = (ape->frames[i].pos - ape->frames[0].pos) & 3;
|
||||||
}
|
}
|
||||||
ape->frames[ape->totalframes - 1].size = ape->finalframeblocks * 4;
|
|
||||||
ape->frames[ape->totalframes - 1].nblocks = ape->finalframeblocks;
|
ape->frames[ape->totalframes - 1].nblocks = ape->finalframeblocks;
|
||||||
|
/* calculate final packet size from total file size, if available */
|
||||||
|
file_size = avio_size(pb);
|
||||||
|
if (file_size > 0) {
|
||||||
|
final_size = file_size - ape->frames[ape->totalframes - 1].pos -
|
||||||
|
ape->wavtaillength;
|
||||||
|
final_size -= final_size & 3;
|
||||||
|
}
|
||||||
|
if (file_size <= 0 || final_size <= 0)
|
||||||
|
final_size = ape->finalframeblocks * 8;
|
||||||
|
ape->frames[ape->totalframes - 1].size = final_size;
|
||||||
|
|
||||||
for (i = 0; i < ape->totalframes; i++) {
|
for (i = 0; i < ape->totalframes; i++) {
|
||||||
if(ape->frames[i].skip){
|
if(ape->frames[i].skip){
|
||||||
|
Loading…
Reference in New Issue
Block a user