]> git.sesse.net Git - vlc/blobdiff - modules/codec/libmpeg2.c
Fixed osd_* functions when the OSD was not loaded.
[vlc] / modules / codec / libmpeg2.c
index 429f10f27393270ba3a043eda10c07f1296b565e..5a2ef6fe7987245632bddbfa0130263327d2dec0 100644 (file)
@@ -82,6 +82,8 @@ struct decoder_sys_t
     mtime_t         i_cc_pts;
     mtime_t         i_cc_dts;
     cc_data_t       cc;
+    uint8_t        *p_gop_user_data;
+    uint32_t        i_gop_user_data;
 };
 
 /*****************************************************************************
@@ -99,14 +101,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 +131,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;
@@ -156,6 +156,8 @@ static int OpenDecoder( vlc_object_t *p_this )
     p_dec->pf_get_cc = GetCc;
     cc_Init( &p_sys->cc );
 #endif
+    p_sys->p_gop_user_data = NULL;
+    p_sys->i_gop_user_data = 0;
 
 #if defined( __i386__ ) || defined( __x86_64__ )
     if( vlc_CPU() & CPU_CAPABILITY_MMX )
@@ -200,6 +202,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 +345,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 )
             {
@@ -464,7 +468,7 @@ static picture_t *DecodeBlock( decoder_t *p_dec, block_t **pp_block )
                 mpeg2_set_buf( p_sys->p_mpeg2dec, buf, p_pic );
                 mpeg2_stride( p_sys->p_mpeg2dec, p_pic->p[Y_PLANE].i_pitch );
             }
-            if( p_sys->p_info->user_data_len > 2 )
+            if( p_sys->p_info->user_data_len > 2 || p_sys->i_gop_user_data > 2 )
             {
                 p_sys->i_cc_pts = i_pts;
                 p_sys->i_cc_dts = i_dts;
@@ -476,11 +480,34 @@ static picture_t *DecodeBlock( decoder_t *p_dec, block_t **pp_block )
                     p_sys->i_cc_flags = BLOCK_FLAG_TYPE_B;
                 else p_sys->i_cc_flags = BLOCK_FLAG_TYPE_I;
 
-                cc_Extract( &p_sys->cc, &p_sys->p_info->user_data[0], p_sys->p_info->user_data_len );
+                if( p_sys->i_gop_user_data > 2 )
+                {
+                    /* We now have picture info for any cached user_data out of the gop */
+                    cc_Extract( &p_sys->cc, &p_sys->p_gop_user_data[0], p_sys->i_gop_user_data );
+                    p_sys->i_gop_user_data = 0;
+                }
+
+                /* Extract the CC from the user_data of the picture */
+                if( p_sys->p_info->user_data_len > 2 )
+                    cc_Extract( &p_sys->cc, &p_sys->p_info->user_data[0], p_sys->p_info->user_data_len );
             }
         }
         break;
 
+        case STATE_GOP:
+            /* There can be userdata in a GOP. It needs to be remembered for the next picture. */
+            if( p_sys->p_info->user_data_len > 2 )
+            {
+                free( p_sys->p_gop_user_data );
+                p_sys->p_gop_user_data = calloc( p_sys->p_info->user_data_len, sizeof(uint8_t) );
+                if( p_sys->p_gop_user_data )
+                {
+                    p_sys->i_gop_user_data = p_sys->p_info->user_data_len;
+                    memcpy( p_sys->p_gop_user_data, p_sys->p_info->user_data, p_sys->p_info->user_data_len );
+                }
+            }
+            break;
+
         case STATE_END:
         case STATE_SLICE:
             p_pic = NULL;
@@ -509,8 +536,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 */
@@ -600,6 +627,8 @@ static void CloseDecoder( vlc_object_t *p_this )
     decoder_t *p_dec = (decoder_t *)p_this;
     decoder_sys_t *p_sys = p_dec->p_sys;
 
+    free( p_sys->p_gop_user_data );
+
     if( p_sys->p_synchro ) decoder_SynchroRelease( p_sys->p_synchro );
 
     if( p_sys->p_mpeg2dec ) mpeg2_close( p_sys->p_mpeg2dec );
@@ -639,7 +668,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;
 
@@ -650,7 +679,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;