gpephone采用GStreamer作为多媒体框架。GStreamer是一个开源的多媒体框架库。利用它,可以构建一系列的媒体处理模块,包括从简单的ogg播放功能到复杂的音频(混音)和视频(非线性编辑)的处理。
应用程序可以透明的利用解码和过滤技术。开发者可以使用简洁通用的接口来编写一个简单的插件来添加新的解码器或滤镜。 GStreamer以LGPL授权发布。想见和
里面的应用开发手册有详细的介绍,并有一些例子。
GStreamer一个重要的概念就是管道。以下是gpephone中soudserver(来电或者来铃声时)中播放的一些代码。
switch (controller->type) {
case CON_LOCATION: {
if (!is_playing) {
is_playing = TRUE;
g_thread_create ((GThreadFunc )ss_gst_player, controller, FALSE, NULL);//播放音乐
}
break;
}
case CON_MUTE: {
if (is_playing) {
ss_gst_volume_set_num (0);
}
break;
}
case CON_STOP: {
if (is_playing) {
ss_gst_stop ();
}
break;
}
case CON_VOLUME: {
if (is_playing) {
ss_gst_volume_set_shift (controller->value.double_float);
}
break;
}
case CON_REMUTE: {
if (is_playing) {
ss_gst_remute ();
}
break;
}
case CON_PAUSE: {
if (is_playing)
ss_gst_pause ();
break;
}
case CON_CONTINUE: {
if (is_playing) {
g_print ("%s: %d\n", __FUNCTION__, __LINE__);
ss_gst_continue ();
}
break;
}
default:
break;
}
以下是创建管道并播放mp3音乐
gpointer ss_gst_player (gpointer data)
{
GstElement *filesrc;
GstElement *decoder;
GstElement *converter;
GstElement *audiosink;
GstBus *bus;
GError *error = NULL;
SSMessParser *controller;
gchar *filename;
gint fd;
controller = (SSMessParser *)data;
if (controller->value.location) {
filename = (gchar *) controller->value.location;
fd = open (filename, O_RDONLY);
if (fd < 0)
filename = ss_gst_get_default_path (controller);
}
else
filename = ss_gst_get_default_path (controller);
#ifdef OS_C8K
ss_shake ();
#endif
bin = gst_bin_new ("mp3");
filesrc = gst_element_factory_make ("filesrc", "my_filesrc");
g_object_set (G_OBJECT (filesrc), "location", filename, NULL);
decoder = gst_element_factory_make ("mad", "decoder");
converter = gst_element_factory_make ("audioconvert", "convert");
volume = gst_element_factory_make ("volume", "volume");
g_object_set (G_OBJECT (volume), "volume", 0.5, NULL);
audiosink = gst_element_factory_make ("esdsink", "audiosink");
gst_bin_add_many (GST_BIN (bin), filesrc, decoder, converter, volume, audiosink, NULL);
gst_element_link_many (filesrc, decoder, converter, volume, audiosink, NULL);
g_print ("%s: %d, bin content:%u, bin location: %u,\n", __FUNCTION__, __LINE__, bin, &bin);
gst_loop = g_main_loop_new (NULL, FALSE);
bus = gst_bus_new ();
gst_element_set_bus (GST_ELEMENT (bin), bus);
gst_bus_add_watch (bus, ss_gst_bus_watcher, (gpointer) controller);
gst_element_set_state (bin, GST_STATE_PLAYING);
g_main_loop_run (gst_loop);
gst_element_set_state (bin, GST_STATE_NULL);
gst_object_unref (bin);
bin = NULL;
g_main_loop_unref (gst_loop);
gst_loop = NULL;
#ifdef OS_C8K
if (shake_id != 0) {
g_source_remove (shake_id);
shake_id = 0;
os_vibrate_off ();
}
#endif
is_playing = FALSE;
}
阅读(1683) | 评论(0) | 转发(0) |