* Local prototypes
*****************************************************************************/
+/* XXX attribute_packed is (and MUST be) used ONLY to reduce memory usage */
+#ifdef HAVE_ATTRIBUTE_PACKED
+# define attribute_packed __attribute__((__packed__))
+#else
+# define attribute_packed
+#endif
+
enum
{
C_ADD,
C_CONTROL,
};
-typedef struct
+typedef struct attribute_packed
{
es_out_id_t *p_es;
es_format_t *p_fmt;
} ts_cmd_add_t;
-typedef struct
+typedef struct attribute_packed
{
es_out_id_t *p_es;
} ts_cmd_del_t;
-typedef struct
+typedef struct attribute_packed
{
es_out_id_t *p_es;
block_t *p_block;
- off_t i_offset;
+ int i_offset; /* We do not use file > INT_MAX */
} ts_cmd_send_t;
-typedef struct
+typedef struct attribute_packed
{
int i_query;
es_out_id_t *p_es;
es_format_t *p_fmt;
} es_fmt;
+ struct
+ {
+ /* FIXME Really too big (double make the whole thing too big) */
+ double f_position;
+ mtime_t i_time;
+ mtime_t i_length;
+ } times;
+ struct
+ {
+ mtime_t i_pts_delay;
+ int i_cr_average;
+ } jitter;
};
} ts_cmd_control_t;
-typedef struct
+typedef struct attribute_packed
{
- int i_type;
+ int8_t i_type;
mtime_t i_date;
union
{
/* */
char *psz_file; /* Filename */
- int64_t i_file_max; /* Max size in bytes */
+ size_t i_file_max; /* Max size in bytes */
int64_t i_file_size;/* Current size in bytes */
FILE *p_filew; /* FILE handle for data writing */
FILE *p_filer; /* FILE handle for data reading */
static void TsStop( ts_thread_t * );
static void TsPushCmd( ts_thread_t *, ts_cmd_t * );
-static int TsPopCmdLocked( ts_thread_t *, ts_cmd_t * );
+static int TsPopCmdLocked( ts_thread_t *, ts_cmd_t *, bool b_flush );
static bool TsHasCmd( ts_thread_t * );
static bool TsIsUnused( ts_thread_t * );
static int TsChangePause( ts_thread_t *, bool b_source_paused, bool b_paused, mtime_t i_date );
static bool TsStorageIsFull( ts_storage_t *, const ts_cmd_t *p_cmd );
static bool TsStorageIsEmpty( ts_storage_t * );
static void TsStoragePushCmd( ts_storage_t *, const ts_cmd_t *p_cmd, bool b_flush );
-static void TsStoragePopCmd( ts_storage_t *p_storage, ts_cmd_t *p_cmd );
+static void TsStoragePopCmd( ts_storage_t *p_storage, ts_cmd_t *p_cmd, bool b_flush );
static void CmdClean( ts_cmd_t * );
static void cmd_cleanup_routine( void *p ) { CmdClean( p ); }
TAB_INIT( p_sys->i_es, p_sys->pp_es );
- /* TODO config
- * timeshift-granularity
- * timeshift-path
- */
- p_sys->i_tmp_size_max = 50 * 1024*1024;
- p_sys->psz_tmp_path = GetTmpPath( NULL );
+ /* */
+ const int i_tmp_size_max = var_CreateGetInteger( p_input, "input-timeshift-granularity" );
+ if( i_tmp_size_max < 0 )
+ p_sys->i_tmp_size_max = 50*1024*1024;
+ else
+ p_sys->i_tmp_size_max = __MAX( i_tmp_size_max, 1*1024*1024 );
+ msg_Dbg( p_input, "using timeshift granularity of %d bytes",
+ (int)p_sys->i_tmp_size_max );
+
+ char *psz_tmp_path = var_CreateGetNonEmptyString( p_input, "input-timeshift-path" );
+ p_sys->psz_tmp_path = GetTmpPath( psz_tmp_path );
+ msg_Dbg( p_input, "using timeshift path '%s'", p_sys->psz_tmp_path );
+
+#if 0
+#define S(t) msg_Err( p_input, "SIZEOF("#t")=%d", sizeof(t) )
+ S(ts_cmd_t);
+ S(ts_cmd_control_t);
+ S(ts_cmd_send_t);
+ S(ts_cmd_del_t);
+ S(ts_cmd_add_t);
+#undef S
+#endif
return p_out;
}
if( p_sys->b_delayed )
{
- assert( !p_sys->p_input->b_can_pace_control );
+ assert( !p_sys->p_input->p->b_can_pace_control );
*pi_wakeup = 0;
}
else
else
{
i_ret = VLC_EGENERIC;
- if( !p_sys->p_input->b_can_pace_control )
+ if( !p_sys->p_input->p->b_can_pace_control )
{
if( !p_sys->b_delayed )
TsStart( p_out );
else
{
i_ret = VLC_EGENERIC;
- if( !p_sys->p_input->b_can_pace_control )
+ if( !p_sys->p_input->p->b_can_pace_control )
{
if( !p_sys->b_delayed )
TsStart( p_out );
assert(0);
return VLC_EGENERIC;
- /* TODO ? or to remove ? */
- case ES_OUT_GET_TS:
- return VLC_EGENERIC;
-
/* Pass-through control */
case ES_OUT_SET_ACTIVE:
case ES_OUT_SET_MODE:
case ES_OUT_SET_NEXT_DISPLAY_TIME:
case ES_OUT_SET_GROUP_META:
case ES_OUT_SET_GROUP_EPG:
+ case ES_OUT_SET_ES_SCRAMBLED_STATE:
case ES_OUT_DEL_GROUP:
case ES_OUT_SET_ES:
case ES_OUT_RESTART_ES:
case ES_OUT_SET_ES_DEFAULT:
case ES_OUT_SET_ES_STATE:
case ES_OUT_SET_ES_FMT:
+ case ES_OUT_SET_TIMES:
+ case ES_OUT_SET_JITTER:
{
ts_cmd_t cmd;
if( CmdInitControl( &cmd, i_query, args, p_sys->b_delayed ) )
*pb_enabled = true;
return VLC_SUCCESS;
}
- return es_out_Control( p_sys->p_out, ES_OUT_GET_ES_STATE, p_es, pb_enabled );
+ return es_out_Control( p_sys->p_out, ES_OUT_GET_ES_STATE, p_es->p_es, pb_enabled );
}
/* Special internal input control */
p_sys->b_delayed = true;
if( vlc_thread_create( p_ts, "es out timeshift",
- TsRun, VLC_THREAD_PRIORITY_INPUT, false ) )
+ TsRun, VLC_THREAD_PRIORITY_INPUT ) )
{
msg_Err( p_sys->p_input, "cannot create input thread" );
{
ts_cmd_t cmd;
- if( TsPopCmdLocked( p_ts, &cmd ) )
+ if( TsPopCmdLocked( p_ts, &cmd, true ) )
break;
CmdClean( &cmd );
vlc_mutex_unlock( &p_ts->lock );
}
-static int TsPopCmdLocked( ts_thread_t *p_ts, ts_cmd_t *p_cmd )
+static int TsPopCmdLocked( ts_thread_t *p_ts, ts_cmd_t *p_cmd, bool b_flush )
{
vlc_assert_locked( &p_ts->lock );
if( TsStorageIsEmpty( p_ts->p_storage_r ) )
return VLC_EGENERIC;
- TsStoragePopCmd( p_ts->p_storage_r, p_cmd );
+ TsStoragePopCmd( p_ts->p_storage_r, p_cmd, b_flush );
while( p_ts->p_storage_r && TsStorageIsEmpty( p_ts->p_storage_r ) )
{
const int canc = vlc_savecancel();
b_buffering = es_out_GetBuffering( p_ts->p_out );
- if( ( !p_ts->b_paused || b_buffering ) && !TsPopCmdLocked( p_ts, &cmd ) )
+ if( ( !p_ts->b_paused || b_buffering ) && !TsPopCmdLocked( p_ts, &cmd, false ) )
{
vlc_restorecancel( canc );
break;
{
ts_cmd_t cmd;
- TsStoragePopCmd( p_storage, &cmd );
+ TsStoragePopCmd( p_storage, &cmd, true );
CmdClean( &cmd );
}
}
p_storage->p_cmd[p_storage->i_cmd_w++] = cmd;
}
-static void TsStoragePopCmd( ts_storage_t *p_storage, ts_cmd_t *p_cmd )
+static void TsStoragePopCmd( ts_storage_t *p_storage, ts_cmd_t *p_cmd, bool b_flush )
{
assert( !TsStorageIsEmpty( p_storage ) );
{
block_t block;
- if( !fseek( p_storage->p_filer, p_cmd->send.i_offset, SEEK_SET ) &&
+ if( !b_flush &&
+ !fseek( p_storage->p_filer, p_cmd->send.i_offset, SEEK_SET ) &&
fread( &block, sizeof(block), 1, p_storage->p_filer ) == 1 )
{
block_t *p_block = block_Alloc( block.i_buffer );
p_cmd->control.int_i64.i_i64 = (int64_t)va_arg( args, int64_t );
break;
+ case ES_OUT_SET_ES_SCRAMBLED_STATE:
+ p_cmd->control.es_bool.p_es = (es_out_id_t*)va_arg( args, es_out_id_t * );
+ p_cmd->control.es_bool.b_bool = (bool)va_arg( args, int );
+ break;
+
case ES_OUT_RESET_PCR: /* no arg */
break;
}
break;
}
+ case ES_OUT_SET_TIMES:
+ {
+ double f_position = (double)va_arg( args, double );
+ mtime_t i_time = (mtime_t)va_arg( args, mtime_t );
+ mtime_t i_length = (mtime_t)va_arg( args, mtime_t );
+
+ p_cmd->control.times.f_position = f_position;
+ p_cmd->control.times.i_time = i_time;
+ p_cmd->control.times.i_length = i_length;
+ break;
+ }
+ case ES_OUT_SET_JITTER:
+ {
+ mtime_t i_pts_delay = (mtime_t)va_arg( args, mtime_t );
+ int i_cr_average = (int)va_arg( args, int );
+
+ p_cmd->control.jitter.i_pts_delay = i_pts_delay;
+ p_cmd->control.jitter.i_cr_average = i_cr_average;
+ break;
+ }
default:
assert(0);
return es_out_Control( p_out, i_query, p_cmd->control.i_i64 );
case ES_OUT_SET_GROUP_PCR: /* arg1= int i_group, arg2=int64_t i_pcr(microsecond!)*/
- return es_out_Control( p_out, i_query, p_cmd->control.int_i64.i_int, p_cmd->control.int_i64.i_i64 );
+ return es_out_Control( p_out, i_query, p_cmd->control.int_i64.i_int,
+ p_cmd->control.int_i64.i_i64 );
case ES_OUT_RESET_PCR: /* no arg */
return es_out_Control( p_out, i_query );
case ES_OUT_SET_GROUP_META: /* arg1=int i_group arg2=vlc_meta_t* */
- return es_out_Control( p_out, i_query, p_cmd->control.int_meta.i_int, p_cmd->control.int_meta.p_meta );
+ return es_out_Control( p_out, i_query, p_cmd->control.int_meta.i_int,
+ p_cmd->control.int_meta.p_meta );
case ES_OUT_SET_GROUP_EPG: /* arg1=int i_group arg2=vlc_epg_t* */
- return es_out_Control( p_out, i_query, p_cmd->control.int_epg.i_int, p_cmd->control.int_epg.p_epg );
+ return es_out_Control( p_out, i_query, p_cmd->control.int_epg.i_int,
+ p_cmd->control.int_epg.p_epg );
+
+ case ES_OUT_SET_ES_SCRAMBLED_STATE: /* arg1=int es_out_id_t* arg2=bool */
+ return es_out_Control( p_out, i_query, p_cmd->control.es_bool.p_es->p_es,
+ p_cmd->control.es_bool.b_bool );
/* Modified control */
case ES_OUT_SET_ES: /* arg1= es_out_id_t* */
return es_out_Control( p_out, i_query, p_cmd->control.p_es->p_es );
case ES_OUT_SET_ES_STATE:/* arg1= es_out_id_t* arg2=bool */
- return es_out_Control( p_out, i_query, p_cmd->control.es_bool.p_es->p_es, p_cmd->control.es_bool.b_bool );
+ return es_out_Control( p_out, i_query, p_cmd->control.es_bool.p_es->p_es,
+ p_cmd->control.es_bool.b_bool );
case ES_OUT_SET_ES_FMT: /* arg1= es_out_id_t* arg2=es_format_t* */
- return es_out_Control( p_out, i_query, p_cmd->control.es_fmt.p_es->p_es, p_cmd->control.es_fmt.p_fmt );
+ return es_out_Control( p_out, i_query, p_cmd->control.es_fmt.p_es->p_es,
+ p_cmd->control.es_fmt.p_fmt );
+
+ case ES_OUT_SET_TIMES:
+ return es_out_Control( p_out, i_query, p_cmd->control.times.f_position,
+ p_cmd->control.times.i_time,
+ p_cmd->control.times.i_length );
+ case ES_OUT_SET_JITTER:
+ return es_out_Control( p_out, i_query, p_cmd->control.jitter.i_pts_delay,
+ p_cmd->control.jitter.i_cr_average );
default:
assert(0);
return NULL;
/* */
- fd = mkstemp( psz_name );
+ fd = utf8_mkstemp( psz_name );
*ppsz_file = psz_name;
if( fd < 0 )
return NULL;
/* */
- f = fdopen( fd, "rw+" );
+ f = fdopen( fd, "w+b" );
if( !f )
close( fd );