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

            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          674 :     RtpSession(const std::string& callId, const std::string& streamId, MediaType type)
      39          674 :         : callId_(callId)
      40          674 :         , streamId_(streamId)
      41         1348 :         , mediaType_(type)
      42          674 :     {}
      43          674 :     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          329 :     void setMediaSource(const std::string& resource) { input_ = resource; }
      49              :     const std::string& getInput() const { return input_; }
      50         3041 :     MediaType getMediaType() const { return mediaType_; };
      51              :     virtual void setMuted(bool mute, Direction dir = Direction::SEND) = 0;
      52              : 
      53          318 :     virtual void updateMedia(const MediaDescription& send, const MediaDescription& receive)
      54              :     {
      55          318 :         send_ = send;
      56          318 :         receive_ = receive;
      57          318 :     }
      58              : 
      59          318 :     void setMtu(uint16_t mtu) { mtu_ = mtu; }
      60              : 
      61          318 :     void setSuccessfulSetupCb(const std::function<void(MediaType, bool)>& cb) { onSuccessfulSetup_ = cb; }
      62              : 
      63              :     virtual void initRecorder() = 0;
      64              :     virtual void deinitRecorder() = 0;
      65          780 :     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          183 :     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          320 :     std::string getRemoteRtpUri() const { return "rtp://" + send_.addr.toString(true); }
      85              : };
      86              : 
      87              : } // namespace jami
        

Generated by: LCOV version 2.0-1