How to get current rtspsrc name from plugin.

Rahibe Meryem rahibemeryem at gmail.com
Sat Jul 8 10:47:35 UTC 2023


Hi Comrades :)

I have a pipeline and dynamically loading .so to execute c++ codes. Fro the loader filter get plugin I want to get the current rtspsrc name to understand where is this frame coming from. 

This one the plugin loading the so. I need to put c++ code in this zumbafilter plugin to find the current rtspsrc source name.
----------------
! zumbafilter function-name=alp_crop config-path=aliveliDereliX use-gst-buffer=true so-path=/local/workspace/lappa/core/zumba/build.release/libs/postprocesses/libalpullu_crop.so 
-----------------
Here the Gstreamer pipeline:

gst-launch-1.0 funnel name=fun 

! queue name=zumba_pre_convert_0 leaky=no max-size-buffers=30 max-size-bytes=0 max-size-time=0 

! videoconvert n-threads=1 qos=false 

! video/x-raw,format=RGB 

! queue name=zumba_pre_cropper1_q leaky=no max-size-buffers=30 max-size-bytes=0 max-size-time=0 

! zumbacropper so-path=/local/workspace/lappa/apps/gstreamer/libs/post_processes//cropping_algorithms/libwhole_buffer.so function-name=create_crops use-letterbox=true resize-method=inter-area internal-offset=true name=cropper1 zumbaaggregator name=agg1 cropper1. 

! queue name=bypess1_q leaky=no max-size-buffers=30 max-size-bytes=0 max-size-time=0 

! agg1. cropper1. 

! queue name=zumba_pre_detector_q leaky=no max-size-buffers=30 max-size-bytes=0 max-size-time=0 

! zumbanet pth-path=/local/workspace/lappa/apps/gstreamer/general/multi_person_multi_camera_tracking/resources/yolov5s_personface.pth scheduling-algorithm=1 vdevice-key=1 

! queue name=detector_post_q leaky=no max-size-buffers=1000 max-size-bytes=0 max-size-time=0 

! zumbafilter so-path=/local/workspace/lappa/apps/gstreamer/libs/post_processes//libyolo_post.so qos=false function_name=yolov5_personface_letterbox config-path=/local/workspace/lappa/apps/gstreamer/general/multi_person_multi_camera_tracking/resources/configs/yolov5_personface.json 

! queue name=detector_pre_agg_q leaky=no max-size-buffers=30 max-size-bytes=0 max-size-time=0 

! agg1. agg1. 

! queue name=zumba_pre_tracker leaky=no max-size-buffers=30 max-size-bytes=0 max-size-time=0 

! zumbatracker name=zumba_tracker class-id=1 kalman-dist-thr=0.7 iou-thr=0.7 init-iou-thr=0.8 keep-new-frames=2 keep-tracked-frames=4 keep-lost-frames=8 qos=false 

! queue leaky=no max-size-buffers=60 max-size-bytes=0 max-size-time=0 

! zumbafilter function-name=alp_crop config-path=aliveliDereliX use-gst-buffer=true so-path=/local/workspace/lappa/core/zumba/build.release/libs/postprocesses/libalpullu_crop.so 

! queue name=zumba_pre_cropper2_q leaky=no max-size-buffers=30 max-size-bytes=0 max-size-time=0 

! zumbacropper so-path=/local/workspace/lappa/apps/gstreamer/libs/post_processes//cropping_algorithms/libre_id.so function-name=create_crops internal-offset=true name=cropper2 zumbaaggregator name=agg2 cropper2. 

! queue name=bypess2_q leaky=no max-size-buffers=30 max-size-bytes=0 max-size-time=0 

! agg2. cropper2. 

! queue name=pre_reid_q leaky=no max-size-buffers=10 max-size-bytes=0 max-size-time=0 

! zumbanet pth-path=/local/workspace/lappa/apps/gstreamer/general/multi_person_multi_camera_tracking/resources/repvgg_a0_person_reid_2048.pth scheduling-algorithm=1 vdevice-key=1 

! queue name=reid_post_q leaky=no max-size-buffers=10 max-size-bytes=0 max-size-time=0 

