MXL : Media eXchange Layer
MXL
Loading...
Searching...
No Matches
mxl::lib::FlowSynchronizationGroup Class Reference

#include <FlowSynchronizationGroup.hpp>

Classes

struct  ListEntry

Public Member Functions

void addReader (ContinuousFlowReader const &reader)
void addReader (DiscreteFlowReader const &reader, std::uint16_t minValidSlices)
void removeReader (FlowReader const &reader)
mxlStatus waitForDataAt (Timepoint originTime, Timepoint deadline) const

Private Types

using ReaderList = std::forward_list<ListEntry>
enum class  Variant : std::uint8_t { Discrete , Continuous }

Private Attributes

ReaderList _readers

Detailed Description

A set of weak references to a flow readers that can be used to check for data availability on all flows of the group at once.

Definition at line 22 of file FlowSynchronizationGroup.hpp.

Member Typedef Documentation

◆ ReaderList

using mxl::lib::FlowSynchronizationGroup::ReaderList = std::forward_list<ListEntry>
private

Definition at line 76 of file FlowSynchronizationGroup.hpp.

Member Enumeration Documentation

◆ Variant

enum class mxl::lib::FlowSynchronizationGroup::Variant : std::uint8_t
strongprivate
Enumerator
Discrete 
Continuous 

Definition at line 32 of file FlowSynchronizationGroup.hpp.

33 {
34 Discrete,
35 Continuous
36 };

Member Function Documentation

◆ addReader() [1/2]

void mxl::lib::FlowSynchronizationGroup::addReader ( ContinuousFlowReader const & reader)

Definition at line 48 of file FlowSynchronizationGroup.cpp.

49 {
50 auto prev = _readers.before_begin();
51 for (auto current = std::next(prev); current != _readers.end(); ++current)
52 {
53 if (current->reader == &reader)
54 {
55 return;
56 }
57 prev = current;
58 }
59
60 _readers.emplace_after(prev, reader);
61 }
mxlFlowReader reader

◆ addReader() [2/2]

void mxl::lib::FlowSynchronizationGroup::addReader ( DiscreteFlowReader const & reader,
std::uint16_t minValidSlices )

Definition at line 32 of file FlowSynchronizationGroup.cpp.

33 {
34 auto prev = _readers.before_begin();
35 for (auto current = std::next(prev); current != _readers.end(); ++current)
36 {
37 if (current->reader == &reader)
38 {
39 current->minValidSlices = minValidSlices;
40 return;
41 }
42 prev = current;
43 }
44
45 _readers.emplace_after(prev, reader, minValidSlices);
46 }

◆ removeReader()

void mxl::lib::FlowSynchronizationGroup::removeReader ( FlowReader const & reader)

Definition at line 63 of file FlowSynchronizationGroup.cpp.

64 {
65 auto prev = _readers.before_begin();
66 for (auto current = std::next(prev); current != _readers.end(); ++current)
67 {
68 if (current->reader == &reader)
69 {
70 _readers.erase_after(prev);
71 return;
72 }
73 prev = current;
74 }
75 }

◆ waitForDataAt()

mxlStatus mxl::lib::FlowSynchronizationGroup::waitForDataAt ( Timepoint originTime,
Timepoint deadline ) const

Definition at line 77 of file FlowSynchronizationGroup.cpp.

78 {
79 auto prev = _readers.before_begin();
80 for (auto it = _readers.begin(); it != _readers.end(); /* Nothing */)
81 {
82 auto const current = it++;
83
84 auto const expectedIndex = timestampToIndex(current->grainRate, originTime);
85 auto const runtimeInfo = current->reader->getFlowRuntimeInfo();
86 if (expectedIndex > runtimeInfo.headIndex)
87 {
88 auto result = mxlStatus{MXL_ERR_UNKNOWN};
89 switch (current->variant)
90 {
92 result =
93 static_cast<DiscreteFlowReader const*>(current->reader)->waitForGrain(expectedIndex, current->minValidSlices, deadline);
94 break;
95
97 result = static_cast<ContinuousFlowReader const*>(current->reader)->waitForSamples(expectedIndex, deadline);
98 break;
99 }
100
101 if (result == MXL_STATUS_OK)
102 {
103 // If the current source delay of this flow exceeds any previously observed source delay of
104 // this flow we update the cached maximum and if this new maximum turns out to be bigger than
105 // the maximum source delay observed for the flow at the head of the list, we move this flow
106 // to the front, hoping that we can save blocking waits in the future.
107 auto const expectedArrivalTime = indexToTimestamp(current->grainRate, expectedIndex);
108 auto const currentTaiTime = currentTime(Clock::TAI);
109 if (currentTaiTime > expectedArrivalTime)
110 {
111 auto const sourceDelay = (currentTaiTime - expectedArrivalTime).value;
112 if (sourceDelay > current->maxObservedSourceDelay)
113 {
114 current->maxObservedSourceDelay = sourceDelay;
115 if (current->maxObservedSourceDelay > _readers.begin()->maxObservedSourceDelay)
116 {
117 // `splice_after` moves the element *following* the iterator it is given.
118 _readers.splice_after(_readers.before_begin(), _readers, prev);
119 continue; // `prev` already precedes `it` after the splice.
120 }
121 }
122 }
123 }
124 else
125 {
126 return result;
127 }
128 }
129 prev = current;
130 }
131 return MXL_STATUS_OK;
132 }
mxlStatus
MXL SDK Status codes.
Definition mxl.h:22
@ MXL_ERR_UNKNOWN
Definition mxl.h:27
@ MXL_STATUS_OK
Definition mxl.h:23
constexpr Timepoint indexToTimestamp(mxlRational const &editRate, std::uint64_t index) noexcept
constexpr std::uint64_t timestampToIndex(mxlRational const &editRate, Timepoint timestamp) noexcept
auto const currentTime
Definition test_time.cpp:58

Member Data Documentation

◆ _readers

ReaderList mxl::lib::FlowSynchronizationGroup::_readers
mutableprivate

Definition at line 79 of file FlowSynchronizationGroup.hpp.


The documentation for this class was generated from the following files: