VLC  4.0.0-dev
chrono.h
Go to the documentation of this file.
1 /*****************************************************************************
2  * chrono.h: vout chrono
3  *****************************************************************************
4  * Copyright (C) 2009-2010 Laurent Aimar
5  *
6  * Authors: Laurent Aimar <fenrir _AT_ videolan _DOT_ org>
7  *
8  * This program is free software; you can redistribute it and/or modify it
9  * under the terms of the GNU Lesser General Public License as published by
10  * the Free Software Foundation; either version 2.1 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public License
19  * along with this program; if not, write to the Free Software Foundation,
20  * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
21  *****************************************************************************/
22 
23 #ifndef LIBVLC_VOUT_CHRONO_H
24 #define LIBVLC_VOUT_CHRONO_H
25 
26 #include <assert.h>
27 
28 typedef struct {
29  int shift;
32 
33  int shift_var;
35 
38 
39 static inline void vout_chrono_Init(vout_chrono_t *chrono, int shift, vlc_tick_t avg_initial)
40 {
41  chrono->shift = shift;
42  chrono->avg_initial =
43  chrono->avg = avg_initial;
44 
45  chrono->shift_var = shift+1;
46  chrono->var = avg_initial / 2;
47 
48  chrono->start = VLC_TICK_INVALID;
49 }
50 static inline void vout_chrono_Clean(vout_chrono_t *chrono)
51 {
52  VLC_UNUSED(chrono);
53 }
54 static inline void vout_chrono_Start(vout_chrono_t *chrono)
55 {
56  chrono->start = vlc_tick_now();
57 }
59 {
60  return chrono->avg + 2 * chrono->var;
61 }
63 {
64  return __MAX(chrono->avg - 2 * chrono->var, 0);
65 }
66 
67 static inline void vout_chrono_Stop(vout_chrono_t *chrono)
68 {
69  assert(chrono->start != VLC_TICK_INVALID);
70 
71  /* */
72  const vlc_tick_t duration = vlc_tick_now() - chrono->start;
73  const vlc_tick_t var = llabs( duration - chrono->avg );
74 
75  /* Update average only if the current point is 'valid' */
76  if( duration < vout_chrono_GetHigh( chrono ) )
77  chrono->avg = (((1 << chrono->shift) - 1) * chrono->avg + duration) >> chrono->shift;
78  /* Always update the variance */
79  chrono->var = (((1 << chrono->shift_var) - 1) * chrono->var + var) >> chrono->shift_var;
80 
81  /* For assert */
82  chrono->start = VLC_TICK_INVALID;
83 }
84 static inline void vout_chrono_Reset(vout_chrono_t *chrono)
85 {
86  vout_chrono_t ch = *chrono;
87  vout_chrono_Clean(chrono);
88  vout_chrono_Init(chrono, ch.shift, ch.avg_initial);
89 }
90 
91 #endif
static vlc_tick_t vout_chrono_GetHigh(vout_chrono_t *chrono)
Definition: chrono.h:58
#define VLC_UNUSED(x)
Definition: vlc_common.h:1102
vlc_tick_t vlc_tick_now(void)
Precision monotonic clock.
Definition: thread.c:292
static void vout_chrono_Clean(vout_chrono_t *chrono)
Definition: chrono.h:50
static void vout_chrono_Start(vout_chrono_t *chrono)
Definition: chrono.h:54
const char var[sizeof("video")]
Definition: player.c:1744
int64_t vlc_tick_t
High precision date or time interval.
Definition: vlc_tick.h:45
vlc_tick_t var
Definition: chrono.h:34
vlc_tick_t start
Definition: chrono.h:36
int shift
Definition: chrono.h:29
static vlc_tick_t vout_chrono_GetLow(vout_chrono_t *chrono)
Definition: chrono.h:62
static void vout_chrono_Reset(vout_chrono_t *chrono)
Definition: chrono.h:84
static void vout_chrono_Init(vout_chrono_t *chrono, int shift, vlc_tick_t avg_initial)
Definition: chrono.h:39
vlc_tick_t avg_initial
Definition: chrono.h:31
vlc_tick_t avg
Definition: chrono.h:30
Definition: chrono.h:28
#define VLC_TICK_INVALID
Definition: vlc_config.h:44
static void vout_chrono_Stop(vout_chrono_t *chrono)
Definition: chrono.h:67
int shift_var
Definition: chrono.h:33