Line data Source code
1 : /* 2 : * Copyright (C) 2004-2024 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 "connectivity/sip_utils.h" 21 : #include "media/media_codec.h" 22 : 23 : #include <functional> 24 : #include <string> 25 : #include <memory> 26 : #include <mutex> 27 : 28 : namespace jami { 29 : 30 : class MediaRecorder; 31 : 32 : class RtpSession 33 : { 34 : public: 35 : // Media direction 36 : enum class Direction { SEND, RECV }; 37 : 38 : // Note: callId is used for ring buffers and smarttools 39 712 : RtpSession(const std::string& callId, const std::string& streamId, MediaType type) 40 712 : : callId_(callId) 41 712 : , streamId_(streamId) 42 1424 : , mediaType_(type) 43 712 : {} 44 712 : 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 353 : void setMediaSource(const std::string& resource) { input_ = resource; } 50 : const std::string& getInput() const { return input_; } 51 2421 : MediaType getMediaType() const { return mediaType_; }; 52 : virtual void setMuted(bool mute, Direction dir = Direction::SEND) = 0; 53 : 54 340 : virtual void updateMedia(const MediaDescription& send, const MediaDescription& receive) 55 : { 56 340 : send_ = send; 57 340 : receive_ = receive; 58 340 : } 59 : 60 340 : void setMtu(uint16_t mtu) { mtu_ = mtu; } 61 : 62 340 : void setSuccessfulSetupCb(const std::function<void(MediaType, bool)>& cb) 63 : { 64 340 : onSuccessfulSetup_ = cb; 65 340 : } 66 : 67 : virtual void initRecorder() = 0; 68 : virtual void deinitRecorder() = 0; 69 826 : 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 185 : inline std::string streamId() const { return streamId_; } 74 : 75 : protected: 76 : std::recursive_mutex mutex_; 77 : const std::string callId_; 78 : const std::string streamId_; 79 : MediaType mediaType_; 80 : std::unique_ptr<SocketPair> socketPair_; 81 : std::string input_ {}; 82 : MediaDescription send_; 83 : MediaDescription receive_; 84 : uint16_t mtu_; 85 : std::shared_ptr<MediaRecorder> recorder_; 86 : std::function<void(MediaType, bool)> onSuccessfulSetup_; 87 : 88 708 : std::string getRemoteRtpUri() const { return "rtp://" + send_.addr.toString(true); } 89 : }; 90 : 91 : } // namespace jami