Roc Toolkit internal modules
Roc Toolkit: real-time audio streaming
timestamp_extractor.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2023 Roc Streaming authors
3  *
4  * This Source Code Form is subject to the terms of the Mozilla Public
5  * License, v. 2.0. If a copy of the MPL was not distributed with this
6  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
7  */
8 
9 //! @file roc_rtp/timestamp_extractor.h
10 //! @brief Extracts capture timestamp field from packets.
11 
12 #ifndef ROC_RTP_TIMESTAMP_EXTRACTOR_H_
13 #define ROC_RTP_TIMESTAMP_EXTRACTOR_H_
14 
15 #include "roc_audio/sample_spec.h"
16 #include "roc_core/attributes.h"
17 #include "roc_core/noncopyable.h"
18 #include "roc_core/rate_limiter.h"
19 #include "roc_core/stddefs.h"
20 #include "roc_packet/iwriter.h"
21 #include "roc_packet/packet.h"
22 
23 namespace roc {
24 namespace rtp {
25 
26 //! Remembers a recent pair of capture timestamp and rtp ts.
28 public:
29  //! Initialize.
31 
32  //! Destroy.
34 
35  //! Passes pkt downstream and remembers its capture and rtp timestamps.
37 
38  //! Check if mapping already available.
39  bool has_mapping();
40 
41  //! Get rtp timestamp mapped to given capture timestamp.
42  //! @pre
43  //! has_mapping() should return true, otherwise it will panic.
45 
46 private:
47  packet::IWriter& writer_;
48 
49  bool has_ts_;
50  core::nanoseconds_t capt_ts_;
52 
53  const audio::SampleSpec sample_spec_;
54 
55  core::RateLimiter rate_limiter_;
56 };
57 
58 } // namespace rtp
59 } // namespace roc
60 
61 #endif // ROC_RTP_TIMESTAMP_EXTRACTOR_H_
Compiler attributes.
#define ROC_ATTR_NODISCARD
Emit warning if function result is not checked.
Definition: attributes.h:31
Sample specification. Describes sample rate and channels.
Definition: sample_spec.h:30
Base class for non-copyable objects.
Definition: noncopyable.h:23
Packet writer interface.
Definition: iwriter.h:23
Remembers a recent pair of capture timestamp and rtp ts.
TimestampExtractor(packet::IWriter &writer, const audio::SampleSpec &sample_spec)
Initialize.
virtual ROC_ATTR_NODISCARD status::StatusCode write(const packet::PacketPtr &pkt)
Passes pkt downstream and remembers its capture and rtp timestamps.
bool has_mapping()
Check if mapping already available.
packet::stream_timestamp_t get_mapping(core::nanoseconds_t capture_ts)
Get rtp timestamp mapped to given capture timestamp.
virtual ~TimestampExtractor()
Destroy.
Packet writer interface.
int64_t nanoseconds_t
Nanoseconds.
Definition: time.h:58
uint32_t stream_timestamp_t
Packet stream timestamp.
Definition: units.h:36
Root namespace.
Non-copyable object.
Packet.
Rate limiter.
Sample specifications.
StatusCode
Status code.
Definition: status_code.h:19
Commonly used types and functions.