MXL : Media eXchange Layer
MXL
Loading...
Searching...
No Matches
test_flows.cpp File Reference
#include <chrono>
#include <cstdint>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <filesystem>
#include <fstream>
#include <memory>
#include <string>
#include <thread>
#include <utility>
#include <uuid.h>
#include <catch2/catch_test_macros.hpp>
#include <picojson/wrapper.h>
#include <mxl/flow.h>
#include <mxl/mxl.h>
#include <mxl/time.h>
#include "../internal/include/mxl-internal/MediaUtils.hpp"
#include "PcapReader.hpp"
#include "Utils.hpp"
Include dependency graph for test_flows.cpp:

Go to the source code of this file.

Classes

struct  BatchIndexAndSize

Functions

 mxlDestroyInstance (instanceReader)
 mxlDestroyInstance (instanceWriter)
std::vector< BatchIndexAndSize > planAudioBatches (std::size_t numOfBatches, std::size_t numOfSamples, std::uint64_t lastBatchIndex)
 REQUIRE (active==true)
 REQUIRE (buffer[0]==0xCA)
 Confirm that the marks are still present.
 REQUIRE (buffer[gInfo.grainSize - 1]==0xFE)
 REQUIRE (configInfo.common.grainRate.numerator==48000U)
 REQUIRE (configInfo.continuous.bufferLength > 128U)
 REQUIRE (configInfo.continuous.channelCount==2U)
 REQUIRE (configInfo.discrete.sliceSizes[0]==fillPayloadStrideSize)
 REQUIRE (configInfo.discrete.sliceSizes[1]==keyPayloadStrideSize)
 REQUIRE (configInfo.discrete.sliceSizes[2]==0)
 REQUIRE (configInfo.discrete.sliceSizes[3]==0)
 REQUIRE (flowWasCreated)
 REQUIRE (gInfo.flags==MXL_GRAIN_FLAG_INVALID)
 Confirm that the flags are preserved.
 REQUIRE (index !=MXL_UNDEFINED_INDEX)
 REQUIRE (instanceReader !=nullptr)
 REQUIRE (instanceWriter !=nullptr)
 REQUIRE (mxlCreateFlowReader(instanceReader, flowId, "", &reader)==MXL_STATUS_OK)
 REQUIRE (mxlCreateFlowWriter(instanceWriter, flowDef.c_str(), "", &writer, &configInfo, &flowWasCreated)==MXL_STATUS_OK)
 REQUIRE (mxlCreateFlowWriter(instanceWriter, flowDef.c_str(), opts, &writer, &configInfo, &flowWasCreated)==MXL_STATUS_OK)
 REQUIRE (mxlFlowReaderGetGrain(reader, index, 16, &gInfo, &buffer)==MXL_STATUS_OK)
 Read back the grain using a flow reader.
 REQUIRE (mxlFlowReaderGetRuntimeInfo(reader, &runtimeInfo1)==MXL_STATUS_OK)
 REQUIRE (mxlFlowReaderGetRuntimeInfo(reader, &runtimeInfo2)==MXL_STATUS_OK)
 REQUIRE (mxlFlowReaderGetSamplesNonBlocking(reader, index, 64U, &payloadBuffersSlices)==MXL_ERR_FLOW_INVALID)
 REQUIRE (mxlFlowWriterCommitGrain(writer, &gInfo)==MXL_STATUS_OK)
 REQUIRE (mxlFlowWriterOpenGrain(writer, index, &gInfo, &buffer)==MXL_STATUS_OK)
 Open the grain for writing.
 REQUIRE (mxlFlowWriterOpenGrain(writer,++index, &gInfo, &buffer)==MXL_STATUS_OK)
 REQUIRE (mxlIsFlowActive(instanceReader, flowId, &active)==MXL_STATUS_OK)
 REQUIRE (mxlReleaseFlowReader(instanceReader, reader)==MXL_STATUS_OK)
 Release the reader.
 REQUIRE (mxlReleaseFlowWriter(instanceWriter, writer)==MXL_STATUS_OK)
 REQUIRE (runtimeInfo1.headIndex==0)
 REQUIRE (runtimeInfo2.headIndex==index)
 Confirm that that head has moved.
 REQUIRE (runtimeInfo2.lastReadTime > runtimeInfo1.lastReadTime)
 TEST_CASE_PERSISTENT_FIXTURE (mxl::tests::mxlDomainFixture, "Audio Flow : Create/Destroy", "[mxl flows]")
 TEST_CASE_PERSISTENT_FIXTURE (mxl::tests::mxlDomainFixture, "Audio Flow : Different writer / reader batch size", "[mxl flows]")
 TEST_CASE_PERSISTENT_FIXTURE (mxl::tests::mxlDomainFixture, "Audio Flow : Jump forward", "[mxl flows]")
 TEST_CASE_PERSISTENT_FIXTURE (mxl::tests::mxlDomainFixture, "Audio Flow : Options", "[mxl flows]")
 TEST_CASE_PERSISTENT_FIXTURE (mxl::tests::mxlDomainFixture, "Data Flow : Create/Destroy", "[mxl flows]")
 TEST_CASE_PERSISTENT_FIXTURE (mxl::tests::mxlDomainFixture, "Flow definitions and options with numbers that do not fit", "[mxl flows]")
 TEST_CASE_PERSISTENT_FIXTURE (mxl::tests::mxlDomainFixture, "Flow definitions with a non-positive rate", "[mxl flows]")
 TEST_CASE_PERSISTENT_FIXTURE (mxl::tests::mxlDomainFixture, "Invalid flow definitions", "[mxl flows]")
 TEST_CASE_PERSISTENT_FIXTURE (mxl::tests::mxlDomainFixture, "mxlCreateFlow: unwritable domain", "[mxl flows]")
 TEST_CASE_PERSISTENT_FIXTURE (mxl::tests::mxlDomainFixture, "mxlCreateFlowReader: unreadable continuous flow descriptor", "[mxl flows]")
 TEST_CASE_PERSISTENT_FIXTURE (mxl::tests::mxlDomainFixture, "mxlCreateFlowReader: unreadable flow directory", "[mxl flows]")
 TEST_CASE_PERSISTENT_FIXTURE (mxl::tests::mxlDomainFixture, "mxlFlowWriterCommitSamples should notify the reader", "[mxl flows][futex]")
 TEST_CASE_PERSISTENT_FIXTURE (mxl::tests::mxlDomainFixture, "mxlGetFlowDef", "[mxl flows]")
 TEST_CASE_PERSISTENT_FIXTURE (mxl::tests::mxlDomainFixture, "Video Flow : commit rejects an inconsistent grain header", "[mxl flows]")
 TEST_CASE_PERSISTENT_FIXTURE (mxl::tests::mxlDomainFixture, "Video Flow : Create/Destroy", "[mxl flows]")
 TEST_CASE_PERSISTENT_FIXTURE (mxl::tests::mxlDomainFixture, "Video Flow : Jump forward", "[mxl flows]")
 TEST_CASE_PERSISTENT_FIXTURE (mxl::tests::mxlDomainFixture, "Video Flow : Options", "[mxl flows]")
 TEST_CASE_PERSISTENT_FIXTURE (mxl::tests::mxlDomainFixture, "Video Flow : reader rejects an inconsistent grain header", "[mxl flows]")
 TEST_CASE_PERSISTENT_FIXTURE (mxl::tests::mxlDomainFixture, "Video Flow : Reopen an incomplete grain after a jump of a full ring", "[mxl flows]")
 TEST_CASE_PERSISTENT_FIXTURE (mxl::tests::mxlDomainFixture, "Video Flow : Slices", "[mxl flows]")
 TEST_CASE_PERSISTENT_FIXTURE (mxl::tests::mxlDomainFixture, "Video Flow : validSlices on grain open", "[mxl flows]")

