subtitles: move global ass_track to struct osd_state

This commit is contained in:
Uoti Urpala 2011-01-12 15:15:02 +02:00
parent 43b1de1dd7
commit adedee4285
7 changed files with 36 additions and 37 deletions

View File

@ -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; demux_stream_t *const d_sub = mpctx->d_sub;
int source = -1, reset_spu = 0; int source = -1, reset_spu = 0;
int source_pos = -1; int source_pos = -1;
char *sub_name;
update_global_sub_size(mpctx); update_global_sub_size(mpctx);
const int global_sub_size = mpctx->global_sub_size; 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; return M_PROPERTY_ERROR;
*(char **) arg = malloc(64); *(char **) arg = malloc(64);
(*(char **) arg)[63] = 0; (*(char **) arg)[63] = 0;
sub_name = 0; char *sub_name = NULL;
if (mpctx->subdata) if (mpctx->subdata)
sub_name = mpctx->subdata->filename; sub_name = mpctx->subdata->filename;
#ifdef CONFIG_ASS #ifdef CONFIG_ASS
if (ass_track && ass_track->name) if (mpctx->osd->ass_track)
sub_name = ass_track->name; sub_name = mpctx->osd->ass_track->name;
#endif #endif
if (!sub_name && mpctx->subdata)
sub_name = mpctx->subdata->filename;
if (sub_name) { if (sub_name) {
const char *tmp = mp_basename(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; reset_spu = 1;
d_sub->id = -2; d_sub->id = -2;
} }
#ifdef CONFIG_ASS mpctx->osd->ass_track = NULL;
ass_track = 0;
#endif
if (source == SUB_SOURCE_VOBSUB) { if (source == SUB_SOURCE_VOBSUB) {
vobsub_id = vobsub_get_id_by_index(vo_vobsub, source_pos); 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; mpctx->set_of_sub_pos = source_pos;
#ifdef CONFIG_ASS #ifdef CONFIG_ASS
if (opts->ass_enabled && mpctx->set_of_ass_tracks[mpctx->set_of_sub_pos]) 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 else
#endif #endif
{ {
@ -1693,7 +1692,7 @@ static int mp_property_sub(m_option_t *prop, int action, void *arg,
init_vo_spudec(mpctx); init_vo_spudec(mpctx);
#ifdef CONFIG_ASS #ifdef CONFIG_ASS
else if (opts->ass_enabled) else if (opts->ass_enabled)
ass_track = sh->ass_track; mpctx->osd->ass_track = sh->ass_track;
#endif #endif
} else { } else {
d_sub->id = -2; 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) { if (mpctx->set_of_sub_pos >= start && mpctx->set_of_sub_pos < end) {
mpctx->global_sub_pos = -2; mpctx->global_sub_pos = -2;
mpctx->subdata = NULL; mpctx->subdata = NULL;
#ifdef CONFIG_ASS mpctx->osd->ass_track = NULL;
ass_track = NULL;
#endif
mp_input_queue_cmd(mpctx->input, mp_input_parse_cmd("sub_select")); mp_input_queue_cmd(mpctx->input, mp_input_parse_cmd("sub_select"));
} else if (mpctx->set_of_sub_pos >= end) { } else if (mpctx->set_of_sub_pos >= end) {
mpctx->set_of_sub_pos -= count; 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; int movement = cmd->args[0].v.i;
step_sub(mpctx->subdata, mpctx->video_pts, movement); step_sub(mpctx->subdata, mpctx->video_pts, movement);
#ifdef CONFIG_ASS #ifdef CONFIG_ASS
if (ass_track) if (mpctx->osd->ass_track)
sub_delay += sub_delay +=
ass_step_sub(ass_track, ass_step_sub(mpctx->osd->ass_track,
(mpctx->video_pts + (mpctx->video_pts +
sub_delay) * 1000 + .5, movement) / 1000.; sub_delay) * 1000 + .5, movement) / 1000.;
#endif #endif

View File

@ -107,8 +107,8 @@ typedef struct vf_seteq_s
#define VFCTRL_DRAW_EOSD 16 /* Render EOSD */ #define VFCTRL_DRAW_EOSD 16 /* Render EOSD */
#define VFCTRL_SET_DEINTERLACE 18 /* Set deinterlacing status */ #define VFCTRL_SET_DEINTERLACE 18 /* Set deinterlacing status */
#define VFCTRL_GET_DEINTERLACE 19 /* Get deinterlacing status */ #define VFCTRL_GET_DEINTERLACE 19 /* Get deinterlacing status */
/* Hack to make the OSD state object available to vf_expand which accesses /* Hack to make the OSD state object available to vf_expand and vf_ass which
* the OSD state outside of normal OSD draw time. */ * access OSD/subtitle state outside of normal OSD draw time. */
#define VFCTRL_SET_OSD_OBJ 20 #define VFCTRL_SET_OSD_OBJ 20
#define VFCTRL_REDRAW_OSD 21 /* Change user-visible OSD immediately */ #define VFCTRL_REDRAW_OSD 21 /* Change user-visible OSD immediately */
#define VFCTRL_SET_YUV_COLORSPACE 22 #define VFCTRL_SET_YUV_COLORSPACE 22

View File

@ -33,6 +33,7 @@
#include "img_format.h" #include "img_format.h"
#include "mp_image.h" #include "mp_image.h"
#include "vf.h" #include "vf.h"
#include "libvo/sub.h"
#include "libvo/fastmemcpy.h" #include "libvo/fastmemcpy.h"
@ -59,6 +60,7 @@ static const struct vf_priv_s {
// 0 = insert always // 0 = insert always
int auto_insert; int auto_insert;
struct osd_state *osd;
ASS_Renderer *ass_priv; ASS_Renderer *ass_priv;
unsigned char *planes[3]; unsigned char *planes[3];
@ -68,9 +70,7 @@ static const struct vf_priv_s {
} *line_limits; } *line_limits;
} vf_priv_dflt; } vf_priv_dflt;
extern ASS_Track *ass_track;
extern float sub_delay; extern float sub_delay;
extern int sub_visibility;
static int config(struct vf_instance *vf, static int config(struct vf_instance *vf,
int width, int height, int d_width, int d_height, 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) static int put_image(struct vf_instance *vf, mp_image_t *mpi, double pts)
{ {
ASS_Image *images = 0; 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)) && (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); (pts + sub_delay) * 1000 + .5, NULL);
prepare_image(vf, mpi); 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) static int control(vf_instance_t *vf, int request, void *data)
{ {
switch (request) { switch (request) {
case VFCTRL_SET_OSD_OBJ:
vf->priv->osd = data;
break;
case VFCTRL_INIT_EOSD: case VFCTRL_INIT_EOSD:
vf->priv->ass_priv = ass_renderer_init((ASS_Library *)data); vf->priv->ass_priv = ass_renderer_init((ASS_Library *)data);
if (!vf->priv->ass_priv) if (!vf->priv->ass_priv)

View File

@ -29,14 +29,11 @@
#include "libvo/video_out.h" #include "libvo/video_out.h"
#ifdef CONFIG_ASS
#include "ass_mp.h" #include "ass_mp.h"
extern ASS_Track *ass_track; #include "libvo/sub.h"
#endif
//===========================================================================// //===========================================================================//
extern int sub_visibility;
extern float sub_delay; extern float sub_delay;
struct vf_priv_s { struct vf_priv_s {
@ -141,10 +138,12 @@ static int control(struct vf_instance *vf, int request, void* data)
} }
case VFCTRL_DRAW_EOSD: case VFCTRL_DRAW_EOSD:
{ {
struct osd_state *osd = data;
mp_eosd_images_t images = {NULL, 2}; mp_eosd_images_t images = {NULL, 2};
double pts = video_out->next_pts; double pts = video_out->next_pts;
if (!video_out->config_ok || !vf->priv->ass_priv) return CONTROL_FALSE; 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; mp_eosd_res_t res;
memset(&res, 0, sizeof(res)); memset(&res, 0, sizeof(res));
if (vo_control(video_out, VOCTRL_GET_EOSD_RES, &res) == VO_TRUE) { 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); 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) if (!vf->priv->prev_visibility)
images.changed = 2; images.changed = 2;
vf->priv->prev_visibility = 1; vf->priv->prev_visibility = 1;

View File

@ -69,6 +69,7 @@ typedef struct mp_osd_obj_s {
struct osd_state { struct osd_state {
unsigned char osd_text[128]; unsigned char osd_text[128];
struct font_desc *sub_font; struct font_desc *sub_font;
struct ass_track *ass_track;
}; };
#include "subreader.h" #include "subreader.h"

View File

@ -19,8 +19,6 @@
#ifndef MPLAYER_MPCOMMON_H #ifndef MPLAYER_MPCOMMON_H
#define MPLAYER_MPCOMMON_H #define MPLAYER_MPCOMMON_H
extern struct ass_track *ass_track;
extern const char *mplayer_version; extern const char *mplayer_version;
#endif /* MPLAYER_MPCOMMON_H */ #endif /* MPLAYER_MPCOMMON_H */

View File

@ -335,9 +335,6 @@ int subcc_enabled=0;
int suboverlap_enabled = 1; int suboverlap_enabled = 1;
#include "ass_mp.h" #include "ass_mp.h"
#ifdef CONFIG_ASS
ASS_Track *ass_track = 0; // current track to render
#endif
char* current_module=NULL; // for debugging char* current_module=NULL; // for debugging
@ -1949,10 +1946,10 @@ void update_subtitles(struct MPContext *mpctx, double refpts,
#ifdef CONFIG_ASS #ifdef CONFIG_ASS
if (opts->ass_enabled) { if (opts->ass_enabled) {
sh_sub_t* sh = d_sub->sh; sh_sub_t* sh = d_sub->sh;
ass_track = sh ? sh->ass_track : NULL; mpctx->osd->ass_track = sh ? sh->ass_track : NULL;
if (!ass_track) continue; if (!mpctx->osd->ass_track) continue;
if (type == 'a') { // ssa/ass subs with libass 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)(subpts*1000 + 0.5),
(long long)((endpts-subpts)*1000 + 0.5)); (long long)((endpts-subpts)*1000 + 0.5));
} else { // plaintext subs with libass } 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); sub_add_text(&tmp_subs, packet, len, endpts);
tmp_subs.start = subpts * 100; tmp_subs.start = subpts * 100;
tmp_subs.end = endpts * 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); 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_teletext(sh_video, mpctx->demuxer, 0);
update_osd_msg(mpctx); update_osd_msg(mpctx);
struct vf_instance *vf = sh_video->vfilter; 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); vf->control(vf, VFCTRL_DRAW_OSD, mpctx->osd);
vo_osd_changed(0); vo_osd_changed(0);
@ -4944,7 +4941,7 @@ if(mpctx->set_of_sub_size > 0) {
mpctx->vo_sub_last = vo_sub=NULL; mpctx->vo_sub_last = vo_sub=NULL;
mpctx->subdata=NULL; mpctx->subdata=NULL;
#ifdef CONFIG_ASS #ifdef CONFIG_ASS
ass_track = NULL; mpctx->osd->ass_track = NULL;
if(ass_library) if(ass_library)
ass_clear_fonts(ass_library); ass_clear_fonts(ass_library);
#endif #endif