我正在尝试将这段代码重写为Vala:
我被困在这一行:
watch_id = gst_bus_add_watch (bus, message_handler, NULL);
相当于我的瓦拉:
var watch_id = bus.add_watch (Priority.DEFAULT, message_handler);
我不知道如何格式化BusFunc及其假定的参数
到目前为止已完成代码:
using Gst;
bool Gst.BusFunc message_handler ()
{
return false;
}
void main (string[] args) {
// Initializing GStreamer
Gst.init (ref args);
var caps = Caps.from_string("audio/x-raw,channels=2");
// Creating pipeline and elements
var pipeline = new Pipeline ("my_pipeline");
var bin = new Bin ("my_bin");
var bus = new Bus ();
var src = ElementFactory.make ("autoaudiosrc", "my_src");
var sink = ElementFactory.make ("autoaudiosink", "my_sink");
var convert = ElementFactory.make ("audioconvert", "my_convert");
var level = ElementFactory.make ("level", "my_level");
var fakesink = ElementFactory.make ("fakesink", "my_fakesink");
// Adding elements to pipeline
//pipeline.add_many (src, sink);
bin.add_many (pipeline, src, convert, level, fakesink);
src.link(convert);
convert.link_filtered (level, caps);
level.link(fakesink);
level.set ("post-messages", true);
fakesink.set ("sync", true);
bus = pipeline.get_bus ();
var watch_id = bus.add_watch (Priority.DEFAULT, message_handler);
// Linking source to sink
src.link (sink);
// Set pipeline state to PLAYING
pipeline.set_state (State.PLAYING);
提前感谢!
您快到了。委托标识函数签名:其参数类型和返回类型。 BusFunc类型具有签名:public delegate bool BusFunc (Bus bus, Message message)
,因此您的处理程序将类似于:
bool message_handler (Bus my_bus, Message my_message)
{
print (@"Message type: $(my_message.type.get_name ())\n");
return true;
}
在此示例中,它返回true
以保留处理程序。
此示例未经测试,但应为您提供前进的正确思路。