summaryrefslogtreecommitdiffstats
path: root/meta-agl-profile-cluster-qt5/conf
AgeCommit message (Collapse)AuthorFilesLines
2020-01-22Declare layer compatibility with zeusJan-Simon Möller1-1/+1
For the uprev to YP 3.0 zeus we need to update the layer compatibility. Change-Id: Ib762915305588c39400c3c8343152b4ecbfa4556 Signed-off-by: Jan-Simon Möller <jsmoeller@linuxfoundation.org>
2019-04-04Upgrade to thudScott Murray1-0/+2
Changes include: - Add LAYERSERIES_COMPAT definitions to layer.conf files - Remove now unnecessary SECURITY_*FLAGS over-rides from distro configuration - Set intel-corei7-64 preferred kernel version to 4.19 to match latest linux-intel kernel available in meta-intel - Update qemuarm preferred kernel version to 4.18 to match latest linux-yocto - Update firmware package and devicetree file names for raspberrypi3 - Remove linux-firmware bbappend specific to raspberrypi, it seems no longer required and breaks the cross SDK build - Update linux-intel bbappend to 4.19, remove now unnecessary patch - Remove now unnecessary lttng-modules backport - Update linux-raspberrypi bbappend to 4.14 kernel - Added kernel configuration fragment for raspberrypi to disable Kprobes. This is required until linux-raspberrypi is updated to greater than 4.14.104 to avoid a build failure in lttng-modules related to a check for known breakage in the kernel CONFIG_OPTPROBES code. - Replace obsolete base_conditional usage with oe.utils.conditional - Add gstreamer1.0-plugins-bad bbappend for raspberrypi3 to disable faad PACKAGECONFIG to avoid commercial license issues - Remove unused and unbuildable Vayu gstreamer recipes - Update linux-ti-staging bbappend for new BSP kernel - Regen dcan2_pinmux_enable.patch for linux-ti-staging to remove fuzz warning, and remove upstreamed fix_dcan_addresses.patch - Remove ipumm-fw from meta-agl-bsp/meta-ti, as newer version is available in the upstream BSP - Update meta-agl-bsp/meta-ti weston patch to apply against 5.0.0 - Update meta-agl-bsp/meta-ti wayland-ivi-extension patch to apply against 2.2.0 - Add ti-sgx-ddk-km patch to add AGL toolchain configuration file - Remove now unnecessary fdtoverlay recipe - Update core.cfg and ivishell.cfg in weston-ini-conf recipe to handle move of ivi-controller.so configuration in Weston 5.0.0 - Update connman-ncurses patch to remove fuzz warning - Add installation of systemd over-ride file for run-postinsts.service in run-postinsts bbappend to workaround race condition between ldconfig.service and the /sbin/ldconfig invocations in the post-install scripts run by run-postinsts.service. The observed failure was cynara's post-install script failing and its database not being created. - Remove now unnecessary valgrind backport - Add patches to fix most driver compilation against newer kernels - Update libmicrohttpd bbappend - Remove libssp-dev from agl-image-graphical-qt5-crosssdk and agl-demo-platform-html5-crosssdk, upstream have removed it from non-mingw32 platform SDKs - Update wayland-ivi-extension recipe to build 2.2.0, and update local patches - Update weston patches for 5.0.0. Patches: 0016-ivi-shell_add_screen_remove_layer_api.patch 0017-ivi-shell-register-ivi_layout_interface.patch have been removed as they have been applied upstream and are no longer necessary. Patches: 0018-compositor-add-output-type-to-weston_output.patch 0019-compositor-drm-introduce-drm_get_dmafd_from_view.patch (both related to Waltham) have been disabled for now as they need significant rework. - Remove weston-conf RRECOMMENDS in weston bbappend to avoid conflict with weston-ini-conf - Add OECMAKE_GENERATOR = "Unix Makefiles" to aglwgt.bbclass to work around CMake+ninja issue in cmake-apps-module - Update dbus cynara patches for 1.12.10 - Add do_install_append in cynara recipe to remove /var/cynara from cynara package so the directory creation and labelling in the post-install scriptlet will function as intended - Remove now unnecessary e2fsprogs backport - Remove now unnecessary libcap-ng backport - Update pulseaudio patches to remove fuzz warnings - Update neardal patch to remove fuzz warning - Update freetype patch to remove fuzz warning - Rename opencv bbappend to 3.% to handle 3.x backports in upstream - Updated qtwayland patch to remove fuzz warning Changes from Stephane Desneux <stephane.desneux@iot.bzh>: - Remove wayland-ivi-extension PREFERRED_VERSION - Remove now unnecessary nativesdk-cmake patch - Remove now unnecessary ptest-runner patches - Remove now unnecessary harfbuzz patches - Disable waltham-transmitter as it does not build against weston 5.0.0 - Update af-main, cynara, and security-manager to use pkg_postinst_ontarget - Bump connman-ncurses revision to avoid deprecated ncurses functions - Update libva package usage with new intel-vaapi-driver name - Add patches to security-manager to fix compilation with gcc8 - Updated systemd bbappend Changes from Jan-Simon Möller <jsmoeller@linuxfoundation.org>: - Remove meta-agl-bsp/ROCKO.FIXMEs - Remove linux-yocto_4.12.bbappend and now unnecessary associated patch - Remove now unneeded kern-tools-native patch - Bump gstreamer PREFERRED_VERSIONs to 1.14.x - Remove latencytop from packagegroup-agl-core-devel, it has been dropped by upstream - Remove now unnecessary rpm patches - Update pulseaudio bbappend to 12.2 - Update opencv bbappend to 3.4 - Update freetype bbappend to 2.9.1 - Update dbus bbappend to 1.12.10 - Update weston bbappend to 5.0.0 - Update cynara patches to remove fuzz warnings - Add patch to cynara to fix compilation with gcc8 - Add xmlsec1 bbappend to clear EXTRA_OECONF to fix compilation on sumo or newer Changes from Ronan Le Martet <ronan.lemartet@iot.bzh>: - Update meta-rcar-gen3-adas layer gstreamer1.0-plugin-vspfilter bbappend to version 1.0.1 Known issues (marked with FIXME): - CMake+ninja issue in cmake-apps-module has been worked around with OECMAKE_GENERATOR - waltham-transmitter and the patches to weston related to it have been disabled - Currently unclear if patch to libcap-native is actually required or not Bug-AGL: SPEC-1837 Change-Id: I7b8b9ef667aec2d229952eace6663dfc761654d0 Signed-off-by: Scott Murray <scott.murray@konsulko.com>
2018-12-20Add instrument cluster profile definitionsScott Murray1-0/+10
Add definitions for instrument cluster profiles for plain Wayland/Weston based images and images that also include Qt5 support. Due to the current requirement that profiles only be a superset of one parent profile, the Qt5 profile inherits from agl-profile-graphical-qt5 and not agl-profile-cluster as one might expect. This is due to some of the required recipes and bbappends for Qt5 usage only being available in the meta-agl-profile-graphical-qt5 layer. Change-Id: I863b35bdc009775ac204a720bbc2cc85e71c268a Signed-off-by: Scott Murray <scott.murray@konsulko.com>
f='#n341'>341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782
/*
 * AlsaLibMapping -- provide low level interface with ALSA lib (extracted from alsa-json-gateway code)
 * Copyright (C) 2015,2016,2017, 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.

   References:
   https://github.com/fulup-bzh/AlsaJsonGateway (original code)
   http://alsa-lib.sourcearchive.com/documentation/1.0.20/modules.html
   http://alsa-lib.sourcearchive.com/documentation/1.0.8/group__Control_gd48d44da8e3bfe150e928267008b8ff5.html
   http://alsa.opensrc.org/HowTo_access_a_mixer_control
   https://github.com/gch1p/alsa-volume-monitor/blob/master/main.c
   https://github.com/DongheonKim/android_hardware_alsa-sound/blob/master/ALSAControl.cpp (ALSA low level API)

*/

