]> git.sesse.net Git - vlc/blobdiff - src/video_parser/video_parser.c
* Borrowed LiViD's MMX and MMX EXT IDCT.
[vlc] / src / video_parser / video_parser.c
index 07122287a282d55422a9acb187eb45c6b0a79c71..7add0ba9fa9b6a2ff69339ed7fbe2b0234314489 100644 (file)
@@ -2,7 +2,7 @@
  * video_parser.c : video parser thread
  *****************************************************************************
  * Copyright (C) 1999, 2000 VideoLAN
- * $Id: video_parser.c,v 1.65 2001/01/12 17:33:18 massiot Exp $
+ * $Id: video_parser.c,v 1.68 2001/01/17 18:17:31 massiot Exp $
  *
  * Authors: Christophe Massiot <massiot@via.ecp.fr>
  *          Samuel Hocevar <sam@via.ecp.fr>
@@ -41,6 +41,7 @@
 #include "threads.h"
 #include "mtime.h"
 #include "plugins.h"
+#include "modules.h"
 
 #include "intf_msg.h"
 
@@ -50,9 +51,9 @@
 #include "video.h"
 #include "video_output.h"
 
-#include "../video_decoder/vdec_idct.h"
-#include "../video_decoder/video_decoder.h"
+#include "video_decoder.h"
 #include "../video_decoder/vdec_motion.h"
+#include "../video_decoder/vdec_idct.h"
 
 #include "../video_decoder/vpar_blocks.h"
 #include "../video_decoder/vpar_headers.h"
@@ -60,6 +61,8 @@
 #include "../video_decoder/video_parser.h"
 #include "../video_decoder/video_fifo.h"
 
+#include "main.h"
+
 /*
  * Local prototypes
  */
@@ -67,7 +70,8 @@ static int      InitThread          ( vpar_thread_t *p_vpar );
 static void     RunThread           ( vpar_thread_t *p_vpar );
 static void     ErrorThread         ( vpar_thread_t *p_vpar );
 static void     EndThread           ( vpar_thread_t *p_vpar );
-static void     BitstreamCallback   ( bit_stream_t *p_bit_stream );
+static void     BitstreamCallback   ( bit_stream_t *p_bit_stream,
+                                      boolean_t b_new_pes );
 
 /*****************************************************************************
  * vpar_CreateThread: create a generic parser thread
@@ -97,11 +101,30 @@ vlc_thread_t vpar_CreateThread( vdec_config_t * p_config )
 
     p_vpar->p_vout = p_config->p_vout;
 
+    /* Choose the best IDCT module */
+    p_vpar->p_module = module_Need( p_main->p_module_bank,
+                                    MODULE_CAPABILITY_IDCT, NULL );
+
+    if( p_vpar->p_module == NULL )
+    {
+        intf_ErrMsg( "vpar error: no suitable IDCT module" );
+        free( p_vpar );
+        return( 0 );
+    }
+
+#define idct_functions p_vpar->p_module->p_functions->idct.functions.idct
+    p_vpar->pf_init         = idct_functions.pf_init;
+    p_vpar->pf_sparse_idct  = idct_functions.pf_sparse_idct;
+    p_vpar->pf_idct         = idct_functions.pf_idct;
+    p_vpar->pf_norm_scan    = idct_functions.pf_norm_scan;
+#undef idct_functions
+
     /* Spawn the video parser thread */
     if ( vlc_thread_create( &p_vpar->thread_id, "video parser",
                             (vlc_thread_func_t)RunThread, (void *)p_vpar ) )
     {
         intf_ErrMsg("vpar error: can't spawn video parser thread");
+        module_Unneed( p_main->p_module_bank, p_vpar->p_module );
         free( p_vpar );
         return( 0 );
     }
@@ -129,6 +152,8 @@ static int InitThread( vpar_thread_t *p_vpar )
 
     p_vpar->p_config->decoder_config.pf_init_bit_stream( &p_vpar->bit_stream,
         p_vpar->p_config->decoder_config.p_decoder_fifo );
+    p_vpar->bit_stream.pf_bitstream_callback = BitstreamCallback;
+    p_vpar->bit_stream.p_callback_arg = (void *)p_vpar;
 
     /* Initialize parsing data */
     p_vpar->sequence.p_forward = NULL;
@@ -137,7 +162,8 @@ static int InitThread( vpar_thread_t *p_vpar )
     p_vpar->sequence.nonintra_quant.b_allocated = 0;
     p_vpar->sequence.chroma_intra_quant.b_allocated = 0;
     p_vpar->sequence.chroma_nonintra_quant.b_allocated = 0;
-    /* FIXME : initialize matrix_coefficients, but to what value ? */
+    p_vpar->sequence.i_matrix_coefficients = 1;
+    p_vpar->sequence.next_pts = p_vpar->sequence.next_dts = 0;
 
     /* Initialize copyright information */
     p_vpar->sequence.b_copyright_flag = 0;
@@ -184,12 +210,14 @@ static int InitThread( vpar_thread_t *p_vpar )
     p_vpar->pp_vdec[0]->b_error = 0;
     p_vpar->pp_vdec[0]->p_vpar = p_vpar;
 
+#   if VDEC_NICE
     /* Re-nice ourself */
     if( nice(VDEC_NICE) == -1 )
     {
         intf_WarnMsg( 2, "vpar warning : couldn't nice() (%s)",
                       strerror(errno) );
     }
+#   endif
 #endif
 
     /* Initialize lookup tables */
@@ -201,6 +229,7 @@ static int InitThread( vpar_thread_t *p_vpar )
     vpar_InitPMBType( p_vpar );
     vpar_InitBMBType( p_vpar );
     vpar_InitDCTTables( p_vpar );
+    vpar_InitScanTable( p_vpar );
 
     /*
      * Initialize the synchro properties
@@ -405,6 +434,8 @@ static void EndThread( vpar_thread_t *p_vpar )
     
     vlc_mutex_destroy( &(p_vpar->synchro.fifo_lock) );
     
+    module_Unneed( p_main->p_module_bank, p_vpar->p_module );
+
     free( p_vpar );
 
     intf_DbgMsg("vpar debug: EndThread(%p)", p_vpar);
@@ -413,7 +444,18 @@ static void EndThread( vpar_thread_t *p_vpar )
 /*****************************************************************************
  * BitstreamCallback: Import parameters from the new data/PES packet
  *****************************************************************************
- * This function is called when the thread ends after a sucessful
- * initialization.
+ * This function is called by input's NextDataPacket.
  *****************************************************************************/
-static void     BitstreamCallback   ( bit_stream_t *p_bit_stream );
+static void BitstreamCallback ( bit_stream_t * p_bit_stream,
+                                boolean_t b_new_pes )
+{
+    vpar_thread_t * p_vpar = (vpar_thread_t *)p_bit_stream->p_callback_arg;
+
+    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;
+    }
+}