Variables

bool active = false
uint8_t * buffer = nullptr
 Set a mark at the beginning and the end of the grain payload.
mxlFlowConfigInfo configInfo
auto fillPayloadSize = fillPayloadStrideSize * h
auto fillPayloadStrideSize = mxl::lib::getV210LineLength(w)
gInfo flags = MXL_GRAIN_FLAG_INVALID
 Mark the grain as invalid.
auto flowDef = mxl::tests::readFile("data/v210a_flow.json")
auto const flowId = "5fbec3b1-1b0f-417d-9059-8b94a47197ed"
bool flowWasCreated = false
mxlGrainInfo gInfo
 Open the grain.
constexpr auto h = 1080
uint64_t index = mxlTimestampToIndex(&rate, now)
auto instanceReader = mxlCreateInstance(domain.string().c_str(), opts)
auto instanceWriter = mxlCreateInstance(domain.string().c_str(), opts)
auto keyPayloadSize = keyPayloadStrideSize * h
auto keyPayloadStrideSize = static_cast<std::size_t>((w + 2) / 3 * 4)
auto const now = mxlGetTime()
auto const rate = mxlRational{60000, 1001}
 Compute the grain index for the flow rate and current TAI time.
mxlFlowReader reader
mxlFlowRuntimeInfo runtimeInfo1
 Get some info about the freshly created flow. Since no grains have been commited, the head should still be at 0.
mxlFlowRuntimeInfo runtimeInfo2
 Get the updated flow info.
constexpr auto w = 1920
mxlFlowWriter writer

Function Documentation

◆ mxlDestroyInstance() [1/2]

mxlDestroyInstance ( instanceReader )

◆ mxlDestroyInstance() [2/2]

mxlDestroyInstance ( instanceWriter )

◆ planAudioBatches()

std::vector< BatchIndexAndSize > planAudioBatches ( std::size_t numOfBatches,
std::size_t numOfSamples,
std::uint64_t lastBatchIndex )

Prepares reading or writing batches in a way that the given numOfSamples are split into numOfBatches batches, which can be read or written. The batch with the lowest index (containing the "oldest" data) is the first one.

Definition at line 879 of file test_flows.cpp.

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}
std::uint64_t index

◆ REQUIRE() [1/31]

REQUIRE ( active = =true)

◆ REQUIRE() [2/31]

REQUIRE ( buffer [0] = =0xCA)

Confirm that the marks are still present.

◆ REQUIRE() [3/31]

REQUIRE ( buffer [gInfo.grainSize - 1] = =0xFE)

◆ REQUIRE() [4/31]

REQUIRE ( configInfo.common.grainRate. numerator = =48000U)

◆ REQUIRE() [5/31]

REQUIRE ( configInfo.continuous. bufferLength,
128U  )

◆ REQUIRE() [6/31]

REQUIRE ( configInfo.continuous. channelCount = =2U)

◆ REQUIRE() [7/31]

REQUIRE ( configInfo.discrete. sliceSizes[0] = =fillPayloadStrideSize)

◆ REQUIRE() [8/31]

REQUIRE ( configInfo.discrete. sliceSizes[1] = =keyPayloadStrideSize)

◆ REQUIRE() [9/31]

REQUIRE ( configInfo.discrete. sliceSizes[2] = =0)

◆ REQUIRE() [10/31]

REQUIRE ( configInfo.discrete. sliceSizes[3] = =0)

◆ REQUIRE() [11/31]

REQUIRE ( flowWasCreated )

◆ REQUIRE() [12/31]

REQUIRE ( gInfo. grainSize = =(fillPayloadSize+keyPayloadSize))

Confirm that the flags are preserved.

◆ REQUIRE() [13/31]

REQUIRE ( index ! = MXL_UNDEFINED_INDEX)

◆ REQUIRE() [14/31]

REQUIRE ( instanceReader ! = nullptr)

◆ REQUIRE() [15/31]

REQUIRE ( instanceWriter ! = nullptr)

◆ REQUIRE() [16/31]

◆ REQUIRE() [17/31]

◆ REQUIRE() [18/31]

REQUIRE ( mxlCreateFlowWriter(instanceWriter, flowDef.c_str(), opts, &writer, &configInfo, &flowWasCreated) = =MXL_STATUS_OK)

◆ REQUIRE() [19/31]

Read back the grain using a flow reader.

◆ REQUIRE() [20/31]

◆ REQUIRE() [21/31]

◆ REQUIRE() [22/31]

REQUIRE ( mxlFlowReaderGetSamplesNonBlocking(reader, index, 64U, &payloadBuffersSlices) = =MXL_ERR_FLOW_INVALID)

◆ REQUIRE() [23/31]

◆ REQUIRE() [24/31]

Open the grain for writing.

◆ REQUIRE() [25/31]

◆ REQUIRE() [26/31]

◆ REQUIRE() [27/31]

Release the reader.

◆ REQUIRE() [28/31]

◆ REQUIRE() [29/31]

REQUIRE ( runtimeInfo1. headIndex = =0)

◆ REQUIRE() [30/31]

REQUIRE ( runtimeInfo2. headIndex = =index)