#define _GNU_SOURCE  // needed for vasprintf

#include "Alsa-ApiHat.h"

PUBLIC void NumidsListParse (queryValuesT *queryValues, ctlRequestT *ctlRequest) {
    json_object *jValues;
    int length;
    
    for (int idx=0; idx < queryValues->count; idx ++) {                
        ctlRequest[idx].jToken = json_object_array_get_idx (queryValues->jNumIds, idx);
        ctlRequest[idx].jValues = NULL;
        ctlRequest[idx].used=0;

        enum json_type jtype=json_object_get_type(ctlRequest[idx].jToken);
        switch (jtype) {
            json_object *jId, *jVal;
            
            case json_type_int:
                // if NUMID is not an array then it should be an integer numid with no value
                ctlRequest[idx].numId = json_object_get_int (ctlRequest[idx].jToken);
                break;

            case  json_type_array:   
                // NUMID is an array 1st slot should be numid, optionally values may come after
                length=json_object_array_length (ctlRequest[idx].jToken);
                if (length < 1 || length >2) {
                    ctlRequest[idx].used=-1;
                    continue; 
                }

                ctlRequest[idx].numId =json_object_get_int(json_object_array_get_idx (ctlRequest[idx].jToken, 0));

                if (length == 2) {
                    jValues = json_object_array_get_idx (ctlRequest[idx].jToken, 1);
                    if (jValues == NULL) {
                        ctlRequest[idx].used=-1;
                        continue; 
                    }            
                    // Value is an int or an array with potentially multiple subvalues
                    ctlRequest[idx].jValues = jValues;
                }
                break;
                
            case json_type_object:
                // numid+values formated as {id:xxx, val:[aa,bb...,nn]}
                if (!json_object_object_get_ex (ctlRequest[idx].jToken,"id", &jId) || !json_object_object_get_ex (ctlRequest[idx].jToken,"val",&jVal)) {
                    AFB_NOTICE("Invalid Json=%s missing 'id'|'val'", json_object_get_string(ctlRequest[idx].jToken));
                    ctlRequest[idx].used=-1;
                } else {
                    ctlRequest[idx].numId   =json_object_get_int(jId);
                    ctlRequest[idx].jValues =jVal;
                }
                
                
            default:                
                ctlRequest[idx].used=-1;   
        }
    }
}

