]> git.sesse.net Git - vlc/blobdiff - plugins/mpeg_vdec/video_parser.c
All decoders (audio, video, subtitles) are now modules.
[vlc] / plugins / mpeg_vdec / video_parser.c
similarity index 81%
rename from src/video_decoder/video_parser.c
rename to plugins/mpeg_vdec/video_parser.c
index b443b113d1a4634c0d0591f26237be57e5cbc85e..e9d59de10945c41db0c619a095c32ffb8bfac619 100644 (file)
@@ -2,7 +2,7 @@
  * video_parser.c : video parser thread
  *****************************************************************************
  * Copyright (C) 1999, 2000 VideoLAN
- * $Id: video_parser.c,v 1.8 2001/10/03 13:14:05 sam Exp $
+ * $Id: video_parser.c,v 1.1 2001/11/13 12:09:18 henri Exp $
  *
  * Authors: Christophe Massiot <massiot@via.ecp.fr>
  *          Samuel Hocevar <sam@via.ecp.fr>
@@ -22,6 +22,9 @@
  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
  *****************************************************************************/
 
+#define MODULE_NAME mpeg_vdec
+#include "modules_inner.h"
+
 /*****************************************************************************
  * Preamble
  *****************************************************************************/
 #include "threads.h"
 #include "mtime.h"
 #include "modules.h"
-
 #include "intf_msg.h"
 
-#include "stream_control.h"
-#include "input_ext-dec.h"
+#include "main.h"
 
 #include "video.h"
 #include "video_output.h"
 
+#include "modules_export.h"
+#include "stream_control.h"
+#include "input_ext-dec.h"
+
+
 #include "vdec_ext-plugins.h"
 #include "vpar_pool.h"
 #include "video_parser.h"
 
-#include "main.h"
 
 /*
  * Local prototypes
  */
-static int      InitThread          ( vpar_thread_t * );
-static void     RunThread           ( vpar_thread_t * );
-static void     ErrorThread         ( vpar_thread_t * );
-static void     EndThread           ( vpar_thread_t * );
-static void     BitstreamCallback   ( bit_stream_t *, boolean_t );
+static int      mpeg_vdec_Probe         ( probedata_t * );
+static int      mpeg_vdec_Run           ( decoder_config_t * );
+static int      mpeg_vdec_Init          ( vpar_thread_t * );
+static void     mpeg_vdec_ErrorThread   ( vpar_thread_t * );
+static void     mpeg_vdec_EndThread     ( vpar_thread_t * );
+static void     BitstreamCallback       ( bit_stream_t *, boolean_t );
+
+/*****************************************************************************
+ * Capabilities
+ *****************************************************************************/
+void _M( vdec_getfunctions )( function_list_t * p_function_list )
+{
+    p_function_list->pf_probe = mpeg_vdec_Probe;
+    p_function_list->functions.dec.pf_RunThread = mpeg_vdec_Run;
+}
+
+/*****************************************************************************
+ * Build configuration tree.
+ *****************************************************************************/
+MODULE_CONFIG_START
+ADD_WINDOW( "Configuration for MPEG video decoder module" )
+    ADD_COMMENT( "Nothing to configure" )
+MODULE_CONFIG_STOP
+
+MODULE_INIT_START
+    p_module->i_capabilities = MODULE_CAPABILITY_DEC;
+    p_module->psz_longname = "MPEG I/II video decoder module";
+MODULE_INIT_STOP
+
+MODULE_ACTIVATE_START
+    _M( vdec_getfunctions )( &p_module->p_functions->dec );
+MODULE_ACTIVATE_STOP
+
+MODULE_DEACTIVATE_START
+MODULE_DEACTIVATE_STOP
+
 
 /*****************************************************************************
- * vpar_CreateThread: create a generic parser thread
+ * mpeg_vdec_Probe: probe the decoder and return score
  *****************************************************************************
- * This function creates a new video parser thread, and returns a pointer
- * to its description. On error, it returns NULL.
+ * Tries to launch a decoder and return score so that the interface is able 
+ * to chose.
+ *****************************************************************************/
+static int mpeg_vdec_Probe( probedata_t *p_data )
+{
+    if( p_data->i_type == MPEG1_VIDEO_ES || p_data->i_type == MPEG2_VIDEO_ES )
+        return( 50 );
+    else
+        return( 0 );
+}
+
+/*****************************************************************************
+ * mpeg_vdec_Run: this function is called just after the thread is created
  *****************************************************************************/
