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-04-25 08:05:53 Functions: 1 1 100.0 %

          Line data    Source code
       1             : /*
       2             :  *  Copyright (C) 2021-2024 Savoir-faire Linux Inc.
       3             :  *
       4             :  *  Author: Mohamed Chibani <mohamed.chibani@savoirfairelinux.com>
       5             :  *
       6             :  *  This program is free software; you can redistribute it and/or modify
       7             :  *  it under the terms of the GNU General Public License as published by
       8             :  *  the Free Software Foundation; either version 3 of the License, or
       9             :  *  (at your option) any later version.
      10             :  *
      11             :  *  This program is distributed in the hope that it will be useful,
      12             :  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
      13             :  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      14             :  *  GNU General Public License for more details.
      15             :  *
      16             :  *  You should have received a copy of the GNU General Public License
      17             :  *  along with this program; if not, write to the Free Software
      18             :  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 USA.
      19             :  */
      20             : 
      21             : #pragma once
      22             : 
      23             : #ifdef HAVE_CONFIG_H
      24             : #include "config.h"
      25             : #endif
      26             : 
      27             : #include "media/media_codec.h"
      28             : #include "jami.h"
      29             : 
      30             : namespace jami {
      31             : 
      32             : class MediaAttribute
      33             : {
      34             : public:
      35         854 :     MediaAttribute(MediaType type = MediaType::MEDIA_NONE,
      36             :                    bool muted = false,
      37             :                    bool secure = true,
      38             :                    bool enabled = false,
      39             :                    std::string_view source = {},
      40             :                    std::string_view label = {},
      41             :                    bool onHold = false)
      42         854 :         : type_(type)
      43         854 :         , muted_(muted)
      44         854 :         , secure_(secure)
      45         854 :         , enabled_(enabled)
      46         854 :         , sourceUri_(source)
      47         854 :         , label_(label)
      48         854 :         , onHold_(onHold)
      49         854 :     {}
      50             : 
      51             :     MediaAttribute(const libjami::MediaMap& mediaMap, bool secure);
      52             : 
      53             :     static std::vector<MediaAttribute> buildMediaAttributesList(
      54             :         const std::vector<libjami::MediaMap>& mediaList, bool secure);
      55             : 
      56             :     static MediaType stringToMediaType(const std::string& mediaType);
      57             : 
      58             :     static std::pair<bool, MediaType> getMediaType(const libjami::MediaMap& map);
      59             : 
      60             :     static std::pair<bool, bool> getBoolValue(const libjami::MediaMap& mediaMap,
      61             :                                               const std::string& key);
      62             : 
      63             :     static std::pair<bool, std::string> getStringValue(const libjami::MediaMap& mediaMap,
      64             :                                                        const std::string& key);
      65             : 
      66             :     // Return true if at least one media has a matching type.
      67             :     static bool hasMediaType(const std::vector<MediaAttribute>& mediaList, MediaType type);
      68             : 
      69             :     // Return a string of a boolean
      70             :     static char const* boolToString(bool val);
      71             : 
      72             :     // Return a string of the media type
      73             :     static char const* mediaTypeToString(MediaType type);
      74             : 
      75             :     // Convert MediaAttribute to MediaMap
      76             :     static libjami::MediaMap toMediaMap(const MediaAttribute& mediaAttr);
      77             : 
      78             :     // Serialize a vector of MediaAttribute to a vector of MediaMap
      79             :     static std::vector<libjami::MediaMap> mediaAttributesToMediaMaps(
      80             :         std::vector<MediaAttribute> mediaAttrList);
      81             : 
      82             :     std::string toString(bool full = false) const;
      83             : 
      84             :     MediaType type_ {MediaType::MEDIA_NONE};
      85             :     bool muted_ {false};
      86             :     bool secure_ {true};
      87             :     bool enabled_ {false};
      88             :     std::string sourceUri_ {};
      89             :     std::string label_ {};
      90             :     bool onHold_ {false};
      91             : 
      92             :     // NOTE: the hold and mute attributes are related but not
      93             :     // tightly coupled. A hold/un-hold operation should always
      94             :     // trigger a new re-invite to notify the change in media
      95             :     // direction.For instance, on an active call, the hold action
      96             :     // would change the media direction attribute from "sendrecv"
      97             :     // to "sendonly". A new SDP with the new media direction will
      98             :     // be generated and sent to the peer in the re-invite.
      99             :     // In contrast, the mute attribute is a local attribute, and
     100             :     // describes the presence (or absence) of the media signal in
     101             :     // the stream. In other words, the mute action can be performed
     102             :     // with or without a media direction change (no re-invite).
     103             :     // For instance, muting the audio can be done by disabling the
     104             :     // audio input (capture) of the encoding session, resulting in
     105             :     // sending RTP packets without actual audio (silence).
     106             : 
     107             :     bool hasValidVideo();
     108             : };
     109             : } // namespace jami

Generated by: LCOV version 1.14