Final modifications for Radio-Audio API communication
authorManuel Bachmann <manuel.bachmann@iot.bzh>
Thu, 17 Dec 2015 09:54:24 +0000 (10:54 +0100)
committerManuel Bachmann <manuel.bachmann@iot.bzh>
Thu, 17 Dec 2015 11:09:22 +0000 (12:09 +0100)
Signed-off-by: Manuel Bachmann <manuel.bachmann@iot.bzh>
12 files changed:
include/local-def.h
nbproject/configurations.xml
nbproject/private/configurations.xml
nbproject/private/private.xml
plugins/audio/audio-alsa.c
plugins/audio/audio-alsa.h
plugins/audio/audio-api.c
plugins/audio/audio-api.h
plugins/radio/radio-api.c
plugins/radio/radio-api.h
plugins/radio/radio-rtlsdr.c
src/main.c

index cbbef0f..54f5ce0 100644 (file)
@@ -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
index c9b7be5..ae317b8 100644 (file)
@@ -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>
         <cTool>
           <incDir>
             <pElem>plugins/samples</pElem>
-            <pElem>/usr/include/uuid</pElem>
           </incDir>
         </cTool>
       </folder>
         <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">
           <incDir>
             <pElem>/usr/include/json-c</pElem>
             <pElem>include</pElem>
+            <pElem>plugins/audio</pElem>
             <pElem>/usr/include/uuid</pElem>
             <pElem>build/plugins</pElem>
           </incDir>
       <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>
             <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>
             <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>
             <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>
             <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>
             <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>
index e198cc1..9a82aa6 100644 (file)
       </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>
         <gdb_interceptlist>
           <gdbinterceptoptions gdb_all="false" gdb_unhandled="true" gdb_unexpected="true"/>
         </gdb_interceptlist>
-        <gdb_signals>
-        </gdb_signals>
         <gdb_options>
           <DebugOptions>
           </DebugOptions>
index 10916bd..6d35908 100644 (file)
@@ -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>
index c13cdc5..813d816 100644 (file)
@@ -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);
 }
index 9a4b0b5..776ac81 100644 (file)
@@ -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 */
index fd5f620..f789768 100644 (file)
 /* 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"));
     }
index 8acb1bd..1cf54fc 100644 (file)
@@ -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 {
index f065a8a..8754b63 100644 (file)
@@ -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;
index 4ea41b1..0dbd342 100644 (file)
@@ -21,6 +21,9 @@
 
 #include "radio-rtlsdr.h"
 
+#include "../audio/audio-api.h"
+#include "../audio/audio-alsa.h"
+
 /* -------------- PLUGIN DEFINITIONS ----------------- */
 
 #define MAX_RADIO 10
index e90bda0..e5a609e 100644 (file)
@@ -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);
     }
 
index d45267b..aa0e9bc 100644 (file)
@@ -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);