-vlc_thread_t vpar_CreateThread( vdec_config_t * p_config )
+static int mpeg_vdec_Run ( decoder_config_t * p_config )
 {
     vpar_thread_t *     p_vpar;
 
-    intf_DbgMsg( "vpar debug: creating video parser thread" );
+    intf_DbgMsg( "vpar debug: video parser thread created. Initializing..." );
 
     /* Allocate the memory needed to store the thread's structure */
     if ( (p_vpar = (vpar_thread_t *)malloc( sizeof(vpar_thread_t) )) == NULL )
     {
         intf_ErrMsg( "vpar error: not enough memory "
                      "for vpar_CreateThread() to create the new thread");
-        return( 0 );
+        return( -1 );
     }
 
     /*
      * Initialize the thread properties
      */
-    p_vpar->p_fifo = p_config->decoder_config.p_decoder_fifo;
+    p_vpar->p_fifo = p_config->p_decoder_fifo;
     p_vpar->p_config = p_config;
     p_vpar->p_vout = NULL;
 
-    /* Spawn the video parser thread */
-    if ( vlc_thread_create( &p_vpar->thread_id, "video parser",
-                            (vlc_thread_func_t)RunThread, (void *)p_vpar ) )
+    /*
+     * Initialize thread
+     */
+    p_vpar->p_fifo->b_error = mpeg_vdec_Init( p_vpar );
+     
+    /*
+     * Main loop - it is not executed if an error occured during
+     * initialization
+     */
+    while( (!p_vpar->p_fifo->b_die) && (!p_vpar->p_fifo->b_error) )
     {
-        intf_ErrMsg("vpar error: can't spawn video parser thread");
-        module_Unneed( p_vpar->p_idct_module );
-        module_Unneed( p_vpar->p_motion_module );
-        free( p_vpar );
-        return( 0 );
+        /* Find the next sequence header in the stream */
+        p_vpar->p_fifo->b_error = vpar_NextSequenceHeader( p_vpar );
+
+        while( (!p_vpar->p_fifo->b_die) && (!p_vpar->p_fifo->b_error) )
+        {
+            p_vpar->c_loops++;
+
+            /* Parse the next sequence, group or picture header */
+            if( vpar_ParseHeader( p_vpar ) )
+            {
+                /* End of sequence */
+                break;
+            }
+        }
     }
 
-    intf_DbgMsg("vpar debug: video parser thread (%p) created", p_vpar);
-    return( p_vpar->thread_id );
-}
+    /*
+     * Error loop
+     */
+    if( p_vpar->p_fifo->b_error )
+    {
+        mpeg_vdec_ErrorThread( p_vpar );
+    }
+
+    /* End of thread */
+    mpeg_vdec_EndThread( p_vpar );
 
-/* following functions are local */
+    if( p_vpar->p_fifo->b_error )
+    {
+        return( -1 );
+    }
+   
+    return( 0 );
+    
+} 
 
 /*****************************************************************************
- * InitThread: initialize vpar output thread
+ * mpeg_vdec_Init: initialize vpar output 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.
+ * This function is called from mpeg_vdec_Run 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( vpar_thread_t *p_vpar )
+static int mpeg_vdec_Init( vpar_thread_t *p_vpar )
 {
-    intf_DbgMsg("vpar debug: initializing video parser thread %p", p_vpar);
-
     /*
      * Choose the best motion compensation module
      */
