1 /*****************************************************************************
2 * es_out_timeshift.c: Es Out timeshift.
3 *****************************************************************************
4 * Copyright (C) 2008 Laurent Aimar
7 * Authors: Laurent Aimar < fenrir _AT_ via _DOT_ ecp _DOT_ fr>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22 *****************************************************************************/
24 /*****************************************************************************
26 *****************************************************************************/
35 #if defined (WIN32) && !defined (UNDER_CE)
38 #ifdef HAVE_SYS_STAT_H
39 # include <sys/stat.h>
42 #include <vlc_common.h>
43 #include <vlc_charset.h>
45 #include <vlc_input.h>
46 #include <vlc_es_out.h>
47 #include <vlc_block.h>
48 #include "input_internal.h"
50 #include "es_out_timeshift.h"
52 /*****************************************************************************
54 *****************************************************************************/
108 input_thread_t *p_input;
112 int64_t i_tmp_size_max; /* Maximal temporary file size in byte */
113 char *psz_tmp_path; /* Path for temporary files */
115 /* Lock for all following fields */
121 vlc_object_t *p_thread;
124 mtime_t i_pause_date;
136 static es_out_id_t *Add ( es_out_t *, const es_format_t * );
137 static int Send ( es_out_t *, es_out_id_t *, block_t * );
138 static void Del ( es_out_t *, es_out_id_t * );
139 static int Control( es_out_t *, int i_query, va_list );
140 static void Destroy( es_out_t * );
142 static int TsStart( es_out_t * );
143 static void TsStop( es_out_t * );
144 static void *TsRun( vlc_object_t * );
146 static void CmdPush( es_out_t *, const ts_cmd_t * );
147 static int CmdPop( es_out_t *, ts_cmd_t * );
148 static void CmdClean( ts_cmd_t * );
149 static void cmd_cleanup_routine( void *p ) { CmdClean( p ); }
151 static int CmdInitAdd ( ts_cmd_t *, es_out_id_t *, const es_format_t *, bool b_copy );
152 static void CmdInitSend ( ts_cmd_t *, es_out_id_t *, block_t * );
153 static int CmdInitDel ( ts_cmd_t *, es_out_id_t * );
154 static int CmdInitControl( ts_cmd_t *, int i_query, va_list, bool b_copy );
156 static void CmdExecuteAdd ( es_out_t *, ts_cmd_t * );
157 static int CmdExecuteSend ( es_out_t *, ts_cmd_t * );
158 static void CmdExecuteDel ( es_out_t *, ts_cmd_t * );
159 static int CmdExecuteControl( es_out_t *, ts_cmd_t * );
161 static void CmdCleanAdd ( ts_cmd_t * );
162 static void CmdCleanSend ( ts_cmd_t * );
163 static void CmdCleanControl( ts_cmd_t *p_cmd );
165 static char *GetTmpPath( char *psz_path );
166 static FILE *GetTmpFile( const char *psz_path );
168 /*****************************************************************************
169 * input_EsOutTimeshiftNew:
170 *****************************************************************************/
171 es_out_t *input_EsOutTimeshiftNew( input_thread_t *p_input, es_out_t *p_next_out )
173 es_out_t *p_out = malloc( sizeof(*p_out) );
177 es_out_sys_t *p_sys = malloc( sizeof(*p_sys) );
186 p_out->pf_send = Send;
188 p_out->pf_control = Control;
189 p_out->pf_destroy = Destroy;
190 p_out->p_sys = p_sys;
191 p_out->b_sout = p_input->p->p_sout != NULL;
194 p_sys->p_input = p_input;
195 p_sys->p_out = p_next_out;
196 vlc_mutex_init_recursive( &p_sys->lock );
197 vlc_cond_init( &p_sys->wait );
199 p_sys->b_delayed = false;
200 p_sys->p_thread = NULL;
201 p_sys->b_paused = false;
202 p_sys->i_pause_date = -1;
203 p_sys->i_cmd_delay = 0;
205 TAB_INIT( p_sys->i_es, p_sys->pp_es );
206 TAB_INIT( p_sys->i_cmd, p_sys->pp_cmd );
209 * timeshift-granularity
212 p_sys->i_tmp_size_max = 50 * 1024*1024;
213 p_sys->psz_tmp_path = GetTmpPath( NULL );
218 /*****************************************************************************
220 *****************************************************************************/
221 static void Destroy( es_out_t *p_out )
223 es_out_sys_t *p_sys = p_out->p_sys;
225 if( p_sys->b_delayed )
232 if( CmdPop( p_out, &cmd ) )
237 TAB_CLEAN( p_sys->i_cmd, p_sys->pp_cmd );
239 while( p_sys->i_es > 0 )
240 Del( p_out, p_sys->pp_es[0] );
241 TAB_CLEAN( p_sys->i_es, p_sys->pp_es );
243 free( p_sys->psz_tmp_path );
244 vlc_cond_destroy( &p_sys->wait );
245 vlc_mutex_destroy( &p_sys->lock );
250 static es_out_id_t *Add( es_out_t *p_out, const es_format_t *p_fmt )
252 es_out_sys_t *p_sys = p_out->p_sys;
255 es_out_id_t *p_es = malloc( sizeof( *p_es ) );
259 vlc_mutex_lock( &p_sys->lock );
261 if( CmdInitAdd( &cmd, p_es, p_fmt, p_sys->b_delayed ) )
263 vlc_mutex_unlock( &p_sys->lock );
268 TAB_APPEND( p_sys->i_es, p_sys->pp_es, p_es );
270 if( p_sys->b_delayed )
271 CmdPush( p_out, &cmd );
273 CmdExecuteAdd( p_out, &cmd );
275 vlc_mutex_unlock( &p_sys->lock );
279 static int Send( es_out_t *p_out, es_out_id_t *p_es, block_t *p_block )
281 es_out_sys_t *p_sys = p_out->p_sys;
283 int i_ret = VLC_SUCCESS;
285 vlc_mutex_lock( &p_sys->lock );
287 CmdInitSend( &cmd, p_es, p_block );
288 if( p_sys->b_delayed )
289 CmdPush( p_out, &cmd );
291 i_ret = CmdExecuteSend( p_out, &cmd) ;
293 vlc_mutex_unlock( &p_sys->lock );
297 static void Del( es_out_t *p_out, es_out_id_t *p_es )
299 es_out_sys_t *p_sys = p_out->p_sys;
302 vlc_mutex_lock( &p_sys->lock );
304 CmdInitDel( &cmd, p_es );
305 if( p_sys->b_delayed )
306 CmdPush( p_out, &cmd );
308 CmdExecuteDel( p_out, &cmd );
310 TAB_REMOVE( p_sys->i_es, p_sys->pp_es, p_es );
312 vlc_mutex_unlock( &p_sys->lock );
315 static int ControlLockedGetEmpty( es_out_t *p_out, bool *pb_empty )
317 es_out_sys_t *p_sys = p_out->p_sys;
319 if( p_sys->b_delayed && p_sys->i_cmd > 0 )
322 *pb_empty = es_out_GetEmpty( p_sys->p_out );
326 static int ControlLockedGetWakeup( es_out_t *p_out, mtime_t *pi_wakeup )
328 es_out_sys_t *p_sys = p_out->p_sys;
330 if( p_sys->b_delayed )
332 assert( !p_sys->p_input->b_can_pace_control );
337 *pi_wakeup = es_out_GetWakeup( p_sys->p_out );
342 static int ControlLockedGetBuffering( es_out_t *p_out, bool *pb_buffering )
344 es_out_sys_t *p_sys = p_out->p_sys;
346 if( p_sys->b_delayed )
347 *pb_buffering = true;
349 *pb_buffering = es_out_GetBuffering( p_sys->p_out );
353 static int ControlLockedSetPauseState( es_out_t *p_out, bool b_source_paused, bool b_paused, mtime_t i_date )
355 es_out_sys_t *p_sys = p_out->p_sys;
357 if( !p_sys->b_delayed &&
358 !b_source_paused == !b_paused )
360 return es_out_SetPauseState( p_sys->p_out, b_source_paused, b_paused, i_date );
363 if( p_sys->p_input->b_can_pace_control )
365 /* XXX we may do it BUT it would be better to finish the clock clean up+improvments
366 * and so be able to advertize correctly pace control property in access
368 msg_Err( p_sys->p_input, "EsOutTimeshift does not work with streams that have space control" );
375 assert( !b_source_paused );
377 if( !p_sys->b_delayed )
380 i_ret = es_out_SetPauseState( p_sys->p_out, true, true, i_date );
384 i_ret = es_out_SetPauseState( p_sys->p_out, false, false, i_date );
391 assert( p_sys->i_pause_date > 0 );
393 p_sys->i_cmd_delay += i_date - p_sys->i_pause_date;
396 p_sys->b_paused = b_paused;
397 p_sys->i_pause_date = i_date;
399 vlc_cond_signal( &p_sys->wait );
403 static int ControlLockedSetRate( es_out_t *p_out, int i_src_rate, int i_rate )
405 es_out_sys_t *p_sys = p_out->p_sys;
407 if( !p_sys->b_delayed &&
408 i_src_rate == i_rate )
410 return es_out_SetRate( p_sys->p_out, i_src_rate, i_rate );
413 msg_Err( p_sys->p_input, "EsOutTimeshift does not yet support rate change" );
416 static int ControlLockedSetTime( es_out_t *p_out, mtime_t i_date )
418 es_out_sys_t *p_sys = p_out->p_sys;
420 if( !p_sys->b_delayed )
421 return es_out_SetTime( p_sys->p_out, i_date );
424 msg_Err( p_sys->p_input, "EsOutTimeshift does not yet support time change" );
427 static int ControlLockedSetFrameNext( es_out_t *p_out )
429 es_out_sys_t *p_sys = p_out->p_sys;
431 if( !p_sys->b_delayed )
432 return es_out_SetFrameNext( p_sys->p_out );
435 msg_Err( p_sys->p_input, "EsOutTimeshift does not yet support frame next" );
439 static int ControlLocked( es_out_t *p_out, int i_query, va_list args )
441 es_out_sys_t *p_sys = p_out->p_sys;
445 /* Invalid query for this es_out level */
446 case ES_OUT_SET_ES_BY_ID:
447 case ES_OUT_RESTART_ES_BY_ID:
448 case ES_OUT_SET_ES_DEFAULT_BY_ID:
449 case ES_OUT_SET_DELAY:
450 case ES_OUT_SET_RECORD_STATE:
454 /* TODO ? or to remove ? */
458 /* Pass-through control */
459 case ES_OUT_SET_ACTIVE:
460 case ES_OUT_GET_ACTIVE:
461 case ES_OUT_SET_MODE:
462 case ES_OUT_GET_MODE:
463 case ES_OUT_SET_GROUP:
464 case ES_OUT_GET_GROUP:
466 case ES_OUT_SET_GROUP_PCR:
467 case ES_OUT_RESET_PCR:
468 case ES_OUT_SET_NEXT_DISPLAY_TIME:
469 case ES_OUT_SET_GROUP_META:
470 case ES_OUT_SET_GROUP_EPG:
471 case ES_OUT_DEL_GROUP:
473 case ES_OUT_RESTART_ES:
474 case ES_OUT_SET_ES_DEFAULT:
475 case ES_OUT_SET_ES_STATE:
476 case ES_OUT_GET_ES_STATE:
477 case ES_OUT_SET_ES_FMT:
480 if( CmdInitControl( &cmd, i_query, args, p_sys->b_delayed ) )
482 if( p_sys->b_delayed )
484 CmdPush( p_out, &cmd );
487 return CmdExecuteControl( p_out, &cmd );
490 /* Special control */
491 case ES_OUT_GET_EMPTY:
493 bool *pb_empty = (bool*)va_arg( args, bool* );
494 return ControlLockedGetEmpty( p_out, pb_empty );
496 case ES_OUT_GET_WAKE_UP: /* TODO ? */
498 mtime_t *pi_wakeup = (mtime_t*)va_arg( args, mtime_t* );
499 return ControlLockedGetWakeup( p_out, pi_wakeup );
501 case ES_OUT_GET_BUFFERING:
503 bool *pb_buffering = (bool *)va_arg( args, bool* );
504 return ControlLockedGetBuffering( p_out, pb_buffering );
506 case ES_OUT_SET_PAUSE_STATE:
508 const bool b_source_paused = (bool)va_arg( args, int );
509 const bool b_paused = (bool)va_arg( args, int );
510 const mtime_t i_date = (mtime_t) va_arg( args, mtime_t );
512 return ControlLockedSetPauseState( p_out, b_source_paused, b_paused, i_date );
514 case ES_OUT_SET_RATE:
516 const int i_src_rate = (int)va_arg( args, int );
517 const int i_rate = (int)va_arg( args, int );
519 return ControlLockedSetRate( p_out, i_src_rate, i_rate );
521 case ES_OUT_SET_TIME:
523 const mtime_t i_date = (mtime_t)va_arg( args, mtime_t );
525 return ControlLockedSetTime( p_out, i_date );
527 case ES_OUT_SET_FRAME_NEXT:
529 return ControlLockedSetFrameNext( p_out );
533 msg_Err( p_sys->p_input, "Unknown es_out_Control query !" );
538 static int Control( es_out_t *p_out, int i_query, va_list args )
540 es_out_sys_t *p_sys = p_out->p_sys;
543 vlc_mutex_lock( &p_sys->lock );
544 i_ret = ControlLocked( p_out, i_query, args );
545 vlc_mutex_unlock( &p_sys->lock );
550 /*****************************************************************************
552 *****************************************************************************/
553 static int TsStart( es_out_t *p_out )
555 es_out_sys_t *p_sys = p_out->p_sys;
557 assert( !p_sys->b_delayed );
559 p_sys->p_thread = vlc_custom_create( p_sys->p_input, sizeof(vlc_object_t),
560 VLC_OBJECT_GENERIC, "es out timeshift" );
561 if( !p_sys->p_thread )
564 p_sys->b_delayed = true;
565 p_sys->p_thread->p_private = p_out;
566 if( vlc_thread_create( p_sys->p_thread, "es out timeshift",
567 TsRun, VLC_THREAD_PRIORITY_INPUT, false ) )
569 msg_Err( p_sys->p_input, "cannot create input thread" );
570 vlc_object_release( p_sys->p_thread );
572 p_sys->b_delayed = false;
578 static void TsStop( es_out_t *p_out )
580 es_out_sys_t *p_sys = p_out->p_sys;
582 assert( p_sys->b_delayed );
584 vlc_object_kill( p_sys->p_thread );
585 vlc_thread_join( p_sys->p_thread );
587 p_sys->b_delayed = false;
589 static void *TsRun( vlc_object_t *p_thread )
591 es_out_t *p_out = p_thread->p_private;
592 es_out_sys_t *p_sys = p_out->p_sys;
598 /* Pop a command to execute */
599 vlc_mutex_lock( &p_sys->lock );
600 mutex_cleanup_push( &p_sys->lock );
602 while( p_sys->b_paused || CmdPop( p_out, &cmd ) )
603 vlc_cond_wait( &p_sys->wait, &p_sys->lock );
606 vlc_mutex_unlock( &p_sys->lock );
608 /* Regulate the speed of command processing to the same one than
610 //fprintf( stderr, "d=%d - %d\n", (int)(p_sys->i_cmd_delay/1000), (int)( (mdate() - cmd.i_date - p_sys->i_cmd_delay)/1000) );
611 vlc_cleanup_push( cmd_cleanup_routine, &cmd );
613 mwait( cmd.i_date + p_sys->i_cmd_delay );
617 /* Execute the command */
618 const int canc = vlc_savecancel();
620 vlc_mutex_lock( &p_sys->lock );
624 CmdExecuteAdd( p_out, &cmd );
628 CmdExecuteSend( p_out, &cmd );
629 CmdCleanSend( &cmd );
632 CmdExecuteControl( p_out, &cmd );
633 CmdCleanControl( &cmd );
636 CmdExecuteDel( p_out, &cmd );
642 vlc_mutex_unlock( &p_sys->lock );
644 vlc_restorecancel( canc );
650 /*****************************************************************************
652 *****************************************************************************/
653 static void CmdPush( es_out_t *p_out, const ts_cmd_t *p_cmd )
655 es_out_sys_t *p_sys = p_out->p_sys;
656 ts_cmd_t *p_dup = malloc( sizeof(*p_dup) );
661 TAB_APPEND( p_sys->i_cmd, p_sys->pp_cmd, p_dup );
663 vlc_cond_signal( &p_sys->wait );
666 static int CmdPop( es_out_t *p_out, ts_cmd_t *p_cmd )
668 es_out_sys_t *p_sys = p_out->p_sys;
670 if( p_sys->i_cmd <= 0 )
673 *p_cmd = *p_sys->pp_cmd[0];
675 free( p_sys->pp_cmd[0] );
676 TAB_REMOVE( p_sys->i_cmd, p_sys->pp_cmd, p_sys->pp_cmd[0] );
680 static void CmdClean( ts_cmd_t *p_cmd )
682 switch( p_cmd->i_type )
685 CmdCleanAdd( p_cmd );
688 CmdCleanSend( p_cmd );
691 CmdCleanControl( p_cmd );
701 static int CmdInitAdd( ts_cmd_t *p_cmd, es_out_id_t *p_es, const es_format_t *p_fmt, bool b_copy )
703 p_cmd->i_type = C_ADD;
704 p_cmd->i_date = mdate();
705 p_cmd->add.p_es = p_es;
708 p_cmd->add.p_fmt = malloc( sizeof(*p_fmt) );
709 if( !p_cmd->add.p_fmt )
711 es_format_Copy( p_cmd->add.p_fmt, p_fmt );
715 p_cmd->add.p_fmt = (es_format_t*)p_fmt;
719 static void CmdExecuteAdd( es_out_t *p_out, ts_cmd_t *p_cmd )
721 es_out_sys_t *p_sys = p_out->p_sys;
723 p_cmd->add.p_es->p_es = es_out_Add( p_sys->p_out, p_cmd->add.p_fmt );
725 static void CmdCleanAdd( ts_cmd_t *p_cmd )
727 es_format_Clean( p_cmd->add.p_fmt );
728 free( p_cmd->add.p_fmt );
731 static void CmdInitSend( ts_cmd_t *p_cmd, es_out_id_t *p_es, block_t *p_block )
733 p_cmd->i_type = C_SEND;
734 p_cmd->i_date = mdate();
735 p_cmd->send.p_es = p_es;
736 p_cmd->send.p_block = p_block;
738 static int CmdExecuteSend( es_out_t *p_out, ts_cmd_t *p_cmd )
740 es_out_sys_t *p_sys = p_out->p_sys;
741 block_t *p_block = p_cmd->send.p_block;
743 p_cmd->send.p_block = NULL;
747 if( p_cmd->send.p_es->p_es )
748 return es_out_Send( p_sys->p_out, p_cmd->send.p_es->p_es, p_block );
749 block_Release( p_block );
753 static void CmdCleanSend( ts_cmd_t *p_cmd )
755 if( p_cmd->send.p_block )
756 block_Release( p_cmd->send.p_block );
759 static int CmdInitDel( ts_cmd_t *p_cmd, es_out_id_t *p_es )
761 p_cmd->i_type = C_DEL;
762 p_cmd->i_date = mdate();
763 p_cmd->del.p_es = p_es;
766 static void CmdExecuteDel( es_out_t *p_out, ts_cmd_t *p_cmd )
768 es_out_sys_t *p_sys = p_out->p_sys;
770 if( p_cmd->del.p_es->p_es )
771 es_out_Del( p_sys->p_out, p_cmd->del.p_es->p_es );
772 free( p_cmd->del.p_es );
775 static int CmdInitControl( ts_cmd_t *p_cmd, int i_query, va_list args, bool b_copy )
777 p_cmd->i_type = C_CONTROL;
778 p_cmd->i_date = mdate();
779 p_cmd->control.i_query = i_query;
780 p_cmd->control.p_meta = NULL;
781 p_cmd->control.p_epg = NULL;
782 p_cmd->control.p_fmt = NULL;
786 /* Pass-through control */
787 case ES_OUT_SET_ACTIVE: /* arg1= bool */
788 p_cmd->control.b_bool = (bool)va_arg( args, int );
791 case ES_OUT_GET_ACTIVE: /* arg1= bool* */
792 p_cmd->control.pb_bool = (bool*)va_arg( args, bool * );
795 case ES_OUT_SET_MODE: /* arg1= int */
796 case ES_OUT_SET_GROUP: /* arg1= int */
797 case ES_OUT_DEL_GROUP: /* arg1=int i_group */
798 p_cmd->control.i_int = (int)va_arg( args, int );
801 case ES_OUT_GET_MODE: /* arg2= int* */
802 case ES_OUT_GET_GROUP: /* arg1= int* */
803 p_cmd->control.pi_int = (int*)va_arg( args, int * );
806 case ES_OUT_SET_PCR: /* arg1=int64_t i_pcr(microsecond!) (using default group 0)*/
807 case ES_OUT_SET_NEXT_DISPLAY_TIME: /* arg1=int64_t i_pts(microsecond) */
808 p_cmd->control.i_i64 = (int64_t)va_arg( args, int64_t );
811 case ES_OUT_SET_GROUP_PCR: /* arg1= int i_group, arg2=int64_t i_pcr(microsecond!)*/
812 p_cmd->control.i_int = (int)va_arg( args, int );
813 p_cmd->control.i_i64 = (int64_t)va_arg( args, int64_t );
816 case ES_OUT_RESET_PCR: /* no arg */
819 case ES_OUT_SET_GROUP_META: /* arg1=int i_group arg2=vlc_meta_t* */
821 p_cmd->control.i_int = (int)va_arg( args, int );
822 vlc_meta_t *p_meta = (vlc_meta_t*)va_arg( args, vlc_meta_t * );
826 p_cmd->control.p_meta = vlc_meta_New();
827 if( !p_cmd->control.p_meta )
829 vlc_meta_Merge( p_cmd->control.p_meta, p_meta );
833 p_cmd->control.p_meta = p_meta;
838 case ES_OUT_SET_GROUP_EPG: /* arg1=int i_group arg2=vlc_epg_t* */
840 p_cmd->control.i_int = (int)va_arg( args, int );
841 vlc_epg_t *p_epg = (vlc_epg_t*)va_arg( args, vlc_epg_t * );
845 p_cmd->control.p_epg = vlc_epg_New( p_epg->psz_name );
846 if( !p_cmd->control.p_epg )
848 for( int i = 0; i < p_epg->i_event; i++ )
850 vlc_epg_event_t *p_evt = p_epg->pp_event[i];
852 vlc_epg_AddEvent( p_cmd->control.p_epg,
853 p_evt->i_start, p_evt->i_duration,
855 p_evt->psz_short_description, p_evt->psz_description );
857 vlc_epg_SetCurrent( p_cmd->control.p_epg,
858 p_epg->p_current ? p_epg->p_current->i_start : -1 );
862 p_cmd->control.p_epg = p_epg;
867 /* Modified control */
868 case ES_OUT_SET_ES: /* arg1= es_out_id_t* */
869 case ES_OUT_RESTART_ES: /* arg1= es_out_id_t* */
870 case ES_OUT_SET_ES_DEFAULT: /* arg1= es_out_id_t* */
871 p_cmd->control.p_es = (es_out_id_t*)va_arg( args, es_out_id_t * );
874 case ES_OUT_SET_ES_STATE:/* arg1= es_out_id_t* arg2=bool */
875 p_cmd->control.p_es = (es_out_id_t*)va_arg( args, es_out_id_t * );
876 p_cmd->control.b_bool = (bool)va_arg( args, int );
879 case ES_OUT_GET_ES_STATE:/* arg1= es_out_id_t* arg2=bool* */
880 p_cmd->control.p_es = (es_out_id_t*)va_arg( args, es_out_id_t * );
881 p_cmd->control.pb_bool = (bool*)va_arg( args, bool * );
884 case ES_OUT_SET_ES_FMT: /* arg1= es_out_id_t* arg2=es_format_t* */
886 p_cmd->control.p_es = (es_out_id_t*)va_arg( args, es_out_id_t * );
887 es_format_t *p_fmt = (es_format_t*)va_arg( args, es_format_t * );
891 p_cmd->control.p_fmt = malloc( sizeof(*p_fmt) );
892 if( !p_cmd->control.p_fmt )
894 es_format_Copy( p_cmd->control.p_fmt, p_fmt );
898 p_cmd->control.p_fmt = p_fmt;
910 static int CmdExecuteControl( es_out_t *p_out, ts_cmd_t *p_cmd )
912 es_out_sys_t *p_sys = p_out->p_sys;
913 const int i_query = p_cmd->control.i_query;
917 /* Pass-through control */
918 case ES_OUT_SET_ACTIVE: /* arg1= bool */
919 return es_out_Control( p_sys->p_out, i_query, p_cmd->control.b_bool );
921 case ES_OUT_GET_ACTIVE: /* arg1= bool* */
922 return es_out_Control( p_sys->p_out, i_query, p_cmd->control.pb_bool );
924 case ES_OUT_SET_MODE: /* arg1= int */
925 case ES_OUT_SET_GROUP: /* arg1= int */
926 case ES_OUT_DEL_GROUP: /* arg1=int i_group */
927 return es_out_Control( p_sys->p_out, i_query, p_cmd->control.i_int );
929 case ES_OUT_GET_MODE: /* arg2= int* */
930 case ES_OUT_GET_GROUP: /* arg1= int* */
931 return es_out_Control( p_sys->p_out, i_query, p_cmd->control.pi_int );
933 case ES_OUT_SET_PCR: /* arg1=int64_t i_pcr(microsecond!) (using default group 0)*/
934 case ES_OUT_SET_NEXT_DISPLAY_TIME: /* arg1=int64_t i_pts(microsecond) */
935 return es_out_Control( p_sys->p_out, i_query, p_cmd->control.i_i64 );
937 case ES_OUT_SET_GROUP_PCR: /* arg1= int i_group, arg2=int64_t i_pcr(microsecond!)*/
938 return es_out_Control( p_sys->p_out, i_query, p_cmd->control.i_int, p_cmd->control.i_i64 );
940 case ES_OUT_RESET_PCR: /* no arg */
941 return es_out_Control( p_sys->p_out, i_query );
943 case ES_OUT_SET_GROUP_META: /* arg1=int i_group arg2=vlc_meta_t* */
944 return es_out_Control( p_sys->p_out, i_query, p_cmd->control.i_int, p_cmd->control.p_meta );
946 case ES_OUT_SET_GROUP_EPG: /* arg1=int i_group arg2=vlc_epg_t* */
947 return es_out_Control( p_sys->p_out, i_query, p_cmd->control.i_int, p_cmd->control.p_epg );
949 /* Modified control */
950 case ES_OUT_SET_ES: /* arg1= es_out_id_t* */
951 case ES_OUT_RESTART_ES: /* arg1= es_out_id_t* */
952 case ES_OUT_SET_ES_DEFAULT: /* arg1= es_out_id_t* */
953 return es_out_Control( p_sys->p_out, i_query, p_cmd->control.p_es->p_es );
955 case ES_OUT_SET_ES_STATE:/* arg1= es_out_id_t* arg2=bool */
956 return es_out_Control( p_sys->p_out, i_query, p_cmd->control.p_es->p_es, p_cmd->control.b_bool );
958 case ES_OUT_GET_ES_STATE:/* arg1= es_out_id_t* arg2=bool* */
959 return es_out_Control( p_sys->p_out, i_query, p_cmd->control.p_es->p_es, p_cmd->control.pb_bool );
961 case ES_OUT_SET_ES_FMT: /* arg1= es_out_id_t* arg2=es_format_t* */
962 return es_out_Control( p_sys->p_out, i_query, p_cmd->control.p_es->p_es, p_cmd->control.p_fmt );
966 msg_Err( p_sys->p_input, "Unknown es_out_Control query in CmdExecuteControl!" );
970 static void CmdCleanControl( ts_cmd_t *p_cmd )
972 if( p_cmd->control.p_meta )
973 vlc_meta_Delete( p_cmd->control.p_meta );
974 if( p_cmd->control.p_epg )
975 vlc_epg_Delete( p_cmd->control.p_epg );
976 if( p_cmd->control.p_fmt )
978 es_format_Clean( p_cmd->control.p_fmt );
979 free( p_cmd->control.p_fmt );
984 /*****************************************************************************
986 *****************************************************************************/
987 static char *GetTmpPath( char *psz_path )
989 if( psz_path && *psz_path )
991 /* Make sure that the path exists and is a directory */
993 const int i_ret = utf8_stat( psz_path, &s );
995 if( i_ret < 0 && !utf8_mkdir( psz_path, 0600 ) )
997 else if( i_ret == 0 && ( s.st_mode & S_IFDIR ) )
1002 /* Create a suitable path */
1003 #if defined (WIN32) && !defined (UNDER_CE)
1004 const DWORD dwCount = GetTempPathW( 0, NULL );
1005 wchar_t *psw_path = calloc( dwCount + 1, sizeof(wchar_t) );
1008 if( GetTempPathW( dwCount + 1, psw_path ) <= 0 )
1012 psw_path = _wgetcwd( NULL, 0 );
1019 psz_path = FromWide( psw_path );
1020 while( psz_path && *psz_path && psz_path[strlen( psz_path ) - 1] == '\\' )
1021 psz_path[strlen( psz_path ) - 1] = '\0';
1026 if( !psz_path || *psz_path == '\0' )
1029 return strdup( "C:" );
1032 psz_path = strdup( "/tmp" );
1038 static FILE *GetTmpFile( const char *psz_path )
1045 if( asprintf( &psz_name, "%s/vlc-timeshift.XXXXXX", psz_path ) < 0 )
1049 fd = mkstemp( psz_name );
1056 f = fdopen( fd, "rw+" );