3 #ifndef __M_AUDIO_GAUGES_H__
4 #define __M_AUDIO_GAUGES_H__
8 #include "nrf_atomic.h"
9 #include "app_util_platform.h"
10 #include "sr3_config.h"
17 uint8_t min_cpu_usage;
18 uint8_t cur_cpu_usage;
19 uint8_t max_cpu_usage;
20 } m_audio_cpu_gauge_t;
29 } m_audio_bitrate_gauge_t;
33 nrf_atomic_u32_t total;
34 nrf_atomic_u32_t lost;
35 nrf_atomic_u32_t discarded;
36 } m_audio_loss_gauge_t;
38 __STATIC_INLINE uint8_t m_audio_gauge_get_cur_cpu_usage(
const m_audio_cpu_gauge_t *p_gauge)
40 return p_gauge->cur_cpu_usage;
43 __STATIC_INLINE uint8_t m_audio_gauge_get_min_cpu_usage(
const m_audio_cpu_gauge_t *p_gauge)
45 return p_gauge->min_cpu_usage;
48 __STATIC_INLINE uint8_t m_audio_gauge_get_avg_cpu_usage(
const m_audio_cpu_gauge_t *p_gauge)
54 total_time = p_gauge->total_time;
55 cpu_time = p_gauge->cpu_time;
63 return 100ull * cpu_time / total_time;
66 __STATIC_INLINE uint8_t m_audio_gauge_get_max_cpu_usage(
const m_audio_cpu_gauge_t *p_gauge)
68 return p_gauge->max_cpu_usage;
71 __STATIC_INLINE uint8_t m_audio_gauge_get_cur_bitrate(
const m_audio_bitrate_gauge_t *p_gauge)
73 return p_gauge->cur_bitrate;
76 __STATIC_INLINE uint8_t m_audio_gauge_get_min_bitrate(
const m_audio_bitrate_gauge_t *p_gauge)
78 return p_gauge->min_bitrate;
81 __STATIC_INLINE uint8_t m_audio_gauge_get_avg_bitrate(
const m_audio_bitrate_gauge_t *p_gauge)
87 frames = p_gauge->frames;
88 bytes = p_gauge->bytes;
96 return (8ull * bytes * CONFIG_AUDIO_REAL_SAMPLING_FREQUENCY) / (1000ull * frames * CONFIG_AUDIO_FRAME_SIZE_SAMPLES);
99 __STATIC_INLINE uint8_t m_audio_gauge_get_max_bitrate(
const m_audio_bitrate_gauge_t *p_gauge)
101 return p_gauge->max_bitrate;
104 __STATIC_INLINE uint32_t m_audio_gauge_get_total_count(
const m_audio_loss_gauge_t *p_gauge)
106 return p_gauge->total;
109 __STATIC_INLINE uint32_t m_audio_gauge_get_lost_count(
const m_audio_loss_gauge_t *p_gauge)
111 return p_gauge->lost;
114 __STATIC_INLINE uint32_t m_audio_gauge_get_discarded_count(
const m_audio_loss_gauge_t *p_gauge)
116 return p_gauge->discarded;
119 #if CONFIG_AUDIO_GAUGES_ENABLED
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);
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);
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);
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)
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)
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)