Roc Toolkit internal modules
Roc Toolkit: real-time audio streaming
Loading...
Searching...
No Matches
filter.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/filter.h
10//! @brief RTP filter.
11
12#ifndef ROC_RTP_FILTER_H_
13#define ROC_RTP_FILTER_H_
14
18#include "roc_core/time.h"
19#include "roc_packet/ireader.h"
20
21namespace roc {
22namespace rtp {
23
24//! RTP filter parameters.
26 //! Maximum allowed delta between two consecutive packet seqnums.
27 //! If exceeded, packet is dropped.
29
30 //! Maximum allowed delta between two consecutive packet timestamps, in nanoseconds.
31 //! If exceeded, packet is dropped.
33
35 : max_sn_jump(100)
36 , max_ts_jump(core::Second) {
37 }
38};
39
40//! RTP filter.
41//!
42//! Performs initial validation and initialization of incoming sequence
43//! of RTP packets.
44//!
45//! - Validates sequence of incoming RTP packets and detects disturbances,
46//! like seqnum jumps, timestamp jumps, SSRC changes, etc.
47//!
48//! - Populates local fields (that are not carried over network),
49//! currently packet duration (based on provided payload decoder).
50class Filter : public packet::IReader, public core::NonCopyable<> {
51public:
52 //! Initialize.
53 //!
54 //! @b Parameters
55 //! - @p reader is used to read input packets
56 //! - @p decoder is used to query parameters of packets
57 //! - @p config defines filtering parameters
58 //! - @p sample_spec defines stream sample spec
60 audio::IFrameDecoder& decoder,
61 const FilterConfig& config,
62 const audio::SampleSpec& sample_spec);
63
64 //! Read next packet.
66
67private:
68 bool validate_(const packet::PacketPtr& packet);
69 void populate_(const packet::PacketPtr& packet);
70
71 bool validate_sequence_(const packet::RTP& prev, const packet::RTP& next) const;
72
73 packet::IReader& reader_;
74 audio::IFrameDecoder& decoder_;
75
76 bool has_prev_packet_;
77 packet::RTP prev_packet_rtp_;
78
79 const FilterConfig config_;
80 const audio::SampleSpec sample_spec_;
81};
82
83} // namespace rtp
84} // namespace roc
85
86#endif // ROC_RTP_FILTER_H_
#define ROC_ATTR_NODISCARD
Emit warning if function result is not checked.
Definition attributes.h:31
Audio frame decoder interface.
Sample specification. Describes sample rate and channels.
Definition sample_spec.h:30
Base class for non-copyable objects.
Definition noncopyable.h:23
Packet reader interface.
Definition ireader.h:23
RTP filter.
Definition filter.h:50
Filter(packet::IReader &reader, audio::IFrameDecoder &decoder, const FilterConfig &config, const audio::SampleSpec &sample_spec)
Initialize.
virtual status::StatusCode read(packet::PacketPtr &pp)
Read next packet.
Audio frame decoder interface.
Packet reader interface.
int64_t nanoseconds_t
Nanoseconds.
Definition time.h:58
StatusCode
Status code.
Definition status_code.h:19
Root namespace.
Non-copyable object.
Sample specifications.
RTP packet.
Definition rtp.h:24
RTP filter parameters.
Definition filter.h:25
size_t max_sn_jump
Maximum allowed delta between two consecutive packet seqnums. If exceeded, packet is dropped.
Definition filter.h:28
core::nanoseconds_t max_ts_jump
Maximum allowed delta between two consecutive packet timestamps, in nanoseconds. If exceeded,...
Definition filter.h:32
Time definitions.