Basic jack dispatcher

This commit is contained in:
Nedko Arnaudov 2009-09-06 01:15:25 +03:00
parent 3fb3fcc75e
commit d7473e1fca
6 changed files with 237 additions and 17 deletions

View File

@ -394,6 +394,11 @@ void ladish_graph_destroy(ladish_graph_handle graph_handle)
free(impl_ptr);
}
const char * ladish_graph_get_opath(ladish_graph_handle graph_handle)
{
return impl_ptr->opath;
}
void ladish_graph_clear(ladish_graph_handle graph_handle)
{
}
@ -403,7 +408,7 @@ void * ladish_graph_get_dbus_context(ladish_graph_handle graph_handle)
return graph_handle;
}
void ladish_graph_add_client(ladish_graph_handle graph_handle, ladish_client_handle client, const char * opath)
void ladish_graph_add_client(ladish_graph_handle graph_handle, ladish_client_handle client)
{
const char * name;
@ -411,12 +416,12 @@ void ladish_graph_add_client(ladish_graph_handle graph_handle, ladish_client_han
list_add_tail(ladish_client_get_graph_link(client), &impl_ptr->clients);
impl_ptr->graph_version++;
name = ladish_client_get_graph_name(client, opath);
name = ladish_client_get_graph_name(client, impl_ptr->opath);
lash_info("adding client '%s' (%p)", name, client);
assert(name != NULL);
dbus_signal_emit(
g_dbus_connection,
opath,
impl_ptr->opath,
JACKDBUS_IFACE_PATCHBAY,
"ClientAppeared",
"tts",

View File

@ -35,7 +35,8 @@ bool ladish_graph_create(ladish_graph_handle * graph_handle_ptr, const char * op
void ladish_graph_destroy(ladish_graph_handle graph_handle);
void ladish_graph_clear(ladish_graph_handle graph_handle);
void * ladish_graph_get_dbus_context(ladish_graph_handle graph_handle);
void ladish_graph_add_client(ladish_graph_handle graph_handle, ladish_client_handle client_handle, const char * opath);
void ladish_graph_add_client(ladish_graph_handle graph_handle, ladish_client_handle client_handle);
const char * ladish_graph_get_opath(ladish_graph_handle graph_handle);
extern const struct dbus_interface_descriptor g_interface_patchbay;

160
daemon/jack_dispatch.c Normal file
View File

@ -0,0 +1,160 @@
/* -*- Mode: C ; c-basic-offset: 2 -*- */
/*
* LADI Session Handler (ladish)
*
* Copyright (C) 2009 Nedko Arnaudov <nedko@arnaudov.name>
*
**************************************************************************
* This file contains implementation of the graph dispatcher object
**************************************************************************
*
* LADI Session Handler is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* LADI Session Handler is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with LADI Session Handler. If not, see <http://www.gnu.org/licenses/>
* or write to the Free Software Foundation, Inc.,
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#include "jack_dispatch.h"
struct jack_dispatcher
{
graph_proxy_handle jack_graph;
ladish_graph_handle studio_graph;
uint64_t system_client_id;
ladish_client_handle system_capture_client;
ladish_client_handle system_playback_client;
};
#define dispatcher_ptr ((struct jack_dispatcher *)context)
static void clear(void * context)
{
lash_info("clear");
}
static void client_appeared(void * context, uint64_t id, const char * name)
{
ladish_client_handle client;
lash_info("client_appeared(%llu, %s)", (unsigned long long)id, name);
if (strcmp(name, "system") == 0)
{
dispatcher_ptr->system_client_id = id;
}
else
{
ladish_client_create(NULL, true, false, true, &client);
ladish_client_set_graph_name(client, ladish_graph_get_opath(dispatcher_ptr->studio_graph), name);
ladish_graph_add_client(dispatcher_ptr->studio_graph, client);
}
}
static void client_disappeared(void * context, uint64_t id)
{
lash_info("client_disappeared(%llu)", (unsigned long long)id);
if (id == dispatcher_ptr->system_client_id)
{
dispatcher_ptr->system_client_id = 0;
}
}
static void port_appeared(void * context, uint64_t client_id, uint64_t port_id, const char * port_name, bool is_input, bool is_terminal, bool is_midi)
{
lash_info("port_appeared(%llu, %llu, %s (%s, %s))", (unsigned long long)client_id, (unsigned long long)port_id, port_name, is_input ? "in" : "out", is_midi ? "midi" : "audio");
if (client_id == dispatcher_ptr->system_client_id)
{
if (!is_input && dispatcher_ptr->system_capture_client == NULL)
{
ladish_client_create(NULL, true, false, true, &dispatcher_ptr->system_capture_client);
ladish_client_set_graph_name(dispatcher_ptr->system_capture_client, ladish_graph_get_opath(dispatcher_ptr->studio_graph), "Hardware Capture");
ladish_graph_add_client(dispatcher_ptr->studio_graph, dispatcher_ptr->system_capture_client);
}
else if (is_input && dispatcher_ptr->system_playback_client == NULL)
{
ladish_client_create(NULL, true, false, true, &dispatcher_ptr->system_playback_client);
ladish_client_set_graph_name(dispatcher_ptr->system_playback_client, ladish_graph_get_opath(dispatcher_ptr->studio_graph), "Hardware Playback");
ladish_graph_add_client(dispatcher_ptr->studio_graph, dispatcher_ptr->system_playback_client);
}
}
}
static void port_disappeared(void * context, uint64_t client_id, uint64_t port_id)
{
lash_info("port_disappeared(%llu)", (unsigned long long)port_id);
}
static void ports_connected(void * context, uint64_t client1_id, uint64_t port1_id, uint64_t client2_id, uint64_t port2_id)
{
lash_info("ports_connected");
}
static void ports_disconnected(void * context, uint64_t client1_id, uint64_t port1_id, uint64_t client2_id, uint64_t port2_id)
{
lash_info("ports_disconnected");
}
#undef dispatcher_ptr
bool
ladish_jack_dispatcher_create(
graph_proxy_handle jack_graph,
ladish_graph_handle studio_graph,
ladish_jack_dispatcher_handle * handle_ptr)
{
struct jack_dispatcher * dispatcher_ptr;
dispatcher_ptr = malloc(sizeof(struct jack_dispatcher));
if (dispatcher_ptr == NULL)
{
lash_error("malloc() failed for struct jack_dispatcher");
return false;
}
dispatcher_ptr->jack_graph = jack_graph;
dispatcher_ptr->studio_graph = studio_graph;
dispatcher_ptr->system_client_id = 0;
dispatcher_ptr->system_capture_client = NULL;
dispatcher_ptr->system_playback_client = NULL;
if (!graph_proxy_attach(
jack_graph,
dispatcher_ptr,
clear,
client_appeared,
client_disappeared,
port_appeared,
port_disappeared,
ports_connected,
ports_disconnected))
{
free(dispatcher_ptr);
return false;
}
*handle_ptr = (ladish_jack_dispatcher_handle)dispatcher_ptr;
return true;
}
#define dispatcher_ptr ((struct jack_dispatcher *)handle)
void
ladish_jack_dispatcher_destroy(
ladish_jack_dispatcher_handle handle)
{
graph_proxy_detach((graph_proxy_handle)handle, NULL);
}
#undef dispatcher_ptr

46
daemon/jack_dispatch.h Normal file
View File

@ -0,0 +1,46 @@
/* -*- Mode: C ; c-basic-offset: 2 -*- */
/*
* LADI Session Handler (ladish)
*
* Copyright (C) 2009 Nedko Arnaudov <nedko@arnaudov.name>
*
**************************************************************************
* This file contains interface to graph dispatcher object
**************************************************************************
*
* LADI Session Handler is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* LADI Session Handler is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with LADI Session Handler. If not, see <http://www.gnu.org/licenses/>
* or write to the Free Software Foundation, Inc.,
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#ifndef JACK_DISPATCH_H__C7566B66_081D_4D00_A702_7C18F7CC0735__INCLUDED
#define JACK_DISPATCH_H__C7566B66_081D_4D00_A702_7C18F7CC0735__INCLUDED
#include "common.h"
#include "../graph_proxy.h"
#include "graph_iface.h"
typedef struct ladish_jack_dispatcher { int unused; } * ladish_jack_dispatcher_handle;
bool
ladish_jack_dispatcher_create(
graph_proxy_handle jack_graph,
ladish_graph_handle studio_graph,
ladish_jack_dispatcher_handle * handle_ptr);
void
ladish_jack_dispatcher_destroy(
ladish_jack_dispatcher_handle handle);
#endif /* #ifndef JACK_DISPATCH_H__C7566B66_081D_4D00_A702_7C18F7CC0735__INCLUDED */

View File

@ -41,6 +41,7 @@
#include "../catdup.h"
#include "../dbus/error.h"
#include "dirhelpers.h"
#include "jack_dispatch.h"
#define STUDIOS_DIR "/studios/"
char * g_studios_dir;
@ -79,6 +80,7 @@ struct studio
graph_proxy_handle jack_graph_proxy;
ladish_graph_handle graph;
ladish_jack_dispatcher_handle jack_dispatcher;
} g_studio;
#define EVENT_JACK_START 0
@ -655,19 +657,15 @@ void on_event_jack_started(void)
}
else
{
#if 1 /* XXX */
ladish_client_handle capture_client;
ladish_client_handle playback_client;
if (!ladish_jack_dispatcher_create(g_studio.jack_graph_proxy, g_studio.graph, &g_studio.jack_dispatcher))
{
lash_error("ladish_jack_dispatcher_create() failed.");
}
ladish_client_create( NULL, true, false, true, &capture_client);
ladish_client_create(NULL, true, false, true, &playback_client);
ladish_client_set_graph_name(capture_client, STUDIO_OBJECT_PATH, "Hardware Capture");
ladish_client_set_graph_name(playback_client, STUDIO_OBJECT_PATH, "Hardware Playback");
ladish_graph_add_client(g_studio.graph, capture_client, STUDIO_OBJECT_PATH);
ladish_graph_add_client(g_studio.graph, playback_client, STUDIO_OBJECT_PATH);
#endif
if (!graph_proxy_activate(g_studio.jack_graph_proxy))
{
lash_error("graph_proxy_activate() failed.");
}
}
}
@ -677,7 +675,16 @@ void on_event_jack_stopped(void)
g_studio.jack_running = false;
graph_proxy_destroy(g_studio.jack_graph_proxy);
if (g_studio.jack_dispatcher)
{
ladish_jack_dispatcher_destroy(g_studio.jack_dispatcher);
}
if (g_studio.jack_graph_proxy)
{
graph_proxy_destroy(g_studio.jack_graph_proxy);
g_studio.jack_graph_proxy = NULL;
}
/* TODO: if user wants, restart jack server and reconnect all jack apps to it */
}

View File

@ -201,6 +201,7 @@ def build(bld):
'studio.c',
'graph_iface.c',
'client.c',
'jack_dispatch.c',
]:
daemon.source.append(os.path.join("daemon", source))