Mercurial > mplayer.hg
annotate libass/ass_utils.c @ 34309:119af6360b00
Discard frames where the size does not match the AVCodecContext width/height.
This avoids possible crashes on video size changes. The problem
is that we reinitialize the vo on get_buffer but due to codec
delay libavcodec might still return frames with the old size
afterwards, which the vo might no longer be able to handle.
Ideally libavcodec should not show this behaviour, since it
requires that any application using DR1 can handle frames of
different sizes simultaneously - which seems a bit extreme.
author | reimar |
---|---|
date | Mon, 05 Dec 2011 18:08:29 +0000 |
parents | 88eebbbbd6a0 |
children | 49fc594fda43 |
rev | line source |
---|---|
20008
fa122b7c71c6
Add copyright notice and vim/emacs comments to libass and vf_ass.c.
eugeni
parents:
19405
diff
changeset
|
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:
26723
diff
changeset
|
4 * This file is part of libass. |
26723 | 5 * |
34011 | 6 * Permission to use, copy, modify, and distribute this software for any |
7 * purpose with or without fee is hereby granted, provided that the above | |
8 * copyright notice and this permission notice appear in all copies. | |
26723 | 9 * |
34011 | 10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES |
11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | |
12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | |
13 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | |
14 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | |
15 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | |
16 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | |
26723 | 17 */ |
20008
fa122b7c71c6
Add copyright notice and vim/emacs comments to libass and vf_ass.c.
eugeni
parents:
19405
diff
changeset
|
18 |
18937 | 19 #include "config.h" |
20 | |
21 #include <stdlib.h> | |
30200 | 22 #include <stdio.h> |
19405 | 23 #include <inttypes.h> |
26034 | 24 #include <ft2build.h> |
25 #include FT_GLYPH_H | |
31875 | 26 #include <strings.h> |
18937 | 27 |
30200 | 28 #include "ass_library.h" |
29 #include "ass.h" | |
18937 | 30 #include "ass_utils.h" |
31 | |
30200 | 32 int mystrtoi(char **p, int *res) |
18937 | 33 { |
30200 | 34 double temp_res; |
35 char *start = *p; | |
36 temp_res = ass_strtod(*p, p); | |
37 *res = (int) (temp_res + (temp_res > 0 ? 0.5 : -0.5)); | |
38 if (*p != start) | |
39 return 1; | |
40 else | |
41 return 0; | |
28717
7bbe6626f0e0
Support fractional arguments for some override tags.
eugeni
parents:
26738
diff
changeset
|
42 } |
7bbe6626f0e0
Support fractional arguments for some override tags.
eugeni
parents:
26738
diff
changeset
|
43 |
30200 | 44 int mystrtoll(char **p, long long *res) |
28717
7bbe6626f0e0
Support fractional arguments for some override tags.
eugeni
parents:
26738
diff
changeset
|
45 { |
30200 | 46 double temp_res; |
47 char *start = *p; | |
48 temp_res = ass_strtod(*p, p); | |
49 *res = (int) (temp_res + (temp_res > 0 ? 0.5 : -0.5)); | |
50 if (*p != start) | |
51 return 1; | |
52 else | |
53 return 0; | |
18937 | 54 } |
55 | |
30200 | 56 int mystrtou32(char **p, int base, uint32_t *res) |
18937 | 57 { |
30200 | 58 char *start = *p; |
59 *res = strtoll(*p, p, base); | |
60 if (*p != start) | |
61 return 1; | |
62 else | |
63 return 0; | |
18937 | 64 } |
65 | |
30200 | 66 int mystrtod(char **p, double *res) |
18937 | 67 { |
30200 | 68 char *start = *p; |
69 *res = ass_strtod(*p, p); | |
70 if (*p != start) | |
71 return 1; | |
72 else | |
73 return 0; | |
18937 | 74 } |
75 | |
30200 | 76 int strtocolor(ASS_Library *library, char **q, uint32_t *res, int hex) |
18937 | 77 { |
30200 | 78 uint32_t color = 0; |
79 int result; | |
80 char *p = *q; | |
81 int base = hex ? 16 : 10; | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28785
diff
changeset
|
82 |
30200 | 83 if (*p == '&') |
84 ++p; | |
85 else | |
86 ass_msg(library, MSGL_DBG2, "suspicious color format: \"%s\"\n", p); | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28785
diff
changeset
|
87 |
30200 | 88 if (*p == 'H' || *p == 'h') { |
89 ++p; | |
90 result = mystrtou32(&p, 16, &color); | |
91 } else { | |
92 result = mystrtou32(&p, base, &color); | |
93 } | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28785
diff
changeset
|
94 |
30200 | 95 { |
96 unsigned char *tmp = (unsigned char *) (&color); | |
97 unsigned char b; | |
98 b = tmp[0]; | |
99 tmp[0] = tmp[3]; | |
100 tmp[3] = b; | |
101 b = tmp[1]; | |
102 tmp[1] = tmp[2]; | |
103 tmp[2] = b; | |
104 } | |
105 if (*p == '&') | |
106 ++p; | |
107 *q = p; | |
18937 | 108 |
30200 | 109 *res = color; |
110 return result; | |
18937 | 111 } |
112 | |
28785 | 113 // Return a boolean value for a string |
30200 | 114 char parse_bool(char *str) |
115 { | |
116 while (*str == ' ' || *str == '\t') | |
117 str++; | |
118 if (!strncasecmp(str, "yes", 3)) | |
119 return 1; | |
120 else if (strtol(str, NULL, 10) > 0) | |
121 return 1; | |
122 return 0; | |
123 } | |
124 | |
125 void ass_msg(ASS_Library *priv, int lvl, char *fmt, ...) | |
126 { | |
127 va_list va; | |
128 va_start(va, fmt); | |
129 priv->msg_callback(lvl, fmt, va, priv->msg_callback_data); | |
130 va_end(va); | |
28785 | 131 } |
132 | |
30200 | 133 unsigned ass_utf8_get_char(char **str) |
26034 | 134 { |
30200 | 135 uint8_t *strp = (uint8_t *) * str; |
136 unsigned c = *strp++; | |
137 unsigned mask = 0x80; | |
138 int len = -1; | |
139 while (c & mask) { | |
140 mask >>= 1; | |
141 len++; | |
142 } | |
143 if (len <= 0 || len > 4) | |
144 goto no_utf8; | |
145 c &= mask - 1; | |
146 while ((*strp & 0xc0) == 0x80) { | |
147 if (len-- <= 0) | |
148 goto no_utf8; | |
149 c = (c << 6) | (*strp++ & 0x3f); | |
150 } | |
151 if (len) | |
152 goto no_utf8; | |
153 *str = (char *) strp; | |
154 return c; | |
155 | |
156 no_utf8: | |
157 strp = (uint8_t *) * str; | |
158 c = *strp++; | |
159 *str = (char *) strp; | |
160 return c; | |
26034 | 161 } |
162 | |
30200 | 163 #ifdef CONFIG_ENCA |
164 void *ass_guess_buffer_cp(ASS_Library *library, unsigned char *buffer, | |
165 int buflen, char *preferred_language, | |
166 char *fallback) | |
26034 | 167 { |
30200 | 168 const char **languages; |
169 size_t langcnt; | |
170 EncaAnalyser analyser; | |
171 EncaEncoding encoding; | |
172 char *detected_sub_cp = NULL; | |
173 int i; | |
174 | |
175 languages = enca_get_languages(&langcnt); | |
176 ass_msg(library, MSGL_V, "ENCA supported languages"); | |
177 for (i = 0; i < langcnt; i++) { | |
178 ass_msg(library, MSGL_V, "lang %s", languages[i]); | |
179 } | |
180 | |
181 for (i = 0; i < langcnt; i++) { | |
182 const char *tmp; | |
183 | |
184 if (strcasecmp(languages[i], preferred_language) != 0) | |
185 continue; | |
186 analyser = enca_analyser_alloc(languages[i]); | |
187 encoding = enca_analyse_const(analyser, buffer, buflen); | |
188 tmp = enca_charset_name(encoding.charset, ENCA_NAME_STYLE_ICONV); | |
189 if (tmp && encoding.charset != ENCA_CS_UNKNOWN) { | |
190 detected_sub_cp = strdup(tmp); | |
191 ass_msg(library, MSGL_INFO, "ENCA detected charset: %s", tmp); | |
192 } | |
193 enca_analyser_free(analyser); | |
194 } | |
195 | |
196 free(languages); | |
197 | |
198 if (!detected_sub_cp) { | |
199 detected_sub_cp = strdup(fallback); | |
200 ass_msg(library, MSGL_INFO, | |
201 "ENCA detection failed: fallback to %s", fallback); | |
202 } | |
203 | |
204 return detected_sub_cp; | |
26034 | 205 } |
26036
8d8c52a169ad
Comment out dump_glyph(): it is unused and, as it is now, breaks compilation.
eugeni
parents:
26034
diff
changeset
|
206 #endif |