mp_msg: print messages to stdout, statusline to stderr
[mplayer.git] / sub / dec_sub.c
blob5fb6c653a0f5624a7c49eff688968f748385a6df
1 /*
2 * This file is part of MPlayer.
4 * MPlayer is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * MPlayer is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License along
15 * with MPlayer; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 #include <stdlib.h>
20 #include <stdbool.h>
21 #include <assert.h>
23 #include "config.h"
24 #include "libmpdemux/stheader.h"
25 #include "sd.h"
26 #include "dec_sub.h"
27 #include "options.h"
29 extern const struct sd_functions sd_ass;
30 extern const struct sd_functions sd_lavc;
32 void sub_init(struct sh_sub *sh, struct osd_state *osd)
34 struct MPOpts *opts = sh->opts;
36 assert(!osd->sh_sub);
37 #ifdef CONFIG_ASS
38 if (opts->ass_enabled && is_text_sub(sh->type))
39 sh->sd_driver = &sd_ass;
40 #endif
41 if (strchr("bpx", sh->type))
42 sh->sd_driver = &sd_lavc;
43 if (sh->sd_driver) {
44 if (sh->sd_driver->init(sh, osd) < 0)
45 return;
46 osd->sh_sub = sh;
47 osd->bitmap_id = ++osd->bitmap_pos_id;
48 sh->initialized = true;
49 sh->active = true;
53 void sub_decode(struct sh_sub *sh, struct osd_state *osd, void *data,
54 int data_len, double pts, double duration)
56 if (sh->active && sh->sd_driver->decode)
57 sh->sd_driver->decode(sh, osd, data, data_len, pts, duration);
60 void sub_get_bitmaps(struct osd_state *osd, struct sub_bitmaps *res)
62 struct MPOpts *opts = osd->opts;
64 *res = (struct sub_bitmaps){ .type = SUBBITMAP_EMPTY,
65 .bitmap_id = osd->bitmap_id,
66 .bitmap_pos_id = osd->bitmap_pos_id };
67 if (!opts->sub_visibility || !osd->sh_sub || !osd->sh_sub->active) {
68 /* Change ID in case we just switched from visible subtitles
69 * to current state. Hopefully, unnecessarily claiming that
70 * things may have changed is harmless for empty contents.
71 * Increase osd-> values ahead so that _next_ returned id
72 * is also guaranteed to differ from this one.
74 res->bitmap_id = ++res->bitmap_pos_id;
75 osd->bitmap_id = osd->bitmap_pos_id += 2;
76 return;
78 if (osd->sh_sub->sd_driver->get_bitmaps)
79 osd->sh_sub->sd_driver->get_bitmaps(osd->sh_sub, osd, res);
80 osd->bitmap_id = res->bitmap_id;
81 osd->bitmap_pos_id = res->bitmap_pos_id;
84 void sub_reset(struct sh_sub *sh, struct osd_state *osd)
86 if (sh->active && sh->sd_driver->reset)
87 sh->sd_driver->reset(sh, osd);
90 void sub_switchoff(struct sh_sub *sh, struct osd_state *osd)
92 if (sh->active && sh->sd_driver->switch_off) {
93 assert(osd->sh_sub == sh);
94 sh->sd_driver->switch_off(sh, osd);
96 sh->active = false;
97 osd->sh_sub = NULL;
100 void sub_uninit(struct sh_sub *sh)
102 assert (!sh->active);
103 if (sh->initialized && sh->sd_driver->uninit)
104 sh->sd_driver->uninit(sh);
105 sh->initialized = false;