static int manage_calls(char *host) { newtComponent form; newtComponent quit; newtComponent hangup; newtComponent redirect; newtComponent channels; struct newtExitStruct es; char tmp[80]; /* If there's one thing you learn from this code, it is this... Never, ever fly Air France. Their customer service is absolutely the worst. I've never heard the words "That's not my problem" as many times as I have from their staff -- It should, without doubt be their corporate motto if it isn't already. Don't bother giving them business because you're just a pain in their side and they will be sure to let you know the first time you speak to them. If you ever want to make me happy just tell me that you, too, will never fly Air France again either (in spite of their excellent cuisine). */ snprintf(tmp, sizeof(tmp), "Asterisk Manager at %s", host); newtCenteredWindow(74, 20, tmp); form = newtForm(NULL, NULL, 0); newtFormWatchFd(form, session.fd, NEWT_FD_READ); newtFormSetTimer(form, 100); quit = newtButton(62, 16, "Quit"); redirect = newtButton(35, 16, "Redirect"); hangup = newtButton(50, 16, "Hangup"); channels = newtListbox(1,1,14, NEWT_FLAG_SCROLL); newtFormAddComponents(form, channels, redirect, hangup, quit, NULL); newtListboxSetWidth(channels, 72); show_doing("Getting Status", "Retrieving system status..."); try_status(); hide_doing(); for(;;) { newtFormRun(form, &es); if (has_input(&session) || (es.reason == NEWT_EXIT_FDREADY)) { if (input_check(&session, NULL)) { show_message("Disconnected", "Disconnected from remote host"); break; } } else if (es.reason == NEWT_EXIT_COMPONENT) { if (es.u.co == quit) break; if (es.u.co == hangup) { try_hangup(channels); } else if (es.u.co == redirect) { try_redirect(channels); } } rebuild_channels(channels); } newtFormDestroy(form); return 0; }
void play_wav_file(char *filename) { char *inwavbuf; short *current; short *audioend; short *audio; WAVE_HEADER *wav_info; int wavfd; int dspfd; struct stat input_fstat; size_t interval; newtComponent vu_1sec; newtComponent vu_total; newtComponent wav_length; newtComponent label_length; newtComponent mainwaveform; newtComponent label_1sec; newtComponent label_total; newtComponent rf_result; char labelstr_1sec[10] = "0"; char labelstr_total[10] = "0"; char labelstr_length[10] = ""; short one_sec_max, total_max; wavfd = open(filename,O_RDONLY,0600); if (wavfd == -1) { printf("Error: open() %s\n",strerror(errno)); exit(1); } if (fstat(wavfd,&input_fstat) != 0) { printf("Error: fstat() %s\n",strerror(errno)); return; } if (input_fstat.st_size < sizeof(WAVE_HEADER)) { printf("File is not large enough to hold a .wav file header even!\n"); return; } inwavbuf = mmap(NULL,input_fstat.st_size,PROT_READ,MAP_SHARED,wavfd,0); if (inwavbuf == MAP_FAILED) { printf("Error: mmap() %s\n",strerror(errno)); exit(1); } audio = (short *)validate_wav_header(inwavbuf,0); current = audio; if (current == NULL) { printf("This program didn't like the wav file\n"); exit(1); } wav_info = (WAVE_HEADER *)inwavbuf; audioend = (short *)((char *)audio + wav_info->nDataBytes); dspfd = open_dsp(wav_info); newtCls(); newtDrawRootText(0, 0, filename); mainwaveform = newtForm(NULL, NULL, NEWT_FLAG_NOF12); vu_1sec = newtScale(9,5,68,(long long)(SHRT_MAX)); label_1sec = newtLabel(1,5,labelstr_1sec); wav_length = newtScale(9,3,68,audioend - audio); label_length = newtLabel(1,3,labelstr_length); vu_total = newtScale(9,8,68,(long long)(SHRT_MAX)); label_total = newtLabel(1,8,labelstr_total); newtFormAddComponent(mainwaveform,vu_1sec); newtFormAddComponent(mainwaveform,vu_total); newtFormAddComponent(mainwaveform,label_1sec); newtFormAddComponent(mainwaveform,label_total); one_sec_max = 0; total_max = 0; newtFormWatchFd(mainwaveform,dspfd,NEWT_FD_WRITE); newtFormAddHotKey(mainwaveform,NEWT_KEY_ENTER); newtPushHelpLine("Hit Enter to end playing"); newtCenteredWindow(78,10,"now playing .wav file"); newtRefresh(); /* presently every second */ interval = (size_t )((double )wav_info->nSamplesPerSec * interval_s * 2); while ((current) < audioend) { short *endcurrent = current + interval; if (endcurrent > audioend) { endcurrent = audioend; } one_sec_max = get_peak_value(current,endcurrent); newtScaleSet(vu_1sec,one_sec_max); sprintf(labelstr_1sec,"%1.6f",((float )one_sec_max/ (float )SHRT_MAX)); newtLabelSetText(label_1sec,labelstr_1sec); newtScaleSet(wav_length,current - audio); sprintf(labelstr_length,"%4.2f", ((double )(current - audio) / 88200)); newtLabelSetText(label_length,labelstr_length); if (one_sec_max > total_max) { total_max = one_sec_max; sprintf(labelstr_total,"%1.6f",((float )total_max/ (float )SHRT_MAX)); newtLabelSetText(label_total,labelstr_total); newtScaleSet(vu_total,total_max); } rf_result = newtRunForm(mainwaveform); if (play_buffer(dspfd,current,endcurrent) == -1) { current = audioend; } current = endcurrent; if (rf_result == NULL) current = audioend; newtRefresh(); } newtFormDestroy(mainwaveform); munmap(inwavbuf,input_fstat.st_size); close(wavfd); close(dspfd); return; }