亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? voip.c

?? 基于實時嵌入式系統的voip系統(real time embeded system)。主要難點在實時處理語音信號。語音信號基于其自身特點
?? C
?? 第 1 頁 / 共 2 頁
字號:
/**************************************************************************
*  voip.c - Main real time code for VOIP final project.
*
*  Author - Ed Hursey
*  Date - December 2005
*
*  Description - This file includes tasks for recording
*     and playing audio.  Tasks for sending and
*     receiving messages (audio) across a netowrk.
*     Tasks for encrypting and decrypting the audio.
*     It also has the main start up function and utility
*     functions for running the code.
*
*  Instructions:
*     1. To start voip, run startVoip(machineIndex), where
*        machineIndex can either be 1 or 2 for a 2 system
*        voip setup.  Index 1 corresponds to the machine
*        that has server1IP below and Index 2 corresponds
*        to the machine that has server2IP below.
*     2. To switch modes (i.e. from 8-bit mono (1) to 8-bit stereo (2)
*        to 16-bit stereo (3) use the switchMode(mode) function.
*        Pass in the mode number (1,2, or 3).  This only needs
*        run on one machine and the other machine will
*        automatically switch modes.  The code starts up by
*        default in 8-bit mono mode.
*     3. To stop VOIP call stopVOIP().
*     4. After calling stop, don't call startVOIP again (the
*        card can't be re-initialized that way.  Instead call
*        resumeVOIP().
*     5. To stop encryption (to prove that encrypt/decrypt are
*        working set enable_encryption to 0.  To stop decryption
*        set enable_decryption to 0.  This doesn't switch the other
*        machinie automatically because I wanted to prove that
*        the audio was being encrypted/decrypted.
**************************************************************************/
#include "voip.h"
#include "cs4281Registers.h"

extern STATUS udpServer (void);

/*semaphores for task and buffer syncronization*/
SEM_ID SEM_OK_TRANSMIT,SEM_ENCRYPT,SEM_DECRYPTED;

/*task loop control variables*/
int enable_play = 1;
int enable_record = 1;
int enable_transmit = 1;
int enable_encryption_task = 1;
int enable_decryption_task = 1;
int enable_encryption = 1;
int enable_decryption = 1;

/*server IP addresses so we know where to send packets*/
char* server1IP = "10.0.1.27";
char* server2IP = "10.0.1.28";
char* transmitToIp = "10.0.1.27";

/*variables used to determine when we missed a packet*/
int transmit_sync_packet_number = 0;
int recieve_sync_packet_number = 0;
int lost_packet = 0;
int first_packet = 1;

/*rc4 encryption/decription key stuff*/
rc4_key encrypt_key;
rc4_key decrypt_key;
unsigned char rc4_key_data[RC4_KEY_DATA_LEN] = {23,82,107,6,35,78,88,7};

/**************************************************************************
*   Function - getRecordBufferTask
*   Parameters - none
*   Returns - void
*   Purpose - Records audio.
*	   Task that loops as long as enable_record = 1.
*      Waits for SEM_DMA_Record semaphore, which is given when DMA1 (ADC)
*      buffer is half full or all the way full.  Then moves appropriate
*      half of DMA buffer to transmitRequest.message and signfies that
*      data is available to be encrypted (i.e. does a semGive of
*      SEM_ENCRYPT semaphore).
/**************************************************************************/
void getRecordBufferTask()
{
   while(enable_record)
   {
      /*wait for DMA1 buffer to have data*/
      semTake(SEM_DMA_Record, WAIT_FOREVER);

	  /*which part of the buffer to move? TC (second half), HTC (first half)*/
      if(DTC_DMA_Record)
        memmove(transmitRequest.message,ADC_BUFFER+ADC_BUFFER_SIZE/2, ADC_BUFFER_SIZE/2);
      else
        memmove(transmitRequest.message,ADC_BUFFER, ADC_BUFFER_SIZE/2);

      /*do encryption*/
      semGive(SEM_ENCRYPT);
   }
}

