]> git.sesse.net Git - vlc/blobdiff - src/video_decoder/video_decoder.c
* Fixed the BeOS compile typo.
[vlc] / src / video_decoder / video_decoder.c
index 9a3b5ae6f6920e83420289f30a63255a05f0bc57..769aaa21169785d60d7b04d63c6e08cad47a4a4f 100644 (file)
@@ -2,6 +2,7 @@
  * video_decoder.c : video decoder thread
  *****************************************************************************
  * Copyright (C) 1999, 2000 VideoLAN
+ * $Id: video_decoder.c,v 1.50 2001/05/30 17:03:12 sam Exp $
  *
  * Authors: Christophe Massiot <massiot@via.ecp.fr>
  *          GaĆ«l Hendryckx <jimmy@via.ecp.fr>
  *****************************************************************************/
 #include "defs.h"
 
-#include <stdlib.h>                                                /* free() */
 #include <unistd.h>                                              /* getpid() */
-#include <sys/types.h>                        /* on BSD, uio.h needs types.h */
-#include <sys/uio.h>                                          /* for input.h */
+
+#include <stdlib.h>                                                /* free() */
+#include <string.h>                                    /* memcpy(), memset() */
+#include <errno.h>                                                  /* errno */
 
 #include "config.h"
 #include "common.h"
 #include "threads.h"
 #include "mtime.h"
-#include "plugins.h"
 
 #include "intf_msg.h"
 
-#include "input.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.h"
 
 #include "vpar_blocks.h"
 #include "vpar_headers.h"
@@ -76,12 +77,12 @@ vdec_thread_t * vdec_CreateThread( vpar_thread_t *p_vpar /*, int *pi_status */ )
 {
     vdec_thread_t *     p_vdec;
 
-    intf_DbgMsg("vdec debug: creating video decoder thread\n");
+    intf_DbgMsg("vdec debug: creating video decoder thread");
 
     /* Allocate the memory needed to store the thread's structure */
     if ( (p_vdec = (vdec_thread_t *)malloc( sizeof(vdec_thread_t) )) == NULL )
     {
-        intf_ErrMsg("vdec error: not enough memory for vdec_CreateThread() to create the new thread\n");
+        intf_ErrMsg("vdec error: not enough memory for vdec_CreateThread() to create the new thread");
         return( NULL );
     }
 
@@ -100,12 +101,12 @@ vdec_thread_t * vdec_CreateThread( vpar_thread_t *p_vpar /*, int *pi_status */ )
     if ( vlc_thread_create(&p_vdec->thread_id, "video decoder",
          (vlc_thread_func_t)RunThread, (void *)p_vdec) )
     {
-        intf_ErrMsg("vdec error: can't spawn video decoder thread\n");
+        intf_ErrMsg("vdec error: can't spawn video decoder thread");
         free( p_vdec );
         return( NULL );
     }
 
-    intf_DbgMsg("vdec debug: video decoder thread (%p) created\n", p_vdec);
+    intf_DbgMsg("vdec debug: video decoder thread (%p) created", p_vdec);
     return( p_vdec );
 }
 