PUBLIC  int alsaCheckQuery (afb_req request, queryValuesT *queryValues) {
    queryValues->devid = afb_req_value(request, "devid");
    if (queryValues->devid == NULL) goto OnErrorExit;
    const char *numids;
    json_object *jNumIds;

    const char *rqtQuiet = afb_req_value(request, "quiet");
    if (!rqtQuiet) queryValues->quiet=99; // default super quiet
    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_get_string(query), rqtQuiet);
        goto OnErrorExit;
    };
   
    // no NumId is interpreted as ALL for get and error for set
    numids = afb_req_value(request, "numids");
    if (numids == NULL) {
        queryValues->count=0;
        goto OnExit;
    }

    jNumIds = json_tokener_parse(numids);
    if (!jNumIds) {
        afb_req_fail_f (request, "numids-notjson","numids=%s not a valid json entry", numids);
        goto OnErrorExit;        
    };
    
    enum json_type jtype= json_object_get_type(jNumIds);
    switch (jtype) {
        case json_type_array:
            queryValues->jNumIds = jNumIds;
            queryValues->count = json_object_array_length (jNumIds);
            break;
            
        case json_type_int:
            queryValues->count = 1;
            queryValues->jNumIds = json_object_new_array ();
            json_object_array_add (queryValues->jNumIds, jNumIds);
            break;
        
        default:           
            afb_req_fail_f (request, "numid-notarray","NumId=%s NumId not valid JSON array", numids);
            goto OnErrorExit;        
    }

OnExit:    
    return 0;
    
OnErrorExit:
    return 1;
}

STATIC json_object *DB2StringJsonOject (long dB) {
    char label [20];
	if (dB < 0) {
		snprintf(label, sizeof(label), "-%li.%02lidB", -dB / 100, -dB % 100);
	} else {
		snprintf(label, sizeof(label), "%li.%02lidB", dB / 100, dB % 100);
	}

    // json function takes care of string copy
	return (json_object_new_string (label));
}


// Direct port from amixer TLV decode routine. This code is too complex for me.
// I hopefully did not break it when porting it.