! zumbafilter so-path=/local/workspace/lappa/apps/gstreamer/libs/post_processes//libre_id.so qos=false 

! queue name=reid_pre_agg_q leaky=no max-size-buffers=10 max-size-bytes=0 max-size-time=0 

! agg2. agg2. 

! queue name=zumba_pre_gallery leaky=no max-size-buffers=30 max-size-bytes=0 max-size-time=0 

! zumbagallery similarity-thr=.4 gallery-queue-size=100 class-id=1 

! queue name=zumba_post_gallery leaky=no max-size-buffers=30 max-size-bytes=0 max-size-time=0 

! videoscale n-threads=2 add-borders=false qos=false 

! video/x-raw, width=800, height=450, pixel-aspect-ratio=1/1 

! queue name=zumba_pre_draw leaky=no max-size-buffers=30 max-size-bytes=0 max-size-time=0 

! zumbafilter use-gst-buffer=true so-path=/local/workspace/lappa/apps/gstreamer/libs/apps/re_id//libre_id_overlay.so qos=false 

! queue name=zumba_post_draw leaky=no max-size-buffers=30 max-size-bytes=0 max-size-time=0 

! streamiddemux name=sid compositor name=comp start-time-selection=0 sink_0::xpos=0 sink_0::ypos=0 sink_1::xpos=640 sink_1::ypos=0 sink_2::xpos=1280 sink_2::ypos=0 sink_3::xpos=1920 sink_3::ypos=0 sink_4::xpos=0 sink_4::ypos=640 sink_5::xpos=640 sink_5::ypos=640 sink_6::xpos=1280 sink_6::ypos=640 sink_7::xpos=1920 sink_7::ypos=640 sink_8::xpos=0 sink_8::ypos=1280 sink_9::xpos=640 sink_9::ypos=1280 sink_10::xpos=1280 sink_10::ypos=1280 sink_11::xpos=1920 sink_11::ypos=1280 sink_12::xpos=0 sink_12::ypos=1920 sink_13::xpos=640 sink_13::ypos=1920 sink_14::xpos=1280 sink_14::ypos=1920 sink_15::xpos=1920 sink_15::ypos=1920 

! queue name=zumba_video_q_0 leaky=no max_size_buffers=30 max-size-bytes=0 max-size-time=0 

! videoconvert n-threads=2 qos=false 

! queue name=zumba_display_q_0 leaky=no max_size_buffers=300 max-size-bytes=0 max-size-time=0 

! fpsdisplaysink video-sink=xvimagesink name=zumba_display sync=false text-overlay=false rtspsrc async-handling=true location='rtsp://zumba:zumba2023@172.16.100.20:554/cam/realmonitor?channel=25&subtype=0' name=source_0 message-forward=true 

! decodebin 

! queue name=zumba_preprocess_q_0 leaky=no max-size-buffers=32 max-size-bytes=0 max-size-time=0 

! decodebin3 

! queue leaky=downstream max-size-buffers=32 max-size-bytes=0 max-size-time=0 

! videoscale n-threads=8 

! video/x-raw,pixel-aspect-ratio=1/1 

! videoconvert n-threads=8 

! video/x-raw,pixel-aspect-ratio=1/1 

! fun.sink_0 sid.src_0 

! queue name=comp_q_0 leaky=downstream max-size-buffers=5 max-size-bytes=0 max-size-time=0 

! comp.sink_0 rtspsrc async-handling=true location='rtsp://zumba:zumba2023@172.16.100.20:554/cam/realmonitor?channel=64&subtype=0' name=source_1 message-forward=true 

! decodebin 

! queue name=zumba_preprocess_q_1 leaky=no max-size-buffers=32 max-size-bytes=0 max-size-time=0 

! decodebin3 

! queue leaky=downstream max-size-buffers=32 max-size-bytes=0 max-size-time=0 

! videoscale n-threads=8 

! video/x-raw,pixel-aspect-ratio=1/1 

! videoconvert n-threads=8 

! video/x-raw,pixel-aspect-ratio=1/1 

! fun.sink_1 sid.src_1 

