mirror of
https://github.com/f4exb/sdrangel.git
synced 2024-11-26 01:39:05 -05:00
DATV demod: formatted code
This commit is contained in:
parent
18e20d36bf
commit
7b9cb0e9fe
@ -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<typename T> struct datvconstellation: runnable
|
||||
std::vector<int> cstln_rows;
|
||||
std::vector<int> cstln_cols;
|
||||
|
||||
datvconstellation(scheduler *sch, pipebuf<complex<T> > &_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<complex<T> > &_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<typename T> 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<int>::const_iterator row_it = cstln_rows.begin();
|
||||
std::vector<int>::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<typename T> struct datvconstellation: runnable
|
||||
|
||||
in.read(pixels_per_frame);
|
||||
|
||||
if (++phase >= decimation)
|
||||
{
|
||||
if (++phase >= decimation) {
|
||||
phase = 0;
|
||||
}
|
||||
}
|
||||
@ -128,6 +132,6 @@ template<typename T> struct datvconstellation: runnable
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
} // leansdr
|
||||
|
||||
#endif // DATVCONSTELLATION_H
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -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:
|
||||
|
@ -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();
|
||||
}
|
||||
|
||||
|
@ -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)
|
||||
{
|
||||
|
||||
}
|
||||
|
@ -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);
|
||||
|
@ -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<QIODevice*>(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<void *>(objDevice),
|
||||
&ReadFunction,
|
||||
NULL,
|
||||
&SeekFunction);
|
||||
objIOCtx = avio_alloc_context(ptrIOBuffer,
|
||||
intIOBufferSize,
|
||||
0,
|
||||
reinterpret_cast<void *>(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;
|
||||
}
|
||||
|
@ -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()
|
||||
|
@ -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()<MinStackSize))
|
||||
if ((m_objFIFO.isEmpty()) || (m_objFIFO.count()<MinStackSize))
|
||||
{
|
||||
m_objMutex.unlock();
|
||||
|
||||
if(MultiThreaded==true)
|
||||
if (MultiThreaded == true)
|
||||
{
|
||||
|
||||
intThreadLoop=0;
|
||||
while((m_objFIFO.isEmpty()) || (m_objFIFO.count()<MinStackSize))
|
||||
|
||||
while ((m_objFIFO.isEmpty()) || (m_objFIFO.count() < MinStackSize))
|
||||
{
|
||||
QThread::msleep(5);
|
||||
intThreadLoop ++;
|
||||
intThreadLoop++;
|
||||
|
||||
if(ThreadTimeOut>=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<intEffectiveLen)
|
||||
if (intExpectedLen < intEffectiveLen)
|
||||
{
|
||||
//Partial Read
|
||||
objCurrentArray = m_objFIFO.head();
|
||||
memcpy((void *)data,objCurrentArray.constData(),intExpectedLen);
|
||||
m_objFIFO.head().remove(0,intExpectedLen);
|
||||
intEffectiveLen=intExpectedLen;
|
||||
intEffectiveLen = intExpectedLen;
|
||||
m_intBytesWaiting -= intExpectedLen;
|
||||
}
|
||||
else
|
||||
@ -210,7 +200,7 @@ qint64 DATVideostream::readData(char *data, qint64 len)
|
||||
}
|
||||
|
||||
m_intQueueWaiting = m_objFIFO.count();
|
||||
m_intPercentBuffer = (100*m_intBytesWaiting)/m_intMemoryLimit;
|
||||
m_intPercentBuffer = (100*m_intBytesWaiting) / m_intMemoryLimit;
|
||||
|
||||
emit onDataPackets(&m_intQueueWaiting, &m_intBytesWaiting, &m_intPercentBuffer, &m_intTotalReceived);
|
||||
|
||||
|
@ -23,18 +23,21 @@
|
||||
|
||||
namespace leansdr
|
||||
{
|
||||
|
||||
template<typename T> struct datvvideoplayer: runnable
|
||||
{
|
||||
datvvideoplayer(scheduler *sch, pipebuf<T> &_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<typename T> 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<T> in;
|
||||
DATVideostream * m_objVideoStream;
|
||||
|
Loading…
Reference in New Issue
Block a user