Mercurial > mplayer.hg
annotate libmpcodecs/vd_xvid4.c @ 34757:da38eb1e2069
subassconvert: handle "\r\n" line ends
Previously the code converting text subtitles to ASS format converted newline
characters, and only those, to ASS "new line" markup. If the subtitles
contained "\r\n", the "\r" was thus left in the text. In previous libass
versions the "\r" was not visible, but in the current one it produces an empty
box. Improve the conversion to remove the "\r" in that case. Also treat a lone
"\r" as a newline.
Picked from mplayer2/3e0a2705
author | cboesch |
---|---|
date | Sat, 07 Apr 2012 11:17:09 +0000 |
parents | cc27da5d7286 |
children | 139f2b064ef9 |
rev | line source |
---|---|
26727 | 1 /* |
26883 | 2 * - XviD 1.x decoder module for mplayer/mencoder - |
11437 | 3 * |
26727 | 4 * Copyright(C) 2003 Marco Belli <elcabesa@inwind.it> |
5 * 2003-2004 Edouard Gomez <ed.gomez@free.fr> | |
11437 | 6 * |
26727 | 7 * This file is part of MPlayer. |
11437 | 8 * |
26727 | 9 * MPlayer is free software; you can redistribute it and/or modify |
10 * it under the terms of the GNU General Public License as published by | |
11 * the Free Software Foundation; either version 2 of the License, or | |
12 * (at your option) any later version. | |
11437 | 13 * |
26727 | 14 * MPlayer is distributed in the hope that it will be useful, |
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
17 * GNU General Public License for more details. | |
11437 | 18 * |
26727 | 19 * You should have received a copy of the GNU General Public License along |
20 * with MPlayer; if not, write to the Free Software Foundation, Inc., | |
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | |
22 */ | |
11437 | 23 |
24 /***************************************************************************** | |
25 * Includes | |
26 ****************************************************************************/ | |
27 | |
28 #include <stdio.h> | |
29 #include <stdlib.h> | |
30 | |
31 #include "config.h" | |
32 #include "mp_msg.h" | |
33 | |
34 #include "vd_internal.h" | |
35 #include "m_option.h" | |
36 | |
37 #include <xvid.h> | |
38 | |
39 /***************************************************************************** | |
40 * Configuration options | |
41 ****************************************************************************/ | |
42 | |
43 static int do_dr2 = 1; | |
11967
4f4b81257d19
Adds support for the film grain effect and deblocking filters in xvid
attila
parents:
11437
diff
changeset
|
44 static int filmeffect = 0; |
4f4b81257d19
Adds support for the film grain effect and deblocking filters in xvid
attila
parents:
11437
diff
changeset
|
45 static int lumadeblock = 0; |
4f4b81257d19
Adds support for the film grain effect and deblocking filters in xvid
attila
parents:
11437
diff
changeset
|
46 static int chromadeblock = 0; |
13652 | 47 static int lumadering = 0; |
48 static int chromadering = 0; | |
11437 | 49 |
25241
bb7c65f2a289
Make m_option_t arrays referenced by cfg-common.h const
reimar
parents:
19614
diff
changeset
|
50 const m_option_t xvid_dec_opts[] = { |
11437 | 51 { "dr2", &do_dr2, CONF_TYPE_FLAG, 0, 0, 1, NULL}, |
52 { "nodr2", &do_dr2, CONF_TYPE_FLAG, 0, 1, 0, NULL}, | |
11967
4f4b81257d19
Adds support for the film grain effect and deblocking filters in xvid
attila
parents:
11437
diff
changeset
|
53 { "filmeffect", &filmeffect, CONF_TYPE_FLAG, 0, 0, 1, NULL}, |
4f4b81257d19
Adds support for the film grain effect and deblocking filters in xvid
attila
parents:
11437
diff
changeset
|
54 { "deblock-luma", &lumadeblock, CONF_TYPE_FLAG, 0, 0, 1, NULL}, |
4f4b81257d19
Adds support for the film grain effect and deblocking filters in xvid
attila
parents:
11437
diff
changeset
|
55 { "deblock-chroma", &chromadeblock, CONF_TYPE_FLAG, 0, 0, 1, NULL}, |
13652 | 56 { "dering-luma", &lumadering, CONF_TYPE_FLAG, 0, 0, 1, NULL}, |
57 { "dering-chroma", &chromadering, CONF_TYPE_FLAG, 0, 0, 1, NULL}, | |
11437 | 58 {NULL, NULL, 0, 0, 0, 0, NULL} |
59 }; | |
60 | |
61 /***************************************************************************** | |
62 * Module private data | |
63 ****************************************************************************/ | |
64 | |
65 typedef struct { | |
66 int cs; | |
67 unsigned char img_type; | |
68 void* hdl; | |
69 mp_image_t* mpi; | |
13652 | 70 int vo_initialized; |
11437 | 71 } priv_t; |
72 | |
73 /***************************************************************************** | |
13652 | 74 * Module function helpers |
75 ****************************************************************************/ | |
76 | |
77 static float stats2aspect(xvid_dec_stats_t *stats); | |
78 | |
79 /***************************************************************************** | |
11437 | 80 * Video decoder API function definitions |
81 ****************************************************************************/ | |
82 | |
83 /*============================================================================ | |
84 * control - to set/get/query special features/parameters | |
85 *==========================================================================*/ | |
86 | |
87 static int control(sh_video_t *sh,int cmd,void* arg,...) | |
88 { | |
26754
63630c09e237
cosmetics: Remove pointless parentheses from return calls.
diego
parents:
26727
diff
changeset
|
89 return CONTROL_UNKNOWN; |
11437 | 90 } |
91 | |
92 /*============================================================================ | |
93 * init - initialize the codec | |
94 *==========================================================================*/ | |
95 | |
96 static int init(sh_video_t *sh) | |
97 { | |
13652 | 98 xvid_gbl_info_t xvid_gbl_info; |
11437 | 99 xvid_gbl_init_t xvid_ini; |
100 xvid_dec_create_t dec_p; | |
101 priv_t* p; | |
102 int cs; | |
103 | |
13652 | 104 memset(&xvid_gbl_info, 0, sizeof(xvid_gbl_info_t)); |
105 xvid_gbl_info.version = XVID_VERSION; | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
26883
diff
changeset
|
106 |
11437 | 107 memset(&xvid_ini, 0, sizeof(xvid_gbl_init_t)); |
108 xvid_ini.version = XVID_VERSION; | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
26883
diff
changeset
|
109 |
11437 | 110 memset(&dec_p, 0, sizeof(xvid_dec_create_t)); |
111 dec_p.version = XVID_VERSION; | |
112 | |
113 | |
114 switch(sh->codec->outfmt[sh->outfmtidx]){ | |
115 case IMGFMT_YV12: | |
116 /* We will use our own buffers, this speeds decoding avoiding | |
117 * frame memcpy's overhead */ | |
118 cs = (do_dr2)?XVID_CSP_INTERNAL:XVID_CSP_USER; | |
119 break; | |
120 case IMGFMT_YUY2: | |
121 cs = XVID_CSP_YUY2; | |
122 break; | |
123 case IMGFMT_UYVY: | |
124 cs = XVID_CSP_UYVY; | |
125 break; | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
26883
diff
changeset
|
126 case IMGFMT_I420: |
11437 | 127 case IMGFMT_IYUV: |
128 /* We will use our own buffers, this speeds decoding avoiding | |
129 * frame memcpy's overhead */ | |
130 cs = (do_dr2)?XVID_CSP_INTERNAL:XVID_CSP_USER; | |
131 break; | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
26883
diff
changeset
|
132 case IMGFMT_BGR15: |
11437 | 133 cs = XVID_CSP_RGB555; |
134 break; | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
26883
diff
changeset
|
135 case IMGFMT_BGR16: |
11437 | 136 cs = XVID_CSP_RGB565; |
137 break; | |
138 case IMGFMT_BGR32: | |
139 cs = XVID_CSP_BGRA; | |
140 break; | |
141 case IMGFMT_YVYU: | |
142 cs = XVID_CSP_YVYU; | |
143 break; | |
144 default: | |
145 mp_msg(MSGT_DECVIDEO, MSGL_ERR, "Unsupported out_fmt: 0x%X\n", | |
146 sh->codec->outfmt[sh->outfmtidx]); | |
26754
63630c09e237
cosmetics: Remove pointless parentheses from return calls.
diego
parents:
26727
diff
changeset
|
147 return 0; |
11437 | 148 } |
149 | |
13652 | 150 /* Gather some information about the host library */ |
151 if(xvid_global(NULL, XVID_GBL_INFO, &xvid_gbl_info, NULL) < 0) { | |
152 mp_msg(MSGT_MENCODER,MSGL_INFO, "xvid: could not get information about the library\n"); | |
153 } else { | |
154 mp_msg(MSGT_MENCODER,MSGL_INFO, "xvid: using library version %d.%d.%d (build %s)\n", | |
155 XVID_VERSION_MAJOR(xvid_gbl_info.actual_version), | |
156 XVID_VERSION_MINOR(xvid_gbl_info.actual_version), | |
157 XVID_VERSION_PATCH(xvid_gbl_info.actual_version), | |
158 xvid_gbl_info.build); | |
159 } | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
26883
diff
changeset
|
160 |
13652 | 161 /* Initialize the xvidcore library */ |
11437 | 162 if(xvid_global(NULL, XVID_GBL_INIT, &xvid_ini, NULL)) |
26754
63630c09e237
cosmetics: Remove pointless parentheses from return calls.
diego
parents:
26727
diff
changeset
|
163 return 0; |
11437 | 164 |
13652 | 165 /* We use 0 width and height so xvidcore will resize its buffers |
166 * if required. That allows this vd plugin to do resize on first | |
167 * VOL encountered (don't trust containers' width and height) */ | |
168 dec_p.width = 0; | |
169 dec_p.height = 0; | |
11437 | 170 |
13652 | 171 /* Get a decoder instance */ |
11437 | 172 if(xvid_decore(0, XVID_DEC_CREATE, &dec_p, NULL)<0) { |
26883 | 173 mp_msg(MSGT_DECVIDEO, MSGL_ERR, "XviD init failed\n"); |
26754
63630c09e237
cosmetics: Remove pointless parentheses from return calls.
diego
parents:
26727
diff
changeset
|
174 return 0; |
11437 | 175 } |
176 | |
18879 | 177 p = malloc(sizeof(priv_t)); |
11437 | 178 p->cs = cs; |
179 p->hdl = dec_p.handle; | |
13652 | 180 p->vo_initialized = 0; |
11437 | 181 sh->context = p; |
182 | |
183 switch(cs) { | |
184 case XVID_CSP_INTERNAL: | |
185 p->img_type = MP_IMGTYPE_EXPORT; | |
186 break; | |
187 case XVID_CSP_USER: | |
188 p->img_type = MP_IMGTYPE_STATIC; | |
189 break; | |
190 default: | |
191 p->img_type = MP_IMGTYPE_TEMP; | |
192 break; | |
193 } | |
194 | |
26754
63630c09e237
cosmetics: Remove pointless parentheses from return calls.
diego
parents:
26727
diff
changeset
|
195 return 1; |
11437 | 196 } |
197 | |
198 /*============================================================================ | |
199 * uninit - close the codec | |
200 *==========================================================================*/ | |
201 | |
202 static void uninit(sh_video_t *sh){ | |
203 priv_t* p = sh->context; | |
204 if(!p) | |
205 return; | |
206 xvid_decore(p->hdl,XVID_DEC_DESTROY, NULL, NULL); | |
207 free(p); | |
208 } | |
209 | |
210 /*============================================================================ | |
211 * decode - decode a frame from stream | |
212 *==========================================================================*/ | |
213 | |
214 static mp_image_t* decode(sh_video_t *sh, void* data, int len, int flags) | |
215 { | |
216 xvid_dec_frame_t dec; | |
13652 | 217 xvid_dec_stats_t stats; |
218 mp_image_t* mpi = NULL; | |
219 | |
11437 | 220 priv_t* p = sh->context; |
221 | |
222 | |
13652 | 223 if(!data || len <= 0) |
26754
63630c09e237
cosmetics: Remove pointless parentheses from return calls.
diego
parents:
26727
diff
changeset
|
224 return NULL; |
11437 | 225 |
226 memset(&dec,0,sizeof(xvid_dec_frame_t)); | |
13652 | 227 memset(&stats, 0, sizeof(xvid_dec_stats_t)); |
11437 | 228 dec.version = XVID_VERSION; |
13652 | 229 stats.version = XVID_VERSION; |
11437 | 230 |
231 dec.bitstream = data; | |
232 dec.length = len; | |
233 | |
13652 | 234 dec.general |= XVID_LOWDELAY |
235 /* XXX: if lowdelay is unset, and xvidcore internal buffers are | |
236 * used => crash. MUST FIX */ | |
11967
4f4b81257d19
Adds support for the film grain effect and deblocking filters in xvid
attila
parents:
11437
diff
changeset
|
237 | (filmeffect ? XVID_FILMEFFECT : 0 ) |
4f4b81257d19
Adds support for the film grain effect and deblocking filters in xvid
attila
parents:
11437
diff
changeset
|
238 | (lumadeblock ? XVID_DEBLOCKY : 0 ) |
4f4b81257d19
Adds support for the film grain effect and deblocking filters in xvid
attila
parents:
11437
diff
changeset
|
239 | (chromadeblock ? XVID_DEBLOCKUV : 0 ); |
13652 | 240 #if XVID_API >= XVID_MAKE_API(4,1) |
241 dec.general |= (lumadering ? XVID_DEBLOCKY|XVID_DERINGY : 0 ); | |
242 dec.general |= (chromadering ? XVID_DEBLOCKUV|XVID_DERINGUV : 0 ); | |
243 #endif | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
26883
diff
changeset
|
244 dec.output.csp = p->cs; |
11437 | 245 |
13652 | 246 /* Decoding loop because xvidcore may return VOL information for |
247 * on the fly buffer resizing. In that case we must decode VOL, | |
248 * init VO, then decode the frame */ | |
249 do { | |
250 int consumed; | |
251 | |
252 /* If we don't know frame size yet, don't even try to request | |
253 * a buffer, we must loop until we find a VOL, so VO plugin | |
254 * is initialized and we can obviously output something */ | |
255 if (p->vo_initialized) { | |
256 mpi = mpcodecs_get_image(sh, p->img_type, | |
257 MP_IMGFLAG_ACCEPT_STRIDE, | |
258 sh->disp_w, sh->disp_h); | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
26883
diff
changeset
|
259 |
13652 | 260 if(p->cs != XVID_CSP_INTERNAL) { |
261 dec.output.plane[0] = mpi->planes[0]; | |
262 dec.output.plane[1] = mpi->planes[1]; | |
263 dec.output.plane[2] = mpi->planes[2]; | |
11437 | 264 |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
26883
diff
changeset
|
265 dec.output.stride[0] = mpi->stride[0]; |
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
26883
diff
changeset
|
266 dec.output.stride[1] = mpi->stride[1]; |
13652 | 267 dec.output.stride[2] = mpi->stride[2]; |
268 } | |
269 } | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
26883
diff
changeset
|
270 |
13652 | 271 /* Decode data */ |
272 consumed = xvid_decore(p->hdl, XVID_DEC_DECODE, &dec, &stats); | |
273 if (consumed < 0) { | |
274 mp_msg(MSGT_DECVIDEO, MSGL_ERR, "Decoding error\n"); | |
26754
63630c09e237
cosmetics: Remove pointless parentheses from return calls.
diego
parents:
26727
diff
changeset
|
275 return NULL; |
13652 | 276 } |
11437 | 277 |
13652 | 278 /* Found a VOL information stats, if VO plugin is not initialized |
279 * yet then do it now */ | |
280 if (stats.type == XVID_TYPE_VOL && !p->vo_initialized) { | |
281 sh->aspect = stats2aspect(&stats); | |
282 if(!mpcodecs_config_vo(sh, stats.data.vol.width, stats.data.vol.height, IMGFMT_YV12)) | |
26754
63630c09e237
cosmetics: Remove pointless parentheses from return calls.
diego
parents:
26727
diff
changeset
|
283 return NULL; |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
26883
diff
changeset
|
284 |
13652 | 285 /* Don't take this path twice */ |
286 p->vo_initialized = !p->vo_initialized; | |
287 } | |
11437 | 288 |
13652 | 289 /* Don't forget to update buffer position and buffer length */ |
290 dec.bitstream += consumed; | |
291 dec.length -= consumed; | |
292 } while ((stats.type == XVID_TYPE_VOL || stats.type == XVID_TYPE_NOTHING) && dec.length > 0); | |
293 | |
294 /* There are two ways to get out of the decoding loop: | |
295 * - a frame has been returned | |
296 * - no more data in buffer and no frames returned */ | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
26883
diff
changeset
|
297 |
13652 | 298 /* If mpi is NULL, it proves nothing has been returned by the decoder |
299 * so don't try to display internal buffers. */ | |
300 if (mpi != NULL && p->cs == XVID_CSP_INTERNAL) { | |
11437 | 301 mpi->planes[0] = dec.output.plane[0]; |
302 mpi->planes[1] = dec.output.plane[1]; | |
303 mpi->planes[2] = dec.output.plane[2]; | |
304 | |
305 mpi->stride[0] = dec.output.stride[0]; | |
306 mpi->stride[1] = dec.output.stride[1]; | |
307 mpi->stride[2] = dec.output.stride[2]; | |
308 } | |
309 | |
13652 | 310 /* If we got out the decoding loop because the buffer was empty and there was nothing |
311 * to output yet, then just return NULL */ | |
26754
63630c09e237
cosmetics: Remove pointless parentheses from return calls.
diego
parents:
26727
diff
changeset
|
312 return (stats.type == XVID_TYPE_NOTHING) ? NULL : mpi; |
13652 | 313 } |
314 | |
315 /***************************************************************************** | |
316 * Helper functions | |
317 ****************************************************************************/ | |
318 | |
319 /* Returns DAR value according to VOL's informations contained in stats | |
320 * param */ | |
321 static float stats2aspect(xvid_dec_stats_t *stats) | |
322 { | |
323 if (stats->type == XVID_TYPE_VOL) { | |
324 float wpar; | |
325 float hpar; | |
326 float dar; | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
26883
diff
changeset
|
327 |
13652 | 328 /* MPEG4 strem stores PAR (Pixel Aspect Ratio), mplayer uses |
329 * DAR (Display Aspect Ratio) | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
26883
diff
changeset
|
330 * |
13652 | 331 * Both are related thanks to the equation: |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
26883
diff
changeset
|
332 * width |
13652 | 333 * DAR = ----- x PAR |
334 * height | |
335 * | |
336 * As MPEG4 is so well designed (*cough*), VOL header carries | |
337 * both informations together -- lucky eh ? */ | |
338 | |
339 switch (stats->data.vol.par) { | |
340 case XVID_PAR_11_VGA: /* 1:1 vga (square), default if supplied PAR is not a valid value */ | |
341 wpar = hpar = 1.0f; | |
342 break; | |
343 case XVID_PAR_43_PAL: /* 4:3 pal (12:11 625-line) */ | |
344 wpar = 12; | |
345 hpar = 11; | |
346 break; | |
347 case XVID_PAR_43_NTSC: /* 4:3 ntsc (10:11 525-line) */ | |
348 wpar = 10; | |
349 hpar = 11; | |
350 break; | |
351 case XVID_PAR_169_PAL: /* 16:9 pal (16:11 625-line) */ | |
352 wpar = 16; | |
353 hpar = 11; | |
354 break; | |
355 case XVID_PAR_169_NTSC: /* 16:9 ntsc (40:33 525-line) */ | |
356 wpar = 40; | |
357 hpar = 33; | |
358 break; | |
359 case XVID_PAR_EXT: /* extended par; use par_width, par_height */ | |
360 wpar = stats->data.vol.par_width; | |
361 hpar = stats->data.vol.par_height; | |
362 break; | |
363 default: | |
364 wpar = hpar = 1.0f; | |
365 break; | |
366 } | |
367 | |
368 dar = ((float)stats->data.vol.width*wpar); | |
369 dar /= ((float)stats->data.vol.height*hpar); | |
370 | |
26754
63630c09e237
cosmetics: Remove pointless parentheses from return calls.
diego
parents:
26727
diff
changeset
|
371 return dar; |
13652 | 372 } |
373 | |
26754
63630c09e237
cosmetics: Remove pointless parentheses from return calls.
diego
parents:
26727
diff
changeset
|
374 return 0.0f; |
11437 | 375 } |
376 | |
377 /***************************************************************************** | |
378 * Module structure definition | |
379 ****************************************************************************/ | |
380 | |
30504
cc27da5d7286
Mark all ad_info_t/vd_info_t structure declarations as const.
diego
parents:
29263
diff
changeset
|
381 static const vd_info_t info = |
11437 | 382 { |
26883 | 383 "XviD 1.0 decoder", |
11437 | 384 "xvid", |
385 "Marco Belli <elcabesa@inwind.it>, Edouard Gomez <ed.gomez@free.fr>", | |
386 "Marco Belli <elcabesa@inwind.it>, Edouard Gomez <ed.gomez@free.fr>", | |
387 "No Comment" | |
388 }; | |
389 | |
390 LIBVD_EXTERN(xvid) | |
391 | |
392 /* Please do not change that tag comment. | |
393 * arch-tag: b7d654a5-76ea-4768-9713-2c791567fe7d mplayer xvid decoder module */ |