简体   繁体   English

Gstreamer调试管道C ++

[英]Gstreamer debug pipeline c++

I am trying to transcode a gstreamer bash script to c++ code, y but I am not able to save de debuggin log into a file 我正在尝试将gstreamer bash脚本转码为c ++代码,但是我无法将调试日志保存到文件中

This is my code 这是我的代码

 int main(int argc, char *argv[]) { YoctoLinuxSystem* hola; //hola->YoctoLinuxSystem(); CustomData DataTest, DataDvi; GstBus *bus; GstMessage *msg; GstStateChangeReturn ret; GMainLoop *loop; //vector<string> lines = YoctoLinuxSystem::getCmdOutputAsLines("./scripts/get_system_temps.sh"); gst_init (&argc, &argv); loop = g_main_loop_new (NULL, FALSE); /******************************/ /****AJUSTES GSTREAMER TEST****/ /******************************/ DataTest.source = gst_element_factory_make ("videotestsrc", "source"); DataTest.capsfilter = gst_element_factory_make ("capsfilter","caps"); DataTest.sink = gst_element_factory_make ("imxipuvideosink", "sink"); DataTest.pipeline = gst_pipeline_new ("test-pipeline"); if (!DataTest.pipeline || !DataTest.source || !DataTest.capsfilter || !DataTest.sink) { g_printerr ("Not all elements could be created.\\n"); return -1; } /* Modify the source's properties */ g_object_set (DataTest.source, "pattern", 0, NULL); g_object_set(DataTest.capsfilter, "caps", gst_caps_new_simple("video/x-raw", "framerate", GST_TYPE_FRACTION, 25, 1,"width", G_TYPE_INT, 1920, "height", G_TYPE_INT, 1080, "format", G_TYPE_STRING, "RGB", NULL), NULL); /* Build the pipeline */ gst_bin_add_many (GST_BIN (DataTest.pipeline), DataTest.source, DataTest.capsfilter, DataTest.sink, NULL); if (gst_element_link (DataTest.source, DataTest.capsfilter) != TRUE) { g_printerr ("Elements source-caps could not be linked.\\n"); gst_object_unref (DataTest.pipeline); return -1; } if (gst_element_link (DataTest.capsfilter, DataTest.sink) != TRUE) { g_printerr ("Elements caps-sink could not be linked.\\n"); gst_object_unref (DataTest.pipeline); return -1; } gst_element_link_many (DataTest.source, DataTest.capsfilter, DataTest.sink, NULL); /******************************/ /****AJUSTES GSTREAMER DVI****/ /******************************/ DataDvi.source = gst_element_factory_make ("v4l2src", "source"); DataDvi.sink = gst_element_factory_make ("imxipuvideosink", "sink"); DataDvi.pipeline = gst_pipeline_new ("test-pipeline"); if (!DataDvi.pipeline || !DataDvi.source || !DataDvi.sink) { g_printerr ("Not all elements could be created.\\n"); return -1; } /* Modify the source's properties */ g_object_set (DataDvi.source, "device", "/dev/video0", NULL); /* Build the pipeline */ gst_bin_add_many (GST_BIN (DataDvi.pipeline), DataDvi.source, DataDvi.sink, NULL); if (gst_element_link (DataDvi.source, DataDvi.sink) != TRUE) { g_printerr ("Elements caps-sink could not be linked.\\n"); gst_object_unref (DataDvi.pipeline); return -1; } gst_element_link_many (DataDvi.source, DataDvi.sink, NULL); GST_DEBUG=2; ifstream fileread; // fileread.open("/var/log/data.log"); while(1) { ifstream fileread("/var/log/data.log"); if (!fileread.good()) { /* Start playing */ //g_print ("Now playing: \\n"); gst_element_set_state (DataDvi.pipeline, GST_STATE_PAUSED); ret = gst_element_set_state (DataTest.pipeline, GST_STATE_PLAYING); if (ret == GST_STATE_CHANGE_FAILURE) { g_printerr ("Unable to set the pipeline to the playing state.\\n"); gst_object_unref (DataTest.pipeline); return -1; } } else { gst_element_set_state (DataTest.pipeline, GST_STATE_PAUSED); ret = gst_element_set_state (DataDvi.pipeline, GST_STATE_PLAYING); /*HERE I NEED TO KNOW THE DEBUG OF THE PIPELINE*/ if (ret == GST_STATE_CHANGE_FAILURE) { g_printerr ("Unable to set the pipeline to the playing state.\\n"); gst_object_unref (DataDvi.pipeline); return -1; } } } g_print ("SALE\\n"); return 0; } 

I am using gstreamer-1.0 library and I have seen that I need use GST_DEBUG_FILE but I do not know how call these functions from c++. 我正在使用gstreamer-1.0库,并且已经看到需要使用GST_DEBUG_FILE,但是我不知道如何从c ++调用这些函数。

Thanks for the help! 谢谢您的帮助!

GST_DEBUG_FILE is environment variable, so it has nothing to do with C++. GST_DEBUG_FILE是环境变量,因此与C ++无关。

You could just use something like 您可以使用类似

export GST_DEBUG_FILE=~/gst.log

before run your application. 在运行您的应用程序之前。 Or add something like this to your bash startup script. 或在您的bash启动脚本中添加类似的内容。

There is a rich API behind the debugging and logging infrastructure. 调试和日志记录基础结构背后有丰富的API。 Take a look at this documentation . 看一下这个文档

For example, you might set some default values when the environment variables have not been setup. 例如,当尚未设置环境变量时,您可以设置一些默认值。

if (!gst_debug_is_active()) {
    gst_debug_set_active(TRUE);
    GstDebugLevel dbglevel = gst_debug_get_default_threshold();
    if (dbglevel < GST_LEVEL_ERROR) {
        dbglevel = GST_LEVEL_ERROR;
        gst_debug_set_default_threshold(dbglevel);
    }
}

For that, the previous poster correctly advised you about the environment variable, GST_DEBUG_FILE. 为此,上一个张贴者正确地建议您有关环境变量GST_DEBUG_FILE。 You could do putenv() before gst_init(). 您可以在gst_init()之前执行putenv()。

If you want to get fancy, you could can replace the default log function, gst_debug_log_default() . 如果想花哨的话,可以替换默认的日志功能gst_debug_log_default() You do this by adding your own via, gst_debug_add_log_function() ; 您可以通过gst_debug_add_log_function()添加自己的gst_debug_add_log_function() then remove the default, gst_debug_remove_log_function(gst_debug_log_default) . 然后删除默认的gst_debug_remove_log_function(gst_debug_log_default) If you simply wish to change the file, then gst_debug_add_log_function (gst_debug_log_default, log_file, NULL) , for some open and ready FILE* log_file . 如果您只想更改文件,则可以使用gst_debug_add_log_function (gst_debug_log_default, log_file, NULL)来获取一些已打开并准备就绪的FILE* log_file

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

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