Commit d17c2e5f authored by Derk-Jan Hartman's avatar Derk-Jan Hartman

* fix an issue with stats on inputstreams (this fixes the check for update crash)

- also fixed a similar potential issue on subtitles.
- lesson for today: Be careful when you use p_parent of an object.
- i chose not to use vlc_object_find, but yield/release instead because of the speed implications.
parent 816ea1d6
...@@ -1468,6 +1468,7 @@ char * stream_ReadLine( stream_t *s ) ...@@ -1468,6 +1468,7 @@ char * stream_ReadLine( stream_t *s )
{ {
input_thread_t *p_input; input_thread_t *p_input;
msg_Dbg( s, "%s BOM detected", psz_encoding ); msg_Dbg( s, "%s BOM detected", psz_encoding );
p_input = (input_thread_t *)vlc_object_find( s, VLC_OBJECT_INPUT, FIND_PARENT );
if( s->i_char_width > 1 ) if( s->i_char_width > 1 )
{ {
s->conv = vlc_iconv_open( "UTF-8", psz_encoding ); s->conv = vlc_iconv_open( "UTF-8", psz_encoding );
...@@ -1475,10 +1476,7 @@ char * stream_ReadLine( stream_t *s ) ...@@ -1475,10 +1476,7 @@ char * stream_ReadLine( stream_t *s )
{ {
msg_Err( s, "iconv_open failed" ); msg_Err( s, "iconv_open failed" );
} }
var_Create( s->p_parent->p_parent, "subsdec-encoding", VLC_VAR_STRING | VLC_VAR_DOINHERIT );
var_SetString( s->p_parent->p_parent, "subsdec-encoding", "UTF-8" );
} }
p_input = (input_thread_t *)vlc_object_find( s, VLC_OBJECT_INPUT, FIND_PARENT );
if( p_input != NULL) if( p_input != NULL)
{ {
var_Create( p_input, "subsdec-encoding", VLC_VAR_STRING | VLC_VAR_DOINHERIT ); var_Create( p_input, "subsdec-encoding", VLC_VAR_STRING | VLC_VAR_DOINHERIT );
...@@ -1575,15 +1573,20 @@ static int AReadStream( stream_t *s, void *p_read, int i_read ) ...@@ -1575,15 +1573,20 @@ static int AReadStream( stream_t *s, void *p_read, int i_read )
{ {
stream_sys_t *p_sys = s->p_sys; stream_sys_t *p_sys = s->p_sys;
access_t *p_access = p_sys->p_access; access_t *p_access = p_sys->p_access;
input_thread_t *p_input = NULL;
int i_read_orig = i_read; int i_read_orig = i_read;
int i_total; int i_total;
input_thread_t *p_input = (input_thread_t *)s->p_parent->p_parent ; if( s->p_parent && s->p_parent->p_parent &&
assert( p_input ); s->p_parent->p_parent->i_object_type == VLC_OBJECT_INPUT )
p_input = (input_thread_t *)s->p_parent->p_parent;
if( !p_sys->i_list ) if( !p_sys->i_list )
{ {
i_read = p_access->pf_read( p_access, p_read, i_read ); i_read = p_access->pf_read( p_access, p_read, i_read );
if( p_input )
{
vlc_object_yield( p_input );
vlc_mutex_lock( &p_input->counters.counters_lock ); vlc_mutex_lock( &p_input->counters.counters_lock );
stats_UpdateInteger( s, p_input->counters.p_read_bytes, i_read, stats_UpdateInteger( s, p_input->counters.p_read_bytes, i_read,
&i_total ); &i_total );
...@@ -1591,6 +1594,8 @@ static int AReadStream( stream_t *s, void *p_read, int i_read ) ...@@ -1591,6 +1594,8 @@ static int AReadStream( stream_t *s, void *p_read, int i_read )
(float)i_total, NULL ); (float)i_total, NULL );
stats_UpdateInteger( s, p_input->counters.p_read_packets, 1, NULL ); stats_UpdateInteger( s, p_input->counters.p_read_packets, 1, NULL );
vlc_mutex_unlock( &p_input->counters.counters_lock ); vlc_mutex_unlock( &p_input->counters.counters_lock );
vlc_object_release( p_input );
}
return i_read; return i_read;
} }
...@@ -1619,12 +1624,17 @@ static int AReadStream( stream_t *s, void *p_read, int i_read ) ...@@ -1619,12 +1624,17 @@ static int AReadStream( stream_t *s, void *p_read, int i_read )
} }
/* Update read bytes in input */ /* Update read bytes in input */
if( p_input )
{
vlc_object_yield( p_input );
vlc_mutex_lock( &p_input->counters.counters_lock ); vlc_mutex_lock( &p_input->counters.counters_lock );
stats_UpdateInteger( s, p_input->counters.p_read_bytes, i_read, &i_total ); stats_UpdateInteger( s, p_input->counters.p_read_bytes, i_read, &i_total );
stats_UpdateFloat( s, p_input->counters.p_input_bitrate, stats_UpdateFloat( s, p_input->counters.p_input_bitrate,
(float)i_total, NULL ); (float)i_total, NULL );
stats_UpdateInteger( s, p_input->counters.p_read_packets, 1, NULL ); stats_UpdateInteger( s, p_input->counters.p_read_packets, 1, NULL );
vlc_mutex_unlock( &p_input->counters.counters_lock ); vlc_mutex_unlock( &p_input->counters.counters_lock );
vlc_object_release( p_input );
}
return i_read; return i_read;
} }
...@@ -1632,19 +1642,22 @@ static block_t *AReadBlock( stream_t *s, vlc_bool_t *pb_eof ) ...@@ -1632,19 +1642,22 @@ static block_t *AReadBlock( stream_t *s, vlc_bool_t *pb_eof )
{ {
stream_sys_t *p_sys = s->p_sys; stream_sys_t *p_sys = s->p_sys;
access_t *p_access = p_sys->p_access; access_t *p_access = p_sys->p_access;
input_thread_t *p_input = NULL;
block_t *p_block; block_t *p_block;
vlc_bool_t b_eof; vlc_bool_t b_eof;
int i_total; int i_total;
input_thread_t *p_input = (input_thread_t *)s->p_parent->p_parent ; if( s->p_parent && s->p_parent->p_parent &&
assert( p_input ); s->p_parent->p_parent->i_object_type == VLC_OBJECT_INPUT )
p_input = (input_thread_t *)s->p_parent->p_parent;
if( !p_sys->i_list ) if( !p_sys->i_list )
{ {
p_block = p_access->pf_block( p_access ); p_block = p_access->pf_block( p_access );
if( pb_eof ) *pb_eof = p_access->info.b_eof; if( pb_eof ) *pb_eof = p_access->info.b_eof;
if( p_block && p_access->p_libvlc->b_stats ) if( p_input && p_block && p_access->p_libvlc->b_stats )
{ {
vlc_object_yield( p_input );
vlc_mutex_lock( &p_input->counters.counters_lock ); vlc_mutex_lock( &p_input->counters.counters_lock );
stats_UpdateInteger( s, p_input->counters.p_read_bytes, stats_UpdateInteger( s, p_input->counters.p_read_bytes,
p_block->i_buffer, &i_total ); p_block->i_buffer, &i_total );
...@@ -1652,6 +1665,7 @@ static block_t *AReadBlock( stream_t *s, vlc_bool_t *pb_eof ) ...@@ -1652,6 +1665,7 @@ static block_t *AReadBlock( stream_t *s, vlc_bool_t *pb_eof )
(float)i_total, NULL ); (float)i_total, NULL );
stats_UpdateInteger( s, p_input->counters.p_read_packets, 1, NULL ); stats_UpdateInteger( s, p_input->counters.p_read_packets, 1, NULL );
vlc_mutex_unlock( &p_input->counters.counters_lock ); vlc_mutex_unlock( &p_input->counters.counters_lock );
vlc_object_release( p_input );
} }
return p_block; return p_block;
} }
...@@ -1682,6 +1696,9 @@ static block_t *AReadBlock( stream_t *s, vlc_bool_t *pb_eof ) ...@@ -1682,6 +1696,9 @@ static block_t *AReadBlock( stream_t *s, vlc_bool_t *pb_eof )
} }
if( p_block ) if( p_block )
{ {
if( p_input )
{
vlc_object_yield( p_input );
vlc_mutex_lock( &p_input->counters.counters_lock ); vlc_mutex_lock( &p_input->counters.counters_lock );
stats_UpdateInteger( s, p_input->counters.p_read_bytes, stats_UpdateInteger( s, p_input->counters.p_read_bytes,
p_block->i_buffer, &i_total ); p_block->i_buffer, &i_total );
...@@ -1690,6 +1707,8 @@ static block_t *AReadBlock( stream_t *s, vlc_bool_t *pb_eof ) ...@@ -1690,6 +1707,8 @@ static block_t *AReadBlock( stream_t *s, vlc_bool_t *pb_eof )
stats_UpdateInteger( s, p_input->counters.p_read_packets, stats_UpdateInteger( s, p_input->counters.p_read_packets,
1 , NULL); 1 , NULL);
vlc_mutex_unlock( &p_input->counters.counters_lock ); vlc_mutex_unlock( &p_input->counters.counters_lock );
vlc_object_release( p_input );
}
} }
return p_block; return p_block;
} }
......
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