! queue name=comp_q_1 leaky=downstream max-size-buffers=5 max-size-bytes=0 max-size-time=0 

! comp.sink_1 rtspsrc async-handling=true location='rtsp://zumba:zumba2023@172.16.100.20:554/cam/realmonitor?channel=48&subtype=0' name=source_2 message-forward=true 

! decodebin 

! queue name=zumba_preprocess_q_2 leaky=no max-size-buffers=32 max-size-bytes=0 max-size-time=0 

! decodebin3 

! queue leaky=downstream max-size-buffers=32 max-size-bytes=0 max-size-time=0 

! videoscale n-threads=8 

! video/x-raw,pixel-aspect-ratio=1/1 

! videoconvert n-threads=8 

! video/x-raw,pixel-aspect-ratio=1/1 

! fun.sink_2 sid.src_2 

! queue name=comp_q_2 leaky=downstream max-size-buffers=5 max-size-bytes=0 max-size-time=0 

! comp.sink_2




Plugin code:




GST_DEBUG_CATEGORY_STATIC(gst_zumbafilter_debug_category);
#define GST_CAT_DEFAULT gst_zumbafilter_debug_category
#define DEFAULT_FUNCTION_NAME "filter"
#define INIT_FUNC_NAME "init"
#define FREE_FUNC_NAME "free_resources"

static void gst_zumbafilter_set_property(GObject *object,
                                         guint property_id, const GValue *value, GParamSpec *pspec);
static void gst_zumbafilter_get_property(GObject *object,
                                         guint property_id, GValue *value, GParamSpec *pspec);
static void gst_zumbafilter_dispose(GObject *object);
static void gst_zumbafilter_finalize(GObject *object);

static gboolean gst_zumbafilter_start(GstBaseTransform *trans);
static gboolean gst_zumbafilter_stop(GstBaseTransform *trans);
static GstFlowReturn gst_zumbafilter_transform_ip(GstBaseTransform *trans,
                                                  GstBuffer *buffer);

enum
{
    PROP_0,
    PROP_PROCESS_LIB,
    PROP_PROCESS_FUNC_NAME,
    PROP_USE_GST_BUFFER,
    PROP_CONFIG_FILE_PATH,
};

G_DEFINE_TYPE_WITH_CODE(Gstzumbafilter, gst_zumbafilter, GST_TYPE_BASE_TRANSFORM,
                        GST_DEBUG_CATEGORY_INIT(gst_zumbafilter_debug_category, "zumbafilter", 0,
                                                "debug category for zumbafilter element"));

