/src/vlc/src/video_output/statistic.h
Line | Count | Source |
1 | | /***************************************************************************** |
2 | | * statistic.h : vout statistic |
3 | | ***************************************************************************** |
4 | | * Copyright (C) 2009 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_STATISTIC_H |
24 | | # define LIBVLC_VOUT_STATISTIC_H |
25 | | # include <stdatomic.h> |
26 | | |
27 | | /* NOTE: Both statistics are atomic on their own, so one might be older than |
28 | | * the other one. Currently, only one of them is updated at a time, so this |
29 | | * is a non-issue. */ |
30 | | typedef struct { |
31 | | atomic_uint displayed; |
32 | | atomic_uint lost; |
33 | | atomic_uint late; |
34 | | } vout_statistic_t; |
35 | | |
36 | | static inline void vout_statistic_Init(vout_statistic_t *stat) |
37 | 0 | { |
38 | 0 | atomic_init(&stat->displayed, 0); |
39 | 0 | atomic_init(&stat->lost, 0); |
40 | 0 | atomic_init(&stat->late, 0); |
41 | 0 | } |
42 | | |
43 | | static inline void vout_statistic_Clean(vout_statistic_t *stat) |
44 | 0 | { |
45 | 0 | (void) stat; |
46 | 0 | } |
47 | | |
48 | | static inline void vout_statistic_GetReset(vout_statistic_t *stat, |
49 | | unsigned *restrict displayed, |
50 | | unsigned *restrict lost, |
51 | | unsigned *restrict late) |
52 | 0 | { |
53 | 0 | *displayed = atomic_exchange_explicit(&stat->displayed, 0, |
54 | 0 | memory_order_relaxed); |
55 | 0 | *lost = atomic_exchange_explicit(&stat->lost, 0, memory_order_relaxed); |
56 | 0 | *late = atomic_exchange_explicit(&stat->late, 0, memory_order_relaxed); |
57 | 0 | } |
58 | | |
59 | | static inline void vout_statistic_AddDisplayed(vout_statistic_t *stat, |
60 | | int displayed) |
61 | 0 | { |
62 | 0 | atomic_fetch_add_explicit(&stat->displayed, displayed, |
63 | 0 | memory_order_relaxed); |
64 | 0 | } |
65 | | |
66 | | static inline void vout_statistic_AddLost(vout_statistic_t *stat, int lost) |
67 | 0 | { |
68 | 0 | atomic_fetch_add_explicit(&stat->lost, lost, memory_order_relaxed); |
69 | 0 | } |
70 | | |
71 | | static inline void vout_statistic_AddLate(vout_statistic_t *stat, int late) |
72 | 0 | { |
73 | | atomic_fetch_add_explicit(&stat->late, late, memory_order_relaxed); |
74 | 0 | } |
75 | | |
76 | | #endif |