]> git.sesse.net Git - vlc/blobdiff - modules/codec/xvmc/xxmc.c
Qt: menus, add VolumeMute/VolumeUp/VolumeDown in the audio menu to match OSX Audio...
[vlc] / modules / codec / xvmc / xxmc.c
index 1fece216e84d6c76cb3272984c499b6288871c24..e502780c4efeca83d362eabd1db670cbafd977af 100644 (file)
 /*****************************************************************************
  * Preamble
  *****************************************************************************/
-#include <vlc/vlc.h>
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include <vlc_common.h>
+#include <vlc_plugin.h>
 #include <vlc_vout.h>
 #include <vlc_codec.h>
+#include <vlc_codec_synchro.h>
 
-#include <mcheck.h>
+#include <unistd.h>
+#ifdef __GLIBC__
+    #include <mcheck.h>
+#endif
 
 #include "mpeg2.h"
 #include "attributes.h"
 #include "mpeg2_internal.h"
 #include "xvmc_vld.h"
 
-#include "vout_synchro.h"
-
 /* Aspect ratio (ISO/IEC 13818-2 section 6.3.3, table 6-3) */
 #define AR_SQUARE_PICTURE       1                           /* square pixels */
 #define AR_3_4_PICTURE          2                        /* 3:4 picture (TV) */
 #define AR_16_9_PICTURE         3              /* 16:9 picture (wide screen) */
 #define AR_221_1_PICTURE        4                  /* 2.21:1 picture (movie) */
 
-#include <unistd.h>
 /*****************************************************************************
  * decoder_sys_t : libmpeg2 decoder descriptor
  *****************************************************************************/
@@ -55,31 +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
      */
-    pes_packet_t     *p_pes;                  /* current PES we are decoding */
-    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
      */
-    vout_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;
 };
 
 /*****************************************************************************
@@ -96,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
@@ -110,12 +114,13 @@ static int OpenDecoder( vlc_object_t *p_this )
 {
 
     decoder_t *p_dec = (decoder_t*)p_this;
-    decoder_sys_t *p_sys;
+    decoder_sys_t *p_sys = NULL;
     uint32_t i_accel = 0;
     FILE *f_wd_dec; 
 
-    msg_Dbg(p_dec, "OpenDecoder Entering");
+#ifdef __GLIBC__
     mtrace();
+#endif
     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 */
@@ -129,17 +134,15 @@ static int OpenDecoder( vlc_object_t *p_this )
         return VLC_EGENERIC;
     }
 
+    msg_Dbg(p_dec, "OpenDecoder Entering");
+
     /* Allocate the memory needed to store the decoder's structure */
-    if( ( p_dec->p_sys = p_sys =
-          (decoder_sys_t *)malloc(sizeof(decoder_sys_t)) ) == NULL )
-    {
-        msg_Err( p_dec, "out of memory" );
-        return VLC_EGENERIC;
-    }
+    p_dec->p_sys = p_sys = (decoder_sys_t *)malloc(sizeof(decoder_sys_t));
+    if( !p_sys )
+        return VLC_ENOMEM;
 
     /* Initialize the thread properties */
     memset( p_sys, 0, sizeof(decoder_sys_t) );
-    p_sys->p_pes      = NULL;
     p_sys->p_mpeg2dec = NULL;
     p_sys->p_synchro  = NULL;
     p_sys->p_info     = NULL;
@@ -154,23 +157,23 @@ static int OpenDecoder( vlc_object_t *p_this )
     p_sys->b_skip     = 0;
 
 #if defined( __i386__ )
-    if( p_dec->p_libvlc->i_cpu & CPU_CAPABILITY_MMX )
+    if( vlc_CPU() & CPU_CAPABILITY_MMX )
     {
         i_accel |= MPEG2_ACCEL_X86_MMX;
     }
 
-    if( p_dec->p_libvlc->i_cpu & CPU_CAPABILITY_3DNOW )
+    if( vlc_CPU() & CPU_CAPABILITY_3DNOW )
     {
         i_accel |= MPEG2_ACCEL_X86_3DNOW;
     }
 
-    if( p_dec->p_libvlc->i_cpu & CPU_CAPABILITY_MMXEXT )
+    if( vlc_CPU() & CPU_CAPABILITY_MMXEXT )
     {
         i_accel |= MPEG2_ACCEL_X86_MMXEXT;
     }
 
 #elif defined( __powerpc__ ) || defined( SYS_DARWIN )
