]> git.sesse.net Git - vlc/blobdiff - plugins/spu_dec/spu_decoder.c
All decoders (audio, video, subtitles) are now modules.
[vlc] / plugins / spu_dec / spu_decoder.c
similarity index 89%
rename from src/spu_decoder/spu_decoder.c
rename to plugins/spu_dec/spu_decoder.c
index be9b49f94997c68a85b7f511957a70208948024c..2993355c8ae0f6add170a336572b3c5614ecb8bd 100644 (file)
@@ -2,7 +2,7 @@
  * spu_decoder.c : spu decoder thread
  *****************************************************************************
  * Copyright (C) 2000 VideoLAN
- * $Id: spu_decoder.c,v 1.49 2001/09/26 12:32:25 massiot Exp $
+ * $Id: spu_decoder.c,v 1.1 2001/11/13 12:09:18 henri Exp $
  *
  * Authors: Samuel Hocevar <sam@zoy.org>
  *
@@ -21,6 +21,9 @@
  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
  *****************************************************************************/
 
+#define MODULE_NAME spu_dec
+#include "modules_inner.h"
+
 /*****************************************************************************
  * Preamble
  *****************************************************************************/
 #include "common.h"
 #include "threads.h"
 #include "mtime.h"
-
 #include "intf_msg.h"
 
-#include "stream_control.h"
-#include "input_ext-dec.h"
-
 #include "video.h"
 #include "video_output.h"
 
+#include "modules.h"
+#include "modules_export.h"
+#include "stream_control.h"
+#include "input_ext-dec.h"
+
 #include "spu_decoder.h"
 
 /*****************************************************************************
  * Local prototypes
  *****************************************************************************/
-static int  InitThread  ( spudec_thread_t * );
-static void RunThread   ( spudec_thread_t * );
-static void ErrorThread ( spudec_thread_t * );
-static void EndThread   ( spudec_thread_t * );
+static int spu_dec_Probe         ( probedata_t * );
+static int  spu_dec_Run          ( decoder_config_t * );
+static int  spu_dec_Init         ( spudec_thread_t * );
+static void spu_dec_ErrorThread  ( spudec_thread_t * );
+static void spu_dec_EndThread    ( spudec_thread_t * );
 
 static int  SyncPacket           ( spudec_thread_t * );
 static void ParsePacket          ( spudec_thread_t * );
@@ -66,11 +71,56 @@ static int  ParseControlSequences( spudec_thread_t *, subpicture_t * );
 static int  ParseRLE             ( spudec_thread_t *, subpicture_t *, u8 * );
 
 /*****************************************************************************
- * spudec_CreateThread: create a spu decoder thread
+ * Capabilities
  *****************************************************************************/
-vlc_thread_t spudec_CreateThread( vdec_config_t * p_config )
+void _M( spu_dec_getfunctions )( function_list_t * p_function_list )
+{
+    p_function_list->pf_probe = spu_dec_Probe;
+    p_function_list->functions.dec.pf_RunThread = spu_dec_Run;
+}
+
+/*****************************************************************************
+ * Build configuration tree.
+ *****************************************************************************/
+MODULE_CONFIG_START
+ADD_WINDOW( "Configuration for SPU decoder module" )
+    ADD_COMMENT( "Nothing to configure" )
+MODULE_CONFIG_STOP
+
+MODULE_INIT_START
+    p_module->i_capabilities = MODULE_CAPABILITY_DEC;
+    p_module->psz_longname = "Subtitles decoder module";
+MODULE_INIT_STOP
+
+MODULE_ACTIVATE_START
+    _M( spu_dec_getfunctions )( &p_module->p_functions->dec );
+MODULE_ACTIVATE_STOP
+
+MODULE_DEACTIVATE_START
+MODULE_DEACTIVATE_STOP
+
+/*****************************************************************************
+ * spu_dec_Probe: probe the decoder and return score
+ *****************************************************************************
+ * Tries to launch a decoder and return score so that the interface is able 
+ * to chose.
+ *****************************************************************************/
+static int spu_dec_Probe( probedata_t *p_data )
+{
+    if( p_data->i_type == DVD_SPU_ES )
+        return( 50 );
+    else
+        return( 0 );
+}
+
+/*****************************************************************************
+ * spu_dec_Run: this function is called just after the thread is created
+ *****************************************************************************/
+static int spu_dec_Run( decoder_config_t * p_config )
 {
     spudec_thread_t *     p_spudec;
+   
+    intf_WarnMsg( 3, "spudec: thread launched. Initializing ..." );
 
     /* Allocate the memory needed to store the thread's structure */
     p_spudec = (spudec_thread_t *)malloc( sizeof(spudec_thread_t) );
@@ -79,16 +129,64 @@ vlc_thread_t spudec_CreateThread( vdec_config_t * p_config )
     {
         intf_ErrMsg( "spudec error: not enough memory "
                      "for spudec_CreateThread() to create the new thread" );
-        return( 0 );
+        return( -1 );
     }
-
+    
     /*
      * Initialize the thread properties
      */
     p_spudec->p_config = p_config;
 
-    p_spudec->p_fifo = p_config->decoder_config.p_decoder_fifo;
+    p_spudec->p_fifo = p_config->p_decoder_fifo;
+        
+    /*
+     * Initialize thread and free configuration
+     */
+    p_spudec->p_fifo->b_error = spu_dec_Init( p_spudec );
+
+    /*
+     * Main loop - it is not executed if an error occured during
+     * initialization
+     */
+    while( (!p_spudec->p_fifo->b_die) && (!p_spudec->p_fifo->b_error) )
+    {
+        if( !SyncPacket( p_spudec ) )
+        {
+            ParsePacket( p_spudec );
+        }
+    }
+
+    /*
+     * Error loop
+     */
+    if( p_spudec->p_fifo->b_error )
+    {
+        spu_dec_ErrorThread( p_spudec );
+    }
+
+    /* End of thread */
+    spu_dec_EndThread( p_spudec );
+
+    if( p_spudec->p_fifo->b_error )
+    {
+        return( -1 );
+    }
+   
+    return( 0 );
 
+}
+
+/* following functions are local */
+
+/*****************************************************************************
+ * spu_dec_Init: initialize spu decoder thread
+ *****************************************************************************
+ * This function is called from RunThread and performs the second step of the
+ * initialization. It returns 0 on success. Note that the thread's flag are not
+ * modified inside this function.
+ *****************************************************************************/
+static int spu_dec_Init( spudec_thread_t *p_spudec )
+{
     /* Spawn a video output if there is none */
     vlc_mutex_lock( &p_vout_bank->lock );
 
@@ -105,7 +203,7 @@ vlc_thread_t spudec_CreateThread( vdec_config_t * p_config )
             vlc_mutex_unlock( &p_vout_bank->lock );
             free( p_spudec );
 
-            return 0;
+            return( -1 );
         }
 
         p_vout_bank->pp_vout[ p_vout_bank->i_count ] = p_spudec->p_vout;
