Commit 3aa9b525 authored by nedko's avatar nedko
Browse files

Move dbus device reservation code to jackdbus

git-svn-id: http://subversion.jackaudio.org/jack/jack2/trunk/jackmp@3579 0c269be4-1314-0410-8aa9-9f06e86f4224
parent 9b185921
......@@ -43,6 +43,7 @@
#include "JackLockedEngine.h"
#include "JackConstants.h"
#include "JackDriverLoader.h"
#include "JackServerGlobals.h"
using namespace Jack;
......@@ -618,7 +619,9 @@ get_realtime_priority_constraint()
return constraint_ptr;
}
EXPORT jackctl_server_t * jackctl_server_create()
EXPORT jackctl_server_t * jackctl_server_create(
bool (* on_device_acquire)(const char * device_name),
void (* on_device_release)(const char * device_name))
{
struct jackctl_server * server_ptr;
union jackctl_parameter_value value;
......@@ -762,6 +765,9 @@ EXPORT jackctl_server_t * jackctl_server_create()
goto fail_free_parameters;
}
JackServerGlobals::on_device_acquire = on_device_acquire;
JackServerGlobals::on_device_release = on_device_release;
if (!jackctl_drivers_load(server_ptr))
{
goto fail_free_parameters;
......
......@@ -88,7 +88,9 @@ jackctl_wait_signals(
sigset_t signals);
EXPORT jackctl_server_t *
jackctl_server_create();
jackctl_server_create(
bool (* on_device_acquire)(const char * device_name),
void (* on_device_release)(const char * device_name));
EXPORT void
jackctl_server_destroy(
......
......@@ -30,6 +30,8 @@ namespace Jack
JackServer* JackServerGlobals::fInstance;
unsigned int JackServerGlobals::fUserCount;
bool (* JackServerGlobals::on_device_acquire)(const char * device_name) = NULL;
void (* JackServerGlobals::on_device_release)(const char * device_name) = NULL;
int JackServerGlobals::Start(const char* server_name,
jack_driver_desc_t* driver_desc,
......
......@@ -38,6 +38,8 @@ struct SERVER_EXPORT JackServerGlobals
{
static JackServer* fInstance;
static unsigned int fUserCount;
static bool (* on_device_acquire)(const char * device_name);
static void (* on_device_release)(const char * device_name);
JackServerGlobals();
~JackServerGlobals();
......
......@@ -207,7 +207,7 @@ int main(int argc, char* argv[])
copyright(stdout);
server_ctl = jackctl_server_create();
server_ctl = jackctl_server_create(NULL, NULL);
if (server_ctl == NULL) {
fprintf(stderr, "Failed to create server object\n");
return -1;
......
......@@ -109,12 +109,17 @@ jackctl_wait_signals(
/**
* Call this function to create server object.
*
* @param on_device_acquire - Optional callback to be called before device is acquired. If false is returned, device usage will fail
* @param on_device_release - Optional callback to be called after device is released.
*
* @return server object handle, NULL if creation of server object
* failed. Successfully created server object must be destroyed with
* paired call to ::jackctl_server_destroy
*/
jackctl_server_t *
jackctl_server_create();
jackctl_server_create(
bool (* on_device_acquire)(const char * device_name),
void (* on_device_release)(const char * device_name));
/**
* Call this function to destroy server object.
......
......@@ -29,6 +29,7 @@
#include "controller.h"
#include "controller_internal.h"
#include "xml.h"
#include "reserve.h"
struct jack_dbus_interface_descriptor * g_jackcontroller_interfaces[] =
{
......@@ -279,6 +280,58 @@ jack_controller_switch_master(
return TRUE;
}
/* TODO: use contianer with unique entries (dict) */
bool g_reserved_device_valid = false;
static rd_device * g_reserved_device;
static
bool
on_device_acquire(const char * device_name)
{
int ret;
DBusError error;
if (g_reserved_device_valid) {
jack_error("Ignoring reservation for more than one device (acquire)");
return false;
}
ret = rd_acquire(
&g_reserved_device,
g_connection,
device_name,
"Jack audio server",
INT32_MAX,
NULL,
&error);
if (ret < 0)
{
jack_error("Failed to acquire device name : %s error : %s", device_name, (error.message ? error.message : strerror(-ret)));
return false;
}
g_reserved_device_valid = true;
jack_info("Acquired audio card %s", device_name);
return true;
}
static
void
on_device_release(const char * device_name)
{
if (!g_reserved_device_valid) {
jack_error("Ignoring reservation for more than one device(release)");
}
rd_release(g_reserved_device);
g_reserved_device_valid = false;
jack_info("Released audio card %s", device_name);
}
void *
jack_controller_create(
DBusConnection *connection)
......@@ -303,7 +356,7 @@ jack_controller_create(
goto fail;
}
controller_ptr->server = jackctl_server_create();
controller_ptr->server = jackctl_server_create(on_device_acquire, on_device_release);
if (controller_ptr->server == NULL)
{
jack_error("Failed to create server object");
......
......@@ -312,5 +312,6 @@ jack_dbus_send_signal(
#define JACK_CONTROLLER_OBJECT_PATH "/org/jackaudio/Controller"
extern struct jack_dbus_interface_descriptor * g_jackcontroller_interfaces[];
extern DBusConnection * g_connection;
#endif /* #ifndef DBUS_H__3DB2458F_44B2_43EA_882A_9F888DF71A88__INCLUDED */
......@@ -59,6 +59,7 @@ def build(bld):
#'xml_nop.c',
'xml_write_raw.c',
'sigsegv.c',
'reserve.c',
]
if bld.env['IS_LINUX']:
obj.uselib = 'PTHREAD DL RT DBUS-1 EXPAT'
......
......@@ -167,7 +167,7 @@ int main(int argc, char *argv[])
}
}
server = jackctl_server_create();
server = jackctl_server_create(NULL, NULL);
parameters = jackctl_server_get_parameters(server);
/*
......
......@@ -48,8 +48,8 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#include "usx2y.h"
#include "generic.h"
#include "memops.h"
#include "JackServerGlobals.h"
#include "audio_reserve.h"
//#define DEBUG_WAKEUP 1
......@@ -2233,25 +2233,24 @@ int JackAlsaDriver::Open(jack_nframes_t nframes,
else if (strcmp(midi_driver_name, "raw") == 0)
midi = alsa_rawmidi_new((jack_client_t*)this);
#if defined(JACK_DBUS)
if (audio_reservation_init() < 0) {
jack_error("Audio device reservation service not available....");
} else if (strcmp(capture_driver_name, playback_driver_name) == 0) { // Same device for input and output
fReservedCaptureDevice = audio_acquire(card_to_num(capture_driver_name));
if (fReservedCaptureDevice == NULL) {
jack_error("Error audio device %s cannot be acquired, trying to open it anyway...", capture_driver_name);
}
} else {
fReservedCaptureDevice = audio_acquire(card_to_num(capture_driver_name));
if (fReservedCaptureDevice == NULL) {
jack_error("Error capture audio device %s cannot be acquired, trying to open it anyway...", capture_driver_name);
}
fReservedPlaybackDevice = audio_acquire(card_to_num(playback_driver_name));
if (fReservedPlaybackDevice == NULL) {
jack_error("Error playback audio device %s cannot be acquired, trying to open it anyway...", playback_driver_name);
}
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];
snprintf(audio_name, sizeof(audio_name) - 1, "Audio%d", capture_card);
if (!JackServerGlobals::on_device_acquire(audio_name)) {
jack_error("Audio device %s cannot be acquired, trying to open it anyway...", capture_driver_name);
}
if (playback_card != capture_card) {
snprintf(audio_name, sizeof(audio_name) - 1, "Audio%d", playback_card);
if (!JackServerGlobals::on_device_acquire(audio_name)) {
jack_error("Audio device %s cannot be acquired, trying to open it anyway...", playback_driver_name);
}
}
}
#endif
fDriver = alsa_driver_new ("alsa_pcm", (char*)playback_driver_name, (char*)capture_driver_name,
NULL,
......@@ -2286,11 +2285,23 @@ int JackAlsaDriver::Close()
{
JackAudioDriver::Close();
alsa_driver_delete((alsa_driver_t*)fDriver);
#if defined(JACK_DBUS)
audio_release(fReservedCaptureDevice);
audio_release(fReservedPlaybackDevice);
audio_reservation_finish();
#endif
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) - 1, "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) - 1, "Audio%d", playback_card);
JackServerGlobals::on_device_release(audio_name);
}
}
return 0;
}
......
......@@ -40,8 +40,8 @@ class JackAlsaDriver : public JackAudioDriver
private:
jack_driver_t* fDriver;
void* fReservedCaptureDevice;
void* fReservedPlaybackDevice;
int fReservedCaptureDevice;
int fReservedPlaybackDevice;
void alsa_driver_release_channel_dependent_memory(alsa_driver_t *driver);
int alsa_driver_check_capabilities(alsa_driver_t *driver);
......@@ -121,8 +121,8 @@ class JackAlsaDriver : public JackAudioDriver
JackAlsaDriver(const char* name, const char* alias, JackLockedEngine* engine, JackSynchro* table)
: JackAudioDriver(name, alias, engine, table)
,fDriver(NULL)
,fReservedCaptureDevice(NULL)
,fReservedPlaybackDevice(NULL)
,fReservedCaptureDevice(-1)
,fReservedPlaybackDevice(-1)
{}
virtual ~JackAlsaDriver()
{}
......
......@@ -47,10 +47,6 @@ def build(bld):
'alsa/hammerfall.c',
'alsa/ice1712.c'
]
if bld.env['BUILD_JACKDBUS']:
alsa_driver_src += ['../dbus/reserve.c', '../dbus/audio_reserve.c']
if bld.env['BUILD_DRIVER_ALSA'] == True:
create_jack_driver_obj(bld, 'alsa', alsa_driver_src, "ALSA")
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment