void *audio_rec(void *data)
{
//unsigned int i;
unsigned int reclen;
//short recpcm[AUDIOBLK/2];
while(1)
{
if(recbuf.len <NMAX)
{
pthread_mutex_lock(&rec_lock);
reclen = Dsp_Read(devfd, recbuf.buffer+recbuf.iput, AUDIOBLK);
//if((recbuf.iput + AUDIOBLK) >= NMAX)
//。。。
sem_post(&recsem);
pthread_mutex_unlock(&rec_lock);
}
}
}
void *audio_send(void *data)
{
unsigned int i;
unsigned int nBlock = 0;
unsigned char sendbuf[AUDIOBLK];
unsigned int ToAddrLen = sizeof(ToAddr);
while(1)
{
sem_wait(&recsem);
pthread_mutex_lock(&rec_lock);
nBlock = recbuf.len/AUDIOBLK;
for(i=0; i<nBlock; i++)
{
MyEncode(recbuf.buffer+recbuf.iget, sendbuf, AUDIOBLK);
//。。。
sendto(sockfd, sendbuf, AUDIOBLK/2, 0, (struct sockaddr *)&ToAddr, ToAddrLen);
}
pthread_mutex_unlock(&rec_lock);
}
}
void *audio_receive(void *data)
{
unsigned recvLen = 0;
unsigned char recvBuf[NMAX/2];
int RemoteAddrLen = sizeof(RemoteAddr);
while(1)
{
pthread_mutex_lock(&play_lock);
recvLen = recvfrom(sockfd, recvBuf, sizeof(recvBuf), 0, (struct sockaddr *)&RemoteAddr, &RemoteAddrLen);
MyDecode(recvBuf, playbuf.buffer + playbuf.iput, recvLen);
//。。。
sem_post(&playsem);
pthread_mutex_unlock(&play_lock);
}
}
void *audio_play(void *data)
{
unsigned int i;
unsigned int nBlock = 0;
while(1)
{
sem_wait(&playsem);
pthread_mutex_lock(&play_lock);
nBlock = playbuf.len/AUDIOBLK;
for(i=0; i<nBlock; i++)
{
Dsp_Write(devfd, playbuf.buffer+playbuf.iget, AUDIOBLK);
//。。。
}
pthread_mutex_unlock(&play_lock);
}
}
|