From 5de29b860b25bb4ba8b1e02d9b3aee7a81009be0 Mon Sep 17 00:00:00 2001 From: wm4 Date: Fri, 6 Feb 2015 21:32:44 +0100 Subject: 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!). --- stream/rar.c | 3 +-- stream/stream.c | 18 ++---------------- stream/stream.h | 3 +-- stream/stream_bluray.c | 4 +++- stream/stream_cdda.c | 6 ++++-- stream/stream_dvd.c | 5 ++++- stream/stream_rar.c | 12 ++++++++++-- 7 files changed, 25 insertions(+), 26 deletions(-) (limited to 'stream') diff --git a/stream/rar.c b/stream/rar.c index 7fae5e35ac..9d8b64717a 100644 --- a/stream/rar.c +++ b/stream/rar.c @@ -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; } diff --git a/stream/stream.c b/stream/stream.c index d4f0fbc320..fd545da7e7 100644 --- a/stream/stream.c +++ b/stream/stream.c @@ -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) diff --git a/stream/stream.h b/stream/stream.h index 1dd00edb91..b824aaf356 100644 --- a/stream/stream.h +++ b/stream/stream.h @@ -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 diff --git a/stream/stream_bluray.c b/stream/stream_bluray.c index ebbdf63a3e..04efed6e51 100644 --- a/stream/stream_bluray.c +++ b/stream/stream_bluray.c @@ -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"; diff --git a/stream/stream_cdda.c b/stream/stream_cdda.c index a75ee3ae40..13ec14644b 100644 --- a/stream/stream_cdda.c +++ b/stream/stream_cdda.c @@ -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; diff --git a/stream/stream_dvd.c b/stream/stream_dvd.c index 5be70b2d1d..0906796986 100644 --- a/stream/stream_dvd.c +++ b/stream/stream_dvd.c @@ -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; diff --git a/stream/stream_rar.c b/stream/stream_rar.c index 733ea3f36c..58e6232092 100644 --- a/stream/stream_rar.c +++ b/stream/stream_rar.c @@ -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); -- cgit v1.2.3