通过 SWIG 包装 C 回调
我正在尝试使用 SWIG 将一些 Gstreamer 功能包装到 PHP 中,但我不知道如何处理 C 回调。我可以从 C 调用 PHP 函数吗?您将如何处理如下回调?
#include <gst/gst.h>
// ...
static gboolean my_callback(GstBus *bus, GstMessage *message, gpointer user_data) {
g_print("Got %s message\n", GST_MESSAGE_TYPE_NAME(message));
switch(GST_MESSAGE_TYPE(message)) {
// ...
}
return TRUE;
}
main(gint argc, gchar *argv[])
{
GstElement *pipeline;
GstBus *bus;
gst_init (&argc, &argv);
pipeline = gst_pipeline_new ("my_pipeline");
/* add handler */
bus = gst_pipeline_get_bus (GST_PIPELINE (pipeline));
gst_bus_add_watch (bus, my_bus_callback, NULL); // ------------<
gst_object_unref (bus);
// ...
}
I'm trying to wrap some Gstreamer functionlity into PHP using SWIG, but i can't figure out how to handle C callbacks. Can I call a PHP function from C? How will you handle a callback like the following?
#include <gst/gst.h>
// ...
static gboolean my_callback(GstBus *bus, GstMessage *message, gpointer user_data) {
g_print("Got %s message\n", GST_MESSAGE_TYPE_NAME(message));
switch(GST_MESSAGE_TYPE(message)) {
// ...
}
return TRUE;
}
main(gint argc, gchar *argv[])
{
GstElement *pipeline;
GstBus *bus;
gst_init (&argc, &argv);
pipeline = gst_pipeline_new ("my_pipeline");
/* add handler */
bus = gst_pipeline_get_bus (GST_PIPELINE (pipeline));
gst_bus_add_watch (bus, my_bus_callback, NULL); // ------------<
gst_object_unref (bus);
// ...
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您下载最新的 swig 源代码 (2.0.1),这里有一个使用 PHP 回调的示例。它位于 swig-2.0.1/Examples/php/callback 目录中。
If you download the latest swig source (2.0.1) there is an example of using callbacks with PHP. It's in the swig-2.0.1/Examples/php/callback directory.