Gamp v0.0.7-54-gccdc599
Gamp: Graphics, Audio, Multimedia and Processing
Loading...
Searching...
No Matches
TimeFrameI.hpp
Go to the documentation of this file.
1/*
2 * Author: Sven Gothel <sgothel@jausoft.com>
3 * Copyright Gothel Software e.K.
4 *
5 * SPDX-License-Identifier: MIT
6 *
7 * This Source Code Form is subject to the terms of the MIT License
8 * If a copy of the MIT was not distributed with this file,
9 * you can obtain one at https://opensource.org/license/mit/.
10 */
11#ifndef GAMP_AV_TIMEFRAMEI_HPP_
12#define GAMP_AV_TIMEFRAMEI_HPP_
13
14#include <cstdint>
15#include <limits>
16
17#include <jau/string_util.hpp>
18
19#include <gamp/GampTypes.hpp>
20
21namespace gamp::av {
22
23 /** \addtogroup Gamp_AV
24 *
25 * @{
26 */
27
28 /**
29 * Integer time frame in milliseconds, maybe specialized for texture/video, audio, .. animated content.
30 * <p>
31 * Type and value range has been chosen to suit embedded CPUs
32 * and characteristics of audio / video streaming and animations.
33 * Milliseconds of type integer with a maximum value of MAX_UINT32 - 2 or 4'294'967'293 ms
34 * will allow tracking time up 4'294'967.293 seconds or
35 * 49 days 17 hours 2 minutes and 43 seconds, see pts() and duration().
36 * </p>
37 * <p>
38 * Milliseconds granularity is also more than enough to deal with A-V synchronization,
39 * where the threshold usually lies within 22ms.
40 * </p>
41 * <p>
42 * Milliseconds granularity for displaying video frames might seem inaccurate
43 * for each single frame, i.e. 60Hz != 16ms, however, accumulated values diminish
44 * this error and vertical sync is achieved by build-in V-Sync of the video drivers.
45 * </p>
46 */
47 class TimeFrameI {
48 public:
49 /** Constant marking an invalid (or undefined) PTS, i.e. MAX_UINT32 == 0xffffffff. Sync w/ native code. */
50 constexpr static uint32_t INVALID_PTS = std::numeric_limits<uint32_t>::max();
51
52 /** Constant marking the end of the stream PTS, i.e. MAX_UINT32 == 0xfffffffe. Sync w/ native code. */
53 constexpr static uint32_t END_OF_STREAM_PTS = std::numeric_limits<uint32_t>::max() - 1;
54
55 protected:
56 uint32_t m_pts;
57 uint32_t m_duration;
58
59 public:
60 /**
61 * Ctor w/ zero duration and ::INVALID_PTS.
62 */
63 constexpr TimeFrameI() noexcept
65 { }
66
67 /**
68 * Create a new instance
69 * @param pts frame pts in milliseconds, see pts()
70 * @param duration frame duration in milliseconds, see duration()
71 * @see pts()
72 * @see duration()
73 */
74 constexpr TimeFrameI(uint32_t pts, uint32_t duration) noexcept
76 { }
77
78 /**
79 * Returns this frame's presentation timestamp (PTS) in milliseconds.
80 * <p>
81 * The relative millisecond PTS since start of the presentation stored in integer
82 * covers a time span of 4'294'967'293 ms
83 * or 4'294'967 seconds or 49 days.
84 * </p>
85 */
86 constexpr uint32_t pts() const noexcept { return m_pts; }
87
88 /**
89 * Set this frame's presentation timestamp (PTS) in milliseconds.
90 * @see pts()
91 */
92 void setPTS(uint32_t pts) noexcept { m_pts = pts; }
93
94 /**
95 * Get this frame's duration in milliseconds.
96 * <p>
97 * The duration stored in integer covers 4'294'967'293 ms
98 * or 4'294'967 seconds or 49 days.
99 * </p>
100 */
101 constexpr uint32_t duration() const noexcept { return m_duration; }
102
103 /**
104 * Set this frame's duration in milliseconds.
105 * @see duration()
106 */
107 void setDuration(uint32_t duration) noexcept { m_duration = duration; }
108
109 std::string toString() noexcept {
110 std::string r("TimeFrame[pts ");
111 if( m_pts < END_OF_STREAM_PTS ) {
112 r.append(std::to_string(m_pts)).append(" ms");
113 } else if( m_pts == END_OF_STREAM_PTS ) {
114 r.append("eos");
115 } else {
116 r.append("undef");
117 }
118 return r.append(", l ").append(std::to_string(m_duration)).append(" ms]");
119 }
120 };
121
122 /**@}*/
123
124} // namespace gamp::av
125
126#endif /* GAMP_AV_TIMEFRAMEI_HPP_ */
constexpr uint32_t pts() const noexcept
Returns this frame's presentation timestamp (PTS) in milliseconds.
std::string toString() noexcept
void setPTS(uint32_t pts) noexcept
Set this frame's presentation timestamp (PTS) in milliseconds.
constexpr TimeFrameI() noexcept
Ctor w/ zero duration and INVALID_PTS.
static constexpr uint32_t END_OF_STREAM_PTS
Constant marking the end of the stream PTS, i.e.
constexpr uint32_t duration() const noexcept
Get this frame's duration in milliseconds.
static constexpr uint32_t INVALID_PTS
Constant marking an invalid (or undefined) PTS, i.e.
constexpr TimeFrameI(uint32_t pts, uint32_t duration) noexcept
Create a new instance.
void setDuration(uint32_t duration) noexcept
Set this frame's duration in milliseconds.