I am attempting to get the current volume level from a live audio stream, using gstreamer 1.0.
Using the following command line:
gst-launch-1.0 -m audiotestsrc ! level ! fakesink
the messages from the level element read "rms=(GValueArray)NULL" (the same for peak and decay).
The same command using version 0.10 will in fact show the values. There was a ticket opened about that here:
and it was closed later stating that the values are in fact in the messages, just not deserialized to a display string.
Trusting that it is true, I am trying to read those values using gst1-java-core, which I understand is the most current version of the java bindings, working with the most current gstreamer. Here is the code:
public static void main(String[] args) {
Gst.init();
Pipeline pipeline = new Pipeline("pipeline");
Element src = ElementFactory.make("audiotestsrc", null);
Element audioConvert = ElementFactory.make("audioconvert", null);
Element level = ElementFactory.make("level", null);
level.set("message", "TRUE");
Element fakesink = ElementFactory.make("fakesink", null);
fakesink.set("sync", "TRUE");
pipeline.addMany(src, audioConvert, level, fakesink);
src.link(audioConvert);
audioConvert.link(level);
level.link(fakesink);
Bus bus = pipeline.getBus();
bus.connect(new Bus.MESSAGE() {
public void busMessage(Bus bus, Message message) {
if (message.getType() == MessageType.ELEMENT) {
Structure struct = message.getStructure();
System.out.println(struct);
ValueList lst = struct.getValueList("peak");
int numValues = lst.getSize();
System.out.println(numValues);
try {
double d = struct.getDouble("peak", 0);
} catch (Exception ex) {
System.out.println(ex);
}
}
}
});
pipeline.setState(State.PLAYING);
Gst.main();
}
the println(struct) output is just like the command line message:
level, endtime=(guint64)23600000000, timestamp=(guint64)23500000000, stream-time=(guint64)23500000000, running-time=(guint64)23500000000, duration=(guint64)100000000, rms=(GValueArray)NULL, peak=(GValueArray)NULL, decay=(GValueArray)NULL;
lst.getSize() will produce an assertion error, and the result is zero:
(unknown:17832): GStreamer-CRITICAL **: gst_value_list_get_size: assertion 'GST_VALUE_HOLDS_LIST (value)' failed
struct.getDouble("peak", 0) will produce another assertion, and then throw an exception:
(unknown:18056): GStreamer-CRITICAL **: gst_value_list_get_value: assertion 'GST_VALUE_HOLDS_LIST (value)' failed
java.lang.RuntimeException: List does not contain value 0
I tried also other types besides double, but never get any results.
Is there no level? or am I doing something wrong here? I can't seem to find any further information online. I tried to run the example program "level-example.c", but I am having a hard time linking it.
If anyone has any more insight it would be greatly appreciated !