1 /*****************************************************************************\
5 **---------------------------------------------------------------------------**
6 ** Copyright: Andreas Eversberg **
10 \*****************************************************************************/
15 #include <sys/types.h>
24 //#define MIXER_DEBUG /* debug mixer buffer overflow and underrun */
26 class Port *port_first = NULL;
28 unsigned long port_serial = 1; /* must be 1, because 0== no port */
31 /* free epointlist relation
33 void Port::free_epointlist(struct epoint_list *epointlist)
35 struct epoint_list *temp, **tempp;
38 tempp = &p_epointlist;
41 if (temp == epointlist)
49 PERROR("SOFTWARE ERROR: epointlist not in port's list.\n");
56 PDEBUG(DEBUG_EPOINT, "PORT(%d) removed epoint from port\n", p_serial);
57 memset(temp, 0, sizeof(struct epoint_list));
63 void Port::free_epointid(unsigned long epoint_id)
65 struct epoint_list *temp, **tempp;
68 tempp = &p_epointlist;
71 if (temp->epoint_id == epoint_id)
79 PERROR("epoint_id not in port's list, exitting.\n");
86 PDEBUG(DEBUG_EPOINT, "PORT(%d) removed epoint from port\n", p_serial);
87 memset(temp, 0, sizeof(struct epoint_list));
93 /* create new epointlist relation
95 struct epoint_list *Port::epointlist_new(unsigned long epoint_id)
97 struct epoint_list *epointlist, **epointlistpointer;
99 /* epointlist structure */
100 epointlist = (struct epoint_list *)calloc(1, sizeof(struct epoint_list));
103 PERROR("no mem for allocating epoint_list\n");
107 PDEBUG(DEBUG_EPOINT, "PORT(%d) allocating epoint_list.\n", p_serial);
108 memset(epointlist, 0, sizeof(struct epoint_list));
110 /* add epoint_list to chain */
111 epointlist->next = NULL;
112 epointlistpointer = &p_epointlist;
113 while(*epointlistpointer)
114 epointlistpointer = &((*epointlistpointer)->next);
115 *epointlistpointer = epointlist;
118 epointlist->epoint_id = epoint_id;
119 epointlist->active = 1;
128 Port::Port(int type, char *portname, struct port_settings *settings)
130 class Port *temp, **tempp;
132 PDEBUG(DEBUG_PORT, "new port of type %d, name '%s'\n", type, portname);
134 /* initialize object */
136 memcpy(&p_settings, settings, sizeof(struct port_settings));
139 memset(&p_settings, 0, sizeof(p_settings));
140 SCPY(p_settings.tones_dir, options.tones_dir);
142 SCPY(p_name, portname);
143 SCPY(p_tone_dir, p_settings.tones_dir); // just to be sure
145 p_serial = port_serial++;
146 p_debug_nothingtosend = 0;
148 p_tone_fetched = NULL;
149 p_tone_name[0] = '\0';
151 // p_knock_fetched = NULL;
152 p_state = PORT_STATE_IDLE;
154 memset(&p_callerinfo, 0, sizeof(p_callerinfo));
155 memset(&p_dialinginfo, 0, sizeof(p_dialinginfo));
156 memset(&p_connectinfo, 0, sizeof(p_connectinfo));
157 memset(&p_redirinfo, 0, sizeof(p_redirinfo));
158 memset(&p_capainfo, 0, sizeof(p_capainfo));
159 memset(p_mixer_buffer, 0, sizeof(p_mixer_buffer));
160 memset(p_record_buffer, 0, sizeof(p_record_buffer));
161 memset(p_stereo_buffer, 0, sizeof(p_stereo_buffer));
169 p_record_filename[0] = '\0';
171 /* append port to chain */
190 struct mixer_relation *relation, *rtemp;
191 class Port *temp, **tempp;
192 struct message *message;
199 PDEBUG(DEBUG_PORT, "removing port of type %d, name '%s'\n", p_type, p_name);
201 /* free mixer relation chain */
202 relation = p_mixer_rel;
206 relation = relation->next;
207 memset(rtemp, 0, sizeof(struct mixer_relation));
211 p_mixer_rel = NULL; /* beeing paranoid */
213 /* disconnect port from endpoint */
216 /* send disconnect */
217 message = message_create(p_serial, p_epointlist->epoint_id, PORT_TO_EPOINT, MESSAGE_RELEASE);
218 message->param.disconnectinfo.cause = 16;
219 message->param.disconnectinfo.location = LOCATION_PRIVATE_LOCAL;
220 message_put(message);
221 /* remove endpoint */
222 free_epointlist(p_epointlist);
225 /* remove port from chain */
237 PERROR("PORT(%s) port not in port's list.\n", p_name);
243 /* close open tones file */
250 p_tone_fetched = NULL;
255 /* set new endpoint state
257 void Port::new_state(int state)
259 PDEBUG(DEBUG_PORT, "PORT(%s) new state %s --> %s\n", p_name, state_name[p_state], state_name[state]);
265 * find the port using h323 token
267 class Port *find_port_with_token(char *name)
269 class Port *port = port_first;
273 //printf("comparing: '%s' with '%s'\n", name, p_name);
274 if ((port->p_type==PORT_TYPE_H323_IN || port->p_type==PORT_TYPE_H323_OUT) && !strcmp(port->p_name, name))
284 * find the port with port_id
286 class Port *find_port_id(unsigned long port_id)
288 class Port *port = port_first;
292 //printf("comparing: '%s' with '%s'\n", name, port->name);
293 if (port->p_serial == port_id)
303 * open the knock sound
305 void Port::set_knock(char *tones_dir_epoint)
307 char filename[128], *tones_dir;
309 /* check if we have the epoint override the tones_dir of options.conf */
310 tones_dir = options.tones_dir;
311 if (tones_dir_epoint[0])
313 tones_dir = tones_dir_epoint;
322 p_knock_fetched = NULL;
324 if ((p_knock_fetched=open_tone_fetched(tones_dir, "knock", &p_knock_codec, &p_knock_size, &p_knock_left)))
326 PDEBUG(DEBUG_PORT, "PORT(%s) opening fetched tone: %s\n", p_name, "knock");
330 SPRINT(filename, "%s/%s/knock", INSTALL_DATA, tones_dir);
331 if ((p_knock_fh=open_tone(filename, &p_knock_codec, &p_knock_size, &p_knock_left)) >= 0)
333 PDEBUG(DEBUG_PORT, "PORT(%s) opening tone: %s\n", p_name, filename);
346 void Port::set_echotest(int echotest)
348 p_echotest = echotest;
352 * set the file in the tone directory with the given name
354 void Port::set_tone(char *dir, char *name)
364 if (!strcmp(name, "knock"))
366 set_knock(tones_dir_epoint);
371 /* no counter, no eof, normal speed */
375 p_tone_codec = CODEC_LAW;
383 p_tone_fetched = NULL;
389 SPRINT(p_tone_name, "%s", name);
390 p_tone_dir[0] = '\0';
393 SCPY(p_tone_dir, dir);
394 SCPY(p_tone_name, name);
398 p_tone_name[0]= '\0';
403 if (!!strncmp(name,"cause_",6))
406 /* now we check if the cause exists, otherwhise we use error tone. */
407 if ((p_tone_fetched=open_tone_fetched(p_tone_dir, p_tone_name, &p_tone_codec, 0, 0)))
409 p_tone_fetched = NULL;
412 SPRINT(filename, "%s_loop", p_tone_name);
413 if ((p_tone_fetched=open_tone_fetched(p_tone_dir, filename, &p_tone_codec, 0, 0)))
415 p_tone_fetched = NULL;
418 SPRINT(filename, "%s/%s/%s", INSTALL_DATA, p_tone_dir, p_tone_name);
419 if ((fh=open_tone(filename, &p_tone_codec, 0, 0)) >= 0)
424 SPRINT(filename, "%s/%s/%s_loop", INSTALL_DATA, p_tone_dir, p_tone_name);
425 if ((fh=open_tone(filename, &p_tone_codec, 0, 0)) >= 0)
431 if (!strcmp(name,"cause_00") || !strcmp(name,"cause_10"))
433 PDEBUG(DEBUG_PORT, "PORT(%s) Given Cause 0x%s has no tone, using release tone\n", p_name, name+6);
434 SPRINT(p_tone_name,"release");
436 if (!strcmp(name,"cause_11"))
438 PDEBUG(DEBUG_PORT, "PORT(%s) Given Cause 0x%s has no tone, using busy tone\n", p_name, name+6);
439 SPRINT(p_tone_name,"busy");
442 PDEBUG(DEBUG_PORT, "PORT(%s) Given Cause 0x%s has no tone, using error tone\n", p_name, name+6);
443 SPRINT(p_tone_name,"error");
449 * set the file in the tone directory for vbox playback
450 * also set the play_eof-flag
452 void Port::set_vbox_tone(char *dir, char *name)
458 p_tone_codec = CODEC_LAW;
467 p_tone_fetched = NULL;
469 SPRINT(p_tone_dir, dir);
470 SPRINT(p_tone_name, name);
472 /* now we check if the cause exists, otherwhise we use error tone. */
475 if ((p_tone_fetched=open_tone_fetched(p_tone_dir, p_tone_name, &p_tone_codec, &p_tone_size, &p_tone_left)))
477 PDEBUG(DEBUG_PORT, "PORT(%s) opening fetched tone: %s\n", p_name, p_tone_name);
480 SPRINT(filename, "%s/%s/%s", INSTALL_DATA, p_tone_dir, p_tone_name);
481 if ((p_tone_fh=open_tone(filename, &p_tone_codec, &p_tone_size, &p_tone_left)) >= 0)
484 PDEBUG(DEBUG_PORT, "PORT(%s) opening tone: %s\n", p_name, filename);
489 SPRINT(filename, "%s", p_tone_name);
490 if ((p_tone_fh=open_tone(filename, &p_tone_codec, &p_tone_size, &p_tone_left)) >= 0)
493 PDEBUG(DEBUG_PORT, "PORT(%s) opening tone: %s\n", p_name, filename);
501 * set the file in the given directory for vbox playback
502 * also set the eof-flag
503 * also set the counter-flag
505 void Port::set_vbox_play(char *name, int offset)
508 struct message *message;
510 /* use ser_box_tone() */
511 set_vbox_tone("", name);
521 //printf("\n\n\n tone_codec = %d\n\n\n\n",p_tone_codec);
527 lseek(p_tone_fh, offset*8000L, SEEK_SET);
528 size = p_tone_size / 8000L;
529 if (offset*8000L <= p_tone_left)
530 p_tone_left -= offset*8000L;
534 lseek(p_tone_fh, offset*16000L, SEEK_SET);
535 size = p_tone_size / 16000L;
536 if (offset*16000L <= p_tone_left)
537 p_tone_left -= offset*16000L;
538 //printf("\n\n\n size = %d\n\n\n\n",size);
542 lseek(p_tone_fh, offset*32000L, SEEK_SET);
543 size = p_tone_size / 32000L;
544 if (offset*32000L <= p_tone_left)
545 p_tone_left -= offset*32000L;
549 PERROR("no codec specified! exitting...\n");
553 lseek(p_tone_fh, offset*8000L, SEEK_SET);
554 size = p_tone_size / 8000L;
555 if (offset*8000L <= p_tone_left)
556 p_tone_left -= offset*8000L;
560 /* send message with counter value */
561 if (p_tone_size>=0 && ACTIVE_EPOINT(p_epointlist))
563 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_TONE_COUNTER);
564 message->param.counter.current = offset;
565 message->param.counter.max = size;
566 message_put(message);
573 * set the playback speed (for recording playback with different speeds)
575 void Port::set_vbox_speed(int speed)
577 /* enable vbox play mode */
578 p_tone_speed = speed;
581 /* write data to port's mixer buffer
582 * it will be read by the port using read_audio
583 * synchronisation is also done when writing is too fast and buffer is full
584 * the mixer buffer will only mix what cannot be mixed by kernel mixer
586 * also write data to the record buffer. the record buffer will mix everything.
588 void Port::mixer(union parameter *param)
590 struct mixer_relation *relation, **relationpointer;
593 signed short *data_16;
595 signed long *buffer, *record;
596 int must_mix = 1; /* set, if we need to mix (not done by kernel) */
598 /* we do not mix if we have audio from ourself but we need to record
599 * unless we have a local echo enabled
601 if (param->data.port_id==p_serial && !p_echotest)
604 if ((param->data.port_type&PORT_CLASS_MASK)==PORT_CLASS_mISDN
605 && (p_type&PORT_CLASS_MASK)==PORT_CLASS_mISDN)
609 if (!p_record && !must_mix) /* if we do not record AND no need to mix */
614 /* get the relation to the write pointer. if no relation exists
615 * for the given source port, we create one.
617 relation = p_mixer_rel;
618 relationpointer = &(p_mixer_rel);
619 if (!relation) /* there is no relation at all */
621 /* clear buffer to 0-volume and reset writep */
622 memset(p_mixer_buffer, 0, sizeof(p_mixer_buffer));
623 memset(p_record_buffer, 0, sizeof(p_record_buffer));
624 memset(p_stereo_buffer, 0, sizeof(p_stereo_buffer));
625 } else /* else because we do not need to run a 0-loop */
628 if (relation->port_id == param->data.port_id)
630 relationpointer = &(relation->next);
631 relation = relation->next;
635 relation = *relationpointer = (struct mixer_relation *)calloc(1, sizeof(struct mixer_relation));
638 PERROR("fatal error: cannot alloc memory for port mixer relation\n");
642 memset(relation, 0, sizeof(struct mixer_relation));
643 relation->port_id = param->data.port_id;
644 /* put write buffer in front of read buffer */
646 relation->mixer_writep = (p_mixer_readp+(PORT_BUFFER/2))%PORT_BUFFER;
648 relation->mixer_writep = p_mixer_readp;
651 PDEBUG(DEBUG_PORT, "PORT(%s) Adding new mixer relation from port #%d (readp=%d, writep=%d, PORT_BUFFER=%d).\n", p_name, param->data.port_id, p_mixer_readp, relation->mixer_writep, PORT_BUFFER);
655 /* adding remote's audio data to our mixer_buffer / record_buffer */
656 len = param->data.len;
657 if (param->data.compressed == 0) /* in case of 16 bit data */
660 PERROR("fatal error: audio data from remote port #%d is larger than mixer buffer %d>%d\n", param->data.port_id, len, PORT_BUFFER);
661 writep = relation->mixer_writep;
662 buffer = p_mixer_buffer;
663 record = p_record_buffer;
664 /* if stereo should be recorded */
665 if (param->data.port_id == p_serial)
666 if (p_record_type == CODEC_STEREO)
667 record = p_stereo_buffer;
668 /* NOTE: if read and write pointer are equal, the buffer is full */
669 if ((p_mixer_readp-writep+PORT_BUFFER)%PORT_BUFFER < len) /* we would overrun the read pointer */
672 PERROR("PORT(%s) buffer overrun, source port #%d is sending too fast. (dropping %d samples)\n", p_name, param->data.port_id, len);
674 // we do not resync since dropping causes slowing writepointer down anyway...
675 //relation->mixer_writep = (p_mixer_readp+(PORT_BUFFER/2))%PORT_BUFFER;
679 if (!p_record && must_mix)
681 /* WE MUST MIX BUT DO NOT RECORD */
682 if (param->data.compressed)
684 /* compressed data */
685 data = param->data.data;
686 if (len+writep >= PORT_BUFFER) /* data hits the buffer end */
688 len = len+writep-PORT_BUFFER; /* rest to write in front of buffer */
689 while(writep < PORT_BUFFER) /* write till buffer end */
690 buffer[writep++] += audio_law_to_s32[*(data++)];
693 while(len--) /* write rest */
694 buffer[writep++] += audio_law_to_s32[*(data++)];
697 /* uncompressed data */
698 data_16 = (signed short *)param->data.data;
699 if (len+writep >= PORT_BUFFER) /* data hits the buffer end */
701 len = len+writep-PORT_BUFFER; /* rest to write in front of buffer */
702 while(writep < PORT_BUFFER) /* write till buffer end */
703 buffer[writep++] += *(data_16++);
706 while(len--) /* write rest */
707 buffer[writep++] += *(data_16++);
710 if (p_record && !must_mix)
712 /* WE MUST RECORD BUT DO NOT MIX */
713 if (param->data.compressed)
715 /* compressed data */
716 data = param->data.data;
717 if (len+writep >= PORT_BUFFER) /* data hits the buffer end */
719 len = len+writep-PORT_BUFFER; /* rest to write in front of buffer */
720 while(writep < PORT_BUFFER) /* write till buffer end */
721 record[writep++] += audio_law_to_s32[*(data++)];
724 while(len--) /* write rest */
725 record[writep++] += audio_law_to_s32[*(data++)];
728 /* uncompressed data */
729 data_16 = (signed short *)param->data.data;
730 if (len+writep >= PORT_BUFFER) /* data hits the buffer end */
732 len = len+writep-PORT_BUFFER; /* rest to write in front of buffer */
733 while(writep < PORT_BUFFER) /* write till buffer end */
734 record[writep++] += *(data_16++);
737 while(len--) /* write rest */
738 record[writep++] += *(data_16++);
742 /* WE MUST MIX AND MUST RECORD */
743 if (param->data.compressed)
745 /* compressed data */
746 data = param->data.data;
747 if (len+writep >= PORT_BUFFER) /* data hits the buffer end */
749 len = len+writep-PORT_BUFFER; /* rest to write in front of buffer */
750 while(writep < PORT_BUFFER) /* write till buffer end */
752 buffer[writep] += audio_law_to_s32[*data];
753 record[writep++] += audio_law_to_s32[*(data++)];
757 while(len--) /* write rest */
759 buffer[writep] += audio_law_to_s32[*data];
760 record[writep++] += audio_law_to_s32[*(data++)];
764 /* uncompressed data */
765 data_16 = (signed short *)param->data.data;
766 if (len+writep >= PORT_BUFFER) /* data hits the buffer end */
768 len = len+writep-PORT_BUFFER; /* rest to write in front of buffer */
769 while(writep < PORT_BUFFER) /* write till buffer end */
771 buffer[writep] += *data_16;
772 record[writep++] += *(data_16++);
776 while(len--) /* write rest */
778 buffer[writep] += *data_16;
779 record[writep++] += *(data_16++);
783 relation->mixer_writep = writep; /* new write pointer */
784 // PDEBUG(DEBUG_PORT "written data len=%d port=%d (readp=%d, writep=%d, PORT_BUFFER=%d).\n", param->data.len, param->data.port_id, p_mixer_readp, relation->mixer_writep, PORT_BUFFER);
789 * read from the given file as specified in port_set_tone and return sample data
790 * this data is mixed with the user space mixer (if anything mixed) and
791 * filled into the buffer as many as given by length.
792 * if compressed is true, the result in buffer is alaw/ulaw-compressed
793 * otherwhise it is 16 bit audio. in this case the buffer size must be twice the lenght.
794 * the length is the number of samples, not bytes in buffer!
796 int Port::read_audio(unsigned char *buffer, int length, int compressed)
799 unsigned short temp_buffer[PORT_BUFFER]; /* buffer for up to 32 bit of data */
800 int codec_in; /* current codec to use */
801 unsigned char *buf_in8; /* buffer pointer for alaw/ulaw/8bit data */
802 signed short *buf_in16; /* buffer pointer for alaw/ulaw/8bit data */
803 signed short *buf_out16; /* buffer pointer for outgoing audio data */
804 signed long *mix_buffer, *mix_buffer2, sample; /* pointer to mixer buffer */
805 struct mixer_relation *relation, **relationpointer;
807 int nodata=0; /* to detect 0-length files */
809 signed short record_buffer[PORT_BUFFER<<1], *rec_buffer; /* buffer of recorded part which will be written (*2 for stereo) */
810 unsigned char *rec8_buffer; /* used to send 8-bit audio (wave-8bit, law) */
811 int tone_left_before; /* temp variable to determine the change in p_tone_left */
817 /* just in case, we get too much to do */
818 if (length > PORT_BUFFER-1)
819 length = PORT_BUFFER-1;
822 buf_in8 = (unsigned char *)temp_buffer;
823 buf_in16 = (signed short *)temp_buffer;
825 codec_in = p_tone_codec;
827 /* if there is no tone set, use silence */
828 if (p_tone_name[0] == 0)
830 codec_in = CODEC_LAW;
835 memset(buf_in8, (options.law=='a')?0x2a:0xff, len); /* silence */
841 memset(buf_in16, 0, len<<1); /* silence */
845 PERROR("Software error: no codec during silence\n");
851 /* if the file pointer is not open, we open it */
852 if (p_tone_fh<0 && p_tone_fetched==NULL)
856 SPRINT(filename, "%s", p_tone_name);
857 /* if file does not exist */
858 if (!(p_tone_fetched=open_tone_fetched(p_tone_dir, filename, &p_tone_codec, &p_tone_size, &p_tone_left)))
860 SPRINT(filename, "%s/%s/%s", INSTALL_DATA, p_tone_dir, p_tone_name);
861 /* if file does not exist */
862 if ((p_tone_fh=open_tone(filename, &p_tone_codec, &p_tone_size, &p_tone_left)) < 0)
864 PDEBUG(DEBUG_PORT, "PORT(%s) no tone: %s\n", p_name, filename);
871 SPRINT(filename, "%s", p_tone_name);
872 /* if file does not exist */
873 if ((p_tone_fh=open_tone(filename, &p_tone_codec, &p_tone_size, &p_tone_left)) < 0)
875 PDEBUG(DEBUG_PORT, "PORT(%s) no tone: %s\n", p_name, filename);
880 codec_in = p_tone_codec;
881 //printf("\n\ncodec=%d\n\n\n", p_tone_codec);
882 PDEBUG(DEBUG_PORT, "PORT(%s) opening %stone: %s\n", p_name, p_tone_fetched?"fetched ":"", filename);
886 /* file descriptor is open read data */
887 tone_left_before = p_tone_left;
893 l = read_tone(p_tone_fh, buf_in8, codec_in, len, p_tone_size, &p_tone_left, p_tone_speed);
894 if (l<0 || l>len) /* paranoia */
901 l = read_tone(p_tone_fh, buf_in16, codec_in, len, p_tone_size, &p_tone_left, p_tone_speed);
902 if (l<0 || l>len) /* paranoia */
909 l = read_tone(p_tone_fh, buf_in16, codec_in, len, p_tone_size, &p_tone_left, p_tone_speed);
910 if (l<0 || l>len) /* paranoia */
917 l = read_tone(p_tone_fh, buf_in16, codec_in, len, p_tone_size, &p_tone_left, p_tone_speed);
918 if (l<0 || l>len) /* paranoia */
925 PERROR("Software error: current tone reading has no codec\n");
934 l = read_tone_fetched(&p_tone_fetched, buf_in8, codec_in, len, p_tone_size, &p_tone_left, p_tone_speed);
935 if (l<0 || l>len) /* paranoia */
942 l = read_tone_fetched(&p_tone_fetched, buf_in16, codec_in, len, p_tone_size, &p_tone_left, p_tone_speed);
943 if (l<0 || l>len) /* paranoia */
950 PERROR("Software error: current tone reading has no codec\n");
955 /* if counter is enabled, we check if we have a change */
956 if (p_tone_counter && p_tone_size>=0 && ACTIVE_EPOINT(p_epointlist))
958 /* if we jumed to the next second */
959 if (((p_tone_size-p_tone_left)/8000) != (p_tone_size-tone_left_before)/8000)
961 //printf("\nsize=%d left=%d\n\n",p_tone_size,p_tone_left);
962 struct message *message;
963 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_TONE_COUNTER);
964 message->param.counter.current = (p_tone_size-p_tone_left)/8000;
965 message->param.counter.max = -1;
966 message_put(message);
979 p_tone_fetched = NULL;
984 /* if the file has 0-length */
987 PDEBUG(DEBUG_PORT, "PORT(%s) 0-length loop: %s\n", p_name, filename);
990 goto rest_is_silence;
993 /* if eof is reached, or if the normal file cannot be opened, continue with the loop file if possible */
995 if (p_tone_eof && ACTIVE_EPOINT(p_epointlist))
997 struct message *message;
998 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_TONE_EOF);
999 message_put(message);
1004 /* if file does not exist */
1005 SPRINT(filename, "%s_loop", p_tone_name);
1006 if (!(p_tone_fetched=open_tone_fetched(p_tone_dir, filename, &p_tone_codec, &p_tone_size, &p_tone_left)))
1008 SPRINT(filename, "%s/%s/%s_loop", INSTALL_DATA, p_tone_dir, p_tone_name);
1009 /* if file does not exist */
1010 if ((p_tone_fh=open_tone(filename, &p_tone_codec, &p_tone_size, &p_tone_left)) < 0)
1012 PDEBUG(DEBUG_PORT, "PORT(%s) no tone loop: %s\n",p_name, filename);
1013 p_tone_dir[0] = '\0';
1014 p_tone_name[0] = '\0';
1015 // codec_in = CODEC_LAW;
1016 goto rest_is_silence;
1022 SPRINT(filename, "%s_loop", p_tone_name);
1023 /* if file does not exist */
1024 if ((p_tone_fh=open_tone(filename, &p_tone_codec, &p_tone_size, &p_tone_left)) < 0)
1026 PDEBUG(DEBUG_PORT, "PORT(%s) no tone loop: %s\n",p_name, filename);
1027 p_tone_dir[0] = '\0';
1028 p_tone_name[0] = '\0';
1029 // codec_in = CODEC_LAW;
1030 goto rest_is_silence;
1034 codec_in = p_tone_codec;
1036 PDEBUG(DEBUG_PORT, "PORT(%s) opening %stone: %s\n", p_name, p_tone_fetched?"fetched ":"", filename);
1038 /* now we have opened the loop */
1043 * we take the buffer content and mix the mixer_buffer to what we got
1046 /* release all writepointer which will underrun, since writing of
1047 * remote port data is too slow
1049 relation = p_mixer_rel;
1050 readp = p_mixer_readp;
1051 relationpointer = &(p_mixer_rel);
1052 while(relation) /* if no relation, this is skipped */
1054 /* NOTE: if writep and readp are equal, the distance ist max
1057 if (((relation->mixer_writep-readp-1+PORT_BUFFER)%PORT_BUFFER)+1 <= length) /* underrun */
1059 /* remove port relation in order to resync.
1060 * this is also caused by ports which do not transmit
1064 PERROR("PORT(%s) Buffer underrun, source port is sending too slow or stopped sending, removing relation. (readp=%d, writep=%d, PORT_BUFFER=%d)\n", p_name, readp, relation->mixer_writep, PORT_BUFFER);
1067 *relationpointer = relation->next;
1068 memset(relation, 0, sizeof(struct mixer_relation));
1071 relation = *relationpointer;
1074 relationpointer = &(relation->next);
1075 relation = relation->next;
1078 /* if we do recording, we write the record data and the buffer data to the record fp and increment record_count */
1080 switch (p_record_type)
1083 /* convert from mixer to uncompressed 16 bit mono audio */
1090 mix_buffer = p_record_buffer;
1091 rec_buffer = record_buffer;
1092 buf_in16 = (signed short *)temp_buffer;
1093 if (len+readp >= PORT_BUFFER) /* data hits the buffer end */
1095 len = len+readp-PORT_BUFFER; /* rest to read from buffer start */
1096 while(readp < PORT_BUFFER)
1097 { /* mix till buffer end */
1098 sample = mix_buffer[readp]+*(buf_in16++);
1099 mix_buffer[readp++] = 0;
1100 if (sample < -32767)
1104 *(rec_buffer++) = sample;
1108 while(len--) /* write rest */
1109 { /* mix till buffer end */
1110 sample = mix_buffer[readp]+*(buf_in16++);
1111 mix_buffer[readp++] = 0;
1112 if (sample < -32767)
1116 *(rec_buffer++) = sample;
1119 /* restore (changed) read pointer for further use */
1120 readp = p_mixer_readp;
1122 /* now write the rec_buffer to the file */
1125 p_record_skip -= length;
1126 if (p_record_skip < 0)
1130 fwrite(record_buffer, (length<<1), 1, p_record);
1131 p_record_length = (length<<1) + p_record_length;
1137 mix_buffer = p_record_buffer;
1138 rec_buffer = record_buffer;
1139 buf_in8 = (unsigned char *)temp_buffer;
1140 if (len+readp >= PORT_BUFFER) /* data hits the buffer end */
1142 len = len+readp-PORT_BUFFER; /* rest to read from buffer start */
1143 while(readp < PORT_BUFFER)
1144 { /* mix till buffer end */
1145 sample = mix_buffer[readp]+audio_law_to_s32[*(buf_in8++)];
1146 mix_buffer[readp++] = 0;
1147 if (sample < -32767)
1151 *(rec_buffer++) = sample;
1155 while(len--) /* write rest */
1156 { /* mix till buffer end */
1157 sample = mix_buffer[readp]+audio_law_to_s32[*(buf_in8++)];
1158 mix_buffer[readp++] = 0;
1159 if (sample < -32767)
1163 *(rec_buffer++) = sample;
1166 /* restore (changed) read pointer for further use */
1167 readp = p_mixer_readp;
1169 /* now write the rec_buffer to the file */
1172 p_record_skip -= length;
1173 if (p_record_skip < 0)
1177 fwrite(record_buffer, (length<<1), 1, p_record);
1178 p_record_length = (length<<1) + p_record_length;
1186 /* convert from mixer to uncompressed 16 bit stereo audio */
1193 mix_buffer = p_record_buffer;
1194 mix_buffer2 = p_stereo_buffer;
1195 rec_buffer = record_buffer;
1196 buf_in16 = (signed short *)temp_buffer;
1197 if (len+readp >= PORT_BUFFER) /* data hits the buffer end */
1199 len = len+readp-PORT_BUFFER; /* rest to read from buffer start */
1200 while(readp < PORT_BUFFER)
1201 { /* mix till buffer end */
1202 sample = mix_buffer[readp]+*(buf_in16++);
1203 mix_buffer[readp] = 0;
1204 if (sample < -32767)
1208 *(rec_buffer++) = sample;
1210 *(rec_buffer++) = mix_buffer2[readp];
1211 mix_buffer2[readp++] = 0;
1215 while(len--) /* write rest */
1216 { /* mix till buffer end */
1217 sample = mix_buffer[readp]+*(buf_in16++);
1218 mix_buffer[readp] = 0;
1219 if (sample < -32767)
1223 *(rec_buffer++) = sample;
1224 *(rec_buffer++) = mix_buffer2[readp];
1225 mix_buffer2[readp++] = 0;
1228 /* restore (changed) read pointer for further use */
1229 readp = p_mixer_readp;
1231 /* now write the rec_buffer to the file */
1234 p_record_skip -= length;
1235 if (p_record_skip < 0)
1239 fwrite(record_buffer, (length<<2), 1, p_record);
1240 p_record_length = (length<<2) + p_record_length;
1246 mix_buffer = p_record_buffer;
1247 mix_buffer2 = p_stereo_buffer;
1248 rec_buffer = record_buffer;
1249 buf_in8 = (unsigned char *)temp_buffer;
1250 if (len+readp >= PORT_BUFFER) /* data hits the buffer end */
1252 len = len+readp-PORT_BUFFER; /* rest to read from buffer start */
1253 while(readp < PORT_BUFFER)
1254 { /* mix till buffer end */
1255 sample = mix_buffer[readp]+audio_law_to_s32[*(buf_in8++)];
1256 mix_buffer[readp] = 0;
1257 if (sample < -32767)
1261 *(rec_buffer++) = sample;
1263 *(rec_buffer++) = mix_buffer2[readp];
1264 mix_buffer2[readp++] = 0;
1268 while(len--) /* write rest */
1269 { /* mix till buffer end */
1270 sample = mix_buffer[readp]+audio_law_to_s32[*(buf_in8++)];
1271 mix_buffer[readp] = 0;
1272 if (sample < -32767)
1276 *(rec_buffer++) = sample;
1277 *(rec_buffer++) = mix_buffer2[readp];
1278 mix_buffer2[readp++] = 0;
1281 /* restore (changed) read pointer for further use */
1282 readp = p_mixer_readp;
1284 /* now write the rec_buffer to the file */
1287 p_record_skip -= length;
1288 if (p_record_skip < 0)
1292 fwrite(record_buffer, (length<<2), 1, p_record);
1293 p_record_length = (length<<2) + p_record_length;
1300 /* convert from mixer to uncompressed 8 bit mono audio */
1307 mix_buffer = p_record_buffer;
1308 rec8_buffer = (unsigned char *)record_buffer;
1309 buf_in16 = (signed short *)temp_buffer;
1310 if (len+readp >= PORT_BUFFER) /* data hits the buffer end */
1312 len = len+readp-PORT_BUFFER; /* rest to read from buffer start */
1313 while(readp < PORT_BUFFER)
1314 { /* mix till buffer end */
1315 sample = mix_buffer[readp]+*(buf_in16++);
1316 mix_buffer[readp++] = 0;
1317 if (sample < -32767)
1321 *(rec8_buffer++) = (sample>>8)+0x80;
1325 while(len--) /* write rest */
1326 { /* mix till buffer end */
1327 sample = mix_buffer[readp]+*(buf_in16++);
1328 mix_buffer[readp++] = 0;
1329 if (sample < -32767)
1333 *(rec8_buffer++) = (sample>>8)+0x80;
1336 /* restore (changed) read pointer for further use */
1337 readp = p_mixer_readp;
1339 /* now write the rec_buffer to the file */
1342 p_record_skip -= length;
1343 if (p_record_skip < 0)
1347 fwrite(record_buffer, (length), 1, p_record);
1348 p_record_length = (length) + p_record_length;
1354 mix_buffer = p_record_buffer;
1355 rec8_buffer = (unsigned char *)record_buffer;
1356 buf_in8 = (unsigned char *)temp_buffer;
1357 if (len+readp >= PORT_BUFFER) /* data hits the buffer end */
1359 len = len+readp-PORT_BUFFER; /* rest to read from buffer start */
1360 while(readp < PORT_BUFFER)
1361 { /* mix till buffer end */
1362 sample = mix_buffer[readp]+audio_law_to_s32[*(buf_in8++)];
1363 mix_buffer[readp++] = 0;
1364 if (sample < -32767)
1368 *(rec8_buffer++) = (sample>>8)+0x80;
1372 while(len--) /* write rest */
1373 { /* mix till buffer end */
1374 sample = mix_buffer[readp]+audio_law_to_s32[*(buf_in8++)];
1375 mix_buffer[readp++] = 0;
1376 if (sample < -32767)
1380 *(rec8_buffer++) = (sample>>8)+0x80;
1383 /* restore (changed) read pointer for further use */
1384 readp = p_mixer_readp;
1386 /* now write the rec_buffer to the file */
1389 p_record_skip -= length;
1390 if (p_record_skip < 0)
1394 fwrite(record_buffer, (length), 1, p_record);
1395 p_record_length = (length) + p_record_length;
1403 case CODEC_OFF: /* if no codec is specified, the recorded data will be stored as LAW */
1404 /* convert from mixer to law */
1411 mix_buffer = p_record_buffer;
1412 rec8_buffer = (unsigned char *)record_buffer;
1413 buf_in16 = (signed short *)temp_buffer;
1414 if (len+readp >= PORT_BUFFER) /* data hits the buffer end */
1416 len = len+readp-PORT_BUFFER; /* rest to read from buffer start */
1417 while(readp < PORT_BUFFER)
1418 { /* mix till buffer end */
1419 sample = mix_buffer[readp]+*(buf_in16++);
1420 mix_buffer[readp++] = 0;
1421 if (sample < -32767)
1425 *(rec8_buffer++) = audio_s16_to_law[sample & 0xffff];
1429 while(len--) /* write rest */
1430 { /* mix till buffer end */
1431 sample = mix_buffer[readp]+*(buf_in16++);
1432 mix_buffer[readp++] = 0;
1433 if (sample < -32767)
1437 *(rec8_buffer++) = audio_s16_to_law[sample & 0xffff];
1440 /* restore (changed) read pointer for further use */
1441 readp = p_mixer_readp;
1443 /* now write the rec_buffer to the file */
1446 p_record_skip -= length;
1447 if (p_record_skip < 0)
1451 fwrite(record_buffer, (length), 1, p_record);
1452 p_record_length = (length) + p_record_length;
1458 mix_buffer = p_record_buffer;
1459 rec8_buffer = (unsigned char *)record_buffer;
1460 buf_in8 = (unsigned char *)temp_buffer;
1461 if (len+readp >= PORT_BUFFER) /* data hits the buffer end */
1463 len = len+readp-PORT_BUFFER; /* rest to read from buffer start */
1464 while(readp < PORT_BUFFER)
1465 { /* mix till buffer end */
1466 sample = mix_buffer[readp]+audio_law_to_s32[*(buf_in8++)];
1467 mix_buffer[readp++] = 0;
1468 if (sample < -32767)
1472 *(rec8_buffer++) = audio_s16_to_law[sample & 0xffff];
1476 while(len--) /* write rest */
1477 { /* mix till buffer end */
1478 sample = mix_buffer[readp]+audio_law_to_s32[*(buf_in8++)];
1479 mix_buffer[readp++] = 0;
1480 if (sample < -32767)
1484 *(rec8_buffer++) = audio_s16_to_law[sample & 0xffff];
1487 /* restore (changed) read pointer for further use */
1488 readp = p_mixer_readp;
1490 /* now write the rec_buffer to the file */
1493 p_record_skip -= length;
1494 if (p_record_skip < 0)
1498 fwrite(record_buffer, (length), 1, p_record);
1499 p_record_length = (length) + p_record_length;
1506 /* if we have no transmitting relation, we do not need read mixer */
1508 { /* nothing mixed to(no rel), so we are just done */
1511 /* compress to law */
1513 buf_in8 = (unsigned char *)temp_buffer;
1514 buf_in16 = (signed short *)temp_buffer;
1515 buf_out16 = (signed short *)buffer;
1522 *(buffer++) = audio_s16_to_law[*(buf_in16++) & 0xffff];
1526 memcpy(buffer, temp_buffer, length);
1530 PERROR("Software error: current tone for unmixed & uncompressed, has no codec\n");
1535 /* uncompress law files */
1537 buf_in8 = (unsigned char *)temp_buffer;
1538 buf_in16 = (signed short *)temp_buffer;
1539 buf_out16 = (signed short *)buffer;
1546 (*(buf_out16++)) = *(buf_in16++);
1551 (*(buf_out16++)) = audio_law_to_s32[*(buf_in8++)];
1555 PERROR("Software error: current tone for unmixed & uncompressed, has no codec\n");
1562 // PDEBUG(DEBUG_PORT, "PORT(%s) mixing %d bytes. (readp=%d, PORT_BUFFER=%d)\n", p_name, length, readp, PORT_BUFFER);
1563 /* now we got our stuff and we'll mix it baby */
1566 mix_buffer = p_mixer_buffer;
1569 /* convert from mixer to compressed law data */
1575 buf_in16 = (signed short *)temp_buffer;
1576 if (len+readp >= PORT_BUFFER) /* data hits the buffer end */
1578 len = len+readp-PORT_BUFFER; /* rest to read from buffer start */
1579 while(readp < PORT_BUFFER)
1580 { /* mix till buffer end */
1581 sample = mix_buffer[readp]+*(buf_in16++);
1582 mix_buffer[readp++] = 0;
1583 if (sample < -32767)
1587 *(buffer++) = audio_s16_to_law[sample & 0xffff];
1591 while(len--) /* write rest */
1592 { /* mix till buffer end */
1593 sample = mix_buffer[readp]+*(buf_in16++);
1594 mix_buffer[readp++] = 0;
1595 if (sample < -32767)
1599 *(buffer++) = audio_s16_to_law[sample & 0xffff];
1604 buf_in8 = (unsigned char *)temp_buffer;
1605 if (len+readp >= PORT_BUFFER) /* data hits the buffer end */
1607 len = len+readp-PORT_BUFFER; /* rest to read from buffer start */
1608 while(readp < PORT_BUFFER)
1609 { /* mix till buffer end */
1610 sample = mix_buffer[readp]+audio_law_to_s32[*(buf_in8++)];
1611 mix_buffer[readp++] = 0;
1612 if (sample < -32767)
1616 *(buffer++) = audio_s16_to_law[sample & 0xffff];
1620 while(len--) /* write rest */
1621 { /* mix till buffer end */
1622 sample = mix_buffer[readp]+audio_law_to_s32[*(buf_in8++)];
1623 mix_buffer[readp++] = 0;
1624 if (sample < -32767)
1628 *(buffer++) = audio_s16_to_law[sample & 0xffff];
1633 PERROR("Software error: current tone for compressed data has no codec\n");
1638 /* convert from mixer to uncompressed 16 bit audio */
1644 buf_in16 = (signed short *)temp_buffer;
1645 buf_out16 = (signed short *)buffer;
1646 if (len+readp >= PORT_BUFFER) /* data hits the buffer end */
1648 len = len+readp-PORT_BUFFER; /* rest to read from buffer start */
1649 while(readp < PORT_BUFFER)
1650 { /* mix till buffer end */
1651 sample = mix_buffer[readp]+*(buf_in16++);
1652 mix_buffer[readp++] = 0;
1653 if (sample < -32767)
1657 *(buf_out16++) = sample;
1661 while(len--) /* write rest */
1662 { /* mix till buffer end */
1663 sample = mix_buffer[readp]+*(buf_in16++);
1664 mix_buffer[readp++] = 0;
1665 if (sample < -32767)
1669 *(buf_out16++) = sample;
1674 buf_in8 = (unsigned char *)temp_buffer;
1675 buf_out16 = (signed short *)buffer;
1676 if (len+readp >= PORT_BUFFER) /* data hits the buffer end */
1678 len = len+readp-PORT_BUFFER; /* rest to read from buffer start */
1679 while(readp < PORT_BUFFER)
1680 { /* mix till buffer end */
1681 sample = mix_buffer[readp]+audio_law_to_s32[*(buf_in8++)];
1682 mix_buffer[readp++] = 0;
1683 if (sample < -32767)
1687 *(buf_out16++) = sample;
1691 while(len--) /* write rest */
1692 { /* mix till buffer end */
1693 sample = mix_buffer[readp]+audio_law_to_s32[*(buf_in8++)];
1694 mix_buffer[readp++] = 0;
1695 if (sample < -32767)
1699 *(buf_out16++) = sample;
1704 PERROR("Software error: current tone for uncompressed data has no codec\n");
1709 p_mixer_readp = readp; /* new read pointer */
1716 int Port::handler(void)
1721 /* endpoint sends messages to the port
1722 * this is called by the message_epoint inherited by child classes
1723 * therefor a return=1 means: stop, no more processing
1725 //extern struct message *dddebug;
1726 int Port::message_epoint(unsigned long epoint_id, int message_id, union parameter *param)
1728 /* check if we got audio data from one remote port */
1731 case MESSAGE_TONE: /* play tone */
1732 PDEBUG(DEBUG_PORT, "PORT(%s) isdn port with (caller id %s) setting tone '%s' dir '%s'\n", p_name, p_callerinfo.id, param->tone.name, param->tone.dir);
1733 set_tone(param->tone.dir,param->tone.name);
1737 //printf("port=%s, epoint=%d\n",p_cardname, epoint->e_serial);
1741 case MESSAGE_VBOX_TONE: /* play tone of answering machine */
1742 PDEBUG(DEBUG_PORT, "PORT(%s) set answering machine tone '%s' '%s'\n", p_name, param->tone.dir, param->tone.name);
1743 set_vbox_tone(param->tone.dir, param->tone.name);
1746 case MESSAGE_VBOX_PLAY: /* play recording of answering machine */
1747 PDEBUG(DEBUG_PORT, "PORT(%s) set answering machine file to play '%s' (offset %d seconds)\n", p_name, param->play.file, param->play.offset);
1748 set_vbox_play(param->play.file, param->play.offset);
1751 case MESSAGE_VBOX_PLAY_SPEED: /* set speed of playback (recording of answering machine) */
1752 PDEBUG(DEBUG_PORT, "PORT(%s) set answering machine playback speed %d (times)\n", p_name, param->speed);
1753 set_vbox_speed(param->speed);
1763 * special function generate individual isdn debug logs
1765 void Port::printisdn(char *fmt, ...)
1773 VUNPRINT(buffer,sizeof(buffer)-1,fmt,args);
1774 buffer[sizeof(buffer)-1]=0;
1777 PDEBUG_RUNTIME(NULL, 0, DEBUG_PORT, "PORT(%s serial=%ld): %s\n", p_name, p_serial, buffer);
1778 if (options.deb & DEBUG_LOG)
1780 SPRINT(name, "%s/debug_%s.log", INSTALL_DATA, p_name);
1781 if (!(fp = fopen(name, "a")))
1784 fprintf(fp, "%04d.%02d.%02d %02d:%02d:%02d %s(%ld): %s", now_tm->tm_year+1900, now_tm->tm_mon+1, now_tm->tm_mday, now_tm->tm_hour, now_tm->tm_min, now_tm->tm_sec, p_name, p_serial, buffer);
1790 /* wave header structure */
1792 unsigned short stereo; /* 1 = mono, 2 = stereo */
1793 unsigned short channels; /* number of channels */
1794 unsigned long sample_rate; /* sample rate */
1795 unsigned long data_rate; /* data rate */
1796 unsigned short bytes_sample; /* bytes per sample (all channels) */
1797 unsigned short bits_sample; /* bits per sample (one channel) */
1802 * open record file (actually a wave file with empty header which will be
1803 * written before close, because we do not know the size yet)
1804 * type=1 record annoucement, type=0 record audio stream, type=2 record vbox
1806 int Port::open_record(int type, int vbox, int skip, char *terminal, int anon_ignore, char *vbox_email, int vbox_email_file)
1808 /* RIFFxxxxWAVEfmt xxxx(fmt-size)dataxxxx... */
1809 char dummyheader[8+4+8+sizeof(fmt)+8];
1814 PERROR("Port(%d) not a terminal\n", p_serial);
1817 SCPY(p_record_extension, terminal);
1818 p_record_anon_ignore = anon_ignore;
1819 SCPY(p_record_vbox_email, vbox_email);
1820 p_record_vbox_email_file = vbox_email_file;
1824 PERROR("Port(%d) already recording\n", p_serial);
1829 SPRINT(filename, "%s/%s/%s/vbox", INSTALL_DATA, options.extensions_dir, p_record_extension);
1831 SPRINT(filename, "%s/%s/%s/recordings", INSTALL_DATA, options.extensions_dir, p_record_extension);
1832 if (mkdir(filename, 0755) < 0)
1834 if (errno != EEXIST)
1836 PERROR("Port(%d) cannot create directory '%s'\n", p_serial, filename);
1842 UPRINT(strchr(filename,'\0'), "/announcement");
1844 UPRINT(strchr(filename,'\0'), "/%04d-%02d-%02d_%02d%02d%02d", now_tm->tm_year+1900, now_tm->tm_mon+1, now_tm->tm_mday, now_tm->tm_hour, now_tm->tm_min, now_tm->tm_sec);
1847 p_record_vbox_year = now_tm->tm_year;
1848 p_record_vbox_mon = now_tm->tm_mon;
1849 p_record_vbox_mday = now_tm->tm_mday;
1850 p_record_vbox_hour = now_tm->tm_hour;
1851 p_record_vbox_min = now_tm->tm_min;
1854 /* check, if file exists (especially when an extension calls the same extension) */
1856 if ((p_record = fopen(filename, "r")))
1859 SCAT(filename, "_2nd");
1862 p_record = fopen(filename, "w");
1865 PERROR("Port(%d) cannot record because file cannot be opened '%s'\n", p_serial, filename);
1870 p_record_type = type;
1871 p_record_vbox = vbox;
1872 p_record_skip = skip;
1873 p_record_length = 0;
1874 switch(p_record_type)
1879 fwrite(dummyheader, sizeof(dummyheader), 1, p_record);
1885 UCPY(p_record_filename, filename);
1887 PDEBUG(DEBUG_PORT, "Port(%d) recording started with file name '%s'\n", p_serial, filename);
1893 * close the recoding file, put header in front and rename
1895 void Port::close_record(int beep)
1897 static signed long beep_mono[] = {-10000, 10000, -10000, 10000, -10000, 10000, -10000, 10000, -10000, 10000, -10000, 10000, -10000, 10000, -10000, 10000};
1898 static unsigned char beep_8bit[] = {48, 208, 48, 208, 48, 208, 48, 208, 48, 208, 48, 208, 48, 208, 48, 208, 48, 208, 48, 208, 48, 208, 48, 208, 48, 208, 48, 208, 48, 208, 48, 208, 48, 208};
1899 unsigned long size, wsize;
1901 char filename[512], indexname[512];
1904 char number[256], callerid[256];
1906 struct caller_info callerinfo;
1907 char *valid_chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ01234567890_.-!$%&/()=+*;~";
1912 memcpy(&callerinfo, &p_callerinfo, sizeof(struct caller_info));
1913 apply_callerid_restriction(p_record_anon_ignore, -1, callerinfo.id, &callerinfo.ntype, &callerinfo.present, &callerinfo.screen, callerinfo.voip, callerinfo.intern, callerinfo.name);
1915 SCPY(number, p_dialinginfo.number);
1916 SCPY(callerid, numberrize_callerinfo(callerinfo.id, callerinfo.ntype));
1917 if (callerid[0] == '\0')
1919 if (callerinfo.present == INFO_PRESENT_RESTRICTED)
1920 UCPY(callerid,"anonymous");
1922 UCPY(callerid,"unknown");
1925 /* change verboten digits */
1927 while((p=strchr(p,'*')))
1930 while((p=strchr(p,'/')))
1933 while((p=strchr(p,'*')))
1936 while((p=strchr(p,'/')))
1939 ii = strlen(callerid);
1942 if (!strchr(valid_chars, callerid[i]))
1947 ii = strlen(number);
1950 if (!strchr(valid_chars, number[i]))
1955 /* add beep to the end of recording */
1957 switch(p_record_type)
1963 fwrite(beep_mono, sizeof(beep_mono), 1, p_record);
1964 i += sizeof(beep_mono);
1965 p_record_length += sizeof(beep_mono);
1972 fwrite(beep_8bit, sizeof(beep_8bit), 1, p_record);
1973 i += sizeof(beep_8bit);
1974 p_record_length += sizeof(beep_8bit);
1982 fwrite(beep_law, sizeof(beep_law), 1, p_record);
1983 i += sizeof(beep_law);
1984 p_record_length += sizeof(beep_law);
1989 PERROR("codec %d not supported for beep adding\n", p_record_type);
1992 /* complete header */
1993 switch(p_record_type)
1999 fprintf(p_record, "cue %c%c%c%c%c%c%c%c", 4, 0, 0, 0, 0,0,0,0);
2002 fprintf(p_record, "LIST%c%c%c%cadtl", 4, 0, 0, 0);
2005 fseek(p_record, 0, SEEK_SET);
2007 /* WAVEfmt xxxx(fmt-size)dataxxxx[data]cue xxxx0000LISTxxxxadtl*/
2008 size = p_record_length;
2009 wsize = 4+8+sizeof(fmt)+8+size+8+4+8+4;
2012 fprintf(p_record, "RIFF%c%c%c%c", (unsigned char)(wsize&0xff), (unsigned char)((wsize>>8)&0xff), (unsigned char)((wsize>>16)&0xff), (unsigned char)(wsize>>24));
2015 fprintf(p_record, "WAVE");
2018 fprintf(p_record, "fmt %c%c%c%c", sizeof(fmt), 0, 0, 0);
2019 switch(p_record_type)
2024 fmt.sample_rate = 8000; /* samples/sec */
2025 fmt.data_rate = 16000; /* full data rate */
2026 fmt.bytes_sample = 2; /* all channels */
2027 fmt.bits_sample = 16; /* one channel */
2033 fmt.sample_rate = 8000; /* samples/sec */
2034 fmt.data_rate = 32000; /* full data rate */
2035 fmt.bytes_sample = 4; /* all channels */
2036 fmt.bits_sample = 16; /* one channel */
2042 fmt.sample_rate = 8000; /* samples/sec */
2043 fmt.data_rate = 8000; /* full data rate */
2044 fmt.bytes_sample = 1; /* all channels */
2045 fmt.bits_sample = 8; /* one channel */
2048 fwrite(&fmt, sizeof(fmt), 1, p_record);
2051 fprintf(p_record, "data%c%c%c%c", (unsigned char)(size&0xff), (unsigned char)((size>>8)&0xff), (unsigned char)((size>>16)&0xff), (unsigned char)(size>>24));
2054 if (p_record_vbox == 1)
2055 SPRINT(filename, "%s.wav", p_record_filename);
2057 SPRINT(filename, "%s_%s-%s.wav", p_record_filename, callerid, number);
2062 if (p_record_vbox == 1)
2063 SPRINT(filename, "%s.isdn", p_record_filename);
2065 SPRINT(filename, "%s_%s-%s.isdn", p_record_filename, callerid, number);
2069 if (p_record_vbox == 1)
2070 SPRINT(filename, "%s.unknown", p_record_filename);
2072 SPRINT(filename, "%s_%s-%s.unknown", p_record_filename, callerid, number);
2079 if (rename(p_record_filename, filename) < 0)
2081 PERROR("Port(%d) cannot rename from '%s' to '%s'\n", p_serial, p_record_filename, filename);
2085 PDEBUG(DEBUG_PORT, "Port(%d) recording is written and renamed to '%s' and must have the following size:%lu raw:%lu samples:%lu\n", p_serial, filename, wsize+8, size, size>>1);
2087 if (p_record_vbox == 2)
2089 SPRINT(indexname, "%s/%s/%s/vbox/index", INSTALL_DATA, options.extensions_dir, p_record_extension);
2090 if ((fp = fopen(indexname,"a")))
2094 /* remove path from file name */
2096 while(strchr(p, '/'))
2097 p = strchr(p, '/')+1;
2098 fprintf(fp, "%s %d %d %d %d %d %s\n", p, p_record_vbox_year, p_record_vbox_mon, p_record_vbox_mday, p_record_vbox_hour, p_record_vbox_min, callerid);
2104 PERROR("Port(%d) cannot open index file '%s' to append.\n", p_serial, indexname);
2107 /* send email with sample*/
2108 if (p_record_vbox_email[0])
2110 send_mail(p_record_vbox_email_file?filename:(char *)"", callerid, callerinfo.intern, callerinfo.name, p_record_vbox_email, p_record_vbox_year, p_record_vbox_mon, p_record_vbox_mday, p_record_vbox_hour, p_record_vbox_min, p_record_extension);