summaryrefslogtreecommitdiffstats
path: root/demux
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2014-12-04 21:06:18 +0100
committerwm4 <wm4@nowhere>2014-12-04 22:42:07 +0100
commitc3d6f4b63b37994a14099e0e88e8ae87121cb7bf (patch)
treef5a9b1460132d2a6d3de28c9ed6e1beacc55cbb4 /demux
parent6e7942af5062570694e08ee868fb9ee6004f102f (diff)
downloadmpv-c3d6f4b63b37994a14099e0e88e8ae87121cb7bf.tar.bz2
mpv-c3d6f4b63b37994a14099e0e88e8ae87121cb7bf.tar.xz
dvd, bd: don't unnecessarily block on demuxer/stream all the time
This was completely breaking any low-level caching. Change it so that at least demuxer caching will work. Do this by using the metadata cache mechanism to funnel through the menu commands. For some incomprehensible reason, I had to reorder the events (which affects their delivery priority), or they would be ignored. Probably some crap about the event state being cleared before it could be delivered. I don't give a shit. All this code sucks. It would probably be better to let discnav.c access the menu event "queue" directly, and to synchronize access with a mutex, instead of going through all the caching layers, making things complicated and slow.
Diffstat (limited to 'demux')
-rw-r--r--demux/demux.c17
-rw-r--r--demux/demux.h1
-rw-r--r--demux/demux_disc.c3
3 files changed, 21 insertions, 0 deletions
diff --git a/demux/demux.c b/demux/demux.c
index 95d35034eb..af7277941e 100644
--- a/demux/demux.c
+++ b/demux/demux.c
@@ -125,6 +125,7 @@ struct demux_internal {
// Cached state.
bool force_cache_update;
double time_length;
+ struct mp_nav_event *nav_event;
struct mp_tags *stream_metadata;
int64_t stream_size;
int64_t stream_cache_size;
@@ -229,6 +230,7 @@ void free_demuxer(demuxer_t *demuxer)
ds_flush(demuxer->streams[n]->ds);
pthread_mutex_destroy(&in->lock);
pthread_cond_destroy(&in->wakeup);
+ talloc_free(in->nav_event);
talloc_free(demuxer);
}
@@ -1135,10 +1137,17 @@ static void update_cache(struct demux_internal *in)
int64_t stream_cache_size = -1;
int64_t stream_cache_fill = -1;
int stream_cache_idle = -1;
+ struct mp_nav_event *nav_event = NULL;
+
+ pthread_mutex_lock(&in->lock);
+ bool need_nav_event = !in->nav_event;;
+ pthread_mutex_unlock(&in->lock);
if (demuxer->desc->control) {
demuxer->desc->control(demuxer, DEMUXER_CTRL_GET_TIME_LENGTH,
&time_length);
+ if (need_nav_event)
+ demuxer->desc->control(demuxer, DEMUXER_CTRL_GET_NAV_EVENT, &nav_event);
}
stream_control(stream, STREAM_CTRL_GET_METADATA, &stream_metadata);
@@ -1158,6 +1167,7 @@ static void update_cache(struct demux_internal *in)
in->stream_metadata = talloc_steal(in, stream_metadata);
in->d_buffer->events |= DEMUX_EVENT_METADATA;
}
+ in->nav_event = nav_event ? nav_event : in->nav_event;
pthread_mutex_unlock(&in->lock);
}
@@ -1248,6 +1258,13 @@ static int cached_demux_control(struct demux_internal *in, int cmd, void *arg)
r->ts_duration = 0;
return DEMUXER_CTRL_OK;
}
+ case DEMUXER_CTRL_GET_NAV_EVENT:
+ if (!in->nav_event)
+ return DEMUXER_CTRL_NOTIMPL;
+ *(struct mp_nav_event **)arg = in->nav_event;
+ in->nav_event = NULL;
+ return DEMUXER_CTRL_OK;
+
}
return DEMUXER_CTRL_DONTKNOW;
}
diff --git a/demux/demux.h b/demux/demux.h
index 7892718027..39bfee7fea 100644
--- a/demux/demux.h
+++ b/demux/demux.h
@@ -55,6 +55,7 @@ enum demux_ctrl {
DEMUXER_CTRL_IDENTIFY_PROGRAM,
DEMUXER_CTRL_STREAM_CTRL,
DEMUXER_CTRL_GET_READER_STATE,
+ DEMUXER_CTRL_GET_NAV_EVENT,
};
struct demux_ctrl_reader_state {
diff --git a/demux/demux_disc.c b/demux/demux_disc.c
index e92198f0af..751b81281f 100644
--- a/demux/demux_disc.c
+++ b/demux/demux_disc.c
@@ -349,6 +349,9 @@ static int d_control(demuxer_t *demuxer, int cmd, void *arg)
case DEMUXER_CTRL_SWITCHED_TRACKS:
reselect_streams(demuxer);
return DEMUXER_CTRL_OK;
+ case DEMUXER_CTRL_GET_NAV_EVENT:
+ return stream_control(demuxer->stream, STREAM_CTRL_GET_NAV_EVENT, arg)
+ == STREAM_OK ? DEMUXER_CTRL_OK : DEMUXER_CTRL_DONTKNOW;
}
return demux_control(p->slave, cmd, arg);
}