Smart Remote 3 nRF52 v1.2
m_audio_gauges.h
1 /*$$$LICENCE_NORDIC_STANDARD<2016>$$$*/
2 
3 #ifndef __M_AUDIO_GAUGES_H__
4 #define __M_AUDIO_GAUGES_H__
5 
6 #include <stdint.h>
7 #include "nrf.h"
8 #include "nrf_atomic.h"
9 #include "app_util_platform.h"
10 #include "sr3_config.h"
11 
12 typedef struct
13 {
14  uint32_t total_time;
15  uint32_t cpu_time;
16  uint32_t timestamp;
17  uint8_t min_cpu_usage;
18  uint8_t cur_cpu_usage;
19  uint8_t max_cpu_usage;
20 } m_audio_cpu_gauge_t;
21 
22 typedef struct
23 {
24  uint32_t frames;
25  uint32_t bytes;
26  uint8_t min_bitrate;
27  uint8_t cur_bitrate;
28  uint8_t max_bitrate;
29 } m_audio_bitrate_gauge_t;
30 
31 typedef struct
32 {
33  nrf_atomic_u32_t total;
34  nrf_atomic_u32_t lost;
35  nrf_atomic_u32_t discarded;
36 } m_audio_loss_gauge_t;
37 
38 __STATIC_INLINE uint8_t m_audio_gauge_get_cur_cpu_usage(const m_audio_cpu_gauge_t *p_gauge)
39 {
40  return p_gauge->cur_cpu_usage;
41 }
42 
43 __STATIC_INLINE uint8_t m_audio_gauge_get_min_cpu_usage(const m_audio_cpu_gauge_t *p_gauge)
44 {
45  return p_gauge->min_cpu_usage;
46 }
47 
48 __STATIC_INLINE uint8_t m_audio_gauge_get_avg_cpu_usage(const m_audio_cpu_gauge_t *p_gauge)
49 {
50  uint32_t total_time;
51  uint32_t cpu_time;
52 
54  total_time = p_gauge->total_time;
55  cpu_time = p_gauge->cpu_time;
57 
58  if (total_time == 0)
59  {
60  return 0;
61  }
62 
63  return 100ull * cpu_time / total_time;
64 }
65 
66 __STATIC_INLINE uint8_t m_audio_gauge_get_max_cpu_usage(const m_audio_cpu_gauge_t *p_gauge)
67 {
68  return p_gauge->max_cpu_usage;
69 }
70 
71 __STATIC_INLINE uint8_t m_audio_gauge_get_cur_bitrate(const m_audio_bitrate_gauge_t *p_gauge)
72 {
73  return p_gauge->cur_bitrate;
74 }
75 
76 __STATIC_INLINE uint8_t m_audio_gauge_get_min_bitrate(const m_audio_bitrate_gauge_t *p_gauge)
77 {
78  return p_gauge->min_bitrate;
79 }
80 
81 __STATIC_INLINE uint8_t m_audio_gauge_get_avg_bitrate(const m_audio_bitrate_gauge_t *p_gauge)
82 {
83  uint32_t frames;
84  uint32_t bytes;
85 
87  frames = p_gauge->frames;
88  bytes = p_gauge->bytes;
90 
91  if (frames == 0)
92  {
93  return 0;
94  }
95 
96  return (8ull * bytes * CONFIG_AUDIO_REAL_SAMPLING_FREQUENCY) / (1000ull * frames * CONFIG_AUDIO_FRAME_SIZE_SAMPLES);
97 }
98 
99 __STATIC_INLINE uint8_t m_audio_gauge_get_max_bitrate(const m_audio_bitrate_gauge_t *p_gauge)
100 {
101  return p_gauge->max_bitrate;
102 }
103 
104 __STATIC_INLINE uint32_t m_audio_gauge_get_total_count(const m_audio_loss_gauge_t *p_gauge)
105 {
106  return p_gauge->total;
107 }
108 
109 __STATIC_INLINE uint32_t m_audio_gauge_get_lost_count(const m_audio_loss_gauge_t *p_gauge)
110 {
111  return p_gauge->lost;
112 }
113 
114 __STATIC_INLINE uint32_t m_audio_gauge_get_discarded_count(const m_audio_loss_gauge_t *p_gauge)
115 {
116  return p_gauge->discarded;
117 }
118 
119 #if CONFIG_AUDIO_GAUGES_ENABLED
120 
121 void m_audio_cpu_gauge_reset(m_audio_cpu_gauge_t *p_gauge);
122 void m_audio_cpu_gauge_log(const m_audio_cpu_gauge_t *p_gauge, const char *p_prefix);
123 void m_audio_measure_cpu_usage_start(m_audio_cpu_gauge_t *p_gauge);
124 void m_audio_measure_cpu_usage_end(m_audio_cpu_gauge_t *p_gauge);
125 
126 void m_audio_bitrate_gauge_reset(m_audio_bitrate_gauge_t *p_gauge);
127 void m_audio_bitrate_gauge_log(const m_audio_bitrate_gauge_t *p_gauge, const char *p_prefix);
128 void m_audio_measure_bitrate(m_audio_bitrate_gauge_t *p_gauge, unsigned int bytes);
129 
130 void m_audio_loss_gauge_reset(m_audio_loss_gauge_t *p_gauge);
131 void m_audio_loss_gauge_log(const m_audio_loss_gauge_t *p_gauge, const char *p_prefix);
132 void m_audio_count_total(m_audio_loss_gauge_t *p_gauge);
133 void m_audio_count_lost(m_audio_loss_gauge_t *p_gauge);
134 void m_audio_count_discarded(m_audio_loss_gauge_t *p_gauge);
135 
136 #else /* !CONFIG_AUDIO_GAUGES_ENABLED */
137 
138 #define m_audio_cpu_gauge_reset(p_gauge) do { } while (0)
139 #define m_audio_cpu_gauge_log(p_gauge, prefix) do { } while (0)
140 #define m_audio_measure_cpu_usage_start(p_gauge) do { } while (0)
141 #define m_audio_measure_cpu_usage_end(p_gauge) do { } while (0)
142 
143 #define m_audio_bitrate_gauge_reset(p_gauge) do { } while (0)
144 #define m_audio_bitrate_gauge_log(p_gauge, prefix) do { } while (0)
145 #define m_audio_measure_bitrate(p_gauge, bytes) do { } while (0)
146 
147 #define m_audio_loss_gauge_reset(p_gauge) do { } while (0)
148 #define m_audio_loss_gauge_log(p_gauge, prefix) do { } while (0)
149 #define m_audio_count_total(p_gauge) do { } while (0)
150 #define m_audio_count_lost(p_gauge) do { } while (0)
151 #define m_audio_count_discarded(p_gauge) do { } while (0)
152 
153 #endif /* CONFIG_AUDIO_GAUGES_ENABLED */
154 #endif /* __M_AUDIO_GAUGES_H__ */

Documentation feedback | Developer Zone | Subscribe | Updated