changeset 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 45966266392b
children 47c6a74eba0f
files Makefile libmpcodecs/dec_video.c libmpcodecs/vf_ass.c libmpcodecs/vf_vo.c mencoder.c mplayer.c
diffstat 6 files changed, 27 insertions(+), 56 deletions(-) [+]
line wrap: on
line diff
--- a/Makefile	Sun Aug 22 23:38:40 2010 +0000
+++ b/Makefile	Mon Aug 23 19:13:05 2010 +0000
@@ -336,6 +336,7 @@
               codec-cfg.c \
               cpudetect.c \
               edl.c \
+              eosd.c \
               find_sub.c \
               fmt-conversion.c \
               m_config.c \
--- a/libmpcodecs/dec_video.c	Sun Aug 22 23:38:40 2010 +0000
+++ b/libmpcodecs/dec_video.c	Mon Aug 23 19:13:05 2010 +0000
@@ -39,6 +39,7 @@
 #include "libmpdemux/stheader.h"
 #include "vd.h"
 #include "vf.h"
+#include "eosd.h"
 
 #include "dec_video.h"
 
@@ -185,6 +186,7 @@
         dlclose(sh_video->dec_handle);
 #endif
     vf_uninit_filter_chain(sh_video->vfilter);
+    eosd_uninit();
     sh_video->initialized = 0;
 }
 
--- a/libmpcodecs/vf_ass.c	Sun Aug 22 23:38:40 2010 +0000
+++ b/libmpcodecs/vf_ass.c	Mon Aug 23 19:13:05 2010 +0000
@@ -39,10 +39,12 @@
 
 #include "libvo/fastmemcpy.h"
 #include "libvo/sub.h"
+#include "libvo/video_out.h"
 #include "m_option.h"
 #include "m_struct.h"
 
 #include "libass/ass_mp.h"
+#include "eosd.h"
 
 #define _r(c)  ((c)>>24)
 #define _g(c)  (((c)>>16)&0xFF)
@@ -62,8 +64,6 @@
 	// 0 = insert always
 	int auto_insert;
 
-	ASS_Renderer* ass_priv;
-
 	unsigned char* planes[3];
 	unsigned char* dirty_rows;
 } vf_priv_dflt;
@@ -73,6 +73,8 @@
 	int width, int height, int d_width, int d_height,
 	unsigned int flags, unsigned int outfmt)
 {
+	mp_eosd_res_t res = {0};
+
 	if (outfmt == IMGFMT_IF09) return 0;
 
 	vf->priv->outh = height + ass_top_margin + ass_bottom_margin;
@@ -87,10 +89,13 @@
 	vf->priv->planes[2] = malloc(vf->priv->outw * vf->priv->outh);
 	vf->priv->dirty_rows = malloc(vf->priv->outh);
 
-	if (vf->priv->ass_priv) {
-		ass_configure(vf->priv->ass_priv, vf->priv->outw, vf->priv->outh, 0);
-		ass_set_aspect_ratio(vf->priv->ass_priv, 1, 1);
-	}
+	res.w    = vf->priv->outw;
+	res.h    = vf->priv->outh;
+	res.srcw = width;
+	res.srch = height;
+	res.mt   = ass_top_margin;
+	res.mb   = ass_bottom_margin;
+	eosd_configure(&res, 0);
 
 	return vf_next_config(vf, vf->priv->outw, vf->priv->outh, d_width, d_height, flags, outfmt);
 }
@@ -324,10 +329,7 @@
 
 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 && (pts != MP_NOPTS_VALUE))
-		images = ass_mp_render_frame(vf->priv->ass_priv, ass_track, (pts+sub_delay) * 1000 + .5, NULL);
-
+	ASS_Image* images = eosd_render_frame(pts, NULL);
 	prepare_image(vf, mpi);
 	if (images) render_frame(vf, mpi, images);
 
@@ -349,21 +351,15 @@
 {
 	switch (request) {
 	case VFCTRL_INIT_EOSD:
-		vf->priv->ass_priv = ass_renderer_init((ASS_Library*)data);
-		if (!vf->priv->ass_priv) return CONTROL_FALSE;
-		ass_configure_fonts(vf->priv->ass_priv);
 		return CONTROL_TRUE;
 	case VFCTRL_DRAW_EOSD:
-		if (vf->priv->ass_priv) return CONTROL_TRUE;
-		break;
+		return CONTROL_TRUE;
 	}
 	return vf_next_control(vf, request, data);
 }
 
 static void uninit(struct vf_instance *vf)
 {
-	if (vf->priv->ass_priv)
-		ass_renderer_done(vf->priv->ass_priv);
 	if (vf->priv->planes[1])
 		free(vf->priv->planes[1]);
 	if (vf->priv->planes[2])
--- a/libmpcodecs/vf_vo.c	Sun Aug 22 23:38:40 2010 +0000
+++ b/libmpcodecs/vf_vo.c	Mon Aug 23 19:13:05 2010 +0000
@@ -38,10 +38,6 @@
 struct vf_priv_s {
     double pts;
     const vo_functions_t *vo;
-#ifdef CONFIG_ASS
-    ASS_Renderer* ass_priv;
-    int prev_visibility;
-#endif
 };
 #define video_out (vf->priv->vo)
 
@@ -81,11 +77,6 @@
     if(config_video_out(video_out,width,height,d_width,d_height,flags,"MPlayer",outfmt))
 	return 0;
 
-#ifdef CONFIG_ASS
-    if (vf->priv->ass_priv)
-	ass_configure(vf->priv->ass_priv, width, height, !!(vf->default_caps & VFCAP_EOSD_UNSCALED));
-#endif
-
     ++vo_config_count;
     return 1;
 }