STATIC json_object *decodeTlv(unsigned int *tlv, unsigned int tlv_size) {
    char label[20];
    unsigned int type = tlv[0];
    unsigned int size;
    unsigned int idx = 0;
    const char *chmap_type = NULL;
    json_object * decodeTlvJson = json_object_new_object();

    if (tlv_size < (unsigned int) (2 * sizeof (unsigned int))) {
        printf("TLV size error!\n");
        return NULL;
    }
    type = tlv[idx++];
    size = tlv[idx++];
    tlv_size -= (unsigned int) (2 * sizeof (unsigned int));
    if (size > tlv_size) {
        fprintf(stderr, "TLV size error (%i, %i, %i)!\n", type, size, tlv_size);
        return NULL;
    }
    switch (type) {

        case SND_CTL_TLVT_CONTAINER:
        {
            json_object * containerJson = json_object_new_array();

            size += (unsigned int) (sizeof (unsigned int) - 1);
            size /= (unsigned int) (sizeof (unsigned int));
            while (idx < size) {
                json_object *embedJson;

                if (tlv[idx + 1] > (size - idx) * sizeof (unsigned int)) {
                    fprintf(stderr, "TLV size error in compound!\n");
                    return NULL;
                }
                embedJson = decodeTlv(tlv + idx, tlv[idx + 1] + 8);
                json_object_array_add(containerJson, embedJson);
                idx += (unsigned int) (2 + (tlv[idx + 1] + sizeof (unsigned int) - 1) / sizeof (unsigned int));
            }
            json_object_object_add(decodeTlvJson, "container", containerJson);
            break;
        }

        case SND_CTL_TLVT_DB_SCALE:
        {
            json_object * dbscaleJson = json_object_new_object();

            if (size != 2 * sizeof (unsigned int)) {
                json_object * arrayJson = json_object_new_array();
                while (size > 0) {
                    snprintf(label, sizeof (label), "0x%08x,", tlv[idx++]);
                    json_object_array_add(arrayJson, json_object_new_string(label));
                    size -= (unsigned int) sizeof (unsigned int);
                }
                json_object_object_add(dbscaleJson, "array", arrayJson);
            } else {
                json_object_object_add(dbscaleJson, "min", DB2StringJsonOject((int) tlv[2]));
                json_object_object_add(dbscaleJson, "step", DB2StringJsonOject(tlv[3] & 0xffff));
                json_object_object_add(dbscaleJson, "mute", DB2StringJsonOject((tlv[3] >> 16) & 1));
            }
            json_object_object_add(decodeTlvJson, "dbscale", dbscaleJson);
            break;
        }

#ifdef SND_CTL_TLVT_DB_LINEAR
        case SND_CTL_TLVT_DB_LINEAR:
        {
            json_object * dbLinearJson = json_object_new_object();

            if (size != 2 * sizeof (unsigned int)) {
                json_object * arrayJson = json_object_new_array();
                while (size > 0) {
                    snprintf(label, sizeof (label), "0x%08x,", tlv[idx++]);
                    json_object_array_add(arrayJson, json_object_new_string(label));
                    size -= (unsigned int) sizeof (unsigned int);
                }
                json_object_object_add(dbLinearJson, "offset", arrayJson);
            } else {
                json_object_object_add(dbLinearJson, "min", DB2StringJsonOject((int) tlv[2]));
                json_object_object_add(dbLinearJson, "max", DB2StringJsonOject((int) tlv[3]));
            }
            json_object_object_add(decodeTlvJson, "dblinear", dbLinearJson);
            break;
        }
#endif

#ifdef SND_CTL_TLVT_DB_RANGE
        case SND_CTL_TLVT_DB_RANGE:
        {
            json_object *dbRangeJson = json_object_new_object();

            if ((size % (6 * sizeof (unsigned int))) != 0) {
                json_object *arrayJson = json_object_new_array();
                while (size > 0) {
                    snprintf(label, sizeof (label), "0x%08x,", tlv[idx++]);
                    json_object_array_add(arrayJson, json_object_new_string(label));
                    size -= (unsigned int) sizeof (unsigned int);
                }
                json_object_object_add(dbRangeJson, "dbrange", arrayJson);
                break;
            }
            while (size > 0) {
                json_object * embedJson = json_object_new_object();
                snprintf(label, sizeof (label), "%i,", tlv[idx++]);
                json_object_object_add(embedJson, "rangemin", json_object_new_string(label));
                snprintf(label, sizeof (label), "%i", tlv[idx++]);
                json_object_object_add(embedJson, "rangemax", json_object_new_string(label));
                embedJson = decodeTlv(tlv + idx, 4 * sizeof (unsigned int));
                json_object_object_add(embedJson, "tlv", embedJson);
                idx += 4;
                size -= (unsigned int) (6 * sizeof (unsigned int));
                json_object_array_add(dbRangeJson, embedJson);
            }
            json_object_object_add(decodeTlvJson, "dbrange", dbRangeJson);
            break;
        }
#endif
#ifdef SND_CTL_TLVT_DB_MINMAX
        case SND_CTL_TLVT_DB_MINMAX:
        case SND_CTL_TLVT_DB_MINMAX_MUTE:
        {
            json_object * dbMinMaxJson = json_object_new_object();

            if (size != 2 * sizeof (unsigned int)) {
                json_object * arrayJson = json_object_new_array();
                while (size > 0) {
                    snprintf(label, sizeof (label), "0x%08x,", tlv[idx++]);
                    json_object_array_add(arrayJson, json_object_new_string(label));
                    size -= (unsigned int) sizeof (unsigned int);
                }
                json_object_object_add(dbMinMaxJson, "array", arrayJson);

            } else {
                json_object_object_add(dbMinMaxJson, "min", DB2StringJsonOject((int) tlv[2]));
                json_object_object_add(dbMinMaxJson, "max", DB2StringJsonOject((int) tlv[3]));
            }

            if (type == SND_CTL_TLVT_DB_MINMAX_MUTE) {
                json_object_object_add(decodeTlvJson, "dbminmaxmute", dbMinMaxJson);
            } else {
                json_object_object_add(decodeTlvJson, "dbminmax", dbMinMaxJson);
            }
            break;
        }
#endif
#ifdef SND_CTL_TLVT_CHMAP_FIXED
        case SND_CTL_TLVT_CHMAP_FIXED:
            chmap_type = "fixed";
            /* Fall through */
        case SND_CTL_TLVT_CHMAP_VAR:
            if (!chmap_type)
                chmap_type = "variable";
            /* Fall through */
        case SND_CTL_TLVT_CHMAP_PAIRED:
            if (!chmap_type)
                chmap_type = "paired";

            json_object * chmapJson = json_object_new_object();
            json_object * arrayJson = json_object_new_array();

            while (size > 0) {
                snprintf(label, sizeof (label), "%s", snd_pcm_chmap_name(tlv[idx++]));
                size -= (unsigned int) sizeof (unsigned int);
                json_object_array_add(arrayJson, json_object_new_string(label));
            }
            json_object_object_add(chmapJson, chmap_type, arrayJson);
            json_object_object_add(decodeTlvJson, "chmap", chmapJson);
            break;
#endif
        default:
        {
            printf("unk-%i-", type);
            json_object * arrayJson = json_object_new_array();

            while (size > 0) {
                snprintf(label, sizeof (label), "0x%08x,", tlv[idx++]);
                size -= (unsigned int) sizeof (unsigned int);
                json_object_array_add(arrayJson, json_object_new_string(label));
            }
            break;
            json_object_object_add(decodeTlvJson, "unknown", arrayJson);
        }
    }

    return (decodeTlvJson);
}


