#include "interfaces.h"
static const char* DestinationNumber;
static const char* AudioTestCase;
static const char* MainAudioSoundPath;
static const char* AudioFilePath;
static int AudioFileFd = -1;
static void MyMediaEventHandler
(
void* contextPtr
)
{
switch(event)
{
LE_INFO(
"File event is LE_AUDIO_MEDIA_ENDED.");
break;
LE_INFO(
"File event is LE_AUDIO_MEDIA_ERROR.");
break;
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)
{
if(res!=LE_OK)
{
LE_ERROR(
"Failed to connect FilePlayback on input connector!");
return;
}
LE_INFO(
"FilePlayback is now connected.");
if(res != LE_OK)
{
}
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)
{
if(res!=LE_OK)
{
LE_ERROR(
"Failed to connect Recorder on output connector!");
return;
}
LE_INFO(
"Recorder is now connected.");
if(res!=LE_OK)
{
}
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)
{
if(res!=LE_OK)
{
LE_ERROR(
"Failed to connect FilePlayback on output connector!");
return;
}
LE_INFO(
"FilePlayback is now connected.");
if(res != LE_OK)
{
}
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)
{
if(res!=LE_OK)
{
LE_ERROR(
"Failed to connect FileRecording on input connector!");
return;
}
LE_INFO(
"Recorder is now connected.");
if(res!=LE_OK)
{
}
else
{
}
}
}
#if (ENABLE_CODEC == 1)
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)
{
LE_ERROR_IF((res!=LE_OK),
"Failed to connect Mic on Input connector!");
LE_ERROR_IF((res!=LE_OK),
"Failed to connect mdmTx on Input connector!");
LE_ERROR_IF((res!=LE_OK),
"Failed to connect Speaker on Output connector!");
LE_ERROR_IF((res!=LE_OK),
"Failed to connect mdmRx on Output connector!");
}
}
#endif
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)
{
LE_ERROR_IF((res!=LE_OK),
"Failed to connect PCM RX on Input connector!");
LE_ERROR_IF((res!=LE_OK),
"Failed to connect mdmTx on Input connector!");
LE_ERROR_IF((res!=LE_OK),
"Failed to connect PCM TX on Output connector!");
LE_ERROR_IF((res!=LE_OK),
"Failed to connect mdmRx on Output connector!");
}
}
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_ERROR_IF((res!=LE_OK),
"Failed to connect I2S RX on Input connector!");
LE_ERROR_IF((res!=LE_OK),
"Failed to connect mdmTx on Input connector!");
LE_ERROR_IF((res!=LE_OK),
"Failed to connect I2S TX on Output connector!");
LE_ERROR_IF((res!=LE_OK),
"Failed to connect mdmRx on Output connector!");
}
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)
{
LE_ERROR_IF((res!=LE_OK),
"Failed to connect USB Rx on Input connector!");
LE_ERROR_IF((res!=LE_OK),
"Failed to connect mdmTx on Input connector!");
LE_ERROR_IF((res!=LE_OK),
"Failed to connect USB Tx on Output connector!");
LE_ERROR_IF((res!=LE_OK),
"Failed to connect mdmRx on Output connector!");
}
}
static void ConnectAudio
(
void
)
{
#if (ENABLE_CODEC == 1)
if (strcmp(AudioTestCase,"MIC")==0)
{
LE_INFO(
"Connect MIC and SPEAKER ");
ConnectAudioToCodec();
}
else
#endif
if (strcmp(AudioTestCase,"PCM")==0)
{
ConnectAudioToPcm();
}
else if (strcmp(AudioTestCase,"I2S")==0)
{
ConnectAudioToI2s();
}
else if (strcmp(AudioTestCase,"USB")==0)
{
ConnectAudioToUsb();
}
else if ((strncmp(AudioTestCase,"R-",2)==0) || (strncmp(AudioTestCase,"L-",2)==0))
{
#if (ENABLE_CODEC == 1)
if (strcmp(MainAudioSoundPath,"MIC")==0)
{
LE_INFO(
"Connect MIC and SPEAKER ");
ConnectAudioToCodec();
}
else
#endif
if (strcmp(MainAudioSoundPath,"PCM")==0)
{
ConnectAudioToPcm();
}
else if (strcmp(MainAudioSoundPath,"I2S")==0)
{
ConnectAudioToI2s();
}
else if (strcmp(MainAudioSoundPath,"USB")==0)
{
ConnectAudioToUsb();
}
else
{
}
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
{
}
}
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;
}
close(AudioFileFd);
}
static void MyCallEventHandler
(
void* contextPtr
)
{
{
LE_INFO(
"Call event is LE_MCC_EVENT_ALERTING.");
}
{
LE_INFO(
"Call event is LE_MCC_EVENT_CONNECTED.");
}
{
LE_INFO(
"Call event is LE_MCC_EVENT_TERMINATED.");
switch(term)
{
LE_INFO(
"Termination reason is LE_MCC_TERM_NETWORK_FAIL");
break;
LE_INFO(
"Termination reason is LE_MCC_TERM_UNASSIGNED_NUMBER");
break;
LE_INFO(
"Termination reason is LE_MCC_TERM_USER_BUSY");
break;
LE_INFO(
"Termination reason is LE_MCC_TERM_LOCAL_ENDED");
break;
LE_INFO(
"Termination reason is LE_MCC_TERM_REMOTE_ENDED");
break;
LE_INFO(
"Termination reason is LE_MCC_TERM_UNDEFINED");
break;
default:
LE_INFO(
"Termination reason is %d", term);
break;
}
DisconnectAllAudio();
}
{
LE_INFO(
"Call event is LE_MCC_EVENT_INCOMING.");
if (res != LE_OK)
{
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:",
#if (ENABLE_CODEC == 1)
" - MIC (for mic/speaker)",
#endif
" - PCM (for devkit's codec use, execute 'wm8940_demo --pcm' command)",
" - I2S (for 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)",
#if (ENABLE_CODEC == 1)
" - MIC (for mic/speaker)",
#endif
" - PCM (for devkit's codec use, execute 'wm8940_demo --pcm' command)",
" - I2S (for 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) ========");
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);
}
}