1 2 3 4 5 6 7 | GstPad *srcpad, *sinkpad; srcpad = gst_element_get_pad (element1, "src"); sinpad = gst_element_get_pad (element2, "sink"); // 连接 gst_pad_link (srcpad, sinkpad); // 断开 gst_pad_unlink (srcpad, sinkpad); |
1 2 3 4 | // 连接 gst_element_link (element1, element2); // 断开 gst_element_unlink (element1, element2); |
1 2 3 | GstElement *bin; /* 创建元件,并将其连接成箱柜bin */ gst_element_set_state (bin, GST_STATE_PLAYING); |
1 2 3 4 5 6 | #include <gst/gst.h> int main (int argc, char *argv[]) { gst_init (&argc, &argv); /* ... */ } |
1 | GstElement *pipeline, *filesrc, *decoder, *audiosink; |
1 2 | /* 创建用来容纳元件的新管道 */ pipeline = gst_pipeline_new ("pipeline"); |
1 2 3 | /* 创建数据源元件 */ filesrc = gst_element_factory_make ("filesrc", "disk_source"); g_object_set (G_OBJECT (filesrc), "location", argv[1], NULL); |
1 2 | /* 创建过滤器元件 */ decoder = gst_element_factory_make ("mad", "decoder"); |
1 2 | /* 创建接收器元件 */ audiosink = gst_element_factory_make ("audiosink", "play_audio"); |
1 2 3 4 | /* 添加元件到管道中 */ gst_bin_add_many (GST_BIN (pipeline), filesrc, decoder, audiosink, NULL); /* 通过衬垫连接元件 */ gst_element_link_many (filesrc, decoder, audiosink, NULL); |
1 2 | /* 启动管道 */ gst_element_set_state (pipeline, GST_STATE_PLAYING); |
1 | while (gst_bin_iterate (GST_BIN (pipeline))); |
1 2 3 4 | /* 终止管道 */ gst_element_set_state (pipeline, GST_STATE_NULL); /* 释放资源 */ gst_object_unref (GST_OBJECT (pipeline)); |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | #include <gst/gst.h> int main (int argc, char *argv[]) { GstElement *pipeline, *filesrc, *decoder, *audiosink; gst_init(&argc, &argv); if (argc != 2) { g_print ("usage: %s <mp3 filename>\n", argv[0]); exit (-1); } /* 创建一条新的管道 */ pipeline = gst_pipeline_new ("pipeline"); /* 生成用于读取硬盘数据的元件 */ filesrc = gst_element_factory_make ("filesrc", "disk_source"); g_object_set (G_OBJECT (filesrc), "location", argv[1], NULL); /* 创建解码器元件 */ decoder = gst_element_factory_make ("mad", "decoder"); /* 创建音频回放元件 */ audiosink = gst_element_factory_make ("osssink", "play_audio"); /* 将生成的元件添加到管道中 */ gst_bin_add_many (GST_BIN (pipeline), filesrc, decoder, audiosink, NULL); /* 连接各个元件 */ gst_element_link_many (filesrc, decoder, audiosink, NULL); /* 开始播放 */ gst_element_set_state (pipeline, GST_STATE_PLAYING); while (gst_bin_iterate (GST_BIN (pipeline))); /* 停止管道处理流程 */ gst_element_set_state (pipeline, GST_STATE_NULL); /* 释放占用的资源 */ gst_object_unref (GST_OBJECT (pipeline)); exit (0); } |
欢迎光临 电子技术论坛_中国专业的电子工程师学习交流社区-中电网技术论坛 (http://bbs.eccn.com/) | Powered by Discuz! 7.0.0 |