Confirm that that head has moved.

◆ REQUIRE() [31/31]

REQUIRE ( runtimeInfo2. lastReadTime,
runtimeInfo1. lastReadTime )

◆ TEST_CASE_PERSISTENT_FIXTURE() [1/21]

TEST_CASE_PERSISTENT_FIXTURE ( mxl::tests::mxlDomainFixture ,
"Audio Flow : Create/Destroy" ,
"" [mxl flows] )

Compute the grain index for the flow rate and current TAI time.

Open a range of samples for writing

Get some info about the freshly created flow. Since no grains have been commited, the head should still be at 0.

Commit the sample range

Open a range of samples for reading

Release the reader

Definition at line 701 of file test_flows.cpp.

701 : 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
713 mxlFlowWriter writer;
714 {
715 mxlFlowConfigInfo configInfo;
716 bool flowWasCreated = false;
717 REQUIRE(mxlCreateFlowWriter(instanceWriter, flowDef.c_str(), opts, &writer, &configInfo, &flowWasCreated) == MXL_STATUS_OK);
718 REQUIRE(flowWasCreated);
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
726 mxlFlowReader reader;
727 REQUIRE(mxlCreateFlowReader(instanceReader, flowId, "", &reader) == MXL_STATUS_OK);
728
730 auto const rate = mxlRational{48000, 1};
731 auto const now = mxlGetTime();
732 auto const index = mxlTimestampToIndex(&rate, now);
733 REQUIRE(index != MXL_UNDEFINED_INDEX);
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;
756 REQUIRE(mxlFlowReaderGetRuntimeInfo(reader, &runtimeInfo) == MXL_STATUS_OK);
757
758 // Verify that the headindex is yet to be modified
759 REQUIRE(runtimeInfo.headIndex == 0);
760
762 REQUIRE(mxlFlowWriterCommitSamples(writer) == MXL_STATUS_OK);
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;
786 REQUIRE(mxlFlowReaderGetRuntimeInfo(reader, &runtimeInfo) == MXL_STATUS_OK);
787
788 // Confirm that that head has moved.
789 REQUIRE(runtimeInfo.headIndex == index);
790 }
791
793 REQUIRE(mxlReleaseFlowReader(instanceReader, reader) == MXL_STATUS_OK);
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
805 REQUIRE(mxlReleaseFlowWriter(instanceWriter, writer) == MXL_STATUS_OK);
806
807 mxlDestroyInstance(instanceReader);
808 mxlDestroyInstance(instanceWriter);
809}

◆ TEST_CASE_PERSISTENT_FIXTURE() [2/21]

TEST_CASE_PERSISTENT_FIXTURE ( mxl::tests::mxlDomainFixture ,
"Audio Flow : Different writer / reader batch size" ,
"" [mxl flows] )

Definition at line 898 of file test_flows.cpp.

898 : 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");
905 mxlFlowWriter writer;
906 mxlFlowConfigInfo configInfo;
907 bool flowWasCreated = false;
908 REQUIRE(mxlCreateFlowWriter(instance, flowDef.c_str(), opts, &writer, &configInfo, &flowWasCreated) == MXL_STATUS_OK);
909 REQUIRE(flowWasCreated);
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);
934 REQUIRE(mxlFlowWriterCommitSamples(writer) == MXL_STATUS_OK);
935 }
936
937 mxlFlowReader reader;
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);
963 REQUIRE(mxlReleaseFlowReader(instance, reader) == MXL_STATUS_OK);
964 REQUIRE(mxlReleaseFlowWriter(instance, writer) == MXL_STATUS_OK);
965
966 REQUIRE(mxlDestroyInstance(instance) == MXL_STATUS_OK);
967}
std::size_t size() const noexcept
Returns the total number of writers that are registered in the DomainWatcher.
mxlFlowReader reader
mxlFlowWriter writer

◆ TEST_CASE_PERSISTENT_FIXTURE() [3/21]

TEST_CASE_PERSISTENT_FIXTURE ( mxl::tests::mxlDomainFixture ,
"Audio Flow : Jump forward" ,
"" [mxl flows] )

Definition at line 1193 of file test_flows.cpp.

1193 : 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");
1205 mxlFlowWriter writer;
1206 mxlFlowConfigInfo configInfo;
1207 bool flowWasCreated = false;
1208 REQUIRE(mxlCreateFlowWriter(instanceWriter, flowDef.c_str(), opts, &writer, &configInfo, &flowWasCreated) == MXL_STATUS_OK);
1209 REQUIRE(flowWasCreated);
1210
1211 mxlFlowReader reader;
1212 auto const flowId = uuids::to_string(configInfo.common.id);
1213 REQUIRE(mxlCreateFlowReader(instanceReader, flowId.c_str(), "", &reader) == MXL_STATUS_OK);
1214
1215 mxlMutableWrappedMultiBufferSlice writeSlices{};
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 }
1236 REQUIRE(mxlFlowWriterCommitSamples(writer) == MXL_STATUS_OK);
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 {
1253 REQUIRE(returnCode == MXL_ERR_OUT_OF_RANGE_TOO_EARLY);
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 }
1280 REQUIRE(mxlFlowWriterCommitSamples(writer) == MXL_STATUS_OK);
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
1299 REQUIRE(mxlReleaseFlowReader(instanceReader, reader) == MXL_STATUS_OK);
1300 REQUIRE(mxlReleaseFlowWriter(instanceWriter, writer) == MXL_STATUS_OK);
1301 REQUIRE(mxlDestroyInstance(instanceReader) == MXL_STATUS_OK);
1302 REQUIRE(mxlDestroyInstance(instanceWriter) == MXL_STATUS_OK);
1303}

◆ TEST_CASE_PERSISTENT_FIXTURE() [4/21]

TEST_CASE_PERSISTENT_FIXTURE ( mxl::tests::mxlDomainFixture ,
"Audio Flow : Options" ,
"" [mxl flows] )

Definition at line 969 of file test_flows.cpp.

