Ring Daemon 16.0.0
Loading...
Searching...
No Matches
rtp_session.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 2004-2025 Savoir-faire Linux Inc.
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <https://www.gnu.org/licenses/>.
16 */
17#pragma once
18
19#include "socket_pair.h"
21#include "media/media_codec.h"
22
23#include <functional>
24#include <string>
25#include <memory>
26#include <mutex>
27
28namespace jami {
29
30class MediaRecorder;
31
33{
34public:
35 // Media direction
36 enum class Direction { SEND, RECV };
37
38 // Note: callId is used for ring buffers and smarttools
39 RtpSession(const std::string& callId, const std::string& streamId, MediaType type)
40 : callId_(callId)
42 , mediaType_(type)
43 {}
44 virtual ~RtpSession() {};
45
46 virtual void start(std::unique_ptr<dhtnet::IceSocket> rtp_sock, std::unique_ptr<dhtnet::IceSocket> rtcp_sock) = 0;
47 virtual void restartSender() = 0;
48 virtual void stop() = 0;
49 void setMediaSource(const std::string& resource) { input_ = resource; }
50 const std::string& getInput() const { return input_; }
51 MediaType getMediaType() const { return mediaType_; };
52 virtual void setMuted(bool mute, Direction dir = Direction::SEND) = 0;
53
54 virtual void updateMedia(const MediaDescription& send, const MediaDescription& receive)
55 {
56 send_ = send;
58 }
59
60 void setMtu(uint16_t mtu) { mtu_ = mtu; }
61
62 void setSuccessfulSetupCb(const std::function<void(MediaType, bool)>& cb)
63 {
65 }
66
67 virtual void initRecorder() = 0;
68 virtual void deinitRecorder() = 0;
69 std::shared_ptr<SystemCodecInfo> getCodec() const { return send_.codec; }
70 const dhtnet::IpAddr& getSendAddr() const { return send_.addr; };
71 const dhtnet::IpAddr& getRecvAddr() const { return receive_.addr; };
72
73 inline std::string streamId() const { return streamId_; }
74
75protected:
76 std::recursive_mutex mutex_;
77 const std::string callId_;
78 const std::string streamId_;
80 std::unique_ptr<SocketPair> socketPair_;
81 std::string input_ {};
85 std::shared_ptr<MediaRecorder> recorder_;
86 std::function<void(MediaType, bool)> onSuccessfulSetup_;
87
88 std::string getRemoteRtpUri() const { return "rtp://" + send_.addr.toString(true); }
89};
90
91} // namespace jami
void setMediaSource(const std::string &resource)
Definition rtp_session.h:49
MediaType mediaType_
Definition rtp_session.h:79
std::string input_
Definition rtp_session.h:81
virtual void initRecorder()=0
std::string getRemoteRtpUri() const
Definition rtp_session.h:88
std::recursive_mutex mutex_
Definition rtp_session.h:76
const std::string callId_
Definition rtp_session.h:77
RtpSession(const std::string &callId, const std::string &streamId, MediaType type)
Definition rtp_session.h:39
virtual void updateMedia(const MediaDescription &send, const MediaDescription &receive)
Definition rtp_session.h:54
MediaDescription receive_
Definition rtp_session.h:83
const std::string streamId_
Definition rtp_session.h:78
const dhtnet::IpAddr & getRecvAddr() const
Definition rtp_session.h:71
virtual void stop()=0
MediaDescription send_
Definition rtp_session.h:82
void setMtu(uint16_t mtu)
Definition rtp_session.h:60
const std::string & getInput() const
Definition rtp_session.h:50
virtual void start(std::unique_ptr< dhtnet::IceSocket > rtp_sock, std::unique_ptr< dhtnet::IceSocket > rtcp_sock)=0
std::function< void(MediaType, bool)> onSuccessfulSetup_
Definition rtp_session.h:86
std::string streamId() const
Definition rtp_session.h:73
void setSuccessfulSetupCb(const std::function< void(MediaType, bool)> &cb)
Definition rtp_session.h:62
std::shared_ptr< SystemCodecInfo > getCodec() const
Definition rtp_session.h:69
virtual ~RtpSession()
Definition rtp_session.h:44
virtual void setMuted(bool mute, Direction dir=Direction::SEND)=0
virtual void restartSender()=0
std::unique_ptr< SocketPair > socketPair_
Definition rtp_session.h:80
const dhtnet::IpAddr & getSendAddr() const
Definition rtp_session.h:70
std::shared_ptr< MediaRecorder > recorder_
Definition rtp_session.h:85
MediaType getMediaType() const
Definition rtp_session.h:51
virtual void deinitRecorder()=0
void emitSignal(Args... args)
Definition ring_signal.h:64
MediaDescription Negotiated RTP media slot.
dhtnet::IpAddr addr
Endpoint socket address.
std::shared_ptr< SystemCodecInfo > codec
RTP.