LCOV - code coverage report
Current view: top level - media/server/gstplayer/include - GenericPlayerContext.h (source / functions) Coverage Total Hit
Test: coverage.info Lines: 100.0 % 4 4
Test Date: 2025-11-17 09:18:47 Functions: 100.0 % 4 4

            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              : #ifndef FIREBOLT_RIALTO_SERVER_GENERIC_PLAYER_CONTEXT_H_
      21              : #define FIREBOLT_RIALTO_SERVER_GENERIC_PLAYER_CONTEXT_H_
      22              : 
      23              : #include "FlushOnPrerollController.h"
      24              : #include "IGstSrc.h"
      25              : #include "IRdkGstreamerUtilsWrapper.h"
      26              : #include "ITimer.h"
      27              : #include "MediaCommon.h"
      28              : #include <gst/gst.h>
      29              : #include <list>
      30              : #include <map>
      31              : #include <memory>
      32              : #include <mutex>
      33              : #include <unordered_map>
      34              : #include <vector>
      35              : 
      36              : namespace firebolt::rialto::server
      37              : {
      38              : constexpr double kNoPendingPlaybackRate{0.0};
      39              : 
      40              : enum class EosState
      41              : {
      42              :     PENDING,
      43              :     SET
      44              : };
      45              : 
      46              : /**
      47              :  * @brief Structure used for video geometry
      48              :  */
      49              : struct Rectangle
      50              : {
      51              :     int x, y, width, height;
      52          503 :     constexpr Rectangle() : x(0), y(0), width(0), height(0) {}
      53            1 :     constexpr Rectangle(int x_, int y_, int w_, int h_) : x(x_), y(y_), width(w_), height(h_) {}
      54              :     Rectangle(const Rectangle &rhs) = default;
      55           10 :     inline constexpr bool empty() { return (width == 0) || (height == 0); }
      56            2 :     inline void clear() { x = y = width = height = 0; }
      57              : };
      58              : 
      59              : /**
      60              :  * @brief Structure used for set source position
      61              :  */
      62              : struct SegmentData
      63              : {
      64              :     int64_t position;
      65              :     bool resetTime;
      66              :     double appliedRate;
      67              :     uint64_t stopPosition;
      68              : };
      69              : 
      70              : struct GenericPlayerContext
      71              : {
      72              :     /**
      73              :      * @brief The rialto src object.
      74              :      */
      75              :     std::shared_ptr<IGstSrc> gstSrc{nullptr};
      76              : 
      77              :     /**
      78              :      * @brief The gstreamer pipeline.
      79              :      */
      80              :     GstElement *pipeline{nullptr};
      81              : 
      82              :     /**
      83              :      * @brief The gstreamer source.
      84              :      */
      85              :     GstElement *source{nullptr};
      86              : 
      87              :     /**
      88              :      * @brief A map of streams attached to the source.
      89              :      */
      90              :     StreamInfoMap streamInfo{};
      91              : 
      92              :     /**
      93              :      * @brief Child sink of the autovideosink.
      94              :      */
      95              :     GstElement *autoVideoChildSink{nullptr};
      96              : 
      97              :     /**
      98              :      * @brief Child sink of the autoaudiosink.
      99              :      */
     100              :     GstElement *autoAudioChildSink{nullptr};
     101              : 
     102              :     /**
     103              :      * @brief The subtitle sink
     104              :      */
     105              :     GstElement *subtitleSink{nullptr};
     106              : 
     107              :     /**
     108              :      * @brief The video sink
     109              :      */
     110              :     GstElement *videoSink{nullptr};
     111              : 
     112              :     /**
     113              :      * @brief Flag used to check, if video decoder handle has been set.
     114              :      */
     115              :     bool isVideoHandleSet{false};
     116              : 
     117              :     /**
     118              :      * @brief Flag used to check, if BUFFERED notification has been sent.
     119              :      *
     120              :      * Flag can be used only in worker thread
     121              :      */
     122              :     bool bufferedNotificationSent{false};
     123              : 
     124              :     /**
     125              :      * @brief Flag used to check, if the playback is in the playing state
     126              :      *
     127              :      * Flag can be used only in worker thread
     128              :      */
     129              :     bool isPlaying{false};
     130              : 
     131              :     /**
     132              :      * @brief Flag used to check, if EOS has been notified to the client
     133              :      *
     134              :      * Flag can be used only in worker thread
     135              :      */
     136              :     bool eosNotified{false};
     137              : 
     138              :     /**
     139              :      * @brief Pending video geometry
     140              :      */
     141              :     Rectangle pendingGeometry;
     142              : 
     143              :     /**
     144              :      * @brief Current playback rate
     145              :      */
     146              :     double playbackRate{1.0};
     147              : 
     148              :     /**
     149              :      * @brief Pending playback rate
     150              :      */
     151              :     double pendingPlaybackRate{kNoPendingPlaybackRate};
     152              : 
     153              :     /**
     154              :      * @brief Pending immediate output for MediaSourceType::VIDEO
     155              :      */
     156              :     std::optional<bool> pendingImmediateOutputForVideo{};
     157              : 
     158              :     /**
     159              :      * @brief Pending low latency
     160              :      */
     161              :     std::optional<bool> pendingLowLatency{};
     162              : 
     163              :     /**
     164              :      * @brief Pending sync
     165              :      */
     166              :     std::optional<bool> pendingSync{};
     167              : 
     168              :     /**
     169              :      * @brief Pending sync off
     170              :      */
     171              :     std::optional<bool> pendingSyncOff{};
     172              : 
     173              :     /**
     174              :      * @brief Pending buffering limit
     175              :      */
     176              :     std::optional<uint32_t> pendingBufferingLimit{};
     177              : 
     178              :     /**
     179              :      * @brief Pending use buffering
     180              :      */
     181              :     std::optional<bool> pendingUseBuffering{};
     182              : 
     183              :     /**
     184              :      * @brief Pending stream sync mode
     185              :      */
     186              :     std::map<MediaSourceType, int32_t> pendingStreamSyncMode{};
     187              : 
     188              :     /**
     189              :      * @brief Pending render frame
     190              :      */
     191              :     bool pendingRenderFrame{false};
     192              : 
     193              :     /**
     194              :      * @brief Pending show video window
     195              :      */
     196              :     std::optional<bool> pendingShowVideoWindow{};
     197              : 
     198              :     /**
     199              :      * @brief Last audio sample timestamps
     200              :      * TODO(LLDEV-31012) Needed to detect audio stream underflow
     201              :      */
     202              :     int64_t lastAudioSampleTimestamps{0};
     203              : 
     204              :     /**
     205              :      * @brief The decryption service.
     206              :      */
     207              :     IDecryptionService *decryptionService{nullptr};
     208              : 
     209              :     /**
     210              :      * @brief Flag used to check, if audio source has been recently removed
     211              :      *
     212              :      * Flag can be used only in worker thread
     213              :      */
     214              :     bool audioSourceRemoved{false};
     215              : 
     216              :     /**
     217              :      * @brief Audio elements of gst pipeline.
     218              :      *
     219              :      * Attribute can be used only in worker thread
     220              :      */
     221              :     firebolt::rialto::wrappers::PlaybackGroupPrivate playbackGroup;
     222              : 
     223              :     /**
     224              :      * @brief A map of streams that have ended.
     225              :      */
     226              :     std::unordered_map<MediaSourceType, EosState> endOfStreamInfo{};
     227              : 
     228              :     /**
     229              :      * @brief Flag used to check if client already notified server that all sources were attached
     230              :      *
     231              :      * Attribute can be used only in worker thread
     232              :      */
     233              :     bool wereAllSourcesAttached{false};
     234              : 
     235              :     /**
     236              :      * @brief Flag used to check if FinishSetupSource is finished. It is needed to avoid need data overwriting.
     237              :      *
     238              :      * Attribute can be used only in worker thread
     239              :      */
     240              :     bool setupSourceFinished{false};
     241              : 
     242              :     /**
     243              :      * @brief Queued source positions. Used by SetSourcePosition task to request pushing new sample.
     244              :      *
     245              :      * Attribute can be used only in worker thread
     246              :      */
     247              :     std::map<GstElement *, std::vector<SegmentData>> initialPositions;
     248              : 
     249              :     /**
     250              :      * @brief Currently set position of a source. Used to check, if additional segment should be pushed.
     251              :      *
     252              :      * Attribute can be used only in worker thread
     253              :      */
     254              :     std::map<GstElement *, SegmentData> currentPosition;
     255              : 
     256              :     /**
     257              :      * @brief The mutex, which protects properties, which are read/written by main/worker thread.
     258              :      *        This mutex should be removed in future, when we find out better solution for
     259              :      *        property read-write.
     260              :      */
     261              :     std::mutex propertyMutex;
     262              : 
     263              :     /**
     264              :      * @brief Flag used to check if audio fade is enabled
     265              :      *
     266              :      * Attribute can be used only in worker thread
     267              :      */
     268              :     std::atomic_bool audioFadeEnabled{false};
     269              : 
     270              :     /**
     271              :      * @brief Workaround for the gstreamer flush issue
     272              :      */
     273              :     FlushOnPrerollController flushOnPrerollController;
     274              : };
     275              : } // namespace firebolt::rialto::server
     276              : 
     277              : #endif // FIREBOLT_RIALTO_SERVER_GENERIC_PLAYER_CONTEXT_H_
        

Generated by: LCOV version 2.0-1