[asterisk-commits] russell: branch russell/jack r91825 - /team/russell/jack/apps/app_jack.c
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Fri Dec 7 14:44:57 CST 2007
Author: russell
Date: Fri Dec 7 14:44:57 2007
New Revision: 91825
URL: http://svn.digium.com/view/asterisk?view=rev&rev=91825
Log:
Add the beginning of a simple Jack application. It only has the initialization
stuff right now ... the audio processing part will be the more challenging part
Added:
team/russell/jack/apps/app_jack.c (with props)
Added: team/russell/jack/apps/app_jack.c
URL: http://svn.digium.com/view/asterisk/team/russell/jack/apps/app_jack.c?view=auto&rev=91825
==============================================================================
--- team/russell/jack/apps/app_jack.c (added)
+++ team/russell/jack/apps/app_jack.c Fri Dec 7 14:44:57 2007
@@ -1,0 +1,215 @@
+/*
+ * Asterisk -- An open source telephony toolkit.
+ *
+ * Copyright (C) 2007, Russell Bryant
+ *
+ * Russell Bryant <russell at digium.com>
+ *
+ * See http://www.asterisk.org for more information about
+ * the Asterisk project. Please do not directly contact
+ * any of the maintainers of this project for assistance;
+ * the project provides a web site, mailing lists and IRC
+ * channels for your use.
+ *
+ * This program is free software, distributed under the terms of
+ * the GNU General Public License Version 2. See the LICENSE file
+ * at the top of the source tree.
+ */
+
+/*! \file
+ *
+ * \brief Jack Application
+ *
+ * \author Russell Bryant <russell at digium.com>
+ *
+ * This is an application to connect an Asterisk channel to an input
+ * and output jack channel so that the audio can be processed through
+ * another application, or to play audio from another application.
+ *
+ * \arg http://www.jackaudio.org/
+ *
+ * \ingroup applications
+ */
+
+/*** MODULEINFO
+ <depend>jack</depend>
+ ***/
+
+#include "asterisk.h"
+
+ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
+
+#include <jack/jack.h>
+#include <jack/types.h>
+
+#include "asterisk/module.h"
+#include "asterisk/channel.h"
+#include "asterisk/strings.h"
+
+static char *jack_app = "Jack";
+static char *jack_synopsis =
+"JACK (Jack Audio Connection Kit) Application";
+static char *jack_desc =
+"Jcak()\n"
+"";
+
+struct jack_data {
+ jack_client_t *client;
+ jack_port_t *input_port;
+ jack_port_t *output_port;
+};
+
+static const struct {
+ jack_status_t status;
+ const char *str;
+} jack_status_table[] = {
+ { JackFailure, "Failure" },
+ { JackInvalidOption, "Invalid Option" },
+ { JackNameNotUnique, "Name Not Unique" },
+ { JackServerStarted, "Server Started" },
+ { JackServerFailed, "Server Failed" },
+ { JackServerError, "Server Error" },
+ { JackNoSuchClient, "No Such Client" },
+ { JackLoadFailure, "Load Failure" },
+ { JackInitFailure, "Init Failure" },
+ { JackShmFailure, "Shared Memory Access Failure" },
+ { JackVersionError, "Version Mismatch" },
+};
+
+static const char *jack_status_to_str(jack_status_t status)
+{
+ int i;
+
+ for (i = 0; i < ARRAY_LEN(jack_status_table); i++) {
+ if (jack_status_table[i].status == status)
+ return jack_status_table[i].str;
+ }
+
+ return "Unknown Error";
+}
+
+static void log_jack_status(const char *prefix, jack_status_t status)
+{
+ struct ast_str *str = ast_str_alloca(512);
+ int i, first = 0;
+
+ for (i = 0; i < (sizeof(status) * 8); i++) {
+ if (!(status & (1 << i)))
+ continue;
+
+ if (!first) {
+ ast_str_set(&str, 0, "%s", jack_status_to_str((1 << i)));
+ first = 1;
+ } else
+ ast_str_append(&str, 0, ", %s", jack_status_to_str((1 << i)));
+ }
+
+ ast_log(LOG_NOTICE, "%s: %s\n", prefix, str->str);
+}
+
+static int jack_process(jack_nframes_t nframes, void *arg)
+{
+ struct jack_data *jack_data = arg;
+
+ (void)(jack_data);
+ /* XXX */
+
+ return 0;
+}
+
+static void jack_shutdown(void *arg)
+{
+ struct jack_data *jack_data = arg;
+
+ (void)(jack_data);
+ /* XXX */
+}
+
+static int init_jack_data(struct ast_channel *chan, struct jack_data *jack_data)
+{
+ const char *chan_name;
+ jack_status_t status = 0;
+
+ ast_channel_lock(chan);
+ chan_name = ast_strdupa(chan->name);
+ ast_channel_unlock(chan);
+
+ jack_data->client = jack_client_open(chan_name, 0, &status);
+
+ log_jack_status("Client Open Status", status);
+
+ if (!jack_data->client)
+ return -1;
+
+ if (jack_set_process_callback(jack_data->client, jack_process, jack_data)) {
+ ast_log(LOG_ERROR, "Failed to register process callback for jack client\n");
+ return -1;
+ }
+
+ jack_on_shutdown(jack_data->client, jack_shutdown, jack_data);
+
+ jack_data->input_port = jack_port_register(jack_data->client, "input",
+ JACK_DEFAULT_AUDIO_TYPE, JackPortIsInput, 0);
+ if (!jack_data->input_port) {
+ ast_log(LOG_ERROR, "Failed to create input port for jack client\n");
+ return -1;
+ }
+
+ jack_data->output_port = jack_port_register(jack_data->client, "output",
+ JACK_DEFAULT_AUDIO_TYPE, JackPortIsOutput, 0);
+ if (!jack_data->output_port) {
+ ast_log(LOG_ERROR, "Failed to create output port for jack client\n");
+ return -1;
+ }
+
+ if (jack_activate(jack_data->client)) {
+ ast_log(LOG_ERROR, "Failed to start the jack client\n");
+ return -1;
+ }
+
+ /* XXX */
+
+ return 0;
+}
+
+static void destroy_jack_data(struct jack_data *jack_data)
+{
+ /* XXX Ports? */
+
+ if (jack_data->client) {
+ jack_client_close(jack_data->client);
+ jack_data->client = NULL;
+ }
+}
+
+static int jack_exec(struct ast_channel *chan, void *data)
+{
+ int res = 0;
+ struct jack_data jack_data = { NULL, };
+
+ if (init_jack_data(chan, &jack_data)) {
+ destroy_jack_data(&jack_data);
+ return -1;
+ }
+
+ /* XXX */
+
+ destroy_jack_data(&jack_data);
+
+ return res;
+}
+
+static int unload_module(void)
+{
+ return ast_unregister_application(jack_app);
+}
+
+static int load_module(void)
+{
+ if (ast_register_application(jack_app, jack_exec, jack_synopsis, jack_desc))
+ return AST_MODULE_LOAD_DECLINE;
+
+ return AST_MODULE_LOAD_SUCCESS;
+}
+
+AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Jack Application");
Propchange: team/russell/jack/apps/app_jack.c
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: team/russell/jack/apps/app_jack.c
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Propchange: team/russell/jack/apps/app_jack.c
------------------------------------------------------------------------------
svn:mime-type = text/plain
More information about the asterisk-commits
mailing list