To send a custom message from one service to another service code changes are required in both the services.
As an example consider sending a custom message from VoiceProcTxSvc to VoiceProcRxSvc to enable loopback between them.
Detailed description of code changes: code changes can be found in bold font.
1. Create a payload structure
Create a payload structure as shown below in <ROOT>\elite\common\VoiceCmnUtils\inc\VoiceMsgs.h
This can be done using any other payload structure as reference. All the elements are same except the new parameter loop_back_enable.
/** Payload structure for enabling loopback mode between VpTx and VpRx using an API in VpTx */
typedef struct
{
qurt_elite_queue_t *pBufferReturnQ;
/**< This is the queue to which this payload buffer needs to be returned*/
qurt_elite_queue_t *pResponseQ;
/**< This is the queue to send the ACK to. NULL indicates no response is required*/
uint32_t unClientToken;
/**< Token that should be given in the ACK. This is different than the unResponeResult and can be used to identify who send the ACK back by the server. */
uint32_t unResponseResult;
/**< This is to be filled with ACK results by the client. */
uint32_t sec_opcode;
/**< This is the secondary opcode indicating the format for the rest of payload For this type, sec_opcode == VOICEPROCRX_SET_LOOPBACK */
uint32_t loop_back_enable;
/**< Enable/disable loopback 0 - Disable, 1- - Enable */
} elite_msg_custom_voc_loopback_enable;
2. Add a new custom message command
Add a new custom message command in vprx_custom_msgs_t to handle it by the VoiceProcrxSvc.
Update <ROOT>\elite\dynamic_svcs\VoiceProcRxSvc\inc\VoiceProcRxSvc.h
/** Enumerations for custom messages supported by this service
*/
typedef enum
{
VOICEPROCRX_CONNECT_DWN_STREAM_CMD = 0,
/**< Connect to downstream peer */
VOICEPROCRX_DISCONNECT_DWN_STREAM_CMD,
/**< Disconnect from downstream peer */
VOICEPROCRX_RECONFIG_CMD,
/**< Reconfigure to a new topology/sampling rate */
VOICEPROCRX_RUN_CMD,
/**< Move to run state and start processing data */
VOICEPROCRX_STOP_CMD,
/**< Move to stop state and stop processing data */
VOICEPROCRX_SET_PARAM_CMD,
/**< Set a parameter */
VOICEPROCRX_GET_PARAM_CMD,
/**< Get a parameter */
VOICEPROCRX_DESTROY_YOURSELF_CMD,
/**< Destroy the service instance */
VOICEPROCRX_SET_MUTE_CMD,
/**< Control mute/unmute */
VOICEPROCRX_CONFIG_HOST_PCM,
/**< Configure Host PCM */
VOICEPROCRX_SET_TIMING_CMD,
/**< Set timing parameters */
VOICEPROCRX_SET_LOOPBACK_CMD,
/**< Set loopback flag */
VOICEPROCRX_NUM_MSGS,
/**< Number of supported message */
} vprx_custom_msgs_t;
3. Include file
Include the VoiceProcRxSvc.h file in <ROOT>\elite\dynamic_svc\VoiceProcTxSvc\src\Vptx_Svc.cpp to send new custom command VOICEPROCRX_SET_LOOPBACK_CMD from VoiceProcTxSvc to VoiceProcRxSvc
/* =======================================================================
INCLUDE FILES FOR MODULE
========================================================================== */
#include "Vptx_Svc.h"
#include "VoiceProcRx.h"
4. Add a new API
Add a new API in <ROOT>\elite\dynamic_svcs\VoiceProcRxSvc\src\Vprx_Svc.cpp file to handle the new custom command sent from VoiceProcTxSvc and define it according to the requirement.
4.1 Declare new API
static ADSPResult vprx_custom_msg(void* pInstance,
elite_msg_any_t* pMsg);
static ADSPResult vprx_set_mute_cmd(void* pInstance,
elite_msg_any_t* pMsg);
static ADSPResult vprx_set_timing_cmd(void* pInstance,
elite_msg_any_t* pMsg);
static ADSPResult vprx_set_loopback_cmd(void* pInstance,
elite_msg_any_t* pMsg);
static ADSPResult vprx_config_host_pcm(void* pInstance,
elite_msg_any_t* pMsg);
static ADSPResult vprx_apr_cmd(void* pInstance, elite_msg_any_t* pMsg);
4.2 Define new API to handle custom message command
Here the new API will enable the loopback flag in VoiceProcRxSvc.
static ADSPResult vprx_set_loopback_cmd(void* pInstance,
elite_msg_any_t* pMsg)
{
ADSPResult nResult = ADSP_EOK;
vprx_t* pVprx = (vprx_t*)pInstance;
elite_msg_custom_voc_loopback_enable *pSetLoopbackCmd = (elite_msg_custom_voc_loopback_enable *) pMsg->pPayload;
if(pVprx != NULL)
{
pVprx->loopback_enable_flag = pSetLoopbackCmd->loop_back_enable;
}
else
{
MSG_1(MSG_SSID_QDSP6, DBG_ERROR_PRIO, "VpRx Failed To Set The Loopback Flag session(%lx)",pVprx->session_num);
}
elite_svc_send_ack(pMsg, ADSP_EBUSY);
return nResult;
}
5. Update the message handler for VoiceProcRxSvc
/* ----------------------------------------------------------------------
** Message handler
** ---------------------------------------------------------------------- */
static elite_svc_msg_handler_func pHandler[VOICEPROCRX_NUM_MSGS] =
{
vprx_connect_dwn_stream_cmd, // - VOICEPROCRX_CONNECT_DWN_STREAM_CMD
vprx_disconnect_dwn_stream_cmd,
// - VOICEPROCRX_DISCONNECT_DWN_STREAM_CMD
vprx_re_config_cmd, // - VOICEPROCRX_RECONFIG_CMD
vprx_run_cmd, // - VOICEPROCRX_OPEN_CMD
vprx_stop_cmd, // - VOICEPROCRX_CLOSE_PARAM_CMD
vprx_set_param_cmd, // - VOICEPROCRX_SET_PARAM_CMD
vprx_get_param_cmd, // - VOICEPROCRX_GET_PARAM_CMD
vprx_destroy_yourself_cmd, // - VOICEPROCRX_DESTROY_YOURSELF_CMD
vprx_set_mute_cmd, // - VOICEPROCRX_SET_MUTE_CMD
vprx_config_host_pcm, // - VOICEPROCRX_CONFIG_HOST_PCM
vprx_set_timing_cmd, // - VOICEPROCRX_SET_TIMING_CMD
vprx_set_loopback_cmd // - VOICEPROCRX_SET_LOOPBACK_CMD
};