I've written the small vala program below, and I don't know how to manipulate the GLib.Value types, see the code below :

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

UPDATE :

THe doc for GLib.Value is here : http://www.valadoc.org/#!api=gobject-2.0/GLib.Value

calling strdup_contents() is somewhat satisfactory, but I'd like to manipulate the array in rms,

printl(rms.type().name()) tells me that it's a GstValueList, so I'd thing that I should cast it to this : http://www.valadoc.org/#!api=gstreamer-1.0/Gst.ValueList but vala seems to know nothing of the type Gst.ValueList...

有帮助吗?

解决方案

Vala makes working with GLib.Value very easy, it will implicitly convert between GLib.Value and the native types. Throwing GLib.StringBuilder into the mix to build your array, something like this (untested) should do the trick:

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 (']');
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top