Mercurial > mplayer.hg
annotate libass/ass.h @ 29385:f9ae25067fe0
Fix 24bit audio playback.
The reordering channels code had reoccurring bug
where in switch(samplesize) block the
case 3 (3 bytes) doesn't end with break;
leading to execution of the next case 4 too.
This mangles the already processed data and
causes massive memory corruption.
author | iive |
---|---|
date | Sun, 19 Jul 2009 09:55:29 +0000 |
parents | fd2047f3adf6 |
children | 73a32da1ef18 |
rev | line source |
---|---|
20008
fa122b7c71c6
Add copyright notice and vim/emacs comments to libass and vf_ass.c.
eugeni
parents:
19652
diff
changeset
|
1 // -*- c-basic-offset: 8; indent-tabs-mode: t -*- |
fa122b7c71c6
Add copyright notice and vim/emacs comments to libass and vf_ass.c.
eugeni
parents:
19652
diff
changeset
|
2 // vim:ts=8:sw=8:noet:ai: |
fa122b7c71c6
Add copyright notice and vim/emacs comments to libass and vf_ass.c.
eugeni
parents:
19652
diff
changeset
|
3 /* |
26723 | 4 * Copyright (C) 2006 Evgeniy Stepanov <eugeni.stepanov@gmail.com> |
5 * | |
26738
588ce97b44f2
Speak of libass instead of MPlayer in the libass license headers.
diego
parents:
26723
diff
changeset
|
6 * This file is part of libass. |
26723 | 7 * |
26738
588ce97b44f2
Speak of libass instead of MPlayer in the libass license headers.
diego
parents:
26723
diff
changeset
|
8 * libass is free software; you can redistribute it and/or modify |
26723 | 9 * it under the terms of the GNU General Public License as published by |
10 * the Free Software Foundation; either version 2 of the License, or | |
11 * (at your option) any later version. | |
12 * | |
26738
588ce97b44f2
Speak of libass instead of MPlayer in the libass license headers.
diego
parents:
26723
diff
changeset
|
13 * libass is distributed in the hope that it will be useful, |
26723 | 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 * GNU General Public License for more details. | |
17 * | |
18 * You should have received a copy of the GNU General Public License along | |
26738
588ce97b44f2
Speak of libass instead of MPlayer in the libass license headers.
diego
parents:
26723
diff
changeset
|
19 * with libass; if not, write to the Free Software Foundation, Inc., |
26723 | 20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
21 */ | |
20008
fa122b7c71c6
Add copyright notice and vim/emacs comments to libass and vf_ass.c.
eugeni
parents:
19652
diff
changeset
|
22 |
25897
aaebaf255b23
Consistently give all libass multiple inclusion guards a LIBASS_ prefix.
diego
parents:
25613
diff
changeset
|
23 #ifndef LIBASS_ASS_H |
aaebaf255b23
Consistently give all libass multiple inclusion guards a LIBASS_ prefix.
diego
parents:
25613
diff
changeset
|
24 #define LIBASS_ASS_H |
18937 | 25 |
26138
74055622161d
Add missing header #includes to fix 'make checkheaders'.
diego
parents:
25897
diff
changeset
|
26 #include <stdio.h> |
18937 | 27 #include "ass_types.h" |
28 | |
20477 | 29 /// Libass renderer object. Contents are private. |
30 typedef struct ass_renderer_s ass_renderer_t; | |
18937 | 31 |
32 /// a linked list of images produced by ass renderer | |
33 typedef struct ass_image_s { | |
34 int w, h; // bitmap width/height | |
35 int stride; // bitmap stride | |
36 unsigned char* bitmap; // 1bpp stride*h alpha buffer | |
29381 | 37 // Actual bitmap size may be as low as |
38 // stride * (h-1) + w | |
18937 | 39 uint32_t color; // RGBA |
40 int dst_x, dst_y; // bitmap placement inside the video frame | |
41 | |
42 struct ass_image_s* next; // linked list | |
43 } ass_image_t; | |
44 | |
23134
1de2a46a0987
Add -ass-hinting option for setting font hinting method.
eugeni
parents:
21506
diff
changeset
|
45 /// Hinting type |
1de2a46a0987
Add -ass-hinting option for setting font hinting method.
eugeni
parents:
21506
diff
changeset
|
46 typedef enum {ASS_HINTING_NONE = 0, |
1de2a46a0987
Add -ass-hinting option for setting font hinting method.
eugeni
parents:
21506
diff
changeset
|
47 ASS_HINTING_LIGHT, |
1de2a46a0987
Add -ass-hinting option for setting font hinting method.
eugeni
parents:
21506
diff
changeset
|
48 ASS_HINTING_NORMAL, |
1de2a46a0987
Add -ass-hinting option for setting font hinting method.
eugeni
parents:
21506
diff
changeset
|
49 ASS_HINTING_NATIVE |
1de2a46a0987
Add -ass-hinting option for setting font hinting method.
eugeni
parents:
21506
diff
changeset
|
50 } ass_hinting_t; |
1de2a46a0987
Add -ass-hinting option for setting font hinting method.
eugeni
parents:
21506
diff
changeset
|
51 |
18937 | 52 /** |
53 * \brief initialize the library | |
54 * \return library handle or NULL if failed | |
55 */ | |
20477 | 56 ass_library_t* ass_library_init(void); |
18937 | 57 |
58 /** | |
59 * \brief finalize the library | |
60 * \param priv library handle | |
61 */ | |
20477 | 62 void ass_library_done(ass_library_t*); |
63 | |
64 /** | |
65 * \brief set private font directory | |
66 * It is used for saving embedded fonts and also in font lookup. | |
67 */ | |
68 void ass_set_fonts_dir(ass_library_t* priv, const char* fonts_dir); | |
69 | |
70 void ass_set_extract_fonts(ass_library_t* priv, int extract); | |
71 | |
72 void ass_set_style_overrides(ass_library_t* priv, char** list); | |
18937 | 73 |
20477 | 74 /** |
75 * \brief initialize the renderer | |
76 * \param priv library handle | |
77 * \return renderer handle or NULL if failed | |
78 */ | |
79 ass_renderer_t* ass_renderer_init(ass_library_t*); | |
80 | |
81 /** | |
82 * \brief finalize the renderer | |
83 * \param priv renderer handle | |
84 */ | |
85 void ass_renderer_done(ass_renderer_t* priv); | |
86 | |
87 void ass_set_frame_size(ass_renderer_t* priv, int w, int h); | |
88 void ass_set_margins(ass_renderer_t* priv, int t, int b, int l, int r); | |
89 void ass_set_use_margins(ass_renderer_t* priv, int use); | |
90 void ass_set_aspect_ratio(ass_renderer_t* priv, double ar); | |
91 void ass_set_font_scale(ass_renderer_t* priv, double font_scale); | |
23134
1de2a46a0987
Add -ass-hinting option for setting font hinting method.
eugeni
parents:
21506
diff
changeset
|
92 void ass_set_hinting(ass_renderer_t* priv, ass_hinting_t ht); |
24554 | 93 void ass_set_line_spacing(ass_renderer_t* priv, double line_spacing); |
20477 | 94 |
95 /** | |
96 * \brief set font lookup defaults | |
97 */ | |
98 int ass_set_fonts(ass_renderer_t* priv, const char* default_font, const char* default_family); | |
18937 | 99 |
100 /** | |
26582
62ac4f8062ee
Remove libass dependency on global font_fontconfig variable.
eugeni
parents:
26138
diff
changeset
|
101 * \brief set font lookup defaults, don't use fontconfig even if it is available |
62ac4f8062ee
Remove libass dependency on global font_fontconfig variable.
eugeni
parents:
26138
diff
changeset
|
102 */ |
62ac4f8062ee
Remove libass dependency on global font_fontconfig variable.
eugeni
parents:
26138
diff
changeset
|
103 int ass_set_fonts_nofc(ass_renderer_t* priv, const char* default_font, const char* default_family); |
62ac4f8062ee
Remove libass dependency on global font_fontconfig variable.
eugeni
parents:
26138
diff
changeset
|
104 |
62ac4f8062ee
Remove libass dependency on global font_fontconfig variable.
eugeni
parents:
26138
diff
changeset
|
105 /** |
18937 | 106 * \brief render a frame, producing a list of ass_image_t |
107 * \param priv library | |
108 * \param track subtitle track | |
109 * \param now video timestamp in milliseconds | |
110 */ | |
21506
8174acbf0633
Speed up ASS subtitles display by detecting changes between two consecutive
eugeni
parents:
21458
diff
changeset
|
111 ass_image_t* ass_render_frame(ass_renderer_t *priv, ass_track_t* track, long long now, int* detect_change); |
18937 | 112 |
113 | |
20477 | 114 // The following functions operate on track objects and do not need an ass_renderer // |
18937 | 115 |
116 /** | |
117 * \brief allocate a new empty track object | |
118 * \return pointer to empty track | |
119 */ | |
20477 | 120 ass_track_t* ass_new_track(ass_library_t*); |
18937 | 121 |
122 /** | |
123 * \brief deallocate track and all its child objects (styles and events) | |
124 * \param track track to deallocate | |
125 */ | |
126 void ass_free_track(ass_track_t* track); | |
127 | |
128 /** | |
129 * \brief allocate new style | |
130 * \param track track | |
131 * \return newly allocated style id | |
132 */ | |
133 int ass_alloc_style(ass_track_t* track); | |
134 | |
135 /** | |
136 * \brief allocate new event | |
137 * \param track track | |
138 * \return newly allocated event id | |
139 */ | |
140 int ass_alloc_event(ass_track_t* track); | |
141 | |
142 /** | |
19474
07209f48e527
Add public functions for removal of styles and events.
eugeni
parents:
18937
diff
changeset
|
143 * \brief delete a style |
07209f48e527
Add public functions for removal of styles and events.
eugeni
parents:
18937
diff
changeset
|
144 * \param track track |
07209f48e527
Add public functions for removal of styles and events.
eugeni
parents:
18937
diff
changeset
|
145 * \param sid style id |
07209f48e527
Add public functions for removal of styles and events.
eugeni
parents:
18937
diff
changeset
|
146 * Deallocates style data. Does not modify track->n_styles. |
07209f48e527
Add public functions for removal of styles and events.
eugeni
parents:
18937
diff
changeset
|
147 */ |
07209f48e527
Add public functions for removal of styles and events.
eugeni
parents:
18937
diff
changeset
|
148 void ass_free_style(ass_track_t* track, int sid); |
07209f48e527
Add public functions for removal of styles and events.
eugeni
parents:
18937
diff
changeset
|
149 |
07209f48e527
Add public functions for removal of styles and events.
eugeni
parents:
18937
diff
changeset
|
150 /** |
07209f48e527
Add public functions for removal of styles and events.
eugeni
parents:
18937
diff
changeset
|
151 * \brief delete an event |
07209f48e527
Add public functions for removal of styles and events.
eugeni
parents:
18937
diff
changeset
|
152 * \param track track |
07209f48e527
Add public functions for removal of styles and events.
eugeni
parents:
18937
diff
changeset
|
153 * \param eid event id |
07209f48e527
Add public functions for removal of styles and events.
eugeni
parents:
18937
diff
changeset
|
154 * Deallocates event data. Does not modify track->n_events. |
07209f48e527
Add public functions for removal of styles and events.
eugeni
parents:
18937
diff
changeset
|
155 */ |
07209f48e527
Add public functions for removal of styles and events.
eugeni
parents:
18937
diff
changeset
|
156 void ass_free_event(ass_track_t* track, int eid); |
07209f48e527
Add public functions for removal of styles and events.
eugeni
parents:
18937
diff
changeset
|
157 |
07209f48e527
Add public functions for removal of styles and events.
eugeni
parents:
18937
diff
changeset
|
158 /** |
27498
d895515b366d
libass: add a new ass_process_data() to process demuxed subtitle packets
aurel
parents:
26738
diff
changeset
|
159 * \brief Parse a chunk of subtitle stream data. |
d895515b366d
libass: add a new ass_process_data() to process demuxed subtitle packets
aurel
parents:
26738
diff
changeset
|
160 * \param track track |
d895515b366d
libass: add a new ass_process_data() to process demuxed subtitle packets
aurel
parents:
26738
diff
changeset
|
161 * \param data string to parse |
d895515b366d
libass: add a new ass_process_data() to process demuxed subtitle packets
aurel
parents:
26738
diff
changeset
|
162 * \param size length of data |
d895515b366d
libass: add a new ass_process_data() to process demuxed subtitle packets
aurel
parents:
26738
diff
changeset
|
163 */ |
d895515b366d
libass: add a new ass_process_data() to process demuxed subtitle packets
aurel
parents:
26738
diff
changeset
|
164 void ass_process_data(ass_track_t* track, char* data, int size); |
d895515b366d
libass: add a new ass_process_data() to process demuxed subtitle packets
aurel
parents:
26738
diff
changeset
|
165 |
d895515b366d
libass: add a new ass_process_data() to process demuxed subtitle packets
aurel
parents:
26738
diff
changeset
|
166 /** |
25514 | 167 * \brief Parse Codec Private section of subtitle stream |
18937 | 168 * \param track target track |
169 * \param data string to parse | |
170 * \param size length of data | |
171 */ | |
19492 | 172 void ass_process_codec_private(ass_track_t* track, char *data, int size); |
18937 | 173 |
174 /** | |
25515 | 175 * \brief Parse a chunk of subtitle stream data. In Matroska, this contains exactly 1 event (or a commentary). |
18937 | 176 * \param track track |
177 * \param data string to parse | |
178 * \param size length of data | |
179 * \param timecode starting time of the event (milliseconds) | |
180 * \param duration duration of the event (milliseconds) | |
181 */ | |
19492 | 182 void ass_process_chunk(ass_track_t* track, char *data, int size, long long timecode, long long duration); |
18937 | 183 |
27499
1dfad1b382fa
libass: fix type mismatch between size parameter and the way it's used
aurel
parents:
27498
diff
changeset
|
184 char* read_file_recode(char* fname, char* codepage, size_t* size); |
23424
7286d245bf33
Move code for reading a file and recoding it to utf-8 to a separate function.
eugeni
parents:
23134
diff
changeset
|
185 |
18937 | 186 /** |
187 * \brief Read subtitles from file. | |
188 * \param fname file name | |
189 * \return newly allocated track | |
190 */ | |
20477 | 191 ass_track_t* ass_read_file(ass_library_t* library, char* fname, char* codepage); |
18937 | 192 |
193 /** | |
20603 | 194 * \brief Read subtitles from memory. |
195 * \param library libass library object | |
196 * \param buf pointer to subtitles text | |
197 * \param bufsize size of buffer | |
198 * \param codepage recode buffer contents from given codepage | |
199 * \return newly allocated track | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
27499
diff
changeset
|
200 */ |
20603 | 201 ass_track_t* ass_read_memory(ass_library_t* library, char* buf, size_t bufsize, char* codepage); |
202 /** | |
19652
2c016957360a
Add -ass-styles option. It allows to load styles from a file and use them
eugeni
parents:
19638
diff
changeset
|
203 * \brief read styles from file into already initialized track |
2c016957360a
Add -ass-styles option. It allows to load styles from a file and use them
eugeni
parents:
19638
diff
changeset
|
204 * \return 0 on success |
2c016957360a
Add -ass-styles option. It allows to load styles from a file and use them
eugeni
parents:
19638
diff
changeset
|
205 */ |
20477 | 206 int ass_read_styles(ass_track_t* track, char* fname, char* codepage); |
19652
2c016957360a
Add -ass-styles option. It allows to load styles from a file and use them
eugeni
parents:
19638
diff
changeset
|
207 |
2c016957360a
Add -ass-styles option. It allows to load styles from a file and use them
eugeni
parents:
19638
diff
changeset
|
208 /** |
21455 | 209 * \brief Add a memory font. |
18937 | 210 * \param name attachment name |
211 * \param data binary font data | |
212 * \param data_size data size | |
213 */ | |
21458
7af6c25a0cfc
Keep embedded fonts in ass_library_t and perform actual disk write
eugeni
parents:
21455
diff
changeset
|
214 void ass_add_font(ass_library_t* library, char* name, char* data, int data_size); |
18937 | 215 |
216 /** | |
25613
f00333e3facf
Copy font data to ass_library instead of referencing demuxer-owned memory.
eugeni
parents:
25535
diff
changeset
|
217 * \brief Remove all fonts stored in ass_library object |
f00333e3facf
Copy font data to ass_library instead of referencing demuxer-owned memory.
eugeni
parents:
25535
diff
changeset
|
218 */ |
f00333e3facf
Copy font data to ass_library instead of referencing demuxer-owned memory.
eugeni
parents:
25535
diff
changeset
|
219 void ass_clear_fonts(ass_library_t* library); |
f00333e3facf
Copy font data to ass_library instead of referencing demuxer-owned memory.
eugeni
parents:
25535
diff
changeset
|
220 |
f00333e3facf
Copy font data to ass_library instead of referencing demuxer-owned memory.
eugeni
parents:
25535
diff
changeset
|
221 /** |
18937 | 222 * \brief Calculates timeshift from now to the start of some other subtitle event, depending on movement parameter |
223 * \param track subtitle track | |
224 * \param now current time, ms | |
225 * \param movement how many events to skip from the one currently displayed | |
226 * +2 means "the one after the next", -1 means "previous" | |
227 * \return timeshift, ms | |
228 */ | |
229 long long ass_step_sub(ass_track_t* track, long long now, int movement); | |
230 | |
25897
aaebaf255b23
Consistently give all libass multiple inclusion guards a LIBASS_ prefix.
diego
parents:
25613
diff
changeset
|
231 #endif /* LIBASS_ASS_H */ |