Added code to render subtitles with the freetype module (disabled by default).
authorSigmund Augdal Helberg <sigmunau@videolan.org>
Sun, 11 May 2003 14:33:32 +0000 (14:33 +0000)
committerSigmund Augdal Helberg <sigmunau@videolan.org>
Sun, 11 May 2003 14:33:32 +0000 (14:33 +0000)
To test it out define USE_FREETYPE in the top of modules/demux/util/sub.c
and  modules/codec/spudec/text.c and run with --filter osdtext

modules/codec/spudec/text.c
modules/demux/util/sub.c

index 656f4b5..3f0a6a6 100644 (file)
@@ -2,7 +2,7 @@
  * text.c: text subtitles parser
  *****************************************************************************
  * Copyright (C) 2000-2001 VideoLAN
- * $Id: text.c,v 1.4 2003/01/30 16:36:04 gbazin Exp $
+ * $Id: text.c,v 1.5 2003/05/11 14:33:32 sigmunau Exp $
  *
  * Authors: Gildas Bazin <gbazin@netcourrier.com>
  *
@@ -21,6 +21,8 @@
  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
  *****************************************************************************/
 
+/* define USE_FREETYPE here to disable the old style subtitles */
+
 /*****************************************************************************
  * Preamble
  *****************************************************************************/
@@ -42,9 +44,9 @@
  *****************************************************************************/
 void E_(ParseText)( spudec_thread_t *p_spudec, subtitler_font_t *p_font )
 {
+#if !defined(USE_FREETYPE)
     char         * psz_subtitle;
     mtime_t        i_pts, i_dts;
-
     /* We cannot display a subpicture with no date */
     i_pts = p_spudec->bit_stream.p_pes->i_pts;
     i_dts = p_spudec->bit_stream.p_pes->i_dts;
@@ -82,4 +84,7 @@ void E_(ParseText)( spudec_thread_t *p_spudec, subtitler_font_t *p_font )
      * p_spudec->bit_stream->p_data is valid since we check later on
      * for b_die and b_error */
     NextDataPacket( p_spudec->p_fifo, &p_spudec->bit_stream );
+#else
+    msleep(10);
+#endif
 }
index 4b31674..1731c2b 100644 (file)
@@ -2,7 +2,7 @@
  * sub.c
  *****************************************************************************
  * Copyright (C) 1999-2001 VideoLAN
- * $Id: sub.c,v 1.13 2003/05/05 22:23:37 gbazin Exp $
+ * $Id: sub.c,v 1.14 2003/05/11 14:33:32 sigmunau Exp $
  *
  * Authors: Laurent Aimar <fenrir@via.ecp.fr>
  *
@@ -21,6 +21,8 @@
  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
  *****************************************************************************/
 
+/* define USE_FREETYPE to use freetype for subtitles */
+
 /*****************************************************************************
  * Preamble
  *****************************************************************************/
@@ -31,7 +33,9 @@
 
 #include <vlc/vlc.h>
 #include <vlc/input.h>
-
+#if defined(USE_FREETYPE)
+#include <osd.h>
+#endif
 #include "video.h"
 
 #include "sub.h"
@@ -442,7 +446,9 @@ static int  sub_open ( subtitle_demux_t *p_sub,
  *****************************************************************************/
 static int  sub_demux( subtitle_demux_t *p_sub, mtime_t i_maxdate )
 {
-
+#if defined(USE_FREETYPE)
+    vlc_object_t *p_vout = NULL;
+#endif
     if( p_sub->p_es->p_decoder_fifo && !p_sub->i_previously_selected )
     {
         p_sub->i_previously_selected = 1;
@@ -462,6 +468,9 @@ static int  sub_demux( subtitle_demux_t *p_sub, mtime_t i_maxdate )
         data_packet_t   *p_data;
 
         int i_len;
+#if defined(USE_FREETYPE)
+        p_vout = vlc_object_find( p_sub, VLC_OBJECT_VOUT, FIND_ANYWHERE );
+#endif
 
         i_len = strlen( p_sub->subtitle[p_sub->i_subtitle].psz_text ) + 1;
 
@@ -504,6 +513,35 @@ static int  sub_demux( subtitle_demux_t *p_sub, mtime_t i_maxdate )
         {
             p_pes->i_dts = 0;
         }
+#if defined(USE_FREETYPE)
+        if( p_vout )
+        {
+            vlc_value_t val, lockval;
+            if( var_Get( p_vout, "lock", &lockval ) == VLC_SUCCESS )
+            {
+                int64_t i_tmp;
+                vlc_mutex_lock( lockval.p_address );
+                msg_Dbg( p_sub, "pts "I64Fd" dts " I64Fd, p_pes->i_pts,
+                         p_pes->i_dts );
+                i_tmp = p_pes->i_dts - p_pes->i_pts;
+                val.i_int = OSD_ALIGN_LEFT|OSD_ALIGN_BOTTOM;
+                var_Set( p_vout, "flags", val ); 
+                val.time.i_low = (int)(p_pes->i_pts+p_sub->p_input->i_pts_delay);
+                val.time.i_high = (int)( p_pes->i_pts >> 32 );
+                var_Set( p_vout, "start-date", val ); 
+                val.time.i_low = (int)(p_pes->i_dts + p_sub->p_input->i_pts_delay);
+                val.time.i_high = (int)( p_pes->i_dts >> 32 );
+                var_Set( p_vout, "stop-date", val ); 
+                val.i_int = 20;
+                var_Set( p_vout, "x-margin", val ); 
+                val.i_int = 20;
+                var_Set( p_vout, "y-margin", val );
+                val.psz_string = p_sub->subtitle[p_sub->i_subtitle].psz_text;
+                var_Set( p_vout, "string", val );
+                vlc_mutex_unlock( lockval.p_address );
+            }
+        }
+#endif
         p_pes->i_nb_data = 1;
         p_pes->p_first =
             p_pes->p_last = p_data;
@@ -524,6 +562,12 @@ static int  sub_demux( subtitle_demux_t *p_sub, mtime_t i_maxdate )
 
         p_sub->i_subtitle++;
     }
+#if defined(USE_FREETYPE)
+    if ( p_vout )
+    {
+        vlc_object_release( p_vout );
+    }
+#endif
     return( 0 );
 }