Java Gstreamer Gnonlin source segmentation - java-gstreamer

Using Java Gstreamer binding 1, I want to read an audio file from disk and write a segment of this file back to disk. For this, I cannot use the "filesrc" element, but instead I found that I can use the "gnlurisource" element from the Gnonlin plugin 2.
I took Gstreamer Java binding and I compiled it locally, getting a jar file that I added to my project. I also installed Gstreamer on Ubuntu using the following commands:
sudo apt-get install libgstreamer1.0-dev
sudo apt-get install gstreamer1.0-gnonlin
The program compiles without errors, but it remains stuck and does nothing. Below I attach my program code:
import java.util.concurrent.TimeUnit;
import org.freedesktop.gstreamer.Element;
import org.freedesktop.gstreamer.ElementFactory;
import org.freedesktop.gstreamer.Gst;
import org.freedesktop.gstreamer.Pipeline;
import org.freedesktop.gstreamer.State;
public class AudioSegmentation {
public static void main(String[] args) {
Pipeline pipe;
Element asr;
Element composition;
Element gnlsource;
Element convert;
Element filesink;
Gst.init();
pipe = new Pipeline("SimplePipeline");
composition = ElementFactory.make("gnlcomposition", "comp");
gnlsource = ElementFactory.make("gnlurisource", "gnlsource");
convert = ElementFactory.make("audioconvert", "compconvert");
filesink = ElementFactory.make("filesink", "filesink");
gnlsource.set("uri", "file:///home/user/Desktop/file-source.wav");
gnlsource.set("start", TimeUnit.SECONDS.toNanos(5));
gnlsource.set("duration", TimeUnit.SECONDS.toNanos(2));
filesink.set("location", "/home/user/Desktop/file-destination.wav");
composition.link(gnlsource);
pipe.addMany(composition, convert, filesink);
Element.linkMany(composition, convert, filesink);
pipe.setState(State.PLAYING);
Gst.main();
Gst.quit();
}
}
I don't have so much experience with Gstreamer, can you give me a hint about what's wrong?
Thank you!

