Ignore device reservation failures

Device reservation could fail because of bad system setup.
Trying to open the device anyway seems to have no undesired impact.
This commit is contained in:
Nedko Arnaudov 2013-04-07 00:44:39 +03:00
parent 8f556dac4f
commit 6f1e24b00c
2 changed files with 65 additions and 41 deletions

View File

@ -241,6 +241,57 @@ fail:
return i;
}
bool JackAlsaDriver::AcquireDevice(int device_no, char* reserved_device)
{
assert(*reserved_device == '\0');
snprintf(reserved_device, MAX_RESERVED_DEVICE_NAME_SIZE, "Audio%d", device_no);
if (!JackServerGlobals::on_device_acquire(reserved_device)) {
*reserved_device = '\0';
return false;
}
return true;
}
void JackAlsaDriver::AcquireDevices(const char* capture, const char* playback)
{
if (JackServerGlobals::on_device_acquire == NULL) {
assert(JackServerGlobals::on_device_release == NULL);
return;
}
int capture_card = card_to_num(capture);
int playback_card = card_to_num(playback);
if (capture_card >= 0)
if (!AcquireDevice(capture_card, fReservedCaptureDevice))
jack_error("Audio device %s cannot be acquired...", capture);
if (playback_card >= 0 && playback_card != capture_card)
if (!AcquireDevice(playback_card, fReservedPlaybackDevice))
jack_error("Audio device %s cannot be acquired...", playback);
}
void JackAlsaDriver::ReleaseDevice(char* reserved_device)
{
if (*reserved_device == '\0') return;
JackServerGlobals::on_device_release(reserved_device);
*reserved_device = '\0';
}
void JackAlsaDriver::ReleaseDevices()
{
if (JackServerGlobals::on_device_release == NULL) {
assert(JackServerGlobals::on_device_acquire == NULL);
return;
}
ReleaseDevice(fReservedCaptureDevice);
ReleaseDevice(fReservedPlaybackDevice);
}
int JackAlsaDriver::Open(jack_nframes_t nframes,
jack_nframes_t user_nperiods,
jack_nframes_t samplerate,
@ -273,31 +324,7 @@ int JackAlsaDriver::Open(jack_nframes_t nframes,
else if (strcmp(midi_driver_name, "raw") == 0)
midi = alsa_rawmidi_new((jack_client_t*)this);
if (JackServerGlobals::on_device_acquire != NULL) {
int capture_card = card_to_num(capture_driver_name);
int playback_card = card_to_num(playback_driver_name);
char audio_name[32];
if (capture_card >= 0) {
snprintf(audio_name, sizeof(audio_name), "Audio%d", capture_card);
if (!JackServerGlobals::on_device_acquire(audio_name)) {
jack_error("Audio device %s cannot be acquired...", capture_driver_name);
return -1;
}
}
if (playback_card >= 0 && playback_card != capture_card) {
snprintf(audio_name, sizeof(audio_name), "Audio%d", playback_card);
if (!JackServerGlobals::on_device_acquire(audio_name)) {
jack_error("Audio device %s cannot be acquired...", playback_driver_name);
if (capture_card >= 0) {
snprintf(audio_name, sizeof(audio_name), "Audio%d", capture_card);
JackServerGlobals::on_device_release(audio_name);
}
return -1;
}
}
}
AcquireDevices(capture_driver_name, playback_driver_name);
fDriver = alsa_driver_new ((char*)"alsa_pcm", (char*)playback_driver_name, (char*)capture_driver_name,
NULL,
@ -335,21 +362,7 @@ int JackAlsaDriver::Close()
alsa_driver_delete((alsa_driver_t*)fDriver);
if (JackServerGlobals::on_device_release != NULL)
{
char audio_name[32];
int capture_card = card_to_num(fCaptureDriverName);
if (capture_card >= 0) {
snprintf(audio_name, sizeof(audio_name), "Audio%d", capture_card);
JackServerGlobals::on_device_release(audio_name);
}
int playback_card = card_to_num(fPlaybackDriverName);
if (playback_card >= 0 && playback_card != capture_card) {
snprintf(audio_name, sizeof(audio_name), "Audio%d", playback_card);
JackServerGlobals::on_device_release(audio_name);
}
}
ReleaseDevices();
return res;
}

View File

@ -29,6 +29,8 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
namespace Jack
{
#define MAX_RESERVED_DEVICE_NAME_SIZE 32
/*!
\brief The ALSA driver.
*/
@ -39,14 +41,23 @@ class JackAlsaDriver : public JackAudioDriver
private:
jack_driver_t* fDriver;
char fReservedCaptureDevice[MAX_RESERVED_DEVICE_NAME_SIZE];
char fReservedPlaybackDevice[MAX_RESERVED_DEVICE_NAME_SIZE];
bool AcquireDevice(int device_no, char* reserved_device);
void ReleaseDevice(char* reserved_device);
void AcquireDevices(const char* capture, const char* playback);
void ReleaseDevices();
void UpdateLatencies();
public:
JackAlsaDriver(const char* name, const char* alias, JackLockedEngine* engine, JackSynchro* table)
: JackAudioDriver(name, alias, engine, table),fDriver(NULL)
{}
{
*fReservedCaptureDevice = '\0';
*fReservedPlaybackDevice = '\0';
}
virtual ~JackAlsaDriver()
{}