LCOV - code coverage report
Current view: top level - media/server/gstplayer/source - GstInitialiser.cpp (source / functions) Coverage Total Hit
Test: coverage.info Lines: 93.5 % 31 29
Test Date: 2025-02-18 13:13:53 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 "IGstWrapper.h"
      23              : #include "RialtoServerLogging.h"
      24              : 
      25              : namespace firebolt::rialto::server
      26              : {
      27            4 : GstInitialiser::~GstInitialiser()
      28              : {
      29            4 :     if (m_thread.joinable())
      30              :     {
      31            4 :         m_thread.join();
      32              :     }
      33              : }
      34              : 
      35           13 : IGstInitialiser &IGstInitialiser::instance()
      36              : {
      37           13 :     static GstInitialiser initialiser;
      38           13 :     return initialiser;
      39              : }
      40              : 
      41            5 : void GstInitialiser::initialise(int *argc, char ***argv)
      42              : {
      43            5 :     if (m_thread.joinable())
      44              :     {
      45            1 :         RIALTO_SERVER_LOG_WARN("Gstreamer is already initialised, no need to do it twice...");
      46            1 :         return;
      47              :     }
      48              : 
      49            8 :     m_thread = std::thread(
      50            4 :         [=]()
      51              :         {
      52              :             std::shared_ptr<firebolt::rialto::wrappers::IGstWrapperFactory> factory =
      53            4 :                 firebolt::rialto::wrappers::IGstWrapperFactory::getFactory();
      54            4 :             std::shared_ptr<firebolt::rialto::wrappers::IGstWrapper> gstWrapper = factory->getGstWrapper();
      55              : 
      56            4 :             if (!gstWrapper)
      57              :             {
      58            0 :                 RIALTO_SERVER_LOG_ERROR("Failed to create the gst wrapper");
      59            0 :                 return;
      60              :             }
      61              : 
      62            4 :             gstWrapper->gstInit(argc, argv);
      63              : 
      64              :             // remove rialto sinks from the registry
      65            4 :             GstPlugin *rialtoPlugin = gstWrapper->gstRegistryFindPlugin(gstWrapper->gstRegistryGet(), "rialtosinks");
      66            4 :             if (rialtoPlugin)
      67              :             {
      68            2 :                 gstWrapper->gstRegistryRemovePlugin(gstWrapper->gstRegistryGet(), rialtoPlugin);
      69            2 :                 gstWrapper->gstObjectUnref(rialtoPlugin);
      70              :             }
      71              : 
      72            4 :             enableGstLogForwarding();
      73              : 
      74            4 :             std::unique_lock lock{m_mutex};
      75            4 :             m_isInitialised = true;
      76            4 :             m_cv.notify_all();
      77            8 :         });
      78              : }
      79              : 
      80            8 : void GstInitialiser::waitForInitialisation() const
      81              : {
      82            8 :     std::unique_lock lock{m_mutex};
      83           20 :     m_cv.wait(lock, [this]() { return m_isInitialised; });
      84            8 : }
      85              : }; // namespace firebolt::rialto::server
        

Generated by: LCOV version 2.0-1