]> git.sesse.net Git - vlc/commitdiff
* input: handle also SPU in es_out_Add (and fix a bad lock).
authorLaurent Aimar <fenrir@videolan.org>
Thu, 13 Nov 2003 13:31:12 +0000 (13:31 +0000)
committerLaurent Aimar <fenrir@videolan.org>
Thu, 13 Nov 2003 13:31:12 +0000 (13:31 +0000)
 * sub: use es_out_Add (and that give a proper solution for multiple tracks)
        fixed seeking with sub. (pf_demux was called in Seek instead of
        pf_seek ...)

modules/demux/util/sub.c
modules/demux/util/sub.h
src/input/input.c

index 624bfd0f867608574301dcc37e6c119537de1730..67493e91b986f1dc1d364a8024db7223aadd4ef9 100644 (file)
@@ -2,7 +2,7 @@
  * sub.c
  *****************************************************************************
  * Copyright (C) 1999-2003 VideoLAN
- * $Id: sub.c,v 1.35 2003/11/05 00:39:16 gbazin Exp $
+ * $Id: sub.c,v 1.36 2003/11/13 13:31:12 fenrir Exp $
  *
  * Authors: Laurent Aimar <fenrir@via.ecp.fr>
  *
@@ -237,18 +237,18 @@ static char * local_stristr( char *psz_big, char *psz_little)
 
     while (*p_pos)
     {
-       if (toupper(*p_pos) == toupper(*psz_little))
+        if (toupper(*p_pos) == toupper(*psz_little))
         {
-           char * psz_cur1 = p_pos + 1;
-           char * psz_cur2 = psz_little + 1;
-           while (*psz_cur1 && *psz_cur2 && toupper(*psz_cur1) == toupper(*psz_cur2))
+            char * psz_cur1 = p_pos + 1;
+            char * psz_cur2 = psz_little + 1;
+            while (*psz_cur1 && *psz_cur2 && toupper(*psz_cur1) == toupper(*psz_cur2))
             {
-               psz_cur1++;
-               psz_cur2++;
-           }
-           if (!*psz_cur2) return p_pos;
-       }
-       p_pos++;
+                psz_cur1++;
+                psz_cur2++;
+            }
+            if (!*psz_cur2) return p_pos;
+        }
+        p_pos++;
     }
     return NULL;
 }
