31#ifndef DW_FRAMEWORK_CHANNEL_PARAMETERS_HPP_
32#define DW_FRAMEWORK_CHANNEL_PARAMETERS_HPP_
34#include <dwcgf/Types.hpp>
36#include <dw/core/base/Types.h>
37#include <dw/core/container/BaseString.hpp>
38#include <dw/core/container/VectorFixed.hpp>
39#include <dw/core/system/NvMediaExt.h>
51 DW_CHANNEL_TYPE_SHMEM_LOCAL = 0,
52 DW_CHANNEL_TYPE_SHMEM_REMOTE = 1,
53 DW_CHANNEL_TYPE_EGLSTREAM = 2,
54 DW_CHANNEL_TYPE_SOCKET = 3,
55 DW_CHANNEL_TYPE_DDS = 4,
56 DW_CHANNEL_TYPE_NVSCI = 5,
64 case DW_CHANNEL_TYPE_SHMEM_LOCAL:
65 result =
"type=SHMEM_LOCAL";
67 case DW_CHANNEL_TYPE_SHMEM_REMOTE:
68 result =
"type=SHMEM_REMOTE";
70 case DW_CHANNEL_TYPE_EGLSTREAM:
71 result =
"type=EGLSTREAM";
73 case DW_CHANNEL_TYPE_SOCKET:
74 result =
"type=SOCKET";
76 case DW_CHANNEL_TYPE_DDS:
79 case DW_CHANNEL_TYPE_NVSCI:
80 result =
"type=NVSCI";
177 std::size_t start = 0;
182 end = value.find(
"|", start);
184 ChannelParamStr valueSubString = (end != dw::core::FixedString<1>::NPOS) ? value.substr(start, end - start) : value.substr(start, value.length() - start);
186 if (valueSubString ==
"CPU")
190 else if (valueSubString ==
"EGL")
194 else if (valueSubString ==
"CUDA")
198 else if (valueSubString ==
"PVA")
202 else if (valueSubString ==
"DLA")
206 else if (valueSubString ==
"NVMEDIA")
212 throw Exception(DW_INVALID_ARGUMENT,
"ChannelNvSciStreamParams: enabledComponents sub-value unrecongnized: ", valueSubString);
216 }
while (end != dw::core::FixedString<1>::NPOS);
225 if (value ==
"dynamic")
229 else if (value ==
"static")
235 throw Exception(DW_INVALID_ARGUMENT,
"ChannelNvSciStreamParams: connection phase value unrecongnized: ", value);
244 if (value ==
"thread")
248 else if (value ==
"process")
252 else if (value ==
"vm")
256 else if (value ==
"chip")
262 throw Exception(DW_INVALID_ARGUMENT,
"ChannelNvSciStreamParams: reach value unrecongnized: ", value);
271 auto translatedSize = strtol(value.c_str(),
nullptr, 10);
272 return translatedSize;
278 auto translatedSize = ParseChannelParameter<int64_t>(value);
279 if (translatedSize < 0)
281 throw Exception(DW_INVALID_ARGUMENT,
"ParseChannelParameter: size_t is negative");
283 size_t result =
static_cast<size_t>(translatedSize);
290 auto translatedSize = ParseChannelParameter<size_t>(value);
291 uint32_t result =
static_cast<uint32_t
>(translatedSize);
298 auto translatedSize = ParseChannelParameter<size_t>(value);
299 if (translatedSize > 0xFFFF)
301 throw Exception(DW_INVALID_ARGUMENT,
"ChannelSocketParams: port is larger than uint16_t allows!");
303 uint16_t result =
static_cast<uint16_t
>(translatedSize);
311 if ((value ==
"true") || (value ==
"1"))
315 else if ((value ==
"false") || (value ==
"0"))
321 throw Exception(DW_INVALID_ARGUMENT,
"ParseChannelParameter: needs to be 'true' or 'false' or 1/0");
330 if (value ==
"producer")
334 else if (value ==
"consumer")
338 else if (value ==
"composite")
344 throw Exception(DW_INVALID_ARGUMENT,
"ParseChannelParameter: role unknown!");
353 if (value ==
"SHMEM_LOCAL")
355 result = ChannelType::DW_CHANNEL_TYPE_SHMEM_LOCAL;
357 else if (value ==
"SHMEM_REMOTE")
359 result = ChannelType::DW_CHANNEL_TYPE_SHMEM_REMOTE;
361 else if (value ==
"EGLSTREAM")
363 result = ChannelType::DW_CHANNEL_TYPE_EGLSTREAM;
365 else if (value ==
"SOCKET")
367 result = ChannelType::DW_CHANNEL_TYPE_SOCKET;
369 else if (value ==
"DDS")
371 result = ChannelType::DW_CHANNEL_TYPE_DDS;
373 else if (value ==
"NVSCI")
375 result = ChannelType::DW_CHANNEL_TYPE_NVSCI;
379 throw Exception(DW_INVALID_ARGUMENT,
"ParseChannelParameter: type unknown!");
389 if (value ==
"mailbox")
393 else if (value ==
"singleton")
399 throw Exception(DW_INVALID_ARGUMENT,
"ParseChannelParameter: ChannelMode unknown!");
407 result = ParseChannelParameter<T>(value);
410template <
size_t Size>
416template <
typename T,
size_t N>
424 endpos = value.find(
":", pos);
425 done = endpos == dw::core::FixedString<1>::NPOS;
426 size_t count = done ? endpos : endpos - pos;
429 result.push_back(entry);
439template <
typename T,
typename... Others>
442 if (key == staticKey)
450template <
typename... Others>
454 std::size_t pos = channelParams.find(
"=");
455 std::size_t value = 0;
456 std::size_t valueEnd = 0;
460 while (pos != dw::core::FixedString<1>::NPOS && value != dw::core::FixedString<1>::NPOS)
462 keyString = channelParams.substr(key, pos - key);
463 value = channelParams.find(
",", pos);
464 valueEnd = (value == dw::core::FixedString<1>::NPOS) ? (channelParams.length() - (pos + 1)) : (value - pos - 1);
465 valueString = channelParams.substr(pos + 1, valueEnd);
469 pos = channelParams.find(
"=", key);
478 bool producerFifo =
false,
479 uint16_t numBlockingConnections = 1,
480 dw::core::FixedString<8>
const sockPrefix = dw::core::FixedString<8>())
482 std::stringstream ss;
483 ss.flags(std::ios::dec);
485 if (serverIP !=
nullptr)
492 ss <<
",producer-fifo=";
493 ss << static_cast<uint32_t>(producerFifo);
494 ss <<
",num-clients=";
495 ss << numBlockingConnections;
496 ss <<
",sock-prefix=";
505 dw::core::FixedString<MAX_CHANNEL_ALL_PARAMS_SIZE> channelParams(params);
508 "producer-fifo", m_producerFifo,
510 "sock-prefix", m_sockPrefix);
525 bool m_producerFifo =
false;
526 dw::core::FixedString<8> m_sockPrefix = dw::core::FixedString<8>();
539 dw::core::FixedString<MAX_CHANNEL_ALL_PARAMS_SIZE> channelParams(params);
567 static_assert(
decltype(
m_streamNames)::CAPACITY_AT_COMPILE_TIME < std::numeric_limits<uint16_t>::max(),
"ChannelNvSciStreamParams: number of outputs over limit");
580 throw Exception(DW_INVALID_ARGUMENT,
"ChannelNvSciStreamParams: stream name index out of range");
593 throw Exception(DW_INVALID_ARGUMENT,
"ChannelNvSciStreamParams: reach index out of range");
614 "fifo-size", m_fifoSize,
616 "singleton-id", m_singletonId,
617 "trace-name", m_traceId,
620 "reuse", m_reuseEnabled,
621 "debug-port", m_debugPort,
622 "num-clients", m_clientsCount,
623 "debug-num-clients", m_debugClientsCount,
626 "data-offset", m_dataOffset,
627 "strict", m_strictFifo,
628 "sync-enabled", m_syncEnabled);
630 adjustPoolCapacity();
632 if (m_clientsCount == 0)
637 if (!m_singletonId.empty())
644 m_mailboxMode =
true;
648 m_singletonMode =
true;
651 if (!m_id.empty() && m_singletonId.empty())
653 m_singletonId = m_id;
664 case DW_CHANNEL_TYPE_SHMEM_LOCAL:
666 case DW_CHANNEL_TYPE_SOCKET:
669 case DW_CHANNEL_TYPE_NVSCI:
672 case DW_CHANNEL_TYPE_SHMEM_REMOTE:
673 case DW_CHANNEL_TYPE_EGLSTREAM:
674 case DW_CHANNEL_TYPE_DDS:
676 throw Exception(DW_NOT_IMPLEMENTED,
"ChannelParams: no parameters for channel type");
689 const char*
getStr()
const {
return m_str.c_str(); }
701 m_strictFifo = strictFifo;
726 if (m_type != ChannelType::DW_CHANNEL_TYPE_SOCKET)
728 throw Exception(DW_CALL_NOT_ALLOWED,
"ChannelParams: getSocketParams: channel is not of type SOCKET");
730 return m_socketParams;
735 if (m_type != ChannelType::DW_CHANNEL_TYPE_NVSCI)
737 throw Exception(DW_CALL_NOT_ALLOWED,
"ChannelParams: getNvSciStreamParams: channel is not of type NVSCI");
739 return m_nvSciStreamParams;
743 void ValidateMailbox()
749 throw Exception(DW_INVALID_ARGUMENT,
"ChannelParams: Singleton and mailbox modes are incompatible with a fifo setting other than 1");
752 if (!m_mailboxMode && m_reuseEnabled)
754 throw Exception(DW_INVALID_ARGUMENT,
"ChannelParams: reuse=true specified when mode!=mailbox. Not valid");
756 if (m_mailboxMode && m_singletonMode)
758 throw Exception(DW_INVALID_ARGUMENT,
"ChannelParams: Singleton mode is incompatible mailbox mode");
762 void ValidateSingleton()
765 if (m_singletonMode && m_singletonId.empty())
767 m_singletonId = m_id;
769 if (!m_singletonMode && !m_singletonId.empty())
771 throw Exception(DW_INVALID_ARGUMENT,
"ChannelParams: Singleton mode requires both the mode set AND singletonId set");
773 if (m_singletonMode && (m_type != ChannelType::DW_CHANNEL_TYPE_SHMEM_LOCAL))
775 throw Exception(DW_INVALID_ARGUMENT,
"ChannelParams: Singleton mode is only valid for SHMEM_LOCAL channels");
779 void adjustPoolCapacity()
801 size_t m_fifoSize = 1;
810 uint32_t m_dataOffset = 0;
811 bool m_syncEnabled =
false;
812 bool m_mailboxMode =
false;
813 bool m_singletonMode =
false;
814 bool m_reuseEnabled =
false;
816 ChannelType m_type = ChannelType::DW_CHANNEL_TYPE_SHMEM_LOCAL;
817 bool m_strictFifo =
true;
819 uint16_t m_clientsCount = 1;
820 uint16_t m_debugClientsCount = 1;
822 uint16_t m_debugPort = 0;
824 ChannelSocketParams m_socketParams{};
825 ChannelNvSciStreamParams m_nvSciStreamParams{};
bool isEnabledComponentPva() const
bool isEnabledComponentCpu() const
ChannelNvSciStreamParams & operator=(const ChannelNvSciStreamParams &other)=default
bool isEnabledComponentDla() const
ChannelConnectionType m_connectionType
dw::core::VectorFixed< ChannelReach, 8 > m_reaches
ChannelNvSciStreamEnabledComponents getEnabledComponents() const
ChannelNvSciStreamParams(const char *params)
bool isConnectionTypeDynamic() const
bool isEnabledComponentCuda() const
ChannelNvSciStreamParams(const ChannelNvSciStreamParams &other)=default
const char * getStreamName(uint16_t index=0) const
bool isConnectionTypeStatic() const
ChannelNvSciStreamEnabledComponents m_enabledComponents
ChannelConnectionType getChannelConnectionType() const
ChannelNvSciStreamParams()=default
uint16_t getNumOutputs() const
dw::core::VectorFixed< dw::core::FixedString< 64 >, 8 > m_streamNames
dwTime_t getTimeoutUsec() const
bool isEnabledComponentEgl() const
bool isEnabledComponentNvmedia() const
ChannelReach getChannelReach(uint16_t index=0) const
void setMailboxMode(bool mailboxEnabled)
bool isStrictFifo() const
bool getReuseEnabled() const
size_t getPoolCapacity() const
const char * getStr() const
uint16_t getExpectedConnectionsCount() const
ChannelType getType() const
uint16_t getExpectedDebugConnectionsCount() const
ChannelParams & operator=(const ChannelParams &other)=default
const ChannelSocketParams & getSocketParams() const
bool getSyncEnabled() const
const ChannelNvSciStreamParams & getNvSciStreamParams() const
bool getDebugMode() const
ChannelParamStr getSingletonId() const
ChannelParamStr getTraceId() const
uint16_t getDebugPort() const
void setStrictFifo(bool strictFifo)
ChannelRole getRole() const
bool getMailboxMode() const
ChannelParams(const ChannelParams &other)
ChannelParamStr getId() const
size_t getFifoSize() const
uint32_t getDataOffset() const
ChannelParams(const char *params)
bool getSingletonMode() const
bool hasProducerFifo() const
dw::core::FixedString< 8 > getSockPrefix() const
ChannelSocketParams & operator=(const ChannelSocketParams &other)=default
ChannelParamStr getServerIP() const
ChannelSocketParams(const ChannelSocketParams &other)=default
ChannelSocketParams(const char *params)
static ChannelParamStr getParamStr(const char *serverIP, uint16_t port, bool producerFifo=false, uint16_t numBlockingConnections=1, dw::core::FixedString< 8 > const sockPrefix=dw::core::FixedString< 8 >())
ChannelSocketParams()=default
static const char * ToParam(ChannelType channelType)
ChannelNvSciStreamEnabledComponents
static constexpr uint16_t MAX_CHANNEL_ALL_PARAMS_SIZE
dw::core::FixedString< MAX_CHANNEL_PARAM_SIZE > ChannelParamStr
@ DW_CHANNEL_ROLE_PRODUCER
@ DW_CHANNEL_ROLE_CONSUMER
@ DW_CHANNEL_ROLE_UNKNOWN
@ DW_CHANNEL_ROLE_COMPOSITE
static void ParseChannelParameters(const ChannelParamStr &, const ChannelParamStr &)
constexpr bool IsProducer(ChannelRole role)
static T ParseChannelParameter(const ChannelParamStr &value)
enum ChannelType :uint8_t { DW_CHANNEL_TYPE_SHMEM_LOCAL=0, DW_CHANNEL_TYPE_SHMEM_REMOTE=1, DW_CHANNEL_TYPE_EGLSTREAM=2, DW_CHANNEL_TYPE_SOCKET=3, DW_CHANNEL_TYPE_DDS=4, DW_CHANNEL_TYPE_NVSCI=5, } ChannelType
constexpr ChannelNvSciStreamEnabledComponents operator&(ChannelNvSciStreamEnabledComponents a, ChannelNvSciStreamEnabledComponents b)
constexpr ChannelNvSciStreamEnabledComponents operator|(ChannelNvSciStreamEnabledComponents a, ChannelNvSciStreamEnabledComponents b)
static void ParseAllChannelParameters(const ChannelParamStr &channelParams, Others &&... others)
static constexpr uint16_t MAX_CHANNEL_PARAM_SIZE
constexpr bool IsConsumer(ChannelRole role)
static constexpr uint16_t MAX_CHANNEL_PRODUCERS_COUNT
@ CONNECTION_TYPE_DYNAMIC
static constexpr uint16_t MAX_CHANNEL_CONSUMERS_COUNT