-    if( p_dec->p_libvlc->i_cpu & CPU_CAPABILITY_ALTIVEC )
+    if( vlc_CPU() & CPU_CAPABILITY_ALTIVEC )
     {
         i_accel |= MPEG2_ACCEL_PPC_ALTIVEC;
     }
@@ -198,7 +201,6 @@ static int OpenDecoder( vlc_object_t *p_this )
     p_dec->pf_decode_video = DecodeBlock;
 
     f_wd_dec = fopen("/vlc/dec_pid", "w");
-
     if (f_wd_dec != NULL)
     {
         fprintf(f_wd_dec, "%d\n", getpid());
@@ -254,7 +256,7 @@ static picture_t *DecodeBlock( decoder_t *p_dec, block_t **pp_block )
                     p_sys->p_info->sequence &&
                     p_sys->p_info->sequence->width != (unsigned int)-1 )
                 {
-                    vout_SynchroReset( p_sys->p_synchro );
+                    decoder_SynchroReset( p_sys->p_synchro );
                     if( p_sys->p_info->current_fbuf != NULL
                         && p_sys->p_info->current_fbuf->id != NULL )
                     {
@@ -273,10 +275,11 @@ static picture_t *DecodeBlock( decoder_t *p_dec, block_t **pp_block )
 
                     if ( p_sys->b_slice_i )
                     {
-                        vout_SynchroNewPicture( p_sys->p_synchro,
-                            I_CODING_TYPE, 2, 0, 0, p_sys->i_current_rate );
-                        vout_SynchroDecode( p_sys->p_synchro );
-                        vout_SynchroEnd( p_sys->p_synchro, I_CODING_TYPE, 0 );
+                        decoder_SynchroNewPicture( p_sys->p_synchro,
+                            I_CODING_TYPE, 2, 0, 0, p_sys->i_current_rate,
+                            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 );
                     }
                 }
 
@@ -375,13 +378,13 @@ 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 )
                 {
-                    vout_SynchroRelease( p_sys->p_synchro );
+                    decoder_SynchroRelease( p_sys->p_synchro );
                 }
-                p_sys->p_synchro = vout_SynchroInit( p_dec,
+                p_sys->p_synchro = decoder_SynchroInit( p_dec,
                     (uint32_t)((uint64_t)1001000000 * 27 /
                     p_sys->p_info->sequence->frame_period) );
                 p_sys->b_after_sequence_header = 1;
@@ -389,18 +392,19 @@ static picture_t *DecodeBlock( decoder_t *p_dec, block_t **pp_block )
             break;
 
             case STATE_PICTURE_2ND:
-                vout_SynchroNewPicture( p_sys->p_synchro,
+                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->i_current_rate,
+                        p_sys->p_info->sequence->flags & SEQ_FLAG_LOW_DELAY );
 
                 if( p_sys->b_skip )
                 {
-                    vout_SynchroTrash( p_sys->p_synchro );
+                    decoder_SynchroTrash( p_sys->p_synchro );
                 }
                 else
                 {
-                    vout_SynchroDecode( p_sys->p_synchro );
+                    decoder_SynchroDecode( p_sys->p_synchro );
                 }
                 break;
 
@@ -416,10 +420,11 @@ 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" );
-                    vout_SynchroNewPicture( p_sys->p_synchro,
-                        I_CODING_TYPE, 2, 0, 0, p_sys->i_current_rate );
-                    vout_SynchroDecode( p_sys->p_synchro );
-                    vout_SynchroEnd( p_sys->p_synchro, I_CODING_TYPE, 0 );
+                    decoder_SynchroNewPicture( p_sys->p_synchro,
+                        I_CODING_TYPE, 2, 0, 0, p_sys->i_current_rate,
+                        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 );
                     p_sys->b_slice_i = 1;
                 }
                 p_sys->b_after_sequence_header = 0;
@@ -448,29 +453,31 @@ static picture_t *DecodeBlock( decoder_t *p_dec, block_t **pp_block )
                 p_block->i_pts = p_block->i_dts = 0;
                 /* End hack */
 
