summaryrefslogtreecommitdiff
path: root/RtAudio.cpp
diff options
context:
space:
mode:
authorgaryscavone <garyscavone@users.noreply.github.com>2022-07-01 11:47:35 -0400
committergaryscavone <garyscavone@users.noreply.github.com>2022-07-01 11:47:35 -0400
commit00d2db5f6fa4818aee75d11b019603f0f3b20cde (patch)
tree9f17925d6a960e513a7c3ed51cc4d61c520c8761 /RtAudio.cpp
parent3448ed36b773ff638cc90cf87cb77d0fb8ecf7d9 (diff)
parent7ee4cdedd065272f0d6dc87074cd44d9e53136c1 (diff)
Resolved merge conflicts with master.
Diffstat (limited to 'RtAudio.cpp')
-rw-r--r--RtAudio.cpp33
1 files changed, 24 insertions, 9 deletions
diff --git a/RtAudio.cpp b/RtAudio.cpp
index b11a1d2..c1a1ca7 100644
--- a/RtAudio.cpp
+++ b/RtAudio.cpp
@@ -120,6 +120,22 @@ const char* rtaudio_api_names[][2] = {
const unsigned int rtaudio_num_api_names =
sizeof(rtaudio_api_names)/sizeof(rtaudio_api_names[0]);
+#if defined(__UNIX_JACK__)
+std::string escapeJackPortRegex(std::string &str)
+{
+ const std::string need_escaping = "()[]{}*+?$^.|\\";
+ std::string escaped_string;
+ for (auto c : str)
+ {
+ if (need_escaping.find(c) != std::string::npos)
+ escaped_string.push_back('\\');
+
+ escaped_string.push_back(c);
+ }
+ return escaped_string;
+}
+#endif
+
// The order here will control the order of RtAudio's API search in
// the constructor.
extern "C" const RtAudio::Api rtaudio_compiled_apis[] = {
@@ -1625,7 +1641,6 @@ void RtApiCore :: closeStream( void )
AudioObjectPropertyAddress property = { kAudioHardwarePropertyDevices,
kAudioObjectPropertyScopeGlobal,
KAUDIOOBJECTPROPERTYELEMENT };
-
if ( handle->xrunListenerAdded[0] ) {
property.mSelector = kAudioDeviceProcessorOverload;
if (AudioObjectRemovePropertyListener( handle->id[0], &property, xrunListener, (void *) handle ) != noErr) {
@@ -2336,7 +2351,7 @@ bool RtApiJack :: probeDeviceInfo( RtAudio::DeviceInfo& info, jack_client_t *cli
// Count the available ports containing the client name as device
// channels. Jack "input ports" equal RtAudio output channels.
unsigned int nChannels = 0;
- const char **ports = jack_get_ports( client, info.name.c_str(), JACK_DEFAULT_AUDIO_TYPE, JackPortIsInput );
+ const char **ports = jack_get_ports( client, escapeJackPortRegex(info.name).c_str(), JACK_DEFAULT_AUDIO_TYPE, JackPortIsInput );
if ( ports ) {
while ( ports[ nChannels ] ) nChannels++;
free( ports );
@@ -2345,7 +2360,7 @@ bool RtApiJack :: probeDeviceInfo( RtAudio::DeviceInfo& info, jack_client_t *cli
// Jack "output ports" equal RtAudio input channels.
nChannels = 0;
- ports = jack_get_ports( client, info.name.c_str(), JACK_DEFAULT_AUDIO_TYPE, JackPortIsOutput );
+ ports = jack_get_ports( client, escapeJackPortRegex(info.name).c_str(), JACK_DEFAULT_AUDIO_TYPE, JackPortIsOutput );
if ( ports ) {
while ( ports[ nChannels ] ) nChannels++;
free( ports );
@@ -2475,7 +2490,7 @@ bool RtApiJack :: probeDeviceOpen( unsigned int deviceId, StreamMode mode, unsig
// Count the available ports containing the client name as device
// channels. Jack "input ports" equal RtAudio output channels.
unsigned int nChannels = 0;
- ports = jack_get_ports( client, deviceName.c_str(), JACK_DEFAULT_AUDIO_TYPE, flag );
+ ports = jack_get_ports( client, escapeJackPortRegex(deviceName).c_str(), JACK_DEFAULT_AUDIO_TYPE, flag );
if ( ports ) {
while ( ports[ nChannels ] ) nChannels++;
free( ports );
@@ -2499,7 +2514,7 @@ bool RtApiJack :: probeDeviceOpen( unsigned int deviceId, StreamMode mode, unsig
stream_.sampleRate = jackRate;
// Get the latency of the JACK port.
- ports = jack_get_ports( client, deviceName.c_str(), JACK_DEFAULT_AUDIO_TYPE, flag );
+ ports = jack_get_ports( client, escapeJackPortRegex(deviceName).c_str(), JACK_DEFAULT_AUDIO_TYPE, flag );
if ( ports[ firstChannel ] ) {
// Added by Ge Wang
jack_latency_callback_mode_t cbmode = (mode == INPUT ? JackCaptureLatency : JackPlaybackLatency);
@@ -2747,7 +2762,7 @@ RtAudioErrorType RtApiJack :: startStream( void )
// Get the list of available ports.
if ( shouldAutoconnect_ && (stream_.mode == OUTPUT || stream_.mode == DUPLEX) ) {
- ports = jack_get_ports( handle->client, handle->deviceName[0].c_str(), JACK_DEFAULT_AUDIO_TYPE, JackPortIsInput);
+ ports = jack_get_ports( handle->client, escapeJackPortRegex(handle->deviceName[0]).c_str(), JACK_DEFAULT_AUDIO_TYPE, JackPortIsInput);
if ( ports == NULL) {
errorText_ = "RtApiJack::startStream(): error determining available JACK input ports!";
goto unlock;
@@ -2770,7 +2785,7 @@ RtAudioErrorType RtApiJack :: startStream( void )
}
if ( shouldAutoconnect_ && (stream_.mode == INPUT || stream_.mode == DUPLEX) ) {
- ports = jack_get_ports( handle->client, handle->deviceName[1].c_str(), JACK_DEFAULT_AUDIO_TYPE, JackPortIsOutput );
+ ports = jack_get_ports( handle->client, escapeJackPortRegex(handle->deviceName[1]).c_str(), JACK_DEFAULT_AUDIO_TYPE, JackPortIsOutput );
if ( ports == NULL) {
errorText_ = "RtApiJack::startStream(): error determining available JACK output ports!";
goto unlock;
@@ -4756,7 +4771,7 @@ bool RtApiWasapi::probeDeviceInfo( RtAudio::DeviceInfo &info, LPWSTR deviceId, b
// Get the device pointer from the device Id
HRESULT hr = deviceEnumerator_->GetDevice( deviceId, &devicePtr );
- if ( FAILED( hr ) ) {
+ if ( FAILED( hr ) || defaultDeviceNameProp.pwszVal == nullptr ) {
errorText_ = "RtApiWasapi::probeDeviceInfo: Unable to retrieve device handle.";
goto Exit;
}
@@ -4771,7 +4786,7 @@ bool RtApiWasapi::probeDeviceInfo( RtAudio::DeviceInfo &info, LPWSTR deviceId, b
PropVariantInit( &deviceNameProp );
hr = devicePropStore->GetValue( PKEY_Device_FriendlyName, &deviceNameProp );
- if ( FAILED( hr ) ) {
+ if ( FAILED( hr ) || deviceNameProp.pwszVal == nullptr ) {
errorText_ = "RtApiWasapi::probeDeviceInfo: Unable to retrieve device property: PKEY_Device_FriendlyName.";
goto Exit;
}