Commit 98bd3d5d authored by Gildas Bazin's avatar Gildas Bazin

* modules/codec/spudec/spudec.c, modules/codec/spudec/text.c: fixed the
   race condition between spudec and vout. This patch may not be all that
   nice because it does a lot of vlc_object_find() but it is the only
   solution I've been able to come-up with.
   Oh and I didn't fix the memory leak caused by the font when using text
   subtitles. If the vout changes while the spudec is running then we don't
   unload this font.
parent 288c2fe3
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* spudec.c : SPU decoder thread * spudec.c : SPU decoder thread
***************************************************************************** *****************************************************************************
* Copyright (C) 2000-2001 VideoLAN * Copyright (C) 2000-2001 VideoLAN
* $Id: spudec.c,v 1.13 2003/01/28 22:03:21 sam Exp $ * $Id: spudec.c,v 1.14 2003/01/30 16:36:04 gbazin Exp $
* *
* Authors: Samuel Hocevar <sam@zoy.org> * Authors: Samuel Hocevar <sam@zoy.org>
* *
...@@ -40,6 +40,7 @@ static int OpenDecoder ( vlc_object_t * ); ...@@ -40,6 +40,7 @@ static int OpenDecoder ( vlc_object_t * );
static int RunDecoder ( decoder_fifo_t * ); static int RunDecoder ( decoder_fifo_t * );
static int InitThread ( spudec_thread_t * ); static int InitThread ( spudec_thread_t * );
static void EndThread ( spudec_thread_t * ); static void EndThread ( spudec_thread_t * );
static vout_thread_t *FindVout( spudec_thread_t * );
/***************************************************************************** /*****************************************************************************
* Module descriptor. * Module descriptor.
...@@ -93,8 +94,9 @@ static int OpenDecoder( vlc_object_t *p_this ) ...@@ -93,8 +94,9 @@ static int OpenDecoder( vlc_object_t *p_this )
static int RunDecoder( decoder_fifo_t * p_fifo ) static int RunDecoder( decoder_fifo_t * p_fifo )
{ {
spudec_thread_t * p_spudec; spudec_thread_t * p_spudec;
subtitler_font_t * p_font; subtitler_font_t * p_font = NULL;
char * psz_font; char * psz_font;
vout_thread_t * p_vout_backup = NULL;
/* Allocate the memory needed to store the thread's structure */ /* Allocate the memory needed to store the thread's structure */
p_spudec = (spudec_thread_t *)malloc( sizeof(spudec_thread_t) ); p_spudec = (spudec_thread_t *)malloc( sizeof(spudec_thread_t) );
...@@ -137,28 +139,54 @@ static int RunDecoder( decoder_fifo_t * p_fifo ) ...@@ -137,28 +139,54 @@ static int RunDecoder( decoder_fifo_t * p_fifo )
if( (psz_font = config_GetPsz( p_fifo, "spudec-font" )) == NULL ) if( (psz_font = config_GetPsz( p_fifo, "spudec-font" )) == NULL )
{ {
msg_Err( p_fifo, "no default font selected" ); msg_Err( p_fifo, "no default font selected" );
p_font = NULL; p_spudec->p_fifo->b_error = VLC_TRUE;
p_spudec->p_fifo->b_error;
} }
else
#endif #endif
while( (!p_spudec->p_fifo->b_die) && (!p_spudec->p_fifo->b_error) )
{ {
p_font = E_(subtitler_LoadFont)( p_spudec->p_vout, psz_font ); /* Find/Wait for a video output */
if ( p_font == NULL ) p_spudec->p_vout = FindVout( p_spudec );
if( p_spudec->p_vout )
{ {
msg_Err( p_fifo, "unable to load font: %s", psz_font ); if( p_spudec->p_vout != p_vout_backup )
p_spudec->p_fifo->b_error; {
/* The vout has changed, we need to reload the fonts */
p_vout_backup = p_spudec->p_vout;
p_font = E_(subtitler_LoadFont)( p_spudec->p_vout,
psz_font );
if( p_font == NULL )
{
msg_Err( p_fifo, "unable to load font: %s", psz_font );
p_spudec->p_fifo->b_error = VLC_TRUE;
vlc_object_release( p_spudec->p_vout );
break;
}
}
E_(ParseText)( p_spudec, p_font );
vlc_object_release( p_spudec->p_vout );
} }
} }
if( psz_font ) free( psz_font ); if( psz_font ) free( psz_font );
while( (!p_spudec->p_fifo->b_die) && (!p_spudec->p_fifo->b_error) ) if( p_font )
{ {
E_(ParseText)( p_spudec, p_font ); /* Find/Wait for a video output */
} p_spudec->p_vout = FindVout( p_spudec );
if( p_font ) E_(subtitler_UnloadFont)( p_spudec->p_vout, p_font ); if( p_spudec->p_vout )
{
E_(subtitler_UnloadFont)( p_spudec->p_vout, p_font );
vlc_object_release( p_spudec->p_vout );
}
}
} }
else else
{ {
...@@ -171,7 +199,13 @@ static int RunDecoder( decoder_fifo_t * p_fifo ) ...@@ -171,7 +199,13 @@ static int RunDecoder( decoder_fifo_t * p_fifo )
continue; continue;
} }
E_(ParsePacket)( p_spudec ); /* Find/Wait for a video output */
p_spudec->p_vout = FindVout( p_spudec );
if( p_spudec->p_vout )
{
E_(ParsePacket)( p_spudec );
vlc_object_release( p_spudec->p_vout );
}
} }
} }
...@@ -203,22 +237,47 @@ static int RunDecoder( decoder_fifo_t * p_fifo ) ...@@ -203,22 +237,47 @@ static int RunDecoder( decoder_fifo_t * p_fifo )
*****************************************************************************/ *****************************************************************************/
static int InitThread( spudec_thread_t *p_spudec ) static int InitThread( spudec_thread_t *p_spudec )
{ {
int i_ret;
/* Call InitBitstream anyway so p_spudec->bit_stream is in a known
* state before calling CloseBitstream */
i_ret = InitBitstream( &p_spudec->bit_stream, p_spudec->p_fifo,
NULL, NULL );
/* Check for a video output */
p_spudec->p_vout = FindVout( p_spudec );
if( !p_spudec->p_vout )
{
return -1;
}
/* It was just a check */
vlc_object_release( p_spudec->p_vout );
p_spudec->p_vout = NULL;
return i_ret;
}
/*****************************************************************************
* FindVout: Find a vout or wait for one to be created.
*****************************************************************************/
static vout_thread_t *FindVout( spudec_thread_t *p_spudec )
{
vout_thread_t *p_vout = NULL;
/* Find an available video output */ /* Find an available video output */
do do
{ {
if( p_spudec->p_fifo->b_die || p_spudec->p_fifo->b_error ) if( p_spudec->p_fifo->b_die || p_spudec->p_fifo->b_error )
{ {
/* Call InitBitstream anyway so p_spudec->bit_stream is in a known break;
* state before calling CloseBitstream */
InitBitstream( &p_spudec->bit_stream, p_spudec->p_fifo,
NULL, NULL );
return -1;
} }
p_spudec->p_vout = vlc_object_find( p_spudec->p_fifo, VLC_OBJECT_VOUT, p_vout = vlc_object_find( p_spudec->p_fifo, VLC_OBJECT_VOUT,
FIND_ANYWHERE ); FIND_ANYWHERE );
if( p_spudec->p_vout ) if( p_vout )
{ {
break; break;
} }
...@@ -227,8 +286,7 @@ static int InitThread( spudec_thread_t *p_spudec ) ...@@ -227,8 +286,7 @@ static int InitThread( spudec_thread_t *p_spudec )
} }
while( 1 ); while( 1 );
return InitBitstream( &p_spudec->bit_stream, p_spudec->p_fifo, return p_vout;
NULL, NULL );
} }
/***************************************************************************** /*****************************************************************************
...@@ -256,8 +314,6 @@ static void EndThread( spudec_thread_t *p_spudec ) ...@@ -256,8 +314,6 @@ static void EndThread( spudec_thread_t *p_spudec )
vout_DestroySubPicture( p_spudec->p_vout, p_subpic ); vout_DestroySubPicture( p_spudec->p_vout, p_subpic );
} }
} }
vlc_object_release( p_spudec->p_vout );
} }
CloseBitstream( &p_spudec->bit_stream ); CloseBitstream( &p_spudec->bit_stream );
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* text.c: text subtitles parser * text.c: text subtitles parser
***************************************************************************** *****************************************************************************
* Copyright (C) 2000-2001 VideoLAN * Copyright (C) 2000-2001 VideoLAN
* $Id: text.c,v 1.3 2002/12/06 16:34:05 sam Exp $ * $Id: text.c,v 1.4 2003/01/30 16:36:04 gbazin Exp $
* *
* Authors: Gildas Bazin <gbazin@netcourrier.com> * Authors: Gildas Bazin <gbazin@netcourrier.com>
* *
...@@ -55,7 +55,6 @@ void E_(ParseText)( spudec_thread_t *p_spudec, subtitler_font_t *p_font ) ...@@ -55,7 +55,6 @@ void E_(ParseText)( spudec_thread_t *p_spudec, subtitler_font_t *p_font )
msg_Warn( p_spudec->p_fifo, "subtitle without a date" ); msg_Warn( p_spudec->p_fifo, "subtitle without a date" );
return; return;
} }
else
/* Check validity of packet data */ /* Check validity of packet data */
if( (p_spudec->bit_stream.p_data->p_payload_end if( (p_spudec->bit_stream.p_data->p_payload_end
......
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