⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ex05_01.cpp

📁 * 1. Run the Advanced Evaluation Board (AEB) Control software program * (Start>AudioCod
💻 CPP
📖 第 1 页 / 共 3 页
字号:
/*   Example:
 * 
 *   General:
 *   -------
 *   This example shows how to play voice data from a file to a TDM (PSTN) channel.
 * 
 *   In this case:
 * 
 *   *  The board is opened with FRAMERS (E1). 
 *      (To open the Framers in T1 or J1, refer to the code.)
 *   *  The board is opened and controlled via the PCI interface.
 *
 *   The executable file of this example can be found in the example directory.
 *
 *   Before executing the example (to execute, Build menu>Execute, or Ctrl+F5):
 *   -------------------------------------------------------------------------
 *   1. Run the Advanced Evaluation Board (AEB) Control software program 
 *      (Start>AudioCodes IPM-260 SDK>).
 *   2. Connect the Evaluation Board's E1 connector to the IPM-260's first E1         
 *      interface (E1 - 0), using the supplied cross connect E1 cable,                  
 *      according to the following scheme:               
 *                                          
 * 2.1. Switch position (if it is present):
 *
 *        MVIP        SC
 *   +---======------====-----+
 *   +-[\]--------------------+
 *   | The switch on the AEB  |  EB Side View
 *   | should point to the    |
 *   | left                   |
 *   +--+     +---------------+
 *      +-----+
 *
 * 2.2. E1 cable connection:
 *
 *   +-----------------------------------------+                                     
 *   |         E1/T1 Interfaces      | |  Net  |                                     
 *   |    +---+  +---+  +---+  +---+ |o|  ---  |                                     
 *   |    |E1 |  |E1 |  |E1 |  |E1 | |o| |ETH| |  IPM-260 Front Panel                
 *   |    |  3|  |  2|  |  1|  |  0| |o| |   | |                                     
 *   |     ---    ---    ---    ---  |o| +---+ |                                     
 *   +--------------------------/\-------------+                                     
 *                              ||                                                   
 *                              ||                                                   
 *                           E1 cable                                                
 *                              ||                                                   
 *                              ||                                                   
 *   +--------------------------\/-------------+                                     
 *   |    Telephone Interface `E1/T1  | | |    |                                     
 *   |     ---    ---    ---  `+---+  |o|o|    |                                     
 *   |    |Ln2|  |Ln1|  |Ln0| `|E1 |  |o|o|    |  EB Front Panel                 
 *   |    |   |  |   |  |   | `|   |  |o|o|    |                                     
 *   |    +---+  +---+  +---+ `o---o  |o|o|    |                                     
 *   +--------------------/\-------------------+                                     
 *                        ||                                                             
 *                        \/                                                         
 *                       ____                                                        
 *                       "/\"                                                    
 *                       /__\                                                        
 *                      Phone                                                        
 *                       #0                                                      
 *                                                                                   
 *   3. In the AEB Control software program, click 'Load Configuration Script' to load the file
 *      Ex05_01.ini.                                           
 * 
 *   Program steps:
 *   -------------
 *   1. Initializes the VoIP library. 
 * 
 *   2. Opens the board with the acOpenBoard() function. 
 *      acOpenBoard() returns a BoardHandle. 
 * 
 *   3. The program enters a loop waiting for the acEV_BOARD_STARTED event.
 * 
 *   NOTE: 
 * 
 *   *  When opening the board with the PSTN interface, the loop continues until 
 *      both acEV_BOARD_STARTED and then acEV_PSTN_STARTED events are received. 
 *   *  When opening the board with (SC, MVIP, H.100, the loop 
 *      continues until only the acEV_BOARD_STARTED event is received.
 * 
 *   4. Creates a thread that handles polling events from the board
 *      using the acGetEvent(BoardHandle,...) function. 
 * 
 *   5. Creates a thread that handles the polling of packets from the board
 *      using the acGetPacket(BoardHandle,....) function.
 * 
 *   6. Opens a channel for Playing - in this example, channel 0 (Trunk 0, BChannels 1). 
 *      The channel is opened in the G711Alaw_64 coder. 
 * 
 *   7. Plays the voice data into the channel (acPlay()).
 *      The file played is in the same coder the channel 
 *      was opened in (G711Alaw_64 in this case).
 *      
 *   NOTE:  
 *      
 *      If you don't have the file, use Example #2 (the recording example)
 *      to generate a similar one.
 * 
 *   8. Stops playing (acStopPlay()).
 *      Playing the file is stopped: 
 *      * Either the User stops it (using acStopPlay())
 *          or
 *      * The file ends (In this case, acStopPlay() is not required, but is allowed).
 * 
 *   NOTE:
 * 
 *      When playing stops, both acEV_PLAY_BUFFER_PROCESSED and acEV_PLAY_TERMINATED
 *      are received.
 * 
 *   9. Closes the channel (acCloseChannel()).
 *
 *   10 Closes the board (acCloseBoard()) and closes the VoPLib library (acCloseLib()).
 *
 *   Notes:
 *   -----
 *
 *   1. VoPLib API functions start with the prefix "ac"; for example, acInitLib().
 *   2. Example-specific functions start with prefix "ex"; for example, exUpdateBoardParams().
 */

#include "voplibapi.h"

#if OS_TYPE==OS_WIN_NT
    #include <process.h>            /* _beginthread(), _endthread() */
    #include <io.h>
    #include <direct.h>
#else
    #include <pthread.h>
#endif

/*
 * The implementation of the example functions is placed in the end of this file 
 */

/*
 * Open board/channel related functions.
 */
void exInitLib();
acTBoardHandle exOpenBoard();
acTChannelHandle exOpenChannel(const acTBoardHandle BoardHandle);
void exUpdateBoardParams(acTBoardParam * pBoardParam);
void exWaitForBoardStartedEvents(const acTBoardHandle BoardHandle);
void exCloseBoard(const acTBoardHandle BoardHandle);
void exCloseChannel(const acTChannelHandle ChannelHandle);
/*
 * Error/event related functions.
 */
void exErrorHandler(acTErrorMsgType ErrorMsgType,
                    acTErrorCode ErrorCode,
                    acTBoardHandle BoardHandle, acTChannelHandle ChannelHandle, const char *Format, ...);
void exProceedEvent(acTBoardHandle BoardHandle, acTEventInfo & EventInfo, acTChannelHandle ChannelHandle, int EventType);
/*
 * Event/packet thread related functions.
 */
void exBeginGetEventThread(const acTBoardHandle BoardHandle);
void exBeginGetPacketThread(const acTBoardHandle BoardHandle);
#if OS_TYPE==OS_WIN_NT
DWORD WINAPI exGetEventThreadFunc(void *arg);
DWORD WINAPI exGetPacketThreadFunc(void *arg);
#else
extern "C" void* exGetEventThreadFunc(void *arg);
extern "C" void* exGetPacketThreadFunc(void *arg);
#endif
void exTerminatePollingThreadsCallback(acTBoardHandle BoardHandle);
/*
 * Play related functions.
 */
void exPlay(const acTChannelHandle ChannelHandle);
/*
 * Help functions.
 */
void exPrintNumBoardsVec(int *NumBoardsVec, int BoardsNumber);
void exPrintMenu(); 
#if OS_TYPE==OS_WIN_NT
char *exFindFile(char *filename, char *dirname);
#endif
int exContinue(const char *Message = NULL);
void exQuit(const char *Message = NULL, int ExitCode = 0);
int exIPAddr2int(const char *IPaddr);

/*
 * Global Parameters 
 */

/*
 * In this example we demonstrate the use of IPM260 board. 
 * In case of other boards, user should change the BoardType 
 * For possible values see acTTrunkPackBoardType enum 
 * (For example: acTrunkPack260 for IPM260). 
 */
acTTrunkPackBoardType BoardType;
char ImageFileName[256];

/*
 * This parameter is used in order to notify the events and packets threads
 * to exit when the board is closed. 
 */
static BOOL ExitPollingThread = FALSE;

/*
 * These paramters are used to hold the board's threads handles. 
 */
#if OS_TYPE==OS_WIN_NT
static HANDLE EventsThreadHandle = NULL;
static HANDLE PacketsThreadHandle = NULL;
#else
static pthread_t EventsThreadHandle;
static pthread_t PacketsThreadHandle;
#endif

/*
 * Functions implementation 
 */

/*********************/
/*                   */
/* The Main Function */
/*                   */
/*********************/

int main(int argc, char **argv)
{
    printf("   EXAMPLE: HOW TO PLAY A VOICE DATA FROM A FILE TO A TDM (PSTN) CHANNEL      \n"
           "The following example is for one of the possible uses of the API's functions. \n"
           "The board is opened with FRAMERS (E1) and controled via the PCI interface.    \n"
           "User should connect the AEB board E1 connector with the IPM260 first E1       \n"
           "interface (E1 - 0), using the supplied cross connect E1 cable, according      \n"
           "to the scheme from the README.txt or from the source code.                    \n");

    exPrintMenu(); 

    /*
     * Do all the necessary work to initialize the VoPLib. 
     */
    exInitLib();

    /*
     * Do all the necessary work to open the board. 
     */
    acTBoardHandle BoardHandle = exOpenBoard();

    /*
     * Do all the necessary work to open the channel in PCI mode.
     * - When playing to the TDM side, the channel should be opened in PCI mode.
     * - When playing to the network side, the channel should be opened in NI mode. 
     */
    acTChannelHandle ChannelHandle = exOpenChannel(BoardHandle);

    /*
     * Play from a file. 
     */
    exPlay(ChannelHandle);

    /*
     * Do all the necessary work to close the channel. 
     */
    exCloseChannel(ChannelHandle);

    /*
     * Do all the necessary work to close the board. 
     */
    exCloseBoard(BoardHandle);

    exQuit();

    return 0;
}                               /* end of main */

/********************************************************/
/* Example Function: exPrintMenu().                     */
/*                                                      */
/* Function that initializes global variables           */
/* according to user's choice.                          */
/********************************************************/

void exPrintMenu()
{
	char command_line[128];
	int board_type;
	printf("\nPlease, enter the Board Type:"
		   "\n1 - acTrunkPack260,"
		   "\n2 - acTrunkPack260_UN.\n");
	memset(command_line, 0, 128);
	fflush(stdin);
	fgets(command_line, 128, stdin);
	board_type = atoi(command_line);

    if(board_type == 2)
    {
        BoardType = acTrunkPack260_UN;
        strcpy(ImageFileName, "ramIPM260_UN.cmp");
    }
    else
    {
        BoardType = acTrunkPack260;
        strcpy(ImageFileName, "ramIPM260.cmp");
    }
}

/********************************************************/
/* Example Function: exContinue().                      */
/*                                                      */
/* Function that prints message and continues.          */
/********************************************************/

int exContinue(const char *Message)
{
    char str[256];
    printf("\n%s", Message?Message:"");
    fflush(stdin);
    fgets(str, 256, stdin);
	if(isdigit((int)(*str)))
		return atoi(str);
	else
        return (int)(*str);
}

/********************************************************/
/* Example Function: exQuit().                          */
/*                                                      */
/* Function that prints error message and exits.        */
/********************************************************/

void exQuit(const char *Message, int ExitCode)
{
    char c;
    printf("\n%sPress 'q' and [Enter] to quit the example.\n", Message?Message:"");
    do
    {
        fflush(stdin);
        c = getchar();
    } 
    while(c!='q' && c!='Q');
	acCloseLib();
    exit(ExitCode);
}

/***********************************************************/
/* Example Function: exIPAddr2int().                       */
/*                                                         */
/* This function converts IP address (A.B.C.D) to integer. */
/***********************************************************/

int exIPAddr2int(const char *IPaddr)
{
    int ip1, ip2, ip3, ip4;
    sscanf(IPaddr, "%d.%d.%d.%d", &ip1, &ip2, &ip3, &ip4);
    return ( (ip1)<<24 | (ip2)<<16 | (ip3)<<8 | (ip4) );
}

/*****************************************************************/
/* Example Function: exInitLib().                                */
/*                                                               */
/* Do all the necessary work to initialize the VoP library.      */
/*****************************************************************/

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -