satdump/plugins/sdr_sources/remote_sdr_support/server/streaming.cpp

48 lines
1.3 KiB
C++
Raw Permalink Normal View History

2023-09-12 18:30:01 +02:00
#include "streaming.h"
#include "main.h"
#include "remote.h"
#include "iq_pkt.h"
std::mutex source_stream_mtx;
bool source_should_stream = false;
std::atomic<int> streaming_bit_depth = 32;
void sourceStreamThread()
{
2023-09-12 18:35:57 +02:00
uint8_t *buffer_tx = new uint8_t[dsp::STREAM_BUFFER_SIZE * sizeof(complex_t)];
2023-09-12 18:30:01 +02:00
float *mag_buffer = new float[dsp::STREAM_BUFFER_SIZE];
while (1)
{
int swrite_ret = 1;
2023-09-12 18:30:01 +02:00
source_stream_mtx.lock();
if (source_should_stream)
{
2023-12-15 09:14:52 -05:00
int nsamples = current_sample_source->output_stream->read();
2023-09-12 18:30:01 +02:00
2023-12-15 09:14:52 -05:00
if (nsamples <= 0)
{
source_stream_mtx.unlock();
continue;
}
2023-09-12 18:30:01 +02:00
2023-12-15 09:14:52 -05:00
int pktlen = 1;
buffer_tx[0] = dsp::remote::PKT_TYPE_IQ;
2023-09-12 18:30:01 +02:00
2023-12-15 09:14:52 -05:00
pktlen += remote_sdr::encode_iq_pkt(&buffer_tx[1], current_sample_source->output_stream->readBuf, mag_buffer, nsamples, streaming_bit_depth);
swrite_ret = tcp_server->swrite(buffer_tx, pktlen);
2023-09-12 18:30:01 +02:00
2023-12-15 09:14:52 -05:00
// logger->trace(nsamples);
current_sample_source->output_stream->flush();
2023-09-12 18:30:01 +02:00
}
source_stream_mtx.unlock();
if(swrite_ret <= 0)
tcp_server->closeconn();
2023-09-12 18:30:01 +02:00
if (!source_should_stream)
std::this_thread::sleep_for(std::chrono::milliseconds(50));
}
delete[] buffer_tx;
delete[] mag_buffer;
}