From c68316b787706d49bbddb387af45e25804678ce6 Mon Sep 17 00:00:00 2001 From: Fulup Ar Foll Date: Mon, 30 Oct 2017 21:18:41 +0100 Subject: Code Reorganisation preparing transfer to gerrit --- ahl-utilities/CMakeLists.txt | 39 ++++++ ahl-utilities/ahl-interface.h | 99 ++++++++++++++++ ahl-utilities/ahl-policy-utils.c | 248 +++++++++++++++++++++++++++++++++++++++ ahl-utilities/ahl-policy-utils.h | 177 ++++++++++++++++++++++++++++ 4 files changed, 563 insertions(+) create mode 100644 ahl-utilities/CMakeLists.txt create mode 100644 ahl-utilities/ahl-interface.h create mode 100644 ahl-utilities/ahl-policy-utils.c create mode 100644 ahl-utilities/ahl-policy-utils.h (limited to 'ahl-utilities') diff --git a/ahl-utilities/CMakeLists.txt b/ahl-utilities/CMakeLists.txt new file mode 100644 index 0000000..1ef3bfa --- /dev/null +++ b/ahl-utilities/CMakeLists.txt @@ -0,0 +1,39 @@ +########################################################################### +# Copyright 2015, 2016, 2017 IoT.bzh +# +# author: Fulup Ar Foll +# +# 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(ahl-utilities) + + # Define project Targets + ADD_LIBRARY(${TARGET_NAME} STATIC ahl-policy-utils.c) + + # Define target includes + TARGET_INCLUDE_DIRECTORIES(${TARGET_NAME} + PUBLIC ${GLIB_PKG_INCLUDE_DIRS} + ) + + # Library dependencies (include updates automatically) + TARGET_LINK_LIBRARIES(${TARGET_NAME} + afb-utilities + ) + + # Define target includes for this target client + TARGET_INCLUDE_DIRECTORIES(${TARGET_NAME} + PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} + ) diff --git a/ahl-utilities/ahl-interface.h b/ahl-utilities/ahl-interface.h new file mode 100644 index 0000000..0488e96 --- /dev/null +++ b/ahl-utilities/ahl-interface.h @@ -0,0 +1,99 @@ +/* + * Copyright (C) 2017 "Audiokinetic Inc" + * + * 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. + */ + +#ifndef AHL_INTERFACE_INCLUDE +#define AHL_INTERFACE_INCLUDE + +///// API ///// + +// Endpoint types +#define AHL_ENDPOINTTYPE_SOURCE "source" // source devices +#define AHL_ENDPOINTTYPE_SINK "sink" // sink devices + +// Stream state +#define AHL_STREAM_STATE_IDLE "idle" // Stream is inactive +#define AHL_STREAM_STATE_RUNNING "running" // Stream is active and running +#define AHL_STREAM_STATE_PAUSED "paused" // Stream is active but paused + +// Stream mute state +#define AHL_STREAM_UNMUTED "off" // Stream is not muted +#define AHL_STREAM_MUTED "on" // Stream is muted + +// Property/Volume/Action events +#define AHL_ENDPOINT_PROPERTY_EVENT "ahl_endpoint_property_event" +#define AHL_ENDPOINT_VOLUME_EVENT "ahl_endpoint_volume_event" +#define AHL_ENDPOINT_INIT_EVENT "ahl_endpoint_init_event" +#define AHL_POST_ACTION_EVENT "ahl_post_action" +#define AHL_STREAM_STATE_EVENT "ahl_stream_state_event" +#define AHL_ENDPOINT_INIT_EVENT "ahl_endpoint_init_event" + + +// Stream state event types +#define AHL_STREAM_EVENT_START "start" // Stream is inactive +#define AHL_STREAM_EVENT_STOP "stop" // Stream is running +#define AHL_STREAM_EVENT_PAUSE "pause" // Audio stream paused +#define AHL_STREAM_EVENT_RESUME "resume" // Audio stream resumed +#define AHL_STREAM_EVENT_MUTE "mute" // Audio stream muted +#define AHL_STREAM_EVENT_UNMUTE "unmute" // Audio stream unmuted + +///// Interpret returned or configuration information ///// + +// Known audio domain string definitions (for configuration file format and device URI interpretation) +#define AHL_DOMAIN_ALSA "alsa" +#define AHL_DOMAIN_PULSE "pulse" +#define AHL_DOMAIN_GSTREAMER "gstreamer" +#define AHL_DOMAIN_EXTERNAL "external" + +// ALSA Device URI type +#define AHL_DEVICEURITYPE_ALSA_HW "hw" // Alsa hardware device URI +#define AHL_DEVICEURITYPE_ALSA_DMIX "dmix" // Alsa Dmix device URI (only for playback devices) +#define AHL_DEVICEURITYPE_ALSA_DSNOOP "dsnoop" // Alsa DSnoop device URI (only for capture devices) +#define AHL_DEVICEURITYPE_ALSA_SOFTVOL "softvol" // Alsa softvol device URI +#define AHL_DEVICEURITYPE_ALSA_PLUG "plug" // Alsa plug device URI +#define AHL_DEVICEURITYPE_ALSA_OTHER "other" // Alsa domain URI device of unspecified type +#define AHL_DEVICEURITYPE_NOT_ALSA "nonalsa" + +// Define default behavior of audio role when interrupting lower priority sources (in configuration) +#define AHL_INTERRUPTBEHAVIOR_CONTINUE "continue" // Continue to play when interrupted (e.g. media may be ducked) +#define AHL_INTERRUPTBEHAVIOR_CANCEL "cancel" // Abort playback when interrupted (e.g. non-important HMI feedback that does not make sense later) +#define AHL_INTERRUPTBEHAVIOR_PAUSE "pause" // Pause source when interrupted, to be resumed afterwards (e.g. non-temporal guidance) + +///// Naming convention ///// + +// Standardized name for common audio roles (not enforced in any way, just helps compatibility) +#define AHL_ROLE_WARNING "warning" // Safety-relevant or critical alerts/alarms +#define AHL_ROLE_GUIDANCE "guidance" // Important user information where user action is expected (e.g. navigation instruction) +#define AHL_ROLE_NOTIFICATION "notification" // HMI or else notifications (e.g. touchscreen events, speech recognition on/off,...) +#define AHL_ROLE_COMMUNICATION "communication" // Voice communications (e.g. handsfree, speech recognition) +#define AHL_ROLE_ENTERTAINMENT "entertainment" // Multimedia content (e.g. tuner, media player, etc.) +#define AHL_ROLE_SYSTEM "system" // System level content or development +#define AHL_ROLE_STARTUP "startup" // Early (startup) sound +#define AHL_ROLE_SHUTDOWN "shutdown" // Late (shutdown) sound +#define AHL_ROLE_NONE "none" // Non-assigned / legacy applications + +// Standardized list of properties (not enforced in any way, just helps compatibility) +#define AHL_PROPERTY_BALANCE "balance" +#define AHL_PROPERTY_FADE "fade" +#define AHL_PROPERTY_EQ_LOW "eq_bass" +#define AHL_PROPERTY_EQ_MID "eq_mid" +#define AHL_PROPERTY_EQ_HIGH "eq_treble" + +// Standardized list of events (not enforced in any way, just helps compatibility) +#define AHL_EVENTS_PLAYSOUND "play_sound" +#define AHL_EVENTS_ECHOCANCEL_ENABLE "echocancel_enable" +#define AHL_EVENTS_ECHOCANCEL_DISABLE "echocancel_disable" + +#endif // AHL_INTERFACE_INCLUDE diff --git a/ahl-utilities/ahl-policy-utils.c b/ahl-utilities/ahl-policy-utils.c new file mode 100644 index 0000000..60ddd36 --- /dev/null +++ b/ahl-utilities/ahl-policy-utils.c @@ -0,0 +1,248 @@ +/* + * Copyright (C) 2017 "Audiokinetic Inc" + * + * 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 "ahl-policy-utils.h" +#include "wrap-json.h" +#include +#include + +void Add_Endpoint_Property_Double( EndpointInfoT * io_pEndpointInfo, char * in_pPropertyName, double in_dPropertyValue) +{ + json_object * propValueJ = json_object_new_double(in_dPropertyValue); + g_hash_table_insert(io_pEndpointInfo->pPropTable, in_pPropertyName, propValueJ); +} + + +void Add_Endpoint_Property_Int( EndpointInfoT * io_pEndpointInfo, char * in_pPropertyName, int in_iPropertyValue) +{ + json_object * propValueJ = json_object_new_int(in_iPropertyValue); + g_hash_table_insert(io_pEndpointInfo->pPropTable, in_pPropertyName, propValueJ); +} + +void Add_Endpoint_Property_String( EndpointInfoT * io_pEndpointInfo, char * in_pPropertyName, const char * in_pPropertyValue) +{ + json_object * propValueJ = json_object_new_string(in_pPropertyValue); + g_hash_table_insert(io_pEndpointInfo->pPropTable, in_pPropertyName, propValueJ); +} + +int PolicyEndpointStructToJSON(EndpointInfoT * pEndpointInfo, json_object **ppPolicyEndpointJ) +{ + if(pEndpointInfo == NULL || pEndpointInfo->pPropTable == NULL) + { + AFB_ERROR("Invalid PolicyEndpointStructToJSON arguments"); + return AHL_POLICY_UTIL_FAIL; + } + + //Create json object for PropTable + json_object *pPropTableJ = json_object_new_array(); + if(pEndpointInfo->pPropTable) { + GHashTableIter iter; + gpointer key, value; + g_hash_table_iter_init (&iter, pEndpointInfo->pPropTable); + while (g_hash_table_iter_next (&iter, &key, &value)) + { + json_object *pPropertyJ = NULL; + int error=wrap_json_pack(&pPropertyJ, "{s:s,s:o}", + "property_name", (char*)key, + "property_value", value + ); + if(error) + { + AFB_ERROR("Unable to pack JSON endpoint, =%s", wrap_json_get_error_string(error)); + return AHL_POLICY_UTIL_FAIL; + } + json_object_array_add(pPropTableJ, pPropertyJ); + } + AFB_DEBUG("json object query=%s", json_object_get_string(pPropTableJ)); + } + + //Create json object for Endpoint + int err= wrap_json_pack(ppPolicyEndpointJ, "{s:i,s:i,s:s,s:s,s:s,s:s,s:s,s:i,s:s,s:i,s:i,s:i,s:i,s:i,s:i,s:i,s:o}", + "endpoint_id", pEndpointInfo->endpointID, + "endpoint_type", pEndpointInfo->type, + "device_name", pEndpointInfo->gsDeviceName, + "display_name", pEndpointInfo->gsDisplayName, + "device_uri", pEndpointInfo->gsDeviceURI, + "device_domain", pEndpointInfo->gsDeviceDomain, + "audio_role",pEndpointInfo->pRoleName, + "device_uri_type", pEndpointInfo->deviceURIType, + "hal_api_name", pEndpointInfo->gsHALAPIName, + "alsa_cardNum", pEndpointInfo->alsaInfo.cardNum, + "alsa_deviceNum", pEndpointInfo->alsaInfo.deviceNum, + "alsa_subDeviceNum", pEndpointInfo->alsaInfo.subDeviceNum, + "format_samplerate", pEndpointInfo->format.sampleRate, + "format_numchannels", pEndpointInfo->format.numChannels, + "format_sampletype",pEndpointInfo->format.sampleType, + "volume", pEndpointInfo->iVolume, + "property_table", pPropTableJ + ); + if (err) { + AFB_ERROR("Unable to pack JSON endpoint, =%s", wrap_json_get_error_string(err)); + return AHL_POLICY_UTIL_FAIL; + } + AFB_DEBUG("JSON endpoint information=%s", json_object_get_string(*ppPolicyEndpointJ)); + return AHL_POLICY_UTIL_SUCCESS; +} + +int PolicyStreamStructToJSON(StreamInfoT * pPolicyStream, json_object **ppPolicyStreamJ) +{ + if(pPolicyStream == NULL) + { + AFB_ERROR("Invalid arguments to PolicyStreamStructToJSON"); + return AHL_POLICY_UTIL_FAIL; + } + + json_object * pEndpointJ = NULL; + int iRet = PolicyEndpointStructToJSON(pPolicyStream->pEndpointInfo, &pEndpointJ); + if (iRet) { + return iRet; + } + + //Create json object for stream + int err = wrap_json_pack(ppPolicyStreamJ, "{s:i,s:i,s:i,s:I,s:i,s:s,s:i,s:i,s:o}", + "stream_id", pPolicyStream->streamID, + "stream_state", pPolicyStream->streamState, + "stream_mute", pPolicyStream->streamMute, + "stream_state_event", &pPolicyStream->streamStateEvent, + "endpoint_sel_mod", pPolicyStream->endpointSelMode, + "role_name", pPolicyStream->pRoleName, + "priority", pPolicyStream->iPriority, + "interrupt_behavior", pPolicyStream->eInterruptBehavior, + "endpoint_info", pEndpointJ + ); + if (err) { + AFB_ERROR("Unable to pack JSON endpoint, =%s", wrap_json_get_error_string(err)); + return AHL_POLICY_UTIL_FAIL; + } + + AFB_DEBUG("JSON stream information=%s", json_object_get_string(*ppPolicyStreamJ)); + + return AHL_POLICY_UTIL_SUCCESS; +} + +int PolicyCtxJSONToEndpoint(json_object *pEndpointJ, EndpointInfoT * pEndpointInfo) +{ + if(pEndpointJ == NULL || pEndpointInfo == NULL /*|| pEndpointInfo->pPropTable == NULL */ ) + { + AFB_ERROR("Invalid arguments for PolicyCtxJSONToEndpoint"); + return AHL_POLICY_UTIL_FAIL; + } + + //Unpack Endpoint + json_object *pPropTableJ = NULL; + int err = wrap_json_unpack(pEndpointJ, "{s:i,s:i,s:s,s:s,s:s,s:s,s:s,s:i,s:s,s:i,s:i,s:i,s:i,s:i,s:i,s:i,s:o}", + "endpoint_id", &pEndpointInfo->endpointID, + "endpoint_type", &pEndpointInfo->type, + "device_name", &pEndpointInfo->gsDeviceName, + "display_name", &pEndpointInfo->gsDisplayName, + "device_uri", &pEndpointInfo->gsDeviceURI, + "device_domain", &pEndpointInfo->gsDeviceDomain, + "audio_role", &pEndpointInfo->pRoleName, + "device_uri_type", &pEndpointInfo->deviceURIType, + "hal_api_name", &pEndpointInfo->gsHALAPIName, + "alsa_cardNum", &pEndpointInfo->alsaInfo.cardNum, + "alsa_deviceNum", &pEndpointInfo->alsaInfo.deviceNum, + "alsa_subDeviceNum", &pEndpointInfo->alsaInfo.subDeviceNum, + "format_samplerate", &pEndpointInfo->format.sampleRate, + "format_numchannels", &pEndpointInfo->format.numChannels, + "format_sampletype",&pEndpointInfo->format.sampleType, + "volume", &pEndpointInfo->iVolume, + "property_table", &pPropTableJ + ); + if (err) { + AFB_ERROR("Unable to unpack JSON endpoint, =%s", wrap_json_get_error_string(err)); + return AHL_POLICY_UTIL_FAIL; + } + + // Unpack prop table + if(pPropTableJ) + { + pEndpointInfo->pPropTable = g_hash_table_new(g_str_hash, g_str_equal); + + int nbProperties = json_object_array_length(pPropTableJ); + for(int i=0; istreamID, + "stream_state", &pPolicyStream->streamState, + "stream_mute", &pPolicyStream->streamMute, + "stream_state_event", &pPolicyStream->streamStateEvent, + "endpoint_sel_mod", &pPolicyStream->endpointSelMode, + "role_name", &pPolicyStream->pRoleName, + "priority", &pPolicyStream->iPriority, + "interrupt_behavior", &pPolicyStream->eInterruptBehavior, + "endpoint_info", &pEndpointJ + ); + + if (err) { + AFB_ERROR("Unable to parse JSON stream information=%s", json_object_get_string(pStreamJ)); + return AHL_POLICY_UTIL_FAIL; + } + + int iRet = PolicyCtxJSONToEndpoint(pEndpointJ,pPolicyStream->pEndpointInfo); + if (iRet) { + return iRet; + } + return AHL_POLICY_UTIL_SUCCESS; +} + \ No newline at end of file diff --git a/ahl-utilities/ahl-policy-utils.h b/ahl-utilities/ahl-policy-utils.h new file mode 100644 index 0000000..6adfa4e --- /dev/null +++ b/ahl-utilities/ahl-policy-utils.h @@ -0,0 +1,177 @@ +/* + * Copyright (C) 2017 "Audiokinetic Inc" + * + * 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. + */ + +#ifndef AHL_POLICY_UTILS_INCLUDE +#define AHL_POLICY_UTILS_INCLUDE + +#define AFB_BINDING_VERSION 2 +#include +#include +#include + +#define AHL_POLICY_ACCEPT 1 +#define AHL_POLICY_REJECT 0 +#define AHL_POLICY_UTIL_SUCCESS 0 +#define AHL_POLICY_UTIL_FAIL 1 + +typedef int endpointID_t; +typedef int streamID_t; + +typedef enum StreamEvent { + STREAM_EVENT_START = 0, // Stream is inactive + STREAM_EVENT_STOP, // Stream is running + STREAM_EVENT_PAUSE, // Audio stream paused + STREAM_EVENT_RESUME, // Audio stream resumed + STREAM_EVENT_MUTED, // Audio stream muted + STREAM_EVENT_UNMUTED, // Audio stream unmuted + STREAM_EVENT_MAXVALUE // Enum count, keep at the end +} StreamEventT; + +typedef enum StreamMute { + STREAM_UNMUTED = 0, // Stream is not muted + STREAM_MUTED, // Stream is muted + STREAM_MUTE_MAXVALUE, // Enum count, keep at the end +} StreamMuteT; + +typedef enum EndpointType { + ENDPOINTTYPE_SOURCE = 0, // source devices + ENDPOINTTYPE_SINK, // sink devices + ENDPOINTTYPE_MAXVALUE // Enum count, keep at the end +} EndpointTypeT; + +typedef enum StreamState { + STREAM_STATE_IDLE = 0, // Stream is inactive + STREAM_STATE_RUNNING, // Stream is active and running + STREAM_STATE_PAUSED, // Stream is active but paused + STREAM_STATE_MAXVALUE // Enum count, keep at the end +} StreamStateT; + +// Define default behavior of audio role when interrupting lower priority sources +typedef enum InterruptBehavior { + INTERRUPTBEHAVIOR_CONTINUE = 0, // Continue to play lower priority source when interrupted (e.g. media may be ducked) + INTERRUPTBEHAVIOR_CANCEL, // Abort playback of lower priority source when interrupted (e.g. non-important HMI feedback that does not make sense later) + INTERRUPTBEHAVIOR_PAUSE, // Pause lower priority source when interrupted, to be resumed afterwards (e.g. non-temporal guidance) + INTERRUPTBEHAVIOR_MAXVALUE, // Enum count, keep at the end +} InterruptBehaviorT; + +typedef enum DeviceURIType { + DEVICEURITYPE_ALSA_HW = 0, // Alsa hardware device URI + DEVICEURITYPE_ALSA_DMIX, // Alsa Dmix device URI (only for playback devices) + DEVICEURITYPE_ALSA_DSNOOP, // Alsa DSnoop device URI (only for capture devices) + DEVICEURITYPE_ALSA_SOFTVOL, // Alsa softvol device URI + DEVICEURITYPE_ALSA_PLUG, // Alsa plug device URI + DEVICEURITYPE_ALSA_OTHER, // Alsa domain URI device of unspecified type + DEVICEURITYPE_NOT_ALSA, // Unknown (not ALSA domain) + DEVICEURITYPE_MAXVALUE // Enum count, keep at the end +} DeviceURITypeT; + +// CPU endianness assumed in all formats +typedef enum SampleType { + AHL_FORMAT_UNKNOWN = -1, // Unknown + AHL_FORMAT_U8 = 0, // Unsigned 8 bit + AHL_FORMAT_S16, // Signed 16 bit Little Endian + AHL_FORMAT_S24, // Signed 24 bit Little Endian using low three bytes in 32-bit word + AHL_FORMAT_S32, // Signed 32 bit Little Endian + AHL_FORMAT_FLOAT, // Float 32 bit Little Endian, Range -1.0 to 1.0 + AHL_FORMAT_FLOAT64, // Float 64 bit Little Endian, Range -1.0 to 1.0 + AHL_FORMAT_IEC958, // IEC-958 Little Endian (SPDIF) + AHL_FORMAT_MU_LAW, // Mu-Law + AHL_FORMAT_A_LAW, // A-Law + AHL_FORMAT_IMA_ADPCM, // Ima-ADPCM + AHL_FORMAT_MPEG, // MPEG + AHL_FORMAT_GSM, // GSM + AHL_FORMAT_G723, // G723 + AHL_FORMAT_DSD, // Direct stream digital + AHL_FORMAT_MAXVALUE, // Enum count, keep at the end +} SampleTypeT; + +typedef struct AudioFormat { + int sampleRate; // Sample rate + int numChannels; // Number of channels + SampleTypeT sampleType; // Sample type + // TODO: Interleaving? + // TODO: Sample sub format? +} AudioFormatT; + +typedef struct AlsaDeviceInfo { + int cardNum; // HW card number + int deviceNum; // HW device number + int subDeviceNum; // HW sub device number +} AlsaDeviceInfoT; + +typedef enum EndpointSelectionMode { + ENDPOINTSELMODE_AUTO = 0, // Automatic endpoint selection based on config priority + ENDPOINTSELMODE_MANUAL, // Explicit endpoint selection + ENDPOINTSELMODEMAXVALUE, // Enum count, keep at the end +} EndpointSelectionModeT; + +typedef struct EndpointInfo +{ + endpointID_t endpointID; // Unique endpoint ID (per type) + EndpointTypeT type; // Source or sink device + char * gsDeviceName; // Unique device card name + char * gsDisplayName; // Application display name + char * gsDeviceURI; // Associated URI + char * gsDeviceDomain; // Device URI domain (e.g. alsa or pulse) + char * pRoleName; // Role assigned to this endpoint + DeviceURITypeT deviceURIType; // Device URI type (includes audio domain information) + char * gsHALAPIName; // HAL associated with the device (for volume control) + AlsaDeviceInfoT alsaInfo; // ALSA specific device information + AudioFormatT format; // Preferred audio format supported (later could be array of supported formats) + int iVolume; // Storage for current endpoint volume (policy effected). + GHashTable * pPropTable; // Storage for array of properties (policy effected) +} EndpointInfoT; + +typedef struct StreamInfo { + streamID_t streamID; // Stream unique ID + EndpointInfoT * pEndpointInfo; // Associated endpoint information (reference) + StreamStateT streamState; // Stream activity state + StreamMuteT streamMute; // Stream mute state + struct afb_event streamStateEvent; // Stream specific event for stream state changes + EndpointSelectionModeT endpointSelMode; // Automatic (priority based) or manual endpoint selection + char * pRoleName; // Role string identifier (from role config but could be programatically overriden later) + int iPriority; // Role normalized priority (0-100) (from role config but could be programatically overriden later) + InterruptBehaviorT eInterruptBehavior; // Role behavior when interrupting lower priority streams (from role config but could be programatically overriden later) +} StreamInfoT; + + +typedef struct StreamPolicyInfo { + streamID_t streamID; + int RolePriority; + char * pAudioRole; + InterruptBehaviorT interruptBehavior; + int iDuckVolume; //duck Volume +} StreamPolicyInfoT; + +typedef struct EndPointPolicyInfo { + endpointID_t endpointID; + EndpointTypeT type; + DeviceURITypeT deviceType; + char * pDeviceName; + char * pHalApiName; + int iVolume; //Current Volume + GArray * streamInfo; //List of playing or duck stream at a given endpoint +} EndPointPolicyInfoT; + +void Add_Endpoint_Property_Double( EndpointInfoT * io_pEndpointInfo, char * in_pPropertyName, double in_dPropertyValue); +void Add_Endpoint_Property_Int( EndpointInfoT * io_pEndpointInfo, char * in_pPropertyName, int in_iPropertyValue); +void Add_Endpoint_Property_String( EndpointInfoT * io_pEndpointInfo, char * in_pPropertyName, const char * in_pPropertyValue); +int PolicyEndpointStructToJSON(EndpointInfoT * pPolicyEndpoint, json_object **ppPolicyEndpointJ); +int PolicyCtxJSONToEndpoint(json_object *pEndpointJ, EndpointInfoT * pPolicyStream); +int PolicyStreamStructToJSON(StreamInfoT * pPolicyStream, json_object **ppPolicyStreamJ); +int PolicyCtxJSONToStream(json_object *pStreamJ, StreamInfoT * pPolicyStream); + +#endif // AHL_POLICY_UTILS_INCLUDE -- cgit 1.2.3-korg From ab6e470190f2cc410b1f6fa8f146317a3c3b08b5 Mon Sep 17 00:00:00 2001 From: Fulup Ar Foll Date: Wed, 1 Nov 2017 22:18:54 +0100 Subject: Integration with AlsaHookPlugin (work in progress) --- ahl-binding/ahl-config.c | 59 ++++++++-- ahl-policy/ahl-interface.h | 99 ++++++++++++++++ ahl-utilities/ahl-interface.h | 99 ---------------- conf.d/cmake/config.cmake | 4 +- conf.d/project/.asoundrc | 164 -------------------------- conf.d/project/.asoundrc-audiok | 164 ++++++++++++++++++++++++++ conf.d/project/.asounrc-fulup | 198 ++++++++++++++++++++++++++++++++ conf.d/project/README.md | 15 +++ conf.d/project/agl-ahl-config.json | 128 --------------------- conf.d/project/ahl-audiok4a-config.json | 128 +++++++++++++++++++++ conf.d/project/ahl-fulup4a-config.json | 39 +++++++ nbproject/configurations.xml | 3 - nbproject/project.xml | 2 +- 13 files changed, 698 insertions(+), 404 deletions(-) create mode 100644 ahl-policy/ahl-interface.h delete mode 100644 ahl-utilities/ahl-interface.h delete mode 100644 conf.d/project/.asoundrc create mode 100644 conf.d/project/.asoundrc-audiok create mode 100644 conf.d/project/.asounrc-fulup create mode 100644 conf.d/project/README.md delete mode 100644 conf.d/project/agl-ahl-config.json create mode 100644 conf.d/project/ahl-audiok4a-config.json create mode 100644 conf.d/project/ahl-fulup4a-config.json (limited to 'ahl-utilities') diff --git a/ahl-binding/ahl-config.c b/ahl-binding/ahl-config.c index 5e3de08..2a61b5e 100644 --- a/ahl-binding/ahl-config.c +++ b/ahl-binding/ahl-config.c @@ -19,6 +19,7 @@ #include #include #include "wrap-json.h" +#include "filescan-utils.h" #include "ahl-binding.h" @@ -40,21 +41,63 @@ static InterruptBehaviorT InterruptBehaviorToEnum(char * in_pInterruptBehaviorSt return INTERRUPTBEHAVIOR_MAXVALUE; } +static json_object* CtlConfigScan(const char *dirList, const char *prefix) { + char controlFile [CONTROL_MAXPATH_LEN]; + strncpy(controlFile, prefix, CONTROL_MAXPATH_LEN); + strncat(controlFile, GetBinderName(), CONTROL_MAXPATH_LEN); + + // search for default dispatch config file + json_object* responseJ = ScanForConfig(dirList, CTL_SCAN_RECURSIVE, controlFile, ".json"); + + return responseJ; +} + +static char* CtlConfigSearch(const char *dirList, const char *prefix) { + int index, err; + + // search for default dispatch config file + json_object* responseJ = CtlConfigScan (dirList, prefix); + if (!responseJ) return NULL; + + // We load 1st file others are just warnings + for (index = 0; index < json_object_array_length(responseJ); index++) { + json_object *entryJ = json_object_array_get_idx(responseJ, index); + + char *filename; + char*fullpath; + err = wrap_json_unpack(entryJ, "{s:s, s:s !}", "fullpath", &fullpath, "filename", &filename); + if (err) { + AFB_ERROR("CTL-INIT HOOPs invalid JSON entry= %s", json_object_get_string(entryJ)); + return NULL; + } + + if (index == 0) { + char filepath[CONTROL_MAXPATH_LEN]; + strncpy(filepath, fullpath, sizeof (filepath)); + strncat(filepath, "/", sizeof (filepath)); + strncat(filepath, filename, sizeof (filepath)); + return (strdup(filepath)); + } + } + // no config found + return NULL; +} + int ParseHLBConfig() { char * versionStr = NULL; json_object * jAudioRoles = NULL; json_object * jHALList = NULL; char * policyModule = NULL; - // TODO: This should be retrieve from binding startup arguments - char configfile_path[256]; - if(getenv("AHL_CONFIG_FILE") == NULL) - { - AFB_ERROR("Please Set Environnement Variable AHL_CONFIG_FILE"); - return 1; - } + const char *dirList=getenv("AAAA_CONFIG_PATH"); + if (!dirList) dirList=CONTROL_CONFIG_PATH; - sprintf(configfile_path, "%s", getenv("AHL_CONFIG_FILE")); + const char *configfile_path =CtlConfigSearch(dirList, "ahl-"); + if (!configfile_path) { + AFB_ERROR("Error: No control-* config found invalid JSON %s ", dirList); + return 1; + } + AFB_INFO("High-level config file -> %s\n", configfile_path); // Open configuration file diff --git a/ahl-policy/ahl-interface.h b/ahl-policy/ahl-interface.h new file mode 100644 index 0000000..0488e96 --- /dev/null +++ b/ahl-policy/ahl-interface.h @@ -0,0 +1,99 @@ +/* + * Copyright (C) 2017 "Audiokinetic Inc" + * + * 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. + */ + +#ifndef AHL_INTERFACE_INCLUDE +#define AHL_INTERFACE_INCLUDE + +///// API ///// + +// Endpoint types +#define AHL_ENDPOINTTYPE_SOURCE "source" // source devices +#define AHL_ENDPOINTTYPE_SINK "sink" // sink devices + +// Stream state +#define AHL_STREAM_STATE_IDLE "idle" // Stream is inactive +#define AHL_STREAM_STATE_RUNNING "running" // Stream is active and running +#define AHL_STREAM_STATE_PAUSED "paused" // Stream is active but paused + +// Stream mute state +#define AHL_STREAM_UNMUTED "off" // Stream is not muted +#define AHL_STREAM_MUTED "on" // Stream is muted + +// Property/Volume/Action events +#define AHL_ENDPOINT_PROPERTY_EVENT "ahl_endpoint_property_event" +#define AHL_ENDPOINT_VOLUME_EVENT "ahl_endpoint_volume_event" +#define AHL_ENDPOINT_INIT_EVENT "ahl_endpoint_init_event" +#define AHL_POST_ACTION_EVENT "ahl_post_action" +#define AHL_STREAM_STATE_EVENT "ahl_stream_state_event" +#define AHL_ENDPOINT_INIT_EVENT "ahl_endpoint_init_event" + + +// Stream state event types +#define AHL_STREAM_EVENT_START "start" // Stream is inactive +#define AHL_STREAM_EVENT_STOP "stop" // Stream is running +#define AHL_STREAM_EVENT_PAUSE "pause" // Audio stream paused +#define AHL_STREAM_EVENT_RESUME "resume" // Audio stream resumed +#define AHL_STREAM_EVENT_MUTE "mute" // Audio stream muted +#define AHL_STREAM_EVENT_UNMUTE "unmute" // Audio stream unmuted + +///// Interpret returned or configuration information ///// + +// Known audio domain string definitions (for configuration file format and device URI interpretation) +#define AHL_DOMAIN_ALSA "alsa" +#define AHL_DOMAIN_PULSE "pulse" +#define AHL_DOMAIN_GSTREAMER "gstreamer" +#define AHL_DOMAIN_EXTERNAL "external" + +// ALSA Device URI type +#define AHL_DEVICEURITYPE_ALSA_HW "hw" // Alsa hardware device URI +#define AHL_DEVICEURITYPE_ALSA_DMIX "dmix" // Alsa Dmix device URI (only for playback devices) +#define AHL_DEVICEURITYPE_ALSA_DSNOOP "dsnoop" // Alsa DSnoop device URI (only for capture devices) +#define AHL_DEVICEURITYPE_ALSA_SOFTVOL "softvol" // Alsa softvol device URI +#define AHL_DEVICEURITYPE_ALSA_PLUG "plug" // Alsa plug device URI +#define AHL_DEVICEURITYPE_ALSA_OTHER "other" // Alsa domain URI device of unspecified type +#define AHL_DEVICEURITYPE_NOT_ALSA "nonalsa" + +// Define default behavior of audio role when interrupting lower priority sources (in configuration) +#define AHL_INTERRUPTBEHAVIOR_CONTINUE "continue" // Continue to play when interrupted (e.g. media may be ducked) +#define AHL_INTERRUPTBEHAVIOR_CANCEL "cancel" // Abort playback when interrupted (e.g. non-important HMI feedback that does not make sense later) +#define AHL_INTERRUPTBEHAVIOR_PAUSE "pause" // Pause source when interrupted, to be resumed afterwards (e.g. non-temporal guidance) + +///// Naming convention ///// + +// Standardized name for common audio roles (not enforced in any way, just helps compatibility) +#define AHL_ROLE_WARNING "warning" // Safety-relevant or critical alerts/alarms +#define AHL_ROLE_GUIDANCE "guidance" // Important user information where user action is expected (e.g. navigation instruction) +#define AHL_ROLE_NOTIFICATION "notification" // HMI or else notifications (e.g. touchscreen events, speech recognition on/off,...) +#define AHL_ROLE_COMMUNICATION "communication" // Voice communications (e.g. handsfree, speech recognition) +#define AHL_ROLE_ENTERTAINMENT "entertainment" // Multimedia content (e.g. tuner, media player, etc.) +#define AHL_ROLE_SYSTEM "system" // System level content or development +#define AHL_ROLE_STARTUP "startup" // Early (startup) sound +#define AHL_ROLE_SHUTDOWN "shutdown" // Late (shutdown) sound +#define AHL_ROLE_NONE "none" // Non-assigned / legacy applications + +// Standardized list of properties (not enforced in any way, just helps compatibility) +#define AHL_PROPERTY_BALANCE "balance" +#define AHL_PROPERTY_FADE "fade" +#define AHL_PROPERTY_EQ_LOW "eq_bass" +#define AHL_PROPERTY_EQ_MID "eq_mid" +#define AHL_PROPERTY_EQ_HIGH "eq_treble" + +// Standardized list of events (not enforced in any way, just helps compatibility) +#define AHL_EVENTS_PLAYSOUND "play_sound" +#define AHL_EVENTS_ECHOCANCEL_ENABLE "echocancel_enable" +#define AHL_EVENTS_ECHOCANCEL_DISABLE "echocancel_disable" + +#endif // AHL_INTERFACE_INCLUDE diff --git a/ahl-utilities/ahl-interface.h b/ahl-utilities/ahl-interface.h deleted file mode 100644 index 0488e96..0000000 --- a/ahl-utilities/ahl-interface.h +++ /dev/null @@ -1,99 +0,0 @@ -/* - * Copyright (C) 2017 "Audiokinetic Inc" - * - * 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. - */ - -#ifndef AHL_INTERFACE_INCLUDE -#define AHL_INTERFACE_INCLUDE - -///// API ///// - -// Endpoint types -#define AHL_ENDPOINTTYPE_SOURCE "source" // source devices -#define AHL_ENDPOINTTYPE_SINK "sink" // sink devices - -// Stream state -#define AHL_STREAM_STATE_IDLE "idle" // Stream is inactive -#define AHL_STREAM_STATE_RUNNING "running" // Stream is active and running -#define AHL_STREAM_STATE_PAUSED "paused" // Stream is active but paused - -// Stream mute state -#define AHL_STREAM_UNMUTED "off" // Stream is not muted -#define AHL_STREAM_MUTED "on" // Stream is muted - -// Property/Volume/Action events -#define AHL_ENDPOINT_PROPERTY_EVENT "ahl_endpoint_property_event" -#define AHL_ENDPOINT_VOLUME_EVENT "ahl_endpoint_volume_event" -#define AHL_ENDPOINT_INIT_EVENT "ahl_endpoint_init_event" -#define AHL_POST_ACTION_EVENT "ahl_post_action" -#define AHL_STREAM_STATE_EVENT "ahl_stream_state_event" -#define AHL_ENDPOINT_INIT_EVENT "ahl_endpoint_init_event" - - -// Stream state event types -#define AHL_STREAM_EVENT_START "start" // Stream is inactive -#define AHL_STREAM_EVENT_STOP "stop" // Stream is running -#define AHL_STREAM_EVENT_PAUSE "pause" // Audio stream paused -#define AHL_STREAM_EVENT_RESUME "resume" // Audio stream resumed -#define AHL_STREAM_EVENT_MUTE "mute" // Audio stream muted -#define AHL_STREAM_EVENT_UNMUTE "unmute" // Audio stream unmuted - -///// Interpret returned or configuration information ///// - -// Known audio domain string definitions (for configuration file format and device URI interpretation) -#define AHL_DOMAIN_ALSA "alsa" -#define AHL_DOMAIN_PULSE "pulse" -#define AHL_DOMAIN_GSTREAMER "gstreamer" -#define AHL_DOMAIN_EXTERNAL "external" - -// ALSA Device URI type -#define AHL_DEVICEURITYPE_ALSA_HW "hw" // Alsa hardware device URI -#define AHL_DEVICEURITYPE_ALSA_DMIX "dmix" // Alsa Dmix device URI (only for playback devices) -#define AHL_DEVICEURITYPE_ALSA_DSNOOP "dsnoop" // Alsa DSnoop device URI (only for capture devices) -#define AHL_DEVICEURITYPE_ALSA_SOFTVOL "softvol" // Alsa softvol device URI -#define AHL_DEVICEURITYPE_ALSA_PLUG "plug" // Alsa plug device URI -#define AHL_DEVICEURITYPE_ALSA_OTHER "other" // Alsa domain URI device of unspecified type -#define AHL_DEVICEURITYPE_NOT_ALSA "nonalsa" - -// Define default behavior of audio role when interrupting lower priority sources (in configuration) -#define AHL_INTERRUPTBEHAVIOR_CONTINUE "continue" // Continue to play when interrupted (e.g. media may be ducked) -#define AHL_INTERRUPTBEHAVIOR_CANCEL "cancel" // Abort playback when interrupted (e.g. non-important HMI feedback that does not make sense later) -#define AHL_INTERRUPTBEHAVIOR_PAUSE "pause" // Pause source when interrupted, to be resumed afterwards (e.g. non-temporal guidance) - -///// Naming convention ///// - -// Standardized name for common audio roles (not enforced in any way, just helps compatibility) -#define AHL_ROLE_WARNING "warning" // Safety-relevant or critical alerts/alarms -#define AHL_ROLE_GUIDANCE "guidance" // Important user information where user action is expected (e.g. navigation instruction) -#define AHL_ROLE_NOTIFICATION "notification" // HMI or else notifications (e.g. touchscreen events, speech recognition on/off,...) -#define AHL_ROLE_COMMUNICATION "communication" // Voice communications (e.g. handsfree, speech recognition) -#define AHL_ROLE_ENTERTAINMENT "entertainment" // Multimedia content (e.g. tuner, media player, etc.) -#define AHL_ROLE_SYSTEM "system" // System level content or development -#define AHL_ROLE_STARTUP "startup" // Early (startup) sound -#define AHL_ROLE_SHUTDOWN "shutdown" // Late (shutdown) sound -#define AHL_ROLE_NONE "none" // Non-assigned / legacy applications - -// Standardized list of properties (not enforced in any way, just helps compatibility) -#define AHL_PROPERTY_BALANCE "balance" -#define AHL_PROPERTY_FADE "fade" -#define AHL_PROPERTY_EQ_LOW "eq_bass" -#define AHL_PROPERTY_EQ_MID "eq_mid" -#define AHL_PROPERTY_EQ_HIGH "eq_treble" - -// Standardized list of events (not enforced in any way, just helps compatibility) -#define AHL_EVENTS_PLAYSOUND "play_sound" -#define AHL_EVENTS_ECHOCANCEL_ENABLE "echocancel_enable" -#define AHL_EVENTS_ECHOCANCEL_DISABLE "echocancel_disable" - -#endif // AHL_INTERFACE_INCLUDE diff --git a/conf.d/cmake/config.cmake b/conf.d/cmake/config.cmake index ba56110..ff824cf 100644 --- a/conf.d/cmake/config.cmake +++ b/conf.d/cmake/config.cmake @@ -54,6 +54,7 @@ set(CONTROL_SUPPORT_LUA 1 CACHE BOOL "Active or not LUA Support") # PKG_CONFIG required packages # ----------------------------- set (PKG_REQUIRED_LIST + glib-2.0 alsa>=1.1.2 libsystemd>=222 libmicrohttpd>=0.9.55 @@ -86,6 +87,7 @@ set(COMPILE_OPTIONS -DMAX_LINEAR_DB_SCALE=24 # until 24db volume normalisation use a simple linear scale -DTLV_BYTE_SIZE=256 # Alsa use 4096 as default but 256 should fit most sndcards -DCONTROL_MAXPATH_LEN=255 +-DCONTROL_CONFIG_PATH="${CMAKE_SOURCE_DIR}/conf.d/project:${CMAKE_INSTALL_PREFIX}/${PROJECT_NAME}" CACHE STRING "Compilation flags") #set(C_COMPILE_OPTIONS "" CACHE STRING "Compilation flags for C language.") #set(CXX_COMPILE_OPTIONS "" CACHE STRING "Compilation flags for C++ language.") @@ -100,7 +102,7 @@ if(IS_DIRECTORY $ENV{HOME}/opt/afb-monitoring) set(MONITORING_ALIAS "--alias=/monitoring:$ENV{HOME}/opt/afb-monitoring") endif() -set(CLOSING_MESSAGE "Debug: afb-daemon --name=afb-aaaa --port=1234 --ws-server=unix:/var/tmp/ahl-4a --cntxtimeout=1 ${MONITORING_ALIAS} --ldpaths=package/lib:../../alsa-4a/build/package/lib:../../hal-sample-4a/build/package/lib --workdir=. --roothttp=../htdocs --token= --verbose ") +set(CLOSING_MESSAGE "Debug: afb-daemon --name=afb-audiok4a --port=1234 --ws-server=unix:/var/tmp/ahl-4a --cntxtimeout=1 ${MONITORING_ALIAS} --binding=package/lib/afb-audiohighlevel.so --ldpaths=../../alsa-4a/build/package/lib:../../hal-sample-4a/build/package/lib --workdir=. --roothttp=../htdocs --token= --verbose ") # Optional location for config.xml.in diff --git a/conf.d/project/.asoundrc b/conf.d/project/.asoundrc deleted file mode 100644 index cba88e5..0000000 --- a/conf.d/project/.asoundrc +++ /dev/null @@ -1,164 +0,0 @@ - - -##### AGL Conf ##### -pcm.SoftMixer { - type dmix - ipc_key 1024 - ipc_key_add_uid false - ipc_perm 0666 # mixing for all users - - # Define target effective sound card (cannot be a plugin) - slave { - pcm "hw:0" # Main sound card - # periods 8 - period_size 1024 - buffer_size 4096 - } - - # DMIX can only map two channels - bindings { - 0 0 - 1 1 - } -} - -pcm.SoftMixer_DriverHR { - type dmix - ipc_key 1024 - ipc_key_add_uid false - ipc_perm 0666 # mixing for all users - - # Define target effective sound card (cannot be a plugin) - slave { - pcm "hw:1" # Alternate sound card / dummy - # periods 8 - period_size 1024 - buffer_size 4096 - } - - # DMIX can only map two channels - bindings { - 0 0 - 1 1 - } -} - -pcm.SoftMixer_RSE { - type dmix - ipc_key 1024 - ipc_key_add_uid false - ipc_perm 0666 # mixing for all users - - # Define target effective sound card (cannot be a plugin) - slave { - pcm "hw:2" # Alternate sound card / dummy - # periods 8 - period_size 1024 - buffer_size 4096 - } - - # DMIX can only map two channels - bindings { - 0 0 - 1 1 - } -} - -pcm.Entertainment_Main { - type softvol - slave.pcm "SoftMixer" - control{ - name "Entertainment_Vol" - card 0 - } -} - -pcm.Guidance_Main { - type softvol - slave.pcm "SoftMixer" - control{ - name "Guidance_Vol" - card 0 - } -} - -pcm.Communications_Main { - type softvol - slave.pcm "SoftMixer" - control{ - name "Communications_Vol" - card 0 - } -} - -pcm.Notification_Main { - type softvol - slave.pcm "SoftMixer" - control{ - name "Notification_Vol" - card 0 - } -} - -pcm.Warning_Main { - type softvol - slave.pcm "SoftMixer" - control{ - name "Warning_Vol" - card 0 - } -} - -pcm.Entertainment_DriverHR { - type softvol - slave.pcm "SoftMixer_DriverHR" - control{ - name "Entertainment_Vol" - card 1 - } -} - -pcm.Guidance_DriverHR { - type softvol - slave.pcm "SoftMixer_DriverHR" - control{ - name "Guidance_Vol" - card 1 - } -} - -pcm.Communications_DriverHR { - type softvol - slave.pcm "SoftMixer_DriverHR" - control{ - name "Communications_Vol" - card 1 - } -} - -pcm.Notification_DriverHR { - type softvol - slave.pcm "SoftMixer_DriverHR" - control{ - name "Notification_Vol" - card 1 - } -} - -pcm.Warning_DriverHR { - type softvol - slave.pcm "SoftMixer_DriverHR" - control{ - name "Warning_Vol" - card 1 - } -} - -pcm.Entertainment_RSE { - type softvol - slave.pcm "SoftMixer_RSE" - control{ - name "Entertainment_Vol" - card 2 - } -} diff --git a/conf.d/project/.asoundrc-audiok b/conf.d/project/.asoundrc-audiok new file mode 100644 index 0000000..cba88e5 --- /dev/null +++ b/conf.d/project/.asoundrc-audiok @@ -0,0 +1,164 @@ + + +##### AGL Conf ##### +pcm.SoftMixer { + type dmix + ipc_key 1024 + ipc_key_add_uid false + ipc_perm 0666 # mixing for all users + + # Define target effective sound card (cannot be a plugin) + slave { + pcm "hw:0" # Main sound card + # periods 8 + period_size 1024 + buffer_size 4096 + } + + # DMIX can only map two channels + bindings { + 0 0 + 1 1 + } +} + +pcm.SoftMixer_DriverHR { + type dmix + ipc_key 1024 + ipc_key_add_uid false + ipc_perm 0666 # mixing for all users + + # Define target effective sound card (cannot be a plugin) + slave { + pcm "hw:1" # Alternate sound card / dummy + # periods 8 + period_size 1024 + buffer_size 4096 + } + + # DMIX can only map two channels + bindings { + 0 0 + 1 1 + } +} + +pcm.SoftMixer_RSE { + type dmix + ipc_key 1024 + ipc_key_add_uid false + ipc_perm 0666 # mixing for all users + + # Define target effective sound card (cannot be a plugin) + slave { + pcm "hw:2" # Alternate sound card / dummy + # periods 8 + period_size 1024 + buffer_size 4096 + } + + # DMIX can only map two channels + bindings { + 0 0 + 1 1 + } +} + +pcm.Entertainment_Main { + type softvol + slave.pcm "SoftMixer" + control{ + name "Entertainment_Vol" + card 0 + } +} + +pcm.Guidance_Main { + type softvol + slave.pcm "SoftMixer" + control{ + name "Guidance_Vol" + card 0 + } +} + +pcm.Communications_Main { + type softvol + slave.pcm "SoftMixer" + control{ + name "Communications_Vol" + card 0 + } +} + +pcm.Notification_Main { + type softvol + slave.pcm "SoftMixer" + control{ + name "Notification_Vol" + card 0 + } +} + +pcm.Warning_Main { + type softvol + slave.pcm "SoftMixer" + control{ + name "Warning_Vol" + card 0 + } +} + +pcm.Entertainment_DriverHR { + type softvol + slave.pcm "SoftMixer_DriverHR" + control{ + name "Entertainment_Vol" + card 1 + } +} + +pcm.Guidance_DriverHR { + type softvol + slave.pcm "SoftMixer_DriverHR" + control{ + name "Guidance_Vol" + card 1 + } +} + +pcm.Communications_DriverHR { + type softvol + slave.pcm "SoftMixer_DriverHR" + control{ + name "Communications_Vol" + card 1 + } +} + +pcm.Notification_DriverHR { + type softvol + slave.pcm "SoftMixer_DriverHR" + control{ + name "Notification_Vol" + card 1 + } +} + +pcm.Warning_DriverHR { + type softvol + slave.pcm "SoftMixer_DriverHR" + control{ + name "Warning_Vol" + card 1 + } +} + +pcm.Entertainment_RSE { + type softvol + slave.pcm "SoftMixer_RSE" + control{ + name "Entertainment_Vol" + card 2 + } +} diff --git a/conf.d/project/.asounrc-fulup b/conf.d/project/.asounrc-fulup new file mode 100644 index 0000000..c98d5a8 --- /dev/null +++ b/conf.d/project/.asounrc-fulup @@ -0,0 +1,198 @@ +# +# Author: Fulup Ar Foll +# Object: PCM hook type +# +# Test : Note: Jabra_USB=hw:v1340 +# Check SoundCard ==> speaker-test -Dhw:v1340 -c2 -twav +# Check MixerPCM ==> speaker-test -DSpeakers -c2 -twav +# Check SoftVol ==> speaker-test -DMusicPCM -c2 -twav +# Check Plugin ==> speaker-test -DMultimedia -c2 -twav +# Check Plugin ==> speaker-test -DNavigation -c2 -twav +# +# MultiMedia aplay -DDMyNavPCM /usr/share/sounds/alsa/test.wav +# +# Bug/Feature: when softvol control is initialised from plugin and not +# from AGL binding. At 1st run ctl has invalid TLV and cannot be +# use. Bypass Solution: +# * start audio-binder before playing sound (binding create control before softvol plugin) +# * run a dummy aplay -DMyNavPCM "" to get a clean control +# +# References: https://www.spinics.net/lists/alsa-devel/msg54235.html +# -------------------------------------------------------------------- + +# ------------------------------------------------------ +# Mixer PCM allow to play multiple stream simultaneously +# ------------------------------------------------------ +pcm.Speakers { + type dmix + slave {pcm "hw:v1340"} #Jabra Solmate 1 + ipc_key 1001 # ipc_key should be unique to each dmix +} + +# ----------------------------------------------------- +# Register ControllerHookPlugin (ToiBeFix fullpath) +# ----------------------------------------------------- +pcm_hook_type.CtlHookPlugin { + install "AlsaInstallHook" + lib "/home/fulup/Workspace/Audio-4a/alsa-4a/build/alsa-hook/policy_alsa_hook.so" +} + + +# ------------------------------------------------------- +# Define one Audio Virtual Channel per Audio Roles +# ------------------------------------------------------- +pcm.MusicPCM { + type softvol + + # Point Slave on HOOK for policies control + slave.pcm "Speakers" + + # name should match with HAL definition + control.name "Playback Multimedia" +} + +pcm.NaviPCM { + type softvol + + # Point Slave on HOOK for policies control + slave.pcm "Speakers" + + # name should match with HAL definition + control.name "Playback Navigation" +} + +pcm.UrgentPCM { + type softvol + + # Point Slave on HOOK for policies control + slave.pcm "Speakers" + + # name should match with HAL definition + control.name "Playback Emergency" +} + +# ---------------------------------------------------- +# Define one hooked PCM channel per Audio Roles +# ---------------------------------------------------- +pcm.Multimedia { + type hooks + slave {pcm "MusicPCM"} + hooks.0 { + comment "Defined used hook sharelib and provide arguments/config to install func" + type "CtlHookPlugin" + hook_args { + + # print few log messages (default false) + verbose true + + # uri to audio-4a policy engine + uri="unix:/var/tmp/ahl-4a" + + # timeout in ms (default 500) + timeout 5000 + + # force API synchronous mode + synchronous true + + # api subcall to request a role + request { + stream_open "{'audio_role':'Entertainment', 'endpoint_type': 'sink'}" + set_stream_state "{'state': 'running'}" + } + + # api subcall to request a role + release { + stream_close "{}" + } + + # map AGL event on Unix signal. Search in event for json key=value + events { + sig-02 {search music, value quit} + sig-31 {search event, value start} + sig-32 {search event, value start} + } + } + } +} + +pcm.Navigation { + type hooks + slave {pcm "NaviPCM"} + hooks.0 { + comment "Defined used hook sharelib and provide arguments/config to install func" + type "CtlHookPlugin" + hook_args { + + # print few log messages (default false) + verbose true + + # uri to audio-4a policy engine + uri="unix:/var/tmp/ahl-4a" + + # timeout in ms (default 500) + timeout 5000 + + # force API synchronous mode + synchronous true + + # api subcall to request a role + request { + stream_open "{'audio_role':'Guidance', 'endpoint_type': 'sink'}" + set_stream_state "{'state': 'running'}" + } + + # api subcall to request a role + release { + release-role "{'uid':'alsa-hook-client'}" + } + + # map AGL event on Unix signal. Search in event for json key=value + events { + sig-02 {search navi, value quit} + sig-31 {search event, value start} + sig-32 {search event, value start} + } + } + } +} + +pcm.Emergency { + type hooks + slave {pcm "UrgentPCM"} + hooks.0 { + comment "Defined used hook sharelib and provide arguments/config to install func" + type "CtlHookPlugin" + hook_args { + + # print few log messages (default false) + verbose true + + # uri to audio-4a policy engine + uri="unix:/var/tmp/ahl-4a" + + # timeout in ms (default 500) + timeout 5000 + + # force API synchronous mode + synchronous true + + # api subcall to request a role + request { + stream_open "{'audio_role':'Emergency', 'endpoint_type': 'sink'}" + set_stream_state "{'state': 'running'}" + } + + # api subcall to request a role + release { + release-role "{'uid':'alsa-hook-client'}" + } + + # map AGL event on Unix signal. Search in event for json key=value + events { + sig-02 {search navi, value quit} + sig-31 {search event, value start} + sig-32 {search event, value start} + } + } + } +} diff --git a/conf.d/project/README.md b/conf.d/project/README.md new file mode 100644 index 0000000..00e3c2f --- /dev/null +++ b/conf.d/project/README.md @@ -0,0 +1,15 @@ + +1) $HOME/.asoundrc or /etc/asound.conf should match you hardware audio configuration. +2) ahl-xxxxxx-config.json should match your .asoundrc config + +Note: config file is search within with following rules: + - default search path is $PROJECT_ROOT/conf.d/project:${CMAKE_INSTALL_PREFIX}/${PROJECT_NAME} + - if environment variable "AAAA_CONFIG_PATH" is defined that it is used as search path + - config file should match "ahl-BINDERNAME-config.json" where BINDERNAME is provided through "--name=BINDERNAME" in afb-daemon commande line. + +Note: you may debug Audio-4A from your development tree with: + + afb-daemon --name=afb-audio4a --port=1234 --ws-server=unix:/var/tmp/ahl-4a --cntxtimeout=1 \ + --alias=/monitoring:/home/fulup/opt/afb-monitoring --binding=package/lib/afb-audiohighlevel.so \ + --ldpaths=../../alsa-4a/build/package/lib:../../hal-sample-4a/build/package/lib --workdir=. \ + --roothttp=../htdocs --token= --verbose --verbose \ No newline at end of file diff --git a/conf.d/project/agl-ahl-config.json b/conf.d/project/agl-ahl-config.json deleted file mode 100644 index f49c0be..0000000 --- a/conf.d/project/agl-ahl-config.json +++ /dev/null @@ -1,128 +0,0 @@ -{ - "version": "0.2.0", - "policy_module": "AudioPolicy_v1", - "description": "High-level binding configuration file", - "note": "Devices and routings are always listed in order of priority (for device selection rules)", - "hal_list": ["ensoniq","usbaudio"], - "audio_roles": [ - { - "name": "Warning", - "id": 0, - "description": "Safety-relevant or critical alerts/alarms", - "priority": 100, - "output": [ - "alsa.plug:Warning_Main", - "alsa.plug:Warning_DriverHR" - ], - "actions": [ - "emergency_brake", - "collision_warning", - "blind_spot_warning" - ], - "interupt_behavior": "pause" - }, - { - "name": "Guidance", - "id": 1, - "description": "Important user information where user action is expected (e.g. navigation instruction)", - "priority": 25, - "output": [ - "alsa.plug:Guidance_Main", - "alsa.plug:Guidance_DriverHR" - ], - "actions": [ - "lane_guidance_left", - "lane_guidance_right", - "destination_reached" - ], - "interupt_behavior": "continue" - }, - { - "name": "Notification", - "id": 2, - "description": "HMI or else notifications (e.g. touchscreen events, speech recognition on/off,...)", - "priority": 0, - "output": [ - "alsa.plug:Notification_Main", - "alsa.plug:Notification_DriverHR" - ], - "actions": [ - "home", - "context_switch", - "accept", - "cancel", - "selection_change" - ], - "interupt_behavior": "cancel" - }, - { - "name": "Communication", - "id": 3, - "description": "Voice communications (e.g. handsfree, speech recognition)", - "priority": 50, - "output": [ - "alsa.plug:Communications_Main", - "alsa.plug:Communications_DriverHR", - ], - "input": [ - "alsa.hw:0", - ], - "actions": [ - "bt_device_connected", - "bt_device_disconnected", - "sms_received" - ], - "interupt_behavior": "continue" - }, - { - "name": "Entertainment", - "id": 4, - "description": "Multimedia content (e.g. tuner, media player, etc.)", - "priority": 0, - "output": [ - "alsa.plug:Entertainment_Main", - "alsa.plug:Entertainment_DriverHR", - ], - "interupt_behavior": "pause" - }, - { - "name": "System", - "id": 5, - "description": "System level content or development", - "priority": 100, - "output": [ - "alsa.hw:0" - ], - "input": [ - "alsa.hw:0" - ], - "interupt_behavior": "continue" - }, - { - "name": "Startup", - "id": 6, - "description": "Early (startup) sound", - "priority": 100, - "output": [ - "alsa.hw:0" - ], - "actions": [ - "welcome_sound" - ], - "interupt_behavior": "pause" - }, - { - "name": "Shutdown", - "id": 7, - "description": "Late (shutdown) sound", - "priority": 100, - "output": [ - "alsa.hw:0" - ], - "actions": [ - "goodbye_sound" - ], - "interupt_behavior": "cancel" - } - ] -} diff --git a/conf.d/project/ahl-audiok4a-config.json b/conf.d/project/ahl-audiok4a-config.json new file mode 100644 index 0000000..f49c0be --- /dev/null +++ b/conf.d/project/ahl-audiok4a-config.json @@ -0,0 +1,128 @@ +{ + "version": "0.2.0", + "policy_module": "AudioPolicy_v1", + "description": "High-level binding configuration file", + "note": "Devices and routings are always listed in order of priority (for device selection rules)", + "hal_list": ["ensoniq","usbaudio"], + "audio_roles": [ + { + "name": "Warning", + "id": 0, + "description": "Safety-relevant or critical alerts/alarms", + "priority": 100, + "output": [ + "alsa.plug:Warning_Main", + "alsa.plug:Warning_DriverHR" + ], + "actions": [ + "emergency_brake", + "collision_warning", + "blind_spot_warning" + ], + "interupt_behavior": "pause" + }, + { + "name": "Guidance", + "id": 1, + "description": "Important user information where user action is expected (e.g. navigation instruction)", + "priority": 25, + "output": [ + "alsa.plug:Guidance_Main", + "alsa.plug:Guidance_DriverHR" + ], + "actions": [ + "lane_guidance_left", + "lane_guidance_right", + "destination_reached" + ], + "interupt_behavior": "continue" + }, + { + "name": "Notification", + "id": 2, + "description": "HMI or else notifications (e.g. touchscreen events, speech recognition on/off,...)", + "priority": 0, + "output": [ + "alsa.plug:Notification_Main", + "alsa.plug:Notification_DriverHR" + ], + "actions": [ + "home", + "context_switch", + "accept", + "cancel", + "selection_change" + ], + "interupt_behavior": "cancel" + }, + { + "name": "Communication", + "id": 3, + "description": "Voice communications (e.g. handsfree, speech recognition)", + "priority": 50, + "output": [ + "alsa.plug:Communications_Main", + "alsa.plug:Communications_DriverHR", + ], + "input": [ + "alsa.hw:0", + ], + "actions": [ + "bt_device_connected", + "bt_device_disconnected", + "sms_received" + ], + "interupt_behavior": "continue" + }, + { + "name": "Entertainment", + "id": 4, + "description": "Multimedia content (e.g. tuner, media player, etc.)", + "priority": 0, + "output": [ + "alsa.plug:Entertainment_Main", + "alsa.plug:Entertainment_DriverHR", + ], + "interupt_behavior": "pause" + }, + { + "name": "System", + "id": 5, + "description": "System level content or development", + "priority": 100, + "output": [ + "alsa.hw:0" + ], + "input": [ + "alsa.hw:0" + ], + "interupt_behavior": "continue" + }, + { + "name": "Startup", + "id": 6, + "description": "Early (startup) sound", + "priority": 100, + "output": [ + "alsa.hw:0" + ], + "actions": [ + "welcome_sound" + ], + "interupt_behavior": "pause" + }, + { + "name": "Shutdown", + "id": 7, + "description": "Late (shutdown) sound", + "priority": 100, + "output": [ + "alsa.hw:0" + ], + "actions": [ + "goodbye_sound" + ], + "interupt_behavior": "cancel" + } + ] +} diff --git a/conf.d/project/ahl-fulup4a-config.json b/conf.d/project/ahl-fulup4a-config.json new file mode 100644 index 0000000..1a851a5 --- /dev/null +++ b/conf.d/project/ahl-fulup4a-config.json @@ -0,0 +1,39 @@ +{ + "version": "0.2.0", + "policy_module": "AudioPolicy_v1", + "description": "High-level binding configuration file", + "note": "Devices and routings are always listed in order of priority (for device selection rules)", + "hal_list": ["jabra-usb"], + "audio_roles": [ + { + "name": "Guidance", + "id": 1, + "description": "Important user information where user action is expected (e.g. navigation instruction)", + "priority": 25, + "output": [ + "alsa.plug:NaviPCM" + ], + "interupt_behavior": "continue" + }, + { + "name": "Emergency", + "id": 2, + "description": "HMI or else notifications (e.g. touchscreen events, speech recognition on/off,...)", + "priority": 100, + "output": [ + "alsa.plug:UrgentPCM" + ], + "interupt_behavior": "pause" + }, + { + "name": "Entertainment", + "id": 3, + "description": "Multimedia content (e.g. tuner, media player, etc.)", + "priority": 0, + "output": [ + "alsa.plug:MusicPCM" + ], + "interupt_behavior": "pause" + } + ] +} diff --git a/nbproject/configurations.xml b/nbproject/configurations.xml index 8ebd7d3..93a17f5 100644 --- a/nbproject/configurations.xml +++ b/nbproject/configurations.xml @@ -12,7 +12,6 @@ ahl-deviceenum.c - ahl-interface.h ahl-policy-utils.c ahl-policy-utils.h @@ -87,8 +86,6 @@ - - diff --git a/nbproject/project.xml b/nbproject/project.xml index 72c2a3b..3e0cffd 100644 --- a/nbproject/project.xml +++ b/nbproject/project.xml @@ -6,7 +6,7 @@ afb-audiohighlevel c cpp,cxx - h + h,hpp UTF-8 -- cgit 1.2.3-korg