]> git.sesse.net Git - vlc/blobdiff - modules/codec/libmpeg2.c
Convenience target to run also the broken tests
[vlc] / modules / codec / libmpeg2.c
index b586e20c579a2b2a1df38a59be9df7a7de2fcaf4..4b6f282b7ea9a08f9e958f0a93734384ea70c243 100644 (file)
@@ -99,14 +99,14 @@ static void GetAR( decoder_t *p_dec );
 /*****************************************************************************
  * Module descriptor
  *****************************************************************************/
-vlc_module_begin();
-    set_description( N_("MPEG I/II video decoder (using libmpeg2)") );
-    set_capability( "decoder", 150 );
-    set_category( CAT_INPUT );
-    set_subcategory( SUBCAT_INPUT_VCODEC );
-    set_callbacks( OpenDecoder, CloseDecoder );
-    add_shortcut( "libmpeg2" );
-vlc_module_end();
+vlc_module_begin ()
+    set_description( N_("MPEG I/II video decoder (using libmpeg2)") )
+    set_capability( "decoder", 150 )
+    set_category( CAT_INPUT )
+    set_subcategory( SUBCAT_INPUT_VCODEC )
+    set_callbacks( OpenDecoder, CloseDecoder )
+    add_shortcut( "libmpeg2" )
+vlc_module_end ()
 
 /*****************************************************************************
  * OpenDecoder: probe the decoder and return score
@@ -129,12 +129,10 @@ static int OpenDecoder( vlc_object_t *p_this )
     }
 
     /* 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 )
+    if( ( p_dec->p_sys = p_sys = calloc( 1, sizeof(*p_sys)) ) == NULL )
         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;
@@ -200,6 +198,8 @@ 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;
 
     return VLC_SUCCESS;
 }
@@ -341,7 +341,7 @@ static picture_t *DecodeBlock( decoder_t *p_dec, block_t **pp_block )
 
             /* For some reason, libmpeg2 will put this pic twice in
              * discard_picture. This can be considered a bug in libmpeg2. */
-            p_dec->pf_picture_link( p_dec, p_pic );
+            decoder_LinkPicture( p_dec, p_pic );
 
             if( p_sys->p_synchro )
             {
@@ -423,6 +423,8 @@ static picture_t *DecodeBlock( decoder_t *p_dec, block_t **pp_block )
                 p_sys->p_info->current_picture->nb_fields, i_pts, i_dts,
                 p_sys->p_info->sequence->flags & SEQ_FLAG_LOW_DELAY );
 
+
+            bool b_skip = false;
             if( !p_dec->b_pace_control && !p_sys->b_preroll &&
                 !(p_sys->b_slice_i
                    && ((p_sys->p_info->current_picture->flags
@@ -432,11 +434,26 @@ static picture_t *DecodeBlock( decoder_t *p_dec, block_t **pp_block )
                                 & PIC_MASK_CODING_TYPE,
                               /*p_sys->p_vout->render_time*/ 0 /*FIXME*/,
                               p_sys->p_info->sequence->flags & SEQ_FLAG_LOW_DELAY ) )
+            {
+                b_skip = true;
+            }
+
+            p_pic = NULL;
+            if( !b_skip )
+                p_pic = GetNewPicture( p_dec, buf );
+
+            if( b_skip || !p_pic )
             {
                 mpeg2_skip( p_sys->p_mpeg2dec, 1 );
                 p_sys->b_skip = 1;
                 decoder_SynchroTrash( p_sys->p_synchro );
                 mpeg2_set_buf( p_sys->p_mpeg2dec, buf, NULL );
+
+                if( !b_skip )
+                {
+                    block_Release( p_block );
+                    return NULL;
+                }
             }
             else
             {
@@ -444,16 +461,9 @@ static picture_t *DecodeBlock( decoder_t *p_dec, block_t **pp_block )
                 p_sys->b_skip = 0;
                 decoder_SynchroDecode( p_sys->p_synchro );
 
-                if( (p_pic = GetNewPicture( p_dec, buf )) == NULL )
-                {
-                    block_Release( p_block );
-                    return NULL;
-                }
-
                 mpeg2_set_buf( p_sys->p_mpeg2dec, buf, p_pic );
                 mpeg2_stride( p_sys->p_mpeg2dec, p_pic->p[Y_PLANE].i_pitch );
             }
-#if MPEG2_RELEASE >= MPEG2_VERSION (0, 5, 0)
             if( p_sys->p_info->user_data_len > 2 )
             {
                 p_sys->i_cc_pts = i_pts;
@@ -468,7 +478,6 @@ static picture_t *DecodeBlock( decoder_t *p_dec, block_t **pp_block )
 
                 cc_Extract( &p_sys->cc, &p_sys->p_info->user_data[0], p_sys->p_info->user_data_len );
             }
-#endif
         }
         break;
 
@@ -500,8 +509,8 @@ 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 */
@@ -630,7 +639,7 @@ static picture_t *GetNewPicture( decoder_t *p_dec, uint8_t **pp_buf )
         VLC_FOURCC('I','4','2','0') : VLC_FOURCC('I','4','2','2');
 
     /* Get a new picture */
-    p_pic = p_dec->pf_vout_buffer_new( p_dec );
+    p_pic = decoder_NewPicture( p_dec );
 
     if( p_pic == NULL ) return NULL;
 
@@ -641,7 +650,7 @@ static picture_t *GetNewPicture( decoder_t *p_dec, uint8_t **pp_buf )
     p_pic->i_nb_fields = p_sys->p_info->current_picture != NULL ?
         p_sys->p_info->current_picture->nb_fields : 2;
 
-    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;