org.gstreamer.lowlevel.MainLoop Maven / Gradle / Ivy
Show all versions of gstreamer-java Show documentation
/*
* Copyright (c) 2007 Wayne Meissner
*
* This file is part of gstreamer-java.
*
* This code is free software: you can redistribute it and/or modify it under
* the terms of the GNU Lesser General Public License version 3 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* version 3 for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* version 3 along with this work. If not, see .
*/
package org.gstreamer.lowlevel;
import static org.gstreamer.lowlevel.GlibAPI.GLIB_API;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;
import org.gstreamer.Gst;
import com.sun.jna.Pointer;
/**
* The GLib main loop.
*/
public class MainLoop extends RefCountedObject {
private static final List bgTasks = new LinkedList();
/**
* Creates a new instance of {@code MainLoop}
*
* This will create a new main loop on the default gstreamer main context.
*
*/
public MainLoop() {
super(initializer(GLIB_API.g_main_loop_new(Gst.getMainContext(), false)));
}
/**
* Creates a new instance of {@code MainLoop}
*
*
This variant is used internally.
*
* @param init internal initialization data.
*/
public MainLoop(Initializer init) {
super(init);
}
/**
* Instructs a main loop to stop processing and return from {@link #run}.
*/
public void quit() {
invokeLater(new Runnable() {
public void run() {
GLIB_API.g_main_loop_quit(MainLoop.this);
}
});
}
/**
* Enter a loop, processing all events.
*
The loop will continue processing events until {@link #quit} is
* called.
*/
public void run() {
GLIB_API.g_main_loop_run(this);
}
/**
* Returns whether this main loop is currently processing or not.
*
* @return true if the main loop is currently being run.
*/
public boolean isRunning() {
return GLIB_API.g_main_loop_is_running(this);
}
/**
* Gets the main context for this main loop.
*
* @return a main context.
*/
public GMainContext getMainContext() {
return GLIB_API.g_main_loop_get_context(this);
}
/**
* Runs the main loop in a background thread.
*/
public void startInBackground() {
bgThread = new java.lang.Thread(new Runnable() {
public void run() {
MainLoop.this.run();
}
});
bgThread.setDaemon(true);
bgThread.setName("gmainloop");
bgThread.start();
}
/**
* Invokes a task on the main loop thread.
*
This method will wait until the task has completed before returning.
*
* @param r the task to invoke.
*/
public void invokeAndWait(Runnable r) {
FutureTask