@@ -133,7 +208,7 @@ static int InitThread( vpar_thread_t *p_vpar )
     {
         intf_ErrMsg( "vpar error: no suitable motion compensation module" );
         free( p_vpar );
-        return( 0 );
+        return( -1 );
     }
 
 #define f ( p_vpar->p_motion_module->p_functions->motion.functions.motion )
@@ -150,7 +225,7 @@ static int InitThread( vpar_thread_t *p_vpar )
         intf_ErrMsg( "vpar error: no suitable IDCT module" );
         module_Unneed( p_vpar->p_motion_module );
         free( p_vpar );
-        return( 0 );
+        return( -1 );
     }
 
 #define f p_vpar->p_idct_module->p_functions->idct.functions.idct
@@ -163,8 +238,8 @@ static int InitThread( vpar_thread_t *p_vpar )
 #undef f
 
     /* Initialize input bitstream */
-    p_vpar->p_config->decoder_config.pf_init_bit_stream( &p_vpar->bit_stream,
-        p_vpar->p_config->decoder_config.p_decoder_fifo, BitstreamCallback,
+    p_vpar->p_config->pf_init_bit_stream( &p_vpar->bit_stream,
+        p_vpar->p_config->p_decoder_fifo, BitstreamCallback,
         (void *)p_vpar );
 
     /* Initialize parsing data */
@@ -205,67 +280,18 @@ static int InitThread( vpar_thread_t *p_vpar )
     vpar_InitPool( p_vpar );
 
     /* Mark thread as running and return */
-    intf_DbgMsg("vpar debug: InitThread(%p) succeeded", p_vpar);
+    intf_DbgMsg("vpar debug: mpeg_vdec_Init(%p) succeeded", p_vpar);
     return( 0 );
 }
 
 /*****************************************************************************
- * RunThread: generic parser thread
- *****************************************************************************
- * Video parser thread. This function only returns when the thread is
- * terminated.
- *****************************************************************************/
-static void RunThread( vpar_thread_t *p_vpar )
-{
-    intf_DbgMsg("vpar debug: running video parser thread (%p) (pid == %i)", p_vpar, getpid());
-
-    /*
-     * Initialize thread
-     */
-    p_vpar->p_fifo->b_error = InitThread( p_vpar );
-
-    /*
-     * Main loop - it is not executed if an error occured during
-     * initialization
-     */
-    while( (!p_vpar->p_fifo->b_die) && (!p_vpar->p_fifo->b_error) )
-    {
-        /* Find the next sequence header in the stream */
-        p_vpar->p_fifo->b_error = vpar_NextSequenceHeader( p_vpar );
-
-        while( (!p_vpar->p_fifo->b_die) && (!p_vpar->p_fifo->b_error) )
-        {
-            p_vpar->c_loops++;
-
-            /* Parse the next sequence, group or picture header */
-            if( vpar_ParseHeader( p_vpar ) )
-            {
-                /* End of sequence */
-                break;
-            }
-        }
-    }
-
-    /*
-     * Error loop
-     */
-    if( p_vpar->p_fifo->b_error )
-    {
-        ErrorThread( p_vpar );
-    }
-
-    /* End of thread */
-    EndThread( p_vpar );
-}
-
-/*****************************************************************************
- * ErrorThread: RunThread() error loop
+ * mpeg_vdec_ErrorThread: RunThread() 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( vpar_thread_t *p_vpar )
+static void mpeg_vdec_ErrorThread( vpar_thread_t *p_vpar )
 {
     /* We take the lock, because we are going to read/write the start/end
      * indexes of the decoder fifo */
@@ -291,12 +317,12 @@ static void ErrorThread( vpar_thread_t *p_vpar )
 }
 
 /*****************************************************************************
- * EndThread: thread destruction
+ * mpeg_vdec_EndThread: thread destruction
  *****************************************************************************
  * This function is called when the thread ends after a sucessful
  * initialization.
  *****************************************************************************/
-static void EndThread( vpar_thread_t *p_vpar )
+static void mpeg_vdec_EndThread( vpar_thread_t *p_vpar )
 {
     intf_DbgMsg("vpar debug: destroying video parser thread %p", p_vpar);