Add generic audio service init

This commit is contained in:
Marcel Holtmann 2007-04-08 23:13:18 +00:00
parent ebfe5886d0
commit 7558cca5c0
4 changed files with 97 additions and 106 deletions

View File

@ -10,10 +10,10 @@ servicedir = $(libdir)/bluetooth
service_PROGRAMS = bluetoothd-service-audio
bluetoothd_service_audio_SOURCES = manager.h manager.c headset.c
bluetoothd_service_audio_SOURCES = main.c manager.h manager.c headset.c
bluetoothd_service_audio_LDADD = $(top_builddir)/common/libhelper.a \
@SBC_LIBS@ @GLIB_LIBS@ @DBUS_LIBS@ @BLUEZ_LIBS@
@GLIB_LIBS@ @DBUS_LIBS@ @BLUEZ_LIBS@
endif
if ALSA
@ -23,7 +23,7 @@ alsa_LTLIBRARIES = libasound_module_pcm_bluetooth.la libasound_module_ctl_blueto
libasound_module_pcm_bluetooth_la_SOURCES = pcm_bluetooth.c
libasound_module_pcm_bluetooth_la_LDFLAGS = -module -avoid-version -export-dynamic
libasound_module_pcm_bluetooth_la_LIBADD = @ALSA_LIBS@
libasound_module_pcm_bluetooth_la_LIBADD = @SBC_LIBS@ @ALSA_LIBS@
libasound_module_ctl_bluetooth_la_SOURCES = ctl_bluetooth.c
libasound_module_ctl_bluetooth_la_LDFLAGS = -module -avoid-version -export-dynamic

View File

@ -1963,78 +1963,11 @@ void audio_manager_free(struct manager *manager)
g_free(manager);
}
static void sig_term(int sig)
static struct manager *manager = NULL;
int headset_init(DBusConnection *conn)
{
g_main_loop_quit(main_loop);
}
int main(int argc, char *argv[])
{
uint8_t opt_channel = 12;
char *opt_bda = NULL;
char *opt_input = NULL;
char *opt_output = NULL;
gboolean register_svc = FALSE;
bdaddr_t bda;
struct headset *hs;
struct manager *manager;
struct sigaction sa;
int opt;
while ((opt = getopt(argc, argv, "c:o:i:ds")) != EOF) {
switch (opt) {
case 'c':
opt_channel = strtol(optarg, NULL, 0);
break;
case 'i':
opt_input = optarg;
break;
case 'o':
opt_output = optarg;
break;
case 'd':
enable_debug();
break;
case 's':
register_svc = TRUE;
break;
default:
printf("Usage: %s -c local_channel [-d] [-o output] [-i input] [bdaddr]\n", argv[0]);
exit(1);
}
}
if (optind < argc && argv[optind])
opt_bda = argv[optind];
start_logging("audio", "Bluetooth audio service daemon");
memset(&sa, 0, sizeof(sa));
sa.sa_flags = SA_NOCLDSTOP;
sa.sa_handler = sig_term;
sigaction(SIGTERM, &sa, NULL);
sigaction(SIGINT, &sa, NULL);
sa.sa_handler = SIG_IGN;
sigaction(SIGCHLD, &sa, NULL);
sigaction(SIGPIPE, &sa, NULL);
main_loop = g_main_loop_new(NULL, FALSE);
connection = init_dbus(NULL, NULL, NULL);
if (!connection) {
error("Connection to system bus failed");
g_main_loop_unref(main_loop);
exit(1);
}
if (register_svc)
register_external_service(connection, "audio", "Audio service", "");
connection = dbus_connection_ref(conn);
manager = audio_manager_new(connection);
if (!manager) {
@ -2044,40 +1977,15 @@ int main(int argc, char *argv[])
exit(1);
}
audio_manager_create_headset_server(manager, opt_channel);
audio_manager_create_headset_server(manager, 12);
if (opt_bda) {
str2ba(opt_bda, &bda);
hs = audio_headset_new(connection, &bda);
if (!hs) {
error("Connection setup failed");
dbus_connection_unref(connection);
g_main_loop_unref(main_loop);
exit(1);
}
if (opt_output)
audio_headset_open_output(hs, opt_output);
if (opt_input)
audio_headset_open_input(hs, opt_input);
audio_manager_add_headset(manager, hs);
/* connect */
hs_connect(hs, NULL);
}
g_main_loop_run(main_loop);
return 0;
}
void headset_exit(void)
{
audio_manager_free(manager);
manager = NULL;
dbus_connection_unref(connection);
g_main_loop_unref(main_loop);
info("Exit");
stop_logging();
return 0;
}

25
audio/headset.h Normal file
View File

@ -0,0 +1,25 @@
/*
*
* BlueZ - Bluetooth protocol stack for Linux
*
* Copyright (C) 2004-2007 Marcel Holtmann <marcel@holtmann.org>
*
*
* This program 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.
*
* This program 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 this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
*/
int headset_init(DBusConnection *conn);
void headset_exit(void);

View File

@ -25,16 +25,74 @@
#include <config.h>
#endif
#include <stdio.h>
#include <errno.h>
#include <stdlib.h>
#include <string.h>
#include <signal.h>
#include <glib.h>
#include <dbus/dbus.h>
#include "dbus.h"
#include "logging.h"
#include "manager.h"
#include "headset.h"
static GMainLoop *main_loop = NULL;
static void sig_term(int sig)
{
g_main_loop_quit(main_loop);
}
int main(int argc, char *argv[])
{
DBusConnection *conn;
struct sigaction sa;
start_logging("audio", "Bluetooth Audio daemon");
memset(&sa, 0, sizeof(sa));
sa.sa_flags = SA_NOCLDSTOP;
sa.sa_handler = sig_term;
sigaction(SIGTERM, &sa, NULL);
sigaction(SIGINT, &sa, NULL);
sa.sa_handler = SIG_IGN;
sigaction(SIGCHLD, &sa, NULL);
sigaction(SIGPIPE, &sa, NULL);
enable_debug();
main_loop = g_main_loop_new(NULL, FALSE);
conn = dbus_bus_system_setup_with_main_loop(NULL, NULL, NULL);
if (!conn) {
g_main_loop_unref(main_loop);
exit(1);
}
audio_init();
headset_init(conn);
if (argc > 1 && !strcmp(argv[1], "-s"))
register_external_service(conn, "audio", "Audio service", "");
g_main_loop_run(main_loop);
headset_exit();
audio_exit();
dbus_connection_unref(conn);
g_main_loop_unref(main_loop);
info("Exit");
stop_logging();
return 0;
}