@@ -118,7 +119,7 @@ vdec_thread_t * vdec_CreateThread( vpar_thread_t *p_vpar /*, int *pi_status */ )
  *****************************************************************************/
 void vdec_DestroyThread( vdec_thread_t *p_vdec /*, int *pi_status */ )
 {
-    intf_DbgMsg("vdec debug: requesting termination of video decoder thread %p\n", p_vdec);
+    intf_DbgMsg("vdec debug: requesting termination of video decoder thread %p", p_vdec);
 
     /* Ask thread to kill itself */
     p_vdec->b_die = 1;
@@ -150,40 +151,25 @@ static int vdec_InitThread( vdec_thread_t *p_vdec )
 int vdec_InitThread( vdec_thread_t *p_vdec )
 #endif
 {
-#ifndef HAVE_MMX
-    int i_dummy;
-#endif
+    intf_DbgMsg("vdec debug: initializing video decoder thread %p", p_vdec);
 
-    intf_DbgMsg("vdec debug: initializing video decoder thread %p\n", p_vdec);
+    p_vdec->pf_decode_init  = p_vdec->p_vpar->pf_decode_init;
+    p_vdec->pf_decode_mb_c  = p_vdec->p_vpar->pf_decode_mb_c;
+    p_vdec->pf_decode_mb_bw = p_vdec->p_vpar->pf_decode_mb_bw;
 
-#ifndef HAVE_MMX
-    /* Init crop table */
-    p_vdec->pi_crop = p_vdec->pi_crop_buf + (VDEC_CROPRANGE >> 1);
-    for( i_dummy = -(VDEC_CROPRANGE >> 1); i_dummy < 0; i_dummy++ )
-    {
-        p_vdec->pi_crop[i_dummy] = 0;
-    }
-    for( ; i_dummy < 255; i_dummy ++ )
-    {
-        p_vdec->pi_crop[i_dummy] = i_dummy;
-    }
-    for( ; i_dummy < (VDEC_CROPRANGE >> 1) -1; i_dummy++ )
-    {
-        p_vdec->pi_crop[i_dummy] = 255;
-    }
-#endif
+    p_vdec->pf_decode_init( p_vdec );
 
 #ifdef VDEC_SMP
     /* Re-nice ourself */
     if( nice(VDEC_NICE) == -1 )
     {
-        intf_WarnMsg( 2, "vdec warning : couldn't nice() (%s)\n",
+        intf_WarnMsg( 2, "vdec warning : couldn't nice() (%s)",
                       strerror(errno) );
     }
 #endif
 
     /* Mark thread as running and return */
-    intf_DbgMsg("vdec debug: InitThread(%p) succeeded\n", p_vdec);
+    intf_DbgMsg("vdec debug: InitThread(%p) succeeded", p_vdec);
     return( 0 );
 }
 
@@ -214,326 +200,8 @@ static void ErrorThread( vdec_thread_t *p_vdec )
  *****************************************************************************/
 static void EndThread( vdec_thread_t *p_vdec )
 {
-    intf_DbgMsg("vdec debug: EndThread(%p)\n", p_vdec);
-}
-
-/*****************************************************************************
- * AddBlock : add a block
- *****************************************************************************/
-#ifndef HAVE_MMX
-static __inline__ void AddBlock( vdec_thread_t * p_vdec, dctelem_t * p_block,
-                                 yuv_data_t * p_data, int i_incr )
-{
-    int i_x, i_y;
-
-    for( i_y = 0; i_y < 8; i_y++ )
-    {
-        for( i_x = 0; i_x < 8; i_x++ )
-        {
-            *p_data = p_vdec->pi_crop[*p_data + *p_block++];
-            p_data++;
-        }
-        p_data += i_incr;
-    }
-}
-#else
-static __inline__ void AddBlock( vdec_thread_t * p_vdec, dctelem_t * p_block,
-                                          yuv_data_t * p_data, int i_incr )
-{
-    asm __volatile__ (
-            "pxor       %%mm7,%%mm7\n\t"
-
-            "movq       (%0),%%mm1\n\t"
-            "movq       %%mm1,%%mm2\n\t"
-            "punpckhbw  %%mm7,%%mm1\n\t"
-            "punpcklbw  %%mm7,%%mm2\n\t"
-            "paddw      (%1),%%mm2\n\t"
-            "paddw      8(%1),%%mm1\n\t"
-            "packuswb   %%mm1,%%mm2\n\t"
-            "movq       %%mm2,(%0)\n\t"
-            "addl       %2,%0\n\t"
-
-            "movq       (%0),%%mm1\n\t"
-            "movq       %%mm1,%%mm2\n\t"
-            "punpckhbw  %%mm7,%%mm1\n\t"
-            "punpcklbw  %%mm7,%%mm2\n\t"
-            "paddw      16(%1),%%mm2\n\t"
-            "paddw      24(%1),%%mm1\n\t"
-            "packuswb   %%mm1,%%mm2\n\t"
-            "movq       %%mm2,(%0)\n\t"
-            "addl       %2,%0\n\t"
-
-            "movq       (%0),%%mm1\n\t"
-            "movq       %%mm1,%%mm2\n\t"
-            "punpckhbw  %%mm7,%%mm1\n\t"
-            "punpcklbw  %%mm7,%%mm2\n\t"
-            "paddw      32(%1),%%mm2\n\t"
-            "paddw      40(%1),%%mm1\n\t"
-            "packuswb   %%mm1,%%mm2\n\t"
-            "movq       %%mm2,(%0)\n\t"
-            "addl       %2,%0\n\t"
-
-            "movq       (%0),%%mm1\n\t"
-            "movq       %%mm1,%%mm2\n\t"
-            "punpckhbw  %%mm7,%%mm1\n\t"
-            "punpcklbw  %%mm7,%%mm2\n\t"
-            "paddw      48(%1),%%mm2\n\t"
-            "paddw      56(%1),%%mm1\n\t"
-            "packuswb   %%mm1,%%mm2\n\t"
-            "movq       %%mm2,(%0)\n\t"
-            "addl       %2,%0\n\t"
-
-            "movq       (%0),%%mm1\n\t"
-            "movq       %%mm1,%%mm2\n\t"
-            "punpckhbw  %%mm7,%%mm1\n\t"
-            "punpcklbw  %%mm7,%%mm2\n\t"
-            "paddw      64(%1),%%mm2\n\t"
-            "paddw      72(%1),%%mm1\n\t"
-            "packuswb   %%mm1,%%mm2\n\t"
-            "movq       %%mm2,(%0)\n\t"
-            "addl       %2,%0\n\t"
-
-            "movq       (%0),%%mm1\n\t"
-            "movq       %%mm1,%%mm2\n\t"
-            "punpckhbw  %%mm7,%%mm1\n\t"
-            "punpcklbw  %%mm7,%%mm2\n\t"
-            "paddw      80(%1),%%mm2\n\t"
-            "paddw      88(%1),%%mm1\n\t"
-            "packuswb   %%mm1,%%mm2\n\t"
-            "movq       %%mm2,(%0)\n\t"
-            "addl       %2,%0\n\t"
-
-            "movq       (%0),%%mm1\n\t"
-            "movq       %%mm1,%%mm2\n\t"
-            "punpckhbw  %%mm7,%%mm1\n\t"
-            "punpcklbw  %%mm7,%%mm2\n\t"
-            "paddw      96(%1),%%mm2\n\t"
-            "paddw      104(%1),%%mm1\n\t"
-            "packuswb   %%mm1,%%mm2\n\t"
-            "movq       %%mm2,(%0)\n\t"
-            "addl       %2,%0\n\t"
-
-            "movq       (%0),%%mm1\n\t"
-            "movq       %%mm1,%%mm2\n\t"
-            "punpckhbw  %%mm7,%%mm1\n\t"
-            "punpcklbw  %%mm7,%%mm2\n\t"
-            "paddw      112(%1),%%mm2\n\t"
-            "paddw      120(%1),%%mm1\n\t"
-            "packuswb   %%mm1,%%mm2\n\t"
-            "movq       %%mm2,(%0)\n\t"
-
-            //"emms"
-            :"+r" (p_data): "r" (p_block),"r" (i_incr+8));
+    intf_DbgMsg("vdec debug: EndThread(%p)", p_vdec);
 }
-#endif
-
-
-/*****************************************************************************
- * CopyBlock : copy a block
- *****************************************************************************/
-#ifndef HAVE_MMX
-static __inline__ void CopyBlock( vdec_thread_t * p_vdec, dctelem_t * p_block,
-                                  yuv_data_t * p_data, int i_incr )
-{
-    int i_x, i_y;
-
-    for( i_y = 0; i_y < 8; i_y++ )
-    {
-        for( i_x = 0; i_x < 8; i_x++ )
-        {
-            *p_data++ = p_vdec->pi_crop[*p_block++];
-        }
-        p_data += i_incr;
-    }
-}
-#else
-static  __inline__ void CopyBlock( vdec_thread_t * p_vdec, dctelem_t * p_block,
-                                          yuv_data_t * p_data, int i_incr )
-{
-    asm __volatile__ (
-            "movq         (%1),%%mm0\n\t"
-            "packuswb   8(%1),%%mm0\n\t"
-            "movq        %%mm0,(%0)\n\t"
-            "addl           %2,%0\n\t"
-
-            "movq        16(%1),%%mm0\n\t"
-            "packuswb   24(%1),%%mm0\n\t"
-            "movq        %%mm0,(%0)\n\t"
-            "addl           %2,%0\n\t"
-
-            "movq        32(%1),%%mm0\n\t"
-            "packuswb   40(%1),%%mm0\n\t"
-            "movq        %%mm0,(%0)\n\t"
-            "addl           %2,%0\n\t"
-
-            "movq        48(%1),%%mm0\n\t"
-            "packuswb   56(%1),%%mm0\n\t"
-            "movq        %%mm0,(%0)\n\t"
-            "addl           %2,%0\n\t"
-
-            "movq        64(%1),%%mm0\n\t"
-            "packuswb   72(%1),%%mm0\n\t"
-            "movq        %%mm0,(%0)\n\t"
-            "addl           %2,%0\n\t"
-
-            "movq        80(%1),%%mm0\n\t"
-            "packuswb   88(%1),%%mm0\n\t"
-            "movq        %%mm0,(%0)\n\t"
-            "addl           %2,%0\n\t"
-
-            "movq        96(%1),%%mm0\n\t"
-            "packuswb   104(%1),%%mm0\n\t"
-            "movq        %%mm0,(%0)\n\t"
-            "addl           %2,%0\n\t"
-
-            "movq        112(%1),%%mm0\n\t"
-            "packuswb   120(%1),%%mm0\n\t"
-            "movq        %%mm0,(%0)\n\t"
-            //"emms"
-            :"+r" (p_data): "r" (p_block),"r" (i_incr+8));
-}
-#endif
-
-
-/*****************************************************************************
- * vdec_DecodeMacroblock : decode a macroblock of a picture
- *****************************************************************************/
-#define DECODEBLOCKSC( OPBLOCK )                                        \
-{                                                                       \
-    int             i_b, i_mask;                                        \
-                                                                        \
-    i_mask = 1 << (3 + p_mb->i_chroma_nb_blocks);                       \
-                                                                        \
-    /* luminance */                                                     \
-    for( i_b = 0; i_b < 4; i_b++, i_mask >>= 1 )                        \
-    {                                                                   \
-        if( p_mb->i_coded_block_pattern & i_mask )                      \
-        {                                                               \
-            /*                                                          \
-             * Inverse DCT (ISO/IEC 13818-2 section Annex A)            \
-             */                                                         \
-            (p_mb->pf_idct[i_b])( p_vdec, p_mb->ppi_blocks[i_b],        \
-                                  p_mb->pi_sparse_pos[i_b] );           \
-                                                                        \
-            /*                                                          \
-             * Adding prediction and coefficient data (ISO/IEC 13818-2  \
-             * section 7.6.8)                                           \
-             */                                                         \
-            OPBLOCK( p_vdec, p_mb->ppi_blocks[i_b],                     \
-                     p_mb->p_data[i_b], p_mb->i_addb_l_stride );        \
-        }                                                               \
-    }                                                                   \
-                                                                        \
-    /* chrominance */                                                   \
-    for( i_b = 4; i_b < 4 + p_mb->i_chroma_nb_blocks;                   \
-         i_b++, i_mask >>= 1 )                                          \
-    {                                                                   \
-        if( p_mb->i_coded_block_pattern & i_mask )                      \
-        {                                                               \
-            /*                                                          \
-             * Inverse DCT (ISO/IEC 13818-2 section Annex A)            \
-             */                                                         \
-            (p_mb->pf_idct[i_b])( p_vdec, p_mb->ppi_blocks[i_b],        \
-                                  p_mb->pi_sparse_pos[i_b] );           \
-                                                                        \
-            /*                                                          \
-             * Adding prediction and coefficient data (ISO/IEC 13818-2  \
-             * section 7.6.8)                                           \
-             */                                                         \
-            OPBLOCK( p_vdec, p_mb->ppi_blocks[i_b],                     \
-                     p_mb->p_data[i_b], p_mb->i_addb_c_stride );        \
-        }                                                               \
-    }                                                                   \
-}
-
-#define DECODEBLOCKSBW( OPBLOCK )                                       \
-{                                                                       \
-    int             i_b, i_mask;                                        \
-                                                                        \
-    i_mask = 1 << (3 + p_mb->i_chroma_nb_blocks);                       \
-                                                                        \
-    /* luminance */                                                     \
-    for( i_b = 0; i_b < 4; i_b++, i_mask >>= 1 )                        \
-    {                                                                   \
-        if( p_mb->i_coded_block_pattern & i_mask )                      \
-        {                                                               \
-            /*                                                          \
-             * Inverse DCT (ISO/IEC 13818-2 section Annex A)            \
-             */                                                         \
-            (p_mb->pf_idct[i_b])( p_vdec, p_mb->ppi_blocks[i_b],        \
-                                  p_mb->pi_sparse_pos[i_b] );           \
-                                                                        \
-            /*                                                          \
-             * Adding prediction and coefficient data (ISO/IEC 13818-2  \
-             * section 7.6.8)                                           \
-             */                                                         \
-            OPBLOCK( p_vdec, p_mb->ppi_blocks[i_b],                     \
-                     p_mb->p_data[i_b], p_mb->i_addb_l_stride );        \
-        }                                                               \
-    }                                                                   \
-}
-
-void vdec_DecodeMacroblockC ( vdec_thread_t *p_vdec, macroblock_t * p_mb )
-{
-    if( !(p_mb->i_mb_type & MB_INTRA) )
-    {
-        /*
-         * Motion Compensation (ISO/IEC 13818-2 section 7.6)
-         */
-        if( p_mb->pf_motion == 0 )
-        {
-            intf_ErrMsg( "vdec error: pf_motion set to NULL\n" );
-        }
-        else
-        {
-            p_mb->pf_motion( p_mb );
-        }
-
-        DECODEBLOCKSC( AddBlock )
-    }
-    else
-    {
-        DECODEBLOCKSC( CopyBlock )
-    }
-
-    /*
-     * Decoding is finished, release the macroblock and free
-     * unneeded memory.
-     */
-    vpar_ReleaseMacroblock( &p_vdec->p_vpar->vfifo, p_mb );
-}
-
-void vdec_DecodeMacroblockBW ( vdec_thread_t *p_vdec, macroblock_t * p_mb )
-{
-    if( !(p_mb->i_mb_type & MB_INTRA) )
-    {
-        /*
-         * Motion Compensation (ISO/IEC 13818-2 section 7.6)
-         */
-        if( p_mb->pf_motion == 0 )
-        {
-            intf_ErrMsg( "vdec error: pf_motion set to NULL\n" );
-        }
-        else
-        {
-            p_mb->pf_motion( p_mb );
-        }
-
-        DECODEBLOCKSBW( AddBlock )
-    }
-    else
-    {
-        DECODEBLOCKSBW( CopyBlock )
-    }
-
-    /*
-     * Decoding is finished, release the macroblock and free
-     * unneeded memory.
-     */
-    vpar_ReleaseMacroblock( &p_vdec->p_vpar->vfifo, p_mb );
-}
-
-
 
 /*****************************************************************************
  * RunThread: video decoder thread
@@ -543,7 +211,7 @@ void vdec_DecodeMacroblockBW ( vdec_thread_t *p_vdec, macroblock_t * p_mb )
  *****************************************************************************/
 static void RunThread( vdec_thread_t *p_vdec )
 {
-    intf_DbgMsg("vdec debug: running video decoder thread (%p) (pid == %i)\n",
+    intf_DbgMsg("vdec debug: running video decoder thread (%p) (pid == %i)",
                 p_vdec, getpid());
 
     /*
@@ -566,7 +234,7 @@ static void RunThread( vdec_thread_t *p_vdec )
 
         if( (p_mb = vpar_GetMacroblock( &p_vdec->p_vpar->vfifo )) != NULL )
         {
-            p_vdec->p_vpar->p_vout->vdec_DecodeMacroblock ( p_vdec, p_mb );
+            p_vdec->pf_decode_mb_c( p_vdec, p_mb );
         }
     }
 
@@ -582,3 +250,4 @@ static void RunThread( vdec_thread_t *p_vdec )
     EndThread( p_vdec );
     p_vdec->b_run = 0;
 }
+