打开gstreamer debug一般方法是:export GST_DEBUG=filesrc:5这样的做法,然后运行程序。但是通过看gstreamer的代码,这个环境变量是在gst_init的时候被读取并设置的,具体是在init_pre这个函数里面。如果程序已经在运行了,gst_init已经做过了,这个时候要打开debug怎么办呢?(Media server就有这样的需求)。
通过看init_pre中的代码,发现很简单,直接调用gst_debug_set_threshold_for_name或gst_debug_set_default_threshold就可以。下面是测试代码:
通过看init_pre中的代码,发现很简单,直接调用gst_debug_set_threshold_for_name或gst_debug_set_default_threshold就可以。下面是测试代码:
#include
<
gst
/
gst.h
>
#include < unistd.h >
GstElement * pipeline, * source, * sink;
int main( int argc, char * argv[])
{
gst_init( & argc, & argv);
// create elements
pipeline = gst_pipeline_new( " test-pipeline " );
source = gst_element_factory_make( " filesrc " , " file-source " );
sink = gst_element_factory_make( " fakesink " , " fake-sink " );
if ( ! pipeline || ! source || ! sink) {
g_print( " One element could not be created!\n " );
return 1 ;
}
// set file name
g_object_set(G_OBJECT(source), " location " , " /home/eric/rphonenfs/medias/Audios/lddgy.mp3 " , NULL);
// put all elements into bin
gst_bin_add_many(GST_BIN(pipeline), source, sink, NULL);
// link together
gst_element_link_many(source, sink, NULL);
// change state to PAUSED
g_print( " Before debug on, Setting to PAUSED\n " );
gst_element_set_state(pipeline, GST_STATE_PAUSED);
sleep( 1 );
g_print( " Then we set pipeline to NULL\n " );
gst_element_set_state(pipeline, GST_STATE_NULL);
// try to open debug
g_print( " Open debug infos...\n " );
// This function call is from "init_pre" which be called in "gst_init_check"
// gst_debug_set_threshold_for_name("filesrc", 5);
gst_debug_set_default_threshold( 5 );
g_print( " Rechange pipeline to PAUSED\n " );
gst_element_set_state(pipeline, GST_STATE_PAUSED);
sleep( 1 );
g_print( " Change pipeline to NULL and terminate.\n " );
gst_element_set_state(pipeline, GST_STATE_NULL);
gst_object_unref(GST_OBJECT(pipeline));
return 0 ;
}
#include < unistd.h >
GstElement * pipeline, * source, * sink;
int main( int argc, char * argv[])
{
gst_init( & argc, & argv);
// create elements
pipeline = gst_pipeline_new( " test-pipeline " );
source = gst_element_factory_make( " filesrc " , " file-source " );
sink = gst_element_factory_make( " fakesink " , " fake-sink " );
if ( ! pipeline || ! source || ! sink) {
g_print( " One element could not be created!\n " );
return 1 ;
}
// set file name
g_object_set(G_OBJECT(source), " location " , " /home/eric/rphonenfs/medias/Audios/lddgy.mp3 " , NULL);
// put all elements into bin
gst_bin_add_many(GST_BIN(pipeline), source, sink, NULL);
// link together
gst_element_link_many(source, sink, NULL);
// change state to PAUSED
g_print( " Before debug on, Setting to PAUSED\n " );
gst_element_set_state(pipeline, GST_STATE_PAUSED);
sleep( 1 );
g_print( " Then we set pipeline to NULL\n " );
gst_element_set_state(pipeline, GST_STATE_NULL);
// try to open debug
g_print( " Open debug infos...\n " );
// This function call is from "init_pre" which be called in "gst_init_check"
// gst_debug_set_threshold_for_name("filesrc", 5);
gst_debug_set_default_threshold( 5 );
g_print( " Rechange pipeline to PAUSED\n " );
gst_element_set_state(pipeline, GST_STATE_PAUSED);
sleep( 1 );
g_print( " Change pipeline to NULL and terminate.\n " );
gst_element_set_state(pipeline, GST_STATE_NULL);
gst_object_unref(GST_OBJECT(pipeline));
return 0 ;
}