From 7b9cb0e9fe0781a03aedf31730407602b3f6de8a Mon Sep 17 00:00:00 2001 From: f4exb Date: Sun, 17 Mar 2019 01:36:44 +0100 Subject: [PATCH] DATV demod: formatted code --- .../channelrx/demoddatv/datvconstellation.h | 42 +- plugins/channelrx/demoddatv/datvdemod.cpp | 687 ++++++++++-------- plugins/channelrx/demoddatv/datvdemod.h | 108 ++- plugins/channelrx/demoddatv/datvdemodgui.cpp | 156 ++-- .../channelrx/demoddatv/datvdemodplugin.cpp | 4 +- plugins/channelrx/demoddatv/datvdemodplugin.h | 2 +- .../channelrx/demoddatv/datvideorender.cpp | 241 +++--- plugins/channelrx/demoddatv/datvideorender.h | 25 +- .../channelrx/demoddatv/datvideostream.cpp | 84 +-- plugins/channelrx/demoddatv/datvvideoplayer.h | 11 +- 10 files changed, 643 insertions(+), 717 deletions(-) diff --git a/plugins/channelrx/demoddatv/datvconstellation.h b/plugins/channelrx/demoddatv/datvconstellation.h index 091bed139..04d7fa0f7 100644 --- a/plugins/channelrx/demoddatv/datvconstellation.h +++ b/plugins/channelrx/demoddatv/datvconstellation.h @@ -24,8 +24,7 @@ #include "leansdr/framework.h" #include "gui/tvscreen.h" -namespace leansdr -{ +namespace leansdr { static const int DEFAULT_GUI_DECIMATION = 64; @@ -41,23 +40,28 @@ template struct datvconstellation: runnable std::vector cstln_rows; std::vector cstln_cols; - datvconstellation(scheduler *sch, pipebuf > &_in, T _xymin, T _xymax, const char *_name = 0, TVScreen *objDATVScreen = 0) : - runnable(sch, _name ? _name : _in.name), - xymin(_xymin), - xymax(_xymax), - decimation(DEFAULT_GUI_DECIMATION), - pixels_per_frame(1024), - cstln(0), - m_objDATVScreen(objDATVScreen), - in(_in), - phase(0) + datvconstellation( + scheduler *sch, + pipebuf > &_in, + T _xymin, + T _xymax, + const char *_name = nullptr, + TVScreen *objDATVScreen = nullptr) : + runnable(sch, _name ? _name : _in.name), + xymin(_xymin), + xymax(_xymax), + decimation(DEFAULT_GUI_DECIMATION), + pixels_per_frame(1024), + cstln(0), + m_objDATVScreen(objDATVScreen), + in(_in), + phase(0) { } void run() { //Symbols - while (in.readable() >= pixels_per_frame) { if ((!phase) && m_objDATVScreen) @@ -69,17 +73,18 @@ template struct datvconstellation: runnable for (; p < pend; ++p) { m_objDATVScreen->selectRow(256 * (p->re - xymin) / (xymax - xymin)); - m_objDATVScreen->setDataColor(256 - 256 * ((p->im - xymin) / (xymax - xymin)), 255, 0, 255); + m_objDATVScreen->setDataColor( + 256 - 256 * ((p->im - xymin) / (xymax - xymin)), + 255, 0, 255); } if (cstln && (*cstln)) { // Plot constellation points - std::vector::const_iterator row_it = cstln_rows.begin(); std::vector::const_iterator col_it = cstln_cols.begin(); - for (; (row_it != cstln_rows.end()) && (col_it != cstln_cols.end()); ++row_it, ++col_it) + for (;(row_it != cstln_rows.end()) && (col_it != cstln_cols.end()); ++row_it, ++col_it) { m_objDATVScreen->selectRow(*row_it); m_objDATVScreen->setDataColor(*col_it, 250, 250, 5); @@ -91,8 +96,7 @@ template struct datvconstellation: runnable in.read(pixels_per_frame); - if (++phase >= decimation) - { + if (++phase >= decimation) { phase = 0; } } @@ -128,6 +132,6 @@ template struct datvconstellation: runnable } }; -} +} // leansdr #endif // DATVCONSTELLATION_H diff --git a/plugins/channelrx/demoddatv/datvdemod.cpp b/plugins/channelrx/demoddatv/datvdemod.cpp index 7d22cd8f6..6b3e51646 100644 --- a/plugins/channelrx/demoddatv/datvdemod.cpp +++ b/plugins/channelrx/demoddatv/datvdemod.cpp @@ -41,8 +41,8 @@ DATVDemod::DATVDemod(DeviceSourceAPI *deviceAPI) : m_deviceAPI(deviceAPI), m_objRegisteredTVScreen(0), m_objRegisteredVideoRender(0), - m_objVideoStream(NULL), - m_objRenderThread(NULL), + m_objVideoStream(nullptr), + m_objRenderThread(nullptr), m_blnRenderingVideo(false), m_blnStartStopVideo(false), m_enmModulation(BPSK /*DATV_FM1*/), @@ -68,13 +68,13 @@ DATVDemod::~DATVDemod() { m_blnInitialized=false; - if(m_objVideoStream!=NULL) + if(m_objVideoStream!=nullptr) { //Immediately exit from DATVideoStream if waiting for data before killing thread m_objVideoStream->ThreadTimeOut=0; } - if(m_objRenderThread!=NULL) + if(m_objRenderThread!=nullptr) { if(m_objRenderThread->isRunning()) { @@ -113,46 +113,40 @@ DATVideostream * DATVDemod::SetVideoRender(DATVideoRender *objScreen) bool DATVDemod::PlayVideo(bool blnStartStop) { - if(m_objVideoStream==NULL) - { + if (m_objVideoStream == nullptr) { return false; } - if(m_objRegisteredVideoRender==NULL) - { + if (m_objRegisteredVideoRender == nullptr) { return false; } - if(m_objRenderThread==NULL) - { + if (m_objRenderThread == nullptr) { return false; } - if (m_blnStartStopVideo && !blnStartStop) - { + if (m_blnStartStopVideo && !blnStartStop) { return true; } - if(blnStartStop==true) - { - m_blnStartStopVideo=true; + if (blnStartStop == true) { + m_blnStartStopVideo = true; } - if(m_objRenderThread->isRunning()) + if (m_objRenderThread->isRunning()) { - if(blnStartStop==true) - { - m_objRenderThread->stopRendering(); - } + if (blnStartStop == true) { + m_objRenderThread->stopRendering(); + } - return true; + return true; } - if(m_objVideoStream->bytesAvailable()>0) + if (m_objVideoStream->bytesAvailable() > 0) { - m_objRenderThread->setStreamAndRenderer(m_objRegisteredVideoRender,m_objVideoStream); - m_objVideoStream->MultiThreaded=true; - m_objVideoStream->ThreadTimeOut=5000; //5000 ms + m_objRenderThread->setStreamAndRenderer(m_objRegisteredVideoRender, m_objVideoStream); + m_objVideoStream->MultiThreaded = true; + m_objVideoStream->ThreadTimeOut = 5000; //5000 ms m_objRenderThread->start(); } @@ -160,41 +154,41 @@ bool DATVDemod::PlayVideo(bool blnStartStop) } void DATVDemod::configure(MessageQueue* objMessageQueue, - int intRFBandwidth, - int intCenterFrequency, - dvb_version enmStandard, - DATVModulation enmModulation, - leansdr::code_rate enmFEC, - int intSymbolRate, - int intNotchFilters, - bool blnAllowDrift, - bool blnFastLock, - dvb_sampler enmFilter, - bool blnHardMetric, - float fltRollOff, - bool blnViterbi, - int intExcursion) + int intRFBandwidth, + int intCenterFrequency, + dvb_version enmStandard, + DATVModulation enmModulation, + leansdr::code_rate enmFEC, + int intSymbolRate, + int intNotchFilters, + bool blnAllowDrift, + bool blnFastLock, + dvb_sampler enmFilter, + bool blnHardMetric, + float fltRollOff, + bool blnViterbi, + int intExcursion) { Message* msgCmd = MsgConfigureDATVDemod::create(intRFBandwidth,intCenterFrequency,enmStandard, enmModulation, enmFEC, intSymbolRate, intNotchFilters, blnAllowDrift,blnFastLock,enmFilter,blnHardMetric,fltRollOff, blnViterbi,intExcursion); objMessageQueue->push(msgCmd); } void DATVDemod::InitDATVParameters(int intMsps, - int intRFBandwidth, - int intCenterFrequency, - dvb_version enmStandard, - DATVModulation enmModulation, - leansdr::code_rate enmFEC, - int intSampleRate, - int intSymbolRate, - int intNotchFilters, - bool blnAllowDrift, - bool blnFastLock, - dvb_sampler enmFilter, - bool blnHardMetric, - float fltRollOff, - bool blnViterbi, - int intExcursion) + int intRFBandwidth, + int intCenterFrequency, + dvb_version enmStandard, + DATVModulation enmModulation, + leansdr::code_rate enmFEC, + int intSampleRate, + int intSymbolRate, + int intNotchFilters, + bool blnAllowDrift, + bool blnFastLock, + dvb_sampler enmFilter, + bool blnHardMetric, + float fltRollOff, + bool blnViterbi, + int intExcursion) { Real fltLowCut; Real fltHiCut; @@ -238,9 +232,9 @@ void DATVDemod::InitDATVParameters(int intMsps, void DATVDemod::CleanUpDATVFramework(bool blnRelease) { - if(blnRelease==true) + if (blnRelease == true) { - if(m_objScheduler!=NULL) + if (m_objScheduler != nullptr) { m_objScheduler->shutdown(); delete m_objScheduler; @@ -248,196 +242,279 @@ void DATVDemod::CleanUpDATVFramework(bool blnRelease) // NOTCH FILTER - if(r_auto_notch!=NULL) delete r_auto_notch; - if(p_autonotched!=NULL) delete p_autonotched; + if (r_auto_notch != nullptr) { + delete r_auto_notch; + } + if (p_autonotched != nullptr) { + delete p_autonotched; + } // FREQUENCY CORRECTION : DEROTATOR - if(p_derot!=NULL) delete p_derot; - if(r_derot!=NULL) delete r_derot; + if (p_derot != nullptr) { + delete p_derot; + } + if (r_derot != nullptr) { + delete r_derot; + } // CNR ESTIMATION - if(p_cnr!=NULL) delete p_cnr; - if(r_cnr!=NULL) delete r_cnr; + if (p_cnr != nullptr) { + delete p_cnr; + } + if (r_cnr != nullptr) { + delete r_cnr; + } //FILTERING - if(r_resample!=NULL) delete r_resample; - if(p_resampled!=NULL) delete p_resampled; - if(coeffs!=NULL) delete coeffs; + if (r_resample != nullptr) { + delete r_resample; + } + if (p_resampled != nullptr) { + delete p_resampled; + } + if (coeffs != nullptr) { + delete coeffs; + } // OUTPUT PREPROCESSED DATA - if(sampler!=NULL) delete sampler; - if(coeffs_sampler!=NULL) delete coeffs_sampler; - if(p_symbols!=NULL) delete p_symbols; - if(p_freq!=NULL) delete p_freq; - if(p_ss!=NULL) delete p_ss; - if(p_mer!=NULL) delete p_mer; - if(p_sampled!=NULL) delete p_sampled; + if (sampler != nullptr) { + delete sampler; + } + if (coeffs_sampler != nullptr) { + delete coeffs_sampler; + } + if (p_symbols != nullptr) { + delete p_symbols; + } + if (p_freq != nullptr) { + delete p_freq; + } + if (p_ss != nullptr) { + delete p_ss; + } + if (p_mer != nullptr) { + delete p_mer; + } + if (p_sampled != nullptr) { + delete p_sampled; + } //DECIMATION - if(p_decimated!=NULL) delete p_decimated; - if(p_decim!=NULL) delete p_decim; - if(r_ppout!=NULL) delete r_ppout; - + if (p_decimated != nullptr) { + delete p_decimated; + } + if (p_decim != nullptr) { + delete p_decim; + } + if (r_ppout != nullptr) { + delete r_ppout; + } //GENERIC CONSTELLATION RECEIVER - if(m_objDemodulator!=NULL) delete m_objDemodulator; + if (m_objDemodulator != nullptr) { + delete m_objDemodulator; + } //DECONVOLUTION AND SYNCHRONIZATION - if(p_bytes!=NULL) delete p_bytes; - if(r_deconv!=NULL) delete r_deconv; - if(r!=NULL) delete r; - if(p_descrambled!=NULL) delete p_descrambled; - if(p_frames!=NULL) delete p_frames; - if(r_etr192_descrambler!=NULL) delete r_etr192_descrambler; - if(r_sync!=NULL) delete r_sync; - if(p_mpegbytes!=NULL) delete p_mpegbytes; - if(p_lock!=NULL) delete p_lock; - if(p_locktime!=NULL) delete p_locktime; - if(r_sync_mpeg!=NULL) delete r_sync_mpeg; - + if (p_bytes != nullptr) { + delete p_bytes; + } + if (r_deconv != nullptr) { + delete r_deconv; + } + if (r != nullptr) { + delete r; + } + if (p_descrambled != nullptr) { + delete p_descrambled; + } + if (p_frames != nullptr) { + delete p_frames; + } + if (r_etr192_descrambler != nullptr) { + delete r_etr192_descrambler; + } + if (r_sync != nullptr) { + delete r_sync; + } + if (p_mpegbytes != nullptr) { + delete p_mpegbytes; + } + if (p_lock != nullptr) { + delete p_lock; + } + if (p_locktime != nullptr) { + delete p_locktime; + } + if (r_sync_mpeg != nullptr) { + delete r_sync_mpeg; + } // DEINTERLEAVING - if(p_rspackets!=NULL) delete p_rspackets; - if(r_deinter!=NULL) delete r_deinter; - if(p_vbitcount!=NULL) delete p_vbitcount; - if(p_verrcount!=NULL) delete p_verrcount; - if(p_rtspackets!=NULL) delete p_rtspackets; - if(r_rsdec!=NULL) delete r_rsdec; + if (p_rspackets != nullptr) { + delete p_rspackets; + } + if (r_deinter != nullptr) { + delete r_deinter; + } + if (p_vbitcount != nullptr) { + delete p_vbitcount; + } + if (p_verrcount != nullptr) { + delete p_verrcount; + } + if (p_rtspackets != nullptr) { + delete p_rtspackets; + } + if (r_rsdec != nullptr) { + delete r_rsdec; + } //BER ESTIMATION - if(p_vber!=NULL) delete p_vber; - if(r_vber!=NULL) delete r_vber; + if (p_vber != nullptr) { + delete p_vber; + } + if (r_vber != nullptr) { + delete r_vber; + } // DERANDOMIZATION - if(p_tspackets!=NULL) delete p_tspackets; - if(r_derand!=NULL) delete r_derand; - + if (p_tspackets != nullptr) { + delete p_tspackets; + } + if (r_derand != nullptr) { + delete r_derand; + } //OUTPUT : To remove - if(r_stdout!=NULL) delete r_stdout; - if(r_videoplayer!=NULL) delete r_videoplayer; + if (r_stdout != nullptr) { + delete r_stdout; + } + if (r_videoplayer != nullptr) { + delete r_videoplayer; + } //CONSTELLATION - if(r_scope_symbols!=NULL) delete r_scope_symbols; + if (r_scope_symbols != nullptr) { + delete r_scope_symbols; + } // INPUT - //if(p_rawiq!=NULL) delete p_rawiq; - //if(p_rawiq_writer!=NULL) delete p_rawiq_writer; - //if(p_preprocessed!=NULL) delete p_preprocessed; - - + //if(p_rawiq!=nullptr) delete p_rawiq; + //if(p_rawiq_writer!=nullptr) delete p_rawiq_writer; + //if(p_preprocessed!=nullptr) delete p_preprocessed; } - m_objScheduler=NULL; + m_objScheduler=nullptr; // INPUT - p_rawiq = NULL; - p_rawiq_writer = NULL; + p_rawiq = nullptr; + p_rawiq_writer = nullptr; - p_preprocessed = NULL; + p_preprocessed = nullptr; // NOTCH FILTER - r_auto_notch = NULL; - p_autonotched = NULL; + r_auto_notch = nullptr; + p_autonotched = nullptr; // FREQUENCY CORRECTION : DEROTATOR - p_derot = NULL; - r_derot=NULL; + p_derot = nullptr; + r_derot=nullptr; // CNR ESTIMATION - p_cnr = NULL; - r_cnr = NULL; + p_cnr = nullptr; + r_cnr = nullptr; //FILTERING - r_resample = NULL; - p_resampled = NULL; - coeffs = NULL; + r_resample = nullptr; + p_resampled = nullptr; + coeffs = nullptr; ncoeffs=0; // OUTPUT PREPROCESSED DATA - sampler = NULL; - coeffs_sampler=NULL; + sampler = nullptr; + coeffs_sampler=nullptr; ncoeffs_sampler=0; - p_symbols = NULL; - p_freq = NULL; - p_ss = NULL; - p_mer = NULL; - p_sampled = NULL; + p_symbols = nullptr; + p_freq = nullptr; + p_ss = nullptr; + p_mer = nullptr; + p_sampled = nullptr; //DECIMATION - p_decimated = NULL; - p_decim = NULL; - r_ppout = NULL; + p_decimated = nullptr; + p_decim = nullptr; + r_ppout = nullptr; //GENERIC CONSTELLATION RECEIVER - m_objDemodulator = NULL; + m_objDemodulator = nullptr; //DECONVOLUTION AND SYNCHRONIZATION - p_bytes=NULL; - r_deconv=NULL; - r = NULL; + p_bytes=nullptr; + r_deconv=nullptr; + r = nullptr; - p_descrambled = NULL; - p_frames = NULL; - r_etr192_descrambler = NULL; - r_sync = NULL; + p_descrambled = nullptr; + p_frames = nullptr; + r_etr192_descrambler = nullptr; + r_sync = nullptr; - p_mpegbytes = NULL; - p_lock = NULL; - p_locktime = NULL; - r_sync_mpeg = NULL; + p_mpegbytes = nullptr; + p_lock = nullptr; + p_locktime = nullptr; + r_sync_mpeg = nullptr; // DEINTERLEAVING - p_rspackets = NULL; - r_deinter = NULL; + p_rspackets = nullptr; + r_deinter = nullptr; - p_vbitcount = NULL; - p_verrcount = NULL; - p_rtspackets = NULL; - r_rsdec = NULL; + p_vbitcount = nullptr; + p_verrcount = nullptr; + p_rtspackets = nullptr; + r_rsdec = nullptr; //BER ESTIMATION - p_vber = NULL; - r_vber = NULL; + p_vber = nullptr; + r_vber = nullptr; // DERANDOMIZATION - p_tspackets = NULL; - r_derand = NULL; + p_tspackets = nullptr; + r_derand = nullptr; //OUTPUT : To remove - r_stdout = NULL; - r_videoplayer = NULL; + r_stdout = nullptr; + r_videoplayer = nullptr; //CONSTELLATION - r_scope_symbols = NULL; + r_scope_symbols = nullptr; } void DATVDemod::InitDATVFramework() { - m_blnDVBInitialized=false; - m_lngReadIQ=0; + m_blnDVBInitialized = false; + m_lngReadIQ = 0; CleanUpDATVFramework(false); qDebug() << "DATVDemod::InitDATVParameters:" - << " Msps: " << m_objRunning.intMsps - << " Sample Rate: " << m_objRunning.intSampleRate - << " Symbol Rate: " << m_objRunning.intSymbolRate - << " Modulation: " << m_objRunning.enmModulation - << " Notch Filters: " << m_objRunning.intNotchFilters - << " Allow Drift: " << m_objRunning.blnAllowDrift - << " Fast Lock: " << m_objRunning.blnFastLock - << " Filter: " << m_objRunning.enmFilter - << " HARD METRIC: " << m_objRunning.blnHardMetric - << " RollOff: " << m_objRunning.fltRollOff - << " Viterbi: " << m_objRunning.blnViterbi - << " Excursion: " << m_objRunning.intExcursion; + << " Msps: " << m_objRunning.intMsps + << " Sample Rate: " << m_objRunning.intSampleRate + << " Symbol Rate: " << m_objRunning.intSymbolRate + << " Modulation: " << m_objRunning.enmModulation + << " Notch Filters: " << m_objRunning.intNotchFilters + << " Allow Drift: " << m_objRunning.blnAllowDrift + << " Fast Lock: " << m_objRunning.blnFastLock + << " Filter: " << m_objRunning.enmFilter + << " HARD METRIC: " << m_objRunning.blnHardMetric + << " RollOff: " << m_objRunning.fltRollOff + << " Viterbi: " << m_objRunning.blnViterbi + << " Excursion: " << m_objRunning.intExcursion; m_objCfg.standard = m_objRunning.enmStandard; @@ -447,51 +524,42 @@ void DATVDemod::InitDATVFramework() m_objCfg.fastlock = m_objRunning.blnFastLock; m_objCfg.sampler = m_objRunning.enmFilter; - m_objCfg.rolloff=m_objRunning.fltRollOff; //0...1 - m_objCfg.rrc_rej=(float) m_objRunning.intExcursion; //dB - m_objCfg.rrc_steps=0; //auto + m_objCfg.rolloff = m_objRunning.fltRollOff; //0...1 + m_objCfg.rrc_rej = (float) m_objRunning.intExcursion; //dB + m_objCfg.rrc_steps = 0; //auto switch(m_objRunning.enmModulation) { case BPSK: m_objCfg.constellation = leansdr::cstln_lut<256>::BPSK; - break; - + break; case QPSK: m_objCfg.constellation = leansdr::cstln_lut<256>::QPSK; - break; - + break; case PSK8: m_objCfg.constellation = leansdr::cstln_lut<256>::PSK8; - break; - + break; case APSK16: m_objCfg.constellation = leansdr::cstln_lut<256>::APSK16; - break; - + break; case APSK32: m_objCfg.constellation = leansdr::cstln_lut<256>::APSK32; - break; - + break; case APSK64E: m_objCfg.constellation = leansdr::cstln_lut<256>::APSK64E; - break; - + break; case QAM16: m_objCfg.constellation = leansdr::cstln_lut<256>::QAM16; - break; - + break; case QAM64: m_objCfg.constellation = leansdr::cstln_lut<256>::QAM64; - break; - + break; case QAM256: m_objCfg.constellation = leansdr::cstln_lut<256>::QAM256; - break; - + break; default: m_objCfg.constellation = leansdr::cstln_lut<256>::BPSK; - break; + break; } m_objCfg.allow_drift = m_objRunning.blnAllowDrift; @@ -541,7 +609,7 @@ void DATVDemod::InitDATVFramework() // NOTCH FILTER - if ( m_objCfg.anf>0 ) + if (m_objCfg.anf>0) { p_autonotched = new leansdr::pipebuf(m_objScheduler, "autonotched", BUF_BASEBAND); r_auto_notch = new leansdr::auto_notch(m_objScheduler, *p_preprocessed, *p_autonotched, m_objCfg.anf, 0); @@ -557,7 +625,7 @@ void DATVDemod::InitDATVFramework() p_cnr = new leansdr::pipebuf(m_objScheduler, "cnr", BUF_SLOW); - if ( m_objCfg.cnr==true ) + if (m_objCfg.cnr == true) { r_cnr = new leansdr::cnr_fft(m_objScheduler, *p_preprocessed, *p_cnr, m_objCfg.Fm/m_objCfg.Fs); r_cnr->decimation = decimation(m_objCfg.Fs, 1); // 1 Hz @@ -586,21 +654,17 @@ void DATVDemod::InitDATVFramework() p_mer = new leansdr::pipebuf (m_objScheduler, "MER", BUF_SLOW); p_sampled = new leansdr::pipebuf (m_objScheduler, "PSK symbols", BUF_BASEBAND); - switch ( m_objCfg.sampler ) + switch (m_objCfg.sampler) { case SAMP_NEAREST: sampler = new leansdr::nearest_sampler(); break; - case SAMP_LINEAR: sampler = new leansdr::linear_sampler(); break; - case SAMP_RRC: { - - - if ( m_objCfg.rrc_steps == 0 ) + if (m_objCfg.rrc_steps == 0) { // At least 64 discrete sampling points between symbols m_objCfg.rrc_steps = std::max(1, (int)(64*m_objCfg.Fm / m_objCfg.Fs)); @@ -610,38 +674,44 @@ void DATVDemod::InitDATVFramework() float transition = (m_objCfg.Fm/2) * m_objCfg.rolloff; int order = m_objCfg.rrc_rej * Frrc / (22*transition); ncoeffs_sampler = leansdr::filtergen::root_raised_cosine(order, m_objCfg.Fm/Frrc, m_objCfg.rolloff, &coeffs_sampler); - sampler = new leansdr::fir_sampler(ncoeffs_sampler, coeffs_sampler, m_objCfg.rrc_steps); break; } - default: qCritical("DATVDemod::InitDATVFramework: Interpolator not implemented"); return; } - m_objDemodulator = new leansdr::cstln_receiver(m_objScheduler, sampler, *p_preprocessed, *p_symbols, p_freq, p_ss, p_mer, p_sampled); + m_objDemodulator = new leansdr::cstln_receiver( + m_objScheduler, + sampler, + *p_preprocessed, + *p_symbols, + p_freq, + p_ss, + p_mer, + p_sampled); - if ( m_objCfg.standard == DVB_S ) + if (m_objCfg.standard == DVB_S) { - if ( m_objCfg.constellation != leansdr::cstln_lut<256>::QPSK && m_objCfg.constellation != leansdr::cstln_lut<256>::BPSK ) - { - fprintf(stderr, "Warning: non-standard constellation for DVB-S\n"); - } + if ( m_objCfg.constellation != leansdr::cstln_lut<256>::QPSK + && m_objCfg.constellation != leansdr::cstln_lut<256>::BPSK ) + { + qWarning("DATVDemod::InitDATVFramework: non-standard constellation for DVB-S"); + } } - if ( m_objCfg.standard == DVB_S2 ) + if (m_objCfg.standard == DVB_S2) { - // For DVB-S2 testing only. - // Constellation should be determined from PL signalling. - fprintf(stderr, "DVB-S2: Testing symbol sampler only.\n"); + // For DVB-S2 testing only. + // Constellation should be determined from PL signalling. + qDebug("DATVDemod::InitDATVFramework: DVB-S2: Testing symbol sampler only."); } m_objDemodulator->cstln = make_dvbs2_constellation(m_objCfg.constellation, m_objCfg.fec); - if ( m_objCfg.hard_metric ) - { - m_objDemodulator->cstln->harden(); + if (m_objCfg.hard_metric) { + m_objDemodulator->cstln->harden(); } m_objDemodulator->set_omega(m_objCfg.Fs/m_objCfg.Fm); @@ -651,27 +721,23 @@ void DATVDemod::InitDATVFramework() // m_objDemodulator->set_freq(m_objCfg.Ftune/m_objCfg.Fs); //} - if ( m_objCfg.allow_drift ) - { - m_objDemodulator->set_allow_drift(true); + if (m_objCfg.allow_drift) { + m_objDemodulator->set_allow_drift(true); } //******** -> if ( m_objCfg.viterbi ) - if ( m_objCfg.viterbi ) - { - m_objDemodulator->pll_adjustment /= 6; + if (m_objCfg.viterbi) { + m_objDemodulator->pll_adjustment /= 6; } - m_objDemodulator->meas_decimation = decimation(m_objCfg.Fs, m_objCfg.Finfo); // TRACKING FILTERS - - if ( r_cnr ) + if (r_cnr) { - r_cnr->freq_tap = &m_objDemodulator->freq_tap; - r_cnr->tap_multiplier = 1.0 / decim; + r_cnr->freq_tap = &m_objDemodulator->freq_tap; + r_cnr->tap_multiplier = 1.0 / decim; } //constellation @@ -679,8 +745,7 @@ void DATVDemod::InitDATVFramework() if (m_objRegisteredTVScreen) { m_objRegisteredTVScreen->resizeTVScreen(256,256); - - r_scope_symbols = new leansdr::datvconstellation(m_objScheduler, *p_sampled, -128,128, NULL, m_objRegisteredTVScreen); + r_scope_symbols = new leansdr::datvconstellation(m_objScheduler, *p_sampled, -128,128, nullptr, m_objRegisteredTVScreen); r_scope_symbols->decimation = 1; r_scope_symbols->cstln = &m_objDemodulator->cstln; r_scope_symbols->calculate_cstln_points(); @@ -690,24 +755,22 @@ void DATVDemod::InitDATVFramework() p_bytes = new leansdr::pipebuf(m_objScheduler, "bytes", BUF_BYTES); - r_deconv = NULL; + r_deconv = nullptr; //******** -> if ( m_objCfg.viterbi ) - if ( m_objCfg.viterbi ) + if (m_objCfg.viterbi) { - if ( m_objCfg.fec == leansdr::FEC23 && (m_objDemodulator->cstln->nsymbols == 4 || m_objDemodulator->cstln->nsymbols == 64) ) - { - m_objCfg.fec = leansdr::FEC46; - } + if (m_objCfg.fec == leansdr::FEC23 && (m_objDemodulator->cstln->nsymbols == 4 || m_objDemodulator->cstln->nsymbols == 64)) { + m_objCfg.fec = leansdr::FEC46; + } - //To uncomment -> Linking Problem : undefined symbol: _ZN7leansdr21viterbi_dec_interfaceIhhiiE6updateEPiS2_ - r = new leansdr::viterbi_sync(m_objScheduler, (*p_symbols), (*p_bytes), m_objDemodulator->cstln, m_objCfg.fec); + //To uncomment -> Linking Problem : undefined symbol: _ZN7leansdr21viterbi_dec_interfaceIhhiiE6updateEPiS2_ + r = new leansdr::viterbi_sync(m_objScheduler, (*p_symbols), (*p_bytes), m_objDemodulator->cstln, m_objCfg.fec); - if ( m_objCfg.fastlock ) - { - r->resync_period = 1; - } + if (m_objCfg.fastlock) { + r->resync_period = 1; + } } else { @@ -726,42 +789,37 @@ void DATVDemod::InitDATVFramework() // DEINTERLEAVING - p_rspackets = new leansdr::pipebuf< leansdr::rspacket >(m_objScheduler, "RS-enc packets", BUF_PACKETS); + p_rspackets = new leansdr::pipebuf >(m_objScheduler, "RS-enc packets", BUF_PACKETS); r_deinter = new leansdr::deinterleaver(m_objScheduler, *p_mpegbytes, *p_rspackets); - // REED-SOLOMON p_vbitcount = new leansdr::pipebuf(m_objScheduler, "Bits processed", BUF_PACKETS); p_verrcount = new leansdr::pipebuf(m_objScheduler, "Bits corrected", BUF_PACKETS); p_rtspackets = new leansdr::pipebuf(m_objScheduler, "rand TS packets", BUF_PACKETS); - r_rsdec = new leansdr::rs_decoder (m_objScheduler, *p_rspackets, *p_rtspackets, p_vbitcount, p_verrcount); - + r_rsdec = new leansdr::rs_decoder(m_objScheduler, *p_rspackets, *p_rtspackets, p_vbitcount, p_verrcount); // BER ESTIMATION - /* - p_vber = new pipebuf (m_objScheduler, "VBER", BUF_SLOW); - r_vber = new rate_estimator (m_objScheduler, *p_verrcount, *p_vbitcount, *p_vber); - r_vber->sample_size = m_objCfg.Fm/2; // About twice per second, depending on CR - // Require resolution better than 2E-5 - if ( r_vber->sample_size < 50000 ) - { - r_vber->sample_size = 50000; - } - */ + p_vber = new pipebuf (m_objScheduler, "VBER", BUF_SLOW); + r_vber = new rate_estimator (m_objScheduler, *p_verrcount, *p_vbitcount, *p_vber); + r_vber->sample_size = m_objCfg.Fm/2; // About twice per second, depending on CR + // Require resolution better than 2E-5 + if ( r_vber->sample_size < 50000 ) + { + r_vber->sample_size = 50000; + } + */ // DERANDOMIZATION - p_tspackets = new leansdr::pipebuf(m_objScheduler, "TS packets", BUF_PACKETS); r_derand = new leansdr::derandomizer(m_objScheduler, *p_rtspackets, *p_tspackets); - // OUTPUT - r_videoplayer = new leansdr::datvvideoplayer(m_objScheduler, *p_tspackets,m_objVideoStream); + r_videoplayer = new leansdr::datvvideoplayer(m_objScheduler, *p_tspackets, m_objVideoStream); - m_blnDVBInitialized=true; + m_blnDVBInitialized = true; } void DATVDemod::feed(const SampleVector::const_iterator& begin, const SampleVector::const_iterator& end, bool firstOfBurst) @@ -812,15 +870,10 @@ void DATVDemod::feed(const SampleVector::const_iterator& begin, const SampleVect if (m_blnNeedConfigUpdate) { - m_objSettingsMutex.lock(); - m_blnNeedConfigUpdate=false; - InitDATVFramework(); - m_objSettingsMutex.unlock(); - } @@ -842,8 +895,8 @@ void DATVDemod::feed(const SampleVector::const_iterator& begin, const SampleVect objRF ++; if (m_blnDVBInitialized - && (p_rawiq_writer!=NULL) - && (m_objScheduler!=NULL)) + && (p_rawiq_writer!=nullptr) + && (m_objScheduler!=nullptr)) { p_rawiq_writer->write(objIQ); m_lngReadIQ++; @@ -865,12 +918,10 @@ void DATVDemod::feed(const SampleVector::const_iterator& begin, const SampleVect void DATVDemod::start() { - } void DATVDemod::stop() { - } bool DATVDemod::handleMessage(const Message& cmd) @@ -880,8 +931,8 @@ bool DATVDemod::handleMessage(const Message& cmd) DownChannelizer::MsgChannelizerNotification& objNotif = (DownChannelizer::MsgChannelizerNotification&) cmd; qDebug() << "DATVDemod::handleMessage: MsgChannelizerNotification:" - << " m_intSampleRate: " << objNotif.getSampleRate() - << " m_intFrequencyOffset: " << objNotif.getFrequencyOffset(); + << " m_intSampleRate: " << objNotif.getSampleRate() + << " m_intFrequencyOffset: " << objNotif.getFrequencyOffset(); if (m_objRunning.intMsps != objNotif.getSampleRate()) { @@ -902,7 +953,7 @@ bool DATVDemod::handleMessage(const Message& cmd) cfg.getCenterFrequency()); qDebug() << "DATVDemod::handleMessage: MsgConfigureChannelizer: sampleRate: " << m_channelizer->getInputSampleRate() - << " centerFrequency: " << cfg.getCenterFrequency(); + << " centerFrequency: " << cfg.getCenterFrequency(); return true; } @@ -911,21 +962,21 @@ bool DATVDemod::handleMessage(const Message& cmd) MsgConfigureDATVDemod& objCfg = (MsgConfigureDATVDemod&) cmd; - if((objCfg.m_objMsgConfig.blnAllowDrift != m_objRunning.blnAllowDrift) - || (objCfg.m_objMsgConfig.intRFBandwidth != m_objRunning.intRFBandwidth) - || (objCfg.m_objMsgConfig.intCenterFrequency != m_objRunning.intCenterFrequency) - || (objCfg.m_objMsgConfig.blnFastLock != m_objRunning.blnFastLock) - || (objCfg.m_objMsgConfig.blnHardMetric != m_objRunning.blnHardMetric) - || (objCfg.m_objMsgConfig.enmFilter != m_objRunning.enmFilter) - || (objCfg.m_objMsgConfig.fltRollOff != m_objRunning.fltRollOff) - || (objCfg.m_objMsgConfig.blnViterbi != m_objRunning.blnViterbi) - || (objCfg.m_objMsgConfig.enmFEC != m_objRunning.enmFEC) - || (objCfg.m_objMsgConfig.enmModulation != m_objRunning.enmModulation) - || (objCfg.m_objMsgConfig.enmStandard != m_objRunning.enmStandard) - || (objCfg.m_objMsgConfig.intNotchFilters != m_objRunning.intNotchFilters) - || (objCfg.m_objMsgConfig.intSymbolRate != m_objRunning.intSymbolRate) - || (objCfg.m_objMsgConfig.intExcursion != m_objRunning.intExcursion)) - { + if ((objCfg.m_objMsgConfig.blnAllowDrift != m_objRunning.blnAllowDrift) + || (objCfg.m_objMsgConfig.intRFBandwidth != m_objRunning.intRFBandwidth) + || (objCfg.m_objMsgConfig.intCenterFrequency != m_objRunning.intCenterFrequency) + || (objCfg.m_objMsgConfig.blnFastLock != m_objRunning.blnFastLock) + || (objCfg.m_objMsgConfig.blnHardMetric != m_objRunning.blnHardMetric) + || (objCfg.m_objMsgConfig.enmFilter != m_objRunning.enmFilter) + || (objCfg.m_objMsgConfig.fltRollOff != m_objRunning.fltRollOff) + || (objCfg.m_objMsgConfig.blnViterbi != m_objRunning.blnViterbi) + || (objCfg.m_objMsgConfig.enmFEC != m_objRunning.enmFEC) + || (objCfg.m_objMsgConfig.enmModulation != m_objRunning.enmModulation) + || (objCfg.m_objMsgConfig.enmStandard != m_objRunning.enmStandard) + || (objCfg.m_objMsgConfig.intNotchFilters != m_objRunning.intNotchFilters) + || (objCfg.m_objMsgConfig.intSymbolRate != m_objRunning.intSymbolRate) + || (objCfg.m_objMsgConfig.intExcursion != m_objRunning.intExcursion)) + { m_objRunning.blnAllowDrift = objCfg.m_objMsgConfig.blnAllowDrift; m_objRunning.blnFastLock = objCfg.m_objMsgConfig.blnFastLock; m_objRunning.blnHardMetric = objCfg.m_objMsgConfig.blnHardMetric; @@ -942,26 +993,26 @@ bool DATVDemod::handleMessage(const Message& cmd) m_objRunning.intExcursion = objCfg.m_objMsgConfig.intExcursion; qDebug() << "ATVDemod::handleMessage: MsgConfigureDATVDemod:" - << " blnAllowDrift: " << objCfg.m_objMsgConfig.blnAllowDrift - << " intRFBandwidth: " << objCfg.m_objMsgConfig.intRFBandwidth - << " intCenterFrequency: " << objCfg.m_objMsgConfig.intCenterFrequency - << " blnFastLock: " << objCfg.m_objMsgConfig.blnFastLock - << " enmFilter: " << objCfg.m_objMsgConfig.enmFilter - << " fltRollOff: " << objCfg.m_objMsgConfig.fltRollOff - << " blnViterbi: " << objCfg.m_objMsgConfig.blnViterbi - << " enmFEC: " << objCfg.m_objMsgConfig.enmFEC - << " enmModulation: " << objCfg.m_objMsgConfig.enmModulation - << " enmStandard: " << objCfg.m_objMsgConfig.enmStandard - << " intNotchFilters: " << objCfg.m_objMsgConfig.intNotchFilters - << " intSymbolRate: " << objCfg.m_objMsgConfig.intSymbolRate - << " intRFBandwidth: " << objCfg.m_objMsgConfig.intRFBandwidth - << " intCenterFrequency: " << objCfg.m_objMsgConfig.intCenterFrequency - << " intExcursion: " << objCfg.m_objMsgConfig.intExcursion; + << " blnAllowDrift: " << objCfg.m_objMsgConfig.blnAllowDrift + << " intRFBandwidth: " << objCfg.m_objMsgConfig.intRFBandwidth + << " intCenterFrequency: " << objCfg.m_objMsgConfig.intCenterFrequency + << " blnFastLock: " << objCfg.m_objMsgConfig.blnFastLock + << " enmFilter: " << objCfg.m_objMsgConfig.enmFilter + << " fltRollOff: " << objCfg.m_objMsgConfig.fltRollOff + << " blnViterbi: " << objCfg.m_objMsgConfig.blnViterbi + << " enmFEC: " << objCfg.m_objMsgConfig.enmFEC + << " enmModulation: " << objCfg.m_objMsgConfig.enmModulation + << " enmStandard: " << objCfg.m_objMsgConfig.enmStandard + << " intNotchFilters: " << objCfg.m_objMsgConfig.intNotchFilters + << " intSymbolRate: " << objCfg.m_objMsgConfig.intSymbolRate + << " intRFBandwidth: " << objCfg.m_objMsgConfig.intRFBandwidth + << " intCenterFrequency: " << objCfg.m_objMsgConfig.intCenterFrequency + << " intExcursion: " << objCfg.m_objMsgConfig.intExcursion; ApplySettings(); } - return true; + return true; } else { @@ -971,31 +1022,29 @@ bool DATVDemod::handleMessage(const Message& cmd) void DATVDemod::ApplySettings() { - if(m_objRunning.intMsps==0) - { + if (m_objRunning.intMsps == 0) { return; } InitDATVParameters(m_objRunning.intMsps, - m_objRunning.intRFBandwidth, - m_objRunning.intCenterFrequency, - m_objRunning.enmStandard, - m_objRunning.enmModulation, - m_objRunning.enmFEC, - m_objRunning.intSampleRate, - m_objRunning.intSymbolRate, - m_objRunning.intNotchFilters, - m_objRunning.blnAllowDrift, - m_objRunning.blnFastLock, - m_objRunning.enmFilter, - m_objRunning.blnHardMetric, - m_objRunning.fltRollOff, - m_objRunning.blnViterbi, - m_objRunning.intExcursion); + m_objRunning.intRFBandwidth, + m_objRunning.intCenterFrequency, + m_objRunning.enmStandard, + m_objRunning.enmModulation, + m_objRunning.enmFEC, + m_objRunning.intSampleRate, + m_objRunning.intSymbolRate, + m_objRunning.intNotchFilters, + m_objRunning.blnAllowDrift, + m_objRunning.blnFastLock, + m_objRunning.enmFilter, + m_objRunning.blnHardMetric, + m_objRunning.fltRollOff, + m_objRunning.blnViterbi, + m_objRunning.intExcursion); } int DATVDemod::GetSampleRate() { return m_objRunning.intMsps; } - diff --git a/plugins/channelrx/demoddatv/datvdemod.h b/plugins/channelrx/demoddatv/datvdemod.h index 8bccb0ca9..5473fab04 100644 --- a/plugins/channelrx/demoddatv/datvdemod.h +++ b/plugins/channelrx/demoddatv/datvdemod.h @@ -73,59 +73,59 @@ inline int decimation(float Fin, float Fout) { int d = Fin / Fout; return std::m struct config { - dvb_version standard; - dvb_sampler sampler; + dvb_version standard; + dvb_sampler sampler; - int buf_factor; // Buffer sizing - float Fs; // Sampling frequency (Hz) - float Fderot; // Shift the signal (Hz). Note: Ftune is faster - int anf; // Number of auto notch filters - bool cnr; // Measure CNR - unsigned int decim; // Decimation, 0=auto - float Fm; // QPSK symbol rate (Hz) - leansdr::cstln_lut<256>::predef constellation; - leansdr::code_rate fec; - float Ftune; // Bias frequency for the QPSK demodulator (Hz) - bool allow_drift; - bool fastlock; - bool viterbi; - bool hard_metric; - bool resample; - float resample_rej; // Approx. filter rejection in dB - int rrc_steps; // Discrete steps between symbols, 0=auto - float rrc_rej; // Approx. RRC filter rejection in dB - float rolloff; // Roll-off 0..1 - bool hdlc; // Expect HDLC frames instead of MPEG packets - bool packetized; // Output frames with 16-bit BE length - float Finfo; // Desired refresh rate on fd_info (Hz) + int buf_factor; // Buffer sizing + float Fs; // Sampling frequency (Hz) + float Fderot; // Shift the signal (Hz). Note: Ftune is faster + int anf; // Number of auto notch filters + bool cnr; // Measure CNR + unsigned int decim; // Decimation, 0=auto + float Fm; // QPSK symbol rate (Hz) + leansdr::cstln_lut<256>::predef constellation; + leansdr::code_rate fec; + float Ftune; // Bias frequency for the QPSK demodulator (Hz) + bool allow_drift; + bool fastlock; + bool viterbi; + bool hard_metric; + bool resample; + float resample_rej; // Approx. filter rejection in dB + int rrc_steps; // Discrete steps between symbols, 0=auto + float rrc_rej; // Approx. RRC filter rejection in dB + float rolloff; // Roll-off 0..1 + bool hdlc; // Expect HDLC frames instead of MPEG packets + bool packetized; // Output frames with 16-bit BE length + float Finfo; // Desired refresh rate on fd_info (Hz) - config() : - standard(DVB_S), - sampler(SAMP_LINEAR), - buf_factor(4), - Fs(2.4e6), - Fderot(0), - anf(0), - cnr(false), - decim(0), - Fm(2e6), - constellation(leansdr::cstln_lut<256>::QPSK), - fec(leansdr::FEC12), - Ftune(0), - allow_drift(false), - fastlock(true), - viterbi(false), - hard_metric(false), - resample(false), - resample_rej(10), - rrc_steps(0), - rrc_rej(10), - rolloff(0.35), - hdlc(false), - packetized(false), - Finfo(5) - { - } + config() : + standard(DVB_S), + sampler(SAMP_LINEAR), + buf_factor(4), + Fs(2.4e6), + Fderot(0), + anf(0), + cnr(false), + decim(0), + Fm(2e6), + constellation(leansdr::cstln_lut<256>::QPSK), + fec(leansdr::FEC12), + Ftune(0), + allow_drift(false), + fastlock(true), + viterbi(false), + hard_metric(false), + resample(false), + resample_rej(10), + rrc_steps(0), + rrc_rej(10), + rolloff(0.35), + hdlc(false), + packetized(false), + Finfo(5) + { + } }; @@ -240,7 +240,6 @@ public: static const QString m_channelIdURI; static const QString m_channelId; - class MsgConfigureChannelizer : public Message { MESSAGE_CLASS_DECLARATION @@ -248,8 +247,7 @@ public: public: int getCenterFrequency() const { return m_centerFrequency; } - static MsgConfigureChannelizer* create(int centerFrequency) - { + static MsgConfigureChannelizer* create(int centerFrequency) { return new MsgConfigureChannelizer(centerFrequency); } @@ -259,7 +257,7 @@ public: MsgConfigureChannelizer(int centerFrequency) : Message(), m_centerFrequency(centerFrequency) - { } + {} }; private: diff --git a/plugins/channelrx/demoddatv/datvdemodgui.cpp b/plugins/channelrx/demoddatv/datvdemodgui.cpp index 090a407db..fd91cc2de 100644 --- a/plugins/channelrx/demoddatv/datvdemodgui.cpp +++ b/plugins/channelrx/demoddatv/datvdemodgui.cpp @@ -309,16 +309,13 @@ DATVDemodGUI::DATVDemodGUI(PluginAPI* objPluginAPI, DeviceUISet *deviceUISet, Ba ui->pushButton_3->setIcon(style()->standardIcon(QStyle::SP_MediaPlay)); resetToDefaults(); // does applySettings() - } DATVDemodGUI::~DATVDemodGUI() { - m_deviceUISet->removeRxChannelInstance(this); delete m_objDATVDemod; delete ui; - } void DATVDemodGUI::blockApplySettings(bool blnBlock) @@ -350,125 +347,83 @@ void DATVDemodGUI::applySettings() strStandard = ui->cmbStandard->currentText(); - if(strStandard=="DVB-S") - { + if(strStandard=="DVB-S") { enmVersion=DVB_S; - } - else if (strStandard=="DVB-S2") - { + } else if (strStandard=="DVB-S2") { enmVersion=DVB_S2; - } - else - { + } else { enmVersion=DVB_S; } - //BPSK, QPSK, PSK8, APSK16, APSK32, APSK64E, QAM16, QAM64, QAM256 strModulation = ui->cmbModulation->currentText(); - if(strModulation=="BPSK") - { + if(strModulation=="BPSK") { enmSelectedModulation=BPSK; } - else if(strModulation=="QPSK") - { + else if(strModulation=="QPSK") { enmSelectedModulation=QPSK; } - else if(strModulation=="8PSK") - { + else if(strModulation=="8PSK") { enmSelectedModulation=PSK8; } - else if(strModulation=="16APSK") - { + else if(strModulation=="16APSK") { enmSelectedModulation=APSK16; } - else if(strModulation=="32APSK") - { + else if(strModulation=="32APSK") { enmSelectedModulation=APSK32; } - else if(strModulation=="64APSKE") - { + else if(strModulation=="64APSKE") { enmSelectedModulation=APSK64E; } - else if(strModulation=="16QAM") - { + else if(strModulation=="16QAM") { enmSelectedModulation=QAM16; } - else if(strModulation=="64QAM") - { + else if(strModulation=="64QAM") { enmSelectedModulation=QAM64; } - else if(strModulation=="256QAM") - { + else if(strModulation=="256QAM") { enmSelectedModulation=QAM256; - } - else - { + } else { enmSelectedModulation=BPSK; } //Viterbi only for BPSK et QPSK - if((enmSelectedModulation!=BPSK) && (enmSelectedModulation!=QPSK)) - { + if ((enmSelectedModulation!=BPSK) && (enmSelectedModulation!=QPSK)) { ui->chkViterbi->setChecked(false); } - strFEC = ui->cmbFEC->currentText(); - if(strFEC == "1/2") - { + if (strFEC == "1/2") { enmFEC = leansdr::FEC12; - } - else if(strFEC == "2/3") - { + } else if (strFEC == "2/3") { enmFEC = leansdr::FEC23; - } - else if(strFEC == "3/4") - { + } else if (strFEC == "3/4") { enmFEC = leansdr::FEC34; - } - else if(strFEC == "5/6") - { + } else if (strFEC == "5/6") { enmFEC = leansdr::FEC56; - } - else if(strFEC == "7/8") - { + } else if (strFEC == "7/8") { enmFEC = leansdr::FEC78; - } - else if(strFEC == "4/5") - { + } else if (strFEC == "4/5") { enmFEC = leansdr::FEC45; - } - else if(strFEC == "8/9") - { + } else if (strFEC == "8/9") { enmFEC = leansdr::FEC89; - } - else if(strFEC == "9/10") - { + } else if (strFEC == "9/10") { enmFEC = leansdr::FEC910; - } - else - { + } else { enmFEC = leansdr::FEC12; } - if (ui->cmbFilter->currentIndex()==0) - { + if (ui->cmbFilter->currentIndex() == 0) { enmSampler = SAMP_LINEAR; - } - else if(ui->cmbFilter->currentIndex()==1) - { + } else if (ui->cmbFilter->currentIndex() == 1) { enmSampler = SAMP_NEAREST; - } - else - { + } else { enmSampler = SAMP_RRC; } - m_objDATVDemod->configure( m_objDATVDemod->getInputMessageQueue(), m_objChannelMarker.getBandwidth(), @@ -487,8 +442,8 @@ void DATVDemodGUI::applySettings() ui->spiExcursion->value()); qDebug() << "DATVDemodGUI::applySettings:" - << " m_objDATVDemod->getCenterFrequency: " << m_objDATVDemod->getCenterFrequency() - << " m_objDATVDemod->GetSampleRate: " << m_objDATVDemod->GetSampleRate(); + << " m_objDATVDemod->getCenterFrequency: " << m_objDATVDemod->getCenterFrequency() + << " m_objDATVDemod->GetSampleRate: " << m_objDATVDemod->GetSampleRate(); } } @@ -675,7 +630,7 @@ void DATVDemodGUI::on_pushButton_3_clicked() m_blnButtonPlayClicked=true; - if(m_objDATVDemod!=NULL) + if(m_objDATVDemod!=nullptr) { m_objDATVDemod->PlayVideo(true); } @@ -695,16 +650,11 @@ void DATVDemodGUI::on_mouseEvent(QMouseEvent* obj) QString DATVDemodGUI::formatBytes(qint64 intBytes) { - if(intBytes<1024) - { + if(intBytes<1024) { return QString("%1").arg(intBytes); - } - else if(intBytes<1024*1024) - { + } else if(intBytes<1024*1024) { return QString("%1 K").arg((float)(10*intBytes/1024)/10.0f); - } - else if(intBytes<1024*1024*1024) - { + } else if(intBytes<1024*1024*1024) { return QString("%1 M").arg((float)(10*intBytes/(1024*1024))/10.0f); } @@ -718,17 +668,13 @@ void DATVDemodGUI::on_StreamDataAvailable(int *intPackets, int *intBytes, int *i ui->lblStatus->setText(QString("Data: %1B").arg(formatBytes(*intTotalReceived))); m_intLastDecodedData = *intTotalReceived; - if((*intPercent)<100) - { - ui->prgSynchro->setValue(*intPercent); - } - else - { - ui->prgSynchro->setValue(100); + if((*intPercent)<100) { + ui->prgSynchro->setValue(*intPercent); + } else { + ui->prgSynchro->setValue(100); } m_intReadyDecodedData = *intBytes; - } void DATVDemodGUI::on_spiBandwidth_valueChanged(int arg1) @@ -758,37 +704,32 @@ void DATVDemodGUI::on_StreamMetaDataChanged(DataTSMetaData2 *objMetaData) { QString strMetaData=""; - if(objMetaData!=NULL) + if (objMetaData != nullptr) { - - if(objMetaData->OK_TransportStream==true) + if (objMetaData->OK_TransportStream == true) { strMetaData.sprintf("PID: %d - Width: %d - Height: %d\r\n%s%s\r\nCodec: %s\r\n", - objMetaData->PID, - objMetaData->Width, - objMetaData->Height, - objMetaData->Program.toStdString().c_str(), - objMetaData->Stream.toStdString().c_str(), - objMetaData->CodecDescription.toStdString().c_str()); + objMetaData->PID, + objMetaData->Width, + objMetaData->Height, + objMetaData->Program.toStdString().c_str(), + objMetaData->Stream.toStdString().c_str(), + objMetaData->CodecDescription.toStdString().c_str()); } - ui->textEdit->setText(strMetaData); + ui->textEdit->setText(strMetaData); ui->chkData->setChecked(objMetaData->OK_Data); ui->chkTS->setChecked(objMetaData->OK_TransportStream); ui->chkVS->setChecked(objMetaData->OK_VideoStream); ui->chkDecoding->setChecked(objMetaData->OK_Decoding); - if(objMetaData->OK_Decoding==true) - { + if (objMetaData->OK_Decoding == true) { ui->pushButton_3->setIcon(style()->standardIcon(QStyle::SP_MediaPause)); - } - else - { + } else { ui->pushButton_3->setIcon(style()->standardIcon(QStyle::SP_MediaPlay)); } - if(objMetaData->Height>0) - { + if (objMetaData->Height > 0) { ui->screenTV_2->setFixedWidth((int)objMetaData->Width*(270.0f/(float)objMetaData->Height)); } } @@ -806,7 +747,6 @@ void DATVDemodGUI::on_cmbFilter_currentIndexChanged(int index) { (void) index; displayRRCParameters((ui->cmbFilter->currentIndex()==2)); - applySettings(); } diff --git a/plugins/channelrx/demoddatv/datvdemodplugin.cpp b/plugins/channelrx/demoddatv/datvdemodplugin.cpp index 0fe293803..c6482406e 100644 --- a/plugins/channelrx/demoddatv/datvdemodplugin.cpp +++ b/plugins/channelrx/demoddatv/datvdemodplugin.cpp @@ -27,7 +27,7 @@ const PluginDescriptor DATVDemodPlugin::m_ptrPluginDescriptor = { QString("DATV Demodulator"), - QString("4.3.1"), + QString("4.5.1"), QString("(c) F4HKW for SDRAngel using LeanSDR framework (c) F4DAV"), QString("https://github.com/f4exb/sdrangel"), true, @@ -36,7 +36,7 @@ const PluginDescriptor DATVDemodPlugin::m_ptrPluginDescriptor = DATVDemodPlugin::DATVDemodPlugin(QObject* ptrParent) : QObject(ptrParent), - m_ptrPluginAPI(NULL) + m_ptrPluginAPI(nullptr) { } diff --git a/plugins/channelrx/demoddatv/datvdemodplugin.h b/plugins/channelrx/demoddatv/datvdemodplugin.h index f2f0ca3ec..b97aea9d6 100644 --- a/plugins/channelrx/demoddatv/datvdemodplugin.h +++ b/plugins/channelrx/demoddatv/datvdemodplugin.h @@ -32,7 +32,7 @@ class DATVDemodPlugin : public QObject, PluginInterface Q_PLUGIN_METADATA(IID "sdrangel.channel.demoddatv") public: - explicit DATVDemodPlugin(QObject* ptrParent = NULL); + explicit DATVDemodPlugin(QObject* ptrParent = nullptr); const PluginDescriptor& getPluginDescriptor() const; void initPlugin(PluginAPI* ptrPluginAPI); diff --git a/plugins/channelrx/demoddatv/datvideorender.cpp b/plugins/channelrx/demoddatv/datvideorender.cpp index 15924f548..39fc6e28a 100644 --- a/plugins/channelrx/demoddatv/datvideorender.cpp +++ b/plugins/channelrx/demoddatv/datvideorender.cpp @@ -26,15 +26,15 @@ DATVideoRender::DATVideoRender(QWidget * parent): m_blnIsFFMPEGInitialized=false; m_blnIsOpen=false; - m_objFormatCtx=NULL; - m_objDecoderCtx=NULL; - m_objSwsCtx=NULL; + m_objFormatCtx=nullptr; + m_objDecoderCtx=nullptr; + m_objSwsCtx=nullptr; m_intVideoStreamIndex=-1; m_intCurrentRenderWidth=-1; m_intCurrentRenderHeight=-1; - m_objFrame=NULL; + m_objFrame=nullptr; m_intFrameCount=-1; } @@ -55,17 +55,15 @@ bool DATVideoRender::eventFilter(QObject *obj, QEvent *event) void DATVideoRender::SetFullScreen(bool blnFullScreen) { - if(m_blnIsFullScreen==blnFullScreen) - { + if (m_blnIsFullScreen == blnFullScreen) { return; } - if(blnFullScreen==true) + if (blnFullScreen == true) { setWindowFlags(Qt::Window); setWindowState(Qt::WindowFullScreen); show(); - m_blnIsFullScreen=true; } else @@ -73,7 +71,6 @@ void DATVideoRender::SetFullScreen(bool blnFullScreen) setWindowFlags(Qt::Widget); setWindowState(Qt::WindowNoState); show(); - m_blnIsFullScreen=false; } } @@ -90,18 +87,15 @@ static int64_t SeekFunction(void* opaque, int64_t offset, int whence) { QIODevice* objStream = reinterpret_cast(opaque); - if (whence == AVSEEK_SIZE) - { + if (whence == AVSEEK_SIZE) { return -1; } - if (objStream->isSequential()) - { + if (objStream->isSequential()) { return -1; } - if (objStream->seek(offset)==false) - { + if (objStream->seek(offset) == false) { return -1; } @@ -131,14 +125,12 @@ bool DATVideoRender::InitializeFFMPEG() { ResetMetaData(); - if(m_blnIsFFMPEGInitialized) - { + if (m_blnIsFFMPEGInitialized) { return false; } avcodec_register_all(); av_register_all(); - av_log_set_level(AV_LOG_FATAL); //av_log_set_level(AV_LOG_ERROR); @@ -149,25 +141,25 @@ bool DATVideoRender::InitializeFFMPEG() bool DATVideoRender::PreprocessStream() { - AVDictionary *objOpts = NULL; - AVCodec *objCodec = NULL; + AVDictionary *objOpts = nullptr; + AVCodec *objCodec = nullptr; int intRet=-1; - char *objBuffer=NULL; + char *objBuffer=nullptr; //Identify stream - if (avformat_find_stream_info(m_objFormatCtx, NULL) < 0) + if (avformat_find_stream_info(m_objFormatCtx, nullptr) < 0) { avformat_close_input(&m_objFormatCtx); - m_objFormatCtx=NULL; + m_objFormatCtx=nullptr; qDebug() << "DATVideoProcess::PreprocessStream cannot find stream info"; return false; } //Find video stream - intRet = av_find_best_stream(m_objFormatCtx, AVMEDIA_TYPE_VIDEO, -1, -1, NULL, 0); + intRet = av_find_best_stream(m_objFormatCtx, AVMEDIA_TYPE_VIDEO, -1, -1, nullptr, 0); if (intRet < 0) { @@ -191,28 +183,24 @@ bool DATVideoRender::PreprocessStream() MetaData.PID = m_objFormatCtx->streams[m_intVideoStreamIndex]->id; MetaData.CodecID = m_objDecoderCtx->codec_id; MetaData.OK_TransportStream = true; - - MetaData.Program=""; MetaData.Stream=""; if(m_objFormatCtx->programs) { - objBuffer=NULL; - + objBuffer=nullptr; av_dict_get_string(m_objFormatCtx->programs[m_intVideoStreamIndex]->metadata,&objBuffer,':','\n'); - if(objBuffer!=NULL) - { + + if(objBuffer!=nullptr) { MetaData.Program = QString("%1").arg(objBuffer); } } - objBuffer=NULL; + objBuffer=nullptr; av_dict_get_string(m_objFormatCtx->streams[m_intVideoStreamIndex]->metadata,&objBuffer,':','\n'); - if(objBuffer!=NULL) - { + if (objBuffer != nullptr) { MetaData.Stream = QString("%1").arg(objBuffer); } @@ -220,10 +208,11 @@ bool DATVideoRender::PreprocessStream() //Decoder objCodec = avcodec_find_decoder(m_objDecoderCtx->codec_id); - if(objCodec==NULL) + + if (objCodec == nullptr) { avformat_close_input(&m_objFormatCtx); - m_objFormatCtx=NULL; + m_objFormatCtx=nullptr; qDebug() << "DATVideoProcess::PreprocessStream cannot find associated CODEC"; return false; @@ -234,7 +223,7 @@ bool DATVideoRender::PreprocessStream() if (avcodec_open2(m_objDecoderCtx, objCodec, &objOpts) < 0) { avformat_close_input(&m_objFormatCtx); - m_objFormatCtx=NULL; + m_objFormatCtx=nullptr; qDebug() << "DATVideoProcess::PreprocessStream cannot open associated CODEC"; return false; @@ -246,21 +235,18 @@ bool DATVideoRender::PreprocessStream() if (!m_objFrame) { avformat_close_input(&m_objFormatCtx); - m_objFormatCtx=NULL; + m_objFormatCtx=nullptr; qDebug() << "DATVideoProcess::PreprocessStream cannot allocate frame"; return false; } m_intFrameCount=0; - - MetaData.Width=m_objDecoderCtx->width; MetaData.Height=m_objDecoderCtx->height; MetaData.BitRate= m_objDecoderCtx->bit_rate; MetaData.Channels=m_objDecoderCtx->channels; MetaData.CodecDescription= QString("%1").arg(objCodec->long_name); - MetaData.OK_VideoStream = true; emit onMetaDataChanged(&MetaData); @@ -271,111 +257,93 @@ bool DATVideoRender::PreprocessStream() bool DATVideoRender::OpenStream(DATVideostream *objDevice) { int intIOBufferSize = 32768; - unsigned char * ptrIOBuffer = NULL; - AVIOContext * objIOCtx = NULL; + unsigned char * ptrIOBuffer = nullptr; + AVIOContext * objIOCtx = nullptr; - if(m_blnRunning) - { + if(m_blnRunning) { return false; } - - if(objDevice==NULL) + if (objDevice == nullptr) { - qDebug() << "DATVideoProcess::OpenStream QIODevice is NULL"; - + qDebug() << "DATVideoProcess::OpenStream QIODevice is nullptr"; return false; } - - if(m_blnIsOpen) + if (m_blnIsOpen) { qDebug() << "DATVideoProcess::OpenStream already open"; - return false; } - if(objDevice->bytesAvailable()<=0) + if (objDevice->bytesAvailable() <= 0) { - qDebug() << "DATVideoProcess::OpenStream no data available"; - - MetaData.OK_Data=false; + MetaData.OK_Data = false; emit onMetaDataChanged(&MetaData); - return false; } //Only once execution - m_blnRunning=true; + m_blnRunning = true; - MetaData.OK_Data=true; + MetaData.OK_Data = true; emit onMetaDataChanged(&MetaData); - InitializeFFMPEG(); - - if(!m_blnIsFFMPEGInitialized) + if (!m_blnIsFFMPEGInitialized) { qDebug() << "DATVideoProcess::OpenStream FFMPEG not initialized"; - - m_blnRunning=false; + m_blnRunning = false; return false; } - if(!objDevice->open(QIODevice::ReadOnly)) + if (!objDevice->open(QIODevice::ReadOnly)) { qDebug() << "DATVideoProcess::OpenStream cannot open QIODevice"; - - m_blnRunning=false; + m_blnRunning = false; return false; } - //Connect QIODevice to FFMPEG Reader m_objFormatCtx = avformat_alloc_context(); - if(m_objFormatCtx==NULL) + if (m_objFormatCtx == nullptr) { qDebug() << "DATVideoProcess::OpenStream cannot alloc format FFMPEG context"; - - m_blnRunning=false; + m_blnRunning = false; return false; } ptrIOBuffer = (unsigned char *)av_malloc(intIOBufferSize+ AV_INPUT_BUFFER_PADDING_SIZE); - objIOCtx = avio_alloc_context( ptrIOBuffer, - intIOBufferSize, - 0, - reinterpret_cast(objDevice), - &ReadFunction, - NULL, - &SeekFunction); + objIOCtx = avio_alloc_context(ptrIOBuffer, + intIOBufferSize, + 0, + reinterpret_cast(objDevice), + &ReadFunction, + nullptr, + &SeekFunction); m_objFormatCtx->pb = objIOCtx; m_objFormatCtx->flags |= AVFMT_FLAG_CUSTOM_IO; - - if (avformat_open_input(&m_objFormatCtx, NULL , NULL, NULL) < 0) + if (avformat_open_input(&m_objFormatCtx, nullptr , nullptr, nullptr) < 0) { qDebug() << "DATVideoProcess::OpenStream cannot open stream"; - m_blnRunning=false; return false; } - if(!PreprocessStream()) + if (!PreprocessStream()) { m_blnRunning=false; return false; } - m_blnIsOpen=true; - m_blnRunning=false; return true; @@ -390,12 +358,10 @@ bool DATVideoRender::RenderStream() if(!m_blnIsOpen) { qDebug() << "DATVideoProcess::RenderStream Stream not open"; - return false; } - if(m_blnRunning) - { + if(m_blnRunning) { return false; } @@ -407,7 +373,6 @@ bool DATVideoRender::RenderStream() if (av_read_frame(m_objFormatCtx, &objPacket) < 0) { qDebug() << "DATVideoProcess::RenderStream reading packet error"; - m_blnRunning=false; return false; } @@ -418,34 +383,31 @@ bool DATVideoRender::RenderStream() memset(m_objFrame, 0, sizeof(AVFrame)); av_frame_unref(m_objFrame); - intGotFrame=0; + intGotFrame = 0; - if(new_decode( m_objDecoderCtx, m_objFrame, &intGotFrame, &objPacket)<0) + if (new_decode( m_objDecoderCtx, m_objFrame, &intGotFrame, &objPacket)<0) { qDebug() << "DATVideoProcess::RenderStream decoding packet error"; - m_blnRunning=false; return false; } - if(intGotFrame) + if (intGotFrame) { //Rendering and RGB Converter setup - blnNeedRenderingSetup=(m_intFrameCount==0); - blnNeedRenderingSetup|=(m_objSwsCtx==NULL); + blnNeedRenderingSetup|=(m_objSwsCtx==nullptr); - if((m_intCurrentRenderWidth!=m_objFrame->width) || (m_intCurrentRenderHeight!=m_objFrame->height)) - { + if ((m_intCurrentRenderWidth!=m_objFrame->width) || (m_intCurrentRenderHeight!=m_objFrame->height)) { blnNeedRenderingSetup=true; } - if(blnNeedRenderingSetup) + if (blnNeedRenderingSetup) { - if(m_objSwsCtx!=NULL) + if (m_objSwsCtx != nullptr) { sws_freeContext(m_objSwsCtx); - m_objSwsCtx=NULL; + m_objSwsCtx=nullptr; } //Convertisseur YUV -> RGB @@ -461,67 +423,57 @@ bool DATVideoRender::RenderStream() av_opt_set_int(m_objSwsCtx,"sws_flag", SWS_FAST_BILINEAR /* SWS_BICUBIC*/,0); - if(sws_init_context(m_objSwsCtx, NULL, NULL)<0) + if (sws_init_context(m_objSwsCtx, nullptr, nullptr) < 0) { qDebug() << "DATVideoProcess::RenderStream cannont init video data converter"; - - m_objSwsCtx=NULL; - + m_objSwsCtx=nullptr; m_blnRunning=false; return false; - } - if((m_intCurrentRenderHeight>0) && (m_intCurrentRenderWidth>0)) + if ((m_intCurrentRenderHeight>0) && (m_intCurrentRenderWidth>0)) { //av_freep(&m_pbytDecodedData[0]); //av_freep(&m_pintDecodedLineSize[0]); } - if(av_image_alloc(m_pbytDecodedData, m_pintDecodedLineSize,m_objFrame->width, m_objFrame->height, AV_PIX_FMT_RGB24, 1)<0) + if (av_image_alloc(m_pbytDecodedData, m_pintDecodedLineSize,m_objFrame->width, m_objFrame->height, AV_PIX_FMT_RGB24, 1)<0) { qDebug() << "DATVideoProcess::RenderStream cannont init video image buffer"; - sws_freeContext(m_objSwsCtx); - m_objSwsCtx=NULL; - + m_objSwsCtx=nullptr; m_blnRunning=false; return false; - } //Rendering device setup - resizeTVScreen(m_objFrame->width,m_objFrame->height); - update(); - resetImage(); + resizeTVScreen(m_objFrame->width,m_objFrame->height); + update(); + resetImage(); - m_intCurrentRenderWidth=m_objFrame->width; - m_intCurrentRenderHeight=m_objFrame->height; + m_intCurrentRenderWidth=m_objFrame->width; + m_intCurrentRenderHeight=m_objFrame->height; - MetaData.Width = m_objFrame->width; - MetaData.Height = m_objFrame->height; - MetaData.OK_Decoding = true; - emit onMetaDataChanged(&MetaData); + MetaData.Width = m_objFrame->width; + MetaData.Height = m_objFrame->height; + MetaData.OK_Decoding = true; + emit onMetaDataChanged(&MetaData); } //Frame rendering - if(sws_scale(m_objSwsCtx, m_objFrame->data, m_objFrame->linesize, 0, m_objFrame->height, m_pbytDecodedData, m_pintDecodedLineSize)<0) + if (sws_scale(m_objSwsCtx, m_objFrame->data, m_objFrame->linesize, 0, m_objFrame->height, m_pbytDecodedData, m_pintDecodedLineSize)<0) { qDebug() << "DATVideoProcess::RenderStream error converting video frame to RGB"; - m_blnRunning=false; return false; } renderImage(m_pbytDecodedData[0]); - av_frame_unref(m_objFrame); - m_intFrameCount ++; } - } av_packet_unref(&objPacket); @@ -536,29 +488,25 @@ bool DATVideoRender::RenderStream() bool DATVideoRender::CloseStream(QIODevice *objDevice) { - if(m_blnRunning) - { + if (m_blnRunning) { return false; } - if(!objDevice) + if (!objDevice) { - qDebug() << "DATVideoProcess::CloseStream QIODevice is NULL"; - + qDebug() << "DATVideoProcess::CloseStream QIODevice is nullptr"; return false; } - if(!m_blnIsOpen) + if (!m_blnIsOpen) { qDebug() << "DATVideoProcess::CloseStream Stream not open"; - return false; } - if(!m_objFormatCtx) + if (!m_objFormatCtx) { qDebug() << "DATVideoProcess::CloseStream FFMEG Context is not initialized"; - return false; } @@ -567,32 +515,29 @@ bool DATVideoRender::CloseStream(QIODevice *objDevice) // maybe done in the avcodec_close // avformat_close_input(&m_objFormatCtx); -// m_objFormatCtx=NULL; +// m_objFormatCtx=nullptr; - if(m_objDecoderCtx) + if (m_objDecoderCtx) { avcodec_close(m_objDecoderCtx); - m_objDecoderCtx=NULL; + m_objDecoderCtx = nullptr; } - if(m_objFrame) + if (m_objFrame) { av_frame_unref(m_objFrame); av_frame_free(&m_objFrame); } - if(m_objSwsCtx!=NULL) + if (m_objSwsCtx != nullptr) { sws_freeContext(m_objSwsCtx); - m_objSwsCtx=NULL; + m_objSwsCtx = nullptr; } objDevice->close(); - m_blnIsOpen=false; - m_blnRunning=false; - m_intCurrentRenderWidth=-1; m_intCurrentRenderHeight=-1; @@ -612,19 +557,25 @@ int DATVideoRender::new_decode(AVCodecContext *avctx, AVFrame *frame, int *got_f *got_frame = 0; - if (pkt) { + if (pkt) + { ret = avcodec_send_packet(avctx, pkt); // In particular, we don't expect AVERROR(EAGAIN), because we read all // decoded frames with avcodec_receive_frame() until done. - if (ret < 0) + if (ret < 0) { return ret == AVERROR_EOF ? 0 : ret; + } } ret = avcodec_receive_frame(avctx, frame); - if (ret < 0 && ret != AVERROR(EAGAIN) && ret != AVERROR_EOF) + + if (ret < 0 && ret != AVERROR(EAGAIN) && ret != AVERROR_EOF) { return ret; - if (ret >= 0) + } + + if (ret >= 0) { *got_frame = 1; + } return 0; } diff --git a/plugins/channelrx/demoddatv/datvideorender.h b/plugins/channelrx/demoddatv/datvideorender.h index 02dddfb3d..081370856 100644 --- a/plugins/channelrx/demoddatv/datvideorender.h +++ b/plugins/channelrx/demoddatv/datvideorender.h @@ -66,22 +66,17 @@ struct DataTSMetaData2 { PID=-1; CodecID=-1; - - Program=""; Stream=""; - Width=-1; Height=-1; BitRate=-1; Channels=-1; CodecDescription=""; - OK_Data=false; OK_Decoding=false; OK_TransportStream=false; OK_VideoStream=false; - } }; @@ -131,18 +126,16 @@ protected: signals: void onMetaDataChanged(DataTSMetaData2 *objMetaData); - }; //To run Video Rendering with a dedicated thread class DATVideoRenderThread: public QThread { - public: DATVideoRenderThread() { - m_objRenderer = NULL; - m_objStream = NULL; + m_objRenderer = nullptr; + m_objStream = nullptr; m_blnRenderingVideo=false; } @@ -162,31 +155,25 @@ class DATVideoRenderThread: public QThread void run() { - if(m_blnRenderingVideo) - { + if (m_blnRenderingVideo) { return; } - if((m_objRenderer==NULL) || (m_objStream==NULL)) - { + if ((m_objRenderer==nullptr) || (m_objStream==nullptr)) { return ; } m_blnRenderingVideo = m_objRenderer->OpenStream(m_objStream); - if(!m_blnRenderingVideo) - { + if (!m_blnRenderingVideo) { return; } - while((m_objRenderer->RenderStream()) && (m_blnRenderingVideo==true)) - { + while ((m_objRenderer->RenderStream()) && (m_blnRenderingVideo == true)) { } m_objRenderer->CloseStream(m_objStream); - m_blnRenderingVideo=false; - } void stopRendering() diff --git a/plugins/channelrx/demoddatv/datvideostream.cpp b/plugins/channelrx/demoddatv/datvideostream.cpp index fbe644ed5..084fac4d1 100644 --- a/plugins/channelrx/demoddatv/datvideostream.cpp +++ b/plugins/channelrx/demoddatv/datvideostream.cpp @@ -22,11 +22,11 @@ DATVideostream::DATVideostream(): m_objMutex(QMutex::NonRecursive) { cleanUp(); - m_intTotalReceived=0; - m_intPacketReceived=0; + m_intTotalReceived = 0; + m_intPacketReceived = 0; m_intMemoryLimit = DefaultMemoryLimit; - MultiThreaded=false; - ThreadTimeOut=-1; + MultiThreaded = false; + ThreadTimeOut = -1; m_objeventLoop.connect(this,SIGNAL(onDataAvailable()), &m_objeventLoop, SLOT(quit()),Qt::QueuedConnection); } @@ -39,72 +39,65 @@ DATVideostream::~DATVideostream() void DATVideostream::cleanUp() { - if(m_objFIFO.size()>0) - { + if (m_objFIFO.size() > 0) { m_objFIFO.clear(); } - if(m_objeventLoop.isRunning()) - { + if (m_objeventLoop.isRunning()) { m_objeventLoop.exit(); } - m_intBytesAvailable=0; - m_intBytesWaiting=0; - m_intQueueWaiting=0; - m_intPercentBuffer=0; + m_intBytesAvailable = 0; + m_intBytesWaiting = 0; + m_intQueueWaiting = 0; + m_intPercentBuffer = 0; } bool DATVideostream::setMemoryLimit(int intMemoryLimit) { - if(intMemoryLimit<=0) - { + if (intMemoryLimit <= 0) { return false; } - m_intMemoryLimit=intMemoryLimit; + m_intMemoryLimit = intMemoryLimit; return true; } int DATVideostream::pushData(const char * chrData, int intSize) { - if(intSize<=0) - { + if (intSize <= 0) { return 0; } m_objMutex.lock(); - m_intPacketReceived ++; - + m_intPacketReceived++; m_intBytesWaiting += intSize; - if(m_intBytesWaiting>m_intMemoryLimit) - { + + if (m_intBytesWaiting > m_intMemoryLimit) { m_intBytesWaiting -= m_objFIFO.dequeue().size(); } m_objFIFO.enqueue(QByteArray(chrData,intSize)); m_intBytesAvailable = m_objFIFO.head().size(); m_intTotalReceived += intSize; - m_intQueueWaiting=m_objFIFO.count(); m_objMutex.unlock(); - if((m_objeventLoop.isRunning()) - && (m_intQueueWaiting>=MinStackSize)) + if ((m_objeventLoop.isRunning()) + && (m_intQueueWaiting >= MinStackSize)) { emit onDataAvailable(); } - if(m_intPacketReceived%MinStackSize==1) + if (m_intPacketReceived % MinStackSize == 1) { - m_intPercentBuffer = (100*m_intBytesWaiting)/m_intMemoryLimit; - if(m_intPercentBuffer>100) - { - m_intPercentBuffer=100; + + if (m_intPercentBuffer > 100) { + m_intPercentBuffer = 100; } emit onDataPackets(&m_intQueueWaiting, &m_intBytesWaiting, &m_intPercentBuffer, &m_intTotalReceived); @@ -140,42 +133,39 @@ bool DATVideostream::open(OpenMode mode) qint64 DATVideostream::readData(char *data, qint64 len) { QByteArray objCurrentArray; - int intEffectiveLen=0; - int intExpectedLen=0; - int intThreadLoop=0; + int intEffectiveLen = 0; + int intExpectedLen = 0; + int intThreadLoop = 0; intExpectedLen = (int) len; - if(intExpectedLen<=0) - { + if (intExpectedLen <= 0) { return 0; } - if(m_objeventLoop.isRunning()) - { + if (m_objeventLoop.isRunning()) { return 0; } m_objMutex.lock(); //DATA in FIFO ? -> Waiting for DATA - if((m_objFIFO.isEmpty()) || (m_objFIFO.count()=0) + if (ThreadTimeOut >= 0) { - if(intThreadLoop*5>ThreadTimeOut) - { + if (intThreadLoop*5 > ThreadTimeOut) { return -1; } } @@ -192,13 +182,13 @@ qint64 DATVideostream::readData(char *data, qint64 len) //Read DATA intEffectiveLen=m_objFIFO.head().size(); - if(intExpectedLen struct datvvideoplayer: runnable { datvvideoplayer(scheduler *sch, pipebuf &_in, DATVideostream * objVideoStream) : - runnable(sch, _in.name), in(_in), m_objVideoStream(objVideoStream) + runnable(sch, _in.name), in(_in), m_objVideoStream(objVideoStream) { } void run() { int size = in.readable() * sizeof(T); - if (!size) + + if (!size) { return; + } int nw = m_objVideoStream->pushData((const char *) in.rd(), size); @@ -43,18 +46,22 @@ template struct datvvideoplayer: runnable fatal("leansdr::datvvideoplayer::run: pipe"); return; } + if (nw < 0) { fatal("leansdr::datvvideoplayer::run: write"); return; } + if (nw % sizeof(T)) { fatal("leansdr::datvvideoplayer::run: partial write"); return; } + in.read(nw / sizeof(T)); } + private: pipereader in; DATVideostream * m_objVideoStream;