-                vout_SynchroNewPicture( p_sys->p_synchro,
+                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->i_current_rate,
+                    p_sys->p_info->sequence->flags & SEQ_FLAG_LOW_DELAY );
 
                 if ( !(p_sys->b_slice_i
                     && ((p_sys->p_info->current_picture->flags
                             & PIC_MASK_CODING_TYPE) == P_CODING_TYPE))
-                    && !vout_SynchroChoose( p_sys->p_synchro,
+                    && !decoder_SynchroChoose( p_sys->p_synchro,
                                 p_sys->p_info->current_picture->flags
                                     & PIC_MASK_CODING_TYPE,
-                                /*FindVout(p_dec)->render_time*/ 0 /*FIXME*/ ) )
+                                /*FindVout(p_dec)->render_time*/ 0 /*FIXME*/,
+                                p_sys->p_info->sequence->flags & SEQ_FLAG_LOW_DELAY ) )
                 {
                     mpeg2_skip( p_sys->p_mpeg2dec, 1 );
                     p_sys->b_skip = 1;
-                    vout_SynchroTrash( p_sys->p_synchro );
+                    decoder_SynchroTrash( p_sys->p_synchro );
                     mpeg2_set_buf( p_sys->p_mpeg2dec, buf, NULL );
                 }
                 else
                 {
                     mpeg2_skip( p_sys->p_mpeg2dec, 0 );
                     p_sys->b_skip = 0;
-                    vout_SynchroDecode( p_sys->p_synchro );
+                    decoder_SynchroDecode( p_sys->p_synchro );
 
                     if( (p_pic = GetNewPicture( p_dec, buf )) == NULL )
                     {
@@ -504,7 +511,7 @@ static picture_t *DecodeBlock( decoder_t *p_dec, block_t **pp_block )
                 {
                     p_pic = (picture_t *)p_sys->p_info->display_fbuf->id;
 
-                    vout_SynchroEnd( p_sys->p_synchro,
+                    decoder_SynchroEnd( p_sys->p_synchro,
                                 p_sys->p_info->display_picture->flags
                                 & PIC_MASK_CODING_TYPE,
                                 p_sys->b_garbage_pic );
@@ -512,7 +519,7 @@ static picture_t *DecodeBlock( decoder_t *p_dec, block_t **pp_block )
 
                     if ( p_sys->p_picture_to_destroy != p_pic )
                     {
-                        p_pic->date = vout_SynchroDate( p_sys->p_synchro );
+                        p_pic->date = decoder_SynchroDate( p_sys->p_synchro );
                     }
                     else
                     {
@@ -524,10 +531,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 )
                 {
@@ -551,7 +558,7 @@ static picture_t *DecodeBlock( decoder_t *p_dec, block_t **pp_block )
                 ( ( p_sys->p_info->current_picture->flags &
                     PIC_MASK_CODING_TYPE) != B_CODING_TYPE ) )
                 {
-                    if( p_sys->p_synchro ) vout_SynchroReset( p_sys->p_synchro );
+                    if( p_sys->p_synchro ) decoder_SynchroReset( p_sys->p_synchro );
                 }
                 mpeg2_skip( p_sys->p_mpeg2dec, 1 );
                 p_sys->b_skip = 1;
@@ -586,10 +593,11 @@ static picture_t *DecodeBlock( decoder_t *p_dec, block_t **pp_block )
 
                 if( p_sys->b_slice_i )
                 {
-                    vout_SynchroNewPicture( p_sys->p_synchro,
-                                I_CODING_TYPE, 2, 0, 0, p_sys->i_current_rate );
-                    vout_SynchroDecode( p_sys->p_synchro );
-                    vout_SynchroEnd( p_sys->p_synchro, I_CODING_TYPE, 0 );
+                    decoder_SynchroNewPicture( p_sys->p_synchro,
+                        I_CODING_TYPE, 2, 0, 0, p_sys->i_current_rate,
+                        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 );
                 }
                 break;
             }
@@ -610,7 +618,7 @@ static void CloseDecoder( vlc_object_t *p_this )
     decoder_sys_t *p_sys = p_dec->p_sys;
     FILE *f_wd_dec;
 
-    if( p_sys->p_synchro ) vout_SynchroRelease( p_sys->p_synchro );
+    if( p_sys->p_synchro ) decoder_SynchroRelease( p_sys->p_synchro );
     if( p_sys->p_mpeg2dec ) mpeg2_close( p_sys->p_mpeg2dec );
 
     f_wd_dec = fopen("/vlc/dec_pid", "w");
@@ -668,7 +676,6 @@ static picture_t *GetNewPicture( decoder_t *p_dec, uint8_t **pp_buf )
     //msg_Dbg(p_dec, "GetNewPicture Entering");
     decoder_sys_t *p_sys = p_dec->p_sys;
     picture_t *p_pic;
-    static int nbpic = 0;
 
     p_dec->fmt_out.video.i_width = p_sys->p_info->sequence->width;
     p_dec->fmt_out.video.i_height = p_sys->p_info->sequence->height;
@@ -691,12 +698,12 @@ static picture_t *GetNewPicture( decoder_t *p_dec, uint8_t **pp_buf )
     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;
 
@@ -709,7 +716,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;