http://blog.csdn.net/tiger99111/article/details/22196957
一. Gstreamer安装:
方法一:使用sudo apt-get install 安装
sudoapt-get install libgstreamer0.10-dev gstreamer-tools gstreamer0.10-toolsgstreamer0.10-doc
sudo apt-getinstall gstreamer0.10-plugins-base gstreamer0.10-plugins-good gstreamer0.10-plugins-ugly gstreamer0.10-plugins-badgstreamer0.10-plugins-bad-multiverse
方法二:在官方网站下载源码包,使用./configure, make, makeinstall进行安装:
官方网址:http://gstreamer.freedesktop.org
另外此网址有介绍链接各资源:http://gstreamer.freedesktop.org/news/,可直接下载tarballs
gstreamer-1.2.2.tar.xz, gst-plugins-base-1.2.1.tar.xz, gst-plugins-good-1.2.2.tar.xz,gst-plugins-ugly-1.2.2.tar.xz或者在列表中选择历史release版本下载
基础包下载:
Gstreamer-0.10.35.tar.bz2
http://gstreamer.freedesktop.org/src/gstreamer/
gst-plugins-base-0.10.35.tar.bz2
http://gstreamer.freedesktop.org/src/gst-plugins-base/
gst-plugins-good-0.10.30.tar.bz2
http://gstreamer.freedesktop.org/src/gst-plugins-good
gst-plugins-ugly-0.10.10.tar.bz2
http://gstreamer.freedesktop.org/src/gst-plugins-ugly/
安装过程中可能出现以下错误:
1. configure: error: Could not find bison
admin@ubuntu:$sudo apt-get install bison
2. configure: error: Could not find flex
admin@ubuntu:$sudo apt-get install flex
3. configure: error: *** Working zlib libraryand headers not found ***
admin@ubuntu:$sudo apt-get install zlib1g
Gstreamer-0.10.35配置成功后出现以下消息:
然后make, make install即可
接下来依次安装gst-plugins-base-0.10.35, gst-plugins-good-0.10.30,此时需注意安装顺序,必须先安装gst-plugins-base-0.10.35,再安装gst-plugins-good-0.10.30,此顺序不可修改,否则出现依赖错误。
以上包安装完成后使用:
gst-launch-vm audiotestsrc ! audioconvert ! audioresample ! osssink
可测试到耳机出现蜂鸣声。
二. Gstreamer测试播放mp3音乐:
需要使用mad解码插件,因此需要先安装gstreamer0.10-plugins-ugly,它依赖其他两个库。
admin@ubuntu:$ apt-get installliblid3tag0-dev
admin@ubuntu:$ apt-get install libmad0-dev
admin@ubuntu:$apt-get install gstreamer0.10-plugins-ugly
编译测序程序:
#include <gst/gst.h>
#include <glib.h>
//定义消息处理函数,
static gboolean bus_call(GstBus *bus,GstMessage *msg,gpointer data)
{
GMainLoop *loop = (GMainLoop *) data;//这个是主循环的指针,在接受EOS消息时退出循环
switch (GST_MESSAGE_TYPE(msg))
{
case GST_MESSAGE_EOS:
g_print("End of stream\n");
g_main_loop_quit(loop);
break;
case GST_MESSAGE_ERROR:
{
gchar *debug;
GError *error;
gst_message_parse_error(msg,&error,&debug);
g_free(debug);
g_printerr("ERROR:%s\n",error->message);
g_error_free(error);
g_main_loop_quit(loop);
break;
}
default:
break;
}
return TRUE;
}
int main(int argc,char *argv[])
{
GMainLoop *loop;
GstElement *pipeline,*source,*decoder,*sink;//定义组件
GstBus *bus;
gst_init(&argc,&argv);
loop = g_main_loop_new(NULL,FALSE);//创建主循环,在执行 g_main_loop_run后正式开始循环
if(argc != 2)
{
g_printerr("Usage:%s <mp3 filename>\n",argv[0]);
return -1;
}
//创建管道和组件
pipeline = gst_pipeline_new("audio-player");
source = gst_element_factory_make("filesrc","file-source");
decoder = gst_element_factory_make("mad","mad-decoder");
sink = gst_element_factory_make("autoaudiosink","audio-output");
if(!pipeline||!source||!decoder||!sink){
g_printerr("One element could not be created.Exiting.\n");
return -1;
}
//设置 source的location 参数。即 文件地址.
g_object_set(G_OBJECT(source),"location",argv[1],NULL);
//得到 管道的消息总线
bus = gst_pipeline_get_bus(GST_PIPELINE(pipeline));
//添加消息监视器
gst_bus_add_watch(bus,bus_call,loop);
gst_object_unref(bus);
//把组件添加到管道中.管道是一个特殊的组件,可以更好的让数据流动
gst_bin_add_many(GST_BIN(pipeline),source,decoder,sink,NULL);
//依次连接组件
gst_element_link_many(source,decoder,sink,NULL);
//开始播放
gst_element_set_state(pipeline,GST_STATE_PLAYING);
g_print("Running\n");
//开始循环
g_main_loop_run(loop);
g_print("Returned,stopping playback\n");
gst_element_set_state(pipeline,GST_STATE_NULL);
gst_object_unref(GST_OBJECT(pipeline));
return 0;
}
编译运行
gcc -Wall $(pkg-config --cflags --libs gstreamer-0.10) -g test2.c -o test2
./test2 /home/admin/mingyue.mp3
参考资料:
http://www.cnblogs.com/phinecos/archive/2009/06/07/1498166.html
http://blog.sina.com.cn/s/blog_638ea1960101eilq.html
一. Gstreamer安装:
方法一:使用sudo apt-get install 安装
sudoapt-get install libgstreamer0.10-dev gstreamer-tools gstreamer0.10-toolsgstreamer0.10-doc
sudo apt-getinstall gstreamer0.10-plugins-base gstreamer0.10-plugins-good gstreamer0.10-plugins-ugly gstreamer0.10-plugins-badgstreamer0.10-plugins-bad-multiverse
方法二:在官方网站下载源码包,使用./configure, make, makeinstall进行安装:
官方网址:http://gstreamer.freedesktop.org
另外此网址有介绍链接各资源:http://gstreamer.freedesktop.org/news/,可直接下载tarballs
gstreamer-1.2.2.tar.xz, gst-plugins-base-1.2.1.tar.xz, gst-plugins-good-1.2.2.tar.xz,gst-plugins-ugly-1.2.2.tar.xz或者在列表中选择历史release版本下载
基础包下载:
Gstreamer-0.10.35.tar.bz2
http://gstreamer.freedesktop.org/src/gstreamer/
gst-plugins-base-0.10.35.tar.bz2
http://gstreamer.freedesktop.org/src/gst-plugins-base/
gst-plugins-good-0.10.30.tar.bz2
http://gstreamer.freedesktop.org/src/gst-plugins-good
gst-plugins-ugly-0.10.10.tar.bz2
http://gstreamer.freedesktop.org/src/gst-plugins-ugly/
安装过程中可能出现以下错误:
1. configure: error: Could not find bison
admin@ubuntu:$sudo apt-get install bison
2. configure: error: Could not find flex
admin@ubuntu:$sudo apt-get install flex
3. configure: error: *** Working zlib libraryand headers not found ***
admin@ubuntu:$sudo apt-get install zlib1g
Gstreamer-0.10.35配置成功后出现以下消息:
然后make, make install即可
接下来依次安装gst-plugins-base-0.10.35, gst-plugins-good-0.10.30,此时需注意安装顺序,必须先安装gst-plugins-base-0.10.35,再安装gst-plugins-good-0.10.30,此顺序不可修改,否则出现依赖错误。
以上包安装完成后使用:
gst-launch-vm audiotestsrc ! audioconvert ! audioresample ! osssink
可测试到耳机出现蜂鸣声。
二. Gstreamer测试播放mp3音乐:
需要使用mad解码插件,因此需要先安装gstreamer0.10-plugins-ugly,它依赖其他两个库。
admin@ubuntu:$ apt-get installliblid3tag0-dev
admin@ubuntu:$ apt-get install libmad0-dev
admin@ubuntu:$apt-get install gstreamer0.10-plugins-ugly
编译测序程序:
#include <gst/gst.h>
#include <glib.h>
//定义消息处理函数,
static gboolean bus_call(GstBus *bus,GstMessage *msg,gpointer data)
{
GMainLoop *loop = (GMainLoop *) data;//这个是主循环的指针,在接受EOS消息时退出循环
switch (GST_MESSAGE_TYPE(msg))
{
case GST_MESSAGE_EOS:
g_print("End of stream\n");
g_main_loop_quit(loop);
break;
case GST_MESSAGE_ERROR:
{
gchar *debug;
GError *error;
gst_message_parse_error(msg,&error,&debug);
g_free(debug);
g_printerr("ERROR:%s\n",error->message);
g_error_free(error);
g_main_loop_quit(loop);
break;
}
default:
break;
}
return TRUE;
}
int main(int argc,char *argv[])
{
GMainLoop *loop;
GstElement *pipeline,*source,*decoder,*sink;//定义组件
GstBus *bus;
gst_init(&argc,&argv);
loop = g_main_loop_new(NULL,FALSE);//创建主循环,在执行 g_main_loop_run后正式开始循环
if(argc != 2)
{
g_printerr("Usage:%s <mp3 filename>\n",argv[0]);
return -1;
}
//创建管道和组件
pipeline = gst_pipeline_new("audio-player");
source = gst_element_factory_make("filesrc","file-source");
decoder = gst_element_factory_make("mad","mad-decoder");
sink = gst_element_factory_make("autoaudiosink","audio-output");
if(!pipeline||!source||!decoder||!sink){
g_printerr("One element could not be created.Exiting.\n");
return -1;
}
//设置 source的location 参数。即 文件地址.
g_object_set(G_OBJECT(source),"location",argv[1],NULL);
//得到 管道的消息总线
bus = gst_pipeline_get_bus(GST_PIPELINE(pipeline));
//添加消息监视器
gst_bus_add_watch(bus,bus_call,loop);
gst_object_unref(bus);
//把组件添加到管道中.管道是一个特殊的组件,可以更好的让数据流动
gst_bin_add_many(GST_BIN(pipeline),source,decoder,sink,NULL);
//依次连接组件
gst_element_link_many(source,decoder,sink,NULL);
//开始播放
gst_element_set_state(pipeline,GST_STATE_PLAYING);
g_print("Running\n");
//开始循环
g_main_loop_run(loop);
g_print("Returned,stopping playback\n");
gst_element_set_state(pipeline,GST_STATE_NULL);
gst_object_unref(GST_OBJECT(pipeline));
return 0;
}
编译运行
gcc -Wall $(pkg-config --cflags --libs gstreamer-0.10) -g test2.c -o test2
./test2 /home/admin/mingyue.mp3
参考资料:
http://www.cnblogs.com/phinecos/archive/2009/06/07/1498166.html
http://blog.sina.com.cn/s/blog_638ea1960101eilq.html