GStreamer 是一个非常强大而且通用的流媒体应用程序框架。 GStreamer所具备的很多优点来源于其框架的模块化: GStreamer能够无缝的合并新的插件。 但是, 由于追求模块化和高效率, 使得GStreamer在整个框架上变的复杂, 也同时因为复杂度的提高, 使得开发一个新的应用程序显得不是那么的简单。
由于工作需求,因此笔者开启了gstreamer构建音频播放器之路!
首先openwrt下面make menuconfig 要选择gstreamer必要的插件库,由于openwrt下面已经很好地支持了gstreamer的大部分插件,因此使得openwrt下面基于gstreamer开发变得轻松一点。
第一步:写程序
当我们准备写一个GStreamer应用程序时,你仅需要通过包含头文件gst/gst.h 来访问库函数。除此之外,不要忘记初始化GStreamer库。
#include <stdio.h>
#include <glib.h>
#include <gst/gst.h>
int main (int argc, char *argv[])
{
const gchar *nano_str;
guint major, minor, micro, nano;
gst_init (&argc, &argv);
gst_version (&major, &minor, µ, &nano);
if (nano == 1)
nano_str = "(CVS)";
else if (nano == 2)
nano_str = "(Prerelease)";
else
nano_str = "";
printf("This program is linked against GStreamer %d.%d.%d %s\n", major, minor, micro, nano_str);
return 0;
}
以上程序是初始gstreamer,并打印gstreamer的版本号!
第二歩:
编写openwrt 下面makefile
include $(TOPDIR)/rules.mk
#LIB_GS=/home/xuyonghong/share/ffmpeg/car_radio_firmware/trunk/staging_dir/target-mips_34kc_uClibc-0.9.33.2/usr/lib
PKG_NAME:=gst-test
PKG_RELEASE:=1
PKG_BUILD_DIR:=$(BUILD_DIR)/$(PKG_NAME)
include $(INCLUDE_DIR)/package.mk
define Package/gst-test
SECTION:=multimedia
CATEGORY:=Multimedia
DEPENDS:=+gstreamer1* +glib2 +libpthread
TITLE:=gstreamer test demo
endef
define Package/gst-test/description
If you can‘t figure out what this program does, you‘re probably
brain-dead and need immediate medical attention.
endef
TARGET_CPPFLAGS:= \
-I$(STAGING_DIR)/usr/include/gstreamer-1.0 \
$(TARGET_CPPFLAGS)
TARGET_CPPFLAGS:= \
-I$(STAGING_DIR)/usr/include/glib-2.0 \
$(TARGET_CPPFLAGS)
MAKE_FLAGS += \
CFLAGS="$(TARGET_CPPFLAGS) $(TARGET_CFLAGS) $(PKG_CONFIGS) -ffunction-sections -fdata-sections" \
LDFLAGS="$(TARGET_LDFLAGS) $(PKG_CONFIGS) -Wl,--gc-sections" \
PKG_CONFIGS:= \
`pkg-config --cflags --libs glib-2.0 gthread-2.0 gstreamer-1.0`
define Build/Prepare
mkdir -p $(PKG_BUILD_DIR)
$(CP) ./src/* $(PKG_BUILD_DIR)/
endef
define Package/gst-test/install
$(INSTALL_DIR) $(1)/bin
$(INSTALL_BIN) $(PKG_BUILD_DIR)/gst-test $(1)/bin/
#
#$(CP) $(LIB_GS)/libgstreamer* $(1)/bin
endef
$(eval $(call BuildPackage,gst-test))
第三步:make编译
第四步;测试之
[email protected]:/#
[email protected]:/# chmod +x gst-test
[email protected]:/# ./gst-test
This program is linked against GStreamer 1.2.3
[email protected]:/#
[email protected]:/#