GStreamer - On Windows

来源:互联网 发布:长沙中信软件教育中心 编辑:程序博客网 时间:2024/05/02 18:40

一、安装

1、安装包的获取

我们需要下面两个安装包

GStreamer-WinBuilds-GPL-x86.msi

GStreamer-WinBuilds-SDK-GPL-x86.msi

安装包可以从如下链接处获取

http://code.google.com/p/ossbuild/

 

另外从其他的介绍中了解GStreamer的运行需要Python,所以最好先安装Python。由于我的机器上已经安装Python2.6(C:\Python26),我并没有验证GStreamer是否可以脱离Python运行。

2、安装

先安装GStreamer-WinBuilds-GPL-x86.msi,直接运行安装包,选上全部组件。再安装SDK,选择全部组件,SDK将被直接到GStreamer-WinBuilds-GPL-x86.msi的安装目录下。

可以使用gst-lauch工具验证一下是否成功安装,可以使用gst-launch filesrc location= D:\\MPEG-1.mpg ! decodebin ! ffmpegcolorspace ! autovideosink测试一下是否可以播放(其中MPEG-1.mpg在文档的附件中可以找到)。Gst-launch使用很有用的工具,类似于graphedit于Directshow,gst-lauch的使用也可以参考gst-lauch。

 

3、playbin

感觉使用playbin有点类似于DirectShow中的RenderFile,GStreamer框架依据当前系统的一些配置直接给用户建立Pipeline,可以使用launch-gst来使用playbin,例如: gst-launch –v playbin uri=file:///D:\\work\\mpeg-1.mpg,其中-v可以打印出pipeline建立的一些细节,对于我们使用GStreamer有一定帮助,当然也可以在source code中使用playbin,具体可以参考GStreamer Application Development Manual。类外还有Decodebin,可以智能的建立decode的pipeline,在安装章节就是用了decodebin。

 

二、Sample Code的编译

1、VC环境设置

我使用的是VS2008。

由于编译GStreamer程序需要用用到一些library和include,所以在VC的Options中设置一下相关的目录方便编译。具体如下,目录依据各自的安装情况。

 

 

2、Application

使用VC创建一个Win32的Win32 ConsoleApplication工程,在source文件中加入#include "gst\gst.h",这样便可以使用GStreamer的一些API了,在具体工程的Properties中加入具体使用的GStreamer库,具体如下:

 

 

详细代码可以参考文档的附件。

3、Filter

GStreamer的filter通过plugin的形式注册到Framework中的,Gstreamer提供了一个工具gst-template可以快速的生成Plugin的框架,可以在下面的地址下载http://cgit.freedesktop.org/gstreamer/gst-template/commit/,是Linux版本的,目前我没有找到Windows版本的。在Linux系统中直接解压缩后进入gst-template-master\gst-plugin\src目录,然后运行../tools/make_element MyFilter,则在src目录中生成gstmyfilter.c和gstmyfilter.h两个文件。在Windows系统中创建一个名字为MyFilter的 Win32 Project,Application type选择DLL,删除MyFilter.cpp文件,将生成的gstmyfilter.c和gstmyfilter.h文件拷贝到工程目录下,将gstmyfilter.c改为gstmyfilter.cpp,并将这两个文件加入到工程中。在gstmyfilter.cpp文件中加入一行#include "stdafx.h"。在GST_PLUGIN_DEFINE的前面定义VERSION,如下:#define VERSION "0.1", 由于编译器的问题生成的代码在gst_my_filter_class_init函数中还有一个类型转换的错误,进行一下强制转换即可,如:


在工程中加入相应的Lib引用,


编译应该OK了。将生成的MyFilter.dll拷贝到gstreamer的安装路径的\v0.10.6\lib\gstreamer-0.10目录下,如果在命令行下运行gst-inspect myfilter能够打印出相关的plugin信息,那么祝贺你,你的第一个gstreamer plugin应该成功加载了,其实我们什么也没有做。也可以使用如下方式进行验证:gst-launch filesrc location= D:\\ MPEG-1.mpg ! myfilter ! decodebin ! ffmpegcolorspace !autovideosink。具体可以参看GStreamer PluginWriter’s Guide文档。

 

三、GStreamer基础

1、Plugin之生

类似于其他的许多Framework,GStreamer的Plugin也是定义了一些用于Framework调用的回调接口,在你的Plugin中实现这些接口就可以了,当然使用Macro是一种非常简洁和优雅的选择。最重要的就是GST_BOILERPLATE了,将其完全展开如下图,大家可以看到一个宏就将我们Framework需要的几个接口定义出来了。暴露一个gst_my_filter_get_type接口Framework就可以找到我们写的Plugin了。

 

/*myfilter.c*/

GST_BOILERPLATE (GstMyFilter, gst_my_filter, GstElement,GST_TYPE_ELEMENT);

/*gstutils.h*/

#define GST_BOILERPLATE(type,type_as_function,parent_type,parent_type_macro)      \

  GST_BOILERPLATE_FULL (type, type_as_function, parent_type, parent_type_macro,   \

      __GST_DO_NOTHING)

#define GST_BOILERPLATE_FULL(type, type_as_function, parent_type, parent_type_macro, additional_initializations)

/*expand GST_BOILERPLATE code*/

static void gst_my_filter_base_init (gpointer      g_class);

static void gst_my_filter_class_init (GstMyFilterClass *g_class);

static void gst_my_filter_init (GstMyFilter  *object, GstMyFilterClass *g_class);

static GstElementClass *parent_class = NULL;

static void gst_my_filter_class_init_trampoline (gpointer g_class,gpointer data)

{

  parent_class = (GstElementClass *) g_type_class_peek_parent (g_class);

  gst_my_filter_class_init ((GstMyFilterClass *)g_class);

}

GType gst_my_filter_get_type (void);

GType gst_my_filter_get_type (void)

{

  /* The typedef for GType may be gulong or gsize, depending on the    

   * system and whether the compiler is c++ or not. The g_once_init_*

   * functions always take a gsize * though ... */

  static volatile gsize gonce_data = 0; 

  if (g_once_init_enter (&gonce_data)) {

    GType _type;

    _type = gst_type_register_static_full (GST_TYPE_ELEMENT,

        g_intern_static_string ("GstMyFilter"),

          sizeof (GstMyFilterClass),

        gst_my_filter_base_init,

        NULL,            /* base_finalize */

        gst_my_filter_class_init_trampoline,

        NULL,            /* class_finalize */

        NULL,               /* class_data */

        sizeof (GstMyFilter),

        0,                  /* n_preallocs */

        (GInstanceInitFunc) gst_my_filter_init,

        NULL,

        (GTypeFlags) 0);

    additional_initializations (_type);

    g_once_init_leave (&gonce_data, (gsize) _type);

  }

  return (GType) gonce_data;

}

  

三、附件



http://blog.csdn.net/dj0379/archive/2010/07/21/5753511.aspx

http://blog.csdn.net/dj0379/archive/2010/07/22/5754953.aspx


原创粉丝点击