]> git.sesse.net Git - vlc/blobdiff - src/video_parser/vpar_blocks.c
The motion compensation routines are now modules as well ; choose your
[vlc] / src / video_parser / vpar_blocks.c
index 75926fdb15a90f7730d172b79efc2ae06bc90af9..12d0bbf9565ef3710d2748563f56bdaf80dfcce3 100644 (file)
@@ -2,6 +2,7 @@
  * vpar_blocks.c : blocks parsing
  *****************************************************************************
  * Copyright (C) 1999, 2000 VideoLAN
+ * $Id: vpar_blocks.c,v 1.72 2001/01/18 05:13:23 sam Exp $
  *
  * Authors: Christophe Massiot <massiot@via.ecp.fr>
  *          Jean-Marc Dressler <polux@via.ecp.fr>
@@ -27,8 +28,6 @@
  *****************************************************************************/
 #include "defs.h"
 
-#include <sys/types.h>                        /* on BSD, uio.h needs types.h */
-#include <sys/uio.h>                                            /* "input.h" */
 #include <string.h>                                                /* memset */
 
 #include "config.h"
 #include "plugins.h"
 
 #include "intf_msg.h"
-#include "debug.h"                 /* XXX?? temporaire, requis par netlist.h */
 
-#include "input.h"
-#include "input_netlist.h"
-#include "decoder_fifo.h"
+#include "stream_control.h"
+#include "input_ext-dec.h"
+
 #include "video.h"
 #include "video_output.h"
 
-#include "vdec_idct.h"
 #include "video_decoder.h"
 #include "vdec_motion.h"
+#include "../video_decoder/vdec_idct.h"
 
 #include "vpar_blocks.h"
-#include "vpar_headers.h"
-#include "vpar_synchro.h"
-#include "video_parser.h"
-#include "video_fifo.h"
+#include "../video_decoder/vpar_headers.h"
+#include "../video_decoder/vpar_synchro.h"
+#include "../video_decoder/video_parser.h"
+#include "../video_decoder/video_fifo.h"
 
 /*
  * Welcome to vpar_blocks.c ! Here's where the heavy processor-critical parsing
@@ -611,6 +609,26 @@ void vpar_InitDCTTables( vpar_thread_t * p_vpar )
     FillDCTTable( p_vpar->ppl_dct_coef[1], pl_DCT_tab6,    1, 16, 16 );
 }
 
+/*****************************************************************************
+ * vpar_InitScanTable : Initialize scan table
+ *****************************************************************************/
+void vpar_InitScanTable( vpar_thread_t * p_vpar )
+{
+    int     i;
+
+    memcpy( p_vpar->ppi_scan, pi_scan, sizeof(pi_scan) );
+    p_vpar->pf_norm_scan( p_vpar->ppi_scan );
+
+    /* If scan table has changed, we must change the quantization matrices. */
+    for( i = 0; i < 64; i++ )
+    {
+        p_vpar->pi_default_intra_quant[ p_vpar->ppi_scan[0][i] ] =
+            pi_default_intra_quant[ pi_scan[0][i] ];
+        p_vpar->pi_default_nonintra_quant[ p_vpar->ppi_scan[0][i] ] =
+            pi_default_nonintra_quant[ pi_scan[0][i] ];
+    }
+}
+
 
 /*
  * Block parsing
@@ -644,7 +662,7 @@ static __inline__ void DecodeMPEG1NonIntra( vpar_thread_t * p_vpar,
 
     /* There should be no D picture in non-intra blocks */
     if( p_vpar->picture.i_coding_type == D_CODING_TYPE )
-        intf_ErrMsg("vpar error : D-picture in non intra block\n");
+        intf_ErrMsg("vpar error : D-picture in non intra block");
     
     /* Decoding of the AC coefficients */
 
