📄 ex05_01.cpp
字号:
acTBoardHandle BoardHandle = (acTBoardHandle)(unsigned long)arg;
acTChannelHandle ChannelHandle = -1;
char Packet[MAX_PACKET_LENGTH + 2];
int PacketLen;
acTPacketType PacketType;
unsigned char SeqNum;
while (!ExitPollingThread)
{
/*
* Poll all the queued packets that were received from the board
*/
while (acGetPacket(BoardHandle, &ChannelHandle, Packet, &PacketLen, &PacketType, &SeqNum) != -1);
acSleep(10);
}
#if OS_TYPE==OS_WIN_NT
return 0;
#else
return arg;
#endif
} /* end of function exGetPacketThreadFunc */
/*******************************************************************/
/* Example Function: exTerminatePollingThreadsCallback(). */
/* */
/* This funcion terminates the polling events and packets Threads. */
/*******************************************************************/
void exTerminatePollingThreadsCallback(acTBoardHandle BoardHandle)
{
ExitPollingThread = TRUE;
} /* end of function exTerminatePollingThreadsCallback */
/****************************************************************************/
/* Example Function: exErrorHandler(). */
/* */
/* This funcion handles the Errors received from the board and the VoIPLib. */
/****************************************************************************/
void exErrorHandler(acTErrorMsgType ErrorMsgType,
acTErrorCode ErrorCode, acTBoardHandle BoardHandle, acTChannelHandle ChannelHandle, const char *Format, ...)
{
switch (ErrorMsgType)
{
case acFatalErrorMsg:
printf("Fatal error: ");
break;
case acRecoverableErrorMsg:
printf("Recoverable error: ");
break;
case acDbgMsg:
printf("Debug message: ");
break;
case acInfoMsg:
printf("Info message: ");
break;
default:
break;
}
char ErrStr[512];
va_list pArguments;
va_start(pArguments, Format);
vsprintf(ErrStr, Format, pArguments);
printf("%s. Error code: 0x%x. BoardHandle=%d, ChannelHandle=%d.\n", ErrStr, ErrorCode, BoardHandle, ChannelHandle);
} /* end of function exErrorHandler */
/*
* Channel openning related functions
*/
/********************************************/
/* Example Function: exOpenChannel(). */
/* */
/* Open a channel in PCI mode. */
/* The function returns the channel handle. */
/********************************************/
acTChannelHandle exOpenChannel(const acTBoardHandle BoardHandle)
{
acTExtChannelParam ChannelParam; /* Using acTChannelParam is not recommended, it is for backwards compatibility only */
acGetDefaultChannelParameters(BoardType, &ChannelParam);
ChannelParam.VoiceSettings.Coder = acG711Alaw_64; /* see acTCoders enum for more possible values */
ChannelParam.TDMBusSettings.TDMBusInputPort = 0; /* Trunk 0 */
ChannelParam.TDMBusSettings.TDMBusInputChannel = 1; /* BChannel 1 */
ChannelParam.TransportSettings.UseNIorPCI = 0; /* =1 if channel will use NI interface, =0 if PCI interface */
/*
* The PCI packets' transfer is enabled automatically during the playback.
*/
ChannelParam.TransportSettings.UniDirectionalPciMode = acPciInactive;
/*
* NOTE: Trunk and BChannel must only be specified when PSTN is used.
* In other cases the ChannelId parameter should be given.
*/
acTChannelHandle ChannelHandle = acOpenChannel(BoardHandle, -1 /* ChannelId */, &ChannelParam);
if (ChannelHandle == INVALID_CHANNEL_HANDLE)
exQuit("Failed to open channel.", 1);
else
printf("Channel handle=%d\n", ChannelHandle);
return ChannelHandle;
} /* end of function exOpenChannel */
/***************************************************/
/* Example Function: exCloseChannel(). */
/* */
/* Do all the necessary work to close the channel. */
/***************************************************/
void exCloseChannel(const acTChannelHandle ChannelHandle)
{
if (acCloseChannel(ChannelHandle) != 0)
exQuit("Close channel failed.", 1);
} /* end of function exCloseChannel */
/*
* Playing related functions
*/
/**************************************************/
/* Example Function: exPlay(). */
/* */
/* Play voice from file to the specified channel. */
/**************************************************/
void exPlay(const acTChannelHandle ChannelHandle)
{
char *play_file_name;
char InputFileName[256] = {"play_ALaw.pcm"};
char UserFileName[256];
#if OS_TYPE == OS_WIN_NT
play_file_name = exFindFile("play_ALaw.pcm", "Data");
#else
play_file_name = (char*) "play_ALaw.pcm";
#endif
if(play_file_name) {
strcpy(InputFileName, play_file_name);
printf("\nThe default play file name is %s. \n"
"Please, enter the input file name, or press Enter to leave \n"
"the default value unchanged. \n", InputFileName);
}
else {
printf("\nThe play file was not found. You have to use your own file \n"
"for playing. Please, enter your play file name. \n");
}
fflush(stdin);
fgets(UserFileName, 256, stdin);
if(strncmp(UserFileName, "\n", 1))
{
UserFileName[strlen(UserFileName)-1] = '\0';
strcpy(InputFileName, UserFileName);
}
acTPlayRecordParam PlayParams;
acGetDefaultPlayRecordParameters(&PlayParams);
PlayParams.PlayRecordTransferParam.PlayRecordTransferType = FILE_TRANSFER;
PlayParams.PlayRecordTransferParam.pFileName = InputFileName;
PlayParams.PlayRecordTransferParam.UserData = (void *)"test string";
PlayParams.PlayRecordCommonParam.FileCoder = acG711Alaw_64;
exContinue("You can hear the playing file through the phone, connected to the\n"
"the opened channel (Trunk 0, BChannel 1). Press Enter to start playing...\n");
if (acPlay(ChannelHandle, &PlayParams) != RESULT_SUCCESS)
exQuit("Play failed.", 1);
exContinue("Playing started. Press Enter to stop playing ...\n");
/*
* Stop playing.
*/
if (acStopPlay(ChannelHandle) == -1)
exQuit("Stop play failed.", 1);
acSleep(1000);
} /* end of function exPlay */
/****************************************************/
/* Example Function: exProceedEvent(). */
/* */
/* This function handles the events from the board. */
/****************************************************/
void exProceedEvent(acTBoardHandle BoardHandle, acTEventInfo & EventInfo, acTChannelHandle ChannelHandle, int EventType )
{
/*
* In this example, the switch handles only a limited number of events.
* User should define here all relevant events for his/her application.
*/
switch (EventType)
{
case acEV_MESSAGE_LOG:
printf("\nacEV_MESSAGE_LOG: \n"
"ErrorCode=%d, Origin=%d, Severity=%d, Param1(Trunk)=%d, Param2(BCh)=%d\n"
"Param3(ConnID)=%d, Param4=%d, File: Filename=%s/%d, \n"
"Message='%s', BoardHandle=%d.\n\n",
EventInfo.MessageReport.ErrorCode ,
EventInfo.MessageReport.ModuleOrigin,
EventInfo.MessageReport.Severity,
EventInfo.MessageReport.OriginAddr.OtherAddr.param1,
EventInfo.MessageReport.OriginAddr.OtherAddr.param2,
EventInfo.MessageReport.OriginAddr.OtherAddr.param3,
EventInfo.MessageReport.OriginAddr.OtherAddr.param4,
EventInfo.MessageReport.FileName,
EventInfo.MessageReport.LineInFile,
EventInfo.MessageReport.Message,
BoardHandle
);
break;
case acEV_PLAY_BUFFER_PROCESSED:
printf("\nacEV_PLAY_BUFFER_PROCESSED:\nChannelHandle=%d, "
"TransferType=%d, Offset=%d, UserData=%s, "
"BytesProcessed=%d, TerminationCause=%d.\n",
ChannelHandle,
EventInfo.IVREventInfo.TransferType,
EventInfo.IVREventInfo.Offset,
(char *)EventInfo.IVREventInfo.UserData,
EventInfo.IVREventInfo.BytesProcessed,
EventInfo.IVREventInfo.TerminationCause);
break;
case acEV_PLAY_TERMINATED:
printf("\nacEV_PLAY_TERMINATED:\nChannelHandle=%d, "
"TransferType=%d, Offset=%d, UserData=%s, "
"BytesProcessed=%d, TerminationCause=%d.\n",
ChannelHandle,
EventInfo.IVREventInfo.TransferType,
EventInfo.IVREventInfo.Offset,
(char *)EventInfo.IVREventInfo.UserData,
EventInfo.IVREventInfo.BytesProcessed,
EventInfo.IVREventInfo.TerminationCause);
break;
/*
* Disable output for some frequent events.
*/
case acEV_RTCP:
case acEV_RTCPXR_REPORT_SENT:
case acEV_RTCPXR_REPORT_RECEIVED:
break;
default:
printf("\nEvent '%s' was received.\n", acGetEventName((acTEvent) EventType));
}
return;
}
/*************************************************************************/
/* Example function: exPrintNumBoardsVec(). */
/* */
/* This function prints NumBoardsVec[] array and number of found boards. */
/*************************************************************************/
void exPrintNumBoardsVec(int *NumBoardsVec, int BoardsNumber)
{
printf("The %d local PCI boards was found: [ ", BoardsNumber);
for (int i = 0; i < MAX_TP_BOARD_TYPES; i++)
printf("%d ", *(NumBoardsVec + i));
printf("]\n");
}
#if OS_TYPE == OS_WIN_NT
char *exFindFile(char *filename, char *dirname)
{
struct _finddata_t c_file;
long rc;
static char full_file_name[256];
char current_dir[256];
char relative_pass[256];
char file_dir[256];
char parent_dir[256];
char *prev;
memset(relative_pass,0,256);
int i,j;
/* save the current directory */
if(_getcwd(current_dir,256) == NULL)
return NULL;
/* check the current directory */
if( (rc = _findfirst( filename, &c_file )) != -1L ) {
strcpy(full_file_name, filename);
return full_file_name;
}
/* try to find the file directory */
sprintf(file_dir, "%s\\%s", current_dir, dirname);
if(_chdir(file_dir) != -1) {
/* succeeded to find the file directory, check it */
if( (rc = _findfirst( filename, &c_file )) != -1L ) {
sprintf(full_file_name, "%s\\%s", file_dir, filename);
/* returning to the working directory */
if(_chdir(current_dir) == -1)
return NULL;
return full_file_name;
}
else if(_chdir(current_dir) == -1)
return NULL;
}
/* checking four up-level directories */
for(i=1;i<=4;i++)
{
/* save the current directory */
if(_getcwd(parent_dir,256) == NULL)
return NULL;
/* receiving the name of the parent directory */
prev = strrchr(parent_dir,'\\');
*prev = '\0';
/* going up one directory */
if(_chdir(parent_dir) == -1)
return NULL;
/* check the new directory */
if( (rc = _findfirst( filename, &c_file )) != -1L ) {
for(j=0;j<i;j++)
strcat(relative_pass,"..\\");
sprintf(full_file_name, "%s%s", relative_pass, filename);
/* returning to the working directory */
if(_chdir(current_dir) == -1)
return NULL;
return full_file_name;
}
/* try to find the file directory */
if(_getcwd(file_dir,256) == NULL)
return NULL;
strcat(file_dir, "\\");
strcat(file_dir, dirname);
if(_chdir(file_dir) != -1) {
/* succeeded to find the file directory, check it */
if( (rc = _findfirst( filename, &c_file )) != -1L ) {
for(j=0;j<i;j++)
strcat(relative_pass,"..\\");
sprintf(full_file_name, "%s%s\\%s", relative_pass, dirname, filename);
/* returning to the working directory */
if(_chdir(current_dir) == -1)
return NULL;
return full_file_name;
}
else if(_chdir(parent_dir) == -1)
return NULL;
}
}
/* file was not found */
return NULL;
}
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -