[vlc-commits] stats: add create/destroy functions
Rémi Denis-Courmont
git at videolan.org
Tue Dec 12 19:36:54 CET 2017
vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Tue Dec 12 19:32:46 2017 +0200| [bc2070aa82f272bf26cfe72fc431d04cbd654ee1] | committer: Rémi Denis-Courmont
stats: add create/destroy functions
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=bc2070aa82f272bf26cfe72fc431d04cbd654ee1
---
src/input/input.c | 20 ++++----------------
src/input/input_internal.h | 3 ++-
src/input/stats.c | 21 ++++++++++++++++++++-
3 files changed, 26 insertions(+), 18 deletions(-)
diff --git a/src/input/input.c b/src/input/input.c
index 7255a24506..31fe533514 100644
--- a/src/input/input.c
+++ b/src/input/input.c
@@ -253,10 +253,7 @@ static void input_Destructor( vlc_object_t *obj )
input_item_Release( priv->p_item );
if( priv->stats != NULL )
- {
- vlc_mutex_destroy( &priv->stats->lock );
- free( priv->stats );
- }
+ input_stats_Destroy( priv->stats );
for( int i = 0; i < priv->i_control; i++ )
{
@@ -472,19 +469,10 @@ static input_thread_t *Create( vlc_object_t *p_parent, input_item_t *p_item,
input_SendEventMeta( p_input );
/* */
- struct input_stats *stats = NULL;
if( !priv->b_preparsing && var_InheritBool( p_input, "stats" ) )
- {
- stats = malloc( sizeof (*stats) );
- if( likely(stats != NULL) )
- {
- memset( stats, 0, sizeof (*stats) );
- input_rate_Init( &stats->input_bitrate );
- input_rate_Init( &stats->demux_bitrate );
- vlc_mutex_init( &stats->lock );
- }
- }
- priv->stats = stats;
+ priv->stats = input_stats_Create();
+ else
+ priv->stats = NULL;
priv->p_es_out_display = input_EsOutNew( p_input, priv->i_rate );
priv->p_es_out = NULL;
diff --git a/src/input/input_internal.h b/src/input/input_internal.h
index 24340c6df4..f00bd9ff9f 100644
--- a/src/input/input_internal.h
+++ b/src/input/input_internal.h
@@ -291,7 +291,8 @@ struct input_stats {
vlc_mutex_t lock;
};
-void input_rate_Init(input_rate_t *rate);
+struct input_stats *input_stats_Create(void);
+void input_stats_Destroy(struct input_stats *);
void input_rate_Update(input_rate_t *, uintmax_t);
void input_stats_Compute(struct input_stats *, input_stats_t*);
diff --git a/src/input/stats.c b/src/input/stats.c
index fb803394e1..0f30d0ae92 100644
--- a/src/input/stats.c
+++ b/src/input/stats.c
@@ -34,7 +34,7 @@
/**
* Create a statistics counter
*/
-void input_rate_Init(input_rate_t *rate)
+static void input_rate_Init(input_rate_t *rate)
{
rate->samples[0].date = VLC_TS_INVALID;
rate->samples[1].date = VLC_TS_INVALID;
@@ -49,6 +49,25 @@ static float stats_GetRate(const input_rate_t *rate)
/ (float)(rate->samples[0].date - rate->samples[1].date);
}
+struct input_stats *input_stats_Create(void)
+{
+ struct input_stats *stats = malloc(sizeof (*stats));
+ if (unlikely(stats == NULL))
+ return NULL;
+
+ memset(stats, 0, sizeof (*stats));
+ input_rate_Init(&stats->input_bitrate);
+ input_rate_Init(&stats->demux_bitrate);
+ vlc_mutex_init(&stats->lock);
+ return stats;
+}
+
+void input_stats_Destroy(struct input_stats *stats)
+{
+ vlc_mutex_destroy(&stats->lock);
+ free(stats);
+}
+
void input_stats_Compute(struct input_stats *stats, input_stats_t *st)
{
vlc_mutex_lock(&stats->lock);
More information about the vlc-commits
mailing list