diff options
author | wm4 <wm4@nowhere> | 2013-06-04 00:29:29 +0200 |
---|---|---|
committer | wm4 <wm4@nowhere> | 2013-06-04 00:29:44 +0200 |
commit | 92ae48db0f91fbfcfbb1722fa81c922808f62d5a (patch) | |
tree | e32fe21b5f8c11ada7788768a76e2d9f7d061c66 /sub/sd_spu.c | |
parent | daf8ed831b4ae63cf0931cc3d6727956137f865f (diff) | |
parent | c1ac97b99b3e80bbf84ed540178dd6689ead0b87 (diff) | |
download | mpv-92ae48db0f91fbfcfbb1722fa81c922808f62d5a.tar.bz2 mpv-92ae48db0f91fbfcfbb1722fa81c922808f62d5a.tar.xz |
Merge branch 'sub_mess'
This branch heavily refactors the subtitle code (both loading and
rendering), and adds support for a few new formats through FFmpeg.
We don't remove any of the old code yet. There are still some subtleties
related to subreader.c to be resolved: code page detection & conversion,
timing post-processing, UTF-16 subtitle support, support for the -subfps
option. Also, SRT reading and loading ASS via libass should be turned
into proper demuxers. (SRT is needed because Libav's is gravely broken,
and we want ASS loading via libass to cover full libass format support.
Both should be demuxers which are probed _before_ libavformat, so that
all subtitles can be loaded through the demuxer infrastructure, and
libavformat subtitles don't need to be treated in a special way.)
Diffstat (limited to 'sub/sd_spu.c')
-rw-r--r-- | sub/sd_spu.c | 102 |
1 files changed, 102 insertions, 0 deletions
diff --git a/sub/sd_spu.c b/sub/sd_spu.c new file mode 100644 index 0000000000..c6aed81641 --- /dev/null +++ b/sub/sd_spu.c @@ -0,0 +1,102 @@ +/* + * 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 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. + * + * You should have received a copy of the GNU General Public License along + * with mpv. If not, see <http://www.gnu.org/licenses/>. + */ + +#include <stdlib.h> +#include <assert.h> + +#include "talloc.h" +#include "core/options.h" +#include "demux/stheader.h" +#include "sd.h" +#include "sub.h" +#include "spudec.h" + +struct sd_spu_priv { + void *spudec; +}; + +static bool is_dvd_sub(const char *t) +{ + return t && (strcmp(t, "dvd_subtitle") == 0 || + strcmp(t, "dvd_subtitle_mpg") == 0); +} + +static bool supports_format(const char *format) +{ + return is_dvd_sub(format); +} + +static int init(struct sd *sd) +{ + void *spudec = spudec_new_scaled(sd->sub_video_w, sd->sub_video_h, + sd->extradata, sd->extradata_len); + if (!spudec) + return -1; + struct sd_spu_priv *priv = talloc_zero(NULL, struct sd_spu_priv); + priv->spudec = spudec; + sd->priv = priv; + return 0; +} + +static void decode(struct sd *sd, struct demux_packet *packet) +{ + struct sd_spu_priv *priv = sd->priv; + + if (packet->pts < 0 || packet->len == 0) + return; + + spudec_assemble(priv->spudec, packet->buffer, packet->len, + packet->pts * 90000); +} + +static void get_bitmaps(struct sd *sd, struct mp_osd_res d, double pts, + struct sub_bitmaps *res) +{ + struct MPOpts *opts = sd->opts; + struct sd_spu_priv *priv = sd->priv; + + spudec_set_forced_subs_only(priv->spudec, opts->forced_subs_only); + spudec_heartbeat(priv->spudec, pts * 90000); + + if (spudec_visible(priv->spudec)) + spudec_get_indexed(priv->spudec, &d, res); +} + +static void reset(struct sd *sd) +{ + struct sd_spu_priv *priv = sd->priv; + + spudec_reset(priv->spudec); +} + +static void uninit(struct sd *sd) +{ + struct sd_spu_priv *priv = sd->priv; + + spudec_free(priv->spudec); + talloc_free(priv); +} + +const struct sd_functions sd_spu = { + .name = "spu", + .supports_format = supports_format, + .init = init, + .decode = decode, + .get_bitmaps = get_bitmaps, + .reset = reset, + .uninit = uninit, +}; |