Start streaming of sound/SDR just before main loop
This prevents buffer overflow during init/creation processes
This commit is contained in:
@@ -532,6 +532,14 @@ int call_open_audio(void)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int call_start_audio(void)
|
||||||
|
{
|
||||||
|
if (!call.audiodev[0])
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
return sound_start(call.sound);
|
||||||
|
}
|
||||||
|
|
||||||
void call_cleanup(void)
|
void call_cleanup(void)
|
||||||
{
|
{
|
||||||
if (call.use_mncc_sock)
|
if (call.use_mncc_sock)
|
||||||
|
@@ -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);
|
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);
|
void call_cleanup(void);
|
||||||
int call_open_audio(void);
|
int call_open_audio(void);
|
||||||
|
int call_start_audio(void);
|
||||||
void process_call(int c);
|
void process_call(int c);
|
||||||
void clear_console_text(void);
|
void clear_console_text(void);
|
||||||
void print_console_text(void);
|
void print_console_text(void);
|
||||||
|
@@ -475,8 +475,6 @@ void main_common(int *quit, int latency, int interval, void (*myhandler)(void))
|
|||||||
/* open audio */
|
/* open audio */
|
||||||
if (sender_open_audio())
|
if (sender_open_audio())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
/* afterwards open call audio, because we cannot wait for SDR to open */
|
|
||||||
if (call_open_audio())
|
if (call_open_audio())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@@ -506,6 +504,12 @@ void main_common(int *quit, int latency, int interval, void (*myhandler)(void))
|
|||||||
signal(SIGTERM, sighandler);
|
signal(SIGTERM, sighandler);
|
||||||
signal(SIGPIPE, sighandler);
|
signal(SIGPIPE, sighandler);
|
||||||
|
|
||||||
|
/* start streaming */
|
||||||
|
if (sender_start_audio())
|
||||||
|
*quit = 1;
|
||||||
|
if (call_start_audio())
|
||||||
|
*quit = 1;
|
||||||
|
|
||||||
while(!(*quit)) {
|
while(!(*quit)) {
|
||||||
begin_time = get_time();
|
begin_time = get_time();
|
||||||
|
|
||||||
|
@@ -21,6 +21,7 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include <errno.h>
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
#include "sample.h"
|
#include "sample.h"
|
||||||
#include "filter.h"
|
#include "filter.h"
|
||||||
@@ -227,6 +228,20 @@ error:
|
|||||||
return NULL;
|
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)
|
void sdr_close(void *inst)
|
||||||
{
|
{
|
||||||
sdr_t *sdr = (sdr_t *)inst;
|
sdr_t *sdr = (sdr_t *)inst;
|
||||||
|
@@ -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_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_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);
|
void sdr_close(void *inst);
|
||||||
int sdr_write(void *inst, sample_t **samples, int num, enum paging_signal *paging_signal, int *on, int channels);
|
int sdr_write(void *inst, sample_t **samples, int num, enum paging_signal *paging_signal, int *on, int channels);
|
||||||
|
@@ -97,6 +97,7 @@ int sender_create(sender_t *sender, int kanal, double sendefrequenz, double empf
|
|||||||
#ifdef HAVE_SDR
|
#ifdef HAVE_SDR
|
||||||
if (!strcmp(audiodev, "sdr")) {
|
if (!strcmp(audiodev, "sdr")) {
|
||||||
sender->audio_open = sdr_open;
|
sender->audio_open = sdr_open;
|
||||||
|
sender->audio_start = sdr_start;
|
||||||
sender->audio_close = sdr_close;
|
sender->audio_close = sdr_close;
|
||||||
sender->audio_read = sdr_read;
|
sender->audio_read = sdr_read;
|
||||||
sender->audio_write = sdr_write;
|
sender->audio_write = sdr_write;
|
||||||
@@ -105,6 +106,7 @@ int sender_create(sender_t *sender, int kanal, double sendefrequenz, double empf
|
|||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
sender->audio_open = sound_open;
|
sender->audio_open = sound_open;
|
||||||
|
sender->audio_start = sound_start;
|
||||||
sender->audio_close = sound_close;
|
sender->audio_close = sound_close;
|
||||||
sender->audio_read = sound_read;
|
sender->audio_read = sound_read;
|
||||||
sender->audio_write = sound_write;
|
sender->audio_write = sound_write;
|
||||||
@@ -202,6 +204,24 @@ int sender_open_audio(void)
|
|||||||
return 0;
|
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. */
|
/* Destroy transceiver instance and unlink from list. */
|
||||||
void sender_destroy(sender_t *sender)
|
void sender_destroy(sender_t *sender)
|
||||||
{
|
{
|
||||||
|
@@ -42,6 +42,7 @@ typedef struct sender {
|
|||||||
void *audio;
|
void *audio;
|
||||||
char audiodev[64]; /* audio device name (alsa or sdr) */
|
char audiodev[64]; /* audio device name (alsa or sdr) */
|
||||||
void *(*audio_open)(const char *, double *, double *, int, double, int, double, double);
|
void *(*audio_open)(const char *, double *, double *, int, double, int, double, double);
|
||||||
|
int (*audio_start)(void *);
|
||||||
void (*audio_close)(void *);
|
void (*audio_close)(void *);
|
||||||
int (*audio_write)(void *, sample_t **, int, enum paging_signal *, int *, int);
|
int (*audio_write)(void *, sample_t **, int, enum paging_signal *, int *, int);
|
||||||
int (*audio_read)(void *, sample_t **, 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_destroy(sender_t *sender);
|
||||||
void sender_set_fm(sender_t *sender, double max_deviation, double max_modulation, double dBm0_deviation, double max_display);
|
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_open_audio(void);
|
||||||
|
int sender_start_audio(void);
|
||||||
void process_sender_audio(sender_t *sender, int *quit, int latspl);
|
void process_sender_audio(sender_t *sender, int *quit, int latspl);
|
||||||
void sender_send(sender_t *sender, sample_t *samples, int count);
|
void sender_send(sender_t *sender, sample_t *samples, int count);
|
||||||
void sender_receive(sender_t *sender, sample_t *samples, int count);
|
void sender_receive(sender_t *sender, sample_t *samples, int count);
|
||||||
|
@@ -170,10 +170,15 @@ int soapy_open(const char *device_args, double tx_frequency, double rx_frequency
|
|||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* start streaming */
|
||||||
|
int soapy_start(void)
|
||||||
|
{
|
||||||
/* enable rx stream */
|
/* enable rx stream */
|
||||||
if (SoapySDRDevice_activateStream(sdr, rxStream, 0, 0, 0) != 0) {
|
if (SoapySDRDevice_activateStream(sdr, rxStream, 0, 0, 0) != 0) {
|
||||||
PDEBUG(DUHD, DEBUG_ERROR, "Failed to issue RX stream command\n");
|
PDEBUG(DUHD, DEBUG_ERROR, "Failed to issue RX stream command\n");
|
||||||
soapy_close();
|
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
|
@@ -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_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);
|
void soapy_close(void);
|
||||||
int soapy_send(float *buff, int num);
|
int soapy_send(float *buff, int num);
|
||||||
int soapy_receive(float *buff, int max);
|
int soapy_receive(float *buff, int max);
|
||||||
|
@@ -2,6 +2,7 @@
|
|||||||
enum paging_signal;
|
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);
|
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);
|
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_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);
|
int sound_read(void *inst, sample_t **samples, int num, int channels);
|
||||||
|
@@ -112,7 +112,6 @@ error:
|
|||||||
static int sound_prepare(sound_t *sound)
|
static int sound_prepare(sound_t *sound)
|
||||||
{
|
{
|
||||||
int rc;
|
int rc;
|
||||||
int16_t buff[2];
|
|
||||||
|
|
||||||
rc = snd_pcm_prepare(sound->phandle);
|
rc = snd_pcm_prepare(sound->phandle);
|
||||||
if (rc < 0) {
|
if (rc < 0) {
|
||||||
@@ -126,9 +125,6 @@ static int sound_prepare(sound_t *sound)
|
|||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* trigger capturing */
|
|
||||||
snd_pcm_readi(sound->chandle, buff, 1);
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -196,6 +192,18 @@ error:
|
|||||||
return NULL;
|
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)
|
void sound_close(void *inst)
|
||||||
{
|
{
|
||||||
sound_t *sound = (sound_t *)inst;
|
sound_t *sound = (sound_t *)inst;
|
||||||
|
@@ -236,6 +236,14 @@ int uhd_open(const char *device_args, double tx_frequency, double rx_frequency,
|
|||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* start streaming */
|
||||||
|
int uhd_start(void)
|
||||||
|
{
|
||||||
|
uhd_error error;
|
||||||
|
|
||||||
/* enable rx stream */
|
/* enable rx stream */
|
||||||
memset(&stream_cmd, 0, sizeof(stream_cmd));
|
memset(&stream_cmd, 0, sizeof(stream_cmd));
|
||||||
stream_cmd.stream_mode = UHD_STREAM_MODE_START_CONTINUOUS;
|
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);
|
error = uhd_rx_streamer_issue_stream_cmd(rx_streamer, &stream_cmd);
|
||||||
if (error) {
|
if (error) {
|
||||||
PDEBUG(DUHD, DEBUG_ERROR, "Failed to issue RX stream command\n");
|
PDEBUG(DUHD, DEBUG_ERROR, "Failed to issue RX stream command\n");
|
||||||
uhd_close();
|
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
|
@@ -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_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);
|
void uhd_close(void);
|
||||||
int uhd_send(float *buff, int num);
|
int uhd_send(float *buff, int num);
|
||||||
int uhd_receive(float *buff, int max);
|
int uhd_receive(float *buff, int max);
|
||||||
|
Reference in New Issue
Block a user