]> git.sesse.net Git - vlc/blobdiff - modules/access_filter/record.c
Don't crash in record filter (Closes:#542)
[vlc] / modules / access_filter / record.c
index 55e18e7974297cba52c74b609d92ec98ce16c1b5..47989bb7fa14d21d684da5c1efefef9d684bd8f7 100644 (file)
@@ -1,8 +1,8 @@
 /*****************************************************************************
  * record.c
  *****************************************************************************
- * Copyright (C) 2005 VideoLAN
- * $Id: demux.c 7546 2004-04-29 13:53:29Z gbazin $
+ * Copyright (C) 2005 the VideoLAN team
+ * $Id$
  *
  * Author: Laurent Aimar <fenrir@via.ecp.fr>
  *
@@ -18,7 +18,7 @@
  *
  * You should have received a copy of the GNU General Public License
  * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
  *****************************************************************************/
 
 /*****************************************************************************
@@ -31,8 +31,9 @@
 #include <vlc/vout.h>
 
 #include "vlc_keys.h"
-#include <osd.h>
+#include <vlc_osd.h>
 #include <errno.h>
+#include <time.h>
 
 /*****************************************************************************
  * Module descriptor
@@ -53,8 +54,8 @@ vlc_module_begin();
     set_capability( "access_filter", 0 );
     add_shortcut( "record" );
 
-    add_string( "record-path", NULL, NULL,
-                RECORD_PATH_TXT, RECORD_PATH_LONGTXT, VLC_TRUE );
+    add_directory( "record-path", NULL, NULL,
+                   RECORD_PATH_TXT, RECORD_PATH_LONGTXT, VLC_TRUE );
 
     set_callbacks( Open, Close );
 
@@ -86,8 +87,26 @@ struct access_sys_t
 
     vout_thread_t *p_vout;
     int            i_vout_chan;
+
+    int i_update_sav;
 };
 
+static inline void PreUpdateFlags( access_t *p_access )
+{
+    access_t *p_src = p_access->p_source;
+    /* backport flags turned off 0 */
+    p_src->info.i_update &= p_access->p_sys->i_update_sav ^ (~p_access->info.i_update);
+}
+
+static inline void PostUpdateFlags( access_t *p_access )
+{
+    access_t *p_src = p_access->p_source;
+    /* */
+    p_access->info = p_src->info;
+    p_access->p_sys->i_update_sav = p_access->info.i_update;
+}
+
+
 /*****************************************************************************
  * Open:
  *****************************************************************************/
@@ -118,6 +137,7 @@ static int Open( vlc_object_t *p_this )
     p_sys->b_dump = VLC_FALSE;
     p_sys->p_vout = NULL;
     p_sys->i_vout_chan = -1;
+    p_sys->i_update_sav = p_access->info.i_update;
 
     if( !strncasecmp( p_src->psz_access, "dvb", 3 ) ||
         !strncasecmp( p_src->psz_access, "udp", 3 ) )
@@ -167,13 +187,16 @@ static block_t *Block( access_t *p_access )
     access_t     *p_src = p_access->p_source;
     block_t      *p_block;
 
+    /* */
+    PreUpdateFlags( p_access );
+
     /* */
     p_block = p_src->pf_block( p_src );
     if( p_block && p_block->i_buffer )
         Dump( p_access, p_block->p_buffer, p_block->i_buffer );
 
     /* */
-    p_access->info = p_src->info;
+    PostUpdateFlags( p_access );
 
     return p_block;
 }
@@ -186,13 +209,17 @@ static int Read( access_t *p_access, uint8_t *p_buffer, int i_len )
     access_t     *p_src = p_access->p_source;
     int i_ret;
 
+    /* */
+    PreUpdateFlags( p_access );
+
+    /* */
     i_ret = p_src->pf_read( p_src, p_buffer, i_len );
 
     if( i_ret > 0 )
         Dump( p_access, p_buffer, i_ret );
 
     /* */
-    p_access->info = p_src->info;
+    PostUpdateFlags( p_access );
 
     return i_ret;
 }
@@ -205,10 +232,14 @@ static int Control( access_t *p_access, int i_query, va_list args )
     access_t     *p_src = p_access->p_source;
     int i_ret;
 
+    /* */
+    PreUpdateFlags( p_access );
+
+    /* */
     i_ret = p_src->pf_control( p_src, i_query, args );
 
     /* */
-    p_access->info = p_src->info;
+    PostUpdateFlags( p_access );
 
     return i_ret;
 }
@@ -221,10 +252,14 @@ static int Seek( access_t *p_access, int64_t i_pos )
     access_t     *p_src = p_access->p_source;
     int i_ret;
 
+    /* */
+    PreUpdateFlags( p_access );
+
+    /* */
     i_ret = p_src->pf_seek( p_src, i_pos );
 
     /* */
-    p_access->info = p_src->info;
+    PostUpdateFlags( p_access );
 
     return i_ret;
 }
@@ -269,6 +304,7 @@ static void Notify( access_t *p_access, vlc_bool_t b_dump )
     vout_thread_t *p_vout;
 
     p_vout = vlc_object_find( p_access, VLC_OBJECT_VOUT, FIND_ANYWHERE );
+    if( !p_vout ) return;
 
     if( p_vout != p_sys->p_vout )
     {
@@ -326,16 +362,13 @@ static void Dump( access_t *p_access, uint8_t *p_buffer, int i_buffer )
         struct tm l;
 
 #ifdef HAVE_LOCALTIME_R
-        if( !localtime_r( &t, &l ) )
-            memset( &l, 0, sizeof(l) );
+        if( !localtime_r( &t, &l ) ) memset( &l, 0, sizeof(l) );
 #else
         /* Grrr */
         {
             struct tm *p_l = localtime( &t );
-            if( p_l )
-                l = *pÃ_l;
-            else
-                memset( &l, 0, sizeof(l) );
+            if( p_l ) l = *p_l;
+            else memset( &l, 0, sizeof(l) );
         }
 #endif
 
@@ -343,13 +376,22 @@ static void Dump( access_t *p_access, uint8_t *p_buffer, int i_buffer )
         if( p_input )
         {
             vlc_mutex_lock( &p_input->input.p_item->lock );
-            if( p_input->input.p_item->psz_name &&
-                strlen( p_input->input.p_item->psz_name ) < 64 )
-                psz_name = strdup( p_input->input.p_item->psz_name );
+            if( p_input->input.p_item->psz_name )
+            {
+                char *p = strrchr( p_input->input.p_item->psz_name, '/' );
+                if( p == NULL )
+                    p = strrchr( p_input->input.p_item->psz_name, '\\' );
+
+                if( p == NULL )
+                    psz_name = strdup( p_input->input.p_item->psz_name );
+                else if( p[1] != '\0' )
+                    psz_name = strdup( &p[1] );
+            }
             vlc_mutex_unlock( &p_input->input.p_item->lock );
 
             vlc_object_release( p_input );
         }
+
         if( psz_name == NULL )
             psz_name = strdup( "Unknown" );