summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ahl-binding/ahl-binding.c77
-rw-r--r--ahl-binding/ahl-config.c46
-rw-r--r--ahl-binding/ahl-deviceenum.c1
-rw-r--r--ahl-policy/ahl-policy.c34
-rwxr-xr-xahl-utilities/ahl-policy-utils.c5
-rw-r--r--conf.d/cmake/config.cmake4
-rw-r--r--htdocs/audiohl.html8
7 files changed, 89 insertions, 86 deletions
diff --git a/ahl-binding/ahl-binding.c b/ahl-binding/ahl-binding.c
index 83b4dc7..446d6e3 100644
--- a/ahl-binding/ahl-binding.c
+++ b/ahl-binding/ahl-binding.c
@@ -59,21 +59,6 @@ static StreamStateT StreamStateToEnum(char * in_pStreamStateStr)
return STREAM_STATE_MAXVALUE;
}
-static StreamMuteT StreamMuteToEnum(char * in_pStreamMuteStr)
-{
- if (in_pStreamMuteStr == NULL) {
- return STREAM_MUTE_MAXVALUE;
- }
- else if (strcasecmp(in_pStreamMuteStr,AHL_STREAM_UNMUTED)==0) {
- return STREAM_UNMUTED;
- }
- else if (strcasecmp(in_pStreamMuteStr,AHL_STREAM_MUTED)==0) {
- return STREAM_MUTED;
- }
- else
- return STREAM_MUTE_MAXVALUE;
-}
-
static streamID_t CreateNewStreamID()
{
streamID_t newID = g_AHLCtx.nextStreamID;
@@ -678,7 +663,7 @@ PUBLIC void audiohlapi_stream_close(struct afb_req req)
afb_req_success(req, NULL, "Stream close completed");
}
-static int SetStreamState(AHLClientCtxT * in_pClientCtx,struct afb_req * pReq, streamID_t streamID, char * pStreamStateStr, char * pMuteStr) {
+static int SetStreamState(AHLClientCtxT * in_pClientCtx,struct afb_req * pReq, streamID_t streamID, char * pStreamStateStr, int iMuteValue) {
StreamInfoT * pStreamInfo = GetStream(streamID);
if (pStreamInfo == NULL) {
@@ -720,31 +705,28 @@ static int SetStreamState(AHLClientCtxT * in_pClientCtx,struct afb_req * pReq, s
#endif
}
- if (pMuteStr != NULL) {
- StreamMuteT muteState = StreamMuteToEnum(pMuteStr);
#ifndef AHL_DISCONNECT_POLICY
- json_object *pPolicyStreamJ = NULL;
- int err = StreamInfoToJSON(pStreamInfo, &pPolicyStreamJ);
- if (err == AHL_POLICY_UTIL_FAIL)
- {
- afb_req_fail((*pReq), "Audio policy violation", "Unable to get JSON object for Policy_SetStreamMute");
- return AHL_FAIL;
- }
+ json_object *pPolicyStreamJ = NULL;
+ int err = StreamInfoToJSON(pStreamInfo, &pPolicyStreamJ);
+ if (err == AHL_POLICY_UTIL_FAIL)
+ {
+ afb_req_fail((*pReq), "Audio policy violation", "Unable to get JSON object for Policy_SetStreamMute");
+ return AHL_FAIL;
+ }
- json_object *paramJ= json_object_new_int(muteState);
- json_object_object_add(pPolicyStreamJ, "mute_state", paramJ);
+ json_object *paramJ= json_object_new_int(iMuteValue);
+ json_object_object_add(pPolicyStreamJ, "mute_state", paramJ);
- int policyAllowed = Policy_SetStreamMute(pPolicyStreamJ);
- if (policyAllowed == AHL_POLICY_REJECT)
- {
- afb_req_fail(*pReq, "Audio policy violation", "Mute stream not allowed in current context");
- return AHL_FAIL;
- }
+ int policyAllowed = Policy_SetStreamMute(pPolicyStreamJ);
+ if (policyAllowed == AHL_POLICY_REJECT)
+ {
+ afb_req_fail(*pReq, "Audio policy violation", "Mute stream not allowed in current context");
+ return AHL_FAIL;
+ }
#else
- // Simulate that policy returns target state (accepted)
- pStreamInfo->streamMute = muteState;
+ // Simulate that policy returns target state (accepted)
+ pStreamInfo->streamMute = (StreamMuteT)(*piMuteValue);
#endif
- }
return AHL_SUCCESS;
}
@@ -754,10 +736,10 @@ static int SetStreamState(AHLClientCtxT * in_pClientCtx,struct afb_req * pReq, s
json_object *queryJ = NULL;
streamID_t streamID = AHL_UNDEFINED;
char * streamStateStr = NULL;
- char * pMuteStr = NULL;
+ int iMuteValue = 0;
queryJ = afb_req_json(req);
- int err = wrap_json_unpack(queryJ, "{s?i,s?s,s?s}", "stream_id", &streamID,"state",&streamStateStr,"mute",&pMuteStr);
+ int err = wrap_json_unpack(queryJ, "{s?i,s?s,s?i}", "stream_id", &streamID,"state",&streamStateStr,"mute",&iMuteValue);
if (err) {
afb_req_fail_f(req, "Invalid arguments", "Args not a valid json object query=%s", json_object_get_string(queryJ));
return;
@@ -777,7 +759,7 @@ static int SetStreamState(AHLClientCtxT * in_pClientCtx,struct afb_req * pReq, s
for (int i = 0; i < pClientCtx->pStreamAccessList->len; i++)
{
streamID_t curStreamID = g_array_index(pClientCtx->pStreamAccessList,streamID_t,i);
- err = SetStreamState(pClientCtx,&req,curStreamID,streamStateStr,pMuteStr);
+ err = SetStreamState(pClientCtx,&req,curStreamID,streamStateStr,iMuteValue);
if (err) {
return;
}
@@ -785,7 +767,7 @@ static int SetStreamState(AHLClientCtxT * in_pClientCtx,struct afb_req * pReq, s
}
}
else {
- err = SetStreamState(pClientCtx,&req,streamID,streamStateStr,pMuteStr);
+ err = SetStreamState(pClientCtx,&req,streamID,streamStateStr,iMuteValue);
if (err) {
return;
}
@@ -936,7 +918,7 @@ PUBLIC void audiohlapi_property(struct afb_req req)
err = EndpointInfoToJSON(pEndpointInfo, &pPolicyEndpointJ);
if (err == AHL_POLICY_UTIL_FAIL)
{
- afb_req_fail(req, "Audio policy violation", "Unable to get JSON object for Policy_SetVolume");
+ afb_req_fail(req, "property fail", "Unable to get JSON object for Policy_SetProperty");
return;
}
@@ -949,14 +931,14 @@ PUBLIC void audiohlapi_property(struct afb_req req)
int policyAllowed = Policy_SetProperty(pPolicyEndpointJ,&pPropertyReply);
if (!policyAllowed)
{
- afb_req_fail(req, "Audio policy violation", "Set endpoint property not allowed in current context");
+ afb_req_fail(req, "Policy Reject Set Property Control", "Policy Reject Set Property Control");
return;
}
json_object * pPropReplyValue = NULL;
err = wrap_json_unpack(pPropertyReply,"{s:o}","value",&pPropReplyValue);
if (err) {
- afb_req_fail_f(req, "Invalid policy reply", "Policy property change reply not a valid json object=%s", json_object_get_string(pPropertyReply));
+ afb_req_fail_f(req, "property fail", "Policy Property value not a valid json object=%s", json_object_get_string(pPropertyReply));
return;
}
if (pEndpointInfo->pPropTable && pPropReplyValue) {
@@ -974,7 +956,7 @@ PUBLIC void audiohlapi_property(struct afb_req req)
// Retrieve cached property value
json_object * propertyValJ = (json_object *)g_hash_table_lookup(pEndpointInfo->pPropTable,propertyName);
if (propertyValJ == NULL) {
- afb_req_fail_f(req, "Property not found", "Property information not found: %s",propertyName);
+ afb_req_fail_f(req, "audiohlapi_property", "Property information not found: %s",propertyName);
return;
}
@@ -1094,7 +1076,12 @@ PUBLIC void audiohlapi_event_subscription(struct afb_req req)
return;
}
- int iNumEvents = json_object_array_length(eventArrayJ);
+ json_type jType = json_object_get_type(eventArrayJ);
+ int iNumEvents = 0;
+ if(jType == json_type_array)
+ {
+ iNumEvents = json_object_array_length(eventArrayJ);
+ }
for (int i = 0; i < iNumEvents; i++)
{
char * pEventName = NULL;
diff --git a/ahl-binding/ahl-config.c b/ahl-binding/ahl-config.c
index 61b6edd..3c92733 100644
--- a/ahl-binding/ahl-config.c
+++ b/ahl-binding/ahl-config.c
@@ -115,10 +115,28 @@ int ParseHLBConfig() {
AFB_INFO("High-level audio API version: %s", "1.0.0");
AFB_INFO("Config version: %s", versionStr);
AFB_INFO("Policy module: %s", policyModule);
+
+ int iHALListLength = 0;
+ int iNumberOfRoles = 0;
+
+ if(jHALList)
+ {
+ json_type jTypeHalList = json_object_get_type(jHALList);
+ if(jTypeHalList ==json_type_array)
+ {
+ iHALListLength = json_object_array_length(jHALList);
+ }
+ }
- int iHALListLength = json_object_array_length(jHALList);
- g_AHLCtx.policyCtx.pHALList = g_ptr_array_new_with_free_func(g_free);
- int iNumberOfRoles = json_object_array_length(jAudioRoles);
+ if(jAudioRoles)
+ {
+ json_type jTypeAudioRole = json_object_get_type(jAudioRoles);
+ if(jTypeAudioRole ==json_type_array)
+ {
+ iNumberOfRoles = json_object_array_length(jAudioRoles);
+ }
+ }
+ g_AHLCtx.policyCtx.pHALList = g_ptr_array_new_with_free_func(g_free);
g_AHLCtx.policyCtx.pRoleInfo = g_hash_table_new(g_str_hash, g_str_equal);
for (int i = 0; i < iHALListLength; i++)
@@ -165,15 +183,25 @@ int ParseHLBConfig() {
if (err) {
AFB_ERROR("Invalid audio role configuration : %s", json_object_to_json_string(jAudioRole));
return AHL_FAIL;
- }
-
+ }
if (jOutputDevices)
- iNumOutDevices = json_object_array_length(jOutputDevices);
+ {
+ json_type jTypeOutputDevices = json_object_get_type(jOutputDevices);
+ if(jTypeOutputDevices == json_type_array)
+ iNumOutDevices = json_object_array_length(jOutputDevices);
+ }
if (jInputDevices)
- iNumInDevices = json_object_array_length(jInputDevices);
+ {
+ json_type jTypeInputDevices = json_object_get_type(jInputDevices);
+ if(jTypeInputDevices == json_type_array)
+ iNumInDevices = json_object_array_length(jInputDevices);
+ }
if (jActions)
- iNumActions = json_object_array_length(jActions);
-
+ {
+ json_type jTypeActions = json_object_get_type(jActions);
+ if(jTypeActions == json_type_array)
+ iNumActions = json_object_array_length(jActions);
+ }
RoleInfoT * pRoleInfo = (RoleInfoT*) malloc(sizeof(RoleInfoT));
memset(pRoleInfo,0,sizeof(RoleInfoT));
pRoleInfo->pRoleName = g_strdup( pRoleName );
diff --git a/ahl-binding/ahl-deviceenum.c b/ahl-binding/ahl-deviceenum.c
index b5b2a46..43e5af5 100644
--- a/ahl-binding/ahl-deviceenum.c
+++ b/ahl-binding/ahl-deviceenum.c
@@ -230,7 +230,6 @@ void TermEndpointInfo( gpointer data )
g_hash_table_destroy(out_pEndpointInfo->pPropTable);
out_pEndpointInfo->pPropTable = NULL;
}
- g_slice_free (EndpointInfoT, out_pEndpointInfo);
}
}
diff --git a/ahl-policy/ahl-policy.c b/ahl-policy/ahl-policy.c
index 5e553b2..21ec669 100644
--- a/ahl-policy/ahl-policy.c
+++ b/ahl-policy/ahl-policy.c
@@ -354,8 +354,7 @@ static void TerminateStreamPolicyInfo(gpointer data)
{
free(pStreamPolicyInfo->pAudioRole);
pStreamPolicyInfo->pAudioRole = NULL;
- }
- g_slice_free(StreamPolicyInfoT, pStreamPolicyInfo);
+ }
}
}
@@ -402,7 +401,6 @@ StreamPolicyInfoT *InitStreamPolicyInfo()
{
g_ptr_array_unref(pEndPointPolicyInfo->streamInfo);
}
- g_slice_free(EndPointPolicyInfoT, pEndPointPolicyInfo);
}
}
@@ -443,8 +441,7 @@ static int PolicyAddEndPoint(StreamInterfaceInfoT *pStreamInfo)
static int PolicyAddStream(EndPointPolicyInfoT *pCurrEndPointPolicy, StreamInterfaceInfoT *pStreamInfo)
{
- StreamPolicyInfoT *pNewStreamPolicyInfo = InitStreamPolicyInfo();
-
+ StreamPolicyInfoT *pNewStreamPolicyInfo = InitStreamPolicyInfo();
if(pNewStreamPolicyInfo == NULL)
{
return POLICY_FAIL;
@@ -696,7 +693,6 @@ static void TerminateHalInfo(gpointer data)
free(pHalInfo->pDisplayName);
pHalInfo->pDisplayName = NULL;
}
- g_slice_free(HalInfoT, pHalInfo);
}
}
@@ -1217,18 +1213,16 @@ int Policy_Endpoint_Init(json_object *pInPolicyEndpointJ,json_object **pOutPolic
iAllocString = 1;
}
- // Populate special device property (TODO: Should be obtained from HAL)
- // if (strcasecmp(gsHALAPIName,"Device")==0)
- // {
- // Create json object for PropTable
- json_object *pPropTableJ = json_object_new_array();
- Add_Endpoint_Property_Int(pPropTableJ,AHL_PROPERTY_EQ_LOW,3);
- Add_Endpoint_Property_Int(pPropTableJ,AHL_PROPERTY_EQ_MID,0);
- Add_Endpoint_Property_Int(pPropTableJ,AHL_PROPERTY_EQ_HIGH,6);
- Add_Endpoint_Property_Int(pPropTableJ,AHL_PROPERTY_BALANCE,0);
- Add_Endpoint_Property_Int(pPropTableJ,AHL_PROPERTY_FADE,30);
- Add_Endpoint_Property_String(pPropTableJ,"preset_name","flat");
- // }
+ // Create json object for PropTable
+ json_object *pPropTableJ = json_object_new_array();
+ //TODO Get Property from HAL
+ //Below are example of property
+ /*Add_Endpoint_Property_Int(pPropTableJ,AHL_PROPERTY_EQ_LOW,3);
+ Add_Endpoint_Property_Int(pPropTableJ,AHL_PROPERTY_EQ_MID,0);
+ Add_Endpoint_Property_Int(pPropTableJ,AHL_PROPERTY_EQ_HIGH,6);
+ Add_Endpoint_Property_Int(pPropTableJ,AHL_PROPERTY_BALANCE,0);
+ Add_Endpoint_Property_Int(pPropTableJ,AHL_PROPERTY_FADE,30);
+ Add_Endpoint_Property_String(pPropTableJ,"preset_name","flat");*/
err = wrap_json_pack(pOutPolicyEndpointJ,"{s:i,s:s,s:s,s:o}",
"init_volume",StreamConfig.iVolumeInit,
@@ -1276,12 +1270,9 @@ int Policy_Init()
GetHALList();
// TODO: Register events from low level / HAL for dynamic changes
-
// Set System Normal for now, this should be set by an event
g_PolicyCtx.systemState = SYSTEM_NORMAL;
-
-
#ifdef AK_POLICY_DEMO
// Register audio backend events (TODO: should instead do this with signal composer with appropriate dependency)
// This is to simulate can bus, only used for demo
@@ -1297,7 +1288,6 @@ int Policy_Init()
}
#endif
-
return AHL_POLICY_ACCEPT;
}
diff --git a/ahl-utilities/ahl-policy-utils.c b/ahl-utilities/ahl-policy-utils.c
index 195c591..41e203e 100755
--- a/ahl-utilities/ahl-policy-utils.c
+++ b/ahl-utilities/ahl-policy-utils.c
@@ -164,11 +164,10 @@ int JSONToStream(json_object *pStreamJ, StreamInterfaceInfoT * pStream)
{
AFB_ERROR("Invalid arguments for InterfaceCtxJSONToStream");
return AHL_POLICY_UTIL_FAIL;
- }
+ }
//Unpack StreamInfo
- json_object *pEndpointJ = NULL;
- AFB_WARNING("json object query=%s", json_object_get_string(pStreamJ));
+ json_object *pEndpointJ = NULL;
int err = wrap_json_unpack(pStreamJ, "{s:i,s:i,s:i,s:s,s:i,s:i,s:o}",
"stream_id", &pStream->streamID,
"stream_state", &pStream->streamState,
diff --git a/conf.d/cmake/config.cmake b/conf.d/cmake/config.cmake
index 3b7d8ae..4192b98 100644
--- a/conf.d/cmake/config.cmake
+++ b/conf.d/cmake/config.cmake
@@ -89,8 +89,8 @@ set(COMPILE_OPTIONS
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.")
-set(PROFILING_COMPILE_OPTIONS -g -O0 -pg -Wp,-U_FORTIFY_SOURCE CACHE STRING "Compilation flags for PROFILING build type.")
-#set(DEBUG_COMPILE_OPTIONS -g -ggdb -Wp,-U_FORTIFY_SOURCE CACHE STRING "Compilation flags for DEBUG build type.")
+#set(PROFILING_COMPILE_OPTIONS -g -O0 -pg -Wp,-U_FORTIFY_SOURCE CACHE STRING "Compilation flags for PROFILING build type.")
+set(DEBUG_COMPILE_OPTIONS -g -ggdb -Wp,-U_FORTIFY_SOURCE CACHE STRING "Compilation flags for DEBUG build type.")
#set(CCOV_COMPILE_OPTIONS -g -O2 --coverage CACHE STRING "Compilation flags for CCOV build type.")
#set(RELEASE_COMPILE_OPTIONS -g -O2 CACHE STRING "Compilation flags for RELEASE build type.")
diff --git a/htdocs/audiohl.html b/htdocs/audiohl.html
index 0e153f5..6745ba1 100644
--- a/htdocs/audiohl.html
+++ b/htdocs/audiohl.html
@@ -8,7 +8,7 @@
<script type="text/javascript" src="AudioBinding.js"></script>
</head>
-<body onload="init('ahl-4a'); ep_type='sink' ; ar='Entertainment' ; ep_id=0 ; s_id=0 ; prop_val=0 ; vol_val='0' ; p_name='balance' ; st_state='idle' ; st_mute='off'">
+<body onload="init('ahl-4a'); ep_type='sink' ; ar='Entertainment' ; ep_id=0 ; s_id=0 ; prop_val=0 ; vol_val='0' ; p_name='balance' ; st_state='idle' ; st_mute=0">
<button id="connected" onclick="init('ahl-4a');">Binder WS Fail</button> <br><br>
<button id="monitoring" onclick="window.open('/monitoring/monitor.html','_monitor_audio')">Debug/Monitoring</a></button>
@@ -40,9 +40,9 @@
<option value='paused'>Paused</option>
</select><br>
<b>Stream Mute State</b>
- <select select_id='stream_mute' onclick='st_mute=this.value'>
- <option selected value='off'>Unmuted</option>
- <option value='on'>Muted</option>
+ <select select_id='stream_mute' onclick='st_mute=parseInt(this.value)'>
+ <option selected value='0'>Unmuted</option>
+ <option value='1'>Muted</option>
</select><br>
<b>Property</b>
<select select_id='property_name_list' onclick='p_name=this.value'>