summaryrefslogtreecommitdiffstats
path: root/player/playloop.c
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2014-07-16 22:40:21 +0200
committerwm4 <wm4@nowhere>2014-07-16 23:25:56 +0200
commit1301a907617459237fb0071b4640ad53d0ae491f (patch)
treea3eb637ac01f1f11c53922ac9589e2e826869f2c /player/playloop.c
parent69a8f08f3e7cc0a9121c7fdb3499081fb2e34ddf (diff)
downloadmpv-1301a907617459237fb0071b4640ad53d0ae491f.tar.bz2
mpv-1301a907617459237fb0071b4640ad53d0ae491f.tar.xz
demux: add a demuxer thread
This adds a thread to the demuxer which reads packets asynchronously. It will do so until a configurable minimum packet queue size is reached. (See options.rst additions.) For now, the thread is disabled by default. There are some corner cases that have to be fixed, such as fixing cache behavior with webradios. Note that most interaction with the demuxer is still blocking, so if e.g. network dies, the player will still freeze. But this change will make it possible to remove most causes for freezing. Most of the new code in demux.c actually consists of weird caches to compensate for thread-safety issues (with the previously single-threaded design), or to avoid blocking by having to wait on the demuxer thread. Most of the changes in the player are due to the fact that we must not access the source stream directly. the demuxer thread already accesses it, and the stream stuff is not thread-safe. For timeline stuff (like ordered chapters), we enable the thread for the current segment only. We also clear its packet queue on seek, so that the remaining (unconsumed) readahead buffer doesn't waste memory. Keep in mind that insane subtitles (such as ASS typesetting muxed into mkv files) will practically disable the readahead, because the total queue size is considered when checking whether the minimum queue size was reached.
Diffstat (limited to 'player/playloop.c')
-rw-r--r--player/playloop.c24
1 files changed, 5 insertions, 19 deletions
diff --git a/player/playloop.c b/player/playloop.c
index 7e9b63995b..9ce4c39ed3 100644
--- a/player/playloop.c
+++ b/player/playloop.c
@@ -448,10 +448,9 @@ double get_current_pos_ratio(struct MPContext *mpctx, bool use_range)
if (len > 0 && !demuxer->ts_resets_possible) {
ans = MPCLAMP((pos - start) / len, 0, 1);
} else {
- struct stream *s = demuxer->stream;
int64_t size;
- if (stream_control(s, STREAM_CTRL_GET_SIZE, &size) > 0 && size > 0) {
- if (demuxer->filepos >= 0)
+ if (demux_stream_control(demuxer, STREAM_CTRL_GET_SIZE, &size) > 0) {
+ if (size > 0 && demuxer->filepos >= 0)
ans = MPCLAMP(demuxer->filepos / (double)size, 0, 1);
}
}
@@ -613,22 +612,13 @@ static bool handle_osd_redraw(struct MPContext *mpctx)
return true;
}
-static void handle_metadata_update(struct MPContext *mpctx)
-{
- if (mp_time_sec() > mpctx->last_metadata_update + 2) {
- if (demux_info_update(mpctx->demuxer))
- mp_notify(mpctx, MPV_EVENT_METADATA_UPDATE, NULL);
- mpctx->last_metadata_update = mp_time_sec();
- }
-}
-
static void handle_pause_on_low_cache(struct MPContext *mpctx)
{
struct MPOpts *opts = mpctx->opts;
- if (!mpctx->stream)
+ if (!mpctx->demuxer)
return;
int64_t fill = -1;
- stream_control(mpctx->stream, STREAM_CTRL_GET_CACHE_FILL, &fill);
+ demux_stream_control(mpctx->demuxer, STREAM_CTRL_GET_CACHE_FILL, &fill);
int cache_kb = fill > 0 ? (fill + 1023) / 1024 : -1;
bool idle = mp_get_cache_idle(mpctx);
if (mpctx->paused && mpctx->paused_for_cache) {
@@ -927,9 +917,7 @@ void run_playloop(struct MPContext *mpctx)
}
#endif
- // Add tracks that were added by the demuxer later (e.g. MPEG)
- if (!mpctx->timeline && mpctx->demuxer)
- add_demuxer_tracks(mpctx, mpctx->demuxer);
+ update_demuxer_properties(mpctx);
if (mpctx->timeline) {
double end = mpctx->timeline[mpctx->timeline_part + 1].start;
@@ -1271,8 +1259,6 @@ void run_playloop(struct MPContext *mpctx)
}
}
- handle_metadata_update(mpctx);
-
handle_pause_on_low_cache(mpctx);
handle_input_and_seek_coalesce(mpctx);