static void
gst_zumbafilter_class_init(GstzumbafilterClass *klass)
{
    GObjectClass *gobject_class = G_OBJECT_CLASS(klass);
    GstBaseTransformClass *base_transform_class =
        GST_BASE_TRANSFORM_CLASS(klass);

    gst_element_class_add_pad_template(GST_ELEMENT_CLASS(klass),
                                       gst_pad_template_new("src", GST_PAD_SRC, GST_PAD_ALWAYS,
                                                            GST_CAPS_ANY));
    gst_element_class_add_pad_template(GST_ELEMENT_CLASS(klass),
                                       gst_pad_template_new("sink", GST_PAD_SINK, GST_PAD_ALWAYS,
                                                            GST_CAPS_ANY));

    gst_element_class_set_static_metadata(GST_ELEMENT_CLASS(klass),
                                          "zumbafilter - postprocessing element", "zumba/Tools", "Allowes to user access zumbanet's output using an so file.",
                                          "zumba.ai <contact at zumba.ai>");

    gobject_class->set_property = gst_zumbafilter_set_property;
    gobject_class->get_property = gst_zumbafilter_get_property;
    g_object_class_install_property(gobject_class, PROP_PROCESS_LIB,
                                    g_param_spec_string("so-path", "process so Path Location",
                                                        "Location of the so file to load", NULL,
                                                        (GParamFlags)(G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | GST_PARAM_MUTABLE_READY)));
    g_object_class_install_property(gobject_class, PROP_PROCESS_FUNC_NAME,
                                    g_param_spec_string("function-name", "Name of function in the so file",
                                                        "function-name", "filter",
                                                        (GParamFlags)(G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | GST_PARAM_MUTABLE_READY)));
    g_object_class_install_property(gobject_class, PROP_USE_GST_BUFFER,
                                    g_param_spec_boolean("use-gst-buffer", "use-gst-buffer", "use function with access to the Gst Buffer", false,
                                                         (GParamFlags)(GST_PARAM_CONTROLLABLE | G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));
    g_object_class_install_property(gobject_class, PROP_CONFIG_FILE_PATH,
                                    g_param_spec_string("config-path", "config-path",
                                                        "json config file path", NULL,
                                                        (GParamFlags)(G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | GST_PARAM_MUTABLE_READY)));

    gobject_class->dispose = gst_zumbafilter_dispose;
    gobject_class->finalize = gst_zumbafilter_finalize;
    base_transform_class->start = GST_DEBUG_FUNCPTR(gst_zumbafilter_start);
    base_transform_class->stop = GST_DEBUG_FUNCPTR(gst_zumbafilter_stop);
    base_transform_class->transform_ip = GST_DEBUG_FUNCPTR(gst_zumbafilter_transform_ip);
}



static void
gst_zumbafilter_init(Gstzumbafilter *zumbafilter)
{
    zumbafilter->use_config = true;
    zumbafilter->params = nullptr;
    zumbafilter->config_path = g_strdup("NULL");
}

void gst_zumbafilter_set_property(GObject *object, guint property_id,
                                  const GValue *value, GParamSpec *pspec)
{
    Gstzumbafilter *zumbafilter = GST_zumba_FILTER(object);

    GST_DEBUG_OBJECT(zumbafilter, "set_property");

    switch (property_id)
    {
    case PROP_PROCESS_LIB:
        zumbafilter->lib_path = g_strdup(g_value_get_string(value));
        break;
    case PROP_PROCESS_FUNC_NAME:
        zumbafilter->function_name = g_strdup(g_value_get_string(value));
        break;
    case PROP_USE_GST_BUFFER:
        zumbafilter->use_gst_buffer = g_value_get_boolean(value);
        break;
    case PROP_CONFIG_FILE_PATH:
        zumbafilter->config_path = g_strdup(g_value_get_string(value));
        break;

    default:
        G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec);
        break;
    }
}

void gst_zumbafilter_get_property(GObject *object, guint property_id,
                                  GValue *value, GParamSpec *pspec)
{
    Gstzumbafilter *zumbafilter = GST_zumba_FILTER(object);

    GST_DEBUG_OBJECT(zumbafilter, "get_property");

    switch (property_id)
    {
    case PROP_PROCESS_LIB:
        g_value_set_string(value, zumbafilter->lib_path);
        break;
    case PROP_PROCESS_FUNC_NAME:
        g_value_set_string(value, zumbafilter->function_name);
        break;
    case PROP_USE_GST_BUFFER:
        g_value_set_boolean(value, zumbafilter->use_gst_buffer);
        break;
    case PROP_CONFIG_FILE_PATH:
        g_value_set_string(value, zumbafilter->config_path);
        break;

    default:
        G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec);
        break;
    }
}
void gst_zumbafilter_dispose(GObject *object)
{
    Gstzumbafilter *zumbafilter = GST_zumba_FILTER(object);
    if (zumbafilter->params != nullptr)
    {
        auto delete_func = (void (*)(void *))dlsym(zumbafilter->loaded_lib, FREE_FUNC_NAME);
        delete_func(zumbafilter->params);
    }
    if (zumbafilter->loaded_lib != nullptr)
    {
        dlclose(zumbafilter->loaded_lib);
    }

    GST_DEBUG_OBJECT(zumbafilter, "dispose");

    /* clean up as possible.  may be called multiple times */

    G_OBJECT_CLASS(gst_zumbafilter_parent_class)->dispose(object);
}

void gst_zumbafilter_finalize(GObject *object)
{
    Gstzumbafilter *zumbafilter = GST_zumba_FILTER(object);

    GST_DEBUG_OBJECT(zumbafilter, "finalize");

    /* clean up object here */

    G_OBJECT_CLASS(gst_zumbafilter_parent_class)->finalize(object);
}


