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: Guillaume Roguez <Guillaume.Roguez@savoirfairelinux.com> 6 : * Author: Philippe Gorley <philippe.gorley@savoirfairelinux.com> 7 : * 8 : * This program is free software; you can redistribute it and/or modify 9 : * it under the terms of the GNU General Public License as published by 10 : * the Free Software Foundation; either version 3 of the License, or 11 : * (at your option) any later version. 12 : * 13 : * This program is distributed in the hope that it will be useful, 14 : * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 : * GNU General Public License for more details. 17 : * 18 : * You should have received a copy of the GNU General Public License 19 : * along with this program; if not, write to the Free Software 20 : * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 21 : */ 22 : 23 : #pragma once 24 : 25 : #include "socket_pair.h" 26 : #include "connectivity/sip_utils.h" 27 : #include "media/media_codec.h" 28 : 29 : #include <functional> 30 : #include <string> 31 : #include <memory> 32 : #include <mutex> 33 : 34 : namespace jami { 35 : 36 : class MediaRecorder; 37 : 38 : class RtpSession 39 : { 40 : public: 41 : // Media direction 42 : enum class Direction { SEND, RECV }; 43 : 44 : // Note: callId is used for ring buffers and smarttools 45 732 : RtpSession(const std::string& callId, const std::string& streamId, MediaType type) 46 732 : : callId_(callId) 47 732 : , streamId_(streamId) 48 1464 : , mediaType_(type) 49 732 : {} 50 732 : virtual ~RtpSession() {}; 51 : 52 : virtual void start(std::unique_ptr<dhtnet::IceSocket> rtp_sock, std::unique_ptr<dhtnet::IceSocket> rtcp_sock) = 0; 53 : virtual void restartSender() = 0; 54 : virtual void stop() = 0; 55 354 : void setMediaSource(const std::string& resource) { input_ = resource; } 56 : const std::string& getInput() const { return input_; } 57 2419 : MediaType getMediaType() const { return mediaType_; }; 58 : virtual void setMuted(bool mute, Direction dir = Direction::SEND) = 0; 59 : 60 334 : virtual void updateMedia(const MediaDescription& send, const MediaDescription& receive) 61 : { 62 334 : send_ = send; 63 334 : receive_ = receive; 64 334 : } 65 : 66 334 : void setMtu(uint16_t mtu) { mtu_ = mtu; } 67 : 68 334 : void setSuccessfulSetupCb(const std::function<void(MediaType, bool)>& cb) 69 : { 70 334 : onSuccessfulSetup_ = cb; 71 334 : } 72 : 73 : virtual void initRecorder() = 0; 74 : virtual void deinitRecorder() = 0; 75 877 : std::shared_ptr<SystemCodecInfo> getCodec() const { return send_.codec; } 76 : const dhtnet::IpAddr& getSendAddr() const { return send_.addr; }; 77 : const dhtnet::IpAddr& getRecvAddr() const { return receive_.addr; }; 78 : 79 218 : inline std::string streamId() const { return streamId_; } 80 : 81 : protected: 82 : std::recursive_mutex mutex_; 83 : const std::string callId_; 84 : const std::string streamId_; 85 : MediaType mediaType_; 86 : std::unique_ptr<SocketPair> socketPair_; 87 : std::string input_ {}; 88 : MediaDescription send_; 89 : MediaDescription receive_; 90 : uint16_t mtu_; 91 : std::shared_ptr<MediaRecorder> recorder_; 92 : std::function<void(MediaType, bool)> onSuccessfulSetup_; 93 : 94 704 : std::string getRemoteRtpUri() const { return "rtp://" + send_.addr.toString(true); } 95 : }; 96 : 97 : } // namespace jami