1
0
mirror of https://github.com/f4exb/sdrangel.git synced 2024-11-19 14:51:47 -05:00

SDRdaemon plugin: handle data reads

This commit is contained in:
f4exb 2016-01-29 08:17:34 +01:00
parent e9058a1c94
commit becf359db9
6 changed files with 36 additions and 65 deletions

View File

@ -40,6 +40,7 @@ SDRdaemonBuffer::SDRdaemonBuffer(uint32_t blockSize) :
m_readCount(0), m_readCount(0),
m_rawSize(0), m_rawSize(0),
m_rawBuffer(0), m_rawBuffer(0),
m_frameBuffer(0),
m_bytesInBlock(0), m_bytesInBlock(0),
m_nbBlocks(0) m_nbBlocks(0)
{ {
@ -59,6 +60,10 @@ SDRdaemonBuffer::~SDRdaemonBuffer()
if (m_lz4OutBuffer) { if (m_lz4OutBuffer) {
delete[] m_lz4OutBuffer; delete[] m_lz4OutBuffer;
} }
if (m_frameBuffer) {
delete[] m_frameBuffer;
}
} }
bool SDRdaemonBuffer::readMeta(char *array, uint32_t length) bool SDRdaemonBuffer::readMeta(char *array, uint32_t length)
@ -227,6 +232,24 @@ void SDRdaemonBuffer::writeToRawBufferLZ4(const char *array, uint32_t length)
writeToRawBufferUncompressed((const char *) m_lz4OutBuffer, m_frameSize); writeToRawBufferUncompressed((const char *) m_lz4OutBuffer, m_frameSize);
} }
uint8_t *SDRdaemonBuffer::readData(uint32_t length)
{
uint32_t readCount = m_readCount;
if (m_readCount + length < m_rawSize)
{
m_readCount += length;
return &m_rawBuffer[readCount];
}
else
{
std::memcpy((void *) m_frameBuffer, (const void *) &m_rawBuffer[readCount], m_rawSize - m_rawCount);
m_readCount = length - (m_rawSize - m_rawCount);
std::memcpy((void *) m_frameBuffer, (const void *) &m_frameBuffer[m_rawSize - m_rawCount], m_readCount);
return m_frameBuffer;
}
}
void SDRdaemonBuffer::updateLZ4Sizes(uint32_t frameSize) void SDRdaemonBuffer::updateLZ4Sizes(uint32_t frameSize)
{ {
uint32_t maxInputSize = LZ4_compressBound(frameSize); uint32_t maxInputSize = LZ4_compressBound(frameSize);
@ -259,6 +282,12 @@ void SDRdaemonBuffer::updateBufferSize(uint32_t frameSize)
m_rawSize = nbFrames * frameSize; m_rawSize = nbFrames * frameSize;
m_rawBuffer = new uint8_t[m_rawSize]; m_rawBuffer = new uint8_t[m_rawSize];
if (m_frameBuffer) {
delete[] m_frameBuffer;
}
m_frameBuffer = new uint8_t[frameSize];
} }
void SDRdaemonBuffer::updateBlockCounts(uint32_t nbBytesReceived) void SDRdaemonBuffer::updateBlockCounts(uint32_t nbBytesReceived)

View File

@ -65,6 +65,7 @@ public:
~SDRdaemonBuffer(); ~SDRdaemonBuffer();
bool readMeta(char *array, uint32_t length); //!< Attempt to read meta. Returns true if meta block bool readMeta(char *array, uint32_t length); //!< Attempt to read meta. Returns true if meta block
void writeData(char *array, uint32_t length); //!< Write data into buffer. void writeData(char *array, uint32_t length); //!< Write data into buffer.
uint8_t *readData(uint32_t length); //!< Read data from buffer
const MetaData& getCurrentMeta() const { return m_currentMeta; } const MetaData& getCurrentMeta() const { return m_currentMeta; }
void updateBlockCounts(uint32_t nbBytesReceived); void updateBlockCounts(uint32_t nbBytesReceived);
bool isSync() const { return m_sync; } bool isSync() const { return m_sync; }
@ -103,6 +104,7 @@ private:
uint32_t m_readCount; //!< Current read position in the raw samples buffer uint32_t m_readCount; //!< Current read position in the raw samples buffer
uint32_t m_rawSize; //!< Size of the raw samples buffer in bytes uint32_t m_rawSize; //!< Size of the raw samples buffer in bytes
uint8_t *m_rawBuffer; //!< Buffer for raw samples obtained from UDP (I/Q not in a formal I/Q structure) uint8_t *m_rawBuffer; //!< Buffer for raw samples obtained from UDP (I/Q not in a formal I/Q structure)
uint8_t *m_frameBuffer; //!< Buffer to build a frame length of raw samples
uint32_t m_bytesInBlock; //!< Number of bytes received in the current UDP block uint32_t m_bytesInBlock; //!< Number of bytes received in the current UDP block
uint32_t m_nbBlocks; //!< Number of UDP blocks received in the current frame uint32_t m_nbBlocks; //!< Number of UDP blocks received in the current frame
}; };

