Skip to content

Commit 4237cf3

Browse files
committed
Remove buffering in MemoryMonitor.processFrames()
- Not needed for 100 Hz stream and improves stream visualization
1 parent dec82a3 commit 4237cf3

File tree

2 files changed

+8
-38
lines changed

2 files changed

+8
-38
lines changed

Source/Devices/MemoryMonitor.cpp

Lines changed: 7 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,6 @@ MemoryMonitor::MemoryMonitor(std::string name, std::string hubName, const oni_de
9191
"percent"
9292
);
9393
streamInfos.add(percentUsedStream);
94-
95-
for (int i = 0; i < numFrames; i++)
96-
eventCodes[i] = 0;
9794
}
9895

9996
OnixDeviceType MemoryMonitor::getDeviceType()
@@ -133,9 +130,8 @@ bool MemoryMonitor::updateSettings()
133130

134131
void MemoryMonitor::startAcquisition()
135132
{
136-
currentFrame = 0;
137-
sampleNumber = 0;
138133

134+
sampleNumber = 0;
139135
lastPercentUsedValue = 0.0f;
140136
}
141137

@@ -152,34 +148,17 @@ float MemoryMonitor::getLastPercentUsedValue()
152148

153149
void MemoryMonitor::processFrames()
154150
{
151+
static uint64_t ec = 0;
155152
oni_frame_t* frame;
156153

157154
while (frameQueue.try_dequeue(frame))
158155
{
159156
uint32_t* dataPtr = (uint32_t*)frame->data;
160-
161-
timestamps[currentFrame] = deviceContext->convertTimestampToSeconds(frame->time);
162-
163-
percentUsedSamples[currentFrame] = 100.0f * float(*(dataPtr + 2)) / totalMemory;
164-
165-
lastPercentUsedValue = percentUsedSamples[currentFrame];
166-
157+
auto t = deviceContext->convertTimestampToSeconds(frame->time);
158+
auto p = 100.0f * float(*(dataPtr + 2)) / totalMemory;
159+
lastPercentUsedValue = p;
167160
oni_destroy_frame(frame);
168-
169-
sampleNumbers[currentFrame] = sampleNumber++;
170-
171-
currentFrame++;
172-
173-
if (currentFrame >= numFrames)
174-
{
175-
shouldAddToBuffer = true;
176-
currentFrame = 0;
177-
}
178-
179-
if (shouldAddToBuffer)
180-
{
181-
shouldAddToBuffer = false;
182-
percentUsedBuffer->addToBuffer(percentUsedSamples, sampleNumbers, timestamps, eventCodes, numFrames);
183-
}
161+
auto sn = sampleNumber++;
162+
percentUsedBuffer->addToBuffer(&p, &sn, &t, &ec, 1);
184163
}
185164
}

Source/Devices/MemoryMonitor.h

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -57,22 +57,13 @@ namespace OnixSourcePlugin
5757

5858
DataBuffer* percentUsedBuffer;
5959

60-
static const int numFrames = 10;
61-
62-
unsigned short currentFrame = 0;
63-
int sampleNumber = 0;
60+
int64_t sampleNumber = 0;
6461

6562
/** The frequency at which memory use is recorded in Hz. */
6663
const uint32_t samplesPerSecond = 100;
6764

6865
bool shouldAddToBuffer = false;
6966

70-
float percentUsedSamples[numFrames];
71-
float bytesUsedSamples[numFrames];
72-
73-
double timestamps[numFrames];
74-
int64_t sampleNumbers[numFrames];
75-
uint64_t eventCodes[numFrames];
7667

7768
/** The total amount of memory, in 32-bit words, on the hardware that is available for data buffering*/
7869
uint32_t totalMemory;

0 commit comments

Comments
 (0)