]> git.sesse.net Git - vlc/blobdiff - modules/access/dvdnav.c
dvdnav: fix memory leak.
[vlc] / modules / access / dvdnav.c
index c02db6433dbdaf3ddf2e9e4d43affc2c062c373f..9f5cf88343e97120621a65c77f07df48a78f58cb 100644 (file)
@@ -96,9 +96,7 @@ vlc_module_begin ()
     add_bool( "dvdnav-menu", true, NULL,
         MENU_TEXT, MENU_LONGTEXT, false )
     set_capability( "access_demux", 5 )
-    add_shortcut( "dvd" )
-    add_shortcut( "dvdnav" )
-    add_shortcut( "file" )
+    add_shortcut( "dvd", "dvdnav", "file" )
     set_callbacks( Open, Close )
 vlc_module_end ()
 
@@ -138,6 +136,12 @@ struct demux_sys_t
     uint8_t  palette[4][4];
     bool b_spu_change;
 
+    /* Aspect ration */
+    struct {
+        unsigned i_num;
+        unsigned i_den;
+    } sar;
+
     /* */
     int           i_title;
     input_title_t **title;
@@ -185,7 +189,7 @@ static int Open( vlc_object_t *p_this )
     char        *psz_name;
     char        *psz_code;
 
-    if( !p_demux->psz_path || !*p_demux->psz_path )
+    if( !p_demux->psz_file || !*p_demux->psz_file )
     {
         /* Only when selected */
         if( !p_demux->psz_access || !*p_demux->psz_access )
@@ -198,7 +202,7 @@ static int Open( vlc_object_t *p_this )
         }
     }
     else
-        psz_name = ToLocaleDup( p_demux->psz_path );
+        psz_name = ToLocaleDup( p_demux->psz_file );
 
 #ifdef WIN32
     /* Remove trailing backslash, otherwise dvdnav_open will fail */
@@ -207,7 +211,6 @@ static int Open( vlc_object_t *p_this )
         *(psz_name + strlen(psz_name) - 1) = '\0';
     }
 #endif
-    decode_URI( psz_name );
 
     /* Try some simple probing to avoid going through dvdnav_open too often */
     if( ProbeDVD( p_demux, psz_name ) != VLC_SUCCESS )
@@ -231,6 +234,8 @@ static int Open( vlc_object_t *p_this )
     p_sys->b_reset_pcr = false;
 
     ps_track_init( p_sys->tk );
+    p_sys->sar.i_num = 0;
+    p_sys->sar.i_den = 0;
     p_sys->i_mux_rate = 0;
     p_sys->i_pgc_length = 0;
     p_sys->b_spu_change = false;
@@ -412,6 +417,11 @@ static void Close( vlc_object_t *p_this )
         }
     }
 
+    /* Free the array of titles */
+    for( int i = 0; i < p_sys->i_title; i++ )
+        vlc_input_title_Delete( p_sys->title[i] );
+    TAB_CLEAN( p_sys->i_title, p_sys->title );
+
     dvdnav_close( p_sys->dvdnav );
     free( p_sys );
 }
@@ -744,6 +754,28 @@ static int Demux( demux_t *p_demux )
             tk->b_seen = false;
         }
 
+#if defined(HAVE_DVDNAV_GET_VIDEO_RESOLUTION)
+        uint32_t i_width, i_height;
+        if( dvdnav_get_video_resolution( p_sys->dvdnav,
+                                         &i_width, &i_height ) )
+            i_width = i_height = 0;
+        switch( dvdnav_get_video_aspect( p_sys->dvdnav ) )
+        {
+        case 0:
+            p_sys->sar.i_num = 4 * i_height;
+            p_sys->sar.i_den = 3 * i_width;
+            break;
+        case 3:
+            p_sys->sar.i_num = 16 * i_height;
+            p_sys->sar.i_den =  9 * i_width;
+            break;
+        default:
+            p_sys->sar.i_num = 0;
+            p_sys->sar.i_den = 0;
+            break;
+        }
+#endif
+
         if( dvdnav_current_title_info( p_sys->dvdnav, &i_title,
                                        &i_part ) == DVDNAV_STATUS_OK )
         {
@@ -1102,17 +1134,17 @@ static int DemuxBlock( demux_t *p_demux, const uint8_t *pkt, int i_pkt )
     demux_sys_t *p_sys = p_demux->p_sys;
     const uint8_t     *p = pkt;
 
-    while( p < &pkt[i_pkt] )
+    while( (p - pkt) <= (i_pkt - 6) )
     {
+        /* ps_pkt_size() needs at least 6 bytes */
         int i_size = ps_pkt_size( p, &pkt[i_pkt] - p );
-        block_t *p_pkt;
         if( i_size <= 0 )
         {
             break;
         }
 
         /* Create a block */
-        p_pkt = block_New( p_demux, i_size );
+        block_t *p_pkt = block_New( p_demux, i_size );
         memcpy( p_pkt->p_buffer, p, i_size);
 
         /* Parse it and send it */
@@ -1217,6 +1249,8 @@ static void ESNew( demux_t *p_demux, int i_id )
     /* Add a new ES */
     if( tk->fmt.i_cat == VIDEO_ES )
     {
+        tk->fmt.video.i_sar_num = p_sys->sar.i_num;
+        tk->fmt.video.i_sar_den = p_sys->sar.i_den;
         b_select = true;
     }
     else if( tk->fmt.i_cat == AUDIO_ES )