From: philippewarren Date: Fri, 25 Feb 2022 19:44:29 +0000 (-0500) Subject: Fixed code review elements X-Git-Url: http://kyz.pub/gitweb/?a=commitdiff_plain;h=fcd067517a4135e8e711b0d1b9c1af1b2837b102;p=yn%2Fyn-odas.git Fixed code review elements --- diff --git a/demo/odaslive/parameters.c b/demo/odaslive/parameters.c index e78eee8..365d04d 100644 --- a/demo/odaslive/parameters.c +++ b/demo/odaslive/parameters.c @@ -141,37 +141,6 @@ } - 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; @@ -290,86 +259,39 @@ 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); - } + unsigned int nChannels = parameters_count(fileConfig, "raw.interface.channelmap"); + pa_channel_map* map = (pa_channel_map*) malloc(sizeof(pa_channel_map)); + pa_channel_map_init(map); + map->channels = 0; - if (channelNamesExists) + char * tmpStr1 = (char *) malloc(sizeof(char) * 1024); + for (unsigned int iChannel = 0; iChannel < nChannels; ++iChannel) { - 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)) + sprintf(tmpStr1, "raw.interface.channelmap.[%u]", iChannel); + char* channel = parameters_lookup_string(fileConfig, tmpStr1); + if (((map->map[iChannel] = pa_channel_position_from_string(channel)) == PA_CHANNEL_POSITION_INVALID)) { - printf("Invalid channel map\n"); + printf("Invalid channel position: %s\n", channel); exit(EXIT_FAILURE); } - - free((void *) tmpStr); - - return map; - + ++(map->channels); + free((void *) channel); } - 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; + free((void *) tmpStr1); - 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 (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; + 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) { diff --git a/src/general/interface.c b/src/general/interface.c index 89ad927..5429929 100644 --- a/src/general/interface.c +++ b/src/general/interface.c @@ -55,7 +55,7 @@ obj->port = 0; // +----------------------------------------------------------+ - // | Soundcard | + // | Soundcard or Pulseaudio | // +----------------------------------------------------------+ obj->deviceName = (char *) NULL; @@ -102,7 +102,7 @@ obj->port = 0; // +----------------------------------------------------------+ - // | Soundcard | + // | Soundcard or Pulseaudio | // +----------------------------------------------------------+ obj->deviceName = (char *) NULL; @@ -150,7 +150,7 @@ obj->port = 0; // +----------------------------------------------------------+ - // | Soundcard | + // | Soundcard or Pulseaudio | // +----------------------------------------------------------+ obj->deviceName = (char *) NULL; @@ -198,7 +198,7 @@ obj->port = port; // +----------------------------------------------------------+ - // | Soundcard | + // | Soundcard or Pulseaudio | // +----------------------------------------------------------+ obj->deviceName = (char *) NULL; @@ -245,7 +245,7 @@ obj->port = 0; // +----------------------------------------------------------+ - // | Soundcard | + // | Soundcard or Pulseaudio | // +----------------------------------------------------------+ obj->deviceName = (char *) malloc(sizeof(char) * (strlen(sourceName)+1)); @@ -263,59 +263,63 @@ interface_obj * interface_construct_soundcard(const unsigned int card, const unsigned int device) { - char * deviceName = (char *) malloc(sizeof(char) * 1024); + char * deviceName = (char *) malloc(sizeof(char) * 1024); - sprintf(deviceName, "hw:%u,%u", card, device); + sprintf(deviceName, "hw:%u,%u", card, device); - return interface_construct_soundcard_by_name(deviceName); + interface_obj * obj = interface_construct_soundcard_by_name(deviceName); + + free((void* ) deviceName); + + return obj; } interface_obj * interface_construct_soundcard_by_name(char * deviceName) { - interface_obj * obj; + interface_obj * obj; - obj = (interface_obj *) malloc(sizeof(interface_obj)); + obj = (interface_obj *) malloc(sizeof(interface_obj)); - // +----------------------------------------------------------+ - // | Type | - // +----------------------------------------------------------+ + // +----------------------------------------------------------+ + // | Type | + // +----------------------------------------------------------+ - obj->type = interface_soundcard; + obj->type = interface_soundcard; - // +----------------------------------------------------------+ - // | Blackhole | - // +----------------------------------------------------------+ + // +----------------------------------------------------------+ + // | Blackhole | + // +----------------------------------------------------------+ - // (Empty) + // (Empty) - // +----------------------------------------------------------+ - // | File | - // +----------------------------------------------------------+ + // +----------------------------------------------------------+ + // | File | + // +----------------------------------------------------------+ - obj->fileName = (char *) NULL; + obj->fileName = (char *) NULL; - // +----------------------------------------------------------+ - // | Socket | - // +----------------------------------------------------------+ + // +----------------------------------------------------------+ + // | Socket | + // +----------------------------------------------------------+ - obj->ip = (char *) NULL; - obj->port = 0; + obj->ip = (char *) NULL; + obj->port = 0; - // +----------------------------------------------------------+ - // | Soundcard | - // +----------------------------------------------------------+ + // +----------------------------------------------------------+ + // | Soundcard or Pulseaudio | + // +----------------------------------------------------------+ obj->deviceName = (char *) malloc(sizeof(char) * (strlen(deviceName)+1)); strcpy(obj->deviceName, deviceName); - // +----------------------------------------------------------+ - // | Terminal | - // +----------------------------------------------------------+ + // +----------------------------------------------------------+ + // | Terminal | + // +----------------------------------------------------------+ - // (Empty) + // (Empty) - return obj; + return obj; } @@ -351,7 +355,7 @@ obj->port = 0; // +----------------------------------------------------------+ - // | Soundcard | + // | Soundcard or Pulseaudio | // +----------------------------------------------------------+ obj->deviceName = (char *) NULL; @@ -408,22 +412,16 @@ } // +----------------------------------------------------------+ - // | Soundcard | + // | Soundcard or Pulseaudio | // +----------------------------------------------------------+ - if (obj->type == interface_soundcard) { - clone->deviceName = obj->deviceName; - } - - // +----------------------------------------------------------+ - // | Pulseaudio | - // +----------------------------------------------------------+ + if (obj->type == interface_soundcard || obj->type == interface_pulseaudio) { + + clone->deviceName = (char *) malloc(sizeof(char) * (strlen(obj->deviceName) + 1)); + strcpy(clone->deviceName, obj->deviceName); - if (obj->type == interface_pulseaudio) { - clone->deviceName = obj->deviceName; } - // +----------------------------------------------------------+ // | Terminal | // +----------------------------------------------------------+ @@ -442,13 +440,11 @@ } - /* Will propably be freed somewhere else. Which is a bit ugly. if (obj->deviceName != NULL) { free((void *) obj->deviceName); } - */ if (obj->ip != NULL) { diff --git a/src/source/src_hops.c b/src/source/src_hops.c index 5fa51e8..784cd4d 100644 --- a/src/source/src_hops.c +++ b/src/source/src_hops.c @@ -43,14 +43,11 @@ // Will not be null if in pulseaudio mode memcpy(&obj->cm, src_hops_config->channel_map, sizeof(pa_channel_map)); } - else + else if (obj->interface->type == interface_pulseaudio) { - // 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); - } + // Can't be null if we are in pulseaudio mode + printf("Error: Pulseaudio interface requires channel map.\n"); + exit(EXIT_FAILURE); } memset(obj->bytes, 0x00, 4 * sizeof(char));