comparison libmpcodecs/vf_ass.c @ 31927:6e0b5a97e00f

EOSD/ASS code factorization Move some code that was partially duplicated between vf_vo and vf_ass with subtle differences into a separate file.
author cigaes
date Mon, 23 Aug 2010 19:13:05 +0000
parents 55dacfca4a43
children 06519a2a9c77
comparison
equal deleted inserted replaced
31926:45966266392b 31927:6e0b5a97e00f
37 #include "vd.h" 37 #include "vd.h"
38 #include "vf.h" 38 #include "vf.h"
39 39
40 #include "libvo/fastmemcpy.h" 40 #include "libvo/fastmemcpy.h"
41 #include "libvo/sub.h" 41 #include "libvo/sub.h"
42 #include "libvo/video_out.h"
42 #include "m_option.h" 43 #include "m_option.h"
43 #include "m_struct.h" 44 #include "m_struct.h"
44 45
45 #include "libass/ass_mp.h" 46 #include "libass/ass_mp.h"
47 #include "eosd.h"
46 48
47 #define _r(c) ((c)>>24) 49 #define _r(c) ((c)>>24)
48 #define _g(c) (((c)>>16)&0xFF) 50 #define _g(c) (((c)>>16)&0xFF)
49 #define _b(c) (((c)>>8)&0xFF) 51 #define _b(c) (((c)>>8)&0xFF)
50 #define _a(c) ((c)&0xFF) 52 #define _a(c) ((c)&0xFF)
60 62
61 // 1 = auto-added filter: insert only if chain does not support EOSD already 63 // 1 = auto-added filter: insert only if chain does not support EOSD already
62 // 0 = insert always 64 // 0 = insert always
63 int auto_insert; 65 int auto_insert;
64 66
65 ASS_Renderer* ass_priv;
66
67 unsigned char* planes[3]; 67 unsigned char* planes[3];
68 unsigned char* dirty_rows; 68 unsigned char* dirty_rows;
69 } vf_priv_dflt; 69 } vf_priv_dflt;
70 70
71 71
72 static int config(struct vf_instance *vf, 72 static int config(struct vf_instance *vf,
73 int width, int height, int d_width, int d_height, 73 int width, int height, int d_width, int d_height,
74 unsigned int flags, unsigned int outfmt) 74 unsigned int flags, unsigned int outfmt)
75 { 75 {
76 mp_eosd_res_t res = {0};
77
76 if (outfmt == IMGFMT_IF09) return 0; 78 if (outfmt == IMGFMT_IF09) return 0;
77 79
78 vf->priv->outh = height + ass_top_margin + ass_bottom_margin; 80 vf->priv->outh = height + ass_top_margin + ass_bottom_margin;
79 vf->priv->outw = width; 81 vf->priv->outw = width;
80 82
85 87
86 vf->priv->planes[1] = malloc(vf->priv->outw * vf->priv->outh); 88 vf->priv->planes[1] = malloc(vf->priv->outw * vf->priv->outh);
87 vf->priv->planes[2] = malloc(vf->priv->outw * vf->priv->outh); 89 vf->priv->planes[2] = malloc(vf->priv->outw * vf->priv->outh);
88 vf->priv->dirty_rows = malloc(vf->priv->outh); 90 vf->priv->dirty_rows = malloc(vf->priv->outh);
89 91
90 if (vf->priv->ass_priv) { 92 res.w = vf->priv->outw;
91 ass_configure(vf->priv->ass_priv, vf->priv->outw, vf->priv->outh, 0); 93 res.h = vf->priv->outh;
92 ass_set_aspect_ratio(vf->priv->ass_priv, 1, 1); 94 res.srcw = width;
93 } 95 res.srch = height;
96 res.mt = ass_top_margin;
97 res.mb = ass_bottom_margin;
98 eosd_configure(&res, 0);
94 99
95 return vf_next_config(vf, vf->priv->outw, vf->priv->outh, d_width, d_height, flags, outfmt); 100 return vf_next_config(vf, vf->priv->outw, vf->priv->outh, d_width, d_height, flags, outfmt);
96 } 101 }
97 102
98 static void get_image(struct vf_instance *vf, mp_image_t *mpi) 103 static void get_image(struct vf_instance *vf, mp_image_t *mpi)
322 return 0; 327 return 0;
323 } 328 }
324 329
325 static int put_image(struct vf_instance *vf, mp_image_t *mpi, double pts) 330 static int put_image(struct vf_instance *vf, mp_image_t *mpi, double pts)
326 { 331 {
327 ASS_Image* images = 0; 332 ASS_Image* images = eosd_render_frame(pts, NULL);
328 if (sub_visibility && vf->priv->ass_priv && ass_track && (pts != MP_NOPTS_VALUE))
329 images = ass_mp_render_frame(vf->priv->ass_priv, ass_track, (pts+sub_delay) * 1000 + .5, NULL);
330
331 prepare_image(vf, mpi); 333 prepare_image(vf, mpi);
332 if (images) render_frame(vf, mpi, images); 334 if (images) render_frame(vf, mpi, images);
333 335
334 return vf_next_put_image(vf, vf->dmpi, pts); 336 return vf_next_put_image(vf, vf->dmpi, pts);
335 } 337 }
347 349
348 static int control(vf_instance_t *vf, int request, void *data) 350 static int control(vf_instance_t *vf, int request, void *data)
349 { 351 {
350 switch (request) { 352 switch (request) {
351 case VFCTRL_INIT_EOSD: 353 case VFCTRL_INIT_EOSD:
352 vf->priv->ass_priv = ass_renderer_init((ASS_Library*)data);
353 if (!vf->priv->ass_priv) return CONTROL_FALSE;
354 ass_configure_fonts(vf->priv->ass_priv);
355 return CONTROL_TRUE; 354 return CONTROL_TRUE;
356 case VFCTRL_DRAW_EOSD: 355 case VFCTRL_DRAW_EOSD:
357 if (vf->priv->ass_priv) return CONTROL_TRUE; 356 return CONTROL_TRUE;
358 break;
359 } 357 }
360 return vf_next_control(vf, request, data); 358 return vf_next_control(vf, request, data);
361 } 359 }
362 360
363 static void uninit(struct vf_instance *vf) 361 static void uninit(struct vf_instance *vf)
364 { 362 {
365 if (vf->priv->ass_priv)
366 ass_renderer_done(vf->priv->ass_priv);
367 if (vf->priv->planes[1]) 363 if (vf->priv->planes[1])
368 free(vf->priv->planes[1]); 364 free(vf->priv->planes[1]);
369 if (vf->priv->planes[2]) 365 if (vf->priv->planes[2])
370 free(vf->priv->planes[2]); 366 free(vf->priv->planes[2]);
371 if (vf->priv->dirty_rows) 367 if (vf->priv->dirty_rows)