X-Git-Url: https://gerrit.automotivelinux.org/gerrit/gitweb?a=blobdiff_plain;f=plugins%2Faudio%2Faudio-pulse.c;h=89e5c21ccf1e67c8c3859db0ac20422c293369ed;hb=9481b4f2960c560ec8297bdc37d8014230072a5c;hp=35de7f9a03599e37e078f608d3b9f9cd82f4f9b0;hpb=d438e411f8f743573c79fd2c0a0a528b4a2cadf3;p=src%2Fapp-framework-binder.git diff --git a/plugins/audio/audio-pulse.c b/plugins/audio/audio-pulse.c index 35de7f9a..89e5c21c 100644 --- a/plugins/audio/audio-pulse.c +++ b/plugins/audio/audio-pulse.c @@ -2,24 +2,31 @@ * 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 . + * 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 + #include "audio-api.h" #include "audio-pulse.h" -PUBLIC unsigned char _pulse_init (const char *name, audioCtxHandleT *ctx) { +static struct alsa_info **alsa_info = NULL; +static struct dev_ctx_pulse **dev_ctx_p = NULL; +static unsigned int client_count = 0; + + +unsigned char _pulse_init (const char *name, audioCtxHandleT *ctx) { pa_mainloop *pa_loop; pa_mainloop_api *pa_api; @@ -55,12 +62,12 @@ PUBLIC unsigned char _pulse_init (const char *name, audioCtxHandleT *ctx) { pa_mainloop_iterate (pa_loop, 0, &ret); if (ret == -1) { - if (verbose) fprintf (stderr, "Stopping PulseAudio backend...\n"); + fprintf (stderr, "Stopping PulseAudio backend...\n"); return 0; } if (ret >= 0) { /* found a matching sink from callback */ - if (verbose) fprintf (stderr, "Success : using sink n.%d\n", error); + fprintf (stderr, "Success : using sink n.%d\n", error); ctx->audio_dev = (void*)dev_ctx_p[ret]; break; } @@ -74,14 +81,14 @@ PUBLIC unsigned char _pulse_init (const char *name, audioCtxHandleT *ctx) { 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))) { @@ -94,12 +101,12 @@ PUBLIC unsigned char _pulse_init (const char *name, audioCtxHandleT *ctx) { client_count++; - if (verbose) fprintf (stderr, "Successfully initialized PulseAudio backend.\n"); + fprintf (stderr, "Successfully initialized PulseAudio backend.\n"); return 1; } -PUBLIC void _pulse_free (audioCtxHandleT *ctx) { +void _pulse_free (audioCtxHandleT *ctx) { int num, i; @@ -125,7 +132,7 @@ PUBLIC void _pulse_free (audioCtxHandleT *ctx) { } } -PUBLIC void _pulse_play (audioCtxHandleT *ctx) { +void _pulse_play (audioCtxHandleT *ctx) { dev_ctx_pulse_T* dev_ctx_p_c = (dev_ctx_pulse_T*)ctx->audio_dev; @@ -137,7 +144,7 @@ PUBLIC void _pulse_play (audioCtxHandleT *ctx) { pthread_create (&dev_ctx_p_c->thr, NULL, _pulse_play_thread_fn, (void*)dev_ctx_p_c); } -PUBLIC void _pulse_stop (audioCtxHandleT *ctx) { +void _pulse_stop (audioCtxHandleT *ctx) { dev_ctx_pulse_T* dev_ctx_p_c = (dev_ctx_pulse_T*)ctx->audio_dev; @@ -150,19 +157,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) { +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) { +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; @@ -178,7 +185,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) { +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; @@ -194,19 +201,19 @@ PUBLIC void _pulse_set_volume_all (audioCtxHandleT *ctx, int vol) { _pulse_refresh_sink (dev_ctx_p_c); } -PUBLIC unsigned char _pulse_get_mute (audioCtxHandleT *ctx) { +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); return (unsigned char)dev_ctx_p_c->mute; } -PUBLIC void _pulse_set_mute (audioCtxHandleT *ctx, unsigned char mute) { +void _pulse_set_mute (audioCtxHandleT *ctx, unsigned char mute) { dev_ctx_pulse_T* dev_ctx_p_c = (dev_ctx_pulse_T*)ctx->audio_dev; @@ -330,7 +337,7 @@ char** _pulse_find_cards (const char *name) { /* ---- LOCAL CALLBACK FUNCTIONS ---- */ -STATIC void _pulse_context_cb (pa_context *context, void *data) { +void _pulse_context_cb (pa_context *context, void *data) { pa_context_state_t state = pa_context_get_state (context); dev_ctx_pulse_T *dev_ctx_p_t = (dev_ctx_pulse_T *)data; @@ -344,7 +351,7 @@ STATIC void _pulse_context_cb (pa_context *context, void *data) { pa_context_get_sink_info_list (context, _pulse_sink_list_cb, (void*)dev_ctx_p_t); } -STATIC void _pulse_sink_list_cb (pa_context *context, const pa_sink_info *info, +void _pulse_sink_list_cb (pa_context *context, const pa_sink_info *info, int eol, void *data) { dev_ctx_pulse_T *dev_ctx_p_t = (dev_ctx_pulse_T *)data; @@ -371,7 +378,7 @@ STATIC void _pulse_sink_list_cb (pa_context *context, const pa_sink_info *info, for (i = 0; i < (sizeof(cards)/sizeof(char*)); i++) { if (!strcmp (cards[i], dev_ctx_p_t->card_name[0])) { /* it did : stop there and succeed */ - if (verbose) fprintf (stderr, "Found matching sink : %s\n", info->name); + fprintf (stderr, "Found matching sink : %s\n", info->name); pa_mainloop_quit (dev_ctx_p_t->pa_loop, num); } } @@ -398,13 +405,13 @@ STATIC void _pulse_sink_list_cb (pa_context *context, const pa_sink_info *info, for (i = 0; i < (sizeof(cards)/sizeof(char*)); i++) { if (!strcmp (cards[i], dev_ctx_p_t->card_name[0])) { /* it did : stop there and succeed */ - if (verbose) fprintf (stderr, "Found matching sink : %s\n", info->name); + fprintf (stderr, "Found matching sink : %s\n", info->name); pa_mainloop_quit (dev_ctx_p_t->pa_loop, num); } } } -STATIC void _pulse_sink_info_cb (pa_context *context, const pa_sink_info *info, +void _pulse_sink_info_cb (pa_context *context, const pa_sink_info *info, int eol, void *data) { dev_ctx_pulse_T *dev_ctx_p_c = (dev_ctx_pulse_T *)data; @@ -419,7 +426,7 @@ STATIC void _pulse_sink_info_cb (pa_context *context, const pa_sink_info *info, /* ---- LOCAL THREADED FUNCTIONS ---- */ -STATIC void* _pulse_play_thread_fn (void *ctx) { +void* _pulse_play_thread_fn (void *ctx) { dev_ctx_pulse_T *dev_ctx_p_c = (dev_ctx_pulse_T *)ctx; FILE *file = NULL;