1
0
mirror of https://github.com/f4exb/sdrangel.git synced 2024-11-04 16:01:14 -05:00

ATV modulator: fixed segfault when there is no GUI message queue

This commit is contained in:
f4exb 2017-10-01 10:12:54 +02:00
parent 35c5d623fd
commit b11cf719d6
5 changed files with 119 additions and 85 deletions

View File

@ -31,9 +31,9 @@ MESSAGE_CLASS_DEFINITION(ATVDemod::MsgReportEffectiveSampleRate, Message)
const int ATVDemod::m_ssbFftLen = 1024; const int ATVDemod::m_ssbFftLen = 1024;
ATVDemod::ATVDemod(BasebandSampleSink* objScopeSink) : ATVDemod::ATVDemod(DeviceSourceAPI *deviceAPI) :
m_objScopeSink(objScopeSink), m_deviceAPI(deviceAPI),
m_objRegisteredATVScreen(NULL), m_registeredATVScreen(NULL),
m_intNumberSamplePerTop(0), m_intNumberSamplePerTop(0),
m_intImageIndex(0), m_intImageIndex(0),
m_intSynchroPoints(0), m_intSynchroPoints(0),
@ -88,7 +88,7 @@ ATVDemod::~ATVDemod()
void ATVDemod::setATVScreen(ATVScreen *objScreen) void ATVDemod::setATVScreen(ATVScreen *objScreen)
{ {
m_objRegisteredATVScreen = objScreen; m_registeredATVScreen = objScreen;
} }
void ATVDemod::configure( void ATVDemod::configure(
@ -207,10 +207,10 @@ void ATVDemod::feed(const SampleVector::const_iterator& begin, const SampleVecto
} }
} }
if ((m_running.m_intVideoTabIndex == 1) && (m_objScopeSink != 0)) // do only if scope tab is selected and scope is available if ((m_running.m_intVideoTabIndex == 1) && (m_scopeSink != 0)) // do only if scope tab is selected and scope is available
{ {
m_objScopeSink->feed(m_objScopeSampleBuffer.begin(), m_objScopeSampleBuffer.end(), false); // m_ssb = positive only m_scopeSink->feed(m_scopeSampleBuffer.begin(), m_scopeSampleBuffer.end(), false); // m_ssb = positive only
m_objScopeSampleBuffer.clear(); m_scopeSampleBuffer.clear();
} }
if (ptrBufferToRelease != 0) if (ptrBufferToRelease != 0)
@ -390,8 +390,8 @@ void ATVDemod::demod(Complex& c)
fltVal = m_running.m_blnInvertVideo ? 1.0f - fltVal : fltVal; fltVal = m_running.m_blnInvertVideo ? 1.0f - fltVal : fltVal;
fltVal = (fltVal < -1.0f) ? -1.0f : (fltVal > 1.0f) ? 1.0f : fltVal; fltVal = (fltVal < -1.0f) ? -1.0f : (fltVal > 1.0f) ? 1.0f : fltVal;
if ((m_running.m_intVideoTabIndex == 1) && (m_objScopeSink != 0)) { // feed scope buffer only if scope is present and visible if ((m_running.m_intVideoTabIndex == 1) && (m_scopeSink != 0)) { // feed scope buffer only if scope is present and visible
m_objScopeSampleBuffer.push_back(Sample(fltVal*32767.0f, 0.0f)); m_scopeSampleBuffer.push_back(Sample(fltVal*32767.0f, 0.0f));
} }
m_fltAmpLineAverage += fltVal; m_fltAmpLineAverage += fltVal;
@ -490,9 +490,9 @@ bool ATVDemod::handleMessage(const Message& cmd)
} }
else else
{ {
if (m_objScopeSink != 0) if (m_scopeSink != 0)
{ {
return m_objScopeSink->handleMessage(cmd); return m_scopeSink->handleMessage(cmd);
} }
else else
{ {
@ -574,8 +574,8 @@ void ATVDemod::applySettings()
m_configPrivate.m_intNumberSamplePerLine = (int) (m_config.m_fltLineDuration * m_config.m_intSampleRate); m_configPrivate.m_intNumberSamplePerLine = (int) (m_config.m_fltLineDuration * m_config.m_intSampleRate);
m_intNumberSamplePerTop = (int) (m_config.m_fltTopDuration * m_config.m_intSampleRate); m_intNumberSamplePerTop = (int) (m_config.m_fltTopDuration * m_config.m_intSampleRate);
m_objRegisteredATVScreen->setRenderImmediate(!(m_config.m_fltFramePerS > 25.0f)); m_registeredATVScreen->setRenderImmediate(!(m_config.m_fltFramePerS > 25.0f));
m_objRegisteredATVScreen->resizeATVScreen( m_registeredATVScreen->resizeATVScreen(
m_configPrivate.m_intNumberSamplePerLine - m_intNumberSamplePerLineSignals, m_configPrivate.m_intNumberSamplePerLine - m_intNumberSamplePerLineSignals,
m_intNumberOfLines - m_intNumberOfBlackLines); m_intNumberOfLines - m_intNumberOfBlackLines);

View File

@ -38,6 +38,7 @@
#include "util/message.h" #include "util/message.h"
#include "atvscreen.h" #include "atvscreen.h"
class DeviceSourceAPI;
class ATVDemod : public BasebandSampleSink class ATVDemod : public BasebandSampleSink
{ {
@ -146,8 +147,9 @@ public:
{ } { }
}; };
ATVDemod(BasebandSampleSink* objScopeSink); ATVDemod(DeviceSourceAPI *deviceAPI);
~ATVDemod(); ~ATVDemod();
void setScopeSink(BasebandSampleSink* scopeSink) { m_scopeSink = scopeSink; }
void configure(MessageQueue* objMessageQueue, void configure(MessageQueue* objMessageQueue,
float fltLineDurationUs, float fltLineDurationUs,
@ -339,13 +341,15 @@ private:
bool m_start; bool m_start;
}; };
DeviceSourceAPI* m_deviceAPI;
//*************** SCOPE *************** //*************** SCOPE ***************
BasebandSampleSink* m_objScopeSink; BasebandSampleSink* m_scopeSink;
SampleVector m_objScopeSampleBuffer; SampleVector m_scopeSampleBuffer;
//*************** ATV PARAMETERS *************** //*************** ATV PARAMETERS ***************
ATVScreen * m_objRegisteredATVScreen; ATVScreen * m_registeredATVScreen;
//int m_intNumberSamplePerLine; //int m_intNumberSamplePerLine;
int m_intNumberSamplePerTop; int m_intNumberSamplePerTop;
@ -429,7 +433,7 @@ private:
inline void processHSkip(float& fltVal, int& intVal) inline void processHSkip(float& fltVal, int& intVal)
{ {
m_objRegisteredATVScreen->setDataColor(m_intColIndex - m_intNumberSaplesPerHSync + m_intNumberSamplePerTop, intVal, intVal, intVal); m_registeredATVScreen->setDataColor(m_intColIndex - m_intNumberSaplesPerHSync + m_intNumberSamplePerTop, intVal, intVal, intVal);
// Horizontal Synchro detection // Horizontal Synchro detection
@ -454,7 +458,7 @@ private:
{ {
//qDebug("VSync: %d %d %d", m_intColIndex, m_intSampleIndex, m_intLineIndex); //qDebug("VSync: %d %d %d", m_intColIndex, m_intSampleIndex, m_intLineIndex);
m_intAvgColIndex = m_intColIndex; m_intAvgColIndex = m_intColIndex;
m_objRegisteredATVScreen->renderImage(0); m_registeredATVScreen->renderImage(0);
m_intImageIndex++; m_intImageIndex++;
m_intLineIndex = 0; m_intLineIndex = 0;
@ -502,7 +506,7 @@ private:
m_fltEffMax = -2000000.0f; m_fltEffMax = -2000000.0f;
} }
m_objRegisteredATVScreen->selectRow(m_intRowIndex); m_registeredATVScreen->selectRow(m_intRowIndex);
m_intLineIndex++; m_intLineIndex++;
m_intRowIndex++; m_intRowIndex++;
} }
@ -590,7 +594,7 @@ private:
if (m_intRowIndex < m_intNumberOfLines) if (m_intRowIndex < m_intNumberOfLines)
{ {
m_objRegisteredATVScreen->selectRow(m_intRowIndex - m_intNumberOfSyncLines); m_registeredATVScreen->selectRow(m_intRowIndex - m_intNumberOfSyncLines);
} }
m_intLineIndex++; m_intLineIndex++;
@ -599,7 +603,7 @@ private:
// Filling pixels // Filling pixels
// +4 is to compensate shift due to hsync amortizing factor of 1/4 // +4 is to compensate shift due to hsync amortizing factor of 1/4
m_objRegisteredATVScreen->setDataColor(m_intColIndex - m_intNumberSaplesPerHSync + m_intNumberSamplePerTop + 4, intVal, intVal, intVal); m_registeredATVScreen->setDataColor(m_intColIndex - m_intNumberSaplesPerHSync + m_intNumberSamplePerTop + 4, intVal, intVal, intVal);
m_intColIndex++; m_intColIndex++;
// Vertical sync and image rendering // Vertical sync and image rendering
@ -618,7 +622,7 @@ private:
if ((m_intLineIndex % 2 == 0) || !m_interleaved) // even => odd image if ((m_intLineIndex % 2 == 0) || !m_interleaved) // even => odd image
{ {
m_objRegisteredATVScreen->renderImage(0); m_registeredATVScreen->renderImage(0);
m_intRowIndex = 1; m_intRowIndex = 1;
} }
else else
@ -626,7 +630,7 @@ private:
m_intRowIndex = 0; m_intRowIndex = 0;
} }
m_objRegisteredATVScreen->selectRow(m_intRowIndex - m_intNumberOfSyncLines); m_registeredATVScreen->selectRow(m_intRowIndex - m_intNumberOfSyncLines);
m_intLineIndex = 0; m_intLineIndex = 0;
m_intImageIndex++; m_intImageIndex++;
} }
@ -643,7 +647,7 @@ private:
{ {
if (m_intImageIndex % 2 == 1) // odd image if (m_intImageIndex % 2 == 1) // odd image
{ {
m_objRegisteredATVScreen->renderImage(0); m_registeredATVScreen->renderImage(0);
if (m_rfRunning.m_enmModulation == ATV_AM) if (m_rfRunning.m_enmModulation == ATV_AM)
{ {
@ -668,7 +672,7 @@ private:
m_intRowIndex = 0; m_intRowIndex = 0;
} }
m_objRegisteredATVScreen->selectRow(m_intRowIndex - m_intNumberOfSyncLines); m_registeredATVScreen->selectRow(m_intRowIndex - m_intNumberOfSyncLines);
m_intLineIndex = 0; m_intLineIndex = 0;
m_intImageIndex++; m_intImageIndex++;
} }

View File

@ -284,7 +284,8 @@ ATVDemodGUI::ATVDemodGUI(PluginAPI* objPluginAPI, DeviceSourceAPI *objDeviceAPI,
connect(this, SIGNAL(menuDoubleClickEvent()), this, SLOT(onMenuDoubleClicked())); connect(this, SIGNAL(menuDoubleClickEvent()), this, SLOT(onMenuDoubleClicked()));
m_scopeVis = new ScopeVisNG(ui->glScope); m_scopeVis = new ScopeVisNG(ui->glScope);
m_atvDemod = new ATVDemod(m_scopeVis); m_atvDemod = new ATVDemod(m_deviceAPI);
m_atvDemod->setScopeSink(m_scopeVis);
m_atvDemod->setMessageQueueToGUI(getInputMessageQueue()); m_atvDemod->setMessageQueueToGUI(getInputMessageQueue());
m_atvDemod->setATVScreen(ui->screenTV); m_atvDemod->setATVScreen(ui->screenTV);

View File

@ -385,6 +385,8 @@ void ATVMod::pullVideo(Real& sample)
time_t start, end; time_t start, end;
cv::Mat frame; cv::Mat frame;
if (getMessageQueueToGUI())
{
MsgReportCameraData *report; MsgReportCameraData *report;
report = MsgReportCameraData::create( report = MsgReportCameraData::create(
camera.m_cameraNumber, camera.m_cameraNumber,
@ -395,6 +397,8 @@ void ATVMod::pullVideo(Real& sample)
camera.m_videoHeight, camera.m_videoHeight,
1); // open splash screen on GUI side 1); // open splash screen on GUI side
getMessageQueueToGUI()->push(report); getMessageQueueToGUI()->push(report);
}
int nbFrames = 0; int nbFrames = 0;
time(&start); time(&start);
@ -414,6 +418,9 @@ void ATVMod::pullVideo(Real& sample)
camera.m_videoFPSCount = camera.m_videoFPSq; camera.m_videoFPSCount = camera.m_videoFPSq;
camera.m_videoPrevFPSCount = 0; camera.m_videoPrevFPSCount = 0;
if (getMessageQueueToGUI())
{
MsgReportCameraData *report;
report = MsgReportCameraData::create( report = MsgReportCameraData::create(
camera.m_cameraNumber, camera.m_cameraNumber,
camera.m_videoFPS, camera.m_videoFPS,
@ -424,6 +431,7 @@ void ATVMod::pullVideo(Real& sample)
2); // close splash screen on GUI side 2); // close splash screen on GUI side
getMessageQueueToGUI()->push(report); getMessageQueueToGUI()->push(report);
} }
}
else if (camera.m_videoFPS == 0.0f) // Hideous hack for windows else if (camera.m_videoFPS == 0.0f) // Hideous hack for windows
{ {
camera.m_videoFPS = 5.0f; camera.m_videoFPS = 5.0f;
@ -431,6 +439,8 @@ void ATVMod::pullVideo(Real& sample)
camera.m_videoFPSCount = camera.m_videoFPSq; camera.m_videoFPSCount = camera.m_videoFPSq;
camera.m_videoPrevFPSCount = 0; camera.m_videoPrevFPSCount = 0;
if (getMessageQueueToGUI())
{
MsgReportCameraData *report; MsgReportCameraData *report;
report = MsgReportCameraData::create( report = MsgReportCameraData::create(
camera.m_cameraNumber, camera.m_cameraNumber,
@ -442,6 +452,7 @@ void ATVMod::pullVideo(Real& sample)
0); 0);
getMessageQueueToGUI()->push(report); getMessageQueueToGUI()->push(report);
} }
}
int fpsIncrement = (int) camera.m_videoFPSCount - camera.m_videoPrevFPSCount; int fpsIncrement = (int) camera.m_videoFPSCount - camera.m_videoPrevFPSCount;
@ -601,9 +612,12 @@ bool ATVMod::handleMessage(const Message& cmd)
framesCount = 0; framesCount = 0;
} }
if (getMessageQueueToGUI())
{
MsgReportVideoFileSourceStreamTiming *report; MsgReportVideoFileSourceStreamTiming *report;
report = MsgReportVideoFileSourceStreamTiming::create(framesCount); report = MsgReportVideoFileSourceStreamTiming::create(framesCount);
getMessageQueueToGUI()->push(report); getMessageQueueToGUI()->push(report);
}
return true; return true;
} }
@ -615,6 +629,9 @@ bool ATVMod::handleMessage(const Message& cmd)
if (index < m_cameras.size()) if (index < m_cameras.size())
{ {
m_cameraIndex = index; m_cameraIndex = index;
if (getMessageQueueToGUI())
{
MsgReportCameraData *report; MsgReportCameraData *report;
report = MsgReportCameraData::create( report = MsgReportCameraData::create(
m_cameras[m_cameraIndex].m_cameraNumber, m_cameras[m_cameraIndex].m_cameraNumber,
@ -626,6 +643,7 @@ bool ATVMod::handleMessage(const Message& cmd)
0); 0);
getMessageQueueToGUI()->push(report); getMessageQueueToGUI()->push(report);
} }
}
return true; return true;
} }
@ -721,10 +739,13 @@ void ATVMod::apply(bool force)
applyStandard(); // set all timings applyStandard(); // set all timings
m_settingsMutex.unlock(); m_settingsMutex.unlock();
if (getMessageQueueToGUI())
{
MsgReportEffectiveSampleRate *report; MsgReportEffectiveSampleRate *report;
report = MsgReportEffectiveSampleRate::create(m_tvSampleRate, m_pointsPerLine); report = MsgReportEffectiveSampleRate::create(m_tvSampleRate, m_pointsPerLine);
getMessageQueueToGUI()->push(report); getMessageQueueToGUI()->push(report);
} }
}
if ((m_config.m_outputSampleRate != m_running.m_outputSampleRate) if ((m_config.m_outputSampleRate != m_running.m_outputSampleRate)
|| (m_config.m_rfOppBandwidth != m_running.m_rfOppBandwidth) || (m_config.m_rfOppBandwidth != m_running.m_rfOppBandwidth)
@ -977,10 +998,13 @@ void ATVMod::openVideo(const QString& fileName)
calculateVideoSizes(); calculateVideoSizes();
m_videoEOF = false; m_videoEOF = false;
if (getMessageQueueToGUI())
{
MsgReportVideoFileSourceStreamData *report; MsgReportVideoFileSourceStreamData *report;
report = MsgReportVideoFileSourceStreamData::create(m_videoFPS, m_videoLength); report = MsgReportVideoFileSourceStreamData::create(m_videoFPS, m_videoLength);
getMessageQueueToGUI()->push(report); getMessageQueueToGUI()->push(report);
} }
}
else else
{ {
qDebug("ATVMod::openVideo: cannot open video file"); qDebug("ATVMod::openVideo: cannot open video file");
@ -1114,6 +1138,9 @@ void ATVMod::getCameraNumbers(std::vector<int>& numbers)
if (m_cameras.size() > 0) if (m_cameras.size() > 0)
{ {
m_cameraIndex = 0; m_cameraIndex = 0;
if (getMessageQueueToGUI())
{
MsgReportCameraData *report; MsgReportCameraData *report;
report = MsgReportCameraData::create( report = MsgReportCameraData::create(
m_cameras[0].m_cameraNumber, m_cameras[0].m_cameraNumber,
@ -1125,6 +1152,7 @@ void ATVMod::getCameraNumbers(std::vector<int>& numbers)
0); 0);
getMessageQueueToGUI()->push(report); getMessageQueueToGUI()->push(report);
} }
}
} }
void ATVMod::mixImageAndText(cv::Mat& image) void ATVMod::mixImageAndText(cv::Mat& image)

View File

@ -19,6 +19,7 @@
#include "util/message.h" #include "util/message.h"
BasebandSampleSource::BasebandSampleSource() : BasebandSampleSource::BasebandSampleSource() :
m_guiMessageQueue(0),
m_sampleFifo(48000) // arbitrary, will be adjusted to match device sink FIFO size m_sampleFifo(48000) // arbitrary, will be adjusted to match device sink FIFO size
{ {
connect(&m_inputMessageQueue, SIGNAL(messageEnqueued()), this, SLOT(handleInputMessages())); connect(&m_inputMessageQueue, SIGNAL(messageEnqueued()), this, SLOT(handleInputMessages()));