diff --git a/plugins/channelrx/demoddatv/datvconstellation.h b/plugins/channelrx/demoddatv/datvconstellation.h index a343cbfe2..2289eb010 100644 --- a/plugins/channelrx/demoddatv/datvconstellation.h +++ b/plugins/channelrx/demoddatv/datvconstellation.h @@ -31,31 +31,24 @@ static const int DEFAULT_GUI_DECIMATION = 64; template struct datvconstellation: runnable { - T xymin; - T xymax; + T xymin, xymax; unsigned long decimation; unsigned long pixels_per_frame; cstln_lut<256> **cstln; // Optional ptr to optional constellation + DATVScreen *m_objDATVScreen; pipereader > in; unsigned long phase; - DATVScreen *m_objDATVScreen; - datvconstellation( - scheduler *sch, - pipebuf > &_in, - T _xymin, - T _xymax, - const char *_name = 0, - DATVScreen * objDATVScreen = 0) : - runnable(sch, _name ? _name : _in.name), - xymin(_xymin), - xymax(_xymax), - decimation(DEFAULT_GUI_DECIMATION), - pixels_per_frame(1024), - cstln(0), - in(_in), - phase(0), - m_objDATVScreen(objDATVScreen) + datvconstellation(scheduler *sch, pipebuf > &_in, T _xymin, T _xymax, const char *_name = NULL, DATVScreen * objDATVScreen = NULL) : + runnable(sch, _name ? _name : _in.name), + xymin(_xymin), + xymax(_xymax), + decimation(DEFAULT_GUI_DECIMATION), + pixels_per_frame(1024), + cstln(NULL), + m_objDATVScreen(objDATVScreen), + in(_in), + phase(0) { } @@ -76,11 +69,8 @@ template struct datvconstellation: runnable if (m_objDATVScreen != NULL) { - m_objDATVScreen->selectRow( - 256 * (p->re - xymin) / (xymax - xymin)); - m_objDATVScreen->setDataColor( - 256 - 256 * ((p->im - xymin) / (xymax - xymin)), - 255, 0, 255); + m_objDATVScreen->selectRow(256 * (p->re - xymin) / (xymax - xymin)); + m_objDATVScreen->setDataColor(256 - 256 * ((p->im - xymin) / (xymax - xymin)), 255, 0, 255); } } @@ -106,7 +96,6 @@ template struct datvconstellation: runnable } m_objDATVScreen->renderImage(NULL); - } in.read(pixels_per_frame); @@ -118,15 +107,8 @@ template struct datvconstellation: runnable } } - //private: - //gfx g; - void draw_begin() { - //g.clear(); - //g.setfg(0, 255, 0); - //g.line(g.w/2,0, g.w/2, g.h); - //g.line(0,g.h/2, g.w,g.h/2); } }; diff --git a/plugins/channelrx/demoddatv/datvdemod.cpp b/plugins/channelrx/demoddatv/datvdemod.cpp index c0a0e0fb2..73a411c6b 100644 --- a/plugins/channelrx/demoddatv/datvdemod.cpp +++ b/plugins/channelrx/demoddatv/datvdemod.cpp @@ -36,23 +36,23 @@ MESSAGE_CLASS_DEFINITION(DATVDemod::MsgConfigureDATVDemod, Message) MESSAGE_CLASS_DEFINITION(DATVDemod::MsgConfigureChannelizer, Message) DATVDemod::DATVDemod(DeviceSourceAPI *deviceAPI) : - ChannelSinkAPI(m_channelIdURI), - m_blnNeedConfigUpdate(false), - m_deviceAPI(deviceAPI), - m_objRegisteredDATVScreen(0), - m_objRegisteredVideoRender(0), - m_objVideoStream(0), - m_objRenderThread(0), - m_blnRenderingVideo(false), - m_enmModulation(BPSK /*DATV_FM1*/), - m_objSettingsMutex(QMutex::NonRecursive) + ChannelSinkAPI(m_channelIdURI), + m_blnNeedConfigUpdate(false), + m_deviceAPI(deviceAPI), + m_objRegisteredDATVScreen(NULL), + m_objRegisteredVideoRender(NULL), + m_objVideoStream(NULL), + m_objRenderThread(NULL), + m_blnRenderingVideo(false), + m_blnStartStopVideo(false), + m_enmModulation(BPSK /*DATV_FM1*/), + m_objSettingsMutex(QMutex::NonRecursive) { setObjectName("DATVDemod"); - qDebug("DATVDemod::DATVDemod: sizeof FixReal: %lu: SDR_RX_SAMP_SZ: %u", sizeof(FixReal), (unsigned int) SDR_RX_SAMP_SZ); //*************** DATV PARAMETERS *************** - m_blnInitialized = false; - CleanUpDATVFramework(); + m_blnInitialized=false; + CleanUpDATVFramework(false); m_objVideoStream = new DATVideostream(); @@ -64,32 +64,33 @@ DATVDemod::DATVDemod(DeviceSourceAPI *deviceAPI) : m_deviceAPI->addChannelAPI(this); connect(m_channelizer, SIGNAL(inputSampleRateChanged()), this, SLOT(channelSampleRateChanged())); + + //To setup correct Sample Rate + channelSampleRateChanged(); } DATVDemod::~DATVDemod() { - m_blnInitialized = false; + m_blnInitialized=false; - if (m_objRenderThread != NULL) + if(m_objVideoStream!=NULL) { - if (m_objRenderThread->isRunning()) + //Immediately exit from DATVideoStream if waiting for data before killing thread + m_objVideoStream->ThreadTimeOut=0; + } + + if(m_objRenderThread!=NULL) + { + if(m_objRenderThread->isRunning()) { - m_objRenderThread->stopRendering(); + m_objRenderThread->stopRendering(); + m_objRenderThread->quit(); } + + m_objRenderThread->wait(2000); } - //CleanUpDATVFramework(true); - - if (m_objRFFilter != NULL) - { - //delete m_objRFFilter; - } - - if (m_objVideoStream != NULL) - { - //m_objVideoStream->close(); - //delete m_objVideoStream; - } + CleanUpDATVFramework(true); m_deviceAPI->removeChannelAPI(this); m_deviceAPI->removeThreadedSink(m_threadedChannelizer); @@ -97,6 +98,20 @@ DATVDemod::~DATVDemod() delete m_channelizer; } +void DATVDemod::channelSampleRateChanged() +{ + qDebug() << "DATVDemod::channelSampleRateChanged:" + << " intMsps: " << m_channelizer->getInputSampleRate(); + + if(m_objRunning.intMsps!=m_channelizer->getInputSampleRate()) + { + m_objRunning.intMsps = m_channelizer->getInputSampleRate(); + m_objRunning.intSampleRate = m_objRunning.intMsps; + + ApplySettings(); + } +} + bool DATVDemod::SetDATVScreen(DATVScreen *objScreen) { m_objRegisteredDATVScreen = objScreen; @@ -107,114 +122,110 @@ DATVideostream * DATVDemod::SetVideoRender(DATVideoRender *objScreen) { m_objRegisteredVideoRender = objScreen; - m_objRenderThread = new DATVideoRenderThread(m_objRegisteredVideoRender, m_objVideoStream); + m_objRenderThread = new DATVideoRenderThread(m_objRegisteredVideoRender,m_objVideoStream); return m_objVideoStream; } + bool DATVDemod::PlayVideo(bool blnStartStop) { - if (m_objVideoStream == NULL) + if(m_objVideoStream==NULL) { return false; } - if (m_objRegisteredVideoRender == NULL) + if(m_objRegisteredVideoRender==NULL) { return false; } - if (m_objRenderThread == NULL) + if(m_objRenderThread==NULL) { return false; } - if (m_objRenderThread->isRunning()) + if (m_blnStartStopVideo && !blnStartStop) { - if (blnStartStop == true) - { - m_objRenderThread->stopRendering(); - } - return true; } - m_objRenderThread->setStreamAndRenderer(m_objRegisteredVideoRender, m_objVideoStream); - m_objVideoStream->MultiThreaded = true; - m_objRenderThread->start(); + if(blnStartStop==true) + { + m_blnStartStopVideo=true; + } - //m_objVideoStream->MultiThreaded=false; - //m_objRenderThread->run(); + if(m_objRenderThread->isRunning()) + { + if(blnStartStop==true) + { + m_objRenderThread->stopRendering(); + } + + return true; + } + + m_objRenderThread->setStreamAndRenderer(m_objRegisteredVideoRender,m_objVideoStream); + m_objVideoStream->MultiThreaded=true; + m_objVideoStream->ThreadTimeOut=5000; //5000 ms + m_objRenderThread->start(); return true; } -void DATVDemod::configure( - MessageQueue* objMessageQueue, - int intRFBandwidth, - int intCenterFrequency, - dvb_version enmStandard, - DATVModulation enmModulation, - code_rate enmFEC, - int intSymbolRate, - int intNotchFilters, - bool blnAllowDrift, - bool blnFastLock, - bool blnHDLC, - bool blnHardMetric, - bool blnResample, - bool blnViterbi) +void DATVDemod::configure(MessageQueue* objMessageQueue, + int intRFBandwidth, + int intCenterFrequency, + dvb_version enmStandard, + DATVModulation enmModulation, + 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, - blnHDLC, - blnHardMetric, - blnResample, - blnViterbi); + 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, - code_rate enmFEC, - int intSampleRate, - int intSymbolRate, - int intNotchFilters, - bool blnAllowDrift, - bool blnFastLock, - bool blnHDLC, - bool blnHardMetric, - bool blnResample, - bool blnViterbi) +void DATVDemod::InitDATVParameters(int intMsps, + int intRFBandwidth, + int intCenterFrequency, + dvb_version enmStandard, + DATVModulation enmModulation, + 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; - m_blnInitialized = false; - m_objSettingsMutex.lock(); - //Recalibrage du filtre passe bande + m_blnInitialized=false; - fltLowCut = -((float) intRFBandwidth / 2.0) / (float) intMsps; - fltHiCut = ((float) intRFBandwidth / 2.0) / (float) intMsps; + //Bandpass filter shaping + + fltLowCut = -((float)intRFBandwidth / 2.0) / (float)intMsps; + fltHiCut = ((float)intRFBandwidth / 2.0) / (float)intMsps; m_objRFFilter->create_filter(fltLowCut, fltHiCut); - m_objNCO.setFreq(-(float) intCenterFrequency, (float) intMsps); + m_objNCO.setFreq(-(float)intCenterFrequency,(float)intMsps); - //Mise à jour de la config + //Config update m_objRunning.intMsps = intMsps; m_objRunning.intCenterFrequency = intCenterFrequency; @@ -227,211 +238,221 @@ void DATVDemod::InitDATVParameters( m_objRunning.intNotchFilters = intNotchFilters; m_objRunning.blnAllowDrift = blnAllowDrift; m_objRunning.blnFastLock = blnFastLock; - m_objRunning.blnHDLC = blnHDLC; + m_objRunning.enmFilter = enmFilter; m_objRunning.blnHardMetric = blnHardMetric; - m_objRunning.blnResample = blnResample; + m_objRunning.fltRollOff = fltRollOff; m_objRunning.blnViterbi = blnViterbi; + m_objRunning.intExcursion = intExcursion; - qDebug() << "DATVDemod::InitDATVParameters:" - << " - Msps: " << intMsps - << " - Sample Rate: " << intSampleRate - << " - Symbol Rate: " << intSymbolRate - << " - Modulation: " << enmModulation - << " - Notch Filters: " << intNotchFilters - << " - Allow Drift: " << blnAllowDrift - << " - Fast Lock: " << blnFastLock - << " - HDLC: " << blnHDLC - << " - HARD METRIC: " << blnHardMetric - << " - Resample: " << blnResample - << " - Viterbi: " << blnViterbi; + m_blnInitialized=true; m_objSettingsMutex.unlock(); - m_blnNeedConfigUpdate = true; - - m_blnInitialized = true; + m_blnNeedConfigUpdate=true; } -void DATVDemod::CleanUpDATVFramework() +void DATVDemod::CleanUpDATVFramework(bool blnRelease) { - //if(blnRelease==true) -// if (false) -// { -// if(m_objScheduler!=NULL) -// { -// m_objScheduler->shutdown(); -// delete m_objScheduler; -// } -// -// // INPUT -// if(p_rawiq!=NULL) delete p_rawiq; -// if(p_rawiq_writer!=NULL) delete p_rawiq_writer; -// if(p_preprocessed!=NULL) delete p_preprocessed; -// -// // NOTCH FILTER -// if(r_auto_notch!=NULL) delete r_auto_notch; -// if(p_autonotched!=NULL) delete p_autonotched; -// -// // FREQUENCY CORRECTION : DEROTATOR -// if(p_derot!=NULL) delete p_derot; -// if(r_derot!=NULL) delete r_derot; -// -// // CNR ESTIMATION -// if(p_cnr!=NULL) delete p_cnr; -// if(r_cnr!=NULL) delete r_cnr; -// -// //FILTERING -// if(r_resample!=NULL) delete r_resample; -// if(p_resampled!=NULL) delete p_resampled; -// if(coeffs!=NULL) 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; -// -// //DECIMATION -// if(p_decimated!=NULL) delete p_decimated; -// if(p_decim!=NULL) delete p_decim; -// if(r_ppout!=NULL) delete r_ppout; -// -// //GENERIC CONSTELLATION RECEIVER -// if(m_objDemodulator!=NULL) 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; -// -// -// // 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; -// -// //BER ESTIMATION -// if(p_vber!=NULL) delete p_vber; -// if(r_vber!=NULL) delete r_vber; -// -// // DERANDOMIZATION -// if(p_tspackets!=NULL) delete p_tspackets; -// if(r_derand!=NULL) delete r_derand; -// -// -// //OUTPUT : To remove -// if(r_stdout!=NULL) delete r_stdout; -// if(r_videoplayer!=NULL) delete r_videoplayer; -// -// //CONSTELLATION -// if(r_scope_symbols!=NULL) delete r_scope_symbols; -// -// } + if(blnRelease==true) + { + if(m_objScheduler!=NULL) + { + m_objScheduler->shutdown(); + delete m_objScheduler; + } - m_objScheduler = 0; + // NOTCH FILTER + + if(r_auto_notch!=NULL) delete r_auto_notch; + if(p_autonotched!=NULL) delete p_autonotched; + + // FREQUENCY CORRECTION : DEROTATOR + if(p_derot!=NULL) delete p_derot; + if(r_derot!=NULL) delete r_derot; + + // CNR ESTIMATION + if(p_cnr!=NULL) delete p_cnr; + if(r_cnr!=NULL) delete r_cnr; + + //FILTERING + if(r_resample!=NULL) delete r_resample; + if(p_resampled!=NULL) delete p_resampled; + if(coeffs!=NULL) 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; + + //DECIMATION + if(p_decimated!=NULL) delete p_decimated; + if(p_decim!=NULL) delete p_decim; + if(r_ppout!=NULL) delete r_ppout; + + + //GENERIC CONSTELLATION RECEIVER + if(m_objDemodulator!=NULL) 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; + + + // 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; + + //BER ESTIMATION + if(p_vber!=NULL) delete p_vber; + if(r_vber!=NULL) delete r_vber; + + // DERANDOMIZATION + if(p_tspackets!=NULL) delete p_tspackets; + if(r_derand!=NULL) delete r_derand; + + + //OUTPUT : To remove + if(r_stdout!=NULL) delete r_stdout; + if(r_videoplayer!=NULL) delete r_videoplayer; + + //CONSTELLATION + if(r_scope_symbols!=NULL) 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; + + + } + + m_objScheduler=NULL; // INPUT - p_rawiq = 0; - p_rawiq_writer = 0; + p_rawiq = NULL; + p_rawiq_writer = NULL; - p_preprocessed = 0; + p_preprocessed = NULL; // NOTCH FILTER - r_auto_notch = 0; - p_autonotched = 0; + r_auto_notch = NULL; + p_autonotched = NULL; // FREQUENCY CORRECTION : DEROTATOR - p_derot = 0; - r_derot = 0; + p_derot = NULL; + r_derot=NULL; // CNR ESTIMATION - p_cnr = 0; - r_cnr = 0; + p_cnr = NULL; + r_cnr = NULL; //FILTERING - r_resample = 0; - p_resampled = 0; - coeffs = 0; - ncoeffs = 0; + r_resample = NULL; + p_resampled = NULL; + coeffs = NULL; + ncoeffs=0; // OUTPUT PREPROCESSED DATA - sampler = 0; - coeffs_sampler = 0; - ncoeffs_sampler = 0; + sampler = NULL; + coeffs_sampler=NULL; + ncoeffs_sampler=0; - p_symbols = 0; - p_freq = 0; - p_ss = 0; - p_mer = 0; - p_sampled = 0; + p_symbols = NULL; + p_freq = NULL; + p_ss = NULL; + p_mer = NULL; + p_sampled = NULL; //DECIMATION - p_decimated = 0; - p_decim = 0; - r_ppout = 0; + p_decimated = NULL; + p_decim = NULL; + r_ppout = NULL; //GENERIC CONSTELLATION RECEIVER - m_objDemodulator = 0; + m_objDemodulator = NULL; //DECONVOLUTION AND SYNCHRONIZATION - p_bytes = 0; - r_deconv = 0; - r = 0; + p_bytes=NULL; + r_deconv=NULL; + r = NULL; - p_descrambled = 0; - p_frames = 0; - r_etr192_descrambler = 0; - r_sync = 0; + p_descrambled = NULL; + p_frames = NULL; + r_etr192_descrambler = NULL; + r_sync = NULL; + + p_mpegbytes = NULL; + p_lock = NULL; + p_locktime = NULL; + r_sync_mpeg = NULL; - p_mpegbytes = 0; - p_lock = 0; - p_locktime = 0; - r_sync_mpeg = 0; // DEINTERLEAVING - p_rspackets = 0; - r_deinter = 0; + p_rspackets = NULL; + r_deinter = NULL; + + p_vbitcount = NULL; + p_verrcount = NULL; + p_rtspackets = NULL; + r_rsdec = NULL; - p_vbitcount = 0; - p_verrcount = 0; - p_rtspackets = 0; - r_rsdec = 0; //BER ESTIMATION - p_vber = 0; - r_vber = 0; + p_vber = NULL; + r_vber = NULL; + // DERANDOMIZATION - p_tspackets = 0; - r_derand = 0; + p_tspackets = NULL; + r_derand = NULL; + //OUTPUT : To remove - r_stdout = 0; - r_videoplayer = 0; + r_stdout = NULL; + r_videoplayer = NULL; + //CONSTELLATION - r_scope_symbols = 0; + r_scope_symbols = NULL; } 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; m_objCfg.standard = m_objRunning.enmStandard; @@ -440,56 +461,61 @@ void DATVDemod::InitDATVFramework() m_objCfg.Fm = (float) m_objRunning.intSymbolRate; m_objCfg.fastlock = m_objRunning.blnFastLock; - switch (m_objRunning.enmModulation) + 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 + + switch(m_objRunning.enmModulation) { - case BPSK: - m_objCfg.constellation = cstln_lut<256>::BPSK; + case BPSK: + m_objCfg.constellation = cstln_lut<256>::BPSK; break; - case QPSK: - m_objCfg.constellation = cstln_lut<256>::QPSK; + case QPSK: + m_objCfg.constellation = cstln_lut<256>::QPSK; break; - case PSK8: - m_objCfg.constellation = cstln_lut<256>::PSK8; + case PSK8: + m_objCfg.constellation = cstln_lut<256>::PSK8; break; - case APSK16: - m_objCfg.constellation = cstln_lut<256>::APSK16; + case APSK16: + m_objCfg.constellation = cstln_lut<256>::APSK16; break; - case APSK32: - m_objCfg.constellation = cstln_lut<256>::APSK32; + case APSK32: + m_objCfg.constellation = cstln_lut<256>::APSK32; break; - case APSK64E: - m_objCfg.constellation = cstln_lut<256>::APSK64E; + case APSK64E: + m_objCfg.constellation = cstln_lut<256>::APSK64E; break; - case QAM16: - m_objCfg.constellation = cstln_lut<256>::QAM16; + case QAM16: + m_objCfg.constellation = cstln_lut<256>::QAM16; break; - case QAM64: - m_objCfg.constellation = cstln_lut<256>::QAM64; + case QAM64: + m_objCfg.constellation = cstln_lut<256>::QAM64; break; - case QAM256: - m_objCfg.constellation = cstln_lut<256>::QAM256; + case QAM256: + m_objCfg.constellation = cstln_lut<256>::QAM256; break; - default: - m_objCfg.constellation = cstln_lut<256>::BPSK; + default: + m_objCfg.constellation = cstln_lut<256>::BPSK; break; } m_objCfg.allow_drift = m_objRunning.blnAllowDrift; m_objCfg.anf = m_objRunning.intNotchFilters; m_objCfg.hard_metric = m_objRunning.blnHardMetric; - m_objCfg.hdlc = m_objRunning.blnHDLC; - m_objCfg.resample = m_objRunning.blnResample; + m_objCfg.sampler = m_objRunning.enmFilter; m_objCfg.viterbi = m_objRunning.blnViterbi; + // Min buffer size for baseband data // scopes: 1024 // ss_estimator: 1024 @@ -519,9 +545,7 @@ void DATVDemod::InitDATVFramework() // Min buffer size for misc measurements: 1 BUF_SLOW = m_objCfg.buf_factor; - m_lngExpectedReadIQ = BUF_BASEBAND; - - CleanUpDATVFramework(); + m_lngExpectedReadIQ = BUF_BASEBAND; m_objScheduler = new scheduler(); @@ -532,29 +556,25 @@ void DATVDemod::InitDATVFramework() // NOTCH FILTER - if (m_objCfg.anf) + if ( m_objCfg.anf>0 ) { p_autonotched = new pipebuf(m_objScheduler, "autonotched", BUF_BASEBAND); r_auto_notch = new auto_notch(m_objScheduler, *p_preprocessed, *p_autonotched, m_objCfg.anf, 0); p_preprocessed = p_autonotched; } + // FREQUENCY CORRECTION - if (m_objCfg.Fderot) - { - p_derot = new pipebuf(m_objScheduler, "derotated", BUF_BASEBAND); - r_derot = new rotator(m_objScheduler, *p_preprocessed, *p_derot, -m_objCfg.Fderot / m_objCfg.Fs); - p_preprocessed = p_derot; - } + //******** -> if ( m_objCfg.Fderot>0 ) // CNR ESTIMATION p_cnr = new pipebuf(m_objScheduler, "cnr", BUF_SLOW); - if (m_objCfg.cnr) + if ( m_objCfg.cnr==true ) { - r_cnr = new cnr_fft(m_objScheduler, *p_preprocessed, *p_cnr, m_objCfg.Fm / m_objCfg.Fs); + r_cnr = new cnr_fft(m_objScheduler, *p_preprocessed, *p_cnr, m_objCfg.Fm/m_objCfg.Fs); r_cnr->decimation = decimation(m_objCfg.Fs, 1); // 1 Hz } @@ -562,164 +582,118 @@ void DATVDemod::InitDATVFramework() int decim = 1; - if (m_objCfg.resample) - { - // Lowpass-filter and decimate. - if (m_objCfg.decim) - { - decim = m_objCfg.decim; - } - else - { - // Decimate to just above 4 samples per symbol - float target_Fs = m_objCfg.Fm * 4; - decim = m_objCfg.Fs / target_Fs; - if (decim < 1) - { - decim = 1; - } - } + //******** -> if ( m_objCfg.resample ) - float transition = (m_objCfg.Fm / 2) * m_objCfg.rolloff; - int order = m_objCfg.resample_rej * m_objCfg.Fs / (22 * transition); - order = ((order + 1) / 2) * 2; // Make even - - p_resampled = new pipebuf(m_objScheduler, "resampled", BUF_BASEBAND); - -#if 1 // Cut in middle of roll-off region - float Fcut = (m_objCfg.Fm / 2) * (1 + m_objCfg.rolloff / 2) / m_objCfg.Fs; -#else // Cut at beginning of roll-off region - float Fcut = (m_objCfg.Fm/2) / cfg.Fs; -#endif - - ncoeffs = filtergen::lowpass(order, Fcut, &coeffs); - - filtergen::normalize_dcgain(ncoeffs, coeffs, 1); - - r_resample = new fir_filter(m_objScheduler, ncoeffs, coeffs, *p_preprocessed, *p_resampled, decim); - p_preprocessed = p_resampled; - m_objCfg.Fs /= decim; - } // DECIMATION // (Unless already done in resampler) - if (!m_objCfg.resample && m_objCfg.decim > 1) - { - decim = m_objCfg.decim; - - p_decimated = new pipebuf(m_objScheduler, "decimated", BUF_BASEBAND); - p_decim = new decimator(m_objScheduler, decim, *p_preprocessed, *p_decimated); - p_preprocessed = p_decimated; - m_objCfg.Fs /= decim; - } + //******** -> if ( !m_objCfg.resample && m_objCfg.decim>1 ) //Resampling FS + // Generic constellation receiver p_symbols = new pipebuf(m_objScheduler, "PSK soft-symbols", BUF_SYMBOLS); - p_freq = new pipebuf(m_objScheduler, "freq", BUF_SLOW); - p_ss = new pipebuf(m_objScheduler, "SS", BUF_SLOW); - p_mer = new pipebuf(m_objScheduler, "MER", BUF_SLOW); - p_sampled = new pipebuf(m_objScheduler, "PSK symbols", BUF_BASEBAND); + p_freq = new pipebuf (m_objScheduler, "freq", BUF_SLOW); + p_ss = new pipebuf (m_objScheduler, "SS", BUF_SLOW); + p_mer = new pipebuf (m_objScheduler, "MER", BUF_SLOW); + p_sampled = new pipebuf (m_objScheduler, "PSK symbols", BUF_BASEBAND); - switch (m_objCfg.sampler) + switch ( m_objCfg.sampler ) { - case SAMP_NEAREST: - sampler = new nearest_sampler(); - break; + case SAMP_NEAREST: + sampler = new nearest_sampler(); + break; - case SAMP_LINEAR: - sampler = new linear_sampler(); - break; + case SAMP_LINEAR: + sampler = new linear_sampler(); + break; - case SAMP_RRC: - { - - if (m_objCfg.rrc_steps == 0) + case SAMP_RRC: { + + + if ( m_objCfg.rrc_steps == 0 ) + { // At least 64 discrete sampling points between symbols - m_objCfg.rrc_steps = max(1, (int) (64 * m_objCfg.Fm / m_objCfg.Fs)); + m_objCfg.rrc_steps = max(1, (int)(64*m_objCfg.Fm / m_objCfg.Fs)); + } + + float Frrc = m_objCfg.Fs * m_objCfg.rrc_steps; // Sample freq of the RRC filter + float transition = (m_objCfg.Fm/2) * m_objCfg.rolloff; + int order = m_objCfg.rrc_rej * Frrc / (22*transition); + ncoeffs_sampler = filtergen::root_raised_cosine(order, m_objCfg.Fm/Frrc, m_objCfg.rolloff, &coeffs_sampler); + + sampler = new fir_sampler(ncoeffs_sampler, coeffs_sampler, m_objCfg.rrc_steps); + break; } - float Frrc = m_objCfg.Fs * m_objCfg.rrc_steps; // Sample freq of the RRC filter - float transition = (m_objCfg.Fm / 2) * m_objCfg.rolloff; - int order = m_objCfg.rrc_rej * Frrc / (22 * transition); - ncoeffs_sampler = filtergen::root_raised_cosine(order, m_objCfg.Fm / Frrc, m_objCfg.rolloff, &coeffs_sampler); - - sampler = new fir_sampler(ncoeffs_sampler, coeffs_sampler, m_objCfg.rrc_steps); - break; - } - - default: - fatal("Interpolator not implemented"); + default: + qCritical("DATVDemod::InitDATVFramework: Interpolator not implemented"); + return; } m_objDemodulator = new 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 != cstln_lut<256>::QPSK && m_objCfg.constellation != cstln_lut<256>::BPSK) - { - qWarning("DATVDemod::InitDATVFramework: non-standard constellation for DVB-S"); - } + if ( m_objCfg.constellation != cstln_lut<256>::QPSK && m_objCfg.constellation != cstln_lut<256>::BPSK ) + { + fprintf(stderr, "Warning: non-standard constellation for DVB-S\n"); + } } - if (m_objCfg.standard == DVB_S2) + if ( m_objCfg.standard == DVB_S2 ) { - // For DVB-S2 testing only. - // Constellation should be determined from PL signalling. - qWarning("DATVDemod::InitDATVFramework: DVB-S2: Testing symbol sampler only."); + // For DVB-S2 testing only. + // Constellation should be determined from PL signalling. + fprintf(stderr, "DVB-S2: Testing symbol sampler only.\n"); } m_objDemodulator->cstln = make_dvbs2_constellation(m_objCfg.constellation, m_objCfg.fec); - if (m_objCfg.hard_metric) + if ( m_objCfg.hard_metric ) { - m_objDemodulator->cstln->harden(); + m_objDemodulator->cstln->harden(); } - m_objDemodulator->set_omega(m_objCfg.Fs / m_objCfg.Fm); + m_objDemodulator->set_omega(m_objCfg.Fs/m_objCfg.Fm); - if (m_objCfg.Ftune) + //******** if ( m_objCfg.Ftune ) + //{ + // m_objDemodulator->set_freq(m_objCfg.Ftune/m_objCfg.Fs); + //} + + if ( m_objCfg.allow_drift ) { - - m_objDemodulator->set_freq(m_objCfg.Ftune / m_objCfg.Fs); + m_objDemodulator->set_allow_drift(true); } - if (m_objCfg.allow_drift) + //******** -> if ( m_objCfg.viterbi ) + if ( m_objCfg.viterbi ) { - m_objDemodulator->set_allow_drift(true); + 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_resample) - { - r_resample->freq_tap = &m_objDemodulator->freq_tap; - r_resample->tap_multiplier = 1.0 / decim; - r_resample->freq_tol = m_objCfg.Fm / (m_objCfg.Fs * decim) * 0.1; - } - 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 - m_objRegisteredDATVScreen->resizeDATVScreen(256, 256); + m_objRegisteredDATVScreen->resizeDATVScreen(256,256); - r_scope_symbols = new datvconstellation(m_objScheduler, *p_sampled, -128, 128, NULL, m_objRegisteredDATVScreen); + r_scope_symbols = new datvconstellation(m_objScheduler, *p_sampled, -128,128, NULL, m_objRegisteredDATVScreen); r_scope_symbols->decimation = 1; r_scope_symbols->cstln = &m_objDemodulator->cstln; @@ -729,20 +703,22 @@ void DATVDemod::InitDATVFramework() r_deconv = NULL; - if (m_objCfg.viterbi) + //******** -> if ( m_objCfg.viterbi ) + + if ( m_objCfg.viterbi ) { - if (m_objCfg.fec == FEC23 && (m_objDemodulator->cstln->nsymbols == 4 || m_objDemodulator->cstln->nsymbols == 64)) - { - m_objCfg.fec = FEC46; - } + if ( m_objCfg.fec==FEC23 && (m_objDemodulator->cstln->nsymbols==4 || m_objDemodulator->cstln->nsymbols==64) ) + { + m_objCfg.fec = FEC46; + } - //To uncomment -> Linking Problem : undefined symbol: _ZN7leansdr21viterbi_dec_interfaceIhhiiE6updateEPiS2_ - r = new 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 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 { @@ -750,71 +726,58 @@ void DATVDemod::InitDATVFramework() r_deconv->fastlock = m_objCfg.fastlock; } - if (m_objCfg.hdlc) - { - p_descrambled = new pipebuf(m_objScheduler, "descrambled", BUF_MPEGBYTES); - r_etr192_descrambler = new etr192_descrambler(m_objScheduler, (*p_bytes), *p_descrambled); - p_frames = new pipebuf(m_objScheduler, "frames", BUF_MPEGBYTES); - r_sync = new hdlc_sync(m_objScheduler, *p_descrambled, *p_frames, 2, 278); + //******* -> if ( m_objCfg.hdlc ) - if (m_objCfg.fastlock) - { - r_sync->resync_period = 1; - } + p_mpegbytes = new pipebuf (m_objScheduler, "mpegbytes", BUF_MPEGBYTES); + p_lock = new pipebuf (m_objScheduler, "lock", BUF_SLOW); + p_locktime = new pipebuf (m_objScheduler, "locktime", BUF_PACKETS); - if (m_objCfg.packetized) - { - r_sync->header16 = true; - } - - } - - p_mpegbytes = new pipebuf(m_objScheduler, "mpegbytes", BUF_MPEGBYTES); - p_lock = new pipebuf(m_objScheduler, "lock", BUF_SLOW); - p_locktime = new pipebuf(m_objScheduler, "locktime", BUF_PACKETS); - - if (!m_objCfg.hdlc) - { - r_sync_mpeg = new mpeg_sync(m_objScheduler, *p_bytes, *p_mpegbytes, r_deconv, p_lock, p_locktime); - r_sync_mpeg->fastlock = m_objCfg.fastlock; - } + r_sync_mpeg = new mpeg_sync(m_objScheduler, *p_bytes, *p_mpegbytes, r_deconv, p_lock, p_locktime); + r_sync_mpeg->fastlock = m_objCfg.fastlock; // DEINTERLEAVING - p_rspackets = new pipebuf >(m_objScheduler, "RS-enc packets", BUF_PACKETS); + p_rspackets = new pipebuf< rspacket >(m_objScheduler, "RS-enc packets", BUF_PACKETS); r_deinter = new deinterleaver(m_objScheduler, *p_mpegbytes, *p_rspackets); + // REED-SOLOMON p_vbitcount = new pipebuf(m_objScheduler, "Bits processed", BUF_PACKETS); p_verrcount = new pipebuf(m_objScheduler, "Bits corrected", BUF_PACKETS); p_rtspackets = new pipebuf(m_objScheduler, "rand TS packets", BUF_PACKETS); - r_rsdec = new rs_decoder(m_objScheduler, *p_rspackets, *p_rtspackets, p_vbitcount, p_verrcount); + r_rsdec = new 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 + + /* + 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) + if ( r_vber->sample_size < 50000 ) { r_vber->sample_size = 50000; } + */ // DERANDOMIZATION p_tspackets = new pipebuf(m_objScheduler, "TS packets", BUF_PACKETS); r_derand = new derandomizer(m_objScheduler, *p_rtspackets, *p_tspackets); - // OUTPUT - r_videoplayer = new datvvideoplayer(m_objScheduler, *p_tspackets, m_objVideoStream); - m_blnDVBInitialized = true; + // OUTPUT + r_videoplayer = new datvvideoplayer(m_objScheduler, *p_tspackets,m_objVideoStream); + + m_blnDVBInitialized=true; } void DATVDemod::feed(const SampleVector::const_iterator& begin, const SampleVector::const_iterator& end, bool firstOfBurst __attribute__((unused))) { + qint16 * ptrBufferToRelease=NULL; float fltI; float fltQ; cf32 objIQ; @@ -822,9 +785,10 @@ void DATVDemod::feed(const SampleVector::const_iterator& begin, const SampleVect fftfilt::cmplx *objRF; int intRFOut; + //********** Bis repetita : Let's rock and roll buddy ! ********** + #ifdef EXTENDED_DIRECT_SAMPLE - qint16 * ptrBufferToRelease=NULL; qint16 * ptrBuffer; qint32 intLen; @@ -843,6 +807,7 @@ void DATVDemod::feed(const SampleVector::const_iterator& begin, const SampleVect ptrBuffer ++; fltQ= ((qint32) (*ptrBuffer)) << 4; ptrBuffer ++; + #else for (SampleVector::const_iterator it = begin; it != end; ++it /* ++it **/) @@ -851,74 +816,75 @@ void DATVDemod::feed(const SampleVector::const_iterator& begin, const SampleVect fltQ = it->imag(); #endif + //********** demodulation ********** - if ((m_blnDVBInitialized == false) || (m_blnNeedConfigUpdate == true)) + + if (m_blnNeedConfigUpdate) { - m_blnNeedConfigUpdate = false; + + m_objSettingsMutex.lock(); + + m_blnNeedConfigUpdate=false; + InitDATVFramework(); + + m_objSettingsMutex.unlock(); + } + //********** iq stream **************** - if (m_lngReadIQ > p_rawiq_writer->writable()) + Complex objC(fltI,fltQ); + + objC *= m_objNCO.nextIQ(); + + intRFOut = m_objRFFilter->runFilt(objC, &objRF); // filter RF before demod + + for (int intI = 0 ; intI < intRFOut; intI++) { - m_objScheduler->step(); + objIQ.re = objRF->real(); + objIQ.im = objRF->imag(); - m_objRegisteredDATVScreen->renderImage(NULL); + objRF ++; - m_lngReadIQ = 0; - p_rawiq_writer = new pipewriter(*p_rawiq); - } - - if (false) - { - objIQ.re = fltI; - objIQ.im = fltQ; - - p_rawiq_writer->write(objIQ); - - m_lngReadIQ++; - } - else - { - - Complex objC(fltI, fltQ); - - objC *= m_objNCO.nextIQ(); - - intRFOut = m_objRFFilter->runFilt(objC, &objRF); // filter RF before demod - - for (int intI = 0; intI < intRFOut; intI++) + if (m_blnDVBInitialized + && (p_rawiq_writer!=NULL) + && (m_objScheduler!=NULL)) { - objIQ.re = objRF->real(); - objIQ.im = objRF->imag(); - p_rawiq_writer->write(objIQ); - - objRF++; m_lngReadIQ++; + + //Leave +1 by safety + if((m_lngReadIQ+1)>=p_rawiq_writer->writable()) + { + m_objScheduler->step(); + + m_lngReadIQ=0; + delete p_rawiq_writer; + p_rawiq_writer = new pipewriter(*p_rawiq); + } } + } //********** demodulation ********** } -#ifdef EXTENDED_DIRECT_SAMPLE if(ptrBufferToRelease!=NULL) { delete ptrBufferToRelease; } -#endif - //m_objSettingsMutex.unlock(); + } void DATVDemod::start() { - //m_objTimer.start(); + } void DATVDemod::stop() @@ -928,57 +894,34 @@ void DATVDemod::stop() bool DATVDemod::handleMessage(const Message& cmd) { - if (DownChannelizer::MsgChannelizerNotification::match(cmd)) - { - DownChannelizer::MsgChannelizerNotification& objNotif = (DownChannelizer::MsgChannelizerNotification&) cmd; + qDebug() << "DATVDemod::handleMessage"; - qDebug() << "DATVDemod::handleMessage: MsgChannelizerNotification:" << " intMsps: " << objNotif.getSampleRate(); - - if (m_objRunning.intMsps != objNotif.getSampleRate()) - { - m_objRunning.intMsps = objNotif.getSampleRate(); - m_objRunning.intSampleRate = m_objRunning.intMsps; - - qDebug("DATVDemod::handleMessage: Sample Rate: %d", m_objRunning.intSampleRate); - ApplySettings(); - } - - return true; - } - else if (MsgConfigureChannelizer::match(cmd)) - { - - MsgConfigureChannelizer& cfg = (MsgConfigureChannelizer&) cmd; - - qDebug() << "DATVDemod::handleMessage: MsgConfigureChannelizer:" - << " sampleRate: " << m_channelizer->getInputSampleRate() - << " centerFrequency: " << cfg.getCenterFrequency(); - - m_channelizer->configure(m_channelizer->getInputMessageQueue(), m_channelizer->getInputSampleRate(), cfg.getCenterFrequency()); - //m_objRunning.intCenterFrequency); - //<< " centerFrequency: " << m_objRunning.intCenterFrequency; - - return true; - } - else if (MsgConfigureDATVDemod::match(cmd)) - { - qDebug() << "DATVDemod::handleMessage: MsgConfigureDATVDemod"; + if (MsgConfigureDATVDemod::match(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.blnHDLC != m_objRunning.blnHDLC) - || (objCfg.m_objMsgConfig.blnResample != m_objRunning.blnResample) || (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)) - { + + 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; - m_objRunning.blnHDLC = objCfg.m_objMsgConfig.blnHDLC; - m_objRunning.blnResample = objCfg.m_objMsgConfig.blnResample; + m_objRunning.enmFilter = objCfg.m_objMsgConfig.enmFilter; + m_objRunning.fltRollOff = objCfg.m_objMsgConfig.fltRollOff; m_objRunning.blnViterbi = objCfg.m_objMsgConfig.blnViterbi; m_objRunning.enmFEC = objCfg.m_objMsgConfig.enmFEC; m_objRunning.enmModulation = objCfg.m_objMsgConfig.enmModulation; @@ -987,49 +930,48 @@ bool DATVDemod::handleMessage(const Message& cmd) m_objRunning.intSymbolRate = objCfg.m_objMsgConfig.intSymbolRate; m_objRunning.intRFBandwidth = objCfg.m_objMsgConfig.intRFBandwidth; m_objRunning.intCenterFrequency = objCfg.m_objMsgConfig.intCenterFrequency; + m_objRunning.intExcursion = objCfg.m_objMsgConfig.intExcursion; + + qDebug() << "ATVDemod::handleMessage: MsgConfigureDATVDemod: sampleRate: " << m_objRunning.intMsps + << " sampleRate: " << m_objRunning.intSampleRate; ApplySettings(); - } + } - return true; - } - else if (DSPSignalNotification::match(cmd)) - { - qDebug() << "DATVDemod::handleMessage: DSPSignalNotification"; - return true; - } - else - { - return false; - } + + return true; + } + else + { + return false; + } } void DATVDemod::ApplySettings() { - if (m_objRunning.intMsps == 0) + if(m_objRunning.intMsps==0) { return; } - //m_objSettingsMutex.lock(); - 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.blnHDLC, - m_objRunning.blnHardMetric, - m_objRunning.blnResample, - m_objRunning.blnViterbi); + 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); } @@ -1038,10 +980,3 @@ int DATVDemod::GetSampleRate() return m_objRunning.intMsps; } -void DATVDemod::channelSampleRateChanged() -{ - qDebug("DATVDemod::channelSampleRateChanged"); - // reconfigure to get full available bandwidth - m_channelizer->configure(m_channelizer->getInputMessageQueue(), m_channelizer->getInputSampleRate(), m_channelizer->getRequestedCenterFrequency()); - // TODO: forward to GUI if necessary -} diff --git a/plugins/channelrx/demoddatv/datvdemod.h b/plugins/channelrx/demoddatv/datvdemod.h index 161711c12..be7906145 100644 --- a/plugins/channelrx/demoddatv/datvdemod.h +++ b/plugins/channelrx/demoddatv/datvdemod.h @@ -68,82 +68,70 @@ class DownChannelizer; using namespace leansdr; -enum DATVModulation -{ - BPSK, QPSK, PSK8, APSK16, APSK32, APSK64E, QAM16, QAM64, QAM256 -}; -enum dvb_version -{ - DVB_S, DVB_S2 -}; -enum dvb_sampler -{ - SAMP_NEAREST, SAMP_LINEAR, SAMP_RRC -}; +enum DATVModulation { BPSK, QPSK, PSK8, APSK16, APSK32, APSK64E, QAM16, QAM64, QAM256 }; +enum dvb_version { DVB_S, DVB_S2 }; +enum dvb_sampler { SAMP_NEAREST, SAMP_LINEAR, SAMP_RRC }; -inline int decimation(float Fin, float Fout) -{ - int d = Fin / Fout; - return max(d, 1); -} +inline int decimation(float Fin, float Fout) { int d = Fin / Fout; return max(d, 1); } 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) - cstln_lut<256>::predef constellation; - 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) + cstln_lut<256>::predef constellation; + 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(1), - cnr(false), - decim(0), - Fm(2e6), - constellation(cstln_lut<256>::QPSK), - fec(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(1), + cnr(false), + decim(0), + Fm(2e6), + constellation(cstln_lut<256>::QPSK), + fec(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) + { + } }; + struct DATVConfig { int intMsps; @@ -157,110 +145,72 @@ struct DATVConfig int intNotchFilters; bool blnAllowDrift; bool blnFastLock; - bool blnHDLC; + dvb_sampler enmFilter; bool blnHardMetric; - bool blnResample; + float fltRollOff; bool blnViterbi; + int intExcursion; DATVConfig() : - intMsps(1024000), - intRFBandwidth(1024000), - intCenterFrequency(0), - enmStandard(DVB_S), - enmModulation(BPSK), - enmFEC(FEC12), - intSampleRate(1024000), - intSymbolRate(250000), - intNotchFilters(1), - blnAllowDrift(false), - blnFastLock(false), - blnHDLC(false), - blnHardMetric(false), - blnResample(false), - blnViterbi(false) + intMsps(1024000), + intRFBandwidth(1024000), + intCenterFrequency(0), + enmStandard(DVB_S), + enmModulation(BPSK), + enmFEC(FEC12), + intSampleRate(1024000), + intSymbolRate(250000), + intNotchFilters(1), + blnAllowDrift(false), + blnFastLock(false), + enmFilter(SAMP_LINEAR), + blnHardMetric(false), + fltRollOff(0.35), + blnViterbi(false), + intExcursion(10) { } }; -class DATVDemod: public BasebandSampleSink, public ChannelSinkAPI + +class DATVDemod : public BasebandSampleSink, public ChannelSinkAPI { -Q_OBJECT + Q_OBJECT public: - class MsgConfigureChannelizer: public Message - { - MESSAGE_CLASS_DECLARATION - - public: - int getCenterFrequency() const - { - return m_centerFrequency; - } - - static MsgConfigureChannelizer* create(int centerFrequency) - { - return new MsgConfigureChannelizer(centerFrequency); - } - - private: - int m_centerFrequency; - - MsgConfigureChannelizer(int centerFrequency) : - Message(), m_centerFrequency(centerFrequency) - { - } - }; DATVDemod(DeviceSourceAPI *); ~DATVDemod(); - virtual void destroy() - { - delete this; - } - virtual void getIdentifier(QString& id) - { - id = objectName(); - } - virtual void getTitle(QString& title) - { - title = objectName(); - } - virtual qint64 getCenterFrequency() const - { - return m_objRunning.intCenterFrequency; - } + virtual void destroy() { delete this; } + virtual void getIdentifier(QString& id) { id = objectName(); } + virtual void getTitle(QString& title) { title = objectName(); } + virtual qint64 getCenterFrequency() const { return m_objRunning.intCenterFrequency; } - virtual QByteArray serialize() const - { - return QByteArray(); - } - virtual bool deserialize(const QByteArray& data __attribute__((unused))) - { - return false; - } + virtual QByteArray serialize() const { return QByteArray(); } + virtual bool deserialize(const QByteArray& data __attribute__((unused))) { return false; } void configure( - MessageQueue* objMessageQueue, - int intRFBandwidth, - int intCenterFrequency, - dvb_version enmStandard, - DATVModulation enmModulation, - code_rate enmFEC, - int intSymbolRate, - int intNotchFilters, - bool blnAllowDrift, - bool blnFastLock, - bool blnHDLC, - bool blnHardMetric, - bool blnResample, - bool blnViterbi); + MessageQueue* objMessageQueue, + int intRFBandwidth, + int intCenterFrequency, + dvb_version enmStandard, + DATVModulation enmModulation, + code_rate enmFEC, + int intSymbolRate, + int intNotchFilters, + bool blnAllowDrift, + bool blnFastLock, + dvb_sampler enmFilter, + bool blnHardMetric, + float fltRollOff, + bool blnViterbi, + int intfltExcursion); - virtual void feed(const SampleVector::const_iterator& begin, - const SampleVector::const_iterator& end, bool po); - virtual void start(); - virtual void stop(); - virtual bool handleMessage(const Message& cmd); + virtual void feed(const SampleVector::const_iterator& begin, const SampleVector::const_iterator& end, bool po); + virtual void start(); + virtual void stop(); + virtual bool handleMessage(const Message& cmd); bool SetDATVScreen(DATVScreen *objScreen); DATVideostream * SetVideoRender(DATVideoRender *objScreen); @@ -268,36 +218,62 @@ public: bool PlayVideo(bool blnStartStop); void InitDATVParameters( - int intMsps, - int intRFBandwidth, - int intCenterFrequency, - dvb_version enmStandard, - DATVModulation enmModulation, - code_rate enmFEC, - int intSampleRate, - int intSymbolRate, - int intNotchFilters, - bool blnAllowDrift, - bool blnFastLock, - bool blnHDLC, - bool blnHardMetric, - bool blnResample, - bool blnViterbi); + int intMsps, + int intRFBandwidth, + int intCenterFrequency, + dvb_version enmStandard, + DATVModulation enmModulation, + code_rate enmFEC, + int intSampleRate, + int intSymbolRate, + int intNotchFilters, + bool blnAllowDrift, + bool blnFastLock, + dvb_sampler enmFilter, + bool blnHardMetric, + float fltRollOff, + bool blnViterbi, + int intEExcursion); - void CleanUpDATVFramework(); + void CleanUpDATVFramework(bool blnRelease); int GetSampleRate(); void InitDATVFramework(); static const QString m_channelIdURI; static const QString m_channelId; -private: - class MsgConfigureDATVDemod: public Message + + class MsgConfigureChannelizer : public Message { - MESSAGE_CLASS_DECLARATION + MESSAGE_CLASS_DECLARATION - public: - static MsgConfigureDATVDemod* create( + public: + int getCenterFrequency() const { return m_centerFrequency; } + + static MsgConfigureChannelizer* create(int centerFrequency) + { + return new MsgConfigureChannelizer(centerFrequency); + } + + private: + int m_centerFrequency; + + MsgConfigureChannelizer(int centerFrequency) : + Message(), + m_centerFrequency(centerFrequency) + { } + }; + +private slots: + void channelSampleRateChanged(); + +private: + class MsgConfigureDATVDemod : public Message + { + MESSAGE_CLASS_DECLARATION + + public: + static MsgConfigureDATVDemod* create( int intRFBandwidth, int intCenterFrequency, dvb_version enmStandard, @@ -307,60 +283,50 @@ private: int intNotchFilters, bool blnAllowDrift, bool blnFastLock, - bool blnHDLC, + dvb_sampler enmFilter, bool blnHardMetric, - bool blnResample, - bool blnViterbi) - { - return new MsgConfigureDATVDemod( - intRFBandwidth, - intCenterFrequency, - enmStandard, - enmModulation, - enmFEC, - intSymbolRate, - intNotchFilters, - blnAllowDrift, - blnFastLock, - blnHDLC, - blnHardMetric, - blnResample, - blnViterbi); - } + float fltRollOff, + bool blnViterbi, + int intExcursion) + { + return new MsgConfigureDATVDemod(intRFBandwidth,intCenterFrequency,enmStandard, enmModulation, enmFEC, intSymbolRate, intNotchFilters, blnAllowDrift,blnFastLock,enmFilter,blnHardMetric,fltRollOff, blnViterbi, intExcursion); + } - DATVConfig m_objMsgConfig; + DATVConfig m_objMsgConfig; - private: - MsgConfigureDATVDemod( - int intRFBandwidth, - int intCenterFrequency, - dvb_version enmStandard, - DATVModulation enmModulation, - code_rate enmFEC, - int intSymbolRate, - int intNotchFilters, - bool blnAllowDrift, - bool blnFastLock, - bool blnHDLC, - bool blnHardMetric, - bool blnResample, - bool blnViterbi) : + private: + MsgConfigureDATVDemod( + int intRFBandwidth, + int intCenterFrequency, + dvb_version enmStandard, + DATVModulation enmModulation, + code_rate enmFEC, + int intSymbolRate, + int intNotchFilters, + bool blnAllowDrift, + bool blnFastLock, + dvb_sampler enmFilter, + bool blnHardMetric, + float fltRollOff, + bool blnViterbi, + int intExcursion) : Message() - { - m_objMsgConfig.intRFBandwidth = intRFBandwidth; - m_objMsgConfig.intCenterFrequency = intCenterFrequency; - m_objMsgConfig.enmStandard = enmStandard; - m_objMsgConfig.enmModulation = enmModulation; - m_objMsgConfig.enmFEC = enmFEC; - m_objMsgConfig.intSymbolRate = intSymbolRate; - m_objMsgConfig.intNotchFilters = intNotchFilters; - m_objMsgConfig.blnAllowDrift = blnAllowDrift; - m_objMsgConfig.blnFastLock = blnFastLock; - m_objMsgConfig.blnHDLC = blnHDLC; - m_objMsgConfig.blnHardMetric = blnHardMetric; - m_objMsgConfig.blnResample = blnResample; - m_objMsgConfig.blnViterbi = blnViterbi; - } + { + m_objMsgConfig.intRFBandwidth = intRFBandwidth; + m_objMsgConfig.intCenterFrequency = intCenterFrequency; + m_objMsgConfig.enmStandard = enmStandard; + m_objMsgConfig.enmModulation = enmModulation; + m_objMsgConfig.enmFEC = enmFEC; + m_objMsgConfig.intSymbolRate = intSymbolRate; + m_objMsgConfig.intNotchFilters = intNotchFilters; + m_objMsgConfig.blnAllowDrift = blnAllowDrift; + m_objMsgConfig.blnFastLock = blnFastLock; + m_objMsgConfig.enmFilter= enmFilter; + m_objMsgConfig.blnHardMetric = blnHardMetric; + m_objMsgConfig.fltRollOff = fltRollOff; + m_objMsgConfig.blnViterbi = blnViterbi; + m_objMsgConfig.intExcursion = intExcursion; + } }; unsigned long m_lngExpectedReadIQ; @@ -403,7 +369,7 @@ private: cnr_fft *r_cnr; //FILTERING - fir_filter *r_resample; + fir_filter *r_resample; pipebuf *p_resampled; float *coeffs; int ncoeffs; @@ -442,17 +408,18 @@ private: pipebuf *p_mpegbytes; pipebuf *p_lock; pipebuf *p_locktime; - mpeg_sync *r_sync_mpeg; + mpeg_sync *r_sync_mpeg; + // DEINTERLEAVING - pipebuf > *p_rspackets; + pipebuf< rspacket > *p_rspackets; deinterleaver *r_deinter; // REED-SOLOMON pipebuf *p_vbitcount; pipebuf *p_verrcount; pipebuf *p_rtspackets; - rs_decoder *r_rsdec; + rs_decoder *r_rsdec; // BER ESTIMATION pipebuf *p_vber; @@ -462,6 +429,7 @@ private: pipebuf *p_tspackets; derandomizer *r_derand; + //OUTPUT file_writer *r_stdout; datvvideoplayer *r_videoplayer; @@ -485,6 +453,7 @@ private: bool m_blnInitialized; bool m_blnRenderingVideo; + bool m_blnStartStopVideo; DATVModulation m_enmModulation; @@ -495,9 +464,6 @@ private: QMutex m_objSettingsMutex; void ApplySettings(); - -private slots: - void channelSampleRateChanged(); }; #endif // INCLUDE_DATVDEMOD_H diff --git a/plugins/channelrx/demoddatv/datvdemodgui.cpp b/plugins/channelrx/demoddatv/datvdemodgui.cpp index 88ae39d06..aa23c85e9 100644 --- a/plugins/channelrx/demoddatv/datvdemodgui.cpp +++ b/plugins/channelrx/demoddatv/datvdemodgui.cpp @@ -78,14 +78,14 @@ void DATVDemodGUI::resetToDefaults() ui->chkAllowDrift->setChecked(false); ui->chkFastlock->setChecked(true); - ui->chkHDLC->setChecked(false); ui->chkHardMetric->setChecked(false); - ui->chkResample->setChecked(false); ui->chkViterbi->setChecked(false); ui->cmbFEC->setCurrentIndex(0); ui->cmbModulation->setCurrentIndex(0); ui->cmbStandard->setCurrentIndex(0); + ui->cmbFilter->setCurrentIndex(0); + displayRRCParameters(false); ui->spiNotchFilters->setValue(1); ui->prgSynchro->setValue(0); @@ -94,6 +94,9 @@ void DATVDemodGUI::resetToDefaults() ui->spiBandwidth->setValue(512000); ui->spiSymbolRate->setValue(250000); + ui->spiRollOff->setValue(35); + ui->spiExcursion->setValue(10); + blockApplySettings(false); @@ -109,9 +112,9 @@ QByteArray DATVDemodGUI::serialize() const s.writeBool(3, ui->chkAllowDrift->isChecked()); s.writeBool(4, ui->chkFastlock->isChecked()); - s.writeBool(5, ui->chkHDLC->isChecked()); + s.writeS32(5, ui->cmbFilter->currentIndex()); s.writeBool(6, ui->chkHardMetric->isChecked()); - s.writeBool(7, ui->chkResample->isChecked()); + s.writeS32(7, ui->spiRollOff->value()); s.writeBool(8, ui->chkViterbi->isChecked()); s.writeS32(9, ui->cmbFEC->currentIndex()); @@ -121,6 +124,7 @@ QByteArray DATVDemodGUI::serialize() const s.writeS32(12, ui->spiNotchFilters->value()); s.writeS32(13, ui->spiBandwidth->value()); s.writeS32(14, ui->spiSymbolRate->value()); + s.writeS32(15, ui->spiExcursion->value()); return s.final(); } @@ -163,14 +167,16 @@ bool DATVDemodGUI::deserialize(const QByteArray& arrData) d.readBool(4, &booltmp, false); ui->chkFastlock->setChecked(booltmp); - d.readBool(5, &booltmp, false); - ui->chkHDLC->setChecked(booltmp); + d.readS32(5, &tmp, false); + ui->cmbFilter->setCurrentIndex(tmp); + + displayRRCParameters((tmp==2)); d.readBool(6, &booltmp, false); ui->chkHardMetric->setChecked(booltmp); - d.readBool(7, &booltmp, false); - ui->chkResample->setChecked(booltmp); + d.readS32(7, &tmp, false); + ui->spiRollOff->setValue(tmp); d.readBool(8, &booltmp, false); ui->chkViterbi->setChecked(booltmp); @@ -194,6 +200,9 @@ bool DATVDemodGUI::deserialize(const QByteArray& arrData) d.readS32(14, &tmp, 250000); ui->spiSymbolRate->setValue(tmp); + d.readS32(15, &tmp, false); + ui->spiExcursion->setValue(tmp); + blockApplySettings(false); m_objChannelMarker.blockSignals(false); @@ -227,11 +236,6 @@ void DATVDemodGUI::channelMarkerHighlightedByCursor() setHighlighted(m_objChannelMarker.getHighlighted()); } -void DATVDemodGUI::channelSampleRateChanged() -{ - qDebug("DATVDemodGUI::channelSampleRateChanged"); - applySettings(); -} void DATVDemodGUI::onWidgetRolled(QWidget* widget __attribute__((unused)), bool rollDown __attribute__((unused))) { @@ -239,14 +243,6 @@ void DATVDemodGUI::onWidgetRolled(QWidget* widget __attribute__((unused)), bool void DATVDemodGUI::onMenuDoubleClicked() { - /* - if (!m_blnBasicSettingsShown) - { - m_blnBasicSettingsShown = true; - BasicChannelSettingsWidget* bcsw = new BasicChannelSettingsWidget(&m_objChannelMarker, this); - bcsw->show(); - } - */ } //DATVDemodGUI::DATVDemodGUI(PluginAPI* objPluginAPI, DeviceSourceAPI *objDeviceAPI, QWidget* objParent) : @@ -262,9 +258,7 @@ DATVDemodGUI::DATVDemodGUI(PluginAPI* objPluginAPI, DeviceUISet *deviceUISet, Ba ui->setupUi(this); setAttribute(Qt::WA_DeleteOnClose, true); connect(this, SIGNAL(widgetRolled(QWidget*,bool)), this, SLOT(onWidgetRolled(QWidget*,bool))); - //connect(this, SIGNAL(menuDoubleClickEvent()), this, SLOT(onMenuDoubleClicked())); - //m_objDATVDemod = new DATVDemod(); m_objDATVDemod = (DATVDemod*) rxChannel; m_objDATVDemod->setMessageQueueToGUI(getInputMessageQueue()); @@ -272,12 +266,7 @@ DATVDemodGUI::DATVDemodGUI(PluginAPI* objPluginAPI, DeviceUISet *deviceUISet, Ba connect(m_objDATVDemod->SetVideoRender(ui->screenTV_2),&DATVideostream::onDataPackets,this,&DATVDemodGUI::on_StreamDataAvailable); - - //connect(m_objChannelizer, SIGNAL(inputSampleRateChanged()), this, SLOT(channelSampleRateChanged())); - - - //m_objPluginAPI->addThreadedSink(m_objThreadedChannelizer); - //connect(&m_objPluginAPI->getMainWindow()->getMasterTimer(), SIGNAL(timeout()), this, SLOT(tick())); // 50 ms + connect(ui->screenTV_2,&DATVideoRender::onMetaDataChanged,this,&DATVDemodGUI::on_StreamMetaDataChanged); m_intPreviousDecodedData=0; m_intLastDecodedData=0; @@ -295,7 +284,6 @@ DATVDemodGUI::DATVDemodGUI(PluginAPI* objPluginAPI, DeviceUISet *deviceUISet, Ba m_objChannelMarker.setCenterFrequency(0); m_objChannelMarker.blockSignals(false); m_objChannelMarker.setVisible(true); - //connect(&m_objChannelMarker, SIGNAL(changed()), this, SLOT(viewChanged())); connect(&m_objChannelMarker, SIGNAL(changedByCursor()), this, SLOT(channelMarkerChangedByCursor())); connect(&m_objChannelMarker, SIGNAL(highlightedByCursor()), this, SLOT(channelMarkerHighlightedByCursor())); @@ -304,8 +292,6 @@ DATVDemodGUI::DATVDemodGUI(PluginAPI* objPluginAPI, DeviceUISet *deviceUISet, Ba m_deviceUISet->addChannelMarker(&m_objChannelMarker); m_deviceUISet->addRollupWidget(this); - //ui->screenTV->connectTimer(m_objPluginAPI->getMainWindow()->getMasterTimer()); - ui->pushButton_3->setIcon(style()->standardIcon(QStyle::SP_MediaPlay)); resetToDefaults(); // does applySettings() @@ -335,22 +321,18 @@ void DATVDemodGUI::applySettings() DATVModulation enmSelectedModulation; dvb_version enmVersion; code_rate enmFEC; + dvb_sampler enmSampler; if (m_blnDoApplySettings) { - - DATVDemod::MsgConfigureChannelizer *msgChan = DATVDemod::MsgConfigureChannelizer::create(m_objChannelMarker.getCenterFrequency()); m_objDATVDemod->getInputMessageQueue()->push(msgChan); //Bandwidth and center frequency m_objChannelMarker.setBandwidth(ui->spiBandwidth->value()); - //m_objChannelizer->configure(m_objChannelizer->getInputMessageQueue(), m_objChannelizer->getInputSampleRate(), m_objChannelMarker.getCenterFrequency()); setTitleColor(m_objChannelMarker.getColor()); - //DATV parameters: cmbStandard cmbModulation cmbFEC spiBandwidth spiSymbolRate spiNotchFilters chkAllowDrift chkFastlock chkHDLC chkHardMetric chkResample chkViterbi - strStandard = ui->cmbStandard->currentText(); if(strStandard=="DVB-S") @@ -412,6 +394,12 @@ void DATVDemodGUI::applySettings() enmSelectedModulation=BPSK; } + //Viterbi only for BPSK et QPSK + if((enmSelectedModulation!=BPSK) && (enmSelectedModulation!=QPSK)) + { + ui->chkViterbi->setChecked(false); + } + strFEC = ui->cmbFEC->currentText(); @@ -452,21 +440,36 @@ void DATVDemodGUI::applySettings() enmFEC=FEC12; } + if (ui->cmbFilter->currentIndex()==0) + { + enmSampler = SAMP_LINEAR; + } + else if(ui->cmbFilter->currentIndex()==1) + { + enmSampler = SAMP_NEAREST; + } + else + { + enmSampler = SAMP_RRC; + } - m_objDATVDemod->configure(m_objDATVDemod->getInputMessageQueue(), - m_objChannelMarker.getBandwidth(), - m_objChannelMarker.getCenterFrequency(), - enmVersion, - enmSelectedModulation, - enmFEC, - ui->spiSymbolRate->value(), - ui->spiNotchFilters->value(), - ui->chkAllowDrift->isChecked(), - ui->chkFastlock->isChecked(), - ui->chkHDLC->isChecked(), - ui->chkHardMetric->isChecked(), - ui->chkResample->isChecked(), - ui->chkViterbi->isChecked()); + + m_objDATVDemod->configure( + m_objDATVDemod->getInputMessageQueue(), + m_objChannelMarker.getBandwidth(), + m_objChannelMarker.getCenterFrequency(), + enmVersion, + enmSelectedModulation, + enmFEC, + ui->spiSymbolRate->value(), + ui->spiNotchFilters->value(), + ui->chkAllowDrift->isChecked(), + ui->chkFastlock->isChecked(), + enmSampler, + ui->chkHardMetric->isChecked(), + ((float)ui->spiRollOff->value())/100.0f, + ui->chkViterbi->isChecked(), + ui->spiExcursion->value()); qDebug() << "DATVDemodGUI::applySettings:" << " .inputSampleRate: " << 0 /*m_objChannelizer->getInputSampleRate()*/ @@ -622,25 +625,11 @@ void DATVDemodGUI::on_chkHardMetric_clicked() applySettings(); } -/* -void DATVDemodGUI::on_pushButton_clicked() -{ - applySettings(); -} -*/ - void DATVDemodGUI::on_pushButton_2_clicked() { resetToDefaults(); } -/* -void DATVDemodGUI::on_spiSampleRate_valueChanged(int arg1) -{ - applySettings(); -} -*/ - void DATVDemodGUI::on_spiSymbolRate_valueChanged(int arg1 __attribute__((unused))) { applySettings(); @@ -651,21 +640,11 @@ void DATVDemodGUI::on_spiNotchFilters_valueChanged(int arg1 __attribute__((unuse applySettings(); } -void DATVDemodGUI::on_chkHDLC_clicked() -{ - applySettings(); -} - void DATVDemodGUI::on_chkAllowDrift_clicked() { applySettings(); } -void DATVDemodGUI::on_chkResample_clicked() -{ - applySettings(); -} - void DATVDemodGUI::on_pushButton_3_clicked() { @@ -677,23 +656,6 @@ void DATVDemodGUI::on_pushButton_3_clicked() } } -/* -void DATVDemodGUI::on_mediaStateChanged(QMediaPlayer::State state) -{ - switch(state) - { - case QMediaPlayer::PlayingState: - ui->pushButton_3->setIcon(style()->standardIcon(QStyle::SP_MediaPause)); - break; - default: - ui->pushButton_3->setIcon(style()->standardIcon(QStyle::SP_MediaPlay)); - break; - } - - ui->lblReadStatus->setText(QString("%1").arg(strLitteralState)); - -} -*/ void DATVDemodGUI::on_pushButton_4_clicked() { @@ -726,7 +688,7 @@ QString DATVDemodGUI::formatBytes(qint64 intBytes) void DATVDemodGUI::on_StreamDataAvailable(int *intPackets __attribute__((unused)), int *intBytes, int *intPercent, qint64 *intTotalReceived) { - ui->lblStatus->setText(QString("Decod: %1B").arg(formatBytes(*intTotalReceived))); + ui->lblStatus->setText(QString("Data: %1B").arg(formatBytes(*intTotalReceived))); m_intLastDecodedData = *intTotalReceived; if((*intPercent)<100) @@ -752,3 +714,68 @@ void DATVDemodGUI::on_chkFastlock_clicked() { applySettings(); } + +void DATVDemodGUI::on_StreamMetaDataChanged(DataTSMetaData2 *objMetaData) +{ + QString strMetaData=""; + + if(objMetaData!=NULL) + { + + 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()); + + } + 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) + { + ui->pushButton_3->setIcon(style()->standardIcon(QStyle::SP_MediaPause)); + } + else + { + ui->pushButton_3->setIcon(style()->standardIcon(QStyle::SP_MediaPlay)); + } + + if(objMetaData->Height>0) + { + ui->screenTV_2->setFixedWidth((int)objMetaData->Width*(270.0f/(float)objMetaData->Height)); + } + } +} + +void DATVDemodGUI::displayRRCParameters(bool blnVisible) +{ + ui->spiRollOff->setVisible(blnVisible); + ui->spiExcursion->setVisible(blnVisible); + ui->label_5->setVisible(blnVisible); + ui->label_6->setVisible(blnVisible); +} + +void DATVDemodGUI::on_cmbFilter_currentIndexChanged(int index __attribute__((unused))) +{ + displayRRCParameters((ui->cmbFilter->currentIndex()==2)); + + applySettings(); +} + +void DATVDemodGUI::on_spiRollOff_valueChanged(int arg1 __attribute__((unused))) +{ + applySettings(); +} + +void DATVDemodGUI::on_spiExcursion_valueChanged(int arg1 __attribute__((unused))) +{ + applySettings(); +} diff --git a/plugins/channelrx/demoddatv/datvdemodgui.h b/plugins/channelrx/demoddatv/datvdemodgui.h index 1f1052d09..406197b43 100644 --- a/plugins/channelrx/demoddatv/datvdemodgui.h +++ b/plugins/channelrx/demoddatv/datvdemodgui.h @@ -81,40 +81,38 @@ private slots: void on_cmbFEC_currentIndexChanged(const QString &arg1); void on_chkViterbi_clicked(); void on_chkHardMetric_clicked(); - //void on_pushButton_clicked(); void on_pushButton_2_clicked(); - //void on_spiSampleRate_valueChanged(int arg1); - void on_spiSymbolRate_valueChanged(int arg1); void on_spiNotchFilters_valueChanged(int arg1); - void on_chkHDLC_clicked(); - void on_chkAllowDrift_clicked(); - void on_chkResample_clicked(); - void on_pushButton_3_clicked(); void on_pushButton_4_clicked(); void on_mouseEvent(QMouseEvent* obj); void on_StreamDataAvailable(int *intPackets, int *intBytes, int *intPercent, qint64 *intTotalReceived); + void on_StreamMetaDataChanged(DataTSMetaData2 *objMetaData); void on_spiBandwidth_valueChanged(int arg1); - void on_chkFastlock_clicked(); + void on_cmbFilter_currentIndexChanged(int index); + + void on_spiRollOff_valueChanged(int arg1); + + void on_spiExcursion_valueChanged(int arg1); + private: Ui::DATVDemodGUI* ui; PluginAPI* m_objPluginAPI; DeviceUISet* m_deviceUISet; - //DeviceSourceAPI* m_objDeviceAPI; ChannelMarker m_objChannelMarker; ThreadedBasebandSampleSink* m_objThreadedChannelizer; DownChannelizer* m_objChannelizer; @@ -132,7 +130,6 @@ private: bool m_blnDoApplySettings; bool m_blnButtonPlayClicked; - //explicit DATVDemodGUI(PluginAPI* objPluginAPI, DeviceSourceAPI *objDeviceAPI, QWidget* objParent = NULL); explicit DATVDemodGUI(PluginAPI* objPluginAPI, DeviceUISet *deviceUISet, BasebandSampleSink *rxChannel, QWidget* objParent = 0); virtual ~DATVDemodGUI(); @@ -140,6 +137,8 @@ private: void applySettings(); QString formatBytes(qint64 intBytes); + void displayRRCParameters(bool blnVisible); + void leaveEvent(QEvent*); void enterEvent(QEvent*); }; diff --git a/plugins/channelrx/demoddatv/datvdemodgui.ui b/plugins/channelrx/demoddatv/datvdemodgui.ui index 4b374e721..6e77f6c43 100644 --- a/plugins/channelrx/demoddatv/datvdemodgui.ui +++ b/plugins/channelrx/demoddatv/datvdemodgui.ui @@ -7,7 +7,7 @@ 0 0 512 - 520 + 640 @@ -19,13 +19,13 @@ 512 - 520 + 640 512 - 520 + 640 @@ -97,6 +97,9 @@ 220 + + Signal constellation + @@ -128,16 +131,14 @@ 21 + + DVB Standard + DVB-S - - - DVB-S2 - - @@ -148,6 +149,9 @@ 21 + + Modulation scheme + BPSK @@ -203,6 +207,9 @@ 21 + + FEC ratio + 1/2 @@ -228,21 +235,6 @@ 7/8 - - - 4/5 - - - - - 8/9 - - - - - 9/10 - - @@ -253,6 +245,9 @@ 20 + + Fast signal decode + FAST LOCK @@ -261,11 +256,14 @@ 140 - 140 + 120 81 20 + + Viterbi algorithm (CPU intensive) + VITERBI @@ -279,6 +277,9 @@ 20 + + Constellation hardening + HARD METRIC @@ -309,19 +310,6 @@ Bandwidth - - - - 10 - 140 - 101 - 20 - - - - HDLC - - @@ -331,6 +319,9 @@ 20 + + Small frequency drift compensation + ALLOW DRIFT @@ -344,6 +335,9 @@ 23 + + Number of stray peaks to suppress + 32 @@ -361,28 +355,18 @@ Notch filter - - - - 140 - 120 - 85 - 20 - - - - RESAMPLE - - 70 - 190 + 200 181 20 + + Video buffer fill + 0 @@ -391,11 +375,14 @@ 10 - 170 + 180 111 16 + + Total number of bytes decoded + - @@ -404,7 +391,7 @@ 230 - 140 + 120 21 22 @@ -422,6 +409,9 @@ 23 + + Symbol rate + 1 @@ -441,6 +431,9 @@ 23 + + RF filter bandwidth + 1000 @@ -455,11 +448,14 @@ 130 - 170 + 180 121 16 + + Stream speed + - @@ -468,7 +464,7 @@ 10 - 190 + 200 61 15 @@ -477,46 +473,189 @@ Buffer: + + + + 10 + 150 + 91 + 22 + + + + Filter + + + + FIR LINEAR + + + + + FIR NEAREST + + + + + FIR RRC + + + + + + + 140 + 150 + 41 + 23 + + + + RRC filter roll off factor + + + 1 + + + 99 + + + 35 + + + + + + 106 + 150 + 28 + 23 + + + + R.off + + + + + + 180 + 150 + 28 + 23 + + + + Exc + + + + + + 210 + 150 + 41 + 23 + + + + Filter excursion (dB) + + + 1 + + + 99 + + + 10 + + 10 - 260 + 250 496 - 240 + 385 496 - 240 + 385 496 - 240 + 385 VIDEO Stream - + + + + 0 + 300 + 281 + 81 + + + + true + + + false + + + + + + 400 + 350 + 91 + 27 + + + + Full screen video (click in the image to return) + + + Full Screen + + + + + + 400 + 300 + 91 + 27 + + + + Start/Stop video streaming + + + Video + + + 0 20 - 358 - 211 + 488 + 272 - - - QLayout::SetMinimumSize - - + + @@ -526,16 +665,19 @@ - 356 - 200 + 480 + 270 - 356 - 200 + 355 + 270 + + Video + @@ -543,73 +685,93 @@ - + + + false + - 360 - 20 - 131 - 211 + 300 + 320 + 85 + 20 - - QFrame::StyledPanel + + Transport stream detected - - QFrame::Raised + + Transport + + + true + + + + + false + + + + 300 + 340 + 85 + 20 + + + + Video data detected + + + Video + + + true + + + + + false + + + + 300 + 360 + 85 + 20 + + + + Video being decoded + + + Decoding + + + true + + + + + false + + + + 300 + 300 + 85 + 20 + + + + Data being received + + + Data + + + true - - - - 10 - 10 - 111 - 27 - - - - Video - - - - - - 10 - 50 - 111 - 27 - - - - Full Screen - - - - - - 10 - 120 - 111 - 16 - - - - - - - - - - - 10 - 90 - 111 - 16 - - - - - - - diff --git a/plugins/channelrx/demoddatv/datvdemodplugin.cpp b/plugins/channelrx/demoddatv/datvdemodplugin.cpp index 690d17ea2..2e3dbe018 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("3.13.0"), + QString("3.2.0"), QString("(c) F4HKW for SDRAngel using LeanSDR framework (c) F4DAV"), QString("https://github.com/f4exb/sdrangel"), true, @@ -52,8 +52,7 @@ void DATVDemodPlugin::initPlugin(PluginAPI* ptrPluginAPI) m_ptrPluginAPI = ptrPluginAPI; // register DATV demodulator - m_ptrPluginAPI->registerRxChannel(DATVDemod::m_channelIdURI, DATVDemod::m_channelId, this); - + m_ptrPluginAPI->registerRxChannel(DATVDemod::m_channelIdURI, DATVDemod::m_channelId, this); } PluginInstanceGUI* DATVDemodPlugin::createRxChannelGUI(DeviceUISet *deviceUISet, BasebandSampleSink *rxChannel) diff --git a/plugins/channelrx/demoddatv/datvideorender.cpp b/plugins/channelrx/demoddatv/datvideorender.cpp index 41e58a21d..efe47e4dc 100644 --- a/plugins/channelrx/demoddatv/datvideorender.cpp +++ b/plugins/channelrx/demoddatv/datvideorender.cpp @@ -108,7 +108,7 @@ static int64_t SeekFunction(void* opaque, int64_t offset, int whence) return objStream->pos(); } -bool DATVideoRender::InitializeFFMPEG() +void DATVideoRender::ResetMetaData() { MetaData.CodecID=-1; MetaData.PID=-1; @@ -120,7 +120,18 @@ bool DATVideoRender::InitializeFFMPEG() MetaData.Channels=-1; MetaData.CodecDescription= ""; - if(m_blnIsFFMPEGInitialized==true) + MetaData.OK_Decoding=false; + MetaData.OK_TransportStream=false; + MetaData.OK_VideoStream=false; + + emit onMetaDataChanged(&MetaData); +} + +bool DATVideoRender::InitializeFFMPEG() +{ + ResetMetaData(); + + if(m_blnIsFFMPEGInitialized) { return false; } @@ -175,6 +186,8 @@ 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=""; @@ -199,6 +212,8 @@ bool DATVideoRender::PreprocessStream() MetaData.Stream = QString("%1").arg(objBuffer); } + emit onMetaDataChanged(&MetaData); + //Decoder objCodec = avcodec_find_decoder(m_objDecoderCtx->codec_id); if(objCodec==NULL) @@ -238,10 +253,14 @@ bool DATVideoRender::PreprocessStream() MetaData.Width=m_objDecoderCtx->width; MetaData.Height=m_objDecoderCtx->height; - MetaData.BitRate=m_objDecoderCtx->bit_rate; + 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); + return true; } @@ -251,13 +270,11 @@ bool DATVideoRender::OpenStream(DATVideostream *objDevice) unsigned char * ptrIOBuffer = NULL; AVIOContext * objIOCtx = NULL; - if(m_blnRunning==true) + if(m_blnRunning) { return false; } - //Only once execution - m_blnRunning=true; if(objDevice==NULL) { @@ -266,19 +283,40 @@ bool DATVideoRender::OpenStream(DATVideostream *objDevice) return false; } - if(m_blnIsOpen==true) + + if(m_blnIsOpen) { qDebug() << "DATVideoProcess::OpenStream already open"; return false; } + if(objDevice->bytesAvailable()<=0) + { + + qDebug() << "DATVideoProcess::OpenStream no data available"; + + MetaData.OK_Data=false; + emit onMetaDataChanged(&MetaData); + + return false; + } + + //Only once execution + m_blnRunning=true; + + MetaData.OK_Data=true; + emit onMetaDataChanged(&MetaData); + + InitializeFFMPEG(); + if(!m_blnIsFFMPEGInitialized) { qDebug() << "DATVideoProcess::OpenStream FFMPEG not initialized"; + m_blnRunning=false; return false; } @@ -286,9 +324,11 @@ bool DATVideoRender::OpenStream(DATVideostream *objDevice) { qDebug() << "DATVideoProcess::OpenStream cannot open QIODevice"; + m_blnRunning=false; return false; } + //Connect QIODevice to FFMPEG Reader m_objFormatCtx = avformat_alloc_context(); @@ -297,6 +337,7 @@ bool DATVideoRender::OpenStream(DATVideostream *objDevice) { qDebug() << "DATVideoProcess::OpenStream cannot alloc format FFMPEG context"; + m_blnRunning=false; return false; } @@ -318,12 +359,13 @@ bool DATVideoRender::OpenStream(DATVideostream *objDevice) { qDebug() << "DATVideoProcess::OpenStream cannot open stream"; + m_blnRunning=false; return false; } - if(!PreprocessStream()) { + m_blnRunning=false; return false; } @@ -341,14 +383,14 @@ bool DATVideoRender::RenderStream() int intGotFrame; bool blnNeedRenderingSetup; - if (!m_blnIsOpen) + if(!m_blnIsOpen) { - qDebug() << "DATVideoProcess::RenderStream: Stream not open"; + qDebug() << "DATVideoProcess::RenderStream Stream not open"; return false; } - if (m_blnRunning) + if(m_blnRunning) { return false; } @@ -413,7 +455,7 @@ bool DATVideoRender::RenderStream() av_opt_set_int(m_objSwsCtx,"dsth",m_objFrame->height,0); av_opt_set_int(m_objSwsCtx,"dst_format",AV_PIX_FMT_RGB24 ,0); - av_opt_set_int(m_objSwsCtx,"sws_flag",SWS_FAST_BILINEAR /* SWS_BICUBIC*/,0); + av_opt_set_int(m_objSwsCtx,"sws_flag", SWS_FAST_BILINEAR /* SWS_BICUBIC*/,0); if(sws_init_context(m_objSwsCtx, NULL, NULL)<0) { @@ -455,6 +497,8 @@ bool DATVideoRender::RenderStream() MetaData.Width = m_objFrame->width; MetaData.Height = m_objFrame->height; + MetaData.OK_Decoding = true; + emit onMetaDataChanged(&MetaData); } //Frame rendering @@ -482,25 +526,17 @@ bool DATVideoRender::RenderStream() m_blnRunning=false; - //AVDictionaryEntry *objRslt= av_dict_get(fmt_ctx->programs[video_stream_index]->metadata,"service_provider",NULL,0); - //char objErrBuf[1024]; - //memset(objErrBuf,0,1024); - //av_strerror(ret,objErrBuf,1024); - return true; } bool DATVideoRender::CloseStream(QIODevice *objDevice) { - if(m_blnRunning==true) + if(m_blnRunning) { return false; } - //Only once execution - m_blnRunning=true; - if(!objDevice) { qDebug() << "DATVideoProcess::CloseStream QIODevice is NULL"; @@ -508,9 +544,9 @@ bool DATVideoRender::CloseStream(QIODevice *objDevice) return false; } - if (!m_blnIsOpen) + if(!m_blnIsOpen) { - qDebug() << "DATVideoProcess::CloseStream: Stream not open"; + qDebug() << "DATVideoProcess::CloseStream Stream not open"; return false; } @@ -522,6 +558,9 @@ bool DATVideoRender::CloseStream(QIODevice *objDevice) return false; } + //Only once execution + m_blnRunning=true; + avformat_close_input(&m_objFormatCtx); m_objFormatCtx=NULL; @@ -531,7 +570,6 @@ bool DATVideoRender::CloseStream(QIODevice *objDevice) m_objDecoderCtx=NULL; } - if(m_objFrame) { av_frame_unref(m_objFrame); @@ -553,5 +591,8 @@ bool DATVideoRender::CloseStream(QIODevice *objDevice) m_intCurrentRenderWidth=-1; m_intCurrentRenderHeight=-1; + ResetMetaData(); + emit onMetaDataChanged(&MetaData); + return true; } diff --git a/plugins/channelrx/demoddatv/datvideorender.h b/plugins/channelrx/demoddatv/datvideorender.h index 3d44cad3a..b3341b9a2 100644 --- a/plugins/channelrx/demoddatv/datvideorender.h +++ b/plugins/channelrx/demoddatv/datvideorender.h @@ -39,13 +39,18 @@ extern "C" #include #include "libswscale/swscale.h" - } struct DataTSMetaData2 { int PID; int CodecID; + + bool OK_Data; + bool OK_Decoding; + bool OK_TransportStream; + bool OK_VideoStream; + QString Program; QString Stream; @@ -53,12 +58,16 @@ struct DataTSMetaData2 int Height; int BitRate; int Channels; + + QString CodecDescription; DataTSMetaData2() { PID=-1; CodecID=-1; + + Program=""; Stream=""; @@ -67,12 +76,19 @@ struct DataTSMetaData2 BitRate=-1; Channels=-1; CodecDescription=""; + + OK_Data=false; + OK_Decoding=false; + OK_TransportStream=false; + OK_VideoStream=false; + } }; class DATVideoRender : public DATVScreen { Q_OBJECT + public: explicit DATVideoRender(QWidget * parent); void SetFullScreen(bool blnFullScreen); @@ -106,18 +122,17 @@ private: bool InitializeFFMPEG(); bool PreprocessStream(); - - + void ResetMetaData(); protected: virtual bool eventFilter(QObject *obj, QEvent *event); signals: - -public slots: + void onMetaDataChanged(DataTSMetaData2 *objMetaData); }; +//To run Video Rendering with a dedicated thread class DATVideoRenderThread: public QThread { @@ -141,12 +156,11 @@ class DATVideoRenderThread: public QThread m_objRenderer = objRenderer; m_objStream = objStream; m_blnRenderingVideo=false; - } void run() { - if(m_blnRenderingVideo==true) + if(m_blnRenderingVideo) { return; } @@ -156,19 +170,11 @@ class DATVideoRenderThread: public QThread return ; } - m_blnRenderingVideo=false; + m_blnRenderingVideo = m_objRenderer->OpenStream(m_objStream); - if(m_objRenderer->OpenStream(m_objStream)) + if(!m_blnRenderingVideo) { - qInfo("DATVideoRenderThread::run: PID: %d W: %d H: %d Codec: %s Data: %s Service: %s", - m_objRenderer->MetaData.PID, - m_objRenderer->MetaData.Width, - m_objRenderer->MetaData.Height, - m_objRenderer->MetaData.CodecDescription.toStdString().c_str(), - m_objRenderer->MetaData.Program.toStdString().c_str(), - m_objRenderer->MetaData.Stream.toStdString().c_str()); - - m_blnRenderingVideo=true; + return; } while((m_objRenderer->RenderStream()) && (m_blnRenderingVideo==true)) @@ -177,6 +183,8 @@ class DATVideoRenderThread: public QThread m_objRenderer->CloseStream(m_objStream); + m_blnRenderingVideo=false; + } void stopRendering() @@ -186,7 +194,6 @@ class DATVideoRenderThread: public QThread private: - DATVideoRender *m_objRenderer; DATVideostream *m_objStream; bool m_blnRenderingVideo; diff --git a/plugins/channelrx/demoddatv/datvideostream.cpp b/plugins/channelrx/demoddatv/datvideostream.cpp index 88807f353..53016cb76 100644 --- a/plugins/channelrx/demoddatv/datvideostream.cpp +++ b/plugins/channelrx/demoddatv/datvideostream.cpp @@ -26,6 +26,7 @@ DATVideostream::DATVideostream(): m_intPacketReceived=0; m_intMemoryLimit = DefaultMemoryLimit; MultiThreaded=false; + ThreadTimeOut=-1; m_objeventLoop.connect(this,SIGNAL(onDataAvailable()), &m_objeventLoop, SLOT(quit()),Qt::QueuedConnection); } @@ -115,7 +116,7 @@ int DATVideostream::pushData(const char * chrData, int intSize) } bool DATVideostream::isSequential() const -{ +{ return true; } @@ -139,10 +140,11 @@ bool DATVideostream::open(OpenMode mode) //PROTECTED qint64 DATVideostream::readData(char *data, qint64 len) -{ +{ QByteArray objCurrentArray; int intEffectiveLen=0; int intExpectedLen=0; + int intThreadLoop=0; intExpectedLen = (int) len; @@ -160,15 +162,25 @@ qint64 DATVideostream::readData(char *data, qint64 len) //DATA in FIFO ? -> Waiting for DATA if((m_objFIFO.isEmpty()) || (m_objFIFO.count()=0) + { + if(intThreadLoop*5>ThreadTimeOut) + { + return -1; + } + } } } else @@ -212,12 +224,12 @@ qint64 DATVideostream::readData(char *data, qint64 len) return (qint64)intEffectiveLen; } -qint64 DATVideostream::writeData(const char *data, qint64 len) +qint64 DATVideostream::writeData(const char *data __attribute__((unused)), qint64 len __attribute__((unused))) { return 0; } -qint64 DATVideostream::readLineData(char *data, qint64 maxSize) -{ +qint64 DATVideostream::readLineData(char *data __attribute__((unused)), qint64 maxSize __attribute__((unused))) +{ return 0; } diff --git a/plugins/channelrx/demoddatv/datvideostream.h b/plugins/channelrx/demoddatv/datvideostream.h index 717ec5ea9..e9387ac69 100644 --- a/plugins/channelrx/demoddatv/datvideostream.h +++ b/plugins/channelrx/demoddatv/datvideostream.h @@ -37,6 +37,7 @@ public: ~DATVideostream(); bool MultiThreaded; + int ThreadTimeOut; int pushData(const char * chrData, int intSize); bool setMemoryLimit(int intMemoryLimit); diff --git a/plugins/channelrx/demoddatv/datvscreen.cpp b/plugins/channelrx/demoddatv/datvscreen.cpp index ea74c249b..754539294 100644 --- a/plugins/channelrx/demoddatv/datvscreen.cpp +++ b/plugins/channelrx/demoddatv/datvscreen.cpp @@ -52,7 +52,7 @@ DATVScreen::~DATVScreen() QRgb* DATVScreen::getRowBuffer(int intRow) { - if (m_blnGLContextInitialized == false) + if (!m_blnGLContextInitialized) { return NULL; } @@ -161,7 +161,7 @@ void DATVScreen::paintGL() m_objMutex.unlock(); } -void DATVScreen::mousePressEvent(QMouseEvent* event) +void DATVScreen::mousePressEvent(QMouseEvent* event __attribute__((unused))) { } @@ -194,13 +194,20 @@ bool DATVScreen::selectRow(int intLine) { return m_objGLShaderArray.SelectRow(intLine); } + else + { + return false; + } } bool DATVScreen::setDataColor(int intCol, int intRed, int intGreen, int intBlue) { if (m_blnGLContextInitialized) - { - return m_objGLShaderArray.SetDataColor(intCol, - qRgb(intRed, intGreen, intBlue)); - } + { + return m_objGLShaderArray.SetDataColor(intCol, qRgb(intRed, intGreen, intBlue)); + } + else + { + return false; + } } diff --git a/plugins/channelrx/demoddatv/datvscreen.h b/plugins/channelrx/demoddatv/datvscreen.h index 05c2ceb68..7dc6b34e0 100644 --- a/plugins/channelrx/demoddatv/datvscreen.h +++ b/plugins/channelrx/demoddatv/datvscreen.h @@ -33,12 +33,8 @@ #include "util/export.h" #include "util/bitfieldindex.h" - - class QPainter; - - class SDRANGEL_API DATVScreen: public QGLWidget { Q_OBJECT diff --git a/plugins/channelrx/demoddatv/datvvideoplayer.h b/plugins/channelrx/demoddatv/datvvideoplayer.h index 3ea33e368..911e13fea 100644 --- a/plugins/channelrx/demoddatv/datvvideoplayer.h +++ b/plugins/channelrx/demoddatv/datvvideoplayer.h @@ -23,32 +23,42 @@ namespace leansdr { - template struct datvvideoplayer : runnable +template struct datvvideoplayer: runnable +{ + datvvideoplayer(scheduler *sch, pipebuf &_in, DATVideostream * objVideoStream) : + runnable(sch, _in.name), in(_in), m_objVideoStream(objVideoStream) { - datvvideoplayer(scheduler *sch, pipebuf &_in, DATVideostream * objVideoStream) : - runnable(sch, _in.name), - in(_in), - m_objVideoStream(objVideoStream) - { - } + } - void run() - { + void run() + { int size = in.readable() * sizeof(T); - if ( ! size ) return; + if (!size) + return; - int nw = m_objVideoStream->pushData((const char *)in.rd(),size); + int nw = m_objVideoStream->pushData((const char *) in.rd(), size); - if ( ! nw ) fatal("pipe"); - if ( nw < 0 ) fatal("write"); - if ( nw % sizeof(T) ) fatal("partial write"); - in.read(nw/sizeof(T)); - - } - private: - pipereader in; - DATVideostream * m_objVideoStream; - }; + if (!nw) + { + 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; +}; } diff --git a/plugins/channelrx/demoddatv/glshaderarray.cpp b/plugins/channelrx/demoddatv/glshaderarray.cpp index bb4bae585..985b16397 100644 --- a/plugins/channelrx/demoddatv/glshaderarray.cpp +++ b/plugins/channelrx/demoddatv/glshaderarray.cpp @@ -126,7 +126,7 @@ void GLShaderArray::InitializeGL(int intCols, int intRows) QRgb * GLShaderArray::GetRowBuffer(int intRow) { - if (m_blnInitialized == false) + if (!m_blnInitialized) { return 0; } @@ -167,7 +167,7 @@ void GLShaderArray::RenderPixels(unsigned char *chrData) QRgb *ptrLine; - if (m_blnInitialized == false) + if (!m_blnInitialized) { return; }