Commit 03cc52a0 authored by Paul B Mahol's avatar Paul B Mahol

takdec: fix seeking

The previous approach was just wrong.
Signed-off-by: 's avatarPaul B Mahol <onemda@gmail.com>
parent c6d39fb3
...@@ -27,7 +27,7 @@ ...@@ -27,7 +27,7 @@
typedef struct TAKDemuxContext { typedef struct TAKDemuxContext {
int mlast_frame; int mlast_frame;
int64_t left; int64_t data_end;
} TAKDemuxContext; } TAKDemuxContext;
static int tak_probe(AVProbeData *p) static int tak_probe(AVProbeData *p)
...@@ -96,15 +96,18 @@ static int tak_read_header(AVFormatContext *s) ...@@ -96,15 +96,18 @@ static int tak_read_header(AVFormatContext *s)
av_log(s, AV_LOG_VERBOSE, "\n"); av_log(s, AV_LOG_VERBOSE, "\n");
break; break;
} }
case TAK_METADATA_END: case TAK_METADATA_END: {
if (pb->seekable) { int64_t curpos = avio_tell(pb);
int64_t curpos = avio_tell(pb);
if (pb->seekable) {
ff_ape_parse_tag(s); ff_ape_parse_tag(s);
avio_seek(pb, curpos, SEEK_SET); avio_seek(pb, curpos, SEEK_SET);
} }
tc->data_end += curpos;
return 0; return 0;
break; break;
}
default: default:
ret = avio_skip(pb, size); ret = avio_skip(pb, size);
if (ret < 0) if (ret < 0)
...@@ -131,8 +134,8 @@ static int tak_read_header(AVFormatContext *s) ...@@ -131,8 +134,8 @@ static int tak_read_header(AVFormatContext *s)
if (size != 11) if (size != 11)
return AVERROR_INVALIDDATA; return AVERROR_INVALIDDATA;
tc->mlast_frame = 1; tc->mlast_frame = 1;
tc->left = get_bits_longlong(&gb, TAK_LAST_FRAME_POS_BITS) + tc->data_end = get_bits_longlong(&gb, TAK_LAST_FRAME_POS_BITS) +
get_bits(&gb, TAK_LAST_FRAME_SIZE_BITS); get_bits(&gb, TAK_LAST_FRAME_SIZE_BITS);
av_freep(&buffer); av_freep(&buffer);
} else if (type == TAK_METADATA_ENCODER) { } else if (type == TAK_METADATA_ENCODER) {
av_log(s, AV_LOG_VERBOSE, "encoder version: %0X\n", av_log(s, AV_LOG_VERBOSE, "encoder version: %0X\n",
...@@ -151,10 +154,11 @@ static int raw_read_packet(AVFormatContext *s, AVPacket *pkt) ...@@ -151,10 +154,11 @@ static int raw_read_packet(AVFormatContext *s, AVPacket *pkt)
if (tc->mlast_frame) { if (tc->mlast_frame) {
AVIOContext *pb = s->pb; AVIOContext *pb = s->pb;
int64_t size; int64_t size, left;
size = FFMIN(tc->left, 1024); left = tc->data_end - avio_tell(s->pb);
if (!size) size = FFMIN(left, 1024);
if (size <= 0)
return AVERROR_EOF; return AVERROR_EOF;
ret = av_get_packet(pb, pkt, size); ret = av_get_packet(pb, pkt, size);
...@@ -162,7 +166,6 @@ static int raw_read_packet(AVFormatContext *s, AVPacket *pkt) ...@@ -162,7 +166,6 @@ static int raw_read_packet(AVFormatContext *s, AVPacket *pkt)
return ret; return ret;
pkt->stream_index = 0; pkt->stream_index = 0;
tc->left -= ret;
} else { } else {
ret = ff_raw_read_partial_packet(s, pkt); ret = ff_raw_read_partial_packet(s, pkt);
} }
......
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