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 % 33 33
Test Date: 2025-06-05 13:57:59 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           17 : 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 = {{"video/h264", "video/x-h264"},
      50              :                                                                                  {"video/h265", "video/x-h265"},
      51              :                                                                                  {"video/x-av1", "video/x-av1"},
      52              :                                                                                  {"video/x-vp9", "video/x-vp9"},
      53              :                                                                                  {"video/mp4", "video/mpeg"},
      54              :                                                                                  {"audio/mp4", "audio/mpeg"},
      55              :                                                                                  {"audio/aac", "audio/mpeg"},
      56              :                                                                                  {"audio/x-eac3", "audio/x-eac3"},
      57              :                                                                                  {"audio/x-opus", "audio/x-opus"},
      58              :                                                                                  {"audio/b-wav", "audio/b-wav"},
      59              :                                                                                  {"audio/x-raw", "audio/x-raw"},
      60              :                                                                                  {"audio/x-flac", "audio/x-flac"},
      61              :                                                                                  {"text/vtt",
      62              :                                                                                   "application/x-subtitle-vtt"},
      63           33 :                                                                                  {"text/ttml", "application/ttml+xml"}};
      64           17 :     auto mimeToMediaTypeIt = mimeToMediaType.find(m_attachedSource.getMimeType());
      65           17 :     if (mimeToMediaTypeIt != mimeToMediaType.end())
      66              :     {
      67           16 :         return m_gstWrapper->gstCapsNewEmptySimple(mimeToMediaTypeIt->second.c_str());
      68              :     }
      69              : 
      70            1 :     return m_gstWrapper->gstCapsNewEmpty();
      71              : }
      72              : 
      73              : /**
      74              :  * @brief Converts simple caps to MIME types.
      75              :  *
      76              :  * @param[in] supportedCaps    : A const reference to a vector of pointers to GstCaps objects representing the supported caps
      77              :  * @param[in] m_gstWrapper     : Member variable that is a shared pointer to an object of type IGstWrapper
      78              :  *
      79              :  * @retval an unordered set of strings representing the supported MIME types
      80              :  */
      81              : 
      82              : inline std::unordered_set<std::string>
      83           10 : convertFromCapsVectorToMimeSet(const std::vector<GstCaps *> &supportedCaps,
      84              :                                std::shared_ptr<firebolt::rialto::wrappers::IGstWrapper> m_gstWrapper)
      85              : {
      86              :     std::vector<std::pair<GstCaps *, std::vector<std::string>>> capsToMimeVec =
      87           10 :         {{m_gstWrapper->gstCapsFromString("audio/mpeg, mpegversion=(int)4"), {"audio/mp4", "audio/aac", "audio/x-eac3"}},
      88           10 :          {m_gstWrapper->gstCapsFromString("audio/x-eac3"), {"audio/x-eac3"}},
      89           10 :          {m_gstWrapper->gstCapsFromString("audio/b-wav"), {"audio/b-wav"}},
      90           10 :          {m_gstWrapper->gstCapsFromString("audio/x-raw"), {"audio/x-raw"}},
      91           10 :          {m_gstWrapper->gstCapsFromString("audio/x-opus"), {"audio/x-opus"}},
      92           10 :          {m_gstWrapper->gstCapsFromString("audio/x-opus, channel-mapping-family=(int)0"), {"audio/x-opus"}},
      93           10 :          {m_gstWrapper->gstCapsFromString("audio/x-flac"), {"audio/x-flac"}},
      94           10 :          {m_gstWrapper->gstCapsFromString("video/x-av1"), {"video/x-av1"}},
      95           10 :          {m_gstWrapper->gstCapsFromString("video/x-h264"), {"video/h264"}},
      96           10 :          {m_gstWrapper->gstCapsFromString("video/x-h265"), {"video/h265"}},
      97           10 :          {m_gstWrapper->gstCapsFromString("video/x-vp9"), {"video/x-vp9"}},
      98           10 :          {m_gstWrapper->gstCapsFromString("video/mpeg, mpegversion=(int)4"), {"video/mp4"}},
      99           10 :          {m_gstWrapper->gstCapsFromString("video/x-h264(memory:DMABuf)"), {"video/h264"}},
     100           10 :          {m_gstWrapper->gstCapsFromString("video/x-h265(memory:DMABuf)"), {"video/h265"}},
     101           10 :          {m_gstWrapper->gstCapsFromString("video/x-av1(memory:DMABuf)"), {"video/x-av1"}},
     102          190 :          {m_gstWrapper->gstCapsFromString("video/x-vp9(memory:DMABuf)"), {"video/x-vp9"}}};
     103              : 
     104           10 :     std::unordered_set<std::string> supportedMimes;
     105              : 
     106           29 :     for (GstCaps *caps : supportedCaps)
     107              :     {
     108          323 :         for (const auto &capsToMime : capsToMimeVec)
     109              :         {
     110          304 :             if (m_gstWrapper->gstCapsCanIntersect(capsToMime.first, caps))
     111              :             {
     112           17 :                 supportedMimes.insert(capsToMime.second.begin(), capsToMime.second.end());
     113              :             }
     114              :         }
     115              :     }
     116              : 
     117          170 :     for (auto &capsToMime : capsToMimeVec)
     118              :     {
     119          160 :         if (capsToMime.first)
     120          160 :             m_gstWrapper->gstCapsUnref(capsToMime.first);
     121              :     }
     122              : 
     123           20 :     return supportedMimes;
     124          210 : }
     125              : 
     126              : }; // namespace firebolt::rialto::server
     127              : 
     128              : #endif // FIREBOLT_RIALTO_SERVER_GST_MIME_MAPPING_H_
        

Generated by: LCOV version 2.0-1