]> git.sesse.net Git - vlc/blobdiff - modules/codec/xvmc/xxmc.c
Use <vlc_cpu.h>
[vlc] / modules / codec / xvmc / xxmc.c
index c6c6f1d62da4c3a07c6d7b718f6131906cd7d6b3..8d16ff5b7480f03a7ddd299f30218350e2c41dae 100644 (file)
 # include "config.h"
 #endif
 
-#include <vlc/vlc.h>
-#include <vlc_vout.h>
+#include <vlc_common.h>
+#include <vlc_plugin.h>
 #include <vlc_codec.h>
 #include <vlc_codec_synchro.h>
+#include <vlc_cpu.h>
 
 #include <unistd.h>
-#include <mcheck.h>
+#ifdef __GLIBC__
+    #include <mcheck.h>
+#endif
 
 #include "mpeg2.h"
-#include "attributes.h"
+//#include "attributes.h"
 #include "mpeg2_internal.h"
-#include "xvmc_vld.h"
+//#include "xvmc_vld.h"
 
 /* Aspect ratio (ISO/IEC 13818-2 section 6.3.3, table 6-3) */
 #define AR_SQUARE_PICTURE       1                           /* square pixels */
@@ -58,30 +61,29 @@ struct decoder_sys_t
      */
     mpeg2dec_t          *p_mpeg2dec;
     const mpeg2_info_t  *p_info;
-    vlc_bool_t          b_skip;
+    bool                b_skip;
 
     /*
      * Input properties
      */
-    mtime_t          i_pts;
-    mtime_t          i_previous_pts;
-    mtime_t          i_current_pts;
-    mtime_t          i_previous_dts;
-    mtime_t          i_current_dts;
-    int              i_current_rate;
-    picture_t *      p_picture_to_destroy;
-    vlc_bool_t       b_garbage_pic;
-    vlc_bool_t       b_after_sequence_header; /* is it the next frame after
-                                               * the sequence header ?    */
-    vlc_bool_t       b_slice_i;             /* intra-slice refresh stream */
+    mtime_t             i_pts;
+    mtime_t             i_previous_pts;
+    mtime_t             i_current_pts;
+    mtime_t             i_previous_dts;
+    mtime_t             i_current_dts;
+    int                 i_current_rate;
+    picture_t *         p_picture_to_destroy;
+    bool                b_garbage_pic;
+    bool                b_after_sequence_header; /* is it the next frame after
+                                                  * the sequence header ?    */
+    bool                b_slice_i;             /* intra-slice refresh stream */
 
     /*
      * Output properties
      */
-    decoder_synchro_t *p_synchro;
-    int            i_aspect;
-    mtime_t        i_last_frame_pts;
-
+    decoder_synchro_t   *p_synchro;
+    int                 i_aspect;
+    mtime_t             i_last_frame_pts;
 };
 
 /*****************************************************************************
@@ -98,12 +100,12 @@ static picture_t *GetNewPicture( decoder_t *, uint8_t ** );
 /*****************************************************************************
  * Module descriptor
  *****************************************************************************/
