summaryrefslogtreecommitdiffstats
path: root/stream/stream.c
diff options
context:
space:
mode:
authorUoti Urpala <uau@mplayer2.org>2011-05-02 00:46:03 +0300
committerUoti Urpala <uau@mplayer2.org>2011-05-02 00:46:03 +0300
commit7e65428712beacd416dc3410c52f22ebfd3b4c53 (patch)
tree79bb2f4388be7031b5505c7745e1a59aff6cff56 /stream/stream.c
parent5c4b059f1608f6d6a981b7d81a14f1c46e40ba52 (diff)
parentd0376729d171a6c0b4cc15928c168f68adefbaa6 (diff)
downloadmpv-7e65428712beacd416dc3410c52f22ebfd3b4c53.tar.bz2
mpv-7e65428712beacd416dc3410c52f22ebfd3b4c53.tar.xz
Merge branch 'mplayer1_changes'
Diffstat (limited to 'stream/stream.c')
-rw-r--r--stream/stream.c24
1 files changed, 23 insertions, 1 deletions
diff --git a/stream/stream.c b/stream/stream.c
index 86dd61389e..9a3f25f8ab 100644
--- a/stream/stream.c
+++ b/stream/stream.c
@@ -28,6 +28,7 @@
#endif
#include <fcntl.h>
#include <strings.h>
+#include <assert.h>
#include "talloc.h"
@@ -279,6 +280,7 @@ void stream_capture_do(stream_t *s)
int stream_read_internal(stream_t *s, void *buf, int len)
{
+ int orig_len = len;
// we will retry even if we already reached EOF previously.
switch(s->type){
case STREAMTYPE_STREAM:
@@ -300,7 +302,26 @@ int stream_read_internal(stream_t *s, void *buf, int len)
default:
len= s->fill_buffer ? s->fill_buffer(s, buf, len) : 0;
}
- if(len<=0){ s->eof=1; return 0; }
+ if(len<=0){
+ // dvdnav has some horrible hacks to "suspend" reads,
+ // we need to skip this code or seeks will hang.
+ if (!s->eof && s->type != STREAMTYPE_DVDNAV) {
+ // just in case this is an error e.g. due to network
+ // timeout reset and retry
+ // Seeking is used as a hack to make network streams
+ // reopen the connection, ideally they would implement
+ // e.g. a STREAM_CTRL_RECONNECT to do this
+ off_t pos = s->pos;
+ s->eof=1;
+ stream_reset(s);
+ stream_seek_internal(s, pos);
+ // make sure EOF is set to ensure no endless loops
+ s->eof=1;
+ return stream_read_internal(s, buf, orig_len);
+ }
+ s->eof=1;
+ return 0;
+ }
// When reading succeeded we are obviously not at eof.
// This e.g. avoids issues with eof getting stuck when lavf seeks in MPEG-TS
s->eof=0;
@@ -328,6 +349,7 @@ int stream_write_buffer(stream_t *s, unsigned char *buf, int len) {
if(rd < 0)
return -1;
s->pos += rd;
+ assert(rd == len && "stream_write_buffer(): unexpected short write");
return rd;
}