LCOV - code coverage report
Current view: top level - media/server/gstplayer/source/tasks/generic - CheckAudioUnderflow.cpp (source / functions) Coverage Total Hit
Test: coverage.info Lines: 100.0 % 16 16
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 2022 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 "tasks/generic/CheckAudioUnderflow.h"
      21              : #include "GenericPlayerContext.h"
      22              : #include "IGstGenericPlayerClient.h"
      23              : #include "IGstWrapper.h"
      24              : #include "RialtoServerLogging.h"
      25              : #include "tasks/generic/Underflow.h"
      26              : #include <gst/gst.h>
      27              : 
      28              : #include <cinttypes>
      29              : 
      30              : namespace firebolt::rialto::server::tasks::generic
      31              : {
      32            3 : CheckAudioUnderflow::CheckAudioUnderflow(GenericPlayerContext &context, IGstGenericPlayerPrivate &player,
      33              :                                          IGstGenericPlayerClient *client,
      34            3 :                                          std::shared_ptr<firebolt::rialto::wrappers::IGstWrapper> gstWrapper)
      35            3 :     : m_context{context}, m_player(player), m_gstPlayerClient{client}, m_gstWrapper{gstWrapper}
      36              : {
      37              : }
      38              : 
      39            2 : void CheckAudioUnderflow::execute() const
      40              : {
      41              :     // TODO(LLDEV-31012) Check if the audio stream is in underflow state.
      42            2 :     if (m_context.streamInfo.find(firebolt::rialto::MediaSourceType::AUDIO) != m_context.streamInfo.end())
      43              :     {
      44            2 :         gint64 position = -1;
      45            2 :         m_gstWrapper->gstElementQueryPosition(m_context.pipeline, GST_FORMAT_TIME, &position);
      46            2 :         constexpr int64_t kAudioUnderflowMarginNs = 350 * 1000000;
      47            5 :         if ((position > m_context.lastAudioSampleTimestamps + kAudioUnderflowMarginNs) &&
      48            3 :             m_gstWrapper->gstElementGetState(m_context.pipeline) == GST_STATE_PLAYING &&
      49            1 :             m_gstWrapper->gstElementGetPendingState(m_context.pipeline) != GST_STATE_PAUSED)
      50              :         {
      51            1 :             RIALTO_SERVER_LOG_INFO("Audio stream underflow! Position %" PRIu64 ", lastAudioSampleTimestamps: %" PRIu64,
      52              :                                    position, m_context.lastAudioSampleTimestamps);
      53            1 :             bool underflowEnabled = m_context.isPlaying && !m_context.audioSourceRemoved;
      54            1 :             Underflow task(m_context, m_player, m_gstPlayerClient, underflowEnabled, MediaSourceType::AUDIO);
      55            1 :             task.execute();
      56              :         }
      57              :     }
      58            2 : }
      59              : 
      60              : } // namespace firebolt::rialto::server::tasks::generic
        

Generated by: LCOV version 2.0-1