View File

@ -88,28 +88,6 @@ SDRdaemonInput::~SDRdaemonInput()
stop(); stop();
} }
void SDRdaemonInput::openFileStream()
{
qDebug() << "SDRdaemonInput::openFileStream: " << m_fileName.toStdString().c_str();
//stopInput();
if (m_ifstream.is_open()) {
m_ifstream.close();
}
m_ifstream.open(m_fileName.toStdString().c_str(), std::ios::binary);
FileSink::Header header;
FileSink::readHeader(m_ifstream, header);
m_sampleRate = header.sampleRate;
m_centerFrequency = header.centerFrequency;
m_startingTimeStamp = header.startTimeStamp;
MsgReportSDRdaemonStreamData *report = MsgReportSDRdaemonStreamData::create(m_sampleRate, m_centerFrequency, m_startingTimeStamp); // file stream data
getOutputMessageQueueToGUI()->push(report);
}
bool SDRdaemonInput::init(const Message& message) bool SDRdaemonInput::init(const Message& message)
{ {
return false; return false;
@ -120,19 +98,12 @@ bool SDRdaemonInput::start(int device)
QMutexLocker mutexLocker(&m_mutex); QMutexLocker mutexLocker(&m_mutex);
qDebug() << "SDRdaemonInput::startInput"; qDebug() << "SDRdaemonInput::startInput";
if (m_ifstream.tellg() != 0) {
m_ifstream.clear();
m_ifstream.seekg(0, std::ios::beg);
}
if(!m_sampleFifo.setSize(96000 * 4)) { if(!m_sampleFifo.setSize(96000 * 4)) {
qCritical("Could not allocate SampleFifo"); qCritical("Could not allocate SampleFifo");
return false; return false;
} }
//openFileStream(); if((m_SDRdaemonThread = new SDRdaemonThread(&m_sampleFifo)) == NULL) {
if((m_SDRdaemonThread = new SDRdaemonThread(&m_ifstream, &m_sampleFifo)) == NULL) {
qFatal("out of memory"); qFatal("out of memory");
stop(); stop();
return false; return false;
@ -197,7 +168,6 @@ bool SDRdaemonInput::handleMessage(const Message& message)
{ {
MsgConfigureSDRdaemonName& conf = (MsgConfigureSDRdaemonName&) message; MsgConfigureSDRdaemonName& conf = (MsgConfigureSDRdaemonName&) message;
m_fileName = conf.getFileName(); m_fileName = conf.getFileName();
openFileStream();
return true; return true;
} }
else if (MsgConfigureSDRdaemonWork::match(message)) else if (MsgConfigureSDRdaemonWork::match(message))
@ -259,13 +229,6 @@ bool SDRdaemonInput::applySettings(const Settings& settings, bool force)
} }
} }
if (m_ifstream.is_open())
{
m_ifstream.close();
}
openFileStream();
if (m_SDRdaemonThread != 0) if (m_SDRdaemonThread != 0)
{ {
m_SDRdaemonThread->setSamplerate(m_sampleRate); m_SDRdaemonThread->setSamplerate(m_sampleRate);
@ -280,7 +243,6 @@ bool SDRdaemonInput::applySettings(const Settings& settings, bool force)
DSPEngine::instance()->getInputMessageQueue()->push(notif); DSPEngine::instance()->getInputMessageQueue()->push(notif);
qDebug() << "SDRdaemonInput::applySettings:" qDebug() << "SDRdaemonInput::applySettings:"
<< " file name: " << settings.m_fileName.toStdString().c_str()
<< " center freq: " << m_centerFrequency << " Hz" << " center freq: " << m_centerFrequency << " Hz"
<< " sample rate: " << m_sampleRate << " sample rate: " << m_sampleRate
<< " Unix timestamp: " << m_startingTimeStamp; << " Unix timestamp: " << m_startingTimeStamp;

View File

@ -22,7 +22,6 @@
#include <QTimer> #include <QTimer>
#include <ctime> #include <ctime>
#include <iostream> #include <iostream>
#include <fstream>
class SDRdaemonThread; class SDRdaemonThread;
@ -197,7 +196,6 @@ public:
private: private:
QMutex m_mutex; QMutex m_mutex;
Settings m_settings; Settings m_settings;
std::ifstream m_ifstream;
SDRdaemonThread* m_SDRdaemonThread; SDRdaemonThread* m_SDRdaemonThread;
QString m_deviceDescription; QString m_deviceDescription;
QString m_fileName; QString m_fileName;
@ -207,7 +205,6 @@ private:
const QTimer& m_masterTimer; const QTimer& m_masterTimer;
bool applySettings(const Settings& settings, bool force); bool applySettings(const Settings& settings, bool force);
void openFileStream();
}; };
#endif // INCLUDE_SDRDAEMONINPUT_H #endif // INCLUDE_SDRDAEMONINPUT_H

