Roc Toolkit internal modules
Roc Toolkit: real-time audio streaming
validator.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2017 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/validator.h
10 //! @brief RTP validator.
11 
12 #ifndef ROC_RTP_VALIDATOR_H_
13 #define ROC_RTP_VALIDATOR_H_
14 
15 #include "roc_audio/sample_spec.h"
16 #include "roc_core/noncopyable.h"
17 #include "roc_core/time.h"
18 #include "roc_packet/ireader.h"
19 
20 namespace roc {
21 namespace rtp {
22 
23 //! Validator parameters.
25  //! Maximum allowed delta between two consecutive packet seqnums.
26  size_t max_sn_jump;
27 
28  //! Maximum allowed delta between two consecutive packet timestamps, in nanoseconds.
30 
32  : max_sn_jump(100)
33  , max_ts_jump(core::Second) {
34  }
35 };
36 
37 //! RTP validator.
38 class Validator : public packet::IReader, public core::NonCopyable<> {
39 public:
40  //! Initialize.
41  //!
42  //! @b Parameters
43  //! - @p reader is input packet reader
44  //! - @p config defines validator parameters
45  //! - @p sample_spec defines session sample spec
47  const ValidatorConfig& config,
48  const audio::SampleSpec& sample_spec);
49 
50  //! Read next packet.
51  //!
52  //! @remarks
53  //! Reads packet from the underlying reader and validates it.
55 
56 private:
57  bool validate_(const packet::RTP& prev, const packet::RTP& next) const;
58 
59  packet::IReader& reader_;
60 
61  bool has_prev_packet_;
62  packet::RTP prev_packet_rtp_;
63 
64  const ValidatorConfig config_;
65  const audio::SampleSpec sample_spec_;
66 };
67 
68 } // namespace rtp
69 } // namespace roc
70 
71 #endif // ROC_RTP_VALIDATOR_H_
#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:26
Base class for non-copyable objects.
Definition: noncopyable.h:23
Packet reader interface.
Definition: ireader.h:23
RTP validator.
Definition: validator.h:38
virtual ROC_ATTR_NODISCARD status::StatusCode read(packet::PacketPtr &pp)
Read next packet.
Validator(packet::IReader &reader, const ValidatorConfig &config, const audio::SampleSpec &sample_spec)
Initialize.
Packet reader interface.
const nanoseconds_t Second
One second represented in nanoseconds.
Definition: time.h:70
int64_t nanoseconds_t
Nanoseconds.
Definition: time.h:58
Root namespace.
Non-copyable object.
Sample specifications.
StatusCode
Status code.
Definition: status_code.h:19
RTP packet.
Definition: rtp.h:24
Validator parameters.
Definition: validator.h:24
core::nanoseconds_t max_ts_jump
Maximum allowed delta between two consecutive packet timestamps, in nanoseconds.
Definition: validator.h:29
size_t max_sn_jump
Maximum allowed delta between two consecutive packet seqnums.
Definition: validator.h:26
Time definitions.