UltraGrid
UltraGrid Low-Latency High-Resolution Transmission System
Loading...
Searching...
No Matches
controlport_stats.cpp File Reference
#include <memory>
#include <string_view>
#include "debug.h"
#include "module.h"
#include "control_socket.h"
#include "audio/audio_filter.h"
#include "audio/types.h"
#include "audio/utils.h"
#include "lib_common.h"
Include dependency graph for controlport_stats.cpp:

Go to the source code of this file.

Classes

struct  state_controlport_stats
 

Functions

static af_result_code configure (void *state, int in_bps, int in_ch_count, int in_sample_rate)
 
static void done (void *state)
 
static af_result_code filter (void *state, struct audio_frame **frame)
 
static void get_configured (void *state, int *bps, int *ch_count, int *sample_rate)
 
static af_result_code init (struct module *parent, const char *cfg, void **state)
 
 REGISTER_MODULE (controlport_stats, &audio_filter_controlport_stats, LIBRARY_CLASS_AUDIO_FILTER, AUDIO_FILTER_ABI_VERSION)
 
static void usage ()
 

Variables

static const struct audio_filter_info audio_filter_controlport_stats
 

Detailed Description

Author
Martin Piatka piatk.nosp@m.a@ce.nosp@m.snet..nosp@m.cz

Definition in file controlport_stats.cpp.

Function Documentation

◆ configure()

static af_result_code configure ( void * state,
int in_bps,
int in_ch_count,
int in_sample_rate )
static

Definition at line 88 of file controlport_stats.cpp.

90{
91 auto s = static_cast<state_controlport_stats *>(state);
92
93 s->bps = in_bps;
94 s->ch_count = in_ch_count;
95 s->sample_rate = in_sample_rate;
96
97 return AF_OK;
98}
void ** state
@ AF_OK

References AF_OK, state_controlport_stats::bps, and state.

Referenced by filter().

◆ done()

static void done ( void * state)
static

Definition at line 100 of file controlport_stats.cpp.

100 {
101 auto s = static_cast<state_controlport_stats *>(state);
102
103 delete s;
104}

References state.

◆ filter()

static af_result_code filter ( void * state,
struct audio_frame ** frame )
static

Definition at line 116 of file controlport_stats.cpp.

116 {
117 auto s = static_cast<state_controlport_stats *>(state);
118
119 auto f = *frame;
120
121 if(f->bps != s->bps || f->ch_count != s->ch_count){
122 if(configure(state, f->bps, f->ch_count, f->sample_rate) != AF_OK){
123 return AF_MISCONFIGURED;
124 }
125 }
126
127 if(!control_stats_enabled(s->control))
128 return AF_OK;
129
130 std::string report = "ASEND";
131 for(int i = 0; i < f->ch_count; i++){
132 double rms, peak;
133 rms = calculate_rms(f, i, &peak);
134 double rms_dbfs0 = 20 * log(rms) / log(10);
135 double peak_dbfs0 = 20 * log(peak) / log(10);
136 report += " volrms" + std::to_string(i) + " " + std::to_string(rms_dbfs0);
137 report += " volpeak" + std::to_string(i) + " " + std::to_string(peak_dbfs0);
138 }
139 control_report_stats(s->control, report.c_str());
140
141 return AF_OK;
142}
struct video_frame * frame
@ AF_MISCONFIGURED
bool control_stats_enabled(struct control_state *s)
void control_report_stats(struct control_state *s, const std::string &report_line)
static af_result_code configure(void *state, int in_bps, int in_ch_count, int in_sample_rate)
double calculate_rms(audio_frame2 *frame, int channel, double *peak)
Calculates mean and peak RMS from audio samples.
Definition utils.cpp:150

References AF_MISCONFIGURED, AF_OK, calculate_rms(), configure(), control_report_stats(), control_stats_enabled(), frame, and state.

Here is the call graph for this function:

◆ get_configured()

static void get_configured ( void * state,
int * bps,
int * ch_count,
int * sample_rate )
static

Definition at line 106 of file controlport_stats.cpp.

108{
109 auto s = static_cast<state_controlport_stats *>(state);
110
111 if(bps) *bps = s->bps;
112 if(ch_count) *ch_count = s->ch_count;
113 if(sample_rate) *sample_rate = s->sample_rate;
114}
int int int sample_rate

References state_controlport_stats::bps, sample_rate, and state.

◆ init()

static af_result_code init ( struct module * parent,
const char * cfg,
void ** state )
static

Definition at line 76 of file controlport_stats.cpp.

76 {
77 auto s = std::make_unique<state_controlport_stats>(parent);
78
79 if(strcmp(cfg, "help") == 0){
80 usage();
81 return AF_HELP_SHOWN;
82 }
83
84 *state = s.release();
85 return AF_OK;
86};
@ AF_HELP_SHOWN
static void usage()
const char * parent
Definition settings.cpp:198

References AF_HELP_SHOWN, AF_OK, parent, state, and usage().

Here is the call graph for this function:

◆ REGISTER_MODULE()

REGISTER_MODULE ( controlport_stats ,
& audio_filter_controlport_stats,
LIBRARY_CLASS_AUDIO_FILTER ,
AUDIO_FILTER_ABI_VERSION  )

◆ usage()

static void usage ( void )
static

Definition at line 71 of file controlport_stats.cpp.

71 {
72 printf("controlport_stats:\n");
73 printf("Reporting of audio volume via control port\n");
74}

Referenced by init().

Variable Documentation

◆ audio_filter_controlport_stats

const struct audio_filter_info audio_filter_controlport_stats
static
Initial value:
= {
.name = "controlport_stats",
.init = init,
.done = done,
.configure = configure,
.get_configured_in = get_configured,
.get_configured_out = get_configured,
.filter = filter,
}
static af_result_code filter(void *state, struct audio_frame **frame)
static void get_configured(void *state, int *bps, int *ch_count, int *sample_rate)
static af_result_code init(struct module *parent, const char *cfg, void **state)
static void done(void *state)

Definition at line 144 of file controlport_stats.cpp.

144 {
145 .name = "controlport_stats",
146 .init = init,
147 .done = done,
148 .configure = configure,
149 .get_configured_in = get_configured,
150 .get_configured_out = get_configured,
151 .filter = filter,
152};