static gboolean gst_zumbafilter_start(GstBaseTransform *trans)
{
    
    std::string RTSP_NAME = "b o s ";
   
     GstPad *srcpad = gst_element_get_static_pad(GST_ELEMENT(trans), "src");

    if (srcpad) {
        const gchar *padName = GST_OBJECT_NAME(srcpad);
        RTSP_NAME = std::string(padName);
        gst_object_unref(srcpad);
    }
    std::cout << ":::::::-----:::::::"  << RTSP_NAME << ":::::::-----:::::::";
    Gstzumbafilter *zumbafilter = GST_zumba_FILTER(trans);
    // Load the give SO using dlopen.
    zumbafilter->loaded_lib = dlopen(zumbafilter->lib_path, RTLD_LAZY);

    if (!zumbafilter->loaded_lib)
    {
        std::cerr << "Could not load lib " << dlerror() << std::endl;
    }
    // reset errors
    dlerror();

    // Use the default function name if no name was provided.
    if (zumbafilter->function_name == nullptr)
    {
        zumbafilter->function_name = g_strdup(DEFAULT_FUNCTION_NAME);
    }

    // Create handler for all function-names on the list.
    //Added the new string for sending PADNAME to the so
    auto init_func = (void *(*)(std::string, std::string, std::string))dlsym(zumbafilter->loaded_lib, INIT_FUNC_NAME);

    if (init_func == nullptr)
    {
        zumbafilter->use_config = false;

        if (zumbafilter->use_gst_buffer)
        {
            /*
            if use_gst_buffer, the function should have three arguments (zumbaROIPtr, GstVideoFrame*, and gchar*),
            and therefore will be able to change the buffer data.
            */

            zumbafilter->handler_gst_no_config = (void (*)(zumbaROIPtr, GstVideoFrame *, gchar *))dlsym(zumbafilter->loaded_lib, zumbafilter->function_name);
        }
        else
        {
            /*
            in this case the funtion doesn't get GstVideoFrame* as argument therefore it can't modify the buffer data.
            */
            zumbafilter->handler_no_config = (void (*)(zumbaROIPtr))dlsym(zumbafilter->loaded_lib, zumbafilter->function_name);
        }
    }
    else // found init function
    {
        
        GstElement *rtspsrcElement = gst_pad_get_parent_element(GST_PAD(trans->srcpad));
        g_object_get(G_OBJECT(rtspsrcElement), "name", &zumbafilter->rtspsrc_name, NULL);
        g_object_unref(rtspsrcElement);

        zumbafilter->params = init_func(zumbafilter->config_path, zumbafilter->function_name , zumbafilter->rtspsrc_name);
        if (zumbafilter->use_gst_buffer)
        {
            /*
            if use_gst_buffer, the function should have four arguments (zumbaROIPtr, GstVideoFrame*, and gchar*,void *),
            and therefore will be able to change the buffer data.
            */
            zumbafilter->handler_gst = (void (*)(zumbaROIPtr, GstVideoFrame *, gchar *, void *))dlsym(zumbafilter->loaded_lib, zumbafilter->function_name);
        }
        else
        {
            /*
                       in this case the funtion doesn't get GstVideoFrame* as argument therefore it can't modify the buffer data.
            */
            zumbafilter->handler = (void (*)(zumbaROIPtr, void *))dlsym(zumbafilter->loaded_lib, zumbafilter->function_name);
        }
    }
    // If there was an error loading one of the symbols, close the dl and break.
    const char *dlsym_error = dlerror();
    if (dlsym_error)
    {
        std::cerr << "Cannot load symbol: " << dlsym_error << std::endl;
        dlclose(zumbafilter->loaded_lib);
    }

    GST_DEBUG_OBJECT(zumbafilter, "start");

    return TRUE;
}

static gboolean
gst_zumbafilter_stop(GstBaseTransform *trans)
{
    Gstzumbafilter *zumbafilter = GST_zumba_FILTER(trans);

    GST_DEBUG_OBJECT(zumbafilter, "stop");

    return TRUE;
}

