1
0
mirror of https://github.com/FFmpeg/FFmpeg.git synced 2024-12-23 12:43:46 +02:00

ftp: fix seeking beyond file size

adjust to ff* tools seek nature

Signed-off-by: Lukasz Marek <lukasz.m.luki@gmail.com>
This commit is contained in:
Lukasz Marek 2013-06-05 12:58:38 +02:00
parent 4d617715c9
commit eeedca4b7f

View File

@ -591,7 +591,7 @@ static int64_t ftp_seek(URLContext *h, int64_t pos, int whence)
{
FTPContext *s = h->priv_data;
int err;
int64_t new_pos;
int64_t new_pos, fake_pos;
av_dlog(h, "ftp protocol seek %"PRId64" %d\n", pos, whence);
@ -617,13 +617,12 @@ static int64_t ftp_seek(URLContext *h, int64_t pos, int whence)
return AVERROR(EIO);
new_pos = FFMAX(0, new_pos);
if (s->filesize >= 0)
new_pos = FFMIN(s->filesize, new_pos);
fake_pos = s->filesize != -1 ? FFMIN(new_pos, s->filesize) : new_pos;
if (new_pos != s->position) {
if (fake_pos != s->position) {
if ((err = ftp_abort(h)) < 0)
return err;
s->position = new_pos;
s->position = fake_pos;
}
return new_pos;
}
@ -652,8 +651,13 @@ static int ftp_read(URLContext *h, unsigned char *buf, int size)
if (read >= 0) {
s->position += read;
if (s->position >= s->filesize) {
if (ftp_abort(h) < 0)
/* server will terminate, but keep current position to avoid madness */
int64_t pos = s->position;
if (ftp_abort(h) < 0) {
s->position = pos;
return AVERROR(EIO);
}
s->position = pos;
}
}
if (read <= 0 && s->position < s->filesize && !h->is_streamed) {