-vlc_module_begin();
-    set_description( _("MPEG I/II hw video decoder (using libmpeg2)") );
-    set_capability( "decoder", 160 );
-    set_callbacks( OpenDecoder, CloseDecoder );
-    add_shortcut( "xxmc" );
-vlc_module_end();
+vlc_module_begin ()
+    set_description( N_("MPEG I/II hw video decoder (using libmpeg2)") )
+    set_capability( "decoder", 140 )
+    set_callbacks( OpenDecoder, CloseDecoder )
+    add_shortcut( "xxmc" )
+vlc_module_end ()
 
 /*****************************************************************************
  * OpenDecoder: probe the decoder and return score
@@ -116,31 +118,38 @@ static int OpenDecoder( vlc_object_t *p_this )
     uint32_t i_accel = 0;
     FILE *f_wd_dec; 
 
-    msg_Dbg(p_dec, "OpenDecoder Entering");
+#ifdef __GLIBC__
     mtrace();
-    if( p_dec->fmt_in.i_codec != VLC_FOURCC('m','p','g','v') &&
-        p_dec->fmt_in.i_codec != VLC_FOURCC('m','p','g','1') &&
-        /* Pinnacle hardware-mpeg1 */
-        p_dec->fmt_in.i_codec != VLC_FOURCC('P','I','M','1') &&
-        /* VIA hardware-mpeg2 */
-        p_dec->fmt_in.i_codec != VLC_FOURCC('X','x','M','C') &&
-        /* ATI Video */
-        p_dec->fmt_in.i_codec != VLC_FOURCC('V','C','R','2') &&
-        p_dec->fmt_in.i_codec != VLC_FOURCC('m','p','g','2') )
-    {
+#endif
+    if( p_dec->fmt_in.i_codec != VLC_CODEC_MPGV )
         return VLC_EGENERIC;
+    /* Select onl recognized original format (standard mpeg video) */
+    switch( p_dec->fmt_in.i_original_fourcc )
+    {
+    case VLC_FOURCC('m','p','g','1'):
+    case VLC_FOURCC('m','p','g','2'):
+    case VLC_FOURCC('m','p','g','v'):
+    /* Pinnacle hardware-mpeg1 */
+    case VLC_FOURCC('P','I','M','1'):
+    /* VIA hardware-mpeg2 */
+    case VLC_FOURCC('X','x','M','C'):
+    /* ATI Video */
+    case VLC_FOURCC('V','C','R','2'):
+        break;
+    default:
+        if( p_dec->fmt_in.i_original_fourcc )
+            return VLC_EGENERIC;
+        break;
     }
 
+    msg_Dbg(p_dec, "OpenDecoder Entering");
+
     /* Allocate the memory needed to store the decoder's structure */
-    p_dec->p_sys = p_sys = (decoder_sys_t *)malloc(sizeof(decoder_sys_t));
+    p_dec->p_sys = p_sys = calloc( 1, sizeof(*p_sys) );
     if( !p_sys )
-    {
-        msg_Err( p_dec, "out of memory" );
-        return VLC_EGENERIC;
-    }
+        return VLC_ENOMEM;
 
     /* Initialize the thread properties */
-    memset( p_sys, 0, sizeof(decoder_sys_t) );
     p_sys->p_mpeg2dec = NULL;
     p_sys->p_synchro  = NULL;
     p_sys->p_info     = NULL;
@@ -197,9 +206,10 @@ static int OpenDecoder( vlc_object_t *p_this )
     p_sys->p_info = mpeg2_info( p_sys->p_mpeg2dec );
 
     p_dec->pf_decode_video = DecodeBlock;
+    p_dec->fmt_out.i_cat = VIDEO_ES;
+    p_dec->fmt_out.i_codec = 0;
 
     f_wd_dec = fopen("/vlc/dec_pid", "w");
-
     if (f_wd_dec != NULL)
     {
         fprintf(f_wd_dec, "%d\n", getpid());
@@ -211,6 +221,7 @@ static int OpenDecoder( vlc_object_t *p_this )
     return VLC_SUCCESS;
 }
 
+#if 0
 static void WriteDecodeFile(int value)
 {
     FILE *f_wd_ok;
@@ -223,6 +234,7 @@ static void WriteDecodeFile(int value)
         fclose(f_wd_ok);
     }
 }
+#endif
 
 /*****************************************************************************
  * RunDecoder: the libmpeg2 decoder
@@ -275,7 +287,7 @@ static picture_t *DecodeBlock( decoder_t *p_dec, block_t **pp_block )
                     if ( p_sys->b_slice_i )
                     {
                         decoder_SynchroNewPicture( p_sys->p_synchro,
-                            I_CODING_TYPE, 2, 0, 0, p_sys->i_current_rate,
+                            I_CODING_TYPE, 2, 0, 0,
                             p_sys->p_info->sequence->flags & SEQ_FLAG_LOW_DELAY );
                         decoder_SynchroDecode( p_sys->p_synchro );
                         decoder_SynchroEnd( p_sys->p_synchro, I_CODING_TYPE, 0 );
@@ -377,7 +389,7 @@ static picture_t *DecodeBlock( decoder_t *p_dec, block_t **pp_block )
                 mpeg2_set_buf( p_sys->p_mpeg2dec, buf, p_pic );
 
                 p_pic->date = 0;
-                p_dec->pf_picture_link( p_dec, p_pic );
+                decoder_LinkPicture( p_dec, p_pic );
 
                 if( p_sys->p_synchro )
                 {
@@ -394,7 +406,7 @@ static picture_t *DecodeBlock( decoder_t *p_dec, block_t **pp_block )
                 decoder_SynchroNewPicture( p_sys->p_synchro,
                         p_sys->p_info->current_picture->flags & PIC_MASK_CODING_TYPE,
                         p_sys->p_info->current_picture->nb_fields,
-                        0, 0, p_sys->i_current_rate,
+                        0, 0,
                         p_sys->p_info->sequence->flags & SEQ_FLAG_LOW_DELAY );
 
                 if( p_sys->b_skip )
@@ -420,7 +432,7 @@ static picture_t *DecodeBlock( decoder_t *p_dec, block_t **pp_block )
                     /* Intra-slice refresh. Simulate a blank I picture. */
                     msg_Dbg( p_dec, "intra-slice refresh stream" );
                     decoder_SynchroNewPicture( p_sys->p_synchro,
-                        I_CODING_TYPE, 2, 0, 0, p_sys->i_current_rate,
+                        I_CODING_TYPE, 2, 0, 0,
                         p_sys->p_info->sequence->flags & SEQ_FLAG_LOW_DELAY );
                     decoder_SynchroDecode( p_sys->p_synchro );
                     decoder_SynchroEnd( p_sys->p_synchro, I_CODING_TYPE, 0 );
