Roc Toolkit internal modules
Roc Toolkit: real-time audio streaming
sender_encoder.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_node/sender_encoder.h
10 //! @brief Sender encoder node.
11 
12 #ifndef ROC_NODE_SENDER_ENCODER_H_
13 #define ROC_NODE_SENDER_ENCODER_H_
14 
15 #include "roc_address/interface.h"
16 #include "roc_address/protocol.h"
18 #include "roc_core/atomic.h"
19 #include "roc_core/attributes.h"
20 #include "roc_core/mutex.h"
21 #include "roc_core/optional.h"
22 #include "roc_node/context.h"
23 #include "roc_node/node.h"
25 #include "roc_packet/ireader.h"
29 
30 namespace roc {
31 namespace node {
32 
33 //! Sender encoder node.
35 public:
36  //! Initialize.
38 
39  //! Deinitialize.
41 
42  //! Check if successfully constructed.
43  bool is_valid() const;
44 
45  //! Get packet factory.
47 
48  //! Activate interface.
50 
51  //! Callback for slot metrics.
52  typedef void (*slot_metrics_func_t)(const pipeline::SenderSlotMetrics& slot_metrics,
53  void* slot_arg);
54 
55  //! Callback for participant metrics.
56  typedef void (*party_metrics_func_t)(
57  const pipeline::SenderParticipantMetrics& party_metrics,
58  size_t party_index,
59  void* party_arg);
60 
61  //! Get metrics.
63  void* slot_metrics_arg,
64  party_metrics_func_t party_metrics_func,
65  void* party_metrics_arg);
66 
67  //! Check if everything is connected.
68  bool is_complete();
69 
70  //! Read encoded packet.
72  packet::PacketPtr& packet);
73 
74  //! Write packet for decoding.
75  //! @note
76  //! Typically used to deliver control packets with receiver feedback.
78  const packet::PacketPtr& packet);
79 
80  //! Sink for writing frames for encoding.
82 
83 private:
84  virtual void schedule_task_processing(pipeline::PipelineLoop&,
85  core::nanoseconds_t delay);
86  virtual void cancel_task_processing(pipeline::PipelineLoop&);
87 
88  core::Mutex mutex_;
89 
90  address::SocketAddr dest_address_;
91 
95 
96  packet::PacketFactory packet_factory_;
97 
98  pipeline::SenderLoop pipeline_;
101 
102  bool valid_;
103 };
104 
105 } // namespace node
106 } // namespace roc
107 
108 #endif // ROC_NODE_SENDER_ENCODER_H_
Atomic.
Compiler attributes.
#define ROC_ATTR_NODISCARD
Emit warning if function result is not checked.
Definition: attributes.h:31
Socket address.
Definition: socket_addr.h:26
Atomic integer. Provides sequential consistency. For a fine-grained memory order control,...
Definition: atomic.h:26
Mutex.
Definition: mutex.h:31
Optionally constructed object.
Definition: optional.h:25
Process pending pipeline tasks on control thread.
Definition: control_loop.h:164
Node context.
Definition: context.h:44
Base class for nodes.
Definition: node.h:23
Context & context()
All nodes hold reference to context.
Sender encoder node.
ROC_ATTR_NODISCARD bool activate(address::Interface iface, address::Protocol proto)
Activate interface.
ROC_ATTR_NODISCARD bool get_metrics(slot_metrics_func_t slot_metrics_func, void *slot_metrics_arg, party_metrics_func_t party_metrics_func, void *party_metrics_arg)
Get metrics.
SenderEncoder(Context &context, const pipeline::SenderSinkConfig &pipeline_config)
Initialize.
ROC_ATTR_NODISCARD status::StatusCode read_packet(address::Interface iface, packet::PacketPtr &packet)
Read encoded packet.
sndio::ISink & sink()
Sink for writing frames for encoding.
bool is_valid() const
Check if successfully constructed.
void(* party_metrics_func_t)(const pipeline::SenderParticipantMetrics &party_metrics, size_t party_index, void *party_arg)
Callback for participant metrics.
void(* slot_metrics_func_t)(const pipeline::SenderSlotMetrics &slot_metrics, void *slot_arg)
Callback for slot metrics.
packet::PacketFactory & packet_factory()
Get packet factory.
ROC_ATTR_NODISCARD status::StatusCode write_packet(address::Interface iface, const packet::PacketPtr &packet)
Write packet for decoding.
bool is_complete()
Check if everything is connected.
~SenderEncoder()
Deinitialize.
Pipeline task scheduler interface. PipelineLoop uses this interface to schedule asynchronous work....
Base class for task-based pipelines.
Sender pipeline loop.
Definition: sender_loop.h:44
struct SlotHandle * SlotHandle
Opaque slot handle.
Definition: sender_loop.h:47
Sink interface.
Definition: isink.h:22
Concurrent blocking packet queue.
Node context.
Interface ID.
Pipeline task scheduler interface.
Packet reader interface.
Mutex.
Interface
Interface ID.
Definition: interface.h:19
@ Iface_Max
Number of interfaces.
Definition: interface.h:36
Protocol
Protocol ID.
Definition: protocol.h:19
int64_t nanoseconds_t
Nanoseconds.
Definition: time.h:58
Root namespace.
Base class for nodes.
Optionally constructed object.
Packet factory.
Protocol ID.
Sender pipeline loop.
Socket address.
StatusCode
Status code.
Definition: status_code.h:19
Sender-side metrics specific to one participant (remote receiver).
Definition: metrics.h:24
Parameters of sender sink and sender session.
Definition: config.h:58
Sender-side metrics of the whole slot.
Definition: metrics.h:36