RAVENNAKIT
Loading...
Searching...
No Matches
ravenna_receiver.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: AGPL-3.0-or-later
2/*
3 * Project: RAVENNAKIT (RAVENNA / AES67 / ST2110-30 SDK)
4 * Copyright (c) 2024-2025 Sound on Digital
5 *
6 * This file is part of RAVENNAKIT.
7 *
8 * RAVENNAKIT is dual-licensed:
9 * 1) Under the terms of the GNU Affero General Public License as published by
10 * the Free Software Foundation, either version 3 of the License, or
11 * (at your option) any later version (the "AGPL License"); and
12 * 2) Under a commercial license from Sound on Digital, for customers who
13 * cannot (or do not wish to) comply with the AGPL License terms.
14 *
15 * If you obtained this file under the AGPL License, you may redistribute it
16 * and/or modify it under the terms of the AGPL License. See the LICENSE
17 * file in the project root for details.
18 *
19 * For commercial licensing, support, and other inquiries, please visit:
20 *
21 * https://ravennakit.com
22 *
23 */
24
25#pragma once
26
34
35namespace rav {
36
38 public:
41
48 std::string session_name;
49 uint32_t delay_frames {};
50 bool enabled {};
51 bool auto_update_sdp {true}; // When true, the receiver will connect to the RTSP server for SDP updates.
52
54 return Configuration {{}, {}, 480, true, true};
55 }
56 };
57
61 class Subscriber {
62 public:
63 virtual ~Subscriber() = default;
64
70 std::ignore = parameters;
71 }
72
78 virtual void ravenna_receiver_configuration_updated(const RavennaReceiver& receiver, const Configuration& configuration) {
79 std::ignore = receiver;
80 std::ignore = configuration;
81 }
82
90 ) {
91 std::ignore = stream_info;
92 std::ignore = state;
93 }
94
101 virtual void ravenna_receiver_stream_stats_updated(Id receiver_id, size_t stream_index, const rtp::PacketStats::Counters& stats) {
102 std::ignore = receiver_id;
103 std::ignore = stream_index;
104 std::ignore = stats;
105 }
106 };
107
109 RavennaRtspClient& rtsp_client, rtp::AudioReceiver& rtp_audio_receiver, Id id, NetworkInterfaceConfig network_interface_config
110 );
112
115
116 RavennaReceiver(RavennaReceiver&&) noexcept = delete;
117 RavennaReceiver& operator=(RavennaReceiver&&) noexcept = delete;
118
122 [[nodiscard]] Id get_id() const;
123
127 [[nodiscard]] const boost::uuids::uuid& get_uuid() const;
128
134 [[nodiscard]] tl::expected<void, std::string> set_configuration(Configuration config);
135
139 [[nodiscard]] const Configuration& get_configuration() const;
140
146 [[nodiscard]] bool subscribe(Subscriber* subscriber);
147
153 [[nodiscard]] bool unsubscribe(const Subscriber* subscriber);
154
159 void set_nmos_node(nmos::Node* nmos_node);
160
165 void set_nmos_device_id(const boost::uuids::uuid& device_id);
166
170 [[nodiscard]] std::optional<sdp::SessionDescription> get_sdp() const;
171
176 [[nodiscard]] std::optional<std::string> get_sdp_text() const;
177
183
187 [[nodiscard]] boost::json::object to_boost_json() const;
188
194 [[nodiscard]] tl::expected<void, std::string> restore_from_json(const boost::json::value& json);
195
199 [[nodiscard]] const nmos::ReceiverAudio& get_nmos_receiver() const;
200
205
206 // ravenna_rtsp_client::subscriber overrides
207 void on_announced(const RavennaRtspClient::AnnouncedEvent& event) override;
208
209 private:
210 RavennaRtspClient& rtsp_client_;
211 rtp::AudioReceiver& rtp_audio_receiver_;
212 nmos::Node* nmos_node_ {nullptr};
213 const Id id_;
214 Configuration configuration_;
215 NetworkInterfaceConfig network_interface_config_;
216 nmos::ReceiverAudio nmos_receiver_;
217 SubscriberList<Subscriber> subscribers_;
218 rtp::AudioReceiver::ReaderParameters reader_parameters_;
219 std::array<rtp::AudioReceiver::StreamState, rtp::AudioReceiver::k_max_num_redundant_sessions> streams_states_ {};
220 Throttle<void> stats_throttle_ {std::chrono::seconds(1)};
221
222 void handle_announced_sdp(const sdp::SessionDescription& sdp);
223 tl::expected<void, std::string> update_nmos();
224 tl::expected<void, std::string> update_rtsp();
225 tl::expected<void, nmos::ApiError> handle_patch_request(const boost::json::value& patch_request);
226};
227
233tl::expected<rtp::AudioReceiver::ReaderParameters, std::string> create_rtp_receiver_parameters(const sdp::SessionDescription& sdp);
234
235void tag_invoke(const boost::json::value_from_tag&, boost::json::value& jv, const RavennaReceiver::Configuration& config);
236
237RavennaReceiver::Configuration tag_invoke(const boost::json::value_to_tag<RavennaReceiver::Configuration>&, const boost::json::value& jv);
238
239} // namespace rav
A class which represents a unique identifier.
Definition id.hpp:38
Baseclass for other classes which want to receive changes to the stream.
virtual void ravenna_receiver_stream_state_updated(const rtp::AudioReceiver::StreamInfo &stream_info, const rtp::AudioReceiver::StreamState state)
Called when the state of a stream has changed.
virtual void ravenna_receiver_parameters_updated(const rtp::AudioReceiver::ReaderParameters &parameters)
Called when the stream has changed.
virtual void ravenna_receiver_stream_stats_updated(Id receiver_id, size_t stream_index, const rtp::PacketStats::Counters &stats)
Called when the stats of a stream have been updated.
virtual void ravenna_receiver_configuration_updated(const RavennaReceiver &receiver, const Configuration &configuration)
Called when the configuration of the stream has changed.
bool unsubscribe(const Subscriber *subscriber)
Removes a subscriber from the receiver.
std::optional< std::string > get_sdp_text() const
RavennaReceiver(const RavennaReceiver &)=delete
std::optional< sdp::SessionDescription > get_sdp() const
void set_network_interface_config(NetworkInterfaceConfig network_interface_config)
Sets the network interface config for the receiver.
void on_announced(const RavennaRtspClient::AnnouncedEvent &event) override
Called when a session is announced.
RavennaReceiver(RavennaReceiver &&) noexcept=delete
bool subscribe(Subscriber *subscriber)
Adds a subscriber to the receiver.
void do_maintenance()
Call regularly from the maintenance thread.
tl::expected< void, std::string > set_configuration(Configuration config)
Updates the configuration of the receiver.
const nmos::ReceiverAudio & get_nmos_receiver() const
tl::expected< void, std::string > restore_from_json(const boost::json::value &json)
Restores the receiver from a JSON representation.
boost::json::object to_boost_json() const
void set_nmos_node(nmos::Node *nmos_node)
Sets the NMOS node for the receiver.
static constexpr auto k_supported_encodings
List of supported audio encodings for the sender.
void set_nmos_device_id(const boost::uuids::uuid &device_id)
Sets the NMOS device ID for the receiver.
const boost::uuids::uuid & get_uuid() const
RavennaReceiver(RavennaRtspClient &rtsp_client, rtp::AudioReceiver &rtp_audio_receiver, Id id, NetworkInterfaceConfig network_interface_config)
~RavennaReceiver() override
RavennaReceiver & operator=(const RavennaReceiver &)=delete
const Configuration & get_configuration() const
Maintains connections to one or more RAVENNA RTSP servers, upon request.
Super basic list of subscribers.
void tag_invoke(const boost::json::value_from_tag &, boost::json::value &jv, const RavennaReceiver::Configuration &config)
tl::expected< rtp::AudioReceiver::ReaderParameters, std::string > create_rtp_receiver_parameters(const sdp::SessionDescription &sdp)
Creates rtp receiver parameters from the given SDP.
Defines the configuration for the receiver.
Describes an audio Receiver.
StreamState
The state of a reader.
A struct that represents an SDP session description as defined in RFC 8866.