Roc Toolkit internal modules
Roc Toolkit: real-time audio streaming
receiver_decoder.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/receiver_decoder.h
10 //! @brief Receiver decoder node.
11 
12 #ifndef ROC_NODE_RECEIVER_DECODER_H_
13 #define ROC_NODE_RECEIVER_DECODER_H_
14 
15 #include "roc_address/interface.h"
16 #include "roc_address/protocol.h"
17 #include "roc_core/attributes.h"
18 #include "roc_core/mutex.h"
19 #include "roc_node/context.h"
20 #include "roc_node/node.h"
25 #include "roc_status/status_code.h"
26 
27 namespace roc {
28 namespace node {
29 
30 //! Receiver decoder node.
32 public:
33  //! Initialize.
35  const pipeline::ReceiverSourceConfig& pipeline_config);
36 
37  //! Deinitialize.
39 
40  //! Check if successfully constructed.
41  bool is_valid();
42 
43  //! Get packet factory.
45 
46  //! Activate interface.
48 
49  //! Callback for slot metrics.
50  typedef void (*slot_metrics_func_t)(const pipeline::ReceiverSlotMetrics& slot_metrics,
51  void* slot_arg);
52 
53  //! Callback for participant metrics.
54  typedef void (*party_metrics_func_t)(
55  const pipeline::ReceiverParticipantMetrics& party_metrics,
56  size_t party_index,
57  void* party_arg);
58 
59  //! Get metrics.
61  void* slot_metrics_arg,
62  party_metrics_func_t party_metrics_func,
63  void* party_metrics_arg);
64 
65  //! Write packet for decoding.
67  const packet::PacketPtr& packet);
68 
69  //! Read encoded packet.
70  //! @note
71  //! Typically used to generate control packets with feedback for sender.
73  packet::PacketPtr& packet);
74 
75  //! Source for reading decoded frames.
77 
78 private:
79  virtual void schedule_task_processing(pipeline::PipelineLoop&,
80  core::nanoseconds_t delay);
81  virtual void cancel_task_processing(pipeline::PipelineLoop&);
82 
83  core::Mutex mutex_;
84 
85  address::SocketAddr bind_address_;
86 
90 
91  packet::PacketFactory packet_factory_;
92 
93  pipeline::ReceiverLoop pipeline_;
96 
97  bool valid_;
98 };
99 
100 } // namespace node
101 } // namespace roc
102 
103 #endif // ROC_NODE_RECEIVER_DECODER_H_
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.
Receiver decoder node.
void(* slot_metrics_func_t)(const pipeline::ReceiverSlotMetrics &slot_metrics, void *slot_arg)
Callback for slot metrics.
bool is_valid()
Check if successfully constructed.
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.
packet::PacketFactory & packet_factory()
Get packet factory.
ReceiverDecoder(Context &context, const pipeline::ReceiverSourceConfig &pipeline_config)
Initialize.
ROC_ATTR_NODISCARD bool activate(address::Interface iface, address::Protocol proto)
Activate interface.
sndio::ISource & source()
Source for reading decoded frames.
~ReceiverDecoder()
Deinitialize.
ROC_ATTR_NODISCARD status::StatusCode write_packet(address::Interface iface, const packet::PacketPtr &packet)
Write packet for decoding.
ROC_ATTR_NODISCARD status::StatusCode read_packet(address::Interface iface, packet::PacketPtr &packet)
Read encoded packet.
void(* party_metrics_func_t)(const pipeline::ReceiverParticipantMetrics &party_metrics, size_t party_index, void *party_arg)
Callback for participant metrics.
Pipeline task scheduler interface. PipelineLoop uses this interface to schedule asynchronous work....
Base class for task-based pipelines.
Receiver pipeline loop.
Definition: receiver_loop.h:46
struct SlotHandle * SlotHandle
Opaque slot handle.
Definition: receiver_loop.h:49
Source interface.
Definition: isource.h:23
Concurrent blocking packet queue.
Node context.
Interface ID.
Pipeline task scheduler 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.
Packet factory.
Protocol ID.
Receiver pipeline loop.
Status codes.
StatusCode
Status code.
Definition: status_code.h:19
Receiver-side metrics specific to one participant (remote sender).
Definition: metrics.h:54
Receiver-side metrics of the whole slot.
Definition: metrics.h:66
Parameters of receiver session.
Definition: config.h:184