#include <stdio.h>
#include <pthread.h>
#include "interfaces.h"
static bool isIncoming=false;
static const char* DestinationNumber;
static const char* DtmfSendingCase;
static const char* DtmfString;
static uint32_t Duration;
static uint32_t Pause;
static void MyDtmfDetectorHandler1
(
char dtmf,
void* contextPtr
)
{
LE_INFO(
"MyDtmfDetectorHandler1 detects %c", dtmf);
}
static void MyDtmfDetectorHandler2
(
char dtmf,
void* contextPtr
)
{
LE_INFO(
"MyDtmfDetectorHandler2 detects %c", dtmf);
}
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 DisconnectAllAudio
(
void
)
{
if (DtmfHandlerRef1)
{
LE_INFO(
"delete DTMF handler 1\n");
DtmfHandlerRef1 = NULL;
sleep(1);
}
if (DtmfHandlerRef2)
{
LE_INFO(
"delete DTMF handler 2\n");
DtmfHandlerRef2 = NULL;
}
if (AudioInputConnectorRef)
{
if (FeInRef)
{
LE_INFO(
"Disconnect %p from connector.%p", FeInRef, AudioInputConnectorRef);
}
if(MdmTxAudioRef)
{
LE_INFO(
"Disconnect %p from connector.%p", MdmTxAudioRef, AudioInputConnectorRef);
}
if(PlayerAudioRef)
{
LE_INFO(
"Disconnect %p from connector.%p", PlayerAudioRef, AudioInputConnectorRef);
}
}
if(AudioOutputConnectorRef)
{
if(FeOutRef)
{
LE_INFO(
"Disconnect %p from connector.%p", FeOutRef, AudioOutputConnectorRef);
}
if(MdmRxAudioRef)
{
LE_INFO(
"Disconnect %p from connector.%p", MdmRxAudioRef, AudioOutputConnectorRef);
}
if(PlayerAudioRef)
{
LE_INFO(
"Disconnect %p from connector.%p", PlayerAudioRef, AudioOutputConnectorRef);
}
}
if(AudioInputConnectorRef)
{
AudioInputConnectorRef = NULL;
}
if(AudioOutputConnectorRef)
{
AudioOutputConnectorRef = NULL;
}
if(FeInRef)
{
FeInRef = NULL;
}
if(FeOutRef)
{
FeOutRef = NULL;
}
if(MdmRxAudioRef)
{
FeOutRef = NULL;
}
if(MdmTxAudioRef)
{
FeOutRef = NULL;
}
if(PlayerAudioRef)
{
PlayerAudioRef = NULL;
}
}
static void MyCallEventHandler
(
void* contextPtr
)
{
{
LE_INFO(
"Call event is LE_MCC_EVENT_ALERTING.");
}
{
LE_INFO(
"Call event is LE_MCC_EVENT_CONNECTED.");
if (strcmp(DtmfSendingCase,"inband")==0)
{
LE_ERROR_IF((PlayerAudioRef==NULL),
"OpenPlayer returns NULL!");
if (PlayerAudioRef && AudioInputConnectorRef)
{
if(res != LE_OK)
{
LE_ERROR(
"Failed to connect Player on input connector!");
return;
}
if(res != LE_OK)
{
return;
}
}
}
else if (strcmp(DtmfSendingCase,"outband")==0)
{
if(res != LE_OK)
{
LE_ERROR(
"Failed to play signalling DTMF!");
return;
}
}
}
{
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();
exit(0);
}
{
LE_INFO(
"Call event is LE_MCC_EVENT_INCOMING.");
isIncoming=true;
if (res != LE_OK)
{
LE_INFO(
"Failed to answer the call.");
}
}
else
{
}
}
static void PlayLocalDtmf
(
void
)
{
#if (ENABLE_CODEC == 1)
LE_ERROR_IF((FeOutRef==NULL),
"OpenSpeaker returns NULL!");
#else
LE_INFO(
"Play DTMF on PCM output interface");
LE_ERROR_IF((FeOutRef==NULL),
"OpenPcmTx returns NULL!");
#endif
LE_ERROR_IF((AudioOutputConnectorRef==NULL),
"AudioOutputConnectorRef is NULL!");
{
LE_ERROR_IF((res!=LE_OK),
"Failed to connect Speaker on Output connector!");
}
LE_ERROR_IF((PlayerAudioRef==NULL),
"OpenPlayer returns NULL!");
if (PlayerAudioRef && AudioOutputConnectorRef)
{
if(res != LE_OK)
{
LE_ERROR(
"Failed to connect Player on output connector!");
return;
}
LE_INFO(
"Play DTMF on PlayerAudioRef.%p", PlayerAudioRef);
if(res != LE_OK)
{
return;
}
}
}
static void PrintUsage()
{
int idx;
bool sandboxed = (getuid() != 0);
const char * usagePtr[] = {
"Usage of the 'dtmfTest' app is:",
" execInApp dtmfTest dtmfTest <loc/rem> <dtmfs> <duration in ms> <pause in ms> "
"[<tel number> <inband/outband>] ",
"",
};
{
if(sandboxed)
{
}
else
{
fprintf(stderr, "%s\n", usagePtr[idx]);
}
}
}
static void SigHandler
(
int sigNum
)
{
DisconnectAllAudio();
if(TestCallRef)
{
}
exit(EXIT_SUCCESS);
}
{
bool isLocalTest = false;
signal(SIGINT, SigHandler);
{
LE_INFO(
" DTMF to play.\"%s\"", DtmfString);
LE_INFO(
" Duration.%dms", Duration);
LE_INFO(
" Phone number.%s", DestinationNumber);
LE_INFO(
" DTMF Sending case.%s", DtmfSendingCase);
}
{
{
LE_INFO(
" Play DTMF on local interface");
LE_INFO(
" DTMF to play.\"%s\"", DtmfString);
LE_INFO(
" Duration.%dms", Duration);
isLocalTest = true;
}
else
{
PrintUsage();
exit(EXIT_FAILURE);
}
}
else
{
PrintUsage();
exit(EXIT_FAILURE);
}
if (!isLocalTest)
{
ConnectAudioToPcm();
MyDtmfDetectorHandler1,
NULL);
MyDtmfDetectorHandler2,
NULL);
}
else
{
PlayLocalDtmf();
}
}