13#include <adtfstreaming3/samplereader.h>
14#include <adtfmediadescription/sample_codec.h>
15#include <adtfstreaming3/streammetatypeimage.h>
21#include <unordered_map>
36 cImageConverter(
const adtf::streaming::IStreamType& oType);
37 QImage convert(
const adtf::streaming::ISample& oSample);
40 adtf::streaming::tStreamImageFormat m_sInputFormat;
43inline tResult script_error_to_result(
const QJSValue& oScriptResult)
45 if (oScriptResult.isError())
47 RETURN_ERROR_DESC(ERR_FAILED,
"Uncaught script exception at %s:%d: %s",
48 oScriptResult.property(
"fileName").toString().toLocal8Bit().data(),
49 oScriptResult.property(
"lineNumber").toInt(), oScriptResult.toString().toLocal8Bit().data());
53 RETURN_ERROR_DESC(ERR_FAILED,
"Uncaught script exception: %s", oScriptResult.toString().toLocal8Bit().data());
57class cSyncSignalRecievers :
public QObject
62 Q_INVOKABLE
void connect(QJSValue oReciever)
64 m_oRecievers.push_back(oReciever);
67 template<
typename... Arguments>
68 tResult call(Arguments&&... arguments)
70 QJSValueList oJSArgs{std::forward<Arguments>(arguments)...};
71 for (
auto& oReciever : m_oRecievers)
73 auto oScriptResult = oReciever.call(oJSArgs);
74 if (!oScriptResult.isNull() && !oScriptResult.isUndefined())
76 return script_error_to_result(oScriptResult);
83 bool isConnected()
const
85 return !m_oRecievers.empty();
89 std::vector<QJSValue> m_oRecievers;
118 cScriptReader(adtf::streaming::cDynamicSampleReader* pReader, QJSEngine& oEngine);
179 void streamTypeChanged(QObject* type);
192 void trigger(qint64 timestamp);
204 void sample(
const QVariant& sample);
208 void requestsChanged();
211 const QVariantList&
requests() const noexcept;
213 virtual tResult OnTrigger(
adtf::
base::tNanoSeconds tmTrigger) = 0;
216 void DiscardSamples();
217 std::
string GetName();
218 virtual tResult ForwardStreamTypeToScriptHandler(QObject* oType) = 0;
219 virtual std::pair<
bool,
bool> TriggerAndSampleCallbacks() const = 0;
220 QJSEngine& m_oEngine;
223 QVariantMap Transform(const
adtf::ucom::iobject_ptr<const
adtf::streaming::ISample>& pSample);
225 adtf::streaming::cDynamicSampleReader* m_pReader =
nullptr;
226 mutable std::mutex m_oSubStreamsLock;
229 using tSubsStreamDecoder =
230 std::variant<std::monostate,
adtf::mediadescription::cSampleCodecFactory, cImageConverter>;
232 struct tDecodableSubStream
234 tDecodableSubStream(
const QString strName,
235 const adtf::ucom::iobject_ptr<const adtf::streaming::IStreamType>& pType):
236 strName(strName), pType(pType)
240 adtf::ucom::object_ptr<const adtf::streaming::IStreamType> pType;
242 std::unique_ptr<tSubsStreamDecoder> pDecoder;
245 struct tRequestableSubStream
247 tRequestableSubStream(uint32_t nId): nId(nId)
251 adtf::ucom::object_ptr<adtf::streaming::IStreamingRequest> pRequest;
255 QVariantList m_oRequestFilters;
257 bool m_bUseSampleSubStreamId =
false;
260 std::unordered_map<uint32_t, tDecodableSubStream> m_oDecodableSubStreams;
262 std::unordered_map<QString, tRequestableSubStream> m_oRequestableSubStream;
264 static std::unique_ptr<tSubsStreamDecoder>
265 GetStreamDecoder(
const adtf::ucom::iobject_ptr<const adtf::streaming::IStreamType>& pType);
267 static bool MatchesFilter(
const QVariant& oRequestFilter,
const QString& strSubStream)
noexcept;
268 bool MatchesCurrentFilters(
const QString& strSubStream)
const noexcept;
283 using cScriptReader::cScriptReader;
284 tResult OnTrigger(adtf::base::tNanoSeconds tmTrigger)
override;
287 void streamTypeChanged(QObject* type);
288 void trigger(qint64 timestamp);
289 void sample(
const QVariant& sample);
290 void triggerProcessed(qint64 timestamp);
293 tResult ForwardStreamTypeToScriptHandler(QObject* oType)
override;
294 std::pair<bool, bool> TriggerAndSampleCallbacks()
const override;
305 Q_PROPERTY(QObject* streamTypeChanged READ getSyncStreamTypes)
306 Q_PROPERTY(QObject* trigger READ getSyncTrigger)
307 Q_PROPERTY(QObject* sample READ getSyncSample)
310 cSyncScriptReader(adtf::streaming::cDynamicSampleReader* pReader, QJSEngine& oEngine);
311 tResult OnTrigger(adtf::base::tNanoSeconds tmTrigger)
override;
314 tResult ForwardStreamTypeToScriptHandler(QObject* oType)
override;
315 std::pair<bool, bool> TriggerAndSampleCallbacks()
const override;
318 QObject* getSyncStreamTypes()
320 return &m_oSyncStreamTypeRecievers;
323 QObject* getSyncTrigger()
325 return &m_oSyncTriggerRecievers;
328 QObject* getSyncSample()
330 return &m_oSyncSampleRecievers;
333 cSyncSignalRecievers m_oSyncStreamTypeRecievers;
334 cSyncSignalRecievers m_oSyncTriggerRecievers;
335 cSyncSignalRecievers m_oSyncSampleRecievers;
Q_INVOKABLE void cancelRequest(const QVariant &oSubStreamFilter)
QVariantList requests
Definition reader.h:166
Q_INVOKABLE QVariant getNextSample()
Q_INVOKABLE QVariant getLastSample()
Q_INVOKABLE void requestSamples(const QVariant &oSubStreamFilter)
Helper namespace for extension of adtf_string_forward interfaces.
Definition qt_string_intf.h:11
Namespace for the ADTF JavaScript Filter SDK.
Definition clock.h:22
Namespace for all functionality provided by ADTF and its SDKs.
Definition adtfui_pkg.h:13