summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2013-07-07 20:49:15 +0200
committerwm4 <wm4@nowhere>2013-07-07 21:10:44 +0200
commitc4f83ac6e93ec9ff2fe97b3f5c6fccc9751fa3e2 (patch)
tree31ae282e119a8de906997afb6ab4d6b5f3ea264d
parentdbf2a6f7d0a9ae09bac024cf3ad4e7b27d303cb6 (diff)
downloadmpv-c4f83ac6e93ec9ff2fe97b3f5c6fccc9751fa3e2.tar.bz2
mpv-c4f83ac6e93ec9ff2fe97b3f5c6fccc9751fa3e2.tar.xz
stream: remove weird STREAMTYPE_STREAM special handling
This was an old leftover from an earlier cleanup (which happened in 2003), and which used "special" stuff for streams that could be only forward-seeked. Also, don't add mode flags to s->flags; they're supposed to be in s->mode instead.
-rw-r--r--stream/stream.c58
-rw-r--r--stream/stream.h1
-rw-r--r--stream/stream_bluray.c2
-rw-r--r--stream/stream_dvd.c2
-rw-r--r--stream/stream_file.c9
-rw-r--r--stream/stream_lavf.c5
6 files changed, 27 insertions, 50 deletions
diff --git a/stream/stream.c b/stream/stream.c
index 7f761f5c18..8aa3a4718e 100644
--- a/stream/stream.c
+++ b/stream/stream.c
@@ -160,7 +160,8 @@ static stream_t *open_stream_plugin(const stream_info_t *sinfo,
s = new_stream(0);
s->opts = options;
s->url = strdup(filename);
- s->flags |= mode;
+ s->flags = 0;
+ s->mode = mode;
*ret = sinfo->open(s, mode, arg, file_format);
if ((*ret) != STREAM_OK) {
free(s->url);
@@ -340,16 +341,12 @@ static int stream_read_unbuffered(stream_t *s, void *buf, int len)
int orig_len = len;
s->buf_pos = s->buf_len = 0;
// we will retry even if we already reached EOF previously.
- switch (s->type) {
- case STREAMTYPE_STREAM:
- if (s->fill_buffer)
- len = s->fill_buffer(s, buf, len);
- else
- len = read(s->fd, buf, len);
- break;
-
- default:
- len = s->fill_buffer ? s->fill_buffer(s, buf, len) : 0;
+ if (s->fill_buffer) {
+ len = s->fill_buffer(s, buf, len);
+ } else if (s->fd >= 0) {
+ len = read(s->fd, buf, len);
+ } else {
+ len = 0;
}
if (len < 0)
len = 0;
@@ -474,33 +471,18 @@ int stream_write_buffer(stream_t *s, unsigned char *buf, int len)
static int stream_seek_unbuffered(stream_t *s, int64_t newpos)
{
if (newpos == 0 || newpos != s->pos) {
- switch (s->type) {
- case STREAMTYPE_STREAM:
- // Some streaming protocol allow to seek backward and forward
- // A function call that return -1 can tell that the protocol
- // doesn't support seeking.
- if (s->seek) {
- if (!s->seek(s, newpos)) {
- mp_tmsg(MSGT_STREAM, MSGL_ERR, "Seek failed\n");
- return 0;
- }
- break;
- }
- if (newpos < s->pos) {
- mp_tmsg(MSGT_STREAM, MSGL_INFO,
- "Cannot seek backward in linear streams!\n");
- return 1;
- }
- break;
- default:
- // This should at the beginning as soon as all streams are converted
- if (!s->seek)
- return 0;
- // Now seek
- if (!s->seek(s, newpos)) {
- mp_tmsg(MSGT_STREAM, MSGL_ERR, "Seek failed\n");
- return 0;
- }
+ if (!s->seek || !(s->flags & MP_STREAM_SEEK)) {
+ mp_tmsg(MSGT_STREAM, MSGL_ERR, "Can not seek in this stream\n");
+ return 0;
+ }
+ if (newpos < s->pos && !(s->flags & MP_STREAM_SEEK_BW)) {
+ mp_tmsg(MSGT_STREAM, MSGL_ERR,
+ "Cannot seek backward in linear streams!\n");
+ return 1;
+ }
+ if (s->seek(s, newpos) <= 0) {
+ mp_tmsg(MSGT_STREAM, MSGL_ERR, "Seek failed\n");
+ return 0;
}
}
s->eof = 0; // EOF reset when seek succeeds.
diff --git a/stream/stream.h b/stream/stream.h
index 98de2f4814..149618ccd6 100644
--- a/stream/stream.h
+++ b/stream/stream.h
@@ -37,7 +37,6 @@
#define STREAMTYPE_DUMMY -1 // for placeholders, when the actual reading is handled in the demuxer
#define STREAMTYPE_FILE 0 // read from seekable file
#define STREAMTYPE_VCD 1 // raw mode-2 CDROM reading, 2324 bytes/sector
-#define STREAMTYPE_STREAM 2 // same as FILE but no seeking (for net/stdin)
#define STREAMTYPE_DVD 3 // libdvdread
#define STREAMTYPE_MEMORY 4
#define STREAMTYPE_PLAYLIST 6 // FIXME!!! same as STREAMTYPE_FILE now
diff --git a/stream/stream_bluray.c b/stream/stream_bluray.c
index 06d1e88b99..64d1856873 100644
--- a/stream/stream_bluray.c
+++ b/stream/stream_bluray.c
@@ -407,7 +407,7 @@ err_no_info:
s->end_pos = title_size;
s->sector_size = BLURAY_SECTOR_SIZE;
- s->flags = mode | MP_STREAM_SEEK;
+ s->flags = MP_STREAM_SEEK;
s->priv = b;
s->type = STREAMTYPE_BLURAY;
s->url = strdup("br://");
diff --git a/stream/stream_dvd.c b/stream/stream_dvd.c
index 23d933e344..bf9cb9d4c7 100644
--- a/stream/stream_dvd.c
+++ b/stream/stream_dvd.c
@@ -1037,7 +1037,7 @@ static int open_s(stream_t *stream,int mode, void* opts, int* file_format) {
// return NULL;
stream->type = STREAMTYPE_DVD;
stream->sector_size = 2048;
- stream->flags = STREAM_READ | MP_STREAM_SEEK;
+ stream->flags = MP_STREAM_SEEK;
stream->fill_buffer = fill_buffer;
stream->seek = seek;
stream->control = control;
diff --git a/stream/stream_file.c b/stream/stream_file.c
index 5797aef59f..924eb31dad 100644
--- a/stream/stream_file.c
+++ b/stream/stream_file.c
@@ -191,14 +191,13 @@ static int open_f(stream_t *stream,int mode, void* opts, int* file_format) {
if(f==0)
len = -1;
#endif
- if(len == -1) {
- if(mode == STREAM_READ) stream->seek = seek_forward;
- stream->type = STREAMTYPE_STREAM; // Must be move to STREAMTYPE_FILE
- stream->flags |= MP_STREAM_SEEK_FW;
+ stream->type = STREAMTYPE_FILE;
+ if(len == -1 && mode == STREAM_READ) {
+ stream->seek = seek_forward;
+ stream->flags = MP_STREAM_SEEK_FW;
} else if(len >= 0) {
stream->seek = seek;
stream->end_pos = len;
- stream->type = STREAMTYPE_FILE;
}
mp_msg(MSGT_OPEN,MSGL_V,"[file] File size is %"PRId64" bytes\n", (int64_t)len);
diff --git a/stream/stream_lavf.c b/stream/stream_lavf.c
index 3223bc3eaa..9a5249db54 100644
--- a/stream/stream_lavf.c
+++ b/stream/stream_lavf.c
@@ -162,7 +162,6 @@ static int open_f(stream_t *stream, int mode, void *opts, int *file_format)
/* This is handled as a special demuxer, without a separate
* stream layer. demux_lavf will do all the real work.
*/
- stream->type = STREAMTYPE_STREAM;
stream->seek = NULL;
*file_format = DEMUXER_TYPE_LAVF;
stream->lavf_type = "rtsp";
@@ -226,10 +225,8 @@ static int open_f(stream_t *stream, int mode, void *opts, int *file_format)
stream->end_pos = size;
stream->type = STREAMTYPE_FILE;
stream->seek = seek;
- if (!avio->seekable) {
- stream->type = STREAMTYPE_STREAM;
+ if (!avio->seekable)
stream->seek = NULL;
- }
stream->fill_buffer = fill_buffer;
stream->write_buffer = write_buffer;
stream->control = control;