]> git.sesse.net Git - vlc/blobdiff - modules/access_filter/timeshift.c
Remove change_unsafe() no-op.
[vlc] / modules / access_filter / timeshift.c
index 97f650d1818cb8c57cdb35f0f4143834f63dc241..a1e353a51e882f927bea53b7999270b7fbf250bd 100644 (file)
@@ -29,7 +29,8 @@
 # include "config.h"
 #endif
 
-#include <vlc/vlc.h>
+#include <vlc_common.h>
+#include <vlc_plugin.h>
 
 #include <errno.h>
 
@@ -61,8 +62,8 @@ static void Close( vlc_object_t * );
   "access declares that it can control pace or pause." )
 
 vlc_module_begin();
-    set_shortname( _("Timeshift") );
-    set_description( _("Timeshift") );
+    set_shortname( N_("Timeshift") );
+    set_description( N_("Timeshift") );
     set_category( CAT_INPUT );
     set_subcategory( SUBCAT_INPUT_ACCESS_FILTER );
     set_capability( "access_filter", 0 );
@@ -72,7 +73,6 @@ vlc_module_begin();
     add_integer( "timeshift-granularity", 50, NULL, GRANULARITY_TEXT,
                  GRANULARITY_LONGTEXT, true );
     add_directory( "timeshift-dir", 0, 0, DIR_TEXT, DIR_LONGTEXT, false );
-        change_unsafe();
     add_bool( "timeshift-force", false, NULL, FORCE_TEXT, FORCE_LONGTEXT,
               false );
 vlc_module_end();
@@ -84,7 +84,7 @@ vlc_module_end();
 static int      Seek( access_t *, int64_t );
 static block_t *Block  ( access_t *p_access );
 static int      Control( access_t *, int i_query, va_list args );
-static void     Thread ( access_t *p_access );
+static void*    Thread ( vlc_object_t *p_this );
 static int      WriteBlockToFile( access_t *p_access, block_t *p_block );
 static block_t *ReadBlockFromFile( access_t *p_access );
 static char    *GetTmpFilePath( access_t *p_access );
