1
0
mirror of https://github.com/mpv-player/mpv synced 2024-12-22 06:42:03 +00:00

stream: don't require streams to set s->pos in seek callback

Instead, set s->pos depending on the success of the seek callback.
This commit is contained in:
wm4 2013-08-22 18:23:33 +02:00
parent a790f2133b
commit f806e268c6
9 changed files with 11 additions and 22 deletions

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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)

View File

@ -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;

View File

@ -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;
}

View File

@ -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;

View File

@ -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;
}