LCOV - code coverage report
Current view: top level - media/server/gstplayer/source - GstInitialiser.cpp (source / functions) Coverage Total Hit
Test: coverage.info Lines: 90.6 % 32 29
Test Date: 2025-06-30 09:40:50 Functions: 100.0 % 6 6

            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 2025 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              : #include "GstInitialiser.h"
      21              : #include "GstLogForwarding.h"
      22              : #include "RialtoServerLogging.h"
      23              : 
      24              : namespace firebolt::rialto::server
      25              : {
      26            4 : GstInitialiser::~GstInitialiser()
      27              : {
      28            4 :     if (m_thread.joinable())
      29              :     {
      30            4 :         m_thread.join();
      31              :     }
      32              : 
      33              : #ifdef FREE_MEM_BEFORE_EXIT
      34              :     if (m_gstWrapper)
      35              :     {
      36              :         m_gstWrapper->gstDeinit();
      37              :         m_gstWrapper.reset();
      38              :     }
      39              : #endif
      40            0 : }
      41              : 
      42           13 : IGstInitialiser &IGstInitialiser::instance()
      43              : {
      44           13 :     static GstInitialiser initialiser;
      45           13 :     return initialiser;
      46              : }
      47              : 
      48            5 : void GstInitialiser::initialise(int *argc, char ***argv)
      49              : {
      50            5 :     if (m_thread.joinable())
      51              :     {
      52            1 :         RIALTO_SERVER_LOG_WARN("Gstreamer is already initialised, no need to do it twice...");
      53            1 :         return;
      54              :     }
      55              : 
      56            4 :     m_thread = std::thread(
      57            8 :         [=]()
      58              :         {
      59              :             std::shared_ptr<firebolt::rialto::wrappers::IGstWrapperFactory> factory =
      60            4 :                 firebolt::rialto::wrappers::IGstWrapperFactory::getFactory();
      61            4 :             m_gstWrapper = factory->getGstWrapper();
      62              : 
      63            4 :             if (!m_gstWrapper)
      64              :             {
      65            0 :                 RIALTO_SERVER_LOG_ERROR("Failed to create the gst wrapper");
      66            0 :                 return;
      67              :             }
      68              : 
      69            4 :             m_gstWrapper->gstInit(argc, argv);
      70              : 
      71              :             // remove rialto sinks from the registry
      72              :             GstPlugin *rialtoPlugin =
      73            4 :                 m_gstWrapper->gstRegistryFindPlugin(m_gstWrapper->gstRegistryGet(), "rialtosinks");
      74            4 :             if (rialtoPlugin)
      75              :             {
      76            2 :                 m_gstWrapper->gstRegistryRemovePlugin(m_gstWrapper->gstRegistryGet(), rialtoPlugin);
      77            2 :                 m_gstWrapper->gstObjectUnref(rialtoPlugin);
      78              :             }
      79              : 
      80            4 :             enableGstLogForwarding();
      81              : 
      82            4 :             std::unique_lock lock{m_mutex};
      83            4 :             m_isInitialised = true;
      84            4 :             m_cv.notify_all();
      85            8 :         });
      86              : }
      87              : 
      88            8 : void GstInitialiser::waitForInitialisation() const
      89              : {
      90            8 :     std::unique_lock lock{m_mutex};
      91           20 :     m_cv.wait(lock, [this]() { return m_isInitialised; });
      92            8 : }
      93              : }; // namespace firebolt::rialto::server
        

Generated by: LCOV version 2.0-1