969 : 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
977 mxlFlowWriter writer;
978 mxlFlowConfigInfo configInfo;
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;
1002 REQUIRE(mxlCreateFlowWriter(instanceWriter, flowDef.c_str(), optsStr.c_str(), &writer, &configInfo, &flowWasCreated) == MXL_STATUS_OK);
1003 REQUIRE(flowWasCreated);
1004 REQUIRE(configInfo.common.maxCommitBatchSizeHint == 5U);
1005 REQUIRE(configInfo.common.maxSyncBatchSizeHint == 10U);
1006 REQUIRE(mxlReleaseFlowWriter(instanceWriter, writer) == MXL_STATUS_OK);
1007
1008 flowWasCreated = false;
1009 REQUIRE(mxlCreateFlowWriter(instanceWriter, flowDef.c_str(), nullptr, &writer, &configInfo, &flowWasCreated) == MXL_STATUS_OK);
1010 REQUIRE(flowWasCreated);
1011 REQUIRE(configInfo.common.maxCommitBatchSizeHint == 480U);
1012 REQUIRE(configInfo.common.maxSyncBatchSizeHint == 480U);
1013 REQUIRE(mxlReleaseFlowWriter(instanceWriter, writer) == MXL_STATUS_OK);
1014 REQUIRE(mxlDestroyInstance(instanceWriter) == MXL_STATUS_OK);
1015}

◆ TEST_CASE_PERSISTENT_FIXTURE() [5/21]

TEST_CASE_PERSISTENT_FIXTURE ( mxl::tests::mxlDomainFixture ,
"Data Flow : Create/Destroy" ,
"" [mxl flows] )

Compute the grain index for the flow rate and current TAI time.

Open the grain.

Open the grain for writing.

ANC Grains are always 4KiB

Get some info about the freshly created flow. Since no grains have been commited, the head should still be at 0.

Mark the grain as invalid

Read back the grain using a flow reader.

Confirm that the flags are preserved.

Confirm that our original RFC-8331 packet is still there

Get the updated flow info

Confirm that that head has moved.

Delete the reader

Definition at line 468 of file test_flows.cpp.

468 : 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
493 mxlFlowWriter writer;
494 mxlFlowConfigInfo configInfo;
495 bool flowWasCreated = false;
496 REQUIRE(mxlCreateFlowWriter(instanceWriter, flowDef.c_str(), "", &writer, &configInfo, &flowWasCreated) == MXL_STATUS_OK);
497 REQUIRE(flowWasCreated);
498
499 mxlFlowReader reader;
500 REQUIRE(mxlCreateFlowReader(instanceReader, flowId, "", &reader) == MXL_STATUS_OK);
501
503 auto const rate = mxlRational{60000, 1001};
504 auto const now = mxlGetTime();
505 uint64_t index = mxlTimestampToIndex(&rate, now);
506 REQUIRE(index != MXL_UNDEFINED_INDEX);
507
509 mxlGrainInfo gInfo;
510 uint8_t* buffer = nullptr;
512 REQUIRE(mxlFlowWriterOpenGrain(writer, index, &gInfo, &buffer) == MXL_STATUS_OK);
513
515 REQUIRE(gInfo.grainSize == 4096);
516
517 // Copy the RFC-8331 packet in the grain
518 memcpy(buffer, rtpData, rtpSize);
519
521 mxlFlowRuntimeInfo runtimeInfo1;
522 REQUIRE(mxlFlowReaderGetRuntimeInfo(reader, &runtimeInfo1) == MXL_STATUS_OK);
523 REQUIRE(runtimeInfo1.headIndex == 0);
524
526 gInfo.flags |= MXL_GRAIN_FLAG_INVALID;
527 REQUIRE(mxlFlowWriterCommitGrain(writer, &gInfo) == MXL_STATUS_OK);
528
530 REQUIRE(mxlFlowReaderGetGrain(reader, index, 16, &gInfo, &buffer) == MXL_STATUS_OK);
531
533 REQUIRE(gInfo.flags == MXL_GRAIN_FLAG_INVALID);
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
542 mxlFlowRuntimeInfo runtimeInfo2;
543 REQUIRE(mxlFlowReaderGetRuntimeInfo(reader, &runtimeInfo2) == MXL_STATUS_OK);
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
555 REQUIRE(mxlReleaseFlowReader(instanceReader, reader) == MXL_STATUS_OK);
556
557 // Use the writer after closing the reader.
558 uint8_t* buffer2 = nullptr;
559 REQUIRE(mxlFlowWriterOpenGrain(writer, ++index, &gInfo, &buffer2) == MXL_STATUS_OK);
560
561 REQUIRE(mxlReleaseFlowWriter(instanceWriter, writer) == MXL_STATUS_OK);
562
563 mxlDestroyInstance(instanceReader);
564 mxlDestroyInstance(instanceWriter);
565}

◆ TEST_CASE_PERSISTENT_FIXTURE() [6/21]

TEST_CASE_PERSISTENT_FIXTURE ( mxl::tests::mxlDomainFixture ,
"Flow definitions and options with numbers that do not fit" ,
"" [mxl flows] )

Definition at line 289 of file test_flows.cpp.

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}
struct mxlFlowWriter_t * mxlFlowWriter
Definition flow.h:206
MXL_EXPORT mxlStatus mxlReleaseFlowWriter(mxlInstance instance, mxlFlowWriter writer)
Definition flow.cpp:262
MXL_EXPORT mxlStatus mxlCreateFlowWriter(mxlInstance instance, char const *flowDef, char const *options, mxlFlowWriter *writer, mxlFlowConfigInfo *configInfo, bool *created)
Definition flow.cpp:198
struct mxlFlowConfigInfo_t mxlFlowConfigInfo
@ MXL_STATUS_OK
Definition mxl.h:23
MXL_EXPORT mxlInstance mxlCreateInstance(char const *in_mxlDomain, char const *in_options)
Definition mxl.cpp:45
std::string readFile(std::filesystem::path const &filepath)
Definition Utils.hpp:78
mxlFlowConfigInfo configInfo
auto flowDef
mxlDestroyInstance(instanceReader)
REQUIRE(timeDelta< 33 '366 '667LL)

◆ TEST_CASE_PERSISTENT_FIXTURE() [7/21]

TEST_CASE_PERSISTENT_FIXTURE ( mxl::tests::mxlDomainFixture ,
"Flow definitions with a non-positive rate" ,
"" [mxl flows] )

Definition at line 1377 of file test_flows.cpp.

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}
auto const rate
Compute the grain index for the flow rate and current TAI time.

◆ TEST_CASE_PERSISTENT_FIXTURE() [8/21]

TEST_CASE_PERSISTENT_FIXTURE ( mxl::tests::mxlDomainFixture ,
"Invalid flow definitions" ,
"" [mxl flows] )

Definition at line 364 of file test_flows.cpp.

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}
bool flowWasCreated

◆ TEST_CASE_PERSISTENT_FIXTURE() [9/21]

