libpromeki 1.0.0-alpha
PROfessional MEdia toolKIt
 
Loading...
Searching...
No Matches
mediapipelineconfig.h
Go to the documentation of this file.
1
8#pragma once
9
10
11#include <promeki/config.h>
12#if PROMEKI_ENABLE_PROAV
13#include <promeki/namespace.h>
14#include <promeki/datastream.h>
15#include <promeki/error.h>
16#include <promeki/filepath.h>
17#include <promeki/framecount.h>
18#include <promeki/json.h>
19#include <promeki/list.h>
20#include <promeki/mediaconfig.h>
21#include <promeki/mediaio.h>
22#include <promeki/metadata.h>
23#include <promeki/sharedptr.h>
24#include <promeki/string.h>
25#include <promeki/stringlist.h>
26
27PROMEKI_NAMESPACE_BEGIN
28
55class MediaPipelineConfig {
56 PROMEKI_SHARED_FINAL(MediaPipelineConfig)
57 public:
59 using Ptr = SharedPtr<MediaPipelineConfig>;
60
62 using List = ::promeki::List<MediaPipelineConfig>;
63
65 using PtrList = ::promeki::List<Ptr>;
66
77 enum class StageRole {
78 NotOpen = 0,
79 Source,
80 Sink,
81 Transform
82 };
83
96 enum class Kind {
97 Playback = 0,
98 Capture
99 };
100
113 struct Stage {
115 String name;
117 String type;
119 String path;
121 StageRole role = StageRole::NotOpen;
123 MediaConfig config;
125 Metadata metadata;
126
139 bool pacesPipeline = false;
140
154 bool captureSink = false;
155
157 bool operator==(const Stage &other) const;
158 bool operator!=(const Stage &other) const { return !(*this == other); }
159 };
160
174 struct Route {
176 String from;
178 String to;
180 String fromTrack;
182 String toTrack;
183
184 bool operator==(const Route &other) const {
185 return from == other.from && to == other.to && fromTrack == other.fromTrack &&
186 toTrack == other.toTrack;
187 }
188 bool operator!=(const Route &other) const { return !(*this == other); }
189 };
190
192 using StageList = ::promeki::List<Stage>;
193
195 using RouteList = ::promeki::List<Route>;
196
198 MediaPipelineConfig() = default;
199
200 // ------------------------------------------------------------
201 // Stages
202 // ------------------------------------------------------------
203
205 const StageList &stages() const { return _stages; }
206
208 StageList &stages() { return _stages; }
209
211 void addStage(const Stage &s) { _stages.pushToBack(s); }
212
214 void addStage(Stage &&s) { _stages.pushToBack(std::move(s)); }
215
221 const Stage *findStage(const String &name) const;
222
224 bool hasStage(const String &name) const { return findStage(name) != nullptr; }
225
227 StringList stageNames() const;
228
229 // ------------------------------------------------------------
230 // Routes
231 // ------------------------------------------------------------
232
234 const RouteList &routes() const { return _routes; }
235
237 RouteList &routes() { return _routes; }
238
240 void addRoute(const Route &r) { _routes.pushToBack(r); }
241
243 void addRoute(const String &from, const String &to);
244
245 // ------------------------------------------------------------
246 // Pipeline kind / transport defaults
247 // ------------------------------------------------------------
248
257 Kind kind() const { return _kind; }
258
260 void setKind(Kind k) { _kind = k; }
261
273 bool startPaused() const { return _startPaused; }
274
276 void setStartPaused(bool v) { _startPaused = v; }
277
278 // ------------------------------------------------------------
279 // Pipeline-wide metadata
280 // ------------------------------------------------------------
281
283 const Metadata &pipelineMetadata() const { return _pipelineMetadata; }
284
286 Metadata &pipelineMetadata() { return _pipelineMetadata; }
287
289 void setPipelineMetadata(const Metadata &m) { _pipelineMetadata = m; }
290
291 // ------------------------------------------------------------
292 // Frame-count limit
293 // ------------------------------------------------------------
294
314 const FrameCount &frameCount() const { return _frameCount; }
315
317 void setFrameCount(const FrameCount &count) { _frameCount = count; }
318
319 // ------------------------------------------------------------
320 // Stats window
321 // ------------------------------------------------------------
322
333 int statsWindowSize() const { return _statsWindowSize; }
334
336 void setStatsWindowSize(int n) { _statsWindowSize = n < 0 ? 0 : n; }
337
338 // ------------------------------------------------------------
339 // Operations
340 // ------------------------------------------------------------
341
355 bool isResolved(String *diagnostic = nullptr) const;
356
374 MediaPipelineConfig resolved(Error *err = nullptr, String *diagnostic = nullptr) const;
375
401 Error validate() const;
402
414 StringList describe() const;
415
428 JsonObject toJson() const;
429
438 static MediaPipelineConfig fromJson(const JsonObject &obj, Error *err = nullptr);
439
446 Error saveToFile(const FilePath &path, unsigned int indent = 2) const;
447
454 static MediaPipelineConfig loadFromFile(const FilePath &path, Error *err = nullptr);
455
457 bool operator==(const MediaPipelineConfig &other) const;
458 bool operator!=(const MediaPipelineConfig &other) const { return !(*this == other); }
459
466 static String roleName(StageRole role);
467
474 static StageRole roleFromName(const String &name, Error *err = nullptr);
475
482 static String kindName(Kind kind);
483
490 static Kind kindFromName(const String &name, Error *err = nullptr);
491
492 private:
493 StageList _stages;
494 RouteList _routes;
495 Metadata _pipelineMetadata;
496 FrameCount _frameCount;
497 int _statsWindowSize = 256;
498 Kind _kind = Kind::Playback;
499 bool _startPaused = false;
500};
501
502// ============================================================================
503// DataStream serialization
504// ============================================================================
505//
506// Stage and Route are simple value types; their operators are declared
507// here and defined in mediapipelineconfig.cpp alongside the rest of the
508// serialization code.
509
511DataStream &operator<<(DataStream &stream, const MediaPipelineConfig::Stage &s);
512
514DataStream &operator>>(DataStream &stream, MediaPipelineConfig::Stage &s);
515
517DataStream &operator<<(DataStream &stream, const MediaPipelineConfig::Route &r);
518
520DataStream &operator>>(DataStream &stream, MediaPipelineConfig::Route &r);
521
523DataStream &operator<<(DataStream &stream, const MediaPipelineConfig &c);
524
526DataStream &operator>>(DataStream &stream, MediaPipelineConfig &c);
527
528PROMEKI_NAMESPACE_END
529
530#endif // PROMEKI_ENABLE_PROAV