aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--include/local-def.h4
-rw-r--r--nbproject/configurations.xml35
-rw-r--r--nbproject/private/configurations.xml5
-rw-r--r--nbproject/private/private.xml13
-rw-r--r--plugins/audio/audio-alsa.c100
-rw-r--r--plugins/audio/audio-alsa.h6
-rw-r--r--plugins/audio/audio-api.c64
-rw-r--r--plugins/audio/audio-api.h4
-rw-r--r--plugins/radio/radio-api.c2
-rw-r--r--plugins/radio/radio-api.h3
-rw-r--r--plugins/radio/radio-rtlsdr.c17
-rw-r--r--src/main.c8
12 files changed, 159 insertions, 102 deletions
diff --git a/include/local-def.h b/include/local-def.h
index cbbef0f9..54f5ce0d 100644
--- a/include/local-def.h
+++ b/include/local-def.h
@@ -18,6 +18,8 @@
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
+#ifndef LOCAL_DEF_H
+#define LOCAL_DEF_H
#ifndef _GNU_SOURCE
#define _GNU_SOURCE
@@ -256,3 +258,5 @@ typedef struct {
#include "proto-def.h"
+
+#endif /* LOCAL_DEF_H */ \ No newline at end of file
diff --git a/nbproject/configurations.xml b/nbproject/configurations.xml
index c9b7be53..ae317b8e 100644
--- a/nbproject/configurations.xml
+++ b/nbproject/configurations.xml
@@ -4,6 +4,7 @@
<df root="." name="0">
<df name="plugins">
<df name="audio">
+ <in>audio-alsa.c</in>
<in>audio-api.c</in>
</df>
<df name="radio">
@@ -87,6 +88,8 @@
<incDir>
<pElem>include</pElem>
<pElem>/usr/include/json-c</pElem>
+ <pElem>/usr/include/uuid</pElem>
+ <pElem>/usr/include/alsa</pElem>
<pElem>/usr/include/libusb-1.0</pElem>
<pElem>build/plugins</pElem>
</incDir>
@@ -96,7 +99,6 @@
<cTool>
<incDir>
<pElem>plugins/audio</pElem>
- <pElem>/usr/include/uuid</pElem>
</incDir>
</cTool>
</folder>
@@ -111,7 +113,6 @@
<cTool>
<incDir>
<pElem>plugins/samples</pElem>
- <pElem>/usr/include/uuid</pElem>
</incDir>
</cTool>
</folder>
@@ -119,12 +120,33 @@
<cTool>
<incDir>
<pElem>plugins/session</pElem>
- <pElem>/usr/include/uuid</pElem>
</incDir>
+ <preprocessorList>
+ <Elem>__PIC__=2</Elem>
+ <Elem>__REGISTER_PREFIX__=</Elem>
+ <Elem>__USER_LABEL_PREFIX__=</Elem>
+ <Elem>__pic__=2</Elem>
+ </preprocessorList>
</cTool>
</folder>
+ <item path="plugins/audio/audio-alsa.c" ex="false" tool="0" flavor2="2">
+ <cTool flags="1">
+ <incDir>
+ <pElem>include</pElem>
+ <pElem>/usr/include/json-c</pElem>
+ <pElem>/usr/include/uuid</pElem>
+ <pElem>build/plugins</pElem>
+ </incDir>
+ </cTool>
+ </item>
<item path="plugins/audio/audio-api.c" ex="false" tool="0" flavor2="2">
<cTool flags="1">
+ <incDir>
+ <pElem>/usr/include/json-c</pElem>
+ <pElem>include</pElem>
+ <pElem>/usr/include/uuid</pElem>
+ <pElem>build/plugins</pElem>
+ </incDir>
</cTool>
</item>
<item path="plugins/radio/radio-api.c" ex="false" tool="0" flavor2="2">
@@ -132,6 +154,7 @@
<incDir>
<pElem>/usr/include/json-c</pElem>
<pElem>include</pElem>
+ <pElem>plugins/audio</pElem>
<pElem>/usr/include/uuid</pElem>
<pElem>build/plugins</pElem>
</incDir>
@@ -140,6 +163,7 @@
<item path="plugins/radio/radio-rtlsdr.c" ex="false" tool="0" flavor2="2">
<cTool flags="1">
<incDir>
+ <pElem>plugins/audio</pElem>
<pElem>include</pElem>
<pElem>/usr/include/json-c</pElem>
<pElem>/usr/include/uuid</pElem>
@@ -193,6 +217,7 @@
<pElem>build/src</pElem>
</incDir>
<preprocessorList>
+ <Elem>HAVE_AUDIO_PLUGIN=1</Elem>
<Elem>HAVE_RADIO_PLUGIN=1</Elem>
<Elem>__PIC__=2</Elem>
<Elem>__REGISTER_PREFIX__=</Elem>
@@ -225,6 +250,7 @@
<pElem>build/src</pElem>
</incDir>
<preprocessorList>
+ <Elem>HAVE_AUDIO_PLUGIN=1</Elem>
<Elem>HAVE_RADIO_PLUGIN=1</Elem>
<Elem>__PIC__=2</Elem>
<Elem>__REGISTER_PREFIX__=</Elem>
@@ -243,6 +269,7 @@
<pElem>build/src</pElem>
</incDir>
<preprocessorList>
+ <Elem>HAVE_AUDIO_PLUGIN=1</Elem>
<Elem>HAVE_RADIO_PLUGIN=1</Elem>
<Elem>__PIC__=2</Elem>
<Elem>__REGISTER_PREFIX__=</Elem>
@@ -279,6 +306,7 @@
<pElem>build/src</pElem>
</incDir>
<preprocessorList>
+ <Elem>HAVE_AUDIO_PLUGIN=1</Elem>
<Elem>HAVE_RADIO_PLUGIN=1</Elem>
<Elem>__PIC__=2</Elem>
<Elem>__REGISTER_PREFIX__=</Elem>
@@ -297,6 +325,7 @@
<pElem>build/src</pElem>
</incDir>
<preprocessorList>
+ <Elem>HAVE_AUDIO_PLUGIN=1</Elem>
<Elem>HAVE_RADIO_PLUGIN=1</Elem>
<Elem>__PIC__=2</Elem>
<Elem>__REGISTER_PREFIX__=</Elem>
diff --git a/nbproject/private/configurations.xml b/nbproject/private/configurations.xml
index e198cc10..9a82aa63 100644
--- a/nbproject/private/configurations.xml
+++ b/nbproject/private/configurations.xml
@@ -48,7 +48,10 @@
</df>
<df name="plugins">
<df name="audio">
+ <in>audio-alsa.c</in>
+ <in>audio-alsa.h</in>
<in>audio-api.c</in>
+ <in>audio-api.h</in>
</df>
<df name="radio">
<in>radio-api.c</in>
@@ -156,8 +159,6 @@
<gdb_interceptlist>
<gdbinterceptoptions gdb_all="false" gdb_unhandled="true" gdb_unexpected="true"/>
</gdb_interceptlist>
- <gdb_signals>
- </gdb_signals>
<gdb_options>
<DebugOptions>
</DebugOptions>
diff --git a/nbproject/private/private.xml b/nbproject/private/private.xml
index 10916bd0..6d359089 100644
--- a/nbproject/private/private.xml
+++ b/nbproject/private/private.xml
@@ -7,10 +7,15 @@
<editor-bookmarks xmlns="http://www.netbeans.org/ns/editor-bookmarks/2" lastBookmarkId="0"/>
<open-files xmlns="http://www.netbeans.org/ns/projectui-open-files/2">
<group>
- <file>file:/home/mbc/git/afb-daemon-newapi/include/local-def.h</file>
- <file>file:/home/mbc/git/afb-daemon-newapi/src/radio-api.c</file>
- <file>file:/home/mbc/git/afb-daemon-newapi/src/afbs-api.c</file>
- <file>file:/home/mbc/git/afb-daemon-newapi/src/dbus-api.c</file>
+ <file>file:/home/mbc/git/afb-daemon-newapi2/plugins/audio/audio-api.c</file>
+ <file>file:/home/mbc/git/afb-daemon-newapi2/plugins/radio/radio-api.c</file>
+ <file>file:/home/mbc/git/afb-daemon-newapi2/src/main.c</file>
+ <file>file:/home/mbc/git/afb-daemon-newapi2/plugins/radio/radio-api.h</file>
+ <file>file:/home/mbc/git/afb-daemon-newapi2/plugins/audio/audio-alsa.c</file>
+ <file>file:/home/mbc/git/afb-daemon-newapi2/plugins/radio/radio-rtlsdr.c</file>
+ <file>file:/home/mbc/git/afb-daemon-newapi2/include/local-def.h</file>
+ <file>file:/home/mbc/git/afb-daemon-newapi2/plugins/audio/audio-api.h</file>
+ <file>file:/home/mbc/git/afb-daemon-newapi2/plugins/audio/audio-alsa.h</file>
</group>
</open-files>
</project-private>
diff --git a/plugins/audio/audio-alsa.c b/plugins/audio/audio-alsa.c
index c13cdc59..813d8167 100644
--- a/plugins/audio/audio-alsa.c
+++ b/plugins/audio/audio-alsa.c
@@ -58,34 +58,36 @@ PUBLIC unsigned char _alsa_init (const char *name, audioCtxHandleT *ctx) {
snd_mixer_selem_id_set_name (mixer_sid, "Master");
mixer_elm = snd_mixer_find_selem (mixer, mixer_sid);
- snd_mixer_selem_get_playback_volume_range (mixer_elm, &vol_min, &vol_max);
- snd_mixer_selem_get_playback_volume (mixer_elm, SND_MIXER_SCHN_FRONT_LEFT, &vol);
+ if (mixer_elm) {
+ snd_mixer_selem_get_playback_volume_range (mixer_elm, &vol_min, &vol_max);
+ snd_mixer_selem_get_playback_volume (mixer_elm, SND_MIXER_SCHN_FRONT_LEFT, &vol);
+ }
/* allocate the global array if it hasn't been done */
- if (!dev_ctx) {
- dev_ctx = (dev_ctx_T**) malloc (sizeof(dev_ctx_T));
- dev_ctx[0] = (dev_ctx_T*) malloc (sizeof(dev_ctx_T));
- dev_ctx[0]->name = NULL;
- dev_ctx[0]->dev = NULL;
+ if (!adev_ctx) {
+ adev_ctx = (adev_ctx_T**) malloc (sizeof(adev_ctx_T));
+ adev_ctx[0] = (adev_ctx_T*) malloc (sizeof(adev_ctx_T));
+ adev_ctx[0]->name = NULL;
+ adev_ctx[0]->dev = NULL;
}
/* is a card with similar name already opened ? */
- for (num = 0; num < (sizeof(dev_ctx)/sizeof(dev_ctx_T)); num++) {
- if (dev_ctx[num]->name &&
- !strcmp (dev_ctx[num]->name, name))
+ for (num = 0; num < (sizeof(adev_ctx)/sizeof(adev_ctx_T)); num++) {
+ if (adev_ctx[num]->name &&
+ !strcmp (adev_ctx[num]->name, name))
return 0;
}
num++;
/* it's not... let us add it to the global array */
- dev_ctx = (dev_ctx_T**) realloc (dev_ctx, (num+1)*sizeof(dev_ctx_T));
- dev_ctx[num] = (dev_ctx_T*) malloc (sizeof(dev_ctx_T));
- dev_ctx[num]->name = strdup (name);
- dev_ctx[num]->dev = dev;
- dev_ctx[num]->params = params;
- dev_ctx[num]->mixer_elm = mixer_elm;
- dev_ctx[num]->vol_max = vol_max;
- dev_ctx[num]->vol = vol;
+ adev_ctx = (adev_ctx_T**) realloc (adev_ctx, (num+1)*sizeof(adev_ctx_T));
+ adev_ctx[num] = (adev_ctx_T*) malloc (sizeof(adev_ctx_T));
+ adev_ctx[num]->name = strdup (name);
+ adev_ctx[num]->dev = dev;
+ adev_ctx[num]->params = params;
+ adev_ctx[num]->mixer_elm = mixer_elm;
+ adev_ctx[num]->vol_max = vol_max;
+ adev_ctx[num]->vol = vol;
/* make the client context aware of current card state */
ctx->volume = _alsa_get_volume (num);
@@ -99,15 +101,15 @@ PUBLIC void _alsa_free (const char *name) {
int num;
- for (num = 0; num < (sizeof(dev_ctx)/sizeof(dev_ctx_T)); num++) {
- if (dev_ctx[num]->name &&
- !strcmp (dev_ctx[num]->name, name)) {
- snd_pcm_close (dev_ctx[num]->dev);
- snd_pcm_hw_params_free (dev_ctx[num]->params);
- free (dev_ctx[num]->name);
- dev_ctx[num]->name = NULL;
- dev_ctx[num]->dev = NULL;
- free(dev_ctx[num]);
+ for (num = 0; num < (sizeof(adev_ctx)/sizeof(adev_ctx_T)); num++) {
+ if (adev_ctx[num]->name &&
+ !strcmp (adev_ctx[num]->name, name)) {
+ snd_pcm_close (adev_ctx[num]->dev);
+ snd_pcm_hw_params_free (adev_ctx[num]->params);
+ free (adev_ctx[num]->name);
+ adev_ctx[num]->name = NULL;
+ adev_ctx[num]->dev = NULL;
+ free(adev_ctx[num]);
return;
}
}
@@ -115,48 +117,48 @@ PUBLIC void _alsa_free (const char *name) {
PUBLIC void _alsa_play (unsigned int num, void *buf, int len) {
- if (!dev_ctx || !dev_ctx[num])
+ if (!adev_ctx || !adev_ctx[num]) {
return;
-
+ }
int16_t *cbuf = (int16_t *)buf;
int frames = len / 2;
int res;
- if ((res = snd_pcm_writei (dev_ctx[num]->dev, cbuf, frames)) != frames) {
- snd_pcm_recover (dev_ctx[num]->dev, res, 0);
- snd_pcm_prepare (dev_ctx[num]->dev);
+ if ((res = snd_pcm_writei (adev_ctx[num]->dev, cbuf, frames)) != frames) {
+ snd_pcm_recover (adev_ctx[num]->dev, res, 0);
+ snd_pcm_prepare (adev_ctx[num]->dev);
}
- /* snd_pcm_drain (dev_ctx[num]->dev); */
+ /* snd_pcm_drain (adev_ctx[num]->dev); */
}
PUBLIC unsigned int _alsa_get_volume (unsigned int num) {
- if (!dev_ctx || !dev_ctx[num])
+ if (!adev_ctx || !adev_ctx[num] || !adev_ctx[num]->mixer_elm)
return;
- snd_mixer_selem_get_playback_volume (dev_ctx[num]->mixer_elm, SND_MIXER_SCHN_FRONT_LEFT, &dev_ctx[num]->vol);
+ snd_mixer_selem_get_playback_volume (adev_ctx[num]->mixer_elm, SND_MIXER_SCHN_FRONT_LEFT, &adev_ctx[num]->vol);
- return (unsigned int)(dev_ctx[num]->vol*100)/dev_ctx[num]->vol_max;
+ return (unsigned int)(adev_ctx[num]->vol*100)/adev_ctx[num]->vol_max;
}
PUBLIC unsigned int _alsa_set_volume (unsigned int num, unsigned int vol) {
- if (!dev_ctx || !dev_ctx[num] || vol > 100)
+ if (!adev_ctx || !adev_ctx[num] || !adev_ctx[num]->mixer_elm || vol > 100)
return;
- snd_mixer_selem_set_playback_volume_all (dev_ctx[num]->mixer_elm, (vol*dev_ctx[num]->vol_max)/100);
+ snd_mixer_selem_set_playback_volume_all (adev_ctx[num]->mixer_elm, (vol*adev_ctx[num]->vol_max)/100);
}
PUBLIC unsigned char _alsa_get_mute (unsigned int num) {
int mute = 0;
- if (!dev_ctx || !dev_ctx[num])
+ if (!adev_ctx || !adev_ctx[num] || !adev_ctx[num]->mixer_elm)
return;
- if (snd_mixer_selem_has_playback_switch (dev_ctx[num]->mixer_elm)) {
- snd_mixer_selem_get_playback_switch (dev_ctx[num]->mixer_elm, SND_MIXER_SCHN_FRONT_LEFT, &mute);
- snd_mixer_selem_get_playback_switch (dev_ctx[num]->mixer_elm, SND_MIXER_SCHN_FRONT_RIGHT, &mute);
+ if (snd_mixer_selem_has_playback_switch (adev_ctx[num]->mixer_elm)) {
+ snd_mixer_selem_get_playback_switch (adev_ctx[num]->mixer_elm, SND_MIXER_SCHN_FRONT_LEFT, &mute);
+ snd_mixer_selem_get_playback_switch (adev_ctx[num]->mixer_elm, SND_MIXER_SCHN_FRONT_RIGHT, &mute);
}
@@ -165,25 +167,25 @@ PUBLIC unsigned char _alsa_get_mute (unsigned int num) {
PUBLIC void _alsa_set_mute (unsigned int num, unsigned char mute) {
- if (!dev_ctx || !dev_ctx[num] || 1 < mute < 0)
+ if (!adev_ctx || !adev_ctx[num] || !adev_ctx[num]->mixer_elm || 1 < mute < 0)
return;
- if (snd_mixer_selem_has_playback_switch (dev_ctx[num]->mixer_elm))
- snd_mixer_selem_set_playback_switch_all (dev_ctx[num]->mixer_elm, !mute);
+ if (snd_mixer_selem_has_playback_switch (adev_ctx[num]->mixer_elm))
+ snd_mixer_selem_set_playback_switch_all (adev_ctx[num]->mixer_elm, !mute);
}
PUBLIC void _alsa_set_rate (unsigned int num, unsigned int rate) {
- if (!dev_ctx || !dev_ctx[num])
+ if (!adev_ctx || !adev_ctx[num])
return;
- snd_pcm_hw_params_set_rate_near (dev_ctx[num]->dev, dev_ctx[num]->params, &rate, 0);
+ snd_pcm_hw_params_set_rate_near (adev_ctx[num]->dev, adev_ctx[num]->params, &rate, 0);
}
PUBLIC void _alsa_set_channels (unsigned int num, unsigned int channels) {
- if (!dev_ctx || !dev_ctx[num])
+ if (!adev_ctx || !adev_ctx[num])
return;
- snd_pcm_hw_params_set_channels (dev_ctx[num]->dev, dev_ctx[num]->params, channels);
+ snd_pcm_hw_params_set_channels (adev_ctx[num]->dev, adev_ctx[num]->params, channels);
}
diff --git a/plugins/audio/audio-alsa.h b/plugins/audio/audio-alsa.h
index 9a4b0b58..776ac819 100644
--- a/plugins/audio/audio-alsa.h
+++ b/plugins/audio/audio-alsa.h
@@ -23,9 +23,9 @@
#include "local-def.h"
-typedef struct dev_ctx dev_ctx_T;
+typedef struct adev_ctx adev_ctx_T;
-struct dev_ctx {
+struct adev_ctx {
char *name;
snd_pcm_t *dev;
snd_pcm_hw_params_t *params;
@@ -37,6 +37,6 @@ struct dev_ctx {
PUBLIC unsigned int _alsa_get_volume (unsigned int);
PUBLIC unsigned char _alsa_get_mute (unsigned int);
-static struct dev_ctx **dev_ctx = NULL;
+static struct adev_ctx **adev_ctx = NULL;
#endif /* AUDIO_ALSA_H */
diff --git a/plugins/audio/audio-api.c b/plugins/audio/audio-api.c
index fd5f620f..f7897682 100644
--- a/plugins/audio/audio-api.c
+++ b/plugins/audio/audio-api.c
@@ -25,24 +25,24 @@
/* private client context creation ; default values */
STATIC audioCtxHandleT* initAudioCtx () {
- audioCtxHandleT *ctx;
+ audioCtxHandleT *actx;
- ctx = malloc (sizeof(audioCtxHandleT));
- ctx->idx = -1;
- ctx->volume = 25;
- ctx->channels = 2;
- ctx->mute = 0;
+ actx = malloc (sizeof(audioCtxHandleT));
+ actx->idx = -1;
+ actx->volume = 25;
+ actx->channels = 2;
+ actx->mute = 0;
- return ctx;
+ return actx;
}
-STATIC AFB_error releaseAudio (audioCtxHandleT *ctx) {
+STATIC AFB_error releaseAudio (audioCtxHandleT *actx) {
/* power it off */
- _alsa_free (ctx->idx);
+ _alsa_free (actx->idx);
/* clean client context */
- ctx->idx = -1;
+ actx->idx = -1;
return AFB_SUCCESS;
}
@@ -61,15 +61,15 @@ STATIC json_object* freeAudio (AFB_clientCtx *client) {
STATIC json_object* init (AFB_request *request) { /* AFB_SESSION_CREATE */
- audioCtxHandleT *ctx;
+ audioCtxHandleT *actx;
json_object *jresp;
int idx;
/* create a private client context */
- ctx = initAudioCtx();
- request->client->ctx = (audioCtxHandleT*)ctx;
+ actx = initAudioCtx();
+ request->client->ctx = (audioCtxHandleT*)actx;
- _alsa_init("default", ctx);
+ _alsa_init("default", actx);
jresp = json_object_new_object();
json_object_object_add (jresp, "token", json_object_new_string (request->client->token));
@@ -78,7 +78,7 @@ STATIC json_object* init (AFB_request *request) { /* AFB_SESSION_CREATE */
STATIC json_object* volume (AFB_request *request) { /* AFB_SESSION_CHECK */
- audioCtxHandleT *ctx = (audioCtxHandleT*)request->client->ctx;
+ audioCtxHandleT *actx = (audioCtxHandleT*)request->client->ctx;
const char *value = getQueryValue (request, "value");
json_object *jresp;
int volume;
@@ -86,8 +86,8 @@ STATIC json_object* volume (AFB_request *request) { /* AFB_SESSION_CHECK */
/* no "?value=" parameter : return current state */
if (!value) {
- ctx->volume = _alsa_get_volume (ctx->idx);
- snprintf (volume_str, sizeof(volume_str), "%d", ctx->volume);
+ actx->volume = _alsa_get_volume (actx->idx);
+ snprintf (volume_str, sizeof(volume_str), "%d", actx->volume);
jresp = json_object_new_object();
json_object_object_add (jresp, "volume", json_object_new_string(volume_str));
}
@@ -99,10 +99,10 @@ STATIC json_object* volume (AFB_request *request) { /* AFB_SESSION_CHECK */
request->errcode = MHD_HTTP_SERVICE_UNAVAILABLE;
return (jsonNewMessage (AFB_FAIL, "Volume must be between 0 and 100"));
}
- ctx->volume = volume;
- _alsa_set_volume (ctx->idx, ctx->volume);
+ actx->volume = volume;
+ _alsa_set_volume (actx->idx, actx->volume);
- snprintf (volume_str, sizeof(volume_str), "%d", ctx->volume);
+ snprintf (volume_str, sizeof(volume_str), "%d", actx->volume);
jresp = json_object_new_object();
json_object_object_add (jresp, "volume", json_object_new_string(volume_str));
}
@@ -112,23 +112,23 @@ STATIC json_object* volume (AFB_request *request) { /* AFB_SESSION_CHECK */
STATIC json_object* channels (AFB_request *request) { /* AFB_SESSION_CHECK */
- audioCtxHandleT *ctx = (audioCtxHandleT*)request->client->ctx;
+ audioCtxHandleT *actx = (audioCtxHandleT*)request->client->ctx;
const char *value = getQueryValue (request, "value");
json_object *jresp = json_object_new_object();
char channels_str[256];
/* no "?value=" parameter : return current state */
if (!value) {
- snprintf (channels_str, sizeof(channels_str), "%d", ctx->channels);
+ snprintf (channels_str, sizeof(channels_str), "%d", actx->channels);
json_object_object_add (jresp, "channels", json_object_new_string (channels_str));
}
/* "?value=" parameter, set channels */
else {
- ctx->channels = atoi (value);
- _alsa_set_channels (ctx->idx, ctx->channels);
+ actx->channels = atoi (value);
+ _alsa_set_channels (actx->idx, actx->channels);
- snprintf (channels_str, sizeof(channels_str), "%d", ctx->channels);
+ snprintf (channels_str, sizeof(channels_str), "%d", actx->channels);
json_object_object_add (jresp, "channels", json_object_new_string (channels_str));
}
@@ -137,30 +137,30 @@ STATIC json_object* channels (AFB_request *request) { /* AFB_SESSION_CHECK */
STATIC json_object* mute (AFB_request *request) { /* AFB_SESSION_CHECK */
- audioCtxHandleT *ctx = (audioCtxHandleT*)request->client->ctx;
+ audioCtxHandleT *actx = (audioCtxHandleT*)request->client->ctx;
const char *value = getQueryValue (request, "value");
json_object *jresp = json_object_new_object();
/* no "?value=" parameter : return current state */
if (!value) {
- ctx->mute = _alsa_get_mute (ctx->idx);
- ctx->mute ?
+ actx->mute = _alsa_get_mute (actx->idx);
+ actx->mute ?
json_object_object_add (jresp, "mute", json_object_new_string ("on"))
: json_object_object_add (jresp, "mute", json_object_new_string ("off"));
}
/* "?value=" parameter is "1" or "on" */
else if ( atoi(value) == 1 || !strcasecmp(value, "on") ) {
- ctx->mute = 1;
- _alsa_set_mute (ctx->idx, ctx->mute);
+ actx->mute = 1;
+ _alsa_set_mute (actx->idx, actx->mute);
json_object_object_add (jresp, "mute", json_object_new_string ("on"));
}
/* "?value=" parameter is "0" or "off" */
else if ( atoi(value) == 0 || !strcasecmp(value, "off") ) {
- ctx->mute = 0;
- _alsa_set_mute (ctx->idx, ctx->mute);
+ actx->mute = 0;
+ _alsa_set_mute (actx->idx, actx->mute);
json_object_object_add (jresp, "mute", json_object_new_string ("off"));
}
diff --git a/plugins/audio/audio-api.h b/plugins/audio/audio-api.h
index 8acb1bd8..1cf54fc0 100644
--- a/plugins/audio/audio-api.h
+++ b/plugins/audio/audio-api.h
@@ -22,9 +22,9 @@
#include "audio-alsa.h"
/* global plugin handle, should store everything we may need */
-typedef struct {
+/*typedef struct {
int devCount;
-} pluginHandleT;
+} pluginHandleT;*/
/* structure holding one audio card with current usage status */
typedef struct {
diff --git a/plugins/radio/radio-api.c b/plugins/radio/radio-api.c
index f065a8ad..8754b63c 100644
--- a/plugins/radio/radio-api.c
+++ b/plugins/radio/radio-api.c
@@ -298,7 +298,7 @@ STATIC json_object* play (AFB_request *request) { /* AFB_SESSION_CHECK */
/* radio stop */
ctx->is_playing = 0;
_radio_stop (ctx->idx);
- json_object_object_add (jresp, "play-on", json_object_new_string ("off"));
+ json_object_object_add (jresp, "play", json_object_new_string ("off"));
}
return jresp;
diff --git a/plugins/radio/radio-api.h b/plugins/radio/radio-api.h
index 4ea41b1c..0dbd3422 100644
--- a/plugins/radio/radio-api.h
+++ b/plugins/radio/radio-api.h
@@ -21,6 +21,9 @@
#include "radio-rtlsdr.h"
+#include "../audio/audio-api.h"
+#include "../audio/audio-alsa.h"
+
/* -------------- PLUGIN DEFINITIONS ----------------- */
#define MAX_RADIO 10
diff --git a/plugins/radio/radio-rtlsdr.c b/plugins/radio/radio-rtlsdr.c
index e90bda08..e5a609e3 100644
--- a/plugins/radio/radio-rtlsdr.c
+++ b/plugins/radio/radio-rtlsdr.c
@@ -19,6 +19,8 @@
#include "radio-api.h"
#include "radio-rtlsdr.h"
+static audioCtxHandleT *actx = NULL;
+
/* ------------- RADIO RTLSDR IMPLEMENTATION ---------------- */
/* --- PUBLIC FUNCTIONS --- */
@@ -46,6 +48,13 @@ PUBLIC unsigned char _radio_on (unsigned int num, radioCtxHandleT *ctx) {
dev_ctx[num]->output = NULL;
_radio_dev_init(dev_ctx[num], num);
+ actx = malloc (sizeof(audioCtxHandleT));
+ actx->idx = -1;
+ actx->volume = 25;
+ actx->channels = 2;
+ actx->mute = 0;
+ _alsa_init ("default", actx);
+
return 1;
}
@@ -58,7 +67,11 @@ PUBLIC void _radio_off (unsigned int num) {
_radio_dev_free(dev_ctx[num]);
free(dev_ctx[num]);
}
+
/* free(dev_ctx); */
+
+ _alsa_free ("default");
+ free (actx);
}
PUBLIC void _radio_set_mode (unsigned int num, Mode mode) {
@@ -398,8 +411,8 @@ STATIC void* _output_thread_fn (void *ctx) {
while (dev_ctx->should_run) {
pthread_wait(&output->ok, &output->ok_m);
pthread_rwlock_rdlock(&output->lck);
- //if (!dev_ctx->mute)
- // mRadio->PlayAlsa((void*)&output->buf, output->buf_len);
+ if (!dev_ctx->mute)
+ _alsa_play(actx->idx, (void*)&output->buf, output->buf_len);
pthread_rwlock_unlock(&output->lck);
}
diff --git a/src/main.c b/src/main.c
index d45267b7..aa0e9bcd 100644
--- a/src/main.c
+++ b/src/main.c
@@ -510,7 +510,7 @@ int main(int argc, char *argv[]) {
}
// let's not take the risk to run as ROOT
- if (getuid() == 0) goto errorNoRoot;
+ //if (getuid() == 0) goto errorNoRoot;
// check session dir and create if it does not exist
if (sessionCheckdir (session) != AFB_SUCCESS) goto errSessiondir;
@@ -597,9 +597,9 @@ errorSetuid:
fprintf (stderr,"\nERR:AFB-daemon Failed to change UID to username=[%s]\n\n", session->config->setuid);
exit (-1);
-errorNoRoot:
- fprintf (stderr,"\nERR:AFB-daemon Not allow to run as root [use --seteuid=username option]\n\n");
- exit (-1);
+//errorNoRoot:
+// fprintf (stderr,"\nERR:AFB-daemon Not allow to run as root [use --seteuid=username option]\n\n");
+// exit (-1);
errorPidFile:
fprintf (stderr,"\nERR:AFB-daemon Failed to write pid file [%s]\n\n", session->config->pidfile);