// retreive info for one given card
STATIC  json_object* alsaCardProbe (const char *rqtSndId) {
    const char  *info, *name;
    const char *devid, *driver;
    json_object *ctlDev;
    snd_ctl_t   *handle;
    snd_ctl_card_info_t *cardinfo;
    int err;

    if ((err = snd_ctl_open(&handle, rqtSndId, 0)) < 0) {
        AFB_INFO ("SndCard [%s] Not Found", rqtSndId);
        return NULL;
    }

    snd_ctl_card_info_alloca(&cardinfo);
    if ((err = snd_ctl_card_info(handle, cardinfo)) < 0) {
        snd_ctl_close(handle);
        AFB_WARNING ("SndCard [%s] info error: %s", rqtSndId, snd_strerror(err));
        return NULL;
    }

    // start a new json object to store card info
    ctlDev = json_object_new_object();

    devid= snd_ctl_card_info_get_id(cardinfo);
    json_object_object_add (ctlDev, "devid"  , json_object_new_string(devid));
    name =  snd_ctl_card_info_get_name(cardinfo);
    json_object_object_add (ctlDev, "name", json_object_new_string (name));

    if (AFB_GET_VERBOSITY > 1) {
        json_object_object_add (ctlDev, "devid", json_object_new_string(rqtSndId));
        driver= snd_ctl_card_info_get_driver(cardinfo);
        json_object_object_add (ctlDev, "driver"  , json_object_new_string(driver));
        info  = strdup(snd_ctl_card_info_get_longname (cardinfo));
        json_object_object_add (ctlDev, "info" , json_object_new_string (info));
        AFB_INFO ("AJG: Soundcard Devid=%-5s devid=%-7s Name=%s\n", rqtSndId, devid, info);
    }

    // free card handle and return info
    snd_ctl_close(handle);    
    return (ctlDev);
}

// Loop on every potential Sound card and register active one
PUBLIC void alsaGetInfo (afb_req request) {
    int  card;
    json_object *ctlDev, *ctlDevs;
    char devid[32];
    
    const char *rqtSndId = afb_req_value(request, "devid");

    // if no specific card requested loop on all

    if (rqtSndId != NULL) {
        // only one card was requested let's probe it
        ctlDev = alsaCardProbe (rqtSndId);
        if (ctlDev != NULL) afb_req_success(request, ctlDev, NULL);
        else afb_req_fail_f (request, "sndscard-notfound", "SndCard [%s] Not Found", rqtSndId);
        
    } else {
        // return an array of ctlDev
        ctlDevs =json_object_new_array();

        // loop on potential card number
        for (card =0; card < MAX_SND_CARD; card++) {

            // build card devid and probe it
            snprintf (devid, sizeof(devid), "hw:%i", card);
            ctlDev = alsaCardProbe (devid);

            // Alsa has hole within card list [ignore them]
            if (ctlDev != NULL) {
                // add current ctlDev to ctlDevs object
                json_object_array_add (ctlDevs, ctlDev);
            }    
        }
        afb_req_success (request, ctlDevs, NULL);  
    }
}

// pack Alsa element's ACL into a JSON object
STATIC json_object *getControlAcl (snd_ctl_elem_info_t *info) {

    json_object * jsonAclCtl = json_object_new_object();

    json_object_object_add (jsonAclCtl, "read"   , json_object_new_boolean(snd_ctl_elem_info_is_readable(info)));
    json_object_object_add (jsonAclCtl, "write"  , json_object_new_boolean(snd_ctl_elem_info_is_writable(info)));
    json_object_object_add (jsonAclCtl, "inact"  , json_object_new_boolean(snd_ctl_elem_info_is_inactive(info)));
    json_object_object_add (jsonAclCtl, "volat"  , json_object_new_boolean(snd_ctl_elem_info_is_volatile(info)));
    json_object_object_add (jsonAclCtl, "lock"   , json_object_new_boolean(snd_ctl_elem_info_is_locked(info)));

    // if TLV is readable we insert its ACL
    if (!snd_ctl_elem_info_is_tlv_readable(info)) {
        json_object * jsonTlv = json_object_new_object();

        json_object_object_add (jsonTlv, "read"   , json_object_new_boolean(snd_ctl_elem_info_is_tlv_readable(info)));
        json_object_object_add (jsonTlv, "write"  , json_object_new_boolean(snd_ctl_elem_info_is_tlv_writable(info)));
        json_object_object_add (jsonTlv, "command", json_object_new_boolean(snd_ctl_elem_info_is_tlv_commandable(info)));

        json_object_object_add (jsonAclCtl, "tlv", jsonTlv);
    }
    return (jsonAclCtl);
}

