X-Git-Url: https://gerrit.automotivelinux.org/gerrit/gitweb?a=blobdiff_plain;f=plugins%2Faudio%2Faudio-alsa.c;h=45ff2edb760d17d9ef399f3578ac70de83c7393d;hb=146bb49ca5acf4bbd5d9841398030c29b4333cc6;hp=dde1ba25a09cf279566487d48eeada1a87acb2b1;hpb=a4c89089944e8b101ec39ce19dacf400c16aeabf;p=src%2Fapp-framework-binder.git diff --git a/plugins/audio/audio-alsa.c b/plugins/audio/audio-alsa.c index dde1ba25..45ff2edb 100644 --- a/plugins/audio/audio-alsa.c +++ b/plugins/audio/audio-alsa.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2015 "IoT.bzh" + * Copyright (C) 2015, 2016 "IoT.bzh" * Author "Manuel Bachmann" * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -44,8 +44,10 @@ unsigned char _alsa_init (const char *name, audioCtxHandleT *ctx) { long vol, vol_min, vol_max; int num, i; - if (snd_pcm_open (&dev, name, SND_PCM_STREAM_PLAYBACK, 0) < 0) + if (snd_pcm_open (&dev, name, SND_PCM_STREAM_PLAYBACK, 0) < 0) { + fprintf (stderr, "ALSA backend could not open card '%s'\n", name); return 0; + } snd_pcm_hw_params_malloc (¶ms); snd_pcm_hw_params_any (dev, params); @@ -55,6 +57,7 @@ unsigned char _alsa_init (const char *name, audioCtxHandleT *ctx) { snd_pcm_hw_params_set_channels (dev, params, ctx->channels); if (snd_pcm_hw_params (dev, params) < 0) { snd_pcm_hw_params_free (params); + fprintf (stderr, "ALSA backend could set channels on card '%s'\n", name); return 0; } snd_pcm_prepare (dev); @@ -62,6 +65,7 @@ unsigned char _alsa_init (const char *name, audioCtxHandleT *ctx) { snd_mixer_open (&mixer, 0); if (snd_mixer_attach (mixer, name) < 0) { snd_pcm_hw_params_free (params); + fprintf (stderr, "ALSA backend could not open mixer for card '%s'\n", name); return 0; } snd_mixer_selem_register (mixer, NULL, NULL); @@ -109,14 +113,17 @@ unsigned char _alsa_init (const char *name, audioCtxHandleT *ctx) { /* is a card with similar name already opened ? */ for (num = 0; num < (sizeof(dev_ctx_a)/sizeof(dev_ctx_alsa_T*)); num++) { if (dev_ctx_a[num]->name && - !strcmp (dev_ctx_a[num]->name, name)) + !strcmp (dev_ctx_a[num]->name, name)) { + fprintf (stderr, "Card '%s' already locked by other ALSA backend session\n", name); return 0; + } } - num++; + num--; /* it's not... let us add it to the global array */ dev_ctx_a = (dev_ctx_alsa_T**) realloc (dev_ctx_a, (num+1)*sizeof(dev_ctx_alsa_T*)); - dev_ctx_a[num] = (dev_ctx_alsa_T*) malloc (sizeof(dev_ctx_alsa_T)); + if (!dev_ctx_a[num]) + dev_ctx_a[num] = (dev_ctx_alsa_T*) malloc (sizeof(dev_ctx_alsa_T)); dev_ctx_a[num]->name = strdup (name); dev_ctx_a[num]->dev = dev; dev_ctx_a[num]->params = params; @@ -206,6 +213,7 @@ void _alsa_set_volume_all (int num, unsigned int vol) { if (!dev_ctx_a || !dev_ctx_a[num] || !dev_ctx_a[num]->mixer_elm || vol > 100) + fflush (stdout); /* seems to force this logic to apply quickly */ snd_mixer_selem_set_playback_volume_all (dev_ctx_a[num]->mixer_elm, (vol*dev_ctx_a[num]->vol_max)/100); }