@@ -104,9 +104,9 @@ struct access_sys_t
 {
     block_fifo_t *p_fifo;
 
-    int  i_files;
-    int  i_file_size;
-    int  i_write_size;
+    unsigned  i_files;
+    unsigned  i_file_size;
+    unsigned  i_write_size;
 
     ts_entry_t *p_read_list;
     ts_entry_t **pp_read_last;
@@ -137,14 +137,14 @@ static int Open( vlc_object_t *p_this )
     else
     {
         /* Only work with not pace controled access */
-        if( access2_Control( p_src, ACCESS_CAN_CONTROL_PACE, &b_bool ) ||
+        if( access_Control( p_src, ACCESS_CAN_CONTROL_PACE, &b_bool ) ||
             b_bool )
         {
             msg_Dbg( p_src, "ACCESS_CAN_CONTROL_PACE: timeshift useless" );
             return VLC_EGENERIC;
         }
         /* Refuse access that can be paused */
-        if( access2_Control( p_src, ACCESS_CAN_PAUSE, &b_bool ) || b_bool )
+        if( access_Control( p_src, ACCESS_CAN_PAUSE, &b_bool ) || b_bool )
         {
             msg_Dbg( p_src, "ACCESS_CAN_PAUSE: timeshift useless" );
             return VLC_EGENERIC;
@@ -159,9 +159,11 @@ static int Open( vlc_object_t *p_this )
     p_access->info = p_src->info;
 
     p_access->p_sys = p_sys = malloc( sizeof( access_sys_t ) );
+    if( !p_sys )
+        return VLC_ENOMEM;
 
     /* */
-    p_sys->p_fifo = block_FifoNew( p_access );
+    p_sys->p_fifo = block_FifoNew();
     p_sys->i_write_size = 0;
     p_sys->i_files = 0;
     p_sys->i_data = 0;
@@ -185,6 +187,7 @@ static int Open( vlc_object_t *p_this )
     if( vlc_thread_create( p_access, "timeshift thread", Thread,
                            VLC_THREAD_PRIORITY_LOW, false ) )
     {
+        Close( p_this );
         msg_Err( p_access, "cannot spawn timeshift access thread" );
         return VLC_EGENERIC;
     }
@@ -200,7 +203,7 @@ static void Close( vlc_object_t *p_this )
     access_t     *p_access = (access_t*)p_this;
     access_sys_t *p_sys = p_access->p_sys;
     ts_entry_t *p_entry;
-    int i;
+    unsigned i;
 
     msg_Dbg( p_access, "timeshift close called" );
     vlc_thread_join( p_access );
@@ -268,13 +271,15 @@ static block_t *Block( access_t *p_access )
 /*****************************************************************************
  *
  *****************************************************************************/
-static void Thread( access_t *p_access )
+static void* Thread( vlc_object_t* p_this )
 {
+    access_t *p_access = (access_t*)p_this;
     access_sys_t *p_sys = p_access->p_sys;
     access_t     *p_src = p_access->p_source;
     block_t      *p_block;
 
-    while( !p_access->b_die )
+    int canc = vlc_savecancel ();
+    while( vlc_object_alive (p_access) )
     {
         /* Get a new block from the source */
         if( p_src->pf_block )
@@ -283,16 +288,17 @@ static void Thread( access_t *p_access )
         }
         else
         {
-            if( ( p_block = block_New( p_access, 2048 ) ) == NULL ) break;
+            int i_read;
 
-            p_block->i_buffer =
-                p_src->pf_read( p_src, p_block->p_buffer, 2048 );
+            if( ( p_block = block_New( p_access, 2048 ) ) == NULL ) break;
 
-            if( p_block->i_buffer <= 0 )
+            i_read = p_src->pf_read( p_src, p_block->p_buffer, 2048 );
+            if( i_read <= 0 )
             {
               block_Release( p_block );
               p_block = NULL;
             }
+            p_block->i_buffer = i_read;
         }
 
         if( p_block == NULL )
@@ -319,7 +325,7 @@ static void Thread( access_t *p_access )
 
         /* Read from file to fill up the fifo */
         while( block_FifoSize( p_sys->p_fifo ) < TIMESHIFT_FIFO_MIN &&
-               !p_access->b_die )
+               vlc_object_alive (p_access) )
         {
             p_block = ReadBlockFromFile( p_access );
             if( !p_block ) break;
@@ -330,12 +336,12 @@ static void Thread( access_t *p_access )
 
     msg_Dbg( p_access, "timeshift: no more input data" );
 
-    while( !p_access->b_die &&
+    while( vlc_object_alive (p_access) &&
            (p_sys->p_read_list || block_FifoSize( p_sys->p_fifo ) ) )
     {
         /* Read from file to fill up the fifo */
         while( block_FifoSize( p_sys->p_fifo ) < TIMESHIFT_FIFO_MIN &&
-               !p_access->b_die && p_sys->p_read_list )
+               vlc_object_alive (p_access) && p_sys->p_read_list )
         {
             p_block = ReadBlockFromFile( p_access );
             if( !p_block ) break;
@@ -351,6 +357,8 @@ static void Thread( access_t *p_access )
 
     /* Send dummy packet to avoid deadlock in Block() */
     block_FifoPut( p_sys->p_fifo, block_New( p_access, 0 ) );
+    vlc_restorecancel (canc);
+    return NULL;
 }
 
 /*****************************************************************************
@@ -423,7 +431,7 @@ static int WriteBlockToFile( access_t *p_access, block_t *p_block )
     {
         FILE *file;
 
-        sprintf( p_sys->psz_filename, "%s%i.dat",
+        sprintf( p_sys->psz_filename, "%s%u.dat",
                  p_sys->psz_filename_base, p_sys->i_files );
         file = utf8_fopen( p_sys->psz_filename, "w+b" );
 
@@ -515,6 +523,8 @@ static block_t *ReadBlockFromFile( access_t *p_access )
 static int Seek( access_t *p_access, int64_t i_pos )
 {
     //access_sys_t *p_sys = p_access->p_sys;
+    (void)p_access;
+    (void)i_pos;
     return VLC_SUCCESS;
 }
 
@@ -550,7 +560,7 @@ static int Control( access_t *p_access, int i_query, va_list args )
 
     /* Forward everything else to the source access */
     default:
-        return access2_vaControl( p_access->p_source, i_query, args );
+        return access_vaControl( p_access->p_source, i_query, args );
     }
     return VLC_SUCCESS;
 }
@@ -593,8 +603,9 @@ static char *GetTmpFilePath( access_t *p_access )
 #endif
     }
 
-    asprintf( &psz_filename_base, "%s/vlc-timeshift-%d-%d-",
-              psz_dir, getpid(), p_access->i_object_id );
+    if( asprintf( &psz_filename_base, "%s/vlc-timeshift-%d-%p-",
+              psz_dir, getpid(), p_access ) == -1 )
+        psz_filename_base = NULL;
     free( psz_dir );
 
     return psz_filename_base;