#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 */
/* free */
PDEBUG(DEBUG_EPOINT, "PORT(%d) removed epoint from port\n", p_serial);
- memset(temp, 0, sizeof(struct epoint_list));
- free(temp);
+ FREE(temp, sizeof(struct epoint_list));
ememuse--;
}
}
if (temp == 0)
{
- PERROR("epoint_id not in port's list, exitting.\n");
+ PERROR("epoint_id not in port's list.\n");
return;
}
/* detach */
/* free */
PDEBUG(DEBUG_EPOINT, "PORT(%d) removed epoint from port\n", p_serial);
- memset(temp, 0, sizeof(struct epoint_list));
- free(temp);
+ FREE(temp, sizeof(struct epoint_list));
ememuse--;
}
struct epoint_list *epointlist, **epointlistpointer;
/* epointlist structure */
- epointlist = (struct epoint_list *)calloc(1, sizeof(struct epoint_list));
+ epointlist = (struct epoint_list *)MALLOC(sizeof(struct epoint_list));
if (!epointlist)
- {
- PERROR("no mem for allocating epoint_list\n");
- return(0);
- }
+ FATAL("No memory for epointlist\n");
ememuse++;
PDEBUG(DEBUG_EPOINT, "PORT(%d) allocating epoint_list.\n", p_serial);
- memset(epointlist, 0, sizeof(struct epoint_list));
/* add epoint_list to chain */
epointlist->next = NULL;
}
SCPY(p_name, portname);
SCPY(p_tone_dir, p_settings.tones_dir); // just to be sure
- p_last_tv_sec = 0;
- p_last_tv_msec = 0;
p_type = type;
p_serial = port_serial++;
- p_debug_nothingtosend = 0;
p_tone_fh = -1;
p_tone_fetched = NULL;
p_tone_name[0] = '\0';
temp = temp->next;
}
if (temp == NULL)
- {
- PERROR("PORT(%s) port not in port's list.\n", p_name);
- exit(-1);
- }
+ FATAL("PORT(%s) port not in port's list.\n", p_name);
/* detach */
*tempp=this->next;
/*
* read from the given file as specified in port_set_tone and return sample data
- * silence is appended if sample ends, but only the number of samples with tones are returned
+ * if the tone ends, the result may be less samples than requested
*/
int Port::read_audio(unsigned char *buffer, int length)
{
len = length;
/* if there is no tone set, use silence */
- if (p_tone_name[0] == 0)
- {
-rest_is_silence:
- memset(buffer, (options.law=='a')?0x2a:0xff, len); /* silence */
- goto done;
- }
+ if (!p_tone_name[0])
+ return(0);
/* if the file pointer is not open, we open it */
if (p_tone_fh<0 && p_tone_fetched==NULL)
}
if (len==0)
- goto done;
+ return(length-len);
if (p_tone_fh >= 0)
{
PDEBUG(DEBUG_PORT, "PORT(%s) 0-length loop: %s\n", p_name, filename);
p_tone_name[0]=0;
p_tone_dir[0]=0;
- goto rest_is_silence;
+ return(length-len);
}
/* if eof is reached, or if the normal file cannot be opened, continue with the loop file if possible */
PDEBUG(DEBUG_PORT, "PORT(%s) no tone loop: %s\n",p_name, filename);
p_tone_dir[0] = '\0';
p_tone_name[0] = '\0';
- goto rest_is_silence;
+ return(length-len);
}
fhuse++;
}
PDEBUG(DEBUG_PORT, "PORT(%s) no tone loop: %s\n",p_name, filename);
p_tone_dir[0] = '\0';
p_tone_name[0] = '\0';
- goto rest_is_silence;
+ return(length-len);
}
fhuse++;
}
/* now we have opened the loop */
goto read_more;
-
-done:
- return(length-len);
}
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, -1, callerinfo.id, &callerinfo.ntype, &callerinfo.present, &callerinfo.screen, NULL/*callerinfo.voip*/, 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.number);
+ SCPY(number, p_dialinginfo.id);
SCPY(callerid, numberrize_callerinfo(callerinfo.id, callerinfo.ntype));
if (callerid[0] == '\0')
{
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)
{
ii = (p_record_buffer_writep - p_record_buffer_readp) & RECORD_BUFFER_MASK;
if (length < ii)
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)
{
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++;
}
{
*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++;
}
}
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++;
}
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++;
}