diff options
-rw-r--r-- | README.md | 4 | ||||
-rw-r--r-- | src/ahl-binding.c | 18 | ||||
-rw-r--r-- | src/ahl-binding.h | 127 | ||||
-rw-r--r-- | src/ahl-config.c | 6 | ||||
-rw-r--r-- | src/ahl-policy-utils.c | 94 | ||||
-rw-r--r-- | src/ahl-policy-utils.h | 152 | ||||
-rw-r--r-- | src/ahl-policy.c | 17 | ||||
-rw-r--r-- | src/ahl-policy.h | 21 |
8 files changed, 196 insertions, 243 deletions
@@ -8,6 +8,10 @@ ``` # Initial clone with submodules git clone https://github.com/Audiokinetic-Automotive/afb-audiohighlevel.git +<<<<<<< HEAD +cd afb-audiohighlevel +======= +>>>>>>> 8a584f01b46d251fdc5de8b071eff755d99f0090 ``` diff --git a/src/ahl-binding.c b/src/ahl-binding.c index cd89b64..264930f 100644 --- a/src/ahl-binding.c +++ b/src/ahl-binding.c @@ -296,7 +296,7 @@ static void TerminateClientContext(void * ptr) json_object *pPolicyStreamJ = NULL; int err = PolicyStreamStructToJSON(pStreamInfo, &pPolicyStreamJ); - if (err == AHL_FAIL) + if (err == AHL_POLICY_UTIL_FAIL) { AFB_ERROR("Audio policy violation, Unable to get JSON object for Policy_CloseStream"); return; @@ -481,7 +481,7 @@ PUBLIC int AhlBindingInit() g_assert_nonnull(pCurEndpointInfo); json_object *pPolicyEndpointJ = NULL; err = PolicyEndpointStructToJSON(pCurEndpointInfo, &pPolicyEndpointJ); - if (err == AHL_FAIL) + if (err == AHL_POLICY_UTIL_FAIL) { AFB_ERROR("Unable to Create Endpoint Json object error:%s ",wrap_json_get_error_string(err)); return err; @@ -504,7 +504,7 @@ PUBLIC int AhlBindingInit() g_assert_nonnull(pCurEndpointInfo); json_object *pPolicyEndpointJ = NULL; err = PolicyEndpointStructToJSON(pCurEndpointInfo, &pPolicyEndpointJ); - if (err == AHL_FAIL) + if (err == AHL_POLICY_UTIL_FAIL) { AFB_ERROR("Unable to Create Endpoint Json object error:%s ",wrap_json_get_error_string(err)); return err; @@ -725,7 +725,7 @@ PUBLIC void audiohlapi_stream_open(struct afb_req req) // Call policy to verify whether creating a new audio stream is allowed in current context and possibly take other actions json_object *pPolicyStreamJ = NULL; err = PolicyStreamStructToJSON(pStreamInfo, &pPolicyStreamJ); - if (err == AHL_FAIL) + if (err == AHL_POLICY_UTIL_FAIL) { afb_req_fail(req, "Audio policy violation", "Unable to get JSON object for Policy_OpenStream"); return; @@ -806,7 +806,7 @@ PUBLIC void audiohlapi_stream_close(struct afb_req req) #ifndef AHL_DISCONNECT_POLICY json_object *pPolicyStreamJ = NULL; err = PolicyStreamStructToJSON(pStreamInfo, &pPolicyStreamJ); - if (err == AHL_FAIL) + if (err == AHL_POLICY_UTIL_FAIL) { afb_req_fail(req, "Audio policy violation", "Unable to get JSON object for Policy_CloseStream"); return; @@ -897,7 +897,7 @@ PUBLIC void audiohlapi_stream_close(struct afb_req req) #ifndef AHL_DISCONNECT_POLICY json_object *pPolicyStreamJ = NULL; err = PolicyStreamStructToJSON(pStreamInfo, &pPolicyStreamJ); - if (err == AHL_FAIL) + if (err == AHL_POLICY_UTIL_FAIL) { afb_req_fail(req, "Audio policy violation", "Unable to get JSON object for Policy_SetStreamState"); return; @@ -961,7 +961,7 @@ PUBLIC void audiohlapi_stream_close(struct afb_req req) #ifndef AHL_DISCONNECT_POLICY json_object *pPolicyStreamJ = NULL; err = PolicyStreamStructToJSON(pStreamInfo, &pPolicyStreamJ); - if (err == AHL_FAIL) + if (err == AHL_POLICY_UTIL_FAIL) { afb_req_fail(req, "Audio policy violation", "Unable to get JSON object for Policy_SetStreamMute"); return; @@ -1036,7 +1036,7 @@ PUBLIC void audiohlapi_set_volume(struct afb_req req) #ifndef AHL_DISCONNECT_POLICY json_object *pPolicyEndpointJ = NULL; err = PolicyEndpointStructToJSON(pEndpointInfo, &pPolicyEndpointJ); - if (err == AHL_FAIL) + if (err == AHL_POLICY_UTIL_FAIL) { afb_req_fail(req, "Audio policy violation", "Unable to get JSON object for Policy_SetVolume"); return; @@ -1146,7 +1146,7 @@ PUBLIC void audiohlapi_set_property(struct afb_req req) #ifndef AHL_DISCONNECT_POLICY json_object *pPolicyEndpointJ = NULL; err = PolicyEndpointStructToJSON(pEndpointInfo, &pPolicyEndpointJ); - if (err == AHL_FAIL) + if (err == AHL_POLICY_UTIL_FAIL) { afb_req_fail(req, "Audio policy violation", "Unable to get JSON object for Policy_SetVolume"); return; diff --git a/src/ahl-binding.h b/src/ahl-binding.h index af122c3..9b4c37e 100644 --- a/src/ahl-binding.h +++ b/src/ahl-binding.h @@ -24,8 +24,10 @@ #include <json-c/json.h> #include <glib.h> -#include "ahl-interface.h" #include <afb/afb-binding.h> +#include "ahl-interface.h" +#include "ahl-policy-utils.h" + #ifndef PUBLIC #define PUBLIC @@ -34,135 +36,12 @@ #define AHL_SUCCESS 0 #define AHL_FAIL 1 -#define AHL_POLICY_ACCEPT 1 -#define AHL_POLICY_REJECT 0 - #define AHL_ACCESS_CONTROL_GRANTED 1 #define AHL_ACCESS_CONTROL_DENIED 0 #define AHL_UNDEFINED -1 - -typedef int endpointID_t; -typedef int streamID_t; - #define AHL_STR_MAX_LENGTH 256 -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; - -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 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; - -// 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 RoleInfo { char * pRoleName; // Role string identifier diff --git a/src/ahl-config.c b/src/ahl-config.c index 168311e..5e3de08 100644 --- a/src/ahl-config.c +++ b/src/ahl-config.c @@ -48,6 +48,12 @@ int ParseHLBConfig() { // 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; + } + sprintf(configfile_path, "%s", getenv("AHL_CONFIG_FILE")); AFB_INFO("High-level config file -> %s\n", configfile_path); diff --git a/src/ahl-policy-utils.c b/src/ahl-policy-utils.c index 52c5862..60ddd36 100644 --- a/src/ahl-policy-utils.c +++ b/src/ahl-policy-utils.c @@ -38,76 +38,12 @@ void Add_Endpoint_Property_String( EndpointInfoT * io_pEndpointInfo, char * in_p g_hash_table_insert(io_pEndpointInfo->pPropTable, in_pPropertyName, propValueJ); } -int PolicyCtxStructToJSON(AHLPolicyCtxT * pPolicyCtx, json_object **ppPolicyCxtJ) -{ - if(pPolicyCtx == NULL) - { - AFB_ERROR("Policy context is NULL"); - return AHL_FAIL; - } - - //Create json object for HALList - json_object *HallListJ = json_object_new_array(); - for(int i=0; i<pPolicyCtx->pHALList->len; i++) - { - char *hallname = g_ptr_array_index(pPolicyCtx->pHALList, i); - json_object *hallNameJ = json_object_new_string(hallname); - json_object_array_add(HallListJ, hallNameJ); - } - - int err = wrap_json_pack(ppPolicyCxtJ, "{s:i,s:o}", - "number_roles", (int)g_hash_table_size(pPolicyCtx->pRoleInfo), - "halllist", HallListJ); - if (err) { - AFB_ERROR("Unable to pack JSON endpoint, =%s", wrap_json_get_error_string(err)); - } - - return AHL_SUCCESS; -} - - - int PolicyCtxJSONToStruct(json_object *CtxJ, int *pNbAudioRole, GPtrArray *pHALList) -{ - if(CtxJ == NULL || pHALList == NULL) - { - AFB_ERROR("Invalid arguments to PolicyCtxJSONToStruct"); - return AHL_FAIL; - } - - json_object *HallListJ = NULL; - int err = wrap_json_unpack(CtxJ, "{s:i, s:o}", - "number_roles", &pNbAudioRole, - "halllist", &HallListJ); - if (err) { - AFB_ERROR("Unable to unpack JSON endpoint, =%s", wrap_json_get_error_string(err)); - return AHL_FAIL; - } - - if(HallListJ) - { - int nbHall = json_object_array_length(HallListJ); - //Create HallList - for(int i=0; i<nbHall; i++) - { - char * pHAL = NULL; - json_object * jHAL = json_object_array_get_idx(HallListJ,i); - if (jHAL) { - pHAL = (char *)json_object_get_string(jHAL); - char * pHALName = g_strdup( pHAL ); - g_ptr_array_add( pHALList, pHALName ); - } - } - } - - return AHL_SUCCESS; -} - int PolicyEndpointStructToJSON(EndpointInfoT * pEndpointInfo, json_object **ppPolicyEndpointJ) { if(pEndpointInfo == NULL || pEndpointInfo->pPropTable == NULL) { AFB_ERROR("Invalid PolicyEndpointStructToJSON arguments"); - return AHL_FAIL; + return AHL_POLICY_UTIL_FAIL; } //Create json object for PropTable @@ -126,7 +62,7 @@ int PolicyEndpointStructToJSON(EndpointInfoT * pEndpointInfo, json_object **ppPo if(error) { AFB_ERROR("Unable to pack JSON endpoint, =%s", wrap_json_get_error_string(error)); - return AHL_FAIL; + return AHL_POLICY_UTIL_FAIL; } json_object_array_add(pPropTableJ, pPropertyJ); } @@ -155,10 +91,10 @@ int PolicyEndpointStructToJSON(EndpointInfoT * pEndpointInfo, json_object **ppPo ); if (err) { AFB_ERROR("Unable to pack JSON endpoint, =%s", wrap_json_get_error_string(err)); - return AHL_FAIL; + return AHL_POLICY_UTIL_FAIL; } AFB_DEBUG("JSON endpoint information=%s", json_object_get_string(*ppPolicyEndpointJ)); - return AHL_SUCCESS; + return AHL_POLICY_UTIL_SUCCESS; } int PolicyStreamStructToJSON(StreamInfoT * pPolicyStream, json_object **ppPolicyStreamJ) @@ -166,7 +102,7 @@ int PolicyStreamStructToJSON(StreamInfoT * pPolicyStream, json_object **ppPolicy if(pPolicyStream == NULL) { AFB_ERROR("Invalid arguments to PolicyStreamStructToJSON"); - return AHL_FAIL; + return AHL_POLICY_UTIL_FAIL; } json_object * pEndpointJ = NULL; @@ -189,12 +125,12 @@ int PolicyStreamStructToJSON(StreamInfoT * pPolicyStream, json_object **ppPolicy ); if (err) { AFB_ERROR("Unable to pack JSON endpoint, =%s", wrap_json_get_error_string(err)); - return AHL_FAIL; + return AHL_POLICY_UTIL_FAIL; } AFB_DEBUG("JSON stream information=%s", json_object_get_string(*ppPolicyStreamJ)); - return AHL_SUCCESS; + return AHL_POLICY_UTIL_SUCCESS; } int PolicyCtxJSONToEndpoint(json_object *pEndpointJ, EndpointInfoT * pEndpointInfo) @@ -202,7 +138,7 @@ int PolicyCtxJSONToEndpoint(json_object *pEndpointJ, EndpointInfoT * pEndpointIn if(pEndpointJ == NULL || pEndpointInfo == NULL /*|| pEndpointInfo->pPropTable == NULL */ ) { AFB_ERROR("Invalid arguments for PolicyCtxJSONToEndpoint"); - return AHL_FAIL; + return AHL_POLICY_UTIL_FAIL; } //Unpack Endpoint @@ -228,7 +164,7 @@ int PolicyCtxJSONToEndpoint(json_object *pEndpointJ, EndpointInfoT * pEndpointIn ); if (err) { AFB_ERROR("Unable to unpack JSON endpoint, =%s", wrap_json_get_error_string(err)); - return AHL_FAIL; + return AHL_POLICY_UTIL_FAIL; } // Unpack prop table @@ -249,7 +185,7 @@ int PolicyCtxJSONToEndpoint(json_object *pEndpointJ, EndpointInfoT * pEndpointIn "property_value", &pPropertyValueJ); if (err) { AFB_ERROR("Unable to unpack JSON endpoint, = %s", wrap_json_get_error_string(err)); - return AHL_FAIL; + return AHL_POLICY_UTIL_FAIL; } // Object type detection for property value (string = state, numeric = property) @@ -266,13 +202,13 @@ int PolicyCtxJSONToEndpoint(json_object *pEndpointJ, EndpointInfoT * pEndpointIn break; default: AFB_ERROR("Invalid property argument Property value not a valid json object query=%s", json_object_get_string(pPropertyValueJ)); - return AHL_FAIL; + return AHL_POLICY_UTIL_FAIL; } } } } - return AHL_SUCCESS; + return AHL_POLICY_UTIL_SUCCESS; } int PolicyCtxJSONToStream(json_object *pStreamJ, StreamInfoT * pPolicyStream) @@ -280,7 +216,7 @@ int PolicyCtxJSONToStream(json_object *pStreamJ, StreamInfoT * pPolicyStream) if(pStreamJ == NULL || pPolicyStream == NULL) { AFB_ERROR("Invalid arguments for PolicyCtxJSONToStream"); - return AHL_FAIL; + return AHL_POLICY_UTIL_FAIL; } //Unpack StreamInfo @@ -300,13 +236,13 @@ int PolicyCtxJSONToStream(json_object *pStreamJ, StreamInfoT * pPolicyStream) if (err) { AFB_ERROR("Unable to parse JSON stream information=%s", json_object_get_string(pStreamJ)); - return AHL_FAIL; + return AHL_POLICY_UTIL_FAIL; } int iRet = PolicyCtxJSONToEndpoint(pEndpointJ,pPolicyStream->pEndpointInfo); if (iRet) { return iRet; } - return AHL_SUCCESS; + return AHL_POLICY_UTIL_SUCCESS; }
\ No newline at end of file diff --git a/src/ahl-policy-utils.h b/src/ahl-policy-utils.h index 6774f13..6adfa4e 100644 --- a/src/ahl-policy-utils.h +++ b/src/ahl-policy-utils.h @@ -17,14 +17,158 @@ #ifndef AHL_POLICY_UTILS_INCLUDE #define AHL_POLICY_UTILS_INCLUDE -#include "ahl-binding.h" +#define AFB_BINDING_VERSION 2 +#include <json-c/json.h> +#include <afb/afb-binding.h> +#include <glib.h> + +#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 PolicyCtxStructToJSON(AHLPolicyCtxT * pPolicyCtx, json_object **ppPolicyCxtJ); -int PolicyCtxJSONToStruct(json_object *CtxJ, int *pNbAudioRole,GPtrArray *pHALList); int PolicyEndpointStructToJSON(EndpointInfoT * pPolicyEndpoint, json_object **ppPolicyEndpointJ); int PolicyCtxJSONToEndpoint(json_object *pEndpointJ, EndpointInfoT * pPolicyStream); int PolicyStreamStructToJSON(StreamInfoT * pPolicyStream, json_object **ppPolicyStreamJ); diff --git a/src/ahl-policy.c b/src/ahl-policy.c index ba15fd2..54634ff 100644 --- a/src/ahl-policy.c +++ b/src/ahl-policy.c @@ -20,6 +20,7 @@ #include <stdbool.h> #include "wrap-json.h" #include "ahl-policy-utils.h" +#include "ahl-interface.h" #include "ahl-policy.h" #ifndef AHL_DISCONNECT_POLICY @@ -592,7 +593,7 @@ int Policy_OpenStream(json_object *pPolicyStreamJ) PolicyStream.pEndpointInfo =&EndpointInfo; int err = PolicyCtxJSONToStream(pPolicyStreamJ, &PolicyStream); - if(err == AHL_FAIL) + if(err == AHL_POLICY_UTIL_FAIL) { return AHL_POLICY_ACCEPT; } @@ -639,7 +640,7 @@ int Policy_CloseStream(json_object *pPolicyStreamJ) EndpointInfoT EndpointInfo; PolicyStream.pEndpointInfo =&EndpointInfo; int err = PolicyCtxJSONToStream(pPolicyStreamJ, &PolicyStream); - if(err == AHL_FAIL) + if(err == AHL_POLICY_UTIL_FAIL) { return AHL_POLICY_ACCEPT; } @@ -659,7 +660,7 @@ int Policy_SetStreamState(json_object *pPolicyStreamJ) StreamStateT streamState = 0; StreamInfoT * pPolicyStream = &PolicyStream; int err = PolicyCtxJSONToStream(pPolicyStreamJ, pPolicyStream); - if(err == AHL_FAIL) + if(err == AHL_POLICY_UTIL_FAIL) { return AHL_POLICY_ACCEPT; } @@ -759,7 +760,7 @@ int Policy_SetStreamMute(json_object *pPolicyStreamJ) StreamInfoT * pPolicyStream = &PolicyStream; int err = PolicyCtxJSONToStream(pPolicyStreamJ, pPolicyStream); - if(err == AHL_FAIL) + if(err == AHL_POLICY_UTIL_FAIL) { return AHL_POLICY_ACCEPT; } @@ -821,7 +822,7 @@ int Policy_SetVolume(json_object *pPolicyEndpointJ) EndpointInfoT EndpointInfo; int err = PolicyCtxJSONToEndpoint(pPolicyEndpointJ, &EndpointInfo); - if(err == AHL_FAIL) + if(err == AHL_POLICY_UTIL_FAIL) { return AHL_POLICY_ACCEPT; } @@ -861,7 +862,7 @@ int Policy_SetProperty(json_object *pPolicyEndpointJ) EndpointInfoT EndpointInfo; int err = PolicyCtxJSONToEndpoint(pPolicyEndpointJ, &EndpointInfo); - if(err == AHL_FAIL) + if(err == AHL_POLICY_UTIL_FAIL) { return AHL_POLICY_ACCEPT; } @@ -957,7 +958,7 @@ int Policy_Endpoint_Init(json_object *pPolicyEndpointJ) EndpointInfoT EndpointInfo; int err = PolicyCtxJSONToEndpoint(pPolicyEndpointJ, &EndpointInfo); - if(err == AHL_FAIL) + if(err == AHL_POLICY_UTIL_FAIL) { return AHL_POLICY_REJECT; } @@ -1004,7 +1005,7 @@ int Policy_Endpoint_Init(json_object *pPolicyEndpointJ) //Create a new Json Object json_object *pNewPolicyEndpointJ = NULL; err = PolicyEndpointStructToJSON(&EndpointInfo, &pNewPolicyEndpointJ); - if (err == AHL_FAIL) + if (err == AHL_POLICY_UTIL_FAIL) { return AHL_POLICY_REJECT; } diff --git a/src/ahl-policy.h b/src/ahl-policy.h index dfb3d7c..d1cf87e 100644 --- a/src/ahl-policy.h +++ b/src/ahl-policy.h @@ -16,7 +16,7 @@ #ifndef AHL_POLICY_INCLUDE #define AHL_POLICY_INCLUDE -#include "ahl-binding.h" +#include "ahl-policy-utils.h" #ifndef AHL_DISCONNECT_POLICY @@ -35,24 +35,6 @@ typedef enum SystemState { SYSTEM_MAXVALUE // Enum count, keep at the end } SystemStateT; -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; - typedef struct HalInfo { char *pDevID; @@ -86,5 +68,6 @@ int Policy_Init(); void Policy_Term(); void Policy_OnEvent(const char *evtname, json_object *eventJ); +extern void audiohlapi_raise_event(json_object * pEventDataJ); #endif // AHL_DISCONNECT_POLICY #endif // AHL_POLICY_INCLUDE
\ No newline at end of file |