LCOV - code coverage report
Current view: top level - src/lib/conversion/pid/query_handlers.c (source / functions) Coverage Total Hit
Test: coverage.filtered.info Lines: 86.4 % 22 19
Test Date: 2025-11-16 07:16:50 Functions: 100.0 % 1 1

            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 "common.h"
      27              : #include "gpacmessages.h"
      28              : #include "lib/pid.h"
      29              : 
      30              : #define QUERY_HANDLER_SIGNATURE(prop_nickname)                    \
      31              :   gboolean prop_nickname##_query_handler(GPAC_PID_PROP_IMPL_ARGS)
      32              : 
      33              : #define DEFAULT_HANDLER(prop_nickname)                            \
      34              :   gboolean prop_nickname##_query_handler(GPAC_PID_PROP_IMPL_ARGS) \
      35              :   {                                                               \
      36              :     return FALSE;                                                 \
      37              :   }
      38              : 
      39              : //
      40              : // Default Query handlers
      41              : //
      42              : 
      43              : //
      44              : // Query handlers
      45              : //
      46           21 : QUERY_HANDLER_SIGNATURE(duration)
      47              : {
      48              :   const GF_PropertyValue* p;
      49              : 
      50              :   // For text streams, we do not set duration
      51           21 :   p = gf_filter_pid_get_property(pid, GF_PROP_PID_STREAM_TYPE);
      52           21 :   if (p && p->value.uint == GF_STREAM_TEXT)
      53            0 :     return TRUE;
      54              : 
      55              :   // Query the duration
      56           42 :   g_autoptr(GstQuery) query = gst_query_new_duration(GST_FORMAT_TIME);
      57           21 :   gboolean ret = gst_pad_peer_query(priv->self, query);
      58           21 :   if (!ret) {
      59            0 :     GST_ELEMENT_ERROR(
      60              :       element, LIBRARY, FAILED, (NULL), ("Failed to query duration"));
      61            0 :     return FALSE;
      62              :   }
      63              : 
      64              :   // Parse the duration
      65              :   gint64 duration;
      66           21 :   gst_query_parse_duration(query, NULL, &duration);
      67              : 
      68              :   // Get the fps from the PID
      69           21 :   GF_Fraction fps = { 30, 1 };
      70           21 :   p = gf_filter_pid_get_property(pid, GF_PROP_PID_FPS);
      71           21 :   if (p)
      72           18 :     fps = p->value.frac;
      73              : 
      74              :   // Get the timescale from the PID
      75           21 :   guint64 timescale = GST_SECOND;
      76           21 :   p = gf_filter_pid_get_property(pid, GF_PROP_PID_TIMESCALE);
      77           21 :   if (p)
      78           21 :     timescale = p->value.uint;
      79              : 
      80              :   // Construct the duration
      81           21 :   GF_Fraction64 duration_fr = {
      82           21 :     .num = (s64)gpac_time_rescale_with_fps(duration, fps, timescale),
      83              :     .den = timescale,
      84              :   };
      85              : 
      86              :   // Set the duration
      87           21 :   SET_PROP(GF_PROP_PID_DURATION, PROP_FRAC64(duration_fr));
      88           21 :   return TRUE;
      89              : }
        

Generated by: LCOV version 2.0-1