UPDATE: I managed to use gstreamer from the command line to select a segment from an audio file. The "gnlurisource" element has the "inpoint" paramenter to set the segment start time and "duration" to specify the duration of the segment.
Here is the command:
gst-launch-1.0 gnlurisource uri=file:///home/user/Desktop/file-source.wav inpoint=2000000000 duration=1500000000 ! audioconvert ! wavenc ! filesink location=/home/user/Desktop/file-destination.wav
I'm still trying to implement this pipeline in Java. I tried something like that, but it doesn't work:
import java.util.concurrent.TimeUnit;
import org.freedesktop.gstreamer.Element;
import org.freedesktop.gstreamer.ElementFactory;
import org.freedesktop.gstreamer.Gst;
import org.freedesktop.gstreamer.Pipeline;
import org.freedesktop.gstreamer.State;
public class AudioSegmentation {
public static void main(String[] args) {
Pipeline pipe;
Element gnlsource;
Element audioconvert;
Element wavenc;
Element filesink;
Gst.init();
pipe = new Pipeline("SimplePipeline");
gnlurisource = ElementFactory.make("gnlurisource", "gnlurisource");
audioconvert = ElementFactory.make("audioconvert", "audioconvert");
wavenc = ElementFactory.make("wavenc", "wavenc");
filesink = ElementFactory.make("filesink", "filesink");
gnlurisource.set("uri", "file:///home/user/Desktop/file-source.wav");
gnlurisource.set("inpoint", TimeUnit.SECONDS.toNanos(2));
gnlurisource.set("duration", TimeUnit.SECONDS.toNanos(3));
filesink.set("location", "/home/user/Desktop/file-destination.wav");
pipe.addMany(gnlurisource, audioconvert, wavenc, filesink);
Element.linkMany(gnlurisource, audioconvert, wavenc, filesink);
pipe.setState(State.PLAYING);
Gst.main();
Gst.quit();
}

Related

How to read cassandra FQL logs in java?

I have a bunch of cassandra FQL logs with the "cq4" extension. I would like to read them in Java, is there a Java class that those log entries can be mapped into?
These are the logs I see.
I want to read this with this code:
import net.openhft.chronicle.Chronicle;
import net.openhft.chronicle.ChronicleQueueBuilder;
import net.openhft.chronicle.ExcerptTailer;
import java.io.IOException;
public class Main{
public static void main(String[] args) throws IOException {
Chronicle chronicle = ChronicleQueueBuilder.indexed("/Users/pavelorekhov/Desktop/fql_logs").build();
ExcerptTailer tailer = chronicle.createTailer();
while (tailer.nextIndex()) {
tailer.readInstance(/*class goes here*/)
}
}
}
I think from the code and screenshot you can understand what kind of class I need in order to read log entries into objects. Does that class exist in some cassandra maven dependency?
You are using Chronicle 3.x, which is very old.
I suggest using Chronicle 5.20.123, which is the version Cassandra uses.
I would assume Cassandra has it's own tool for reading the contents of these file however, you can dump the raw messages with net.openhft.chronicle.queue.main.DumpMain
I ended up cloning cassandra's github repo from here: https://github.com/apache/cassandra
In their code they have the FQLQueryIterator class which you can use to read logs, like so:
SingleChronicleQueue scq = SingleChronicleQueueBuilder.builder().path("/Users/pavelorekhov/Desktop/fql_logs").build();
ExcerptTailer excerptTailer = scq.createTailer();
FQLQueryIterator iterator = new FQLQueryIterator(excerptTailer, 1);
while (iterator.hasNext()) {
FQLQuery fqlQuery = iterator.next(); // object that holds the log entry
// do whatever you need to do with that log entry...
}

Custom update listener to set subtask's fix-version

I'm developing custom listener which will update subtask's fix version to same value as it's parent issue.
Currently we are using post-function in workflow in order to set subtask's fix version according to parent on subtask creation. This however doesn't cover cases when subtask already exists and parent's fix version gets updated. New value from parent task is not propagated to subtask.
I'm using script runner and I'm creating 'Custom lisatener', for my specific project and specified Event: 'Issue Updated'. I added script as following:
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.config.SubTaskManager
import com.atlassian.jira.event.issue.AbstractIssueEventListener
import com.atlassian.jira.event.issue.IssueEvent
import com.atlassian.jira.event.type.EventDispatchOption
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.project.version.Version
import org.apache.log4j.Logger
class CopyFixVersionFromParentToChild extends AbstractIssueEventListener {
Logger log = Logger.getLogger(CopyFixVersionFromParentToChild.class);
SubTaskManager subTaskManager = ComponentAccessor.getComponent(SubTaskManager.class)
IssueManager issueManager = ComponentAccessor.getComponent(IssueManager.class)
#Override
void issueUpdated(IssueEvent event) {
log.warn("\nIssue updated!!!\n")
try {
Issue updatedIssue = event.getIssue()
if (updatedIssue.issueTypeObject.name == "Parent issue type") {
Collection<Version> fixVersions = new ArrayList<Version>()
fixVersions = updatedIssue.getFixVersions()
Collection<Issue> subTasks = updatedIssue.getSubTaskObjects()
if (subTaskManager.subTasksEnabled && !subTasks.empty) {
subTasks.each {
if (it instanceof MutableIssue) {
((MutableIssue) it).setFixVersions(fixVersions)
issueManager.updateIssue(event.getUser(), it, EventDispatchOption.ISSUE_UPDATED, false)
}
}
}
}
} catch (ex) {
log.debug "Event: ${event.getEventTypeId()} fired for ${event.issue} and caught by script 'CopyVersionFromParentToChild'"
log.debug(ex.getMessage())
}
}
}
Problem is, that it doesn't work. I'm not sure whethe rit's problem that my script logic is encapsulated inside class. Do I have to register this in some specific way? Or am I using script runner completely wrong and I'm pasting this script to wrong section? I checked code against JIRA API and it looks like it should work, my IDE doesnt show any warnings/errors.
Also, could anyone give me hints on where to find logging output from custom scripts like this? Whatever message I put into logger, I seem to be unable to find anywhere in JIRA logs (although I'm aware that script might not work for now).
Any response is much appreciated guys, Thanks.
Martin
Well, I figure it out.
Method I posted, which implements listener as groovy class is used in different way than I expected. These kind of script files were used to be located in to specific path in JIRA installation and ScriptRunner would register them into JIRA as listeners.
In in order to create 'simple' listener script which reacts to issue updated event, I had to strip it down to this code
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.event.type.EventDispatchOption
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.project.version.Version
IssueManager issueManager = ComponentAccessor.getComponent(IssueManager.class)
Issue updatedIssue = event.getIssue()
Collection<Version> fixVersions = new ArrayList<Version>()
fixVersions = updatedIssue.getFixVersions()
Collection<Issue> subTasks = updatedIssue.getSubTaskObjects()
subTasks.each {
if (it instanceof MutableIssue) {
((MutableIssue) it).setFixVersions(fixVersions)
issueManager.updateIssue(event.getUser(), it, EventDispatchOption.ISSUE_UPDATED, false)
}
}
You past this to script runner interface and it works :-). Hope this helps anyone who's learning ScriptRunner. Cheers.
Matthew

Vala gstreamer link failed

I've a problem with playing a mjpeg stream in vala.
I have construct my pipeline and it works with only two elements(videotestsrc and cluttersink), but if I want to add more I get an "Internal data flow error" and "streaming task paused, reason not-linked (-1)".
If I run the pipeline manually it works:
gst-launch souphttpsrc location=http://mjpeg.sanford.io/count.mjpeg ! multipartdemux ! jpegdec ! autovideosink
Here is my streaming class:
public class Stream : Clutter.Actor {
Clutter.Texture video;
public dynamic Gst.Element playbin;
public Gst.Pipeline pipeline;
public Gst.Element demux;
public Gst.Element jpegdec;
public Gst.Element outputsink;
public dynamic Gst.Element src;
public dynamic Gst.Element video_sink;
public Stream(){
print("stream");
video = new Clutter.Texture ();
this.pipeline = new Gst.Pipeline("videopipeline");
this.src = Gst.ElementFactory.make ("souphttpsrc","httpsrc");
this.demux = Gst.ElementFactory.make ("multipartdemux","demux");
this.jpegdec = Gst.ElementFactory.make ("jpegdec","jpegdec");
this.outputsink = Gst.ElementFactory.make("autovideosink","output");
this.video_sink = Gst.ElementFactory.make ("cluttersink", "source");
this.video_sink.texture = video;
this.src.set("location","http://mjpeg.sanford.io/count.mjpeg");
this.pipeline.add_many(this.src,this.demux,this.jpegdec,this.outputsink,this.video_sink);
this.src.link(this.demux);
this.demux.link(this.jpegdec);
this.jpegdec.link(this.outputsink);
this.outputsink.link(this.video_sink);
this.add_child (video);
this.pipeline.set_state(Gst.State.PLAYING);
}
}
Here is the full error log:
http://pastebin.com/b9GnA5ke
You can't have two sink elements attached to jpegdec. If you need to do that you should use the "tee" element, while making sure to use add a "queue" to each branch of the tee.
There may also be a caps issue going from jpegdec to cluttersink. I'd structure it as follows:
souphttpsrc ! multipartdemux ! jpegdec ! tee name=t ! queue ! videoconvert ! autovideosink
t. ! queue ! videoconvert ! cluttersink

Neo4j Spatial: can't run spatial

I have been trying to work with Neo4j Spatial for my project, but I can't make it work.
With limited documentation and examples I figured out how to load OSM map to the database. But to check if it is loaded, I am trying to execute a spatial query.
While trying to run my code I get this error:
import.java:69: error: cannot access GremlinGroovyPipeline
.startIntersectSearch(layer, bbox)
^
class file for com.tinkerpop.gremlin.groovy.GremlinGroovyPipeline not found
I understand what's wrong (it can't find the required library), but I don't know how to fix it. The reason is when I run Neo4j Spatial tests, LayerTest.java and TestSpatial.java do include GeoPipeline library and it works perfectly fine. However, when I created my simple java file to test Neo4j, and trying to execute commands that depend GeoPipeline library I get the error above.
I read the instructions on github for Neo4j and saw this note:
Note: neo4j-spatial has a mandatory dependency on
GremlinGroovyPipeline from the com.tinkerpop.gremlin.groovy package.
The dependency in neo4j is type 'provided', so when using
neo4j-spatial in your own Java project, make sure to add the following
dependency to your pom.xml, too.
However, I am not using Maven to build my app. It is a simple java file, that I want to run to test if I get how everything works.
here is the code from my java file:
package org.neo4j.gis.spatial;
import java.io.File;
import java.io.IOException;
import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.geotools.data.DataStore;
import org.geotools.data.neo4j.Neo4jSpatialDataStore;
import org.geotools.data.simple.SimpleFeatureCollection;
import org.neo4j.gis.spatial.osm.OSMDataset;
import org.neo4j.gis.spatial.osm.OSMDataset.Way;
import org.neo4j.gis.spatial.osm.OSMGeometryEncoder;
import org.neo4j.gis.spatial.osm.OSMImporter;
import org.neo4j.gis.spatial.osm.OSMLayer;
import org.neo4j.gis.spatial.osm.OSMRelation;
import org.neo4j.gis.spatial.pipes.osm.OSMGeoPipeline;
import org.neo4j.graphdb.Direction;
import org.neo4j.graphdb.Node;
import org.neo4j.graphdb.Relationship;
import com.vividsolutions.jts.geom.Envelope;
import com.vividsolutions.jts.geom.Geometry;
import org.neo4j.kernel.impl.batchinsert.BatchInserter;
import org.neo4j.kernel.impl.batchinsert.BatchInserterImpl;
import org.neo4j.kernel.EmbeddedGraphDatabase;
import org.neo4j.graphdb.GraphDatabaseService;
import org.neo4j.gis.spatial.pipes.GeoPipeline;
class SpatialOsmImport {
public static void main(String[] args)
{
OSMImporter importer = new OSMImporter("ott.osm");
Map<String, String> config = new HashMap<String, String>();
config.put("neostore.nodestore.db.mapped_memory", "90M" );
config.put("dump_configuration", "true");
config.put("use_memory_mapped_buffers", "true");
BatchInserter batchInserter = new BatchInserterImpl("target/dependency", config);
importer.setCharset(Charset.forName("UTF-8"));
try{
importer.importFile(batchInserter, "ott.osm", false);
batchInserter.shutdown();
GraphDatabaseService db = new EmbeddedGraphDatabase("target/dependency");
importer.reIndex(db, 10000);
db.shutdown();
}
catch(Exception e)
{
System.out.println(e.getMessage());
}
GraphDatabaseService database = new EmbeddedGraphDatabase("target/dependency");
try{
SpatialDatabaseService spatialService = new SpatialDatabaseService(database);
Layer layer = spatialService.getLayer("layer_roads");
LayerIndexReader spatialIndex = layer.getIndex();
System.out.println("Have " + spatialIndex.count() + " geometries in " + spatialIndex.getBoundingBox());
Envelope bbox = new Envelope(-75.80, 45.19, -75.7, 45.23);
// Search searchQuery = new SearchIntersectWindow(bbox);
// spatialIndex.executeSearch(searchQuery);
// List<SpatialDatabaseRecord> results = searchQuery.getResults();
List<SpatialDatabaseRecord> results = GeoPipeline
.startIntersectSearch(layer, bbox)
.toSpatialDatabaseRecordList();
doGeometryTestsOnResults(bbox, results);
} finally {
database.shutdown();
}
}
private static void doGeometryTestsOnResults(Envelope bbox, List<SpatialDatabaseRecord> results) {
System.out.println("Found " + results.size() + " geometries in " + bbox);
Geometry geometry = results.get(0).getGeometry();
System.out.println("First geometry is " + geometry);
geometry.buffer(2);
}
}
It is very simple right now, but I can't make it work. How do I include com.tinkerpop.gremlin.groovy.GremlinGroovyPipeline in my app, so it works?
I run everything on Ubuntu 12.04 and java version "1.7.0_25", Java(TM) SE Runtime Environment (build 1.7.0_25-b15).
Any help is greatly appreciated.
the best way to get all the required dependencies in a place where you can include them in your classpath is to run
mvn dependency:copy-dependencies
in neo4j-spatial, and find the libs to include in target/deps, see http://maven.apache.org/plugins/maven-dependency-plugin/usage.html