// process ALSA control and store resulting value into ctlRequest
PUBLIC int alsaSetSingleCtl (snd_ctl_t *ctlDev, snd_ctl_elem_id_t *elemId, ctlRequestT *ctlRequest) {
    snd_ctl_elem_value_t *elemData;
    snd_ctl_elem_info_t  *elemInfo;
    int count, length, err, valueIsArray;

    // let's make sure we are processing the right control    
    if (ctlRequest->numId != snd_ctl_elem_id_get_numid (elemId)) goto OnErrorExit;
         
    // set info event ID and get value
    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_get_string(ctlRequest->jValues));
        goto OnErrorExit;
    }
    
    if (!snd_ctl_elem_info_is_writable(elemInfo)) {
        AFB_NOTICE( "Not Writable ALSA NUMID=%d Values=[%s]", ctlRequest->numId, json_object_get_string(ctlRequest->jValues));
        goto OnErrorExit;
    }
    
    count = snd_ctl_elem_info_get_count (elemInfo); 
    if (count == 0) goto OnErrorExit;
    
    enum json_type jtype= json_object_get_type(ctlRequest->jValues);
    switch (jtype) {
        case json_type_array:
            length = json_object_array_length (ctlRequest->jValues);
            valueIsArray=1;           
            break;
        case json_type_int:
            length=1;
            valueIsArray=0;
            break;                        
        default:
            count =0;
            length = 0;
            break;
    }


    if (count == 0 || count < length) {
        AFB_NOTICE( "Invalid values NUMID='%d' Values='%s' count='%d' wanted='%d'", ctlRequest->numId, json_object_get_string(ctlRequest->jValues), length, count);
        goto OnErrorExit;
    }

    snd_ctl_elem_value_alloca(&elemData);    
    snd_ctl_elem_value_set_id(elemData, elemId);  // map ctlInfo to ctlId elemInfo is updated !!!
    if (snd_ctl_elem_read(ctlDev, elemData) < 0) goto OnErrorExit;   

    // Loop on every control value and push to sndcard
    for (int index=0; index < count && index < length; index++) {
        json_object *element;
        int value;
        
        if (valueIsArray) element= json_object_array_get_idx(ctlRequest->jValues, index);
        else element= ctlRequest->jValues;
        
        value= json_object_get_int (element);
        snd_ctl_elem_value_set_integer(elemData, index, value);
    }
    
    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_get_string(ctlRequest->jValues), snd_strerror(err));
        goto OnErrorExit;
    }
    
    ctlRequest->used=1;
    return 0;
   
 OnErrorExit:
    ctlRequest->used=-1;
    return -1;   
}

