MXL : Media eXchange Layer
MXL
Loading...
Searching...
No Matches
test_flows.cpp
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2025 Contributors to the Media eXchange Layer project.
2// SPDX-License-Identifier: Apache-2.0
3
4#include <chrono>
5#include <cstdint>
6#include <cstdlib>
7#include <cstring>
8#include <ctime>
9#include <filesystem>
10#include <fstream>
11#include <memory>
12#include <string>
13#include <thread>
14#include <utility>
15#include <uuid.h>
16#include <catch2/catch_test_macros.hpp>
17#include <picojson/wrapper.h>
18#include <mxl/flow.h>
19#include <mxl/mxl.h>
20#include <mxl/time.h>
22#include "PcapReader.hpp"
23#include "Utils.hpp"
24
25namespace fs = std::filesystem;
26
27TEST_CASE_PERSISTENT_FIXTURE(mxl::tests::mxlDomainFixture, "Video Flow : Create/Destroy", "[mxl flows]")
28{
29 auto const opts = "{}";
30 auto const flowId = "5fbec3b1-1b0f-417d-9059-8b94a47197ed";
31 auto flowDef = mxl::tests::readFile("data/v210_flow.json");
32 bool active = false;
33
34 auto instanceReader = mxlCreateInstance(domain.string().c_str(), opts);
35 REQUIRE(instanceReader != nullptr);
36
37 auto instanceWriter = mxlCreateInstance(domain.string().c_str(), opts);
38 REQUIRE(instanceWriter != nullptr);
39
42 bool flowWasCreated = false;
45
48
49 // The writer is now created. The flow should be active.
51 REQUIRE(active == true);
52
54 auto const rate = mxlRational{60000, 1001};
55 auto const now = mxlGetTime();
56 uint64_t index = mxlTimestampToIndex(&rate, now);
58
61 uint8_t* buffer = nullptr;
64
65 // Confirm that the grain index is set in the grain info
66 REQUIRE(gInfo.index == index);
67
68 // Confirm that the grain size and stride lengths are what we expect.
69 constexpr auto w = 1920;
70 constexpr auto h = 1080;
71
73 REQUIRE(configInfo.discrete.sliceSizes[0] == fillPayloadStrideSize);
74 REQUIRE(configInfo.discrete.sliceSizes[1] == 0);
75 REQUIRE(configInfo.discrete.sliceSizes[2] == 0);
76 REQUIRE(configInfo.discrete.sliceSizes[3] == 0);
77
79 REQUIRE(gInfo.grainSize == fillPayloadSize);
80
82 buffer[0] = 0xCA;
83 buffer[gInfo.grainSize - 1] = 0xFE;
84
88 REQUIRE(runtimeInfo1.headIndex == 0);
89
93
96
97 // Give some time to the inotify message to reach the directorywatcher.
98 std::this_thread::sleep_for(std::chrono::milliseconds(5));
99
102
104 REQUIRE(buffer[0] == 0xCA);
105 REQUIRE(buffer[gInfo.grainSize - 1] == 0xFE);
106
110
112 REQUIRE(runtimeInfo2.headIndex == index);
113
114 // We accessed the grain using mxlFlowReaderGetGrain. This should have increased the lastReadTime field.
115 REQUIRE(runtimeInfo2.lastReadTime > runtimeInfo1.lastReadTime);
116
117 // We commited a new grain. This should have increased the lastWriteTime field.
118 REQUIRE(runtimeInfo2.lastWriteTime > runtimeInfo1.lastWriteTime);
119
122
123 // Use the writer after closing the reader.
124 buffer = nullptr;
127 buffer[0] = 0xCA;
128 buffer[gInfo.grainSize - 1] = 0xFE;
129
131
134}
135
136TEST_CASE_PERSISTENT_FIXTURE(mxl::tests::mxlDomainFixture, "Video Flow (With Alpha) : Create/Destroy", "[mxl flows]")
137{
138 auto const opts = "{}";
139 auto const flowId = "5fbec3b1-1b0f-417d-9059-8b94a47197ed";
140 auto flowDef = mxl::tests::readFile("data/v210a_flow.json");
141 bool active = false;
142
143 auto instanceReader = mxlCreateInstance(domain.string().c_str(), opts);
145
146 auto instanceWriter = mxlCreateInstance(domain.string().c_str(), opts);
148
151 bool flowWasCreated = false;
154
157
158 // The writer is now created. The flow should be active.
160 REQUIRE(active == true);
161
163 auto const rate = mxlRational{60000, 1001};
164 auto const now = mxlGetTime();
167
170 uint8_t* buffer = nullptr;
173
174 // Confirm that the grain size and stride lengths are what we expect.
175 constexpr auto w = 1920;
176 constexpr auto h = 1080;
177
180 REQUIRE(configInfo.discrete.sliceSizes[0] == fillPayloadStrideSize);
181
182 auto keyPayloadStrideSize = static_cast<std::size_t>((w + 2) / 3 * 4);
184 REQUIRE(configInfo.discrete.sliceSizes[1] == keyPayloadStrideSize);
185 REQUIRE(configInfo.discrete.sliceSizes[2] == 0);
186 REQUIRE(configInfo.discrete.sliceSizes[3] == 0);
187
189
191 buffer[0] = 0xCA;
192 buffer[gInfo.grainSize - 1] = 0xFE;
193
197 REQUIRE(runtimeInfo1.headIndex == 0);
198
202
205
206 // Give some time to the inotify message to reach the directorywatcher.
207 std::this_thread::sleep_for(std::chrono::milliseconds(5));
208
211
213 REQUIRE(buffer[0] == 0xCA);
214 REQUIRE(buffer[gInfo.grainSize - 1] == 0xFE);
215
219
222
223 // We accessed the grain using mxlFlowReaderGetGrain. This should have increased the lastReadTime field.
224 REQUIRE(runtimeInfo2.lastReadTime > runtimeInfo1.lastReadTime);
225
226 // We commited a new grain. This should have increased the lastWriteTime field.
227 REQUIRE(runtimeInfo2.lastWriteTime > runtimeInfo1.lastWriteTime);
228
231
232 // Use the writer after closing the reader.
233 buffer = nullptr;
236 buffer[0] = 0xCA;
237 buffer[gInfo.grainSize - 1] = 0xFE;
238
240
243}
244
245TEST_CASE_PERSISTENT_FIXTURE(mxl::tests::mxlDomainFixture, "Video Flow : Invalid flow (discrete)", "[mxl flows]")
246{
247 auto const opts = "{}";
248 auto const flowId = "5fbec3b1-1b0f-417d-9059-8b94a47197ed";
249 auto flowDef = mxl::tests::readFile("data/v210_flow.json");
250
251 auto instanceReader = mxlCreateInstance(domain.string().c_str(), opts);
252 REQUIRE(instanceReader != nullptr);
253
254 auto instanceWriter = mxlCreateInstance(domain.string().c_str(), opts);
255 REQUIRE(instanceWriter != nullptr);
256
259 bool flowWasCreated = false;
262
265
266 // The writer is now created. The flow should be active.
267 bool active = false;
269 REQUIRE(active == true);
270
272
274 auto const rate = mxlRational{60000, 1001};
275 auto const now = mxlGetTime();
276 uint64_t index = mxlTimestampToIndex(&rate, now);
278
281 uint8_t* buffer = nullptr;
282
284
287}
288
289TEST_CASE_PERSISTENT_FIXTURE(mxl::tests::mxlDomainFixture, "Flow definitions and options with numbers that do not fit", "[mxl flows]")
290{
291 auto const opts = "{}";
292 auto instance = mxlCreateInstance(domain.string().c_str(), opts);
293 REQUIRE(instance != nullptr);
294
295 auto parse = [](char const* file)
296 {
297 auto jsonValue = picojson::value{};
298 REQUIRE(picojson::parse(jsonValue, mxl::tests::readFile(file)).empty());
299 return jsonValue.get<picojson::object>();
300 };
301 auto const video = parse("data/v210_flow.json");
302 auto const audio = parse("data/audio_flow.json");
303
304 auto tryCreate = [&](picojson::object const& flowObj, std::string const& options)
305 {
306 auto const flowDef = picojson::value(flowObj).serialize();
307 auto writer = mxlFlowWriter{};
309 auto const status = mxlCreateFlowWriter(instance, flowDef.c_str(), options.c_str(), &writer, &configInfo, nullptr);
310 if (status == MXL_STATUS_OK)
311 {
313 }
314 return status;
315 };
316
317 for (auto const value : {1e300, -1.0, 1920.5})
318 {
319 CAPTURE(value);
320 auto flowObj = video;
321 flowObj["frame_width"] = picojson::value{value};
322 REQUIRE(tryCreate(flowObj, opts) != MXL_STATUS_OK);
323
324 flowObj = video;
325 flowObj["frame_height"] = picojson::value{value};
326 REQUIRE(tryCreate(flowObj, opts) != MXL_STATUS_OK);
327
328 flowObj = audio;
329 flowObj["channel_count"] = picojson::value{value};
330 REQUIRE(tryCreate(flowObj, opts) != MXL_STATUS_OK);
331 }
332
333 for (auto const value : {1e20, -1e20, 25.5})
334 {
335 CAPTURE(value);
336 auto flowObj = video;
337 flowObj.find("grain_rate")->second.get<picojson::object>()["numerator"] = picojson::value{value};
338 REQUIRE(tryCreate(flowObj, opts) != MXL_STATUS_OK);
339 }
340
341 for (auto const* key : {"maxCommitBatchSizeHint", "maxSyncBatchSizeHint"})
342 {
343 CAPTURE(key);
344 auto optsObj = picojson::object{};
345 optsObj[key] = picojson::value{1e12};
346 REQUIRE(tryCreate(video, picojson::value(optsObj).serialize()) != MXL_STATUS_OK);
347 }
348
349 // Duplicate keys and trailing content are rejected.
350 auto const flowDef = picojson::value(video).serialize();
351 auto writer = mxlFlowWriter{};
353 auto const duplicate = flowDef.substr(0, flowDef.size() - 1U) + R"(,"label":"other"})";
354 REQUIRE(mxlCreateFlowWriter(instance, duplicate.c_str(), opts, &writer, &configInfo, nullptr) != MXL_STATUS_OK);
355 auto const trailing = flowDef + " {}";
356 REQUIRE(mxlCreateFlowWriter(instance, trailing.c_str(), opts, &writer, &configInfo, nullptr) != MXL_STATUS_OK);
357
358 // The valid definition is still accepted.
359 REQUIRE(tryCreate(video, opts) == MXL_STATUS_OK);
360
362}
363
364TEST_CASE_PERSISTENT_FIXTURE(mxl::tests::mxlDomainFixture, "Invalid flow definitions", "[mxl flows]")
365{
366 // Create the instance
367 char const* opts = "{}";
368 auto instance = mxlCreateInstance(domain.string().c_str(), opts);
369 REQUIRE(instance != nullptr);
370
371 //
372 // Parse a valid flow definition and keep it as a reference picojson object.
373 //
374 auto const flowDef = mxl::tests::readFile("data/v210_flow.json");
375 auto jsonValue = picojson::value{};
376 auto const err = picojson::parse(jsonValue, flowDef);
377 REQUIRE(err.empty());
378 REQUIRE(jsonValue.is<picojson::object>());
379 auto const validFlowObj = jsonValue.get<picojson::object>();
380
383
384 // Create a flow definition with no grain rate
385 auto noGrainRateObj = validFlowObj;
386 noGrainRateObj.erase("grain_rate");
387 auto const noGrainRate = picojson::value(noGrainRateObj).serialize();
388 REQUIRE(mxlCreateFlowWriter(instance, noGrainRate.c_str(), opts, &writer, &configInfo, nullptr) != MXL_STATUS_OK);
389
390 // Create a flow definition with no id
391 auto noIdObj = validFlowObj;
392 noIdObj.erase("id");
393 auto const noId = picojson::value(noIdObj).serialize();
394 REQUIRE(mxlCreateFlowWriter(instance, noId.c_str(), opts, &writer, &configInfo, nullptr) != MXL_STATUS_OK);
395
396 // Create a flow definition with no media type
397 auto noMediaTypeObj = validFlowObj;
398 noMediaTypeObj.erase("media_type");
399 auto const noMediaType = picojson::value(noMediaTypeObj).serialize();
400 REQUIRE(mxlCreateFlowWriter(instance, noMediaType.c_str(), opts, &writer, &configInfo, nullptr) != MXL_STATUS_OK);
401
402 // Create a flow definition without label
403 auto labelObj = validFlowObj;
404 labelObj.erase("label");
405 auto const noLabel = picojson::value(labelObj).serialize();
406 REQUIRE(mxlCreateFlowWriter(instance, noLabel.c_str(), opts, &writer, &configInfo, nullptr) != MXL_STATUS_OK);
407
408 // Create an invalid flow definition with an empty label
409 labelObj["label"] = picojson::value{""};
410 auto const emptyLabel = picojson::value(labelObj).serialize();
411 REQUIRE(mxlCreateFlowWriter(instance, emptyLabel.c_str(), opts, &writer, &configInfo, nullptr) != MXL_STATUS_OK);
412
413 // Create a flow definition with an invalid tag
414 auto invalidTagObj = validFlowObj;
415 auto& tagObj = invalidTagObj.find("tags")->second.get<picojson::object>();
416 auto& tagArray = tagObj["urn:x-nmos:tag:grouphint/v1.0"].get<picojson::array>();
417 tagArray.push_back(picojson::value{"a/b/c"});
418 auto const invalidTag = picojson::value(invalidTagObj).serialize();
419 REQUIRE(mxlCreateFlowWriter(instance, invalidTag.c_str(), opts, &writer, &configInfo, nullptr) != MXL_STATUS_OK);
420
421 // Create a flow definition without tags
422 auto noTagsObj = validFlowObj;
423 noTagsObj.erase("tags");
424 auto const noTags = picojson::value(noTagsObj).serialize();
425 REQUIRE(mxlCreateFlowWriter(instance, noTags.c_str(), opts, &writer, &configInfo, nullptr) != MXL_STATUS_OK);
426
427 // Create an interlaced flow definition with an invalid grain rate
428 auto invalidInterlacedRateObj = validFlowObj;
429 invalidInterlacedRateObj["interlace_mode"] = picojson::value{"interlaced_tff"};
430 auto& rate = invalidInterlacedRateObj.find("grain_rate")->second.get<picojson::object>();
431 rate["numerator"] = picojson::value{60000.0};
432 auto const invalidInterlaced = picojson::value(invalidInterlacedRateObj).serialize();
433 REQUIRE(mxlCreateFlowWriter(instance, invalidInterlaced.c_str(), opts, &writer, &configInfo, nullptr) != MXL_STATUS_OK);
434
435 // Create an interlaced flow definition with an invalid height
436 auto invalidInterlacedHeightObj = validFlowObj;
437 invalidInterlacedHeightObj["interlace_mode"] = picojson::value{"interlaced_tff"};
438 invalidInterlacedHeightObj["frame_height"] = picojson::value{1081.0};
439 auto const invalidInterlacedHeight = picojson::value(invalidInterlacedHeightObj).serialize();
440 REQUIRE(mxlCreateFlowWriter(instance, invalidInterlacedHeight.c_str(), opts, &writer, &configInfo, nullptr) != MXL_STATUS_OK);
441
442 // Create a flow definition that is not json
443 char const* malformed = "{ this is not json";
444 REQUIRE(mxlCreateFlowWriter(instance, malformed, opts, &writer, &configInfo, nullptr) != MXL_STATUS_OK);
445
446 // Create a flow definition that has a non-normalized grain rate. it creating the flow
447 // should succeed but the grain rate should be normalized when we read the flow info back.
448 {
449 bool flowWasCreated = false;
450 auto nonNormalizedRateObj = validFlowObj;
451 auto& rate = nonNormalizedRateObj.find("grain_rate")->second.get<picojson::object>();
452 // This is a dumb way to express 50/1.
453 rate["numerator"] = picojson::value{100000.0};
454 rate["denominator"] = picojson::value{2000.0};
455 auto const nonNormalizedRate = picojson::value(nonNormalizedRateObj).serialize();
456 REQUIRE(mxlCreateFlowWriter(instance, nonNormalizedRate.c_str(), opts, &writer, &configInfo, &flowWasCreated) == MXL_STATUS_OK);
458
459 // the rational value found in the json should be normalized to 50/1.
460 REQUIRE(configInfo.common.grainRate.numerator == 50);
461 REQUIRE(configInfo.common.grainRate.denominator == 1);
463 }
464
465 mxlDestroyInstance(instance);
466}
467
468TEST_CASE_PERSISTENT_FIXTURE(mxl::tests::mxlDomainFixture, "Data Flow : Create/Destroy", "[mxl flows]")
469{
470 // Read some RFC-8331 packets from a pcap file downloaded from https://github.com/NEOAdvancedTechnology/ST2110_pcap_zoo
471 auto const datagrams = mxl::tests::readUdpDatagrams("data/ST2110-40-Closed_Captions.cap");
472
473 // We know that in the pcap file the first packet is an empty packet with a marker bit. Skip it and read the second one.
474 REQUIRE(datagrams.size() >= 2);
475 auto const* rtpData = datagrams[1].payload.data();
476 auto rtpSize = datagrams[1].payload.size();
477 REQUIRE(rtpSize > 14);
478 rtpData += 14; // skip packet header until Length field, as defined in RFC-8331, section 2.
479 rtpSize -= 14;
480 uint8_t ancCount = rtpData[2];
481 REQUIRE(ancCount == 1);
482
483 char const* opts = "{}";
484 auto flowDef = mxl::tests::readFile("data/data_flow.json");
485 char const* flowId = "db3bd465-2772-484f-8fac-830b0471258b";
486
487 auto instanceReader = mxlCreateInstance(domain.string().c_str(), opts);
488 REQUIRE(instanceReader != nullptr);
489
490 auto instanceWriter = mxlCreateInstance(domain.string().c_str(), opts);
491 REQUIRE(instanceWriter != nullptr);
492
495 bool flowWasCreated = false;
498
501
503 auto const rate = mxlRational{60000, 1001};
504 auto const now = mxlGetTime();
505 uint64_t index = mxlTimestampToIndex(&rate, now);
507
510 uint8_t* buffer = nullptr;
513
515 REQUIRE(gInfo.grainSize == 4096);
516
517 // Copy the RFC-8331 packet in the grain
518 memcpy(buffer, rtpData, rtpSize);
519
523 REQUIRE(runtimeInfo1.headIndex == 0);
524
528
531
534
536 REQUIRE(0 == memcmp(buffer, rtpData, reinterpret_cast<size_t>(rtpSize)));
537
538 // Give some time to the inotify message to reach the directorywatcher.
539 std::this_thread::sleep_for(std::chrono::milliseconds(5));
540
544
546 REQUIRE(runtimeInfo2.headIndex == index);
547
548 // We accessed the grain using mxlFlowReaderGetGrain. This should have increased the lastReadTime field.
549 REQUIRE(runtimeInfo2.lastReadTime > runtimeInfo1.lastReadTime);
550
551 // We commited a new grain. This should have increased the lastWriteTime field.
552 REQUIRE(runtimeInfo2.lastWriteTime > runtimeInfo1.lastWriteTime);
553
556
557 // Use the writer after closing the reader.
558 uint8_t* buffer2 = nullptr;
560
562
565}
566
567TEST_CASE_PERSISTENT_FIXTURE(mxl::tests::mxlDomainFixture, "Video Flow : Options", "[mxl flows]")
568{
569 auto flowDef = mxl::tests::readFile("data/v210_flow.json");
570
571 auto instanceOpts = "";
572 auto instanceWriter = mxlCreateInstance(domain.string().c_str(), instanceOpts);
573 REQUIRE(instanceWriter != nullptr);
574
577
578 picojson::object optsObj;
579 optsObj["maxCommitBatchSizeHint"] = picojson::value{0.0}; // Invalid value
580
581 auto optsStr = picojson::value(optsObj).serialize();
582 REQUIRE(mxlCreateFlowWriter(instanceWriter, flowDef.c_str(), optsStr.c_str(), &writer, &configInfo, nullptr) == MXL_ERR_UNKNOWN);
583
584 optsObj.clear();
585 optsObj["maxSyncBatchSizeHint"] = picojson::value{-1.0}; // Invalid value
586 optsStr = picojson::value(optsObj).serialize();
587 REQUIRE(mxlCreateFlowWriter(instanceWriter, flowDef.c_str(), optsStr.c_str(), &writer, &configInfo, nullptr) == MXL_ERR_UNKNOWN);
588
589 optsObj.clear();
590 optsObj["maxCommitBatchSizeHint"] = picojson::value{5.0};
591 optsObj["maxSyncBatchSizeHint"] = picojson::value{6.0}; // Not a multiple of maxCommitBatchSizeHint
592 optsStr = picojson::value(optsObj).serialize();
593 REQUIRE(mxlCreateFlowWriter(instanceWriter, flowDef.c_str(), optsStr.c_str(), &writer, &configInfo, nullptr) == MXL_ERR_UNKNOWN);
594
595 optsObj.clear();
596 optsObj["maxCommitBatchSizeHint"] = picojson::value{5.0};
597 optsObj["maxSyncBatchSizeHint"] = picojson::value{10.0};
598 optsStr = picojson::value(optsObj).serialize();
599 bool flowWasCreated = false;
602 REQUIRE(configInfo.common.maxCommitBatchSizeHint == 5U);
603 REQUIRE(configInfo.common.maxSyncBatchSizeHint == 10U);
605
606 flowWasCreated = false;
609 REQUIRE(configInfo.common.maxCommitBatchSizeHint == 1080U);
610 REQUIRE(configInfo.common.maxSyncBatchSizeHint == 1080U);
613}
614
615TEST_CASE_PERSISTENT_FIXTURE(mxl::tests::mxlDomainFixture, "Video Flow : Slices", "[mxl flows]")
616{
617 char const* opts = "{}";
618 auto flowDef = mxl::tests::readFile("data/v210_flow.json");
619 char const* flowId = "5fbec3b1-1b0f-417d-9059-8b94a47197ed";
620
621 auto instanceReader = mxlCreateInstance(domain.string().c_str(), opts);
622 REQUIRE(instanceReader != nullptr);
623
624 auto instanceWriter = mxlCreateInstance(domain.string().c_str(), opts);
625 REQUIRE(instanceWriter != nullptr);
626
629 bool flowWasCreated = false;
632
635
637 auto const rate = mxlRational{60000, 1001};
638 auto const now = mxlGetTime();
639 uint64_t index = mxlTimestampToIndex(&rate, now);
641
644 uint8_t* buffer = nullptr;
646
648 mxlFlowInfo flowInfo1;
650 REQUIRE(flowInfo1.runtime.headIndex == 0);
651
652 // Total number of batches that will be written
653 auto const numBatches =
654 (gInfo.totalSlices + flowInfo1.config.common.maxCommitBatchSizeHint - 1U) / flowInfo1.config.common.maxCommitBatchSizeHint;
655 auto defaultBatchSize = std::size_t{flowInfo1.config.common.maxCommitBatchSizeHint};
656
657 for (auto batchIndex = std::size_t{0}; batchIndex < numBatches; batchIndex++)
658 {
659 auto batchSize = defaultBatchSize;
660
661 // If the total number of slices is not a multiple of the default batch size, the last batch must
662 // be the number of remaining slices
663 if ((batchIndex + 1) * batchSize > gInfo.totalSlices)
664 {
665 batchSize = gInfo.totalSlices - gInfo.validSlices;
666 }
667
669 gInfo.validSlices += batchSize;
671
672 mxlFlowRuntimeInfo sliceRuntimeInfo;
674 REQUIRE(sliceRuntimeInfo.headIndex == index);
675
676 // We commited data to a grain. This should have increased the lastWriteTime field.
677 REQUIRE(sliceRuntimeInfo.lastWriteTime > flowInfo1.runtime.lastWriteTime);
678
680 std::uint8_t* readBuffer = nullptr;
681 auto const expectedValidSlices = std::min(defaultBatchSize * (batchIndex + 1), static_cast<std::size_t>(gInfo.totalSlices));
682 REQUIRE(mxlFlowReaderGetGrainSlice(reader, index, expectedValidSlices, 8, &gInfo, &readBuffer) == MXL_STATUS_OK);
683
684 // Validate the commited size
685 REQUIRE(gInfo.validSlices == expectedValidSlices);
686
687 // Give some time to the inotify message to reach the directorywatcher.
688 std::this_thread::sleep_for(std::chrono::milliseconds(5));
689
690 // We accessed the grain using mxlFlowReaderGetGrain. This should have increased the lastReadTime field.
692 REQUIRE(sliceRuntimeInfo.lastReadTime > flowInfo1.runtime.lastReadTime);
693 }
694
699}
700
701TEST_CASE_PERSISTENT_FIXTURE(mxl::tests::mxlDomainFixture, "Audio Flow : Create/Destroy", "[mxl flows]")
702{
703 auto const opts = "{}";
704 auto const flowId = "b3bb5be7-9fe9-4324-a5bb-4c70e1084449";
705 auto const flowDef = mxl::tests::readFile("data/audio_flow.json");
706
707 auto instanceReader = mxlCreateInstance(domain.string().c_str(), opts);
708 REQUIRE(instanceReader != nullptr);
709
710 auto instanceWriter = mxlCreateInstance(domain.string().c_str(), opts);
711 REQUIRE(instanceWriter != nullptr);
712
714 {
716 bool flowWasCreated = false;
719
720 REQUIRE(configInfo.common.grainRate.numerator == 48000U);
721 REQUIRE(configInfo.common.grainRate.denominator == 1U);
722 REQUIRE(configInfo.continuous.channelCount == 2U);
723 REQUIRE(configInfo.continuous.bufferLength > 128U);
724 }
725
728
730 auto const rate = mxlRational{48000, 1};
731 auto const now = mxlGetTime();
732 auto const index = mxlTimestampToIndex(&rate, now);
734
735 {
737 mxlMutableWrappedMultiBufferSlice payloadBuffersSlices;
738 REQUIRE(mxlFlowWriterOpenSamples(writer, index, 64U, &payloadBuffersSlices) == MXL_STATUS_OK);
739
740 // Verify that the returned info looks alright
741 REQUIRE(payloadBuffersSlices.count == 2U);
742 REQUIRE((payloadBuffersSlices.base.fragments[0].size + payloadBuffersSlices.base.fragments[1].size) == 256U);
743
744 // Fill some test data
745 for (auto i = 0U; i < payloadBuffersSlices.base.fragments[0].size; ++i)
746 {
747 static_cast<std::uint8_t*>(payloadBuffersSlices.base.fragments[0].pointer)[i] = i;
748 }
749 for (auto i = 0U; i < payloadBuffersSlices.base.fragments[1].size; ++i)
750 {
751 static_cast<std::uint8_t*>(payloadBuffersSlices.base.fragments[1].pointer)[i] = payloadBuffersSlices.base.fragments[0].size + i;
752 }
753
755 mxlFlowRuntimeInfo runtimeInfo;
757
758 // Verify that the headindex is yet to be modified
759 REQUIRE(runtimeInfo.headIndex == 0);
760
763 }
764
765 {
767 mxlWrappedMultiBufferSlice payloadBuffersSlices;
768 REQUIRE(mxlFlowReaderGetSamplesNonBlocking(reader, index, 64U, &payloadBuffersSlices) == MXL_STATUS_OK);
769
770 // Verify that the returned info looks alright
771 REQUIRE(payloadBuffersSlices.count == 2U);
772 REQUIRE((payloadBuffersSlices.base.fragments[0].size + payloadBuffersSlices.base.fragments[1].size) == 256U);
773
774 for (auto i = 0U; i < payloadBuffersSlices.base.fragments[0].size; ++i)
775 {
776 REQUIRE(static_cast<std::uint8_t const*>(payloadBuffersSlices.base.fragments[0].pointer)[i] == i);
777 }
778 for (auto i = 0U; i < payloadBuffersSlices.base.fragments[1].size; ++i)
779 {
780 REQUIRE(static_cast<std::uint8_t const*>(payloadBuffersSlices.base.fragments[1].pointer)[i] ==
781 payloadBuffersSlices.base.fragments[0].size + i);
782 }
783
784 // Get the updated flow info
785 mxlFlowRuntimeInfo runtimeInfo;
787
788 // Confirm that that head has moved.
789 REQUIRE(runtimeInfo.headIndex == index);
790 }
791
794
795 {
796 // Use the writer after closing the reader.
797 mxlMutableWrappedMultiBufferSlice payloadBuffersSlices;
798 REQUIRE(mxlFlowWriterOpenSamples(writer, index + 64U, 64U, &payloadBuffersSlices) == MXL_STATUS_OK);
799
800 // Verify that the returned info looks alright
801 REQUIRE(payloadBuffersSlices.count == 2U);
802 REQUIRE((payloadBuffersSlices.base.fragments[0].size + payloadBuffersSlices.base.fragments[1].size) == 256U);
803 }
804
806
809}
810
811TEST_CASE_PERSISTENT_FIXTURE(mxl::tests::mxlDomainFixture, "Audio Flow : Invalid Flow (continuous)", "[mxl flows]")
812{
813 auto const opts = "{}";
814 auto const flowId = "b3bb5be7-9fe9-4324-a5bb-4c70e1084449";
815 auto const flowDef = mxl::tests::readFile("data/audio_flow.json");
816
817 auto instanceReader = mxlCreateInstance(domain.string().c_str(), opts);
818 REQUIRE(instanceReader != nullptr);
819
820 auto instanceWriter = mxlCreateInstance(domain.string().c_str(), opts);
821 REQUIRE(instanceWriter != nullptr);
822
824 {
826 bool flowWasCreated = false;
829
830 REQUIRE(configInfo.common.grainRate.numerator == 48000U);
831 REQUIRE(configInfo.common.grainRate.denominator == 1U);
832 REQUIRE(configInfo.continuous.channelCount == 2U);
833 REQUIRE(configInfo.continuous.bufferLength > 128U);
834 }
835
838
839 // This should be gone from the filesystem.
841
843 auto const rate = mxlRational{48000, 1};
844 auto const now = mxlGetTime();
845 auto const index = mxlTimestampToIndex(&rate, now);
847
848 // Recreate the flow with the same id.
850 bool flowWasCreated = false;
853
854 {
859 mxlWrappedMultiBufferSlice payloadBuffersSlices;
861 }
862
866
869}
870
872{
873 std::uint64_t index;
874 std::size_t size;
875};
876
879std::vector<BatchIndexAndSize> planAudioBatches(std::size_t numOfBatches, std::size_t numOfSamples, std::uint64_t lastBatchIndex)
880{
881 std::vector<BatchIndexAndSize> result;
882 auto const batchSize = numOfSamples / numOfBatches;
883 auto const remainder = numOfSamples % numOfBatches;
884
885 std::size_t samplesSoFar = 0U;
886 for (std::size_t i = 0; i < numOfBatches; ++i)
887 {
888 BatchIndexAndSize batch;
889 batch.size = batchSize + (i < remainder ? 1 : 0);
890 samplesSoFar += batch.size;
891 batch.index = lastBatchIndex - numOfSamples + samplesSoFar;
892 result.push_back(batch);
893 }
894
895 return result;
896}
897
898TEST_CASE_PERSISTENT_FIXTURE(mxl::tests::mxlDomainFixture, "Audio Flow : Different writer / reader batch size", "[mxl flows]")
899{
900 auto const opts = "{}";
901 auto instance = mxlCreateInstance(domain.string().c_str(), opts);
902 REQUIRE(instance != nullptr);
903
904 auto flowDef = mxl::tests::readFile("data/audio_flow.json");
907 bool flowWasCreated = false;
910 auto const flowId = uuids::to_string(configInfo.common.id);
911 REQUIRE(
912 configInfo.continuous.bufferLength > 11U); // To have at least 2 samples per batch in our second part of the test with reading in 3 batches.
913
914 // We write the whole buffer worth of data in 4 batches, and then we try to read the second half back in both equally-sized batches and in
915 // different-sized batches.
916 auto const lastIndex = mxlGetCurrentIndex(&configInfo.common.grainRate);
917 auto writeBatches = planAudioBatches(4, configInfo.continuous.bufferLength, lastIndex);
918
919 for (auto const& batch : writeBatches)
920 {
921 mxlMutableWrappedMultiBufferSlice payloadBuffersSlices;
922 REQUIRE(mxlFlowWriterOpenSamples(writer, batch.index, batch.size, &payloadBuffersSlices) == MXL_STATUS_OK);
923 REQUIRE((payloadBuffersSlices.base.fragments[0].size + payloadBuffersSlices.base.fragments[1].size) / 4 == batch.size);
924 std::uint64_t index = batch.index - batch.size + 1;
925 for (std::size_t i = 0U; i < payloadBuffersSlices.base.fragments[0].size / 4; ++i)
926 {
927 static_cast<std::uint32_t*>(payloadBuffersSlices.base.fragments[0].pointer)[i] = static_cast<std::uint32_t>(index++);
928 }
929 for (std::size_t i = 0U; i < payloadBuffersSlices.base.fragments[1].size / 4; ++i)
930 {
931 static_cast<std::uint32_t*>(payloadBuffersSlices.base.fragments[1].pointer)[i] = static_cast<std::uint32_t>(index++);
932 }
933 REQUIRE(index == batch.index + 1);
935 }
936
938 REQUIRE(mxlCreateFlowReader(instance, flowId.c_str(), "", &reader) == MXL_STATUS_OK);
939 auto const readCheckFn = [](mxlFlowReader reader, std::vector<BatchIndexAndSize> const& batches)
940 {
941 for (auto const& batch : batches)
942 {
943 mxlWrappedMultiBufferSlice payloadBuffersSlices;
944 REQUIRE(mxlFlowReaderGetSamplesNonBlocking(reader, batch.index, batch.size, &payloadBuffersSlices) == MXL_STATUS_OK);
945 REQUIRE((payloadBuffersSlices.base.fragments[0].size + payloadBuffersSlices.base.fragments[1].size) / 4 == batch.size);
946 std::uint64_t index = batch.index - batch.size + 1;
947 for (std::size_t i = 0U; i < payloadBuffersSlices.base.fragments[0].size / 4; ++i)
948 {
949 REQUIRE(static_cast<std::uint32_t const*>(payloadBuffersSlices.base.fragments[0].pointer)[i] == static_cast<std::uint32_t>(index++));
950 }
951 for (std::size_t i = 0U; i < payloadBuffersSlices.base.fragments[1].size / 4; ++i)
952 {
953 REQUIRE(static_cast<std::uint32_t const*>(payloadBuffersSlices.base.fragments[1].pointer)[i] == static_cast<std::uint32_t>(index++));
954 }
955 REQUIRE(index == batch.index + 1);
956 }
957 };
958 // When checking the batches, we can only check the second half of the buffer (this is what mxlFlowReaderGetSamples and friends allow us).
959 writeBatches.erase(writeBatches.begin(), writeBatches.begin() + writeBatches.size() / 2);
960 readCheckFn(reader, writeBatches);
961 auto const readBatches = planAudioBatches(writeBatches.size() + 1, configInfo.continuous.bufferLength / 2, lastIndex);
962 readCheckFn(reader, readBatches);
965
967}
968
969TEST_CASE_PERSISTENT_FIXTURE(mxl::tests::mxlDomainFixture, "Audio Flow : Options", "[mxl flows]")
970{
971 auto flowDef = mxl::tests::readFile("data/audio_flow.json");
972
973 auto instanceOpts = "";
974 auto instanceWriter = mxlCreateInstance(domain.string().c_str(), instanceOpts);
975 REQUIRE(instanceWriter != nullptr);
976
979
980 picojson::object optsObj;
981 optsObj["maxCommitBatchSizeHint"] = picojson::value{-1.0}; // Invalid value
982
983 auto optsStr = picojson::value(optsObj).serialize();
984 REQUIRE(mxlCreateFlowWriter(instanceWriter, flowDef.c_str(), optsStr.c_str(), &writer, &configInfo, nullptr) == MXL_ERR_UNKNOWN);
985
986 optsObj.clear();
987 optsObj["maxSyncBatchSizeHint"] = picojson::value{0.0}; // Invalid value
988 optsStr = picojson::value(optsObj).serialize();
989 REQUIRE(mxlCreateFlowWriter(instanceWriter, flowDef.c_str(), optsStr.c_str(), &writer, &configInfo, nullptr) == MXL_ERR_UNKNOWN);
990
991 optsObj.clear();
992 optsObj["maxCommitBatchSizeHint"] = picojson::value{10.0};
993 optsObj["maxSyncBatchSizeHint"] = picojson::value{2.0}; // Not a multiple of maxCommitBatchSizeHint
994 optsStr = picojson::value(optsObj).serialize();
995 REQUIRE(mxlCreateFlowWriter(instanceWriter, flowDef.c_str(), optsStr.c_str(), &writer, &configInfo, nullptr) == MXL_ERR_UNKNOWN);
996
997 optsObj.clear();
998 optsObj["maxCommitBatchSizeHint"] = picojson::value{5.0};
999 optsObj["maxSyncBatchSizeHint"] = picojson::value{10.0};
1000 optsStr = picojson::value(optsObj).serialize();
1001 bool flowWasCreated = false;
1004 REQUIRE(configInfo.common.maxCommitBatchSizeHint == 5U);
1005 REQUIRE(configInfo.common.maxSyncBatchSizeHint == 10U);
1007
1008 flowWasCreated = false;
1011 REQUIRE(configInfo.common.maxCommitBatchSizeHint == 480U);
1012 REQUIRE(configInfo.common.maxSyncBatchSizeHint == 480U);
1015}
1016
1018{
1019 auto const opts = "{}";
1020 auto instance = mxlCreateInstance(domain.string().c_str(), opts);
1021 REQUIRE(instance != nullptr);
1022
1023 auto flowDef = mxl::tests::readFile("data/v210_flow.json");
1026 bool flowWasCreated = false;
1029 auto const flowId = uuids::to_string(configInfo.common.id);
1030
1031 char fourKBuffer[4096];
1032 auto fourKBufferSize = sizeof(fourKBuffer);
1033
1034 REQUIRE(mxlGetFlowDef(nullptr, flowId.c_str(), fourKBuffer, &fourKBufferSize) == MXL_ERR_INVALID_ARG);
1035 REQUIRE(fourKBufferSize == sizeof(fourKBuffer));
1036
1037 REQUIRE(mxlGetFlowDef(instance, nullptr, fourKBuffer, &fourKBufferSize) == MXL_ERR_INVALID_ARG);
1038 REQUIRE(fourKBufferSize == sizeof(fourKBuffer));
1039 REQUIRE(mxlGetFlowDef(instance, "this is not UUID", fourKBuffer, &fourKBufferSize) == MXL_ERR_INVALID_ARG);
1040 REQUIRE(fourKBufferSize == sizeof(fourKBuffer));
1041 REQUIRE(mxlGetFlowDef(instance, "75f369f9-6814-48a3-b827-942bc24c3d25", fourKBuffer, &fourKBufferSize) == MXL_ERR_FLOW_NOT_FOUND);
1042 REQUIRE(fourKBufferSize == sizeof(fourKBuffer));
1043
1044 REQUIRE(mxlGetFlowDef(instance, flowId.c_str(), fourKBuffer, nullptr) == MXL_ERR_INVALID_ARG);
1045
1046 auto requiredBufferSize = size_t{0U};
1047 REQUIRE(mxlGetFlowDef(instance, flowId.c_str(), nullptr, &requiredBufferSize) == MXL_ERR_INVALID_ARG);
1048 REQUIRE(requiredBufferSize == flowDef.size() + 1);
1049 auto requiredBufferSize2 = size_t{10U};
1050 REQUIRE(mxlGetFlowDef(instance, flowId.c_str(), fourKBuffer, &requiredBufferSize2) == MXL_ERR_INVALID_ARG);
1051 REQUIRE(requiredBufferSize == requiredBufferSize2);
1052
1053 requiredBufferSize = fourKBufferSize;
1054 REQUIRE(mxlGetFlowDef(instance, flowId.c_str(), fourKBuffer, &requiredBufferSize) == MXL_STATUS_OK);
1055 REQUIRE(requiredBufferSize == requiredBufferSize2);
1056 REQUIRE(flowDef == std::string{fourKBuffer});
1057
1060}
1061
1062// Verify that we obtain a proper error code when attempting to create a flow
1063// in an unwritable domain.
1064TEST_CASE_PERSISTENT_FIXTURE(mxl::tests::mxlDomainFixture, "mxlCreateFlow: unwritable domain", "[mxl flows]")
1065{
1066 // remove write perms on domain
1067 permissions(domain, std::filesystem::perms::owner_write, std::filesystem::perm_options::remove);
1068
1069 auto const opts = "{}";
1070 auto instance = mxlCreateInstance(domain.string().c_str(), opts);
1071 REQUIRE(instance != nullptr);
1072
1073 auto flowDef = mxl::tests::readFile("data/v210_flow.json");
1076 REQUIRE(mxlCreateFlowWriter(instance, flowDef.c_str(), opts, &writer, &configInfo, nullptr) == MXL_ERR_PERMISSION_DENIED);
1077
1078 // restore perms so we can clean up
1079 permissions(domain, std::filesystem::perms::owner_all, std::filesystem::perm_options::add);
1080 remove_all(domain);
1081}
1082
1083// Verify that a reader that may not open the files of a flow gets a proper error
1084// code. The reader uses an instance of its own, as a reading process would.
1085TEST_CASE_PERSISTENT_FIXTURE(mxl::tests::mxlDomainFixture, "mxlCreateFlowReader: unreadable flow directory", "[mxl flows]")
1086{
1087 auto const opts = "{}";
1088 auto const instance = mxlCreateInstance(domain.string().c_str(), opts);
1089 REQUIRE(instance != nullptr);
1090 auto const readerInstance = mxlCreateInstance(domain.string().c_str(), opts);
1091 REQUIRE(readerInstance != nullptr);
1092
1093 auto const flowDef = mxl::tests::readFile("data/v210_flow.json");
1094 mxlFlowWriter writer = nullptr;
1096 REQUIRE(mxlCreateFlowWriter(instance, flowDef.c_str(), opts, &writer, &configInfo, nullptr) == MXL_STATUS_OK);
1097 auto const flowId = uuids::to_string(configInfo.common.id);
1098 auto const flowDirectory = mxl::lib::makeFlowDirectoryName(domain, flowId);
1099
1100 // Restore the permissions before checking, so the domain can be removed whatever the outcome.
1101 permissions(flowDirectory, std::filesystem::perms::owner_read | std::filesystem::perms::owner_exec, std::filesystem::perm_options::remove);
1102 mxlFlowReader reader = nullptr;
1103 auto const status = mxlCreateFlowReader(readerInstance, flowId.c_str(), "", &reader);
1104 permissions(flowDirectory, std::filesystem::perms::owner_all, std::filesystem::perm_options::add);
1106
1108 REQUIRE(mxlDestroyInstance(readerInstance) == MXL_STATUS_OK);
1110}
1111
1112// Verify that a reader of a continuous flow whose descriptor it may not read gets
1113// a proper error code.
1114TEST_CASE_PERSISTENT_FIXTURE(mxl::tests::mxlDomainFixture, "mxlCreateFlowReader: unreadable continuous flow descriptor", "[mxl flows]")
1115{
1116 auto const opts = "{}";
1117 auto const instance = mxlCreateInstance(domain.string().c_str(), opts);
1118 REQUIRE(instance != nullptr);
1119 auto const readerInstance = mxlCreateInstance(domain.string().c_str(), opts);
1120 REQUIRE(readerInstance != nullptr);
1121
1122 auto const flowDef = mxl::tests::readFile("data/audio_flow.json");
1123 mxlFlowWriter writer = nullptr;
1125 REQUIRE(mxlCreateFlowWriter(instance, flowDef.c_str(), opts, &writer, &configInfo, nullptr) == MXL_STATUS_OK);
1126 auto const flowId = uuids::to_string(configInfo.common.id);
1127 auto const flowDescriptor = mxl::lib::makeFlowDescriptorFilePath(domain, flowId);
1128
1129 permissions(flowDescriptor, std::filesystem::perms::owner_read, std::filesystem::perm_options::remove);
1130 mxlFlowReader reader = nullptr;
1131 auto const status = mxlCreateFlowReader(readerInstance, flowId.c_str(), "", &reader);
1132 permissions(flowDescriptor, std::filesystem::perms::owner_read, std::filesystem::perm_options::add);
1134
1136 REQUIRE(mxlDestroyInstance(readerInstance) == MXL_STATUS_OK);
1138}
1139
1140TEST_CASE_PERSISTENT_FIXTURE(mxl::tests::mxlDomainFixture, "mxlFlowWriterCommitSamples should notify the reader", "[mxl flows][futex]")
1141{
1142 constexpr auto const startIndex = 1000;
1143 constexpr auto const blockSize = 480;
1144 constexpr auto const iterations = std::uint64_t{50};
1145 constexpr auto const readTimeout = std::chrono::duration_cast<std::chrono::nanoseconds>(std::chrono::milliseconds(150));
1146 auto flowDef = mxl::tests::readFile("data/audio_flow.json");
1148 auto instance = mxlCreateInstance(domain.c_str(), nullptr);
1149 mxlFlowWriter writer = nullptr;
1150 mxlFlowReader reader = nullptr;
1151
1152 REQUIRE(instance != nullptr);
1153 REQUIRE(mxlCreateFlowWriter(instance, flowDef.c_str(), nullptr, &writer, &configInfo, nullptr) == MXL_STATUS_OK);
1154 REQUIRE(mxlCreateFlowReader(instance, "b3bb5be7-9fe9-4324-a5bb-4c70e1084449", nullptr, &reader) == MXL_STATUS_OK);
1155
1156 auto stillWriting = std::atomic_flag{true};
1157 auto writerThread = std::thread{[&]()
1158 {
1159 auto slice = mxlMutableWrappedMultiBufferSlice{};
1160 for (auto i = std::uint64_t{0}; i < iterations; ++i)
1161 {
1162 REQUIRE(mxlFlowWriterOpenSamples(writer, startIndex + (i * blockSize), blockSize, &slice) == MXL_STATUS_OK);
1164 std::this_thread::sleep_for(std::chrono::milliseconds(10));
1165 }
1166 stillWriting.clear();
1167 }};
1168
1169 // read in a loop until `stillWriting` is cleared
1170 auto slices = mxlWrappedMultiBufferSlice{};
1171 auto currentBlockIndex = std::uint64_t{0};
1172 for (;;)
1173 {
1174 auto const status = mxlFlowReaderGetSamples(reader, startIndex + (currentBlockIndex * blockSize), blockSize, readTimeout.count(), &slices);
1175 if (!stillWriting.test_and_set())
1176 {
1177 break;
1178 }
1179
1180 REQUIRE(status == MXL_STATUS_OK);
1181 ++currentBlockIndex;
1182 }
1183
1184 writerThread.join();
1185 REQUIRE(currentBlockIndex == iterations);
1186
1189
1191}
1192
1193TEST_CASE_PERSISTENT_FIXTURE(mxl::tests::mxlDomainFixture, "Audio Flow : Jump forward", "[mxl flows]")
1194{
1195 auto const opts = "{}";
1196 constexpr std::uint64_t samplesPerCommit = 480;
1197
1198 auto instanceReader = mxlCreateInstance(domain.string().c_str(), opts);
1199 REQUIRE(instanceReader != nullptr);
1200
1201 auto instanceWriter = mxlCreateInstance(domain.string().c_str(), opts);
1202 REQUIRE(instanceWriter != nullptr);
1203
1204 auto flowDef = mxl::tests::readFile("data/audio_flow.json");
1207 bool flowWasCreated = false;
1210
1212 auto const flowId = uuids::to_string(configInfo.common.id);
1214
1216 auto const groupToSampleIndex = [](std::uint64_t groupIndex)
1217 {
1218 return ((groupIndex + 1U) * samplesPerCommit) - 1U;
1219 };
1220
1221 // Write initial groups 42-46.
1222 for (auto writerGroupIndex = std::uint64_t{42}; writerGroupIndex <= std::uint64_t{46}; ++writerGroupIndex)
1223 {
1224 auto const writerSampleIndex = groupToSampleIndex(writerGroupIndex);
1225 REQUIRE(mxlFlowWriterOpenSamples(writer, writerSampleIndex, samplesPerCommit, &writeSlices) == MXL_STATUS_OK);
1226 auto const firstSamples = writeSlices.base.fragments[0].size / sizeof(std::uint32_t);
1227 for (std::size_t i = 0U; i < firstSamples; ++i)
1228 {
1229 static_cast<std::uint32_t*>(writeSlices.base.fragments[0].pointer)[i] = static_cast<std::uint32_t>(writerGroupIndex);
1230 }
1231 auto const secondSamples = writeSlices.base.fragments[1].size / sizeof(std::uint32_t);
1232 for (std::size_t i = 0U; i < secondSamples; ++i)
1233 {
1234 static_cast<std::uint32_t*>(writeSlices.base.fragments[1].pointer)[i] = static_cast<std::uint32_t>(writerGroupIndex);
1235 }
1237 }
1238
1239 // Jump forward to group 100, skipping groups 47-99.
1240 std::uint64_t writerGroupIndex = 100;
1241 std::uint64_t writerSampleIndex = groupToSampleIndex(writerGroupIndex);
1242 REQUIRE(mxlFlowWriterOpenSamples(writer, writerSampleIndex, samplesPerCommit, &writeSlices) == MXL_STATUS_OK);
1243
1244 // Before commit, the earlier groups should still have their original values because invalidation happens on commit.
1245 mxlWrappedMultiBufferSlice readSlices{};
1246 for (auto readGroupIndex = std::uint64_t{42}; readGroupIndex <= std::uint64_t{46}; ++readGroupIndex)
1247 {
1248 auto const sampleIndex = groupToSampleIndex(readGroupIndex);
1249 auto const returnCode = mxlFlowReaderGetSamplesNonBlocking(reader, sampleIndex, 1U, &readSlices);
1250 // This condition lines up because we picked 480 samples (10ms), which is a divider of the default history duration (200 ms).
1251 if (sampleIndex % configInfo.continuous.bufferLength == writerSampleIndex % configInfo.continuous.bufferLength)
1252 {
1254 }
1255 else
1256 {
1257 REQUIRE(returnCode == MXL_STATUS_OK);
1258 // Before commit, data should still have original values (group index).
1259 if (readSlices.base.fragments[0].size > 0U)
1260 {
1261 REQUIRE(static_cast<std::uint32_t const*>(readSlices.base.fragments[0].pointer)[0] == readGroupIndex);
1262 }
1263 if (readSlices.base.fragments[1].size > 0U)
1264 {
1265 REQUIRE(static_cast<std::uint32_t const*>(readSlices.base.fragments[1].pointer)[0] == readGroupIndex);
1266 }
1267 }
1268 }
1269
1270 auto const firstSamples = writeSlices.base.fragments[0].size / sizeof(std::uint32_t);
1271 for (std::size_t i = 0U; i < firstSamples; ++i)
1272 {
1273 static_cast<std::uint32_t*>(writeSlices.base.fragments[0].pointer)[i] = static_cast<std::uint32_t>(writerGroupIndex);
1274 }
1275 auto const secondSamples = writeSlices.base.fragments[1].size / sizeof(std::uint32_t);
1276 for (std::size_t i = 0U; i < secondSamples; ++i)
1277 {
1278 static_cast<std::uint32_t*>(writeSlices.base.fragments[1].pointer)[i] = static_cast<std::uint32_t>(writerGroupIndex);
1279 }
1281
1282 // After commit, the gap between group 46 and 100 should be invalidated (zeroed out).
1283 // Check a sample right before group 100 to verify the gap was cleared.
1284 auto const gapSampleIndex = groupToSampleIndex(99U);
1285 REQUIRE(mxlFlowReaderGetSamplesNonBlocking(reader, gapSampleIndex, 1U, &readSlices) == MXL_STATUS_OK);
1286 if (readSlices.base.fragments[0].size > 0U)
1287 {
1288 REQUIRE(static_cast<std::uint32_t const*>(readSlices.base.fragments[0].pointer)[0] == 0U);
1289 }
1290 if (readSlices.base.fragments[1].size > 0U)
1291 {
1292 REQUIRE(static_cast<std::uint32_t const*>(readSlices.base.fragments[1].pointer)[0] == 0U);
1293 }
1294
1295 // Group 100 endpoint should contain the latest write after commit
1296 REQUIRE(mxlFlowReaderGetSamplesNonBlocking(reader, writerSampleIndex, 1U, &readSlices) == MXL_STATUS_OK);
1297 REQUIRE(static_cast<std::uint32_t const*>(readSlices.base.fragments[0].pointer)[0] == 100U);
1298
1303}
1304
1305TEST_CASE_PERSISTENT_FIXTURE(mxl::tests::mxlDomainFixture, "Video Flow : Jump forward", "[mxl flows]")
1306{
1307 auto const opts = "{}";
1308 auto instanceReader = mxlCreateInstance(domain.string().c_str(), opts);
1309 REQUIRE(instanceReader != nullptr);
1310
1311 auto instanceWriter = mxlCreateInstance(domain.string().c_str(), opts);
1312 REQUIRE(instanceWriter != nullptr);
1313
1314 auto flowDef = mxl::tests::readFile("data/v210_flow.json");
1317 bool flowWasCreated = false;
1320
1322 auto const flowId = uuids::to_string(configInfo.common.id);
1324
1326 std::uint8_t* buffer = nullptr;
1327 // Write initial grains 42-46.
1328 for (auto writerGrainIndex = std::uint64_t{42}; writerGrainIndex <= std::uint64_t{46}; ++writerGrainIndex)
1329 {
1331 REQUIRE(buffer != nullptr);
1332 std::memcpy(buffer, &writerGrainIndex, sizeof(std::uint64_t));
1333 gInfo.validSlices = gInfo.totalSlices;
1335 }
1336
1337 // Jump forward to grain 100, skipping grains 47-99
1338 auto writerGrainIndex = std::uint64_t{100};
1340
1341 // From the moment we open grain 100, the whole ring buffer should be invalidated. The head does not move until grain 100 is committed though, so
1342 // we have to check grains 46 and earlier.
1343 for (auto grainIndex = std::max(std::uint64_t{46} - configInfo.discrete.grainCount + 2, std::uint64_t{42}); grainIndex <= std::uint64_t{46};
1344 ++grainIndex)
1345 {
1346 mxlGrainInfo readGrainInfo;
1347 std::uint8_t* readBuffer = nullptr;
1348
1349 auto returnCode = mxlFlowReaderGetGrain(reader, grainIndex, 0, &readGrainInfo, &readBuffer);
1350 if (grainIndex % configInfo.discrete.grainCount == writerGrainIndex % configInfo.discrete.grainCount)
1351 {
1353 }
1354 else
1355 {
1356 REQUIRE(returnCode == MXL_STATUS_OK);
1357 }
1358 REQUIRE((readGrainInfo.flags & MXL_GRAIN_FLAG_INVALID) != 0);
1359 }
1360
1361 // Commit grain 100 and verify that it is readable.
1362 std::memcpy(buffer, &writerGrainIndex, sizeof(std::uint64_t));
1363 gInfo.validSlices = gInfo.totalSlices;
1365 REQUIRE(mxlFlowReaderGetGrain(reader, writerGrainIndex, 0, &gInfo, &buffer) == MXL_STATUS_OK);
1366 REQUIRE(reinterpret_cast<std::uint64_t*>(buffer)[0] == writerGrainIndex);
1367
1372}
1373
1374// Verify that opening a new grain resets validSlices to zero when the
1375// underlying ring-buffer slot is reused, while reopening the same
1376// incomplete grain preserves its existing validSlices value.
1377TEST_CASE_PERSISTENT_FIXTURE(mxl::tests::mxlDomainFixture, "Flow definitions with a non-positive rate", "[mxl flows]")
1378{
1379 auto const opts = "{}";
1380 auto instance = mxlCreateInstance(domain.string().c_str(), opts);
1381 REQUIRE(instance != nullptr);
1382
1383 struct RateCase
1384 {
1385 char const* file;
1386 char const* key;
1387 };
1388
1389 for (auto const [file, key] : {
1390 RateCase{"data/v210_flow.json", "grain_rate" },
1391 RateCase{"data/data_flow.json", "grain_rate" },
1392 RateCase{"data/audio_flow.json", "sample_rate"}
1393 })
1394 {
1395 auto const flowDef = mxl::tests::readFile(file);
1396 auto jsonValue = picojson::value{};
1397 REQUIRE(picojson::parse(jsonValue, flowDef).empty());
1398 auto const validFlowObj = jsonValue.get<picojson::object>();
1399
1400 for (auto const [numerator, denominator] : {
1401 std::pair{0.0, 1.0 },
1402 std::pair{-25.0, 1.0 },
1403 std::pair{25.0, 0.0 },
1404 std::pair{25.0, -1.0}
1405 })
1406 {
1407 CAPTURE(file, numerator, denominator);
1408 auto flowObj = validFlowObj;
1409 auto& rate = flowObj.find(key)->second.get<picojson::object>();
1410 rate["numerator"] = picojson::value{numerator};
1411 rate["denominator"] = picojson::value{denominator};
1412 auto const invalidRate = picojson::value(flowObj).serialize();
1413
1414 auto writer = mxlFlowWriter{};
1416 REQUIRE(mxlCreateFlowWriter(instance, invalidRate.c_str(), opts, &writer, &configInfo, nullptr) != MXL_STATUS_OK);
1417 }
1418 }
1419
1421}
1422
1423TEST_CASE_PERSISTENT_FIXTURE(mxl::tests::mxlDomainFixture, "Video Flow : commit rejects an inconsistent grain header", "[mxl flows]")
1424{
1425 auto const opts = "{}";
1426 auto const flowId = "5fbec3b1-1b0f-417d-9059-8b94a47197ed";
1427 auto flowDef = mxl::tests::readFile("data/v210_flow.json");
1428
1429 auto instance = mxlCreateInstance(domain.string().c_str(), opts);
1430 REQUIRE(instance != nullptr);
1431
1432 auto writer = mxlFlowWriter{};
1434 REQUIRE(mxlCreateFlowWriter(instance, flowDef.c_str(), opts, &writer, &configInfo, nullptr) == MXL_STATUS_OK);
1435
1436 auto reader = mxlFlowReader{};
1438
1439 auto const index = std::uint64_t{100};
1440 auto gInfo = mxlGrainInfo{};
1441 auto buffer = static_cast<std::uint8_t*>(nullptr);
1443 auto const validInfo = gInfo;
1444
1445 // grainSize larger than the mapped payload.
1446 gInfo.grainSize = validInfo.grainSize + 1U;
1447 gInfo.validSlices = gInfo.totalSlices;
1449 gInfo.grainSize = UINT32_MAX;
1451
1452 // validSlices larger than totalSlices.
1453 gInfo = validInfo;
1454 gInfo.totalSlices = 0;
1455 gInfo.validSlices = 8;
1457 gInfo = validInfo;
1458 gInfo.validSlices = UINT16_MAX;
1460
1461 // A rejected commit publishes nothing.
1462 auto readInfo = mxlGrainInfo{};
1463 auto readBuffer = static_cast<std::uint8_t*>(nullptr);
1465
1466 // The grain stays open and a valid header can still be committed.
1467 gInfo = validInfo;
1468 gInfo.validSlices = gInfo.totalSlices;
1470 REQUIRE(mxlFlowReaderGetGrain(reader, index, 16, &readInfo, &readBuffer) == MXL_STATUS_OK);
1471
1475}
1476
1477TEST_CASE_PERSISTENT_FIXTURE(mxl::tests::mxlDomainFixture, "Video Flow : reader rejects an inconsistent grain header", "[mxl flows]")
1478{
1479 auto const opts = "{}";
1480 auto const flowId = "5fbec3b1-1b0f-417d-9059-8b94a47197ed";
1481 auto flowDef = mxl::tests::readFile("data/v210_flow.json");
1482
1483 auto instance = mxlCreateInstance(domain.string().c_str(), opts);
1484 REQUIRE(instance != nullptr);
1485
1486 auto writer = mxlFlowWriter{};
1488 REQUIRE(mxlCreateFlowWriter(instance, flowDef.c_str(), opts, &writer, &configInfo, nullptr) == MXL_STATUS_OK);
1489
1490 auto reader = mxlFlowReader{};
1492
1493 auto const grainCount = static_cast<std::uint64_t>(configInfo.discrete.grainCount);
1494
1495 // Commit a valid grain, then overwrite its header in the grain file. This is what a process with write access to the
1496 // flow files can do without going through the SDK.
1497 auto commitAndCorrupt = [&](std::uint64_t index, auto&& corrupt)
1498 {
1499 auto gInfo = mxlGrainInfo{};
1500 auto buffer = static_cast<std::uint8_t*>(nullptr);
1502 gInfo.validSlices = gInfo.totalSlices;
1504
1505 corrupt(gInfo);
1506 auto const grainPath = domain / (std::string{flowId} + ".mxl-flow") / "grains" / ("data." + std::to_string(index % grainCount));
1507 auto file = std::fstream{grainPath, std::ios::in | std::ios::out | std::ios::binary};
1508 REQUIRE(file.is_open());
1509 file.write(reinterpret_cast<char const*>(&gInfo), sizeof gInfo);
1510 file.close();
1511
1512 auto readInfo = mxlGrainInfo{};
1513 auto readBuffer = static_cast<std::uint8_t*>(nullptr);
1514 return mxlFlowReaderGetGrain(reader, index, 16, &readInfo, &readBuffer);
1515 };
1516
1517 auto index = std::uint64_t{100};
1518
1519 // An unchanged header is returned.
1520 REQUIRE(commitAndCorrupt(index++, [](mxlGrainInfo&) {}) == MXL_STATUS_OK);
1521
1522 // grainSize larger than the mapped payload.
1523 REQUIRE(commitAndCorrupt(index++, [](mxlGrainInfo& info) { info.grainSize += 1U; }) == MXL_ERR_INVALID_STATE);
1524 REQUIRE(commitAndCorrupt(index++, [](mxlGrainInfo& info) { info.grainSize = UINT32_MAX; }) == MXL_ERR_INVALID_STATE);
1525
1526 // validSlices larger than totalSlices.
1527 REQUIRE(commitAndCorrupt(index++,
1528 [](mxlGrainInfo& info)
1529 {
1530 info.totalSlices = 0;
1531 info.validSlices = 8;
1532 }) == MXL_ERR_INVALID_STATE);
1533 REQUIRE(commitAndCorrupt(index++, [](mxlGrainInfo& info) { info.validSlices = UINT16_MAX; }) == MXL_ERR_INVALID_STATE);
1534
1538}
1539
1540TEST_CASE_PERSISTENT_FIXTURE(mxl::tests::mxlDomainFixture, "Video Flow : validSlices on grain open", "[mxl flows]")
1541{
1542 auto const opts = "{}";
1543 auto flowDef = mxl::tests::readFile("data/v210_flow.json");
1544
1545 auto instance = mxlCreateInstance(domain.string().c_str(), opts);
1546 REQUIRE(instance != nullptr);
1547
1548 auto writer = mxlFlowWriter{};
1550 auto flowWasCreated = false;
1553
1554 auto const grainCount = static_cast<std::uint64_t>(configInfo.discrete.grainCount);
1555 REQUIRE(grainCount > 1U);
1556
1557 auto const firstSlotIndex = std::uint64_t{100};
1558 auto const nextSlotIndex = firstSlotIndex + 1U;
1559 auto const reusedSlotIndex = firstSlotIndex + grainCount;
1560
1561 auto gInfo = mxlGrainInfo{};
1562 auto buffer = static_cast<std::uint8_t*>(nullptr);
1563
1564 // A freshly created grain starts with zero valid slices.
1566 REQUIRE(gInfo.index == firstSlotIndex);
1567 REQUIRE(gInfo.validSlices == 0);
1568
1569 auto const partialValidSlices = std::uint16_t{3};
1570 REQUIRE(partialValidSlices < gInfo.totalSlices);
1571
1572 gInfo.validSlices = partialValidSlices;
1574
1575 // Reopening the same incomplete grain preserves progress.
1576 auto reopenedInfo = mxlGrainInfo{};
1577 auto reopenedBuffer = static_cast<std::uint8_t*>(nullptr);
1578
1579 REQUIRE(mxlFlowWriterOpenGrain(writer, firstSlotIndex, &reopenedInfo, &reopenedBuffer) == MXL_STATUS_OK);
1580 REQUIRE(reopenedInfo.index == firstSlotIndex);
1581 REQUIRE(reopenedBuffer == buffer);
1582 REQUIRE(reopenedInfo.validSlices == partialValidSlices);
1583
1584 // Complete the grain.
1585 reopenedInfo.validSlices = reopenedInfo.totalSlices;
1587
1588 // A new grain starts with zero valid slices after the previous grain is complete.
1589 auto nextInfo = mxlGrainInfo{};
1590 auto nextBuffer = static_cast<std::uint8_t*>(nullptr);
1591
1592 REQUIRE(mxlFlowWriterOpenGrain(writer, nextSlotIndex, &nextInfo, &nextBuffer) == MXL_STATUS_OK);
1593 REQUIRE(nextInfo.index == nextSlotIndex);
1594 REQUIRE(nextInfo.validSlices == 0);
1595
1596 nextInfo.validSlices = nextInfo.totalSlices;
1598
1599 // A new grain reusing the same physical ring slot starts with
1600 // zero valid slices rather than inheriting the previous grain's state.
1601 auto reusedInfo = mxlGrainInfo{};
1602 auto reusedBuffer = static_cast<std::uint8_t*>(nullptr);
1603
1604 REQUIRE(mxlFlowWriterOpenGrain(writer, reusedSlotIndex, &reusedInfo, &reusedBuffer) == MXL_STATUS_OK);
1605 REQUIRE(reusedInfo.index == reusedSlotIndex);
1606 REQUIRE(reusedBuffer == buffer);
1607 REQUIRE(reusedInfo.validSlices == 0);
1608
1611}
1612
1613TEST_CASE_PERSISTENT_FIXTURE(mxl::tests::mxlDomainFixture, "Video Flow : Reopen an incomplete grain after a jump of a full ring", "[mxl flows]")
1614{
1615 auto const opts = "{}";
1616 auto flowDef = mxl::tests::readFile("data/v210_flow.json");
1617
1618 auto instance = mxlCreateInstance(domain.string().c_str(), opts);
1619 REQUIRE(instance != nullptr);
1620
1621 auto writer = mxlFlowWriter{};
1623 auto flowWasCreated = false;
1626
1627 auto const grainCount = static_cast<std::uint64_t>(configInfo.discrete.grainCount);
1628
1629 auto gInfo = mxlGrainInfo{};
1630 auto buffer = static_cast<std::uint8_t*>(nullptr);
1631
1632 auto lastCompleteIndex = std::uint64_t{100};
1633 REQUIRE(mxlFlowWriterOpenGrain(writer, lastCompleteIndex, &gInfo, &buffer) == MXL_STATUS_OK);
1634 gInfo.validSlices = gInfo.totalSlices;
1636
1637 // When grainCount or more grains are skipped, the ring buffer entry of the first skipped grain is the entry of the grain being written.
1638 for (auto const skippedCount : {grainCount, (3U * grainCount) + 2U})
1639 {
1640 CAPTURE(skippedCount);
1641 auto const grainIndex = lastCompleteIndex + skippedCount + 1U;
1642
1644 REQUIRE(gInfo.index == grainIndex);
1645 REQUIRE(gInfo.validSlices == 0);
1646
1647 auto const partialValidSlices = std::uint16_t{3};
1648 REQUIRE(partialValidSlices < gInfo.totalSlices);
1649 gInfo.validSlices = partialValidSlices;
1651
1652 // The grain is incomplete, so the last complete grain is still the one before the jump. Reopening the grain keeps its progress.
1653 auto reopenedInfo = mxlGrainInfo{};
1654 auto reopenedBuffer = static_cast<std::uint8_t*>(nullptr);
1655 REQUIRE(mxlFlowWriterOpenGrain(writer, grainIndex, &reopenedInfo, &reopenedBuffer) == MXL_STATUS_OK);
1656 REQUIRE(reopenedInfo.index == grainIndex);
1657 REQUIRE(reopenedBuffer == buffer);
1658 REQUIRE(reopenedInfo.validSlices == partialValidSlices);
1659 REQUIRE((reopenedInfo.flags & MXL_GRAIN_FLAG_INVALID) == 0);
1660
1661 reopenedInfo.validSlices = reopenedInfo.totalSlices;
1663 lastCompleteIndex = grainIndex;
1664 }
1665
1668}
Minimal reader for the UDP datagrams in the pcap files used by the tests.
Public flow reader, writer, payload and synchronization APIs.
MXL_EXPORT mxlStatus mxlFlowWriterOpenGrain(mxlFlowWriter writer, uint64_t index, mxlGrainInfo *mxlGrainInfo, uint8_t **payload)
Definition flow.cpp:446
MXL_EXPORT mxlStatus mxlFlowReaderGetGrain(mxlFlowReader reader, uint64_t index, uint64_t timeoutNs, mxlGrainInfo *grain, uint8_t **payload)
Definition flow.cpp:362
MXL_EXPORT mxlStatus mxlReleaseFlowReader(mxlInstance instance, mxlFlowReader reader)
Definition flow.cpp:177
struct mxlFlowReader_t * mxlFlowReader
Definition flow.h:205
struct mxlGrainInfo_t mxlGrainInfo
MXL_EXPORT mxlStatus mxlFlowReaderGetSamplesNonBlocking(mxlFlowReader reader, uint64_t index, size_t count, mxlWrappedMultiBufferSlice *payloadBuffersSlices)
Definition flow.cpp:558
MXL_EXPORT mxlStatus mxlFlowWriterCommitSamples(mxlFlowWriter writer)
Definition flow.cpp:646
MXL_EXPORT mxlStatus mxlFlowReaderGetGrainSlice(mxlFlowReader reader, uint64_t index, uint16_t minValidSlices, uint64_t timeoutNs, mxlGrainInfo *grain, uint8_t **payload)
Definition flow.cpp:369
struct mxlWrappedMultiBufferSlice_t mxlWrappedMultiBufferSlice
MXL_EXPORT mxlStatus mxlFlowReaderGetSamples(mxlFlowReader reader, uint64_t index, size_t count, uint64_t timeoutNs, mxlWrappedMultiBufferSlice *payloadBuffersSlices)
Definition flow.cpp:534
#define MXL_GRAIN_FLAG_INVALID
Definition flow.h:33
struct mxlFlowWriter_t * mxlFlowWriter
Definition flow.h:206
struct mxlMutableWrappedMultiBufferSlice_t mxlMutableWrappedMultiBufferSlice
MXL_EXPORT mxlStatus mxlReleaseFlowWriter(mxlInstance instance, mxlFlowWriter writer)
Definition flow.cpp:262
MXL_EXPORT mxlStatus mxlFlowReaderGetRuntimeInfo(mxlFlowReader reader, mxlFlowRuntimeInfo *info)
Definition flow.cpp:339
MXL_EXPORT mxlStatus mxlFlowReaderGetInfo(mxlFlowReader reader, mxlFlowInfo *info)
Definition flow.cpp:293
MXL_EXPORT mxlStatus mxlCreateFlowWriter(mxlInstance instance, char const *flowDef, char const *options, mxlFlowWriter *writer, mxlFlowConfigInfo *configInfo, bool *created)
Definition flow.cpp:198
MXL_EXPORT mxlStatus mxlCreateFlowReader(mxlInstance instance, char const *flowId, char const *options, mxlFlowReader *reader)
Definition flow.cpp:136
MXL_EXPORT mxlStatus mxlFlowWriterOpenSamples(mxlFlowWriter writer, uint64_t index, size_t count, mxlMutableWrappedMultiBufferSlice *payloadBuffersSlices)
Definition flow.cpp:605
MXL_EXPORT mxlStatus mxlFlowWriterCommitGrain(mxlFlowWriter writer, mxlGrainInfo const *grain)
Definition flow.cpp:487
MXL_EXPORT mxlStatus mxlIsFlowActive(mxlInstance instance, char const *flowId, bool *isActive)
Definition flow.cpp:28
MXL_EXPORT mxlStatus mxlGetFlowDef(mxlInstance instance, char const *flowId, char *buffer, size_t *bufferSize)
Definition flow.cpp:86
struct mxlFlowRuntimeInfo_t mxlFlowRuntimeInfo
struct mxlFlowConfigInfo_t mxlFlowConfigInfo
struct mxlFlowInfo_t mxlFlowInfo
@ MXL_ERR_FLOW_INVALID
Definition mxl.h:41
@ MXL_ERR_INVALID_STATE
Definition mxl.h:47
@ MXL_ERR_UNKNOWN
Definition mxl.h:27
@ MXL_ERR_PERMISSION_DENIED
Definition mxl.h:37
@ MXL_ERR_OUT_OF_RANGE_TOO_EARLY
Definition mxl.h:31
@ MXL_ERR_FLOW_NOT_FOUND
Definition mxl.h:29
@ MXL_ERR_INVALID_ARG
Definition mxl.h:35
@ MXL_STATUS_OK
Definition mxl.h:23
MXL_EXPORT mxlInstance mxlCreateInstance(char const *in_mxlDomain, char const *in_options)
Definition mxl.cpp:45
std::filesystem::path makeFlowDescriptorFilePath(std::filesystem::path const &flowDirectory)
Definition PathUtils.cpp:23
std::filesystem::path makeFlowDirectoryName(std::filesystem::path const &domain, std::string const &uuid)
Definition PathUtils.cpp:11
std::uint32_t getV210LineLength(std::size_t width)
Definition MediaUtils.cpp:8
std::string readFile(std::filesystem::path const &filepath)
Definition Utils.hpp:78
std::vector< UdpDatagram > readUdpDatagrams(std::filesystem::path const &path)
#define MXL_UNDEFINED_INDEX
Definition rational.h:17
struct mxlRational_t mxlRational
std::uint64_t index
size_t size
Definition flow.h:55
void const * pointer
Definition flow.h:53
uint32_t maxCommitBatchSizeHint
Definition flowinfo.h:74
mxlCommonFlowConfigInfo common
Definition flowinfo.h:178
mxlFlowRuntimeInfo runtime
Definition flowinfo.h:229
mxlFlowConfigInfo config
Definition flowinfo.h:227
uint64_t lastWriteTime
Definition flowinfo.h:202
uint64_t lastReadTime
Definition flowinfo.h:205
uint32_t flags
Grain flags.
Definition flow.h:141
uint32_t grainSize
Size in bytes of the complete payload of a grain.
Definition flow.h:143
uint16_t totalSlices
Definition flow.h:146
uint16_t validSlices
Definition flow.h:149
mxlMutableBufferSlice fragments[2]
Definition flow.h:87
mxlMutableWrappedBufferSlice base
Definition flow.h:117
mxlBufferSlice fragments[2]
Definition flow.h:77
mxlWrappedBufferSlice base
Definition flow.h:97
bool active
constexpr auto w
uint8_t * buffer
Set a mark at the beginning and the end of the grain payload.
mxlFlowRuntimeInfo runtimeInfo2
Get the updated flow info.
bool flowWasCreated
mxlFlowConfigInfo configInfo
std::vector< BatchIndexAndSize > planAudioBatches(std::size_t numOfBatches, std::size_t numOfSamples, std::uint64_t lastBatchIndex)
TEST_CASE_PERSISTENT_FIXTURE(mxl::tests::mxlDomainFixture, "Video Flow : Create/Destroy", "[mxl flows]")
mxlFlowReader reader
mxlFlowWriter writer
mxlFlowRuntimeInfo runtimeInfo1
Get some info about the freshly created flow. Since no grains have been commited, the head should sti...
auto keyPayloadStrideSize
auto const flowId
constexpr auto h
uint64_t index
auto const rate
Compute the grain index for the flow rate and current TAI time.
auto const now
auto fillPayloadStrideSize
auto flowDef
auto instanceReader
auto keyPayloadSize
auto instanceWriter
mxlGrainInfo gInfo
Open the grain.
mxlDestroyInstance(instanceReader)
auto fillPayloadSize
REQUIRE(timeDelta< 33 '366 '667LL)
MXL_EXPORT uint64_t mxlTimestampToIndex(mxlRational const *editRate, uint64_t timestamp)
Definition time.cpp:31
MXL_EXPORT uint64_t mxlGetCurrentIndex(mxlRational const *editRate)
Definition time.cpp:18
MXL_EXPORT uint64_t mxlGetTime(void)
Definition time.cpp:11