Ring Daemon
Loading...
Searching...
No Matches
audio_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 "media/media_device.h"
20#include "media/rtp_session.h"
21#include "media/media_stream.h"
22
23#include "threadloop.h"
24
25#include <string>
26#include <memory>
27
28namespace jami {
29
30class AudioInput;
31class AudioReceiveThread;
32class AudioSender;
33class IceSocket;
34class MediaRecorder;
35class RingBuffer;
36
38{
40 unsigned int jitter;
41 unsigned int nb_sample;
42 float latency;
43};
44
45class AudioRtpSession : public RtpSession, public std::enable_shared_from_this<AudioRtpSession>
46{
47public:
48 AudioRtpSession(const std::string& callId, const std::string& streamId, const std::shared_ptr<MediaRecorder>& rec);
49 virtual ~AudioRtpSession();
50
51 void start(std::unique_ptr<dhtnet::IceSocket> rtp_sock, std::unique_ptr<dhtnet::IceSocket> rtcp_sock) override;
52 void restartSender() override;
53 void stop() override;
54 void setMuted(bool muted, Direction dir = Direction::SEND) override;
55
56 void initRecorder() override;
57 void deinitRecorder() override;
58
59 std::shared_ptr<AudioInput>& getAudioLocal() { return audioInput_; }
60 std::unique_ptr<AudioReceiveThread>& getAudioReceive() { return receiveThread_; }
61
62 void setVoiceCallback(std::function<void(bool)> cb);
63
64private:
65 void startSender();
66 void startReceiver();
67 bool check_RCTP_Info_RR(RTCPInfo& rtcpi);
68 void adaptQualityAndBitrate();
69 void dropProcessing(RTCPInfo* rtcpi);
70 void setNewPacketLoss(unsigned int newPL);
71 float getPonderateLoss(float lastLoss);
72
73 std::unique_ptr<AudioSender> sender_;
74 std::unique_ptr<AudioReceiveThread> receiveThread_;
75 std::shared_ptr<AudioInput> audioInput_;
76 std::shared_ptr<RingBuffer> ringbuffer_;
77 uint16_t initSeqVal_ {0};
78 bool muteState_ {false};
79 unsigned packetLoss_ {10};
80 DeviceParams localAudioParams_;
81
82 InterruptedThreadLoop rtcpCheckerThread_;
83 void processRtcpChecker();
84
85 // Interval in seconds between RTCP checking
86 std::chrono::seconds rtcp_checking_interval {4};
87
88 std::function<void(bool)> voiceCallback_;
89
90 void attachRemoteRecorder(const MediaStream& ms);
91 void attachLocalRecorder(const MediaStream& ms);
92};
93
94} // namespace jami
void setVoiceCallback(std::function< void(bool)> cb)
void setMuted(bool muted, Direction dir=Direction::SEND) override
void start(std::unique_ptr< dhtnet::IceSocket > rtp_sock, std::unique_ptr< dhtnet::IceSocket > rtcp_sock) override
std::unique_ptr< AudioReceiveThread > & getAudioReceive()
std::shared_ptr< AudioInput > & getAudioLocal()
std::string streamId() const
Definition rtp_session.h:69
void emitSignal(Args... args)
Definition jami_signal.h:64
unsigned int jitter
unsigned int nb_sample