From 4e25feda0d5e084761a9935de7c1e592e86de94f Mon Sep 17 00:00:00 2001 From: wm4 Date: Tue, 10 Jan 2017 14:03:41 +0100 Subject: player: change aspects of cover art handling Cover art handling is a disgusting hack that causes a mess in all components. And this will stay this way. This is the Xth time I've changed cover art handling, and that will probably also continue. But change the code such that cover art is injected into the demux packet stream, instead of having an explicit special case it in the decoder glue code. (This is somewhat more similar to the cover art hack in libavformat.) To avoid that the over art picture is decoded again on each seek, we need some additional "caching" in player/video.c. Decoding it after each seek would work as well, but since cover art pictures can be pretty huge, it's probably ok to invest some lines of code into caching it. One weird thing is that the cover art packet will remain queued after seeks, but that is probably not an issue. In exchange, we can drop the dec_video.c code, which is pretty convenient for one of the following commits. This code duplicates a bunch of lower-level decode calls and does icky messing with this weird state stuff, so I'm glad it goes away. --- player/video.c | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) (limited to 'player/video.c') diff --git a/player/video.c b/player/video.c index 4621d19cb4..78d10fd107 100644 --- a/player/video.c +++ b/player/video.c @@ -328,6 +328,10 @@ static void vo_chain_reset_state(struct vo_chain *vo_c) if (vo_c->video_src) video_reset(vo_c->video_src); + + // Prepare for continued playback after a seek. + if (!vo_c->input_mpi && vo_c->cached_coverart) + vo_c->input_mpi = mp_image_new_ref(vo_c->cached_coverart); } void reset_video_state(struct MPContext *mpctx) @@ -381,6 +385,7 @@ static void vo_chain_uninit(struct vo_chain *vo_c) lavfi_set_connected(vo_c->filter_src, false); mp_image_unrefp(&vo_c->input_mpi); + mp_image_unrefp(&vo_c->cached_coverart); vf_destroy(vo_c->vf); talloc_free(vo_c); // this does not free the VO @@ -682,14 +687,25 @@ static int video_decode_and_filter(struct MPContext *mpctx) return r; if (!vo_c->input_mpi) { - // Decode a new image, or at least feed the decoder a packet. - r = decode_image(mpctx); - if (r == VD_WAIT) - return r; + if (vo_c->cached_coverart) { + // Don't ever decode it twice, not even after seek resets. + // (On seek resets, input_mpi is set to the cached image.) + r = VD_EOF; + } else { + // Decode a new image, or at least feed the decoder a packet. + r = decode_image(mpctx); + if (r == VD_WAIT) + return r; + } } - if (vo_c->input_mpi) + + if (vo_c->input_mpi) { vo_c->input_format = vo_c->input_mpi->params; + if (vo_c->is_coverart && !vo_c->cached_coverart) + vo_c->cached_coverart = mp_image_new_ref(vo_c->input_mpi); + } + bool eof = !vo_c->input_mpi && (r == VD_EOF || r < 0); r = video_filter(mpctx, eof); if (r == VD_RECONFIG) // retry feeding decoded image -- cgit v1.2.3