TEST_CASE_PERSISTENT_FIXTURE ( mxl::tests::mxlDomainFixture ,
"mxlCreateFlow: unwritable domain" ,
"" [mxl flows] )

Definition at line 1064 of file test_flows.cpp.

1064 : 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");
1074 mxlFlowWriter writer;
1075 mxlFlowConfigInfo configInfo;
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}

◆ TEST_CASE_PERSISTENT_FIXTURE() [10/21]

TEST_CASE_PERSISTENT_FIXTURE ( mxl::tests::mxlDomainFixture ,
"mxlCreateFlowReader: unreadable continuous flow descriptor" ,
"" [mxl flows] )

Definition at line 1114 of file test_flows.cpp.

1114 : 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;
1124 auto configInfo = mxlFlowConfigInfo{};
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);
1133 REQUIRE(status == MXL_ERR_PERMISSION_DENIED);
1134
1135 REQUIRE(mxlReleaseFlowWriter(instance, writer) == MXL_STATUS_OK);
1136 REQUIRE(mxlDestroyInstance(readerInstance) == MXL_STATUS_OK);
1137 REQUIRE(mxlDestroyInstance(instance) == MXL_STATUS_OK);
1138}

◆ TEST_CASE_PERSISTENT_FIXTURE() [11/21]

TEST_CASE_PERSISTENT_FIXTURE ( mxl::tests::mxlDomainFixture ,
"mxlCreateFlowReader: unreadable flow directory" ,
"" [mxl flows] )

Definition at line 1085 of file test_flows.cpp.

1085 : 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;
1095 auto configInfo = mxlFlowConfigInfo{};
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);
1105 REQUIRE(status == MXL_ERR_PERMISSION_DENIED);
1106
1107 REQUIRE(mxlReleaseFlowWriter(instance, writer) == MXL_STATUS_OK);
1108 REQUIRE(mxlDestroyInstance(readerInstance) == MXL_STATUS_OK);
1109 REQUIRE(mxlDestroyInstance(instance) == MXL_STATUS_OK);
1110}

◆ TEST_CASE_PERSISTENT_FIXTURE() [12/21]

TEST_CASE_PERSISTENT_FIXTURE ( mxl::tests::mxlDomainFixture ,
"mxlFlowWriterCommitSamples should notify the reader" ,
"" [mxl flows][futex] )

Definition at line 1140 of file test_flows.cpp.

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}
MXL_EXPORT mxlStatus mxlReleaseFlowReader(mxlInstance instance, mxlFlowReader reader)
Definition flow.cpp:177
struct mxlFlowReader_t * mxlFlowReader
Definition flow.h:205
MXL_EXPORT mxlStatus mxlFlowWriterCommitSamples(mxlFlowWriter writer)
Definition flow.cpp:646
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
struct mxlMutableWrappedMultiBufferSlice_t mxlMutableWrappedMultiBufferSlice
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

◆ TEST_CASE_PERSISTENT_FIXTURE() [13/21]

TEST_CASE_PERSISTENT_FIXTURE ( mxl::tests::mxlDomainFixture ,
"mxlGetFlowDef" ,
"" [mxl flows] )

Definition at line 1017 of file test_flows.cpp.

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}
MXL_EXPORT mxlStatus mxlGetFlowDef(mxlInstance instance, char const *flowId, char *buffer, size_t *bufferSize)
Definition flow.cpp:86
@ MXL_ERR_FLOW_NOT_FOUND
Definition mxl.h:29
@ MXL_ERR_INVALID_ARG
Definition mxl.h:35
auto const flowId

◆ TEST_CASE_PERSISTENT_FIXTURE() [14/21]

TEST_CASE_PERSISTENT_FIXTURE ( mxl::tests::mxlDomainFixture ,
"Video Flow : commit rejects an inconsistent grain header" ,
"" [mxl flows] )

Definition at line 1423 of file test_flows.cpp.

1423 : 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{};
1433 auto configInfo = mxlFlowConfigInfo{};
1434 REQUIRE(mxlCreateFlowWriter(instance, flowDef.c_str(), opts, &writer, &configInfo, nullptr) == MXL_STATUS_OK);
1435
1436 auto reader = mxlFlowReader{};
1437 REQUIRE(mxlCreateFlowReader(instance, flowId, "", &reader) == MXL_STATUS_OK);
1438
1439 auto const index = std::uint64_t{100};
1440 auto gInfo = mxlGrainInfo{};
1441 auto buffer = static_cast<std::uint8_t*>(nullptr);
1442 REQUIRE(mxlFlowWriterOpenGrain(writer, index, &gInfo, &buffer) == MXL_STATUS_OK);
1443 auto const validInfo = gInfo;
1444
1445 // grainSize larger than the mapped payload.
1446 gInfo.grainSize = validInfo.grainSize + 1U;
1447 gInfo.validSlices = gInfo.totalSlices;
1448 REQUIRE(mxlFlowWriterCommitGrain(writer, &gInfo) == MXL_ERR_INVALID_ARG);
1449 gInfo.grainSize = UINT32_MAX;
1450 REQUIRE(mxlFlowWriterCommitGrain(writer, &gInfo) == MXL_ERR_INVALID_ARG);
1451
1452 // validSlices larger than totalSlices.
1453 gInfo = validInfo;
1454 gInfo.totalSlices = 0;
1455 gInfo.validSlices = 8;
1456 REQUIRE(mxlFlowWriterCommitGrain(writer, &gInfo) == MXL_ERR_INVALID_ARG);
1457 gInfo = validInfo;
1458 gInfo.validSlices = UINT16_MAX;
1459 REQUIRE(mxlFlowWriterCommitGrain(writer, &gInfo) == MXL_ERR_INVALID_ARG);
1460
1461 // A rejected commit publishes nothing.
1462 auto readInfo = mxlGrainInfo{};
1463 auto readBuffer = static_cast<std::uint8_t*>(nullptr);
1464 REQUIRE(mxlFlowReaderGetGrain(reader, index, 16, &readInfo, &readBuffer) == MXL_ERR_OUT_OF_RANGE_TOO_EARLY);
1465
1466 // The grain stays open and a valid header can still be committed.
1467 gInfo = validInfo;
1468 gInfo.validSlices = gInfo.totalSlices;
1469 REQUIRE(mxlFlowWriterCommitGrain(writer, &gInfo) == MXL_STATUS_OK);
1470 REQUIRE(mxlFlowReaderGetGrain(reader, index, 16, &readInfo, &readBuffer) == MXL_STATUS_OK);
1471
1472 REQUIRE(mxlReleaseFlowReader(instance, reader) == MXL_STATUS_OK);
1473 REQUIRE(mxlReleaseFlowWriter(instance, writer) == MXL_STATUS_OK);
1474 REQUIRE(mxlDestroyInstance(instance) == MXL_STATUS_OK);
1475}

