sACN  2.0.2
Implementation of ANSI E1.31 (Streaming ACN)
View other versions:
Loading...
Searching...
No Matches
dmx_merger.h
Go to the documentation of this file.
1/******************************************************************************
2 * Copyright 2022 ETC Inc.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 ******************************************************************************
16 * This file is a part of sACN. For more information, go to:
17 * https://github.com/ETCLabs/sACN
18 *****************************************************************************/
19
20#ifndef SACN_CPP_DMX_MERGER_H_
21#define SACN_CPP_DMX_MERGER_H_
22
28#include "sacn/cpp/common.h"
29
30#include "sacn/dmx_merger.h"
31#include "etcpal/cpp/inet.h"
33
40namespace sacn
41{
42namespace detail
43{
45{
46};
47}; // namespace detail
48
67{
68public:
71
76 struct Settings
77 {
78 /********* Required values **********/
79
84 uint8_t* levels{nullptr};
85
86 /********* Optional values **********/
87
93 uint8_t* per_address_priorities{nullptr};
94
99
103 uint8_t* universe_priority{nullptr};
104
112
117 Settings() = default;
118
123 Settings(uint8_t* levels_ptr);
124
125 bool IsValid() const;
126 };
127
128 DmxMerger() = default;
129 DmxMerger(const DmxMerger& other) = delete;
130 DmxMerger& operator=(const DmxMerger& other) = delete;
131 DmxMerger(DmxMerger&& other) = default;
132 DmxMerger& operator=(DmxMerger&& other) = default;
134 etcpal::Error Startup(const Settings& settings);
135 void Shutdown();
136
140
141 etcpal::Error UpdateLevels(sacn_dmx_merger_source_t source, const uint8_t* new_levels, size_t new_levels_count);
142 etcpal::Error UpdatePap(sacn_dmx_merger_source_t source, const uint8_t* pap, size_t pap_count);
143 etcpal::Error UpdateUniversePriority(sacn_dmx_merger_source_t source, uint8_t universe_priority);
145
146 constexpr Handle handle() const;
147
148private:
149 SacnDmxMergerConfig TranslateConfig(const Settings& settings);
150
151 Handle handle_;
152};
153
159inline DmxMerger::Settings::Settings(uint8_t* levels_ptr) : levels(levels_ptr)
160{
161}
162
167{
168 return (levels != nullptr);
169}
170
185{
186 SacnDmxMergerConfig config = TranslateConfig(settings);
187
189 etcpal::Error result = sacn_dmx_merger_create(&config, &c_handle);
190
191 handle_.SetValue(c_handle);
192
193 return result;
194}
195
207{
209 handle_.Clear();
210}
211
228{
230 etcpal_error_t err = sacn_dmx_merger_add_source(handle_.value(), &result);
231 if (err == kEtcPalErrOk)
232 return result;
233 else
234 return err;
235}
236
252
264{
265 return sacn_dmx_merger_get_source(handle_.value(), source);
266}
267
285inline etcpal::Error DmxMerger::UpdateLevels(sacn_dmx_merger_source_t source, const uint8_t* new_levels,
286 size_t new_levels_count)
287{
288 return sacn_dmx_merger_update_levels(handle_.value(), source, new_levels, new_levels_count);
289}
290
309inline etcpal::Error DmxMerger::UpdatePap(sacn_dmx_merger_source_t source, const uint8_t* pap, size_t pap_count)
310{
311 return sacn_dmx_merger_update_pap(handle_.value(), source, pap, pap_count);
312}
313
336{
337 return sacn_dmx_merger_update_universe_priority(handle_.value(), source, universe_priority);
338}
339
357
363inline constexpr DmxMerger::Handle DmxMerger::handle() const
364{
365 return handle_;
366}
367
368inline SacnDmxMergerConfig DmxMerger::TranslateConfig(const Settings& settings)
369{
370 // clang-format off
371 SacnDmxMergerConfig config = {
372 settings.levels,
373 settings.per_address_priorities,
374 settings.per_address_priorities_active,
375 settings.universe_priority,
376 settings.owners,
377 settings.source_count_max
378 };
379 // clang-format on
380
381 return config;
382}
383
384}; // namespace sacn
385
386#endif // SACN_CPP_DMX_MERGER_H_
ETCPAL_CONSTEXPR_14 void Clear()
ETCPAL_CONSTEXPR_14 void SetValue(const ValueType &new_value)
constexpr ValueType value() const
An instance of sACN DMX Merger functionality; see Using the sACN DMX Merger API.
Definition dmx_merger.h:67
DmxMerger(DmxMerger &&other)=default
etcpal::Error UpdateLevels(sacn_dmx_merger_source_t source, const uint8_t *new_levels, size_t new_levels_count)
Updates a source's levels and recalculates outputs.
Definition dmx_merger.h:285
const SacnDmxMergerSource * GetSourceInfo(sacn_dmx_merger_source_t source) const
Gets a read-only view of the source data.
Definition dmx_merger.h:263
etcpal::Error UpdatePap(sacn_dmx_merger_source_t source, const uint8_t *pap, size_t pap_count)
Updates a source's per-address priorities (PAP) and recalculates outputs.
Definition dmx_merger.h:309
constexpr Handle handle() const
Get the current handle to the underlying C DMX merger.
Definition dmx_merger.h:363
etcpal::Error RemoveSource(sacn_dmx_merger_source_t source)
Removes a source from the merger.
Definition dmx_merger.h:248
etcpal::Error Startup(const Settings &settings)
Create a new merger instance.
Definition dmx_merger.h:184
DmxMerger & operator=(DmxMerger &&other)=default
etcpal::Expected< sacn_dmx_merger_source_t > AddSource()
Adds a new source to the merger.
Definition dmx_merger.h:227
void Shutdown()
Destroy a merger instance.
Definition dmx_merger.h:206
etcpal::Error UpdateUniversePriority(sacn_dmx_merger_source_t source, uint8_t universe_priority)
Updates a source's universe priority and recalculates outputs.
Definition dmx_merger.h:335
etcpal::Error RemovePap(sacn_dmx_merger_source_t source)
Removes the per-address priority (PAP) data from the source and recalculate outputs.
Definition dmx_merger.h:353
Definition dmx_merger.h:45
C++ wrapper for the sACN init/deinit functions.
sACN DMX Merger API definitions
etcpal_error_t
kEtcPalErrOk
#define SACN_DMX_MERGER_SOURCE_INVALID
Definition dmx_merger.h:75
const SacnDmxMergerSource * sacn_dmx_merger_get_source(sacn_dmx_merger_t merger, sacn_dmx_merger_source_t source)
Gets a read-only view of the source data.
Definition dmx_merger.c:344
#define SACN_DMX_MERGER_INVALID
Definition dmx_merger.h:68
etcpal_error_t sacn_dmx_merger_destroy(sacn_dmx_merger_t handle)
Destroy a merger instance.
Definition dmx_merger.c:212
uint16_t sacn_dmx_merger_source_t
Definition dmx_merger.h:72
etcpal_error_t sacn_dmx_merger_update_levels(sacn_dmx_merger_t merger, sacn_dmx_merger_source_t source, const uint8_t *new_levels, size_t new_levels_count)
Updates a source's levels and recalculates outputs.
Definition dmx_merger.c:385
etcpal_error_t sacn_dmx_merger_create(const SacnDmxMergerConfig *config, sacn_dmx_merger_t *handle)
Create a new merger instance.
Definition dmx_merger.c:170
etcpal_error_t sacn_dmx_merger_update_universe_priority(sacn_dmx_merger_t merger, sacn_dmx_merger_source_t source, uint8_t universe_priority)
Updates a source's universe priority and recalculates outputs.
Definition dmx_merger.c:500
int sacn_dmx_merger_t
Definition dmx_merger.h:65
etcpal_error_t sacn_dmx_merger_update_pap(sacn_dmx_merger_t merger, sacn_dmx_merger_source_t source, const uint8_t *pap, size_t pap_count)
Updates a source's per-address priorities (PAP) and recalculates outputs.
Definition dmx_merger.c:441
etcpal_error_t sacn_dmx_merger_remove_source(sacn_dmx_merger_t merger, sacn_dmx_merger_source_t source)
Removes a source from the merger.
Definition dmx_merger.c:302
etcpal_error_t sacn_dmx_merger_remove_pap(sacn_dmx_merger_t merger, sacn_dmx_merger_source_t source)
Removes the per-address priority (PAP) data from the source and recalculate outputs.
Definition dmx_merger.c:544
etcpal_error_t sacn_dmx_merger_add_source(sacn_dmx_merger_t merger, sacn_dmx_merger_source_t *source_id)
Adds a new source to the merger.
Definition dmx_merger.c:260
#define SACN_RECEIVER_INFINITE_SOURCES
Constant for "infinite" when listening or merging sACN universes.
Definition receiver.h:68
A namespace which contains all C++ language definitions in the sACN library.
Definition common.h:50
Definition dmx_merger.h:79
uint8_t * levels
Definition dmx_merger.h:86
Definition dmx_merger.h:148
A set of configuration settings that a merger needs to initialize.
Definition dmx_merger.h:77
uint8_t * levels
Definition dmx_merger.h:84
uint8_t * per_address_priorities
Definition dmx_merger.h:93
int source_count_max
Definition dmx_merger.h:113
bool * per_address_priorities_active
Definition dmx_merger.h:98
bool IsValid() const
Definition dmx_merger.h:166
uint8_t * universe_priority
Definition dmx_merger.h:103
sacn_dmx_merger_source_t * owners
Definition dmx_merger.h:111