LCOV - code coverage report
Current view: top level - media/server/gstplayer/include - GstMimeMapping.h (source / functions) Coverage Total Hit
Test: coverage.info Lines: 100.0 % 32 32
Test Date: 2025-02-18 13:13:53 Functions: 100.0 % 2 2

            Line data    Source code
       1              : /*
       2              :  * If not stated otherwise in this file or this component's LICENSE file the
       3              :  * following copyright and licenses apply:
       4              :  *
       5              :  * Copyright 2023 Sky UK
       6              :  *
       7              :  * Licensed under the Apache License, Version 2.0 (the "License");
       8              :  * you may not use this file except in compliance with the License.
       9              :  * You may obtain a copy of the License at
      10              :  *
      11              :  * http://www.apache.org/licenses/LICENSE-2.0
      12              :  *
      13              :  * Unless required by applicable law or agreed to in writing, software
      14              :  * distributed under the License is distributed on an "AS IS" BASIS,
      15              :  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
      16              :  * See the License for the specific language governing permissions and
      17              :  * limitations under the License.
      18              :  */
      19              : 
      20              : #ifndef FIREBOLT_RIALTO_SERVER_GST_MIME_MAPPING_H_
      21              : #define FIREBOLT_RIALTO_SERVER_GST_MIME_MAPPING_H_
      22              : 
      23              : #include "GstCapabilities.h"
      24              : #include "IGstWrapper.h"
      25              : #include "IMediaPipeline.h"
      26              : #include <memory>
      27              : #include <string>
      28              : #include <unordered_map>
      29              : #include <unordered_set>
      30              : #include <utility>
      31              : #include <vector>
      32              : 
      33              : namespace firebolt::rialto::server
      34              : {
      35              : 
      36              : /**
      37              :  * @brief Converts MIME types to simple caps.
      38              :  *
      39              :  * @param[in] m_gstWrapper        : Member variable that is a shared pointer to an object of type IGstWrapper
      40              :  * @param[in] m_attachedSource    : A const reference to an object of type MediaSource
      41              :  *
      42              :  * @retval the pointer to the GstCaps object, which represents the simple caps for the given MIME type. If MIME type is
      43              :  * not found, an empty GstCaps object is returned
      44              :  */
      45              : 
      46           16 : inline GstCaps *createSimpleCapsFromMimeType(std::shared_ptr<firebolt::rialto::wrappers::IGstWrapper> m_gstWrapper,
      47              :                                              const IMediaPipeline::MediaSource &m_attachedSource)
      48              : {
      49              :     static const std::unordered_map<std::string, std::string> mimeToMediaType =
      50              :         {{"video/h264", "video/x-h264"},       {"video/h265", "video/x-h265"},
      51              :          {"video/x-av1", "video/x-av1"},       {"video/x-vp9", "video/x-vp9"},
      52              :          {"video/mp4", "video/mpeg"},          {"audio/mp4", "audio/mpeg"},
      53              :          {"audio/aac", "audio/mpeg"},          {"audio/x-eac3", "audio/x-eac3"},
      54              :          {"audio/x-opus", "audio/x-opus"},     {"audio/b-wav", "audio/b-wav"},
      55              :          {"audio/x-raw", "audio/x-raw"},       {"text/vtt", "application/x-subtitle-vtt"},
      56           29 :          {"text/ttml", "application/ttml+xml"}};
      57           16 :     auto mimeToMediaTypeIt = mimeToMediaType.find(m_attachedSource.getMimeType());
      58           16 :     if (mimeToMediaTypeIt != mimeToMediaType.end())
      59              :     {
      60           15 :         return m_gstWrapper->gstCapsNewEmptySimple(mimeToMediaTypeIt->second.c_str());
      61              :     }
      62              : 
      63            1 :     return m_gstWrapper->gstCapsNewEmpty();
      64              : }
      65              : 
      66              : /**
      67              :  * @brief Converts simple caps to MIME types.
      68              :  *
      69              :  * @param[in] supportedCaps    : A const reference to a vector of pointers to GstCaps objects representing the supported caps
      70              :  * @param[in] m_gstWrapper     : Member variable that is a shared pointer to an object of type IGstWrapper
      71              :  *
      72              :  * @retval an unordered set of strings representing the supported MIME types
      73              :  */
      74              : 
      75              : inline std::unordered_set<std::string>
      76           10 : convertFromCapsVectorToMimeSet(const std::vector<GstCaps *> &supportedCaps,
      77              :                                std::shared_ptr<firebolt::rialto::wrappers::IGstWrapper> m_gstWrapper)
      78              : {
      79              :     std::vector<std::pair<GstCaps *, std::vector<std::string>>> capsToMimeVec =
      80           10 :         {{m_gstWrapper->gstCapsFromString("audio/mpeg, mpegversion=(int)4"), {"audio/mp4", "audio/aac", "audio/x-eac3"}},
      81           10 :          {m_gstWrapper->gstCapsFromString("audio/x-eac3"), {"audio/x-eac3"}},
      82           10 :          {m_gstWrapper->gstCapsFromString("audio/b-wav"), {"audio/b-wav"}},
      83           10 :          {m_gstWrapper->gstCapsFromString("audio/x-raw"), {"audio/x-raw"}},
      84           10 :          {m_gstWrapper->gstCapsFromString("audio/x-opus"), {"audio/x-opus"}},
      85           10 :          {m_gstWrapper->gstCapsFromString("audio/x-opus, channel-mapping-family=(int)0"), {"audio/x-opus"}},
      86           10 :          {m_gstWrapper->gstCapsFromString("video/x-av1"), {"video/x-av1"}},
      87           10 :          {m_gstWrapper->gstCapsFromString("video/x-h264"), {"video/h264"}},
      88           10 :          {m_gstWrapper->gstCapsFromString("video/x-h265"), {"video/h265"}},
      89           10 :          {m_gstWrapper->gstCapsFromString("video/x-vp9"), {"video/x-vp9"}},
      90           10 :          {m_gstWrapper->gstCapsFromString("video/mpeg, mpegversion=(int)4"), {"video/mp4"}},
      91           10 :          {m_gstWrapper->gstCapsFromString("video/x-h264(memory:DMABuf)"), {"video/h264"}},
      92           10 :          {m_gstWrapper->gstCapsFromString("video/x-h265(memory:DMABuf)"), {"video/h265"}},
      93           10 :          {m_gstWrapper->gstCapsFromString("video/x-av1(memory:DMABuf)"), {"video/x-av1"}},
      94          630 :          {m_gstWrapper->gstCapsFromString("video/x-vp9(memory:DMABuf)"), {"video/x-vp9"}}};
      95              : 
      96           10 :     std::unordered_set<std::string> supportedMimes;
      97              : 
      98           29 :     for (GstCaps *caps : supportedCaps)
      99              :     {
     100          304 :         for (const auto &capsToMime : capsToMimeVec)
     101              :         {
     102          285 :             if (m_gstWrapper->gstCapsCanIntersect(capsToMime.first, caps))
     103              :             {
     104           17 :                 supportedMimes.insert(capsToMime.second.begin(), capsToMime.second.end());
     105              :             }
     106              :         }
     107              :     }
     108              : 
     109          160 :     for (auto &capsToMime : capsToMimeVec)
     110              :     {
     111          150 :         if (capsToMime.first)
     112          150 :             m_gstWrapper->gstCapsUnref(capsToMime.first);
     113              :     }
     114              : 
     115           20 :     return supportedMimes;
     116           10 : }
     117              : 
     118              : }; // namespace firebolt::rialto::server
     119              : 
     120              : #endif // FIREBOLT_RIALTO_SERVER_GST_MIME_MAPPING_H_
        

Generated by: LCOV version 2.0-1