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.
This commit is contained in:
wm4 2013-07-07 20:49:15 +02:00
parent dbf2a6f7d0
commit c4f83ac6e9
6 changed files with 27 additions and 50 deletions

View File

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

View File

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

View File

@ -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://");

View File

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

View File

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

View File

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