/**************************************************************************
*   Function - encryptionTask
*   Parameters - none
*   Returns - void
*   Purpose - Encrypts audio.
*	   Task that loops as long as enable_encryption_task = 1.
*      It should be noted that encryption can be shutoff
*      (set enable_encryption = 0) without shuting down the encryption
*      task.  Waits for SEM_ENCRYPT semaphore, which is given after
*      data has been moved from the DMA1 buffer to transmitRequest.message
*      It then encrypts the audio and signifies that data is ready to be
*      transmitted (i.e does a semGive of SEM_OK_TRANSMIT).
/**************************************************************************/
void encryptionTask()
{
   while(enable_encryption_task)
   {
      /*wait for data to be ready to encrypt*/
      semTake(SEM_ENCRYPT, WAIT_FOREVER);

      /*have ability not to encrypt so can hear non encrypted value*/
      if(enable_encryption)
      {
         /*get a local copy of the rc4 key*/
         encrypt_key.x = perm_key.x;
         encrypt_key.y = perm_key.y;
         memmove(encrypt_key.state,perm_key.state, 256);
         rc4_crypt(&encrypt_key,transmitRequest.message,transmitRequest.message,REQUEST_MSG_SIZE);
      }

      /*now do a semGive to signfy that the buffer can be transmitted*/
      semGive(SEM_OK_TRANSMIT);
   }
}

/**************************************************************************
*   Function - decryptionTask
*   Parameters - none
*   Returns - void
*   Purpose - Decrypts audio.
*	   Task that loops as long as enable_decryption_task = 1.
*      It should be noted that decryption can be shutoff
*      (set enable_decryption = 0) without shuting down the decryption
*      task.  Waits for SEM_RECEIVED semaphore, which is given after
*      the udpServer has receivied a new packet.
*      It then decrypts the audio and signifies that data is ready to be
*      played (i.e does a semGive of SEM_DECRYPTED).
/**************************************************************************/
void decryptionTask()
{
   while(enable_decryption_task)
   {
      /*wait until udpServer has something to decrypt*/
      semTake(SEM_RECEIVED, WAIT_FOREVER);

      /*have ability not to decrypt so can hear non decrypted value*/
      if(enable_decryption)
      {
         /*get a local copy of the rc4 key*/
         decrypt_key.x = perm_key.x;
         decrypt_key.y = perm_key.y;
         memmove(decrypt_key.state,perm_key.state, 256);
         rc4_crypt(&decrypt_key,receivedRequest.message,receivedRequest.message,REQUEST_MSG_SIZE);
      }

      /*tell play that something has been decrypted and can be played*/
      semGive(SEM_DECRYPTED);
   }
}

/**************************************************************************
*   Function - setPlayBufferTask
*   Parameters - none
*   Returns - void
*   Purpose - Plays audio.
*	   Task that loops as long as enable_play = 1.
*      Waits for SEM_DECRYPTED semaphore, which is given when receivied
*      data has been decrypted.  Then waits for the play buffer to signify
*      that it has room for more data (i.e. SEM_DMA_PLAYBACK).
*      It then checks the received message to make sure the packet number
*      is the packet we are expecting.  If it is not then we play the old
*      buffer again (this is mainly done so that undecrypted audio doesn't
*      get played which would cause an awful noise in the speaker).
*      Then moves receivedRequest.message to the appropriate half of the
*      DMA buffer.
/**************************************************************************/
void setPlayBufferTask()
{
   while(enable_play)
   {
      /*wait until buffer has been decrypted*/
      semTake(SEM_DECRYPTED, WAIT_FOREVER);


      /*also must wait until play buffer has room for us to put data */
      semTake(SEM_DMA_Playback, WAIT_FOREVER);

      /*increment packet number so we know if this packet is the one we
      were expecting*/
      recieve_sync_packet_number++;

	  /*sync the numbers the first time we get a packet*/
      if( first_packet == 1 )
      {
         recieve_sync_packet_number = receivedRequest.message_number;
         first_packet = 0;
      }

      /*make sure packet number is what we think it should be*/
      if( recieve_sync_packet_number != receivedRequest.message_number )
		{
			logMsg("Must have lost a packet\n");
			lost_packet = 1;
			/*resync packet numbers so that we aren't off for the rest of time*/
			recieve_sync_packet_number = receivedRequest.message_number;
		}

		/*if lost packet, don't move into buffer because it could be encrypted which would cause static*/
		if( lost_packet )
		{
			lost_packet=0;
		}
		else
		{
			/*which part of the buffer to right to? TC (second half), HTC (first half)*/
			if(DTC_DMA_Playback)
				memmove(DAC_BUFFER+DAC_BUFFER_SIZE/2, receivedRequest.message, DAC_BUFFER_SIZE/2);
			else
				memmove(DAC_BUFFER, receivedRequest.message, DAC_BUFFER_SIZE/2);
		}
   }
}

