From adedee42851d413de87b479340eb015ee33b497b Mon Sep 17 00:00:00 2001 From: Uoti Urpala Date: Wed, 12 Jan 2011 15:15:02 +0200 Subject: subtitles: move global ass_track to struct osd_state --- command.c | 25 +++++++++++-------------- libmpcodecs/vf.h | 4 ++-- libmpcodecs/vf_ass.c | 12 ++++++++---- libmpcodecs/vf_vo.c | 14 ++++++++------ libvo/sub.h | 1 + mpcommon.h | 2 -- mplayer.c | 15 ++++++--------- 7 files changed, 36 insertions(+), 37 deletions(-) diff --git a/command.c b/command.c index cab0c0b87f..5474b92fed 100644 --- a/command.c +++ b/command.c @@ -1523,7 +1523,6 @@ static int mp_property_sub(m_option_t *prop, int action, void *arg, demux_stream_t *const d_sub = mpctx->d_sub; int source = -1, reset_spu = 0; int source_pos = -1; - char *sub_name; update_global_sub_size(mpctx); const int global_sub_size = mpctx->global_sub_size; @@ -1542,13 +1541,15 @@ static int mp_property_sub(m_option_t *prop, int action, void *arg, return M_PROPERTY_ERROR; *(char **) arg = malloc(64); (*(char **) arg)[63] = 0; - sub_name = 0; + char *sub_name = NULL; if (mpctx->subdata) sub_name = mpctx->subdata->filename; #ifdef CONFIG_ASS - if (ass_track && ass_track->name) - sub_name = ass_track->name; + if (mpctx->osd->ass_track) + sub_name = mpctx->osd->ass_track->name; #endif + if (!sub_name && mpctx->subdata) + sub_name = mpctx->subdata->filename; if (sub_name) { const char *tmp = mp_basename(sub_name); @@ -1654,9 +1655,7 @@ static int mp_property_sub(m_option_t *prop, int action, void *arg, reset_spu = 1; d_sub->id = -2; } -#ifdef CONFIG_ASS - ass_track = 0; -#endif + mpctx->osd->ass_track = NULL; if (source == SUB_SOURCE_VOBSUB) { vobsub_id = vobsub_get_id_by_index(vo_vobsub, source_pos); @@ -1664,7 +1663,7 @@ static int mp_property_sub(m_option_t *prop, int action, void *arg, mpctx->set_of_sub_pos = source_pos; #ifdef CONFIG_ASS if (opts->ass_enabled && mpctx->set_of_ass_tracks[mpctx->set_of_sub_pos]) - ass_track = mpctx->set_of_ass_tracks[mpctx->set_of_sub_pos]; + mpctx->osd->ass_track = mpctx->set_of_ass_tracks[mpctx->set_of_sub_pos]; else #endif { @@ -1693,7 +1692,7 @@ static int mp_property_sub(m_option_t *prop, int action, void *arg, init_vo_spudec(mpctx); #ifdef CONFIG_ASS else if (opts->ass_enabled) - ass_track = sh->ass_track; + mpctx->osd->ass_track = sh->ass_track; #endif } else { d_sub->id = -2; @@ -2694,9 +2693,7 @@ static void remove_subtitle_range(MPContext *mpctx, int start, int count) if (mpctx->set_of_sub_pos >= start && mpctx->set_of_sub_pos < end) { mpctx->global_sub_pos = -2; mpctx->subdata = NULL; -#ifdef CONFIG_ASS - ass_track = NULL; -#endif + mpctx->osd->ass_track = NULL; mp_input_queue_cmd(mpctx->input, mp_input_parse_cmd("sub_select")); } else if (mpctx->set_of_sub_pos >= end) { mpctx->set_of_sub_pos -= count; @@ -2934,9 +2931,9 @@ void run_command(MPContext *mpctx, mp_cmd_t *cmd) int movement = cmd->args[0].v.i; step_sub(mpctx->subdata, mpctx->video_pts, movement); #ifdef CONFIG_ASS - if (ass_track) + if (mpctx->osd->ass_track) sub_delay += - ass_step_sub(ass_track, + ass_step_sub(mpctx->osd->ass_track, (mpctx->video_pts + sub_delay) * 1000 + .5, movement) / 1000.; #endif diff --git a/libmpcodecs/vf.h b/libmpcodecs/vf.h index 0d10abd6c6..8814ffe11a 100644 --- a/libmpcodecs/vf.h +++ b/libmpcodecs/vf.h @@ -107,8 +107,8 @@ typedef struct vf_seteq_s #define VFCTRL_DRAW_EOSD 16 /* Render EOSD */ #define VFCTRL_SET_DEINTERLACE 18 /* Set deinterlacing status */ #define VFCTRL_GET_DEINTERLACE 19 /* Get deinterlacing status */ -/* Hack to make the OSD state object available to vf_expand which accesses - * the OSD state outside of normal OSD draw time. */ +/* Hack to make the OSD state object available to vf_expand and vf_ass which + * access OSD/subtitle state outside of normal OSD draw time. */ #define VFCTRL_SET_OSD_OBJ 20 #define VFCTRL_REDRAW_OSD 21 /* Change user-visible OSD immediately */ #define VFCTRL_SET_YUV_COLORSPACE 22 diff --git a/libmpcodecs/vf_ass.c b/libmpcodecs/vf_ass.c index 2678986025..f1a43b52bd 100644 --- a/libmpcodecs/vf_ass.c +++ b/libmpcodecs/vf_ass.c @@ -33,6 +33,7 @@ #include "img_format.h" #include "mp_image.h" #include "vf.h" +#include "libvo/sub.h" #include "libvo/fastmemcpy.h" @@ -59,6 +60,7 @@ static const struct vf_priv_s { // 0 = insert always int auto_insert; + struct osd_state *osd; ASS_Renderer *ass_priv; unsigned char *planes[3]; @@ -68,9 +70,7 @@ static const struct vf_priv_s { } *line_limits; } vf_priv_dflt; -extern ASS_Track *ass_track; extern float sub_delay; -extern int sub_visibility; static int config(struct vf_instance *vf, int width, int height, int d_width, int d_height, @@ -351,9 +351,10 @@ static int render_frame(struct vf_instance *vf, mp_image_t *mpi, static int put_image(struct vf_instance *vf, mp_image_t *mpi, double pts) { ASS_Image *images = 0; - if (sub_visibility && vf->priv->ass_priv && ass_track + if (sub_visibility && vf->priv->ass_priv && vf->priv->osd->ass_track && (pts != MP_NOPTS_VALUE)) - images = ass_mp_render_frame(vf->priv->ass_priv, ass_track, + images = ass_mp_render_frame(vf->priv->ass_priv, + vf->priv->osd->ass_track, (pts + sub_delay) * 1000 + .5, NULL); prepare_image(vf, mpi); @@ -377,6 +378,9 @@ static int query_format(struct vf_instance *vf, unsigned int fmt) static int control(vf_instance_t *vf, int request, void *data) { switch (request) { + case VFCTRL_SET_OSD_OBJ: + vf->priv->osd = data; + break; case VFCTRL_INIT_EOSD: vf->priv->ass_priv = ass_renderer_init((ASS_Library *)data); if (!vf->priv->ass_priv) diff --git a/libmpcodecs/vf_vo.c b/libmpcodecs/vf_vo.c index 0e8563d5a6..81dff4cea9 100644 --- a/libmpcodecs/vf_vo.c +++ b/libmpcodecs/vf_vo.c @@ -29,14 +29,11 @@ #include "libvo/video_out.h" -#ifdef CONFIG_ASS #include "ass_mp.h" -extern ASS_Track *ass_track; -#endif +#include "libvo/sub.h" //===========================================================================// -extern int sub_visibility; extern float sub_delay; struct vf_priv_s { @@ -141,10 +138,12 @@ static int control(struct vf_instance *vf, int request, void* data) } case VFCTRL_DRAW_EOSD: { + struct osd_state *osd = data; mp_eosd_images_t images = {NULL, 2}; double pts = video_out->next_pts; if (!video_out->config_ok || !vf->priv->ass_priv) return CONTROL_FALSE; - if (sub_visibility && vf->priv->ass_priv && ass_track && (pts != MP_NOPTS_VALUE)) { + if (sub_visibility && vf->priv->ass_priv && osd->ass_track + && (pts != MP_NOPTS_VALUE)) { mp_eosd_res_t res; memset(&res, 0, sizeof(res)); if (vo_control(video_out, VOCTRL_GET_EOSD_RES, &res) == VO_TRUE) { @@ -153,7 +152,10 @@ static int control(struct vf_instance *vf, int request, void* data) ass_set_aspect_ratio(vf->priv->ass_priv, vf->priv->scale_ratio, 1); } - images.imgs = ass_mp_render_frame(vf->priv->ass_priv, ass_track, (pts+sub_delay) * 1000 + .5, &images.changed); + images.imgs = ass_mp_render_frame(vf->priv->ass_priv, + osd->ass_track, + (pts+sub_delay) * 1000 + .5, + &images.changed); if (!vf->priv->prev_visibility) images.changed = 2; vf->priv->prev_visibility = 1; diff --git a/libvo/sub.h b/libvo/sub.h index f3a6f072c2..12d5474e5f 100644 --- a/libvo/sub.h +++ b/libvo/sub.h @@ -69,6 +69,7 @@ typedef struct mp_osd_obj_s { struct osd_state { unsigned char osd_text[128]; struct font_desc *sub_font; + struct ass_track *ass_track; }; #include "subreader.h" diff --git a/mpcommon.h b/mpcommon.h index 8a55d33a9f..ac57ae9d02 100644 --- a/mpcommon.h +++ b/mpcommon.h @@ -19,8 +19,6 @@ #ifndef MPLAYER_MPCOMMON_H #define MPLAYER_MPCOMMON_H -extern struct ass_track *ass_track; - extern const char *mplayer_version; #endif /* MPLAYER_MPCOMMON_H */ diff --git a/mplayer.c b/mplayer.c index 091287c1fd..f36bb2788f 100644 --- a/mplayer.c +++ b/mplayer.c @@ -335,9 +335,6 @@ int subcc_enabled=0; int suboverlap_enabled = 1; #include "ass_mp.h" -#ifdef CONFIG_ASS -ASS_Track *ass_track = 0; // current track to render -#endif char* current_module=NULL; // for debugging @@ -1949,10 +1946,10 @@ void update_subtitles(struct MPContext *mpctx, double refpts, #ifdef CONFIG_ASS if (opts->ass_enabled) { sh_sub_t* sh = d_sub->sh; - ass_track = sh ? sh->ass_track : NULL; - if (!ass_track) continue; + mpctx->osd->ass_track = sh ? sh->ass_track : NULL; + if (!mpctx->osd->ass_track) continue; if (type == 'a') { // ssa/ass subs with libass - ass_process_chunk(ass_track, packet, len, + ass_process_chunk(mpctx->osd->ass_track, packet, len, (long long)(subpts*1000 + 0.5), (long long)((endpts-subpts)*1000 + 0.5)); } else { // plaintext subs with libass @@ -1962,7 +1959,7 @@ void update_subtitles(struct MPContext *mpctx, double refpts, sub_add_text(&tmp_subs, packet, len, endpts); tmp_subs.start = subpts * 100; tmp_subs.end = endpts * 100; - ass_process_subtitle(ass_track, &tmp_subs); + ass_process_subtitle(mpctx->osd->ass_track, &tmp_subs); sub_clear_text(&tmp_subs, MP_NOPTS_VALUE); } } @@ -3416,7 +3413,7 @@ static void run_playloop(struct MPContext *mpctx) update_teletext(sh_video, mpctx->demuxer, 0); update_osd_msg(mpctx); struct vf_instance *vf = sh_video->vfilter; - vf->control(vf, VFCTRL_DRAW_EOSD, NULL); + vf->control(vf, VFCTRL_DRAW_EOSD, mpctx->osd); vf->control(vf, VFCTRL_DRAW_OSD, mpctx->osd); vo_osd_changed(0); @@ -4944,7 +4941,7 @@ if(mpctx->set_of_sub_size > 0) { mpctx->vo_sub_last = vo_sub=NULL; mpctx->subdata=NULL; #ifdef CONFIG_ASS -ass_track = NULL; +mpctx->osd->ass_track = NULL; if(ass_library) ass_clear_fonts(ass_library); #endif -- cgit v1.2.3