#include "legato.h"
#include "interfaces.h"
static le_mcc_CallRef_t TestCallRef;
static le_audio_StreamRef_t MdmRxAudioRef = NULL;
static le_audio_StreamRef_t MdmTxAudioRef = NULL;
static le_audio_StreamRef_t FeInRef = NULL;
static le_audio_StreamRef_t FeOutRef = NULL;
static le_audio_StreamRef_t FileAudioRef = NULL;
static le_audio_ConnectorRef_t AudioInputConnectorRef = NULL;
static le_audio_ConnectorRef_t AudioOutputConnectorRef = NULL;
static le_audio_MediaHandlerRef_t MediaHandlerRef = NULL;
static const char* DestinationNumber;
static const char* AudioTestCase;
static const char* MainAudioSoundPath;
static const char* AudioFilePath;
static int AudioFileFd = -1;
#define GAIN_VALUE 0x3000
static void MyMediaEventHandler
(
le_audio_StreamRef_t streamRef,
le_audio_MediaEvent_t event,
void* contextPtr
)
{
switch(event)
{
case LE_AUDIO_MEDIA_ENDED:
LE_INFO(
"File event is LE_AUDIO_MEDIA_ENDED.");
break;
case LE_AUDIO_MEDIA_ERROR:
LE_INFO(
"File event is LE_AUDIO_MEDIA_ERROR.");
break;
case LE_AUDIO_MEDIA_NO_MORE_SAMPLES:
LE_INFO(
"File event is LE_AUDIO_MEDIA_NO_MORE_SAMPLES.");
break;
default:
LE_INFO(
"File event is %d", event);
break;
}
}
static void ConnectAudioToFileRemotePlay
(
void
)
{
if ((AudioFileFd=open(AudioFilePath, O_RDONLY)) == -1)
{
LE_ERROR(
"Open file %s failure: errno.%d (%s)", AudioFilePath, errno, strerror(errno));
}
else
{
LE_INFO(
"Open file %s with AudioFileFd.%d", AudioFilePath, AudioFileFd);
}
LE_ERROR_IF((FileAudioRef==NULL),
"OpenFilePlayback returns NULL!");
LE_ERROR_IF((MediaHandlerRef==NULL),
"AddMediaHandler returns NULL!");
if (FileAudioRef && AudioInputConnectorRef)
{
{
LE_ERROR(
"Failed to connect FilePlayback on input connector!");
return;
}
LE_INFO(
"FilePlayback is now connected.");
{
}
else
{
}
}
}
static void ConnectAudioToFileRemoteRec
(
void
)
{
if ((AudioFileFd=open(AudioFilePath, O_WRONLY | O_CREAT | O_TRUNC)) == -1)
{
LE_ERROR(
"Open file %s failure: errno.%d (%s)", AudioFilePath, errno, strerror(errno));
}
else
{
LE_INFO(
"Open file %s with AudioFileFd.%d", AudioFilePath, AudioFileFd);
}
LE_ERROR_IF((FileAudioRef==NULL),
"OpenFileRecording returns NULL!");
if (FileAudioRef && AudioOutputConnectorRef)
{
{
LE_ERROR(
"Failed to connect Recorder on output connector!");
return;
}
LE_INFO(
"Recorder is now connected.");
{
}
else
{
}
}
}
static void ConnectAudioToFileLocalPlay
(
void
)
{
if ((AudioFileFd=open(AudioFilePath, O_RDONLY)) == -1)
{
LE_ERROR(
"Open file %s failure: errno.%d (%s)", AudioFilePath, errno, strerror(errno));
}
else
{
LE_INFO(
"Open file %s with AudioFileFd.%d", AudioFilePath, AudioFileFd);
}
LE_ERROR_IF((FileAudioRef==NULL),
"OpenFilePlayback returns NULL!");
LE_ERROR_IF((MediaHandlerRef==NULL),
"AddMediaHandler returns NULL!");
if (FileAudioRef && AudioOutputConnectorRef)
{
{
LE_ERROR(
"Failed to connect FilePlayback on output connector!");
return;
}
LE_INFO(
"FilePlayback is now connected.");
{
}
else
{
}
}
}
static void ConnectAudioToFileLocalRec
(
void
)
{
if ((AudioFileFd=open(AudioFilePath, O_WRONLY | O_CREAT | O_TRUNC)) == -1)
{
LE_ERROR(
"Open file %s failure: errno.%d (%s)", AudioFilePath, errno, strerror(errno));
}
else
{
LE_INFO(
"Open file %s with AudioFileFd.%d", AudioFilePath, AudioFileFd);
}
LE_ERROR_IF((FileAudioRef==NULL),
"OpenFileRecording returns NULL!");
if (FileAudioRef && AudioInputConnectorRef)
{
{
LE_ERROR(
"Failed to connect FileRecording on input connector!");
return;
}
LE_INFO(
"Recorder is now connected.");
{
}
else
{
}
}
}
static void ConnectAudioToCodec
(
void
)
{
LE_ERROR_IF((MdmRxAudioRef==NULL),
"GetRxAudioStream returns NULL!");
LE_ERROR_IF((MdmTxAudioRef==NULL),
"GetTxAudioStream returns NULL!");
LE_ERROR_IF((FeOutRef==NULL),
"OpenSpeaker returns NULL!");
LE_ERROR_IF((AudioInputConnectorRef==NULL),
"AudioInputConnectorRef is NULL!");
LE_ERROR_IF((AudioOutputConnectorRef==NULL),
"AudioOutputConnectorRef is NULL!");
if (MdmRxAudioRef && MdmTxAudioRef && FeOutRef && FeInRef &&
AudioInputConnectorRef && AudioOutputConnectorRef)
{
}
}
static void ConnectAudioToPcm
(
void
)
{
LE_ERROR_IF((MdmRxAudioRef==NULL),
"GetRxAudioStream returns NULL!");
LE_ERROR_IF((MdmTxAudioRef==NULL),
"GetTxAudioStream returns NULL!");
LE_ERROR_IF((FeOutRef==NULL),
"OpenPcmTx returns NULL!");
LE_ERROR_IF((FeInRef==NULL),
"OpenPcmRx returns NULL!");
LE_ERROR_IF((AudioInputConnectorRef==NULL),
"AudioInputConnectorRef is NULL!");
LE_ERROR_IF((AudioOutputConnectorRef==NULL),
"AudioOutputConnectorRef is NULL!");
if (MdmRxAudioRef && MdmTxAudioRef && FeOutRef && FeInRef &&
AudioInputConnectorRef && AudioOutputConnectorRef)
{
}
}
static void ConnectAudioToI2s
(
void
)
{
LE_ERROR_IF((MdmRxAudioRef==NULL),
"GetRxAudioStream returns NULL!");
LE_ERROR_IF((MdmTxAudioRef==NULL),
"GetTxAudioStream returns NULL!");
LE_ERROR_IF((FeOutRef==NULL),
"OpenI2sTx returns NULL!");
LE_ERROR_IF((FeInRef==NULL),
"OpenI2sRx returns NULL!");
LE_INFO(
"Open I2s: FeInRef.%p FeOutRef.%p", FeInRef, FeOutRef);
LE_ERROR_IF((AudioInputConnectorRef==NULL),
"AudioInputConnectorRef is NULL!");
LE_ERROR_IF((AudioOutputConnectorRef==NULL),
"AudioOutputConnectorRef is NULL!");
if (MdmRxAudioRef && MdmTxAudioRef && FeOutRef && FeInRef &&
AudioInputConnectorRef && AudioOutputConnectorRef)
{
}
LE_INFO(
"Open I2s: FeInRef.%p FeOutRef.%p", FeInRef, FeOutRef);
}
static void ConnectAudioToUsb
(
void
)
{
LE_ERROR_IF((MdmRxAudioRef==NULL),
"GetRxAudioStream returns NULL!");
LE_ERROR_IF((MdmTxAudioRef==NULL),
"GetTxAudioStream returns NULL!");
LE_ERROR_IF((FeOutRef==NULL),
"OpenUsbTx returns NULL!");
LE_ERROR_IF((FeInRef==NULL),
"OpenUsbRx returns NULL!");
LE_ERROR_IF((AudioInputConnectorRef==NULL),
"AudioInputConnectorRef is NULL!");
LE_ERROR_IF((AudioOutputConnectorRef==NULL),
"AudioOutputConnectorRef is NULL!");
if (MdmRxAudioRef && MdmTxAudioRef && FeOutRef && FeInRef &&
AudioInputConnectorRef && AudioOutputConnectorRef)
{
}
}
static void ConnectAudioToUsbTxI2sRx
(
void
)
{
LE_ERROR_IF((MdmRxAudioRef == NULL),
"GetRxAudioStream returns NULL!");
LE_ERROR_IF((MdmTxAudioRef == NULL),
"GetTxAudioStream returns NULL!");
LE_ERROR_IF((FeOutRef == NULL),
"OpenUsbTx returns NULL!");
LE_ERROR_IF((FeInRef == NULL),
"OpenI2sRx returns NULL!");
LE_ERROR_IF((AudioInputConnectorRef == NULL),
"AudioInputConnectorRef is NULL!");
LE_ERROR_IF((AudioOutputConnectorRef == NULL),
"AudioOutputConnectorRef is NULL!");
if (MdmRxAudioRef && MdmTxAudioRef && FeOutRef && FeInRef &&
AudioInputConnectorRef && AudioOutputConnectorRef)
{
}
}
static void ConnectAudioToUsbTxPcmRx
(
void
)
{
LE_ERROR_IF((MdmRxAudioRef == NULL),
"GetRxAudioStream returns NULL!");
LE_ERROR_IF((MdmTxAudioRef == NULL),
"GetTxAudioStream returns NULL!");
LE_ERROR_IF((FeOutRef == NULL),
"OpenUsbTx returns NULL!");
LE_ERROR_IF((FeInRef == NULL),
"OpenPcmRx returns NULL!");
LE_ERROR_IF((AudioInputConnectorRef == NULL),
"AudioInputConnectorRef is NULL!");
LE_ERROR_IF((AudioOutputConnectorRef == NULL),
"AudioOutputConnectorRef is NULL!");
if (MdmRxAudioRef && MdmTxAudioRef && FeOutRef && FeInRef &&
AudioInputConnectorRef && AudioOutputConnectorRef)
{
}
}
static void ConnectAudioToUsbRxI2sTx
(
void
)
{
LE_ERROR_IF((MdmRxAudioRef == NULL),
"GetRxAudioStream returns NULL!");
LE_ERROR_IF((MdmTxAudioRef == NULL),
"GetTxAudioStream returns NULL!");
LE_ERROR_IF((FeOutRef == NULL),
"OpenI2sTx returns NULL!");
LE_ERROR_IF((FeInRef == NULL),
"OpenUsbRx returns NULL!");
LE_ERROR_IF((AudioInputConnectorRef == NULL),
"AudioInputConnectorRef is NULL!");
LE_ERROR_IF((AudioOutputConnectorRef == NULL),
"AudioOutputConnectorRef is NULL!");
if (MdmRxAudioRef && MdmTxAudioRef && FeOutRef && FeInRef &&
AudioInputConnectorRef && AudioOutputConnectorRef)
{
}
}
static void ConnectAudioToUsbRxPcmTx
(
void
)
{
LE_ERROR_IF((MdmRxAudioRef == NULL),
"GetRxAudioStream returns NULL!");
LE_ERROR_IF((MdmTxAudioRef == NULL),
"GetTxAudioStream returns NULL!");
LE_ERROR_IF((FeOutRef == NULL),
"OpenPcmTx returns NULL!");
LE_ERROR_IF((FeInRef == NULL),
"OpenUsbRx returns NULL!");
LE_ERROR_IF((AudioInputConnectorRef == NULL),
"AudioInputConnectorRef is NULL!");
LE_ERROR_IF((AudioOutputConnectorRef == NULL),
"AudioOutputConnectorRef is NULL!");
if (MdmRxAudioRef && MdmTxAudioRef && FeOutRef && FeInRef &&
AudioInputConnectorRef && AudioOutputConnectorRef)
{
}
}
static void ConnectAudio
(
void
)
{
if (strcmp(AudioTestCase,"MIC")==0)
{
LE_INFO(
"Connect MIC and SPEAKER ");
ConnectAudioToCodec();
}
else if (strcmp(AudioTestCase,"PCM")==0)
{
ConnectAudioToPcm();
}
else if (strcmp(AudioTestCase,"I2S")==0)
{
ConnectAudioToI2s();
}
else if (strcmp(AudioTestCase,"USB")==0)
{
ConnectAudioToUsb();
}
else if (strcmp(MainAudioSoundPath,"USBTXI2SRX")==0)
{
ConnectAudioToUsbTxI2sRx();
}
else if (strcmp(MainAudioSoundPath,"USBTXPCMRX")==0)
{
ConnectAudioToUsbTxPcmRx();
}
else if (strcmp(MainAudioSoundPath,"USBRXI2STX")==0)
{
ConnectAudioToUsbRxI2sTx();
}
else if (strcmp(MainAudioSoundPath,"USBRXPCMTX")==0)
{
ConnectAudioToUsbRxPcmTx();
}
else if ((strncmp(AudioTestCase,"R-",2)==0) || (strncmp(AudioTestCase,"L-",2)==0))
{
if (strcmp(MainAudioSoundPath,"MIC")==0)
{
LE_INFO(
"Connect MIC and SPEAKER ");
ConnectAudioToCodec();
}
else if (strcmp(MainAudioSoundPath,"PCM")==0)
{
ConnectAudioToPcm();
}
else if (strcmp(MainAudioSoundPath,"I2S")==0)
{
ConnectAudioToI2s();
}
else if (strcmp(MainAudioSoundPath,"USB")==0)
{
ConnectAudioToUsb();
}
else if (strcmp(MainAudioSoundPath,"USBTXI2SRX")==0)
{
ConnectAudioToUsbTxI2sRx();
}
else if (strcmp(MainAudioSoundPath,"USBTXPCMRX")==0)
{
ConnectAudioToUsbTxPcmRx();
}
else if (strcmp(MainAudioSoundPath,"USBRXI2STX")==0)
{
ConnectAudioToUsbRxI2sTx();
}
else if (strcmp(MainAudioSoundPath,"USBRXPCMTX")==0)
{
ConnectAudioToUsbRxPcmTx();
}
else
{
}
}
else
{
}
}
static void DisconnectAllAudio
(
void
)
{
if (AudioInputConnectorRef)
{
if(FileAudioRef)
{
LE_INFO(
"Disconnect %p from connector.%p", FileAudioRef, AudioInputConnectorRef);
}
if (FeInRef)
{
LE_INFO(
"Disconnect %p from connector.%p", FeInRef, AudioInputConnectorRef);
}
if(MdmTxAudioRef)
{
LE_INFO(
"Disconnect %p from connector.%p", MdmTxAudioRef, AudioInputConnectorRef);
}
}
if(AudioOutputConnectorRef)
{
if(FileAudioRef)
{
LE_INFO(
"Disconnect %p from connector.%p", FileAudioRef, AudioOutputConnectorRef);
}
if(FeOutRef)
{
LE_INFO(
"Disconnect %p from connector.%p", FeOutRef, AudioOutputConnectorRef);
}
if(MdmRxAudioRef)
{
LE_INFO(
"Disconnect %p from connector.%p", MdmRxAudioRef, AudioOutputConnectorRef);
}
}
if(AudioInputConnectorRef)
{
AudioInputConnectorRef = NULL;
}
if(AudioOutputConnectorRef)
{
AudioOutputConnectorRef = NULL;
}
if(FileAudioRef)
{
FeOutRef = NULL;
}
if(FeInRef)
{
FeInRef = NULL;
}
if(FeOutRef)
{
FeOutRef = NULL;
}
if(MdmRxAudioRef)
{
FeOutRef = NULL;
}
if(MdmTxAudioRef)
{
FeOutRef = NULL;
}
if(MediaHandlerRef)
{
MediaHandlerRef = NULL;
}
}
static void MyCallEventHandler
(
le_mcc_CallRef_t callRef,
le_mcc_Event_t callEvent,
void* contextPtr
)
{
if (callEvent == LE_MCC_EVENT_ALERTING)
{
LE_INFO(
"Call event is LE_MCC_EVENT_ALERTING.");
}
else if (callEvent == LE_MCC_EVENT_CONNECTED)
{
LE_INFO(
"Call event is LE_MCC_EVENT_CONNECTED.");
if (strcmp(AudioTestCase,"R-PB")==0)
{
ConnectAudioToFileRemotePlay();
}
else
if (strcmp(AudioTestCase,"R-REC")==0)
{
ConnectAudioToFileRemoteRec();
}
else if (strcmp(AudioTestCase,"L-PB")==0)
{
ConnectAudioToFileLocalPlay();
}
else if (strcmp(AudioTestCase,"L-REC")==0)
{
ConnectAudioToFileLocalRec();
}
else
{
}
}
else if (callEvent == LE_MCC_EVENT_TERMINATED)
{
LE_INFO(
"Call event is LE_MCC_EVENT_TERMINATED.");
switch(term)
{
case LE_MCC_TERM_NETWORK_FAIL:
LE_INFO(
"Termination reason is LE_MCC_TERM_NETWORK_FAIL");
break;
case LE_MCC_TERM_UNASSIGNED_NUMBER:
LE_INFO(
"Termination reason is LE_MCC_TERM_UNASSIGNED_NUMBER");
break;
case LE_MCC_TERM_USER_BUSY:
LE_INFO(
"Termination reason is LE_MCC_TERM_USER_BUSY");
break;
case LE_MCC_TERM_LOCAL_ENDED:
LE_INFO(
"Termination reason is LE_MCC_TERM_LOCAL_ENDED");
break;
case LE_MCC_TERM_REMOTE_ENDED:
LE_INFO(
"Termination reason is LE_MCC_TERM_REMOTE_ENDED");
break;
case LE_MCC_TERM_UNDEFINED:
LE_INFO(
"Termination reason is LE_MCC_TERM_UNDEFINED");
break;
default:
LE_INFO(
"Termination reason is %d", term);
break;
}
DisconnectAllAudio();
}
else if (callEvent == LE_MCC_EVENT_INCOMING)
{
LE_INFO(
"Call event is LE_MCC_EVENT_INCOMING.");
{
LE_INFO(
"Failed to answer the call.");
}
}
else
{
}
}
static void PrintUsage()
{
int idx;
bool sandboxed = (getuid() != 0);
const char * usagePtr[] = {
"Usage of the audioMccTest is:",
" audioMccTest <Phone number> <test case> [main audio path] [file's name]",
"",
"Test cases are:",
" - MIC (for mic/speaker)",
" - PCM (not supported on mangOH board - for AR755x, AR8652 devkit's codec use, "
"execute 'wm8940_demo --pcm' command)",
" - I2S (not supported on mangOH board - for AR755x, AR8652 devkit's codec use, "
"execute 'wm8940_demo --i2s' command)",
" - USB (for USB)",
" - R-PB (for Remote playback)",
" - R-REC (for Remote recording)",
" - L-PB (for Local playback)",
" - L-REC (for Local recording)",
"",
"Main audio paths are: (for file playback/recording only)",
" - MIC (for mic/speaker)",
" - PCM (not supported on mangOH board - for AR755x, AR8652 devkit's codec use, "
"execute 'wm8940_demo --pcm' command)",
" - I2S (not supported on mangOH board - for AR755x, AR8652 devkit's codec use, "
"execute 'wm8940_demo --i2s' command)",
" - USB (for USB)",
"",
"File's name can be the complete file's path (for file playback/recording only).",
};
{
if(sandboxed)
{
}
else
{
fprintf(stderr, "%s\n", usagePtr[idx]);
}
}
}
{
{
LE_INFO(
"======== Start Audio implementation Test (audioMccTest) ========");
if (NULL == DestinationNumber)
{
exit(EXIT_FAILURE);
}
LE_INFO(
" Phone number.%s", DestinationNumber);
LE_INFO(
" Test case.%s", AudioTestCase);
{
LE_INFO(
" Main audio path.%s", MainAudioSoundPath);
LE_INFO(
" Audio file [%s]", AudioFilePath);
}
ConnectAudio();
LE_INFO(
"======== Audio implementation Test (audioMccTest) started successfully ========");
}
else
{
PrintUsage();
exit(EXIT_FAILURE);
}
}