]> git.sesse.net Git - vlc/blobdiff - modules/access_filter/timeshift.c
Convert the new libvlc API (so, the one that is in src/control) not to use the old...
[vlc] / modules / access_filter / timeshift.c
index c813352803a55e79da3d81e62930795380a7be92..6dbba48becfce58f43868bb78af1f01497897c40 100644 (file)
 /*****************************************************************************
  * Preamble
  *****************************************************************************/
+#include <vlc/vlc.h>
+
+#include <stdio.h>
 #include <stdlib.h>
 
 #include <errno.h>
 
-#include <vlc/vlc.h>
 #include <vlc/input.h>
+#include "charset.h"
+
 #include <unistd.h>
 
 /*****************************************************************************
@@ -40,11 +44,15 @@ static int  Open ( vlc_object_t * );
 static void Close( vlc_object_t * );
 
 #define GRANULARITY_TEXT N_("Timeshift granularity")
-#define GRANULARITY_LONGTEXT N_( "Size of the temporary files use to store " \
-  "the timeshifted stream." )
+/// \bug [String] typo
+#define GRANULARITY_LONGTEXT N_( "This is the size of the temporary files " \
+  "that will be used to store the timeshifted streams." )
 #define DIR_TEXT N_("Timeshift directory")
 #define DIR_LONGTEXT N_( "Directory used to store the timeshift temporary " \
   "files." )
+#define FORCE_TEXT N_("Force use of the timeshift module")
+#define FORCE_LONGTEXT N_("Force use of the timeshift module even if the " \
+  "access declares that it can control pace or pause." )
 
 vlc_module_begin();
     set_shortname( _("Timeshift") );
@@ -58,6 +66,8 @@ vlc_module_begin();
     add_integer( "timeshift-granularity", 50, NULL, GRANULARITY_TEXT,
                  GRANULARITY_LONGTEXT, VLC_TRUE );
     add_directory( "timeshift-dir", 0, 0, DIR_TEXT, DIR_LONGTEXT, VLC_FALSE );
+    add_bool( "timeshift-force", VLC_FALSE, NULL, FORCE_TEXT, FORCE_LONGTEXT,
+              VLC_FALSE );
 vlc_module_end();
 
 /*****************************************************************************
@@ -110,17 +120,27 @@ static int Open( vlc_object_t *p_this )
     access_sys_t *p_sys;
     vlc_bool_t b_bool;
 
-    /* Only work with not pace controled access */
-    if( access2_Control( p_src, ACCESS_CAN_CONTROL_PACE, &b_bool ) || b_bool )
+    var_Create( p_access, "timeshift-force",
+                VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
+    if( var_GetBool( p_access, "timeshift-force" ) == VLC_TRUE )
     {
-        msg_Dbg( p_src, "ACCESS_CAN_CONTROL_PACE" );
-        return VLC_EGENERIC;
+        msg_Dbg( p_access, "Forcing use of timeshift even if access can control pace or pause" );
     }
-    /* Refuse access that can be paused */
-    if( access2_Control( p_src, ACCESS_CAN_PAUSE, &b_bool ) || b_bool )
+    else
     {
-        msg_Dbg( p_src, "ACCESS_CAN_PAUSE: timeshift useless" );
-        return VLC_EGENERIC;
+        /* Only work with not pace controled access */
+        if( access2_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 )
+        {
+            msg_Dbg( p_src, "ACCESS_CAN_PAUSE: timeshift useless" );
+            return VLC_EGENERIC;
+        }
     }
 
     /* */
@@ -535,35 +555,38 @@ static char *GetTmpFilePath( access_t *p_access )
     char *psz_dir = var_GetString( p_access, "timeshift-dir" );
     char *psz_filename_base;
 
-    if( psz_dir && !*psz_dir )
+    if( ( psz_dir != NULL ) && ( psz_dir[0] == '\0' ) )
     {
         free( psz_dir );
-        psz_dir = 0;
+        psz_dir = NULL;
     }
 
-    if( !psz_dir )
+    if( psz_dir == NULL )
     {
 #ifdef WIN32
+        char psz_local_dir[MAX_PATH];
         int i_size;
 
-        psz_dir = malloc( MAX_PATH + 1 );
-        i_size = GetTempPath( MAX_PATH, psz_dir );
+        i_size = GetTempPath( MAX_PATH, psz_local_dir );
         if( i_size <= 0 || i_size > MAX_PATH )
         {
-            if( !getcwd( psz_dir, MAX_PATH ) ) strcpy( psz_dir, "c:" );
+            if( !getcwd( psz_local_dir, MAX_PATH ) )
+                strcpy( psz_local_dir, "C:" );
         }
 
+        psz_dir = FromLocaleDup( psz_local_dir );
+
         /* remove last \\ if any */
         if( psz_dir[strlen(psz_dir)-1] == '\\' )
             psz_dir[strlen(psz_dir)-1] = '\0';
 #else
-
         psz_dir = strdup( "/tmp" );
 #endif
     }
 
     asprintf( &psz_filename_base, "%s/vlc-timeshift-%d-%d-",
               psz_dir, getpid(), p_access->i_object_id );
+    free( psz_dir );
 
     return psz_filename_base;
 }