LCOV - code coverage report
Current view: top level - source - RialtoGStreamerMSEVideoSink.cpp (source / functions) Coverage Total Hit
Test: coverage.info Lines: 97.6 % 124 121
Test Date: 2025-08-04 11:40:41 Functions: 100.0 % 6 6

            Line data    Source code
       1              : /*
       2              :  * Copyright (C) 2022 Sky UK
       3              :  *
       4              :  * This library is free software; you can redistribute it and/or
       5              :  * modify it under the terms of the GNU Lesser General Public
       6              :  * License as published by the Free Software Foundation;
       7              :  * version 2.1 of the License.
       8              :  *
       9              :  * This library is distributed in the hope that it will be useful,
      10              :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      11              :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      12              :  * Lesser General Public License for more details.
      13              :  *
      14              :  * You should have received a copy of the GNU Lesser General Public
      15              :  * License along with this library; if not, write to the Free Software
      16              :  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
      17              :  */
      18              : 
      19              : #include <gst/gst.h>
      20              : #include <inttypes.h>
      21              : #include <stdint.h>
      22              : 
      23              : #include "GStreamerEMEUtils.h"
      24              : #include "GStreamerMSEUtils.h"
      25              : #include "IMediaPipelineCapabilities.h"
      26              : #include "PullModeVideoPlaybackDelegate.h"
      27              : #include "RialtoGStreamerMSEBaseSinkPrivate.h"
      28              : #include "RialtoGStreamerMSEVideoSink.h"
      29              : 
      30              : using namespace firebolt::rialto::client;
      31              : 
      32              : GST_DEBUG_CATEGORY_STATIC(RialtoMSEVideoSinkDebug);
      33              : #define GST_CAT_DEFAULT RialtoMSEVideoSinkDebug
      34              : 
      35              : #define rialto_mse_video_sink_parent_class parent_class
      36          173 : G_DEFINE_TYPE_WITH_CODE(RialtoMSEVideoSink, rialto_mse_video_sink, RIALTO_TYPE_MSE_BASE_SINK,
      37              :                         GST_DEBUG_CATEGORY_INIT(RialtoMSEVideoSinkDebug, "rialtomsevideosink", 0,
      38              :                                                 "rialto mse video sink"));
      39              : 
      40              : enum
      41              : {
      42              :     PROP_0,
      43              :     PROP_WINDOW_SET,
      44              :     PROP_MAX_VIDEO_WIDTH,
      45              :     PROP_MAX_VIDEO_HEIGHT,
      46              :     PROP_MAX_VIDEO_WIDTH_DEPRECATED,
      47              :     PROP_MAX_VIDEO_HEIGHT_DEPRECATED,
      48              :     PROP_FRAME_STEP_ON_PREROLL,
      49              :     PROP_IMMEDIATE_OUTPUT,
      50              :     PROP_SYNCMODE_STREAMING,
      51              :     PROP_SHOW_VIDEO_WINDOW,
      52              :     PROP_IS_MASTER,
      53              :     PROP_LAST
      54              : };
      55              : 
      56          170 : static GstStateChangeReturn rialto_mse_video_sink_change_state(GstElement *element, GstStateChange transition)
      57              : {
      58          170 :     RialtoMSEVideoSink *sink = RIALTO_MSE_VIDEO_SINK(element);
      59          170 :     if (GST_STATE_CHANGE_NULL_TO_READY == transition)
      60              :     {
      61           56 :         GST_INFO_OBJECT(sink, "RialtoMSEVideoSink state change to READY. Initializing delegate");
      62           56 :         rialto_mse_base_sink_initialise_delegate(RIALTO_MSE_BASE_SINK(sink),
      63          112 :                                                  std::make_shared<PullModeVideoPlaybackDelegate>(element));
      64              :     }
      65          170 :     GstStateChangeReturn result = GST_ELEMENT_CLASS(parent_class)->change_state(element, transition);
      66          170 :     if (G_UNLIKELY(result == GST_STATE_CHANGE_FAILURE))
      67              :     {
      68            1 :         GST_WARNING_OBJECT(sink, "State change failed");
      69            1 :         return result;
      70              :     }
      71              : 
      72          169 :     return result;
      73              : }
      74              : 
      75           15 : static void rialto_mse_video_sink_get_property(GObject *object, guint propId, GValue *value, GParamSpec *pspec)
      76              : {
      77           15 :     switch (propId)
      78              :     {
      79            5 :     case PROP_WINDOW_SET:
      80              :     {
      81            5 :         g_value_set_string(value, "0,0,1920,1080"); // Set default value
      82            5 :         rialto_mse_base_sink_handle_get_property(RIALTO_MSE_BASE_SINK(object), IPlaybackDelegate::Property::WindowSet,
      83              :                                                  value);
      84            5 :         break;
      85              :     }
      86            1 :     case PROP_MAX_VIDEO_WIDTH_DEPRECATED:
      87            1 :         GST_WARNING_OBJECT(object, "MaxVideoWidth property is deprecated. Use 'max-video-width' instead");
      88              :     case PROP_MAX_VIDEO_WIDTH:
      89              :     {
      90            2 :         g_value_set_uint(value, 0); // Set default value
      91            2 :         rialto_mse_base_sink_handle_get_property(RIALTO_MSE_BASE_SINK(object),
      92            2 :                                                  IPlaybackDelegate::Property::MaxVideoWidth, value);
      93            2 :         break;
      94              :     }
      95            1 :     case PROP_MAX_VIDEO_HEIGHT_DEPRECATED:
      96            1 :         GST_WARNING_OBJECT(object, "MaxVideoHeight property is deprecated. Use 'max-video-height' instead");
      97              :     case PROP_MAX_VIDEO_HEIGHT:
      98              :     {
      99            2 :         g_value_set_uint(value, 0); // Set default value
     100            2 :         rialto_mse_base_sink_handle_get_property(RIALTO_MSE_BASE_SINK(object),
     101            2 :                                                  IPlaybackDelegate::Property::MaxVideoHeight, value);
     102            2 :         break;
     103              :     }
     104            1 :     case PROP_FRAME_STEP_ON_PREROLL:
     105              :     {
     106            1 :         g_value_set_boolean(value, FALSE); // Set default value
     107            1 :         rialto_mse_base_sink_handle_get_property(RIALTO_MSE_BASE_SINK(object),
     108            1 :                                                  IPlaybackDelegate::Property::FrameStepOnPreroll, value);
     109            1 :         break;
     110              :     }
     111            3 :     case PROP_IMMEDIATE_OUTPUT:
     112              :     {
     113            3 :         g_value_set_boolean(value, FALSE); // Set default value
     114            3 :         rialto_mse_base_sink_handle_get_property(RIALTO_MSE_BASE_SINK(object),
     115            3 :                                                  IPlaybackDelegate::Property::ImmediateOutput, value);
     116            3 :         break;
     117              :     }
     118            1 :     case PROP_IS_MASTER:
     119              :     {
     120            1 :         g_value_set_boolean(value, TRUE); // Set default value
     121              :         std::unique_ptr<firebolt::rialto::IMediaPipelineCapabilities> mediaPlayerCapabilities =
     122            1 :             firebolt::rialto::IMediaPipelineCapabilitiesFactory::createFactory()->createMediaPipelineCapabilities();
     123            1 :         bool isMaster{false};
     124            1 :         if (mediaPlayerCapabilities && mediaPlayerCapabilities->isVideoMaster(isMaster))
     125              :         {
     126            1 :             g_value_set_boolean(value, isMaster);
     127              :         }
     128            1 :         break;
     129              :     }
     130            1 :     default:
     131            1 :         G_OBJECT_WARN_INVALID_PROPERTY_ID(object, propId, pspec);
     132            1 :         break;
     133              :     }
     134           15 : }
     135              : 
     136           24 : static void rialto_mse_video_sink_set_property(GObject *object, guint propId, const GValue *value, GParamSpec *pspec)
     137              : {
     138           24 :     switch (propId)
     139              :     {
     140            4 :     case PROP_WINDOW_SET:
     141              :     {
     142            4 :         rialto_mse_base_sink_handle_set_property(RIALTO_MSE_BASE_SINK(object), IPlaybackDelegate::Property::WindowSet,
     143              :                                                  value);
     144            4 :         break;
     145              :     }
     146            2 :     case PROP_MAX_VIDEO_WIDTH:
     147              :     case PROP_MAX_VIDEO_WIDTH_DEPRECATED:
     148            2 :         rialto_mse_base_sink_handle_set_property(RIALTO_MSE_BASE_SINK(object),
     149            2 :                                                  IPlaybackDelegate::Property::MaxVideoWidth, value);
     150            2 :         break;
     151            2 :     case PROP_MAX_VIDEO_HEIGHT:
     152              :     case PROP_MAX_VIDEO_HEIGHT_DEPRECATED:
     153            2 :         rialto_mse_base_sink_handle_set_property(RIALTO_MSE_BASE_SINK(object),
     154            2 :                                                  IPlaybackDelegate::Property::MaxVideoHeight, value);
     155            2 :         break;
     156            5 :     case PROP_FRAME_STEP_ON_PREROLL:
     157              :     {
     158            5 :         rialto_mse_base_sink_handle_set_property(RIALTO_MSE_BASE_SINK(object),
     159            5 :                                                  IPlaybackDelegate::Property::FrameStepOnPreroll, value);
     160            5 :         break;
     161              :     }
     162            4 :     case PROP_IMMEDIATE_OUTPUT:
     163              :     {
     164            4 :         rialto_mse_base_sink_handle_set_property(RIALTO_MSE_BASE_SINK(object),
     165            4 :                                                  IPlaybackDelegate::Property::ImmediateOutput, value);
     166            4 :         break;
     167              :     }
     168            4 :     case PROP_SYNCMODE_STREAMING:
     169              :     {
     170            4 :         rialto_mse_base_sink_handle_set_property(RIALTO_MSE_BASE_SINK(object),
     171            4 :                                                  IPlaybackDelegate::Property::SyncmodeStreaming, value);
     172            4 :         break;
     173              :     }
     174            2 :     case PROP_SHOW_VIDEO_WINDOW:
     175              :     {
     176            2 :         rialto_mse_base_sink_handle_set_property(RIALTO_MSE_BASE_SINK(object),
     177            2 :                                                  IPlaybackDelegate::Property::ShowVideoWindow, value);
     178            2 :         break;
     179              :     }
     180            1 :     default:
     181            1 :         G_OBJECT_WARN_INVALID_PROPERTY_ID(object, propId, pspec);
     182            1 :         break;
     183              :     }
     184           24 : }
     185              : 
     186           56 : static void rialto_mse_video_sink_init(RialtoMSEVideoSink *sink)
     187              : {
     188           56 :     RialtoMSEBaseSinkPrivate *basePriv = sink->parent.priv;
     189              : 
     190           56 :     if (!rialto_mse_base_sink_initialise_sinkpad(RIALTO_MSE_BASE_SINK(sink)))
     191              :     {
     192            0 :         GST_ERROR_OBJECT(sink, "Failed to initialise VIDEO sink. Sink pad initialisation failed.");
     193            0 :         return;
     194              :     }
     195              : 
     196           56 :     gst_pad_set_chain_function(basePriv->m_sinkPad, rialto_mse_base_sink_chain);
     197           56 :     gst_pad_set_event_function(basePriv->m_sinkPad, rialto_mse_base_sink_event);
     198              : }
     199              : 
     200            1 : static void rialto_mse_video_sink_class_init(RialtoMSEVideoSinkClass *klass)
     201              : {
     202            1 :     GObjectClass *gobjectClass = G_OBJECT_CLASS(klass);
     203            1 :     GstElementClass *elementClass = GST_ELEMENT_CLASS(klass);
     204            1 :     gobjectClass->get_property = rialto_mse_video_sink_get_property;
     205            1 :     gobjectClass->set_property = rialto_mse_video_sink_set_property;
     206            1 :     elementClass->change_state = rialto_mse_video_sink_change_state;
     207              : 
     208            1 :     g_object_class_install_property(gobjectClass, PROP_WINDOW_SET,
     209              :                                     g_param_spec_string("rectangle", "rectangle", "Window Set Format: x,y,width,height",
     210              :                                                         nullptr, GParamFlags(G_PARAM_READWRITE)));
     211              : 
     212            1 :     g_object_class_install_property(gobjectClass, PROP_MAX_VIDEO_WIDTH,
     213              :                                     g_param_spec_uint("max-video-width",
     214              :                                                       "max video width", "Maximum width of video frames to be decoded. Should only be set for video only streams.",
     215              :                                                       0, 3840, DEFAULT_MAX_VIDEO_WIDTH, GParamFlags(G_PARAM_READWRITE)));
     216              : 
     217            1 :     g_object_class_install_property(gobjectClass, PROP_MAX_VIDEO_HEIGHT,
     218              :                                     g_param_spec_uint("max-video-height",
     219              :                                                       "max video height", "Maximum height of video frames to be decoded. should only be set for video only streams.",
     220              :                                                       0, 2160, DEFAULT_MAX_VIDEO_HEIGHT, GParamFlags(G_PARAM_READWRITE)));
     221              : 
     222            1 :     g_object_class_install_property(gobjectClass, PROP_MAX_VIDEO_WIDTH_DEPRECATED,
     223              :                                     g_param_spec_uint("maxVideoWidth", "maxVideoWidth", "[DEPRECATED] Use max-video-width",
     224              :                                                       0, 3840, DEFAULT_MAX_VIDEO_WIDTH, GParamFlags(G_PARAM_READWRITE)));
     225              : 
     226            1 :     g_object_class_install_property(gobjectClass, PROP_MAX_VIDEO_HEIGHT_DEPRECATED,
     227              :                                     g_param_spec_uint("maxVideoHeight", "maxVideoHeight", "[DEPRECATED] max-video-height",
     228              :                                                       0, 2160, DEFAULT_MAX_VIDEO_HEIGHT, GParamFlags(G_PARAM_READWRITE)));
     229              : 
     230            1 :     g_object_class_install_property(gobjectClass, PROP_FRAME_STEP_ON_PREROLL,
     231              :                                     g_param_spec_boolean("frame-step-on-preroll", "frame step on preroll",
     232              :                                                          "allow frame stepping on preroll into pause", FALSE,
     233              :                                                          G_PARAM_READWRITE));
     234            1 :     g_object_class_install_property(gobjectClass, PROP_IS_MASTER,
     235              :                                     g_param_spec_boolean("is-master", "is master",
     236              :                                                          "Checks if the platform is video master", TRUE,
     237              :                                                          G_PARAM_READABLE));
     238              : 
     239              :     std::unique_ptr<firebolt::rialto::IMediaPipelineCapabilities> mediaPlayerCapabilities =
     240            1 :         firebolt::rialto::IMediaPipelineCapabilitiesFactory::createFactory()->createMediaPipelineCapabilities();
     241            1 :     if (mediaPlayerCapabilities)
     242              :     {
     243              :         std::vector<std::string> supportedMimeTypes =
     244            1 :             mediaPlayerCapabilities->getSupportedMimeTypes(firebolt::rialto::MediaSourceType::VIDEO);
     245              : 
     246            1 :         rialto_mse_sink_setup_supported_caps(elementClass, supportedMimeTypes);
     247              : 
     248            2 :         const std::string kImmediateOutputPropertyName{"immediate-output"};
     249            2 :         const std::string kSyncmodeStreamingPropertyName{"syncmode-streaming"};
     250            1 :         const std::string kShowVideoWindowPropertyName{"show-video-window"};
     251              :         const std::vector<std::string> kPropertyNamesToSearch{kImmediateOutputPropertyName,
     252              :                                                               kSyncmodeStreamingPropertyName,
     253            5 :                                                               kShowVideoWindowPropertyName};
     254              :         std::vector<std::string> supportedProperties{
     255            1 :             mediaPlayerCapabilities->getSupportedProperties(firebolt::rialto::MediaSourceType::VIDEO,
     256            1 :                                                             kPropertyNamesToSearch)};
     257              : 
     258            4 :         for (const auto &propertyName : supportedProperties)
     259              :         {
     260            3 :             if (kImmediateOutputPropertyName == propertyName)
     261              :             {
     262            1 :                 g_object_class_install_property(gobjectClass, PROP_IMMEDIATE_OUTPUT,
     263              :                                                 g_param_spec_boolean(kImmediateOutputPropertyName.c_str(),
     264              :                                                                      "immediate output", "immediate output", TRUE,
     265              :                                                                      GParamFlags(G_PARAM_READWRITE)));
     266              :             }
     267            2 :             else if (kSyncmodeStreamingPropertyName == propertyName)
     268              :             {
     269            1 :                 g_object_class_install_property(gobjectClass, PROP_SYNCMODE_STREAMING,
     270              :                                                 g_param_spec_boolean("syncmode-streaming", "Streaming Sync Mode",
     271              :                                                                      "Enable/disable OTT streaming sync mode", FALSE,
     272              :                                                                      G_PARAM_WRITABLE));
     273              :             }
     274            1 :             else if (kShowVideoWindowPropertyName == propertyName)
     275              :             {
     276            1 :                 g_object_class_install_property(gobjectClass, PROP_SHOW_VIDEO_WINDOW,
     277              :                                                 g_param_spec_boolean(kShowVideoWindowPropertyName.c_str(),
     278              :                                                                      "make video window visible",
     279              :                                                                      "true: visible, false: hidden", TRUE,
     280              :                                                                      G_PARAM_WRITABLE));
     281              :             }
     282              :         }
     283              :     }
     284              :     else
     285              :     {
     286            0 :         GST_ERROR("Failed to get supported mime types for VIDEO");
     287              :     }
     288              : 
     289            1 :     gst_element_class_set_details_simple(elementClass, "Rialto Video Sink", "Decoder/Video/Sink/Video",
     290              :                                          "Communicates with Rialto Server", "Sky");
     291            2 : }
        

Generated by: LCOV version 2.0-1