/**************************************************************************
*   Function - transmitTask
*   Parameters - none
*   Returns - void
*   Purpose - Builds a request object and transmits it to another machine.
*	    Task that loops as long as enable_transmit = 1.
*      Waits for SEM_OK_TRANSMIT semaphore, which is given when after
*      audion has been encrypted.  Calls the udp client so it can send
*      a message.
/**************************************************************************/
void transmitTask()
{
   while(enable_transmit)
   {
      semTake(SEM_OK_TRANSMIT, WAIT_FOREVER);

      /*set the display to 1, this is no longer used, it was used for debugging
      at first, then a 1 meant to display debugging info on the receivied side*/
		transmitRequest.display = 1;

		/*we increment the packet number each time we send a message so that
		we can tell on the receivied side if we miss a message*/
		transmit_sync_packet_number++;
		transmitRequest.message_number = transmit_sync_packet_number;

		/*we set the request type to 3, which means it is an audio message,
		other types of messages can be used to perform other features*/
		transmitRequest.request_type = 3;

		/*we set the mode to the current mode (8-bit mono, 8-bit stereo
		or 16-bit stereo so the receiving side knows if it has to change
		modes to play the data*/
		transmitRequest.mode = current_mode;

		/*send the message*/
      udpSendRequest();
   }
}