◆ TEST_CASE_PERSISTENT_FIXTURE() [15/21]

TEST_CASE_PERSISTENT_FIXTURE ( mxl::tests::mxlDomainFixture ,
"Video Flow : Create/Destroy" ,
"" [mxl flows] )

Compute the grain index for the flow rate and current TAI time.

Open the grain.

Open the grain for writing.

Set a mark at the beginning and the end of the grain payload.

Get some info about the freshly created flow. Since no grains have been commited, the head should still be at 0.

Mark the grain as invalid

Read back the grain using a flow reader.

Confirm that the flags are preserved.

Confirm that the marks are still present.

Get the updated flow info

Confirm that that head has moved.

Release the reader

Set a mark at the beginning and the end of the grain payload.

Definition at line 27 of file test_flows.cpp.

27 : 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
40 mxlFlowWriter writer;
41 mxlFlowConfigInfo configInfo;
42 bool flowWasCreated = false;
43 REQUIRE(mxlCreateFlowWriter(instanceWriter, flowDef.c_str(), "", &writer, &configInfo, &flowWasCreated) == MXL_STATUS_OK);
44 REQUIRE(flowWasCreated);
45
46 mxlFlowReader reader;
47 REQUIRE(mxlCreateFlowReader(instanceReader, flowId, "", &reader) == MXL_STATUS_OK);
48
49 // The writer is now created. The flow should be active.
50 REQUIRE(mxlIsFlowActive(instanceReader, flowId, &active) == MXL_STATUS_OK);
51 REQUIRE(active == true);
52
54 auto const rate = mxlRational{60000, 1001};
55 auto const now = mxlGetTime();
56 uint64_t index = mxlTimestampToIndex(&rate, now);
57 REQUIRE(index != MXL_UNDEFINED_INDEX);
58
60 mxlGrainInfo gInfo;
61 uint8_t* buffer = nullptr;
63 REQUIRE(mxlFlowWriterOpenGrain(writer, index, &gInfo, &buffer) == MXL_STATUS_OK);
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
72 auto fillPayloadStrideSize = mxl::lib::getV210LineLength(w);
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
78 auto fillPayloadSize = fillPayloadStrideSize * h;
79 REQUIRE(gInfo.grainSize == fillPayloadSize);
80
82 buffer[0] = 0xCA;
83 buffer[gInfo.grainSize - 1] = 0xFE;
84
86 mxlFlowRuntimeInfo runtimeInfo1;
87 REQUIRE(mxlFlowReaderGetRuntimeInfo(reader, &runtimeInfo1) == MXL_STATUS_OK);
88 REQUIRE(runtimeInfo1.headIndex == 0);
89
91 gInfo.flags |= MXL_GRAIN_FLAG_INVALID;
92 REQUIRE(mxlFlowWriterCommitGrain(writer, &gInfo) == MXL_STATUS_OK);
93
95 REQUIRE(mxlFlowReaderGetGrain(reader, index, 16, &gInfo, &buffer) == MXL_STATUS_OK);
96
97 // Give some time to the inotify message to reach the directorywatcher.
98 std::this_thread::sleep_for(std::chrono::milliseconds(5));
99
101 REQUIRE(gInfo.flags == MXL_GRAIN_FLAG_INVALID);
102
104 REQUIRE(buffer[0] == 0xCA);
105 REQUIRE(buffer[gInfo.grainSize - 1] == 0xFE);
106
108 mxlFlowRuntimeInfo runtimeInfo2;
109 REQUIRE(mxlFlowReaderGetRuntimeInfo(reader, &runtimeInfo2) == MXL_STATUS_OK);
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
121 REQUIRE(mxlReleaseFlowReader(instanceReader, reader) == MXL_STATUS_OK);
122
123 // Use the writer after closing the reader.
124 buffer = nullptr;
125 REQUIRE(mxlFlowWriterOpenGrain(writer, ++index, &gInfo, &buffer) == MXL_STATUS_OK);
127 buffer[0] = 0xCA;
128 buffer[gInfo.grainSize - 1] = 0xFE;
129
130 REQUIRE(mxlReleaseFlowWriter(instanceWriter, writer) == MXL_STATUS_OK);
131
132 mxlDestroyInstance(instanceReader);
133 mxlDestroyInstance(instanceWriter);
134}

◆ TEST_CASE_PERSISTENT_FIXTURE() [16/21]

TEST_CASE_PERSISTENT_FIXTURE ( mxl::tests::mxlDomainFixture ,
"Video Flow : Jump forward" ,
"" [mxl flows] )

Definition at line 1305 of file test_flows.cpp.

1305 : 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");
1315 mxlFlowWriter writer;
1316 mxlFlowConfigInfo configInfo;
1317 bool flowWasCreated = false;
1318 REQUIRE(mxlCreateFlowWriter(instanceWriter, flowDef.c_str(), opts, &writer, &configInfo, &flowWasCreated) == MXL_STATUS_OK);
1319 REQUIRE(flowWasCreated);
1320
1321 mxlFlowReader reader;
1322 auto const flowId = uuids::to_string(configInfo.common.id);
1323 REQUIRE(mxlCreateFlowReader(instanceReader, flowId.c_str(), "", &reader) == MXL_STATUS_OK);
1324
1325 mxlGrainInfo gInfo;
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 {
1330 REQUIRE(mxlFlowWriterOpenGrain(writer, writerGrainIndex, &gInfo, &buffer) == MXL_STATUS_OK);
1331 REQUIRE(buffer != nullptr);
1332 std::memcpy(buffer, &writerGrainIndex, sizeof(std::uint64_t));
1333 gInfo.validSlices = gInfo.totalSlices;
1334 REQUIRE(mxlFlowWriterCommitGrain(writer, &gInfo) == MXL_STATUS_OK);
1335 }
1336
1337 // Jump forward to grain 100, skipping grains 47-99
1338 auto writerGrainIndex = std::uint64_t{100};
1339 REQUIRE(mxlFlowWriterOpenGrain(writer, writerGrainIndex, &gInfo, &buffer) == MXL_STATUS_OK);
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 {
1352 REQUIRE(returnCode == MXL_ERR_OUT_OF_RANGE_TOO_EARLY);
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;
1364 REQUIRE(mxlFlowWriterCommitGrain(writer, &gInfo) == MXL_STATUS_OK);
1365 REQUIRE(mxlFlowReaderGetGrain(reader, writerGrainIndex, 0, &gInfo, &buffer) == MXL_STATUS_OK);
1366 REQUIRE(reinterpret_cast<std::uint64_t*>(buffer)[0] == writerGrainIndex);
1367
1368 REQUIRE(mxlReleaseFlowReader(instanceReader, reader) == MXL_STATUS_OK);
1369 REQUIRE(mxlReleaseFlowWriter(instanceWriter, writer) == MXL_STATUS_OK);
1370 REQUIRE(mxlDestroyInstance(instanceReader) == MXL_STATUS_OK);
1371 REQUIRE(mxlDestroyInstance(instanceWriter) == MXL_STATUS_OK);
1372}

