1 /*****************************************************************************
2 * spudec.c : SPU decoder thread
3 *****************************************************************************
4 * Copyright (C) 2000-2001 VideoLAN
5 * $Id: spudec.c,v 1.8 2002/11/06 21:48:24 gbazin Exp $
7 * Authors: Samuel Hocevar <sam@zoy.org>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
22 *****************************************************************************/
24 /*****************************************************************************
26 *****************************************************************************/
27 #include <stdlib.h> /* malloc(), free() */
28 #include <string.h> /* memcpy(), memset() */
32 #include <vlc/decoder.h>
36 /*****************************************************************************
38 *****************************************************************************/
39 static int OpenDecoder ( vlc_object_t * );
40 static int RunDecoder ( decoder_fifo_t * );
41 static int InitThread ( spudec_thread_t * );
42 static void EndThread ( spudec_thread_t * );
44 /*****************************************************************************
46 *****************************************************************************/
47 #define FONT_TEXT N_("Font used by the text subtitler")
48 #define FONT_LONGTEXT N_(\
49 "When the subtitles are coded in text form then, you can choose " \
50 "which font will be used to display them.")
53 add_category_hint( N_("subtitles"), NULL );
54 add_file( "spudec-font", "./share/font-eutopiabold36.rle", NULL,
55 FONT_TEXT, FONT_LONGTEXT );
56 set_description( _("subtitles decoder module") );
57 set_capability( "decoder", 50 );
58 set_callbacks( OpenDecoder, NULL );
61 /*****************************************************************************
62 * OpenDecoder: probe the decoder and return score
63 *****************************************************************************
64 * Tries to launch a decoder and return score so that the interface is able
66 *****************************************************************************/
67 static int OpenDecoder( vlc_object_t *p_this )
69 decoder_fifo_t *p_fifo = (decoder_fifo_t*) p_this;
71 if( p_fifo->i_fourcc != VLC_FOURCC('s','p','u',' ')
72 && p_fifo->i_fourcc != VLC_FOURCC('s','p','u','b')
73 && p_fifo->i_fourcc != VLC_FOURCC('s','u','b','t') )
78 p_fifo->pf_run = RunDecoder;
83 /*****************************************************************************
84 * RunDecoder: this function is called just after the thread is created
85 *****************************************************************************/
86 static int RunDecoder( decoder_fifo_t * p_fifo )
88 spudec_thread_t * p_spudec;
89 subtitler_font_t * p_font;
92 /* Allocate the memory needed to store the thread's structure */
93 p_spudec = (spudec_thread_t *)malloc( sizeof(spudec_thread_t) );
95 if ( p_spudec == NULL )
97 msg_Err( p_fifo, "out of memory" );
98 DecoderError( p_fifo );
103 * Initialize the thread properties
105 p_spudec->p_vout = NULL;
106 p_spudec->p_fifo = p_fifo;
109 * Initialize thread and free configuration
111 p_spudec->p_fifo->b_error = InitThread( p_spudec );
114 * Main loop - it is not executed if an error occured during
117 if( p_fifo->i_fourcc == VLC_FOURCC('s','u','b','t') )
119 /* Here we are dealing with text subtitles */
121 if( (psz_font = config_GetPsz( p_fifo, "spudec-font" )) == NULL )
123 msg_Err( p_fifo, "no default font selected" );
125 p_spudec->p_fifo->b_error;
129 p_font = subtitler_LoadFont( p_spudec->p_vout, psz_font );
130 if ( p_font == NULL )
132 msg_Err( p_fifo, "unable to load font: %s", psz_font );
133 p_spudec->p_fifo->b_error;
136 if( psz_font ) free( psz_font );
138 while( (!p_spudec->p_fifo->b_die) && (!p_spudec->p_fifo->b_error) )
140 E_(ParseText)( p_spudec, p_font );
143 if( p_font ) subtitler_UnloadFont( p_spudec->p_vout, p_font );
148 /* Here we are dealing with sub-pictures subtitles*/
150 while( (!p_spudec->p_fifo->b_die) && (!p_spudec->p_fifo->b_error) )
152 if( E_(SyncPacket)( p_spudec ) )
157 E_(ParsePacket)( p_spudec );
164 if( p_spudec->p_fifo->b_error )
166 DecoderError( p_spudec->p_fifo );
169 EndThread( p_spudec );
174 EndThread( p_spudec );
178 /* following functions are local */
180 /*****************************************************************************
181 * InitThread: initialize spu decoder thread
182 *****************************************************************************
183 * This function is called from RunThread and performs the second step of the
184 * initialization. It returns 0 on success. Note that the thread's flag are not
185 * modified inside this function.
186 *****************************************************************************/
187 static int InitThread( spudec_thread_t *p_spudec )
189 /* Find an available video output */
192 if( p_spudec->p_fifo->b_die || p_spudec->p_fifo->b_error )
194 /* Call InitBitstream anyway so p_spudec->bit_stream is in a known
195 * state before calling CloseBitstream */
196 InitBitstream( &p_spudec->bit_stream, p_spudec->p_fifo,
201 p_spudec->p_vout = vlc_object_find( p_spudec->p_fifo, VLC_OBJECT_VOUT,
204 if( p_spudec->p_vout )
209 msleep( VOUT_OUTMEM_SLEEP );
213 return InitBitstream( &p_spudec->bit_stream, p_spudec->p_fifo,
217 /*****************************************************************************
218 * EndThread: thread destruction
219 *****************************************************************************
220 * This function is called when the thread ends after a sucessful
222 *****************************************************************************/
223 static void EndThread( spudec_thread_t *p_spudec )
225 if( p_spudec->p_vout != NULL
226 && p_spudec->p_vout->p_subpicture != NULL )
228 subpicture_t * p_subpic;
231 for( i_subpic = 0; i_subpic < VOUT_MAX_SUBPICTURES; i_subpic++ )
233 p_subpic = &p_spudec->p_vout->p_subpicture[i_subpic];
235 if( p_subpic != NULL &&
236 ( ( p_subpic->i_status == RESERVED_SUBPICTURE )
237 || ( p_subpic->i_status == READY_SUBPICTURE ) ) )
239 vout_DestroySubPicture( p_spudec->p_vout, p_subpic );
243 vlc_object_release( p_spudec->p_vout );
246 CloseBitstream( &p_spudec->bit_stream );