libpromeki 1.0.0-alpha
PROfessional MEdia toolKIt
 
Loading...
Searching...
No Matches
mediaioportgroup.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/objectbase.h>
15#include <promeki/atomic.h>
16#include <promeki/error.h>
17#include <promeki/framenumber.h>
18#include <promeki/framecount.h>
19#include <promeki/framerate.h>
20#include <promeki/ratetracker.h>
21#include <promeki/timestamp.h>
22#include <promeki/list.h>
23#include <promeki/string.h>
24#include <promeki/clock.h>
25#include <promeki/mediaio.h>
26
27PROMEKI_NAMESPACE_BEGIN
28
29class MediaIO;
30class MediaIOPort;
31class MediaIORequest;
32
83class MediaIOPortGroup : public ObjectBase {
84 PROMEKI_OBJECT(MediaIOPortGroup, ObjectBase)
85 friend class MediaIO;
86 friend class MediaIOSink;
87 friend class MediaIOSource;
88 friend class MediaIOReadCache;
89 friend class CommandMediaIO;
90 public:
92 using PortList = ::promeki::List<MediaIOPort *>;
93
115 MediaIOPortGroup(MediaIO *mediaIO, const String &name, const Clock::Ptr &clock);
116
118 ~MediaIOPortGroup() override;
119
121 MediaIO *mediaIO() const { return _mediaIO; }
122
124 const String &name() const { return _name; }
125
133 const PortList &ports() const { return _ports; }
134
145 void addPort(MediaIOPort *port);
146
161 const Clock::Ptr &clock() const { return _clock; }
162
195 MediaIORequest setClock(const Clock::Ptr &clock);
196
208 int pendingWrites() const { return _pendingWriteCount.value(); }
209
218 int pendingReads() const { return _pendingReadCount.value(); }
219
228 FrameNumber currentFrame() const { return _currentFrame; }
229
249 double rate() const { return _rate; }
250
268 void setRate(double r);
269
295 int nextStep();
296
319 MediaIORequest seekToFrame(const FrameNumber &frameNumber,
320 MediaIOSeekMode mode = MediaIO_SeekDefault);
321
323 FrameCount frameCount() const { return _frameCount; }
324
326 bool canSeek() const { return _canSeek; }
327
329 void setCanSeek(bool val) { _canSeek = val; }
330
332 void setFrameCount(const FrameCount &val) { _frameCount = val; }
333
335 bool atEnd() const { return _atEnd; }
336
338 const FrameRate &frameRate() const { return _frameRate; }
339
341 void setFrameRate(const FrameRate &val) { _frameRate = val; }
342
344 const TimeStamp &originTime() const { return _originTime; }
345
347 void setOriginTime(const TimeStamp &val) { _originTime = val; }
348
349 // ---- Per-group accounting ----
350 //
351 // A single backend tick (one CmdRead or CmdWrite)
352 // advances the whole group, regardless of how many
353 // ports it has — so the rate tracker, dropped /
354 // repeated / late counters, and pending-command
355 // counts all live here. Reporting one dropped frame
356 // on a paired audio + video group correctly counts
357 // one missed tick rather than inflating the metric
358 // to two.
359
361 int64_t bytesPerSecond() const { return _rateTracker.bytesPerSecond(); }
362
364 double framesPerSecond() const { return _rateTracker.framesPerSecond(); }
365
367 int64_t framesDroppedTotal() const { return _framesDroppedTotal.value(); }
368
370 int64_t framesRepeatedTotal() const { return _framesRepeatedTotal.value(); }
371
373 int64_t framesLateTotal() const { return _framesLateTotal.value(); }
374
375 private:
376 MediaIO *_mediaIO = nullptr;
377 String _name;
378 PortList _ports;
379 Clock::Ptr _clock;
380 Atomic<int> _pendingWriteCount;
381 Atomic<int> _pendingReadCount;
382 FrameNumber _currentFrame;
383 FrameCount _frameCount;
384 FrameRate _frameRate;
385 TimeStamp _originTime;
386 RateTracker _rateTracker;
387 Atomic<int64_t> _framesDroppedTotal{0};
388 Atomic<int64_t> _framesRepeatedTotal{0};
389 Atomic<int64_t> _framesLateTotal{0};
390 double _rate = 1.0;
391 double _rateAccumulator = 0.0;
392 bool _canSeek = false;
393 bool _atEnd = false;
394};
395
396PROMEKI_NAMESPACE_END
397
398#endif // PROMEKI_ENABLE_PROAV