LCOV - code coverage report
Current view: top level - foo/src/media - rtp_session.h (source / functions) Hit Total Coverage
Test: jami-coverage-filtered.info Lines: 17 17 100.0 %
Date: 2026-04-01 09:29:43 Functions: 10 11 90.9 %

          Line data    Source code
       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             : 
      27             : namespace jami {
      28             : 
      29             : class MediaRecorder;
      30             : 
      31             : class RtpSession
      32             : {
      33             : public:
      34             :     // Media direction
      35             :     enum class Direction : uint8_t { SEND, RECV };
      36             : 
      37             :     // Note: callId is used for ring buffers and smarttools
      38         666 :     RtpSession(const std::string& callId, const std::string& streamId, MediaType type)
      39         666 :         : callId_(callId)
      40         666 :         , streamId_(streamId)
      41        1332 :         , mediaType_(type)
      42         666 :     {}
      43         666 :     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         327 :     void setMediaSource(const std::string& resource) { input_ = resource; }
      49             :     const std::string& getInput() const { return input_; }
      50        3003 :     MediaType getMediaType() const { return mediaType_; };
      51             :     virtual void setMuted(bool mute, Direction dir = Direction::SEND) = 0;
      52             : 
      53         316 :     virtual void updateMedia(const MediaDescription& send, const MediaDescription& receive)
      54             :     {
      55         316 :         send_ = send;
      56         316 :         receive_ = receive;
      57         316 :     }
      58             : 
      59         316 :     void setMtu(uint16_t mtu) { mtu_ = mtu; }
      60             : 
      61         316 :     void setSuccessfulSetupCb(const std::function<void(MediaType, bool)>& cb) { onSuccessfulSetup_ = cb; }
      62             : 
      63             :     virtual void initRecorder() = 0;
      64             :     virtual void deinitRecorder() = 0;
      65         764 :     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         177 :     inline std::string streamId() const { return streamId_; }
      70             : 
      71             : protected:
      72             :     std::recursive_mutex mutex_;
      73             :     const std::string callId_;
      74             :     const std::string streamId_;
      75             :     MediaType mediaType_;
      76             :     std::unique_ptr<SocketPair> socketPair_;
      77             :     std::string input_ {};
      78             :     MediaDescription send_;
      79             :     MediaDescription receive_;
      80             :     uint16_t mtu_;
      81             :     std::shared_ptr<MediaRecorder> recorder_;
      82             :     std::function<void(MediaType, bool)> onSuccessfulSetup_;
      83             : 
      84         640 :     std::string getRemoteRtpUri() const { return "rtp://" + send_.addr.toString(true); }
      85             : };
      86             : 
      87             : } // namespace jami

Generated by: LCOV version 1.14