#include #include #include #include #include #include #include #include //#include "ipc-char-ioctls.h" #include #include #include #include #include typedef int int32; typedef unsigned int uint32; typedef char int8; typedef unsigned char uint8; #define SCO_CHUNK_SIZE 256 #define PRINT #define CAPTURE_ENABLED int uninit(int iIpcFd); int StartAudio(int iFragment, int iFormat); int StopAudio(); int ReadFromAlsa(void *buf, int len); int WriteToAlsa(void *buf, int len); //GSC3A_CREATE_MODULEID(OSA); int giIpcFd = -1; int giAudFd = -1; int ghUpstreamThread = 0; void usage() { printf("USAGE:\n\t "); printf("Example:\tipcsco-tester /dev/ipcttysco sine.wav"); } int iAudioFd = -1; void signal_handler(int sig) { switch(sig) { case SIGHUP: { }break; case SIGTERM: { if(iAudioFd>=0) { close(iAudioFd); } printf("Calling Uninit"); uninit(giIpcFd); printf("Exiting \n"); exit(0); }break; } } int StartPlaybackAndCapture(int ipcFD) { unsigned char acData[SCO_CHUNK_SIZE]; int iCount; int iCount123; printf("Start the while looop\n"); //iCount123 = WriteToAlsa(acData,SCO_CHUNK_SIZE); while(1) { #ifdef CAPTURE_ENABLED //gettimeofday(&start, &tz); //iCount = ReadFromAlsa(acData, SCO_CHUNK_SIZE); iCount = ReadFromAlsa(acData, SCO_CHUNK_SIZE); //printf("Written iCount\t%d\n", iCount); #else iCount = read(giAudFd,acData,SCO_CHUNK_SIZE); #endif if(iCount < 0) { printf("Read Error. %d\n", iCount); break; } else if(iCount == 0) { printf("Overflow state\n"); #ifndef CAPTURE_ENABLED lseek(giAudFd, 0, SEEK_SET); #endif continue; } { // iCount = 0; //printf(""); iCount = WriteToAlsa(acData,iCount); if (iCount < 0) { printf("Write Error : %d\n",iCount); break; } } } return 0; } int main(int argc, char *argv[]) { int iIpcFd = -1; if(argc < 2) { usage(); return -1; } else { printf("In Execution - [%s %s]\n", argv[0], argv[1]); } signal(SIGHUP,signal_handler); /* catch hangup signal */ signal(SIGTERM,signal_handler); /* catch kill signal */ StartAudio(SCO_CHUNK_SIZE, SND_PCM_FORMAT_S16_LE); #ifndef CAPTURE_ENABLED giAudFd = open(argv[2],O_RDONLY); if(giAudFd < 0) { printf("OPeing Audio file failed \n"); return -1; } #endif StartPlaybackAndCapture(iIpcFd); uninit(iIpcFd); return 0; } int uninit(int iIpcFd) { StopAudio(); #ifndef CAPTURE_ENABLED close(giAudFd); #endif return 0; }