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 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_core/noncopyable.h"
16 #include "roc_core/time.h"
17 #include "roc_packet/ireader.h"
18 
19 namespace roc {
20 namespace rtp {
21 
22 //! Validator parameters.
24  //! Maximum allowed delta between two consecutive packet seqnums.
25  size_t max_sn_jump;
26 
27  //! Maximum allowed delta between two consecutive packet timestamps, in nanoseconds.
29 
31  : max_sn_jump(100)
32  , max_ts_jump(core::Second) {
33  }
34 };
35 
36 //! RTP validator.
37 class Validator : public packet::IReader, public core::NonCopyable<> {
38 public:
39  //! Initialize.
40  //!
41  //! @b Parameters
42  //! - @p reader is input packet reader
43  //! - @p config defines validator parameters
44  //! - @p sample_rate defines session sample rate
45  Validator(packet::IReader& reader, const ValidatorConfig& config, size_t sample_rate);
46 
47  //! Read next packet.
48  //! @remarks
49  //! Reads packet from the underlying reader and validates it. If the packet
50  //! is valid, return it. Otherwise, returns NULL.
51  virtual packet::PacketPtr read();
52 
53 private:
54  bool check_(const packet::RTP& prev, const packet::RTP& next) const;
55 
56  packet::IReader& reader_;
57  packet::PacketPtr prev_packet_;
58 
59  const ValidatorConfig config_;
60  const size_t sample_rate_;
61 };
62 
63 } // namespace rtp
64 } // namespace roc
65 
66 #endif // ROC_RTP_VALIDATOR_H_
Validator parameters.
Definition: validator.h:23
core::nanoseconds_t max_ts_jump
Maximum allowed delta between two consecutive packet timestamps, in nanoseconds.
Definition: validator.h:28
Packet reader interface.
Time definitions.
RTP validator.
Definition: validator.h:37
Packet reader interface.
Definition: ireader.h:21
Root namespace.
int64_t nanoseconds_t
Nanoseconds.
Definition: time.h:21
RTP packet.
Definition: rtp.h:23
Base class for non-copyable objects.
Definition: noncopyable.h:23
const nanoseconds_t Second
One second represented in nanoseconds.
Definition: time.h:33
Non-copyable object.
size_t max_sn_jump
Maximum allowed delta between two consecutive packet seqnums.
Definition: validator.h:25