summaryrefslogtreecommitdiffstats
path: root/plugins/alsa/alsa-softmixer.c
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/alsa/alsa-softmixer.c')
-rw-r--r--plugins/alsa/alsa-softmixer.c95
1 files changed, 55 insertions, 40 deletions
diff --git a/plugins/alsa/alsa-softmixer.c b/plugins/alsa/alsa-softmixer.c
index 253a00b..9586fa3 100644
--- a/plugins/alsa/alsa-softmixer.c
+++ b/plugins/alsa/alsa-softmixer.c
@@ -29,71 +29,86 @@ CTLP_ONLOAD(plugin, callbacks) {
return NULL;
}
+CTLP_LUA2C(AlsaDmix, source, argsJ, responseJ) {
+ json_object* subscribeArgsJ = NULL;
+
+ int error = 0;
+ wrap_json_pack(&subscribeArgsJ, "{ss}", "value", "location");
+ AFB_ApiNotice(source->api, "lua2c router with %s", json_object_to_json_string_ext(subscribeArgsJ, JSON_C_TO_STRING_PRETTY));
+
+ return error;
+}
+
+
CTLP_LUA2C(AlsaRouter, source, argsJ, responseJ) {
- json_object *devInJ, *devOutJ, *paramsJ=NULL;
- AlsaDevByPathT devIn, devOut;
- int err;
+ json_object *sndInJ, *sndOutJ, *paramsJ=NULL;
+ AlsaPcmInfoT *sndIn, *sndOut;
+ int error;
- // init default values
- memset(&devIn,0,sizeof(AlsaDevByPathT));
- memset(&devOut,0,sizeof(AlsaDevByPathT));
- int rate=ALSA_PCM_DEFAULT_RATE;
- int channels=ALSA_PCM_DEFAULT_CHANNELS;
- snd_pcm_format_t format=ALSA_PCM_DEFAULT_FORMAT;
- snd_pcm_access_t access=ALSA_PCM_DEFAULT_ACCESS;
+ // make sndIn/Out a pointer to get cleaner code
+ sndIn=calloc(1, sizeof(AlsaPcmInfoT));
+ sndOut=calloc(1, sizeof(AlsaPcmInfoT));
+ // set pcm options to defaults
+ AlsaPcmHwInfoT *pcmOpts;
+ pcmOpts=calloc(1, sizeof(AlsaPcmHwInfoT));
+ pcmOpts->format=SND_PCM_FORMAT_UNKNOWN;
+ pcmOpts->access=SND_PCM_ACCESS_RW_INTERLEAVED;
- err= wrap_json_unpack(argsJ, "{s:o,s:o,s?o}", "devin", &devInJ, "devout", &devOutJ, "params", &paramsJ);
- if (err) {
+ error= wrap_json_unpack(argsJ, "{s:o,s:o,s?o}", "devin", &sndInJ, "devout", &sndOutJ, "params", &paramsJ);
+ if (error) {
AFB_ApiNotice(source->api, "--lua2c-- AlsaRouter ARGS missing devIn|devOut args=%s", json_object_get_string(argsJ));
goto OnErrorExit;
}
- AFB_ApiNotice(source->api, "--lua2c-- AlsaRouter **** PARAMS missing 'format|access|rate|channels' params=%s", json_object_get_string(paramsJ));
-
- err= wrap_json_unpack(devInJ, "{s?s,s?s,s?i,s?i}", "path", &devIn.devpath, "id",&devIn.devid,"numid",&devIn.numid,"dev", &devIn.device, "sub", &devIn.subdev);
- if (err || (!devIn.devpath && !devIn.devid)) {
- AFB_ApiNotice(source->api, "--lua2c-- AlsaRouter DEV-IN missing 'path|id|dev|sub|numid' devin=%s", json_object_get_string(devInJ));
+ error= wrap_json_unpack(sndInJ, "{s?s,s?s,s?i,s?i,s?i}", "path",&sndIn->devpath, "id",&sndIn->devid, "numid",&sndIn->numid, "dev",&sndIn->device, "sub",&sndIn->subdev);
+ if (error || (!sndIn->devpath && !sndIn->devid)) {
+ AFB_ApiNotice(source->api, "--lua2c-- AlsaRouter DEV-IN missing 'path|id|dev|sub|numid' devin=%s", json_object_get_string(sndInJ));
goto OnErrorExit;
}
- err= wrap_json_unpack(devOutJ, "{s?s,s?s,s?i, s?i,s?i}", "path", &devOut.devpath, "id", &devOut.device, "sub", &devOut.subdev);
- if (err || (!devOut.devpath && !devOut.devid)) {
- AFB_ApiNotice(source->api, "--lua2c-- AlsaRouter DEV-OUT missing 'path|id|dev|sub' devout=%s", json_object_get_string(devOutJ));
+ error= wrap_json_unpack(sndOutJ, "{s?s,s?s,s?i,s?i, s?i}", "path",&sndOut->devpath, "id",&sndOut->devid, "numid",&sndOut->numid,"dev",&sndOut->device, "sub",&sndOut->subdev);
+ if (error || (!sndOut->devpath && !sndOut->devid)) {
+ AFB_ApiNotice(source->api, "--lua2c-- AlsaRouter DEV-OUT missing 'path|id|dev|sub' devout=%s", json_object_get_string(sndOutJ));
goto OnErrorExit;
}
- if (paramsJ) if ((err= wrap_json_unpack(paramsJ, "{s?i, s?i, s?i, s?i}", "format", &format, "access", &access, "rate", &rate, "channels",&channels)) != 0) {
+ if (paramsJ) if ((error= wrap_json_unpack(paramsJ, "{s?i, s?i, s?i, s?i}", "format", &pcmOpts->format, "access", &pcmOpts->access, "rate", &pcmOpts->rate, "channels",&pcmOpts->channels)) != 0) {
AFB_ApiNotice(source->api, "--lua2c-- AlsaRouter PARAMS missing 'format|access|rate|channels' params=%s", json_object_get_string(paramsJ));
goto OnErrorExit;
}
- AFB_ApiNotice(source->api, "--lua2c-- AlsaRouter devIn=%s devOut=%s rate=%d channel=%d", devIn.devpath, devOut.devpath, rate, channels);
-
- // open PCM and start frame copy from binder Mainloop
- snd_pcm_t* pcmIn = AlsaByPathOpenPcm(source, &devIn, SND_PCM_STREAM_CAPTURE);
- snd_pcm_t* pcmOut = AlsaByPathOpenPcm(source, &devOut, SND_PCM_STREAM_PLAYBACK);
- err = AlsaPcmCopy(source, pcmIn, pcmOut, format, access, (unsigned int)rate, (unsigned int)channels);
- if(err) goto OnErrorExit;
+ AFB_ApiNotice(source->api, "--lua2c-- AlsaRouter devin=%s devout=%s rate=%d channel=%d", sndIn->devpath, sndOut->devpath, pcmOpts->rate, pcmOpts->channels);
+
+ // Check sndOut Exist and build a valid devid config
+ error= AlsaByPathDevid (source, sndOut);
+ if (error) goto OnErrorExit;
+
+ //AlsaPcmInfoT *pcmOut = AlsaByPathOpenPcm(source, sndOut, SND_PCM_STREAM_PLAYBACK);
+
+ // open capture PCM
+ AlsaPcmInfoT *pcmIn = AlsaByPathOpenPcm(source, sndIn, SND_PCM_STREAM_CAPTURE);
+ if (!pcmIn) goto OnErrorExit;
+
+ AlsaPcmInfoT *pcmDmix= AlsaCreateDmix(source, "DmixPlugPcm", sndOut);
+ if(!pcmDmix) goto OnErrorExit;
+
+ AlsaPcmInfoT *pcmVol= AlsaCreateVol(source, "SoftVol", sndIn, pcmDmix);
+ if(!pcmVol) goto OnErrorExit;
+
+ error = AlsaPcmCopy(source, pcmIn, pcmVol, pcmOpts);
+ if(error) goto OnErrorExit;
// Registration to event should be done after pcm_start
- if (devIn.numid) {
- err= AlsaCtlRegister(source, pcmIn, devIn.numid);
- if(err) goto OnErrorExit;
+ if (sndIn->numid) {
+ error= AlsaCtlRegister(source, pcmIn, sndIn->numid);
+ if(error) goto OnErrorExit;
}
return 0;
OnErrorExit:
+ AFB_ApiNotice(source->api, "--lua2c-- ERROR AlsaRouter sndIn=%s sndOut=%s rate=%d channel=%d", sndIn->devpath, sndOut->devpath, pcmOpts->rate, pcmOpts->channels);
return -1;
}
-CTLP_LUA2C(AlsaDmix, source, argsJ, responseJ) {
- json_object* subscribeArgsJ = NULL;
-
- int err = 0;
- wrap_json_pack(&subscribeArgsJ, "{ss}", "value", "location");
- AFB_ApiNotice(source->api, "lua2c router with %s", json_object_to_json_string_ext(subscribeArgsJ, JSON_C_TO_STRING_PRETTY));
-
- return err;
-}