summaryrefslogtreecommitdiffstats
path: root/alsa-binding/Alsa-RegEvt.c
diff options
context:
space:
mode:
Diffstat (limited to 'alsa-binding/Alsa-RegEvt.c')
-rw-r--r--alsa-binding/Alsa-RegEvt.c126
1 files changed, 74 insertions, 52 deletions
diff --git a/alsa-binding/Alsa-RegEvt.c b/alsa-binding/Alsa-RegEvt.c
index 1a803cb..1241e0e 100644
--- a/alsa-binding/Alsa-RegEvt.c
+++ b/alsa-binding/Alsa-RegEvt.c
@@ -242,6 +242,67 @@ STATIC void freeCardAlsaControlHandle(ctrlEvtHandleT **cardControlHandle)
*cardControlHandle = NULL;
}
+STATIC int updatePcmAvailabilityAndFireEvent(pcmEvtHandleT *pcmEventHandle)
+{
+ int err, pcmStatus, subscriberCount = -1;
+
+ char *pcmName;
+
+ json_object *eventJ = NULL;
+
+ pcmStatus = alsaIsPcmAvailableUsingId(pcmEventHandle->card,
+ pcmEventHandle->device,
+ pcmEventHandle->subdevice,
+ pcmEventHandle->stream);
+ if(pcmEventHandle->available == pcmStatus)
+ return 0;
+
+ pcmEventHandle->available = pcmStatus;
+
+ err = asprintf(&pcmName,
+ "hw:%i,%i,%i",
+ pcmEventHandle->card,
+ pcmEventHandle->device,
+ pcmEventHandle->subdevice);
+ if(err <= 0) {
+ AFB_ERROR("Did not succeed to generate pcm name string (card : %i, device : %i, subdevice : %i)",
+ pcmEventHandle->card,
+ pcmEventHandle->device,
+ pcmEventHandle->subdevice);
+ freePcmHandle(pcmEventHandle);
+ return -1;
+ }
+
+ err = wrap_json_pack(&eventJ,
+ "{s:s, s:i, s:i}",
+ "name", pcmName,
+ "stream", pcmEventHandle->stream,
+ "available", pcmEventHandle->available);
+ if(err) {
+ AFB_ERROR("Did not succeed to generate pcm event json info (name : %s, stream : %s, available : %i)",
+ pcmName,
+ (pcmEventHandle->stream == SND_PCM_STREAM_PLAYBACK) ? "playback" : "capture",
+ pcmEventHandle->available);
+ free(pcmName);
+ freePcmHandle(pcmEventHandle);
+ return -2;
+ }
+
+ subscriberCount = afb_event_push(pcmEventHandle->afbevt, eventJ);
+
+ if(! subscriberCount) {
+ AFB_WARNING("Nobody listening for pcm %s hw:%i,%i,%i availability events, stop monitoring from now on",
+ (pcmEventHandle->stream == SND_PCM_STREAM_PLAYBACK) ? "playback" : "capture",
+ pcmEventHandle->card,
+ pcmEventHandle->device,
+ pcmEventHandle->subdevice);
+ freePcmHandle(pcmEventHandle);
+ return -3;
+ }
+
+ return 0;
+}
+
STATIC void updateSelectedAlsaCardsAvailabilityAndFireEvents(sndCardsT *sndCards, int first, int last)
{
int idx, available, subscriberCount = -1;
@@ -291,7 +352,8 @@ STATIC void updateSelectedAlsaCardsAvailabilityAndFireEvents(sndCardsT *sndCards
}
}
-STATIC void updateAllAlsaCardsAvailabilityAndFireEvents(sndCardsT *sndCards) {
+STATIC void updateAllAlsaCardsAvailabilityAndFireEvents(sndCardsT *sndCards)
+{
updateSelectedAlsaCardsAvailabilityAndFireEvents(sndCards, 0, (MAX_SND_CARD - 1));
}
@@ -322,16 +384,14 @@ STATIC int sndCardTimerForCreatedFileCB(TimerHandleT *context)
STATIC int pcmEventCB(sd_event_source* src, int fd, uint32_t revents, void* userData)
{
- int err, pcmStatus, subscriberCount = -1;
+ int err;
ssize_t length, i = 0;
- char buffer[INOTIFY_EVENT_BUF_LEN], *pcmName;
+ char buffer[INOTIFY_EVENT_BUF_LEN];
struct inotify_event *event;
pcmEvtHandleT *pcmEventHandle = (pcmEvtHandleT *) userData;
- json_object *eventJ = NULL;
-
if(revents & EPOLLERR) {
AFB_ERROR("An error has been send by event loop polling, prevent new errors to be fired by deleting event src");
freePcmHandle(pcmEventHandle);
@@ -358,58 +418,20 @@ STATIC int pcmEventCB(sd_event_source* src, int fd, uint32_t revents, void* user
}
if((event->mask & IN_OPEN) || (event->mask & IN_CLOSE)) {
- pcmStatus = alsaIsPcmAvailableUsingId(pcmEventHandle->card,
- pcmEventHandle->device,
- pcmEventHandle->subdevice,
- pcmEventHandle->stream);
- if(pcmEventHandle->available != pcmStatus) {
- pcmEventHandle->available = pcmStatus;
-
- err = asprintf(&pcmName,
- "hw:%i,%i,%i",
- pcmEventHandle->card,
- pcmEventHandle->device,
- pcmEventHandle->subdevice);
- if(err <= 0) {
- AFB_ERROR("Did not succeed to generate pcm name string (card : %i, device : %i, subdevice : %i)",
- pcmEventHandle->card,
- pcmEventHandle->device,
- pcmEventHandle->subdevice);
- freePcmHandle(pcmEventHandle);
- return -4;
- }
-
- err = wrap_json_pack(&eventJ,
- "{s:s, s:i, s:i}",
- "name", pcmName,
- "stream", pcmEventHandle->stream,
- "available", pcmEventHandle->available);
- if(err) {
- AFB_ERROR("Did not succeed to generate pcm event json info (name : %s, stream : %s, available : %i)",
- pcmName,
- (pcmEventHandle->stream == SND_PCM_STREAM_PLAYBACK) ? "playback" : "capture",
- pcmEventHandle->available);
- free(pcmName);
- freePcmHandle(pcmEventHandle);
- return -5;
- }
-
- subscriberCount = afb_event_push(pcmEventHandle->afbevt, eventJ);
+ err = updatePcmAvailabilityAndFireEvent(pcmEventHandle);
+ if(err) {
+ AFB_ERROR("Error %i happened when tried to refresh %s pcm hw:%i,%i,%i availability",
+ err,
+ (pcmEventHandle->stream == SND_PCM_STREAM_PLAYBACK) ? "playback" : "capture",
+ pcmEventHandle->card,
+ pcmEventHandle->device,
+ pcmEventHandle->subdevice);
+ return -4;
}
}
}
}
- if(! subscriberCount) {
- AFB_WARNING("Nobody listening for pcm %s hw:%i,%i,%i availability events, stop monitoring from now on",
- (pcmEventHandle->stream == SND_PCM_STREAM_PLAYBACK) ? "playback" : "capture",
- pcmEventHandle->card,
- pcmEventHandle->device,
- pcmEventHandle->subdevice);
- freePcmHandle(pcmEventHandle);
- return -6;
- }
-
return 0;
}