Line data Source code
1 : /* 2 : * Copyright (C) 2004-2024 Savoir-faire Linux Inc. 3 : * 4 : * Author: Tristan Matthews <tristan.matthews@savoirfairelinux.com> 5 : * Author: Adrien BĂ©raud <adrien.beraud@savoirfairelinux.com> 6 : * 7 : * This program is free software; you can redistribute it and/or modify 8 : * it under the terms of the GNU General Public License as published by 9 : * the Free Software Foundation; either version 3 of the License, or 10 : * (at your option) any later version. 11 : * 12 : * This program is distributed in the hope that it will be useful, 13 : * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 : * GNU General Public License for more details. 16 : * 17 : * You should have received a copy of the GNU General Public License 18 : * along with this program; if not, write to the Free Software 19 : * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 20 : */ 21 : 22 : #pragma once 23 : 24 : #include "media/media_device.h" 25 : #include "media/rtp_session.h" 26 : #include "media/media_stream.h" 27 : 28 : #include "threadloop.h" 29 : 30 : #include <string> 31 : #include <memory> 32 : 33 : namespace jami { 34 : 35 : class AudioInput; 36 : class AudioReceiveThread; 37 : class AudioSender; 38 : class IceSocket; 39 : class MediaRecorder; 40 : class RingBuffer; 41 : 42 : struct RTCPInfo 43 : { 44 : float packetLoss; 45 : unsigned int jitter; 46 : unsigned int nb_sample; 47 : float latency; 48 : }; 49 : 50 : class AudioRtpSession : public RtpSession, public std::enable_shared_from_this<AudioRtpSession> 51 : { 52 : public: 53 : AudioRtpSession(const std::string& callId, 54 : const std::string& streamId, 55 : const std::shared_ptr<MediaRecorder>& rec); 56 : virtual ~AudioRtpSession(); 57 : 58 : void start(std::unique_ptr<dhtnet::IceSocket> rtp_sock, std::unique_ptr<dhtnet::IceSocket> rtcp_sock) override; 59 : void restartSender() override; 60 : void stop() override; 61 : void setMuted(bool muted, Direction dir = Direction::SEND) override; 62 : 63 : void initRecorder() override; 64 : void deinitRecorder() override; 65 : 66 238 : std::shared_ptr<AudioInput>& getAudioLocal() { return audioInput_; } 67 246 : std::unique_ptr<AudioReceiveThread>& getAudioReceive() { return receiveThread_; } 68 : 69 : void setVoiceCallback(std::function<void(bool)> cb); 70 : 71 : private: 72 : void startSender(); 73 : void startReceiver(); 74 : bool check_RCTP_Info_RR(RTCPInfo& rtcpi); 75 : void adaptQualityAndBitrate(); 76 : void dropProcessing(RTCPInfo* rtcpi); 77 : void setNewPacketLoss(unsigned int newPL); 78 : float getPonderateLoss(float lastLoss); 79 : 80 : std::unique_ptr<AudioSender> sender_; 81 : std::unique_ptr<AudioReceiveThread> receiveThread_; 82 : std::shared_ptr<AudioInput> audioInput_; 83 : std::shared_ptr<RingBuffer> ringbuffer_; 84 : uint16_t initSeqVal_ {0}; 85 : bool muteState_ {false}; 86 : unsigned packetLoss_ {10}; 87 : DeviceParams localAudioParams_; 88 : 89 : InterruptedThreadLoop rtcpCheckerThread_; 90 : void processRtcpChecker(); 91 : 92 : // Interval in seconds between RTCP checking 93 408 : std::chrono::seconds rtcp_checking_interval {4}; 94 : 95 : std::function<void(bool)> voiceCallback_; 96 : 97 : void attachRemoteRecorder(const MediaStream& ms); 98 : void attachLocalRecorder(const MediaStream& ms); 99 : }; 100 : 101 : } // namespace jami