我正在尝试将gstreamer bash脚本转码为c ++代码,但是我无法将de debuggin日志保存到文件中
这是我的代码
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;
}
我正在使用gstreamer-1.0库,我看到我需要使用GST_DEBUG_FILE,但我不知道如何从c ++中调用这些函数。
感谢您的帮助!
答案 0 :(得分:1)
GST_DEBUG_FILE是环境变量,所以它与C ++无关。
您可以使用类似
的内容export GST_DEBUG_FILE=~/gst.log
在运行您的应用程序之前。或者在你的bash启动脚本中添加这样的内容。
答案 1 :(得分:1)
调试和日志记录基础结构背后有一个丰富的API。看看this documentation。
例如,您可以在尚未设置环境变量时设置一些默认值。
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);
}
}
为此,上一张海报正确地告诉了你环境变量GST_DEBUG_FILE。你可以在gst_init()之前做putenv()。
如果您想获得幻想,可以替换默认日志功能gst_debug_log_default()
。您可以通过添加自己的via gst_debug_add_log_function()
来完成此操作;然后删除默认值gst_debug_remove_log_function(gst_debug_log_default)
。如果您只是想更改文件,请gst_debug_add_log_function (gst_debug_log_default, log_file, NULL)
,以获得一些开放且准备就绪的FILE* log_file
。