Updated to new jitter buffer API
This commit is contained in:
parent
a6caf2c3d9
commit
7ffa1c11a0
|
@ -38,6 +38,7 @@ static const char *name = "alsa";
|
|||
static const char *audiodev = NULL;
|
||||
static int samplerate = 48000;
|
||||
static int latency = 50;
|
||||
static int tx_delay = 0;
|
||||
static int rt_prio = 1;
|
||||
static const char *caller_id = "";
|
||||
static int early_audio = 0;
|
||||
|
@ -76,12 +77,18 @@ static void print_help()
|
|||
printf(" Sample rate of sound device (default = '%d')\n", samplerate);
|
||||
printf(" -b --buffer <ms>\n");
|
||||
printf(" How many milliseconds are processed in advance (default = '%d')\n", latency);
|
||||
printf(" --tx-delay <ms>\n");
|
||||
printf(" Give a delay in milliseconds. This is required for modem/fax. Audio\n");
|
||||
printf(" toward ISDN interface is buffered with the given delay.\n");
|
||||
printf(" This feature alters dejittering strategy.\n");
|
||||
printf(" -r --realtime <prio>\n");
|
||||
printf(" Set prio: 0 to disable, 99 for maximum (default = %d)\n", rt_prio);
|
||||
printf(" -C --cc \"<osmo-cc arg>\" [--cc ...]\n");
|
||||
printf(" Pass arguments to Osmo-CC endpoint. Use '-cc help' for description.\n");
|
||||
}
|
||||
|
||||
#define OPT_TX_DELAY 256
|
||||
|
||||
static void add_options(void)
|
||||
{
|
||||
option_add('h', "help", 0);
|
||||
|
@ -93,6 +100,7 @@ static void add_options(void)
|
|||
option_add('a', "audio-device", 1);
|
||||
option_add('s', "samplerate", 1);
|
||||
option_add('b', "buffer", 1);
|
||||
option_add(OPT_TX_DELAY, "tx-delay", 1);
|
||||
option_add('r', "realtime", 1);
|
||||
option_add('C', "cc", 1);
|
||||
}
|
||||
|
@ -152,6 +160,9 @@ static int handle_options(int short_option, int argi, char **argv)
|
|||
case 'b':
|
||||
latency = atoi(argv[argi]);
|
||||
break;
|
||||
case OPT_TX_DELAY:
|
||||
tx_delay = atoi(argv[argi]);
|
||||
break;
|
||||
case 'r':
|
||||
rt_prio = atoi(argv[argi]);
|
||||
break;
|
||||
|
@ -233,7 +244,7 @@ int main(int argc, char *argv[])
|
|||
goto error;
|
||||
}
|
||||
|
||||
rc = telephone_init(telephone_ep, name, caller_id, OSMO_CC_LOCATION_USER, early_audio, audiodev, samplerate, samplerate * latency / 1000);
|
||||
rc = telephone_init(telephone_ep, name, caller_id, OSMO_CC_LOCATION_USER, early_audio, audiodev, samplerate, samplerate * latency / 1000, tx_delay);
|
||||
if (rc) {
|
||||
PDEBUG(DTEL, DEBUG_ERROR, "Endpoint initializing failed!\n");
|
||||
goto error;
|
||||
|
|
|
@ -139,13 +139,14 @@ void telephone_destroy(telephone_t *telephone_ep)
|
|||
}
|
||||
|
||||
/* initialization and configuration of interface instance */
|
||||
int telephone_init(telephone_t *telephone_ep, const char *name, const char *callerid, uint8_t serving_location, int early_audio, const char *audiodev, int samplerate, int __attribute__((unused)) buffer_size)
|
||||
int telephone_init(telephone_t *telephone_ep, const char *name, const char *callerid, uint8_t serving_location, int early_audio, const char *audiodev, int samplerate, int __attribute__((unused)) buffer_size, int tx_delay)
|
||||
{
|
||||
telephone_ep->name = strdup(name);
|
||||
telephone_ep->serving_location = serving_location;
|
||||
telephone_ep->early_audio = early_audio;
|
||||
telephone_ep->samplerate = samplerate;
|
||||
telephone_ep->buffer_size = buffer_size;
|
||||
telephone_ep->tx_delay = tx_delay;
|
||||
telephone_ep->loopback = 0;
|
||||
strcpy(ui_local_id, callerid);
|
||||
|
||||
|
@ -222,12 +223,15 @@ static call_t *call_create(telephone_t *telephone_ep)
|
|||
call->telephone_ep = telephone_ep;
|
||||
|
||||
/* init sample rate conversion */
|
||||
rc = init_samplerate(&call->srstate, 8000.0, (double)telephone_ep->samplerate, 3300.0);
|
||||
rc = init_samplerate(&call->srstate, 8000.0, (double)telephone_ep->samplerate, 3700.0);
|
||||
if (rc < 0)
|
||||
abort();
|
||||
|
||||
/* allocate jitter buffer */
|
||||
rc = jitter_create(&call->dejitter, telephone_ep->samplerate / 10); // FIXME: size
|
||||
if (telephone_ep->tx_delay)
|
||||
rc = jitter_create(&call->tx_dejitter, "tx", 8000, sizeof(sample_t), (double)telephone_ep->tx_delay / 1000.0, (double)telephone_ep->tx_delay / 1000.0 * 2.0, JITTER_FLAG_NONE);
|
||||
else
|
||||
rc = jitter_create(&call->tx_dejitter, "tx", 8000, sizeof(sample_t), JITTER_AUDIO);
|
||||
if (rc < 0)
|
||||
abort();
|
||||
|
||||
|
@ -244,7 +248,7 @@ static void call_destroy(call_t *call)
|
|||
free((char *)call->sdp);
|
||||
|
||||
/* free jitter buffer */
|
||||
jitter_destroy(&call->dejitter);
|
||||
jitter_destroy(&call->tx_dejitter);
|
||||
|
||||
/* free session description */
|
||||
if (call->cc_session)
|
||||
|
@ -291,7 +295,7 @@ void alsa_work(telephone_t *telephone_ep)
|
|||
call_t *call;
|
||||
sample_t samples[telephone_ep->buffer_size + 10], *samples_list[1];
|
||||
uint8_t *power_list[1];
|
||||
int count;
|
||||
int count, input_num;
|
||||
int rc;
|
||||
|
||||
/* hunt for call */
|
||||
|
@ -306,9 +310,12 @@ void alsa_work(telephone_t *telephone_ep)
|
|||
return;
|
||||
}
|
||||
if (count > 0) {
|
||||
if (call)
|
||||
jitter_load(&call->dejitter, samples, count);
|
||||
else
|
||||
if (call) {
|
||||
input_num = samplerate_upsample_input_num(&call->srstate, count);
|
||||
jitter_load(&call->tx_dejitter, samples, input_num);
|
||||
samplerate_upsample(&call->srstate, samples, input_num, samples, count);
|
||||
|
||||
} else
|
||||
memset(samples, 0, sizeof(*samples) * count);
|
||||
samples_list[0] = samples;
|
||||
power_list[0] = NULL;
|
||||
|
@ -332,7 +339,7 @@ void alsa_work(telephone_t *telephone_ep)
|
|||
int i;
|
||||
|
||||
if (telephone_ep->loopback == 3)
|
||||
jitter_save(&call->dejitter, samples, count);
|
||||
jitter_save(&call->tx_dejitter, samples, count, 0, 0, 0, 0);
|
||||
count = samplerate_downsample(&call->srstate, samples, count);
|
||||
/* put samples into ring buffer */
|
||||
for (i = 0; i < count; i++) {
|
||||
|
|
|
@ -32,6 +32,7 @@ typedef struct telephone {
|
|||
/* settings */
|
||||
int serving_location; /* who we serve when sending causes towards interface */
|
||||
int early_audio;
|
||||
int tx_delay;
|
||||
|
||||
/* sound */
|
||||
int loopback;
|
||||
|
@ -58,7 +59,7 @@ typedef struct call_list {
|
|||
enum call_state state;
|
||||
|
||||
/* audio states */
|
||||
jitter_t dejitter;
|
||||
jitter_t tx_dejitter;
|
||||
samplerate_t srstate;
|
||||
sample_t tx_buffer[160]; /* transmit audio buffer */
|
||||
int tx_buffer_pos; /* current position in transmit audio buffer */
|
||||
|
@ -66,7 +67,7 @@ typedef struct call_list {
|
|||
|
||||
void telephone_destroy(telephone_t *telephone_ep);
|
||||
telephone_t *telephone_create(void);
|
||||
int telephone_init(telephone_t *telephone_ep, const char *name, const char *callerid, uint8_t serving_location, int early_audio, const char *audiodev, int samplerate, int __attribute__((unused)) latspl);
|
||||
int telephone_init(telephone_t *telephone_ep, const char *name, const char *callerid, uint8_t serving_location, int early_audio, const char *audiodev, int samplerate, int latspl, int tx_delay);
|
||||
void cc_message(osmo_cc_endpoint_t *ep, uint32_t callref, osmo_cc_msg_t *msg);
|
||||
int ui_init(const char *remote_id, int autoalert, int autoanswer);
|
||||
int ui_work(telephone_t *telephone_ep, int c);
|
||||
|
|
Loading…
Reference in New Issue