@@ -455,7 +467,7 @@ static picture_t *DecodeBlock( decoder_t *p_dec, block_t **pp_block )
                 decoder_SynchroNewPicture( p_sys->p_synchro,
                     p_sys->p_info->current_picture->flags & PIC_MASK_CODING_TYPE,
                     p_sys->p_info->current_picture->nb_fields, i_pts,
-                    0, p_sys->i_current_rate,
+                    0,
                     p_sys->p_info->sequence->flags & SEQ_FLAG_LOW_DELAY );
 
                 if ( !(p_sys->b_slice_i
@@ -484,8 +496,8 @@ static picture_t *DecodeBlock( decoder_t *p_dec, block_t **pp_block )
                         return NULL;
                     }
 
-                    p_sys->p_mpeg2dec->ptr_forward_ref_picture = p_sys->p_mpeg2dec->fbuf[2]->id;
-                    p_sys->p_mpeg2dec->ptr_backward_ref_picture = p_sys->p_mpeg2dec->fbuf[1]->id;
+                    //p_sys->p_mpeg2dec->ptr_forward_ref_picture = p_sys->p_mpeg2dec->fbuf[2]->id;
+                    //p_sys->p_mpeg2dec->ptr_backward_ref_picture = p_sys->p_mpeg2dec->fbuf[1]->id;
 
                     if ((p_sys->p_info->current_picture->flags & PIC_MASK_CODING_TYPE) != B_CODING_TYPE)
                     {
@@ -493,9 +505,9 @@ static picture_t *DecodeBlock( decoder_t *p_dec, block_t **pp_block )
                         //    p_sys->p_mpeg2dec->ptr_forward_ref_picture != picture->backward_reference_frame)
                         //    p_pic->forward_reference_frame->free (p_pic->forward_reference_frame);
 
-                        p_sys->p_mpeg2dec->ptr_forward_ref_picture =
-                                    p_sys->p_mpeg2dec->ptr_backward_ref_picture;
-                        p_sys->p_mpeg2dec->ptr_backward_ref_picture = (void *)p_pic;
+                        //p_sys->p_mpeg2dec->ptr_forward_ref_picture =
+                        //            p_sys->p_mpeg2dec->ptr_backward_ref_picture;
+                        //p_sys->p_mpeg2dec->ptr_backward_ref_picture = (void *)p_pic;
                     }
                     mpeg2_set_buf( p_sys->p_mpeg2dec, buf, p_pic );
                 }
@@ -530,10 +542,10 @@ static picture_t *DecodeBlock( decoder_t *p_dec, block_t **pp_block )
                 if( p_sys->p_info->discard_fbuf &&
                     p_sys->p_info->discard_fbuf->id )
                 {
-                    p_dec->pf_picture_unlink( p_dec, p_sys->p_info->discard_fbuf->id );
+                    decoder_UnlinkPicture( p_dec, p_sys->p_info->discard_fbuf->id );
                 }
                 /* For still frames */
