vala:操纵(gstreamer)GLib.Value

时间:2013-10-19 09:50:27

标签: gstreamer vala

我写了下面的小vala程序,我不知道怎么做 要操纵GLib.Value类型,请参阅下面的代码:

http://gstreamer.freedesktop.org/data/doc/gstreamer/head/gst-plugins-good-plugins/html/gst-plugins-good-plugins-level.html

using Gst;


void application_message(Gst.Bus bus, Gst.Message msg) {

        var s = msg.get_structure();

        if(s == null)
            return;

        string msgtype = s.get_name();

        if(msgtype != "level")
            return;

        GLib.Value rms = s.get_value("rms");
        GLib.Value st = s.get_value("stream-time");

        // according to the doc here : http://gstreamer.freedesktop.org/data/doc/gstreamer/head/gst-plugins-good-plugins/html/gst-plugins-good-plugins-level.html

        // "rms" is apparently a  "GValueArray of gdouble"
        // and         
        // "st" is a GstClockTime, which is a "typedef guint64 GstClockTime"

        // I want to create a string representation of the two, ex: 

        // 72374237490234, [0.234234,0,424234234,0.423423423,0.5345345, ...]

        // and I'm clueless as to how to do the conversions or typecasts...
}


void main (string[] args) {

    Gst.init (ref args);

    try {

        var pipeline = Gst.parse_launch(
          "pulsesrc device=\"alsa_input.usb-046d_08c9_674634A4-02-U0x46d0x8c9.analog-mono\" ! " +
          "level name=wavelevel interval=10000000 ! " +
          "wavenc ! filesink location=audioz.wav"
        );

        var bus = pipeline.get_bus();

        bus.add_signal_watch();
        bus.message.connect(application_message);

        // Set pipeline state to PLAYING
        pipeline.set_state (State.PLAYING);

        // Creating and starting a GLib main loop
        new MainLoop ().run ();        
    }
    catch(Error e) {
        print("%s\n", e.message);
    }
}

更新:

GLib.Value的文档在这里:http://www.valadoc.org/#!api=gobject-2.0/GLib.Value

调用strdup_contents()有点令人满意,但我想在rms中操作数组,

printl(rms.type()。name())告诉我它是GstValueList, 所以我应该把它投入到这个: http://www.valadoc.org/#!api=gstreamer-1.0/Gst.ValueList 但是vala似乎对类型Gst.ValueList ...

一无所知

1 个答案:

答案 0 :(得分:2)

Vala非常容易使用GLib.Value,它将隐式转换GLib.Value和本机类型。将GLib.StringBuilder投入到混合中以构建您的数组,像这样(未经测试)应该可以解决这个问题:

GLib.StringBuilder s = new GLib.StringBuilder ();

s.append (((uint64) st).to_string ());
s.append (",[");
{
  bool first = true;
  foreach ( unowned GLib.Value value in rms.values ) {
    if (!first) {
      s.append_c (',');
    } else {
      first = false;
    }
    s.append (((double) value).to_string ());
  }
}
s.append_c (']');