@@ -652,7 +670,7 @@ static __inline__ void DecodeMPEG1NonIntra( vpar_thread_t * p_vpar,
     i_coef = 0;
     b_sign = 0;
 
-    for( i_parse = 0; !p_vpar->b_die; i_parse++ )
+    for( i_parse = 0; !p_vpar->p_fifo->b_die; i_parse++ )
     {
         i_code = ShowBits( &p_vpar->bit_stream, 16 );
         if( i_code >= 16384 )
@@ -688,19 +706,14 @@ static __inline__ void DecodeMPEG1NonIntra( vpar_thread_t * p_vpar,
                 
                 break;
             case DCT_EOB:
-#ifdef HAVE_MMX
-                /* The MMX IDCT has a precision problem with non-intra
-                 * blocks. */
-                p_mb->ppi_blocks[i_b][0] += 4;
-#endif
                 if( i_nc <= 1 )
                 {
-                    p_mb->pf_idct[i_b] = vdec_SparseIDCT;
+                    p_mb->pf_idct[i_b] = p_vpar->pf_sparse_idct;
                     p_mb->pi_sparse_pos[i_b] = i_coef;
                 }
                 else
                 {
-                    p_mb->pf_idct[i_b] = vdec_IDCT;
+                    p_mb->pf_idct[i_b] = p_vpar->pf_idct;
                 }
                 return;
 
@@ -717,7 +730,7 @@ static __inline__ void DecodeMPEG1NonIntra( vpar_thread_t * p_vpar,
             break;
         }
 
-        i_pos = pi_scan[p_vpar->picture.b_alternate_scan][i_parse];
+        i_pos = p_vpar->ppi_scan[p_vpar->picture.b_alternate_scan][i_parse];
         i_level = ( ((i_level << 1) + 1) * p_vpar->mb.i_quantizer_scale
                     * p_vpar->sequence.nonintra_quant.pi_matrix[i_pos] ) >> 4;
 
@@ -731,7 +744,7 @@ static __inline__ void DecodeMPEG1NonIntra( vpar_thread_t * p_vpar,
         p_mb->ppi_blocks[i_b][i_pos] = b_sign ? -i_level : i_level;
     }
 
-    intf_ErrMsg("vpar error: DCT coeff (non-intra) is out of bounds\n");
+    intf_ErrMsg("vpar error: DCT coeff (non-intra) is out of bounds");
     p_vpar->picture.b_error = 1;
 }
 
@@ -810,7 +823,7 @@ static __inline__ void DecodeMPEG1Intra( vpar_thread_t * p_vpar,
     i_coef = 0;
     b_sign = 0;
 
-    for( i_parse = 1; !p_vpar->b_die/*i_parse < 64*/; i_parse++ )
+    for( i_parse = 1; !p_vpar->p_fifo->b_die/*i_parse < 64*/; i_parse++ )
     {
         i_code = ShowBits( &p_vpar->bit_stream, 16 );
         /* We use 2 main tables for the coefficients */
@@ -846,12 +859,12 @@ static __inline__ void DecodeMPEG1Intra( vpar_thread_t * p_vpar,
             case DCT_EOB:
                 if( i_nc <= 1 )
                 {
-                    p_mb->pf_idct[i_b] = vdec_SparseIDCT;
+                    p_mb->pf_idct[i_b] = p_vpar->pf_sparse_idct;
                     p_mb->pi_sparse_pos[i_b] = i_coef;
                 }
                 else
                 {
-                    p_mb->pf_idct[i_b] = vdec_IDCT;
+                    p_mb->pf_idct[i_b] = p_vpar->pf_idct;
                 }
                 return;
 
@@ -872,7 +885,7 @@ static __inline__ void DecodeMPEG1Intra( vpar_thread_t * p_vpar,
         }
 
         /* Determine the position of the block in the frame */
-        i_pos = pi_scan[p_vpar->picture.b_alternate_scan][i_parse];
+        i_pos = p_vpar->ppi_scan[p_vpar->picture.b_alternate_scan][i_parse];
         i_level = ( i_level *
                     p_vpar->mb.i_quantizer_scale *
                     p_vpar->sequence.intra_quant.pi_matrix[i_pos] ) >> 3;
@@ -887,7 +900,7 @@ static __inline__ void DecodeMPEG1Intra( vpar_thread_t * p_vpar,
         p_mb->ppi_blocks[i_b][i_pos] = b_sign ? -i_level : i_level;
     }
 
-    intf_ErrMsg("vpar error: DCT coeff (intra) is out of bounds\n");
+    intf_ErrMsg("vpar error: DCT coeff (intra) is out of bounds");
     p_vpar->picture.b_error = 1;
 }
 
@@ -910,7 +923,7 @@ static __inline__ void DecodeMPEG2NonIntra( vpar_thread_t * p_vpar,
     boolean_t   b_dc;
     boolean_t   b_sign;
     boolean_t   b_chroma;
-    int *       pi_quant;
+    u8 *        pi_quant;
 
     /* Give the chromatic component (0, 1, 2) */
     i_cc = pi_cc_index[i_b];
@@ -932,7 +945,7 @@ static __inline__ void DecodeMPEG2NonIntra( vpar_thread_t * p_vpar,
 
     i_nc = 0;
     i_coef = 0;
-    for( i_parse = 0; !p_vpar->b_die; i_parse++ )
+    for( i_parse = 0; !p_vpar->p_fifo->b_die; i_parse++ )
     {
         i_code = ShowBits( &p_vpar->bit_stream, 16 );
         if( i_code >= 16384 )
@@ -968,12 +981,12 @@ static __inline__ void DecodeMPEG2NonIntra( vpar_thread_t * p_vpar,
 #endif
                 if( i_nc <= 1 )
                 {
-                    p_mb->pf_idct[i_b] = vdec_SparseIDCT;
+                    p_mb->pf_idct[i_b] = p_vpar->pf_sparse_idct;
                     p_mb->pi_sparse_pos[i_b] = i_coef;
                 }
                 else
                 {
-                    p_mb->pf_idct[i_b] = vdec_IDCT;
+                    p_mb->pf_idct[i_b] = p_vpar->pf_idct;
                 }
                 return;
 
@@ -990,13 +1003,13 @@ static __inline__ void DecodeMPEG2NonIntra( vpar_thread_t * p_vpar,
             break;
         }
 
-        i_pos = pi_scan[p_vpar->picture.b_alternate_scan][i_parse];
+        i_pos = p_vpar->ppi_scan[p_vpar->picture.b_alternate_scan][i_parse];
         i_level = ( ((i_level << 1) + 1) * p_vpar->mb.i_quantizer_scale
                     * pi_quant[i_pos] ) >> 5;
         p_mb->ppi_blocks[i_b][i_pos] = b_sign ? -i_level : i_level;
     }
 
-    intf_ErrMsg("vpar error: DCT coeff (non-intra) is out of bounds\n");
+    intf_ErrMsg("vpar error: DCT coeff (non-intra) is out of bounds");
     p_vpar->picture.b_error = 1;
 }
 
@@ -1021,7 +1034,7 @@ static __inline__ void DecodeMPEG2Intra( vpar_thread_t * p_vpar,
     boolean_t       b_vlc_intra;
     boolean_t       b_sign;
     boolean_t       b_chroma;
-    int *           pi_quant;
+    u8 *            pi_quant;
     
     /* Give the chromatic component (0, 1, 2) */
     i_cc = pi_cc_index[i_b];
@@ -1078,7 +1091,7 @@ static __inline__ void DecodeMPEG2Intra( vpar_thread_t * p_vpar,
 
     i_coef = 0;
     b_vlc_intra = p_vpar->picture.b_intra_vlc_format;
-    for( i_parse = 1; !p_vpar->b_die/*i_parse < 64*/; i_parse++ )
+    for( i_parse = 1; !p_vpar->p_fifo->b_die/*i_parse < 64*/; i_parse++ )
     {
         i_code = ShowBits( &p_vpar->bit_stream, 16 );
         /* We use 2 main tables for the coefficients */
@@ -1108,12 +1121,12 @@ static __inline__ void DecodeMPEG2Intra( vpar_thread_t * p_vpar,
             case DCT_EOB:
                 if( i_nc <= 1 )
                 {
-                    p_mb->pf_idct[i_b] = vdec_SparseIDCT;
+                    p_mb->pf_idct[i_b] = p_vpar->pf_sparse_idct;
                     p_mb->pi_sparse_pos[i_b] = i_coef;
                 }
                 else
                 {
-                    p_mb->pf_idct[i_b] = vdec_IDCT;
+                    p_mb->pf_idct[i_b] = p_vpar->pf_idct;
                 }
                 return;
 
@@ -1134,14 +1147,14 @@ static __inline__ void DecodeMPEG2Intra( vpar_thread_t * p_vpar,
         }
 
         /* Determine the position of the block in the frame */
-        i_pos = pi_scan[p_vpar->picture.b_alternate_scan][i_parse];
+        i_pos = p_vpar->ppi_scan[p_vpar->picture.b_alternate_scan][i_parse];
         i_level = ( i_level *
                     p_vpar->mb.i_quantizer_scale *
                     pi_quant[i_pos] ) >> 4;
         p_mb->ppi_blocks[i_b][i_pos] = b_sign ? -i_level : i_level;
     }
 
-    intf_ErrMsg("vpar error: DCT coeff (intra) is out of bounds\n");
+    intf_ErrMsg("vpar error: DCT coeff (intra) is out of bounds");
     p_vpar->picture.b_error = 1;
 }
 
@@ -1190,7 +1203,7 @@ static __inline__ int MotionCode( vpar_thread_t * p_vpar )
     if( (i_code -= 12) < 0 )
     {
         p_vpar->picture.b_error = 1;
-        intf_DbgMsg( "vpar debug: Invalid motion_vector code\n" );
+        intf_DbgMsg( "vpar debug: Invalid motion_vector code" );
         return 0;
     }
 
@@ -1572,20 +1585,9 @@ static __inline__ void SkippedMacroblock( vpar_thread_t * p_vpar, int i_mb,
 {
     macroblock_t *  p_mb;
 
-    static f_motion_t   pf_motion_skipped[4][4] =
-    {
-        {NULL, NULL, NULL, NULL},
-        {NULL, vdec_MotionFieldField420, vdec_MotionFieldField420,
-            vdec_MotionFrameFrame420},
-        {NULL, vdec_MotionFieldField422, vdec_MotionFieldField422,
-            vdec_MotionFrameFrame422},
-        {NULL, vdec_MotionFieldField444, vdec_MotionFieldField444,
-            vdec_MotionFrameFrame444},
-    };
-
     if( i_coding_type == I_CODING_TYPE )
     {
-        intf_DbgMsg("vpar error: skipped macroblock in I-picture\n");
+        intf_DbgMsg("vpar error: skipped macroblock in I-picture");
         p_vpar->picture.b_error = 1;
         return;
     }
@@ -1603,8 +1605,8 @@ static __inline__ void SkippedMacroblock( vpar_thread_t * p_vpar, int i_mb,
                     i_structure, b_second_field );
 
     /* Motion type is picture structure. */
-    p_mb->pf_motion = pf_motion_skipped[i_chroma_format]
-                                       [i_structure];
+    p_mb->pf_motion = p_vpar->ppf_motion_skipped[i_chroma_format]
+                                                [i_structure];
     p_mb->i_coded_block_pattern = 0;
 
     /* Motion direction and motion vectors depend on the coding type. */
@@ -1807,27 +1809,6 @@ static __inline__ void ParseMacroblock(
                            boolean_t b_second_field )     /* second field of a
                                                            * field picture   */
 {
-    static f_motion_t   pppf_motion[4][2][4] =
-      {
-        { {NULL, NULL, NULL, NULL},
-          {NULL, NULL, NULL, NULL}
-        },
-        { {NULL, vdec_MotionFieldField420, vdec_MotionField16x8420,
-            vdec_MotionFieldDMV420},
-          {NULL, vdec_MotionFrameField420, vdec_MotionFrameFrame420,
-            vdec_MotionFrameDMV420}
-        },
-        { {NULL, vdec_MotionFieldField422, vdec_MotionField16x8422,
-            vdec_MotionFieldDMV422},
-          {NULL, vdec_MotionFrameField422, vdec_MotionFrameFrame422,
-            vdec_MotionFrameDMV422}
-        },
-        { {NULL, vdec_MotionFieldField444, vdec_MotionField16x8444,
-            vdec_MotionFieldDMV444},
-          {NULL, vdec_MotionFrameField444, vdec_MotionFrameFrame444,
-            vdec_MotionFrameDMV444}
-        }
-      };
     static int      pi_x[12] = {0,8,0,8,0,0,0,0,8,8,8,8};
     static int      pi_y[2][12] = { {0,0,8,8,0,0,8,8,0,0,8,8},
                                     {0,0,1,1,0,0,1,1,0,0,1,1} };
@@ -1842,7 +1823,7 @@ static __inline__ void ParseMacroblock(
 
     if( i_inc < 0 )
     {
-        intf_ErrMsg( "vpar error: bad address increment (%d)\n", i_inc );
+        intf_ErrMsg( "vpar error: bad address increment (%d)", i_inc );
         p_vpar->picture.b_error = 1;
         return;
     }
@@ -1930,9 +1911,9 @@ static __inline__ void ParseMacroblock(
             = 1 << (7 + p_vpar->picture.i_intra_dc_precision);
 
         /* Motion function pointer. */
-        p_mb->pf_motion = pppf_motion[i_chroma_format]
-                                     [i_structure == FRAME_STRUCTURE]
-                                     [p_vpar->mb.i_motion_type];
+        p_mb->pf_motion = p_vpar->pppf_motion[i_chroma_format]
+                                             [i_structure == FRAME_STRUCTURE]
+                                             [p_vpar->mb.i_motion_type];
 
         if( p_mb->i_mb_type & MB_PATTERN )
         {
@@ -2227,7 +2208,7 @@ static __inline__ void SliceHeader( vpar_thread_t * p_vpar,
 
     if( *pi_mb_address < i_mb_address_save )
     {
-        intf_ErrMsg( "vpar error: slices do not follow, maybe a PES has been trashed\n" );
+        intf_ErrMsg( "vpar error: slices do not follow, maybe a PES has been trashed" );
         p_vpar->picture.b_error = 1;
         return;
     }
@@ -2264,7 +2245,7 @@ static __inline__ void SliceHeader( vpar_thread_t * p_vpar,
             if( ppf_parse_mb[i_structure]
                             [p_vpar->picture.i_coding_type] == NULL )
             {
-                intf_ErrMsg( "vpar error: bad ppf_parse_mb function pointer (struct:%d, coding type:%d)\n",
+                intf_ErrMsg( "vpar error: bad ppf_parse_mb function pointer (struct:%d, coding type:%d)",
                          i_structure, i_coding_type );
             }
             else
@@ -2283,8 +2264,9 @@ static __inline__ void SliceHeader( vpar_thread_t * p_vpar,
             return;
         }
     }
-    while( ShowBits( &p_vpar->bit_stream, 23 ) && !p_vpar->b_die );
-    NextStartCode( p_vpar );
+    while( ShowBits( &p_vpar->bit_stream, 23 )
+            && !p_vpar->p_fifo->b_die );
+    NextStartCode( &p_vpar->bit_stream );
 }
 
 /*****************************************************************************
@@ -2295,19 +2277,19 @@ void vpar_PictureData( vpar_thread_t * p_vpar, int i_mb_base )
     int         i_mb_address = 0;
     u32         i_dummy;
 
-    NextStartCode( p_vpar );
+    NextStartCode( &p_vpar->bit_stream );
     while( ((p_vpar->picture.i_coding_type != I_CODING_TYPE
                     && p_vpar->picture.i_coding_type != D_CODING_TYPE)
              || !p_vpar->picture.b_error)
            && i_mb_address < (p_vpar->sequence.i_mb_size
                     >> (p_vpar->picture.i_structure != FRAME_STRUCTURE))
-           && !p_vpar->b_die )
+           && !p_vpar->p_fifo->b_die )
     {
         if( ((i_dummy = ShowBits( &p_vpar->bit_stream, 32 ))
                  < SLICE_START_CODE_MIN) ||
             (i_dummy > SLICE_START_CODE_MAX) )
         {
-            intf_DbgMsg("vpar debug: premature end of picture\n");
+            intf_DbgMsg("vpar debug: premature end of picture");
             p_vpar->picture.b_error = 1;
             break;
         }