From 8a9b64329c0e387dc59a1fca477a43c50f59ff34 Mon Sep 17 00:00:00 2001 From: wm4 Date: Tue, 19 Jan 2016 18:36:06 +0100 Subject: Relicense some non-MPlayer source files to LGPL 2.1 or later This covers source files which were added in mplayer2 and mpv times only, and where all code is covered by LGPL relicensing agreements. There are probably more files to which this applies, but I'm being conservative here. A file named ao_sdl.c exists in MPlayer too, but the mpv one is a complete rewrite, and was added some time after the original ao_sdl.c was removed. The same applies to vo_sdl.c, for which the SDL2 API is radically different in addition (MPlayer supports SDL 1.2 only). common.c contains only code written by me. But common.h is a strange case: although it originally was named mp_common.h and exists in MPlayer too, by now it contains only definitions written by uau and me. The exceptions are the CONTROL_ defines - thus not changing the license of common.h yet. codec_tags.c contained once large tables generated from MPlayer's codecs.conf, but all of these tables were removed. From demux_playlist.c I'm removing a code fragment from someone who was not asked; this probably could be done later (see commit 15dccc37). misc.c is a bit complicated to reason about (it was split off mplayer.c and thus contains random functions out of this file), but actually all functions have been added post-MPlayer. Except get_relative_time(), which was written by uau, but looks similar to 3 different versions of something similar in each of the Unix/win32/OSX timer source files. I'm not sure what that means in regards to copyright, so I've just moved it into another still-GPL source file for now. screenshot.c once had some minor parts of MPlayer's vf_screenshot.c, but they're all gone. --- sub/dec_sub.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'sub/dec_sub.c') diff --git a/sub/dec_sub.c b/sub/dec_sub.c index 561f8b8be8..e8b63986ab 100644 --- a/sub/dec_sub.c +++ b/sub/dec_sub.c @@ -1,18 +1,18 @@ /* * This file is part of mpv. * - * mpv is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. + * mpv is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. * * mpv is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. + * GNU Lesser General Public License for more details. * - * You should have received a copy of the GNU General Public License along - * with mpv. If not, see . + * You should have received a copy of the GNU Lesser General Public + * License along with mpv. If not, see . */ #include -- cgit v1.2.3 From 028773611949186865ea6977eca9493b2fc57853 Mon Sep 17 00:00:00 2001 From: wm4 Date: Fri, 12 Feb 2016 15:58:48 +0100 Subject: sub: remove always-true check Confuses Coverity with FORWARD_NULL on the mp_err() at the end of the function. These pointers are never NULL. Fixes CID 1350059. --- sub/dec_sub.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'sub/dec_sub.c') diff --git a/sub/dec_sub.c b/sub/dec_sub.c index e8b63986ab..641a5ab1da 100644 --- a/sub/dec_sub.c +++ b/sub/dec_sub.c @@ -104,7 +104,7 @@ struct dec_sub *sub_create(struct mpv_global *global, struct demuxer *demuxer, .codec = sh->codec, }; - if (sh->codec && sub->sd->driver->init(sub->sd) >= 0) + if (sub->sd->driver->init(sub->sd) >= 0) return sub; ta_set_parent(log, NULL); -- cgit v1.2.3 From 8aeaa34a5c9206392a23b1017a47df2c968c43fe Mon Sep 17 00:00:00 2001 From: wm4 Date: Mon, 15 Feb 2016 20:26:01 +0100 Subject: sub: move sub decoder init to a function Preparation for timeline rewrite. --- sub/dec_sub.c | 74 +++++++++++++++++++++++++++++++++++------------------------ 1 file changed, 44 insertions(+), 30 deletions(-) (limited to 'sub/dec_sub.c') diff --git a/sub/dec_sub.c b/sub/dec_sub.c index 641a5ab1da..5a952e4fd5 100644 --- a/sub/dec_sub.c +++ b/sub/dec_sub.c @@ -46,8 +46,12 @@ struct dec_sub { pthread_mutex_t lock; struct mp_log *log; + struct mpv_global *global; struct MPOpts *opts; + struct demuxer *demuxer; + struct mp_codec_params *codec; + struct sh_stream *sh; double last_pkt_pts; @@ -75,46 +79,56 @@ void sub_destroy(struct dec_sub *sub) talloc_free(sub); } -// Thread-safety of the returned object: all functions are thread-safe, -// except sub_get_bitmaps() and sub_get_text(). Decoder backends (sd_*) -// do not need to acquire locks. -struct dec_sub *sub_create(struct mpv_global *global, struct demuxer *demuxer, - struct sh_stream *sh) +static struct sd *init_decoder(struct dec_sub *sub) { - assert(demuxer && sh && sh->type == STREAM_SUB); - - struct mp_log *log = mp_log_new(NULL, global->log, "sub"); - for (int n = 0; sd_list[n]; n++) { const struct sd_functions *driver = sd_list[n]; - struct dec_sub *sub = talloc_zero(NULL, struct dec_sub); - sub->log = talloc_steal(sub, log), - sub->opts = global->opts; - sub->sh = sh; - sub->last_pkt_pts = MP_NOPTS_VALUE; - mpthread_mutex_init_recursive(&sub->lock); - - sub->sd = talloc(NULL, struct sd); - *sub->sd = (struct sd){ - .global = global, - .log = mp_log_new(sub->sd, sub->log, driver->name), + struct sd *sd = talloc(NULL, struct sd); + *sd = (struct sd){ + .global = sub->global, + .log = mp_log_new(sd, sub->log, driver->name), .opts = sub->opts, .driver = driver, - .demuxer = demuxer, - .codec = sh->codec, + .demuxer = sub->demuxer, + .codec = sub->codec, }; - if (sub->sd->driver->init(sub->sd) >= 0) - return sub; + if (sd->driver->init(sd) >= 0) + return sd; - ta_set_parent(log, NULL); - talloc_free(sub->sd); - talloc_free(sub); + talloc_free(sd); } - mp_err(log, "Could not find subtitle decoder for format '%s'.\n", - sh->codec->codec); - talloc_free(log); + MP_ERR(sub, "Could not find subtitle decoder for format '%s'.\n", + sub->codec->codec); + return NULL; +} + +// Thread-safety of the returned object: all functions are thread-safe, +// except sub_get_bitmaps() and sub_get_text(). Decoder backends (sd_*) +// do not need to acquire locks. +struct dec_sub *sub_create(struct mpv_global *global, struct demuxer *demuxer, + struct sh_stream *sh) +{ + assert(demuxer && sh && sh->type == STREAM_SUB); + + struct dec_sub *sub = talloc(NULL, struct dec_sub); + *sub = (struct dec_sub){ + .log = mp_log_new(sub, global->log, "sub"), + .global = global, + .opts = global->opts, + .sh = sh, + .codec = sh->codec, + .demuxer = demuxer, + .last_pkt_pts = MP_NOPTS_VALUE, + }; + mpthread_mutex_init_recursive(&sub->lock); + + sub->sd = init_decoder(sub); + if (sub->sd) + return sub; + + talloc_free(sub); return NULL; } -- cgit v1.2.3 From 0af5335383887cda7650d4b33bc42759c1a5891f Mon Sep 17 00:00:00 2001 From: wm4 Date: Mon, 15 Feb 2016 21:04:07 +0100 Subject: Rewrite ordered chapters and timeline stuff This uses a different method to piece segments together. The old approach basically changes to a new file (with a new start offset) any time a segment ends. This meant waiting for audio/video end on segment end, and then changing to the new segment all at once. It had a very weird impact on the playback core, and some things (like truly gapless segment transitions, or frame backstepping) just didn't work. The new approach adds the demux_timeline pseudo-demuxer, which presents an uniform packet stream from the many segments. This is pretty similar to how ordered chapters are implemented everywhere else. It also reminds of the FFmpeg concat pseudo-demuxer. The "pure" version of this approach doesn't work though. Segments can actually have different codec configurations (different extradata), and subtitles are most likely broken too. (Subtitles have multiple corner cases which break the pure stream-concatenation approach completely.) To counter this, we do two things: - Reinit the decoder with each segment. We go as far as allowing concatenating files with completely different codecs for the sake of EDL (which also uses the timeline infrastructure). A "lighter" approach would try to make use of decoder mechanism to update e.g. the extradata, but that seems fragile. - Clip decoded data to segment boundaries. This is equivalent to normal playback core mechanisms like hr-seek, but now the playback core doesn't need to care about these things. These two mechanisms are equivalent to what happened in the old implementation, except they don't happen in the playback core anymore. In other words, the playback core is completely relieved from timeline implementation details. (Which honestly is exactly what I'm trying to do here. I don't think ordered chapter behavior deserves improvement, even if it's bad - but I want to get it out from the playback core.) There is code duplication between audio and video decoder common code. This is awful and could be shareable - but this will happen later. Note that the audio path has some code to clip audio frames for the purpose of codec preroll/gapless handling, but it's not shared as sharing it would cause more pain than it would help. --- sub/dec_sub.c | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 57 insertions(+), 2 deletions(-) (limited to 'sub/dec_sub.c') diff --git a/sub/dec_sub.c b/sub/dec_sub.c index 5a952e4fd5..58562140fa 100644 --- a/sub/dec_sub.c +++ b/sub/dec_sub.c @@ -50,12 +50,17 @@ struct dec_sub { struct MPOpts *opts; struct demuxer *demuxer; - struct mp_codec_params *codec; struct sh_stream *sh; double last_pkt_pts; + struct mp_codec_params *codec; + double start, end; + + double last_vo_pts; struct sd *sd; + + struct demux_packet *new_segment; }; void sub_lock(struct dec_sub *sub) @@ -121,6 +126,9 @@ struct dec_sub *sub_create(struct mpv_global *global, struct demuxer *demuxer, .codec = sh->codec, .demuxer = demuxer, .last_pkt_pts = MP_NOPTS_VALUE, + .last_vo_pts = MP_NOPTS_VALUE, + .start = MP_NOPTS_VALUE, + .end = MP_NOPTS_VALUE, }; mpthread_mutex_init_recursive(&sub->lock); @@ -132,6 +140,31 @@ struct dec_sub *sub_create(struct mpv_global *global, struct demuxer *demuxer, return NULL; } +// Called locked. +static void update_segment(struct dec_sub *sub) +{ + if (sub->new_segment && sub->last_vo_pts != MP_NOPTS_VALUE && + sub->last_vo_pts >= sub->new_segment->start) + { + sub->codec = sub->new_segment->codec; + sub->start = sub->new_segment->start; + sub->end = sub->new_segment->end; + struct sd *new = init_decoder(sub); + if (new) { + sub->sd->driver->uninit(sub->sd); + talloc_free(sub->sd); + sub->sd = new; + } else { + // We'll just keep the current decoder, and feed it possibly + // invalid data (not our fault if it crashes or something). + MP_ERR(sub, "Can't change to new codec.\n"); + } + sub->sd->driver->decode(sub->sd, sub->new_segment); + talloc_free(sub->new_segment); + sub->new_segment = NULL; + } +} + // Read all packets from the demuxer and decode/add them. Returns false if // there are circumstances which makes this not possible. bool sub_read_all_packets(struct dec_sub *sub) @@ -170,6 +203,9 @@ bool sub_read_packets(struct dec_sub *sub, double video_pts) if (!read_more) break; + if (sub->new_segment) + break; + struct demux_packet *pkt; int st = demux_read_packet_async(sub->sh, &pkt); // Note: "wait" (st==0) happens with non-interleaved streams only, and @@ -183,8 +219,16 @@ bool sub_read_packets(struct dec_sub *sub, double video_pts) break; } - sub->sd->driver->decode(sub->sd, pkt); sub->last_pkt_pts = pkt->pts; + + if (pkt->new_segment) { + sub->new_segment = pkt; + // Note that this can be delayed to a much later point in time. + update_segment(sub); + break; + } + + sub->sd->driver->decode(sub->sd, pkt); talloc_free(pkt); } pthread_mutex_unlock(&sub->lock); @@ -199,6 +243,9 @@ void sub_get_bitmaps(struct dec_sub *sub, struct mp_osd_res dim, double pts, { struct MPOpts *opts = sub->opts; + sub->last_vo_pts = pts; + update_segment(sub); + *res = (struct sub_bitmaps) {0}; if (opts->sub_visibility && sub->sd->driver->get_bitmaps) sub->sd->driver->get_bitmaps(sub->sd, dim, pts, res); @@ -212,6 +259,10 @@ char *sub_get_text(struct dec_sub *sub, double pts) pthread_mutex_lock(&sub->lock); struct MPOpts *opts = sub->opts; char *text = NULL; + + sub->last_vo_pts = pts; + update_segment(sub); + if (opts->sub_visibility && sub->sd->driver->get_text) text = sub->sd->driver->get_text(sub->sd, pts); pthread_mutex_unlock(&sub->lock); @@ -224,6 +275,10 @@ void sub_reset(struct dec_sub *sub) if (sub->sd->driver->reset) sub->sd->driver->reset(sub->sd); sub->last_pkt_pts = MP_NOPTS_VALUE; + sub->start = sub->end = MP_NOPTS_VALUE; + sub->last_vo_pts = MP_NOPTS_VALUE; + talloc_free(sub->new_segment); + sub->new_segment = NULL; pthread_mutex_unlock(&sub->lock); } -- cgit v1.2.3 From da24cb9e3e861aa1499506014fecfcb87cd8c535 Mon Sep 17 00:00:00 2001 From: wm4 Date: Sat, 20 Feb 2016 16:23:44 +0100 Subject: sub: always clip subtitles against segment end This happens only if the new segment wasn't read yet. This is not quite proper and a problem with dec_sub.c internals. Ideally, it'd wait with rendering until a new enough segment has been read. Normally, the new segment is available immediately, so the end will be automatically clipped by switching to the right segment in the exact moment it's supposed to become effective. Usually shouldn't cause any problems, though. --- sub/dec_sub.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'sub/dec_sub.c') diff --git a/sub/dec_sub.c b/sub/dec_sub.c index 58562140fa..75f5509c62 100644 --- a/sub/dec_sub.c +++ b/sub/dec_sub.c @@ -243,10 +243,14 @@ void sub_get_bitmaps(struct dec_sub *sub, struct mp_osd_res dim, double pts, { struct MPOpts *opts = sub->opts; + *res = (struct sub_bitmaps) {0}; + sub->last_vo_pts = pts; update_segment(sub); - *res = (struct sub_bitmaps) {0}; + if (sub->end != MP_NOPTS_VALUE && pts >= sub->end) + return; + if (opts->sub_visibility && sub->sd->driver->get_bitmaps) sub->sd->driver->get_bitmaps(sub->sd, dim, pts, res); } -- cgit v1.2.3