Commit 6b0d4285 authored by Gildas Bazin's avatar Gildas Bazin

* modules/access_filter/timeshift.c: complete rewrite. Configurable...

* modules/access_filter/timeshift.c: complete rewrite. Configurable granularity so it doesn't waste as much disk space + deals with full disk by overwritting oldest data.
parent 37a65fa6
/***************************************************************************** /*****************************************************************************
* timeshift.c * timeshift.c: access filter implementing timeshifting capabilities
***************************************************************************** *****************************************************************************
* Copyright (C) 2005 the VideoLAN team * Copyright (C) 2005 the VideoLAN team
* $Id: demux.c 7546 2004-04-29 13:53:29Z gbazin $ * $Id$
* *
* Author: Laurent Aimar <fenrir@via.ecp.fr> * Authors: Laurent Aimar <fenrir@via.ecp.fr>
* Gildas Bazin <gbazin@videolan.org>
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
...@@ -38,6 +39,13 @@ ...@@ -38,6 +39,13 @@
static int Open ( vlc_object_t * ); static int Open ( vlc_object_t * );
static void Close( 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." )
#define DIR_TEXT N_("Timeshift directory")
#define DIR_LONGTEXT N_( "Directory used to store the timeshift temporary " \
"files." )
vlc_module_begin(); vlc_module_begin();
set_shortname( _("Timeshift") ); set_shortname( _("Timeshift") );
set_description( _("Timeshift") ); set_description( _("Timeshift") );
...@@ -46,34 +54,50 @@ vlc_module_begin(); ...@@ -46,34 +54,50 @@ vlc_module_begin();
set_capability( "access_filter", 0 ); set_capability( "access_filter", 0 );
add_shortcut( "timeshift" ); add_shortcut( "timeshift" );
set_callbacks( Open, Close ); set_callbacks( Open, Close );
add_integer( "timeshift-granularity", 50, NULL, GRANULARITY_TEXT,
GRANULARITY_LONGTEXT, VLC_TRUE );
add_directory( "timeshift-dir", 0, 0, DIR_TEXT, DIR_LONGTEXT, VLC_FALSE );
vlc_module_end(); vlc_module_end();
/***************************************************************************** /*****************************************************************************
* Local prototypes * Local prototypes
*****************************************************************************/ *****************************************************************************/
static int Seek( access_t *, int64_t );
static block_t *Block ( access_t *p_access ); static block_t *Block ( access_t *p_access );
static int Control( access_t *, int i_query, va_list args ); static int Control( access_t *, int i_query, va_list args );
static void Thread ( access_t * ); static void Thread ( access_t *p_access );
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 );
#define TIMESHIFT_FIFO_MAX (4*1024*1024) #define TIMESHIFT_FIFO_MAX (10*1024*1024)
#define TIMESHIFT_FIFO_MIN (TIMESHIFT_FIFO_MAX/4) #define TIMESHIFT_FIFO_MIN (TIMESHIFT_FIFO_MAX/4)
#define TMP_FILE_MAX 256
struct access_sys_t typedef struct ts_entry_t
{ {
block_fifo_t *p_fifo; FILE *file;
struct ts_entry_t *p_next;
vlc_bool_t b_opened; } ts_entry_t;
FILE *t1, *t2; struct access_sys_t
{
block_fifo_t *p_fifo;
char *psz_tmp1; int i_files;
char *psz_tmp2; int i_file_size;
int i_write_size;
FILE *w; ts_entry_t *p_read_list;
int i_w; ts_entry_t **pp_read_last;
ts_entry_t *p_write_list;
ts_entry_t **pp_write_last;
FILE *r; char *psz_filename_base;
char *psz_filename;
}; };
/***************************************************************************** /*****************************************************************************
...@@ -85,10 +109,6 @@ static int Open( vlc_object_t *p_this ) ...@@ -85,10 +109,6 @@ static int Open( vlc_object_t *p_this )
access_t *p_src = p_access->p_source; access_t *p_src = p_access->p_source;
access_sys_t *p_sys; access_sys_t *p_sys;
vlc_bool_t b_bool; vlc_bool_t b_bool;
#ifdef WIN32
char buffer[4096];
int i_size;
#endif
/* Only work with not pace controled access */ /* Only work with not pace controled access */
if( access2_Control( p_src, ACCESS_CAN_CONTROL_PACE, &b_bool ) || b_bool ) if( access2_Control( p_src, ACCESS_CAN_CONTROL_PACE, &b_bool ) || b_bool )
...@@ -106,41 +126,32 @@ static int Open( vlc_object_t *p_this ) ...@@ -106,41 +126,32 @@ static int Open( vlc_object_t *p_this )
/* */ /* */
p_access->pf_read = NULL; p_access->pf_read = NULL;
p_access->pf_block = Block; p_access->pf_block = Block;
p_access->pf_seek = NULL; p_access->pf_seek = Seek;
p_access->pf_control = Control; p_access->pf_control = Control;
p_access->info = p_src->info; p_access->info = p_src->info;
p_access->p_sys = p_sys = malloc( sizeof( access_sys_t ) ); p_access->p_sys = p_sys = malloc( sizeof( access_sys_t ) );
/* */ /* */
p_sys->p_fifo = block_FifoNew( p_access ); p_sys->p_fifo = block_FifoNew( p_access );
p_sys->b_opened = VLC_FALSE; p_sys->i_write_size = 0;
p_sys->t1 = p_sys->t2 = NULL; p_sys->i_files = 0;
p_sys->w = p_sys->r = NULL;
p_sys->i_w = 0;
#ifdef WIN32 p_sys->p_read_list = NULL;
i_size = GetTempPath( 4095, buffer ); p_sys->pp_read_last = &p_sys->p_read_list;
if( i_size <= 0 || i_size >= 4095 ) p_sys->p_write_list = NULL;
{ p_sys->pp_write_last = &p_sys->p_write_list;
if( getcwd( buffer, 4095 ) == NULL )
strcpy( buffer, "c:" );
}
/* remove last \\ if any */
if( buffer[strlen(buffer)-1] == '\\' )
buffer[strlen(buffer)-1] = '\0';
asprintf( &p_sys->psz_tmp1, "%s\\vlc-timeshift-%d-%d-1.dat", var_Create( p_access, "timeshift-dir",
buffer, GetCurrentProcessId(), p_access->i_object_id ); VLC_VAR_DIRECTORY | VLC_VAR_DOINHERIT );
asprintf( &p_sys->psz_tmp2, "%s\\vlc-timeshift-%d-%d-2.dat", var_Create( p_access, "timeshift-granularity",
buffer, GetCurrentProcessId(), p_access->i_object_id ); VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
#else p_sys->i_file_size = var_GetInteger( p_access, "timeshift-granularity" );
asprintf( &p_sys->psz_tmp1, "/tmp/vlc-timeshift-%d-%d-1.dat", if( p_sys->i_file_size < 1 ) p_sys->i_file_size = 1;
getpid(), p_access->i_object_id ); p_sys->i_file_size *= 1024 * 1024; /* In MBytes */
asprintf( &p_sys->psz_tmp2, "/tmp/vlc-timeshift-%d-%d-2.dat",
getpid(), p_access->i_object_id ); p_sys->psz_filename_base = GetTmpFilePath( p_access );
#endif p_sys->psz_filename = malloc( strlen( p_sys->psz_filename_base ) + 1000 );
if( vlc_thread_create( p_access, "timeshift thread", Thread, if( vlc_thread_create( p_access, "timeshift thread", Thread,
VLC_THREAD_PRIORITY_LOW, VLC_FALSE ) ) VLC_THREAD_PRIORITY_LOW, VLC_FALSE ) )
...@@ -159,22 +170,35 @@ static void Close( vlc_object_t *p_this ) ...@@ -159,22 +170,35 @@ static void Close( vlc_object_t *p_this )
{ {
access_t *p_access = (access_t*)p_this; access_t *p_access = (access_t*)p_this;
access_sys_t *p_sys = p_access->p_sys; access_sys_t *p_sys = p_access->p_sys;
ts_entry_t *p_entry;
int i;
/* */
msg_Dbg( p_access, "timeshift close called" ); msg_Dbg( p_access, "timeshift close called" );
vlc_thread_join( p_access ); vlc_thread_join( p_access );
if( p_sys->b_opened ) for( p_entry = p_sys->p_write_list; p_entry; )
{ {
if( p_sys->t1 ) fclose( p_sys->t1 ); ts_entry_t *p_next = p_entry->p_next;
if( p_sys->t2 ) fclose( p_sys->t2 ); fclose( p_entry->file );
unlink( p_sys->psz_tmp1 ); free( p_entry );
unlink( p_sys->psz_tmp2 ); p_entry = p_next;
}
for( p_entry = p_sys->p_read_list; p_entry; )
{
ts_entry_t *p_next = p_entry->p_next;
fclose( p_entry->file );
free( p_entry );
p_entry = p_next;
}
for( i = 0; i < p_sys->i_files; i++ )
{
sprintf( p_sys->psz_filename, "%s%i.dat",
p_sys->psz_filename_base, i );
unlink( p_sys->psz_filename );
} }
free( p_sys->psz_tmp1 ); free( p_sys->psz_filename );
free( p_sys->psz_tmp2 ); free( p_sys->psz_filename_base );
block_FifoRelease( p_sys->p_fifo ); block_FifoRelease( p_sys->p_fifo );
free( p_sys ); free( p_sys );
} }
...@@ -185,6 +209,7 @@ static void Close( vlc_object_t *p_this ) ...@@ -185,6 +209,7 @@ static void Close( vlc_object_t *p_this )
static block_t *Block( access_t *p_access ) static block_t *Block( access_t *p_access )
{ {
access_sys_t *p_sys = p_access->p_sys; access_sys_t *p_sys = p_access->p_sys;
block_t *p_block;
if( p_access->b_die ) if( p_access->b_die )
{ {
...@@ -192,65 +217,9 @@ static block_t *Block( access_t *p_access ) ...@@ -192,65 +217,9 @@ static block_t *Block( access_t *p_access )
return NULL; return NULL;
} }
return block_FifoGet( p_sys->p_fifo ); p_block = block_FifoGet( p_sys->p_fifo );
} //p_access->info.i_size -= p_block->i_buffer;
return p_block;
/*****************************************************************************
*
*****************************************************************************/
static int Control( access_t *p_access, int i_query, va_list args )
{
access_t *p_src = p_access->p_source;
vlc_bool_t *pb_bool;
int *pi_int;
int64_t *pi_64;
switch( i_query )
{
/* */
case ACCESS_CAN_SEEK:
case ACCESS_CAN_FASTSEEK:
pb_bool = (vlc_bool_t*)va_arg( args, vlc_bool_t* );
*pb_bool = VLC_FALSE;
break;
case ACCESS_CAN_CONTROL_PACE: /* Not really true */
case ACCESS_CAN_PAUSE:
pb_bool = (vlc_bool_t*)va_arg( args, vlc_bool_t* );
*pb_bool = VLC_TRUE;
break;
/* */
case ACCESS_GET_MTU:
pi_int = (int*)va_arg( args, int * );
*pi_int = 0;
break;
case ACCESS_GET_PTS_DELAY:
pi_64 = (int64_t*)va_arg( args, int64_t * );
return access2_Control( p_src, ACCESS_GET_PTS_DELAY, pi_64 );
/* */
case ACCESS_SET_PAUSE_STATE:
return VLC_SUCCESS;
case ACCESS_GET_TITLE_INFO:
case ACCESS_SET_TITLE:
case ACCESS_SET_SEEKPOINT:
case ACCESS_GET_META:
return VLC_EGENERIC;
case ACCESS_SET_PRIVATE_ID_STATE:
case ACCESS_GET_PRIVATE_ID_STATE:
case ACCESS_SET_PRIVATE_ID_CA:
return access2_vaControl( p_src, i_query, args );
default:
msg_Warn( p_access, "unimplemented query in control" );
return VLC_EGENERIC;
}
return VLC_SUCCESS;
} }
/***************************************************************************** /*****************************************************************************
...@@ -260,203 +229,341 @@ static void Thread( access_t *p_access ) ...@@ -260,203 +229,341 @@ static void Thread( access_t *p_access )
{ {
access_sys_t *p_sys = p_access->p_sys; access_sys_t *p_sys = p_access->p_sys;
access_t *p_src = p_access->p_source; access_t *p_src = p_access->p_source;
int i_loop = 0; int i;
while( !p_access->b_die ) while( !p_access->b_die )
{ {
block_t *p_block; block_t *p_block;
/* Get a new block */ /* Get a new block from the source */
if( p_src->pf_block ) if( p_src->pf_block )
{ {
p_block = p_src->pf_block( p_src ); p_block = p_src->pf_block( p_src );
if( p_block == NULL ) if( p_block == NULL )
{ {
if( p_src->info.b_eof ) if( p_src->info.b_eof ) break;
break;
msleep( 1000 ); msleep( 1000 );
continue; continue;
} }
} }
else else
{ {
if( ( p_block = block_New( p_access, 2048 ) ) == NULL ) if( ( p_block = block_New( p_access, 2048 ) ) == NULL ) break;
break;
p_block->i_buffer =
p_src->pf_read( p_src, p_block->p_buffer, 2048 );
p_block->i_buffer = p_src->pf_read( p_src, p_block->p_buffer, 2048);
if( p_block->i_buffer < 0 ) if( p_block->i_buffer < 0 )
{ {
block_Release( p_block ); block_Release( p_block );
if( p_block->i_buffer == 0 ) if( p_block->i_buffer == 0 ) break;
break;
msleep( 1000 ); msleep( 1000 );
continue; continue;
} }
} }
/* Open dump files if we need them */ /* Write block */
if( p_sys->p_fifo->i_size >= TIMESHIFT_FIFO_MAX && !p_sys->b_opened ) if( !p_sys->p_write_list && !p_sys->p_read_list &&
p_sys->p_fifo->i_size < TIMESHIFT_FIFO_MAX )
{ {
msg_Dbg( p_access, "opening first temporary files (%s)", /* If there isn't too much timeshifted data,
p_sys->psz_tmp1 ); * write directly to FIFO */
block_FifoPut( p_sys->p_fifo, p_block );
p_sys->b_opened = VLC_TRUE; //p_access->info.i_size += p_block->i_buffer;
p_sys->t1 = p_sys->t2 = NULL; //p_access->info.i_update |= INPUT_UPDATE_SIZE;
p_sys->w = p_sys->r = NULL;
p_sys->t1 = fopen( p_sys->psz_tmp1, "w+b" ); /* Nothing else to do */
if( p_sys->t1 ) continue;
{ }
msg_Dbg( p_access, "opening second temporary files (%s)",
p_sys->psz_tmp2 );
p_sys->t2 = fopen( p_sys->psz_tmp2, "w+b" ); WriteBlockToFile( p_access, p_block );
if( p_sys->t2 ) block_Release( p_block );
{
p_sys->w = p_sys->t1;
p_sys->i_w = 0;
msg_Dbg( p_access, "start writing into temporary file" ); /* Read from file to fill up the fifo */
} while( p_sys->p_fifo->i_size < TIMESHIFT_FIFO_MIN &&
else !p_access->b_die )
{ {
msg_Err( p_access, "cannot open temporary file '%s' (%s)", p_block = ReadBlockFromFile( p_access );
p_sys->psz_tmp2, strerror(errno) ); if( !p_block ) break;
fclose( p_sys->t1 ); block_FifoPut( p_sys->p_fifo, p_block );
p_sys->t1 = NULL;
} }
} }
else
msg_Dbg( p_access, "timeshift: EOF" );
/* Send dummy packet to avoid deadlock in TShiftBlock */
for( i = 0; i < 2; i++ )
{ {
msg_Err( p_access, "cannot open temporary file '%s' (%s)", block_t *p_dummy = block_New( p_access, 128 );
p_sys->psz_tmp1, strerror(errno) ); p_dummy->i_flags |= BLOCK_FLAG_DISCONTINUITY;
} memset( p_dummy->p_buffer, 0, p_dummy->i_buffer );
block_FifoPut( p_sys->p_fifo, p_dummy );
} }
}
if( p_sys->w ) /*****************************************************************************
* NextFileWrite:
*****************************************************************************/
static void NextFileWrite( access_t *p_access )
{
access_sys_t *p_sys = p_access->p_sys;
ts_entry_t *p_next;
if( !p_sys->p_write_list )
{ {
int i_write; p_sys->i_write_size = 0;
return;
}
/* Dump the block */ p_next = p_sys->p_write_list->p_next;
i_write = fwrite( p_block->p_buffer, 1, p_block->i_buffer,
p_sys->w );
block_Release( p_block );
if( i_write > 0 ) /* Put written file in read list */
p_sys->i_w += i_write; if( p_sys->i_write_size < p_sys->i_file_size )
else ftruncate( fileno( p_sys->p_write_list->file ), p_sys->i_write_size );
msg_Warn( p_access, "cannot write data" );
/* Start reading from a file if fifo isn't at 25% */ fseek( p_sys->p_write_list->file, 0, SEEK_SET );
if( p_sys->p_fifo->i_size < TIMESHIFT_FIFO_MIN && !p_sys->r ) *p_sys->pp_read_last = p_sys->p_write_list;
{ p_sys->pp_read_last = &p_sys->p_write_list->p_next;
msg_Dbg( p_access, "start reading from temporary file (dumped=%d)", p_sys->i_w ); p_sys->p_write_list->p_next = 0;
p_sys->r = p_sys->w; /* Switch to next file to write */
fseek( p_sys->r, 0, SEEK_SET ); p_sys->p_write_list = p_next;
if( !p_sys->p_write_list ) p_sys->pp_write_last = &p_sys->p_write_list;
p_sys->w = p_sys->t2; p_sys->i_write_size = 0;
p_sys->i_w = 0; }
}
if( p_sys->r ) /*****************************************************************************
{ * NextFileRead:
while( p_sys->p_fifo->i_size < TIMESHIFT_FIFO_MIN ) *****************************************************************************/
static void NextFileRead( access_t *p_access )
{
access_sys_t *p_sys = p_access->p_sys;
ts_entry_t *p_next;
if( !p_sys->p_read_list ) return;
p_next = p_sys->p_read_list->p_next;
/* Put read file in write list */
fseek( p_sys->p_read_list->file, 0, SEEK_SET );
*p_sys->pp_write_last = p_sys->p_read_list;
p_sys->pp_write_last = &p_sys->p_read_list->p_next;
p_sys->p_read_list->p_next = 0;
/* Switch to next file to read */
p_sys->p_read_list = p_next;
if( !p_sys->p_read_list ) p_sys->pp_read_last = &p_sys->p_read_list;
}
/*****************************************************************************
* WriteBlockToFile:
*****************************************************************************/
static int WriteBlockToFile( access_t *p_access, block_t *p_block )
{
access_sys_t *p_sys = p_access->p_sys;
int i_write, i_buffer;
if( p_sys->i_write_size == p_sys->i_file_size ) NextFileWrite( p_access );
/* Open new file if necessary */
if( !p_sys->p_write_list )
{ {
p_block = block_New( p_access, 4096 ); FILE *file;
p_block->i_buffer = fread( p_block->p_buffer, 1, 4096,
p_sys->r ); sprintf( p_sys->psz_filename, "%s%i.dat",
p_sys->psz_filename_base, p_sys->i_files );
file = fopen( p_sys->psz_filename, "w+b" );
if( p_block->i_buffer > 0 ) if( !file && p_sys->i_files < 2 )
{ {
block_FifoPut( p_sys->p_fifo, p_block ); /* We just can't work with less than 2 buffer files */
msg_Err( p_access, "cannot open temporary file '%s' (%s)",
p_sys->psz_filename, strerror(errno) );
return VLC_EGENERIC;
} }
else if( p_sys->i_w > 32*1024) else if( !file ) return VLC_EGENERIC;
{
FILE *tmp;
block_Release( p_block );
msg_Dbg( p_access, "switching temporary files (dumped=%d)", p_sys->i_w ); p_sys->p_write_list = malloc( sizeof(ts_entry_t) );
p_sys->p_write_list->p_next = 0;
p_sys->p_write_list->file = file;
p_sys->pp_write_last = &p_sys->p_write_list->p_next;
/* Switch read/write */ p_sys->i_files++;
tmp = p_sys->r; }
p_sys->r = p_sys->w; /* Write to file */
fseek( p_sys->r, 0, SEEK_SET ); i_buffer = __MIN( p_block->i_buffer,
p_sys->i_file_size - p_sys->i_write_size );
p_sys->w = tmp; i_write = fwrite( p_block->p_buffer, 1, i_buffer,
fseek( p_sys->w, 0, SEEK_SET ); p_sys->p_write_list->file );
ftruncate( fileno(p_sys->w), 0 );
p_sys->i_w = 0;
}
else
{
msg_Dbg( p_access, "removing temporary files" );
/* We will remove the need of tmp files */ if( i_write > 0 ) p_sys->i_write_size += i_write;
if( p_sys->i_w > 0 )
{ //p_access->info.i_size += i_write;
msg_Dbg( p_access, "loading temporary file" ); //p_access->info.i_update |= INPUT_UPDATE_SIZE;
fseek( p_sys->w, 0, SEEK_SET );
for( ;; ) if( i_write < i_buffer )
{ {
p_block = block_New( p_access, 4096 ); /* Looks like we're short of space */
p_block->i_buffer = fread( p_block->p_buffer,
1, 4096, if( !p_sys->p_write_list->p_next )
p_sys->w );
if( p_block->i_buffer <= 0 )
{ {
block_Release( p_block ); msg_Warn( p_access, "no more space, overwritting old data" );
break; NextFileRead( p_access );
} NextFileRead( p_access );
block_FifoPut( p_sys->p_fifo, p_block );
} }
/* Make sure we switch to next file in write list */
p_sys->i_write_size = p_sys->i_file_size;
} }
p_sys->b_opened = VLC_FALSE; p_block->p_buffer += i_write;
p_block->i_buffer -= i_write;
fclose( p_sys->t1 ); /* Check if we have some data left */
fclose( p_sys->t2 ); if( p_block->i_buffer ) return WriteBlockToFile( p_access, p_block );
p_sys->t1 = p_sys->t2 = NULL; return VLC_SUCCESS;
p_sys->w = p_sys->r = NULL; }
unlink( p_sys->psz_tmp1 ); /*****************************************************************************
unlink( p_sys->psz_tmp2 ); * ReadBlockFromFile:
break; *****************************************************************************/
} static block_t *ReadBlockFromFile( access_t *p_access )
} {
} access_sys_t *p_sys = p_access->p_sys;
} block_t *p_block;
else if( p_sys->p_fifo->i_size < TIMESHIFT_FIFO_MAX )
if( !p_sys->p_read_list && p_sys->p_write_list )
{ {
block_FifoPut( p_sys->p_fifo, p_block ); /* Force switching to next write file, that should
* give us something to read */
NextFileWrite( p_access );
} }
else
if( !p_sys->p_read_list ) return 0;
p_block = block_New( p_access, 4096 );
p_block->i_buffer = fread( p_block->p_buffer, 1, 4096,
p_sys->p_read_list->file );
if( p_block->i_buffer == 0 ) NextFileRead( p_access );
//p_access->info.i_size -= p_block->i_buffer;
//p_access->info.i_update |= INPUT_UPDATE_SIZE;
return p_block;
}
/*****************************************************************************
* Seek: seek to a specific location in a file
*****************************************************************************/
static int Seek( access_t *p_access, int64_t i_pos )
{
//access_sys_t *p_sys = p_access->p_sys;
return VLC_SUCCESS;
}
/*****************************************************************************
*
*****************************************************************************/
static int Control( access_t *p_access, int i_query, va_list args )
{
access_t *p_src = p_access->p_source;
vlc_bool_t *pb_bool;
int *pi_int;
int64_t *pi_64;
switch( i_query )
{ {
/* We failed to opened files so trash new data */ case ACCESS_CAN_SEEK:
block_Release( p_block ); case ACCESS_CAN_FASTSEEK:
pb_bool = (vlc_bool_t*)va_arg( args, vlc_bool_t* );
*pb_bool = VLC_TRUE;
break;
case ACCESS_CAN_CONTROL_PACE: /* Not really true */
case ACCESS_CAN_PAUSE:
pb_bool = (vlc_bool_t*)va_arg( args, vlc_bool_t* );
*pb_bool = VLC_TRUE;
break;
case ACCESS_GET_MTU:
pi_int = (int*)va_arg( args, int * );
*pi_int = 0;
break;
case ACCESS_GET_PTS_DELAY:
pi_64 = (int64_t*)va_arg( args, int64_t * );
return access2_Control( p_src, ACCESS_GET_PTS_DELAY, pi_64 );
case ACCESS_SET_PAUSE_STATE:
return VLC_SUCCESS;
case ACCESS_GET_TITLE_INFO:
case ACCESS_SET_TITLE:
case ACCESS_SET_SEEKPOINT:
case ACCESS_GET_META:
return VLC_EGENERIC;
case ACCESS_SET_PRIVATE_ID_STATE:
case ACCESS_GET_PRIVATE_ID_STATE:
case ACCESS_SET_PRIVATE_ID_CA:
return access2_vaControl( p_src, i_query, args );
default:
msg_Warn( p_access, "unimplemented query in control" );
return VLC_EGENERIC;
} }
#if 0 return VLC_SUCCESS;
if( (i_loop % 400) == 0 ) }
msg_Dbg( p_access, "timeshift: buff=%d", p_sys->p_fifo->i_size );
/*****************************************************************************
* GetTmpFilePath:
*****************************************************************************/
#ifdef WIN32
#define getpid() GetCurrentProcessId()
#endif #endif
i_loop++; 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 )
{
free( psz_dir );
psz_dir = 0;
} }
msg_Warn( p_access, "timeshift: EOF" ); if( !psz_dir )
{
#ifdef WIN32
int i_size;
/* Send dummy packet to avoid deadlock in TShiftBlock */ psz_dir = malloc( MAX_PATH + 1 );
for( i_loop = 0; i_loop < 2; i_loop++ ) i_size = GetTempPath( MAX_PATH, psz_dir );
if( i_size <= 0 || i_size > MAX_PATH )
{ {
block_t *p_dummy = block_New( p_access, 128 ); if( !getcwd( psz_dir, MAX_PATH ) ) strcpy( psz_dir, "c:" );
}
p_dummy->i_flags |= BLOCK_FLAG_DISCONTINUITY; /* remove last \\ if any */
memset( p_dummy->p_buffer, 0, p_dummy->i_buffer ); if( psz_dir[strlen(psz_dir)-1] == '\\' )
psz_dir[strlen(psz_dir)-1] = '\0';
#else
block_FifoPut( p_sys->p_fifo, p_dummy ); psz_dir = strdup( "/tmp" );
#endif
} }
}
asprintf( &psz_filename_base, "%s/vlc-timeshift-%d-%d-",
psz_dir, getpid(), p_access->i_object_id );
return psz_filename_base;
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment