summaryrefslogtreecommitdiffstats
path: root/src/ahl-policy.c
diff options
context:
space:
mode:
authorTai Vuong <tvuong@audiokinetic.com>2017-10-04 14:21:28 -0400
committerTai Vuong <tvuong@audiokinetic.com>2017-10-04 14:21:28 -0400
commit539f65bb5ad87238422a5ca26c5b524c3be44bd1 (patch)
tree01fa955edf1e9b597a4a4247b3a35390c7b6ddbc /src/ahl-policy.c
parentd69dc9732886074e9f400961b500e70d5c8305d7 (diff)
Post AudioWorkshop Work phase v1
Diffstat (limited to 'src/ahl-policy.c')
-rw-r--r--src/ahl-policy.c123
1 files changed, 86 insertions, 37 deletions
diff --git a/src/ahl-policy.c b/src/ahl-policy.c
index 7741afd..fa050af 100644
--- a/src/ahl-policy.c
+++ b/src/ahl-policy.c
@@ -21,70 +21,119 @@
#include "ahl-binding.h"
-
// This file provides example of custom, business logic driven policy actions that can affect behavior of the high level
-// TODO: Currently only isolated in separate source file. Objective is to make this to at least a shared lib plug-in
-// Going a step further would be to implement this within afb-controler policy plug-in (would require bi-directional access to HLB context)
+// TODO: Currently only isolated in separate source file. Objective is to make this to at least a shared lib plug-in (shared C context)
+// Going a step further would be to implement this within a distinct policy binding (requires to switch to JSON interface)
extern AHLCtxT g_AHLCtx; // TODO: Cannot stay if moved to external module
-// Attribute of high-level binding (parsed), policy enforced
-typedef enum InterruptedBehavior {
- INTERRUPTEDBEHAVIOR_CONTINUE = 0, // Continue to play when interrupted (e.g. media will be ducked)
- INTERRUPTEDBEHAVIOR_CANCEL, // Abort playback when interrupted (e.g. non-important HMI feedback that does not make sense later)
- INTERRUPTEDBEHAVIOR_PAUSE, // Pause source when interrupted, to be resumed afterwards (e.g. non-temporal guidance)
- INTERRUPTEDBEHAVIOR_MAXVALUE, // Enum count, keep at the end
-} InterruptedBehaviorT;
-
-PUBLIC int Policy_OpenStream(char *pAudioRole, EndpointTypeT endpointType, endpointID_t endpointID)
+static void Add_Endpoint_Property_Numeric( EndpointInfoT * io_pEndpointInfo, char * in_pPropertyName, int in_iPropertyValue)
{
- return 1; // Policy allowed
+ json_object * propValueJ = json_object_new_int(in_iPropertyValue);
+ g_hash_table_insert(io_pEndpointInfo->pPropTable, in_pPropertyName, propValueJ);
}
-PUBLIC int Policy_SetVolume(EndpointTypeT endpointType, endpointID_t endpointID, char *volumeStr, int rampTimeMS)
+static void Add_Endpoint_Property_String( EndpointInfoT * io_pEndpointInfo, char * in_pPropertyName, char * in_pPropertyValue)
{
- return 1; // Policy allowed
+ json_object * propValueJ = json_object_new_string(in_pPropertyValue);
+ g_hash_table_insert(io_pEndpointInfo->pPropTable, in_pPropertyName, propValueJ);
}
-PUBLIC int Policy_SetProperty(EndpointTypeT endpointType, endpointID_t endpointID, char *propertyName, char *propValueStr, int rampTimeMS)
+int Policy_OpenStream(char *pAudioRole, EndpointTypeT endpointType, endpointID_t endpointID)
{
- return 1; // Policy allowed
+ // TODO: Example rule -> when system is in shutdown or low power mode, no audio stream can be opened (return AHL_POLICY_REJECT)
+
+ return AHL_POLICY_ACCEPT;
}
+int Policy_CloseStream(streamID_t streamID)
+{
+ // For completeness, unlikely to have any policy rules here
-PUBLIC int Policy_SetState(EndpointTypeT endpointType, endpointID_t endpointID, char *pStateName, char *pStateValue)
+ return AHL_POLICY_ACCEPT;
+}
+
+int Policy_SetStreamState(streamID_t streamID, StreamStateT streamState )
{
+ // If higher priority audio role stream requires audio ducking (and un-ducking) of other streams (e.g. navigation ducks entertainment)
+ // TODO: Could potentially provide a fairly generic system using interupt behavior information and audio role priority (implemented and can be customized here)
+ // Specific exception can also be
+
+ // Source exclusion. E.g. When a source (e.g tuner) with same audio role as already active stream (e.g. media player) with same endpoint target,
+ // the former source is stopped (i.e. raise streamstate stop event)
+
+ // If source on communication role is active (e.g. handsfree call), activating entertainment sources is prohibited
+
+ // If handsfree or speech recognition (communication role) is started during entertainment playback, mute all entertainment streams (any endpoints except RSE)
+
+ // Startup or Shutdown audio stream mute entertainment (unmut when stream no longer active)
+
+ // Optional: Mute endpoint before activation, unmute afterwards (after a delay?) to avoid noises
+
+
+ return AHL_POLICY_ACCEPT;
+}
+int Policy_SetStreamMute(streamID_t streamID, StreamMuteT streamMute)
+{
+ return AHL_POLICY_ACCEPT;
+}
- //Mute
- if(strcmp(pStateName, AUDIOHL_STATE_NAME_MUTE) == 0)
- {
- if(strcmp(pStateName, AUDIOHL_STATE_NAME_MUTE) == 0)
+int Policy_SetVolume(EndpointTypeT endpointType, endpointID_t endpointID, char *volumeStr)
+{
+ return AHL_POLICY_ACCEPT;
+}
+int Policy_SetProperty(EndpointTypeT endpointType, endpointID_t endpointID, char *propertyName, char *propValueStr)
+{
+ return AHL_POLICY_ACCEPT;
+}
- return AUDIOHL_POLICY_ACCEPT;
- }
+int Policy_PostEvent(char *eventName, char *audioRole, char *mediaName, void *audioContext)
+{
+ // 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)?)
- //Retrieve global context
+ // 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
- //Active rule check
-
- //Ducking rule settings
+ return AHL_POLICY_ACCEPT;
+}
+int Policy_AudioDeviceChange()
+{
+ // Allow or disallow a new audio endpoint to be used by the system
+ // TODO: Policy assigns audio role(s) for device (or default)
+ // TODO: Raise events to engage device switching if active stream in audio role assigned to the new endpoint
+
+ return AHL_POLICY_ACCEPT;
+}
- return AUDIOHL_POLICY_ACCEPT;
+int Policy_Endpoint_Property_Init(EndpointInfoT * io_EndpointInfo)
+{
+ // Populate list of supported properties for specified endpoint (use helper functions)
+ // Setup initial values for all properties
+
+ // TODO: Switch on different known endpoints to populate different properties
+
+ // Test example
+ Add_Endpoint_Property_Numeric(io_EndpointInfo,AHL_PROPERTY_EQ_LOW,3);
+ Add_Endpoint_Property_Numeric(io_EndpointInfo,AHL_PROPERTY_EQ_MID,0);
+ Add_Endpoint_Property_Numeric(io_EndpointInfo,AHL_PROPERTY_EQ_HIGH,6);
+ Add_Endpoint_Property_Numeric(io_EndpointInfo,AHL_PROPERTY_BALANCE,0);
+ Add_Endpoint_Property_Numeric(io_EndpointInfo,AHL_PROPERTY_FADE,30);
+ Add_Endpoint_Property_String(io_EndpointInfo,"preset_name","flat");
+
+ return 0; // No errors
}
-PUBLIC int Policy_PostSoundEvent(char *eventName, char *audioRole, char *mediaName, void *audioContext)
+int Policy_Init()
{
- return 1; // Policy allowed
+ // Other policy specific initialization
+ return 0; // No errors
}
-PUBLIC int Policy_AudioDeviceChange()
+void Policy_Term()
{
- // Allow or disallow a new audio device
- // Raise events to engage device switching
- // Policy can also assign audio role(s) for device
- return 1; // Policy allowed
-} \ No newline at end of file
+ // Policy termination
+}