]> git.sesse.net Git - vlc/blobdiff - plugins/mpeg_vdec/video_parser.c
* ALL: got rid of *_Probe functions because most of them were duplicates
[vlc] / plugins / mpeg_vdec / video_parser.c
index 1c3d22839ab6fad81890c735777b5e0c1d507c30..70093a9d95735f07d8782a0fdb8e158531ef141a 100644 (file)
@@ -2,7 +2,7 @@
  * video_parser.c : video parser thread
  *****************************************************************************
  * Copyright (C) 1999-2001 VideoLAN
- * $Id: video_parser.c,v 1.4 2001/11/28 15:08:05 massiot Exp $
+ * $Id: video_parser.c,v 1.13 2002/02/15 13:32:53 sam Exp $
  *
  * Authors: Christophe Massiot <massiot@via.ecp.fr>
  *          Samuel Hocevar <sam@via.ecp.fr>
  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
  *****************************************************************************/
 
-#define MODULE_NAME mpeg_vdec
-#include "modules_inner.h"
-
 /*****************************************************************************
  * Preamble
  *****************************************************************************/
-#include "defs.h"
-
 #include <stdlib.h>                                      /* malloc(), free() */
 
+#include <videolan/vlc.h>
+
 #ifdef HAVE_UNISTD_H
 #include <unistd.h>                                              /* getpid() */
 #endif
 #   include <sys/times.h>
 #endif
 
-#include "config.h"
-#include "common.h"
-#include "intf_msg.h"
-#include "threads.h"
-#include "mtime.h"
-#include "modules.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 "vpar_pool.h"
 #include "video_parser.h"
 
-
 /*
  * Local prototypes
  */
-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 );
+static int      decoder_Probe     ( u8 * );
+static int      decoder_Run       ( decoder_config_t * );
+static int      InitThread        ( vpar_thread_t * );
+static void     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;
+    p_function_list->functions.dec.pf_probe = decoder_Probe;
+    p_function_list->functions.dec.pf_run   = decoder_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";
+    SET_DESCRIPTION( "MPEG I/II video decoder module" )
+    ADD_CAPABILITY( DECODER, 50 )
 MODULE_INIT_STOP
 
 MODULE_ACTIVATE_START
@@ -105,23 +88,21 @@ MODULE_DEACTIVATE_STOP
 
 
 /*****************************************************************************
- * mpeg_vdec_Probe: probe the decoder and return score
+ * decoder_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 mpeg_vdec_Probe( probedata_t *p_data )
+static int decoder_Probe( u8 *pi_type )
 {
-    if( p_data->i_type == MPEG1_VIDEO_ES || p_data->i_type == MPEG2_VIDEO_ES )
-        return( 50 );
-    else
-        return( 0 );
+    return( ( *pi_type == MPEG1_VIDEO_ES
+               || *pi_type == MPEG2_VIDEO_ES ) ? 0 : -1 );
 }
 
 /*****************************************************************************
- * mpeg_vdec_Run: this function is called just after the thread is created
+ * decoder_Run: this function is called just after the thread is created
  *****************************************************************************/
