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

            Line data    Source code
       1              : /*
       2              :  * Copyright (C) 2024 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 "PullModeSubtitlePlaybackDelegate.h"
      27              : #include "RialtoGStreamerMSEBaseSinkPrivate.h"
      28              : #include "RialtoGStreamerMSESubtitleSink.h"
      29              : 
      30              : using namespace firebolt::rialto::client;
      31              : 
      32              : GST_DEBUG_CATEGORY_STATIC(RialtoMSESubtitleSinkDebug);
      33              : #define GST_CAT_DEFAULT RialtoMSESubtitleSinkDebug
      34              : 
      35              : #define rialto_mse_subtitle_sink_parent_class parent_class
      36           69 : G_DEFINE_TYPE_WITH_CODE(RialtoMSESubtitleSink, rialto_mse_subtitle_sink, RIALTO_TYPE_MSE_BASE_SINK,
      37              :                         GST_DEBUG_CATEGORY_INIT(RialtoMSESubtitleSinkDebug, "rialtomsesubtitlesink", 0,
      38              :                                                 "rialto mse subtitle sink"));
      39              : 
      40              : enum
      41              : {
      42              :     PROP_0,
      43              :     PROP_MUTE,
      44              :     PROP_TEXT_TRACK_IDENTIFIER,
      45              :     PROP_WINDOW_ID,
      46              :     PROP_ASYNC,
      47              :     PROP_LAST
      48              : };
      49              : 
      50           66 : static GstStateChangeReturn rialto_mse_subtitle_sink_change_state(GstElement *element, GstStateChange transition)
      51              : {
      52           66 :     RialtoMSESubtitleSink *sink = RIALTO_MSE_SUBTITLE_SINK(element);
      53              : 
      54           66 :     if (GST_STATE_CHANGE_NULL_TO_READY == transition)
      55              :     {
      56           21 :         GST_INFO_OBJECT(sink, "RialtoMSESubtitleSink state change to READY. Initializing delegate");
      57           21 :         rialto_mse_base_sink_initialise_delegate(RIALTO_MSE_BASE_SINK(sink),
      58           42 :                                                  std::make_shared<PullModeSubtitlePlaybackDelegate>(element));
      59              :     }
      60              : 
      61           66 :     GstStateChangeReturn result = GST_ELEMENT_CLASS(parent_class)->change_state(element, transition);
      62           66 :     if (G_UNLIKELY(result == GST_STATE_CHANGE_FAILURE))
      63              :     {
      64            1 :         GST_WARNING_OBJECT(sink, "State change failed");
      65            1 :         return result;
      66              :     }
      67              : 
      68           65 :     return result;
      69              : }
      70              : 
      71            7 : static void rialto_mse_subtitle_sink_get_property(GObject *object, guint propId, GValue *value, GParamSpec *pspec)
      72              : {
      73            7 :     switch (propId)
      74              :     {
      75            2 :     case PROP_MUTE:
      76              :     {
      77            2 :         g_value_set_boolean(value, FALSE); // Set default value first
      78            2 :         rialto_mse_base_sink_handle_get_property(RIALTO_MSE_BASE_SINK(object), IPlaybackDelegate::Property::Mute, value);
      79            2 :         break;
      80              :     }
      81            2 :     case PROP_TEXT_TRACK_IDENTIFIER:
      82              :     {
      83            2 :         g_value_set_string(value, ""); // Set default value first
      84            2 :         rialto_mse_base_sink_handle_get_property(RIALTO_MSE_BASE_SINK(object),
      85            2 :                                                  IPlaybackDelegate::Property::TextTrackIdentifier, value);
      86            2 :         break;
      87              :     }
      88            1 :     case PROP_WINDOW_ID:
      89              :     {
      90            1 :         g_value_set_uint(value, 0); // Set default value first
      91            1 :         rialto_mse_base_sink_handle_get_property(RIALTO_MSE_BASE_SINK(object), IPlaybackDelegate::Property::WindowId,
      92              :                                                  value);
      93            1 :         break;
      94              :     }
      95            1 :     case PROP_ASYNC:
      96              :     {
      97            1 :         g_value_set_boolean(value, FALSE); // Set default value first
      98            1 :         rialto_mse_base_sink_handle_get_property(RIALTO_MSE_BASE_SINK(object), IPlaybackDelegate::Property::Async, value);
      99            1 :         break;
     100              :     }
     101            1 :     default:
     102            1 :         G_OBJECT_WARN_INVALID_PROPERTY_ID(object, propId, pspec);
     103            1 :         break;
     104              :     }
     105            7 : }
     106              : 
     107           10 : static void rialto_mse_subtitle_sink_set_property(GObject *object, guint propId, const GValue *value, GParamSpec *pspec)
     108              : {
     109           10 :     switch (propId)
     110              :     {
     111            3 :     case PROP_MUTE:
     112            3 :         rialto_mse_base_sink_handle_set_property(RIALTO_MSE_BASE_SINK(object), IPlaybackDelegate::Property::Mute, value);
     113            3 :         break;
     114            4 :     case PROP_TEXT_TRACK_IDENTIFIER:
     115              :     {
     116            4 :         rialto_mse_base_sink_handle_set_property(RIALTO_MSE_BASE_SINK(object),
     117            4 :                                                  IPlaybackDelegate::Property::TextTrackIdentifier, value);
     118            4 :         break;
     119              :     }
     120            1 :     case PROP_WINDOW_ID:
     121              :     {
     122            1 :         rialto_mse_base_sink_handle_set_property(RIALTO_MSE_BASE_SINK(object), IPlaybackDelegate::Property::WindowId,
     123              :                                                  value);
     124            1 :         break;
     125              :     }
     126            1 :     case PROP_ASYNC:
     127              :     {
     128            1 :         rialto_mse_base_sink_handle_set_property(RIALTO_MSE_BASE_SINK(object), IPlaybackDelegate::Property::Async, value);
     129            1 :         break;
     130              :     }
     131            1 :     default:
     132            1 :         G_OBJECT_WARN_INVALID_PROPERTY_ID(object, propId, pspec);
     133            1 :         break;
     134              :     }
     135           10 : }
     136              : 
     137           21 : static void rialto_mse_subtitle_sink_init(RialtoMSESubtitleSink *sink)
     138              : {
     139           21 :     RialtoMSEBaseSinkPrivate *basePriv = sink->parent.priv;
     140              : 
     141           21 :     if (!rialto_mse_base_sink_initialise_sinkpad(RIALTO_MSE_BASE_SINK(sink)))
     142              :     {
     143            0 :         GST_ERROR_OBJECT(sink, "Failed to initialise SUBTITLE sink. Sink pad initialisation failed.");
     144            0 :         return;
     145              :     }
     146              : 
     147           21 :     gst_pad_set_chain_function(basePriv->m_sinkPad, rialto_mse_base_sink_chain);
     148           21 :     gst_pad_set_event_function(basePriv->m_sinkPad, rialto_mse_base_sink_event);
     149              : }
     150              : 
     151            1 : static void rialto_mse_subtitle_sink_class_init(RialtoMSESubtitleSinkClass *klass)
     152              : {
     153            1 :     GObjectClass *gobjectClass = G_OBJECT_CLASS(klass);
     154            1 :     GstElementClass *elementClass = GST_ELEMENT_CLASS(klass);
     155            1 :     gobjectClass->get_property = rialto_mse_subtitle_sink_get_property;
     156            1 :     gobjectClass->set_property = rialto_mse_subtitle_sink_set_property;
     157            1 :     elementClass->change_state = rialto_mse_subtitle_sink_change_state;
     158              : 
     159            1 :     g_object_class_install_property(gobjectClass, PROP_MUTE,
     160              :                                     g_param_spec_boolean("mute", "Mute", "Mute subtitles", FALSE, G_PARAM_READWRITE));
     161              : 
     162            1 :     g_object_class_install_property(gobjectClass, PROP_TEXT_TRACK_IDENTIFIER,
     163              :                                     g_param_spec_string("text-track-identifier", "Text Track Identifier",
     164              :                                                         "Identifier of text track. Valid input for service is "
     165              :                                                         "\"CC[1-4]\", \"TEXT[1-4]\", \"SERVICE[1-64]\"",
     166              :                                                         nullptr, GParamFlags(G_PARAM_READWRITE)));
     167              : 
     168            1 :     g_object_class_install_property(gobjectClass, PROP_WINDOW_ID,
     169              :                                     g_param_spec_uint("window-id", "Window ID", "Id of window (placeholder)", 0, 256, 0,
     170              :                                                       GParamFlags(G_PARAM_READWRITE)));
     171              : 
     172            1 :     g_object_class_install_property(gobjectClass, PROP_ASYNC,
     173              :                                     g_param_spec_boolean("async", "Async", "Asynchronous mode", FALSE, G_PARAM_READWRITE));
     174              : 
     175              :     std::unique_ptr<firebolt::rialto::IMediaPipelineCapabilities> mediaPlayerCapabilities =
     176            1 :         firebolt::rialto::IMediaPipelineCapabilitiesFactory::createFactory()->createMediaPipelineCapabilities();
     177            1 :     if (mediaPlayerCapabilities)
     178              :     {
     179              :         std::vector<std::string> supportedMimeTypes =
     180            1 :             mediaPlayerCapabilities->getSupportedMimeTypes(firebolt::rialto::MediaSourceType::SUBTITLE);
     181              : 
     182            1 :         rialto_mse_sink_setup_supported_caps(elementClass, supportedMimeTypes);
     183              :     }
     184              :     else
     185              :     {
     186            0 :         GST_ERROR("Failed to get supported mime types for Subtitle");
     187              :     }
     188              : 
     189            1 :     gst_element_class_set_details_simple(elementClass, "Rialto Subtitle Sink", "Parser/Subtitle/Sink/Subtitle",
     190              :                                          "Communicates with Rialto Server", "Sky");
     191              : }
        

Generated by: LCOV version 2.0-1