Commit 55320a77 authored by Laurent Aimar's avatar Laurent Aimar

* input: handle also SPU in es_out_Add (and fix a bad lock).

 * 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 ...)
parent 3f71e771
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* sub.c * sub.c
***************************************************************************** *****************************************************************************
* Copyright (C) 1999-2003 VideoLAN * 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> * Authors: Laurent Aimar <fenrir@via.ecp.fr>
* *
...@@ -264,6 +264,7 @@ static int sub_open ( subtitle_demux_t *p_sub, ...@@ -264,6 +264,7 @@ static int sub_open ( subtitle_demux_t *p_sub,
{ {
text_t txt; text_t txt;
vlc_value_t val; vlc_value_t val;
es_format_t fmt;
int i; int i;
int i_sub_type; int i_sub_type;
...@@ -469,35 +470,26 @@ static int sub_open ( subtitle_demux_t *p_sub, ...@@ -469,35 +470,26 @@ static int sub_open ( subtitle_demux_t *p_sub,
} }
/* *** add subtitle ES *** */ /* *** 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 ) if( p_sub->i_sub_type == SUB_TYPE_VOBSUB )
{ {
p_sub->p_es->i_fourcc = VLC_FOURCC( 's','p','u',' ' ); es_format_Init( &fmt, SPU_ES, VLC_FOURCC( 's','p','u',' ' ) );
/* open vobsub file */
} }
else if( p_sub->i_sub_type == SUB_TYPE_SSA1 || else if( p_sub->i_sub_type == SUB_TYPE_SSA1 ||
p_sub->i_sub_type == SUB_TYPE_SSA2_4 ) 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 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; p_sub->i_previously_selected = 0;
return VLC_SUCCESS; return VLC_SUCCESS;
...@@ -508,13 +500,17 @@ static int sub_open ( subtitle_demux_t *p_sub, ...@@ -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 ) 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->i_previously_selected = 1;
p_sub->pf_seek( p_sub, i_maxdate ); p_sub->pf_seek( p_sub, i_maxdate );
return VLC_SUCCESS; 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; p_sub->i_previously_selected = 0;
return VLC_SUCCESS; return VLC_SUCCESS;
...@@ -578,10 +574,10 @@ static int sub_demux( subtitle_demux_t *p_sub, mtime_t i_maxdate ) ...@@ -578,10 +574,10 @@ static int sub_demux( subtitle_demux_t *p_sub, mtime_t i_maxdate )
memcpy( p_data->p_payload_start, memcpy( p_data->p_payload_start,
p_sub->subtitle[p_sub->i_subtitle].psz_text, p_sub->subtitle[p_sub->i_subtitle].psz_text,
i_len ); 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 else
{ {
...@@ -590,7 +586,7 @@ static int sub_demux( subtitle_demux_t *p_sub, mtime_t i_maxdate ) ...@@ -590,7 +586,7 @@ static int sub_demux( subtitle_demux_t *p_sub, mtime_t i_maxdate )
p_sub->i_subtitle++; 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 ) ...@@ -605,7 +601,6 @@ static int sub_seek ( subtitle_demux_t *p_sub, mtime_t i_date )
{ {
p_sub->i_subtitle++; p_sub->i_subtitle++;
} }
return( 0 ); return( 0 );
} }
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* sub.h * sub.h
***************************************************************************** *****************************************************************************
* Copyright (C) 2001-2003 VideoLAN * 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> * Authors: Laurent Aimar <fenrir@via.ecp.fr>
* *
...@@ -40,7 +40,8 @@ typedef struct subtitle_s ...@@ -40,7 +40,8 @@ typedef struct subtitle_s
} subtitle_t; } subtitle_t;
typedef struct subtitle_track_s #if 0
typedef struct
{ {
int i_track_id; int i_track_id;
char *psz_header; char *psz_header;
...@@ -53,6 +54,7 @@ typedef struct subtitle_track_s ...@@ -53,6 +54,7 @@ typedef struct subtitle_track_s
es_descriptor_t *p_es; es_descriptor_t *p_es;
} subtitle_track_t; } subtitle_track_t;
#endif
typedef struct subtitle_demux_s typedef struct subtitle_demux_s
{ {
...@@ -69,7 +71,6 @@ typedef struct subtitle_demux_s ...@@ -69,7 +71,6 @@ typedef struct subtitle_demux_s
int (*pf_seek) ( struct subtitle_demux_s *p_sub, mtime_t i_date ); int (*pf_seek) ( struct subtitle_demux_s *p_sub, mtime_t i_date );
void (*pf_close)( struct subtitle_demux_s *p_sub ); void (*pf_close)( struct subtitle_demux_s *p_sub );
/* *** private *** */ /* *** private *** */
input_thread_t *p_input; input_thread_t *p_input;
int i_sub_type; int i_sub_type;
...@@ -78,25 +79,15 @@ typedef struct subtitle_demux_s ...@@ -78,25 +79,15 @@ typedef struct subtitle_demux_s
int i_subtitle; int i_subtitle;
int i_subtitles; int i_subtitles;
subtitle_t *subtitle; subtitle_t *subtitle;
es_descriptor_t *p_es; es_out_id_t *p_es;
int i_previously_selected; /* to make pf_seek */ int i_previously_selected; /* to make pf_seek */
/*unsigned int i_tracks; /*unsigned int i_tracks;
subtitle_track_t *p_tracks subtitle_track_t *p_tracks
*/ */
} subtitle_demux_t; } 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. * selected by default.
...@@ -110,45 +101,6 @@ typedef struct subtitle_demux_s ...@@ -110,45 +101,6 @@ typedef struct subtitle_demux_s
* *
*****************************************************************************/ *****************************************************************************/
static inline subtitle_demux_t *subtitle_New( input_thread_t *p_input, 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, char *psz_name,
mtime_t i_microsecperframe, mtime_t i_microsecperframe,
int i_track_id ) int i_track_id )
...@@ -185,37 +137,25 @@ static inline ...@@ -185,37 +137,25 @@ static inline
return( p_sub ); return( p_sub );
} }
static inline void subtitle_Select( subtitle_demux_t *p_sub ) /*****************************************************************************
{ * subtitle_Demux: send subtitle to decoder from last date to i_max
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;
}
}
static inline int subtitle_Demux( subtitle_demux_t *p_sub, mtime_t 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 ) ); 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 ) 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 ) static inline void subtitle_Close( subtitle_demux_t *p_sub )
{ {
msg_Info( p_sub, "subtitle stopped" ); msg_Info( p_sub, "subtitle stopped" );
...@@ -229,3 +169,4 @@ static inline void subtitle_Close( subtitle_demux_t *p_sub ) ...@@ -229,3 +169,4 @@ static inline void subtitle_Close( subtitle_demux_t *p_sub )
vlc_object_destroy( p_sub ); vlc_object_destroy( p_sub );
} }
} }
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
* decoders. * decoders.
***************************************************************************** *****************************************************************************
* Copyright (C) 1998-2002 VideoLAN * 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> * Authors: Christophe Massiot <massiot@via.ecp.fr>
* *
...@@ -745,8 +745,10 @@ static int InitThread( input_thread_t * p_input ) ...@@ -745,8 +745,10 @@ static int InitThread( input_thread_t * p_input )
{ {
if( ( p_sub = subtitle_New( p_input, strdup(val.psz_string), i_microsecondperframe, 0 ) ) ) 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 ); 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 ); if( val.psz_string ) free( val.psz_string );
...@@ -1111,6 +1113,22 @@ static es_out_id_t *EsOutAdd( es_out_t *out, es_format_t *fmt ) ...@@ -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; id->p_es->p_bitmapinfoheader = p_bih;
break; 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: default:
break; break;
} }
...@@ -1238,19 +1256,21 @@ static int EsOutControl( es_out_t *out, int i_query, va_list args ) ...@@ -1238,19 +1256,21 @@ static int EsOutControl( es_out_t *out, int i_query, va_list args )
switch( i_query ) switch( i_query )
{ {
case ES_OUT_SET_SELECT: 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 * ); id = (es_out_id_t*) va_arg( args, es_out_id_t * );
b = (vlc_bool_t) va_arg( args, vlc_bool_t ); b = (vlc_bool_t) va_arg( args, vlc_bool_t );
if( b && id->p_es->p_decoder_fifo == NULL ) if( b && id->p_es->p_decoder_fifo == NULL )
{ {
input_SelectES( p_sys->p_input, id->p_es ); 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; return id->p_es->p_decoder_fifo ? VLC_SUCCESS : VLC_EGENERIC;
} }
else if( !b && id->p_es->p_decoder_fifo ) else if( !b && id->p_es->p_decoder_fifo )
{ {
input_UnselectES( p_sys->p_input, id->p_es ); 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: case ES_OUT_GET_SELECT:
id = (es_out_id_t*) va_arg( args, es_out_id_t * ); id = (es_out_id_t*) va_arg( args, es_out_id_t * );
pb = (vlc_bool_t*) va_arg( args, vlc_bool_t * ); pb = (vlc_bool_t*) va_arg( args, vlc_bool_t * );
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment