]> git.sesse.net Git - vlc/commitdiff
Moved out video statistics to its own file and use a dedicated lock.
authorLaurent Aimar <fenrir@videolan.org>
Fri, 31 Jul 2009 22:32:54 +0000 (00:32 +0200)
committerLaurent Aimar <fenrir@videolan.org>
Sat, 1 Aug 2009 10:07:12 +0000 (12:07 +0200)
src/Makefile.am
src/video_output/statistic.h [new file with mode: 0644]
src/video_output/video_output.c
src/video_output/vout_internal.h

index f4f52afb8c1ac23b9db9e4574fdc7f08a06cce63..0eb0ad8ecf4efa295df2239261d24c5ab1f8d685 100644 (file)
@@ -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 (file)
index 0000000..68f81f8
--- /dev/null
@@ -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
+
index 691e144064b91334005ed7e8fe141e0cfae6d92e..7f9783b91d864bde8b83f03a97fc18ac7fcb6101 100644 (file)
@@ -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;
@@ -585,6 +584,9 @@ static void vout_Destructor( vlc_object_t * p_this )
     vlc_mutex_destroy( &p_vout->change_lock );
     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 );
index 12a57302b5eb44584f9317227cc4b0086abba1bc..b22c81e19553082d3a6a5c6fdc418524d214fa53 100644 (file)
@@ -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;