Ring Daemon
Loading...
Searching...
No Matches
rtp_session.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 2004-2026 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"
20#include "media/media_codec.h"
21
22#include <functional>
23#include <string>
24#include <memory>
25#include <mutex>
26
27namespace jami {
28
29class MediaRecorder;
30
32{
33public:
34 // Media direction
35 enum class Direction : uint8_t { SEND, RECV };
36
37 // Note: callId is used for ring buffers and smarttools
38 RtpSession(const std::string& callId, const std::string& streamId, MediaType type)
39 : callId_(callId)
41 , mediaType_(type)
42 {}
43 virtual ~RtpSession() {};
44
45 virtual void start(std::unique_ptr<dhtnet::IceSocket> rtp_sock, std::unique_ptr<dhtnet::IceSocket> rtcp_sock) = 0;
46 virtual void restartSender() = 0;
47 virtual void stop() = 0;
48 void setMediaSource(const std::string& resource) { input_ = resource; }
49 const std::string& getInput() const { return input_; }
50 MediaType getMediaType() const { return mediaType_; };
51 virtual void setMuted(bool mute, Direction dir = Direction::SEND) = 0;
52
53 virtual void updateMedia(const MediaDescription& send, const MediaDescription& receive)
54 {
55 send_ = send;
57 }
58
59 void setMtu(uint16_t mtu) { mtu_ = mtu; }
60
61 void setSuccessfulSetupCb(const std::function<void(MediaType, bool)>& cb) { onSuccessfulSetup_ = cb; }
62
63 virtual void initRecorder() = 0;
64 virtual void deinitRecorder() = 0;
65 std::shared_ptr<SystemCodecInfo> getCodec() const { return send_.codec; }
66 const dhtnet::IpAddr& getSendAddr() const { return send_.addr; };
67 const dhtnet::IpAddr& getRecvAddr() const { return receive_.addr; };
68
69 inline std::string streamId() const { return streamId_; }
70
71protected:
72 std::recursive_mutex mutex_;
73 const std::string callId_;
74 const std::string streamId_;
76 std::unique_ptr<SocketPair> socketPair_;
77 std::string input_ {};
81 std::shared_ptr<MediaRecorder> recorder_;
82 std::function<void(MediaType, bool)> onSuccessfulSetup_;
83
84 std::string getRemoteRtpUri() const { return "rtp://" + send_.addr.toString(true); }
85};
86
87} // namespace jami
void setMediaSource(const std::string &resource)
Definition rtp_session.h:48
MediaType mediaType_
Definition rtp_session.h:75
std::string input_
Definition rtp_session.h:77
virtual void initRecorder()=0
std::string getRemoteRtpUri() const
Definition rtp_session.h:84
std::recursive_mutex mutex_
Definition rtp_session.h:72
const std::string callId_
Definition rtp_session.h:73
RtpSession(const std::string &callId, const std::string &streamId, MediaType type)
Definition rtp_session.h:38
virtual void updateMedia(const MediaDescription &send, const MediaDescription &receive)
Definition rtp_session.h:53
MediaDescription receive_
Definition rtp_session.h:79
const std::string streamId_
Definition rtp_session.h:74
const dhtnet::IpAddr & getRecvAddr() const
Definition rtp_session.h:67
virtual void stop()=0
MediaDescription send_
Definition rtp_session.h:78
void setMtu(uint16_t mtu)
Definition rtp_session.h:59
const std::string & getInput() const
Definition rtp_session.h:49
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:82
std::string streamId() const
Definition rtp_session.h:69
void setSuccessfulSetupCb(const std::function< void(MediaType, bool)> &cb)
Definition rtp_session.h:61
std::shared_ptr< SystemCodecInfo > getCodec() const
Definition rtp_session.h:65
virtual ~RtpSession()
Definition rtp_session.h:43
virtual void setMuted(bool mute, Direction dir=Direction::SEND)=0
virtual void restartSender()=0
std::unique_ptr< SocketPair > socketPair_
Definition rtp_session.h:76
const dhtnet::IpAddr & getSendAddr() const
Definition rtp_session.h:66
std::shared_ptr< MediaRecorder > recorder_
Definition rtp_session.h:81
MediaType getMediaType() const
Definition rtp_session.h:50
virtual void deinitRecorder()=0
void emitSignal(Args... args)
Definition jami_signal.h:64
MediaDescription Negotiated RTP media slot.
dhtnet::IpAddr addr
Endpoint socket address.
std::shared_ptr< SystemCodecInfo > codec
RTP.