changing the license to apache 2
[src/app-framework-binder.git] / plugins / audio / audio-pulse.c
index 4caf3db..d7988d4 100644 (file)
@@ -2,20 +2,22 @@
  * Copyright (C) 2016 "IoT.bzh"
  * Author "Manuel Bachmann"
  *
- * 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 3 of the License, or
- * (at your option) any later version.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
  *
- * 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.
+ *   http://www.apache.org/licenses/LICENSE-2.0
  *
- * You should have received a copy of the GNU General Public License
- * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
  */
 
+#define _GNU_SOURCE
+#include <stdio.h>
+
 #include "audio-api.h"
 #include "audio-pulse.h"
 
@@ -56,7 +58,7 @@ PUBLIC unsigned char _pulse_init (const char *name, audioCtxHandleT *ctx) {
 
         if (ret == -1) {
             if (verbose) fprintf (stderr, "Stopping PulseAudio backend...\n");
-            return -1;
+            return 0;
         }
         if (ret >= 0) {
             /* found a matching sink from callback */
@@ -68,33 +70,35 @@ PUBLIC unsigned char _pulse_init (const char *name, audioCtxHandleT *ctx) {
     }
     /* fail if we found no matching sink */
     if (!ctx->audio_dev)
-      return -1;
+      return 0;
 
     /* make the client context aware of current card state */
     ctx->mute = (unsigned char)dev_ctx_p[ret]->mute;
     ctx->channels = (unsigned int)dev_ctx_p[ret]->volume.channels;
     for (i = 0; i < ctx->channels; i++)
-        ctx->volume[i] = (int)dev_ctx_p[ret]->volume.values[i];
+        ctx->volume[i] = dev_ctx_p[ret]->volume.values[i];
     ctx->idx = ret;
 
     /* open matching sink for playback */
     pa_spec = (pa_sample_spec*) malloc (sizeof(pa_sample_spec));
     pa_spec->format = PA_SAMPLE_S16LE;
     pa_spec->rate = 22050;
-    pa_spec->channels = ctx->channels;
+    pa_spec->channels = (uint8_t)ctx->channels;
 
     if (!(pa = pa_simple_new (NULL, "afb-audio-plugin", PA_STREAM_PLAYBACK, dev_ctx_p[ret]->sink_name,
                               "afb-audio-output", pa_spec, NULL, NULL, &error))) {
         fprintf (stderr, "Error opening PulseAudio sink %s : %s\n",
                           dev_ctx_p[ret]->sink_name, pa_strerror(error));
-        return -1;
+        return 0;
     }
     dev_ctx_p[ret]->pa = pa;
     free (pa_spec);
 
     client_count++;
 
-    return 0;
+    if (verbose) fprintf (stderr, "Successfully initialized PulseAudio backend.\n");
+
+    return 1;
 }
 
 PUBLIC void _pulse_free (audioCtxHandleT *ctx) {
@@ -148,19 +152,19 @@ PUBLIC void _pulse_stop (audioCtxHandleT *ctx) {
     pthread_join (dev_ctx_p_c->thr, NULL);
 }
 
-PUBLIC int _pulse_get_volume (audioCtxHandleT *ctx, unsigned int channel) {
+PUBLIC unsigned int _pulse_get_volume (audioCtxHandleT *ctx, unsigned int channel) {
 
     dev_ctx_pulse_T* dev_ctx_p_c = (dev_ctx_pulse_T*)ctx->audio_dev;
 
     if (!dev_ctx_p_c)
-        return;
+        return 0;
 
     _pulse_refresh_sink (dev_ctx_p_c);
 
-    return (int)dev_ctx_p_c->volume.values[channel];
+    return dev_ctx_p_c->volume.values[channel];
 }
 
-PUBLIC void _pulse_set_volume (audioCtxHandleT *ctx, unsigned int channel, int vol) {
+PUBLIC void _pulse_set_volume (audioCtxHandleT *ctx, unsigned int channel, unsigned int vol) {
 
     dev_ctx_pulse_T* dev_ctx_p_c = (dev_ctx_pulse_T*)ctx->audio_dev;
     struct pa_cvolume volume;
@@ -176,7 +180,7 @@ PUBLIC void _pulse_set_volume (audioCtxHandleT *ctx, unsigned int channel, int v
     _pulse_refresh_sink (dev_ctx_p_c);
 }
 
-PUBLIC void _pulse_set_volume_all (audioCtxHandleT *ctx, int vol) {
+PUBLIC void _pulse_set_volume_all (audioCtxHandleT *ctx, unsigned int vol) {
 
     dev_ctx_pulse_T* dev_ctx_p_c = (dev_ctx_pulse_T*)ctx->audio_dev;
     struct pa_cvolume volume;
@@ -197,7 +201,7 @@ PUBLIC unsigned char _pulse_get_mute (audioCtxHandleT *ctx) {
     dev_ctx_pulse_T* dev_ctx_p_c = (dev_ctx_pulse_T*)ctx->audio_dev;
 
     if (!dev_ctx_p_c)
-        return;
+        return 0;
 
     _pulse_refresh_sink (dev_ctx_p_c);