2011-05-23 05:46:40 +02:00
|
|
|
|
/*
|
2023-06-03 03:39:33 +02:00
|
|
|
|
DUMMY-BUILDER-CONTEXT.hpp - fake simulated builder result for player tests
|
2011-05-23 05:46:40 +02:00
|
|
|
|
|
Copyright: clarify and simplify the file headers
* Lumiera source code always was copyrighted by individual contributors
* there is no entity "Lumiera.org" which holds any copyrights
* Lumiera source code is provided under the GPL Version 2+
== Explanations ==
Lumiera as a whole is distributed under Copyleft, GNU General Public License Version 2 or above.
For this to become legally effective, the ''File COPYING in the root directory is sufficient.''
The licensing header in each file is not strictly necessary, yet considered good practice;
attaching a licence notice increases the likeliness that this information is retained
in case someone extracts individual code files. However, it is not by the presence of some
text, that legally binding licensing terms become effective; rather the fact matters that a
given piece of code was provably copyrighted and published under a license. Even reformatting
the code, renaming some variables or deleting parts of the code will not alter this legal
situation, but rather creates a derivative work, which is likewise covered by the GPL!
The most relevant information in the file header is the notice regarding the
time of the first individual copyright claim. By virtue of this initial copyright,
the first author is entitled to choose the terms of licensing. All further
modifications are permitted and covered by the License. The specific wording
or format of the copyright header is not legally relevant, as long as the
intention to publish under the GPL remains clear. The extended wording was
based on a recommendation by the FSF. It can be shortened, because the full terms
of the license are provided alongside the distribution, in the file COPYING.
2024-11-17 23:42:55 +01:00
|
|
|
|
Copyright (C)
|
|
|
|
|
|
2011, Hermann Vosseler <Ichthyostega@web.de>
|
2011-05-23 05:46:40 +02:00
|
|
|
|
|
Copyright: clarify and simplify the file headers
* Lumiera source code always was copyrighted by individual contributors
* there is no entity "Lumiera.org" which holds any copyrights
* Lumiera source code is provided under the GPL Version 2+
== Explanations ==
Lumiera as a whole is distributed under Copyleft, GNU General Public License Version 2 or above.
For this to become legally effective, the ''File COPYING in the root directory is sufficient.''
The licensing header in each file is not strictly necessary, yet considered good practice;
attaching a licence notice increases the likeliness that this information is retained
in case someone extracts individual code files. However, it is not by the presence of some
text, that legally binding licensing terms become effective; rather the fact matters that a
given piece of code was provably copyrighted and published under a license. Even reformatting
the code, renaming some variables or deleting parts of the code will not alter this legal
situation, but rather creates a derivative work, which is likewise covered by the GPL!
The most relevant information in the file header is the notice regarding the
time of the first individual copyright claim. By virtue of this initial copyright,
the first author is entitled to choose the terms of licensing. All further
modifications are permitted and covered by the License. The specific wording
or format of the copyright header is not legally relevant, as long as the
intention to publish under the GPL remains clear. The extended wording was
based on a recommendation by the FSF. It can be shortened, because the full terms
of the license are provided alongside the distribution, in the file COPYING.
2024-11-17 23:42:55 +01:00
|
|
|
|
**Lumiera** is free software; you can redistribute it and/or modify it
|
|
|
|
|
|
under the terms of the GNU General Public License as published by the
|
|
|
|
|
|
Free Software Foundation; either version 2 of the License, or (at your
|
|
|
|
|
|
option) any later version. See the file COPYING for further details.
|
2011-05-23 05:46:40 +02:00
|
|
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
2023-06-03 03:39:33 +02:00
|
|
|
|
/** @file dummy-builder-context.hpp
|
|
|
|
|
|
** Simulated result of a builder run for test purposes, without actual session and model content.
|
|
|
|
|
|
** Integration tests for the render engine or the player have to deal with a lot of prerequisites,
|
|
|
|
|
|
** since both an external environment and actual content form the Session is required to start any
|
|
|
|
|
|
** processing. Effectively the complete core application is required — while in fact the engine is
|
|
|
|
|
|
** built in an abstracted way and does not need to know much about the rest of the application.
|
|
|
|
|
|
** Thus, as a remedy, it is possible to establish a _faked context,_ exposing just those interfaces
|
|
|
|
|
|
** used by the engine for processing. As additional benefit, dedicated test operations can be rigged
|
|
|
|
|
|
** and verification routines can be used in place of actual media output.
|
2016-12-10 01:21:08 +01:00
|
|
|
|
**
|
2023-06-03 03:39:33 +02:00
|
|
|
|
** This faked builder context provides a selection of consistent media element IDs with sensible
|
|
|
|
|
|
** properties and type markers, plus the attachment points for a simulated model structure, as
|
|
|
|
|
|
** if generated from an actual session model by a real Builder run.
|
|
|
|
|
|
** - a set of ModelPort elements
|
|
|
|
|
|
** - a set of DataSink handles, as if an actual playback connection has been established
|
|
|
|
|
|
** @todo 5/2023 add more elements as needed for test driven integration of Player and engine
|
2026-03-20 23:39:10 +01:00
|
|
|
|
** @todo this was invented in 2012 -- as an act of desperation, since everything to build upon
|
|
|
|
|
|
** seemed to evade my grip. My hope at that time was so somehow _bootstrap_ an explorative
|
|
|
|
|
|
** design in order to get away from that top-down reasoning, that seemed to lead nowhere.
|
|
|
|
|
|
** However, work on the player had to be postponed to care for the GUI first; meanwhile
|
|
|
|
|
|
** I follow a similar idea, relying on »vertical integration slices«
|
|
|
|
|
|
** @deprecated 3/2026 not sure if we need this henceforth...
|
|
|
|
|
|
** It might be useful though in case we consider to build some kind of
|
|
|
|
|
|
** _component integration test_ -- yet for this to work, we'd need
|
|
|
|
|
|
** - a fake calculation
|
|
|
|
|
|
** - a fake OutputSlot
|
2026-06-01 19:54:51 +02:00
|
|
|
|
** @todo 5/2026 now I have beefed up the OutputSlot so that it can receive
|
|
|
|
|
|
** two feeds with an arbitrary number of frames. Still not sure if it's needed;
|
|
|
|
|
|
** however it should be noted that the MockDispatcher relies on the DummyPlayConnection,
|
|
|
|
|
|
** which in turn uses SimulatedBuilderContext, mostly to get _just some model ports_.
|
2012-01-28 23:12:42 +01:00
|
|
|
|
**
|
2023-06-03 03:39:33 +02:00
|
|
|
|
** @see mock-dispatcher.hpp
|
2023-06-17 03:10:57 +02:00
|
|
|
|
** @see JobPlanningPipeline_test
|
2011-05-23 05:46:40 +02:00
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
2023-06-03 03:39:33 +02:00
|
|
|
|
#ifndef STEAM_PLAY_DUMMY_BUILDER_CONTEXT_H
|
|
|
|
|
|
#define STEAM_PLAY_DUMMY_BUILDER_CONTEXT_H
|
2011-05-23 05:46:40 +02:00
|
|
|
|
|
|
|
|
|
|
|
2026-06-01 19:54:51 +02:00
|
|
|
|
#include "lib/error.hpp"
|
|
|
|
|
|
#include "lib/format-string.hpp"
|
2018-11-15 23:42:43 +01:00
|
|
|
|
#include "steam/mobject/model-port.hpp"
|
2023-06-07 04:03:00 +02:00
|
|
|
|
#include "steam/fixture/model-port-registry.hpp"
|
2026-03-10 23:12:30 +01:00
|
|
|
|
#include "vault/out/output-slot-connection.hpp"
|
2023-06-03 03:39:33 +02:00
|
|
|
|
#include "steam/play/output-manager.hpp"
|
2018-11-15 23:42:43 +01:00
|
|
|
|
#include "steam/asset/timeline.hpp"
|
|
|
|
|
|
#include "steam/asset/pipe.hpp"
|
2026-02-28 22:55:09 +01:00
|
|
|
|
#include "vessel/query.hpp"
|
2012-02-20 01:13:53 +01:00
|
|
|
|
|
2026-05-31 23:48:26 +02:00
|
|
|
|
#include "lib/iter-explorer.hpp"
|
2012-01-27 00:14:21 +01:00
|
|
|
|
#include "lib/iter-source.hpp"
|
2018-03-24 05:35:13 +01:00
|
|
|
|
#include "lib/nocopy.hpp"
|
|
|
|
|
|
#include "lib/util.hpp"
|
|
|
|
|
|
|
2012-02-20 01:13:53 +01:00
|
|
|
|
#include <vector>
|
2026-06-01 19:54:51 +02:00
|
|
|
|
#include <deque>
|
|
|
|
|
|
#include <array>
|
2011-05-23 05:46:40 +02:00
|
|
|
|
|
|
|
|
|
|
|
2023-04-18 20:02:36 +02:00
|
|
|
|
namespace steam{
|
2011-05-28 01:46:06 +02:00
|
|
|
|
namespace play {
|
2023-04-18 20:02:36 +02:00
|
|
|
|
namespace test {
|
2026-06-01 19:54:51 +02:00
|
|
|
|
namespace err = lumiera::error;
|
2023-06-02 02:31:34 +02:00
|
|
|
|
|
2023-06-07 04:03:00 +02:00
|
|
|
|
using fixture::ModelPortRegistry;
|
2026-03-21 23:46:58 +01:00
|
|
|
|
using vault::mem::Buff;
|
2026-03-10 23:12:30 +01:00
|
|
|
|
using vault::mem::BuffHandle;
|
|
|
|
|
|
using vault::out::FrameID;
|
|
|
|
|
|
using lib::time::TimeValue;
|
2026-06-01 19:54:51 +02:00
|
|
|
|
using util::_Fmt;
|
2023-06-07 04:03:00 +02:00
|
|
|
|
|
2026-06-01 23:33:25 +02:00
|
|
|
|
using DataSink = vault::out::OutputSlot::DataSink;
|
|
|
|
|
|
|
2023-06-02 02:31:34 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2026-05-31 23:48:26 +02:00
|
|
|
|
/**
|
2026-06-01 19:54:51 +02:00
|
|
|
|
* A placeholder/dummy OutputSlot that captures all
|
|
|
|
|
|
* delivered output data into heap-allocated memory.
|
|
|
|
|
|
* @todo 5/2026 it can now be created and allocates a fixed layout
|
|
|
|
|
|
* of buffer storage, which implies it should not be copied
|
|
|
|
|
|
* and is thus used differently than a real OutputSlot;
|
2026-05-31 23:48:26 +02:00
|
|
|
|
* should reconsider what is actually needed here!
|
2026-06-01 19:54:51 +02:00
|
|
|
|
* @warning this used to be placeholder code, and now it was adapted
|
|
|
|
|
|
* to store frames, yet this new functionality is untested as of 5/2026
|
2026-05-31 23:48:26 +02:00
|
|
|
|
*/
|
2026-06-01 19:54:51 +02:00
|
|
|
|
struct FakeOutput
|
2026-05-31 23:48:26 +02:00
|
|
|
|
: OutputSlot
|
2026-06-01 19:54:51 +02:00
|
|
|
|
, util::NonCopyable
|
2026-05-31 23:48:26 +02:00
|
|
|
|
{
|
2026-06-01 19:54:51 +02:00
|
|
|
|
static constexpr uint NUM_FEEDS = 2;
|
2026-05-31 23:48:26 +02:00
|
|
|
|
static constexpr bool SINGLE_THREADED_TEST = true;
|
|
|
|
|
|
|
2026-06-01 19:54:51 +02:00
|
|
|
|
using DummyDat = uint64_t;
|
|
|
|
|
|
static constexpr size_t DUMMY_BUFF_SIZ = 1_KiB * sizeof(DummyDat);
|
|
|
|
|
|
|
|
|
|
|
|
using DummyBuff = std::array<DummyDat, DUMMY_BUFF_SIZ>;
|
|
|
|
|
|
using DummyBuffSeq = std::deque<DummyBuff>;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* @todo 5/2026 quick-n-dirty placeholder code
|
|
|
|
|
|
* to expose some output buffers and provide
|
|
|
|
|
|
* the corresponding DataSink handles
|
|
|
|
|
|
*/
|
|
|
|
|
|
class DummyOutputConnection
|
|
|
|
|
|
: public vault::out::OutputSlot::Connection
|
|
|
|
|
|
{
|
|
|
|
|
|
DummyBuffSeq& buffers_;
|
|
|
|
|
|
|
|
|
|
|
|
size_t getBufferSize() const override { return DUMMY_BUFF_SIZ; }
|
|
|
|
|
|
Buff* claimBufferFor (FrameID) override;
|
|
|
|
|
|
void publish (Buff*) override { /* fake "publish buffer content" */ }
|
|
|
|
|
|
void release (Buff*) override { /* fake "complete buffer cycle" */ }
|
|
|
|
|
|
void shutDown () override { /* fake "shutDown() Connection" */ }
|
|
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
~DummyOutputConnection();
|
|
|
|
|
|
DummyOutputConnection (DummyBuffSeq& buffers)
|
|
|
|
|
|
: buffers_{buffers}
|
|
|
|
|
|
{ }
|
|
|
|
|
|
// OutputSlot::Connection is non-copyable
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
using Connections = lib::ScopedCollection<DummyOutputConnection>;
|
|
|
|
|
|
using MockConnectState = OutputSlot::AllocState<DummyOutputConnection, SINGLE_THREADED_TEST>;
|
|
|
|
|
|
|
|
|
|
|
|
using OutBuffs = std::array<DummyBuffSeq, NUM_FEEDS>;
|
|
|
|
|
|
OutBuffs buffers_{};
|
|
|
|
|
|
|
|
|
|
|
|
FakeOutput()
|
|
|
|
|
|
: OutputSlot{std::make_unique<MockConnectState> (NUM_FEEDS
|
|
|
|
|
|
,[&,i=0](auto& storage) mutable
|
|
|
|
|
|
{
|
|
|
|
|
|
storage.template create<DummyOutputConnection> (buffers_[i++]);
|
|
|
|
|
|
})}
|
2026-05-31 23:48:26 +02:00
|
|
|
|
{ }
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2026-06-01 19:54:51 +02:00
|
|
|
|
inline Buff*
|
|
|
|
|
|
FakeOutput::DummyOutputConnection::claimBufferFor (FrameID fra)
|
|
|
|
|
|
{
|
|
|
|
|
|
REQUIRE (fra >= 0);
|
|
|
|
|
|
if (uint64_t(fra) >= buffers_.size())
|
|
|
|
|
|
buffers_.resize(fra+10);
|
|
|
|
|
|
return reinterpret_cast<Buff*> (& buffers_[fra]);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2023-06-03 18:38:37 +02:00
|
|
|
|
using asset::Pipe;
|
|
|
|
|
|
using asset::PPipe;
|
|
|
|
|
|
using asset::Struct;
|
|
|
|
|
|
using asset::Timeline;
|
|
|
|
|
|
using asset::PTimeline;
|
|
|
|
|
|
using mobject::ModelPort;
|
2023-06-07 04:03:00 +02:00
|
|
|
|
using fixture::ModelPortRegistry;
|
2023-06-03 18:38:37 +02:00
|
|
|
|
using util::contains;
|
2026-02-28 22:55:09 +01:00
|
|
|
|
using vessel::Query;
|
2023-06-03 18:38:37 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
using PID = asset::ID<Pipe>;
|
|
|
|
|
|
using TID = asset::ID<Struct>;
|
|
|
|
|
|
|
|
|
|
|
|
using ModelPorts = lib::IterSource<mobject::ModelPort>::iterator;
|
2026-03-10 23:12:30 +01:00
|
|
|
|
using DummyOutputLink = std::pair<mobject::ModelPort, DataSink>;
|
2023-06-03 18:38:37 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
inline PID
|
|
|
|
|
|
getPipe (string id)
|
|
|
|
|
|
{
|
|
|
|
|
|
return Pipe::query ("id("+id+")");
|
|
|
|
|
|
}
|
2012-02-20 01:13:53 +01:00
|
|
|
|
|
2023-06-03 18:38:37 +02:00
|
|
|
|
inline TID
|
|
|
|
|
|
getTimeline (string id)
|
|
|
|
|
|
{
|
|
|
|
|
|
return asset::Struct::retrieve (Query<Timeline> ("id("+id+")"))->getID();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const uint NUMBER_OF_PORTS = 2;
|
|
|
|
|
|
const string namePortA("bus-A");
|
|
|
|
|
|
const string namePortB("bus-B");
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* helper for dummy render engine:
|
|
|
|
|
|
* Simulate the result of a build process,
|
|
|
|
|
|
* without actually running the builder.
|
|
|
|
|
|
* Produces some mock pipes, model ports etc.
|
2011-05-28 01:46:06 +02:00
|
|
|
|
*/
|
2023-06-03 18:38:37 +02:00
|
|
|
|
struct SimulatedBuilderContext
|
2011-05-28 01:46:06 +02:00
|
|
|
|
{
|
2023-06-03 18:38:37 +02:00
|
|
|
|
ModelPortRegistry registry_;
|
|
|
|
|
|
ModelPortRegistry* existingRegistry_;
|
2011-05-28 01:46:06 +02:00
|
|
|
|
|
2023-06-03 18:38:37 +02:00
|
|
|
|
std::vector<ModelPort> modelPorts_;
|
|
|
|
|
|
std::vector<DataSink> dataSinks_;
|
2012-01-27 00:14:21 +01:00
|
|
|
|
|
2026-06-01 19:54:51 +02:00
|
|
|
|
FakeOutput fakeOutput_;
|
|
|
|
|
|
|
2023-06-03 18:38:37 +02:00
|
|
|
|
/** setup */
|
|
|
|
|
|
SimulatedBuilderContext()
|
|
|
|
|
|
: registry_()
|
|
|
|
|
|
, existingRegistry_(ModelPortRegistry::setActiveInstance (registry_))
|
2023-06-02 02:31:34 +02:00
|
|
|
|
{
|
2023-06-03 18:38:37 +02:00
|
|
|
|
performMockBuild();
|
2023-06-02 02:31:34 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2023-06-03 18:38:37 +02:00
|
|
|
|
/** tear-down */
|
|
|
|
|
|
~SimulatedBuilderContext()
|
2012-01-27 00:14:21 +01:00
|
|
|
|
{
|
2023-06-03 18:38:37 +02:00
|
|
|
|
if (existingRegistry_)
|
|
|
|
|
|
ModelPortRegistry::setActiveInstance (*existingRegistry_);
|
|
|
|
|
|
else
|
|
|
|
|
|
ModelPortRegistry::shutdown();
|
2012-01-27 00:14:21 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2023-06-03 18:38:37 +02:00
|
|
|
|
void
|
|
|
|
|
|
performMockBuild()
|
2012-01-27 00:14:21 +01:00
|
|
|
|
{
|
2023-06-03 18:38:37 +02:00
|
|
|
|
PID pipeA = getPipe (namePortA);
|
|
|
|
|
|
PID pipeB = getPipe (namePortB);
|
|
|
|
|
|
TID someTimeline = getTimeline ("dummy_Timeline");
|
|
|
|
|
|
|
|
|
|
|
|
// start out with defining some new model ports......
|
|
|
|
|
|
registry_.definePort (pipeA, someTimeline);
|
|
|
|
|
|
registry_.definePort (pipeB, someTimeline);
|
|
|
|
|
|
|
|
|
|
|
|
registry_.commit();
|
|
|
|
|
|
|
|
|
|
|
|
// now "bus-A" and "bus-B" are known as model ports
|
|
|
|
|
|
modelPorts_.push_back (ModelPort(pipeA));
|
|
|
|
|
|
modelPorts_.push_back (ModelPort(pipeB));
|
|
|
|
|
|
|
|
|
|
|
|
// prepare corresponding placeholder DataSink (a fake active output connection)
|
2026-05-31 23:48:26 +02:00
|
|
|
|
dataSinks_.clear();
|
2026-06-01 19:54:51 +02:00
|
|
|
|
lib::explore(fakeOutput_.getOpenedSinks())
|
2026-05-31 23:48:26 +02:00
|
|
|
|
.effuse (dataSinks_);
|
2012-01-27 00:14:21 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2023-06-03 18:38:37 +02:00
|
|
|
|
ModelPorts
|
|
|
|
|
|
getAllModelPorts()
|
2012-01-27 00:14:21 +01:00
|
|
|
|
{
|
2023-06-03 18:38:37 +02:00
|
|
|
|
return lib::iter_source::eachEntry (modelPorts_.begin(), modelPorts_.end());
|
2012-01-27 00:14:21 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2023-06-03 18:38:37 +02:00
|
|
|
|
DummyOutputLink
|
|
|
|
|
|
getModelPort (uint index)
|
2012-01-27 00:14:21 +01:00
|
|
|
|
{
|
2023-06-03 18:38:37 +02:00
|
|
|
|
REQUIRE (index < modelPorts_.size());
|
|
|
|
|
|
return {modelPorts_[index]
|
|
|
|
|
|
,dataSinks_[index]
|
|
|
|
|
|
};
|
2012-01-27 00:14:21 +01:00
|
|
|
|
}
|
2026-03-10 23:12:30 +01:00
|
|
|
|
|
2026-06-01 19:54:51 +02:00
|
|
|
|
/**
|
|
|
|
|
|
* Access a generated output frame.
|
|
|
|
|
|
* @remark FakeOutput maintains Deque-Storage for each feed.
|
|
|
|
|
|
* @tparam X data type to assume as content of the frame (only checked for size)
|
|
|
|
|
|
* @param feed number of the output feed to access
|
|
|
|
|
|
* @param frame frame numer within the output feed
|
|
|
|
|
|
*/
|
|
|
|
|
|
template<typename X>
|
|
|
|
|
|
X&
|
|
|
|
|
|
accessOutputBufferAs (uint feed, FrameID frame)
|
2026-03-10 23:12:30 +01:00
|
|
|
|
{
|
2026-06-01 19:54:51 +02:00
|
|
|
|
static_assert (sizeof(X) <= FakeOutput::DUMMY_BUFF_SIZ
|
|
|
|
|
|
,"desired data type would not fit into FakeOutput buffer");
|
|
|
|
|
|
if (feed >= FakeOutput::NUM_FEEDS)
|
|
|
|
|
|
throw err::Invalid{_Fmt{"Feed #%i > %i allowed"}
|
|
|
|
|
|
% feed % (FakeOutput::NUM_FEEDS-1)};
|
|
|
|
|
|
|
|
|
|
|
|
auto availFrames = fakeOutput_.buffers_[feed].size();
|
|
|
|
|
|
if (frame >= availFrames)
|
|
|
|
|
|
throw err::Invalid{_Fmt{"Frame #%02i > %02i available frames"}
|
|
|
|
|
|
% frame % availFrames};
|
|
|
|
|
|
|
|
|
|
|
|
return reinterpret_cast<X&> (fakeOutput_.buffers_[feed][frame]);
|
2026-03-10 23:12:30 +01:00
|
|
|
|
}
|
2026-06-01 19:54:51 +02:00
|
|
|
|
};
|
2026-03-10 23:12:30 +01:00
|
|
|
|
|
2026-06-01 19:54:51 +02:00
|
|
|
|
}}} // namespace steam::play::test
|
2023-06-03 03:39:33 +02:00
|
|
|
|
#endif /*STEAM_PLAY_DUMMY_BUILDER_CONTEXT_H*/
|