stream: get rid of remaining uses of the end_pos field

Most things stopped using this field for better support of growing
files. Go through the trouble to repalce the remaining uses, so it can
be removed.

Also move the "streaming" field; saves 4 bytes (wow!).
This commit is contained in:
wm4 2015-02-06 21:32:44 +01:00
parent 347cf97231
commit 5de29b860b
7 changed files with 25 additions and 26 deletions

View File

@ -257,8 +257,7 @@ exit:
/* We stop on the first non empty file if we cannot seek */
if (current) {
bool can_seek = s->end_pos > 0;
if (!can_seek && current->size > 0)
if (!s->seekable && current->size > 0)
return -1;
}

View File

@ -676,7 +676,7 @@ bool stream_seek(stream_t *s, int64_t pos)
}
if (s->mode == STREAM_WRITE)
return s->seekable && s->seek(s, pos));
return s->seekable && s->seek(s, pos);
int64_t newpos = pos;
if (s->sector_size)
@ -717,21 +717,7 @@ bool stream_skip(stream_t *s, int64_t len)
int stream_control(stream_t *s, int cmd, void *arg)
{
if (!s->control)
return STREAM_UNSUPPORTED;
int r = s->control(s, cmd, arg);
if (r == STREAM_UNSUPPORTED) {
// Fallbacks
switch (cmd) {
case STREAM_CTRL_GET_SIZE:
if (s->end_pos > 0) {
*(int64_t *)arg = s->end_pos;
return STREAM_OK;
}
break;
}
}
return r;
return s->control ? s->control(s, cmd, arg) : STREAM_UNSUPPORTED;
}
void free_stream(stream_t *s)

View File

@ -185,16 +185,15 @@ typedef struct stream {
int read_chunk; // maximum amount of data to read at once to limit latency
unsigned int buf_pos, buf_len;
int64_t pos;
uint64_t end_pos; // static size; use STREAM_CTRL_GET_SIZE instead
int eof;
int mode; //STREAM_READ or STREAM_WRITE
bool streaming; // known to be a network stream if true
void *priv; // used for DVD, TV, RTSP etc
char *url; // filename/url (possibly including protocol prefix)
char *path; // filename (url without protocol prefix)
char *mime_type; // when HTTP streaming is used
char *demuxer; // request demuxer to be used
char *lavf_type; // name of expected demuxer type for lavf
bool streaming : 1; // known to be a network stream if true
bool seekable : 1; // presence of general byte seeking support
bool fast_skip : 1; // consider stream fast enough to fw-seek by skipping
bool safe_origin : 1; // used for playlists that can be opened safely

View File

@ -600,6 +600,9 @@ static int bluray_stream_control(stream_t *s, int cmd, void *arg)
fill_next_event(s, ev);
return STREAM_OK;
}
case STREAM_CTRL_GET_SIZE:
*(int64_t *)arg = bd_get_title_size(b->bd);
return STREAM_OK;
default:
break;
}
@ -794,7 +797,6 @@ static int bluray_stream_open(stream_t *s)
s->close = bluray_stream_close;
s->control = bluray_stream_control;
s->type = STREAMTYPE_BLURAY;
s->end_pos = bd_get_title_size(bd);
s->sector_size = BLURAY_SECTOR_SIZE;
s->priv = b;
s->demuxer = "+disc";

View File

@ -266,6 +266,10 @@ static int control(stream_t *stream, int cmd, void *arg)
*(double *)arg = pos / (44100.0 * 2 * 2);
return STREAM_OK;
}
case STREAM_CTRL_GET_SIZE:
*(int64_t *)arg =
(p->end_sector + 1 - p->start_sector) * CDIO_CD_FRAMESIZE_RAW;
return STREAM_OK;
}
return STREAM_UNSUPPORTED;
}
@ -373,8 +377,6 @@ static int open_cdda(stream_t *st)
priv->sector = priv->start_sector;
st->priv = priv;
st->end_pos =
(priv->end_sector + 1 - priv->start_sector) * CDIO_CD_FRAMESIZE_RAW;
st->sector_size = CDIO_CD_FRAMESIZE_RAW;
st->fill_buffer = fill_buffer;

View File

@ -649,6 +649,10 @@ static int control(stream_t *stream,int cmd,void* arg)
*(char**)arg = talloc_strdup(NULL, buffer);
return STREAM_OK;
}
case STREAM_CTRL_GET_SIZE:
*(int64_t *)arg =
(d->cur_pgc->cell_playback[d->last_cell-1].last_sector)*2048LL;
return STREAM_OK;
}
return STREAM_UNSUPPORTED;
}
@ -917,7 +921,6 @@ static int open_s(stream_t *stream)
stream->fill_buffer = fill_buffer;
stream->control = control;
stream->close = stream_dvd_close;
stream->end_pos = (int64_t)(d->cur_pgc->cell_playback[d->last_cell-1].last_sector)*2048;
MP_VERBOSE(stream, "DVD start=%d end=%d \n",d->cur_pack,d->cur_pgc->cell_playback[d->last_cell-1].last_sector);
stream->priv = (void*)d;
return STREAM_OK;

View File

@ -82,6 +82,9 @@ static int rar_entry_control(stream_t *s, int cmd, void *arg)
case STREAM_CTRL_GET_BASE_FILENAME:
*(char **)arg = talloc_strdup(NULL, rar_file->s->url);
return STREAM_OK;
case STREAM_CTRL_GET_SIZE:
*(int64_t *)arg = rar_file->size;
return STREAM_OK;
}
return STREAM_UNSUPPORTED;
}
@ -131,7 +134,6 @@ static int rar_entry_open(stream_t *stream)
RarSeek(file, 0);
stream->priv = file;
stream->end_pos = file->size;
stream->fill_buffer = rar_entry_fill_buffer;
stream->seek = rar_entry_seek;
stream->seekable = true;
@ -159,6 +161,12 @@ static void rar_filter_close(stream_t *s)
free_stream(m);
}
static int rar_filter_control(stream_t *s, int cmd, void *arg)
{
struct stream *m = s->priv;
return stream_control(m, cmd, arg);
}
static int rar_filter_open(stream_t *stream)
{
struct stream *rar = stream->source;
@ -186,11 +194,11 @@ static int rar_filter_open(stream_t *stream)
struct stream *m = open_memory_stream(pl, strlen(pl));
stream->priv = m;
stream->end_pos = m->end_pos;
stream->fill_buffer = rar_filter_fill_buffer;
stream->seek = rar_filter_seek;
stream->seekable = true;
stream->close = rar_filter_close;
stream->control = rar_filter_control;
stream->safe_origin = true;
talloc_free(tmp);