Mercurial > mplayer.hg
annotate libass/ass_library.c @ 33469:17519ae1f249
Constrain libcdparanoia's caching which badly breaks playback with -nocache.
Switching to libcdio by default which does not have this issue might be a
better long-term solution though.
author | reimar |
---|---|
date | Sat, 04 Jun 2011 10:27:45 +0000 |
parents | ac6e48baa03d |
children | 88eebbbbd6a0 |
rev | line source |
---|---|
20477 | 1 /* |
26723 | 2 * Copyright (C) 2006 Evgeniy Stepanov <eugeni.stepanov@gmail.com> |
3 * | |
26738
588ce97b44f2
Speak of libass instead of MPlayer in the libass license headers.
diego
parents:
26724
diff
changeset
|
4 * This file is part of libass. |
26723 | 5 * |
26738
588ce97b44f2
Speak of libass instead of MPlayer in the libass license headers.
diego
parents:
26724
diff
changeset
|
6 * libass is free software; you can redistribute it and/or modify |
26723 | 7 * it under the terms of the GNU General Public License as published by |
8 * the Free Software Foundation; either version 2 of the License, or | |
9 * (at your option) any later version. | |
10 * | |
26738
588ce97b44f2
Speak of libass instead of MPlayer in the libass license headers.
diego
parents:
26724
diff
changeset
|
11 * libass is distributed in the hope that it will be useful, |
26723 | 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 * GNU General Public License for more details. | |
15 * | |
16 * 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:
26724
diff
changeset
|
17 * with libass; if not, write to the Free Software Foundation, Inc., |
26724
980ec8f69c58
Fix one more license header wording detail for consistency.
diego
parents:
26723
diff
changeset
|
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
26723 | 19 */ |
20477 | 20 |
31875 | 21 #include "config.h" |
22 | |
20477 | 23 #include <inttypes.h> |
24 #include <stdio.h> | |
25 #include <stdlib.h> | |
26 #include <string.h> | |
30200 | 27 #include <stdarg.h> |
20477 | 28 |
29 #include "ass.h" | |
30 #include "ass_library.h" | |
30200 | 31 #include "ass_utils.h" |
20477 | 32 |
30200 | 33 static void ass_msg_handler(int level, const char *fmt, va_list va, void *data) |
20477 | 34 { |
30200 | 35 if (level > MSGL_INFO) |
36 return; | |
37 fprintf(stderr, "[ass] "); | |
38 vfprintf(stderr, fmt, va); | |
39 fprintf(stderr, "\n"); | |
20477 | 40 } |
41 | |
30200 | 42 ASS_Library *ass_library_init(void) |
20477 | 43 { |
30200 | 44 ASS_Library* lib = calloc(1, sizeof(*lib)); |
45 lib->msg_callback = ass_msg_handler; | |
46 | |
47 return lib; | |
20477 | 48 } |
49 | |
30200 | 50 void ass_library_done(ASS_Library *priv) |
20477 | 51 { |
30200 | 52 if (priv) { |
53 ass_set_fonts_dir(priv, NULL); | |
54 ass_set_style_overrides(priv, NULL); | |
55 ass_clear_fonts(priv); | |
56 free(priv); | |
57 } | |
20477 | 58 } |
59 | |
30200 | 60 void ass_set_fonts_dir(ASS_Library *priv, const char *fonts_dir) |
20477 | 61 { |
31875 | 62 free(priv->fonts_dir); |
30200 | 63 |
64 priv->fonts_dir = fonts_dir ? strdup(fonts_dir) : 0; | |
65 } | |
66 | |
67 void ass_set_extract_fonts(ASS_Library *priv, int extract) | |
68 { | |
69 priv->extract_fonts = !!extract; | |
20477 | 70 } |
71 | |
30200 | 72 void ass_set_style_overrides(ASS_Library *priv, char **list) |
20477 | 73 { |
30200 | 74 char **p; |
75 char **q; | |
76 int cnt; | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
26738
diff
changeset
|
77 |
30200 | 78 if (priv->style_overrides) { |
79 for (p = priv->style_overrides; *p; ++p) | |
80 free(*p); | |
81 } | |
31875 | 82 free(priv->style_overrides); |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
26738
diff
changeset
|
83 |
30200 | 84 if (!list) |
85 return; | |
20477 | 86 |
30200 | 87 for (p = list, cnt = 0; *p; ++p, ++cnt) { |
88 } | |
89 | |
90 priv->style_overrides = malloc((cnt + 1) * sizeof(char *)); | |
91 for (p = list, q = priv->style_overrides; *p; ++p, ++q) | |
92 *q = strdup(*p); | |
93 priv->style_overrides[cnt] = NULL; | |
20477 | 94 } |
21458
7af6c25a0cfc
Keep embedded fonts in ass_library_t and perform actual disk write
eugeni
parents:
20722
diff
changeset
|
95 |
7af6c25a0cfc
Keep embedded fonts in ass_library_t and perform actual disk write
eugeni
parents:
20722
diff
changeset
|
96 static void grow_array(void **array, int nelem, size_t elsize) |
7af6c25a0cfc
Keep embedded fonts in ass_library_t and perform actual disk write
eugeni
parents:
20722
diff
changeset
|
97 { |
30200 | 98 if (!(nelem & 31)) |
99 *array = realloc(*array, (nelem + 32) * elsize); | |
100 } | |
101 | |
102 void ass_add_font(ASS_Library *priv, char *name, char *data, int size) | |
103 { | |
104 int idx = priv->num_fontdata; | |
105 if (!name || !data || !size) | |
106 return; | |
107 grow_array((void **) &priv->fontdata, priv->num_fontdata, | |
108 sizeof(*priv->fontdata)); | |
109 | |
110 priv->fontdata[idx].name = strdup(name); | |
111 | |
112 priv->fontdata[idx].data = malloc(size); | |
113 memcpy(priv->fontdata[idx].data, data, size); | |
114 | |
115 priv->fontdata[idx].size = size; | |
116 | |
117 priv->num_fontdata++; | |
21458
7af6c25a0cfc
Keep embedded fonts in ass_library_t and perform actual disk write
eugeni
parents:
20722
diff
changeset
|
118 } |
7af6c25a0cfc
Keep embedded fonts in ass_library_t and perform actual disk write
eugeni
parents:
20722
diff
changeset
|
119 |
30200 | 120 void ass_clear_fonts(ASS_Library *priv) |
21458
7af6c25a0cfc
Keep embedded fonts in ass_library_t and perform actual disk write
eugeni
parents:
20722
diff
changeset
|
121 { |
30200 | 122 int i; |
123 for (i = 0; i < priv->num_fontdata; ++i) { | |
124 free(priv->fontdata[i].name); | |
125 free(priv->fontdata[i].data); | |
126 } | |
127 free(priv->fontdata); | |
128 priv->fontdata = NULL; | |
129 priv->num_fontdata = 0; | |
21458
7af6c25a0cfc
Keep embedded fonts in ass_library_t and perform actual disk write
eugeni
parents:
20722
diff
changeset
|
130 } |
7af6c25a0cfc
Keep embedded fonts in ass_library_t and perform actual disk write
eugeni
parents:
20722
diff
changeset
|
131 |
30200 | 132 /* |
133 * Register a message callback function with libass. Without setting one, | |
134 * a default handler is used which prints everything with MSGL_INFO or | |
135 * higher to the standard output. | |
136 * | |
137 * \param msg_cb the callback function | |
138 * \param data additional data that will be passed to the callback | |
139 */ | |
140 void ass_set_message_cb(ASS_Library *priv, | |
141 void (*msg_cb)(int, const char *, va_list, void *), | |
142 void *data) | |
25613
f00333e3facf
Copy font data to ass_library instead of referencing demuxer-owned memory.
eugeni
parents:
21497
diff
changeset
|
143 { |
30200 | 144 if (msg_cb) { |
145 priv->msg_callback = msg_cb; | |
146 priv->msg_callback_data = data; | |
147 } | |
25613
f00333e3facf
Copy font data to ass_library instead of referencing demuxer-owned memory.
eugeni
parents:
21497
diff
changeset
|
148 } |