View File

@ -26,14 +26,13 @@
const int SDRdaemonThread::m_rateDivider = 1000/SDRDAEMON_THROTTLE_MS; const int SDRdaemonThread::m_rateDivider = 1000/SDRDAEMON_THROTTLE_MS;
const int SDRdaemonThread::m_udpPayloadSize = 512; const int SDRdaemonThread::m_udpPayloadSize = 512;
SDRdaemonThread::SDRdaemonThread(std::ifstream *samplesStream, SampleFifo* sampleFifo, QObject* parent) : SDRdaemonThread::SDRdaemonThread(SampleFifo* sampleFifo, QObject* parent) :
QThread(parent), QThread(parent),
m_running(false), m_running(false),
m_dataSocket(0), m_dataSocket(0),
m_dataAddress(QHostAddress::LocalHost), m_dataAddress(QHostAddress::LocalHost),
m_dataPort(9090), m_dataPort(9090),
m_dataConnected(false), m_dataConnected(false),
m_ifstream(samplesStream),
m_buf(0), m_buf(0),
m_udpBuf(0), m_udpBuf(0),
m_bufsize(0), m_bufsize(0),
@ -43,7 +42,6 @@ SDRdaemonThread::SDRdaemonThread(std::ifstream *samplesStream, SampleFifo* sampl
m_sdrDaemonBuffer(m_udpPayloadSize), m_sdrDaemonBuffer(m_udpPayloadSize),
m_samplerate(0) m_samplerate(0)
{ {
assert(m_ifstream != 0);
m_udpBuf = new char[m_udpPayloadSize]; m_udpBuf = new char[m_udpPayloadSize];
} }
@ -163,23 +161,8 @@ void SDRdaemonThread::tick()
if (m_running) if (m_running)
{ {
// read samples directly feeding the SampleFifo (no callback) // read samples directly feeding the SampleFifo (no callback)
m_ifstream->read(reinterpret_cast<char*>(m_buf), m_chunksize); m_sampleFifo->write(reinterpret_cast<quint8*>(m_sdrDaemonBuffer.readData(m_chunksize)), m_chunksize);
m_samplesCount += m_chunksize / 4;
if (m_ifstream->eof())
{
m_sampleFifo->write(m_buf, m_ifstream->gcount());
// TODO: handle loop playback situation
m_ifstream->clear();
m_ifstream->seekg(0, std::ios::beg);
m_samplesCount = 0;
//stopWork();
//m_ifstream->close();
}
else
{
m_sampleFifo->write(m_buf, m_chunksize);
m_samplesCount += m_chunksize / 4;
}
} }
} }

View File

@ -24,7 +24,6 @@
#include <QHostAddress> #include <QHostAddress>
#include <iostream> #include <iostream>
#include <fstream>
#include <cstdlib> #include <cstdlib>
#include "dsp/samplefifo.h" #include "dsp/samplefifo.h"
#include "dsp/inthalfbandfilter.h" #include "dsp/inthalfbandfilter.h"
@ -38,7 +37,7 @@ class SDRdaemonThread : public QThread {
Q_OBJECT Q_OBJECT
public: public:
SDRdaemonThread(std::ifstream *samplesStream, SampleFifo* sampleFifo, QObject* parent = NULL); SDRdaemonThread(SampleFifo* sampleFifo, QObject* parent = NULL);
~SDRdaemonThread(); ~SDRdaemonThread();
void startWork(); void startWork();
@ -57,7 +56,6 @@ private:
QWaitCondition m_startWaiter; QWaitCondition m_startWaiter;
bool m_running; bool m_running;
std::ifstream* m_ifstream;
QUdpSocket *m_dataSocket; QUdpSocket *m_dataSocket;
QHostAddress m_dataAddress; QHostAddress m_dataAddress;
int m_dataPort; int m_dataPort;