inter2.c
上传用户:sy_wanhua
上传日期:2013-07-25
资源大小:3048k
文件大小:3k
- #include <sys/types.h>
- #include <stdio.h>
- #include <stdlib.h>
- #include <strings.h>
- #include <sys/ioctl.h>
- #include <unistd.h>
- #include <fcntl.h>
- #include <asm/errno.h>
- #include "ixjuser.h"
- void closeall(void);
- int ixj1, ixj2;
- int main(int argc, char *argv[])
- {
- char pname1[80], pname2[80], buff1[480], buff2[480];
- unsigned long cnt, write1, write2;
- int size, codec, len, depth;
- sprintf(pname1, "/dev/ixj%s", argv[1]);
- sprintf(pname2, "/dev/ixj%s", argv[2]);
- ixj1 = open(pname1, O_RDWR);
- ixj2 = open(pname2, O_RDWR);
- atexit(closeall);
- if(!ioctl(ixj1, IXJCTL_RING))
- {
- exit(0);
- }
- if(!ioctl(ixj2, IXJCTL_RING))
- {
- exit(0);
- }
- codec = atoi(argv[3]);
- switch(codec)
- {
- case G723_63:
- len = 24;
- break;
- case G723_53:
- len = 20;
- break;
- case TS85:
- len = 32;
- break;
- case TS48:
- len = 18;
- break;
- case TS41:
- len = 16;
- break;
- case G728:
- len = 96;
- break;
- case G729:
- len = 36;
- break;
- case ULAW:
- len = 240;
- break;
- case ALAW:
- len = 240;
- break;
- case LINEAR16:
- len = 480;
- break;
- case LINEAR8:
- len = 240;
- break;
- case WSS:
- len = 240;
- break;
- }
- cnt = write1 = write2 = 0;
- if(argc >= 5)
- {
- depth = atoi(argv[4]);
- ioctl(ixj1, IXJCTL_PLAY_DEPTH, depth);
- ioctl(ixj1, IXJCTL_REC_DEPTH, depth);
- ioctl(ixj2, IXJCTL_PLAY_DEPTH, depth);
- ioctl(ixj2, IXJCTL_REC_DEPTH, depth);
- }
- ioctl(ixj1, IXJCTL_PLAY_CODEC, codec);
- ioctl(ixj1, IXJCTL_REC_CODEC, codec);
- ioctl(ixj2, IXJCTL_PLAY_CODEC, codec);
- ioctl(ixj2, IXJCTL_REC_CODEC, codec);
- ioctl(ixj1, IXJCTL_PLAY_START);
- ioctl(ixj2, IXJCTL_REC_START);
- ioctl(ixj2, IXJCTL_PLAY_START);
- ioctl(ixj1, IXJCTL_REC_START);
- // for(cnt=0;cnt < 655000;cnt++)
- while(ioctl(ixj1, IXJCTL_HOOKSTATE) && ioctl(ixj2, IXJCTL_HOOKSTATE))
- {
- if(write1 == 500)
- {
- ioctl(ixj1, IXJCTL_AEC_START);
- ioctl(ixj2, IXJCTL_AEC_START);
- printf("AEC On.n");
- }
- size = read(ixj1, buff1, len);
- if(size > 0)
- {
- write(ixj2, buff1, len);
- write1++;
- }
- size = read(ixj2, buff2, len);
- if(size > 0)
- {
- write(ixj1, buff2, len);
- write2++;
- }
- }
- printf("Write1 = %ld, Write2 = %ldn",write1,write2);
- getchar();
- }
- void closeall(void)
- {
- ioctl(ixj1, IXJCTL_REC_STOP);
- ioctl(ixj1, IXJCTL_PLAY_STOP);
- ioctl(ixj2, IXJCTL_REC_STOP);
- ioctl(ixj2, IXJCTL_PLAY_STOP);
- ioctl(ixj1, IXJCTL_AEC_STOP);
- ioctl(ixj2, IXJCTL_AEC_STOP);
- close(ixj1);
- close(ixj2);
- }