◆ TEST_CASE_PERSISTENT_FIXTURE() [17/21]

TEST_CASE_PERSISTENT_FIXTURE ( mxl::tests::mxlDomainFixture ,
"Video Flow : Options" ,
"" [mxl flows] )

Definition at line 567 of file test_flows.cpp.

567 : 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
575 mxlFlowWriter writer;
576 mxlFlowConfigInfo configInfo;
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;
600 REQUIRE(mxlCreateFlowWriter(instanceWriter, flowDef.c_str(), optsStr.c_str(), &writer, &configInfo, &flowWasCreated) == MXL_STATUS_OK);
601 REQUIRE(flowWasCreated);
602 REQUIRE(configInfo.common.maxCommitBatchSizeHint == 5U);
603 REQUIRE(configInfo.common.maxSyncBatchSizeHint == 10U);
604 REQUIRE(mxlReleaseFlowWriter(instanceWriter, writer) == MXL_STATUS_OK);
605
606 flowWasCreated = false;
607 REQUIRE(mxlCreateFlowWriter(instanceWriter, flowDef.c_str(), nullptr, &writer, &configInfo, &flowWasCreated) == MXL_STATUS_OK);
608 REQUIRE(flowWasCreated);
609 REQUIRE(configInfo.common.maxCommitBatchSizeHint == 1080U);
610 REQUIRE(configInfo.common.maxSyncBatchSizeHint == 1080U);
611 REQUIRE(mxlReleaseFlowWriter(instanceWriter, writer) == MXL_STATUS_OK);
612 REQUIRE(mxlDestroyInstance(instanceWriter) == MXL_STATUS_OK);
613}

◆ TEST_CASE_PERSISTENT_FIXTURE() [18/21]

TEST_CASE_PERSISTENT_FIXTURE ( mxl::tests::mxlDomainFixture ,
"Video Flow : reader rejects an inconsistent grain header" ,
"" [mxl flows] )

Definition at line 1477 of file test_flows.cpp.

1477 : 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{};
1487 auto configInfo = mxlFlowConfigInfo{};
1488 REQUIRE(mxlCreateFlowWriter(instance, flowDef.c_str(), opts, &writer, &configInfo, nullptr) == MXL_STATUS_OK);
1489
1490 auto reader = mxlFlowReader{};
1491 REQUIRE(mxlCreateFlowReader(instance, flowId, "", &reader) == MXL_STATUS_OK);
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);
1501 REQUIRE(mxlFlowWriterOpenGrain(writer, index, &gInfo, &buffer) == MXL_STATUS_OK);
1502 gInfo.validSlices = gInfo.totalSlices;
1503 REQUIRE(mxlFlowWriterCommitGrain(writer, &gInfo) == MXL_STATUS_OK);
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
1535 REQUIRE(mxlReleaseFlowReader(instance, reader) == MXL_STATUS_OK);
1536 REQUIRE(mxlReleaseFlowWriter(instance, writer) == MXL_STATUS_OK);
1537 REQUIRE(mxlDestroyInstance(instance) == MXL_STATUS_OK);
1538}

◆ TEST_CASE_PERSISTENT_FIXTURE() [19/21]

TEST_CASE_PERSISTENT_FIXTURE ( mxl::tests::mxlDomainFixture ,
"Video Flow : Reopen an incomplete grain after a jump of a full ring" ,
"" [mxl flows] )

Definition at line 1613 of file test_flows.cpp.

1613 : 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{};
1622 auto configInfo = mxlFlowConfigInfo{};
1623 auto flowWasCreated = false;
1624 REQUIRE(mxlCreateFlowWriter(instance, flowDef.c_str(), opts, &writer, &configInfo, &flowWasCreated) == MXL_STATUS_OK);
1625 REQUIRE(flowWasCreated);
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;
1635 REQUIRE(mxlFlowWriterCommitGrain(writer, &gInfo) == MXL_STATUS_OK);
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
1643 REQUIRE(mxlFlowWriterOpenGrain(writer, grainIndex, &gInfo, &buffer) == MXL_STATUS_OK);
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;
1650 REQUIRE(mxlFlowWriterCommitGrain(writer, &gInfo) == MXL_STATUS_OK);
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;
1662 REQUIRE(mxlFlowWriterCommitGrain(writer, &reopenedInfo) == MXL_STATUS_OK);
1663 lastCompleteIndex = grainIndex;
1664 }
1665
1666 REQUIRE(mxlReleaseFlowWriter(instance, writer) == MXL_STATUS_OK);
1667 REQUIRE(mxlDestroyInstance(instance) == MXL_STATUS_OK);
1668}

◆ TEST_CASE_PERSISTENT_FIXTURE() [20/21]

TEST_CASE_PERSISTENT_FIXTURE ( mxl::tests::mxlDomainFixture ,
"Video Flow : Slices" ,
"" [mxl flows] )

Compute the grain index for the flow rate and current TAI time.

Open the grain.

Get some info about the freshly created flow. Since no grains have been commited, the head should still be at 0.

Write a slice to the grain.

Read back the partial grain using the flow reader.

Definition at line 615 of file test_flows.cpp.