@@ -118,86 +216,22 @@ vlc_thread_t spudec_CreateThread( vdec_config_t * p_config )
     }
 
     vlc_mutex_unlock( &p_vout_bank->lock );
-
-    /* Spawn the spu decoder thread */
-    if ( vlc_thread_create(&p_spudec->thread_id, "spu decoder",
-         (vlc_thread_func_t)RunThread, (void *)p_spudec) )
-    {
-        intf_ErrMsg( "spudec error: can't spawn spu decoder thread" );
-        free( p_spudec );
-        return 0;
-    }
-
-    return( p_spudec->thread_id );
-}
-
-/* following functions are local */
-
-/*****************************************************************************
- * InitThread: initialize spu decoder thread
- *****************************************************************************
- * This function is called from RunThread and performs the second step of the
- * initialization. It returns 0 on success. Note that the thread's flag are not
- * modified inside this function.
- *****************************************************************************/
-static int InitThread( spudec_thread_t *p_spudec )
-{
-    p_spudec->p_config->decoder_config.pf_init_bit_stream(
+    p_spudec->p_config->pf_init_bit_stream(
             &p_spudec->bit_stream,
-            p_spudec->p_config->decoder_config.p_decoder_fifo, NULL, NULL );
+            p_spudec->p_config->p_decoder_fifo, NULL, NULL );
 
     /* Mark thread as running and return */
     return( 0 );
 }
 
 /*****************************************************************************
- * RunThread: spu decoder thread
- *****************************************************************************
- * spu decoder thread. This function only returns when the thread is
- * terminated.
- *****************************************************************************/
-static void RunThread( spudec_thread_t *p_spudec )
-{
-    intf_WarnMsg( 3, "spudec: spu decoder thread %i spawned", getpid() );
-
-    /*
-     * Initialize thread and free configuration
-     */
-    p_spudec->p_fifo->b_error = InitThread( p_spudec );
-
-    /*
-     * Main loop - it is not executed if an error occured during
-     * initialization
-     */
-    while( (!p_spudec->p_fifo->b_die) && (!p_spudec->p_fifo->b_error) )
-    {
-        if( !SyncPacket( p_spudec ) )
-        {
-            ParsePacket( p_spudec );
-        }
-    }
-
-    /*
-     * Error loop
-     */
-    if( p_spudec->p_fifo->b_error )
-    {
-        ErrorThread( p_spudec );
-    }
-
-    /* End of thread */
-    intf_WarnMsg( 3, "spudec: destroying spu decoder thread %i", getpid() );
-    EndThread( p_spudec );
-}
-
-/*****************************************************************************
- * ErrorThread: RunThread() error loop
+ * spu_dec_ErrorThread: spu_dec_Run() error loop
  *****************************************************************************
  * This function is called when an error occured during thread main's loop. The
  * thread can still receive feed, but must be ready to terminate as soon as
  * possible.
  *****************************************************************************/
-static void ErrorThread( spudec_thread_t *p_spudec )
+static void spu_dec_ErrorThread( spudec_thread_t *p_spudec )
 {
     /* We take the lock, because we are going to read/write the start/end
      * indexes of the decoder fifo */
@@ -224,12 +258,12 @@ static void ErrorThread( spudec_thread_t *p_spudec )
 }
 
 /*****************************************************************************
- * EndThread: thread destruction
+ * spu_dec_EndThread: thread destruction
  *****************************************************************************
  * This function is called when the thread ends after a sucessful
  * initialization.
  *****************************************************************************/
-static void EndThread( spudec_thread_t *p_spudec )
+static void spu_dec_EndThread( spudec_thread_t *p_spudec )
 {
     free( p_spudec->p_config );
     free( p_spudec );