From f806e268c6c3a76f65b1282219e16fcdfb80a9b5 Mon Sep 17 00:00:00 2001 From: wm4 Date: Thu, 22 Aug 2013 18:23:33 +0200 Subject: stream: don't require streams to set s->pos in seek callback Instead, set s->pos depending on the success of the seek callback. --- stream/stream.c | 8 +++----- stream/stream_bluray.c | 1 - stream/stream_cdda.c | 5 ++--- stream/stream_dvd.c | 4 ++-- stream/stream_file.c | 5 +---- stream/stream_lavf.c | 3 +-- stream/stream_memory.c | 1 - stream/stream_smb.c | 3 +-- stream/stream_vcd.c | 3 +-- 9 files changed, 11 insertions(+), 22 deletions(-) diff --git a/stream/stream.c b/stream/stream.c index f735329cdd..3687dc75b0 100644 --- a/stream/stream.c +++ b/stream/stream.c @@ -550,6 +550,7 @@ static int stream_seek_unbuffered(stream_t *s, int64_t newpos) return 0; } } + s->pos = newpos; s->eof = 0; // EOF reset when seek succeeds. return -1; } @@ -558,7 +559,6 @@ static int stream_seek_unbuffered(stream_t *s, int64_t newpos) // Unlike stream_seek_unbuffered(), it still fills the local buffer. static int stream_seek_long(stream_t *s, int64_t pos) { - int64_t oldpos = s->pos; s->buf_pos = s->buf_len = 0; s->eof = 0; @@ -572,14 +572,12 @@ static int stream_seek_long(stream_t *s, int64_t pos) if (s->sector_size) newpos = (pos / s->sector_size) * s->sector_size; - mp_msg(MSGT_STREAM, MSGL_DBG3, "s->pos=%" PRIX64 " newpos=%" PRIX64 - " new_bufpos=%" PRIX64 " buflen=%X \n", - (int64_t)s->pos, (int64_t)newpos, (int64_t)pos, s->buf_len); + mp_msg(MSGT_STREAM, MSGL_DBG3, "Seek from %" PRId64 " to %" PRId64 + " (with offset %d)\n", s->pos, pos, (int)(pos - newpos)); if (!s->seek && (s->flags & MP_STREAM_FAST_SKIPPING) && pos >= s->pos) { // skipping is handled by generic code below } else if (stream_seek_unbuffered(s, newpos) >= 0) { - s->pos = oldpos; return 0; } diff --git a/stream/stream_bluray.c b/stream/stream_bluray.c index 3058792766..61e63151fb 100644 --- a/stream/stream_bluray.c +++ b/stream/stream_bluray.c @@ -92,7 +92,6 @@ static int bluray_stream_seek(stream_t *s, int64_t pos) if (p == -1) return 0; - s->pos = p; return 1; } diff --git a/stream/stream_cdda.c b/stream/stream_cdda.c index 02ba28d54b..26ad560cae 100644 --- a/stream/stream_cdda.c +++ b/stream/stream_cdda.c @@ -213,9 +213,8 @@ static int seek(stream_t *s, int64_t newpos) int seek_to_track = 0; int i; - s->pos = newpos; - sec = s->pos / CDIO_CD_FRAMESIZE_RAW; - if (s->pos < 0 || sec > p->end_sector) { + sec = newpos / CDIO_CD_FRAMESIZE_RAW; + if (newpos < 0 || sec > p->end_sector) { p->sector = p->end_sector + 1; return 0; } diff --git a/stream/stream_dvd.c b/stream/stream_dvd.c index 0372e6c3c0..340002fb46 100644 --- a/stream/stream_dvd.c +++ b/stream/stream_dvd.c @@ -354,13 +354,13 @@ static int fill_buffer(stream_t *s, char *buf, int len) pos = dvd_read_sector(s->priv, buf); if (pos < 0) return -1; + // dvd_read_sector() sometimes internally skips disk-level blocks s->pos = 2048*(pos - 1); return 2048; // full sector } static int seek(stream_t *s, int64_t newpos) { - s->pos=newpos; // real seek - dvd_seek(s->priv,s->pos/2048); + dvd_seek(s->priv,newpos/2048); return 1; } diff --git a/stream/stream_file.c b/stream/stream_file.c index a8dcf8fbdb..87e77d7bf3 100644 --- a/stream/stream_file.c +++ b/stream/stream_file.c @@ -63,10 +63,7 @@ static int write_buffer(stream_t *s, char *buffer, int len) static int seek(stream_t *s, int64_t newpos) { struct priv *p = s->priv; - s->pos = newpos; - if (lseek(p->fd, s->pos, SEEK_SET) < 0) - return 0; - return 1; + return lseek(p->fd, newpos, SEEK_SET) != (off_t)-1; } static int control(stream_t *s, int cmd, void *arg) diff --git a/stream/stream_lavf.c b/stream/stream_lavf.c index 0526d701f9..cedea2fb4b 100644 --- a/stream/stream_lavf.c +++ b/stream/stream_lavf.c @@ -60,8 +60,7 @@ static int seek(stream_t *s, int64_t newpos) AVIOContext *avio = s->priv; if (!avio) return -1; - s->pos = newpos; - if (avio_seek(avio, s->pos, SEEK_SET) < 0) { + if (avio_seek(avio, newpos, SEEK_SET) < 0) { return 0; } return 1; diff --git a/stream/stream_memory.c b/stream/stream_memory.c index 4d56fb4a3f..eaf74bb07e 100644 --- a/stream/stream_memory.c +++ b/stream/stream_memory.c @@ -36,7 +36,6 @@ static int fill_buffer(stream_t *s, char* buffer, int len) static int seek(stream_t *s, int64_t newpos) { - s->pos = newpos; return 1; } diff --git a/stream/stream_smb.c b/stream/stream_smb.c index 971c394051..d50258be97 100644 --- a/stream/stream_smb.c +++ b/stream/stream_smb.c @@ -76,8 +76,7 @@ static int control(stream_t *s, int cmd, void *arg) { static int seek(stream_t *s,int64_t newpos) { struct priv *p = s->priv; - s->pos = newpos; - if(smbc_lseek(p->fd,s->pos,SEEK_SET)<0) { + if(smbc_lseek(p->fd,newpos,SEEK_SET)<0) { return 0; } return 1; diff --git a/stream/stream_vcd.c b/stream/stream_vcd.c index f1c36545bf..6ec8453536 100644 --- a/stream/stream_vcd.c +++ b/stream/stream_vcd.c @@ -67,8 +67,7 @@ static int fill_buffer(stream_t *s, char* buffer, int max_len){ } static int seek(stream_t *s,int64_t newpos) { - s->pos = newpos; - vcd_set_msf(s->priv,s->pos/VCD_SECTOR_DATA); + vcd_set_msf(s->priv,newpos/VCD_SECTOR_DATA); return 1; } -- cgit v1.2.3