}
+ bool parameters_exists(const char * file, const char * path)
+ {
+ config_t cfg;
+ unsigned int rtnValue;
+
+ config_init(&cfg);
+
+ if(!config_read_file(&cfg, file))
+ {
+
+ printf("%s:%d - %s\n", config_error_file(&cfg), config_error_line(&cfg), config_error_text(&cfg));
+ config_destroy(&cfg);
+
+ exit(EXIT_FAILURE);
+
+ }
+
+ if (config_lookup(&cfg, path) == NULL)
+ {
+ rtnValue = false;
+ }
+ else
+ {
+ rtnValue = true;
+ }
+
+ config_destroy(&cfg);
+
+ return rtnValue;
+ }
+
src_hops_cfg * parameters_src_hops_mics_config(const char * fileConfig) {
src_hops_cfg * cfg;
unsigned int tmpInt2;
cfg = src_hops_cfg_construct();
+ cfg->channel_map = NULL; // Only used in pulseaudio mode
// +----------------------------------------------------------+
// | Format |
cfg->interface = interface_construct_soundcard_by_name(tmpStr2);
+ free((void *) tmpStr2);
+
}
else if (strcmp(tmpStr1, "pulseaudio") == 0) {
tmpStr2 = parameters_lookup_string(fileConfig, "raw.interface.source");
cfg->interface = interface_construct_pulseaudio(tmpStr2);
+ cfg->channel_map = parameters_pa_channel_map_config(fileConfig);
+
+ free((void *) tmpStr2);
}
else {
}
+ pa_channel_map* parameters_pa_channel_map_config(const char* fileConfig)
+ {
+ bool channelNamesExists = parameters_exists(fileConfig, "raw.interface.channelnames");
+ bool channelMapExists = parameters_exists(fileConfig, "raw.interface.channelmap");
+ if (channelNamesExists && channelMapExists)
+ {
+ printf("Configuration error: raw.interface.channelnames and raw.interface.channelmap cannot be used at the same time\n");
+ exit(EXIT_FAILURE);
+ }
+ else if (!(channelNamesExists || channelMapExists))
+ {
+ printf("Configuration error: either raw.interface.channelnames or raw.interface.channelmap must be used with pulseaudio\n");
+ exit(EXIT_FAILURE);
+ }
+
+ if (channelNamesExists)
+ {
+ char * tmpStr;
+ pa_channel_map* map = (pa_channel_map*) malloc(sizeof(pa_channel_map));
+ pa_channel_map_init(map);
+ map->channels = parameters_lookup_int(fileConfig, "raw.nChannels");
+
+ tmpStr = parameters_lookup_string(fileConfig, "raw.interface.channelnames");
+
+ if (!pa_channel_map_parse(map, tmpStr))
+ {
+ printf("Invalid channel map string: %s\n", tmpStr);
+ exit(EXIT_FAILURE);
+ }
+
+ if (map->channels != parameters_lookup_int(fileConfig, "raw.nChannels"))
+ {
+ printf("Configuration error: raw.interface.channelnames length does not match raw.nChannels\n");
+ exit(EXIT_FAILURE);
+ }
+
+ if (!pa_channel_map_valid(map))
+ {
+ printf("Invalid channel map\n");
+ exit(EXIT_FAILURE);
+ }
+
+ free((void *) tmpStr);
+
+ return map;
+
+ }
+ else
+ {
+ unsigned int nChannels = parameters_count(fileConfig, "raw.interface.channelmap");
+ char tmpStr[1024];
+ pa_channel_map* map = (pa_channel_map*) malloc(sizeof(pa_channel_map));
+ pa_channel_map_init(map);
+ map->channels = 0;
+
+ for (unsigned int iChannel = 0; iChannel < nChannels; ++iChannel)
+ {
+ sprintf(tmpStr, "raw.interface.channelmap.[%u]", iChannel);
+ char* channel = parameters_lookup_string(fileConfig, tmpStr);
+ if (((map->map[iChannel] = pa_channel_position_from_string(channel)) == PA_CHANNEL_POSITION_INVALID))
+ {
+ printf("Invalid channel position: %s\n", channel);
+ exit(EXIT_FAILURE);
+ }
+ ++(map->channels);
+ free(channel);
+ }
+
+ if (map->channels != parameters_lookup_int(fileConfig, "raw.nChannels"))
+ {
+ printf("Configuration error: raw.interface.channelmap length does not match raw.nChannels\n");
+ exit(EXIT_FAILURE);
+ }
+
+ if (!pa_channel_map_valid(map))
+ {
+ printf("Invalid channel map\n");
+ exit(EXIT_FAILURE);
+ }
+
+ return map;
+ }
+ }
mod_mapping_cfg * parameters_mod_mapping_mics_config(const char * fileConfig) {
return cfg;
- }
\ No newline at end of file
+ }
obj->format = format_clone(src_hops_config->format);
obj->interface = interface_clone(src_hops_config->interface);
+ if (src_hops_config->channel_map != NULL)
+ {
+ // Will not be null if in pulseaudio mode
+ memcpy(&obj->cm, src_hops_config->channel_map, sizeof(pa_channel_map));
+ }
+ else
+ {
+ // Can be null if not in pulseaudio mode ONLY
+ if (obj->interface->type == interface_pulseaudio)
+ {
+ printf("Error: Pulseaudio interface requires channel map.\n");
+ exit(EXIT_FAILURE);
+ }
+ }
memset(obj->bytes, 0x00, 4 * sizeof(char));
obj->ss.channels = obj->nChannels;
int err;
- if (!(obj->pa = pa_simple_new(NULL, "Odas", PA_STREAM_RECORD, obj->interface->deviceName, "record", &obj->ss, NULL, NULL, &err))) {
+ if (!(obj->pa = pa_simple_new(NULL, "Odas", PA_STREAM_RECORD, obj->interface->deviceName, "record", &obj->ss, &obj->cm, NULL, &err))) {
printf("Source hops: Cannot open pulseaudio device %s: %s\n", obj->interface->deviceName, pa_strerror(err));
exit(EXIT_FAILURE);
}
printf("Source hops: Invalid interface type.\n");
exit(EXIT_FAILURE);
- break;
+ break;
}
if (src_hops_config->interface != NULL) {
interface_destroy(src_hops_config->interface);
}
+ if (src_hops_config->channel_map != NULL) {
+ free((void *) src_hops_config->channel_map);
+ }
free((void *) src_hops_config);