2018-02-22 16:52:49 -05: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-2019, 2021 Edouard Griffiths, F4EXB <f4exb06@gmail.com> //
|
|
|
|
// Copyright (C) 2015 John Greb <hexameron@spam.no> //
|
|
|
|
|
2018-02-22 16:52:49 -05:00
|
|
|
// Copyright (C) 2018 F4HKW //
|
|
|
|
// for F4EXB / SDRAngel //
|
|
|
|
// //
|
|
|
|
// 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 //
|
2019-04-11 00:39:30 -04:00
|
|
|
// (at your option) any later version. //
|
2018-02-22 16:52:49 -05:00
|
|
|
// //
|
|
|
|
// 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/>. //
|
|
|
|
///////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
#ifndef DATVVIDEOPLAYER_H
|
|
|
|
#define DATVVIDEOPLAYER_H
|
|
|
|
|
|
|
|
#include "leansdr/framework.h"
|
|
|
|
#include "datvideostream.h"
|
2019-07-28 04:54:04 -04:00
|
|
|
#include "datvudpstream.h"
|
2018-02-22 16:52:49 -05:00
|
|
|
|
|
|
|
namespace leansdr
|
|
|
|
{
|
2019-03-16 20:36:44 -04:00
|
|
|
|
2018-02-25 19:04:45 -05:00
|
|
|
template<typename T> struct datvvideoplayer: runnable
|
|
|
|
{
|
2019-07-28 04:54:04 -04:00
|
|
|
datvvideoplayer(
|
2021-03-12 18:13:00 -05:00
|
|
|
scheduler *sch,
|
|
|
|
pipebuf<T> &_in,
|
2021-04-11 17:52:16 -04:00
|
|
|
DATVideostream *videoStream,
|
2021-03-12 18:13:00 -05:00
|
|
|
DATVUDPStream *udpStream) :
|
2019-07-28 04:54:04 -04:00
|
|
|
runnable(sch, _in.name),
|
|
|
|
in(_in),
|
2021-04-11 17:52:16 -04:00
|
|
|
m_videoStream(videoStream),
|
|
|
|
m_udpStream(udpStream),
|
|
|
|
m_atomicUDPRunning(0)
|
2018-02-22 16:52:49 -05:00
|
|
|
{
|
2018-02-25 19:04:45 -05:00
|
|
|
}
|
2018-02-22 16:52:49 -05:00
|
|
|
|
2018-02-25 19:04:45 -05:00
|
|
|
void run()
|
|
|
|
{
|
|
|
|
int size = in.readable() * sizeof(T);
|
2019-03-16 20:36:44 -04:00
|
|
|
|
|
|
|
if (!size) {
|
2018-02-25 19:04:45 -05:00
|
|
|
return;
|
2019-03-16 20:36:44 -04:00
|
|
|
}
|
2018-02-22 16:52:49 -05:00
|
|
|
|
2021-04-11 17:52:16 -04:00
|
|
|
int nw;
|
|
|
|
|
2019-07-28 04:54:04 -04:00
|
|
|
m_udpStream->pushData((const char *) in.rd(), in.readable());
|
2021-04-12 05:41:21 -04:00
|
|
|
#if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)
|
2021-04-11 17:52:16 -04:00
|
|
|
m_atomicUDPRunning.storeRelaxed(m_udpStream->isActive() && (size > 0) ? 1 : 0);
|
2021-04-12 05:41:21 -04:00
|
|
|
#else
|
|
|
|
m_atomicUDPRunning.store(m_udpStream->isActive() && (size > 0) ? 1 : 0);
|
|
|
|
#endif
|
2021-04-11 17:52:16 -04:00
|
|
|
if (m_videoStream)
|
2018-02-25 19:04:45 -05:00
|
|
|
{
|
2021-04-11 17:52:16 -04:00
|
|
|
nw = m_videoStream->pushData((const char *) in.rd(), size);
|
2019-03-16 20:36:44 -04:00
|
|
|
|
2021-04-11 17:52:16 -04:00
|
|
|
if (!nw)
|
|
|
|
{
|
|
|
|
fatal("leansdr::datvvideoplayer::run: pipe");
|
|
|
|
return;
|
|
|
|
}
|
2019-03-16 20:36:44 -04:00
|
|
|
|
2021-04-11 17:52:16 -04:00
|
|
|
if (nw < 0)
|
|
|
|
{
|
|
|
|
fatal("leansdr::datvvideoplayer::run: write");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (nw % sizeof(T))
|
|
|
|
{
|
|
|
|
fatal("leansdr::datvvideoplayer::run: partial write");
|
|
|
|
return;
|
|
|
|
}
|
2019-03-16 20:36:44 -04:00
|
|
|
|
2021-04-11 17:52:16 -04:00
|
|
|
if (nw != size) {
|
|
|
|
fprintf(stderr, "leansdr::datvvideoplayer::run: nw: %d size: %d\n", nw, size);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
nw = size;
|
2019-07-28 04:54:04 -04:00
|
|
|
}
|
|
|
|
|
2018-02-25 19:04:45 -05:00
|
|
|
in.read(nw / sizeof(T));
|
|
|
|
}
|
2019-03-16 20:36:44 -04:00
|
|
|
|
2021-04-12 05:41:21 -04:00
|
|
|
bool isUDPRunning() const
|
|
|
|
{
|
|
|
|
#if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)
|
|
|
|
return m_atomicUDPRunning.loadRelaxed() == 1;
|
|
|
|
#else
|
|
|
|
return m_atomicUDPRunning.load() == 1;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
void resetUDPRunning()
|
|
|
|
{
|
|
|
|
#if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)
|
|
|
|
m_atomicUDPRunning.storeRelaxed(0);
|
|
|
|
#else
|
|
|
|
m_atomicUDPRunning.store(0);
|
|
|
|
#endif
|
|
|
|
}
|
2021-04-11 17:52:16 -04:00
|
|
|
|
2018-02-25 19:04:45 -05:00
|
|
|
private:
|
|
|
|
pipereader<T> in;
|
2021-04-11 17:52:16 -04:00
|
|
|
DATVideostream *m_videoStream;
|
2019-07-28 04:54:04 -04:00
|
|
|
DATVUDPStream *m_udpStream;
|
2021-04-11 17:52:16 -04:00
|
|
|
QAtomicInt m_atomicUDPRunning;
|
2018-02-25 19:04:45 -05:00
|
|
|
};
|
2018-02-22 16:52:49 -05:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // DATVVIDEOPLAYER_H
|