// process ALSA control and store then into ctlRequest
PUBLIC int alsaGetSingleCtl (snd_ctl_t *ctlDev, snd_ctl_elem_id_t *elemId, ctlRequestT *ctlRequest, int quiet) {
    snd_ctl_elem_type_t  elemType;
    snd_ctl_elem_value_t *elemData;
    snd_ctl_elem_info_t  *elemInfo;
    int count, idx, err;

         
    // set info event ID and get value

    snd_ctl_elem_info_alloca(&elemInfo);
    snd_ctl_elem_info_set_id(elemInfo, elemId); 
    if (snd_ctl_elem_info(ctlDev, elemInfo) < 0) goto OnErrorExit;
    count = snd_ctl_elem_info_get_count (elemInfo); 
    if (count == 0) goto OnErrorExit;
    
    if (!snd_ctl_elem_info_is_readable(elemInfo)) goto OnErrorExit;
    elemType = snd_ctl_elem_info_get_type(elemInfo);    

    snd_ctl_elem_value_alloca(&elemData);    
    snd_ctl_elem_value_set_id(elemData, elemId); 
    if (snd_ctl_elem_read(ctlDev, elemData) < 0) goto OnErrorExit;
    
    int numid= snd_ctl_elem_info_get_numid(elemInfo);

    ctlRequest->jValues= json_object_new_object();
    json_object_object_add (ctlRequest->jValues,"numid" , json_object_new_int(numid));
    if (quiet < 2) json_object_object_add (ctlRequest->jValues,"name" , json_object_new_string(snd_ctl_elem_id_get_name (elemId)));
    if (quiet < 1) json_object_object_add (ctlRequest->jValues,"iface" , json_object_new_string(snd_ctl_elem_iface_name(snd_ctl_elem_id_get_interface(elemId))));
    if (quiet < 3) json_object_object_add (ctlRequest->jValues,"actif", json_object_new_boolean(!snd_ctl_elem_info_is_inactive(elemInfo)));

    json_object *jsonValuesCtl = json_object_new_array();
    for (idx = 0; idx < count; idx++) { // start from one in amixer.c !!!
        switch (elemType) {
        case SND_CTL_ELEM_TYPE_BOOLEAN: {
                json_object_array_add (jsonValuesCtl, json_object_new_boolean (snd_ctl_elem_value_get_boolean(elemData, idx)));
                break;
                }
        case SND_CTL_ELEM_TYPE_INTEGER:
                json_object_array_add (jsonValuesCtl, json_object_new_int ((int)snd_ctl_elem_value_get_integer(elemData, idx)));
                break;
        case SND_CTL_ELEM_TYPE_INTEGER64:
                json_object_array_add (jsonValuesCtl, json_object_new_int64 (snd_ctl_elem_value_get_integer64(elemData, idx)));
                break;
        case SND_CTL_ELEM_TYPE_ENUMERATED:
                json_object_array_add (jsonValuesCtl, json_object_new_int (snd_ctl_elem_value_get_enumerated(elemData, idx)));
                break;
        case SND_CTL_ELEM_TYPE_BYTES:
                json_object_array_add (jsonValuesCtl, json_object_new_int ((int)snd_ctl_elem_value_get_byte(elemData, idx)));
                break;
        case SND_CTL_ELEM_TYPE_IEC958: {
                json_object *jsonIec958Ctl = json_object_new_object();
                snd_aes_iec958_t iec958;
                snd_ctl_elem_value_get_iec958(elemData, &iec958);

                json_object_object_add (jsonIec958Ctl,"AES0",json_object_new_int(iec958.status[0]));
                json_object_object_add (jsonIec958Ctl,"AES1",json_object_new_int(iec958.status[1]));
                json_object_object_add (jsonIec958Ctl,"AES2",json_object_new_int(iec958.status[2]));
                json_object_object_add (jsonIec958Ctl,"AES3",json_object_new_int(iec958.status[3]));
                json_object_array_add  (jsonValuesCtl, jsonIec958Ctl);
                break;
                }
        default:
                json_object_array_add (jsonValuesCtl, json_object_new_string ("?unknown?"));
                break;
        }
    }
    json_object_object_add (ctlRequest->jValues,"val",jsonValuesCtl);

    if (!quiet) {  // in simple mode do not print usable values
        json_object *jsonClassCtl = json_object_new_object();
        json_object_object_add (jsonClassCtl,"type" , json_object_new_int(elemType));
		json_object_object_add (jsonClassCtl,"count", json_object_new_int(count));

		switch (elemType) {
			case SND_CTL_ELEM_TYPE_INTEGER:
				json_object_object_add (jsonClassCtl,"min",  json_object_new_int((int)snd_ctl_elem_info_get_min(elemInfo)));
				json_object_object_add (jsonClassCtl,"max",  json_object_new_int((int)snd_ctl_elem_info_get_max(elemInfo)));
				json_object_object_add (jsonClassCtl,"step", json_object_new_int((int)snd_ctl_elem_info_get_step(elemInfo)));
				break;
			case SND_CTL_ELEM_TYPE_INTEGER64:
				json_object_object_add (jsonClassCtl,"min",  json_object_new_int64(snd_ctl_elem_info_get_min64(elemInfo)));
				json_object_object_add (jsonClassCtl,"max",  json_object_new_int64(snd_ctl_elem_info_get_max64(elemInfo)));
				json_object_object_add (jsonClassCtl,"step", json_object_new_int64(snd_ctl_elem_info_get_step64(elemInfo)));
				break;
			case SND_CTL_ELEM_TYPE_ENUMERATED: {
				unsigned int item, items = snd_ctl_elem_info_get_items(elemInfo);
				json_object *jsonEnum = json_object_new_array();

				for (item = 0; item < items; item++) {
					snd_ctl_elem_info_set_item(elemInfo, item);
					if ((err = snd_ctl_elem_info(ctlDev, elemInfo)) >= 0) {
						json_object_array_add (jsonEnum, json_object_new_string(snd_ctl_elem_info_get_item_name(elemInfo)));
					}
				}
				json_object_object_add (jsonClassCtl, "enums",jsonEnum);
				break;
			}
			default: break; // ignore any unknown type
			}

		// add collected class info with associated ACLs
		json_object_object_add (ctlRequest->jValues,"ctrl", jsonClassCtl);
		json_object_object_add (ctlRequest->jValues,"acl"  , getControlAcl (elemInfo));

		// check for tlv [direct port from amixer.c]
		if (snd_ctl_elem_info_is_tlv_readable(elemInfo)) {
				unsigned int *tlv;
				tlv = malloc(4096);
				if ((err = snd_ctl_elem_info(ctlDev, elemInfo)) < 0) {
					fprintf (stderr, "Control %s element TLV read error\n", snd_strerror(err));
					free(tlv);
				} else {
					json_object_object_add (ctlRequest->jValues,"tlv", decodeTlv (tlv, 4096));
		   }
		}
    }
    ctlRequest->used=1;
    return 0;
   
 OnErrorExit:
    ctlRequest->used=-1;
    return -1;   
}