/**************************************************************************

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
日本道在线观看一区二区| 亚洲国产高清在线观看视频| 精品国产露脸精彩对白| 亚洲欧美日韩综合aⅴ视频| 免费高清在线视频一区·| 99久久精品费精品国产一区二区 | 亚洲精品免费看| 精品中文字幕一区二区小辣椒| 成人av在线电影| 欧美大片在线观看| 亚洲综合激情另类小说区| 国产成人免费视频网站| 日韩一区二区在线观看视频| 一区二区三区不卡在线观看| 国产成人亚洲综合a∨猫咪| 91精品婷婷国产综合久久性色| 专区另类欧美日韩| 成人综合婷婷国产精品久久蜜臀 | 国产成人精品aa毛片| 日韩一级完整毛片| 亚洲一区二区在线免费看| gogo大胆日本视频一区| 久久午夜免费电影| 日本欧美韩国一区三区| 欧美日韩三级视频| 一区二区三区电影在线播| 成人97人人超碰人人99| 国产欧美日韩精品在线| 国产一区二区影院| 精品国精品国产| 精品一区二区三区久久| 日韩视频在线你懂得| 日韩专区在线视频| 欧美日韩aaa| 亚洲成a人v欧美综合天堂| 色哟哟在线观看一区二区三区| 国产精品久久久久精k8| 成人av小说网| 亚洲人成在线观看一区二区| 91视频在线看| 一区二区国产视频| 欧美无人高清视频在线观看| 一区二区三区四区精品在线视频| 91视频国产观看| 一区二区三区丝袜| 91国偷自产一区二区开放时间| 一区二区三区四区国产精品| 欧美在线制服丝袜| 天天综合色天天| 欧美成人三级在线| 国产成人啪免费观看软件| 日本一区二区动态图| 99精品久久久久久| 亚洲超丰满肉感bbw| 欧美高清hd18日本| 韩国毛片一区二区三区| 国产亚洲一区二区在线观看| aaa欧美大片| 亚洲国产精品麻豆| 精品日产卡一卡二卡麻豆| 国产成人免费av在线| 亚洲视频一区在线观看| 欧美肥胖老妇做爰| 国产激情一区二区三区四区| 中文字幕一区二区不卡| 欧美区在线观看| 国产成人在线网站| 一个色在线综合| 精品国产乱码久久久久久久久| 国产成人免费网站| 亚洲电影欧美电影有声小说| 精品久久久久久久久久久久包黑料| 国产福利电影一区二区三区| 一区二区在线观看视频| 日韩精品专区在线影院重磅| 99国产精品久久久| 美女一区二区久久| 亚洲麻豆国产自偷在线| 精品日韩av一区二区| 色综合中文字幕| 精品一区二区在线播放| 一区二区不卡在线播放| 国产亚洲一区二区在线观看| 久久久久一区二区三区四区| 99久久99久久免费精品蜜臀| 免费精品视频最新在线| 亚洲手机成人高清视频| 久久午夜免费电影| 欧美日韩大陆在线| 99精品在线观看视频| 激情成人综合网| 亚洲一区二区免费视频| 国产免费观看久久| 日韩欧美一二区| 欧美日韩亚洲高清一区二区| 成人av电影在线播放| 国产美女精品人人做人人爽| 亚洲6080在线| 一区二区三区**美女毛片| 亚洲国产经典视频| 精品久久久久一区| 91.com视频| 欧美日本在线播放| 色视频欧美一区二区三区| 成人黄动漫网站免费app| 狠狠色狠狠色综合系列| 免费精品视频最新在线| 午夜视频一区在线观看| 亚洲一卡二卡三卡四卡五卡| 日韩理论在线观看| 中文字幕一区二区三区不卡| 欧美国产综合色视频| 久久精品欧美日韩| 久久精品一区二区| 久久久www免费人成精品| 日韩一级成人av| 欧美成人性福生活免费看| 91精品啪在线观看国产60岁| 欧美喷水一区二区| 欧美日韩亚洲综合在线 | 国产欧美精品在线观看| 久久久综合激的五月天| 精品成人一区二区三区| 精品剧情在线观看| 精品国产乱码久久| 久久亚洲春色中文字幕久久久| 日韩欧美一区二区不卡| 亚洲色图.com| 国产精品第13页| 亚洲精品亚洲人成人网在线播放| 亚洲女人的天堂| 亚洲成人在线免费| 麻豆精品久久久| 国产真实乱对白精彩久久| 成人免费视频视频| 99久久久久久| 欧美视频在线一区| 日韩午夜激情免费电影| 久久这里只有精品6| 国产精品麻豆视频| 亚洲精品伦理在线| 奇米色一区二区三区四区| 捆绑紧缚一区二区三区视频| 国产一区二区0| 99久久夜色精品国产网站| 欧美丝袜第三区| 欧美电影免费观看完整版| 久久精品视频一区二区| 亚洲欧洲制服丝袜| 七七婷婷婷婷精品国产| 国产在线看一区| 成人精品国产一区二区4080| 在线亚洲高清视频| 欧美一区二区视频观看视频| 久久奇米777| 一区二区成人在线视频| 激情五月播播久久久精品| 粉嫩av一区二区三区在线播放| 91免费观看在线| 欧美mv和日韩mv的网站| 亚洲色图.com| 日韩国产一二三区| 成人av中文字幕| 欧美一级一级性生活免费录像| 欧美国产精品一区| 日产欧产美韩系列久久99| 成人av电影在线网| 日韩亚洲欧美在线观看| 亚洲欧洲日韩女同| 图片区小说区国产精品视频| 国产精品 欧美精品| 欧美日本高清视频在线观看| 国产精品丝袜久久久久久app| 亚洲一区二区三区四区中文字幕| 韩国v欧美v亚洲v日本v| 欧美日韩一级片网站| 国产亚洲综合av| 人人超碰91尤物精品国产| 色哟哟一区二区在线观看| 久久久噜噜噜久久中文字幕色伊伊| 亚洲一区二区三区视频在线 | 一级精品视频在线观看宜春院| 久久精品国产一区二区| 在线日韩av片| 中文字幕一区二区三区四区不卡| 激情五月婷婷综合| 欧美一级理论片| 五月激情综合色| 在线观看国产日韩| 亚洲视频免费观看| 成人黄色777网| 国产欧美日韩三级| 久久成人免费日本黄色| 欧美一区二区免费| 亚洲mv在线观看| 欧美视频一区二区三区四区 | 欧美国产精品久久| 国产一区不卡精品| 欧美精品一区二| 国产一区二区福利视频|