@@ -264,6 +264,7 @@ static int  sub_open ( subtitle_demux_t *p_sub,
 {
     text_t  txt;
     vlc_value_t val;
+    es_format_t  fmt;
 
     int     i;
     int     i_sub_type;
@@ -469,35 +470,26 @@ static int  sub_open ( subtitle_demux_t *p_sub,
     }
 
     /* *** add subtitle ES *** */
-    vlc_mutex_lock( &p_input->stream.stream_lock );
-    p_sub->p_es = input_AddES( p_input, p_input->stream.p_selected_program,
-                               0xff - i_track_id,    /* FIXME */
-                               SPU_ES, NULL, 0 );
-    vlc_mutex_unlock( &p_input->stream.stream_lock );
-
-    p_sub->p_es->i_stream_id = 0xff - i_track_id;    /* FIXME */
-    
-    if( p_sub->psz_header != NULL )
-    {
-        p_sub->p_es->p_demux_data = malloc( sizeof( subtitle_data_t ) );
-        p_sub->p_es->p_demux_data->psz_header = strdup( p_sub->psz_header );
-        free( p_sub->psz_header );
-    }
-
     if( p_sub->i_sub_type == SUB_TYPE_VOBSUB )
     {
-        p_sub->p_es->i_fourcc    = VLC_FOURCC( 's','p','u',' ' );
-        /* open vobsub file */
+        es_format_Init( &fmt, SPU_ES, VLC_FOURCC( 's','p','u',' ' ) );
     }
     else if( p_sub->i_sub_type == SUB_TYPE_SSA1 ||
              p_sub->i_sub_type == SUB_TYPE_SSA2_4 )
     {
-        p_sub->p_es->i_fourcc    = VLC_FOURCC( 's','s','a',' ' );
+        es_format_Init( &fmt, SPU_ES, VLC_FOURCC( 's','s','a',' ' ) );
     }
     else
     {
-        p_sub->p_es->i_fourcc    = VLC_FOURCC( 's','u','b','t' );
+        es_format_Init( &fmt, SPU_ES, VLC_FOURCC( 's','u','b','t' ) );
     }
+    if( p_sub->psz_header != NULL )
+    {
+        fmt.i_extra_type = ES_EXTRA_TYPE_SUBHEADER;
+        fmt.i_extra = strlen( p_sub->psz_header ) + 1;
+        fmt.p_extra = strdup( p_sub->psz_header );
+    }
+    p_sub->p_es = es_out_Add( p_input->p_es_out, &fmt );
 
     p_sub->i_previously_selected = 0;
     return VLC_SUCCESS;
@@ -508,13 +500,17 @@ static int  sub_open ( subtitle_demux_t *p_sub,
  *****************************************************************************/
 static int  sub_demux( subtitle_demux_t *p_sub, mtime_t i_maxdate )
 {
-    if( p_sub->p_es->p_decoder_fifo && !p_sub->i_previously_selected )
+    input_thread_t *p_input = p_sub->p_input;
+    vlc_bool_t     b;
+
+    es_out_Control( p_input->p_es_out, ES_OUT_GET_SELECT, p_sub->p_es, &b );
+    if( b && !p_sub->i_previously_selected )
     {
         p_sub->i_previously_selected = 1;
         p_sub->pf_seek( p_sub, i_maxdate );
         return VLC_SUCCESS;
     }
-    else if( !p_sub->p_es->p_decoder_fifo && p_sub->i_previously_selected )
+    else if( !b && p_sub->i_previously_selected )
     {
         p_sub->i_previously_selected = 0;
         return VLC_SUCCESS;
@@ -572,16 +568,16 @@ static int  sub_demux( subtitle_demux_t *p_sub, mtime_t i_maxdate )
 
         p_pes->i_nb_data = 1;
         p_pes->p_first =
-            p_pes->p_last = p_data;
+        p_pes->p_last = p_data;
         p_pes->i_pes_size = i_len;
 
         memcpy( p_data->p_payload_start,
                 p_sub->subtitle[p_sub->i_subtitle].psz_text,
                 i_len );
-        if( p_sub->p_es->p_decoder_fifo && p_pes->i_pts > 0 )
-        {
 
-            input_DecodePES( p_sub->p_es->p_decoder_fifo, p_pes );
+        if( p_pes->i_pts > 0 )
+        {
+            es_out_Send( p_input->p_es_out, p_sub->p_es, p_pes );
         }
         else
         {
@@ -590,7 +586,7 @@ static int  sub_demux( subtitle_demux_t *p_sub, mtime_t i_maxdate )
 
         p_sub->i_subtitle++;
     }
-    return( 0 );
+    return VLC_SUCCESS;
 }
 
 /*****************************************************************************
@@ -605,7 +601,6 @@ static int  sub_seek ( subtitle_demux_t *p_sub, mtime_t i_date )
     {
         p_sub->i_subtitle++;
     }
-
     return( 0 );
 }
 
index 45966f2a84c1af0c376da1d7b22dca26d9d8b18f..7413c7592acf4158349a2ce96cc4c7090f6d1fc1 100644 (file)
@@ -2,15 +2,15 @@
  * sub.h
  *****************************************************************************
  * Copyright (C) 2001-2003 VideoLAN
- * $Id: sub.h,v 1.10 2003/11/05 00:17:50 hartman Exp $
+ * $Id: sub.h,v 1.11 2003/11/13 13:31:12 fenrir Exp $
  *
  * Authors: Laurent Aimar <fenrir@via.ecp.fr>
- * 
+ *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
  * the Free Software Foundation; either version 2 of the License, or
  * (at your option) any later version.
- * 
+ *
  * This program is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
@@ -40,7 +40,8 @@ typedef struct subtitle_s
 
 } subtitle_t;
 
-typedef struct subtitle_track_s
+#if 0
+typedef struct
 {
     int             i_track_id;
     char            *psz_header;
@@ -51,24 +52,24 @@ typedef struct subtitle_track_s
 
     int             i_previously_selected; /* to make pf_seek */
     es_descriptor_t *p_es;
-    
+
 } subtitle_track_t;
+#endif
 
 typedef struct subtitle_demux_s
 {
     VLC_COMMON_MEMBERS
-    
+
     module_t        *p_module;
-    
-    int     (*pf_open) ( struct subtitle_demux_s *p_sub, 
-                         input_thread_t*p_input, 
+
+    int     (*pf_open) ( struct subtitle_demux_s *p_sub,
+                         input_thread_t*p_input,
                          char *psz_name,
                          mtime_t i_microsecperframe,
                          int i_track_id );
     int     (*pf_demux)( struct subtitle_demux_s *p_sub, mtime_t i_maxdate );
     int     (*pf_seek) ( struct subtitle_demux_s *p_sub, mtime_t i_date );
     void    (*pf_close)( struct subtitle_demux_s *p_sub );
-    
 
     /* *** private *** */
     input_thread_t      *p_input;
@@ -78,27 +79,17 @@ typedef struct subtitle_demux_s
     int                 i_subtitle;
     int                 i_subtitles;
     subtitle_t          *subtitle;
-    es_descriptor_t     *p_es;
+    es_out_id_t         *p_es;
     int                 i_previously_selected; /* to make pf_seek */
 
-    /*unsigned int     i_tracks;
-    subtitle_track_t   *p_tracks
+    /*unsigned int i_tracks;
+    subtitle_track_t *p_tracks
     */
-    
 
 } subtitle_demux_t;
 
 /*****************************************************************************
- *
- * I made somes wrappers : So use them !
- *  I think you shouldn't need access to subtitle_demux_t members else said
- *  it to me.
- *
- *****************************************************************************/
-
-
-/*****************************************************************************
- * subtitle_New: Start a new subtitle demux instance (but subtitle ES isn't 
+ * subtitle_New: Start a new subtitle demux instance (but subtitle ES isn't
  *               selected by default.
  *****************************************************************************
  * Return: NULL if failed, else a pointer on a new subtitle_demux_t.
@@ -112,46 +103,7 @@ typedef struct subtitle_demux_s
 static inline subtitle_demux_t *subtitle_New( input_thread_t *p_input,
                                               char *psz_name,
                                               mtime_t i_microsecperframe,
-                                              int i_track_id );
-/*****************************************************************************
- * subtitle_Select: Select the related subtitle ES.
- *****************************************************************************/
-static inline void subtitle_Select( subtitle_demux_t *p_sub );
-
-/*****************************************************************************
- * subtitle_Unselect: Unselect the related subtitle ES.
- *****************************************************************************/
-static inline void subtitle_Unselect( subtitle_demux_t *p_sub );
-
-/*****************************************************************************
- * subtitle_Demux: send subtitle to decoder from last date to i_max
- *****************************************************************************/
-static inline int  subtitle_Demux( subtitle_demux_t *p_sub, mtime_t i_max );
-
-/*****************************************************************************
- * subtitle_Seek: Seek to i_date
- *****************************************************************************/
-static inline int  subtitle_Seek( subtitle_demux_t *p_sub, mtime_t i_date );
-
-/*****************************************************************************
- * subtitle_Close: Stop ES decoder and free all memory included p_sub.
- *****************************************************************************/
-static inline void subtitle_Close( subtitle_demux_t *p_sub );
-
-
-
-
-
-/*****************************************************************************/
-/*****************************************************************************/
-/*****************************************************************************/
-
-
-static inline 
-    subtitle_demux_t *subtitle_New( input_thread_t *p_input,
-                                    char *psz_name,
-                                    mtime_t i_microsecperframe,
-                                    int i_track_id )
+                                              int i_track_id )
 {
     subtitle_demux_t *p_sub;
 
@@ -185,37 +137,25 @@ static inline
     return( p_sub );
 }
 
-static inline void subtitle_Select( subtitle_demux_t *p_sub )
-{
-    if( p_sub && p_sub->p_es )
-    {
-        vlc_mutex_lock( &p_sub->p_input->stream.stream_lock );
-        input_SelectES( p_sub->p_input, p_sub->p_es );
-        vlc_mutex_unlock( &p_sub->p_input->stream.stream_lock );
-        p_sub->i_previously_selected = 0;
-    }
-}
-static inline void subtitle_Unselect( subtitle_demux_t *p_sub )
-{
-    if( p_sub && p_sub->p_es )
-    {
-        vlc_mutex_lock( &p_sub->p_input->stream.stream_lock );
-        input_UnselectES( p_sub->p_input, p_sub->p_es );
-        vlc_mutex_unlock( &p_sub->p_input->stream.stream_lock );
-        p_sub->i_previously_selected = 0;
-    }
-}
-
+/*****************************************************************************
+ * subtitle_Demux: send subtitle to decoder from last date to i_max
+ *****************************************************************************/
 static inline int subtitle_Demux( subtitle_demux_t *p_sub, mtime_t i_max )
 {
     return( p_sub->pf_demux( p_sub, i_max ) );
 }
 
+/*****************************************************************************
+ * subtitle_Seek: Seek to i_date
+ *****************************************************************************/
 static inline int subtitle_Seek( subtitle_demux_t *p_sub, mtime_t i_date )
 {
-    return( p_sub->pf_demux( p_sub, i_date ) );
+    return( p_sub->pf_seek( p_sub, i_date ) );
 }
 
+/*****************************************************************************
+ * subtitle_Close: Stop ES decoder and free all memory included p_sub.
+ *****************************************************************************/
 static inline void subtitle_Close( subtitle_demux_t *p_sub )
 {
     msg_Info( p_sub, "subtitle stopped" );
@@ -229,3 +169,4 @@ static inline void subtitle_Close( subtitle_demux_t *p_sub )
         vlc_object_destroy( p_sub );
     }
 }
+
index 7037d63740f5ebf8304aea0ac51b43fbb3f371dc..2690647b16455a7e17fd7d16429105005404d79c 100644 (file)
@@ -4,7 +4,7 @@
  * decoders.
  *****************************************************************************
  * Copyright (C) 1998-2002 VideoLAN
- * $Id: input.c,v 1.253 2003/11/13 12:28:34 fenrir Exp $
+ * $Id: input.c,v 1.254 2003/11/13 13:31:12 fenrir Exp $
  *
  * Authors: Christophe Massiot <massiot@via.ecp.fr>
  *
@@ -745,12 +745,14 @@ static int InitThread( input_thread_t * p_input )
     {
         if( ( p_sub = subtitle_New( p_input, strdup(val.psz_string), i_microsecondperframe, 0 ) ) )
         {
+            /* Select this ES by default */
+            es_out_Control( p_input->p_es_out, ES_OUT_SET_SELECT, p_sub->p_es, VLC_TRUE );
+
             TAB_APPEND( p_input->p_sys->i_sub, p_input->p_sys->sub, p_sub );
-            subtitle_Select( p_sub );
         }
     }
     if( val.psz_string ) free( val.psz_string );
-    
+
     var_Get( p_input, "sub-autodetect-file", &val );
     if( val.b_bool )
     {
@@ -1111,6 +1113,22 @@ static es_out_id_t *EsOutAdd( es_out_t *out, es_format_t *fmt )
             id->p_es->p_bitmapinfoheader = p_bih;
             break;
         }
+        case SPU_ES:
+        {
+            subtitle_data_t *p_sub = malloc( sizeof( subtitle_data_t ) );
+            memset( p_sub, 0, sizeof( subtitle_data_t ) );
+            if( fmt->i_extra > 0 )
+            {
+                if( fmt->i_extra_type == ES_EXTRA_TYPE_SUBHEADER )
+                {
+                    p_sub->psz_header = malloc( fmt->i_extra  );
+                    memcpy( p_sub->psz_header, fmt->p_extra , fmt->i_extra );
+                }
+            }
+            /* FIXME beuuuuuurk */
+            id->p_es->p_demux_data = p_sub;
+            break;
+        }
         default:
             break;
     }
@@ -1238,19 +1256,21 @@ static int EsOutControl( es_out_t *out, int i_query, va_list args )
     switch( i_query )
     {
         case ES_OUT_SET_SELECT:
+            vlc_mutex_lock( &p_sys->p_input->stream.stream_lock );
             id = (es_out_id_t*) va_arg( args, es_out_id_t * );
             b = (vlc_bool_t) va_arg( args, vlc_bool_t );
             if( b && id->p_es->p_decoder_fifo == NULL )
             {
                 input_SelectES( p_sys->p_input, id->p_es );
+                vlc_mutex_unlock( &p_sys->p_input->stream.stream_lock );
                 return id->p_es->p_decoder_fifo ? VLC_SUCCESS : VLC_EGENERIC;
             }
             else if( !b && id->p_es->p_decoder_fifo )
             {
                 input_UnselectES( p_sys->p_input, id->p_es );
+                vlc_mutex_unlock( &p_sys->p_input->stream.stream_lock );
+                return VLC_SUCCESS;
             }
-            return VLC_SUCCESS;
-
         case ES_OUT_GET_SELECT:
             id = (es_out_id_t*) va_arg( args, es_out_id_t * );
             pb = (vlc_bool_t*) va_arg( args, vlc_bool_t * );