From: philippewarren Date: Tue, 1 Feb 2022 19:17:42 +0000 (-0500) Subject: Added pulseaudio support from rendezvous X-Git-Url: http://kyz.pub/gitweb/?a=commitdiff_plain;h=7183c89d00e3b69b9fc13ca7b78ce874756c5428;p=yn%2Fyn-odas.git Added pulseaudio support from rendezvous --- diff --git a/CMakeLists.txt b/CMakeLists.txt index 9a2ac3c..dd0a7f6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -12,10 +12,10 @@ pkg_check_modules(PC_LIBCONFIG REQUIRED libconfig) include_directories("${PROJECT_SOURCE_DIR}/include") -set(CMAKE_BUILD_TYPE "Release") - -set(EXECUTABLE_OUTPUT_PATH "${PROJECT_SOURCE_DIR}/bin") -set(LIBRARY_OUTPUT_PATH "${PROJECT_SOURCE_DIR}/lib") +# Compile in release mode if not set +if(NOT CMAKE_BUILD_TYPE) + SET(CMAKE_BUILD_TYPE "Release") +endif(NOT CMAKE_BUILD_TYPE) #Add base directory for includes (global) include_directories(include/odas) @@ -193,6 +193,8 @@ target_link_libraries(odas ${PC_FFTW3_LIBRARIES} ${PC_ALSA_LIBRARIES} ${PC_LIBCONFIG_LIBRARIES} + pulse + pulse-simple m pthread ) @@ -217,5 +219,3 @@ target_link_libraries(odasserver ) install(TARGETS odas DESTINATION lib) - - diff --git a/demo/odaslive/parameters.c b/demo/odaslive/parameters.c index eb0777a..bc4ad32 100644 --- a/demo/odaslive/parameters.c +++ b/demo/odaslive/parameters.c @@ -204,6 +204,13 @@ cfg->interface = interface_construct_soundcard_by_name(tmpStr2); + } + else if (strcmp(tmpStr1, "pulseaudio") == 0) { + + tmpStr2 = parameters_lookup_string(fileConfig, "raw.interface.source"); + + cfg->interface = interface_construct_pulseaudio(tmpStr2); + } else { printf("raw.interface.type: Invalid type\n"); diff --git a/include/odas/general/interface.h b/include/odas/general/interface.h index 349ca1e..58c71fe 100644 --- a/include/odas/general/interface.h +++ b/include/odas/general/interface.h @@ -35,6 +35,7 @@ interface_socket = 3, interface_soundcard = 4, interface_terminal = 5, + interface_pulseaudio = 6 } interface_type; @@ -59,6 +60,8 @@ interface_obj * interface_construct_socket(const char * ip, const unsigned int port); + interface_obj * interface_construct_pulseaudio(const char * sourceName); + interface_obj * interface_construct_soundcard(const unsigned int card, const unsigned int device); interface_obj * interface_construct_soundcard_by_name(char * deviceName); diff --git a/include/odas/source/src_hops.h b/include/odas/source/src_hops.h index b0a32b9..8856bb9 100644 --- a/include/odas/source/src_hops.h +++ b/include/odas/source/src_hops.h @@ -27,6 +27,8 @@ #include #include #include + #include + #include #include "../general/format.h" #include "../general/interface.h" @@ -47,6 +49,8 @@ FILE * fp; snd_pcm_t * ch; + pa_simple * pa; + pa_sample_spec ss; char * buffer; unsigned int bufferSize; @@ -78,18 +82,24 @@ void src_hops_open_interface_soundcard(src_hops_obj * obj); + void src_hops_open_interface_pulseaudio(src_hops_obj * obj); + void src_hops_close(src_hops_obj * obj); void src_hops_close_interface_file(src_hops_obj * obj); void src_hops_close_interface_soundcard(src_hops_obj * obj); + void src_hops_close_interface_pulseaudio(src_hops_obj * obj); + int src_hops_process(src_hops_obj * obj); int src_hops_process_interface_file(src_hops_obj * obj); int src_hops_process_interface_soundcard(src_hops_obj * obj); + int src_hops_process_interface_pulseaudio(src_hops_obj * obj); + void src_hops_process_format_binary_int08(src_hops_obj * obj); void src_hops_process_format_binary_int16(src_hops_obj * obj); diff --git a/src/general/interface.c b/src/general/interface.c index c01a628..02e07a5 100644 --- a/src/general/interface.c +++ b/src/general/interface.c @@ -213,6 +213,54 @@ } + interface_obj * interface_construct_pulseaudio(const char * sourceName) { + + interface_obj * obj; + + obj = (interface_obj *) malloc(sizeof(interface_obj)); + + // +----------------------------------------------------------+ + // | Type | + // +----------------------------------------------------------+ + + obj->type = interface_pulseaudio; + + // +----------------------------------------------------------+ + // | Blackhole | + // +----------------------------------------------------------+ + + // (Empty) + + // +----------------------------------------------------------+ + // | File | + // +----------------------------------------------------------+ + + obj->fileName = (char *) NULL; + + // +----------------------------------------------------------+ + // | Socket | + // +----------------------------------------------------------+ + + obj->ip = (char *) NULL; + obj->port = 0; + + // +----------------------------------------------------------+ + // | Soundcard | + // +----------------------------------------------------------+ + + obj->deviceName = (char *) malloc(sizeof(char) * (strlen(sourceName)+1)); + strcpy(obj->deviceName, sourceName); + + // +----------------------------------------------------------+ + // | Terminal | + // +----------------------------------------------------------+ + + // (Empty) + + return obj; + + } + interface_obj * interface_construct_soundcard(const unsigned int card, const unsigned int device) { char * deviceName = (char *) malloc(sizeof(char) * 1024); @@ -366,6 +414,15 @@ clone->deviceName = obj->deviceName; } + // +----------------------------------------------------------+ + // | Pulseaudio | + // +----------------------------------------------------------+ + + if (obj->type == interface_pulseaudio) { + clone->deviceName = obj->deviceName; + } + + // +----------------------------------------------------------+ // | Terminal | // +----------------------------------------------------------+ @@ -432,6 +489,12 @@ break; + case interface_pulseaudio: + + printf("type = pulseaudio, devicename = %s\n", obj->deviceName); + + break; + case interface_terminal: printf("type = terminal\n"); diff --git a/src/source/src_hops.c b/src/source/src_hops.c index 8c2081f..96ec097 100644 --- a/src/source/src_hops.c +++ b/src/source/src_hops.c @@ -48,7 +48,11 @@ ((obj->interface->type == interface_soundcard) && (obj->format->type == format_binary_int08)) || ((obj->interface->type == interface_soundcard) && (obj->format->type == format_binary_int16)) || ((obj->interface->type == interface_soundcard) && (obj->format->type == format_binary_int24)) || - ((obj->interface->type == interface_soundcard) && (obj->format->type == format_binary_int32)))) { + ((obj->interface->type == interface_soundcard) && (obj->format->type == format_binary_int32)) || + ((obj->interface->type == interface_pulseaudio) && (obj->format->type == format_binary_int08)) || + ((obj->interface->type == interface_pulseaudio) && (obj->format->type == format_binary_int16)) || + ((obj->interface->type == interface_pulseaudio) && (obj->format->type == format_binary_int24)) || + ((obj->interface->type == interface_pulseaudio) && (obj->format->type == format_binary_int32)))) { printf("Source hops: Invalid interface and/or format.\n"); exit(EXIT_FAILURE); @@ -111,6 +115,12 @@ break; + case interface_pulseaudio: + + src_hops_open_interface_pulseaudio(obj); + + break; + default: printf("Source hops: Invalid interface type.\n"); @@ -133,6 +143,57 @@ } + void src_hops_open_interface_pulseaudio(src_hops_obj * obj) { + + pa_sample_format_t format; + + switch (obj->format->type) { + + case format_binary_int08: + + format = PA_SAMPLE_U8; + + break; + + case format_binary_int16: + + format = PA_SAMPLE_S16LE; + + break; + + case format_binary_int24: + + format = PA_SAMPLE_S24LE; + + break; + + case format_binary_int32: + + format = PA_SAMPLE_S32LE; + + break; + + default: + + printf("Source hops: Invalid format.\n"); + exit(EXIT_FAILURE); + + break; + + } + + obj->ss.format = format; + obj->ss.rate = obj->fS; + 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))) { + printf("Source hops: Cannot open pulseaudio device %s: %s\n", obj->interface->deviceName, pa_strerror(err)); + exit(EXIT_FAILURE); + } + + } + void src_hops_open_interface_soundcard(src_hops_obj * obj) { snd_pcm_hw_params_t * hw_params; @@ -240,6 +301,12 @@ break; + case interface_pulseaudio: + + src_hops_close_interface_pulseaudio(obj); + + break; + default: printf("Source hops: Invalid interface type.\n"); @@ -263,6 +330,13 @@ } + void src_hops_close_interface_pulseaudio(src_hops_obj * obj) { + + if (obj->pa != NULL) + pa_simple_free(obj->pa); + + } + int src_hops_process(src_hops_obj * obj) { int rtnValue; @@ -316,6 +390,12 @@ break; + case interface_pulseaudio: + + rtnValue = src_hops_process_interface_pulseaudio(obj); + + break; + default: printf("Source hops: Invalid interface type.\n"); @@ -375,6 +455,26 @@ } + int src_hops_process_interface_pulseaudio(src_hops_obj * obj) { + + int rtnValue; + int err; + + if (pa_simple_read(obj->pa, obj->buffer, obj->bufferSize, &err) < 0) { + + rtnValue = -1; + + } + else { + + rtnValue = 0; + + } + + return rtnValue; + + } + void src_hops_process_format_binary_int08(src_hops_obj * obj) { unsigned int iSample;