@@ -130,34 +121,17 @@
 #ifdef CONFIG_ASS
     case VFCTRL_INIT_EOSD:
     {
-        vf->priv->ass_priv = ass_renderer_init((ASS_Library*)data);
-        if (!vf->priv->ass_priv) return CONTROL_FALSE;
-        ass_configure_fonts(vf->priv->ass_priv);
-        vf->priv->prev_visibility = 0;
         return CONTROL_TRUE;
     }
     case VFCTRL_DRAW_EOSD:
     {
         EOSD_ImageList images = {NULL, 2};
+        mp_eosd_res_t res = {0};
         double pts = vf->priv->pts;
-        if (!vo_config_count || !vf->priv->ass_priv) return CONTROL_FALSE;
-        if (sub_visibility && vf->priv->ass_priv && ass_track && (pts != MP_NOPTS_VALUE)) {
-            mp_eosd_res_t res;
-            memset(&res, 0, sizeof(res));
-            if (video_out->control(VOCTRL_GET_EOSD_RES, &res) == VO_TRUE) {
-                double dar = (double) (res.w - res.ml - res.mr) / (res.h - res.mt - res.mb);
-                ass_set_frame_size(vf->priv->ass_priv, res.w, res.h);
-                ass_set_margins(vf->priv->ass_priv, res.mt, res.mb, res.ml, res.mr);
-                ass_set_aspect_ratio(vf->priv->ass_priv, dar, (double)res.srcw/res.srch);
-            }
-
-            images.imgs = ass_mp_render_frame(vf->priv->ass_priv, ass_track, (pts+sub_delay) * 1000 + .5, &images.changed);
-            if (!vf->priv->prev_visibility)
-                images.changed = 2;
-            vf->priv->prev_visibility = 1;
-        } else
-            vf->priv->prev_visibility = 0;
-        vf->priv->prev_visibility = sub_visibility;
+        if (!vo_config_count) return CONTROL_FALSE;
+        if (video_out->control(VOCTRL_GET_EOSD_RES, &res) == VO_TRUE)
+            eosd_configure(&res, !!(vf->default_caps & VFCAP_EOSD_UNSCALED));
+        images.imgs = eosd_render_frame(pts, &images.changed);
         return (video_out->control(VOCTRL_DRAW_EOSD, &images) == VO_TRUE) ? CONTROL_TRUE : CONTROL_FALSE;
     }
 #endif
@@ -222,13 +196,7 @@
 
 static void uninit(struct vf_instance *vf)
 {
-    if (vf->priv) {
-#ifdef CONFIG_ASS
-        if (vf->priv->ass_priv)
-            ass_renderer_done(vf->priv->ass_priv);
-#endif
         free(vf->priv);
-    }
 }
 //===========================================================================//
 
--- a/mencoder.c	Sun Aug 22 23:38:40 2010 +0000
+++ b/mencoder.c	Mon Aug 23 19:13:05 2010 +0000
@@ -97,6 +97,7 @@
 #include "path.h"
 #include "spudec.h"
 #include "vobsub.h"
+#include "eosd.h"
 
 
 int vo_doublebuffering=0;
@@ -1052,10 +1053,11 @@
 #endif
 
     sh_video->vfilter=append_filters(sh_video->vfilter);
+  eosd_init(sh_video->vfilter);
 
 #ifdef CONFIG_ASS
   if (ass_enabled)
-    ((vf_instance_t *)sh_video->vfilter)->control(sh_video->vfilter, VFCTRL_INIT_EOSD, ass_library);
+    eosd_ass_init(ass_library);
 #endif
 
 // after reading video params we should load subtitles because
--- a/mplayer.c	Sun Aug 22 23:38:40 2010 +0000
+++ b/mplayer.c	Mon Aug 23 19:13:05 2010 +0000
@@ -124,6 +124,7 @@
 #include "spudec.h"
 #include "subreader.h"
 #include "vobsub.h"
+#include "eosd.h"
 
 #ifdef CONFIG_X11
 #include "libvo/x11_common.h"
@@ -2322,10 +2323,11 @@
 #endif
 
   sh_video->vfilter=append_filters(sh_video->vfilter);
+  eosd_init(sh_video->vfilter);
 
 #ifdef CONFIG_ASS
   if (ass_enabled)
-    ((vf_instance_t *)sh_video->vfilter)->control(sh_video->vfilter, VFCTRL_INIT_EOSD, ass_library);
+    eosd_ass_init(ass_library);
 #endif
 
   current_module="init_video_codec";