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

Go to the source code of this file.

Classes

struct  state_channel_remap
 

Macros

#define MOD_NAME   "[Remap filter] "
 

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_in (void *state, int *bps, int *ch_count, int *sample_rate)
 
static void get_configured_out (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 (channel_remap, &audio_filter_channel_remap, LIBRARY_CLASS_AUDIO_FILTER, AUDIO_FILTER_ABI_VERSION)
 
static void usage ()
 

Variables

static const struct audio_filter_info audio_filter_channel_remap
 

Detailed Description

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

Definition in file channel_remap.cpp.

Macro Definition Documentation

◆ MOD_NAME

#define MOD_NAME   "[Remap filter] "

Definition at line 56 of file channel_remap.cpp.

Referenced by configure().

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 104 of file channel_remap.cpp.

106{
107 auto s = static_cast<state_channel_remap *>(state);
108
109 s->bps = in_bps;
110 s->ch_count = in_ch_count;
111 s->sample_rate = in_sample_rate;
112
113 s->out_frame.bps = s->bps;
114 s->out_frame.sample_rate = s->sample_rate;
115
116 if(s->channel_map.size > in_ch_count){
117 log_msg(LOG_LEVEL_WARNING, MOD_NAME "Audio channel map references channels with idx higher than ch. count!\n");
118 }
119
120 return AF_OK;
121}
void ** state
@ AF_OK
#define MOD_NAME
void log_msg(int level, const char *format,...)
Definition debug.cpp:130
#define LOG_LEVEL_WARNING
less severe errors
Definition debug.h:60

References AF_OK, state_channel_remap::bps, LOG_LEVEL_WARNING, log_msg(), MOD_NAME, and state.

Referenced by filter().

Here is the call graph for this function:

◆ done()

static void done ( void * state)
static

Definition at line 123 of file channel_remap.cpp.

123 {
124 auto s = static_cast<state_channel_remap *>(state);
125
126 delete s;
127}

References state.

Referenced by rm_singleton().

◆ filter()

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

Definition at line 149 of file channel_remap.cpp.

149 {
150 auto s = static_cast<state_channel_remap *>(state);
151 auto f = *frame;
152
153 if(f->bps != s->bps || f->ch_count != s->ch_count){
154 if(configure(state, f->bps, f->ch_count, f->sample_rate) != AF_OK){
155 return AF_MISCONFIGURED;
156 }
157 }
158
159 int frame_count = f->data_len / f->ch_count / f->bps;
160
161 s->out_frame.ch_count = s->channel_map.max_output + 1;
162 s->out_frame.data_len = frame_count * s->out_frame.bps * s->out_frame.ch_count;
163 if(s->out_frame.data_len > s->out_frame.max_size){
164 s->out_frame.max_size = s->out_frame.data_len;
165 s->out_buffer.resize(s->out_frame.max_size);
166 s->out_frame.data = s->out_buffer.data();
167 }
168
169 memset(s->out_frame.data, 0, s->out_frame.data_len);
170
171 int max_src_count = std::min(s->channel_map.size, f->ch_count);
172
173 for(int src_ch = 0; src_ch < max_src_count; src_ch++){
174 for(int dst_ch = 0; dst_ch < s->channel_map.sizes[src_ch]; dst_ch++){
175 remux_and_mix_channel(s->out_frame.data, f->data,
176 s->bps, frame_count,
177 f->ch_count, s->out_frame.ch_count,
178 src_ch, s->channel_map.map[src_ch][dst_ch], 1.0);
179 }
180 }
181
182 s->out_frame.timestamp = f->timestamp;
183
184 *frame = &s->out_frame;
185
186 return AF_OK;
187}
struct video_frame * frame
@ AF_MISCONFIGURED
static af_result_code configure(void *state, int in_bps, int in_ch_count, int in_sample_rate)
void remux_and_mix_channel(char *out, const char *in, int bps, int frames, int in_stream_channels, int out_stream_channels, int in_channel, int out_channel, double scale)
Definition utils.cpp:423

References AF_MISCONFIGURED, AF_OK, configure(), frame, remux_and_mix_channel(), and state.

Referenced by audio_filter_init(), and FindUnconnectedPin().

Here is the call graph for this function:

◆ get_configured_in()

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

Definition at line 129 of file channel_remap.cpp.

131{
132 auto s = static_cast<state_channel_remap *>(state);
133
134 if(bps) *bps = s->bps;
135 if(ch_count) *ch_count = s->ch_count;
136 if(sample_rate) *sample_rate = s->sample_rate;
137}
int int int sample_rate

References audio_frame::bps, state_channel_remap::bps, audio_frame::ch_count, sample_rate, and state.

◆ get_configured_out()

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

Definition at line 139 of file channel_remap.cpp.

141{
142 auto s = static_cast<state_channel_remap *>(state);
143
144 if(bps) *bps = s->bps;
145 if(ch_count) *ch_count = s->channel_map.max_output + 1;
146 if(sample_rate) *sample_rate = s->sample_rate;
147}

References audio_frame::bps, state_channel_remap::bps, audio_frame::ch_count, sample_rate, and state.

◆ init()

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

Definition at line 85 of file channel_remap.cpp.

85 {
86 auto s = std::make_unique<state_channel_remap>(parent);
87
88 if(strcmp(cfg, "help") == 0){
89 usage();
90 return AF_HELP_SHOWN;
91 }
92
93 if(!parse_channel_map_cfg(&s->channel_map, cfg)){
94 return AF_FAILURE;
95 }
96
97 assert(s->channel_map.size > 0);
98
99 *state = s.release();
100
101 return AF_OK;
102};
@ AF_FAILURE
@ AF_HELP_SHOWN
static void usage()
const char * parent
Definition settings.cpp:198
bool parse_channel_map_cfg(struct channel_map *channel_map, const char *cfg)
Definition utils.cpp:716

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

Referenced by common_cleanup(), common_preinit(), main(), main(), ref_count_init_once< T >::operator()(), and start_nat_traverse().

Here is the call graph for this function:

◆ REGISTER_MODULE()

REGISTER_MODULE ( channel_remap ,
& audio_filter_channel_remap,
LIBRARY_CLASS_AUDIO_FILTER ,
AUDIO_FILTER_ABI_VERSION  )

◆ usage()

static void usage ( void )
static

Definition at line 73 of file channel_remap.cpp.

73 {
74 color_printf("Audio filter " TBOLD(
75 "channel_remap") " allows remapping audio channels.\n\n");
76 color_printf("Usage:\n");
77 color_printf("\t" TBOLD("--audio-filter channel_remap:[<src_ch>]:<dst_ch>[,[<src_ch>]:<dst_ch>]...\n\n"));
78 color_printf("(indexed from zero)\n");
79 color_printf("Maps source channels into destination channels.\n");
80 color_printf("If multiple source channels are mapped into the same destination channel, they are mixed together.\n");
81 color_printf("E.g. 0:0,1:0 means that the first and second channel are mixed to produce a single mono channel.\n");
82 color_printf("2:0,3:1 means that the third and fourth channel are mapped into first and second channel respectively.\n");
83}
int color_printf(const char *format,...)
#define TBOLD(x)
Definition color_out.h:70

References color_printf(), and TBOLD.

Referenced by init().

Here is the call graph for this function:

Variable Documentation

◆ audio_filter_channel_remap

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

Definition at line 189 of file channel_remap.cpp.

189 {
190 .name = "channel_remap",
191 .init = init,
192 .done = done,
193 .configure = configure,
194 .get_configured_in = get_configured_in,
195 .get_configured_out = get_configured_out,
196 .filter = filter,
197};