LCOV - code coverage report
Current view: top level - src/media - media_attribute.h (source / functions) Hit Total Coverage
Test: jami-coverage-filtered.info Lines: 9 9 100.0 %
Date: 2024-12-21 08:56:24 Functions: 1 1 100.0 %

          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             : #ifdef HAVE_CONFIG_H
      20             : #include "config.h"
      21             : #endif
      22             : 
      23             : #include "media/media_codec.h"
      24             : #include "jami.h"
      25             : 
      26             : namespace jami {
      27             : 
      28             : class MediaAttribute
      29             : {
      30             : public:
      31        1026 :     MediaAttribute(MediaType type = MediaType::MEDIA_NONE,
      32             :                    bool muted = false,
      33             :                    bool secure = true,
      34             :                    bool enabled = false,
      35             :                    std::string_view source = {},
      36             :                    std::string_view label = {},
      37             :                    bool onHold = false)
      38        1026 :         : type_(type)
      39        1026 :         , muted_(muted)
      40        1026 :         , secure_(secure)
      41        1026 :         , enabled_(enabled)
      42        1026 :         , sourceUri_(source)
      43        1026 :         , label_(label)
      44        1026 :         , onHold_(onHold)
      45        1026 :     {}
      46             : 
      47             :     MediaAttribute(const libjami::MediaMap& mediaMap, bool secure);
      48             : 
      49             :     static std::vector<MediaAttribute> buildMediaAttributesList(
      50             :         const std::vector<libjami::MediaMap>& mediaList, bool secure);
      51             : 
      52             :     static MediaType stringToMediaType(const std::string& mediaType);
      53             : 
      54             :     static std::pair<bool, MediaType> getMediaType(const libjami::MediaMap& map);
      55             : 
      56             :     static std::pair<bool, bool> getBoolValue(const libjami::MediaMap& mediaMap,
      57             :                                               const std::string& key);
      58             : 
      59             :     static std::pair<bool, std::string> getStringValue(const libjami::MediaMap& mediaMap,
      60             :                                                        const std::string& key);
      61             : 
      62             :     // Return true if at least one media has a matching type.
      63             :     static bool hasMediaType(const std::vector<MediaAttribute>& mediaList, MediaType type);
      64             : 
      65             :     // Return a string of a boolean
      66             :     static char const* boolToString(bool val);
      67             : 
      68             :     // Return a string of the media type
      69             :     static char const* mediaTypeToString(MediaType type);
      70             : 
      71             :     // Convert MediaAttribute to MediaMap
      72             :     static libjami::MediaMap toMediaMap(const MediaAttribute& mediaAttr);
      73             : 
      74             :     // Serialize a vector of MediaAttribute to a vector of MediaMap
      75             :     static std::vector<libjami::MediaMap> mediaAttributesToMediaMaps(
      76             :         std::vector<MediaAttribute> mediaAttrList);
      77             : 
      78             :     std::string toString(bool full = false) const;
      79             : 
      80             :     MediaType type_ {MediaType::MEDIA_NONE};
      81             :     bool muted_ {false};
      82             :     bool secure_ {true};
      83             :     bool enabled_ {false};
      84             :     std::string sourceUri_ {};
      85             :     std::string label_ {};
      86             :     bool onHold_ {false};
      87             : 
      88             :     // NOTE: the hold and mute attributes are related but not
      89             :     // tightly coupled. A hold/unhold operation should always
      90             :     // trigger a new re-invite to notify the change in media
      91             :     // direction. For instance, on an active call, the hold action
      92             :     // would change the media direction attribute from "sendrecv"
      93             :     // to "sendonly". A new SDP with the new media direction will
      94             :     // be generated and sent to the peer in the re-invite.
      95             :     // In contrast, the mute attribute is a local attribute, and
      96             :     // describes the presence (or absence) of the media signal in
      97             :     // the stream. In other words, the mute action can be performed
      98             :     // with or without a media direction change (no re-invite).
      99             :     // For instance, muting the audio can be done by disabling the
     100             :     // audio input (capture) of the encoding session, resulting in
     101             :     // sending RTP packets without actual audio (silence).
     102             : 
     103             :     bool hasValidVideo();
     104             : };
     105             : } // namespace jami

Generated by: LCOV version 1.14