After each time GStreamer destroys and recreates the pipeline, an file descriptor for /dev/video0 and 4 socket file descriptors remain ,why?

petalinux2023.2
GStreamer Core Library version 1.20.5

with
gst_debug_bin_to_dot_file(
GST_BIN(play_ptr->pipeline),
GST_DEBUG_GRAPH_SHOW_ALL,
“pipeline-structure”
);

create

VGST_ERROR_LOG wy_create_pipeline (vgst_ip_params *ip_param, vgst_enc_params *enc_param, vgst_playback *play_ptr, guint sink_type, gchar *uri, vgst_aud_params *aud_param)
{
    play_ptr->pipeline        = gst_pipeline_new ("pipeline");
    play_ptr->ip_src          = gst_element_factory_make (V4L
    play_ptr->ip_src          = gst_element_factory_make (V4L2_SRC_NAME, NULL);
    play_ptr->srccapsfilter   = gst_element_factory_make ("capsfilter",      NULL);
    play_ptr->queue           = gst_element_factory_make ("queue",           "src_queue");
    play_ptr->enc_queue       = gst_element_factory_make ("queue",           "record_queue");
    play_ptr->enccapsfilter   = gst_element_factory_make ("capsfilter",      NULL);
    play_ptr->videosink2 = gst_element_factory_make ("appsink", "asink");
    if (!play_ptr->videosink2) 
    {
        GST_ERROR ("FAILED to create video-sink2 element \n");
        return VGST_ERROR_PIPELINE_CREATE_FAIL;
    }
    else 
    {
        GST_DEBUG ("Video-sink2 element is created \n");
    }

    play_ptr->videoenc    = gst_element_factory_make (H264_ENC_NAME,    NULL);
    play_ptr->videoparser = gst_element_factory_make (H264_PARSER_NAME, NULL);

    if (!play_ptr->videoenc || !play_ptr->videoparser) 
    {
        GST_ERROR ("FAILED to create enc-dec-parser elements \n");
        return VGST_ERROR_PIPELINE_CREATE_FAIL;
    }
    gst_bin_add_many(GST_BIN(play_ptr->pipeline),
            play_ptr->ip_src,
            play_ptr->srccapsfilter,  // 确保添加
            play_ptr->queue,          // 确保添加
            play_ptr->videoenc,
            play_ptr->enc_queue,
            play_ptr->enccapsfilter,
            play_ptr->videoparser,
            play_ptr->videosink2,
            NULL);
    return VGST_SUCCESS;
}

VGST_ERROR_LOG wy_link_elements (vgst_ip_params *ip_param, vgst_playback *play_ptr, gint sink_type, vgst_aud_params *aud_param, gchar *uri, vgst_enc_params *enc_param)
{
        if (!gst_element_link_many (play_ptr->ip_src, play_ptr->srccapsfilter,play_ptr- >queue,play_ptr->videoenc, play_ptr->enc_queue,play_ptr->enccapsfilter,play_ptr->videoparser, play_ptr->videosink2,NULL))
        {
            return VGST_ERROR_PIPELINE_LINKING_FAIL;
        } 
        else
        {
            GST_DEBUG ("Linked for ip_src --> srccapsfilter -->  queue --> videoenc -->    enc_queue --> enccapsfilter --> videoparser --> videosink2 successfully \n");
        }
        if (GST_STATE_CHANGE_FAILURE == gst_element_set_state (play_ptr->pipeline,GST_STATE_PLAYING)) 
        {
          GST_ERROR ("state change to Play failed  \n");
          return VGST_ERROR_STATE_CHANGE_FAIL;
        }
        else
        {
           printf("###################  pipeline play success ############# \n");
        }
}

destroys

gint stop_pipeline (void) {
    GST_DEBUG ("setting to NULL state \n");
    if (GST_STATE_CHANGE_FAILURE == gst_element_set_state (play_ptr->pipeline, GST_STATE_NULL)) {
        GST_ERROR ("state change is failed \n");
        return;
    }
    if (play_ptr->pipeline) {
        GstBus *bus;
       bus = gst_pipeline_get_bus (GST_PIPELINE (play_ptr->pipeline));
        if (bus) {
            gst_bus_remove_watch (bus);
            gst_object_unref (bus);
        }
        if (play_ptr->err_msg) {
            g_free (play_ptr->err_msg);
            play_ptr->err_msg = NULL;
        }
        gst_object_unref (GST_OBJECT (play_ptr->pipeline));
        play_ptr->pipeline = NULL;
        gst_object_unref(play_ptr->ip_src);
    }
    
    GST_DEBUG ("returning from stop \n");
    return ret;
}

After each time GStreamer destroys and recreates the pipeline, an file descriptor for /dev/video0 and 4 socket file descriptors remain

root@petaWellyo:~# ls /proc/$(pidof ui_main)/fd -l |grep video
lrwx------    1 root     root            64 Jun 11 23:44 26 -> /dev/video0
lrwx------    1 root     root            64 Jun 11 23:44 29 -> /dev/video0
lrwx------    1 root     root            64 Jun 11 23:44 33 -> /dev/video0
lrwx------    1 root     root            64 Jun 11 23:44 39 -> /dev/video0

root@petaWellyo:~# ls /proc/$(pidof ui_main)/fd -l |grep socket
lrwx------    1 root     root            64 Jun 11 23:44 15 -> socket:[20996]
lrwx------    1 root     root            64 Jun 11 23:44 20 -> socket:[34706]
lrwx------    1 root     root            64 Jun 11 23:44 21 -> socket:[34705]
lrwx------    1 root     root            64 Jun 11 23:44 30 -> socket:[36681]
lrwx------    1 root     root            64 Jun 11 23:44 31 -> socket:[36682]
lrwx------    1 root     root            64 Jun 11 23:44 32 -> socket:[36683]
lrwx------    1 root     root            64 Jun 11 23:44 34 -> socket:[21015]
lrwx------    1 root     root            64 Jun 11 23:44 35 -> socket:[21016]
lrwx------    1 root     root            64 Jun 11 23:44 36 -> socket:[21017]
lrwx------    1 root     root            64 Jun 11 23:44 37 -> socket:[21018]
lrwx------    1 root     root            64 Jun 11 23:44 38 -> socket:[36684]
lrwx------    1 root     root            64 Jun 11 23:44 4 -> socket:[21974]
lrwx------    1 root     root            64 Jun 11 23:44 40 -> socket:[32472]
lrwx------    1 root     root            64 Jun 11 23:44 41 -> socket:[32473]
lrwx------    1 root     root            64 Jun 11 23:44 42 -> socket:[32474]
lrwx------    1 root     root            64 Jun 11 23:44 43 -> socket:[32475]
lrwx------    1 root     root            64 Jun 11 23:44 45 -> socket:[36760]
lrwx------    1 root     root            64 Jun 11 23:44 46 -> socket:[36761]
lrwx------    1 root     root            64 Jun 11 23:44 47 -> socket:[36762]
lrwx------    1 root     root            64 Jun 11 23:44 48 -> socket:[36763]

thx for your reply

There’s an issue for this now: After each time GStreamer destroys and recreates the pipeline, an file descriptor for /dev/video0 and 4 socket file descriptors remain ,why? (#4491) · Issues · GStreamer / gstreamer · GitLab

And the driver could be very old as well. Upgrade is definitely needed.