summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ahl-policy/ahl-interface.h30
-rw-r--r--ahl-policy/ahl-policy.c629
2 files changed, 347 insertions, 312 deletions
diff --git a/ahl-policy/ahl-interface.h b/ahl-policy/ahl-interface.h
index fc0ac68..e9c0af5 100644
--- a/ahl-policy/ahl-interface.h
+++ b/ahl-policy/ahl-interface.h
@@ -25,7 +25,7 @@
// 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_RUNNING "running" // Stream is active and running
#define AHL_STREAM_STATE_PAUSED "paused" // Stream is active but paused
// Stream mute state
@@ -40,7 +40,7 @@
// 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_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
@@ -71,21 +71,25 @@
///// 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
+#define AHL_ROLE_Emergency "emergency" // critical alerts/alarms
+#define AHL_ROLE_Warning "warning" // Safety-relevant alerts/alarms
+#define AHL_ROLE_CustomHigh "customhigh" //
+#define AHL_ROLE_Phone "phone" // Voice communications (e.g. handsfree, speech recognition)
+#define AHL_ROLE_Navigation "navigation" // Important user information where user action is expected (e.g. navigation instruction)
+#define AHL_ROLE_CustomMedium "customMedium" //
+#define AHL_ROLE_Video "video" // Video content
+#define AHL_ROLE_Streaming "streaming" // Streaming content
+#define AHL_ROLE_Multimedia "multimedia" // Multimedia content
+#define AHL_ROLE_Radio "radio" // Radio content
+#define AHL_ROLE_CustomLow "customLow" //
+#define AHL_ROLE_Fallback "fallback" //
+
// 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_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)
diff --git a/ahl-policy/ahl-policy.c b/ahl-policy/ahl-policy.c
index 62e1e3c..90fe9f6 100644
--- a/ahl-policy/ahl-policy.c
+++ b/ahl-policy/ahl-policy.c
@@ -33,18 +33,18 @@
typedef struct StreamPolicyInfo {
streamID_t streamID;
int RolePriority;
- char * pAudioRole;
- InterruptBehaviorT interruptBehavior;
+ char * pAudioRole;
+ InterruptBehaviorT interruptBehavior;
int iDuckVolume; //duck Volume
} StreamPolicyInfoT;
-
+
typedef struct EndPointPolicyInfo {
endpointID_t endpointID;
- EndpointTypeT type;
+ EndpointTypeT type;
DeviceURITypeT deviceType;
char * pDeviceName;
- char * pHalApiName;
- int iVolume; //Current Volume
+ char * pHalApiName;
+ int iVolume; //Current Volume
GPtrArray * streamInfo; //List of playing or duck stream at a given endpoint
} EndPointPolicyInfoT;
@@ -87,53 +87,84 @@ static int getStreamConfig(char *pAudioRole, StreamConfigT *pStreamConfig)
return POLICY_FAIL;
}
- if ( strcasecmp(pAudioRole,AHL_ROLE_WARNING) == 0 )
+ if ( strcasecmp(pAudioRole,AHL_ROLE_Emergency) == 0 )
+ {
+ pStreamConfig->iNbMaxStream = 4;
+ pStreamConfig->iVolumeInit = 80;
+ pStreamConfig->iVolumeDuckValue = 0;
+ }
+ else if ( strcasecmp(pAudioRole,AHL_ROLE_Warning) == 0 )
+ {
+ pStreamConfig->iNbMaxStream = 4;
+ pStreamConfig->iVolumeInit = 80;
+ pStreamConfig->iVolumeDuckValue = 0;
+ }
+ else if ( strcasecmp(pAudioRole,AHL_ROLE_CustomHigh) == 0 )
{
pStreamConfig->iNbMaxStream = 4;
- pStreamConfig->iVolumeInit = 80;
+ pStreamConfig->iVolumeInit = 80;
pStreamConfig->iVolumeDuckValue = 0;
}
- else if ( strcasecmp(pAudioRole,AHL_ROLE_GUIDANCE) == 0 )
+ else if ( strcasecmp(pAudioRole,AHL_ROLE_Phone) == 0 )
+ {
+ pStreamConfig->iNbMaxStream = 4;
+ pStreamConfig->iVolumeInit = 80;
+ pStreamConfig->iVolumeDuckValue = 0;
+ }
+ else if ( strcasecmp(pAudioRole,AHL_ROLE_Navigation) == 0 )
{
pStreamConfig->iNbMaxStream = 10;
- pStreamConfig->iVolumeInit = 70;
+ pStreamConfig->iVolumeInit = 70;
pStreamConfig->iVolumeDuckValue = 30;
}
- else if ( strcasecmp(pAudioRole,AHL_ROLE_NOTIFICATION) == 0 )
+ else if ( strcasecmp(pAudioRole,AHL_ROLE_CustomMedium) == 0 )
{
pStreamConfig->iNbMaxStream = 4;
- pStreamConfig->iVolumeInit = 80;
- pStreamConfig->iVolumeDuckValue = 10;
+ pStreamConfig->iVolumeInit = 80;
+ pStreamConfig->iVolumeDuckValue = 0;
}
- else if ( strcasecmp(pAudioRole,AHL_ROLE_COMMUNICATION) == 0 )
+ else if ( strcasecmp(pAudioRole,AHL_ROLE_Video) == 0 )
{
- pStreamConfig->iNbMaxStream = 10;
- pStreamConfig->iVolumeInit = 70;
- pStreamConfig->iVolumeDuckValue = 10;
+ pStreamConfig->iNbMaxStream = 4;
+ pStreamConfig->iVolumeInit = 80;
+ pStreamConfig->iVolumeDuckValue = 0;
+ }
+ else if ( strcasecmp(pAudioRole,AHL_ROLE_Streaming) == 0 )
+ {
+ pStreamConfig->iNbMaxStream = 4;
+ pStreamConfig->iVolumeInit = 80;
+ pStreamConfig->iVolumeDuckValue = 0;
}
- else if ( strcasecmp(pAudioRole,AHL_ROLE_ENTERTAINMENT) == 0 )
+ else if ( strcasecmp(pAudioRole,AHL_ROLE_Multimedia) == 0 )
{
- pStreamConfig->iNbMaxStream = MAX_ACTIVE_STREAM_POLICY;
- pStreamConfig->iVolumeInit = 60;
- pStreamConfig->iVolumeDuckValue = 40;
+ pStreamConfig->iNbMaxStream = 4;
+ pStreamConfig->iVolumeInit = 80;
+ pStreamConfig->iVolumeDuckValue = 0;
+ }
+ else if ( strcasecmp(pAudioRole,AHL_ROLE_Radio) == 0 )
+ {
+ pStreamConfig->iNbMaxStream = 4;
+ pStreamConfig->iVolumeInit = 80;
+ pStreamConfig->iVolumeDuckValue = 0;
}
- else if ( strcasecmp(pAudioRole,AHL_ROLE_SYSTEM) == 0 )
+ else if ( strcasecmp(pAudioRole,AHL_ROLE_CustomLow) == 0 )
{
- pStreamConfig->iNbMaxStream = 2;
- pStreamConfig->iVolumeInit = 100;
- pStreamConfig->iVolumeDuckValue = 0;
+ pStreamConfig->iNbMaxStream = 4;
+ pStreamConfig->iVolumeInit = 80;
+ pStreamConfig->iVolumeDuckValue = 0;
}
- else if ( strcasecmp(pAudioRole,AHL_ROLE_STARTUP) == 0 )
+ else if ( strcasecmp(pAudioRole,AHL_ROLE_Fallback) == 0 )
{
- pStreamConfig->iNbMaxStream = 1;
- pStreamConfig->iVolumeInit = 90;
- pStreamConfig->iVolumeDuckValue = 0;
+ pStreamConfig->iNbMaxStream = 4;
+ pStreamConfig->iVolumeInit = 80;
+ pStreamConfig->iVolumeDuckValue = 0;
}
- else if ( strcasecmp(pAudioRole,AHL_ROLE_SHUTDOWN) == 0 )
+ else
{
- pStreamConfig->iNbMaxStream = 1;
- pStreamConfig->iVolumeInit = 90;
- pStreamConfig->iVolumeDuckValue = 0;
+ pStreamConfig->iNbMaxStream = 4;
+ pStreamConfig->iVolumeInit = 80;
+ pStreamConfig->iVolumeDuckValue = 0;
+ AFB_WARNING("Unkwon AudioRole %s", pAudioRole);
}
return POLICY_SUCCESS;
}
@@ -142,36 +173,36 @@ static int PolicySetVolume(int iEndpointID, int iEndpointType, char *pHalApiName
{
if(pHalApiName == NULL || (strcasecmp(pHalApiName, AHL_POLICY_UNDEFINED_HALNAME) == 0))
{
- AFB_WARNING("SetVolume cannot be accomplished without proper HAL association");
+ AFB_WARNING("SetVolume cannot be accomplished without proper HAL association");
return POLICY_FAIL;
}
if(AudioRole == NULL)
{
- AFB_ERROR("Invalid AudioRole : %s",AudioRole);
+ AFB_ERROR("Invalid AudioRole : %s",AudioRole);
return POLICY_FAIL;
}
// Using audio role available from endpoint to target the right HAL control (build string based on convention)
- GString * gsHALControlName = NULL;
+ GString * gsHALControlName = NULL;
switch(deviceType)
{
case DEVICEURITYPE_ALSA_HW:
- gsHALControlName = g_string_new("Master_Playback_Volume");
- break;
+ gsHALControlName = g_string_new("Master_Playback_Volume");
+ break;
case DEVICEURITYPE_ALSA_DMIX:
case DEVICEURITYPE_ALSA_DSNOOP:
case DEVICEURITYPE_ALSA_PLUG:
- case DEVICEURITYPE_ALSA_SOFTVOL:
+ case DEVICEURITYPE_ALSA_SOFTVOL:
gsHALControlName = g_string_new(AudioRole);
if(bRamp)
{
- g_string_append(gsHALControlName,VOLUME_RAMP_SUFFIX);
+ g_string_append(gsHALControlName,VOLUME_RAMP_SUFFIX);
}
else
{
- g_string_append(gsHALControlName,VOLUME_SUFFIX); // no ramping
- }
+ g_string_append(gsHALControlName,VOLUME_SUFFIX); // no ramping
+ }
break;
default:
// Not supported yet
@@ -182,12 +213,12 @@ static int PolicySetVolume(int iEndpointID, int iEndpointType, char *pHalApiName
// Set endpoint volume using HAL services (leveraging ramps etc.)
json_object *j_response = NULL, *j_query = NULL;
-
+
// Package query
int err = wrap_json_pack(&j_query,"{s:s,s:i}","label",gsHALControlName->str, "val",iVolume);
- if (err)
+ if (err)
{
- AFB_ERROR("Invalid query for HAL ctlset: %s with errorcode: %i",json_object_to_json_string(j_query), err);
+ AFB_ERROR("Invalid query for HAL ctlset: %s with errorcode: %i",json_object_to_json_string(j_query), err);
return POLICY_FAIL;
}
@@ -195,9 +226,9 @@ static int PolicySetVolume(int iEndpointID, int iEndpointType, char *pHalApiName
// Set the volume using the HAL
err = afb_service_call_sync(pHalApiName, "ctlset", j_query, &j_response);
- if (err)
+ if (err)
{
- AFB_ERROR("Could not ctlset on HAL: %s with errorcode: %i",pHalApiName, err);
+ AFB_ERROR("Could not ctlset on HAL: %s with errorcode: %i",pHalApiName, err);
return POLICY_FAIL;
}
AFB_DEBUG("HAL ctlset response=%s", json_object_to_json_string(j_response));
@@ -206,9 +237,9 @@ static int PolicySetVolume(int iEndpointID, int iEndpointType, char *pHalApiName
// Package event data
json_object * eventDataJ = NULL;
err = wrap_json_pack(&eventDataJ,"{s:s,s:i,s:i,s:i,s:s}","event_name", AHL_ENDPOINT_VOLUME_EVENT,"endpoint_id", iEndpointID, "endpoint_type", iEndpointType,"value",iVolume, "audio_role", AudioRole);
- if (err)
+ if (err)
{
- AFB_ERROR("Invalid event data for volume event %s with errorcode: %i",json_object_to_json_string(eventDataJ), err);
+ AFB_ERROR("Invalid event data for volume event %s with errorcode: %i",json_object_to_json_string(eventDataJ), err);
return POLICY_FAIL;
}
@@ -216,25 +247,25 @@ static int PolicySetVolume(int iEndpointID, int iEndpointType, char *pHalApiName
}
- return POLICY_SUCCESS;
+ return POLICY_SUCCESS;
}
static int PolicyGetVolume(int iEndpointID, int iEndpointType, char *pHalApiName, char *AudioRole, DeviceURITypeT deviceType, int *pVolume)
{
GString * gsHALControlName = NULL;
- // Using audio role available from endpoint to target the right HAL control (build string based on convention)
+ // Using audio role available from endpoint to target the right HAL control (build string based on convention)
switch(deviceType)
{
case DEVICEURITYPE_ALSA_HW:
- gsHALControlName = g_string_new("Master_Playback_Volume");
- break;
+ gsHALControlName = g_string_new("Master_Playback_Volume");
+ break;
case DEVICEURITYPE_ALSA_DMIX:
case DEVICEURITYPE_ALSA_DSNOOP:
case DEVICEURITYPE_ALSA_PLUG:
- case DEVICEURITYPE_ALSA_SOFTVOL:
+ case DEVICEURITYPE_ALSA_SOFTVOL:
gsHALControlName = g_string_new(AudioRole);
- g_string_append(gsHALControlName,VOLUME_SUFFIX); // Return target value
+ g_string_append(gsHALControlName,VOLUME_SUFFIX); // Return target value
break;
default:
// Set volume to zero for display purpose only.
@@ -246,81 +277,81 @@ static int PolicyGetVolume(int iEndpointID, int iEndpointType, char *pHalApiName
// Set endpoint volume using HAL services (leveraging ramps etc.)
json_object *j_response = NULL, *j_query = NULL;
-
+
// Package query
int err = wrap_json_pack(&j_query,"{s:s}","label",gsHALControlName->str);
- if (err)
+ if (err)
{
- AFB_WARNING("Invalid query for HAL ctlset: %s, errorcode: %i",json_object_to_json_string(j_query),err);
+ AFB_WARNING("Invalid query for HAL ctlset: %s, errorcode: %i",json_object_to_json_string(j_query),err);
return POLICY_FAIL;
}
// Get the volume using the HAL
err = afb_service_call_sync(pHalApiName, "ctlget", j_query, &j_response);
- if (err)
+ if (err)
{
- AFB_WARNING("Could not ctlset on HAL: %s, errorcode: %i",pHalApiName, err);
+ AFB_WARNING("Could not ctlset on HAL: %s, errorcode: %i",pHalApiName, err);
return POLICY_FAIL;
}
AFB_DEBUG("HAL ctlget response=%s", json_object_to_json_string(j_response));
-
+
// Parse response
json_object * jRespObj = NULL;
json_object_object_get_ex(j_response, "response", &jRespObj);
json_object * jVal = NULL;
- int val1 = 0, val2 = 0; // Why 2 values?
+ int val1 = 0, val2 = 0; // Why 2 values?
json_object_object_get_ex(jRespObj, "val", &jVal);
int nbElement = json_object_array_length(jVal);
if(nbElement == 2)
- {
+ {
err = wrap_json_unpack(jVal, "[ii]", &val1, &val2);
if (err) {
AFB_ERROR("Volume retrieve failed Could not retrieve volume value -> %s", json_object_get_string(jVal));
return POLICY_FAIL;
- }
+ }
}
else
- {
+ {
err = wrap_json_unpack(jVal, "[i]", &val1);
if (err) {
AFB_ERROR("Volume retrieve failed Could not retrieve volume value -> %s", json_object_get_string(jVal));
return POLICY_FAIL;
}
}
-
+
*pVolume = val1;
// Package event data
json_object * eventDataJ = NULL;
err = wrap_json_pack(&eventDataJ,"{s:s,s:i,s:i,s:i,s:s}","event_name", AHL_ENDPOINT_VOLUME_EVENT,"endpoint_id", iEndpointID, "endpoint_type", iEndpointType,"value",*pVolume, "audio_role", AudioRole);
- if (err)
+ if (err)
{
- AFB_ERROR("Invalid event data for volume event %s with errorcode: %i",json_object_to_json_string(eventDataJ), err);
+ AFB_ERROR("Invalid event data for volume event %s with errorcode: %i",json_object_to_json_string(eventDataJ), err);
return POLICY_FAIL;
}
audiohlapi_raise_event(eventDataJ);
- return POLICY_SUCCESS;
+ return POLICY_SUCCESS;
}
static void PolicyPostStateEvent(int iStreamID, StreamEventT eventState)
{
json_object * eventDataJ = NULL;
int err = wrap_json_pack(&eventDataJ,"{s:s,s:i,s:i}","event_name", AHL_STREAM_STATE_EVENT,"stream_id",iStreamID, "state_event",eventState);
- if (err)
+ if (err)
{
AFB_ERROR("Invalid event data for stream state event: %s",json_object_to_json_string(eventDataJ));
}
- else
+ else
{
audiohlapi_raise_event(eventDataJ);
- }
+ }
}
static EndPointPolicyInfoT *PolicySearchEndPoint(EndpointTypeT type, char *pDeviceName)
-{
+{
GPtrArray *pcurEndpointArray = NULL;
if(type==ENDPOINTTYPE_SINK)
@@ -334,7 +365,7 @@ static EndPointPolicyInfoT *PolicySearchEndPoint(EndpointTypeT type, char *pDevi
for(int i=0; i<pcurEndpointArray->len; i++)
{
- EndPointPolicyInfoT * pCurEndpoint = g_ptr_array_index(pcurEndpointArray,i);
+ EndPointPolicyInfoT * pCurEndpoint = g_ptr_array_index(pcurEndpointArray,i);
if(strcasecmp(pCurEndpoint->pDeviceName,pDeviceName)==0)
{
@@ -349,22 +380,22 @@ static void TerminateStreamPolicyInfo(gpointer data)
{
StreamPolicyInfoT *pStreamPolicyInfo = (StreamPolicyInfoT *)data;
if(pStreamPolicyInfo)
- {
+ {
if( pStreamPolicyInfo->pAudioRole)
{
free(pStreamPolicyInfo->pAudioRole);
pStreamPolicyInfo->pAudioRole = NULL;
- }
+ }
}
}
StreamPolicyInfoT *InitStreamPolicyInfo()
{
- StreamPolicyInfoT *pStreamPolicyInfo = malloc(sizeof(StreamPolicyInfoT));
+ StreamPolicyInfoT *pStreamPolicyInfo = malloc(sizeof(StreamPolicyInfoT));
if(pStreamPolicyInfo)
- {
- memset(pStreamPolicyInfo,0,sizeof(StreamPolicyInfoT));
- pStreamPolicyInfo->pAudioRole = malloc(AHL_POLICY_STR_MAX_LENGTH*sizeof(char));
+ {
+ memset(pStreamPolicyInfo,0,sizeof(StreamPolicyInfoT));
+ pStreamPolicyInfo->pAudioRole = malloc(AHL_POLICY_STR_MAX_LENGTH*sizeof(char));
}
return pStreamPolicyInfo;
}
@@ -372,10 +403,10 @@ StreamPolicyInfoT *InitStreamPolicyInfo()
EndPointPolicyInfoT *InitEndPointPolicyInfo()
{
- EndPointPolicyInfoT *pEndPointPolicyInfo = malloc(sizeof(EndPointPolicyInfoT));
+ EndPointPolicyInfoT *pEndPointPolicyInfo = malloc(sizeof(EndPointPolicyInfoT));
if(pEndPointPolicyInfo)
- {
- memset(pEndPointPolicyInfo,0,sizeof(EndPointPolicyInfoT));
+ {
+ memset(pEndPointPolicyInfo,0,sizeof(EndPointPolicyInfoT));
pEndPointPolicyInfo->streamInfo = g_ptr_array_new_with_free_func (TerminateStreamPolicyInfo);
pEndPointPolicyInfo->pDeviceName = malloc(AHL_POLICY_STR_MAX_LENGTH*sizeof(char));
pEndPointPolicyInfo->pHalApiName = malloc(AHL_POLICY_STR_MAX_LENGTH*sizeof(char));
@@ -388,7 +419,7 @@ StreamPolicyInfoT *InitStreamPolicyInfo()
{
EndPointPolicyInfoT *pEndPointPolicyInfo = (EndPointPolicyInfoT*)data;
if(pEndPointPolicyInfo)
- {
+ {
if( pEndPointPolicyInfo->pDeviceName)
{
free(pEndPointPolicyInfo->pDeviceName);
@@ -398,8 +429,8 @@ StreamPolicyInfoT *InitStreamPolicyInfo()
free(pEndPointPolicyInfo->pHalApiName);
}
if(pEndPointPolicyInfo->streamInfo)
- {
- g_ptr_array_unref(pEndPointPolicyInfo->streamInfo);
+ {
+ g_ptr_array_unref(pEndPointPolicyInfo->streamInfo);
}
}
}
@@ -411,14 +442,14 @@ static int PolicyAddEndPoint(StreamInterfaceInfoT *pStreamInfo)
if(pPolicyEndPoint == NULL)
{
//create EndPoint and add playing stream
- EndPointPolicyInfoT *pNewEndPointPolicyInfo=InitEndPointPolicyInfo();
+ EndPointPolicyInfoT *pNewEndPointPolicyInfo=InitEndPointPolicyInfo();
if(pNewEndPointPolicyInfo)
{
pNewEndPointPolicyInfo->endpointID = pStreamInfo->endpoint.endpointID;
pNewEndPointPolicyInfo->type = pStreamInfo->endpoint.type;
pNewEndPointPolicyInfo->deviceType = pStreamInfo->endpoint.deviceURIType;
- g_strlcpy(pNewEndPointPolicyInfo->pDeviceName,pStreamInfo->endpoint.gsDeviceName,AHL_POLICY_STR_MAX_LENGTH);
- g_strlcpy(pNewEndPointPolicyInfo->pHalApiName,pStreamInfo->endpoint.gsHALAPIName,AHL_POLICY_STR_MAX_LENGTH);
+ g_strlcpy(pNewEndPointPolicyInfo->pDeviceName,pStreamInfo->endpoint.gsDeviceName,AHL_POLICY_STR_MAX_LENGTH);
+ g_strlcpy(pNewEndPointPolicyInfo->pHalApiName,pStreamInfo->endpoint.gsHALAPIName,AHL_POLICY_STR_MAX_LENGTH);
pNewEndPointPolicyInfo->iVolume = pStreamInfo->endpoint.iVolume;
if(pStreamInfo->endpoint.type == ENDPOINTTYPE_SINK)
{
@@ -427,32 +458,32 @@ static int PolicyAddEndPoint(StreamInterfaceInfoT *pStreamInfo)
else
{
g_ptr_array_add(g_PolicyCtx.pSourceEndpoints, pNewEndPointPolicyInfo);
- }
+ }
}
else
{
AFB_ERROR("Unable to allocate memory for a new EndPointPolicyInfo");
- return POLICY_FAIL;
+ return POLICY_FAIL;
}
-
+
}
- return POLICY_SUCCESS;
+ return POLICY_SUCCESS;
}
static int PolicyAddStream(EndPointPolicyInfoT *pCurrEndPointPolicy, StreamInterfaceInfoT *pStreamInfo)
{
- StreamPolicyInfoT *pNewStreamPolicyInfo = InitStreamPolicyInfo();
+ StreamPolicyInfoT *pNewStreamPolicyInfo = InitStreamPolicyInfo();
if(pNewStreamPolicyInfo == NULL)
{
return POLICY_FAIL;
}
- pNewStreamPolicyInfo->streamID = pStreamInfo->streamID;
- pNewStreamPolicyInfo->RolePriority = pStreamInfo->iPriority;
- g_strlcpy(pNewStreamPolicyInfo->pAudioRole,pStreamInfo->pRoleName,AHL_POLICY_STR_MAX_LENGTH);
- pNewStreamPolicyInfo->interruptBehavior = pStreamInfo->eInterruptBehavior;
- pNewStreamPolicyInfo->iDuckVolume = 0;
- g_ptr_array_add(pCurrEndPointPolicy->streamInfo, pNewStreamPolicyInfo);
- return POLICY_SUCCESS;
+ pNewStreamPolicyInfo->streamID = pStreamInfo->streamID;
+ pNewStreamPolicyInfo->RolePriority = pStreamInfo->iPriority;
+ g_strlcpy(pNewStreamPolicyInfo->pAudioRole,pStreamInfo->pRoleName,AHL_POLICY_STR_MAX_LENGTH);
+ pNewStreamPolicyInfo->interruptBehavior = pStreamInfo->eInterruptBehavior;
+ pNewStreamPolicyInfo->iDuckVolume = 0;
+ g_ptr_array_add(pCurrEndPointPolicy->streamInfo, pNewStreamPolicyInfo);
+ return POLICY_SUCCESS;
}
static int PolicyRunningIdleTransition(EndPointPolicyInfoT *pCurrEndPointPolicy,StreamInterfaceInfoT * pStreamInfo)
@@ -461,7 +492,7 @@ static int PolicyRunningIdleTransition(EndPointPolicyInfoT *pCurrEndPointPolicy,
if(pCurrEndPointPolicy == NULL || pCurrEndPointPolicy->streamInfo == NULL)
{
AFB_ERROR("StreamID not found in active endpoint when running to idle transition is requested");
- return POLICY_FAIL;
+ return POLICY_FAIL;
}
// Search for the matching stream
int iNbStream=pCurrEndPointPolicy->streamInfo->len;
@@ -469,9 +500,9 @@ static int PolicyRunningIdleTransition(EndPointPolicyInfoT *pCurrEndPointPolicy,
{
StreamPolicyInfoT *pCurrentPolicyStreamInfo = g_ptr_array_index(pCurrEndPointPolicy->streamInfo,i);
if(pCurrentPolicyStreamInfo->streamID == pStreamInfo->streamID)
- {
+ {
//remove the current stream
- g_ptr_array_remove_index(pCurrEndPointPolicy->streamInfo, i);
+ g_ptr_array_remove_index(pCurrEndPointPolicy->streamInfo, i);
if((pCurrEndPointPolicy->streamInfo->len > 0) && (i==iNbStream-1)) //need to unduck
{
//check the next highest priority stream (last stream is alway higher priority)
@@ -482,70 +513,70 @@ static int PolicyRunningIdleTransition(EndPointPolicyInfoT *pCurrEndPointPolicy,
}
switch(pCurrentPolicyStreamInfo->interruptBehavior)
{
- case INTERRUPTBEHAVIOR_CONTINUE:
+ case INTERRUPTBEHAVIOR_CONTINUE:
//unduck and set Volume back to original value
- err = PolicySetVolume(pCurrEndPointPolicy->endpointID,
+ err = PolicySetVolume(pCurrEndPointPolicy->endpointID,
pCurrEndPointPolicy->type,
- pCurrEndPointPolicy->pHalApiName,
- pHighPriorityStreamInfo->pAudioRole,
- pCurrEndPointPolicy->deviceType,
+ pCurrEndPointPolicy->pHalApiName,
+ pHighPriorityStreamInfo->pAudioRole,
+ pCurrEndPointPolicy->deviceType,
pHighPriorityStreamInfo->iDuckVolume,
true, // ramp volume
true);// raise event
- if(err)
- {
- return POLICY_FAIL;
+ if(err)
+ {
+ return POLICY_FAIL;
}
-
- return POLICY_SUCCESS;
+
+ return POLICY_SUCCESS;
case INTERRUPTBEHAVIOR_PAUSE:
- PolicyPostStateEvent(pHighPriorityStreamInfo->streamID,STREAM_EVENT_RESUME);
+ PolicyPostStateEvent(pHighPriorityStreamInfo->streamID,STREAM_EVENT_RESUME);
// unmute stream (safety net for legacy streams)
- err = PolicySetVolume(pCurrEndPointPolicy->endpointID,
+ err = PolicySetVolume(pCurrEndPointPolicy->endpointID,
pCurrEndPointPolicy->type,
- pCurrEndPointPolicy->pHalApiName,
- pHighPriorityStreamInfo->pAudioRole,
- pCurrEndPointPolicy->deviceType,
+ pCurrEndPointPolicy->pHalApiName,
+ pHighPriorityStreamInfo->pAudioRole,
+ pCurrEndPointPolicy->deviceType,
pCurrEndPointPolicy->iVolume, // restore volume
false, // ramp volume
- false);// raise event
- if(err)
- {
- return POLICY_FAIL;
- }
- return POLICY_SUCCESS;
+ false);// raise event
+ if(err)
+ {
+ return POLICY_FAIL;
+ }
+ return POLICY_SUCCESS;
case INTERRUPTBEHAVIOR_CANCEL:
- PolicyPostStateEvent(pHighPriorityStreamInfo->streamID,STREAM_EVENT_START);
- return POLICY_SUCCESS;
+ PolicyPostStateEvent(pHighPriorityStreamInfo->streamID,STREAM_EVENT_START);
+ return POLICY_SUCCESS;
default:
AFB_ERROR("Unsupported Intterupt Behavior");
- return POLICY_FAIL;
- }
- }
- return POLICY_SUCCESS;
+ return POLICY_FAIL;
+ }
+ }
+ return POLICY_SUCCESS;
}
- }
- AFB_ERROR("StreamID not found in active endpoint when running to idle transition is requested");
+ }
+ AFB_ERROR("StreamID not found in active endpoint when running to idle transition is requested");
return POLICY_FAIL;
}
static int PolicyIdleRunningTransition(EndPointPolicyInfoT *pCurrEndPointPolicy, StreamInterfaceInfoT * pStreamInfo)
{
- int err=0;
+ int err=0;
if(pCurrEndPointPolicy->streamInfo == NULL)
{
AFB_ERROR("pCurrEndPointPolicy->streamInfo is null on an active endpoint");
- return POLICY_FAIL;
+ return POLICY_FAIL;
}
if(pCurrEndPointPolicy->streamInfo->len == 0) //No stream is playing on this endpoint
- {
+ {
PolicyAddStream(pCurrEndPointPolicy, pStreamInfo);
}
else //Interrupt case
{
- //check the last element
+ //check the last element
StreamPolicyInfoT *pCurrentActiveStreamInfo = g_ptr_array_index(pCurrEndPointPolicy->streamInfo,pCurrEndPointPolicy->streamInfo->len-1);
g_assert_nonnull(pCurrentActiveStreamInfo);
if(pStreamInfo->iPriority >= pCurrentActiveStreamInfo->RolePriority)
@@ -559,48 +590,48 @@ static int PolicyIdleRunningTransition(EndPointPolicyInfoT *pCurrEndPointPolicy,
err = getStreamConfig(pStreamInfo->pRoleName, &StreamConfig);
if(err == POLICY_FAIL)
{
- AFB_ERROR("Error getting stream configuration for audiorole: %s", pStreamInfo->pRoleName);
- return POLICY_FAIL;
+ AFB_ERROR("Error getting stream configuration for audiorole: %s", pStreamInfo->pRoleName);
+ return POLICY_FAIL;
}
- err = PolicySetVolume(pCurrEndPointPolicy->endpointID,
+ err = PolicySetVolume(pCurrEndPointPolicy->endpointID,
pCurrEndPointPolicy->type,
- pCurrEndPointPolicy->pHalApiName,
- pCurrentActiveStreamInfo->pAudioRole,
- pCurrEndPointPolicy->deviceType,
+ pCurrEndPointPolicy->pHalApiName,
+ pCurrentActiveStreamInfo->pAudioRole,
+ pCurrEndPointPolicy->deviceType,
StreamConfig.iVolumeDuckValue,
true, // volume ramp
true); // raise event
- if(err)
+ if(err)
{
- AFB_ERROR("Set volume return with errorcode %i for streamID: %i and Hal:%s", err, pCurrentActiveStreamInfo->streamID, pCurrEndPointPolicy->pHalApiName);
- return POLICY_FAIL;
- }
+ AFB_ERROR("Set volume return with errorcode %i for streamID: %i and Hal:%s", err, pCurrentActiveStreamInfo->streamID, pCurrEndPointPolicy->pHalApiName);
+ return POLICY_FAIL;
+ }
break;
case INTERRUPTBEHAVIOR_PAUSE:
- PolicyPostStateEvent(pCurrentActiveStreamInfo->streamID,STREAM_EVENT_PAUSE);
- // mute stream as a safety net for legacy streams
- err = PolicySetVolume(pCurrEndPointPolicy->endpointID,
+ PolicyPostStateEvent(pCurrentActiveStreamInfo->streamID,STREAM_EVENT_PAUSE);
+ // mute stream as a safety net for legacy streams
+ err = PolicySetVolume(pCurrEndPointPolicy->endpointID,
pCurrEndPointPolicy->type,
- pCurrEndPointPolicy->pHalApiName,
- pCurrentActiveStreamInfo->pAudioRole,
- pCurrEndPointPolicy->deviceType,
+ pCurrEndPointPolicy->pHalApiName,
+ pCurrentActiveStreamInfo->pAudioRole,
+ pCurrEndPointPolicy->deviceType,
0, // mute volume
false, // volume ramp
false); // raise event
- if(err)
+ if(err)
{
- AFB_ERROR("Set volume return with errorcode %i for streamID: %i and Hal:%s", err, pCurrentActiveStreamInfo->streamID, pCurrEndPointPolicy->pHalApiName);
- return POLICY_FAIL;
- }
+ AFB_ERROR("Set volume return with errorcode %i for streamID: %i and Hal:%s", err, pCurrentActiveStreamInfo->streamID, pCurrEndPointPolicy->pHalApiName);
+ return POLICY_FAIL;
+ }
break;
case INTERRUPTBEHAVIOR_CANCEL:
- PolicyPostStateEvent(pCurrentActiveStreamInfo->streamID,STREAM_EVENT_STOP);
+ PolicyPostStateEvent(pCurrentActiveStreamInfo->streamID,STREAM_EVENT_STOP);
g_ptr_array_remove_index(pCurrEndPointPolicy->streamInfo, pCurrEndPointPolicy->streamInfo->len-1);
break;
default:
AFB_ERROR("Unsupported Intterupt Behavior");
- return AHL_POLICY_REJECT;
- }
+ return AHL_POLICY_REJECT;
+ }
//Add the playing stream at last
PolicyAddStream(pCurrEndPointPolicy, pStreamInfo);
@@ -609,8 +640,8 @@ static int PolicyIdleRunningTransition(EndPointPolicyInfoT *pCurrEndPointPolicy,
{
//Higher Priority Stream is playing
AFB_ERROR("Higher Priority Stream is playing");
- return POLICY_FAIL;
- }
+ return POLICY_FAIL;
+ }
}
return POLICY_SUCCESS;
@@ -620,32 +651,32 @@ static void PolicySpeedModify(int speed)
{
for(int i=0; i<g_PolicyCtx.pSinkEndpoints->len; i++)
{
- EndPointPolicyInfoT * pCurEndpoint = g_ptr_array_index(g_PolicyCtx.pSinkEndpoints,i);
+ EndPointPolicyInfoT * pCurEndpoint = g_ptr_array_index(g_PolicyCtx.pSinkEndpoints,i);
if(pCurEndpoint == NULL)
{
AFB_WARNING("Sink Endpoint not found");
return;
}
- //check if active
+ //check if active
if(pCurEndpoint->streamInfo->len > 0 )
{
- StreamPolicyInfoT * pCurStream = g_ptr_array_index(pCurEndpoint->streamInfo,pCurEndpoint->streamInfo->len-1);
- if(strcasecmp(pCurStream->pAudioRole,AHL_ROLE_ENTERTAINMENT)==0)
+ StreamPolicyInfoT * pCurStream = g_ptr_array_index(pCurEndpoint->streamInfo,pCurEndpoint->streamInfo->len-1);
+ if(strcasecmp(pCurStream->pAudioRole,AHL_ROLE_Multimedia)==0)
{
if(speed > 30 && speed < 100)
{
int volume =speed;
PolicySetVolume(pCurEndpoint->endpointID,
- pCurEndpoint->type,
+ pCurEndpoint->type,
pCurEndpoint->pHalApiName,
pCurStream->pAudioRole,
- pCurEndpoint->deviceType,
+ pCurEndpoint->deviceType,
volume,
true, // volume ramp
true); // raise event
- }
- }
+ }
+ }
}
}
}
@@ -666,10 +697,10 @@ static int RetrieveAssociatedHALAPIName(int iAlsaCardNumber,char ** out_pDisplay
*out_pDisplayName = pHalInfo->pDisplayName;
*out_pHALName = pHalInfo->pAPIName;
return POLICY_SUCCESS;
- }
+ }
}
}
-
+
return POLICY_FAIL;
}
@@ -708,7 +739,7 @@ HalInfoT *InitHalInfo()
pHalInfo->pDevID = malloc(AHL_POLICY_STR_MAX_LENGTH*sizeof(char));
pHalInfo->pAPIName = malloc(AHL_POLICY_STR_MAX_LENGTH*sizeof(char));
- pHalInfo->pDisplayName = malloc(AHL_POLICY_STR_MAX_LENGTH*sizeof(char));
+ pHalInfo->pDisplayName = malloc(AHL_POLICY_STR_MAX_LENGTH*sizeof(char));
return pHalInfo;
}
@@ -733,7 +764,7 @@ static int GetHALList(void)
char * pDevIDStr = NULL;
char * pAPIName = NULL;
char * pShortName = NULL;
-
+
int err = wrap_json_unpack(jHAL, "{s:s,s:s,s:s}", "devid", &pDevIDStr,"api", &pAPIName,"shortname",&pShortName);
if (err) {
AFB_ERROR("Could not retrieve devid string=%s", json_object_get_string(jHAL));
@@ -745,7 +776,7 @@ static int GetHALList(void)
AFB_ERROR("Unable to allocate memory for HalInfo");
return POLICY_FAIL;
}
- g_strlcpy(pHalInfo->pDevID,pDevIDStr,AHL_POLICY_STR_MAX_LENGTH);
+ g_strlcpy(pHalInfo->pDevID,pDevIDStr,AHL_POLICY_STR_MAX_LENGTH);
g_strlcpy(pHalInfo->pAPIName,pAPIName,AHL_POLICY_STR_MAX_LENGTH);
g_strlcpy(pHalInfo->pDisplayName,pShortName,AHL_POLICY_STR_MAX_LENGTH);
g_ptr_array_add( g_PolicyCtx.pHALList, pHalInfo);
@@ -758,12 +789,12 @@ static int GetHALList(void)
//
int Policy_OpenStream(json_object *pStreamJ)
{
- StreamInterfaceInfoT Stream;
+ StreamInterfaceInfoT Stream;
int err = JSONToStream(pStreamJ, &Stream);
if(err == AHL_POLICY_UTIL_FAIL)
{
- return AHL_POLICY_REJECT;
+ return AHL_POLICY_REJECT;
}
// Example rule -> when system is in shutdown or low power mode, no audio stream can be opened (return AHL_POLICY_REJECT)
@@ -771,22 +802,22 @@ int Policy_OpenStream(json_object *pStreamJ)
if(g_PolicyCtx.systemState != SYSTEM_NORMAL)
{
return AHL_POLICY_REJECT;
- }
-
+ }
+
StreamConfigT StreamConfig;
err = getStreamConfig(Stream.pRoleName, &StreamConfig);
if(err == POLICY_FAIL)
{
- return AHL_POLICY_REJECT;
+ return AHL_POLICY_REJECT;
}
// Volume support only possible through ALSA
if(Stream.endpoint.deviceURIType != DEVICEURITYPE_NOT_ALSA) {
- err = PolicyGetVolume(Stream.endpoint.endpointID,
+ err = PolicyGetVolume(Stream.endpoint.endpointID,
Stream.endpoint.type,
- Stream.endpoint.gsHALAPIName,
- Stream.endpoint.pRoleName,
- Stream.endpoint.deviceURIType,
+ Stream.endpoint.gsHALAPIName,
+ Stream.endpoint.pRoleName,
+ Stream.endpoint.deviceURIType,
&Stream.endpoint.iVolume);
if(err == POLICY_FAIL)
{
@@ -799,33 +830,33 @@ int Policy_OpenStream(json_object *pStreamJ)
{
return AHL_POLICY_REJECT;
}
- return AHL_POLICY_ACCEPT;
+ return AHL_POLICY_ACCEPT;
}
int Policy_CloseStream(json_object *pStreamJ)
{
- StreamInterfaceInfoT Stream;
+ StreamInterfaceInfoT Stream;
int err = JSONToStream(pStreamJ, &Stream);
if(err == AHL_POLICY_UTIL_FAIL)
{
- return AHL_POLICY_REJECT;
+ return AHL_POLICY_REJECT;
}
- //seach corresponding endpoint and gather information on it
+ //seach corresponding endpoint and gather information on it
EndPointPolicyInfoT *pCurrEndPointPolicy = PolicySearchEndPoint(Stream.endpoint.type , Stream.endpoint.gsDeviceName);
if(pCurrEndPointPolicy)
{
//close the stream and handle unduck if need be
if((pCurrEndPointPolicy->streamInfo != NULL) && (pCurrEndPointPolicy->streamInfo->len > 0))
{
- PolicyRunningIdleTransition(pCurrEndPointPolicy, &Stream);
+ PolicyRunningIdleTransition(pCurrEndPointPolicy, &Stream);
}
-
+
}
- return AHL_POLICY_ACCEPT;
+ return AHL_POLICY_ACCEPT;
}
int Policy_SetStreamState(json_object *pStreamJ)
-{
+{
// Optional TODO: Could mute endpoint before activation, unmute afterwards (after a delay?) to avoid noises
StreamStateT streamState = 0;
@@ -834,108 +865,108 @@ int Policy_SetStreamState(json_object *pStreamJ)
int err = JSONToStream(pStreamJ, &Stream);
if(err == AHL_POLICY_UTIL_FAIL)
{
- return AHL_POLICY_REJECT;
+ return AHL_POLICY_REJECT;
}
json_object *streamStateJ = NULL;
if(!json_object_object_get_ex(pStreamJ, "arg_stream_state", &streamStateJ))
{
- return AHL_POLICY_REJECT;
+ return AHL_POLICY_REJECT;
}
streamState = (StreamStateT)json_object_get_int(streamStateJ);
// Change of state
if(Stream.streamState != streamState)
{
- //seach corresponding endpoint and gather information on it
+ //seach corresponding endpoint and gather information on it
EndPointPolicyInfoT *pCurrEndPointPolicy = PolicySearchEndPoint(Stream.endpoint.type , Stream.endpoint.gsDeviceName);
-
+
switch(Stream.streamState)
{
- case STREAM_STATE_IDLE:
+ case STREAM_STATE_IDLE:
switch(streamState)
{
case STREAM_STATE_RUNNING:
err = PolicyIdleRunningTransition(pCurrEndPointPolicy, &Stream);
if(err)
{
- return AHL_POLICY_REJECT;
- }
- PolicyPostStateEvent(Stream.streamID,STREAM_EVENT_START);
+ return AHL_POLICY_REJECT;
+ }
+ PolicyPostStateEvent(Stream.streamID,STREAM_EVENT_START);
break;
case STREAM_STATE_PAUSED:
err = PolicyIdleRunningTransition(pCurrEndPointPolicy, &Stream);
if(err)
{
- return AHL_POLICY_REJECT;
- }
- PolicyPostStateEvent(Stream.streamID,STREAM_EVENT_PAUSE);
+ return AHL_POLICY_REJECT;
+ }
+ PolicyPostStateEvent(Stream.streamID,STREAM_EVENT_PAUSE);
break;
default:
- return AHL_POLICY_REJECT;
+ return AHL_POLICY_REJECT;
}
break;
- case STREAM_STATE_RUNNING:
+ case STREAM_STATE_RUNNING:
switch(streamState)
{
case STREAM_STATE_IDLE:
err = PolicyRunningIdleTransition(pCurrEndPointPolicy, &Stream);
if(err)
{
- return AHL_POLICY_REJECT;
- }
- PolicyPostStateEvent(Stream.streamID,STREAM_EVENT_STOP);
+ return AHL_POLICY_REJECT;
+ }
+ PolicyPostStateEvent(Stream.streamID,STREAM_EVENT_STOP);
break;
case STREAM_STATE_PAUSED:
- PolicyPostStateEvent(Stream.streamID,STREAM_EVENT_PAUSE);
+ PolicyPostStateEvent(Stream.streamID,STREAM_EVENT_PAUSE);
break;
default:
- return AHL_POLICY_REJECT;
+ return AHL_POLICY_REJECT;
}
break;
- case STREAM_STATE_PAUSED:
+ case STREAM_STATE_PAUSED:
switch(streamState)
{
case STREAM_STATE_IDLE:
err = PolicyRunningIdleTransition(pCurrEndPointPolicy, &Stream);
if(err)
{
- return AHL_POLICY_REJECT;
- }
- PolicyPostStateEvent(Stream.streamID,STREAM_EVENT_STOP);
+ return AHL_POLICY_REJECT;
+ }
+ PolicyPostStateEvent(Stream.streamID,STREAM_EVENT_STOP);
break;
case STREAM_STATE_RUNNING:
- PolicyPostStateEvent(Stream.streamID,STREAM_EVENT_RESUME);
- break;
+ PolicyPostStateEvent(Stream.streamID,STREAM_EVENT_RESUME);
+ break;
default:
- return AHL_POLICY_REJECT;
+ return AHL_POLICY_REJECT;
}
break;
default:
- return AHL_POLICY_REJECT;
- }
+ return AHL_POLICY_REJECT;
+ }
}
- return AHL_POLICY_ACCEPT;
+ return AHL_POLICY_ACCEPT;
}
int Policy_SetStreamMute(json_object *pStreamJ)
{
// Note: stream mute currently implemented directly using ALSA volume. It should later be implemented with a distinct mute switch control instead
StreamMuteT streamMute = 0;
- StreamInterfaceInfoT Stream;
+ StreamInterfaceInfoT Stream;
int err = JSONToStream(pStreamJ, &Stream);
if(err == AHL_POLICY_UTIL_FAIL)
{
- return AHL_POLICY_REJECT;
+ return AHL_POLICY_REJECT;
}
json_object *streamMuteJ=NULL;
if(!json_object_object_get_ex(pStreamJ, "mute_state", &streamMuteJ))
{
- return AHL_POLICY_REJECT;
+ return AHL_POLICY_REJECT;
}
streamMute = (StreamMuteT)json_object_get_int(streamMuteJ);
@@ -943,20 +974,20 @@ int Policy_SetStreamMute(json_object *pStreamJ)
{
if(streamMute == STREAM_MUTED)
{
- err = PolicySetVolume(Stream.endpoint.endpointID,
+ err = PolicySetVolume(Stream.endpoint.endpointID,
Stream.endpoint.type,
Stream.endpoint.gsHALAPIName,
Stream.pRoleName,
Stream.endpoint.deviceURIType,
- 0, // mute volume
+ 0, // mute volume
false, // no volume ramp
false); // no volume event
- if(err)
+ if(err)
{
- AFB_ERROR("StreamID:%i Set Volume return with errorcode%i",Stream.streamID, err);
- return AHL_POLICY_REJECT;
- }
- PolicyPostStateEvent(Stream.streamID,STREAM_EVENT_MUTED);
+ AFB_ERROR("StreamID:%i Set Volume return with errorcode%i",Stream.streamID, err);
+ return AHL_POLICY_REJECT;
+ }
+ PolicyPostStateEvent(Stream.streamID,STREAM_EVENT_MUTED);
}
else
{
@@ -964,19 +995,19 @@ int Policy_SetStreamMute(json_object *pStreamJ)
Stream.endpoint.type,
Stream.endpoint.gsHALAPIName,
Stream.pRoleName,
- Stream.endpoint.deviceURIType,
+ Stream.endpoint.deviceURIType,
Stream.endpoint.iVolume, // restore volume
false, // no volume ramp
- false); // no volume event
- if(err)
+ false); // no volume event
+ if(err)
{
- AFB_ERROR("Endpoint:%i Set Volume return with errorcode%i",Stream.streamID, err);
- return AHL_POLICY_REJECT;
- }
- PolicyPostStateEvent(Stream.streamID,STREAM_EVENT_UNMUTED);
+ AFB_ERROR("Endpoint:%i Set Volume return with errorcode%i",Stream.streamID, err);
+ return AHL_POLICY_REJECT;
+ }
+ PolicyPostStateEvent(Stream.streamID,STREAM_EVENT_UNMUTED);
}
}
-
+
return AHL_POLICY_ACCEPT;
}
@@ -984,45 +1015,45 @@ int Policy_SetVolume(json_object *pEndpointJ,json_object ** ppVolumeReply)
{
char *volumeStr = NULL;
EndPointInterfaceInfoT Endpoint;
-
+
int err = JSONToEndpoint(pEndpointJ, &Endpoint);
if(err == AHL_POLICY_UTIL_FAIL)
{
- return AHL_POLICY_REJECT;
+ return AHL_POLICY_REJECT;
}
json_object *volumeJ = NULL;
if(!json_object_object_get_ex(pEndpointJ, "arg_volume", &volumeJ))
{
- return AHL_POLICY_REJECT;
+ return AHL_POLICY_REJECT;
}
volumeStr = (char*)json_object_get_string(volumeJ);
// TODO: Parse volume string to support increment/absolute/percent notation
int vol = atoi(volumeStr);
-
+
// Set the volume
- err = PolicySetVolume(Endpoint.endpointID,
+ err = PolicySetVolume(Endpoint.endpointID,
Endpoint.type,
Endpoint.gsHALAPIName,
Endpoint.pRoleName,
- Endpoint.deviceURIType,
+ Endpoint.deviceURIType,
vol,
true, // volume ramp
true); // send events (to be forwarded to application clients)
- if (err)
+ if (err)
{
- AFB_ERROR("Set Volume return with errorcode %i", err);
+ AFB_ERROR("Set Volume return with errorcode %i", err);
return AHL_POLICY_REJECT;
}
err = wrap_json_pack(ppVolumeReply,"{s:i}","volume",vol);
- if (err)
+ if (err)
{
- return AHL_POLICY_REJECT;
+ return AHL_POLICY_REJECT;
}
- return AHL_POLICY_ACCEPT;
+ return AHL_POLICY_ACCEPT;
}
int Policy_SetProperty(json_object *pEndpointJ,json_object ** ppPropertyReply)
@@ -1033,33 +1064,33 @@ int Policy_SetProperty(json_object *pEndpointJ,json_object ** ppPropertyReply)
int err = JSONToEndpoint(pEndpointJ, &Endpoint);
if(err == AHL_POLICY_UTIL_FAIL)
{
- return AHL_POLICY_REJECT;
+ return AHL_POLICY_REJECT;
}
json_object *propertyNameJ = NULL;
if(!json_object_object_get_ex(pEndpointJ, "arg_property_name", &propertyNameJ))
{
- return AHL_POLICY_REJECT;
+ return AHL_POLICY_REJECT;
}
propertyName = (char*)json_object_get_string(propertyNameJ);
json_object *propValueJ = NULL;
if(!json_object_object_get_ex(pEndpointJ, "arg_property_value", &propValueJ))
{
- return AHL_POLICY_REJECT;
+ return AHL_POLICY_REJECT;
}
json_type currentTypeJ = json_object_get_type(propValueJ);
json_object *propArray = NULL;
if(!json_object_object_get_ex(pEndpointJ, "property_table", &propArray))
{
- return AHL_POLICY_REJECT;
+ return AHL_POLICY_REJECT;
}
- int iPropArrayLen = json_object_array_length(propArray);
+ int iPropArrayLen = json_object_array_length(propArray);
int foundProperty = 0;
-
- for (int i = 0; i < iPropArrayLen; i++)
+
+ for (int i = 0; i < iPropArrayLen; i++)
{
// get the i-th object in medi_array
json_object *propElementJ = json_object_array_get_idx(propArray, i);
@@ -1068,8 +1099,8 @@ int Policy_SetProperty(json_object *pEndpointJ,json_object ** ppPropertyReply)
json_object *propElementNameJ=NULL;
if(json_object_object_get_ex(propElementJ, "property_name", &propElementNameJ))
{
- char *propElementName = (char*)json_object_get_string(propElementNameJ);
- if(strcasecmp(propElementName,propertyName)==0)
+ char *propElementName = (char*)json_object_get_string(propElementNameJ);
+ if(strcasecmp(propElementName,propertyName)==0)
{
json_object *propElementValueJ=NULL;
AFB_NOTICE("property element =%s",json_object_get_string(propElementJ));
@@ -1083,46 +1114,46 @@ int Policy_SetProperty(json_object *pEndpointJ,json_object ** ppPropertyReply)
if(currentTypeJ != elementTypeJ)
{
AFB_ERROR("Property Value Type is wrong");
- return AHL_POLICY_REJECT;
+ return AHL_POLICY_REJECT;
}
foundProperty = 1;
- break;
+ break;
}
}
- }
+ }
}
}
if(foundProperty== 0)
{
AFB_ERROR("Can't find property %s, request will be rejected", propertyName);
- return AHL_POLICY_REJECT;
+ return AHL_POLICY_REJECT;
}
- // Create a new Json Object
+ // Create a new Json Object
json_object *pEventDataJ = NULL;
err = wrap_json_pack(&pEventDataJ,"{s:s,s:i,s:i,s:s,s:o,s:s}",
"event_name", AHL_ENDPOINT_PROPERTY_EVENT,
- "endpoint_id", Endpoint.endpointID,
+ "endpoint_id", Endpoint.endpointID,
"endpoint_type", Endpoint.type,
"property_name", propertyName,
- "value",propValueJ,
+ "value",propValueJ,
"audio_role", Endpoint.pRoleName);
if(err)
{
- AFB_ERROR("Unable to pack property event");
+ AFB_ERROR("Unable to pack property event");
return AHL_POLICY_REJECT;
}
- // Raise event to notify HLB clients
+ // Raise event to notify HLB clients
// Same mechanic that policy could use if a particular state change would need to affect a property
audiohlapi_raise_event(pEventDataJ);
// HLB expects synchronous return of policy effected value
err = wrap_json_pack(ppPropertyReply,"{s:o}","value",propValueJ);
- if (err)
+ if (err)
{
- return AHL_POLICY_REJECT;
+ return AHL_POLICY_REJECT;
}
return AHL_POLICY_ACCEPT;
@@ -1130,7 +1161,7 @@ int Policy_SetProperty(json_object *pEndpointJ,json_object ** ppPropertyReply)
int Policy_PostAction(json_object *pPolicyActionJ)
{
- char * actionName = NULL;
+ char * actionName = NULL;
char * audioRole = NULL;
char * mediaName = NULL;
json_object *actionContext = NULL;
@@ -1140,11 +1171,11 @@ int Policy_PostAction(json_object *pPolicyActionJ)
AFB_ERROR("Unable to pack JSON endpoint, =%s", wrap_json_get_error_string(err));
return AHL_POLICY_REJECT;
}
-
+
// TODO: Any event with media specified should trigger action on provided rendering services (e.g. Wwise binding, gstreamer file player wrapper, MPDC? simple ALSA player (aplay)?)
// Example (when the policy is hooked to CAN events). Post audio playback events other than safety during reverse gear engaged declined
// Example post HMI audio role playback events declined when higher priority streams are active
-
+
//In this use case just return the action back to highlevel binding.
json_object *pEventDataJ = NULL;
@@ -1174,10 +1205,10 @@ int Policy_Endpoint_Init(json_object *pInPolicyEndpointJ,json_object **pOutPolic
"device_uri_type",&deviceURIType,
"audio_role",&pRoleName,
"alsa_cardNum", &iAlsaCardNumber,
- "device_name", &pDeviceName );
+ "device_name", &pDeviceName );
if (err) {
AFB_ERROR("Unable to unpack JSON endpoint, =%s", wrap_json_get_error_string(err));
- goto OnError;
+ goto OnError;
}
StreamConfigT StreamConfig;
@@ -1189,7 +1220,7 @@ int Policy_Endpoint_Init(json_object *pInPolicyEndpointJ,json_object **pOutPolic
// Update Hal Name
err = RetrieveAssociatedHALAPIName(iAlsaCardNumber,&pDisplayName,&pHALName);
if (err) {
- AFB_WARNING("HAL not found for device %s", pDeviceName);
+ AFB_WARNING("HAL not found for device %s", pDeviceName);
pDisplayName = g_strdup(AHL_POLICY_UNDEFINED_DISPLAYNAME);
pHALName = g_strdup(AHL_POLICY_UNDEFINED_HALNAME);
iAllocString = 1;
@@ -1197,16 +1228,16 @@ int Policy_Endpoint_Init(json_object *pInPolicyEndpointJ,json_object **pOutPolic
else
{
// Set initial Volume
- err = PolicySetVolume(endpointID,
+ err = PolicySetVolume(endpointID,
endpointType,
- pHALName,
- pRoleName,
- deviceURIType,
+ pHALName,
+ pRoleName,
+ deviceURIType,
StreamConfig.iVolumeInit,
false, // no volume ramp
false); // Do not raise event
- if(err) {
- goto OnError;
+ if(err) {
+ goto OnError;
}
}
}
@@ -1219,7 +1250,7 @@ int Policy_Endpoint_Init(json_object *pInPolicyEndpointJ,json_object **pOutPolic
// Create json object for PropTable
json_object *pPropTableJ = json_object_new_array();
- //TODO Get Property from HAL
+ //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);
@@ -1227,7 +1258,7 @@ int Policy_Endpoint_Init(json_object *pInPolicyEndpointJ,json_object **pOutPolic
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,
"display_name",pDisplayName,
@@ -1236,9 +1267,9 @@ int Policy_Endpoint_Init(json_object *pInPolicyEndpointJ,json_object **pOutPolic
);
if (err) {
AFB_ERROR("Unable to pack JSON endpoint, =%s", wrap_json_get_error_string(err));
- goto OnError;
+ goto OnError;
}
-
+
// TODO: Future policy binding to return request response with pOutPolicyEndpointJ (instead of output argument)
return AHL_POLICY_ACCEPT; // No errors
@@ -1258,7 +1289,7 @@ int Policy_Init()
// Initialize Ressources
g_PolicyCtx.pSourceEndpoints = g_ptr_array_new_with_free_func(TerminateEndPointPolicyInfo);
- g_PolicyCtx.pSinkEndpoints = g_ptr_array_new_with_free_func(TerminateEndPointPolicyInfo);
+ g_PolicyCtx.pSinkEndpoints = g_ptr_array_new_with_free_func(TerminateEndPointPolicyInfo);
g_PolicyCtx.pHALList = g_ptr_array_new_with_free_func(TerminateHalInfo);
@@ -1274,7 +1305,7 @@ 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
+ // Set System Normal for now, this should be set by an event
g_PolicyCtx.systemState = SYSTEM_NORMAL;
#ifdef AK_POLICY_DEMO
@@ -1300,17 +1331,17 @@ void Policy_Term()
// Free Ressources
if(g_PolicyCtx.pHALList)
{
- g_ptr_array_unref(g_PolicyCtx.pHALList);
+ g_ptr_array_unref(g_PolicyCtx.pHALList);
}
- if (g_PolicyCtx.pSourceEndpoints)
- {
- g_ptr_array_unref(g_PolicyCtx.pSourceEndpoints);
+ if (g_PolicyCtx.pSourceEndpoints)
+ {
+ g_ptr_array_unref(g_PolicyCtx.pSourceEndpoints);
+ }
+ if (g_PolicyCtx.pSinkEndpoints)
+ {
+ g_ptr_array_unref(g_PolicyCtx.pSinkEndpoints);
}
- if (g_PolicyCtx.pSinkEndpoints)
- {
- g_ptr_array_unref(g_PolicyCtx.pSinkEndpoints);
- }
}
// For demo purpose only, should be listening to signal composer / CAN events instead
@@ -1324,19 +1355,19 @@ void Policy_OnEvent(const char *evtname, json_object *eventJ)
if(strcasecmp(evtname, "audiod/system_events")==0)
{
int err = wrap_json_unpack(eventJ, "{s:s,s:o}", "event_name", &eventName, "event_parameter", &event_parameter);
- if (err) {
+ if (err) {
AFB_WARNING("Invalid arguments, Args not a valid json object query=%s", json_object_get_string(eventJ));
return;
}
-
+
if(strcasecmp(eventName, "speed")==0)
{
AFB_NOTICE("Invalid arguments, Args not a valid json object query=%s", json_object_get_string(event_parameter));
err = wrap_json_unpack(event_parameter, "{s:i}", "speed_value", &speed);
- if (err) {
+ if (err) {
AFB_WARNING("Invalid arguments, Args not a valid json object query=%s", json_object_get_string(event_parameter));
return;
- }
+ }
// When speed change Modify volume on Endpoint where entertainment change
PolicySpeedModify(speed);
}