aboutsummaryrefslogtreecommitdiffstats
path: root/src/common
diff options
context:
space:
mode:
authorAndreas Eversberg <jolly@eversberg.eu>2017-02-25 07:09:53 +0100
committerAndreas Eversberg <jolly@eversberg.eu>2017-02-25 07:09:53 +0100
commit2e1999b1eee19861f25c31b23c59c1bccf81fe9d (patch)
treeb21341255c92493f953cb2e814d9190897fd589c /src/common
parent04fd1ddceab83bc4480de06992465f28668bcf2c (diff)
Start streaming of sound/SDR just before main loop
This prevents buffer overflow during init/creation processes
Diffstat (limited to 'src/common')
-rw-r--r--src/common/call.c8
-rw-r--r--src/common/call.h1
-rw-r--r--src/common/main_common.c8
-rw-r--r--src/common/sdr.c15
-rw-r--r--src/common/sdr.h1
-rw-r--r--src/common/sender.c20
-rw-r--r--src/common/sender.h2
-rw-r--r--src/common/soapy.c7
-rw-r--r--src/common/soapy.h1
-rw-r--r--src/common/sound.h1
-rw-r--r--src/common/sound_alsa.c16
-rw-r--r--src/common/uhd.c9
-rw-r--r--src/common/uhd.h1
13 files changed, 82 insertions, 8 deletions
diff --git a/src/common/call.c b/src/common/call.c
index 09f4a1e..f2db043 100644
--- a/src/common/call.c
+++ b/src/common/call.c
@@ -532,6 +532,14 @@ int call_open_audio(void)
return 0;
}
+int call_start_audio(void)
+{
+ if (!call.audiodev[0])
+ return 0;
+
+ return sound_start(call.sound);
+}
+
void call_cleanup(void)
{
if (call.use_mncc_sock)
diff --git a/src/common/call.h b/src/common/call.h
index 11b0a9c..03bc1d2 100644
--- a/src/common/call.h
+++ b/src/common/call.h
@@ -12,6 +12,7 @@ enum number_type {
int call_init(const char *station_id, const char *audiodev, int samplerate, int latency, int dial_digits, int loopback, int use_mncc_sock, int send_patterns, int release_on_disconnect);
void call_cleanup(void);
int call_open_audio(void);
+int call_start_audio(void);
void process_call(int c);
void clear_console_text(void);
void print_console_text(void);
diff --git a/src/common/main_common.c b/src/common/main_common.c
index 76fcd63..754f7e8 100644
--- a/src/common/main_common.c
+++ b/src/common/main_common.c
@@ -475,8 +475,6 @@ void main_common(int *quit, int latency, int interval, void (*myhandler)(void))
/* open audio */
if (sender_open_audio())
return;
-
- /* afterwards open call audio, because we cannot wait for SDR to open */
if (call_open_audio())
return;
@@ -506,6 +504,12 @@ void main_common(int *quit, int latency, int interval, void (*myhandler)(void))
signal(SIGTERM, sighandler);
signal(SIGPIPE, sighandler);
+ /* start streaming */
+ if (sender_start_audio())
+ *quit = 1;
+ if (call_start_audio())
+ *quit = 1;
+
while(!(*quit)) {
begin_time = get_time();
diff --git a/src/common/sdr.c b/src/common/sdr.c
index bf158cf..ea080d4 100644
--- a/src/common/sdr.c
+++ b/src/common/sdr.c
@@ -21,6 +21,7 @@
#include <stdlib.h>
#include <stdint.h>
#include <string.h>
+#include <errno.h>
#include <math.h>
#include "sample.h"
#include "filter.h"
@@ -227,6 +228,20 @@ error:
return NULL;
}
+/* start streaming */
+int sdr_start(void __attribute__((__unused__)) *inst)
+{
+// sdr_t *sdr = (sdr_t *)inst;
+
+#ifdef HAVE_UHD
+ return uhd_start();
+#endif
+#ifdef HAVE_SOAPY
+ return soapy_start();
+#endif
+ return -EINVAL;
+}
+
void sdr_close(void *inst)
{
sdr_t *sdr = (sdr_t *)inst;
diff --git a/src/common/sdr.h b/src/common/sdr.h
index ac00a2d..3d1aaca 100644
--- a/src/common/sdr.h
+++ b/src/common/sdr.h
@@ -1,5 +1,6 @@
int sdr_init(int sdr_uhd, int sdr_soapy, const char *device_args, double rx_gain, double tx_gain, const char *write_iq_rx_wave, const char *write_iq_tx_wave, const char *read_iq_rx_wave);
+int sdr_start(void *inst);
void *sdr_open(const char *audiodev, double *tx_frequency, double *rx_frequency, int channels, double paging_frequency, int samplerate, double bandwidth, double sample_deviation);
void sdr_close(void *inst);
int sdr_write(void *inst, sample_t **samples, int num, enum paging_signal *paging_signal, int *on, int channels);
diff --git a/src/common/sender.c b/src/common/sender.c
index 2a0744f..b24db0b 100644
--- a/src/common/sender.c
+++ b/src/common/sender.c
@@ -97,6 +97,7 @@ int sender_create(sender_t *sender, int kanal, double sendefrequenz, double empf
#ifdef HAVE_SDR
if (!strcmp(audiodev, "sdr")) {
sender->audio_open = sdr_open;
+ sender->audio_start = sdr_start;
sender->audio_close = sdr_close;
sender->audio_read = sdr_read;
sender->audio_write = sdr_write;
@@ -105,6 +106,7 @@ int sender_create(sender_t *sender, int kanal, double sendefrequenz, double empf
#endif
{
sender->audio_open = sound_open;
+ sender->audio_start = sound_start;
sender->audio_close = sound_close;
sender->audio_read = sound_read;
sender->audio_write = sound_write;
@@ -202,6 +204,24 @@ int sender_open_audio(void)
return 0;
}
+int sender_start_audio(void)
+{
+ sender_t *master;
+ int rc = 0;
+
+ for (master = sender_head; master; master = master->next) {
+ /* skip audio slaves */
+ if (master->master)
+ continue;
+
+ rc = master->audio_start(master->audio);
+ if (rc)
+ break;
+ }
+
+ return rc;
+}
+
/* Destroy transceiver instance and unlink from list. */
void sender_destroy(sender_t *sender)
{
diff --git a/src/common/sender.h b/src/common/sender.h
index cb59671..658d444 100644
--- a/src/common/sender.h
+++ b/src/common/sender.h
@@ -42,6 +42,7 @@ typedef struct sender {
void *audio;
char audiodev[64]; /* audio device name (alsa or sdr) */
void *(*audio_open)(const char *, double *, double *, int, double, int, double, double);
+ int (*audio_start)(void *);
void (*audio_close)(void *);
int (*audio_write)(void *, sample_t **, int, enum paging_signal *, int *, int);
int (*audio_read)(void *, sample_t **, int, int);
@@ -91,6 +92,7 @@ int sender_create(sender_t *sender, int kanal, double sendefrequenz, double empf
void sender_destroy(sender_t *sender);
void sender_set_fm(sender_t *sender, double max_deviation, double max_modulation, double dBm0_deviation, double max_display);
int sender_open_audio(void);
+int sender_start_audio(void);
void process_sender_audio(sender_t *sender, int *quit, int latspl);
void sender_send(sender_t *sender, sample_t *samples, int count);
void sender_receive(sender_t *sender, sample_t *samples, int count);
diff --git a/src/common/soapy.c b/src/common/soapy.c
index c31e29f..b01f586 100644
--- a/src/common/soapy.c
+++ b/src/common/soapy.c
@@ -170,10 +170,15 @@ int soapy_open(const char *device_args, double tx_frequency, double rx_frequency
return -EIO;
}
+ return 0;
+}
+
+/* start streaming */
+int soapy_start(void)
+{
/* enable rx stream */
if (SoapySDRDevice_activateStream(sdr, rxStream, 0, 0, 0) != 0) {
PDEBUG(DUHD, DEBUG_ERROR, "Failed to issue RX stream command\n");
- soapy_close();
return -EIO;
}
return 0;
diff --git a/src/common/soapy.h b/src/common/soapy.h
index ee7c59a..36ec304 100644
--- a/src/common/soapy.h
+++ b/src/common/soapy.h
@@ -1,5 +1,6 @@
int soapy_open(const char *device_args, double tx_frequency, double rx_frequency, double rate, double rx_gain, double tx_gain);
+int soapy_start(void);
void soapy_close(void);
int soapy_send(float *buff, int num);
int soapy_receive(float *buff, int max);
diff --git a/src/common/sound.h b/src/common/sound.h
index 607e1f5..339cea6 100644
--- a/src/common/sound.h
+++ b/src/common/sound.h
@@ -2,6 +2,7 @@
enum paging_signal;
void *sound_open(const char *audiodev, double *tx_frequency, double *rx_frequency, int channels, double paging_frequency, int samplerate, double bandwidth, double sample_deviation);
+int sound_start(void *inst);
void sound_close(void *inst);
int sound_write(void *inst, sample_t **samples, int num, enum paging_signal *paging_signal, int *on, int channels);
int sound_read(void *inst, sample_t **samples, int num, int channels);
diff --git a/src/common/sound_alsa.c b/src/common/sound_alsa.c
index c12fe25..22b1b77 100644
--- a/src/common/sound_alsa.c
+++ b/src/common/sound_alsa.c
@@ -112,7 +112,6 @@ error:
static int sound_prepare(sound_t *sound)
{
int rc;
- int16_t buff[2];
rc = snd_pcm_prepare(sound->phandle);
if (rc < 0) {
@@ -126,9 +125,6 @@ static int sound_prepare(sound_t *sound)
return rc;
}
- /* trigger capturing */
- snd_pcm_readi(sound->chandle, buff, 1);
-
return 0;
}
@@ -196,6 +192,18 @@ error:
return NULL;
}
+/* start streaming */
+int sound_start(void *inst)
+{
+ sound_t *sound = (sound_t *)inst;
+ int16_t buff[2];
+
+ /* trigger capturing */
+ snd_pcm_readi(sound->chandle, buff, 1);
+
+ return 0;
+}
+
void sound_close(void *inst)
{
sound_t *sound = (sound_t *)inst;
diff --git a/src/common/uhd.c b/src/common/uhd.c
index f79d851..15c13b9 100644
--- a/src/common/uhd.c
+++ b/src/common/uhd.c
@@ -236,6 +236,14 @@ int uhd_open(const char *device_args, double tx_frequency, double rx_frequency,
return -EIO;
}
+ return 0;
+}
+
+/* start streaming */
+int uhd_start(void)
+{
+ uhd_error error;
+
/* enable rx stream */
memset(&stream_cmd, 0, sizeof(stream_cmd));
stream_cmd.stream_mode = UHD_STREAM_MODE_START_CONTINUOUS;
@@ -243,7 +251,6 @@ int uhd_open(const char *device_args, double tx_frequency, double rx_frequency,
error = uhd_rx_streamer_issue_stream_cmd(rx_streamer, &stream_cmd);
if (error) {
PDEBUG(DUHD, DEBUG_ERROR, "Failed to issue RX stream command\n");
- uhd_close();
return -EIO;
}
return 0;
diff --git a/src/common/uhd.h b/src/common/uhd.h
index d6335b9..09ae519 100644
--- a/src/common/uhd.h
+++ b/src/common/uhd.h
@@ -1,5 +1,6 @@
int uhd_open(const char *device_args, double tx_frequency, double rx_frequency, double rate, double rx_gain, double tx_gain);
+int uhd_start(void);
void uhd_close(void);
int uhd_send(float *buff, int num);
int uhd_receive(float *buff, int max);