* from the upper layer to the channel
-> sound from remote channel
- -> sound from asterisk
Audio is required:
-> if local or remote channel is not mISDN
- -> if endpoint is linked to asterisk
-> if call is recorded (vbox)
*/
-#include <stdio.h>
-#include <string.h>
-#include <stdlib.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-#include <unistd.h>
-#include <errno.h>
#include "main.h"
+#define SHORT_MIN -32768
+#define SHORT_MAX 32767
+
class Port *port_first = NULL;
-unsigned long port_serial = 1; /* must be 1, because 0== no port */
+unsigned int port_serial = 1; /* must be 1, because 0== no port */
/* free epointlist relation
temp = p_epointlist;
tempp = &p_epointlist;
- while(temp)
- {
+ while(temp) {
if (temp == epointlist)
break;
tempp = &temp->next;
temp = temp->next;
}
- if (temp == 0)
- {
+ if (temp == 0) {
PERROR("SOFTWARE ERROR: epointlist not in port's list.\n");
return;
}
}
-void Port::free_epointid(unsigned long epoint_id)
+void Port::free_epointid(unsigned int epoint_id)
{
struct epoint_list *temp, **tempp;
temp = p_epointlist;
tempp = &p_epointlist;
- while(temp)
- {
+ while(temp) {
if (temp->epoint_id == epoint_id)
break;
tempp = &temp->next;
temp = temp->next;
}
- if (temp == 0)
- {
+ if (temp == 0) {
PERROR("epoint_id not in port's list.\n");
return;
}
/* create new epointlist relation
*/
-struct epoint_list *Port::epointlist_new(unsigned long epoint_id)
+struct epoint_list *Port::epointlist_new(unsigned int epoint_id)
{
struct epoint_list *epointlist, **epointlistpointer;
/*
* port constructor
*/
-Port::Port(int type, char *portname, struct port_settings *settings)
+Port::Port(int type, const char *portname, struct port_settings *settings)
{
class Port *temp, **tempp;
/* initialize object */
if (settings)
memcpy(&p_settings, settings, sizeof(struct port_settings));
- else
- {
+ else {
memset(&p_settings, 0, sizeof(p_settings));
- SCPY(p_settings.tones_dir, options.tones_dir);
}
SCPY(p_name, portname);
- SCPY(p_tone_dir, p_settings.tones_dir); // just to be sure
+ p_tone_dir[0] = '\0';
p_type = type;
p_serial = port_serial++;
p_tone_fh = -1;
next = NULL;
temp = port_first;
tempp = &port_first;
- while(temp)
- {
+ while(temp) {
tempp = &temp->next;
temp = temp->next;
}
Port::~Port(void)
{
class Port *temp, **tempp;
- struct message *message;
+ struct lcr_msg *message;
if (p_record)
- close_record(0);
+ close_record(0, 0);
classuse--;
PDEBUG(DEBUG_PORT, "removing port of type %d, name '%s'\n", p_type, p_name);
/* disconnect port from endpoint */
- while(p_epointlist)
- {
+ while(p_epointlist) {
/* send disconnect */
message = message_create(p_serial, p_epointlist->epoint_id, PORT_TO_EPOINT, MESSAGE_RELEASE);
message->param.disconnectinfo.cause = 16;
/* remove port from chain */
temp=port_first;
tempp=&port_first;
- while(temp)
- {
+ while(temp) {
if (temp == this)
break;
tempp = &temp->next;
*tempp=this->next;
/* close open tones file */
- if (p_tone_fh >= 0)
- {
+ if (p_tone_fh >= 0) {
close(p_tone_fh);
p_tone_fh = -1;
fhuse--;
/*
* find the port with port_id
*/
-class Port *find_port_id(unsigned long port_id)
+class Port *find_port_id(unsigned int port_id)
{
class Port *port = port_first;
- while(port)
- {
+ while(port) {
//printf("comparing: '%s' with '%s'\n", name, port->name);
if (port->p_serial == port_id)
return(port);
/*
* set the file in the tone directory with the given name
*/
-void Port::set_tone(char *dir, char *name)
+void Port::set_tone(const char *dir, const char *name)
{
int fh;
char filename[128];
if (name == NULL)
name = "";
+ if (!dir && !dir[0])
+ dir = options.tones_dir; /* just in case we have no PmISDN instance */
+
/* no counter, no eof, normal speed */
p_tone_counter = 0;
p_tone_eof = 0;
p_tone_speed = 1;
p_tone_codec = CODEC_LAW;
- if (p_tone_fh >= 0)
- {
+ if (p_tone_fh >= 0) {
close(p_tone_fh);
p_tone_fh = -1;
fhuse--;
}
p_tone_fetched = NULL;
- if (name[0])
- {
- if (name[0] == '/')
- {
+ if (name[0]) {
+ if (name[0] == '/') {
SPRINT(p_tone_name, "%s", name);
p_tone_dir[0] = '\0';
- } else
- {
+ } else {
SCPY(p_tone_dir, dir);
SCPY(p_tone_name, name);
}
- } else
- {
+ /* trigger playback */
+ update_load();
+ } else {
p_tone_name[0]= '\0';
p_tone_dir[0]= '\0';
return;
return;
/* now we check if the cause exists, otherwhise we use error tone. */
- if ((p_tone_fetched=open_tone_fetched(p_tone_dir, p_tone_name, &p_tone_codec, 0, 0)))
- {
+ if ((p_tone_fetched=open_tone_fetched(p_tone_dir, p_tone_name, &p_tone_codec, 0, 0))) {
p_tone_fetched = NULL;
return;
}
SPRINT(filename, "%s_loop", p_tone_name);
- if ((p_tone_fetched=open_tone_fetched(p_tone_dir, filename, &p_tone_codec, 0, 0)))
- {
+ if ((p_tone_fetched=open_tone_fetched(p_tone_dir, filename, &p_tone_codec, 0, 0))) {
p_tone_fetched = NULL;
return;
}
- SPRINT(filename, "%s/%s/%s", INSTALL_DATA, p_tone_dir, p_tone_name);
- if ((fh=open_tone(filename, &p_tone_codec, 0, 0)) >= 0)
- {
+ SPRINT(filename, "%s/%s/%s", SHARE_DATA, p_tone_dir, p_tone_name);
+ if ((fh=open_tone(filename, &p_tone_codec, 0, 0)) >= 0) {
close(fh);
return;
}
- SPRINT(filename, "%s/%s/%s_loop", INSTALL_DATA, p_tone_dir, p_tone_name);
- if ((fh=open_tone(filename, &p_tone_codec, 0, 0)) >= 0)
- {
+ SPRINT(filename, "%s/%s/%s_loop", SHARE_DATA, p_tone_dir, p_tone_name);
+ if ((fh=open_tone(filename, &p_tone_codec, 0, 0)) >= 0) {
close(fh);
return;
}
- if (!strcmp(name,"cause_00") || !strcmp(name,"cause_10"))
- {
+ if (!strcmp(name,"cause_00") || !strcmp(name,"cause_10")) {
PDEBUG(DEBUG_PORT, "PORT(%s) Given Cause 0x%s has no tone, using release tone\n", p_name, name+6);
SPRINT(p_tone_name,"release");
} else
- if (!strcmp(name,"cause_11"))
- {
+ if (!strcmp(name,"cause_11")) {
PDEBUG(DEBUG_PORT, "PORT(%s) Given Cause 0x%s has no tone, using busy tone\n", p_name, name+6);
SPRINT(p_tone_name,"busy");
- } else
- {
+ } else {
PDEBUG(DEBUG_PORT, "PORT(%s) Given Cause 0x%s has no tone, using error tone\n", p_name, name+6);
SPRINT(p_tone_name,"error");
}
* set the file in the tone directory for vbox playback
* also set the play_eof-flag
*/
-void Port::set_vbox_tone(char *dir, char *name)
+void Port::set_vbox_tone(const char *dir, const char *name)
{
char filename[256];
p_tone_codec = CODEC_LAW;
p_tone_eof = 1;
- if (p_tone_fh >= 0)
- {
+ if (p_tone_fh >= 0) {
close(p_tone_fh);
p_tone_fh = -1;
fhuse--;
SPRINT(p_tone_dir, dir);
SPRINT(p_tone_name, name);
+ /* trigger playback */
+ update_load();
/* now we check if the cause exists, otherwhise we use error tone. */
- if (p_tone_dir[0])
- {
- if ((p_tone_fetched=open_tone_fetched(p_tone_dir, p_tone_name, &p_tone_codec, &p_tone_size, &p_tone_left)))
- {
+ if (p_tone_dir[0]) {
+ if ((p_tone_fetched=open_tone_fetched(p_tone_dir, p_tone_name, &p_tone_codec, &p_tone_size, &p_tone_left))) {
PDEBUG(DEBUG_PORT, "PORT(%s) opening fetched tone: %s\n", p_name, p_tone_name);
return;
}
- SPRINT(filename, "%s/%s/%s", INSTALL_DATA, p_tone_dir, p_tone_name);
- if ((p_tone_fh=open_tone(filename, &p_tone_codec, &p_tone_size, &p_tone_left)) >= 0)
- {
+ SPRINT(filename, "%s/%s/%s", SHARE_DATA, p_tone_dir, p_tone_name);
+ if ((p_tone_fh=open_tone(filename, &p_tone_codec, &p_tone_size, &p_tone_left)) >= 0) {
fhuse++;
PDEBUG(DEBUG_PORT, "PORT(%s) opening tone: %s\n", p_name, filename);
return;
}
- } else
- {
+ } else {
SPRINT(filename, "%s", p_tone_name);
- if ((p_tone_fh=open_tone(filename, &p_tone_codec, &p_tone_size, &p_tone_left)) >= 0)
- {
+ if ((p_tone_fh=open_tone(filename, &p_tone_codec, &p_tone_size, &p_tone_left)) >= 0) {
fhuse++;
PDEBUG(DEBUG_PORT, "PORT(%s) opening tone: %s\n", p_name, filename);
return;
* also set the eof-flag
* also set the counter-flag
*/
-void Port::set_vbox_play(char *name, int offset)
+void Port::set_vbox_play(const char *name, int offset)
{
- signed long size;
- struct message *message;
+ struct lcr_msg *message;
/* use ser_box_tone() */
set_vbox_tone("", name);
p_tone_counter = 1;
/* seek */
- if (p_tone_name[0])
- {
+ if (p_tone_name[0]) {
/* send message with counter value */
- if (p_tone_size>=0 && ACTIVE_EPOINT(p_epointlist))
- {
+ if (p_tone_size>=0 && ACTIVE_EPOINT(p_epointlist)) {
message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_TONE_COUNTER);
message->param.counter.current = offset;
- message->param.counter.max = size;
+ message->param.counter.max = p_tone_size;
message_put(message);
}
}
*/
int Port::read_audio(unsigned char *buffer, int length)
{
- int l,len;
+ int l = 0,len;
int nodata=0; /* to detect 0-length files and avoid endless reopen */
char filename[128];
int tone_left_before; /* temp variable to determine the change in p_tone_left */
return(0);
/* if the file pointer is not open, we open it */
- if (p_tone_fh<0 && p_tone_fetched==NULL)
- {
- if (p_tone_dir[0])
- {
+ if (p_tone_fh<0 && p_tone_fetched==NULL) {
+ if (p_tone_dir[0]) {
SPRINT(filename, "%s", p_tone_name);
/* if file does not exist */
- if (!(p_tone_fetched=open_tone_fetched(p_tone_dir, filename, &p_tone_codec, &p_tone_size, &p_tone_left)))
- {
- SPRINT(filename, "%s/%s/%s", INSTALL_DATA, p_tone_dir, p_tone_name);
+ if (!(p_tone_fetched=open_tone_fetched(p_tone_dir, filename, &p_tone_codec, &p_tone_size, &p_tone_left))) {
+ SPRINT(filename, "%s/%s/%s", SHARE_DATA, p_tone_dir, p_tone_name);
/* if file does not exist */
- if ((p_tone_fh=open_tone(filename, &p_tone_codec, &p_tone_size, &p_tone_left)) < 0)
- {
+ if ((p_tone_fh=open_tone(filename, &p_tone_codec, &p_tone_size, &p_tone_left)) < 0) {
PDEBUG(DEBUG_PORT, "PORT(%s) no tone: %s\n", p_name, filename);
goto try_loop;
}
fhuse++;
}
- } else
- {
+ } else {
SPRINT(filename, "%s", p_tone_name);
/* if file does not exist */
- if ((p_tone_fh=open_tone(filename, &p_tone_codec, &p_tone_size, &p_tone_left)) < 0)
- {
+ if ((p_tone_fh=open_tone(filename, &p_tone_codec, &p_tone_size, &p_tone_left)) < 0) {
PDEBUG(DEBUG_PORT, "PORT(%s) no tone: %s\n", p_name, filename);
goto try_loop;
}
read_more:
/* file descriptor is open read data */
tone_left_before = p_tone_left;
- if (p_tone_fh >= 0)
- {
+ if (p_tone_fh >= 0) {
l = read_tone(p_tone_fh, buffer, p_tone_codec, len, p_tone_size, &p_tone_left, p_tone_speed);
if (l<0 || l>len) /* paranoia */
l=0;
buffer += l;
len -= l;
}
- if (p_tone_fetched)
- {
+ if (p_tone_fetched) {
l = read_tone_fetched(&p_tone_fetched, buffer, len, p_tone_size, &p_tone_left, p_tone_speed);
if (l<0 || l>len) /* paranoia */
l=0;
}
/* if counter is enabled, we check if we have a change */
- if (p_tone_counter && p_tone_size>=0 && ACTIVE_EPOINT(p_epointlist))
- {
+ if (p_tone_counter && p_tone_size>=0 && ACTIVE_EPOINT(p_epointlist)) {
/* if we jumed to the next second */
- if (((p_tone_size-p_tone_left)/8000) != (p_tone_size-tone_left_before)/8000)
- {
+ if (((p_tone_size-p_tone_left)/8000) != (p_tone_size-tone_left_before)/8000) {
//printf("\nsize=%d left=%d\n\n",p_tone_size,p_tone_left);
- struct message *message;
+ struct lcr_msg *message;
message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_TONE_COUNTER);
message->param.counter.current = (p_tone_size-p_tone_left)/8000;
message->param.counter.max = -1;
if (len==0)
return(length-len);
- if (p_tone_fh >= 0)
- {
+ if (p_tone_fh >= 0) {
close(p_tone_fh);
p_tone_fh = -1;
fhuse--;
nodata=0;
/* if the file has 0-length */
- if (nodata>1)
- {
+ if (nodata>1) {
PDEBUG(DEBUG_PORT, "PORT(%s) 0-length loop: %s\n", p_name, filename);
p_tone_name[0]=0;
p_tone_dir[0]=0;
/* if eof is reached, or if the normal file cannot be opened, continue with the loop file if possible */
try_loop:
- if (p_tone_eof && ACTIVE_EPOINT(p_epointlist))
- {
- struct message *message;
+ if (p_tone_eof && ACTIVE_EPOINT(p_epointlist)) {
+ struct lcr_msg *message;
message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_TONE_EOF);
message_put(message);
}
- if (p_tone_dir[0])
- {
+ if (p_tone_dir[0]) {
/* if file does not exist */
SPRINT(filename, "%s_loop", p_tone_name);
- if (!(p_tone_fetched=open_tone_fetched(p_tone_dir, filename, &p_tone_codec, &p_tone_size, &p_tone_left)))
- {
- SPRINT(filename, "%s/%s/%s_loop", INSTALL_DATA, p_tone_dir, p_tone_name);
+ if (!(p_tone_fetched=open_tone_fetched(p_tone_dir, filename, &p_tone_codec, &p_tone_size, &p_tone_left))) {
+ SPRINT(filename, "%s/%s/%s_loop", SHARE_DATA, p_tone_dir, p_tone_name);
/* if file does not exist */
- if ((p_tone_fh=open_tone(filename, &p_tone_codec, &p_tone_size, &p_tone_left)) < 0)
- {
+ if ((p_tone_fh=open_tone(filename, &p_tone_codec, &p_tone_size, &p_tone_left)) < 0) {
PDEBUG(DEBUG_PORT, "PORT(%s) no tone loop: %s\n",p_name, filename);
p_tone_dir[0] = '\0';
p_tone_name[0] = '\0';
}
fhuse++;
}
- } else
- {
+ } else {
SPRINT(filename, "%s_loop", p_tone_name);
/* if file does not exist */
- if ((p_tone_fh=open_tone(filename, &p_tone_codec, &p_tone_size, &p_tone_left)) < 0)
- {
+ if ((p_tone_fh=open_tone(filename, &p_tone_codec, &p_tone_size, &p_tone_left)) < 0) {
PDEBUG(DEBUG_PORT, "PORT(%s) no tone loop: %s\n",p_name, filename);
p_tone_dir[0] = '\0';
p_tone_name[0] = '\0';
}
-/* port handler:
- * process transmission clock */
-int Port::handler(void)
-{
- return(0);
-}
-
/* endpoint sends messages to the port
* this is called by the message_epoint inherited by child classes
* therefor a return=1 means: stop, no more processing
*/
-//extern struct message *dddebug;
-int Port::message_epoint(unsigned long epoint_id, int message_id, union parameter *param)
+//extern struct lcr_msg *dddebug;
+int Port::message_epoint(unsigned int epoint_id, int message_id, union parameter *param)
{
/* check if we got audio data from one remote port */
- switch(message_id)
- {
+ switch(message_id) {
case MESSAGE_TONE: /* play tone */
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);
set_tone(param->tone.dir,param->tone.name);
struct fmt {
unsigned short stereo; /* 1 = mono, 2 = stereo */
unsigned short channels; /* number of channels */
- unsigned long sample_rate; /* sample rate */
- unsigned long data_rate; /* data rate */
+ unsigned int sample_rate; /* sample rate */
+ unsigned int data_rate; /* data rate */
unsigned short bytes_sample; /* bytes per sample (all channels) */
unsigned short bits_sample; /* bits per sample (one channel) */
};
* written before close, because we do not know the size yet)
* type=1 record annoucement, type=0 record audio stream, type=2 record vbox
*/
-int Port::open_record(int type, int vbox, int skip, char *extension, int anon_ignore, char *vbox_email, int vbox_email_file)
+int Port::open_record(int type, int vbox, int skip, char *extension, int anon_ignore, const char *vbox_email, int vbox_email_file)
{
/* RIFFxxxxWAVEfmt xxxx(fmt-size)dataxxxx... */
char dummyheader[8+4+8+sizeof(fmt)+8];
char filename[256];
+ time_t now;
+ struct tm *now_tm;
+ int ret;
- if (!extension)
- {
+ if (!extension) {
PERROR("Port(%d) not an extension\n", p_serial);
return(0);
}
SCPY(p_record_vbox_email, vbox_email);
p_record_vbox_email_file = vbox_email_file;
- if (p_record)
- {
+ if (p_record) {
PERROR("Port(%d) already recording\n", p_serial);
return(0);
}
if (vbox != 0)
- SPRINT(filename, "%s/%s/%s/vbox", INSTALL_DATA, options.extensions_dir, p_record_extension);
+ SPRINT(filename, "%s/%s/vbox", EXTENSION_DATA, p_record_extension);
else
- SPRINT(filename, "%s/%s/%s/recordings", INSTALL_DATA, options.extensions_dir, p_record_extension);
- if (mkdir(filename, 0755) < 0)
- {
- if (errno != EEXIST)
- {
+ SPRINT(filename, "%s/%s/recordings", EXTENSION_DATA, p_record_extension);
+ if (mkdir(filename, 0755) < 0) {
+ if (errno != EEXIST) {
PERROR("Port(%d) cannot create directory '%s'\n", p_serial, filename);
return(0);
}
if (vbox == 1)
UPRINT(strchr(filename,'\0'), "/announcement");
- else
+ else {
+ time(&now);
+ now_tm = localtime(&now);
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);
- if (vbox == 2)
- {
+ }
+ if (vbox == 2) {
p_record_vbox_year = now_tm->tm_year;
p_record_vbox_mon = now_tm->tm_mon;
p_record_vbox_mday = now_tm->tm_mday;
/* check, if file exists (especially when an extension calls the same extension) */
if (vbox != 1)
- if ((p_record = fopen(filename, "r")))
- {
+ if ((p_record = fopen(filename, "r"))) {
fclose(p_record);
SCAT(filename, "_2nd");
}
p_record = fopen(filename, "w");
- if (!p_record)
- {
+ if (!p_record) {
PERROR("Port(%d) cannot record because file cannot be opened '%s'\n", p_serial, filename);
return(0);
}
+ update_rxoff();
fduse++;
p_record_type = type;
p_record_vbox = vbox;
p_record_skip = skip;
p_record_length = 0;
- switch(p_record_type)
- {
+ switch(p_record_type) {
case CODEC_MONO:
case CODEC_STEREO:
case CODEC_8BIT:
- fwrite(dummyheader, sizeof(dummyheader), 1, p_record);
+ ret = fwrite(dummyheader, sizeof(dummyheader), 1, p_record);
break;
case CODEC_LAW:
/*
* close the recoding file, put header in front and rename
*/
-void Port::close_record(int beep)
+void Port::close_record(int beep, int mute)
{
- static signed long beep_mono[] = {-10000, 10000, -10000, 10000, -10000, 10000, -10000, 10000, -10000, 10000, -10000, 10000, -10000, 10000, -10000, 10000};
- 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};
- unsigned long size, wsize;
+ static signed short beep_mono[256];
+ unsigned int size = 0, wsize = 0;
struct fmt fmt;
char filename[512], indexname[512];
FILE *fp;
char number[256], callerid[256];
char *p;
struct caller_info callerinfo;
- char *valid_chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ01234567890_.-!$%&/()=+*;~";
+ const char *valid_chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ01234567890_.-!$%&/()=+*;~";
+ int ret;
if (!p_record)
return;
PDEBUG(DEBUG_PORT, "data still in record buffer: %d (dir %d)\n", (p_record_buffer_writep - p_record_buffer_readp) & RECORD_BUFFER_MASK, p_record_buffer_dir);
memcpy(&callerinfo, &p_callerinfo, sizeof(struct caller_info));
- apply_callerid_restriction(p_record_anon_ignore, callerinfo.id, &callerinfo.ntype, &callerinfo.present, &callerinfo.screen, callerinfo.extension, callerinfo.name);
+// apply_callerid_restriction(p_record_anon_ignore, callerinfo.id, &callerinfo.ntype, &callerinfo.present, &callerinfo.screen, callerinfo.extension, callerinfo.name);
SCPY(number, p_dialinginfo.id);
- SCPY(callerid, numberrize_callerinfo(callerinfo.id, callerinfo.ntype));
- if (callerid[0] == '\0')
- {
+ SCPY(callerid, numberrize_callerinfo(callerinfo.id, callerinfo.ntype, options.national, options.international));
+ if (callerid[0] == '\0') {
if (callerinfo.present == INFO_PRESENT_RESTRICTED)
UCPY(callerid,"anonymous");
else
*(p++) = 'x';
i = 0;
ii = strlen(callerid);
- while(i < ii)
- {
+ while(i < ii) {
if (!strchr(valid_chars, callerid[i]))
callerid[i] = '_';
i++;
}
i = 0;
ii = strlen(number);
- while(i < ii)
- {
+ while(i < ii) {
if (!strchr(valid_chars, number[i]))
number[i] = '_';
i++;
}
+ /* mute */
+ if (mute && p_record_type==CODEC_MONO) {
+ i = p_record_length;
+ if (i > mute)
+ i = mute;
+ fseek(p_record, -(i<<1), SEEK_END);
+ p_record_length -= (i<<1);
+ }
/* add beep to the end of recording */
- if (beep)
- switch(p_record_type)
- {
- case CODEC_MONO:
- i = 0;
- while(i < beep)
- {
- fwrite(beep_mono, sizeof(beep_mono), 1, p_record);
- i += sizeof(beep_mono);
- p_record_length += sizeof(beep_mono);
- }
- break;
- case CODEC_8BIT:
+ if (beep && p_record_type==CODEC_MONO) {
i = 0;
- while(i < beep)
- {
- fwrite(beep_8bit, sizeof(beep_8bit), 1, p_record);
- i += sizeof(beep_8bit);
- p_record_length += sizeof(beep_8bit);
+ while(i < 256) {
+ beep_mono[i] = (signed short)(sin((double)i / 5.688888888889 * 2.0 * 3.1415927) * 2000.0);
+ i++;
}
- break;
-#if 0
- case CODEC_LAW:
i = 0;
- while(i < beep)
- {
- fwrite(beep_law, sizeof(beep_law), 1, p_record);
- i += sizeof(beep_law);
- p_record_length += sizeof(beep_law);
+ while(i < beep) {
+ ret = fwrite(beep_mono, sizeof(beep_mono), 1, p_record);
+ i += sizeof(beep_mono);
+ p_record_length += sizeof(beep_mono);
}
- break;
-#endif
- default:
- PERROR("codec %d not supported for beep adding\n", p_record_type);
}
/* complete header */
- switch(p_record_type)
- {
+ switch(p_record_type) {
case CODEC_MONO:
case CODEC_STEREO:
case CODEC_8BIT:
fprintf(p_record, "WAVE");
/* fmt */
- fprintf(p_record, "fmt %c%c%c%c", sizeof(fmt), 0, 0, 0);
- switch(p_record_type)
- {
+ fprintf(p_record, "fmt %c%c%c%c", (unsigned int)sizeof(fmt), 0, 0, 0);
+ switch(p_record_type) {
case CODEC_MONO:
fmt.stereo = 1;
fmt.channels = 1;
fmt.bits_sample = 8; /* one channel */
break;
}
- fwrite(&fmt, sizeof(fmt), 1, p_record);
+ ret = fwrite(&fmt, sizeof(fmt), 1, p_record);
/* data */
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));
fclose(p_record);
fduse--;
p_record = NULL;
+ update_rxoff();
- if (rename(p_record_filename, filename) < 0)
- {
+ if (rename(p_record_filename, filename) < 0) {
PERROR("Port(%d) cannot rename from '%s' to '%s'\n", p_serial, p_record_filename, filename);
return;
}
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);
- if (p_record_vbox == 2)
- {
- SPRINT(indexname, "%s/%s/%s/vbox/index", INSTALL_DATA, options.extensions_dir, p_record_extension);
- if ((fp = fopen(indexname,"a")))
- {
+ if (p_record_vbox == 2) {
+ SPRINT(indexname, "%s/%s/vbox/index", EXTENSION_DATA, p_record_extension);
+ if ((fp = fopen(indexname,"a"))) {
fduse++;
/* remove path from file name */
fclose(fp);
fduse--;
- } else
- {
+ } else {
PERROR("Port(%d) cannot open index file '%s' to append.\n", p_serial, indexname);
}
/* send email with sample*/
- if (p_record_vbox_email[0])
- {
+ if (p_record_vbox_email[0]) {
send_mail(p_record_vbox_email_file?filename:(char *)"", callerid, callerinfo.extension, 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);
}
}
unsigned char write_buffer[1024], *d;
signed short *s;
int free, i, ii;
- signed long sample;
+ signed int sample;
+ int ret;
/* no recording */
if (!p_record || !length)
return;
- /* skip */
- if (dir_fromup)
- {
- /* more than we have */
- if (p_record_skip > length)
- {
+ /* skip data from local caller (dtmf input) */
+ if (p_record_skip && !dir_fromup) {
+ /* more to skip than we have */
+ if (p_record_skip > length) {
p_record_skip -= length;
return;
}
+ /* less to skip */
data += p_record_skip;
length -= p_record_skip;
+ p_record_skip = 0;
}
+//printf("dir=%d len=%d\n", dir_fromup, length);
+
free = ((p_record_buffer_readp - p_record_buffer_writep - 1) & RECORD_BUFFER_MASK);
+//PDEBUG(DEBUG_PORT, "record(data,%d,%d): free=%d, p_record_buffer_dir=%d, p_record_buffer_readp=%d, p_record_buffer_writep=%d.\n", length, dir_fromup, free, p_record_buffer_dir, p_record_buffer_readp, p_record_buffer_writep);
+
/* the buffer stores the same data stream */
- if (dir_fromup == p_record_buffer_dir)
- {
- same_again:
+ if (dir_fromup == p_record_buffer_dir) {
+same_again:
+//printf("same free=%d length=%d\n", free, length);
/* first write what we can to the buffer */
- while(free && length)
- {
+ while(free && length) {
p_record_buffer[p_record_buffer_writep] = audio_law_to_s32[*data++];
p_record_buffer_writep = (p_record_buffer_writep + 1) & RECORD_BUFFER_MASK;
free--;
/* all written, so we return */
if (!length)
return;
- /* still data left, buffer is full, so we need to write to file */
- switch(p_record_type)
- {
+ /* still data left, buffer is full, so we need to write a chunk to file */
+ switch(p_record_type) {
case CODEC_MONO:
s = (signed short *)write_buffer;
i = 0;
- while(i < 256)
- {
+ while(i < 256) {
*s++ = p_record_buffer[p_record_buffer_readp];
p_record_buffer_readp = (p_record_buffer_readp + 1) & RECORD_BUFFER_MASK;
i++;
}
- fwrite(write_buffer, 512, 1, p_record);
+ ret = fwrite(write_buffer, 512, 1, p_record);
+ p_record_length += 512;
break;
case CODEC_STEREO:
s = (signed short *)write_buffer;
- if (p_record_buffer_dir)
- {
+ if (p_record_buffer_dir) {
i = 0;
- while(i < 256)
- {
+ while(i < 256) {
*s++ = 0; /* nothing from down */
*s++ = p_record_buffer[p_record_buffer_readp];
p_record_buffer_readp = (p_record_buffer_readp + 1) & RECORD_BUFFER_MASK;
i++;
}
- } else
- {
+ } else {
i = 0;
- while(i < 256)
- {
+ while(i < 256) {
*s++ = p_record_buffer[p_record_buffer_readp];
*s++ = 0; /* nothing from up */
p_record_buffer_readp = (p_record_buffer_readp + 1) & RECORD_BUFFER_MASK;
i++;
}
}
- fwrite(write_buffer, 1024, 1, p_record);
+ ret = fwrite(write_buffer, 1024, 1, p_record);
+ p_record_length += 1024;
break;
case CODEC_8BIT:
d = write_buffer;
i = 0;
- while(i < 256)
- {
- *d++ = (p_record_buffer[p_record_buffer_readp]+0x8000) >> 8;
+ while(i < 256) {
+ *d++ = ((unsigned short)(p_record_buffer[p_record_buffer_readp]+0x8000)) >> 8;
p_record_buffer_readp = (p_record_buffer_readp + 1) & RECORD_BUFFER_MASK;
i++;
}
- fwrite(write_buffer, 512, 1, p_record);
+ ret = fwrite(write_buffer, 512, 1, p_record);
+ p_record_length += 512;
break;
case CODEC_LAW:
d = write_buffer;
i = 0;
- while(i < 256)
- {
+ while(i < 256) {
*d++ = audio_s16_to_law[p_record_buffer[p_record_buffer_readp] & 0xffff];
p_record_buffer_readp = (p_record_buffer_readp + 1) & RECORD_BUFFER_MASK;
i++;
}
- fwrite(write_buffer, 256, 1, p_record);
+ ret = fwrite(write_buffer, 256, 1, p_record);
+ p_record_length += 256;
break;
}
/* because we still have data, we write again */
- free += sizeof(write_buffer);
+ free += 256;
goto same_again;
}
/* the buffer stores the other stream */
+different_again:
/* if buffer empty, change it */
- if (p_record_buffer_readp == p_record_buffer_writep)
- {
+ if (p_record_buffer_readp == p_record_buffer_writep) {
p_record_buffer_dir = dir_fromup;
goto same_again;
}
ii = (p_record_buffer_writep - p_record_buffer_readp) & RECORD_BUFFER_MASK;
if (length < ii)
ii = length;
+
+ if (ii > 256)
+ ii = 256;
+//printf("same ii=%d length=%d\n", ii, length);
+//PDEBUG(DEBUG_PORT, "record(data,%d,%d): free=%d, p_record_buffer_dir=%d, p_record_buffer_readp=%d, p_record_buffer_writep=%d: mixing %d bytes.\n", length, dir_fromup, free, p_record_buffer_dir, p_record_buffer_readp, p_record_buffer_writep, ii);
+
/* write data mixed with the buffer */
- switch(p_record_type)
- {
+ switch(p_record_type) {
case CODEC_MONO:
s = (signed short *)write_buffer;
i = 0;
- while(i < ii)
- {
+ while(i < ii) {
sample = p_record_buffer[p_record_buffer_readp]
+ audio_law_to_s32[*data++];
p_record_buffer_readp = (p_record_buffer_readp + 1) & RECORD_BUFFER_MASK;
- if (sample < 32767)
- sample = -32767;
- if (sample > 32768)
- sample = 32768;
+ if (sample < SHORT_MIN) sample = SHORT_MIN;
+ if (sample > SHORT_MAX) sample = SHORT_MAX;
*s++ = sample;
i++;
}
- fwrite(write_buffer, ii<<1, 1, p_record);
+ ret = fwrite(write_buffer, ii<<1, 1, p_record);
+ p_record_length += (ii<<1);
break;
case CODEC_STEREO:
s = (signed short *)write_buffer;
- if (p_record_buffer_dir)
- {
+ if (p_record_buffer_dir) {
i = 0;
- while(i < ii)
- {
+ while(i < ii) {
*s++ = audio_law_to_s32[*data++];
*s++ = p_record_buffer[p_record_buffer_readp];
p_record_buffer_readp = (p_record_buffer_readp + 1) & RECORD_BUFFER_MASK;
i++;
}
- } else
- {
+ } else {
i = 0;
- while(i < ii)
- {
+ while(i < ii) {
*s++ = p_record_buffer[p_record_buffer_readp];
*s++ = audio_law_to_s32[*data++];
+ p_record_buffer_readp = (p_record_buffer_readp + 1) & RECORD_BUFFER_MASK;
i++;
}
}
- fwrite(write_buffer, ii<<2, 1, p_record);
+ ret = fwrite(write_buffer, ii<<2, 1, p_record);
+ p_record_length += (ii<<2);
break;
case CODEC_8BIT:
d = write_buffer;
i = 0;
- while(i < ii)
- {
+ while(i < ii) {
sample = p_record_buffer[p_record_buffer_readp]
+ audio_law_to_s32[*data++];
p_record_buffer_readp = (p_record_buffer_readp + 1) & RECORD_BUFFER_MASK;
- if (sample < 32767)
- sample = -32767;
- if (sample > 32768)
- sample = 32768;
+ if (sample < SHORT_MIN) sample = SHORT_MIN;
+ if (sample > SHORT_MAX) sample = SHORT_MAX;
*d++ = (sample+0x8000) >> 8;
i++;
}
- fwrite(write_buffer, ii, 1, p_record);
+ ret = fwrite(write_buffer, ii, 1, p_record);
+ p_record_length += ii;
break;
case CODEC_LAW:
d = write_buffer;
i = 0;
- while(i < ii)
- {
+ while(i < ii) {
sample = p_record_buffer[p_record_buffer_readp]
+ audio_law_to_s32[*data++];
p_record_buffer_readp = (p_record_buffer_readp + 1) & RECORD_BUFFER_MASK;
- if (sample < 32767)
- sample = -32767;
- if (sample > 32768)
- sample = 32768;
+ if (sample < SHORT_MIN) sample = SHORT_MIN;
+ if (sample > SHORT_MAX) sample = SHORT_MAX;
*d++ = audio_s16_to_law[sample & 0xffff];
i++;
}
- fwrite(write_buffer, ii, 1, p_record);
+ ret = fwrite(write_buffer, ii, 1, p_record);
+ p_record_length += ii;
break;
}
length -= ii;
- /* data, but buffer empty */
+ /* still data */
if (length)
- {
- p_record_buffer_dir = dir_fromup;
- goto same_again;
- }
+ goto different_again;
/* no data (maybe buffer) */
return;
}
+void Port::update_rxoff(void)
+{
+}
+
+void Port::update_load(void)
+{
+}