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.
24 #include "libmpdemux/stheader.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
;
38 if (opts
->ass_enabled
&& is_text_sub(sh
->type
))
39 sh
->sd_driver
= &sd_ass
;
41 if (strchr("bpx", sh
->type
))
42 sh
->sd_driver
= &sd_lavc
;
44 if (sh
->sd_driver
->init(sh
, osd
) < 0)
47 osd
->bitmap_id
= ++osd
->bitmap_pos_id
;
48 sh
->initialized
= 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;
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
);
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;