2019-07-28 04:54:04 -04:00
|
|
|
///////////////////////////////////////////////////////////////////////////////////
|
2023-11-18 06:02:48 -05:00
|
|
|
// Copyright (C) 2012 maintech GmbH, Otto-Hahn-Str. 15, 97204 Hoechberg, Germany //
|
|
|
|
// written by Christian Daniel //
|
|
|
|
// Copyright (C) 2015-2021 Edouard Griffiths, F4EXB <f4exb06@gmail.com> //
|
2019-07-28 04:54:04 -04:00
|
|
|
// //
|
|
|
|
// This program is free software; you can redistribute it and/or modify //
|
|
|
|
// it under the terms of the GNU General Public License as published by //
|
|
|
|
// the Free Software Foundation as version 3 of the License, or //
|
|
|
|
// (at your option) any later version. //
|
|
|
|
// //
|
|
|
|
// This program is distributed in the hope that it will be useful, //
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of //
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
|
|
|
|
// GNU General Public License V3 for more details. //
|
|
|
|
// //
|
|
|
|
// You should have received a copy of the GNU General Public License //
|
|
|
|
// along with this program. If not, see <http://www.gnu.org/licenses/>. //
|
|
|
|
///////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
#include <algorithm>
|
|
|
|
#include "datvudpstream.h"
|
|
|
|
|
|
|
|
const int DATVUDPStream::m_tsBlocksPerFrame = 7; // The usual value
|
|
|
|
|
|
|
|
DATVUDPStream::DATVUDPStream(int tsBlockSize) :
|
|
|
|
m_active(false),
|
|
|
|
m_address(QHostAddress::LocalHost),
|
|
|
|
m_port(8882),
|
|
|
|
m_tsBlockSize(tsBlockSize),
|
2021-04-11 17:52:16 -04:00
|
|
|
m_tsBlockIndex(0),
|
|
|
|
m_dataBytes(0),
|
|
|
|
m_totalBytes(0),
|
|
|
|
m_fifoSignalCount(0)
|
2019-07-28 04:54:04 -04:00
|
|
|
{
|
|
|
|
m_tsBuffer = new char[m_tsBlocksPerFrame*m_tsBlockSize];
|
|
|
|
}
|
|
|
|
|
|
|
|
DATVUDPStream::~DATVUDPStream()
|
|
|
|
{
|
|
|
|
delete[] m_tsBuffer;
|
|
|
|
}
|
|
|
|
|
|
|
|
void DATVUDPStream::pushData(const char *chrData, int nbTSBlocks)
|
|
|
|
{
|
|
|
|
if (!m_active) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (int i = 0; i < nbTSBlocks; i++)
|
|
|
|
{
|
2020-08-29 06:46:37 -04:00
|
|
|
std::copy(chrData + i*m_tsBlockSize, chrData + (i+1)*m_tsBlockSize, m_tsBuffer + m_tsBlockIndex*m_tsBlockSize);
|
2021-04-11 17:52:16 -04:00
|
|
|
|
|
|
|
if (m_tsBlockIndex < m_tsBlocksPerFrame - 1)
|
2019-07-28 04:54:04 -04:00
|
|
|
{
|
|
|
|
m_tsBlockIndex++;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_udpSocket.writeDatagram(m_tsBuffer, m_tsBlocksPerFrame*m_tsBlockSize, m_address, m_port);
|
2021-04-11 17:52:16 -04:00
|
|
|
m_dataBytes += m_tsBlocksPerFrame*m_tsBlockSize;
|
|
|
|
m_totalBytes += m_tsBlocksPerFrame*m_tsBlockSize;
|
|
|
|
|
|
|
|
if (++m_fifoSignalCount == 10)
|
|
|
|
{
|
2021-04-11 18:31:47 -04:00
|
|
|
emit fifoData(m_dataBytes, 0, m_totalBytes);
|
2021-04-11 17:52:16 -04:00
|
|
|
m_fifoSignalCount = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_dataBytes = 0;
|
2019-07-28 04:54:04 -04:00
|
|
|
m_tsBlockIndex = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-04-11 17:52:16 -04:00
|
|
|
|
|
|
|
void DATVUDPStream::resetTotalReceived()
|
|
|
|
{
|
|
|
|
m_totalBytes = 0;
|
2021-04-11 18:31:47 -04:00
|
|
|
emit fifoData(m_dataBytes, 0, m_totalBytes);
|
2021-04-11 17:52:16 -04:00
|
|
|
}
|