From: Pierre d'Herbemont Date: Sat, 29 Mar 2008 20:53:12 +0000 (+0100) Subject: stats: Move the stat to libvlc instead of the playlist. As stated in the code it... X-Git-Tag: 0.9.0-test0~1729 X-Git-Url: https://git.sesse.net/?a=commitdiff_plain;h=719f576184819f07b1807f8cc3e814ee4321fbaf;p=vlc stats: Move the stat to libvlc instead of the playlist. As stated in the code it is not playlist related. --- diff --git a/include/main.h b/include/main.h index c798a60898..11908effbc 100644 --- a/include/main.h +++ b/include/main.h @@ -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 */ diff --git a/include/vlc_playlist.h b/include/vlc_playlist.h index b7f33a91f4..9e88a68759 100644 --- a/include/vlc_playlist.h +++ b/include/vlc_playlist.h @@ -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 */ diff --git a/modules/misc/logger.c b/modules/misc/logger.c index c22860b373..c68271f3a2 100644 --- a/modules/misc/logger.c +++ b/modules/misc/logger.c @@ -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 ); } } diff --git a/src/input/input.c b/src/input/input.c index 3fdae9340f..ca1510e6cb 100644 --- a/src/input/input.c +++ b/src/input/input.c @@ -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 ); diff --git a/src/libvlc-common.c b/src/libvlc-common.c index e7755d5cda..c3e9f01c36 100644 --- a/src/libvlc-common.c +++ b/src/libvlc-common.c @@ -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; } diff --git a/src/playlist/engine.c b/src/playlist/engine.c index 55c084b2c5..444932d89e 100644 --- a/src/playlist/engine.c +++ b/src/playlist/engine.c @@ -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 */ diff --git a/src/playlist/thread.c b/src/playlist/thread.c index 69f62a3df2..8d2bd71c66 100644 --- a/src/playlist/thread.c +++ b/src/playlist/thread.c @@ -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 ) );