简体   繁体   English

在 gstreamer 管道设置为 GST_STATE_NULL 后未释放 Memory

[英]Memory not freed after gstreamer pipeline set to GST_STATE_NULL

My application requires gstreamer pipeline to be restarted multiple times.我的应用程序需要多次重新启动 gstreamer 管道。 But after setting the pipeline to GST_STATE_NULL and calling unref on the pipeline, memory appears to be not freed.但是在将管道设置为 GST_STATE_NULL 并在管道上调用 unref 后,memory 似乎没有被释放。 After every restart, the memory associated with the process keeps increasing.每次重启后,与进程关联的memory不断增加。

I was able to reproduce the problem with just videotestsrc-fakesink elements as given below:我能够仅使用 videotestsrc-fakesink 元素重现该问题,如下所示:

//g++ -Wall testpage_Simple.cpp -o testpage_Simple $(pkg-config --cflags --libs gstreamer-1.0) //g++ -Wall testpage_Simple.cpp -o testpage_Simple $(pkg-config --cflags --libs gstreamer-1.0)

#include <gst/gst.h> 
GstElement *pipeline;
GstElement *src;
GstElement *sink;
void clearPipeline () {
    // g_print ("clearPipeline    ");
    gst_element_set_state (pipeline, GST_STATE_NULL); 
    gst_object_unref (pipeline); 
}
void createPipeline () {
    pipeline = gst_pipeline_new ("pipelinePlay");
    src = gst_element_factory_make ("videotestsrc", "source");
    sink = gst_element_factory_make ("fakesink", "sink");

    gst_bin_add_many (GST_BIN (pipeline), src, sink, NULL);

    if (gst_element_link (src, sink)!= TRUE) {
        g_printerr ("src, sink could not be linked.\n");
    }
    gst_element_set_state (pipeline, GST_STATE_PLAYING);
}

gint main (gint argc, gchar * argv[]) 
{ 
    gst_init (NULL, NULL);
    system("gst-launch-1.0 --gst-version");
    g_print ("Start Test - ");
 //   for (int i=1; i<=10; i++) {
        system ("top -b -n 1 | grep testpage | awk '{print $6}'");
        createPipeline();
        clearPipeline(); 
 //   }
    g_print ("End of test !! ");
    system ("top -b -n 1 | grep testpage | awk '{print $6}'");
    gst_deinit();
    return 0; 
}

Sample output on Ubuntu 19.04 (showing only RES column value from top command for this process): Ubuntu 19.04 上的示例 output(仅显示此过程的顶部命令中的 RES 列值):
GStreamer Core Library version 1.16.1 GStreamer 核心库版本 1.16.1
Start Test - 7140开始测试 - 7140
End of test !!测试结束!! 8504 8504

We observed similar memory trend on Ubuntu 18.04 with gstreamer 1.12.4 as well.我们在 Ubuntu 18.04 和 gstreamer 1.12.4 上观察到类似的 memory 趋势。

Is this the expected behavior or did I miss something in cleaning up the pipeline??这是预期的行为还是我在清理管道时遗漏了什么?

I checked the below link.我检查了以下链接。 It appears to be a similar problem, but this question is unanswered这似乎是一个类似的问题,但这个问题没有答案
GStreamer memory leak after the pipeline restart 管道重启后 GStreamer memory 泄漏

I tried the disk cache suggestion in the below link, with a similar problem.我尝试了以下链接中的磁盘缓存建议,但遇到了类似的问题。 But that did not help as well.但这也无济于事。
http://gstreamer-devel.966125.n4.nabble.com/Properly-freeing-resources-td4658631.html http://gstreamer-devel.966125.n4.nabble.com/Properly-freeing-resources-td4658631.html

Just a guess, maybe the problem is related to possible state transitions for elements只是猜测,也许问题与元素的可能 state 转换有关

according https://gstreamer.freedesktop.org/documentation/additional/design/states.html?gi-language=c# the following state changes are possible:根据https://gstreamer.freedesktop.org/documentation/additional/design/states.html?gi-language=c#以下 state 更改是可能的:

NULL -> READY:
    The element must check if the resources it needs are available. Device sinks and sources typically try to probe the device to constrain their caps.
    The element opens the device, this is needed if the previous step requires the device to be opened.

READY -> PAUSED:
    The element pads are activated in order to receive data in PAUSED. Streaming threads are started.
    Some elements might need to return ASYNC and complete the state change when they have enough information. It is a requirement for sinks to return ASYNC and complete the state change when they receive the first buffer or EOS event (preroll). Sinks also block the dataflow when in PAUSED.
    A pipeline resets the running_time to 0.
    Live sources return NO_PREROLL and don't generate data.

PAUSED -> PLAYING:
    Most elements ignore this state change.
    The pipeline selects a clock and distributes this to all the children before setting them to PLAYING. This means that it is only allowed to synchronize on the clock in the PLAYING state.
    The pipeline uses the clock and the running_time to calculate the base_time. This base_time is distributed to all children when performing the state change.
    Sink elements stop blocking on the preroll buffer or event and start rendering the data.
    Sinks can post the EOS message in the PLAYING state. It is not allowed to post EOS when not in the PLAYING state.
    While streaming in PAUSED or PLAYING elements can create and remove sometimes pads.
    Live sources start generating data and return SUCCESS.

PLAYING -> PAUSED:
    Most elements ignore this state change.
    The pipeline calculates the running_time based on the last selected clock and the base_time. It stores this information to continue playback when going back to the PLAYING state.
    Sinks unblock any clock wait calls.
    When a sink does not have a pending buffer to play, it returns ASYNC from this state change and completes the state change when it receives a new buffer or an EOS event.
    Any queued EOS messages are removed since they will be reposted when going back to the PLAYING state. The EOS messages are queued in GstBins.
    Live sources stop generating data and return NO_PREROLL.

PAUSED -> READY:
    Sinks unblock any waits in the preroll.
    Elements unblock any waits on devices
    Chain or get_range() functions return FLUSHING.
    The element pads are deactivated so that streaming becomes impossible and all streaming threads are stopped.
    The sink forgets all negotiated formats
    Elements remove all sometimes pads

READY -> NULL:
    Elements close devices
    Elements reset any internal state.

if the current state is playing then st.如果当前 state 正在播放,则 ST。 like喜欢

gst_element_set_state (pipeline, GST_STATE_PAUSED);
gst_element_set_state (pipeline, GST_STATE_READY);
gst_element_set_state (pipeline, GST_STATE_NULL);

might help可能有帮助

Checking the return value of gst_element_set_state(...) might not be a bad idea either:)检查 gst_element_set_state(...) 的返回值也可能不是一个坏主意:)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM