LCOV - code coverage report
Current view: top level - src/lib/caps.c (source / functions) Coverage Total Hit
Test: coverage.filtered.info Lines: 85.7 % 35 30
Test Date: 2025-09-18 00:43:48 Functions: 100.0 % 4 4

            Line data    Source code
       1              : /*
       2              :  *                      GPAC - Multimedia Framework C SDK
       3              :  *
       4              :  *                      Authors: Deniz Ugur, Romain Bouqueau, Sohaib Larbi
       5              :  *                      Copyright (c) Motion Spell
       6              :  *                              All rights reserved
       7              :  *
       8              :  *  This file is part of the GPAC/GStreamer wrapper
       9              :  *
      10              :  *  This GPAC/GStreamer wrapper is free software; you can redistribute it
      11              :  *  and/or modify it under the terms of the GNU Affero General Public License
      12              :  *  as published by the Free Software Foundation; either version 3, or (at
      13              :  *  your option) any later version.
      14              :  *
      15              :  *  This GPAC/GStreamer wrapper is distributed in the hope that it will be
      16              :  *  useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
      17              :  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      18              :  *  GNU Affero General Public License for more details.
      19              :  *
      20              :  *  You should have received a copy of the GNU Affero General Public
      21              :  *  License along with this library; see the file LICENSE.  If not, write to
      22              :  *  the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
      23              :  *
      24              :  */
      25              : 
      26              : #include "lib/caps.h"
      27              : 
      28              : GstGpacFormatProp gst_gpac_sink_formats = {
      29              :   .video_caps = GST_STATIC_CAPS(AV1_CAPS "; " H264_CAPS "; " H265_CAPS),
      30              :   .audio_caps = GST_STATIC_CAPS(AAC_CAPS "; " EAC3_CAPS),
      31              :   .subtitle_caps = GST_STATIC_CAPS(TEXT_UTF8),
      32              :   .caption_caps = GST_STATIC_CAPS(CEA708_CAPS),
      33              : };
      34              : 
      35              : GstPadTemplate* sink_templates[4] = { NULL };
      36              : 
      37              : GstPadTemplate*
      38        13071 : gst_gpac_get_sink_template(GstGpacSinkTemplateType type)
      39              : {
      40        13071 :   return sink_templates[type];
      41              : }
      42              : 
      43              : void
      44            4 : gpac_install_sink_pad_templates(GstElementClass* klass)
      45              : {
      46              :   // Video pad template
      47            4 :   if (sink_templates[GPAC_TEMPLATE_VIDEO] == NULL) {
      48            2 :     sink_templates[GPAC_TEMPLATE_VIDEO] = gst_pad_template_new(
      49              :       "video_%u",
      50              :       GST_PAD_SINK,
      51              :       GST_PAD_REQUEST,
      52              :       gst_static_caps_get(&gst_gpac_sink_formats.video_caps));
      53              :   }
      54            4 :   gst_element_class_add_pad_template(klass,
      55              :                                      sink_templates[GPAC_TEMPLATE_VIDEO]);
      56              : 
      57              :   // Audio pad template
      58            4 :   if (sink_templates[GPAC_TEMPLATE_AUDIO] == NULL) {
      59            2 :     sink_templates[GPAC_TEMPLATE_AUDIO] = gst_pad_template_new(
      60              :       "audio_%u",
      61              :       GST_PAD_SINK,
      62              :       GST_PAD_REQUEST,
      63              :       gst_static_caps_get(&gst_gpac_sink_formats.audio_caps));
      64              :   }
      65            4 :   gst_element_class_add_pad_template(klass,
      66              :                                      sink_templates[GPAC_TEMPLATE_AUDIO]);
      67              : 
      68              :   // NOLINTNEXTLINE
      69              : #if 0 // FIXME: Subtitle and caption support has not been tested yet
      70              :   // Subtitle pad template
      71              :   if (sink_templates[GPAC_TEMPLATE_SUBTITLE] == NULL) {
      72              :     sink_templates[GPAC_TEMPLATE_SUBTITLE] = gst_pad_template_new(
      73              :       "subtitle_%u",
      74              :       GST_PAD_SINK,
      75              :       GST_PAD_REQUEST,
      76              :       gst_static_caps_get(&gst_gpac_sink_formats.subtitle_caps));
      77              :   }
      78              :   gst_element_class_add_pad_template(klass, sink_templates[GPAC_TEMPLATE_SUBTITLE]);
      79              : 
      80              :   // Caption pad template
      81              :   if (sink_templates[GPAC_TEMPLATE_CAPTION] == NULL) {
      82              :     sink_templates[GPAC_TEMPLATE_CAPTION] = gst_pad_template_new(
      83              :       "caption_%u",
      84              :       GST_PAD_SINK,
      85              :       GST_PAD_REQUEST,
      86              :       gst_static_caps_get(&gst_gpac_sink_formats.caption_caps));
      87              :   }
      88              :   gst_element_class_add_pad_template(klass, sink_templates[GPAC_TEMPLATE_CAPTION]);
      89              : #endif
      90            4 : }
      91              : 
      92              : GstStaticPadTemplate gst_gpac_src_template =
      93              :   GST_STATIC_PAD_TEMPLATE("src",
      94              :                           GST_PAD_SRC,
      95              :                           GST_PAD_ALWAYS,
      96              :                           GST_STATIC_CAPS(QT_CAPS "; " MPEG_TS_CAPS));
      97              : 
      98              : void
      99            4 : gpac_install_src_pad_templates(GstElementClass* klass)
     100              : {
     101            4 :   gst_element_class_add_static_pad_template(klass, &gst_gpac_src_template);
     102            4 : }
     103              : 
     104              : GF_FilterCapability*
     105            9 : gpac_gstcaps_to_gfcaps(GstCaps* caps, guint* nb_caps)
     106              : {
     107            9 :   if (!caps)
     108            0 :     return NULL;
     109              : 
     110              :   // Get the structure from the caps
     111            9 :   if (gst_caps_get_size(caps) == 0) {
     112            0 :     GST_ERROR("No structure in caps");
     113            0 :     return NULL;
     114              :   }
     115            9 :   if (gst_caps_get_size(caps) > 1)
     116            0 :     GST_WARNING("Multiple structures in caps, will only use the first one");
     117            9 :   GstStructure* structure = gst_caps_get_structure(caps, 0);
     118              : 
     119              :   /**
     120              :    * Currently, we only support file output stream. Therefore, we only need to
     121              :    * set MIME type and stream type.
     122              :    */
     123              : 
     124              :   // Allocate the capabilities
     125            9 :   *nb_caps = 2;
     126            9 :   GF_FilterCapability* gf_caps = g_new0(GF_FilterCapability, *nb_caps);
     127            9 :   if (!gf_caps)
     128            0 :     return NULL;
     129              : 
     130              :   // Set the stream type
     131            9 :   gf_caps[0].code = GF_PROP_PID_STREAM_TYPE;
     132            9 :   gf_caps[0].val.type = GF_PROP_UINT;
     133            9 :   gf_caps[0].val.value.uint = GF_STREAM_FILE;
     134            9 :   gf_caps[0].flags = GF_CAPS_INPUT;
     135              : 
     136              :   // Set the mime type
     137            9 :   gf_caps[1].code = GF_PROP_PID_MIME;
     138            9 :   gf_caps[1].val.type = GF_PROP_STRING;
     139            9 :   gf_caps[1].val.value.string = g_strdup(gst_structure_get_name(structure));
     140            9 :   gf_caps[1].flags = GF_CAPS_INPUT;
     141              : 
     142            9 :   return gf_caps;
     143              : }
        

Generated by: LCOV version 2.0-1