comparison libmpcodecs/vf_vo.c @ 19576:3e7ce339d74b

Add EOSD support to vf_vo.
author eugeni
date Mon, 28 Aug 2006 19:10:11 +0000
parents ed2785b4dd48
children 52a319698894
comparison
equal deleted inserted replaced
19575:dbbc66400ceb 19576:3e7ce339d74b
8 #include "mp_image.h" 8 #include "mp_image.h"
9 #include "vf.h" 9 #include "vf.h"
10 10
11 #include "libvo/video_out.h" 11 #include "libvo/video_out.h"
12 12
13 #ifdef USE_ASS
14 #include "libass/ass.h"
15 #include "libass/ass_mp.h"
16 extern ass_track_t* ass_track;
17 #endif
18
13 //===========================================================================// 19 //===========================================================================//
14 20
15 struct vf_priv_s {double pts; vo_functions_t *vo;}; 21 extern int sub_visibility;
16 #define video_out (vf->priv->vo) 22 extern double sub_delay;
23
24 typedef struct vf_vo_data_s {
25 double pts;
26 vo_functions_t *vo;
27 } vf_vo_data_t;
28
29 struct vf_priv_s {
30 vf_vo_data_t* vf_vo_data;
31 #ifdef USE_ASS
32 ass_instance_t* ass_priv;
33 ass_settings_t ass_settings;
34 #endif
35 };
36 #define video_out (vf->priv->vf_vo_data->vo)
17 37
18 static int query_format(struct vf_instance_s* vf, unsigned int fmt); /* forward declaration */ 38 static int query_format(struct vf_instance_s* vf, unsigned int fmt); /* forward declaration */
19 39
20 static int config(struct vf_instance_s* vf, 40 static int config(struct vf_instance_s* vf,
21 int width, int height, int d_width, int d_height, 41 int width, int height, int d_width, int d_height,
47 vf->default_caps=query_format(vf,outfmt) & VFCAP_ACCEPT_STRIDE; 67 vf->default_caps=query_format(vf,outfmt) & VFCAP_ACCEPT_STRIDE;
48 68
49 if(video_out->config(width,height,d_width,d_height,flags,"MPlayer",outfmt)) 69 if(video_out->config(width,height,d_width,d_height,flags,"MPlayer",outfmt))
50 return 0; 70 return 0;
51 71
72 #ifdef USE_ASS
73 if (vf->priv->ass_priv) {
74 vf->priv->ass_settings.font_size_coeff = ass_font_scale;
75 vf->priv->ass_settings.line_spacing = ass_line_spacing;
76 vf->priv->ass_settings.use_margins = ass_use_margins;
77 }
78 #endif
79
52 ++vo_config_count; 80 ++vo_config_count;
53 return 1; 81 return 1;
54 } 82 }
55 83
56 static int control(struct vf_instance_s* vf, int request, void* data) 84 static int control(struct vf_instance_s* vf, int request, void* data)
78 { 106 {
79 vf_equalizer_t *eq=data; 107 vf_equalizer_t *eq=data;
80 if(!vo_config_count) return CONTROL_FALSE; // vo not configured? 108 if(!vo_config_count) return CONTROL_FALSE; // vo not configured?
81 return((video_out->control(VOCTRL_GET_EQUALIZER, eq->item, &eq->value) == VO_TRUE) ? CONTROL_TRUE : CONTROL_FALSE); 109 return((video_out->control(VOCTRL_GET_EQUALIZER, eq->item, &eq->value) == VO_TRUE) ? CONTROL_TRUE : CONTROL_FALSE);
82 } 110 }
111 #ifdef USE_ASS
112 case VFCTRL_INIT_EOSD:
113 {
114 vf->priv->ass_priv = ass_init();
115 return vf->priv->ass_priv ? CONTROL_TRUE : CONTROL_FALSE;
116 }
117 case VFCTRL_DRAW_EOSD:
118 {
119 ass_image_t* images = 0;
120 double pts = vf->priv->vf_vo_data->pts;
121 if (!vo_config_count || !vf->priv->ass_priv) return CONTROL_FALSE;
122 if (sub_visibility && vf->priv->ass_priv && ass_track && (pts != MP_NOPTS_VALUE)) {
123 mp_eosd_res_t res;
124 ass_settings_t* const settings = &vf->priv->ass_settings;
125 memset(&res, 0, sizeof(res));
126 if (video_out->control(VOCTRL_GET_EOSD_RES, &res) == VO_TRUE) {
127 settings->frame_width = res.w;
128 settings->frame_height = res.h;
129 settings->top_margin = res.mt;
130 settings->bottom_margin = res.mb;
131 settings->left_margin = res.ml;
132 settings->right_margin = res.mr;
133 settings->aspect = ((double)res.w) / res.h;
134 }
135 ass_configure(vf->priv->ass_priv, settings);
136
137 images = ass_render_frame(vf->priv->ass_priv, ass_track, (pts+sub_delay) * 1000 + .5);
138 }
139 return (video_out->control(VOCTRL_DRAW_EOSD, images) == VO_TRUE) ? CONTROL_TRUE : CONTROL_FALSE;
140 }
141 #endif
83 } 142 }
84 // return video_out->control(request,data); 143 // return video_out->control(request,data);
85 return CONTROL_UNKNOWN; 144 return CONTROL_UNKNOWN;
86 } 145 }
87 146
102 161
103 static int put_image(struct vf_instance_s* vf, 162 static int put_image(struct vf_instance_s* vf,
104 mp_image_t *mpi, double pts){ 163 mp_image_t *mpi, double pts){
105 if(!vo_config_count) return 0; // vo not configured? 164 if(!vo_config_count) return 0; // vo not configured?
106 // record pts (potentially modified by filters) for main loop 165 // record pts (potentially modified by filters) for main loop
107 vf->priv->pts = pts; 166 vf->priv->vf_vo_data->pts = pts;
108 // first check, maybe the vo/vf plugin implements draw_image using mpi: 167 // first check, maybe the vo/vf plugin implements draw_image using mpi:
109 if(video_out->control(VOCTRL_DRAW_IMAGE,mpi)==VO_TRUE) return 1; // done. 168 if(video_out->control(VOCTRL_DRAW_IMAGE,mpi)==VO_TRUE) return 1; // done.
110 // nope, fallback to old draw_frame/draw_slice: 169 // nope, fallback to old draw_frame/draw_slice:
111 if(!(mpi->flags&(MP_IMGFLAG_DIRECT|MP_IMGFLAG_DRAW_CALLBACK))){ 170 if(!(mpi->flags&(MP_IMGFLAG_DIRECT|MP_IMGFLAG_DRAW_CALLBACK))){
112 // blit frame: 171 // blit frame:
129 unsigned char** src, int* stride, int w,int h, int x, int y){ 188 unsigned char** src, int* stride, int w,int h, int x, int y){
130 if(!vo_config_count) return; // vo not configured? 189 if(!vo_config_count) return; // vo not configured?
131 video_out->draw_slice(src,stride,w,h,x,y); 190 video_out->draw_slice(src,stride,w,h,x,y);
132 } 191 }
133 192
193 static void uninit(struct vf_instance_s* vf)
194 {
195 if (vf->priv) {
196 if (vf->priv->ass_priv)
197 ass_done(vf->priv->ass_priv);
198 free(vf->priv);
199 }
200 }
134 //===========================================================================// 201 //===========================================================================//
135 202
136 static int open(vf_instance_t *vf, char* args){ 203 static int open(vf_instance_t *vf, char* args){
137 vf->config=config; 204 vf->config=config;
138 vf->control=control; 205 vf->control=control;
139 vf->query_format=query_format; 206 vf->query_format=query_format;
140 vf->get_image=get_image; 207 vf->get_image=get_image;
141 vf->put_image=put_image; 208 vf->put_image=put_image;
142 vf->draw_slice=draw_slice; 209 vf->draw_slice=draw_slice;
143 vf->start_slice=start_slice; 210 vf->start_slice=start_slice;
144 vf->priv=(void*)args; // video_out 211 vf->uninit=uninit;
212 vf->priv=calloc(1, sizeof(struct vf_priv_s));
213 vf->priv->vf_vo_data=(vf_vo_data_t*)args;
145 if(!video_out) return 0; // no vo ? 214 if(!video_out) return 0; // no vo ?
146 // if(video_out->preinit(args)) return 0; // preinit failed 215 // if(video_out->preinit(args)) return 0; // preinit failed
147 return 1; 216 return 1;
148 } 217 }
149 218