diff --git a/configure.ac b/configure.ac index 8b140adb0..4a9103a1c 100644 --- a/configure.ac +++ b/configure.ac @@ -2345,8 +2345,8 @@ fi if test $portaudio = yes then - PORTAUDIO_CAP_OBJ="src/audio/capture/portaudio.o" - PORTAUDIO_PLAY_OBJ="src/audio/playback/portaudio.o" + PORTAUDIO_CAP_OBJ="src/audio/portaudio_common.o src/audio/capture/portaudio.o" + PORTAUDIO_PLAY_OBJ="src/audio/portaudio_common.o src/audio/playback/portaudio.o" AC_DEFINE([HAVE_PORTAUDIO], [1], [Build with Portaudio support]) ADD_MODULE("acap_portaudio", "$PORTAUDIO_CAP_OBJ", "$PORTAUDIO_LIB") ADD_MODULE("aplay_portaudio", "$PORTAUDIO_PLAY_OBJ", "$PORTAUDIO_LIB") diff --git a/src/audio/capture/portaudio.c b/src/audio/capture/portaudio.c index 250d1faab..f9eef5ca9 100644 --- a/src/audio/capture/portaudio.c +++ b/src/audio/capture/portaudio.c @@ -62,7 +62,7 @@ #include "audio/audio.h" #include "audio/audio_capture.h" -#include "portaudio.h" +#include "audio/portaudio_common.h" #include "debug.h" #include "host.h" #include "lib_common.h" @@ -128,7 +128,7 @@ static void print_device_info(PaDeviceIndex device) } const PaDeviceInfo *device_info = Pa_GetDeviceInfo(device); - printf(" %s (output channels: %d; input channels: %d)", device_info->name, device_info->maxOutputChannels, device_info->maxInputChannels); + printf(" %s (output channels: %d; input channels: %d; %s)", device_info->name, device_info->maxOutputChannels, device_info->maxInputChannels, portaudio_get_api_name(device)); } static void audio_cap_portaudio_probe(struct device_info **available_devices, int *count) diff --git a/src/audio/playback/portaudio.cpp b/src/audio/playback/portaudio.cpp index 60c95cdfe..187ebe6a5 100644 --- a/src/audio/playback/portaudio.cpp +++ b/src/audio/playback/portaudio.cpp @@ -63,6 +63,7 @@ #include "audio/audio.h" #include "audio/audio_playback.h" +#include "audio/portaudio_common.h" #include "debug.h" #include "lib_common.h" #include "utils/audio_buffer.h" @@ -128,7 +129,6 @@ static bool portaudio_start_stream(PaStream *stream) return true; } - static void print_device_info(PaDeviceIndex device) { if( (device < 0) || (device >= Pa_GetDeviceCount()) ) @@ -138,7 +138,7 @@ static void print_device_info(PaDeviceIndex device) } const PaDeviceInfo *device_info = Pa_GetDeviceInfo(device); - printf(" %s (output channels: %d; input channels: %d)", device_info->name, device_info->maxOutputChannels, device_info->maxInputChannels); + printf(" %s (output channels: %d; input channels: %d; %s)", device_info->name, device_info->maxOutputChannels, device_info->maxInputChannels, portaudio_get_api_name(device)); } static void audio_play_portaudio_probe(struct device_info **available_devices, int *count) diff --git a/src/audio/portaudio_common.c b/src/audio/portaudio_common.c new file mode 100644 index 000000000..4bf34159c --- /dev/null +++ b/src/audio/portaudio_common.c @@ -0,0 +1,60 @@ +/** + * @file audio/portaudio_common.c + * @author Martin Pulec + */ +/* + * Copyright (c) 2018 CESNET, z. s. p. o. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, is permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * 3. Neither the name of CESNET nor the names of its contributors may be + * used to endorse or promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, + * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY + * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO + * EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#include "config_unix.h" +#include "config_win32.h" +#endif + +#include + +#include "portaudio_common.h" + +const char *portaudio_get_api_name(PaDeviceIndex device) { + for (int i = 0; i < Pa_GetHostApiCount(); ++i) { + const PaHostApiInfo *info = Pa_GetHostApiInfo(i); + for (int j = 0; j < info->deviceCount; ++j) { + if (device == Pa_HostApiDeviceIndexToDeviceIndex(i, j)) { + return info->name; + } + } + + } + return "(unknown API)"; +} + diff --git a/src/audio/portaudio_common.h b/src/audio/portaudio_common.h new file mode 100644 index 000000000..44372b764 --- /dev/null +++ b/src/audio/portaudio_common.h @@ -0,0 +1,52 @@ +/** + * @file audio/portaudio_common.h + * @author Martin Pulec + */ +/* + * Copyright (c) 2018 CESNET, z. s. p. o. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, is permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * 3. Neither the name of CESNET nor the names of its contributors may be + * used to endorse or promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, + * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY + * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO + * EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef UTILS_PORTAUDIO_H_ +#define UTILS_PORTAUDIO_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +const char *portaudio_get_api_name(PaDeviceIndex device); + +#ifdef __cplusplus +} +#endif + +#endif // defined UTILS_PORTAUDIO_H_ +