aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorfulup <fulup.arfoll@iot.bzh>2017-07-03 15:38:35 +0200
committerfulup <fulup.arfoll@iot.bzh>2017-07-03 15:38:35 +0200
commit85a4c0a1e0f666505cf2a2922c12e78b3c83c062 (patch)
treea52de3541fca1f7847ab2b083034d93ac8d69205
parent1abf42ee54f669b523bb1a6f4d57d15d78ce0255 (diff)
Moved to V2
-rw-r--r--ALSA-afb/Alsa-AddCtl.c161
-rw-r--r--ALSA-afb/Alsa-SetGet.c12
-rw-r--r--ALSA-afb/Alsa-Ucm.c2
-rw-r--r--HAL-afb/HAL-interface/hal-interface.c54
-rw-r--r--HAL-afb/HAL-plugin/CMakeLists.txt41
-rw-r--r--HAL-afb/HAL-plugin/HalPlugCtl.c267
-rw-r--r--HAL-afb/HAL-plugin/HalPlugPcm.c430
-rw-r--r--HAL-afb/Scarlett-Focusrite/ScarlettUsbHAL.c12
-rw-r--r--conf.d/cmake/config.cmake2
-rw-r--r--nbproject/configurations.xml68
10 files changed, 957 insertions, 92 deletions
diff --git a/ALSA-afb/Alsa-AddCtl.c b/ALSA-afb/Alsa-AddCtl.c
index 2edec5f..5754c15 100644
--- a/ALSA-afb/Alsa-AddCtl.c
+++ b/ALSA-afb/Alsa-AddCtl.c
@@ -13,6 +13,10 @@
* 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.
+ *
+ * References:
+ * https://kernel.readthedocs.io/en/sphinx-samples/writing-an-alsa-driver.html#control-names
+ * https://01.org/linuxgraphics/gfx-docs/drm/sound/designs/control-names.html
*/
#define _GNU_SOURCE // needed for vasprintf
@@ -21,25 +25,95 @@
#include <systemd/sd-event.h>
#include "Alsa-ApiHat.h"
+#include <sys/ioctl.h>
+
+typedef struct _snd_ctl_ops {
+ int (*close)(snd_ctl_t *handle);
+ int (*nonblock)(snd_ctl_t *handle, int nonblock);
+ int (*async)(snd_ctl_t *handle, int sig, pid_t pid);
+ int (*subscribe_events)(snd_ctl_t *handle, int subscribe);
+ int (*card_info)(snd_ctl_t *handle, snd_ctl_card_info_t *info);
+ int (*element_list)(snd_ctl_t *handle, snd_ctl_elem_list_t *list);
+ int (*element_info)(snd_ctl_t *handle, snd_ctl_elem_info_t *info);
+ int (*element_add)(snd_ctl_t *handle, snd_ctl_elem_info_t *info);
+ int (*element_replace)(snd_ctl_t *handle, snd_ctl_elem_info_t *info);
+ int (*element_remove)(snd_ctl_t *handle, snd_ctl_elem_id_t *id);
+ int (*element_read)(snd_ctl_t *handle, snd_ctl_elem_value_t *control);
+ int (*element_write)(snd_ctl_t *handle, snd_ctl_elem_value_t *control);
+ int (*element_lock)(snd_ctl_t *handle, snd_ctl_elem_id_t *lock);
+ int (*element_unlock)(snd_ctl_t *handle, snd_ctl_elem_id_t *unlock);
+ int (*element_tlv)(snd_ctl_t *handle, int op_flag, unsigned int numid,
+ unsigned int *tlv, unsigned int tlv_size);
+ int (*hwdep_next_device)(snd_ctl_t *handle, int *device);
+ int (*hwdep_info)(snd_ctl_t *handle, snd_hwdep_info_t * info);
+ int (*pcm_next_device)(snd_ctl_t *handle, int *device);
+ int (*pcm_info)(snd_ctl_t *handle, snd_pcm_info_t * info);
+ int (*pcm_prefer_subdevice)(snd_ctl_t *handle, int subdev);
+ int (*rawmidi_next_device)(snd_ctl_t *handle, int *device);
+ int (*rawmidi_info)(snd_ctl_t *handle, snd_rawmidi_info_t * info);
+ int (*rawmidi_prefer_subdevice)(snd_ctl_t *handle, int subdev);
+ int (*set_power_state)(snd_ctl_t *handle, unsigned int state);
+ int (*get_power_state)(snd_ctl_t *handle, unsigned int *state);
+ int (*read)(snd_ctl_t *handle, snd_ctl_event_t *event);
+ int (*poll_descriptors_count)(snd_ctl_t *handle);
+ int (*poll_descriptors)(snd_ctl_t *handle, struct pollfd *pfds, unsigned int space);
+ int (*poll_revents)(snd_ctl_t *handle, struct pollfd *pfds, unsigned int nfds, unsigned short *revents);
+} snd_ctl_ops_t;
+
+typedef struct private_snd_ctl {
+ void *open_func;
+ char *name;
+ snd_ctl_type_t type;
+ const snd_ctl_ops_t *ops;
+ void *private_data;
+ int nonblock;
+ int poll_fd;
+ void *async_handlers;
+} private_snd_ctl_t;
+
+typedef struct {
+ int card;
+ int fd;
+ unsigned int protocol;
+} snd_ctl_hw_t;
+
+static int snd_ctl_hw_elem_replace(snd_ctl_t *ctlDev, snd_ctl_elem_info_t *info, snd_ctl_elem_id_t *elemId) {
+ size_t len=snd_ctl_elem_info_sizeof();
+ private_snd_ctl_t *handle= (private_snd_ctl_t*) ctlDev;
+ snd_ctl_hw_t *hw = handle->private_data;
+
+ NOTICE ("count=%d ITEMNAME=%s writable=%d owner=%d", snd_ctl_elem_info_get_count(info), snd_ctl_elem_info_get_name(info)
+ , snd_ctl_elem_info_is_writable(info), snd_ctl_elem_info_get_owner(info));
+ snd_ctl_elem_lock(ctlDev, elemId);
+
+ int err= handle->ops->element_replace (ctlDev, info);
+ NOTICE ("count=%d ITEMNAME=%s writable=%d isowner=%d islocked=%d innactiv=%d", snd_ctl_elem_info_get_count(info), snd_ctl_elem_info_get_name(info)
+ , snd_ctl_elem_info_is_writable(info), snd_ctl_elem_info_is_owner(info), snd_ctl_elem_info_is_locked(info), snd_ctl_elem_info_is_inactive(info));
+ return err;
+}
+
+
STATIC int addOneSndCtl(afb_req request, snd_ctl_t *ctlDev, json_object *ctlJ) {
- int err;
- json_object *jName, *jNumid, *jTmp;
+ int err, ctlExist;
+ json_object *jTmp;
const char *ctlName;
- int ctlNumid, ctlMax, ctlMin, ctlStep, ctlCount, ctlSubDev;
+ int ctlNumid, ctlMax, ctlMin, ctlStep, ctlCount, ctlSubDev, ctlSndDev;
snd_ctl_elem_type_t ctlType;
+ snd_ctl_elem_id_t *elemId;
snd_ctl_elem_info_t *elemInfo;
-
+ snd_ctl_elem_value_t *elemValue;
// parse json ctl object
- json_object_object_get_ex (ctlJ, "name" , &jName);
- json_object_object_get_ex (ctlJ, "numid", &jNumid);
- if (!jName || !jNumid) {
- afb_req_fail_f (request, "ctl-invalid", "crl=%s name/numid missing", json_object_to_json_string(ctlJ));
+ json_object_object_get_ex (ctlJ, "name" , &jTmp);
+ if (!jTmp) {
+ afb_req_fail_f (request, "ctl-invalid", "crl=%s name missing", json_object_get_string(ctlJ));
goto OnErrorExit;
- }
+ }
+ ctlName = json_object_get_string(jTmp);
- ctlName = json_object_to_json_string(jName);
- ctlNumid = json_object_get_int(jNumid);
+ // default value when not present => 0
+ json_object_object_get_ex (ctlJ, "numid" , &jTmp);
+ ctlNumid = json_object_get_int(jTmp);
// default for json_object_get_int is zero
json_object_object_get_ex (ctlJ, "min" , &jTmp);
@@ -57,32 +131,56 @@ STATIC int addOneSndCtl(afb_req request, snd_ctl_t *ctlDev, json_object *ctlJ)
if (!jTmp) ctlCount=2;
else ctlCount = json_object_get_int(jTmp);
+ json_object_object_get_ex (ctlJ, "snddev" , &jTmp);
+ ctlSndDev = json_object_get_int(jTmp);
+
json_object_object_get_ex (ctlJ, "subdev" , &jTmp);
ctlSubDev = json_object_get_int(jTmp);
json_object_object_get_ex (ctlJ, "type" , &jTmp);
- if (!jTmp) ctlType=SND_CTL_ELEM_TYPE_INTEGER;
+ if (!jTmp) ctlType=SND_CTL_ELEM_TYPE_BOOLEAN;
else ctlType = json_object_get_int(jTmp);
- // set info event ID and get value
+ // Add requested ID into elemInfo
snd_ctl_elem_info_alloca(&elemInfo);
- snd_ctl_elem_info_set_name (elemInfo, ctlName); // map ctlInfo to ctlId elemInfo is updated !!!
- snd_ctl_elem_info_set_numid(elemInfo, ctlNumid); // map ctlInfo to ctlId elemInfo is updated !!!
+ snd_ctl_elem_id_alloca(&elemId);
+ snd_ctl_elem_id_set_numid (elemId, ctlNumid);
+ snd_ctl_elem_id_set_name (elemId, ctlName);
+ snd_ctl_elem_id_set_interface(elemId, SND_CTL_ELEM_IFACE_HWDEP);
+ snd_ctl_elem_id_set_device(elemId, ctlSndDev);
+ snd_ctl_elem_id_set_subdevice(elemId, ctlSubDev);
- if (snd_ctl_elem_info(ctlDev, elemInfo) >= 0) {
- afb_req_fail_f (request, "ctl-already-exist", "crl=%s name/numid not unique", json_object_to_json_string(ctlJ));
- goto OnErrorExit;
+ // Assert that this ctls is not used
+ snd_ctl_elem_info_set_id (elemInfo, elemId);
+ ctlExist= !snd_ctl_elem_info(ctlDev, elemInfo);
+ if (ctlExist) {
+ NOTICE ("1:ctl exist ctlName=%s NUMID=%d NAME=%s", ctlName, snd_ctl_elem_info_get_numid(elemInfo), snd_ctl_elem_info_get_name(elemInfo));
+ snd_ctl_elem_id_set_name (elemId, ctlName);
+ snd_ctl_elem_info_set_name (elemInfo, ctlName);
+ err= snd_ctl_hw_elem_replace (ctlDev, elemInfo, elemId);
+ if (err) {
+ NOTICE ("Fail changing ctlname error=%s", snd_strerror(err));
+ }
+ NOTICE ("2:ctl exist ctlName=%s NUMID=%d NAME=%s", ctlName, snd_ctl_elem_info_get_numid(elemInfo), snd_ctl_elem_info_get_name(elemInfo));
}
-
- snd_ctl_elem_info_set_subdevice(elemInfo, ctlSubDev);
-
- switch (ctlType) {
+
+ // try to normalise ctl name
+ snd_ctl_elem_value_alloca(&elemValue);
+ snd_ctl_elem_id_set_name (elemId, ctlName);
+ snd_ctl_elem_value_set_id(elemValue, elemId);
+
+ if (!ctlExist) switch (ctlType) {
case SND_CTL_ELEM_TYPE_BOOLEAN:
err = snd_ctl_add_boolean_elem_set(ctlDev, elemInfo, 1, ctlCount);
if (err) {
- afb_req_fail_f (request, "ctl-invalid-bool", "crl=%s invalid boolean data", json_object_to_json_string(ctlJ));
+ afb_req_fail_f (request, "ctl-invalid-bool", "devid=%s crl=%s invalid boolean data", snd_ctl_name(ctlDev), json_object_get_string(ctlJ));
goto OnErrorExit;
}
+
+ // Provide FALSE as default value
+ for (int idx=0; idx < ctlCount; idx ++) {
+ snd_ctl_elem_value_set_boolean (elemValue, idx, 0);
+ }
break;
case SND_CTL_ELEM_TYPE_INTEGER:
@@ -98,9 +196,16 @@ STATIC int addOneSndCtl(afb_req request, snd_ctl_t *ctlDev, json_object *ctlJ)
break;
default:
- afb_req_fail_f (request, "ctl-invalid-type", "crl=%s invalid/unknown type", json_object_to_json_string(ctlJ));
+ afb_req_fail_f (request, "ctl-invalid-type", "crl=%s invalid/unknown type", json_object_get_string(ctlJ));
goto OnErrorExit;
- }
+ }
+
+ err = snd_ctl_elem_write (ctlDev, elemValue);
+ if (err < 0) {
+ afb_req_fail_f (request, "ctl-write-fail", "crl=%s fail to write data data", json_object_get_string(ctlJ));
+ goto OnErrorExit;
+ }
+
return 0;
@@ -122,7 +227,7 @@ PUBLIC void alsaAddCustomCtls(afb_req request) {
}
// open control interface for devid
- err = snd_ctl_open(&ctlDev, devid, SND_CTL_READONLY);
+ err = snd_ctl_open(&ctlDev, devid, 0);
if (err < 0) {
afb_req_fail_f (request, "devid-unknown", "SndCard devid=[%s] Not Found err=%s", devid, snd_strerror(err));
goto OnErrorExit;
@@ -141,14 +246,14 @@ PUBLIC void alsaAddCustomCtls(afb_req request) {
break;
case json_type_array:
- for (int idx= 1; idx < json_object_array_length (ctlsJ); idx++) {
+ for (int idx= 0; idx < json_object_array_length (ctlsJ); idx++) {
json_object *ctlJ = json_object_array_get_idx (ctlsJ, idx);
addOneSndCtl(request, ctlDev, ctlJ) ;
}
break;
default:
- afb_req_fail_f (request, "ctls-invalid","ctls=%s not valid JSON array", json_object_to_json_string(ctlsJ));
+ afb_req_fail_f (request, "ctls-invalid","ctls=%s not valid JSON array", json_object_get_string(ctlsJ));
goto OnErrorExit;
}
diff --git a/ALSA-afb/Alsa-SetGet.c b/ALSA-afb/Alsa-SetGet.c
index 280078c..9d0ec43 100644
--- a/ALSA-afb/Alsa-SetGet.c
+++ b/ALSA-afb/Alsa-SetGet.c
@@ -95,7 +95,7 @@ PUBLIC int alsaCheckQuery (afb_req request, queryValuesT *queryValues) {
else if (rqtQuiet && ! sscanf (rqtQuiet, "%d", &queryValues->quiet)) {
json_object *query = afb_req_json(request);
- afb_req_fail_f (request, "quiet-notinteger","Query=%s Quiet not integer &quiet=%s&", json_object_to_json_string(query), rqtQuiet);
+ afb_req_fail_f (request, "quiet-notinteger","Query=%s Quiet not integer &quiet=%s&", json_object_get_string(query), rqtQuiet);
goto OnErrorExit;
};
@@ -457,13 +457,13 @@ PUBLIC int alsaSetSingleCtl (snd_ctl_t *ctlDev, snd_ctl_elem_id_t *elemId, ctlRe
snd_ctl_elem_info_alloca(&elemInfo);
snd_ctl_elem_info_set_id(elemInfo, elemId); // map ctlInfo to ctlId elemInfo is updated !!!
if (snd_ctl_elem_info(ctlDev, elemInfo) < 0) {
- AFB_NOTICE( "Fail to load ALSA NUMID=%d Values=[%s]", ctlRequest->numId, json_object_to_json_string(ctlRequest->jValues));
+ AFB_NOTICE( "Fail to load ALSA NUMID=%d Values=[%s]", ctlRequest->numId, json_object_get_string(ctlRequest->jValues));
goto OnErrorExit;
}
snd_ctl_elem_info_get_id(elemInfo, elemId); // map ctlInfo to ctlId elemInfo is updated !!!
if (!snd_ctl_elem_info_is_writable(elemInfo)) {
- AFB_NOTICE( "Not Writable ALSA NUMID=%d Values=[%s]", ctlRequest->numId, json_object_to_json_string(ctlRequest->jValues));
+ AFB_NOTICE( "Not Writable ALSA NUMID=%d Values=[%s]", ctlRequest->numId, json_object_get_string(ctlRequest->jValues));
goto OnErrorExit;
}
@@ -488,7 +488,7 @@ PUBLIC int alsaSetSingleCtl (snd_ctl_t *ctlDev, snd_ctl_elem_id_t *elemId, ctlRe
if (count == 0 || count < length) {
- AFB_NOTICE( "Invalid values NUMID='%d' Values='%s' count='%d' wanted='%d'", ctlRequest->numId, json_object_to_json_string(ctlRequest->jValues), length, count);
+ AFB_NOTICE( "Invalid values NUMID='%d' Values='%s' count='%d' wanted='%d'", ctlRequest->numId, json_object_get_string(ctlRequest->jValues), length, count);
goto OnErrorExit;
}
@@ -510,7 +510,7 @@ PUBLIC int alsaSetSingleCtl (snd_ctl_t *ctlDev, snd_ctl_elem_id_t *elemId, ctlRe
err = snd_ctl_elem_write(ctlDev, elemData);
if (err < 0) {
- AFB_NOTICE( "Fail to write ALSA NUMID=%d Values=[%s] Error=%s", ctlRequest->numId, json_object_to_json_string(ctlRequest->jValues), snd_strerror(err));
+ AFB_NOTICE( "Fail to write ALSA NUMID=%d Values=[%s] Error=%s", ctlRequest->numId, json_object_get_string(ctlRequest->jValues), snd_strerror(err));
goto OnErrorExit;
}
@@ -762,7 +762,7 @@ STATIC void alsaSetGetCtls (afb_req request, ActionSetGetT action) {
*/
}
- if (json_object_array_length(warnings)) warmsg=json_object_to_json_string_ext(warnings, JSON_C_TO_STRING_PLAIN);
+ if (json_object_array_length(warnings)) warmsg=json_object_get_string (warnings);
else json_object_put(warnings);
// send response+warning if any
diff --git a/ALSA-afb/Alsa-Ucm.c b/ALSA-afb/Alsa-Ucm.c
index c9ee4f9..bc492b3 100644
--- a/ALSA-afb/Alsa-Ucm.c
+++ b/ALSA-afb/Alsa-Ucm.c
@@ -310,7 +310,7 @@ PUBLIC void alsaUseCaseGet (struct afb_req request) {
if (json_object_array_length (jWarnings) > 0) {
json_object *jTmp = json_object_new_object ();
json_object_object_add (jTmp, "no-context", jWarnings);
- warnings= json_object_to_json_string (jTmp);
+ warnings= json_object_get_string (jTmp);
}
afb_req_success (request, jResponse, warnings);
diff --git a/HAL-afb/HAL-interface/hal-interface.c b/HAL-afb/HAL-interface/hal-interface.c
index 29c5e88..035278b 100644
--- a/HAL-afb/HAL-interface/hal-interface.c
+++ b/HAL-afb/HAL-interface/hal-interface.c
@@ -222,13 +222,13 @@ OnExit:
// This receive all event this binding subscribe to
PUBLIC void halServiceEvent(const char *evtname, struct json_object *object) {
- AFB_NOTICE("afbBindingV1ServiceEvent evtname=%s [msg=%s]", evtname, json_object_to_json_string(object));
+ AFB_NOTICE("afbBindingV1ServiceEvent evtname=%s [msg=%s]", evtname, json_object_get_string(object));
}
// this is call when after all bindings are loaded
PUBLIC int halServiceInit (const char *apiPrefix, alsaHalSndCardT *alsaHalSndCard) {
int ok, err;
- struct json_object *queryurl, *responseJ, *devidJ, *tmpJ;
+ struct json_object *queryurl, *responseJ, *devidJ, *ctlsJ, *tmpJ;
halCtls = alsaHalSndCard->ctls; // Get sndcard specific HAL control mapping
err= afb_daemon_require_api("alsacore", 1);
@@ -245,38 +245,44 @@ PUBLIC int halServiceInit (const char *apiPrefix, alsaHalSndCardT *alsaHalSndCar
ok= afb_service_call_sync ("alsacore", "registerHal", queryurl, &responseJ);
json_object_put(queryurl);
if (!ok) {
- NOTICE ("Fail to register HAL to ALSA lowlevel binding Response=[%s]", json_object_to_json_string(responseJ));
+ NOTICE ("Fail to register HAL to ALSA lowlevel binding Response=[%s]", json_object_get_string(responseJ));
goto OnErrorExit;
}
// extract sound devid from HAL registration
if (!json_object_object_get_ex(responseJ, "response", &tmpJ) || !json_object_object_get_ex(tmpJ, "devid", &devidJ)) {
- AFB_ERROR ("Ooops: Internal error no devid return from HAL registration Response=[%s]", json_object_to_json_string(responseJ));
+ AFB_ERROR ("Ooops: Internal error no devid return from HAL registration Response=[%s]", json_object_get_string(responseJ));
goto OnErrorExit;
}
+
+
// for each Non Alsa Control callback create a custom control
+ ctlsJ= json_object_new_array();
for (int idx = 0; halCtls[idx].alsa.numid != 0; idx++) {
- if (halCtls[idx].cb.callback != NULL) {
- queryurl = json_object_new_object();
- json_object_object_add(queryurl, "devid",devidJ);
- tmpJ = json_object_new_object();
- if (halCtls[idx].alsa.name) json_object_object_add(tmpJ, "name" , json_object_new_string(halCtls[idx].alsa.name));
- if (halCtls[idx].alsa.numid) json_object_object_add(tmpJ, "numid" , json_object_new_int(halCtls[idx].alsa.numid));
- if (halCtls[idx].alsa.minval) json_object_object_add(tmpJ, "minval", json_object_new_int(halCtls[idx].alsa.minval));
- if (halCtls[idx].alsa.maxval) json_object_object_add(tmpJ, "maxval", json_object_new_int(halCtls[idx].alsa.maxval));
- if (halCtls[idx].alsa.step) json_object_object_add(tmpJ, "step" , json_object_new_int(halCtls[idx].alsa.step));
- if (halCtls[idx].alsa.type) json_object_object_add(tmpJ, "type" , json_object_new_int(halCtls[idx].alsa.type));
- json_object_object_add(queryurl, "ctls",tmpJ);
-
- AFB_NOTICE("QUERY=%s", json_object_to_json_string(queryurl));
-
- ok= afb_service_call_sync ("alsacore", "addcustomctl", queryurl, &responseJ);
- if (!ok) {
- AFB_ERROR ("Fail to add Customer Sound Control for ctrl=[%s] Response=[%s]", halCtls[idx].alsa.name, json_object_to_json_string(responseJ));
- goto OnErrorExit;
- }
- }
+ struct json_object *ctlJ;
+ if (halCtls[idx].alsa.numid != 0 || halCtls[idx].cb.callback != NULL) {
+ ctlJ = json_object_new_object();
+ if (halCtls[idx].alsa.name) json_object_object_add(ctlJ, "name" , json_object_new_string(halCtls[idx].alsa.name));
+ if (halCtls[idx].alsa.numid) json_object_object_add(ctlJ, "numid" , json_object_new_int(halCtls[idx].alsa.numid));
+ if (halCtls[idx].alsa.minval) json_object_object_add(ctlJ, "minval", json_object_new_int(halCtls[idx].alsa.minval));
+ if (halCtls[idx].alsa.maxval) json_object_object_add(ctlJ, "maxval", json_object_new_int(halCtls[idx].alsa.maxval));
+ if (halCtls[idx].alsa.step) json_object_object_add(ctlJ, "step" , json_object_new_int(halCtls[idx].alsa.step));
+ if (halCtls[idx].alsa.type) json_object_object_add(ctlJ, "type" , json_object_new_int(halCtls[idx].alsa.type));
+ json_object_array_add(ctlsJ, ctlJ);
+ }
+ }
+
+ // Build new queryJ to add HAL custom control if any
+ if (json_object_array_length (ctlsJ) > 0) {
+ queryurl = json_object_new_object();
+ json_object_object_add(queryurl, "devid",devidJ);
+ json_object_object_add(queryurl, "ctls",ctlsJ);
+ ok= afb_service_call_sync ("alsacore", "addcustomctl", queryurl, &responseJ);
+ if (!ok) {
+ AFB_ERROR ("Fail creating HAL Custom ALSA ctls Response=[%s]", json_object_get_string(responseJ));
+ goto OnErrorExit;
+ }
}
// finally register for alsa lowlevel event
diff --git a/HAL-afb/HAL-plugin/CMakeLists.txt b/HAL-afb/HAL-plugin/CMakeLists.txt
new file mode 100644
index 0000000..73390b8
--- /dev/null
+++ b/HAL-afb/HAL-plugin/CMakeLists.txt
@@ -0,0 +1,41 @@
+###########################################################################
+# Copyright 2015, 2016, 2017 IoT.bzh
+#
+# author: Fulup Ar Foll <fulup@iot.bzh>
+#
+# 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
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# 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.
+###########################################################################
+
+
+# Add target to project dependency list
+PROJECT_TARGET_ADD(hal-ctl-plugin)
+
+ # Define targets
+ ADD_LIBRARY(hal-ctl-plugin MODULE HalPlugCtl.c)
+
+ # Alsa Plugin properties
+ SET_TARGET_PROPERTIES(hal-ctl-plugin PROPERTIES
+ PREFIX "alsa-"
+ OUTPUT_NAME ${TARGET_NAME}
+ )
+
+PROJECT_TARGET_ADD(hal-pcm-plugin)
+
+ # Define targets
+ ADD_LIBRARY(hal-pcm-plugin MODULE HalPlugPcm.c)
+
+ # Alsa Plugin properties
+ SET_TARGET_PROPERTIES(hal-pcm-plugin PROPERTIES
+ PREFIX "alsa-"
+ OUTPUT_NAME ${TARGET_NAME}
+ )
diff --git a/HAL-afb/HAL-plugin/HalPlugCtl.c b/HAL-afb/HAL-plugin/HalPlugCtl.c
new file mode 100644
index 0000000..21e7cfc
--- /dev/null
+++ b/HAL-afb/HAL-plugin/HalPlugCtl.c
@@ -0,0 +1,267 @@
+/*
+ * Copyright (C) 2016 "IoT.bzh"
+ * Author Fulup Ar Foll <fulup@iot.bzh>
+ *
+ * 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
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * 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.
+ *
+ */
+
+
+#include <stdio.h>
+#include <sys/ioctl.h>
+#include <alsa/asoundlib.h>
+#include <alsa/control_external.h>
+#include <linux/soundcard.h>
+
+typedef struct afbHalPlug {
+ snd_ctl_ext_t ext;
+ char *device;
+ unsigned int num_vol_ctls;
+ unsigned int num_rec_items;
+ unsigned int vol_ctl[SOUND_MIXER_NRDEVICES];
+ unsigned int rec_item[SOUND_MIXER_NRDEVICES];
+} afbHalPlug_t;
+
+static const char *const vol_devices[SOUND_MIXER_NRDEVICES] = {
+ [SOUND_MIXER_VOLUME] = "Master Playback Volume",
+ [SOUND_MIXER_BASS] = "Tone Control - Bass",
+ [SOUND_MIXER_TREBLE] = "Tone Control - Treble",
+ [SOUND_MIXER_SYNTH] = "Synth Playback Volume",
+ [SOUND_MIXER_PCM] = "PCM Playback Volume",
+ [SOUND_MIXER_SPEAKER] = "PC Speaker Playback Volume",
+ [SOUND_MIXER_LINE] = "Line Playback Volume",
+ [SOUND_MIXER_MIC] = "Mic Playback Volume",
+ [SOUND_MIXER_CD] = "CD Playback Volume",
+ [SOUND_MIXER_IMIX] = "Monitor Mix Playback Volume",
+ [SOUND_MIXER_ALTPCM] = "Headphone Playback Volume",
+ [SOUND_MIXER_RECLEV] = "Capture Volume",
+ [SOUND_MIXER_IGAIN] = "Capture Volume",
+ [SOUND_MIXER_OGAIN] = "Playback Volume",
+ [SOUND_MIXER_LINE1] = "Aux Playback Volume",
+ [SOUND_MIXER_LINE2] = "Aux1 Playback Volume",
+ [SOUND_MIXER_LINE3] = "Line1 Playback Volume",
+ [SOUND_MIXER_DIGITAL1] = "IEC958 Playback Volume",
+ [SOUND_MIXER_DIGITAL2] = "Digital Playback Volume",
+ [SOUND_MIXER_DIGITAL3] = "Digital1 Playback Volume",
+ [SOUND_MIXER_PHONEIN] = "Phone Playback Volume",
+ [SOUND_MIXER_PHONEOUT] = "Master Mono Playback Volume",
+ [SOUND_MIXER_VIDEO] = "Video Playback Volume",
+ [SOUND_MIXER_RADIO] = "Radio Playback Volume",
+ [SOUND_MIXER_MONITOR] = "Monitor Playback Volume",
+};
+
+static const char *const rec_devices[SOUND_MIXER_NRDEVICES] = {
+ [SOUND_MIXER_VOLUME] = "Mix Capture Switch",
+ [SOUND_MIXER_SYNTH] = "Synth Capture Switch",
+ [SOUND_MIXER_PCM] = "PCM Capture Switch",
+ [SOUND_MIXER_LINE] = "Line Capture Switch",
+ [SOUND_MIXER_MIC] = "Mic Capture Switch",
+ [SOUND_MIXER_CD] = "CD Capture Switch",
+ [SOUND_MIXER_LINE1] = "Aux Capture Switch",
+ [SOUND_MIXER_LINE2] = "Aux1 Capture Switch",
+ [SOUND_MIXER_LINE3] = "Line1 Capture Switch",
+ [SOUND_MIXER_DIGITAL1] = "IEC958 Capture Switch",
+ [SOUND_MIXER_DIGITAL2] = "Digital Capture Switch",
+ [SOUND_MIXER_DIGITAL3] = "Digital1 Capture Switch",
+ [SOUND_MIXER_PHONEIN] = "Phone Capture Switch",
+ [SOUND_MIXER_VIDEO] = "Video Capture Switch",
+ [SOUND_MIXER_RADIO] = "Radio Capture Switch",
+};
+
+static const char *const rec_items[SOUND_MIXER_NRDEVICES] = {
+ [SOUND_MIXER_VOLUME] = "Mix",
+ [SOUND_MIXER_SYNTH] = "Synth",
+ [SOUND_MIXER_PCM] = "PCM",
+ [SOUND_MIXER_LINE] = "Line",
+ [SOUND_MIXER_MIC] = "Mic",
+ [SOUND_MIXER_CD] = "CD",
+ [SOUND_MIXER_LINE1] = "Aux",
+ [SOUND_MIXER_LINE2] = "Aux1",
+ [SOUND_MIXER_LINE3] = "Line1",
+ [SOUND_MIXER_DIGITAL1] = "IEC958",
+ [SOUND_MIXER_DIGITAL2] = "Digital",
+ [SOUND_MIXER_DIGITAL3] = "Digital1",
+ [SOUND_MIXER_PHONEIN] = "Phone",
+ [SOUND_MIXER_VIDEO] = "Video",
+ [SOUND_MIXER_RADIO] = "Radio",
+};
+
+
+
+
+static snd_ctl_ext_key_t AfbHalElemFind(snd_ctl_ext_t *ext,
+ const snd_ctl_elem_id_t *id) {
+
+ snd_ctl_hal_t *ctlHal = ext->private_data;
+ const char *name;
+ unsigned int i, key, numid;
+
+ numid = snd_ctl_elem_id_get_numid(id);
+ if (numid > 0) {
+ numid--;
+ if (numid < afbHalPlug->num_vol_ctls)
+ return afbHalPlug->vol_ctl[numid];
+ numid -= afbHalPlug->num_vol_ctls;
+ if (afbHalPlug->exclusive_input) {
+ if (!numid)
+ return OSS_KEY_CAPTURE_MUX;
+ } else if (numid < afbHalPlug->num_rec_items)
+ return afbHalPlug->rec_item[numid] |
+ OSS_KEY_CAPTURE_FLAG;
+ }
+
+ name = snd_ctl_elem_id_get_name(id);
+ if (! strcmp(name, "Capture Source")) {
+ if (afbHalPlug->exclusive_input)
+ return OSS_KEY_CAPTURE_MUX;
+ else
+ return SND_CTL_EXT_KEY_NOT_FOUND;
+ }
+ for (i = 0; i < afbHalPlug->num_vol_ctls; i++) {
+ key = afbHalPlug->vol_ctl[i];
+ if (! strcmp(name, vol_devices[key]))
+ return key;
+ }
+ for (i = 0; i < afbHalPlug->num_rec_items; i++) {
+ key = afbHalPlug->rec_item[i];
+ if (! strcmp(name, rec_devices[key]))
+ return key | OSS_KEY_CAPTURE_FLAG;
+ }
+ return SND_CTL_EXT_KEY_NOT_FOUND;
+}
+
+static int AfbHalGetAttrib(snd_ctl_ext_t *ext, snd_ctl_ext_key_t key,
+ int *type, unsigned int *acc, unsigned int *count) {
+ return 0;
+}
+
+static int AfbHalGetInfo(snd_ctl_ext_t *ext ATTRIBUTE_UNUSED,
+ snd_ctl_ext_key_t key ATTRIBUTE_UNUSED,
+ long *imin, long *imax, long *istep) {
+
+ return 0;
+}
+
+static int AfbHalGetEnumInfo(snd_ctl_ext_t *ext,
+ snd_ctl_ext_key_t key ATTRIBUTE_UNUSED,
+ unsigned int *items) {
+
+ return 0;
+}
+
+static int AfbHalGetEnumName(snd_ctl_ext_t *ext,
+ snd_ctl_ext_key_t key ATTRIBUTE_UNUSED,
+ unsigned int item, char *name,
+ size_t name_max_len) {
+
+ return 0;
+}
+
+static int AfbHalReadInt(snd_ctl_ext_t *ext, snd_ctl_ext_key_t key, long *value) {
+
+ return 0;
+}
+
+static int AfbHalReadEnumerate(snd_ctl_ext_t *ext,
+ snd_ctl_ext_key_t key ATTRIBUTE_UNUSED,
+ unsigned int *items) {
+
+ return 0;
+}
+
+static int AfbHalWriteInt(snd_ctl_ext_t *ext, snd_ctl_ext_key_t key, long *value) {
+
+ return 0;
+}
+
+static int AfbHalWriteEnum(snd_ctl_ext_t *ext,
+ snd_ctl_ext_key_t key ATTRIBUTE_UNUSED,
+ unsigned int *items) {
+
+ return 0;
+}
+
+static int AfbHalEventRead(snd_ctl_ext_t *ext ATTRIBUTE_UNUSED,
+ snd_ctl_elem_id_t *id ATTRIBUTE_UNUSED,
+ unsigned int *event_mask ATTRIBUTE_UNUSED)
+{
+ return -EAGAIN;
+}
+
+static snd_ctl_ext_callback_t afbHalCBs = {
+ .close = AfbHalClose,
+ .elem_count = AfbHalElemCount,
+ .elem_list = AfbHalElemList,
+ .find_elem = AfbHalElemFind,
+ .get_attribute = AfbHalGetAttrib,
+ .get_integer_info = AfbHalGetInfo,
+ .get_enumerated_info = AfbHalGetEnumInfo,
+ .get_enumerated_name = AfbHalGetEnumName,
+ .read_integer = AfbHalReadInt,
+ .read_enumerated = AfbHalReadEnumerate,
+ .write_integer = AfbHalWriteInt,
+ .write_enumerated = AfbHalWriteEnum,
+ .read_event = AfbHalEventRead,
+};
+
+
+SND_CTL_PLUGIN_DEFINE_FUNC(afb_hal) {
+
+ snd_config_iterator_t it, next;
+ afbHalPlug_t *afbHalPlug;
+ int err;
+
+ snd_config_for_each(it, next, conf) {
+ snd_config_t *n = snd_config_iterator_entry(it);
+ const char *id;
+ if (snd_config_get_id(n, &id) < 0)
+ continue;
+ if (strcmp(id, "comment") == 0 || strcmp(id, "type") == 0 || strcmp(id, "hint") == 0)
+ continue;
+ if (strcmp(id, "slave") == 0) {
+ if (snd_config_get_string(n, &device) < 0) {
+ SNDERR("Invalid type for %s", id);
+ return -EINVAL;
+ }
+ continue;
+ }
+ SNDERR("Unknown field %s", id);
+ return -EINVAL;
+ }
+
+ // Create ALSA control plugin structure
+ afbHalPlug->ext.version = SND_CTL_EXT_VERSION;
+ afbHalPlug->ext.card_idx = 0; /* FIXME */
+ strcpy(afbHalPlug->ext.id, "AFB-HAL-CTL");
+ strcpy(afbHalPlug->ext.driver, "AFB-HAL");
+ strcpy(afbHalPlug->ext.name, "AFB-HAL Control Plugin");
+ strcpy(afbHalPlug->ext.mixername, "AFB-HAL Mixer Plugin");
+ strcpy(afbHalPlug->ext.longname, "Automotive-Linux Sound Abstraction Control Plugin");
+ afbHalPlug->ext.poll_fd = -1;
+ afbHalPlug->ext.callback = &afbHalCBs;
+ afbHalPlug->ext.private_data = afbHalPlug;
+
+
+ err = snd_ctl_ext_create(&afbHalPlug->ext, name, mode);
+ if (err < 0) goto OnErrorExit;
+
+ // Plugin register controls update handlep before exiting
+ *handlep = afbHalPlug->ext.handle;
+ return 0;
+
+OnErrorExit:
+ free(afbHalPlug);
+ return -1;
+}
+
+SND_CTL_PLUGIN_SYMBOL(afb_hal);
diff --git a/HAL-afb/HAL-plugin/HalPlugPcm.c b/HAL-afb/HAL-plugin/HalPlugPcm.c
new file mode 100644
index 0000000..d43b44c
--- /dev/null
+++ b/HAL-afb/HAL-plugin/HalPlugPcm.c
@@ -0,0 +1,430 @@
+/*
+ * ALSA <-> OSS PCM I/O plugin
+ *
+ * Copyright (c) 2005 by Takashi Iwai <tiwai@suse.de>
+ *
+ * This library is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * 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 Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#include <stdio.h>
+#include <sys/ioctl.h>
+#include <alsa/asoundlib.h>
+#include <alsa/pcm_external.h>
+#include <linux/soundcard.h>
+
+typedef struct snd_pcm_oss {
+ snd_pcm_ioplug_t io;
+ char *device;
+ int fd;
+ int fragment_set;
+ int caps;
+ int format;
+ unsigned int period_shift;
+ unsigned int periods;
+ unsigned int frame_bytes;
+} snd_pcm_oss_t;
+
+static snd_pcm_sframes_t oss_write(snd_pcm_ioplug_t *io,
+ const snd_pcm_channel_area_t *areas,
+ snd_pcm_uframes_t offset,
+ snd_pcm_uframes_t size)
+{
+ snd_pcm_oss_t *oss = io->private_data;
+ const char *buf;
+ ssize_t result;
+
+ /* we handle only an interleaved buffer */
+ buf = (char *)areas->addr + (areas->first + areas->step * offset) / 8;
+ size *= oss->frame_bytes;
+ result = write(oss->fd, buf, size);
+ if (result <= 0)
+ return result;
+ return result / oss->frame_bytes;
+}
+
+static snd_pcm_sframes_t oss_read(snd_pcm_ioplug_t *io,
+ const snd_pcm_channel_area_t *areas,
+ snd_pcm_uframes_t offset,
+ snd_pcm_uframes_t size)
+{
+ snd_pcm_oss_t *oss = io->private_data;
+ char *buf;
+ ssize_t result;
+
+ /* we handle only an interleaved buffer */
+ buf = (char *)areas->addr + (areas->first + areas->step * offset) / 8;
+ size *= oss->frame_bytes;
+ result = read(oss->fd, buf, size);
+ if (result <= 0)
+ return result;
+ return result / oss->frame_bytes;
+}
+
+static snd_pcm_sframes_t oss_pointer(snd_pcm_ioplug_t *io)
+{
+ snd_pcm_oss_t *oss = io->private_data;
+ struct count_info info;
+ int ptr;
+
+ if (ioctl(oss->fd, io->stream == SND_PCM_STREAM_PLAYBACK ?
+ SNDCTL_DSP_GETOPTR : SNDCTL_DSP_GETIPTR, &info) < 0) {
+ fprintf(stderr, "*** OSS: oss_pointer error\n");
+ return 0;
+ }
+ ptr = snd_pcm_bytes_to_frames(io->pcm, info.ptr);
+ return ptr;
+}
+
+static int oss_start(snd_pcm_ioplug_t *io)
+{
+ snd_pcm_oss_t *oss = io->private_data;
+ int tmp = io->stream == SND_PCM_STREAM_PLAYBACK ?
+ PCM_ENABLE_OUTPUT : PCM_ENABLE_INPUT;
+
+ if (ioctl(oss->fd, SNDCTL_DSP_SETTRIGGER, &tmp) < 0) {
+ fprintf(stderr, "*** OSS: trigger failed\n");
+ if (io->stream == SND_PCM_STREAM_CAPTURE)
+ /* fake read to trigger */
+ read(oss->fd, &tmp, 0);
+ }
+ return 0;
+}
+
+static int oss_stop(snd_pcm_ioplug_t *io)
+{
+ snd_pcm_oss_t *oss = io->private_data;
+ int tmp = 0;
+
+ ioctl(oss->fd, SNDCTL_DSP_SETTRIGGER, &tmp);
+ return 0;
+}
+
+static int oss_drain(snd_pcm_ioplug_t *io)
+{
+ snd_pcm_oss_t *oss = io->private_data;
+
+ if (io->stream == SND_PCM_STREAM_PLAYBACK)
+ ioctl(oss->fd, SNDCTL_DSP_SYNC);
+ return 0;
+}
+
+static int oss_prepare(snd_pcm_ioplug_t *io)
+{
+ snd_pcm_oss_t *oss = io->private_data;
+ int tmp;
+
+ ioctl(oss->fd, SNDCTL_DSP_RESET);
+
+ tmp = io->channels;
+ if (ioctl(oss->fd, SNDCTL_DSP_CHANNELS, &tmp) < 0) {
+ perror("SNDCTL_DSP_CHANNELS");
+ return -EINVAL;
+ }
+ tmp = oss->format;
+ if (ioctl(oss->fd, SNDCTL_DSP_SETFMT, &tmp) < 0) {
+ perror("SNDCTL_DSP_SETFMT");
+ return -EINVAL;
+ }
+ tmp = io->rate;
+ if (ioctl(oss->fd, SNDCTL_DSP_SPEED, &tmp) < 0 ||
+ tmp > io->rate * 1.01 || tmp < io->rate * 0.99) {
+ perror("SNDCTL_DSP_SPEED");
+ return -EINVAL;
+ }
+ return 0;
+}
+
+static int oss_hw_params(snd_pcm_ioplug_t *io,
+ snd_pcm_hw_params_t *params ATTRIBUTE_UNUSED)
+{
+ snd_pcm_oss_t *oss = io->private_data;
+ int i, tmp, err;
+ unsigned int period_bytes;
+ long oflags, flags;
+
+ oss->frame_bytes = (snd_pcm_format_physical_width(io->format) * io->channels) / 8;
+ switch (io->format) {
+ case SND_PCM_FORMAT_U8:
+ oss->format = AFMT_U8;
+ break;
+ case SND_PCM_FORMAT_S16_LE:
+ oss->format = AFMT_S16_LE;
+ break;
+ case SND_PCM_FORMAT_S16_BE:
+ oss->format = AFMT_S16_BE;
+ break;
+ default:
+ fprintf(stderr, "*** OSS: unsupported format %s\n", snd_pcm_format_name(io->format));
+ return -EINVAL;
+ }
+ period_bytes = io->period_size * oss->frame_bytes;
+ oss->period_shift = 0;
+ for (i = 31; i >= 4; i--) {
+ if (period_bytes & (1U << i)) {
+ oss->period_shift = i;
+ break;
+ }
+ }
+ if (! oss->period_shift) {
+ fprintf(stderr, "*** OSS: invalid period size %d\n", (int)io->period_size);
+ return -EINVAL;
+ }
+ oss->periods = io->buffer_size / io->period_size;
+
+ _retry:
+ tmp = oss->period_shift | (oss->periods << 16);
+ if (ioctl(oss->fd, SNDCTL_DSP_SETFRAGMENT, &tmp) < 0) {
+ if (! oss->fragment_set) {
+ perror("SNDCTL_DSP_SETFRAGMENT");
+ fprintf(stderr, "*** period shift = %d, periods = %d\n", oss->period_shift, oss->periods);
+ return -EINVAL;
+ }
+ /* OSS has no proper way to reinitialize the fragments */
+ /* try to reopen the device */
+ close(oss->fd);
+ oss->fd = open(oss->device, io->stream == SND_PCM_STREAM_PLAYBACK ?
+ O_WRONLY : O_RDONLY);
+ if (oss->fd < 0) {
+ err = -errno;
+ SNDERR("Cannot reopen the device %s", oss->device);
+ return err;
+ }
+ io->poll_fd = oss->fd;
+ io->poll_events = io->stream == SND_PCM_STREAM_PLAYBACK ?
+ POLLOUT : POLLIN;
+ snd_pcm_ioplug_reinit_status(io);
+ oss->fragment_set = 0;
+ goto _retry;
+ }
+ oss->fragment_set = 1;
+
+ if ((flags = fcntl(oss->fd, F_GETFL)) < 0) {
+ err = -errno;
+ perror("F_GETFL");
+ } else {
+ oflags = flags;
+ if (io->nonblock)
+ flags |= O_NONBLOCK;
+ else
+ flags &= ~O_NONBLOCK;
+ if (flags != oflags &&
+ fcntl(oss->fd, F_SETFL, flags) < 0) {
+ err = -errno;
+ perror("F_SETFL");
+ }
+ }
+
+ return 0;
+}
+
+#define ARRAY_SIZE(ary) (sizeof(ary)/sizeof(ary[0]))
+
+static int oss_hw_constraint(snd_pcm_oss_t *oss)
+{
+ snd_pcm_ioplug_t *io = &oss->io;
+ static const snd_pcm_access_t access_list[] = {
+ SND_PCM_ACCESS_RW_INTERLEAVED,
+ SND_PCM_ACCESS_MMAP_INTERLEAVED
+ };
+ unsigned int nformats;
+ unsigned int format[5];
+ unsigned int nchannels;
+ unsigned int channel[6];
+ /* period and buffer bytes must be power of two */
+ static const unsigned int bytes_list[] = {
+ 1U<<8, 1U<<9, 1U<<10, 1U<<11, 1U<<12, 1U<<13, 1U<<14, 1U<<15,
+ 1U<<16, 1U<<17, 1U<<18, 1U<<19, 1U<<20, 1U<<21, 1U<<22, 1U<<23
+ };
+ int i, err, tmp;
+
+ /* check trigger */
+ oss->caps = 0;
+ if (ioctl(oss->fd, SNDCTL_DSP_GETCAPS, &oss->caps) >= 0) {
+ if (! (oss->caps & DSP_CAP_TRIGGER))
+ fprintf(stderr, "*** OSS: trigger is not supported!\n");
+ }
+
+ /* access type - interleaved only */
+ if ((err = snd_pcm_ioplug_set_param_list(io, SND_PCM_IOPLUG_HW_ACCESS,
+ ARRAY_SIZE(access_list), access_list)) < 0)
+ return err;
+
+ /* supported formats */
+ tmp = 0;
+ ioctl(oss->fd, SNDCTL_DSP_GETFMTS, &tmp);
+ nformats = 0;
+ if (tmp & AFMT_U8)
+ format[nformats++] = SND_PCM_FORMAT_U8;
+ if (tmp & AFMT_S16_LE)
+ format[nformats++] = SND_PCM_FORMAT_S16_LE;
+ if (tmp & AFMT_S16_BE)
+ format[nformats++] = SND_PCM_FORMAT_S16_BE;
+ if (tmp & AFMT_MU_LAW)
+ format[nformats++] = SND_PCM_FORMAT_MU_LAW;
+ if (! nformats)
+ format[nformats++] = SND_PCM_FORMAT_S16;
+ if ((err = snd_pcm_ioplug_set_param_list(io, SND_PCM_IOPLUG_HW_FORMAT,
+ nformats, format)) < 0)
+ return err;
+
+ /* supported channels */
+ nchannels = 0;
+ for (i = 0; i < 6; i++) {
+ tmp = i + 1;
+ if (ioctl(oss->fd, SNDCTL_DSP_CHANNELS, &tmp) >= 0)
+ channel[nchannels++] = tmp;
+ }
+ if (! nchannels) /* assume 2ch stereo */
+ err = snd_pcm_ioplug_set_param_minmax(io, SND_PCM_IOPLUG_HW_CHANNELS,
+ 2, 2);
+ else
+ err = snd_pcm_ioplug_set_param_list(io, SND_PCM_IOPLUG_HW_CHANNELS,
+ nchannels, channel);
+ if (err < 0)
+ return err;
+
+ /* supported rates */
+ /* FIXME: should query? */
+ err = snd_pcm_ioplug_set_param_minmax(io, SND_PCM_IOPLUG_HW_RATE, 8000, 480000);
+ if (err < 0)
+ return err;
+
+ /* period size (in power of two) */
+ err = snd_pcm_ioplug_set_param_list(io, SND_PCM_IOPLUG_HW_PERIOD_BYTES,
+ ARRAY_SIZE(bytes_list), bytes_list);
+ if (err < 0)
+ return err;
+ /* periods */
+ err = snd_pcm_ioplug_set_param_minmax(io, SND_PCM_IOPLUG_HW_PERIODS, 2, 1024);
+ if (err < 0)
+ return err;
+ /* buffer size (in power of two) */
+ err = snd_pcm_ioplug_set_param_list(io, SND_PCM_IOPLUG_HW_BUFFER_BYTES,
+ ARRAY_SIZE(bytes_list), bytes_list);
+ if (err < 0)
+ return err;
+
+ return 0;
+}
+
+
+static int oss_close(snd_pcm_ioplug_t *io)
+{
+ snd_pcm_oss_t *oss = io->private_data;
+
+ close(oss->fd);
+ free(oss->device);
+ free(oss);
+ return 0;
+}
+
+static const snd_pcm_ioplug_callback_t oss_playback_callback = {
+ .start = oss_start,
+ .stop = oss_stop,
+ .transfer = oss_write,
+ .pointer = oss_pointer,
+ .close = oss_close,
+ .hw_params = oss_hw_params,
+ .prepare = oss_prepare,
+ .drain = oss_drain,
+};
+
+static const snd_pcm_ioplug_callback_t oss_capture_callback = {
+ .start = oss_start,
+ .stop = oss_stop,
+ .transfer = oss_read,
+ .pointer = oss_pointer,
+ .close = oss_close,
+ .hw_params = oss_hw_params,
+ .prepare = oss_prepare,
+ .drain = oss_drain,
+};
+
+
+SND_PCM_PLUGIN_DEFINE_FUNC(oss)
+{
+ snd_config_iterator_t i, next;
+ const char *device = "/dev/dsp";
+ int err;
+ snd_pcm_oss_t *oss;
+
+ snd_config_for_each(i, next, conf) {
+ snd_config_t *n = snd_config_iterator_entry(i);
+ const char *id;
+ if (snd_config_get_id(n, &id) < 0)
+ continue;
+ if (strcmp(id, "comment") == 0 || strcmp(id, "type") == 0 || strcmp(id, "hint") == 0)
+ continue;
+ if (strcmp(id, "device") == 0) {
+ if (snd_config_get_string(n, &device) < 0) {
+ SNDERR("Invalid type for %s", id);
+ return -EINVAL;
+ }
+ continue;
+ }
+ SNDERR("Unknown field %s", id);
+ return -EINVAL;
+ }
+
+ oss = calloc(1, sizeof(*oss));
+ if (! oss) {
+ SNDERR("cannot allocate");
+ return -ENOMEM;
+ }
+
+ oss->device = strdup(device);
+ if (oss->device == NULL) {
+ SNDERR("cannot allocate");
+ free(oss);
+ return -ENOMEM;
+ }
+ oss->fd = open(device, stream == SND_PCM_STREAM_PLAYBACK ?
+ O_WRONLY : O_RDONLY);
+ if (oss->fd < 0) {
+ err = -errno;
+ SNDERR("Cannot open device %s", device);
+ goto error;
+ }
+
+ oss->io.version = SND_PCM_IOPLUG_VERSION;
+ oss->io.name = "ALSA <-> OSS PCM I/O Plugin";
+ oss->io.poll_fd = oss->fd;
+ oss->io.poll_events = stream == SND_PCM_STREAM_PLAYBACK ? POLLOUT : POLLIN;
+ oss->io.mmap_rw = 0;
+ oss->io.callback = stream == SND_PCM_STREAM_PLAYBACK ?
+ &oss_playback_callback : &oss_capture_callback;
+ oss->io.private_data = oss;
+
+ err = snd_pcm_ioplug_create(&oss->io, name, stream, mode);
+ if (err < 0)
+ goto error;
+
+ if ((err = oss_hw_constraint(oss)) < 0) {
+ snd_pcm_ioplug_delete(&oss->io);
+ return err;
+ }
+
+ *pcmp = oss->io.pcm;
+ return 0;
+
+ error:
+ if (oss->fd >= 0)
+ close(oss->fd);
+ free(oss->device);
+ free(oss);
+ return err;
+}
+
+SND_PCM_PLUGIN_SYMBOL(oss);
diff --git a/HAL-afb/Scarlett-Focusrite/ScarlettUsbHAL.c b/HAL-afb/Scarlett-Focusrite/ScarlettUsbHAL.c
index 1ff5320..3b9ee4c 100644
--- a/HAL-afb/Scarlett-Focusrite/ScarlettUsbHAL.c
+++ b/HAL-afb/Scarlett-Focusrite/ScarlettUsbHAL.c
@@ -18,7 +18,7 @@
* To find out which control your sound card uses
* aplay -l # Check sndcard name name in between []
* amixer -D hw:xx controls # get supported controls
- * amixer -D "hw:3" cget numid=xx # get control settings
+ * amixer -D "hw:4" cget numid=xx # get control settings
*
*/
#define _GNU_SOURCE
@@ -41,11 +41,11 @@ STATIC struct json_object* MasterOnOff (alsaHalCtlMapT *control, void* handle) {
// Map HAL hight sndctl with Alsa numid and optionally with a custom callback for non Alsa supported functionalities.
STATIC alsaHalMapT alsaHalMap[]= {
- { .alsa={.control=Master_Playback_Volume,.numid=16, .name="Master-Vol" , .values=1,.minval=0,.maxval= 87 ,.step=0}, .info= "Master Playback Volume" },
- { .alsa={.control=PCM_Playback_Volume ,.numid=27, .name="Play-Vol" , .values=2,.minval=0,.maxval= 255,.step=0}, .info= "PCM Playback Volume" },
- { .alsa={.control=PCM_Playback_Switch ,.numid=17, .name="Play-Switch" , .values=1,.minval=0,.maxval= 1 ,.step=0}, .info= "Master Playback Switch" },
- { .alsa={.control=Capture_Volume ,.numid=12, .name="Capt-vol" , .values=2,.minval=0,.maxval= 31 ,.step=0}, .info= "Capture Volume" },
- { .alsa={.control=Master_OnOff_Switch ,.numid=99, .name="Power-Switch"}, .cb={.callback=MasterOnOff, .handle=NULL}, .info= "OnOff Global Switch"},
+ { .alsa={.control=Master_Playback_Volume,.numid=04, .name="Matrix 03 Mix A Playback Volume" , .values=1,.minval=0,.maxval= 87 ,.step=0}, .info= "Master Playback Volume" },
+ { .alsa={.control=PCM_Playback_Volume ,.numid=06, .name="play-vol" , .values=2,.minval=0,.maxval= 255,.step=0}, .info= "PCM Playback Volume" },
+ { .alsa={.control=PCM_Playback_Switch ,.numid=05, .name="play-switch" , .values=1,.minval=0,.maxval= 1 ,.step=0}, .info= "Master Playback Switch" },
+ { .alsa={.control=Capture_Volume ,.numid=12, .name="capt-vol" , .values=2,.minval=0,.maxval= 31 ,.step=0}, .info= "Capture Volume" },
+ { .alsa={.control=Master_OnOff_Switch, .name="Power-Switch"}, .cb={.callback=MasterOnOff, .handle=NULL}, .info= "OnOff Global Switch"},
{ .alsa={.numid=0}, .cb={.callback=NULL, .handle=NULL}} /* marker for end of the array */
} ;
diff --git a/conf.d/cmake/config.cmake b/conf.d/cmake/config.cmake
index e9367bc..c5f0b8a 100644
--- a/conf.d/cmake/config.cmake
+++ b/conf.d/cmake/config.cmake
@@ -56,7 +56,7 @@ set (gcc_minimal_version 4.9)
set (PKG_REQUIRED_LIST
alsa
libsystemd>=222
- libmicrohttpd>=0.9.54
+ libmicrohttpd>=0.9.55
afb-daemon
json-c
)
diff --git a/nbproject/configurations.xml b/nbproject/configurations.xml
index c476dbc..ed34f91 100644
--- a/nbproject/configurations.xml
+++ b/nbproject/configurations.xml
@@ -70,9 +70,10 @@
<rebuildPropChanged>false</rebuildPropChanged>
</toolsSet>
<flagsDictionary>
- <element flagsID="0" commonFlags="-g -fPIC -fPIC -g"/>
- <element flagsID="1" commonFlags="-mtune=generic -march=x86-64 -g -fPIC"/>
- <element flagsID="2" commonFlags="-mtune=generic -march=x86-64 -g -g -fPIC"/>
+ <element flagsID="0" commonFlags="-fPIC -fPIC -g"/>
+ <element flagsID="1" commonFlags="-g -fPIC -fPIC -g"/>
+ <element flagsID="2" commonFlags="-mtune=generic -march=x86-64 -g -fPIC"/>
+ <element flagsID="3" commonFlags="-mtune=generic -march=x86-64 -g -g -fPIC"/>
</flagsDictionary>
<codeAssistance>
<includeAdditional>true</includeAdditional>
@@ -91,68 +92,86 @@
</preBuild>
</makefileType>
<item path="ALSA-afb/Alsa-AddCtl.c" ex="false" tool="0" flavor2="3">
- <cTool flags="1">
+ <cTool flags="0">
<incDir>
+ <pElem>/usr/include/alsa</pElem>
+ <pElem>../../../opt/include</pElem>
+ <pElem>/usr/include/p11-kit-1</pElem>
<pElem>/usr/include/json-c</pElem>
+ <pElem>Shared-Interface</pElem>
<pElem>build/ALSA-afb</pElem>
</incDir>
+ <preprocessorList>
+ <Elem>CONTROL_CDEV_RX="/dev/inic-usb-crx"</Elem>
+ <Elem>CONTROL_CDEV_TX="/dev/inic-usb-ctx"</Elem>
+ <Elem>MAX_SND_CARD=16</Elem>
+ <Elem>alsa_lowlevel_EXPORTS</Elem>
+ </preprocessorList>
</cTool>
</item>
<item path="ALSA-afb/Alsa-ApiHat.c" ex="false" tool="0" flavor2="3">
- <cTool flags="1">
+ <cTool flags="2">
<incDir>
+ <pElem>../../../opt/include/afb</pElem>
+ <pElem>ALSA-afb</pElem>
<pElem>build/ALSA-afb</pElem>
</incDir>
</cTool>
</item>
<item path="ALSA-afb/Alsa-RegEvt.c" ex="false" tool="0" flavor2="3">
- <cTool flags="1">
+ <cTool flags="2">
<incDir>
+ <pElem>../../../opt/include/afb</pElem>
+ <pElem>ALSA-afb</pElem>
<pElem>/usr/include/json-c</pElem>
<pElem>build/ALSA-afb</pElem>
</incDir>
</cTool>
</item>
<item path="ALSA-afb/Alsa-SetGet.c" ex="false" tool="0" flavor2="3">
- <cTool flags="1">
+ <cTool flags="2">
<incDir>
+ <pElem>../../../opt/include/afb</pElem>
+ <pElem>ALSA-afb</pElem>
<pElem>/usr/include/json-c</pElem>
<pElem>build/ALSA-afb</pElem>
</incDir>
</cTool>
</item>
<item path="ALSA-afb/Alsa-Ucm.c" ex="false" tool="0" flavor2="3">
- <cTool flags="1">
+ <cTool flags="2">
<incDir>
+ <pElem>../../../opt/include/afb</pElem>
+ <pElem>ALSA-afb</pElem>
<pElem>/usr/include/json-c</pElem>
<pElem>build/ALSA-afb</pElem>
</incDir>
</cTool>
</item>
<item path="Common/AudioCommonLib.c" ex="false" tool="0" flavor2="2">
- <cTool flags="0">
+ <cTool flags="1">
</cTool>
</item>
<item path="HAL-afb/HAL-interface/hal-interface.c"
ex="false"
tool="0"
flavor2="3">
- <cTool flags="1">
+ <cTool flags="2">
</cTool>
</item>
<item path="HAL-afb/HDA-intel/IntelHdaHAL.c" ex="false" tool="0" flavor2="3">
- <cTool flags="1">
+ <cTool flags="2">
</cTool>
</item>
<item path="HAL-afb/Scarlett-Focusrite/ScarlettUsbHAL.c"
ex="false"
tool="0"
flavor2="3">
- <cTool flags="1">
+ <cTool flags="0">
</cTool>
</item>
<item path="HighLevel-afb/HighLevelApiConf.c" ex="false" tool="0" flavor2="3">
- <cTool flags="2">
+ <cTool flags="3">
<incDir>
<pElem>Shared-Interface</pElem>
<pElem>../../../opt/include</pElem>
@@ -161,7 +180,7 @@
</cTool>
</item>
<item path="HighLevel-afb/HighLevelBinding.c" ex="false" tool="0" flavor2="3">
- <cTool flags="2">
+ <cTool flags="3">
<incDir>
<pElem>/usr/include/json-c</pElem>
<pElem>Shared-Interface</pElem>
@@ -205,17 +224,9 @@
<item path="MostVolume/libmostvolume.cpp" ex="false" tool="1" flavor2="4">
</item>
<item path="Shared-Interface/audio-interface.c" ex="false" tool="0" flavor2="3">
- <cTool flags="1">
+ <cTool flags="2">
</cTool>
</item>
- <folder path="0/ALSA-afb">
- <cTool>
- <incDir>
- <pElem>../../../opt/include/afb</pElem>
- <pElem>ALSA-afb</pElem>
- </incDir>
- </cTool>
- </folder>
<folder path="0/Common">
<cTool>
<incDir>
@@ -268,12 +279,17 @@
<folder path="0/HAL-afb/Scarlett-Focusrite">
<cTool>
<incDir>
- <pElem>HAL-afb/Scarlett-Focusrite</pElem>
- <pElem>Shared-Interface</pElem>
- <pElem>HAL-afb/HAL-interface</pElem>
+ <pElem>/usr/include/alsa</pElem>
<pElem>../../../opt/include</pElem>
+ <pElem>/usr/include/p11-kit-1</pElem>
+ <pElem>/usr/include/json-c</pElem>
+ <pElem>HAL-afb/HAL-interface</pElem>
+ <pElem>Shared-Interface</pElem>
<pElem>build/HAL-afb/Scarlett-Focusrite</pElem>
</incDir>
+ <preprocessorList>
+ <Elem>hal_scalett_usb_EXPORTS</Elem>
+ </preprocessorList>
</cTool>
</folder>
<folder path="0/HighLevel-afb">