mirror of
https://github.com/FFmpeg/FFmpeg.git
synced 2025-02-04 06:08:26 +02:00
avformat/cache: remember EOF point if hit and use it to handle SEEK_END
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
This commit is contained in:
parent
0c0168a210
commit
681559d3ff
@ -57,6 +57,7 @@ typedef struct Context {
|
|||||||
int64_t cache_pos;
|
int64_t cache_pos;
|
||||||
int64_t inner_pos;
|
int64_t inner_pos;
|
||||||
int64_t end;
|
int64_t end;
|
||||||
|
int is_true_eof;
|
||||||
URLContext *inner;
|
URLContext *inner;
|
||||||
int64_t cache_hit, cache_miss;
|
int64_t cache_hit, cache_miss;
|
||||||
} Context;
|
} Context;
|
||||||
@ -174,6 +175,10 @@ static int cache_read(URLContext *h, unsigned char *buf, int size)
|
|||||||
}
|
}
|
||||||
|
|
||||||
r = ffurl_read(c->inner, buf, size);
|
r = ffurl_read(c->inner, buf, size);
|
||||||
|
if (r == 0 && size>0) {
|
||||||
|
c->is_true_eof = 1;
|
||||||
|
av_assert0(c->end >= c->logical_pos);
|
||||||
|
}
|
||||||
if (r<=0)
|
if (r<=0)
|
||||||
return r;
|
return r;
|
||||||
c->inner_pos += r;
|
c->inner_pos += r;
|
||||||
@ -198,6 +203,8 @@ static int64_t cache_seek(URLContext *h, int64_t pos, int whence)
|
|||||||
if (ffurl_seek(c->inner, c->inner_pos, SEEK_SET) < 0)
|
if (ffurl_seek(c->inner, c->inner_pos, SEEK_SET) < 0)
|
||||||
av_log(h, AV_LOG_ERROR, "Inner protocol failed to seekback\n");
|
av_log(h, AV_LOG_ERROR, "Inner protocol failed to seekback\n");
|
||||||
}
|
}
|
||||||
|
if (pos > 0)
|
||||||
|
c->is_true_eof = 1;
|
||||||
c->end = FFMAX(c->end, pos);
|
c->end = FFMAX(c->end, pos);
|
||||||
return pos;
|
return pos;
|
||||||
}
|
}
|
||||||
@ -205,6 +212,9 @@ static int64_t cache_seek(URLContext *h, int64_t pos, int whence)
|
|||||||
if (whence == SEEK_CUR) {
|
if (whence == SEEK_CUR) {
|
||||||
whence = SEEK_SET;
|
whence = SEEK_SET;
|
||||||
pos += c->logical_pos;
|
pos += c->logical_pos;
|
||||||
|
} else if (whence == SEEK_END && c->is_true_eof) {
|
||||||
|
whence = SEEK_SET;
|
||||||
|
pos += c->end;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (whence == SEEK_SET && pos >= 0 && pos < c->end) {
|
if (whence == SEEK_SET && pos >= 0 && pos < c->end) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user