inter2.c
上传用户:sy_wanhua
上传日期:2013-07-25
资源大小:3048k
文件大小:5k
- #include <sys/types.h>
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <sys/ioctl.h>
- #include <unistd.h>
- #include <fcntl.h>
- #include <errno.h>
- #include "ixjuser.h"
- void closeall(void);
- void usage(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, frame, frame1, frame2;
- sprintf(pname1, "/dev/ixj%s", argv[1]);
- sprintf(pname2, "/dev/ixj%s", argv[2]);
- ixj1 = open(pname1, O_RDWR);
- if(ixj1 < 0)
- {
- printf("%s open failed %d %sn" ,pname1, ixj1, strerror(errno));
- exit(-1);
- }
- ixj2 = open(pname2, O_RDWR);
- if(ixj2 < 0)
- {
- printf("%s open failed %d %sn" ,pname2, ixj2, strerror(errno));
- exit(-1);
- }
- if(argc < 4)
- {
- usage();
- exit(-1);
- }
- if(argc >= 6)
- {
- frame = atoi(argv[5]);
- }
- else
- {
- frame = 30;
- }
- frame1 = ioctl(ixj1, IXJCTL_FRAME, frame);
- frame2 = ioctl(ixj2, IXJCTL_FRAME, frame);
- atexit(closeall);
- // ioctl(ixj1, IXJCTL_HZ, 300);
- // ioctl(ixj1, IXJCTL_RATE, 100);
- 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:
- switch(frame)
- {
- case 30:
- len = 240;
- break;
- case 20:
- len = 160;
- break;
- case 10:
- len = 80;
- break;
- }
- break;
- case ALAW:
- switch(frame)
- {
- case 30:
- len = 240;
- break;
- case 20:
- len = 160;
- break;
- case 10:
- len = 80;
- break;
- }
- break;
- case LINEAR16:
- switch(frame)
- {
- case 30:
- len = 480;
- break;
- case 20:
- len = 320;
- break;
- case 10:
- len = 160;
- break;
- }
- break;
- case LINEAR8:
- switch(frame)
- {
- case 30:
- len = 240;
- break;
- case 20:
- len = 160;
- break;
- case 10:
- len = 80;
- break;
- }
- break;
- case WSS:
- switch(frame)
- {
- case 30:
- len = 240;
- break;
- case 20:
- len = 160;
- break;
- case 10:
- len = 80;
- break;
- }
- 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);
- printf("Frame1 = %d, Frame2 = %d, len = %d, depth = %d, codec = %dn",
- frame1, frame2, len, depth, codec);
- fflush(stdout);
- ioctl(ixj1, IXJCTL_AEC_START);
- ioctl(ixj2, IXJCTL_AEC_START);
- printf("AEC On.n");
- while(ioctl(ixj1, IXJCTL_HOOKSTATE) && ioctl(ixj2, IXJCTL_HOOKSTATE))
- {
- size = read(ixj1, buff1, len);
- if(size > 0)
- {
- write(ixj2, buff1, size);
- write1++;
- }
- size = read(ixj2, buff2, len);
- if(size > 0)
- {
- write(ixj1, buff2, size);
- write2++;
- }
- }
- printf("Write1 = %ld, Write2 = %ldn",write1,write2);
- getchar();
- }
- void closeall(void)
- {
- ioctl(ixj1, IXJCTL_AEC_STOP);
- ioctl(ixj2, IXJCTL_AEC_STOP);
- ioctl(ixj1, IXJCTL_REC_STOP);
- ioctl(ixj1, IXJCTL_PLAY_STOP);
- ioctl(ixj2, IXJCTL_REC_STOP);
- ioctl(ixj2, IXJCTL_PLAY_STOP);
- printf("AEC Off.n");
- ioctl(ixj1, IXJCTL_DSP_IDLE);
- ioctl(ixj2, IXJCTL_DSP_IDLE);
- close(ixj1);
- close(ixj2);
- }
- void usage(void)
- {
- printf("inter2 card1 card2 codec depth framen");
- printf("tcard1 and card2 - 0 = /dev/ixj0, 1 = /dev/ixj1 etc.n");
- printf("tcodec 1 = g.723.1 6.3n");
- printf("t 2 = g.723.1 5.3n");
- printf("t 3 = TrueSpeech 8.5n");
- printf("t 4 = TrueSpeech 4.8n");
- printf("t 5 = TrueSpeech 4.1n");
- printf("t 6 = g.728n");
- printf("t 7 = g.729n");
- printf("t 8 = uLawn");
- printf("t 9 = aLawn");
- printf("t 10 = Linear 16 Bitn");
- printf("t 11 = Linear 8 Bitn");
- printf("t 12 = Windows Sound Systemn");
- printf("Optional arguments:n");
- printf("tdepth - DSP buffer depth in framesn");
- printf("tframe - 10 = 10ms, 20 = 20ms, 30 = 30msn");
- }