Roc Toolkit internal modules
Roc Toolkit: real-time audio streaming
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
receiver_endpoint.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_pipeline/receiver_endpoint.h
10//! @brief Receiver endpoint pipeline.
11
12#ifndef ROC_PIPELINE_RECEIVER_ENDPOINT_H_
13#define ROC_PIPELINE_RECEIVER_ENDPOINT_H_
14
17#include "roc_core/iarena.h"
18#include "roc_core/mpsc_queue.h"
19#include "roc_core/optional.h"
21#include "roc_core/scoped_ptr.h"
22#include "roc_packet/iparser.h"
23#include "roc_packet/iwriter.h"
24#include "roc_packet/shipper.h"
25#include "roc_pipeline/config.h"
27#include "roc_rtcp/composer.h"
28#include "roc_rtcp/parser.h"
30#include "roc_rtp/parser.h"
31
32namespace roc {
33namespace pipeline {
34
35class ReceiverSessionGroup;
36
37//! Receiver endpoint sub-pipeline.
38//!
39//! Contains:
40//! - a pipeline for processing packets from single network endpoint
41//! - a reference to session group to which packets are routed
42class ReceiverEndpoint : public core::RefCounted<ReceiverEndpoint, core::ArenaAllocation>,
43 public core::ListNode<>,
44 private packet::IWriter {
45public:
46 //! Initialize.
48 StateTracker& state_tracker,
49 ReceiverSessionGroup& session_group,
50 const rtp::EncodingMap& encoding_map,
54
55 //! Check if the port pipeline was succefully constructed.
56 bool is_valid() const;
57
58 //! Get protocol.
60
61 //! Get composer for outbound packets.
62 //! @remarks
63 //! This composer will create packets according to endpoint protocol.
64 //! @note
65 //! Not all protocols support outbound packets on receiver. If it's
66 //! not supported, the method returns NULL.
68
69 //! Get writer for outbound packets.
70 //! This way feedback packets for sender generated by receiver reach network.
71 //! @remarks
72 //! Packets passed to this writer will be enqueued for sending.
73 //! When frame is requested to ReceiverSession, it generates packets
74 //! and writes them to outbound writers of endpoints.
75 //! @note
76 //! Not all protocols support outbound packets on receiver. If it's
77 //! not supported, the method returns NULL.
79
80 //! Get bind address for inbound packets.
82
83 //! Get writer for inbound packets.
84 //! This way packets from network reach receiver pipeline.
85 //! @remarks
86 //! Packets passed to this writer will be pulled into pipeline.
87 //! This writer is thread-safe and lock-free, packets can be written
88 //! to it from netio thread.
90
91 //! Pull packets written to inbound writer into pipeline.
92 //! @remarks
93 //! Packets are written to inbound_writer() from network thread.
94 //! They don't appear in pipeline immediately. Instead, pipeline thread
95 //! should periodically call pull_packets() to make them available.
97
98private:
99 virtual ROC_ATTR_NODISCARD status::StatusCode write(const packet::PacketPtr& packet);
100
101 const address::Protocol proto_;
102
103 StateTracker& state_tracker_;
104 ReceiverSessionGroup& session_group_;
105
106 // Outbound packets sub-pipeline.
107 // On receiver, typically present only in control endpoints.
108 packet::IComposer* composer_;
109 core::Optional<rtcp::Composer> rtcp_composer_;
111
112 // Inbound packets sub-pipeline.
113 // On receiver, always present.
114 packet::IParser* parser_;
115 core::Optional<rtp::Parser> rtp_parser_;
117 core::Optional<rtcp::Parser> rtcp_parser_;
118 address::SocketAddr inbound_address_;
119 core::MpscQueue<packet::Packet> inbound_queue_;
120
121 bool valid_;
122};
123
124} // namespace pipeline
125} // namespace roc
126
127#endif // ROC_PIPELINE_RECEIVER_ENDPOINT_H_
#define ROC_ATTR_NODISCARD
Emit warning if function result is not checked.
Definition attributes.h:31
IArena & arena() const
Get arena.
Memory arena interface.
Definition iarena.h:23
Base class for List element.
Definition list_node.h:48
Base class for object with reference counter.
Definition ref_counted.h:40
Packet composer interface.
Definition icomposer.h:22
Packet parser interface.
Definition iparser.h:22
Packet writer interface.
Definition iwriter.h:23
Receiver endpoint sub-pipeline.
packet::IWriter & inbound_writer()
Get writer for inbound packets. This way packets from network reach receiver pipeline.
ReceiverEndpoint(address::Protocol proto, StateTracker &state_tracker, ReceiverSessionGroup &session_group, const rtp::EncodingMap &encoding_map, const address::SocketAddr &inbound_address, packet::IWriter *outbound_writer, core::IArena &arena)
Initialize.
status::StatusCode pull_packets(core::nanoseconds_t current_time)
Pull packets written to inbound writer into pipeline.
packet::IComposer * outbound_composer()
Get composer for outbound packets.
packet::IWriter * outbound_writer()
Get writer for outbound packets. This way feedback packets for sender generated by receiver reach net...
address::Protocol proto() const
Get protocol.
bool is_valid() const
Check if the port pipeline was succefully constructed.
const address::SocketAddr & inbound_address() const
Get bind address for inbound packets.
Pipeline state tracker.
RTP encoding map. Thread-safe. Returned encodings are immutable and can be safely used from any threa...
RTP encoding map.
Memory arena interface.
Interface ID.
Packet parser interface.
Packet writer interface.
Multi-producer single-consumer queue.
Protocol
Protocol ID.
Definition protocol.h:19
int64_t nanoseconds_t
Nanoseconds.
Definition time.h:58
StatusCode
Status code.
Definition status_code.h:19
Root namespace.
Optionally constructed object.
Protocol ID.
Base class for object with reference counter.
Pipeline config.
RTCP packet composer.
RTCP packet parser.
RTP packet parser.
Unique ownrship pointer.
Prepare and ship outgoing packets.
Pipeline state tracker.