Gstreamer Windows开发

做Gstreamer开发已经有一段日子了,但是都是在linux下的。今天偶然见到也能在windows下弄,所以就摆弄了一下,并已经测试通过。


以下为所做步骤:

1. 下载Gstreamer开发包(用的是现成的)地址如下:

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


http://code.google.com/p/ossbuild/downloads/detail?name=GStreamer-WinBuilds-GPL-x86.msi

http://code.google.com/p/ossbuild/downloads/detail?name=GStreamer-WinBuilds-SDK-GPL-x86.msi

这两个一个是runtime一个是sdk。


2. 安装,双击ok!

不过这里需要注意的是,这两个安装包最关键的安装动作是设置的一个环境变量,如下

"GST_PLUGIN_PATH"="D:\\Program Files (x86)\\OSSBuild\\GStreamer\\v0.10.6\\lib\\gstreamer-0.10"

在注册表 或 环境变量

HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Control\Session Manager\Environment


3.安装mingw

这个步骤很麻烦,先简述一下

下载mingw自动安装程序:http://sourceforge.net/projects/mingw/

安装的时候最好选早期的版本,假设安装在D:/migw

下载一下库,并安装在D:/mingw

http://ftp.gnome.org/pub/GNOME/binaries/win32/glib
ftp://ftp.gnome.org/pub/gnome/binaries/win32/dependencies/pkg-config_0.23-3_win32.zip
ftp://ftp.gnome.org/pub/gnome/binaries/win32/dependencies/pkg-config-dev_0.23-3_win32.zip

将过程2的bin lib include也装在D:/mingw下

在msys.bat首部添加下面一行

set PKG_CONFIG_PATH=/mingw/lib/pkgconfig

好了要是有时间我会把这个过程详细的说说的,先这样。


4. 编写测试程序

//gsttest.c

#include <gst/gst.h>
#include <glib.h>


static gboolean
bus_call (GstBus     *bus,
        GstMessage *msg,
        gpointer    data)
{
    GMainLoop *loop = (GMainLoop *) data;

    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;
}


static void
on_pad_added (GstElement *element,
        GstPad     *pad,
        gpointer    data)
{
    GstPad *sinkpad;
    GstElement *decoder = (GstElement *) data;

    /* We can now link this pad with the vorbis-decoder sink pad */
    g_print ("Dynamic pad created, linking demuxer/decoder\n");

    sinkpad = gst_element_get_static_pad (decoder, "sink");

    gst_pad_link (pad, sinkpad);

    gst_object_unref (sinkpad);
}



int
main (int   argc,
        char *argv[])
{
    GMainLoop *loop;

    GstElement *pipeline, *source, *queue, *sink;
    GstBus *bus;
    guint bus_watch_id;

    gst_init (&argc, &argv);

    loop = g_main_loop_new (NULL, FALSE);


    pipeline = gst_pipeline_new ("audio-player");
    source   = gst_element_factory_make ("audiotestsrc",       "audiotestsrc0");
    queue  = gst_element_factory_make ("queue",      "queue0");
    sink  = gst_element_factory_make ("sdlaudiosink",     "sdlaudiosink0");


    if (!pipeline || !source || !queue || !sink) {
        g_printerr ("One element could not be created. Exiting.\n");
        return -1;
    }

    bus = gst_pipeline_get_bus (GST_PIPELINE (pipeline));
    bus_watch_id = gst_bus_add_watch (bus, bus_call, loop);
    gst_object_unref (bus);

    gst_bin_add_many (GST_BIN (pipeline), source, queue, sink, NULL);

    gst_element_link (source, queue);
    gst_element_link_many (queue, sink, NULL);

    gst_element_set_state (pipeline, GST_STATE_PLAYING);


    /* Iterate */
    g_print ("Running...\n");
    g_main_loop_run (loop);


    /* Out of the main loop, clean up nicely */
    g_print ("Returned, stopping playback\n");
    gst_element_set_state (pipeline, GST_STATE_NULL);

    g_print ("Deleting pipeline\n");
    gst_object_unref (GST_OBJECT (pipeline));
    g_source_remove (bus_watch_id);
    g_main_loop_unref (loop);

    return 0;
}
//Makefile

PROG     = gsttest

OBJS     = gsttest.o

INCLUDE =-I/mingw/include -I/mingw/include/gstreamer-0.10
CFLAGS  = -O2 $(shell pkg-config --cflags libxml-2.0 glib-2.0 gobject-2.0) $(INCLUDE)
LDLIBS  = -lpthread $(shell pkg-config --libs libxml-2.0 glib-2.0 gobject-2.0) -lgstreamer-0.10

.PHONY: clean

$(PROG): $(OBJS)
	$(CC) $^ $(LDLIBS) -o $@

%.o:%.c
	$(CC) $(CFLAGS) -c $<

deps:
	$(CC) -MM $(CCFLAGS) $(SRCS) > $(DEPFILE)

clean:
	rm $(OBJS) $(PROG)

make编译

执行,OK!!!




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值