-                //if( state == STATE_END && p_pic ) p_pic->b_force = VLC_TRUE;
+                //if( state == STATE_END && p_pic ) p_pic->b_force = true;
 
                 if( p_pic )
                 {
@@ -593,7 +605,7 @@ static picture_t *DecodeBlock( decoder_t *p_dec, block_t **pp_block )
                 if( p_sys->b_slice_i )
                 {
                     decoder_SynchroNewPicture( p_sys->p_synchro,
-                        I_CODING_TYPE, 2, 0, 0, p_sys->i_current_rate,
+                        I_CODING_TYPE, 2, 0, 0,
                         p_sys->p_info->sequence->flags & SEQ_FLAG_LOW_DELAY );
                     decoder_SynchroDecode( p_sys->p_synchro );
                     decoder_SynchroEnd( p_sys->p_synchro, I_CODING_TYPE, 0 );
@@ -630,6 +642,7 @@ static void CloseDecoder( vlc_object_t *p_this )
     free( p_sys );
 }
 
+#if 0
 static double get_aspect_ratio( decoder_t *p_dec )
 {
     decoder_sys_t *p_sys = p_dec->p_sys;
@@ -642,7 +655,7 @@ static double get_aspect_ratio( decoder_t *p_dec )
     {
         /* these hardcoded values are defined on mpeg2 standard for
         * aspect ratio. other values are reserved or forbidden.  */
-        switch( p_sys->p_mpeg2dec->decoder.aspect_ratio_information )
+        /*switch( p_sys->p_mpeg2dec->decoder.aspect_ratio_information )
         {
             case 2:
                 ratio = 4.0/3.0;
@@ -654,19 +667,21 @@ static double get_aspect_ratio( decoder_t *p_dec )
                 ratio = 2.11/1.0;
                 break;
             case 1:
-                default:
+                default:*/
                 ratio = (double)p_sys->p_mpeg2dec->decoder.width/(double)p_sys->p_mpeg2dec->decoder.height;
-            break;
-        }
+        /*    break;
+        }*/
     }
     else
     {
         /* mpeg1 constants refer to pixel aspect ratio */
         ratio = (double)p_sys->p_mpeg2dec->decoder.width/(double)p_sys->p_mpeg2dec->decoder.height;
-        ratio /= mpeg1_pel_ratio[p_sys->p_mpeg2dec->decoder.aspect_ratio_information];
+        /* ratio /= mpeg1_pel_ratio[p_sys->p_mpeg2dec->decoder.aspect_ratio_information]; */
     }
     return ratio;
 }
+#endif
+
 /*****************************************************************************
  * GetNewPicture: Get a new picture from the vout and set the buf struct
  *****************************************************************************/
@@ -691,18 +706,18 @@ static picture_t *GetNewPicture( decoder_t *p_dec, uint8_t **pp_buf )
     p_dec->fmt_out.i_codec =
         ( p_sys->p_info->sequence->chroma_height <
           p_sys->p_info->sequence->height ) ?
-        VLC_FOURCC('I','4','2','0') : VLC_FOURCC('I','4','2','2');
+        VLC_CODEC_I420 : VLC_CODEC_I422;
 
 #if 0
     p_sys->f_wd_nb = fopen("/vlc/dec_nb", "w");
     if (p_sys->f_wd_nb != NULL)
     {
-//         fprintf(p_sys->f_wd_nb, "%d\n", mdate());
+//      fprintf(p_sys->f_wd_nb, "%d\n", mdate());
         fprintf(p_sys->f_wd_nb, "%s\n", mdate());
-       fflush(p_sys->f_wd_nb); 
+        fflush(p_sys->f_wd_nb);
     }
 #endif
-    p_pic = p_dec->pf_vout_buffer_new( p_dec );
+    p_pic = decoder_NewPicture( p_dec );
 
     if( p_pic == NULL ) return NULL;
 
@@ -715,7 +730,7 @@ static picture_t *GetNewPicture( decoder_t *p_dec, uint8_t **pp_buf )
     p_pic->format.i_frame_rate = p_dec->fmt_out.video.i_frame_rate;
     p_pic->format.i_frame_rate_base = p_dec->fmt_out.video.i_frame_rate_base;
 
-    p_dec->pf_picture_link( p_dec, p_pic );
+    decoder_LinkPicture( p_dec, p_pic );
 
     pp_buf[0] = p_pic->p[0].p_pixels;
     pp_buf[1] = p_pic->p[1].p_pixels;
@@ -728,8 +743,8 @@ static picture_t *GetNewPicture( decoder_t *p_dec, uint8_t **pp_buf )
                                        p_dec->fmt_out.video.i_height,
                                        p_dec->fmt_out.video.i_aspect,
                                        format, flags);
-#endif
     mpeg2_xxmc_choose_coding( p_dec, &p_sys->p_mpeg2dec->decoder, p_pic,
                               get_aspect_ratio(p_dec), 0 );
+#endif
     return p_pic;
 }