/**
 * @brief Get the tensors from meta object
 *
 * @param buffer The buffer to extract the tensor_meta from.
 * @param roi ROI to add the tensors to.
 * @note This function implementation should be changed according to HRT-5150 on the next release.
 */
void get_tensors_from_meta(GstBuffer *buffer, zumbaROIPtr roi)
{
    gpointer state = NULL;
    GstMeta *meta;
    GstParentBufferMeta *pmeta;
    GstMapInfo info;
    while ((meta = gst_buffer_iterate_meta_filtered(buffer, &state, GST_PARENT_BUFFER_META_API_TYPE)))
    {
        pmeta = reinterpret_cast<GstParentBufferMeta *>(meta);
        (void)gst_buffer_map(pmeta->buffer, &info, GST_MAP_READWRITE);
        const zumba_vstream_info_t vstream_info = reinterpret_cast<GstzumbaTensorMeta *>(gst_buffer_get_meta(pmeta->buffer, g_type_from_name(TENSOR_META_API_NAME)))->info;
        roi->add_tensor(std::make_shared<zumbaTensor>(reinterpret_cast<uint8_t *>(info.data), vstream_info));
        gst_buffer_unmap(pmeta->buffer, &info);
    }
}

/**
 * @brief Remove all tensors from the buffer and the ROI.
 *
 * @param buffer The buffer to remove tensors from.
 * @param roi The roi to remove tensors from.
 * @return gboolean true if all removals were successful, false otherwise.
 */
gboolean remove_tensors(GstBuffer *buffer, zumbaROIPtr roi)
{
    gpointer state = NULL;
    GstMeta *meta;
    std::vector<GstMeta *> meta_vector;
    gboolean ret = false;
    roi->clear_tensors();
    while ((meta = gst_buffer_iterate_meta_filtered(buffer, &state, GST_PARENT_BUFFER_META_API_TYPE)))
    {
        meta_vector.emplace_back(std::move(meta));
    }
    for (auto meta : meta_vector)
    {
        ret = gst_buffer_remove_meta(buffer, meta);
        if (ret == false)
            return ret;
    }
    return true;
}

static GstFlowReturn gst_zumbafilter_transform_ip(GstBaseTransform *trans,
                                                  GstBuffer *buffer)
{
    Gstzumbafilter *zumbafilter = GST_zumba_FILTER(trans);
   
    


    zumbaROIPtr zumba_roi = get_zumba_main_roi(buffer, true);
    get_tensors_from_meta(buffer, zumba_roi);
    // Call all functions.

    if (zumbafilter->use_gst_buffer)
    {
        GstPad *srcpad = trans->srcpad;
        GstCaps *caps = gst_pad_get_current_caps(srcpad);
        gchar *stream_id = gst_pad_get_stream_id(srcpad);
        GstVideoFrame frame;
        GstVideoInfo info;
        gst_video_info_from_caps(&info, caps);
        gst_caps_unref(caps);

        
        if (!gst_video_frame_map(&frame, &info, buffer, GstMapFlags(GST_MAP_READ | GST_MAP_WRITE)))
        {
            std::cerr << "Cannot map buffer to frame" << std::endl;
        }
        if (zumbafilter->use_config)
        {
            auto handler = zumbafilter->handler_gst;
            handler(zumba_roi, &frame, stream_id, zumbafilter->params);
        }
        else
        {
            auto handler = zumbafilter->handler_gst_no_config;
            handler(zumba_roi, &frame, stream_id);
        }
        gst_video_frame_unmap(&frame);
        g_free(stream_id);
    }
    else
    {
        if (zumbafilter->use_config)
        {
            auto handler = zumbafilter->handler;
            handler(zumba_roi, zumbafilter->params);
        }
        else
        {
            auto handler = zumbafilter->handler_no_config;
            handler(zumba_roi);
        }
    }

    remove_tensors(buffer, zumba_roi);
    GST_DEBUG_OBJECT(zumbafilter, "transform_ip");
    return GST_FLOW_OK;
}





I am new to Gstreamer… not found a way to get current rtspsrc name .. any help and idea appreciated. 


Best



More information about the gstreamer-devel mailing list