Commit 719f5761 authored by Pierre d'Herbemont's avatar Pierre d'Herbemont

stats: Move the stat to libvlc instead of the playlist. As stated in the code...

stats: Move the stat to libvlc instead of the playlist. As stated in the code it is not playlist related.
parent 1dfd50c2
......@@ -47,7 +47,10 @@ struct libvlc_int_t
playlist_t *p_playlist; ///< playlist object
vlc_object_t *p_interaction; ///< interface interaction object
vlc_object_t *p_interaction; ///< interface interaction object
void *p_stats_computer; ///< Input thread computing stats (needs cleanup)
global_stats_t *p_stats; ///< Global statistics
/* There is no real reason to keep a list of items, but not to break
* everything, let's keep it */
......
......@@ -231,10 +231,6 @@ struct playlist_t
when processing the request */
vlc_mutex_t lock; /**< Lock to protect request */
} request;
// Playlist-unrelated fields
input_thread_t *p_stats_computer; /**< Input thread computing stats */
global_stats_t *p_stats; /**< Global statistics */
};
/** Helper to add an item */
......
......@@ -454,20 +454,17 @@ static void HtmlPrint( const msg_item_t *p_msg, FILE *p_file )
static void DoRRD( intf_thread_t *p_intf )
{
playlist_t *p_playlist;
if( mdate() - p_intf->p_sys->last_update < 1000000 )
return;
p_intf->p_sys->last_update = mdate();
p_playlist = (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
FIND_ANYWHERE );
if( p_playlist && p_playlist->p_stats )
if( p_intf->p_libvlc->p_stats )
{
lldiv_t din = lldiv( p_playlist->p_stats->f_input_bitrate * 1000000,
lldiv_t din = lldiv( p_intf->p_libvlc->p_stats->f_input_bitrate * 1000000,
1000 );
lldiv_t ddm = lldiv( p_playlist->p_stats->f_demux_bitrate * 1000000,
lldiv_t ddm = lldiv( p_intf->p_libvlc->p_stats->f_demux_bitrate * 1000000,
1000 );
lldiv_t dout = lldiv( p_playlist->p_stats->f_output_bitrate * 1000000,
lldiv_t dout = lldiv( p_intf->p_libvlc->p_stats->f_output_bitrate * 1000000,
1000 );
fprintf( p_intf->p_sys->p_rrd,
I64Fi":%lld.%03u:%lld.%03u:%lld.%03u\n",
......@@ -476,6 +473,5 @@ static void DoRRD( intf_thread_t *p_intf )
ddm.quot, (unsigned int)ddm.rem,
dout.quot, (unsigned int)dout.rem );
fflush( p_intf->p_sys->p_rrd );
vlc_object_release( p_playlist );
}
}
......@@ -142,14 +142,14 @@ static input_thread_t *Create( vlc_object_t *p_parent, input_item_t *p_item,
/* One "randomly" selected input thread is responsible for computing
* the global stats. Check if there is already someone doing this */
if( p_input->p_libvlc->p_playlist->p_stats && !b_quick )
if( p_input->p_libvlc->p_stats && !b_quick )
{
vlc_mutex_lock( &p_input->p_libvlc->p_playlist->p_stats->lock );
if( p_input->p_libvlc->p_playlist->p_stats_computer == NULL )
vlc_mutex_lock( &p_input->p_libvlc->p_stats->lock );
if( p_input->p_libvlc->p_stats_computer == NULL )
{
p_input->p_libvlc->p_playlist->p_stats_computer = p_input;
p_input->p_libvlc->p_stats_computer = p_input;
}
vlc_mutex_unlock( &p_input->p_libvlc->p_playlist->p_stats->lock );
vlc_mutex_unlock( &p_input->p_libvlc->p_stats->lock );
}
p_input->b_preparsing = b_quick;
......@@ -748,10 +748,10 @@ static void MainLoop( input_thread_t *p_input )
{
stats_ComputeInputStats( p_input, p_input->p->input.p_item->p_stats );
/* Are we the thread responsible for computing global stats ? */
if( p_input->p_libvlc->p_playlist->p_stats_computer == p_input )
if( p_input->p_libvlc->p_stats_computer == p_input )
{
stats_ComputeGlobalStats( p_input->p_libvlc->p_playlist,
p_input->p_libvlc->p_playlist->p_stats );
stats_ComputeGlobalStats( p_input->p_libvlc,
p_input->p_libvlc->p_stats );
}
}
}
......@@ -1298,11 +1298,11 @@ static void End( input_thread_t * p_input )
{
/* make sure we are up to date */
stats_ComputeInputStats( p_input, p_input->p->input.p_item->p_stats );
if( p_input->p_libvlc->p_playlist->p_stats_computer == p_input )
if( p_input->p_libvlc->p_stats_computer == p_input )
{
stats_ComputeGlobalStats( p_input->p_libvlc->p_playlist,
p_input->p_libvlc->p_playlist->p_stats );
p_input->p_libvlc->p_playlist->p_stats_computer = NULL;
stats_ComputeGlobalStats( p_input->p_libvlc,
p_input->p_libvlc->p_stats );
p_input->p_libvlc->p_stats_computer = NULL;
}
CL_CO( read_bytes );
CL_CO( read_packets );
......
......@@ -726,6 +726,16 @@ int libvlc_InternalInit( libvlc_int_t *p_libvlc, int i_argc,
p_libvlc->i_timers = 0;
p_libvlc->pp_timers = NULL;
/* Init stats */
p_libvlc->p_stats = (global_stats_t *)malloc( sizeof( global_stats_t ) );
if( !p_libvlc->p_stats )
{
vlc_object_release( p_libvlc );
return VLC_ENOMEM;
}
vlc_mutex_init( p_libvlc, &p_libvlc->p_stats->lock );
p_libvlc->p_stats_computer = NULL;
/* Init the array that holds every input item */
ARRAY_INIT( p_libvlc->input_items );
p_libvlc->i_last_input_id = 0;
......@@ -992,6 +1002,10 @@ int libvlc_InternalCleanup( libvlc_int_t *p_libvlc )
FOREACH_END();
ARRAY_RESET( p_libvlc->input_items );
msg_Dbg( p_libvlc, "removing stats" );
vlc_mutex_destroy( &p_libvlc->p_stats->lock );
FREENULL( p_libvlc->p_stats );
return VLC_SUCCESS;
}
......
......@@ -202,11 +202,6 @@ static void playlist_Destructor( vlc_object_t * p_this )
{
vlc_object_release( p_playlist->p_fetcher );
}
// Stats
vlc_mutex_destroy( &p_playlist->p_stats->lock );
if( p_playlist->p_stats )
free( p_playlist->p_stats );
}
/* Destroy remaining objects */
......
......@@ -58,16 +58,6 @@ void __playlist_ThreadCreate( vlc_object_t *p_parent )
playlist_t *p_playlist = playlist_Create( p_parent );
if( !p_playlist ) return;
// Stats
p_playlist->p_stats = (global_stats_t *)malloc( sizeof( global_stats_t ) );
if( !p_playlist->p_stats )
{
vlc_object_release( p_playlist );
return;
}
vlc_mutex_init( p_playlist, &p_playlist->p_stats->lock );
p_playlist->p_stats_computer = NULL;
// Preparse
p_playlist->p_preparse = vlc_object_create( p_playlist,
sizeof( playlist_preparse_t ) );
......
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