[vlc-devel] commit: Moved out video statistics to its own file and use a dedicated lock . (Laurent Aimar )

git version control git at videolan.org
Sat Aug 1 12:08:13 CEST 2009


vlc | branch: master | Laurent Aimar <fenrir at videolan.org> | Sat Aug  1 00:32:54 2009 +0200| [2bffade09ed0334fa0cc4cd9cdec043f92034891] | committer: Laurent Aimar 

Moved out video statistics to its own file and use a dedicated lock.

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=2bffade09ed0334fa0cc4cd9cdec043f92034891
---

 src/Makefile.am                  |    1 +
 src/video_output/statistic.h     |   65 ++++++++++++++++++++++++++++++++++++++
 src/video_output/video_output.c  |   21 +++++-------
 src/video_output/vout_internal.h |    4 +-
 4 files changed, 76 insertions(+), 15 deletions(-)

diff --git a/src/Makefile.am b/src/Makefile.am
index f4f52af..0eb0ad8 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -346,6 +346,7 @@ SOURCES_libvlc_common = \
 	input/var.c \
 	video_output/snapshot.c \
 	video_output/snapshot.h \
+	video_output/statistic.h \
 	video_output/video_output.c \
 	video_output/vout_pictures.c \
 	video_output/vout_pictures.h \
diff --git a/src/video_output/statistic.h b/src/video_output/statistic.h
new file mode 100644
index 0000000..68f81f8
--- /dev/null
+++ b/src/video_output/statistic.h
@@ -0,0 +1,65 @@
+/*****************************************************************************
+ * statistic.c : vout statistic
+ *****************************************************************************
+ * Copyright (C) 2009 Laurent Aimar
+ * $Id$
+ *
+ * Authors: Laurent Aimar <fenrir _AT_ videolan _DOT_ org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
+ *****************************************************************************/
+
+#if defined(__PLUGIN__) || defined(__BUILTIN__) || !defined(__LIBVLC__)
+# error This header file can only be included from LibVLC.
+#endif
+
+#ifndef _VOUT_STATISTIC_H
+#define _VOUT_STATISTIC_H
+
+typedef struct {
+    vlc_spinlock_t spin;
+
+    int displayed;
+    int lost;
+} vout_statistic_t;
+
+static inline void vout_statistic_Init(vout_statistic_t *stat)
+{
+    vlc_spin_init(&stat->spin);
+}
+static inline void vout_statistic_Clean(vout_statistic_t *stat)
+{
+    vlc_spin_destroy(&stat->spin);
+}
+static inline void vout_statistic_GetReset(vout_statistic_t *stat, int *displayed, int *lost)
+{
+    vlc_spin_lock(&stat->spin);
+    *displayed = stat->displayed;
+    *lost      = stat->lost;
+
+    stat->displayed = 0;
+    stat->lost      = 0;
+    vlc_spin_unlock(&stat->spin);
+}
+static inline void vout_statistic_Update(vout_statistic_t *stat, int displayed, int lost)
+{
+    vlc_spin_lock(&stat->spin);
+    stat->displayed += displayed;
+    stat->lost      += lost;
+    vlc_spin_unlock(&stat->spin);
+}
+
+#endif
+
diff --git a/src/video_output/video_output.c b/src/video_output/video_output.c
index 691e144..7f9783b 100644
--- a/src/video_output/video_output.c
+++ b/src/video_output/video_output.c
@@ -384,8 +384,7 @@ vout_thread_t * __vout_Create( vlc_object_t *p_parent, video_format_t *p_fmt )
     p_vout->i_alignment  = 0;
     p_vout->p->render_time  = 10;
     p_vout->p->c_fps_samples = 0;
-    p_vout->p->i_picture_lost = 0;
-    p_vout->p->i_picture_displayed = 0;
+    vout_statistic_Init( &p_vout->p->statistic );
     p_vout->p->b_filter_change = 0;
     p_vout->p->b_paused = false;
     p_vout->p->i_pause_date = 0;
@@ -586,6 +585,9 @@ static void vout_Destructor( vlc_object_t * p_this )
     vlc_mutex_destroy( &p_vout->p->vfilter_lock );
 
     /* */
+    vout_statistic_Clean( &p_vout->p->statistic );
+
+    /* */
     vout_snapshot_Clean( &p_vout->p->snapshot );
 
     /* */
@@ -652,15 +654,8 @@ void vout_ChangePause( vout_thread_t *p_vout, bool b_paused, mtime_t i_date )
 
 void vout_GetResetStatistic( vout_thread_t *p_vout, int *pi_displayed, int *pi_lost )
 {
-    vlc_mutex_lock( &p_vout->change_lock );
-
-    *pi_displayed = p_vout->p->i_picture_displayed;
-    *pi_lost = p_vout->p->i_picture_lost;
-
-    p_vout->p->i_picture_displayed = 0;
-    p_vout->p->i_picture_lost = 0;
-
-    vlc_mutex_unlock( &p_vout->change_lock );
+    vout_statistic_GetReset( &p_vout->p->statistic,
+                             pi_displayed, pi_lost );
 }
 
 void vout_Flush( vout_thread_t *p_vout, mtime_t i_date )
@@ -1052,7 +1047,7 @@ static void* RunThread( void *p_this )
                 /* Picture is late: it will be destroyed and the thread
                  * will directly choose the next picture */
                 vout_UsePictureLocked( p_vout, p_pic );
-                p_vout->p->i_picture_lost++;
+                vout_statistic_Update( &p_vout->p->statistic, 0, 1 );
 
                 msg_Warn( p_vout, "late picture skipped (%"PRId64" > %d)",
                                   current_date - p_pic->date, - p_vout->p->render_time );
@@ -1167,7 +1162,7 @@ static void* RunThread( void *p_this )
         /*
          * Perform rendering
          */
-        p_vout->p->i_picture_displayed++;
+        vout_statistic_Update( &p_vout->p->statistic, 1, 0 );
         p_directbuffer = vout_RenderPicture( p_vout,
                                              p_filtered_picture, p_subpic,
                                              spu_render_time );
diff --git a/src/video_output/vout_internal.h b/src/video_output/vout_internal.h
index 12a5730..b22c81e 100644
--- a/src/video_output/vout_internal.h
+++ b/src/video_output/vout_internal.h
@@ -32,6 +32,7 @@
 
 #include "vout_control.h"
 #include "snapshot.h"
+#include "statistic.h"
 
 /* Number of pictures required to computes the FPS rate */
 #define VOUT_FPS_SAMPLES                20
@@ -72,8 +73,7 @@ struct vout_thread_sys_t
     mtime_t         p_fps_sample[VOUT_FPS_SAMPLES];     /**< FPS samples dates */
 
     /* Statistics */
-    int             i_picture_lost;
-    int             i_picture_displayed;
+    vout_statistic_t statistic;
 
     /* Pause */
     bool            b_paused;




More information about the vlc-devel mailing list