diff options
Diffstat (limited to 'libvo/sub.c')
-rw-r--r-- | libvo/sub.c | 103 |
1 files changed, 65 insertions, 38 deletions
diff --git a/libvo/sub.c b/libvo/sub.c index 597c121498..987ab76ba0 100644 --- a/libvo/sub.c +++ b/libvo/sub.c @@ -32,6 +32,7 @@ #include "stream/tv.h" #include "osdep/timer.h" +#include "talloc.h" #include "mplayer.h" #include "mp_msg.h" #include "help_mp.h" @@ -64,7 +65,7 @@ struct osd_text_p { }; //^ -char * sub_osd_names[]={ +char * const sub_osd_names[]={ MSGTR_VO_SUB_Seekbar, MSGTR_VO_SUB_Play, MSGTR_VO_SUB_Pause, @@ -79,13 +80,11 @@ char * sub_osd_names[]={ MSGTR_VO_SUB_Hue, MSGTR_VO_SUB_Balance }; -char * sub_osd_names_short[] ={ "", "|>", "||", "[]", "<<" , ">>", "", "", "", "", "", "", "" }; +char * const sub_osd_names_short[] ={ "", "|>", "||", "[]", "<<" , ">>", "", "", "", "", "", "", "" }; //static int vo_font_loaded=-1; font_desc_t* vo_font=NULL; -font_desc_t* sub_font=NULL; -unsigned char* vo_osd_text=NULL; #ifdef CONFIG_TV_TELETEXT void* vo_osd_teletext_page=NULL; int vo_osd_teletext_half = 0; @@ -167,9 +166,11 @@ static void alloc_buf(mp_osd_obj_t* obj) } // renders the buffer -inline static void vo_draw_text_from_buffer(mp_osd_obj_t* obj,void (*draw_alpha)(int x0,int y0, int w,int h, unsigned char* src, unsigned char *srca, int stride)){ +inline static void vo_draw_text_from_buffer(mp_osd_obj_t* obj,void (*draw_alpha)(void *ctx, int x0,int y0, int w,int h, unsigned char* src, unsigned char *srca, int stride), void *ctx) +{ if (obj->allocated > 0) { - draw_alpha(obj->bbox.x1,obj->bbox.y1, + draw_alpha(ctx, + obj->bbox.x1,obj->bbox.y1, obj->bbox.x2-obj->bbox.x1, obj->bbox.y2-obj->bbox.y1, obj->bitmap_buffer, @@ -192,8 +193,10 @@ no_utf8: return c; } -inline static void vo_update_text_osd(mp_osd_obj_t* obj,int dxs,int dys){ - const char *cp=vo_osd_text; +inline static void vo_update_text_osd(struct osd_state *osd, mp_osd_obj_t* obj, + int dxs, int dys) +{ + const char *cp = osd->osd_text; int x=20; int h=0; int font; @@ -214,7 +217,7 @@ inline static void vo_update_text_osd(mp_osd_obj_t* obj,int dxs,int dys){ alloc_buf(obj); - cp=vo_osd_text; + cp = osd->osd_text; x = obj->x; while (*cp){ uint16_t c=utf8_get_char(&cp); @@ -669,7 +672,7 @@ inline static void vo_update_text_progbar(mp_osd_obj_t* obj,int dxs,int dys){ subtitle* vo_sub=NULL; -inline static void vo_update_text_sub(mp_osd_obj_t* obj,int dxs,int dys){ +inline static void vo_update_text_sub(struct osd_state *osd, mp_osd_obj_t* obj,int dxs,int dys){ unsigned char *t; int c,i,j,l,x,y,font,prevc,counter; int k; @@ -678,10 +681,11 @@ inline static void vo_update_text_sub(mp_osd_obj_t* obj,int dxs,int dys){ int xmin=dxs,xmax=0; int h,lasth; int xtblc, utblc; + struct font_desc *sub_font = osd->sub_font; obj->flags|=OSDFLAG_CHANGED|OSDFLAG_VISIBLE; - if(!vo_sub || !sub_font || !sub_visibility || (sub_font->font[40]<0)){ + if(!vo_sub || !osd->sub_font || !sub_visibility || (sub_font->font[40]<0)){ obj->flags&=~OSDFLAG_VISIBLE; return; } @@ -1052,9 +1056,9 @@ inline static void vo_update_spudec_sub(mp_osd_obj_t* obj, int dxs, int dys) obj->flags |= OSDFLAG_BBOX; } -inline static void vo_draw_spudec_sub(mp_osd_obj_t* obj, void (*draw_alpha)(int x0, int y0, int w, int h, unsigned char* src, unsigned char* srca, int stride)) +inline static void vo_draw_spudec_sub(mp_osd_obj_t* obj, void (*draw_alpha)(void *ctx, int x0, int y0, int w, int h, unsigned char* src, unsigned char* srca, int stride), void *ctx) { - spudec_draw_scaled(vo_spudec, obj->dxs, obj->dys, draw_alpha); + spudec_draw_scaled(vo_spudec, obj->dxs, obj->dys, draw_alpha, ctx); } void *vo_spudec=NULL; @@ -1078,7 +1082,8 @@ static mp_osd_obj_t* new_osd_obj(int type){ return osd; } -void free_osd_list(void){ +void osd_free(struct osd_state *osd) +{ mp_osd_obj_t* obj=vo_osd_list; while(obj){ mp_osd_obj_t* next=obj->next; @@ -1088,12 +1093,15 @@ void free_osd_list(void){ obj=next; } vo_osd_list=NULL; + talloc_free(osd); } #define FONT_LOAD_DEFER 6 -int vo_update_osd_ext(int dxs,int dys, int left_border, int top_border, - int right_border, int bottom_border, int orig_w, int orig_h){ +int osd_update_ext(struct osd_state *osd, int dxs, int dys, int left_border, + int top_border, int right_border, int bottom_border, + int orig_w, int orig_h) +{ mp_osd_obj_t* obj=vo_osd_list; int chg=0; #ifdef CONFIG_FREETYPE @@ -1123,20 +1131,20 @@ int vo_update_osd_ext(int dxs,int dys, int left_border, int top_border, force_load_font = 0; load_font_ft(dxs, dys, &vo_font, font_name, osd_font_scale_factor); if (sub_font_name) - load_font_ft(dxs, dys, &sub_font, sub_font_name, text_font_scale_factor); + load_font_ft(dxs, dys, &osd->sub_font, sub_font_name, text_font_scale_factor); else - load_font_ft(dxs, dys, &sub_font, font_name, text_font_scale_factor); + load_font_ft(dxs, dys, &osd->sub_font, font_name, text_font_scale_factor); prev_dxs = dxs; prev_dys = dys; defer_counter = 0; } else { if (!vo_font) load_font_ft(dxs, dys, &vo_font, font_name, osd_font_scale_factor); - if (!sub_font) { + if (!osd->sub_font) { if (sub_font_name) - load_font_ft(dxs, dys, &sub_font, sub_font_name, text_font_scale_factor); + load_font_ft(dxs, dys, &osd->sub_font, sub_font_name, text_font_scale_factor); else - load_font_ft(dxs, dys, &sub_font, font_name, text_font_scale_factor); + load_font_ft(dxs, dys, &osd->sub_font, font_name, text_font_scale_factor); } } #endif @@ -1152,7 +1160,7 @@ int vo_update_osd_ext(int dxs,int dys, int left_border, int top_border, break; #endif case OSDTYPE_SUBTITLE: - vo_update_text_sub(obj,dxs,dys); + vo_update_text_sub(osd, obj,dxs,dys); break; #ifdef CONFIG_TV_TELETEXT case OSDTYPE_TELETEXT: @@ -1171,8 +1179,8 @@ int vo_update_osd_ext(int dxs,int dys, int left_border, int top_border, obj->flags&=~OSDFLAG_VISIBLE; break; case OSDTYPE_OSD: - if(vo_font && vo_osd_text && vo_osd_text[0]){ - vo_update_text_osd(obj,dxs,dys); // update bbox + if(vo_font && osd->osd_text[0]){ + vo_update_text_osd(osd, obj, dxs, dys); // update bbox obj->flags|=OSDFLAG_VISIBLE|OSDFLAG_CHANGED; } else obj->flags&=~OSDFLAG_VISIBLE; @@ -1212,16 +1220,20 @@ int vo_update_osd_ext(int dxs,int dys, int left_border, int top_border, return chg; } -int vo_update_osd(int dxs, int dys) { - return vo_update_osd_ext(dxs, dys, 0, 0, 0, 0, dxs, dys); +int osd_update(struct osd_state *osd, int dxs, int dys) +{ + return osd_update_ext(osd, dxs, dys, 0, 0, 0, 0, dxs, dys); } -void vo_init_osd(void){ +struct osd_state *osd_create(void) +{ + struct osd_state *osd = talloc_zero(NULL, struct osd_state); + *osd = (struct osd_state){ + }; if(!draw_alpha_init_flag){ draw_alpha_init_flag=1; vo_draw_alpha_init(); } - if(vo_osd_list) free_osd_list(); // temp hack, should be moved to mplayer/mencoder later new_osd_obj(OSDTYPE_OSD); new_osd_obj(OSDTYPE_SUBTITLE); @@ -1236,13 +1248,16 @@ void vo_init_osd(void){ #ifdef CONFIG_FREETYPE force_load_font = 1; #endif + return osd; } int vo_osd_changed_flag=0; -void vo_remove_text(int dxs,int dys,void (*remove)(int x0,int y0, int w,int h)){ +void osd_remove_text(struct osd_state *osd, int dxs, int dys, + void (*remove)(int x0, int y0, int w, int h)) +{ mp_osd_obj_t* obj=vo_osd_list; - vo_update_osd(dxs,dys); + osd_update(osd, dxs, dys); while(obj){ if(((obj->flags&OSDFLAG_CHANGED) || (obj->flags&OSDFLAG_VISIBLE)) && (obj->flags&OSDFLAG_OLD_BBOX)){ @@ -1258,17 +1273,24 @@ void vo_remove_text(int dxs,int dys,void (*remove)(int x0,int y0, int w,int h)){ } } -void vo_draw_text_ext(int dxs, int dys, int left_border, int top_border, - int right_border, int bottom_border, int orig_w, int orig_h, - void (*draw_alpha)(int x0, int y0, int w,int h, unsigned char* src, unsigned char *srca, int stride)) { +void osd_draw_text_ext(struct osd_state *osd, int dxs, int dys, + int left_border, int top_border, int right_border, + int bottom_border, int orig_w, int orig_h, + void (*draw_alpha)(void *ctx, int x0, int y0, int w, + int h, unsigned char* src, + unsigned char *srca, + int stride), + void *ctx) +{ mp_osd_obj_t* obj=vo_osd_list; - vo_update_osd_ext(dxs, dys, left_border, top_border, right_border, bottom_border, orig_w, orig_h); + osd_update_ext(osd, dxs, dys, left_border, top_border, right_border, + bottom_border, orig_w, orig_h); while(obj){ if(obj->flags&OSDFLAG_VISIBLE){ vo_osd_changed_flag=obj->flags&OSDFLAG_CHANGED; // temp hack switch(obj->type){ case OSDTYPE_SPU: - vo_draw_spudec_sub(obj, draw_alpha); // FIXME + vo_draw_spudec_sub(obj, draw_alpha, ctx); // FIXME break; #ifdef CONFIG_DVDNAV case OSDTYPE_DVDNAV: @@ -1279,7 +1301,7 @@ void vo_draw_text_ext(int dxs, int dys, int left_border, int top_border, case OSDTYPE_OSD: case OSDTYPE_SUBTITLE: case OSDTYPE_PROGBAR: - vo_draw_text_from_buffer(obj,draw_alpha); + vo_draw_text_from_buffer(obj, draw_alpha, ctx); break; } obj->old_bbox=obj->bbox; @@ -1290,8 +1312,13 @@ void vo_draw_text_ext(int dxs, int dys, int left_border, int top_border, } } -void vo_draw_text(int dxs, int dys, void (*draw_alpha)(int x0, int y0, int w,int h, unsigned char* src, unsigned char *srca, int stride)) { - vo_draw_text_ext(dxs, dys, 0, 0, 0, 0, dxs, dys, draw_alpha); +void osd_draw_text(struct osd_state *osd, int dxs, int dys, + void (*draw_alpha)(void *ctx, int x0, int y0, int w, int h, + unsigned char* src, unsigned char *srca, + int stride), + void *ctx) +{ + osd_draw_text_ext(osd, dxs, dys, 0, 0, 0, 0, dxs, dys, draw_alpha, ctx); } static int vo_osd_changed_status = 0; |