615 : 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
627 mxlFlowConfigInfo configInfo;
628 mxlFlowWriter writer;
629 bool flowWasCreated = false;
630 REQUIRE(mxlCreateFlowWriter(instanceWriter, flowDef.c_str(), opts, &writer, &configInfo, &flowWasCreated) == MXL_STATUS_OK);
631 REQUIRE(flowWasCreated);
632
633 mxlFlowReader reader;
634 REQUIRE(mxlCreateFlowReader(instanceReader, flowId, "", &reader) == MXL_STATUS_OK);
635
637 auto const rate = mxlRational{60000, 1001};
638 auto const now = mxlGetTime();
639 uint64_t index = mxlTimestampToIndex(&rate, now);
640 REQUIRE(index != MXL_UNDEFINED_INDEX);
641
643 mxlGrainInfo gInfo;
644 uint8_t* buffer = nullptr;
645 REQUIRE(mxlFlowWriterOpenGrain(writer, index, &gInfo, &buffer) == MXL_STATUS_OK);
646
648 mxlFlowInfo flowInfo1;
649 REQUIRE(mxlFlowReaderGetInfo(reader, &flowInfo1) == MXL_STATUS_OK);
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;
670 REQUIRE(mxlFlowWriterCommitGrain(writer, &gInfo) == MXL_STATUS_OK);
671
672 mxlFlowRuntimeInfo sliceRuntimeInfo;
673 REQUIRE(mxlFlowReaderGetRuntimeInfo(reader, &sliceRuntimeInfo) == MXL_STATUS_OK);
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.
691 REQUIRE(mxlFlowReaderGetRuntimeInfo(reader, &sliceRuntimeInfo) == MXL_STATUS_OK);
692 REQUIRE(sliceRuntimeInfo.lastReadTime > flowInfo1.runtime.lastReadTime);
693 }
694
695 REQUIRE(mxlReleaseFlowReader(instanceReader, reader) == MXL_STATUS_OK);
696 REQUIRE(mxlReleaseFlowWriter(instanceWriter, writer) == MXL_STATUS_OK);
697 REQUIRE(mxlDestroyInstance(instanceReader) == MXL_STATUS_OK);
698 REQUIRE(mxlDestroyInstance(instanceWriter) == MXL_STATUS_OK);
699}

◆ TEST_CASE_PERSISTENT_FIXTURE() [21/21]

TEST_CASE_PERSISTENT_FIXTURE ( mxl::tests::mxlDomainFixture ,
"Video Flow : validSlices on grain open" ,
"" [mxl flows] )

Definition at line 1540 of file test_flows.cpp.

1540 : 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{};
1549 auto configInfo = mxlFlowConfigInfo{};
1550 auto flowWasCreated = false;
1551 REQUIRE(mxlCreateFlowWriter(instance, flowDef.c_str(), opts, &writer, &configInfo, &flowWasCreated) == MXL_STATUS_OK);
1552 REQUIRE(flowWasCreated);
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.
1565 REQUIRE(mxlFlowWriterOpenGrain(writer, firstSlotIndex, &gInfo, &buffer) == MXL_STATUS_OK);
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;
1573 REQUIRE(mxlFlowWriterCommitGrain(writer, &gInfo) == MXL_STATUS_OK);
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;
1586 REQUIRE(mxlFlowWriterCommitGrain(writer, &reopenedInfo) == MXL_STATUS_OK);
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;
1597 REQUIRE(mxlFlowWriterCommitGrain(writer, &nextInfo) == MXL_STATUS_OK);
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
1609 REQUIRE(mxlReleaseFlowWriter(instance, writer) == MXL_STATUS_OK);
1610 REQUIRE(mxlDestroyInstance(instance) == MXL_STATUS_OK);
1611}

Variable Documentation

◆ active

bool active = false

Definition at line 141 of file test_flows.cpp.

◆ buffer

uint8_t * buffer = nullptr

Set a mark at the beginning and the end of the grain payload.

Definition at line 170 of file test_flows.cpp.

◆ configInfo

mxlFlowConfigInfo configInfo

Definition at line 150 of file test_flows.cpp.

◆ fillPayloadSize

auto fillPayloadSize = fillPayloadStrideSize * h

Definition at line 179 of file test_flows.cpp.

◆ fillPayloadStrideSize

auto fillPayloadStrideSize = mxl::lib::getV210LineLength(w)

Definition at line 178 of file test_flows.cpp.

◆ flags

Mark the grain as invalid.

Definition at line 200 of file test_flows.cpp.

◆ flowDef

auto const flowDef = mxl::tests::readFile("data/v210a_flow.json")

Definition at line 140 of file test_flows.cpp.

◆ flowId

auto const flowId = "5fbec3b1-1b0f-417d-9059-8b94a47197ed"

Definition at line 139 of file test_flows.cpp.

◆ flowWasCreated

bool flowWasCreated = false

Definition at line 151 of file test_flows.cpp.

◆ gInfo

mxlGrainInfo gInfo

Open the grain.

Definition at line 169 of file test_flows.cpp.

◆ h

auto h = 1080
constexpr

Definition at line 176 of file test_flows.cpp.

◆ index

auto const index = mxlTimestampToIndex(&rate, now)

Definition at line 165 of file test_flows.cpp.

◆ instanceReader

auto instanceReader = mxlCreateInstance(domain.string().c_str(), opts)

Definition at line 143 of file test_flows.cpp.

◆ instanceWriter

auto instanceWriter = mxlCreateInstance(domain.string().c_str(), opts)

Definition at line 146 of file test_flows.cpp.

◆ keyPayloadSize

auto keyPayloadSize = keyPayloadStrideSize * h

Definition at line 183 of file test_flows.cpp.

◆ keyPayloadStrideSize

auto keyPayloadStrideSize = static_cast<std::size_t>((w + 2) / 3 * 4)

Definition at line 182 of file test_flows.cpp.

◆ now

auto const now = mxlGetTime()

Definition at line 164 of file test_flows.cpp.

◆ rate

auto const rate = mxlRational{60000, 1001}

Compute the grain index for the flow rate and current TAI time.

Definition at line 163 of file test_flows.cpp.

163{60000, 1001};

◆ reader

mxlFlowReader reader

Definition at line 155 of file test_flows.cpp.

◆ runtimeInfo1

mxlFlowRuntimeInfo runtimeInfo1

Get some info about the freshly created flow. Since no grains have been commited, the head should still be at 0.

Definition at line 195 of file test_flows.cpp.

◆ runtimeInfo2

mxlFlowRuntimeInfo runtimeInfo2

Get the updated flow info.

Definition at line 217 of file test_flows.cpp.

◆ w

auto w = 1920
constexpr

Definition at line 175 of file test_flows.cpp.

◆ writer

mxlFlowWriter writer

Definition at line 149 of file test_flows.cpp.