[nexuiz-commits] r8637 - in trunk/misc/tools/NexuizDemoRecorder: . main plugins plugins/sample plugins/sample/src plugins/sample/src/main plugins/sample/src/main/java plugins/sample/src/main/java/com plugins/sample/src/main/java/com/nexuiz plugins/sample/src/main/java/com/nexuiz/demorecorder plugins/sample/src/main/java/com/nexuiz/demorecorder/application plugins/sample/src/main/java/com/nexuiz/demorecorder/application/plugins plugins/sample/src/main/java/com/nexuiz/demorecorder/application/plugins/impl plugins/sample/src/main/java/com/nexuiz/demorecorder/application/plugins/impl/sample plugins/sample/src/main/resources plugins/sample/src/main/resources/META-INF plugins/sample/src/main/resources/META-INF/services plugins/virtualdub plugins/virtualdub/src plugins/virtualdub/src/main plugins/virtualdub/src/main/java plugins/virtualdub/src/main/java/com plugins/virtualdub/src/main/java/com/nexuiz plugins/virtualdub/src/main/java/com/nexuiz/demorecorder plugins/virtualdub/src/main/java/com/nexuiz/demorecorder/application plugins/virtualdub/src/main/java/com/nexuiz/demorecorder/application/plugins plugins/virtualdub/src/main/java/com/nexuiz/demorecorder/application/plugins/impl plugins/virtualdub/src/main/java/com/nexuiz/demorecorder/application/plugins/impl/virtualdub plugins/virtualdub/src/main/resources plugins/virtualdub/src/main/resources/META-INF plugins/virtualdub/src/main/resources/META-INF/services
DONOTREPLY at icculus.org
DONOTREPLY at icculus.org
Thu Feb 11 11:02:27 EST 2010
Author: greenmarine
Date: 2010-02-11 11:02:26 -0500 (Thu, 11 Feb 2010)
New Revision: 8637
Added:
trunk/misc/tools/NexuizDemoRecorder/main/pom.xml
trunk/misc/tools/NexuizDemoRecorder/plugins/sample/
trunk/misc/tools/NexuizDemoRecorder/plugins/sample/pom.xml
trunk/misc/tools/NexuizDemoRecorder/plugins/sample/src/
trunk/misc/tools/NexuizDemoRecorder/plugins/sample/src/main/
trunk/misc/tools/NexuizDemoRecorder/plugins/sample/src/main/java/
trunk/misc/tools/NexuizDemoRecorder/plugins/sample/src/main/java/com/
trunk/misc/tools/NexuizDemoRecorder/plugins/sample/src/main/java/com/nexuiz/
trunk/misc/tools/NexuizDemoRecorder/plugins/sample/src/main/java/com/nexuiz/demorecorder/
trunk/misc/tools/NexuizDemoRecorder/plugins/sample/src/main/java/com/nexuiz/demorecorder/application/
trunk/misc/tools/NexuizDemoRecorder/plugins/sample/src/main/java/com/nexuiz/demorecorder/application/plugins/
trunk/misc/tools/NexuizDemoRecorder/plugins/sample/src/main/java/com/nexuiz/demorecorder/application/plugins/impl/
trunk/misc/tools/NexuizDemoRecorder/plugins/sample/src/main/java/com/nexuiz/demorecorder/application/plugins/impl/sample/
trunk/misc/tools/NexuizDemoRecorder/plugins/sample/src/main/java/com/nexuiz/demorecorder/application/plugins/impl/sample/SamplePlugin.java
trunk/misc/tools/NexuizDemoRecorder/plugins/sample/src/main/resources/
trunk/misc/tools/NexuizDemoRecorder/plugins/sample/src/main/resources/META-INF/
trunk/misc/tools/NexuizDemoRecorder/plugins/sample/src/main/resources/META-INF/services/
trunk/misc/tools/NexuizDemoRecorder/plugins/sample/src/main/resources/META-INF/services/com.nexuiz.demorecorder.application.plugins.EncoderPlugin
trunk/misc/tools/NexuizDemoRecorder/plugins/virtualdub/
trunk/misc/tools/NexuizDemoRecorder/plugins/virtualdub/pom.xml
trunk/misc/tools/NexuizDemoRecorder/plugins/virtualdub/src/
trunk/misc/tools/NexuizDemoRecorder/plugins/virtualdub/src/main/
trunk/misc/tools/NexuizDemoRecorder/plugins/virtualdub/src/main/java/
trunk/misc/tools/NexuizDemoRecorder/plugins/virtualdub/src/main/java/com/
trunk/misc/tools/NexuizDemoRecorder/plugins/virtualdub/src/main/java/com/nexuiz/
trunk/misc/tools/NexuizDemoRecorder/plugins/virtualdub/src/main/java/com/nexuiz/demorecorder/
trunk/misc/tools/NexuizDemoRecorder/plugins/virtualdub/src/main/java/com/nexuiz/demorecorder/application/
trunk/misc/tools/NexuizDemoRecorder/plugins/virtualdub/src/main/java/com/nexuiz/demorecorder/application/plugins/
trunk/misc/tools/NexuizDemoRecorder/plugins/virtualdub/src/main/java/com/nexuiz/demorecorder/application/plugins/impl/
trunk/misc/tools/NexuizDemoRecorder/plugins/virtualdub/src/main/java/com/nexuiz/demorecorder/application/plugins/impl/virtualdub/
trunk/misc/tools/NexuizDemoRecorder/plugins/virtualdub/src/main/java/com/nexuiz/demorecorder/application/plugins/impl/virtualdub/VirtualDubPlugin.java
trunk/misc/tools/NexuizDemoRecorder/plugins/virtualdub/src/main/resources/
trunk/misc/tools/NexuizDemoRecorder/plugins/virtualdub/src/main/resources/META-INF/
trunk/misc/tools/NexuizDemoRecorder/plugins/virtualdub/src/main/resources/META-INF/services/
trunk/misc/tools/NexuizDemoRecorder/plugins/virtualdub/src/main/resources/META-INF/services/com.nexuiz.demorecorder.application.plugins.EncoderPlugin
Removed:
trunk/misc/tools/NexuizDemoRecorder/pom.xml
Log:
NDR: add sample and virtualdub plug-in
Added: trunk/misc/tools/NexuizDemoRecorder/main/pom.xml
===================================================================
--- trunk/misc/tools/NexuizDemoRecorder/main/pom.xml (rev 0)
+++ trunk/misc/tools/NexuizDemoRecorder/main/pom.xml 2010-02-11 16:02:26 UTC (rev 8637)
@@ -0,0 +1,83 @@
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>NexuizDemoRecorder</groupId>
+ <artifactId>NexuizDemoRecorder</artifactId>
+ <packaging>jar</packaging>
+ <version>0.2</version>
+ <name>NexuizDemoRecorder</name>
+ <url>http://maven.apache.org</url>
+ <dependencies>
+ <dependency>
+ <groupId>com.miglayout</groupId>
+ <artifactId>miglayout</artifactId>
+ <version>3.7.2</version>
+ </dependency>
+ <dependency>
+ <groupId>org.swinglabs</groupId>
+ <artifactId>swingx</artifactId>
+ <version>1.6</version>
+ <exclusions>
+ <!-- Exclude unneeded libs that have been transitively resolved for SwingX -->
+ <exclusion>
+ <groupId>org.swinglabs</groupId>
+ <artifactId>swing-worker</artifactId>
+ </exclusion>
+ <exclusion>
+ <groupId>com.jhlabs</groupId>
+ <artifactId>filters</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+ <dependency>
+ <groupId>javax.help</groupId>
+ <artifactId>javahelp</artifactId>
+ <version>2.0.02</version>
+ </dependency>
+ </dependencies>
+ <build>
+ <resources>
+ <resource>
+ <directory>src/main/resources</directory>
+ </resource>
+ </resources>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <version>2.0.2</version>
+ <configuration>
+ <source>1.6</source>
+ <target>1.6</target>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-jar-plugin</artifactId>
+ <configuration>
+ <archive>
+ <manifest>
+ <addClasspath>true</addClasspath>
+ <classpathPrefix>lib/</classpathPrefix>
+ <mainClass>com.nexuiz.demorecorder.main.Driver</mainClass>
+ </manifest>
+ </archive>
+ </configuration>
+ </plugin>
+ <plugin>
+ <artifactId>maven-dependency-plugin</artifactId>
+ <executions>
+ <execution>
+ <phase>package</phase>
+ <goals>
+ <goal>copy-dependencies</goal>
+ </goals>
+ <configuration>
+ <outputDirectory>${project.build.directory}/lib</outputDirectory>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+</project>
Added: trunk/misc/tools/NexuizDemoRecorder/plugins/sample/pom.xml
===================================================================
--- trunk/misc/tools/NexuizDemoRecorder/plugins/sample/pom.xml (rev 0)
+++ trunk/misc/tools/NexuizDemoRecorder/plugins/sample/pom.xml 2010-02-11 16:02:26 UTC (rev 8637)
@@ -0,0 +1,35 @@
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>NexuizDemoRecorder</groupId>
+ <artifactId>SamplePlugin</artifactId>
+ <version>0.0.1-SNAPSHOT</version>
+ <dependencies>
+ <dependency>
+ <groupId>NexuizDemoRecorder</groupId>
+ <artifactId>NexuizDemoRecorder</artifactId>
+ <version>0.2</version>
+ <scope>provided</scope>
+ </dependency>
+ </dependencies>
+ <build>
+ <resources>
+ <resource>
+ <directory>src/main/resources</directory>
+ </resource>
+ </resources>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <version>2.0.2</version>
+ <configuration>
+ <source>1.6</source>
+ <target>1.6</target>
+ </configuration>
+ </plugin>
+
+
+ </plugins>
+ </build>
+</project>
\ No newline at end of file
Added: trunk/misc/tools/NexuizDemoRecorder/plugins/sample/src/main/java/com/nexuiz/demorecorder/application/plugins/impl/sample/SamplePlugin.java
===================================================================
--- trunk/misc/tools/NexuizDemoRecorder/plugins/sample/src/main/java/com/nexuiz/demorecorder/application/plugins/impl/sample/SamplePlugin.java (rev 0)
+++ trunk/misc/tools/NexuizDemoRecorder/plugins/sample/src/main/java/com/nexuiz/demorecorder/application/plugins/impl/sample/SamplePlugin.java 2010-02-11 16:02:26 UTC (rev 8637)
@@ -0,0 +1,202 @@
+package com.nexuiz.demorecorder.application.plugins.impl.sample;
+
+import java.util.Properties;
+
+import com.nexuiz.demorecorder.application.DemoRecorderApplication;
+import com.nexuiz.demorecorder.application.jobs.RecordJob;
+import com.nexuiz.demorecorder.application.plugins.EncoderPlugin;
+import com.nexuiz.demorecorder.application.plugins.EncoderPluginException;
+
+/**
+ * This is a sample plug-in implementation. It does not really do anything, but it
+ * is supposed to show you how to implement a plug-in and where to do what.
+ *
+ * First of all, it is important that your final jar file (you can have Maven create
+ * it for you) contains the META-INF folder (it will have that one anyway), and within
+ * that folder you must have the folder "services", in which you must have a file called
+ * com.nexuiz.demorecorder.application.plugins.EncoderPlugin (this is the fully
+ * qualified name of the interface you need to implement, EncoderPlugin).
+ * This file needs to contain just one line: the fully qualified name to your
+ * implementation class!
+ *
+ * Okay. The Nexuiz Demo Recorder (NDR) gives your plug-in 2 kinds of possibilities to
+ * configure it ("set it up") from within the NDR. Configuring the plug-in is also
+ * referred to as "setting preferences". There are
+ * - Global preferences: these will be shown in the "Preferences" dialog of the NDR
+ * - Job-specific preferences: these will be shown in the dialog you get when creating
+ * new jobs or templates, or when editing them
+ *
+ * Once the NDR loaded your plug-in, the first thing it will do is to call
+ * setApplicationLayer(), handing your plug-in the reference to the app-layer. Make sure that
+ * you save it in a private member variable!
+ *
+ * NDR will ask your plug-in to tell it about its global and job-specific preferences that exist.
+ * For each of these 2 kinds of preferences it will also ask you for the order in which you want
+ * these settings to appear in dialogs.
+ *
+ * The methods that ask you to return a Properties object: create a new Properties object and fill
+ * it with KEYS (that identify the setting), and VALUES (reasonable default values). The app-layer
+ * will save these "new" settings in the app_preferences.xml in the "settings" folder once NDR
+ * is closed (this applies only to the global settings!). That just means that, later on, to figure
+ * out whether the user changed settings from their default value, you need to ask the app-layer
+ * for its preferences object (that might have been manipulated by the user using the GUI) and look
+ * for "your" settings in that Properties object. A good example is the isEnabled() method.
+ */
+public class SamplePlugin implements EncoderPlugin {
+
+ /**
+ * Do not put the word "plug-in" in here, that would be redundant.
+ */
+ private static final String PLUGIN_NAME = "Sample";
+
+ /**
+ * Here we store our preferences. It is not necessary that these are in a inner-class, do it in
+ * your way if you want.
+ */
+ private static class Preferences {
+ /*
+ * Lets start with GLOBAL settings which will be seen in the Preferences dialog of the NDR
+ */
+ public static final String ENABLED = "Enabled"; //we will need this! "Enabled" means that
+ //that the preferences dialog will show the exact word "Enabled"
+
+ public static final String SAMPLE_SETTING = "Some sample setting";
+
+ /*
+ * Now we define the order in which we want these to be shown.
+ */
+ public static final String[] GLOBAL_PREFERENCES_ORDER = {
+ ENABLED,
+ SAMPLE_SETTING
+ };
+
+ //job-specific preferences
+ public static final String IN_USE_FOR_THIS_JOB = "Do something for this job";
+
+ /*
+ * OK, so far we have actually only created labels. But we also need default values
+ * So let's have a function that sets the default values up.
+ */
+ public static Properties globalDefaultPreferences = new Properties();
+ public static void createPreferenceDefaultValues() {
+ globalDefaultPreferences.setProperty(ENABLED, "false");
+ globalDefaultPreferences.setProperty(SAMPLE_SETTING, "filechooser");
+ /*
+ * Note that the values for the defaults can be:
+ * - "true" or "false", in this case the GUI will show a check-box
+ * - "filechooser", in this case the GUI will show a button that allows the user to select
+ * a file
+ * - anything else (also empty string if you like): will show a text field in the GUI
+ * (you are in charge of parsing it)
+ */
+ }
+
+ }
+
+ private DemoRecorderApplication appLayer;
+
+ /**
+ * You must only have a default constructor without parameters!
+ */
+ public SamplePlugin() {
+ Preferences.createPreferenceDefaultValues();
+ }
+
+
+
+ @Override
+ public Properties getGlobalPreferences() {
+ return Preferences.globalDefaultPreferences;
+ }
+
+ @Override
+ public String[] getGlobalPreferencesOrder() {
+ return Preferences.GLOBAL_PREFERENCES_ORDER;
+ }
+
+ @Override
+ public Properties getJobSpecificPreferences() {
+ /*
+ * This method is called whenever the dialog to create new jobs/templates (or edit them)
+ * is opened. This means that you can dynamically create the returned Properties object
+ * if you like, or you could of course also return something static.
+ */
+ Properties preferences = new Properties();
+ preferences.setProperty(Preferences.IN_USE_FOR_THIS_JOB, "true");
+ return preferences;
+ }
+
+ @Override
+ public String[] getJobSpecificPreferencesOrder() {
+ String[] order = {Preferences.IN_USE_FOR_THIS_JOB};
+ return order;
+ }
+
+ @Override
+ public String getName() {
+ return PLUGIN_NAME;
+ }
+
+ @Override
+ public void setApplicationLayer(DemoRecorderApplication appLayer) {
+ this.appLayer = appLayer;
+ }
+
+ @Override
+ public boolean isEnabled() {
+ /*
+ * Here we get the Properties object of the app-layer. Notice that this is actually a
+ * NDRPreferences object. It has a new method getProperty(String category, String key).
+ * The category is the name of our plug-in. The key is obviously our own ENABLED key.
+ */
+ String enabledString = this.appLayer.getPreferences().getProperty(PLUGIN_NAME, Preferences.ENABLED);
+ return Boolean.valueOf(enabledString);
+ }
+
+ @Override
+ public void executeEncoder(RecordJob job) throws EncoderPluginException {
+ /*
+ * This is where the party gets started.
+ * Of course you need to check whether your plug-in is enabled by the user, and whether the
+ * job-specific settings are set correctly. So let's do this now:
+ */
+ if (!this.isEnabled()) {
+ return;
+ }
+
+ if (job.getActualVideoDestination() == null) {
+ //should never happen... but just to make sure!
+ throw new EncoderPluginException("Actual video destination is not set (should have been set when processing the job)");
+ }
+
+ if (!job.getActualVideoDestination().exists()) {
+ throw new EncoderPluginException("Could not locate recorded video file (source) at location "
+ + job.getActualVideoDestination().getAbsolutePath());
+ }
+
+ //check for a job-specific setting ... this time we need it from the job:
+ Properties jobSpecificSettings = job.getEncoderPluginSettings(this);
+ String isEnabled = jobSpecificSettings.getProperty(Preferences.IN_USE_FOR_THIS_JOB);
+ if (!Boolean.valueOf(isEnabled)) {
+ //the job does not want our plug-in to be executed, d'oh
+ throw new EncoderPluginException("We are not enabled to do anything for this job :-(");
+ //of course in a real implementation, instead of throwing an exception we'd just "return;"
+ }
+
+ /*
+ * Now we can start doing the work. What you'll normally do is to construct a big string that you then have executed
+ * Have a look at the VirtualDub plug-in implementation to see how I did it.
+ *
+ * IMPORTANT: unless you parse the output of the console when executing a shell command (to check whether
+ * the encoder threw error messages at you), it is recommended that you create a log file of each job.
+ * The VirtualDub plug-in also provides an example of how to do that.
+ *
+ * Also notice the use of the EncoderPluginException. Whenever something goes wrong, throw this exception.
+ * Note that there is also another constructor EncoderPluginException(String message, Throwable t) where you
+ * can attach the original exception.
+ */
+ }
+
+
+
+}
Added: trunk/misc/tools/NexuizDemoRecorder/plugins/sample/src/main/resources/META-INF/services/com.nexuiz.demorecorder.application.plugins.EncoderPlugin
===================================================================
--- trunk/misc/tools/NexuizDemoRecorder/plugins/sample/src/main/resources/META-INF/services/com.nexuiz.demorecorder.application.plugins.EncoderPlugin (rev 0)
+++ trunk/misc/tools/NexuizDemoRecorder/plugins/sample/src/main/resources/META-INF/services/com.nexuiz.demorecorder.application.plugins.EncoderPlugin 2010-02-11 16:02:26 UTC (rev 8637)
@@ -0,0 +1 @@
+com.nexuiz.demorecorder.application.plugins.impl.sample.SamplePlugin
Added: trunk/misc/tools/NexuizDemoRecorder/plugins/virtualdub/pom.xml
===================================================================
--- trunk/misc/tools/NexuizDemoRecorder/plugins/virtualdub/pom.xml (rev 0)
+++ trunk/misc/tools/NexuizDemoRecorder/plugins/virtualdub/pom.xml 2010-02-11 16:02:26 UTC (rev 8637)
@@ -0,0 +1,38 @@
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>NexuizDemoRecorder</groupId>
+ <artifactId>VirtualDubPlugin</artifactId>
+ <packaging>jar</packaging>
+ <version>1.0</version>
+ <name>VirtualDubPlugin</name>
+ <url>http://maven.apache.org</url>
+ <dependencies>
+ <dependency>
+ <groupId>NexuizDemoRecorder</groupId>
+ <artifactId>NexuizDemoRecorder</artifactId>
+ <version>0.2</version>
+ <scope>provided</scope>
+ </dependency>
+ </dependencies>
+ <build>
+ <resources>
+ <resource>
+ <directory>src/main/resources</directory>
+ </resource>
+ </resources>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <version>2.0.2</version>
+ <configuration>
+ <source>1.6</source>
+ <target>1.6</target>
+ </configuration>
+ </plugin>
+
+
+ </plugins>
+ </build>
+</project>
Added: trunk/misc/tools/NexuizDemoRecorder/plugins/virtualdub/src/main/java/com/nexuiz/demorecorder/application/plugins/impl/virtualdub/VirtualDubPlugin.java
===================================================================
--- trunk/misc/tools/NexuizDemoRecorder/plugins/virtualdub/src/main/java/com/nexuiz/demorecorder/application/plugins/impl/virtualdub/VirtualDubPlugin.java (rev 0)
+++ trunk/misc/tools/NexuizDemoRecorder/plugins/virtualdub/src/main/java/com/nexuiz/demorecorder/application/plugins/impl/virtualdub/VirtualDubPlugin.java 2010-02-11 16:02:26 UTC (rev 8637)
@@ -0,0 +1,355 @@
+package com.nexuiz.demorecorder.application.plugins.impl.virtualdub;
+
+import java.io.BufferedReader;
+import java.io.BufferedWriter;
+import java.io.File;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Properties;
+
+import com.nexuiz.demorecorder.application.DemoRecorderApplication;
+import com.nexuiz.demorecorder.application.DemoRecorderException;
+import com.nexuiz.demorecorder.application.DemoRecorderUtils;
+import com.nexuiz.demorecorder.application.jobs.RecordJob;
+import com.nexuiz.demorecorder.application.plugins.EncoderPlugin;
+import com.nexuiz.demorecorder.application.plugins.EncoderPluginException;
+
+public class VirtualDubPlugin implements EncoderPlugin {
+
+ private static final String PLUGIN_NAME = "Virtual Dub";
+
+ private static class Preferences {
+ public static final String ENABLED = "Enabled";
+ public static final String VIRTUAL_DUB_BINARY_PATH = "Path to vdub.exe";
+ public static final String VCF_PER_JOB_LIMIT = "Max. number of VCFs per job";
+ public static final String OUTPUT_FILE_MODE = "Output as suffix (0) or file (1)";
+ public static final String EXTRA_OPTIONS = "Show extra options";
+
+ public static final String[] GLOBAL_PREFERENCES_ORDER = {
+ ENABLED,
+ VIRTUAL_DUB_BINARY_PATH,
+ VCF_PER_JOB_LIMIT,
+ OUTPUT_FILE_MODE,
+ EXTRA_OPTIONS
+ };
+
+ //job-specific preferences
+ public static final String CLEAR_JOBCONTROL = "Clear VDub job control on first VCF";
+ public static final String RENDER_OUTPUT = "VDub renders queued jobs";
+ public static final String VCF_PATH = "Path to VCF file "; //x will be attached, e.g. "Path to VCF file 1"
+ public static final String OUTPUT_SUFFIX = "Suffix for output file "; //x will be attached, e.g. "Suffix for output file 1"
+ public static final String OUTPUT_FILE = "Output file "; //x will be attached
+ public static final String USE_ENCODED_VIDEO = "<HTML><BODY>Use encoded video from VCF "; //x will be attached
+ public static final String USE_ENCODED_VIDEO_2 = "<BR>for consecutive VCFs</BODY></HTML>";
+ public static final String DELETE_ORIG_FILE = "Delete orig. file after processing VCF "; //x will be attached
+ }
+
+ private DemoRecorderApplication appLayer = null;
+ private Properties globalDefaultPreferences = new Properties();
+
+ public VirtualDubPlugin() {
+ this.createPreferenceDefaultValues();
+ }
+
+ @Override
+ public void executeEncoder(RecordJob job) throws EncoderPluginException {
+ this.checkAppLayer();
+ if (!this.isEnabled()) {
+ return;
+ }
+
+ if (job.getActualVideoDestination() == null) {
+ //should never happen... but just to make sure!
+ throw new EncoderPluginException("Actual video destination is not set (should have been set when processing the job)");
+ }
+
+ if (!job.getActualVideoDestination().exists()) {
+ throw new EncoderPluginException("Could not locate video file (source) at location "
+ + job.getActualVideoDestination().getAbsolutePath());
+ }
+
+ String limitStr = this.appLayer.getPreferences().getProperty(this.getName(), Preferences.VCF_PER_JOB_LIMIT);
+ int vcfCounter;
+ try {
+ vcfCounter = Integer.valueOf(limitStr);
+ } catch (NumberFormatException e) {
+ throw new EncoderPluginException("Invalid value \"" + limitStr + "\" for setting " + Preferences.VCF_PER_JOB_LIMIT);
+ }
+
+ //check vdub.exe
+ String vDubBinary = this.appLayer.getPreferences().getProperty(this.getName(), Preferences.VIRTUAL_DUB_BINARY_PATH);
+ File vDubBinaryFile = new File(vDubBinary);
+ if (!vDubBinaryFile.exists() || !vDubBinaryFile.canExecute()) {
+ throw new EncoderPluginException("Invalid location for the vdub.exe: " + vDubBinary);
+ }
+
+ this.doEncoding(job, vcfCounter);
+ }
+
+ @Override
+ public Properties getGlobalPreferences() {
+ return this.globalDefaultPreferences;
+ }
+
+ @Override
+ public String[] getGlobalPreferencesOrder() {
+ return Preferences.GLOBAL_PREFERENCES_ORDER;
+ }
+
+ @Override
+ public Properties getJobSpecificPreferences() {
+ this.checkAppLayer();
+ Properties jobSpecificPreferences = new Properties();
+
+ //static properties
+ jobSpecificPreferences.setProperty(Preferences.CLEAR_JOBCONTROL, "true");
+ jobSpecificPreferences.setProperty(Preferences.RENDER_OUTPUT, "true");
+
+ //dynamic properties
+ String limitStr = this.appLayer.getPreferences().getProperty(this.getName(), Preferences.VCF_PER_JOB_LIMIT);
+ try {
+ int limit = Integer.valueOf(limitStr);
+ if (limit > 0) {
+ for (int i = 1; i <= limit; i++) {
+ jobSpecificPreferences.setProperty(Preferences.VCF_PATH + i, "filechooser");
+ if (Boolean.valueOf(this.appLayer.getPreferences().getProperty(this.getName(), Preferences.OUTPUT_FILE_MODE))) {
+ //filechooser
+ jobSpecificPreferences.setProperty(Preferences.OUTPUT_FILE + i, "filechooser");
+ } else {
+ //suffix
+ jobSpecificPreferences.setProperty(Preferences.OUTPUT_SUFFIX + i, "_vdub" + i);
+ }
+
+ if (Boolean.valueOf(this.appLayer.getPreferences().getProperty(this.getName(), Preferences.EXTRA_OPTIONS))) {
+ String useEncStringKey = Preferences.USE_ENCODED_VIDEO + i + Preferences.USE_ENCODED_VIDEO_2;
+ jobSpecificPreferences.setProperty(useEncStringKey, "false");
+ jobSpecificPreferences.setProperty(Preferences.DELETE_ORIG_FILE + i, "false");
+ }
+ }
+ }
+ } catch (NumberFormatException e) {
+ throw new DemoRecorderException("Invalid value \"" + limitStr + "\" for setting " + Preferences.VCF_PER_JOB_LIMIT);
+ }
+
+ return jobSpecificPreferences;
+ }
+
+ @Override
+ public String[] getJobSpecificPreferencesOrder() {
+ this.checkAppLayer();
+ List<String> preferencesOrderList = new ArrayList<String>();
+
+ //static properties
+ preferencesOrderList.add(Preferences.CLEAR_JOBCONTROL);
+ preferencesOrderList.add(Preferences.RENDER_OUTPUT);
+
+ //dynamic properties
+ String limitStr = this.appLayer.getPreferences().getProperty(this.getName(), Preferences.VCF_PER_JOB_LIMIT);
+ try {
+ int limit = Integer.valueOf(limitStr);
+ if (limit > 0) {
+ for (int i = 1; i <= limit; i++) {
+ preferencesOrderList.add(Preferences.VCF_PATH + i);
+ if (Boolean.valueOf(this.appLayer.getPreferences().getProperty(this.getName(), Preferences.OUTPUT_FILE_MODE))) {
+ //filechooser
+ preferencesOrderList.add(Preferences.OUTPUT_FILE + i);
+ } else {
+ //suffix
+ preferencesOrderList.add(Preferences.OUTPUT_SUFFIX + i);
+ }
+
+ if (Boolean.valueOf(this.appLayer.getPreferences().getProperty(this.getName(), Preferences.EXTRA_OPTIONS))) {
+ String useEncStringKey = Preferences.USE_ENCODED_VIDEO + i + Preferences.USE_ENCODED_VIDEO_2;
+ preferencesOrderList.add(useEncStringKey);
+ preferencesOrderList.add(Preferences.DELETE_ORIG_FILE + i);
+ }
+ }
+ }
+ } catch (NumberFormatException e) {
+ throw new DemoRecorderException("Invalid value \"" + limitStr + "\" for setting " + Preferences.VCF_PER_JOB_LIMIT);
+ }
+
+ Object[] arr = preferencesOrderList.toArray();
+ String[] stringArr = new String[arr.length];
+ for (int i = 0; i < arr.length; i++) {
+ stringArr[i] = (String) arr[i];
+ }
+
+ return stringArr;
+ }
+
+ @Override
+ public String getName() {
+ return PLUGIN_NAME;
+ }
+
+ @Override
+ public boolean isEnabled() {
+ this.checkAppLayer();
+ String enabledString = this.appLayer.getPreferences().getProperty(this.getName(), Preferences.ENABLED);
+ return Boolean.valueOf(enabledString);
+ }
+
+ @Override
+ public void setApplicationLayer(DemoRecorderApplication appLayer) {
+ this.appLayer = appLayer;
+ }
+
+ private void checkAppLayer() {
+ if (this.appLayer == null) {
+ throw new DemoRecorderException("Error in plugin " + PLUGIN_NAME + "! Application layer not set!");
+ }
+ }
+
+ private void createPreferenceDefaultValues() {
+ this.globalDefaultPreferences.setProperty(Preferences.ENABLED, "false");
+ this.globalDefaultPreferences.setProperty(Preferences.VIRTUAL_DUB_BINARY_PATH, "filechooser");
+ this.globalDefaultPreferences.setProperty(Preferences.VCF_PER_JOB_LIMIT, "1");
+ this.globalDefaultPreferences.setProperty(Preferences.OUTPUT_FILE_MODE, "false");
+ this.globalDefaultPreferences.setProperty(Preferences.EXTRA_OPTIONS, "false");
+ }
+
+ private void doEncoding(RecordJob job, int vcfCounter) throws EncoderPluginException {
+ boolean firstValidVCF = true;
+ for (int i = 1; i <= vcfCounter; i++) {
+ Properties jobSpecificSettings = job.getEncoderPluginSettings(this);
+ String path = jobSpecificSettings.getProperty(Preferences.VCF_PATH + i);
+ if (path != null) {
+ File vcfFile = new File(path);
+ if (vcfFile.exists()) {
+ if (Boolean.valueOf(this.appLayer.getPreferences().getProperty(this.getName(), Preferences.OUTPUT_FILE_MODE))) {
+ //filechooser
+ String outputPath = jobSpecificSettings.getProperty(Preferences.OUTPUT_FILE + i, "filechooser");
+ if (outputPath == null || outputPath.equals("") || outputPath.equals("filechoose")) {
+ //user has not yet selected a file
+ continue;
+ }
+ } else {
+ //suffix
+ String suffix = jobSpecificSettings.getProperty(Preferences.OUTPUT_SUFFIX + i);
+ if (suffix == null || suffix.equals("")) {
+ continue;
+ }
+ }
+ BufferedWriter logWriter = this.getLogWriter(job.getJobName(), i);
+ this.executeVDub(job, i, firstValidVCF, logWriter);
+ firstValidVCF = false;
+ }
+ }
+ }
+ }
+
+ private void executeVDub(RecordJob job, int index, boolean firstValidVCF, BufferedWriter logWriter) throws EncoderPluginException {
+ String shellString = "";
+ Properties jobSpecificSettings = job.getEncoderPluginSettings(this);
+ File vcfFile = new File(jobSpecificSettings.getProperty(Preferences.VCF_PATH + index));
+ File sourceFile = job.getActualVideoDestination();
+
+ String vDubBinary = this.appLayer.getPreferences().getProperty(this.getName(), Preferences.VIRTUAL_DUB_BINARY_PATH);
+ shellString += '"' + vDubBinary.trim() + '"';
+
+ shellString += " /s " + '"' + vcfFile.getAbsolutePath() + '"';
+
+ boolean clearJobControl = Boolean.valueOf(jobSpecificSettings.getProperty(Preferences.CLEAR_JOBCONTROL, "true"));
+ if (clearJobControl && firstValidVCF) {
+ shellString += " /c";
+ }
+
+ String outputFilePath = this.getOutputFilePath(job, index);
+ File outputFile = new File(outputFilePath);
+ shellString += " /p " + '"' + sourceFile.getAbsolutePath() + '"';
+ shellString += " " + '"' + outputFilePath + '"';
+
+ boolean renderOutput = Boolean.valueOf(jobSpecificSettings.getProperty(Preferences.RENDER_OUTPUT, "true"));
+ if (renderOutput) {
+ shellString += " /r";
+ }
+
+ shellString += " /x";
+
+ try {
+ logWriter.write("Executing commandline: " + shellString);
+ logWriter.newLine();
+ File vdubDir = new File(vDubBinary).getParentFile();
+ Process vDubProc;
+ vDubProc = Runtime.getRuntime().exec(shellString, null, vdubDir);
+ vDubProc.getOutputStream();
+ InputStreamReader isr = new InputStreamReader(vDubProc.getInputStream());
+ BufferedReader bufferedInputStream = new BufferedReader(isr);
+ String currentLine;
+ while ((currentLine = bufferedInputStream.readLine()) != null) {
+ logWriter.write(currentLine);
+ logWriter.newLine();
+ }
+ InputStreamReader isrErr = new InputStreamReader(vDubProc.getErrorStream());
+ BufferedReader bufferedInputStreamErr = new BufferedReader(isrErr);
+ while ((currentLine = bufferedInputStreamErr.readLine()) != null) {
+ logWriter.write(currentLine);
+ logWriter.newLine();
+ }
+ logWriter.close();
+
+ } catch (IOException e) {
+ throw new EncoderPluginException("I/O Exception occurred when trying to execute the VDub binary or logging output", e);
+ }
+
+ //extra options: replace original video with encoded one, possibly delete original one
+ if (Boolean.valueOf(this.appLayer.getPreferences().getProperty(this.getName(), Preferences.EXTRA_OPTIONS))) {
+ String useEncStringKey = Preferences.USE_ENCODED_VIDEO + index + Preferences.USE_ENCODED_VIDEO_2;
+ String useEncVideo = jobSpecificSettings.getProperty(useEncStringKey);
+ File origFile = job.getActualVideoDestination();
+ if (useEncVideo != null && Boolean.valueOf(useEncVideo)) {
+ job.setActualVideoDestination(outputFile);
+ }
+
+ String deleteOrigFile = jobSpecificSettings.getProperty(Preferences.DELETE_ORIG_FILE + index);
+ if (deleteOrigFile != null && Boolean.valueOf(deleteOrigFile)) {
+ //only delete the original file if the encoded one exists:
+ if (outputFile.exists() && outputFile.length() > 0) {
+ origFile.delete();
+ }
+ }
+ }
+ }
+
+ private String getOutputFilePath(RecordJob job, int index) {
+ File sourceFile = job.getActualVideoDestination();
+ String ext = DemoRecorderUtils.getFileExtension(sourceFile);
+ String outputFilePath;
+ Properties jobSpecificSettings = job.getEncoderPluginSettings(this);
+ if (Boolean.valueOf(this.appLayer.getPreferences().getProperty(this.getName(), Preferences.OUTPUT_FILE_MODE))) {
+ //filechooser
+ outputFilePath = jobSpecificSettings.getProperty(Preferences.OUTPUT_FILE + index);
+ } else {
+ //suffix
+ outputFilePath = sourceFile.getAbsolutePath();
+ String suffix = jobSpecificSettings.getProperty(Preferences.OUTPUT_SUFFIX + index);
+ int idx = outputFilePath.indexOf("." + ext);
+ outputFilePath = outputFilePath.substring(0, idx);
+ outputFilePath += suffix + "." + ext;
+ }
+
+ return outputFilePath;
+ }
+
+ private BufferedWriter getLogWriter(String jobName, int vcfIndex) throws EncoderPluginException {
+ File logDir = DemoRecorderUtils.computeLocalFile(DemoRecorderApplication.LOGS_DIRNAME, "");
+ if (jobName == null || jobName.equals("")) {
+ jobName = "unnamed_job";
+ }
+ String path = logDir.getAbsolutePath() + File.separator + PLUGIN_NAME + '_' + jobName + '_' + "vcf" + vcfIndex + ".log";
+ File logFile = new File(path);
+ if (!DemoRecorderUtils.attemptFileCreation(logFile)) {
+ throw new EncoderPluginException("Could not create log file for VDub job at location: " + path);
+ }
+ try {
+ FileWriter fileWriter = new FileWriter(logFile);
+ return new BufferedWriter(fileWriter);
+ } catch (IOException e) {
+ throw new EncoderPluginException("Could not create log file for VDub job at location: " + path, e);
+ }
+ }
+}
Added: trunk/misc/tools/NexuizDemoRecorder/plugins/virtualdub/src/main/resources/META-INF/services/com.nexuiz.demorecorder.application.plugins.EncoderPlugin
===================================================================
--- trunk/misc/tools/NexuizDemoRecorder/plugins/virtualdub/src/main/resources/META-INF/services/com.nexuiz.demorecorder.application.plugins.EncoderPlugin (rev 0)
+++ trunk/misc/tools/NexuizDemoRecorder/plugins/virtualdub/src/main/resources/META-INF/services/com.nexuiz.demorecorder.application.plugins.EncoderPlugin 2010-02-11 16:02:26 UTC (rev 8637)
@@ -0,0 +1 @@
+com.nexuiz.demorecorder.application.plugins.impl.virtualdub.VirtualDubPlugin
Deleted: trunk/misc/tools/NexuizDemoRecorder/pom.xml
===================================================================
--- trunk/misc/tools/NexuizDemoRecorder/pom.xml 2010-02-11 15:59:48 UTC (rev 8636)
+++ trunk/misc/tools/NexuizDemoRecorder/pom.xml 2010-02-11 16:02:26 UTC (rev 8637)
@@ -1,83 +0,0 @@
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
- <modelVersion>4.0.0</modelVersion>
- <groupId>NexuizDemoRecorder</groupId>
- <artifactId>NexuizDemoRecorder</artifactId>
- <packaging>jar</packaging>
- <version>0.2</version>
- <name>NexuizDemoRecorder</name>
- <url>http://maven.apache.org</url>
- <dependencies>
- <dependency>
- <groupId>com.miglayout</groupId>
- <artifactId>miglayout</artifactId>
- <version>3.7.2</version>
- </dependency>
- <dependency>
- <groupId>org.swinglabs</groupId>
- <artifactId>swingx</artifactId>
- <version>1.6</version>
- <exclusions>
- <!-- Exclude unneeded libs that have been transitively resolved for SwingX -->
- <exclusion>
- <groupId>org.swinglabs</groupId>
- <artifactId>swing-worker</artifactId>
- </exclusion>
- <exclusion>
- <groupId>com.jhlabs</groupId>
- <artifactId>filters</artifactId>
- </exclusion>
- </exclusions>
- </dependency>
- <dependency>
- <groupId>javax.help</groupId>
- <artifactId>javahelp</artifactId>
- <version>2.0.02</version>
- </dependency>
- </dependencies>
- <build>
- <resources>
- <resource>
- <directory>src/main/resources</directory>
- </resource>
- </resources>
- <plugins>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-compiler-plugin</artifactId>
- <version>2.0.2</version>
- <configuration>
- <source>1.6</source>
- <target>1.6</target>
- </configuration>
- </plugin>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-jar-plugin</artifactId>
- <configuration>
- <archive>
- <manifest>
- <addClasspath>true</addClasspath>
- <classpathPrefix>lib/</classpathPrefix>
- <mainClass>com.nexuiz.demorecorder.main.Driver</mainClass>
- </manifest>
- </archive>
- </configuration>
- </plugin>
- <plugin>
- <artifactId>maven-dependency-plugin</artifactId>
- <executions>
- <execution>
- <phase>package</phase>
- <goals>
- <goal>copy-dependencies</goal>
- </goals>
- <configuration>
- <outputDirectory>${project.build.directory}/lib</outputDirectory>
- </configuration>
- </execution>
- </executions>
- </plugin>
- </plugins>
- </build>
-</project>
More information about the nexuiz-commits
mailing list