How to record / capture audio with RecordControl on Java ME, SE K770i

I want to record sound on my Java ME App on K770i. So I used this:
http://java.sun.com/javame/reference/apis/jsr135/javax/microedition/media/control/RecordControl.html
example of RecordControl in my code. It goes like this:
import java.util.Vector;
import javax.microedition.lcdui.Choice;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.List;
import javax.microedition.media.Manager;
import javax.microedition.media.MediaException;
import javax.microedition.midlet.MIDlet;
import java.io.*;
import javax.microedition.lcdui.*;
import javax.microedition.media.*;
import javax.microedition.media.control.*;
import javax.microedition.midlet.*;
import javax.microedition.rms.*;
(...)
try {
// Create a Player that captures live audio.
Player p = Manager.createPlayer("capture://audio");
p.realize();
// Get the RecordControl, set the record stream,
// start the Player and record for 5 seconds.
RecordControl rc = (RecordControl)p.getControl("RecordControl");
ByteArrayOutputStream output = new ByteArrayOutputStream();
rc.setRecordStream(output);
rc.startRecord();
p.start();
Thread.currentThread().sleep(5000);
rc.commit();
p.close();
} catch (IOException ioe) {
} catch (MediaException me) {
} catch (InterruptedException ie) { }
But unfortunately when I try to build it, it tells me:
*** Creating directories ***
*** Compiling source files ***
..\src\example\audiodemo\AudioPlayer.java:121: cannot find symbol
symbol : class RecordControl
location: class example.audiodemo.AudioPlayer
RecordControl rc = (RecordControl)p.getControl("RecordControl");
^
..\src\example\audiodemo\AudioPlayer.java:121: cannot find symbol
symbol : class RecordControl
location: class example.audiodemo.AudioPlayer
RecordControl rc = (RecordControl)p.getControl("RecordControl");
^
2 errors
So my question is: why there is no RecordControl class if in documentations it is written this class should be there. Or is there other method to record / capture audio from microfone in Java ME of Sony Ericsson?
How do you record sound?
The reason might be that it does not support audio capture.
Try to get this value from the Sony phone.
System.getProperty("supports.audio.capture")
Write a simple midlet with a form appending the above statement. like below..
frm.append("Supports Audio:" + System.getProperty("supports.audio.capture"));
If this returns the false, then you are clear...
The RecordControl wont work.
Few Sony phones dont support audio capture..like Sony p1i.
Hope this helps..
OK, so as i said I am java me newbie. So what I needed to do:
1) Added to MIDlet-Permissions in JAD and Manifest file to javax.microedition.media.control.RecordControl
2) In build.bat that I used from other demo project add inclusion of mmapi.jar, where the RecordControl is located in.
So i've added one last line shown here:
set CLDCAPI=%LIB_DIR%\cldcapi10.jar
set MIDPAPI=%LIB_DIR%\midpapi20.jar
set MMAPI=%LIB_DIR%\mmapi.jar
And according to this change updated two other lines of code:
%JAVAC% -bootclasspath %CLDCAPI%;%MIDPAPI%;%MMAPI% -source 1.3 -target 1.3 -d ..\tmpclasses -classpath ..\tmpclasses %JAVA_FILES%
%PREVERIFY% -classpath %CLDCAPI%;%MIDPAPI%;%MMAPI%;..\tmpclasses -d ..\classes ..\tmpclasses
And now everything compiles well. It was very lame isn't it?

Resources