• <xmp id="om0om">
  • <table id="om0om"><noscript id="om0om"></noscript></table>
  • Compute Graph Framework SDK Reference  5.8
    All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
    ChannelParameters.hpp
    Go to the documentation of this file.
    1
    2//
    3// Notice
    4// ALL NVIDIA DESIGN SPECIFICATIONS AND CODE ("MATERIALS") ARE PROVIDED "AS IS" NVIDIA MAKES
    5// NO REPRESENTATIONS, WARRANTIES, EXPRESSED, IMPLIED, STATUTORY, OR OTHERWISE WITH RESPECT TO
    6// THE MATERIALS, AND EXPRESSLY DISCLAIMS ANY IMPLIED WARRANTIES OF NONINFRINGEMENT,
    7// MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
    8//
    9// NVIDIA CORPORATION & AFFILIATES assumes no responsibility for the consequences of use of such
    10// information or for any infringement of patents or other rights of third parties that may
    11// result from its use. No license is granted by implication or otherwise under any patent
    12// or patent rights of NVIDIA CORPORATION & AFFILIATES. No third party distribution is allowed unless
    13// expressly authorized by NVIDIA. Details are subject to change without notice.
    14// This code supersedes and replaces all information previously supplied.
    15// NVIDIA CORPORATION & AFFILIATES products are not authorized for use as critical
    16// components in life support devices or systems without express written approval of
    17// NVIDIA CORPORATION & AFFILIATES.
    18//
    19// SPDX-FileCopyrightText: Copyright (c) 2018-2022 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
    20// SPDX-License-Identifier: LicenseRef-NvidiaProprietary
    21//
    22// NVIDIA CORPORATION, its affiliates and licensors retain all intellectual
    23// property and proprietary rights in and to this material, related
    24// documentation and any modifications thereto. Any use, reproduction,
    25// disclosure or distribution of this material and related documentation
    26// without an express license agreement from NVIDIA CORPORATION or
    27// its affiliates is strictly prohibited.
    28//
    30
    31#ifndef DW_FRAMEWORK_CHANNEL_PARAMETERS_HPP_
    32#define DW_FRAMEWORK_CHANNEL_PARAMETERS_HPP_
    33
    34#include <dwcgf/Types.hpp>
    35#include <dwcgf/Exception.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>
    41#include <sstream>
    42#include <limits>
    43
    44namespace dw
    45{
    46namespace framework
    47{
    48
    50using ChannelType = enum ChannelType : uint8_t {
    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,
    57};
    58
    59static inline const char* ToParam(ChannelType channelType)
    60{
    61 const char* result;
    62 switch (channelType)
    63 {
    64 case DW_CHANNEL_TYPE_SHMEM_LOCAL:
    65 result = "type=SHMEM_LOCAL";
    66 break;
    67 case DW_CHANNEL_TYPE_SHMEM_REMOTE:
    68 result = "type=SHMEM_REMOTE";
    69 break;
    70 case DW_CHANNEL_TYPE_EGLSTREAM:
    71 result = "type=EGLSTREAM";
    72 break;
    73 case DW_CHANNEL_TYPE_SOCKET:
    74 result = "type=SOCKET";
    75 break;
    76 case DW_CHANNEL_TYPE_DDS:
    77 result = "type=DDS";
    78 break;
    79 case DW_CHANNEL_TYPE_NVSCI:
    80 result = "type=NVSCI";
    81 break;
    82 default:
    83 result = "";
    84 break;
    85 }
    86 return result;
    87}
    88
    89enum class ChannelRole : uint8_t
    90{
    94 DW_CHANNEL_ROLE_COMPOSITE = 0b11, // Contains both producer and consumer
    95};
    96
    97inline constexpr bool IsProducer(ChannelRole role)
    98{
    99 return static_cast<uint8_t>(role) & static_cast<uint8_t>(ChannelRole::DW_CHANNEL_ROLE_PRODUCER);
    100}
    101
    102inline constexpr bool IsConsumer(ChannelRole role)
    103{
    104 return static_cast<uint8_t>(role) & static_cast<uint8_t>(ChannelRole::DW_CHANNEL_ROLE_CONSUMER);
    105}
    106
    107static constexpr uint16_t MAX_CHANNEL_PARAM_SIZE = 256;
    108static constexpr uint16_t MAX_CHANNEL_ALL_PARAMS_SIZE = 256;
    109static constexpr uint16_t MAX_CHANNEL_PRODUCERS_COUNT = 1024;
    110static constexpr uint16_t MAX_CHANNEL_CONSUMERS_COUNT = 256;
    111
    112using ChannelParamStr = dw::core::FixedString<MAX_CHANNEL_PARAM_SIZE>;
    113
    114enum class ChannelMode
    115{
    116 FIFO,
    117 MAILBOX,
    119};
    120
    121// NOTE(eklein): This is slightly awkward. I would much prefer to put this in
    122// the ChannelNvSciStreamParams class directly, but I need access to the
    123// operator overloads inside ChannelNvSciStreamParams.
    124// I cannot forward declare the operators inside the class, and I cannot put the
    125// operators inside the enum class (as you would ideally do). The best compromise
    126// I could think of was to put this enum class here outside.
    128{
    129 COMPONENT_NONE = 0,
    130
    131 COMPONENT_CPU = 1 << 0,
    132 COMPONENT_EGL = 1 << 1,
    133 COMPONENT_CUDA = 1 << 2,
    134 COMPONENT_PVA = 1 << 3,
    135 COMPONENT_DLA = 1 << 4,
    136 COMPONENT_NVMEDIA = 1 << 5,
    137};
    138
    139// whether the channel is created statically, or dynamically at runtime
    141{
    145};
    146
    147// the farthest reach this channel can achieve
    148// shorter reach is faster, so if topology is known upfront,
    149// use the shortest matching reach for maximum performance
    150enum class ChannelReach
    151{
    152 REACH_NONE = 0,
    155 REACH_VM,
    157};
    158
    161{
    162 return static_cast<ChannelNvSciStreamEnabledComponents>(static_cast<uint32_t>(a) & static_cast<uint32_t>(b));
    163}
    164
    167{
    168 return static_cast<ChannelNvSciStreamEnabledComponents>(static_cast<uint32_t>(a) | static_cast<uint32_t>(b));
    169}
    170
    171template <typename T>
    172static inline T ParseChannelParameter(const ChannelParamStr& value);
    173
    174template <>
    176{
    177 std::size_t start = 0;
    178 std::size_t end;
    180 do
    181 {
    182 end = value.find("|", start);
    183
    184 ChannelParamStr valueSubString = (end != dw::core::FixedString<1>::NPOS) ? value.substr(start, end - start) : value.substr(start, value.length() - start);
    185
    186 if (valueSubString == "CPU")
    187 {
    189 }
    190 else if (valueSubString == "EGL")
    191 {
    193 }
    194 else if (valueSubString == "CUDA")
    195 {
    197 }
    198 else if (valueSubString == "PVA")
    199 {
    201 }
    202 else if (valueSubString == "DLA")
    203 {
    205 }
    206 else if (valueSubString == "NVMEDIA")
    207 {
    209 }
    210 else
    211 {
    212 throw Exception(DW_INVALID_ARGUMENT, "ChannelNvSciStreamParams: enabledComponents sub-value unrecongnized: ", valueSubString);
    213 }
    214
    215 start = end + 1;
    216 } while (end != dw::core::FixedString<1>::NPOS);
    217
    218 return result;
    219}
    220
    221template <>
    223{
    225 if (value == "dynamic")
    226 {
    228 }
    229 else if (value == "static")
    230 {
    232 }
    233 else
    234 {
    235 throw Exception(DW_INVALID_ARGUMENT, "ChannelNvSciStreamParams: connection phase value unrecongnized: ", value);
    236 }
    237 return result;
    238}
    239
    240template <>
    242{
    243 ChannelReach result;
    244 if (value == "thread")
    245 {
    247 }
    248 else if (value == "process")
    249 {
    251 }
    252 else if (value == "vm")
    253 {
    254 result = ChannelReach::REACH_VM;
    255 }
    256 else if (value == "chip")
    257 {
    259 }
    260 else
    261 {
    262 throw Exception(DW_INVALID_ARGUMENT, "ChannelNvSciStreamParams: reach value unrecongnized: ", value);
    263 }
    264
    265 return result;
    266}
    267
    268template <>
    270{
    271 auto translatedSize = strtol(value.c_str(), nullptr, 10);
    272 return translatedSize;
    273}
    274
    275template <>
    277{
    278 auto translatedSize = ParseChannelParameter<int64_t>(value);
    279 if (translatedSize < 0)
    280 {
    281 throw Exception(DW_INVALID_ARGUMENT, "ParseChannelParameter: size_t is negative");
    282 }
    283 size_t result = static_cast<size_t>(translatedSize);
    284 return result;
    285}
    286
    287template <>
    289{
    290 auto translatedSize = ParseChannelParameter<size_t>(value);
    291 uint32_t result = static_cast<uint32_t>(translatedSize);
    292 return result;
    293}
    294
    295template <>
    297{
    298 auto translatedSize = ParseChannelParameter<size_t>(value);
    299 if (translatedSize > 0xFFFF)
    300 {
    301 throw Exception(DW_INVALID_ARGUMENT, "ChannelSocketParams: port is larger than uint16_t allows!");
    302 }
    303 uint16_t result = static_cast<uint16_t>(translatedSize);
    304 return result;
    305}
    306
    307template <>
    309{
    310 bool result;
    311 if ((value == "true") || (value == "1"))
    312 {
    313 result = true;
    314 }
    315 else if ((value == "false") || (value == "0"))
    316 {
    317 result = false;
    318 }
    319 else
    320 {
    321 throw Exception(DW_INVALID_ARGUMENT, "ParseChannelParameter: needs to be 'true' or 'false' or 1/0");
    322 }
    323 return result;
    324}
    325
    326template <>
    328{
    329 ChannelRole result{};
    330 if (value == "producer")
    331 {
    333 }
    334 else if (value == "consumer")
    335 {
    337 }
    338 else if (value == "composite")
    339 {
    341 }
    342 else
    343 {
    344 throw Exception(DW_INVALID_ARGUMENT, "ParseChannelParameter: role unknown!");
    345 }
    346 return result;
    347}
    348
    349template <>
    351{
    352 ChannelType result{};
    353 if (value == "SHMEM_LOCAL")
    354 {
    355 result = ChannelType::DW_CHANNEL_TYPE_SHMEM_LOCAL;
    356 }
    357 else if (value == "SHMEM_REMOTE")
    358 {
    359 result = ChannelType::DW_CHANNEL_TYPE_SHMEM_REMOTE;
    360 }
    361 else if (value == "EGLSTREAM")
    362 {
    363 result = ChannelType::DW_CHANNEL_TYPE_EGLSTREAM;
    364 }
    365 else if (value == "SOCKET")
    366 {
    367 result = ChannelType::DW_CHANNEL_TYPE_SOCKET;
    368 }
    369 else if (value == "DDS")
    370 {
    371 result = ChannelType::DW_CHANNEL_TYPE_DDS;
    372 }
    373 else if (value == "NVSCI")
    374 {
    375 result = ChannelType::DW_CHANNEL_TYPE_NVSCI;
    376 }
    377 else
    378 {
    379 throw Exception(DW_INVALID_ARGUMENT, "ParseChannelParameter: type unknown!");
    380 }
    381
    382 return result;
    383}
    384
    385template <>
    387{
    388 ChannelMode result;
    389 if (value == "mailbox")
    390 {
    391 result = ChannelMode::MAILBOX;
    392 }
    393 else if (value == "singleton")
    394 {
    395 result = ChannelMode::SINGLETON;
    396 }
    397 else
    398 {
    399 throw Exception(DW_INVALID_ARGUMENT, "ParseChannelParameter: ChannelMode unknown!");
    400 }
    401 return result;
    402}
    403
    404template <typename T>
    405void ParseChannelParameter(const ChannelParamStr& value, T& result)
    406{
    407 result = ParseChannelParameter<T>(value);
    408}
    409
    410template <size_t Size>
    411void ParseChannelParameter(const ChannelParamStr& value, dw::core::FixedString<Size>& result)
    412{
    413 result = value;
    414}
    415
    416template <typename T, size_t N>
    417void ParseChannelParameter(const ChannelParamStr& value, dw::core::VectorFixed<T, N>& result)
    418{
    419 size_t pos = 0U;
    420 size_t endpos = 0U;
    421 bool done = false;
    422 while (!done)
    423 {
    424 endpos = value.find(":", pos);
    425 done = endpos == dw::core::FixedString<1>::NPOS;
    426 size_t count = done ? endpos : endpos - pos;
    427 T entry{};
    428 ParseChannelParameter(value.substr(pos, count), entry);
    429 result.push_back(entry);
    430 pos = endpos + 1;
    431 }
    432}
    433
    435{
    436 return;
    437}
    438
    439template <typename T, typename... Others>
    440static inline void ParseChannelParameters(const ChannelParamStr& key, const ChannelParamStr& value, const char* staticKey, T& result, Others&&... others)
    441{
    442 if (key == staticKey)
    443 {
    444 ParseChannelParameter(value, result);
    445 return;
    446 }
    447 ParseChannelParameters(key, value, std::forward<Others>(others)...);
    448}
    449
    450template <typename... Others>
    451static inline void ParseAllChannelParameters(const ChannelParamStr& channelParams, Others&&... others)
    452{
    453 std::size_t key = 0;
    454 std::size_t pos = channelParams.find("=");
    455 std::size_t value = 0;
    456 std::size_t valueEnd = 0;
    457
    458 ChannelParamStr keyString;
    459 ChannelParamStr valueString;
    460 while (pos != dw::core::FixedString<1>::NPOS && value != dw::core::FixedString<1>::NPOS)
    461 {
    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);
    466 ParseChannelParameters(keyString, valueString, std::forward<Others>(others)...);
    467
    468 key = value + 1;
    469 pos = channelParams.find("=", key);
    470 }
    471}
    472
    474{
    475public:
    476 static inline ChannelParamStr getParamStr(const char* serverIP,
    477 uint16_t port,
    478 bool producerFifo = false,
    479 uint16_t numBlockingConnections = 1,
    480 dw::core::FixedString<8> const sockPrefix = dw::core::FixedString<8>())
    481 {
    482 std::stringstream ss;
    483 ss.flags(std::ios::dec);
    484 ss << "type=SOCKET";
    485 if (serverIP != nullptr)
    486 {
    487 ss << ",ip=";
    488 ss << serverIP;
    489 }
    490 ss << ",id=";
    491 ss << port;
    492 ss << ",producer-fifo=";
    493 ss << static_cast<uint32_t>(producerFifo);
    494 ss << ",num-clients=";
    495 ss << numBlockingConnections;
    496 ss << ",sock-prefix=";
    497 ss << sockPrefix;
    498 ChannelParamStr result(ss.str().c_str());
    499 return result;
    500 }
    501
    503 explicit ChannelSocketParams(const char* params)
    504 {
    505 dw::core::FixedString<MAX_CHANNEL_ALL_PARAMS_SIZE> channelParams(params);
    506 ParseAllChannelParameters(channelParams,
    507 "ip", m_serverIP,
    508 "producer-fifo", m_producerFifo,
    509 "id", m_port,
    510 "sock-prefix", m_sockPrefix);
    511 }
    512
    514
    516
    517 ChannelParamStr getServerIP() const { return m_serverIP; }
    518 uint16_t getPort() const { return m_port; }
    519 bool hasProducerFifo() const { return m_producerFifo; }
    520 dw::core::FixedString<8> getSockPrefix() const { return m_sockPrefix; }
    521
    522private:
    523 ChannelParamStr m_serverIP; // needed for socket client connection
    524 uint16_t m_port = 0;
    525 bool m_producerFifo = false; // Allow the socket producer to have its own fifo to queue up work
    526 dw::core::FixedString<8> m_sockPrefix = dw::core::FixedString<8>();
    527};
    528
    530
    532{
    533public:
    535
    536 explicit ChannelNvSciStreamParams(const char* params)
    538 {
    539 dw::core::FixedString<MAX_CHANNEL_ALL_PARAMS_SIZE> channelParams(params);
    540 ParseAllChannelParameters(channelParams,
    541 "streamName", m_streamNames,
    542 "enabledComponents", m_enabledComponents,
    543 "connectionType", m_connectionType,
    544 "timeoutUsec", m_timeoutUsec,
    545 "reach", m_reaches);
    546 }
    547
    549
    551
    552 dwTime_t getTimeoutUsec() const { return m_timeoutUsec; }
    553
    561
    565 uint16_t getNumOutputs() const
    566 {
    567 static_assert(decltype(m_streamNames)::CAPACITY_AT_COMPILE_TIME < std::numeric_limits<uint16_t>::max(), "ChannelNvSciStreamParams: number of outputs over limit");
    568 return static_cast<uint16_t>(m_streamNames.size());
    569 }
    570
    571 bool isMulticast() const
    572 {
    573 return m_streamNames.size() > 1U;
    574 }
    575
    576 const char* getStreamName(uint16_t index = 0) const
    577 {
    578 if (index >= m_streamNames.size())
    579 {
    580 throw Exception(DW_INVALID_ARGUMENT, "ChannelNvSciStreamParams: stream name index out of range");
    581 }
    582 return m_streamNames[index].c_str();
    583 }
    584
    585 ChannelReach getChannelReach(uint16_t index = 0) const
    586 {
    587 if (m_reaches.size() == 0)
    588 {
    590 }
    591 if (index >= m_reaches.size())
    592 {
    593 throw Exception(DW_INVALID_ARGUMENT, "ChannelNvSciStreamParams: reach index out of range");
    594 }
    595 return m_reaches[index];
    596 }
    597
    598protected:
    599 dwTime_t m_timeoutUsec = 5000 * 1000;
    600 // bitmask of ChannelNvSciStreamEnabledComponents enum
    603 dw::core::VectorFixed<dw::core::FixedString<64>, 8> m_streamNames{};
    604 dw::core::VectorFixed<ChannelReach, 8> m_reaches{};
    605};
    606
    608{
    609public:
    610 explicit ChannelParams(const char* params)
    611 : m_str(params)
    612 {
    614 "fifo-size", m_fifoSize,
    615 "id", m_id,
    616 "singleton-id", m_singletonId,
    617 "trace-name", m_traceId, // TODO(chale): should be trace-id but assumption that id field is
    618 // is only parameter with 'id' as a substring is hardcoded in many places
    619 "mode", m_mode,
    620 "reuse", m_reuseEnabled,
    621 "debug-port", m_debugPort,
    622 "num-clients", m_clientsCount,
    623 "debug-num-clients", m_debugClientsCount,
    624 "role", m_role,
    625 "type", m_type,
    626 "data-offset", m_dataOffset,
    627 "strict", m_strictFifo,
    628 "sync-enabled", m_syncEnabled);
    629
    630 adjustPoolCapacity();
    631
    632 if (m_clientsCount == 0)
    633 {
    634 m_clientsCount = 1;
    635 }
    636
    637 if (!m_singletonId.empty())
    638 {
    639 m_mode = ChannelMode::SINGLETON;
    640 }
    641
    642 if (m_mode == ChannelMode::MAILBOX)
    643 {
    644 m_mailboxMode = true;
    645 }
    646 else if (m_mode == ChannelMode::SINGLETON)
    647 {
    648 m_singletonMode = true;
    649
    650 // Assign singletonId with id
    651 if (!m_id.empty() && m_singletonId.empty())
    652 {
    653 m_singletonId = m_id;
    654 }
    655 }
    656
    657 // Why break this up like this? Code complexity.
    658 // Without this, we fail the code complexity analysis.
    659 ValidateMailbox();
    660 ValidateSingleton();
    661
    662 switch (m_type)
    663 {
    664 case DW_CHANNEL_TYPE_SHMEM_LOCAL:
    665 break;
    666 case DW_CHANNEL_TYPE_SOCKET:
    667 m_socketParams = ChannelSocketParams(params);
    668 break;
    669 case DW_CHANNEL_TYPE_NVSCI:
    670 m_nvSciStreamParams = ChannelNvSciStreamParams(params);
    671 break;
    672 case DW_CHANNEL_TYPE_SHMEM_REMOTE:
    673 case DW_CHANNEL_TYPE_EGLSTREAM:
    674 case DW_CHANNEL_TYPE_DDS:
    675 default:
    676 throw Exception(DW_NOT_IMPLEMENTED, "ChannelParams: no parameters for channel type");
    677 break;
    678 }
    679 }
    680
    682 {
    683 *this = other;
    684 }
    685
    686 ChannelParams& operator=(const ChannelParams& other) = default;
    687 ~ChannelParams() = default;
    688
    689 const char* getStr() const { return m_str.c_str(); }
    690 ChannelParamStr getId() const { return m_id; }
    691 ChannelParamStr getSingletonId() const { return m_singletonId; }
    692 uint16_t getDebugPort() const { return m_debugPort; }
    693 size_t getFifoSize() const { return m_fifoSize; }
    694 // Note(chale): Normally the fifo length governs whether a consumer
    695 // will receive packet. The actual packet pool's size may be larger
    696 // than the fifo length. non-strict mode allows consumers to receive
    697 // up to the entire pool size instead of just their fifo length.
    698 bool isStrictFifo() const { return m_strictFifo; }
    699 void setStrictFifo(bool strictFifo)
    700 {
    701 m_strictFifo = strictFifo;
    702 }
    703 size_t getPoolCapacity() const { return m_poolCapacity; }
    704 bool getMailboxMode() const { return m_mailboxMode; }
    705 // Note (ajayawardane): The data-offset parameter is used to describe
    706 // the consumption offset between the producer and the consumer
    707 // in the sync packet use-case. For example, if a packet is produced with the
    708 // sync count x, and is inteneded to be consumed when the sync count is x + 1,
    709 // the data-offset would be 1. This parameter is also used to identify whether
    710 // to use sync packets to transfer data, so needs to be included in both the
    711 // producer and the consumer params.
    712 uint32_t getDataOffset() const { return m_dataOffset; }
    713 bool getSyncEnabled() const { return m_syncEnabled; }
    714 void setMailboxMode(bool mailboxEnabled) { m_mailboxMode = mailboxEnabled; }
    715 bool getSingletonMode() const { return m_singletonMode; }
    716 bool getReuseEnabled() const { return m_reuseEnabled; }
    717 bool getDebugMode() const { return m_debugPort > 0; }
    718 uint16_t getExpectedConnectionsCount() const { return m_clientsCount; }
    719 uint16_t getExpectedDebugConnectionsCount() const { return m_debugClientsCount; }
    720 ChannelRole getRole() const { return m_role; }
    721 ChannelType getType() const { return m_type; }
    722 ChannelParamStr getTraceId() const { return m_traceId; }
    723
    725 {
    726 if (m_type != ChannelType::DW_CHANNEL_TYPE_SOCKET)
    727 {
    728 throw Exception(DW_CALL_NOT_ALLOWED, "ChannelParams: getSocketParams: channel is not of type SOCKET");
    729 }
    730 return m_socketParams;
    731 }
    732
    734 {
    735 if (m_type != ChannelType::DW_CHANNEL_TYPE_NVSCI)
    736 {
    737 throw Exception(DW_CALL_NOT_ALLOWED, "ChannelParams: getNvSciStreamParams: channel is not of type NVSCI");
    738 }
    739 return m_nvSciStreamParams;
    740 }
    741
    742private:
    743 void ValidateMailbox()
    744 {
    745 if (m_singletonMode)
    746 {
    747 if (m_fifoSize != 1)
    748 {
    749 throw Exception(DW_INVALID_ARGUMENT, "ChannelParams: Singleton and mailbox modes are incompatible with a fifo setting other than 1");
    750 }
    751 }
    752 if (!m_mailboxMode && m_reuseEnabled)
    753 {
    754 throw Exception(DW_INVALID_ARGUMENT, "ChannelParams: reuse=true specified when mode!=mailbox. Not valid");
    755 }
    756 if (m_mailboxMode && m_singletonMode)
    757 {
    758 throw Exception(DW_INVALID_ARGUMENT, "ChannelParams: Singleton mode is incompatible mailbox mode");
    759 }
    760 }
    761
    762 void ValidateSingleton()
    763 {
    764 // Assign singletonId with id in singleton mode
    765 if (m_singletonMode && m_singletonId.empty())
    766 {
    767 m_singletonId = m_id;
    768 }
    769 if (!m_singletonMode && !m_singletonId.empty())
    770 {
    771 throw Exception(DW_INVALID_ARGUMENT, "ChannelParams: Singleton mode requires both the mode set AND singletonId set");
    772 }
    773 if (m_singletonMode && (m_type != ChannelType::DW_CHANNEL_TYPE_SHMEM_LOCAL))
    774 {
    775 throw Exception(DW_INVALID_ARGUMENT, "ChannelParams: Singleton mode is only valid for SHMEM_LOCAL channels");
    776 }
    777 }
    778
    779 void adjustPoolCapacity()
    780 {
    781 // This deserves a comment. The LocalShmem pools (in the fifo-case)
    782 // need the following number of slots, in the worst case:
    783 // 1 for getImpl to return at any time
    784 // 1 per consumer for in-flight data
    785 // fifo-size to store a full fifo worth of packets
    786 // So assuming max consumers, we'd need fifo-size + MAX_CHANNEL_CONSUMERS_COUNT + 1
    787 if (m_fifoSize + MAX_CHANNEL_CONSUMERS_COUNT + 1 > m_poolCapacity)
    788 {
    789 m_poolCapacity = m_fifoSize + MAX_CHANNEL_CONSUMERS_COUNT + 1;
    790 }
    791 }
    792
    793private:
    794 ChannelParamStr m_str{};
    795 ChannelParamStr m_id{};
    796 ChannelParamStr m_singletonId{};
    797 ChannelParamStr m_traceId{};
    798
    799 // fifo size of the socket client that implies the maximum number of packets
    800 // a client can hold simultaneously
    801 size_t m_fifoSize = 1;
    802 // This deserves a comment. The LocalShmem pools (in the fifo-case)
    803 // need the following number of slots, in the worst case:
    804 // 1 for getImpl to return at any time
    805 // 1 per consumer for in-flight data
    806 // fifo-size to store a full fifo worth of packets
    807 // So assuming a fifo-size of 1 and max consumers, we'd need MAX_CHANNEL_CONSUMERS_COUNT + 2
    808 size_t m_poolCapacity = MAX_CHANNEL_CONSUMERS_COUNT + 2;
    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;
    818
    819 uint16_t m_clientsCount = 1; // number of clients for blocking mode for socket
    820 uint16_t m_debugClientsCount = 1; // number of debug clients for blocking mode for socket
    821
    822 uint16_t m_debugPort = 0;
    823
    824 ChannelSocketParams m_socketParams{};
    825 ChannelNvSciStreamParams m_nvSciStreamParams{};
    826};
    827
    828} // namespace framework
    829} // namespace dw
    830
    831#endif // DW_FRAMEWORK_CHANNEL_HPP_
    ChannelNvSciStreamParams & operator=(const ChannelNvSciStreamParams &other)=default
    dw::core::VectorFixed< ChannelReach, 8 > m_reaches
    ChannelNvSciStreamEnabledComponents getEnabledComponents() const
    ChannelNvSciStreamParams(const ChannelNvSciStreamParams &other)=default
    const char * getStreamName(uint16_t index=0) const
    ChannelNvSciStreamEnabledComponents m_enabledComponents
    ChannelConnectionType getChannelConnectionType() const
    dw::core::VectorFixed< dw::core::FixedString< 64 >, 8 > m_streamNames
    ChannelReach getChannelReach(uint16_t index=0) const
    void setMailboxMode(bool mailboxEnabled)
    uint16_t getExpectedConnectionsCount() const
    uint16_t getExpectedDebugConnectionsCount() const
    ChannelParams & operator=(const ChannelParams &other)=default
    const ChannelSocketParams & getSocketParams() const
    const ChannelNvSciStreamParams & getNvSciStreamParams() const
    ChannelParamStr getSingletonId() const
    ChannelParamStr getTraceId() const
    void setStrictFifo(bool strictFifo)
    ChannelParams(const ChannelParams &other)
    ChannelParamStr getId() const
    dw::core::FixedString< 8 > getSockPrefix() const
    ChannelSocketParams & operator=(const ChannelSocketParams &other)=default
    ChannelSocketParams(const ChannelSocketParams &other)=default
    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 >())
    static const char * ToParam(ChannelType channelType)
    static constexpr uint16_t MAX_CHANNEL_ALL_PARAMS_SIZE
    dw::core::FixedString< MAX_CHANNEL_PARAM_SIZE > ChannelParamStr
    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
    static constexpr uint16_t MAX_CHANNEL_CONSUMERS_COUNT
    Definition: Exception.hpp:47
    人人超碰97caoporen国产