// assign multiple control to the same value
STATIC void alsaSetGetCtls (afb_req request, ActionSetGetT action) {
    ctlRequestT *ctlRequest;
    const char *warmsg=NULL;
    int err=0, status=0;
    unsigned int ctlCount;
    snd_ctl_t *ctlDev;
    snd_ctl_elem_list_t *ctlList;  
    json_object *sndctls=json_object_new_array();;
    queryValuesT queryValues;
       
    err = alsaCheckQuery (request, &queryValues);
    if (err) goto OnErrorExit;
    

    if ((err = snd_ctl_open(&ctlDev, queryValues.devid, 0)) < 0) {
        afb_req_fail_f (request, "sndcrl-notfound","devid=[%s] load fail error=%s\n", queryValues.devid, snd_strerror(err));
        goto OnErrorExit;
    }
    
    snd_ctl_elem_list_alloca(&ctlList); 
    if ((err = snd_ctl_elem_list (ctlDev, ctlList)) < 0) {
        afb_req_fail_f (request, "listInit-failed","devid=[%s] load fail error=%s\n", queryValues.devid, snd_strerror(err));
        goto OnErrorExit;
    }

    if ((err = snd_ctl_elem_list_alloc_space(ctlList, snd_ctl_elem_list_get_count(ctlList))) < 0) {
        afb_req_fail_f (request, "listAlloc-failed","devid=[%s] load fail error=%s\n", queryValues.devid, snd_strerror(err));
        goto OnErrorExit;
    }
    
    if ((err = snd_ctl_elem_list (ctlDev, ctlList)) < 0) {
        afb_req_fail_f (request, "listOpen-failed","devid=[%s] load fail error=%s\n", queryValues.devid, snd_strerror(err));
        goto OnErrorExit;
    }

    // Parse numids string (empty == all)
    ctlCount= snd_ctl_elem_list_get_used(ctlList);
    if (queryValues.count==0) {
        ctlRequest= alloca (sizeof(ctlRequestT)*(ctlCount));
    } else {
        ctlRequest= alloca (sizeof(ctlRequestT)*(queryValues.count));
        NumidsListParse (&queryValues, ctlRequest);
    }
          
    // Loop on all ctlDev controls
    for (int ctlIndex=0; ctlIndex < ctlCount; ctlIndex++) {
        unsigned int selected=0;
        int jdx;
        
        if (queryValues.count == 0 && action == ACTION_GET) {
                selected=1; // check is this numid is selected within query        
                jdx = ctlIndex;  // map all existing ctl as requested
        } else {
            int numid = snd_ctl_elem_list_get_numid(ctlList, ctlIndex); 
            if (numid < 0) {
                AFB_NOTICE("snd_ctl_elem_list_get_numid index=%d fail", ctlIndex);
                continue;
            }
            // check if current control was requested in query numids list
            for (jdx=0; jdx < queryValues.count; jdx++) {
                if (numid == ctlRequest[jdx].numId) {
                    selected = 1;
                    break;
                }
            }            
        }
        
        // control is selected open ctlid and get value 
        if (selected) {
            snd_ctl_elem_id_t  *elemId;
            snd_ctl_elem_id_alloca(&elemId);
           
            snd_ctl_elem_list_get_id (ctlList, ctlIndex, elemId);
            switch (action) {
                case ACTION_GET:
                    err = alsaGetSingleCtl (ctlDev, elemId, &ctlRequest[jdx], queryValues.quiet);
                break;
                
                case ACTION_SET:
                    err = alsaSetSingleCtl (ctlDev, elemId, &ctlRequest[jdx]);
                    
                default:
                    err = 1;
            }
            if (err) status++;
            else {
                json_object_array_add (sndctls, ctlRequest[jdx].jValues);
            }
        }
    }
  
    // if we had error let's add them into response message info
    json_object *warnings = json_object_new_array();
    for (int jdx=0; jdx < queryValues.count; jdx++) {
        if (ctlRequest[jdx].used <= 0) {
            json_object *failctl = json_object_new_object();
            json_object_object_add (failctl, "numid", ctlRequest[jdx].jToken);
            if (ctlRequest[jdx].jValues) 
                json_object_object_add(failctl, "values", ctlRequest[jdx].jValues);

            if (ctlRequest[jdx].numId == -1) json_object_object_add (failctl, "info", json_object_new_string ("Invalid NumID"));
            else {
               if (ctlRequest[jdx].used == 0) json_object_object_add (failctl, "info", json_object_new_string ("Does Not Exist"));
               if (ctlRequest[jdx].used == -1) json_object_object_add (failctl, "info", json_object_new_string ("Invalid Value"));
            }
            json_object_array_add (warnings, failctl);
        }
        /* WARNING!!!! Check with Jose why following put free jValues
        if (ctlRequest[jdx].jToken) json_object_put(ctlRequest[jdx].jToken);
        if (ctlRequest[jdx].jValues) json_object_put(ctlRequest[jdx].jValues);
        */
    }
    
    if (json_object_array_length(warnings)) warmsg=json_object_get_string (warnings);
    else json_object_put(warnings);
  
    // send response+warning if any
    afb_req_success (request, sndctls, warmsg);
    snd_ctl_elem_list_clear(ctlList);
    
    OnErrorExit:
        return;        
}

PUBLIC void alsaGetCtls (afb_req request) {
    alsaSetGetCtls (request, ACTION_GET);
}
    
PUBLIC void alsaSetCtls (afb_req request) {
    alsaSetGetCtls (request, ACTION_SET);
}