diff options
Diffstat (limited to 'stream')
-rw-r--r-- | stream/cache.c | 41 | ||||
-rw-r--r-- | stream/discnav.h | 1 | ||||
-rw-r--r-- | stream/stream.h | 1 | ||||
-rw-r--r-- | stream/stream_bluray.c | 8 | ||||
-rw-r--r-- | stream/stream_dvdnav.c | 9 | ||||
-rw-r--r-- | stream/stream_file.c | 27 |
6 files changed, 39 insertions, 48 deletions
diff --git a/stream/cache.c b/stream/cache.c index 51d228a08c..0ffa3927be 100644 --- a/stream/cache.c +++ b/stream/cache.c @@ -18,7 +18,7 @@ // Time in seconds the main thread waits for the cache thread. On wakeups, the // code checks for user requested aborts and also prints warnings that the // cache is being slow. -#define CACHE_WAIT_TIME 0.5 +#define CACHE_WAIT_TIME 1.0 // The time the cache sleeps in idle mode. This controls how often the cache // retries reading from the stream after EOF has reached (in case the stream is @@ -32,9 +32,6 @@ // the cache is active. #define CACHE_UPDATE_CONTROLS_TIME 2.0 -// Time in seconds the cache prints a new message at all. -#define CACHE_NO_SPAM 5.0 - #include <stdio.h> #include <stdlib.h> @@ -81,7 +78,6 @@ struct priv { // Owned by the main thread stream_t *cache; // wrapper stream, used by demuxer etc. - double last_warn_time; // Owned by the cache thread stream_t *stream; // "real" stream, used to read from the source media @@ -118,8 +114,6 @@ struct priv { }; enum { - CACHE_INTERRUPTED = -1, - CACHE_CTRL_NONE = 0, CACHE_CTRL_QUIT = -1, CACHE_CTRL_PING = -2, @@ -131,31 +125,19 @@ enum { // Used by the main thread to wakeup the cache thread, and to wait for the // cache thread. The cache mutex has to be locked when calling this function. // *retry_time should be set to 0 on the first call. -// Returns CACHE_INTERRUPTED if the caller is supposed to abort. -static int cache_wakeup_and_wait(struct priv *s, double *retry_time) +static void cache_wakeup_and_wait(struct priv *s, double *retry_time) { - if (mp_cancel_test(s->cache->cancel)) - return CACHE_INTERRUPTED; - double start = mp_time_sec(); - - if (!s->last_warn_time || start - s->last_warn_time >= CACHE_NO_SPAM) { - // Print a "more severe" warning after waiting 1 second and no new data - if ((*retry_time) >= 1.0) { - MP_ERR(s, "Cache keeps not responding.\n"); - s->last_warn_time = start; - } else if (*retry_time > 0.1) { - MP_WARN(s, "Cache is not responding - slow/stuck network connection?\n"); - s->last_warn_time = start; - } + if (*retry_time >= CACHE_WAIT_TIME) { + MP_WARN(s, "Cache is not responding - slow/stuck network connection?\n"); + *retry_time = -1; // do not warn again for this call } pthread_cond_signal(&s->wakeup); mpthread_cond_timedwait_rel(&s->wakeup, &s->mutex, CACHE_WAIT_TIME); - *retry_time += mp_time_sec() - start; - - return 0; + if (*retry_time >= 0) + *retry_time += mp_time_sec() - start; } // Runs in the cache thread @@ -226,6 +208,9 @@ static bool cache_fill(struct priv *s) goto done; } + if (mp_cancel_test(s->cache->cancel)) + goto done; + // number of buffer bytes which should be preserved in backwards direction int64_t back = MPCLAMP(read - s->min_filepos, 0, s->back_size); @@ -511,8 +496,9 @@ static int cache_fill_buffer(struct stream *cache, char *buffer, int max_len) if (s->eof && s->read_filepos >= s->max_filepos && s->reads >= retry) break; s->idle = false; - if (cache_wakeup_and_wait(s, &retry_time) == CACHE_INTERRUPTED) + if (mp_cancel_test(s->cache->cancel)) break; + cache_wakeup_and_wait(s, &retry_time); } } @@ -570,11 +556,12 @@ static int cache_control(stream_t *cache, int cmd, void *arg) s->control_arg = arg; double retry = 0; while (s->control != CACHE_CTRL_NONE) { - if (cache_wakeup_and_wait(s, &retry) == CACHE_INTERRUPTED) { + if (mp_cancel_test(s->cache->cancel)) { s->eof = 1; r = STREAM_UNSUPPORTED; goto done; } + cache_wakeup_and_wait(s, &retry); } r = s->control_res; if (s->control_flush) { diff --git a/stream/discnav.h b/stream/discnav.h index e6a063f8e1..b40998d3cb 100644 --- a/stream/discnav.h +++ b/stream/discnav.h @@ -80,6 +80,7 @@ struct mp_nav_cmd { int x, y; } mouse_pos; } u; + bool mouse_on_button; }; #endif /* MPLAYER_STREAM_DVDNAV_H */ diff --git a/stream/stream.h b/stream/stream.h index 387006cb8f..7b4751450c 100644 --- a/stream/stream.h +++ b/stream/stream.h @@ -31,6 +31,7 @@ enum streamtype { STREAMTYPE_GENERIC = 0, STREAMTYPE_FILE, + STREAMTYPE_DIR, STREAMTYPE_DVB, STREAMTYPE_DVD, STREAMTYPE_BLURAY, diff --git a/stream/stream_bluray.c b/stream/stream_bluray.c index 1718531ecc..adc2e5828b 100644 --- a/stream/stream_bluray.c +++ b/stream/stream_bluray.c @@ -455,7 +455,9 @@ static void handle_nav_command(stream_t *s, struct mp_nav_cmd *ev) bd_vk_key_e key = translate_nav_menu_action(action); if (key != BD_VK_NONE) { if (key == BD_VK_MOUSE_ACTIVATE) - bd_mouse_select(priv->bd, pts, priv->mousex, priv->mousey); + ev->mouse_on_button = bd_mouse_select(priv->bd, pts, + priv->mousex, + priv->mousey); bd_user_input(priv->bd, pts, key); } else if (strcmp(action, "menu") == 0) { if (priv->popup_enabled) @@ -467,7 +469,9 @@ static void handle_nav_command(stream_t *s, struct mp_nav_cmd *ev) } case MP_NAV_CMD_MOUSE_POS: priv->mousex = ev->u.mouse_pos.x; priv->mousey = ev->u.mouse_pos.y; - bd_mouse_select(priv->bd, mp_time_us(), priv->mousex, priv->mousey); + ev->mouse_on_button = bd_mouse_select(priv->bd, mp_time_us(), + priv->mousex, + priv->mousey); break; case MP_NAV_CMD_SKIP_STILL: bd_read_skip_still(priv->bd); diff --git a/stream/stream_dvdnav.c b/stream/stream_dvdnav.c index b94187b3ff..095ba98ddf 100644 --- a/stream/stream_dvdnav.c +++ b/stream/stream_dvdnav.c @@ -202,18 +202,19 @@ static void handle_menu_input(stream_t *stream, const char *cmd) } } -static void handle_mouse_pos(stream_t *stream, int x, int y) +static dvdnav_status_t handle_mouse_pos(stream_t *stream, int x, int y) { struct priv *priv = stream->priv; dvdnav_t *nav = priv->dvdnav; pci_t *pci = dvdnav_get_current_nav_pci(nav); if (!pci) - return; + return DVDNAV_STATUS_ERR; - dvdnav_mouse_select(nav, pci, x, y); + dvdnav_status_t status = dvdnav_mouse_select(nav, pci, x, y); priv->mousex = x; priv->mousey = y; + return status; } /** @@ -305,7 +306,7 @@ static void handle_cmd(stream_t *s, struct mp_nav_cmd *ev) handle_menu_input(s, ev->u.menu.action); break; case MP_NAV_CMD_MOUSE_POS: - handle_mouse_pos(s, ev->u.mouse_pos.x, ev->u.mouse_pos.y); + ev->mouse_on_button = handle_mouse_pos(s, ev->u.mouse_pos.x, ev->u.mouse_pos.y); break; } diff --git a/stream/stream_file.c b/stream/stream_file.c index 01e983fa31..d0da8629bc 100644 --- a/stream/stream_file.c +++ b/stream/stream_file.c @@ -155,12 +155,11 @@ char *mp_file_get_path(void *talloc_ctx, bstr url) } #if HAVE_BSD_FSTATFS -static bool check_stream_network(stream_t *stream) +static bool check_stream_network(int fd) { struct statfs fs; const char *stypes[] = { "afpfs", "nfs", "smbfs", "webdav", NULL }; - struct priv *priv = stream->priv; - if (fstatfs(priv->fd, &fs) == 0) + if (fstatfs(fd, &fs) == 0) for (int i=0; stypes[i]; i++) if (strcmp(stypes[i], fs.f_fstypename) == 0) return true; @@ -168,7 +167,7 @@ static bool check_stream_network(stream_t *stream) } #elif HAVE_LINUX_FSTATFS -static bool check_stream_network(stream_t *stream) +static bool check_stream_network(int fd) { struct statfs fs; const uint32_t stypes[] = { @@ -181,8 +180,7 @@ static bool check_stream_network(stream_t *stream) 0xBEEFDEAD /*SNFS*/, 0xBACBACBC /*VMHGFS*/, 0x7461636f /*OCFS2*/, 0 }; - struct priv *priv = stream->priv; - if (fstatfs(priv->fd, &fs) == 0) { + if (fstatfs(fd, &fs) == 0) { for (int i=0; stypes[i]; i++) { if (stypes[i] == fs.f_type) return true; @@ -192,7 +190,7 @@ static bool check_stream_network(stream_t *stream) } #elif defined(_WIN32) -static bool check_stream_network(stream_t *stream) +static bool check_stream_network(int fd) { NTSTATUS (NTAPI *pNtQueryVolumeInformationFile)(HANDLE, PIO_STATUS_BLOCK, PVOID, ULONG, FS_INFORMATION_CLASS) = NULL; @@ -208,8 +206,7 @@ static bool check_stream_network(stream_t *stream) if (!pNtQueryVolumeInformationFile) return false; - struct priv *priv = stream->priv; - HANDLE h = (HANDLE)_get_osfhandle(priv->fd); + HANDLE h = (HANDLE)_get_osfhandle(fd); if (h == INVALID_HANDLE_VALUE) return false; @@ -224,7 +221,7 @@ static bool check_stream_network(stream_t *stream) (info.Characteristics & FILE_REMOTE_DEVICE); } #else -static bool check_stream_network(stream_t *stream) +static bool check_stream_network(int fd) { return false; } @@ -238,6 +235,7 @@ static int open_f(stream_t *stream) .fd = -1 }; stream->priv = priv; + stream->type = STREAMTYPE_FILE; bool write = stream->mode == STREAM_WRITE; int m = O_CLOEXEC | (write ? O_RDWR | O_CREAT | O_TRUNC : O_RDONLY); @@ -278,9 +276,9 @@ static int open_f(stream_t *stream) struct stat st; if (fstat(fd, &st) == 0) { if (S_ISDIR(st.st_mode)) { - MP_ERR(stream, "File is a directory: '%s'\n", filename); - close(fd); - return STREAM_ERROR; + stream->type = STREAMTYPE_DIR; + stream->allow_caching = false; + MP_INFO(stream, "This is a directory - adding to playlist.\n"); } #ifndef __MINGW32__ if (S_ISREG(st.st_mode)) { @@ -302,7 +300,6 @@ static int open_f(stream_t *stream) stream->seekable = true; } - stream->type = STREAMTYPE_FILE; stream->fast_skip = true; stream->fill_buffer = fill_buffer; stream->write_buffer = write_buffer; @@ -310,7 +307,7 @@ static int open_f(stream_t *stream) stream->read_chunk = 64 * 1024; stream->close = s_close; - if (check_stream_network(stream)) + if (check_stream_network(fd)) stream->streaming = true; return STREAM_OK; |