Commit 21145a59 authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont

TS: fix ts-dump error handling, remove a useless variable

parent d64ca8ac
...@@ -392,7 +392,6 @@ struct demux_sys_t ...@@ -392,7 +392,6 @@ struct demux_sys_t
char *psz_file; /* file to dump data in */ char *psz_file; /* file to dump data in */
FILE *p_file; /* filehandle */ FILE *p_file; /* filehandle */
uint64_t i_write; /* bytes written */ uint64_t i_write; /* bytes written */
bool b_file_out; /* dump mode enabled */
/* */ /* */
bool b_start_record; bool b_start_record;
...@@ -590,12 +589,9 @@ static int Open( vlc_object_t *p_this ) ...@@ -590,12 +589,9 @@ static int Open( vlc_object_t *p_this )
p_sys->i_write = 0; p_sys->i_write = 0;
p_sys->buffer = NULL; p_sys->buffer = NULL;
p_sys->p_file = NULL; p_sys->p_file = NULL;
p_sys->b_file_out = false; p_sys->psz_file = var_InheritString( p_demux, "ts-dump-file" );
p_sys->psz_file = var_CreateGetString( p_demux, "ts-dump-file" ); if( p_sys->psz_file != NULL )
if( *p_sys->psz_file != '\0' )
{ {
p_sys->b_file_out = true;
b_append = var_CreateGetBool( p_demux, "ts-dump-append" ); b_append = var_CreateGetBool( p_demux, "ts-dump-append" );
if ( b_append ) if ( b_append )
psz_mode = "ab"; psz_mode = "ab";
...@@ -607,14 +603,20 @@ static int Open( vlc_object_t *p_this ) ...@@ -607,14 +603,20 @@ static int Open( vlc_object_t *p_this )
msg_Info( p_demux, "dumping raw stream to standard output" ); msg_Info( p_demux, "dumping raw stream to standard output" );
p_sys->p_file = stdout; p_sys->p_file = stdout;
} }
else if( ( p_sys->p_file = vlc_fopen( p_sys->psz_file, psz_mode ) ) == NULL ) else
{
p_sys->p_file = vlc_fopen( p_sys->psz_file, psz_mode );
if( p_sys->p_file == NULL )
{ {
msg_Err( p_demux, "cannot create `%s' for writing", p_sys->psz_file ); msg_Err( p_demux, "cannot write to file `%s': %m",
p_sys->b_file_out = false; p_sys->psz_file );
free( p_sys->psz_file );
vlc_mutex_destroy( &p_sys->csa_lock );
free( p_sys );
return VLC_EGENERIC;
}
} }
if( p_sys->b_file_out )
{
/* Determine how many packets to read. */ /* Determine how many packets to read. */
int bufsize = var_CreateGetInteger( p_demux, "ts-dump-size" ); int bufsize = var_CreateGetInteger( p_demux, "ts-dump-size" );
p_sys->i_ts_read = (int) (bufsize / p_sys->i_packet_size); p_sys->i_ts_read = (int) (bufsize / p_sys->i_packet_size);
...@@ -626,12 +628,8 @@ static int Open( vlc_object_t *p_this ) ...@@ -626,12 +628,8 @@ static int Open( vlc_object_t *p_this )
msg_Info( p_demux, "%s raw stream to file `%s' reading packets %d", msg_Info( p_demux, "%s raw stream to file `%s' reading packets %d",
b_append ? "appending" : "dumping", p_sys->psz_file, b_append ? "appending" : "dumping", p_sys->psz_file,
p_sys->i_ts_read ); p_sys->i_ts_read );
}
}
/* Fill p_demux field */
if( p_sys->b_file_out )
p_demux->pf_demux = DemuxFile; p_demux->pf_demux = DemuxFile;
}
else else
p_demux->pf_demux = Demux; p_demux->pf_demux = Demux;
p_demux->pf_control = Control; p_demux->pf_control = Control;
...@@ -709,7 +707,7 @@ static int Open( vlc_object_t *p_this ) ...@@ -709,7 +707,7 @@ static int Open( vlc_object_t *p_this )
p_sys->b_es_id_pid = var_CreateGetBool( p_demux, "ts-es-id-pid" ); p_sys->b_es_id_pid = var_CreateGetBool( p_demux, "ts-es-id-pid" );
char* psz_string = var_CreateGetString( p_demux, "ts-out" ); char* psz_string = var_CreateGetString( p_demux, "ts-out" );
if( psz_string && *psz_string && !p_sys->b_file_out ) if( psz_string && *psz_string && !p_sys->p_file )
{ {
char *psz = strchr( psz_string, ':' ); char *psz = strchr( psz_string, ':' );
int i_port = 0; int i_port = 0;
...@@ -822,14 +820,15 @@ static int Open( vlc_object_t *p_this ) ...@@ -822,14 +820,15 @@ static int Open( vlc_object_t *p_this )
p_sys->b_force_seek_per_percent = true; p_sys->b_force_seek_per_percent = true;
} }
while( !p_sys->b_file_out && p_sys->i_pmt_es <= 0 && if( p_sys->p_file != NULL )
vlc_object_alive( p_demux ) ) return VLC_SUCCESS;
while( p_sys->i_pmt_es <= 0 && vlc_object_alive( p_demux ) )
{ {
if( p_demux->pf_demux( p_demux ) != 1 ) if( p_demux->pf_demux( p_demux ) != 1 )
break; break;
} }
return VLC_SUCCESS; return VLC_SUCCESS;
} }
...@@ -900,16 +899,13 @@ static void Close( vlc_object_t *p_this ) ...@@ -900,16 +899,13 @@ static void Close( vlc_object_t *p_this )
free( p_sys->programs_list.p_values ); free( p_sys->programs_list.p_values );
/* If in dump mode, then close the file */ /* If in dump mode, then close the file */
if( p_sys->b_file_out ) if( p_sys->p_file != NULL )
{ {
msg_Info( p_demux ,"closing %s (%"PRId64" KiB dumped)", msg_Info( p_demux ,"closing %s (%"PRId64" KiB dumped)",
p_sys->psz_file, p_sys->i_write / 1024 ); p_sys->psz_file, p_sys->i_write / 1024 );
if( p_sys->p_file != stdout ) if( p_sys->p_file != stdout )
{
fclose( p_sys->p_file ); fclose( p_sys->p_file );
} }
}
/* When streaming, close the port */ /* When streaming, close the port */
if( p_sys->fd > -1 ) if( p_sys->fd > -1 )
{ {
...@@ -1178,7 +1174,7 @@ static int Control( demux_t *p_demux, int i_query, va_list args ) ...@@ -1178,7 +1174,7 @@ static int Control( demux_t *p_demux, int i_query, va_list args )
int64_t *pi64; int64_t *pi64;
int i_int; int i_int;
if( p_sys->b_file_out ) if( p_sys->p_file != NULL )
return demux_vaControlHelper( p_demux->s, 0, -1, 0, 1, i_query, args ); return demux_vaControlHelper( p_demux->s, 0, -1, 0, 1, i_query, args );
switch( i_query ) switch( i_query )
......
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