-static int mpeg_vdec_Run ( decoder_config_t * p_config )
+static int decoder_Run ( decoder_config_t * p_config )
 {
     vpar_thread_t *     p_vpar;
     boolean_t           b_error;
@@ -133,6 +114,7 @@ static int mpeg_vdec_Run ( decoder_config_t * p_config )
     {
         intf_ErrMsg( "vpar error: not enough memory "
                      "for vpar_CreateThread() to create the new thread");
+        DecoderError( p_config->p_decoder_fifo );
         return( -1 );
     }
 
@@ -146,7 +128,7 @@ static int mpeg_vdec_Run ( decoder_config_t * p_config )
     /*
      * Initialize thread
      */
-    p_vpar->p_fifo->b_error = mpeg_vdec_Init( p_vpar );
+    p_vpar->p_fifo->b_error = InitThread( p_vpar );
      
     /*
      * Main loop - it is not executed if an error occured during
@@ -175,11 +157,11 @@ static int mpeg_vdec_Run ( decoder_config_t * p_config )
      */
     if( ( b_error = p_vpar->p_fifo->b_error ) )
     {
-        mpeg_vdec_ErrorThread( p_vpar );
+        DecoderError( p_vpar->p_fifo );
     }
 
     /* End of thread */
-    mpeg_vdec_EndThread( p_vpar );
+    EndThread( p_vpar );
 
     if( b_error )
     {
@@ -191,18 +173,20 @@ static int mpeg_vdec_Run ( decoder_config_t * p_config )
 } 
 
 /*****************************************************************************
- * mpeg_vdec_Init: initialize vpar output thread
+ * InitThread: initialize vpar output thread
  *****************************************************************************
- * This function is called from mpeg_vdec_Run and performs the second step 
+ * This function is called from decoder_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 mpeg_vdec_Init( vpar_thread_t *p_vpar )
+static int InitThread( vpar_thread_t *p_vpar )
 {
     /*
      * Choose the best motion compensation module
      */
-    p_vpar->p_motion_module = module_Need( MODULE_CAPABILITY_MOTION, NULL );
+    p_vpar->p_motion_module = module_Need( MODULE_CAPABILITY_MOTION,
+                                main_GetPszVariable( MOTION_METHOD_VAR, NULL ),
+                                NULL );
 
     if( p_vpar->p_motion_module == NULL )
     {
@@ -218,7 +202,9 @@ static int mpeg_vdec_Init( vpar_thread_t *p_vpar )
     /*
      * Choose the best IDCT module
      */
-    p_vpar->p_idct_module = module_Need( MODULE_CAPABILITY_IDCT, NULL );
+    p_vpar->p_idct_module = module_Need( MODULE_CAPABILITY_IDCT,
+                                  main_GetPszVariable( IDCT_METHOD_VAR, NULL ),
+                                  NULL );
 
     if( p_vpar->p_idct_module == NULL )
     {
@@ -238,9 +224,8 @@ static int mpeg_vdec_Init( vpar_thread_t *p_vpar )
 #undef f
 
     /* Initialize input bitstream */
-    p_vpar->p_config->pf_init_bit_stream( &p_vpar->bit_stream,
-        p_vpar->p_config->p_decoder_fifo, BitstreamCallback,
-        (void *)p_vpar );
+    InitBitstream( &p_vpar->bit_stream, p_vpar->p_config->p_decoder_fifo,
+                   BitstreamCallback, (void *)p_vpar );
 
     /* Initialize parsing data */
     p_vpar->sequence.p_forward = NULL;
@@ -280,49 +265,17 @@ static int mpeg_vdec_Init( vpar_thread_t *p_vpar )
     vpar_InitPool( p_vpar );
 
     /* Mark thread as running and return */
-    intf_DbgMsg("vpar debug: mpeg_vdec_Init(%p) succeeded", p_vpar);
+    intf_DbgMsg("vpar debug: InitThread(%p) succeeded", p_vpar);
     return( 0 );
 }
 
 /*****************************************************************************
- * 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 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 */
-    vlc_mutex_lock( &p_vpar->p_fifo->data_lock );
-
-    /* Wait until a `die' order is sent */
-    while( !p_vpar->p_fifo->b_die )
-    {
-        /* Trash all received PES packets */
-        while( !DECODER_FIFO_ISEMPTY(*p_vpar->p_fifo) )
-        {
-            p_vpar->p_fifo->pf_delete_pes( p_vpar->p_fifo->p_packets_mgt,
-                                  DECODER_FIFO_START(*p_vpar->p_fifo) );
-            DECODER_FIFO_INCSTART( *p_vpar->p_fifo );
-        }
-
-        /* Waiting for the input thread to put new PES packets in the fifo */
-        vlc_cond_wait( &p_vpar->p_fifo->data_wait, &p_vpar->p_fifo->data_lock );
-    }
-
-    /* We can release the lock before leaving */
-    vlc_mutex_unlock( &p_vpar->p_fifo->data_lock );
-}
-
-/*****************************************************************************
- * mpeg_vdec_EndThread: thread destruction
+ * EndThread: thread destruction
  *****************************************************************************
  * This function is called when the thread ends after a sucessful
  * initialization.
  *****************************************************************************/
-static void mpeg_vdec_EndThread( vpar_thread_t *p_vpar )
+static void EndThread( vpar_thread_t *p_vpar )
 {
     intf_DbgMsg("vpar debug: destroying video parser thread %p", p_vpar);
 
@@ -430,14 +383,10 @@ static void BitstreamCallback ( bit_stream_t * p_bit_stream,
 
     if( b_new_pes )
     {
-        p_vpar->sequence.next_pts =
-            DECODER_FIFO_START( *p_bit_stream->p_decoder_fifo )->i_pts;
-        p_vpar->sequence.next_dts =
-            DECODER_FIFO_START( *p_bit_stream->p_decoder_fifo )->i_dts;
         p_vpar->sequence.i_current_rate =
-            DECODER_FIFO_START( *p_bit_stream->p_decoder_fifo )->i_rate;
+            p_bit_stream->p_decoder_fifo->p_first->i_rate;
 
-        if( DECODER_FIFO_START( *p_bit_stream->p_decoder_fifo )->b_discontinuity )
+        if( p_bit_stream->p_decoder_fifo->p_first->b_discontinuity )
         {
 #ifdef TRACE_VPAR
             intf_DbgMsg( "Discontinuity in BitstreamCallback" );