[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v2 2/3] Factor out common audio module stuff into a macro
From: |
Boris Dušek |
Subject: |
[PATCH v2 2/3] Factor out common audio module stuff into a macro |
Date: |
Sun, 29 Jul 2012 16:37:01 +0200 |
From: Boris Dus?ek <address@hidden>
To: address@hidden
We use the same pattern when declaring an audio module in the end
of the respective implementation file. Factor out that patter into
a macro to ease maintainability and provide opportunities for
future portability improvements.
---
src/audio/alsa.c | 22 +++----------------
src/audio/libao.c | 20 ++---------------
src/audio/nas.c | 23 +++-----------------
src/audio/oss.c | 22 +++----------------
src/audio/pulse.c | 21 ++----------------
src/audio/spd_audio_plugin_p.h | 46 ++++++++++++++++++++++++++++++++++++++++
6 files changed, 59 insertions(+), 95 deletions(-)
create mode 100644 src/audio/spd_audio_plugin_p.h
diff --git a/src/audio/alsa.c b/src/audio/alsa.c
index 4e20a54..c0690dd 100644
--- a/src/audio/alsa.c
+++ b/src/audio/alsa.c
@@ -2,7 +2,7 @@
/*
* alsa.c -- The Advanced Linux Sound System backend for Speech Dispatcher
*
- * Copyright (C) 2005,2006 Brailcom, o.p.s.
+ * Copyright (C) 2005,2006, 2012 Brailcom, o.p.s.
*
* This is free software; you can redistribute it and/or modify it under the
* terms of the GNU Lesser General Public License as published by the Free
@@ -37,8 +37,8 @@
#include <alsa/asoundlib.h>
-#define SPD_AUDIO_PLUGIN_ENTRY spd_alsa_LTX_spd_audio_plugin_get
#include <spd_audio_plugin.h>
+#include "spd_audio_plugin_p.h"
typedef struct {
AudioID id;
@@ -861,23 +861,7 @@ static char const *alsa_get_playcmd(void)
}
/* Provide the Alsa backend. */
-static spd_audio_plugin_t alsa_functions = {
- "alsa",
- alsa_open,
- alsa_play,
- alsa_stop,
- alsa_close,
- alsa_set_volume,
- alsa_set_loglevel,
- alsa_get_playcmd
-};
-
-spd_audio_plugin_t *alsa_plugin_get(void)
-{
- return &alsa_functions;
-}
+SPD_AUDIO_PLUGIN_REGISTER(alsa);
-spd_audio_plugin_t *SPD_AUDIO_PLUGIN_ENTRY(void)
- __attribute__ ((weak, alias("alsa_plugin_get")));
#undef MSG
#undef ERR
diff --git a/src/audio/libao.c b/src/audio/libao.c
index e82be2b..2cedb11 100644
--- a/src/audio/libao.c
+++ b/src/audio/libao.c
@@ -31,8 +31,8 @@
#include <glib.h>
#include <ao/ao.h>
-#define SPD_AUDIO_PLUGIN_ENTRY spd_libao_LTX_spd_audio_plugin_get
#include <spd_audio_plugin.h>
+#include "spd_audio_plugin_p.h"
/* send a packet of XXX bytes to the sound device */
#define AO_SEND_BYTES 256
@@ -224,23 +224,7 @@ static char const *libao_get_playcmd(void)
}
/* Provide the libao backend. */
-static spd_audio_plugin_t libao_functions = {
- "libao",
- libao_open,
- libao_play,
- libao_stop,
- libao_close,
- libao_set_volume,
- libao_set_loglevel,
- libao_get_playcmd
-};
-
-spd_audio_plugin_t *libao_plugin_get(void)
-{
- return &libao_functions;
-}
+SPD_AUDIO_PLUGIN_REGISTER(libao);
-spd_audio_plugin_t *SPD_AUDIO_PLUGIN_ENTRY(void)
- __attribute__ ((weak, alias("libao_plugin_get")));
#undef MSG
#undef ERR
diff --git a/src/audio/nas.c b/src/audio/nas.c
index ca76127..d748958 100644
--- a/src/audio/nas.c
+++ b/src/audio/nas.c
@@ -1,7 +1,7 @@
/*
* nas.c -- The Network Audio System backend for the spd_audio library.
*
- * Copyright (C) 2004,2006 Brailcom, o.p.s.
+ * Copyright (C) 2004,2006,2012 Brailcom, o.p.s.
*
* This is free software; you can redistribute it and/or modify it under the
* terms of the GNU Lesser General Public License as published by the Free
@@ -33,8 +33,8 @@
#include <pthread.h>
-#define SPD_AUDIO_PLUGIN_ENTRY spd_nas_LTX_spd_audio_plugin_get
#include <spd_audio_plugin.h>
+#include "spd_audio_plugin_p.h"
typedef struct {
AudioID id;
@@ -243,21 +243,4 @@ static char const *nas_get_playcmd(void)
}
/* Provide the NAS backend */
-static spd_audio_plugin_t nas_functions = {
- "nas",
- nas_open,
- nas_play,
- nas_stop,
- nas_close,
- nas_set_volume,
- nas_set_loglevel,
- nas_get_playcmd
-};
-
-spd_audio_plugin_t *nas_plugin_get(void)
-{
- return &nas_functions;
-}
-
-spd_audio_plugin_t *SPD_AUDIO_PLUGIN_ENTRY(void)
- __attribute__ ((weak, alias("nas_plugin_get")));
+SPD_AUDIO_PLUGIN_REGISTER(nas);
diff --git a/src/audio/oss.c b/src/audio/oss.c
index b7232c3..15e5215 100644
--- a/src/audio/oss.c
+++ b/src/audio/oss.c
@@ -2,7 +2,7 @@
/*
* oss.c -- The Open Sound System backend for the spd_audio library.
*
- * Copyright (C) 2004,2006 Brailcom, o.p.s.
+ * Copyright (C) 2004,2006,2012 Brailcom, o.p.s.
*
* This is free software; you can redistribute it and/or modify it under the
* terms of the GNU Leser General Public License as published by the Free
@@ -41,8 +41,8 @@
#include <sys/soundcard.h>
-#define SPD_AUDIO_PLUGIN_ENTRY spd_oss_LTX_spd_audio_plugin_get
#include <spd_audio_plugin.h>
+#include "spd_audio_plugin_p.h"
typedef struct {
AudioID id;
@@ -501,23 +501,7 @@ static char const *oss_get_playcmd(void)
}
/* Provide the OSS backend. */
-static spd_audio_plugin_t oss_functions = {
- "oss",
- oss_open,
- oss_play,
- oss_stop,
- oss_close,
- oss_set_volume,
- oss_set_loglevel,
- oss_get_playcmd
-};
-
-spd_audio_plugin_t *oss_plugin_get(void)
-{
- return &oss_functions;
-}
+SPD_AUDIO_PLUGIN_REGISTER(oss);
-spd_audio_plugin_t *SPD_AUDIO_PLUGIN_ENTRY(void)
- __attribute__ ((weak, alias("oss_plugin_get")));
#undef MSG
#undef ERR
diff --git a/src/audio/pulse.c b/src/audio/pulse.c
index a4137e5..5e9466f 100644
--- a/src/audio/pulse.c
+++ b/src/audio/pulse.c
@@ -43,8 +43,8 @@
#include <pulse/simple.h>
#include <pulse/error.h>
-#define SPD_AUDIO_PLUGIN_ENTRY spd_pulse_LTX_spd_audio_plugin_get
#include <spd_audio_plugin.h>
+#include "spd_audio_plugin_p.h"
/* Switch this on to debug, see output log location in MSG() */
//#define DEBUG_PULSE
@@ -290,21 +290,4 @@ static char const *pulse_get_playcmd(void)
}
/* Provide the pulse backend. */
-static spd_audio_plugin_t pulse_functions = {
- "pulse",
- pulse_open,
- pulse_play,
- pulse_stop,
- pulse_close,
- pulse_set_volume,
- pulse_set_loglevel,
- pulse_get_playcmd
-};
-
-spd_audio_plugin_t *pulse_plugin_get(void)
-{
- return &pulse_functions;
-}
-
-spd_audio_plugin_t *SPD_AUDIO_PLUGIN_ENTRY(void)
- __attribute__ ((weak, alias("pulse_plugin_get")));
+SPD_AUDIO_PLUGIN_REGISTER(pulse);
diff --git a/src/audio/spd_audio_plugin_p.h b/src/audio/spd_audio_plugin_p.h
new file mode 100644
index 0000000..38289c6
--- /dev/null
+++ b/src/audio/spd_audio_plugin_p.h
@@ -0,0 +1,46 @@
+/*
+ * spd_audio_plugin_p.h - Utility functions and macros for audio modules
+ *
+ * Copyright (C) 2012 BRAILCOM, o.p.s.
+ *
+ * This 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, or (at your option)
+ * any later version.
+ *
+ * This software 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 package; see the file COPYING. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ *
+ */
+
+#ifndef SPD_AUDIO_PLUGIN_P_H_
+#define SPD_AUDIO_PLUGIN_P_H_
+
+#define SPD_AUDIO_PLUGIN_DEFINE_ENTRY(modname) \
+ spd_audio_plugin_t * modname##_plugin_get(void) { return
&modname##_functions; }\
+ spd_audio_plugin_t * spd_##modname##_LTX_spd_audio_plugin_get (void)
__attribute__ ((weak, alias(#modname "_plugin_get")))
+
+#define SPD_AUDIO_PLUGIN_DEFINE_VTABLE(modname) \
+static spd_audio_plugin_t modname##_functions = { \
+ #modname, \
+ modname##_open, \
+ modname##_play, \
+ modname##_stop, \
+ modname##_close, \
+ modname##_set_volume, \
+ modname##_set_loglevel, \
+ modname##_get_playcmd \
+}
+
+#define SPD_AUDIO_PLUGIN_REGISTER(modname) \
+SPD_AUDIO_PLUGIN_DEFINE_VTABLE(modname); \
+SPD_AUDIO_PLUGIN_DEFINE_ENTRY(modname)
+
+#endif
--
1.7.9.6 (Apple Git-31.1)
- [PATCH 2/3] Factor out common audio module stuff into a macro, (continued)
[PATCH 1/3] Remove references to TEMP_FAILURE_RETRY, Trevor Saunders, 2012/07/25
[PATCH v2 0/3] Portability improvements, Boris Dušek, 2012/07/29