--- /dev/null
+/nbproject/private/
+/bin/
+/build/
+/dist/
+
--- /dev/null
+
+dist_VERSION=3.99
+dist_NAME=jjmpeg
+dist_EXTRA=README \
+ build.xml \
+ nbproject/build-impl.xml \
+ nbproject/genfiles.properties \
+ nbproject/project.properties \
+ nbproject/project.xml
+
+include config.make
+
+java_MODULES=notzed.jjmpeg notzed.jjmpeg.fx notzed.jjmpeg.awt notzed.jjmpeg.demo
+
+notzed.jjmpeg.awt_JDEPMOD=notzed.jjmpeg
+notzed.jjmpeg.fx_JDEPMOD=notzed.jjmpeg
+notzed.jjmpeg.demo_JDEPMOD=notzed.jjmpeg notzed.jjmpeg.awt notzed.jjmpeg.fx
+
+include java.make
--- /dev/null
+
+Copyright (C) 2017-2019 Michael Zucchi
+
+See the section LICENSE for details.
+
+Introduction
+------------
+
+jjmpeg is a JNI based Java binding for the suite of libraries provided
+by FFmpeg.
+
+The original version of jjmpeg was released sometime in the distant
+past and has slowly got further and further behind the current FFmpeg
+version. This is a completely new implementation intended as a
+project to catch up with the current API.
+
+Compile
+-------
+
+jdk (javac, jar) and native compiler tools (GNU make, cc, cpp, perl)
+must be in path. In addition the program cproto must be installed.
+JDK 11 is required (JDK 9+ may work?).
+
+The prequisitve project notzed.nativez must also have previously been
+compiled and will be automatically used if it is present in the
+directory above this one (../nativez/).
+
+See config.make for configuration parameters.
+
+Build everything for default target of linux-amd64:
+
+$ make
+
+Build everything for a specific target:
+
+$ make TARGET=<target>
+
+All intermediate and final results are place in `bin/'.
+
+`bin/<module>/<module>.jar' Cross platform modular .jar.
+`bin/<module>/<target>/lib' Platform specific libraries.
+
+`bin/<module>/<target>/<module>.jmod' Target specific .jmod.
+
+$ make bin
+
+Build everything but the jars and jmods.
+
+$ make dist
+
+Create a source archive. The source is found via $(find) so
+this will include any droppings.
+
+NetBeans
+--------
+
+Before the source can be easily edited in NetBeans one must
+first run the makefile to generate any auto-generated files.
+
+$ make gen
+
+This needs to be done each time `make clean' is executed or
+files in `src/notzed.jjmpeg/gen' are edited.
+
+Development
+-----------
+
+Some notes on internals.
+
+Java Native Interface
+- - - - - - - - - - -
+
+All jj-*.c files are independent of one another, they may only
+reference functions and variables from jjmpeg.c.
+
+The native interface is implemented using the notzed.nativez project.
+This allows it to support full garbage collection of all relevant
+objects. In some cases this currently requires references to be
+manually kept to ensure they survive for the relevant C side objects.
+All objects are unique (and keyed) based on their C pointer address.
+
+If used with care, objects can also be manually released safely.
+
+Unlike earlier versions of jjmpeg, version 3+ is implemented almost
+entirely using hand-rolled Java and macro-assisted C source-code.
+Also unlike earlier versions almost all code is written directly in C
+with only skeleton Java wrappers of native method signatures. This
+requires less work and produces smaller code than previous versions.
+
+To further reduce code-size most initialisation is implemented via
+tables.
+
+Enumerations
+- - - - - -
+
+A set of small(ish) perl scripts are used to extract various
+enumeration and #define tables directly from the FFmpeg development
+header files. They generate interfaces which are "implemented" to add
+the defines to the desired structures. These reside in the scripts
+directory.
+
+All enumerations were converted to final integer values for
+consistency. Where the corresponding functions exist, static
+valueOf() and toString() are available for obvious purposes.
+
+The perl scripts generate C code which is then compiled and executed
+to create the Java interfaces.
+
+Exceptions
+- - - - -
+
+Exceptions fall into two categories, AVIOException and AVException,
+both checked exceptions. The former derives from IOException for
+simplicity.
+
+They contain the error code (errno and AVERROR defines) and a
+description.
+
+Where it makes sense other Java checked and unchecked exceptions such
+as FileNotFoundException or OutOfMemoryError are also thrown.
+
+Linkage
+- - - -
+
+All libraries are dynamically linked at runtime. Missing functions
+result in an initialisation failure.
+
+Method signatures are automatically extracted from headers via the
+script src/notzed.jjmpeg/jni/extract-proto.pl based on per-file .def
+files. This also generates a table for initialising the pointers.
+
+Build System
+- - - - - -
+
+See java.make. It's a lot simpler than it looks and is based on
+meta-make programming via macros and pattern variables.
+
+Documentation
+- - - - - - -
+
+Very lacking, but at least most of the enumerations now have the
+comments present in the header files.
+
+Status
+------
+
+Enough core classes to read and write video frames is implemented as
+well as a pair of high-level interfaces JJMediaReader and
+JJMediaWriter. These have been simplified somewhat from the previous
+implementation, but it takes less code to use them anyway.
+
+Most functions that should throw exceptions do although that which
+they throw may be tweaked.
+
+Many accessors have been implemented, in some cases they have been
+Javaised or NotZedised (e.g. setFlags(mask, value)) for a cleaner
+interface. Because of the complexity of the libraries and objects it
+is not always clear which members need to be accessed by user code so
+some of the choices are arbitrary. Or I just gave up part way
+through. They are easy to add.
+
+There are two sub-modules notzed.jjmpeg.fx and notzed.jjmpeg.awt which
+supply the JavaFX and Swing/AWT specific functionality.
+
+See also TODO.
+
+Compatibility
+-------------
+
+This version is compatible with at least version 4.0 of FFmpeg.
+
+No deprecated functions or fields have been made accessible from Java
+or are used in the native code.
+
+Links
+-----
+
+* nativez <https://www.zedzone.space/software/nativez.html>
+* jjmpeg <https://www.zedzone.space/software/jjmpeg.html>
+* FFmpeg <http://www.ffmpeg.org/>
+* OpenJDK <http://openjdk.java.net/>
+
+LICENSE
+-------
+
+Most of the code is licensed under GNU General Public License version
+3, see src/<module>/legal/LICENSE for the full details for each module.
+
+ Copyright (C) 2017-2019 Michael Zucchi
+
+ This program is free software: you can redistribute it and/or
+ modify it under the terms of the GNU General Public License as
+ published by the Free Software Foundation, either version 3 of the
+ License, or (at your option) any later version.
+
+ This program 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
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see
+ <http://www.gnu.org/licenses/>.
+
+Portions are auto-generated from FFmpeg header files and are thus
+copyright various authors but are also distributed under the GNU
+General Public License Version 3 (or later) as per the copyright
+header permissions.
+
+These portions are clearly marked in the bin/gen/*Bits.java files.
--- /dev/null
+
+* AVSampleWriter for audio
+* Improve Exception design.
+* Documentation
+* JNI stuff like exception checks are very under-done.
+* Simplify jni .def file for Java
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- You may freely edit this file. See commented blocks below for -->
+<!-- some examples of how to customize the build. -->
+<!-- (If you delete it and reopen the project it will be recreated.) -->
+<!-- By default, only the Clean and Build commands use this build script. -->
+<!-- Commands such as Run, Debug, and Test only use this build script if -->
+<!-- the Compile on Save feature is turned off for the project. -->
+<!-- You can turn off the Compile on Save (or Deploy on Save) setting -->
+<!-- in the project's Project Properties dialog box.-->
+<project name="notzed.jjmpeg" default="default" basedir="." xmlns:j2semodularproject="http://www.netbeans.org/ns/j2se-modular-project/1">
+ <description>Builds, tests, and runs the project notzed.jjmpeg.</description>
+ <import file="nbproject/build-impl.xml"/>
+ <!--
+
+ There exist several targets which are by default empty and which can be
+ used for execution of your tasks. These targets are usually executed
+ before and after some main targets. They are:
+
+ -pre-init: called before initialization of project properties
+ -post-init: called after initialization of project properties
+ -pre-compile: called before javac compilation
+ -post-compile: called after javac compilation
+ -pre-compile-single: called before javac compilation of single file
+ -post-compile-single: called after javac compilation of single file
+ -pre-compile-test: called before javac compilation of JUnit tests
+ -post-compile-test: called after javac compilation of JUnit tests
+ -pre-compile-test-single: called before javac compilation of single JUnit test
+ -post-compile-test-single: called after javac compilation of single JUunit test
+ -pre-jar: called before JAR building
+ -post-jar: called after JAR building
+ -post-clean: called after cleaning build products
+
+ (Targets beginning with '-' are not intended to be called on their own.)
+
+ Example of inserting an obfuscator after compilation could look like this:
+
+ <target name="-post-compile">
+ <obfuscate>
+ <fileset dir="${build.classes.dir}"/>
+ </obfuscate>
+ </target>
+
+ For list of available properties check the imported
+ nbproject/build-impl.xml file.
+
+
+ Another way to customize the build is by overriding existing main targets.
+ The targets of interest are:
+
+ -init-macrodef-javac: defines macro for javac compilation
+ -init-macrodef-junit: defines macro for junit execution
+ -init-macrodef-debug: defines macro for class debugging
+ -init-macrodef-java: defines macro for class execution
+ -do-jar: JAR building
+ run: execution of project
+ -javadoc-build: Javadoc generation
+ test-report: JUnit report generation
+
+ Notice that the overridden target depends on the jar target and not only on
+ the compile target as the regular run target does. Again, for a list of available
+ properties which you can use, check the target you are overriding in the
+ nbproject/build-impl.xml file.
+
+ -->
+</project>
--- /dev/null
+
+TARGET ?= linux-amd64
+
+JAVA_HOME ?= /usr/local/jdk-11.0.2
+JAVAFX_HOME ?= /usr/local/javafx-sdk-11.0.2
+FFMPEG_HOME ?= /opt/ffmpeg/4.0
+
+# See also JAVACFLAGS
+NATIVEZ_HOME=../nativez/bin/notzed.nativez/$(TARGET)
+
+JAVACFLAGS += --module-path $(JAVAFX_HOME)/lib:../nativez/bin/notzed.nativez
+JAVACFLAGS += -source 11
+
+JAVAC ?= javac
+JAR ?= jar
+JMOD ?= jmod
+
+# Linux options
+linux-amd64_CPPFLAGS = \
+ -I$(JAVA_HOME)/include -I$(JAVA_HOME)/include/linux
+linux-amd64_CFLAGS = -fPIC -Wall -Os
+linux-amd64_CC = cc
+linux-amd64_LD = ld
+
+linux-amd64_SO = .so
+linux-amd64_LIB = lib
+linux-amd64_JMOD_LIBS = --libs
+
+# Windows options
+windows-amd64_CPPFLAGS= \
+ -I$(JAVA_HOME)/include -I$(JAVA_HOME)/include/linux \
+ -DHAVE_ALIGNED_MALLOC \
+ -DWIN32
+windows-amd64_CC = x86_64-w64-mingw32-gcc
+windows-amd64_LD = x86_64-w64-mingw32-ld
+windows-amd64_LDFLAGS = -Wl,--subsystem,windows
+
+windows-amd64_SO = .dll
+windows-amd64_LIB =
+windows-amd64_JMOD_LIBS = --cmds
--- /dev/null
+#
+# Copyright (C) 2019 Michael Zucchi
+#
+# This is the copyright for java.make
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program 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 General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+#
+
+# General purpose modular java makefile that supports native library
+# compilation directly. Non-recrusve implementation.
+#
+# Uses metamake programming with some file conventions to implement
+# auto-make-like features.
+
+# Define modules
+# --------------
+# java_MODULES list of java modules to compile. The sources must
+# exist in src/<module>/classes. Resource files are
+# stored in src/<module>/classes. Source-code
+# generators must exist in src/<module>/gen. Native
+# libraries must exist in src/<module>/jni.
+
+# Global variables
+
+# JAVA_HOME location of jdk.
+# JAVAC java compiler to use. Default is 'javac' on the path.
+# JAVACFLAGS javac flags applied to all invocations.
+# JAR jar command.
+# JARFLAGS jar flags
+# JMOD jmod command.
+# JMODFLAGS jmod flags.
+
+# Module specific variables
+
+# <module>_JDEPMOD Lists modules which this one depends on.
+
+# <module>_JAVACFLAGS Extra module-specific flags for each command.
+# <module>_JARFLAGS
+# <module>_JMODFLAGS
+
+# <module>_JAVA Java sources. If not set it is found from src/<module>/classes/(*.java)
+# <module>_RESOURCES .jar resources. If not set it is found from src/<module>/classes/(not *.java)
+# <module>_JAVA_GENERATED Java generated sources. These must be relative to the package name.
+
+# Variables for use in fragments
+
+# gen.make and jni.make can additionally make use of these variables
+
+# <module>_gendir Location for files used in Java generation process (per project).
+# <module>_genjavadir Location where _JAVA_GENERATED .java files will be created (per project).
+# <module>_jnidir Location for jni generated files (per target).
+# <module>_objdir Location for c objects (per target).
+# <module>_incdir Location for output includes, .jmod staging.
+# <module>_libdir Location for output libraries, .jmod staging.
+
+# Define libraries
+# ----------------
+
+# Each module can define one or more native libraries.
+
+# These are compiled after the java sources have been compiled as that
+# process also generates any native binding headers.
+
+# <module>_JNI_LIBRARIES list of libraries to build.
+# library names match System.loadLibrary().
+
+# Global variables
+
+# <target>_LDFLAGS
+# <target>_LDLIBS
+# <target>_CPPFLAGS
+# <target>_CFLAGS
+# SO shared library suffix
+# LIB shared library prefix
+
+# Utility functions
+#
+# $(call library-path,<module>,<libname>) will resolve to the library file name.
+
+# Per library variables.
+
+# <library>_SOURCES .c, .cc, .C - source files for library. Paths are relative to src/<module>/jni.
+# <library>_HEADERS header files for jmod
+
+# <library>_LDFLAGS link flags
+# <library>_LIBADD extra objects to add to link line
+# <library>_LDLIBS link libraries
+# <library>_CPPFLAGS c pre-processor flags. "-Isrc/<module>/jni -Ibin/include/<module>" is implicit.
+# <library>_CCFLAGS c compiler flags
+
+# <library>_DEPENDENCIES A list of other objects on which this library depends before linking.
+
+# .c files have dependencies automatically generated
+
+# Targets
+# -------
+
+# make gen only generate java sources
+# make clean rm -rf bin
+# make dist create dist tar in bin/
+# make | make jar make all jars and jmods
+# make bin make everything but jars and mods
+
+# Outputs
+# -------
+
+# All intermediate and output files are written to bin/
+
+# This layout is enforced by javac
+# bin/include/<module>/ .h files from javac -h
+# bin/modules/<module>/ .class files from javac
+
+# This layout is convenient for netbeans
+# bin/gen/<module>/gen/ .c, exe files for generator free use
+# bin/gen/<module>/classes/ .java files from generator <module>_JAVA_GENERATED
+
+# bin/status/ marker files for makefile
+
+# bin/<module>/<module>.jar .jar modular
+
+# Native code
+
+# bin/<module>/<target>/lib .so librareies for jmod <module>_LIBRARIES = libname
+# bin/<module>/<target>/obj .o, .d files for library <libname>_SOURCES
+# bin/<module>/<target>/include .h files for jmod <libname>_HEADERS
+# bin/<module>/<target>/<module>.jmod .jmod module
+
+# ######################################################################
+
+E:=
+S:=$(E) $(E)
+
+# All modules with native code
+java_JMODS=$(foreach module,$(java_MODULES),$(if $(wildcard src/$(module)/jni/jni.make),$(module)))
+# Only modules with no native code
+java_JARS=$(foreach module,$(java_MODULES),$(if $(wildcard src/$(module)/jni/jni.make),,$(module)))
+# Modules with generated java source
+java_JGEN=$(foreach module,$(java_MODULES),$(if $(wildcard src/$(module)/gen/gen.make),$(module)))
+
+# Define some useful variables before including fragments
+define java_variables=
+$(1)_gendir:=bin/gen/$(1)/gen
+$(1)_genjavadir:=bin/gen/$(1)/classes
+$(1)_jnidir:=bin/$(1)/$(TARGET)/jni
+$(1)_objdir:=bin/$(1)/$(TARGET)/obj
+$(1)_incdir:=bin/$(1)/$(TARGET)/include
+$(1)_libdir:=bin/$(1)/$(TARGET)/lib
+ifndef $(1)_JAVA
+$(1)_JAVA := $$(shell find src/$(1)/classes -type f -name '*.java')
+endif
+ifndef $(1)_RESOURCES
+$(1)_RESOURCES := $$(shell find src/$(1)/classes -type f \! -name '*.java')
+endif
+endef
+
+$(foreach module,$(java_MODULES),$(eval $(call java_variables,$(module))))
+
+# ######################################################################
+
+all: jar
+bin:
+gen:
+
+.PHONY: all clean jar bin gen
+clean:
+ rm -rf bin
+
+include $(patsubst %,src/%/gen/gen.make,$(java_JGEN))
+include $(patsubst %,src/%/jni/jni.make,$(java_JMODS))
+
+# ######################################################################
+# Java
+# ######################################################################
+
+define java_targets=
+# Rules for module $(1)
+$(1)_JAVA_generated = $$(addprefix $$($(1)_genjavadir)/,$$($(1)_JAVA_GENERATED))
+
+bin/status/$(1).data: $$($(1)_RESOURCES)
+bin/status/$(1).classes: $(patsubst %,bin/status/%.classes,$($(1)_JDEPMOD)) $$($(1)_JAVA) $$($(1)_JAVA_generated)
+jar $(1): bin/$(1)/$(1).jar $(if $(wildcard src/$(1)/jni/jni.make),bin/$(1)/$(TARGET)/$(1).jmod)
+bin: bin/status/$(1).classes bin/status/$(1).data
+sources: bin/$(1)/$(1)-sources.zip
+gen: $$($(1)_JAVA_generated)
+
+# Create modular jar
+bin/$(1)/$(1).jar: bin/status/$(1).classes bin/status/$(1).data
+ @install -d $$(@D)
+ $(JAR) cf $$@ \
+ $(JARFLAGS) $$($(1)_JARFLAGS) \
+ -C bin/modules/$(1) .
+
+# Create a jmod
+bin/$(1)/$(TARGET)/$(1).jmod: bin/status/$(1).classes bin/status/$(1).data
+ rm -f $$@
+ @install -d $$(@D)
+ $$(JMOD) create \
+ $$(JMODFLAGS) $$($(1)_JMODFLAGS) \
+ --target-platform $(TARGET) \
+ --class-path bin/modules/$(1) \
+ $$(if $$(wildcard bin/$(1)/$(TARGET)/include),--header-files bin/$(1)/$(TARGET)/include) \
+ $$(if $$(wildcard src/$(1)/legal),--legal-notices src/$(1)/legal) \
+ $$($(TARGET)_JMOD_LIBS) bin/$(1)/$(TARGET)/lib \
+ $$@
+
+# Create an IDE source zip, paths have to match --module-source-path
+bin/$(1)/$(1)-sources.zip: bin/status/$(1).classes
+ @install -d $$(@D)
+ jar -c -f $$@ -M \
+ $$(patsubst src/$(1)/classes/%,-C src/$(1)/classes %,$$(filter src/$(1)/classes/%,$$($(1)_JAVA))) \
+ $$(patsubst bin/gen/$(1)/classes/%,-C bin/gen/$(1)/classes %,$$(filter bin/gen/$(1)/classes/%,$$($(1)_JAVA)))
+
+endef
+
+#$(foreach module,$(java_MODULES),$(info $(call java_targets,$(module))))
+$(foreach module,$(java_MODULES),$(eval $(call java_targets,$(module))))
+
+# ######################################################################
+# Global pattern rules
+
+# Stage resources
+bin/status/%.data:
+ @install -d $(@D)
+ for data in $(patsubst src/$*/classes/%,"%",$($*_RESOURCES)) ; do \
+ install -vDC "src/$*/classes/$$data" "bin/modules/$*/$$data" || exit 1 ; \
+ done
+ touch $@
+
+# Compile one module. This only updates (javac -h) headers if they changed.
+bin/status/%.classes:
+ @install -d $(@D)
+ $(JAVAC) \
+ --module-source-path "src/*/classes:bin/gen/*/classes" \
+ $(JAVACFLAGS) $($*_JAVACFLAGS) \
+ -h bin/inc \
+ -d bin/modules \
+ -m $* \
+ $($*_JAVA) $($*_JAVA_generated)
+ if [ -d bin/inc/$* ] ; then \
+ install -DC -t bin/include/$* bin/inc/$*/*.h ; \
+ fi
+ touch $@
+
+# ######################################################################
+# C stuff
+# ######################################################################
+
+SUFFIXES=.c .C .cc
+SO=$($(TARGET)_SO)
+LIB=$($(TARGET)_LIB)
+
+# functions to find cross-module stuff $(call library-path,modname,libname)
+library-path=bin/$(1)/$(TARGET)/lib/$(LIB)$(2)$(SO)
+library-dir=bin/$(1)/$(TARGET)/lib/
+
+define jni_library=
+# Rule for library $(2) in module $(1)
+$(2)_OBJS = $(foreach sx,$(SUFFIXES),$(patsubst %$(sx), $($(1)_objdir)/%.o, $(filter %$(sx),$($(2)_SOURCES))))
+$(2)_SRCS = $(addprefix src/$(1)/jni/,$($(2)_SOURCES))
+
+$($(1)_libdir)/$(LIB)$(2)$(SO): $$($(2)_OBJS) $($(2)_LIBADD) $($(2)_DEPENDENCIES)
+ @install -d $$(@D)
+ $($(TARGET)_CC) -o $$@ -shared \
+ $($(TARGET)_LDFLAGS) $($(2)_LDFLAGS) $$($(2)_OBJS) $($(2)_LIBADD) $($(TARGET)_LDLIBS) $($(2)_LDLIBS)
+
+$($(1)_objdir)/%.o: src/$(1)/jni/%.c bin/status/$(1).classes
+ @install -d $$(@D)
+ $($(TARGET)_CC) -Isrc/$(1)/jni -Ibin/include/$(1) $($(TARGET)_CPPFLAGS) $($(2)_CPPFLAGS) \
+ $($(TARGET)_CFLAGS) $($(2)_CFLAGS) -c -o $$@ $$<
+
+$($(1)_incdir)/%.h: src/$(1)/jni/%.h
+ install -D $$< $$@
+
+$($(1)_objdir)/%.d: src/$(1)/jni/%.c bin/status/$(1).classes
+ @install -d $$(@D)
+ @rm -f $$@
+ @$($(TARGET)_CC) -MM -MT "bin/$(1)/$(TARGET)/obj/$$*.o" -Isrc/$(1)/jni -Ibin/include/$(1) \
+ $($(TARGET)_CPPFLAGS) $($(2)_CPPFLAGS) $$< -o $$@.d 2>/dev/null
+ @sed 's,\($$*\.o\) *:,\1 $$@ : ,g' $$@.d > $$@ ; rm $$@.d
+
+bin jni $(1) bin/$(1)/$(TARGET)/$(1).jmod: $($(1)_libdir)/$(LIB)$(2)$(SO) $(addprefix $($(1)_incdir)/,$($(2)_HEADERS))
+
+$(if $(filter clean dist gen,$(MAKECMDGOALS)),,-include $$($(2)_OBJS:.o=.d))
+endef
+
+#$(foreach module,$(java_JMODS),$(foreach library,$($(module)_JNI_LIBRARIES),$(info $(call jni_library,$(module),$(library)))))
+$(foreach module,$(java_JMODS),$(foreach library,$($(module)_JNI_LIBRARIES),$(eval $(call jni_library,$(module),$(library)))))
+
+# ######################################################################
+
+dist:
+ @install -d bin
+ tar cfz bin/$(dist_NAME)-$(dist_VERSION).tar.gz \
+ --transform=s,^,$(dist_NAME)-$(dist_VERSION)/, \
+ config.make java.make Makefile src \
+ $(dist_EXTRA)
+
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+*** GENERATED FROM project.xml - DO NOT EDIT ***
+*** EDIT ../build.xml INSTEAD ***
+
+For the purpose of easier reading the script
+is divided into following sections:
+
+ - initialization
+ - compilation
+ - jar
+ - execution
+ - debugging
+ - javadoc
+ - test compilation
+ - test execution
+ - test debugging
+ - applet
+ - cleanup
+
+ -->
+<project xmlns:if="ant:if" xmlns:unless="ant:unless" basedir=".." default="default" name="notzed.jjmpeg-impl">
+ <fail message="Please build using Ant 1.9.7 or higher.">
+ <condition>
+ <not>
+ <antversion atleast="1.9.7"/>
+ </not>
+ </condition>
+ </fail>
+ <target depends="test,jar,javadoc" description="Build and test whole project." name="default"/>
+ <!--
+ ======================
+ INITIALIZATION SECTION
+ ======================
+ -->
+ <target name="-pre-init">
+ <!-- Empty placeholder for easier customization. -->
+ <!-- You can override this target in the ../build.xml file. -->
+ </target>
+ <target depends="-pre-init" name="-init-private">
+ <property file="nbproject/private/config.properties"/>
+ <property file="nbproject/private/configs/${config}.properties"/>
+ <property file="nbproject/private/private.properties"/>
+ </target>
+ <target depends="-pre-init,-init-private" name="-init-user">
+ <property file="${user.properties.file}"/>
+ <!-- The two properties below are usually overridden -->
+ <!-- by the active platform. Just a fallback. -->
+ <property name="default.javac.source" value="9"/>
+ <property name="default.javac.target" value="9"/>
+ </target>
+ <target depends="-pre-init,-init-private,-init-user" name="-init-project">
+ <property file="nbproject/configs/${config}.properties"/>
+ <property file="nbproject/project.properties"/>
+ </target>
+ <target name="-init-source-module-properties">
+ <property name="javac.modulepath" value=""/>
+ <property name="run.modulepath" value="${javac.modulepath}:${build.modules.dir}"/>
+ <property name="debug.modulepath" value="${run.modulepath}"/>
+ <property name="javac.upgrademodulepath" value=""/>
+ <property name="run.upgrademodulepath" value="${javac.upgrademodulepath}"/>
+ <condition else="" property="javac.systemmodulepath.cmd.line.arg" value="-system '${javac.systemmodulepath}'">
+ <and>
+ <isset property="javac.systemmodulepath"/>
+ <length length="0" string="${javac.systemmodulepath}" when="greater"/>
+ </and>
+ </condition>
+ <property name="dist.jlink.dir" value="${dist.dir}/jlink"/>
+ <property name="dist.jlink.output" value="${dist.jlink.dir}/${application.title}"/>
+ </target>
+ <target depends="-pre-init,-init-private,-init-user,-init-project,-init-macrodef-property" name="-do-init">
+ <property name="platform.java" value="${java.home}/bin/java"/>
+ <j2semodularproject1:modsource_regexp xmlns:j2semodularproject1="http://www.netbeans.org/ns/j2se-modular-project/1" modsource="${test.src.dir.path}" property="have.tests.test.src.dir.regexp"/>
+ <dirset dir="${basedir}/${test.src.dir}" id="have.tests.test.src.dir.set" includes="*/*">
+ <filename regex="${have.tests.test.src.dir.regexp}"/>
+ </dirset>
+ <union id="have.tests.set">
+ <dirset refid="have.tests.test.src.dir.set"/>
+ </union>
+ <condition property="have.tests">
+ <or>
+ <resourcecount count="0" when="greater">
+ <union refid="have.tests.set"/>
+ </resourcecount>
+ </or>
+ </condition>
+ <j2semodularproject1:modsource_regexp xmlns:j2semodularproject1="http://www.netbeans.org/ns/j2se-modular-project/1" modsource="${test.src.dir.path}" property="have.tests.test.src.dir.regexp"/>
+ <dirset dir="${basedir}/${test.src.dir}" id="have.tests.test.src.dir.patchset" includes="*/*">
+ <filename regex="${have.tests.test.src.dir.regexp}"/>
+ <scriptselector language="javascript">
+ self.setSelected(!new java.io.File(file, "module-info.java").exists());
+ </scriptselector>
+ </dirset>
+ <union id="have.tests.patchset">
+ <dirset refid="have.tests.test.src.dir.patchset"/>
+ </union>
+ <j2semodularproject1:modsource_regexp xmlns:j2semodularproject1="http://www.netbeans.org/ns/j2se-modular-project/1" modsource="${src.dir.path}" property="have.sources.src.dir.regexp"/>
+ <dirset dir="${basedir}/${src.dir}" id="have.sources.src.dir.set" includes="*/*">
+ <filename regex="${have.sources.src.dir.regexp}"/>
+ </dirset>
+ <j2semodularproject1:modsource_regexp xmlns:j2semodularproject1="http://www.netbeans.org/ns/j2se-modular-project/1" modsource="${src.gen.dir.path}" property="have.sources.src.gen.dir.regexp"/>
+ <dirset dir="${basedir}/${src.gen.dir}" id="have.sources.src.gen.dir.set" includes="*/*">
+ <filename regex="${have.sources.src.gen.dir.regexp}"/>
+ </dirset>
+ <union id="have.sources.set">
+ <dirset refid="have.sources.src.dir.set"/>
+ <dirset refid="have.sources.src.gen.dir.set"/>
+ </union>
+ <condition property="have.sources">
+ <or>
+ <resourcecount count="0" when="greater">
+ <union refid="have.sources.set"/>
+ </resourcecount>
+ <resourcecount count="0" when="greater">
+ <union refid="have.sources.set"/>
+ </resourcecount>
+ </or>
+ </condition>
+ <condition property="main.class.available">
+ <and>
+ <isset property="main.class"/>
+ <not>
+ <equals arg1="${main.class}" arg2="" trim="true"/>
+ </not>
+ </and>
+ </condition>
+ <condition property="netbeans.home+have.tests">
+ <and>
+ <isset property="netbeans.home"/>
+ <isset property="have.tests"/>
+ </and>
+ </condition>
+ <condition property="no.javadoc.preview">
+ <and>
+ <isset property="javadoc.preview"/>
+ <isfalse value="${javadoc.preview}"/>
+ </and>
+ </condition>
+ <condition property="do.archive">
+ <or>
+ <not>
+ <istrue value="${jar.archive.disabled}"/>
+ </not>
+ <istrue value="${not.archive.disabled}"/>
+ </or>
+ </condition>
+ <property name="run.jvmargs" value=""/>
+ <property name="run.jvmargs.ide" value=""/>
+ <property name="javac.compilerargs" value=""/>
+ <property name="work.dir" value="${basedir}"/>
+ <condition property="no.deps">
+ <and>
+ <istrue value="${no.dependencies}"/>
+ </and>
+ </condition>
+ <property name="javac.debug" value="true"/>
+ <property name="javadoc.preview" value="true"/>
+ <property name="application.args" value=""/>
+ <property name="source.encoding" value="${file.encoding}"/>
+ <property name="runtime.encoding" value="${source.encoding}"/>
+ <condition property="javadoc.encoding.used" value="${javadoc.encoding}">
+ <and>
+ <isset property="javadoc.encoding"/>
+ <not>
+ <equals arg1="${javadoc.encoding}" arg2=""/>
+ </not>
+ </and>
+ </condition>
+ <property name="javadoc.encoding.used" value="${source.encoding}"/>
+ <property name="includes" value="**"/>
+ <property name="excludes" value=""/>
+ <property name="do.depend" value="false"/>
+ <condition property="do.depend.true">
+ <istrue value="${do.depend}"/>
+ </condition>
+ <path id="endorsed.classpath.path" path="${endorsed.classpath}"/>
+ <condition else="" property="endorsed.classpath.cmd.line.arg" value="-Xbootclasspath/p:'${toString:endorsed.classpath.path}'">
+ <and>
+ <isset property="endorsed.classpath"/>
+ <not>
+ <equals arg1="${endorsed.classpath}" arg2="" trim="true"/>
+ </not>
+ </and>
+ </condition>
+ <condition else="" property="javac.profile.cmd.line.arg" value="-profile ${javac.profile}">
+ <isset property="profile.available"/>
+ </condition>
+ <condition else="false" property="jdkBug6558476">
+ <and>
+ <matches pattern="1\.[56]" string="${java.specification.version}"/>
+ <not>
+ <os family="unix"/>
+ </not>
+ </and>
+ </condition>
+ <condition else="false" property="javac.fork">
+ <or>
+ <istrue value="${jdkBug6558476}"/>
+ <istrue value="${javac.external.vm}"/>
+ </or>
+ </condition>
+ <condition property="main.class.check.available">
+ <and>
+ <isset property="libs.CopyLibs.classpath"/>
+ <available classname="org.netbeans.modules.java.j2seproject.moduletask.ModuleMainClass" classpath="${libs.CopyLibs.classpath}"/>
+ </and>
+ </condition>
+ <property name="jar.index" value="false"/>
+ <property name="jar.index.metainf" value="${jar.index}"/>
+ <condition property="junit.available">
+ <or>
+ <available classname="org.junit.Test" classpath="${run.test.classpath}"/>
+ <available classname="junit.framework.Test" classpath="${run.test.classpath}"/>
+ </or>
+ </condition>
+ <condition property="testng.available">
+ <available classname="org.testng.annotations.Test" classpath="${run.test.classpath}"/>
+ </condition>
+ <condition property="junit+testng.available">
+ <and>
+ <istrue value="${junit.available}"/>
+ <istrue value="${testng.available}"/>
+ </and>
+ </condition>
+ <condition else="testng" property="testng.mode" value="mixed">
+ <istrue value="${junit+testng.available}"/>
+ </condition>
+ <condition else="" property="testng.debug.mode" value="-mixed">
+ <istrue value="${junit+testng.available}"/>
+ </condition>
+ <property name="java.failonerror" value="true"/>
+ <macrodef name="for-paths" uri="http://www.netbeans.org/ns/j2se-modular-project/1">
+ <attribute name="paths"/>
+ <attribute default="${path.separator}" name="separator"/>
+ <element implicit="yes" name="call"/>
+ <sequential>
+ <local name="entry"/>
+ <local name="tail"/>
+ <local name="moreElements"/>
+ <loadresource property="entry" quiet="true" unless:blank="@{paths}">
+ <concat>@{paths}</concat>
+ <filterchain>
+ <replaceregex pattern="([^@{separator}]*)\Q@{separator}\E.*" replace="\1"/>
+ </filterchain>
+ </loadresource>
+ <sequential if:set="entry">
+ <call/>
+ </sequential>
+ <condition else="false" property="moreElements" value="true">
+ <contains string="@{paths}" substring="@{separator}"/>
+ </condition>
+ <loadresource if:true="${moreElements}" property="tail" quiet="true">
+ <concat>@{paths}</concat>
+ <filterchain>
+ <replaceregex pattern="[^@{separator}]*\Q@{separator}\E(.*)" replace="\1"/>
+ </filterchain>
+ </loadresource>
+ <j2semodularproject1:for-paths xmlns:j2semodularproject1="http://www.netbeans.org/ns/j2se-modular-project/1" if:true="${moreElements}" paths="${tail}">
+ <call/>
+ </j2semodularproject1:for-paths>
+ </sequential>
+ </macrodef>
+ <property name="modules.supported.internal" value="true"/>
+ <condition else="${file.separator}" property="file.separator.string" value="\${file.separator}">
+ <equals arg1="${file.separator}" arg2="\"/>
+ </condition>
+ </target>
+ <target name="-post-init">
+ <!-- Empty placeholder for easier customization. -->
+ <!-- You can override this target in the ../build.xml file. -->
+ </target>
+ <target depends="-pre-init,-init-private,-init-user,-init-project,-do-init" name="-init-check">
+ <fail unless="src.dir">Must set src.dir</fail>
+ <fail unless="src.gen.dir">Must set src.gen.dir</fail>
+ <fail unless="test.src.dir">Must set test.src.dir</fail>
+ <fail unless="build.dir">Must set build.dir</fail>
+ <fail unless="dist.dir">Must set dist.dir</fail>
+ <fail unless="build.modules.dir">Must set build.modules.dir</fail>
+ <fail unless="dist.javadoc.dir">Must set dist.javadoc.dir</fail>
+ <fail unless="build.test.modules.dir">Must set build.test.modules.dir</fail>
+ <fail unless="build.test.results.dir">Must set build.test.results.dir</fail>
+ <fail unless="build.classes.excludes">Must set build.classes.excludes</fail>
+ <fail message="Java 9 support requires Ant 1.10.0 or higher.">
+ <condition>
+ <not>
+ <antversion atleast="1.10.0"/>
+ </not>
+ </condition>
+ </fail>
+ </target>
+ <target name="-init-macrodef-property">
+ <macrodef name="property" uri="http://www.netbeans.org/ns/j2se-modular-project/1">
+ <attribute name="name"/>
+ <attribute name="value"/>
+ <sequential>
+ <property name="@{name}" value="${@{value}}"/>
+ </sequential>
+ </macrodef>
+ </target>
+ <target depends="-init-ap-cmdline-properties,-init-source-module-properties" name="-init-macrodef-javac">
+ <macrodef name="javac" uri="http://www.netbeans.org/ns/j2se-modular-project/1">
+ <attribute default="${build.modules.dir}" name="destdir"/>
+ <attribute default="${javac.classpath}" name="classpath"/>
+ <attribute default="${javac.modulepath}" name="modulepath"/>
+ <attribute default="${src.dir}/*/${src.dir.path}:${src.gen.dir}/*/${src.gen.dir.path}" name="modulesourcepath"/>
+ <attribute default="${javac.upgrademodulepath}" name="upgrademodulepath"/>
+ <attribute default="${javac.processorpath}" name="processorpath"/>
+ <attribute default="${javac.processormodulepath}" name="processormodulepath"/>
+ <attribute default="${build.generated.sources.dir}/ap-source-output" name="apgeneratedsrcdir"/>
+ <attribute default="${includes}" name="includes"/>
+ <attribute default="${excludes}" name="excludes"/>
+ <attribute default="${javac.debug}" name="debug"/>
+ <attribute default="${empty.dir}" name="gensrcdir"/>
+ <element name="customize" optional="true"/>
+ <sequential>
+ <property location="${build.dir}/empty" name="empty.dir"/>
+ <mkdir dir="${empty.dir}"/>
+ <mkdir dir="@{apgeneratedsrcdir}"/>
+ <condition property="processormodulepath.set">
+ <resourcecount count="0" when="greater">
+ <path>
+ <pathelement path="@{processormodulepath}"/>
+ </path>
+ </resourcecount>
+ </condition>
+ <javac debug="@{debug}" deprecation="${javac.deprecation}" destdir="@{destdir}" encoding="${source.encoding}" excludes="@{excludes}" fork="${javac.fork}" includeantruntime="false" includes="@{includes}" source="${javac.source}" target="${javac.target}" tempdir="${java.io.tmpdir}">
+ <classpath>
+ <path path="@{classpath}"/>
+ </classpath>
+ <modulepath>
+ <path path="@{modulepath}"/>
+ </modulepath>
+ <modulesourcepath>
+ <path path="@{modulesourcepath}"/>
+ </modulesourcepath>
+ <upgrademodulepath>
+ <path path="@{upgrademodulepath}"/>
+ </upgrademodulepath>
+ <compilerarg line="${javac.systemmodulepath.cmd.line.arg}"/>
+ <compilerarg line="${javac.profile.cmd.line.arg}"/>
+ <compilerarg line="${javac.compilerargs}"/>
+ <compilerarg if:set="processormodulepath.set" value="--processor-module-path"/>
+ <compilerarg if:set="processormodulepath.set" path="@{processormodulepath}"/>
+ <compilerarg unless:set="processormodulepath.set" value="-processorpath"/>
+ <compilerarg path="@{processorpath}:${empty.dir}" unless:set="processormodulepath.set"/>
+ <compilerarg line="${ap.processors.internal}"/>
+ <compilerarg line="${annotation.processing.processor.options}"/>
+ <compilerarg value="-s"/>
+ <compilerarg path="@{apgeneratedsrcdir}"/>
+ <compilerarg line="${ap.proc.none.internal}"/>
+ <customize/>
+ </javac>
+ </sequential>
+ </macrodef>
+ </target>
+ <target depends="-init-macrodef-javac" name="-init-macrodef-javac-depend">
+ <macrodef name="depend" uri="http://www.netbeans.org/ns/j2se-modular-project/1">
+ <attribute default="${src.dir}:${src.gen.dir}" name="srcdir"/>
+ <attribute default="${build.classes.dir}" name="destdir"/>
+ <attribute default="${javac.classpath}" name="classpath"/>
+ <sequential>
+ <depend cache="${build.dir}/depcache" destdir="@{destdir}" excludes="${excludes}" includes="${includes}" srcdir="@{srcdir}">
+ <classpath>
+ <path path="@{classpath}"/>
+ </classpath>
+ </depend>
+ </sequential>
+ </macrodef>
+ <macrodef name="force-recompile" uri="http://www.netbeans.org/ns/j2se-modular-project/1">
+ <attribute default="${build.modules.dir}" name="destdir"/>
+ <sequential>
+ <fail unless="javac.includes">Must set javac.includes</fail>
+ <pathconvert pathsep="${line.separator}" property="javac.includes.binary">
+ <path>
+ <filelist dir="@{destdir}" files="${javac.includes}"/>
+ </path>
+ <globmapper from="*.java" to="*.class"/>
+ </pathconvert>
+ <tempfile deleteonexit="true" property="javac.includesfile.binary"/>
+ <echo file="${javac.includesfile.binary}" message="${javac.includes.binary}"/>
+ <delete>
+ <files includesfile="${javac.includesfile.binary}"/>
+ </delete>
+ <delete>
+ <fileset file="${javac.includesfile.binary}"/>
+ </delete>
+ </sequential>
+ </macrodef>
+ </target>
+ <target if="${junit.available}" name="-init-macrodef-junit-init">
+ <condition else="false" property="nb.junit.batch" value="true">
+ <and>
+ <istrue value="${junit.available}"/>
+ <not>
+ <isset property="test.method"/>
+ </not>
+ </and>
+ </condition>
+ <condition else="false" property="nb.junit.single" value="true">
+ <and>
+ <istrue value="${junit.available}"/>
+ <isset property="test.method"/>
+ </and>
+ </condition>
+ </target>
+ <target name="-init-test-properties">
+ <property name="test.binaryincludes" value="<nothing>"/>
+ <property name="test.binarytestincludes" value=""/>
+ <property name="test.binaryexcludes" value=""/>
+ </target>
+ <target name="-init-macrodef-junit-prototype">
+ <macrodef name="junit-prototype" uri="http://www.netbeans.org/ns/j2se-modular-project/1">
+ <attribute default="${includes}" name="includes"/>
+ <attribute default="${excludes}" name="excludes"/>
+ <element name="customizePrototype" optional="true"/>
+ <sequential>
+ <property location="${build.dir}/empty" name="empty.dir"/>
+ <property name="junit.forkmode" value="perTest"/>
+ <junit dir="${work.dir}" errorproperty="tests.failed" failureproperty="tests.failed" fork="true" forkmode="${junit.forkmode}" showoutput="true" tempdir="${build.dir}">
+ <syspropertyset>
+ <propertyref prefix="test-sys-prop."/>
+ <mapper from="test-sys-prop.*" to="*" type="glob"/>
+ </syspropertyset>
+ <classpath>
+ <path path="${run.test.classpath}"/>
+ </classpath>
+ <formatter type="brief" usefile="false"/>
+ <formatter type="xml"/>
+ <jvmarg line="${endorsed.classpath.cmd.line.arg}"/>
+ <jvmarg value="-ea"/>
+ <jvmarg value="--module-path"/>
+ <jvmarg path="${run.modulepath}${path.separator}${run.test.modulepath}${path.separator}${empty.dir}"/>
+ <jvmarg line="${run.test.jvmargs}"/>
+ <customizePrototype/>
+ </junit>
+ </sequential>
+ </macrodef>
+ </target>
+ <target depends="-init-test-properties,-init-macrodef-junit-prototype" if="${nb.junit.single}" name="-init-macrodef-junit-single" unless="${nb.junit.batch}">
+ <macrodef name="junit" uri="http://www.netbeans.org/ns/j2se-modular-project/1">
+ <attribute default="${includes}" name="includes"/>
+ <attribute default="${excludes}" name="excludes"/>
+ <attribute default="**" name="testincludes"/>
+ <attribute default="" name="testmethods"/>
+ <element name="customize" optional="true"/>
+ <sequential>
+ <j2semodularproject1:junit-prototype xmlns:j2semodularproject1="http://www.netbeans.org/ns/j2se-modular-project/1">
+ <customizePrototype>
+ <test methods="@{testmethods}" name="@{testincludes}" todir="${build.test.results.dir}"/>
+ <customize/>
+ </customizePrototype>
+ </j2semodularproject1:junit-prototype>
+ </sequential>
+ </macrodef>
+ </target>
+ <target depends="-init-test-properties,-init-macrodef-junit-prototype" if="${nb.junit.batch}" name="-init-macrodef-junit-batch" unless="${nb.junit.single}">
+ <macrodef name="junit" uri="http://www.netbeans.org/ns/j2se-modular-project/1">
+ <attribute default="${includes}" name="includes"/>
+ <attribute default="${excludes}" name="excludes"/>
+ <attribute default="**" name="testincludes"/>
+ <attribute default="" name="testmethods"/>
+ <element name="customize" optional="true"/>
+ <sequential>
+ <j2semodularproject1:junit-prototype xmlns:j2semodularproject1="http://www.netbeans.org/ns/j2se-modular-project/1">
+ <customizePrototype>
+ <batchtest todir="${build.test.results.dir}">
+ <mappedresources>
+ <union>
+ <fileset dir="${test.src.dir}" excludes="@{excludes},${excludes}" includes="**/@{includes}">
+ <filename name="**/@{testincludes}"/>
+ <filename regex="${have.tests.test.src.dir.regexp}"/>
+ </fileset>
+ </union>
+ <regexpmapper from="${have.tests.test.src.dir.regexp}\Q${file.separator}\E(.*)$" to="\3"/>
+ </mappedresources>
+ <fileset dir="${build.test.modules.dir}" excludes="@{excludes},${excludes},${test.binaryexcludes}" includes="${test.binaryincludes}">
+ <filename name="${test.binarytestincludes}"/>
+ </fileset>
+ </batchtest>
+ <customize/>
+ </customizePrototype>
+ </j2semodularproject1:junit-prototype>
+ </sequential>
+ </macrodef>
+ </target>
+ <target depends="-init-macrodef-junit-init,-init-macrodef-junit-single, -init-macrodef-junit-batch" if="${junit.available}" name="-init-macrodef-junit"/>
+ <target if="${testng.available}" name="-init-macrodef-testng">
+ <macrodef name="testng" uri="http://www.netbeans.org/ns/j2se-modular-project/1">
+ <attribute default="${includes}" name="includes"/>
+ <attribute default="${excludes}" name="excludes"/>
+ <attribute default="**" name="testincludes"/>
+ <attribute default="" name="testmethods"/>
+ <element name="customize" optional="true"/>
+ <sequential>
+ <condition else="" property="testng.methods.arg" value="@{testincludes}.@{testmethods}">
+ <isset property="test.method"/>
+ </condition>
+ <union id="test.set">
+ <fileset dir="${test.src.dir}" excludes="@{excludes},**/*.xml,${excludes}" includes="@{includes}">
+ <filename name="@{testincludes}"/>
+ </fileset>
+ </union>
+ <taskdef classname="org.testng.TestNGAntTask" classpath="${run.test.classpath}" name="testng"/>
+ <testng classfilesetref="test.set" failureProperty="tests.failed" listeners="org.testng.reporters.VerboseReporter" methods="${testng.methods.arg}" mode="${testng.mode}" outputdir="${build.test.results.dir}" suitename="notzed.jjmpeg" testname="TestNG tests" workingDir="${work.dir}">
+ <xmlfileset dir="${build.test.classes.dir}" includes="@{testincludes}"/>
+ <propertyset>
+ <propertyref prefix="test-sys-prop."/>
+ <mapper from="test-sys-prop.*" to="*" type="glob"/>
+ </propertyset>
+ <classpath>
+ <path path="${run.test.classpath}"/>
+ </classpath>
+ <jvmarg line="${endorsed.classpath.cmd.line.arg}"/>
+ <customize/>
+ </testng>
+ </sequential>
+ </macrodef>
+ </target>
+ <target name="-init-macrodef-test-impl">
+ <macrodef name="test-impl" uri="http://www.netbeans.org/ns/j2se-modular-project/1">
+ <attribute default="${includes}" name="includes"/>
+ <attribute default="${excludes}" name="excludes"/>
+ <attribute default="**" name="testincludes"/>
+ <attribute default="" name="testmethods"/>
+ <element implicit="true" name="customize" optional="true"/>
+ <sequential>
+ <echo>No tests executed.</echo>
+ </sequential>
+ </macrodef>
+ </target>
+ <target depends="-init-macrodef-junit" if="${junit.available}" name="-init-macrodef-junit-impl">
+ <macrodef name="test-impl" uri="http://www.netbeans.org/ns/j2se-modular-project/1">
+ <attribute default="${includes}" name="includes"/>
+ <attribute default="${excludes}" name="excludes"/>
+ <attribute default="**" name="testincludes"/>
+ <attribute default="" name="testmethods"/>
+ <element implicit="true" name="customize" optional="true"/>
+ <sequential>
+ <j2semodularproject1:junit xmlns:j2semodularproject1="http://www.netbeans.org/ns/j2se-modular-project/1" excludes="@{excludes}" includes="@{includes}" testincludes="@{testincludes}" testmethods="@{testmethods}">
+ <customize/>
+ </j2semodularproject1:junit>
+ </sequential>
+ </macrodef>
+ </target>
+ <target depends="-init-macrodef-testng" if="${testng.available}" name="-init-macrodef-testng-impl">
+ <macrodef name="test-impl" uri="http://www.netbeans.org/ns/j2se-modular-project/1">
+ <attribute default="${includes}" name="includes"/>
+ <attribute default="${excludes}" name="excludes"/>
+ <attribute default="**" name="testincludes"/>
+ <attribute default="" name="testmethods"/>
+ <element implicit="true" name="customize" optional="true"/>
+ <sequential>
+ <j2semodularproject1:testng xmlns:j2semodularproject1="http://www.netbeans.org/ns/j2se-modular-project/1" excludes="@{excludes}" includes="@{includes}" testincludes="@{testincludes}" testmethods="@{testmethods}">
+ <customize/>
+ </j2semodularproject1:testng>
+ </sequential>
+ </macrodef>
+ </target>
+ <target depends="-init-macrodef-test-impl,-init-macrodef-junit-impl,-init-macrodef-testng-impl" name="-init-macrodef-test">
+ <macrodef name="test" uri="http://www.netbeans.org/ns/j2se-modular-project/1">
+ <attribute default="${includes}" name="includes"/>
+ <attribute default="${excludes}" name="excludes"/>
+ <attribute default="**" name="testincludes"/>
+ <attribute default="" name="testmethods"/>
+ <sequential>
+ <j2semodularproject1:test-impl xmlns:j2semodularproject1="http://www.netbeans.org/ns/j2se-modular-project/1" excludes="@{excludes}" includes="@{includes}" testincludes="@{testincludes}" testmethods="@{testmethods}">
+ <customize>
+ <jvmarg line="${run.jvmargs}"/>
+ <jvmarg line="${run.jvmargs.ide}"/>
+ </customize>
+ </j2semodularproject1:test-impl>
+ </sequential>
+ </macrodef>
+ </target>
+ <target depends="-init-macrodef-junit" if="${junit.available}" name="-init-macrodef-junit-debug-impl">
+ <macrodef name="test-debug-impl" uri="http://www.netbeans.org/ns/j2se-modular-project/1">
+ <attribute default="${includes}" name="includes"/>
+ <attribute default="${excludes}" name="excludes"/>
+ <attribute default="**" name="testincludes"/>
+ <attribute default="" name="testmethods"/>
+ <element name="customizeDebuggee" optional="true"/>
+ <sequential>
+ <j2semodularproject1:junit xmlns:j2semodularproject1="http://www.netbeans.org/ns/j2se-modular-project/1" excludes="@{excludes}" includes="@{includes}" testincludes="@{testincludes}" testmethods="@{testmethods}">
+ <customize>
+ <jvmarg value="-agentlib:jdwp=transport=${debug-transport},address=${jpda.address}"/>
+ <customizeDebuggee/>
+ </customize>
+ </j2semodularproject1:junit>
+ </sequential>
+ </macrodef>
+ </target>
+ <target if="${testng.available}" name="-init-macrodef-testng-debug">
+ <macrodef name="testng-debug" uri="http://www.netbeans.org/ns/j2se-modular-project/1">
+ <attribute default="${main.class}" name="testClass"/>
+ <attribute default="" name="testMethod"/>
+ <element name="customize2" optional="true"/>
+ <sequential>
+ <condition else="-testclass @{testClass}" property="test.class.or.method" value="-methods @{testClass}.@{testMethod}">
+ <isset property="test.method"/>
+ </condition>
+ <condition else="-suitename notzed.jjmpeg -testname @{testClass} ${test.class.or.method}" property="testng.cmd.args" value="@{testClass}">
+ <matches pattern=".*\.xml" string="@{testClass}"/>
+ </condition>
+ <delete dir="${build.test.results.dir}" quiet="true"/>
+ <mkdir dir="${build.test.results.dir}"/>
+ <j2semodularproject1:debug xmlns:j2semodularproject1="http://www.netbeans.org/ns/j2se-modular-project/1" classname="org.testng.TestNG" classpath="${debug.test.classpath}">
+ <customizeDebuggee>
+ <customize2/>
+ <jvmarg value="-ea"/>
+ <arg line="${testng.debug.mode}"/>
+ <arg line="-d ${build.test.results.dir}"/>
+ <arg line="-listener org.testng.reporters.VerboseReporter"/>
+ <arg line="${testng.cmd.args}"/>
+ </customizeDebuggee>
+ </j2semodularproject1:debug>
+ </sequential>
+ </macrodef>
+ </target>
+ <target depends="-init-macrodef-testng-debug" if="${testng.available}" name="-init-macrodef-testng-debug-impl">
+ <macrodef name="testng-debug-impl" uri="http://www.netbeans.org/ns/j2se-modular-project/1">
+ <attribute default="${main.class}" name="testClass"/>
+ <attribute default="" name="testMethod"/>
+ <element implicit="true" name="customize2" optional="true"/>
+ <sequential>
+ <j2semodularproject1:testng-debug xmlns:j2semodularproject1="http://www.netbeans.org/ns/j2se-modular-project/1" testClass="@{testClass}" testMethod="@{testMethod}">
+ <customize2/>
+ </j2semodularproject1:testng-debug>
+ </sequential>
+ </macrodef>
+ </target>
+ <target depends="-init-macrodef-junit-debug-impl" if="${junit.available}" name="-init-macrodef-test-debug-junit">
+ <macrodef name="test-debug" uri="http://www.netbeans.org/ns/j2se-modular-project/1">
+ <attribute default="${includes}" name="includes"/>
+ <attribute default="${excludes}" name="excludes"/>
+ <attribute default="**" name="testincludes"/>
+ <attribute default="" name="testmethods"/>
+ <attribute default="${main.class}" name="testClass"/>
+ <attribute default="" name="testMethod"/>
+ <sequential>
+ <j2semodularproject1:test-debug-impl xmlns:j2semodularproject1="http://www.netbeans.org/ns/j2se-modular-project/1" excludes="@{excludes}" includes="@{includes}" testincludes="@{testincludes}" testmethods="@{testmethods}">
+ <customizeDebuggee>
+ <jvmarg line="${run.jvmargs}"/>
+ <jvmarg line="${run.jvmargs.ide}"/>
+ </customizeDebuggee>
+ </j2semodularproject1:test-debug-impl>
+ </sequential>
+ </macrodef>
+ </target>
+ <target depends="-init-macrodef-testng-debug-impl" if="${testng.available}" name="-init-macrodef-test-debug-testng">
+ <macrodef name="test-debug" uri="http://www.netbeans.org/ns/j2se-modular-project/1">
+ <attribute default="${includes}" name="includes"/>
+ <attribute default="${excludes}" name="excludes"/>
+ <attribute default="**" name="testincludes"/>
+ <attribute default="" name="testmethods"/>
+ <attribute default="${main.class}" name="testClass"/>
+ <attribute default="" name="testMethod"/>
+ <sequential>
+ <j2semodularproject1:testng-debug-impl xmlns:j2semodularproject1="http://www.netbeans.org/ns/j2se-modular-project/1" testClass="@{testClass}" testMethod="@{testMethod}">
+ <customize2>
+ <syspropertyset>
+ <propertyref prefix="test-sys-prop."/>
+ <mapper from="test-sys-prop.*" to="*" type="glob"/>
+ </syspropertyset>
+ </customize2>
+ </j2semodularproject1:testng-debug-impl>
+ </sequential>
+ </macrodef>
+ </target>
+ <target depends="-init-macrodef-test-debug-junit,-init-macrodef-test-debug-testng" name="-init-macrodef-test-debug"/>
+ <!--
+ pre NB7.2 profiling section; consider it deprecated
+ -->
+ <target depends="-profile-pre-init, init, -profile-post-init, -profile-init-macrodef-profile, -profile-init-check" if="profiler.info.jvmargs.agent" name="profile-init"/>
+ <target if="profiler.info.jvmargs.agent" name="-profile-pre-init">
+ <!-- Empty placeholder for easier customization. -->
+ <!-- You can override this target in the ../build.xml file. -->
+ </target>
+ <target if="profiler.info.jvmargs.agent" name="-profile-post-init">
+ <!-- Empty placeholder for easier customization. -->
+ <!-- You can override this target in the ../build.xml file. -->
+ </target>
+ <target if="profiler.info.jvmargs.agent" name="-profile-init-macrodef-profile">
+ <macrodef name="resolve">
+ <attribute name="name"/>
+ <attribute name="value"/>
+ <sequential>
+ <property name="@{name}" value="${env.@{value}}"/>
+ </sequential>
+ </macrodef>
+ <macrodef name="profile">
+ <attribute default="${main.class}" name="classname"/>
+ <element name="customize" optional="true"/>
+ <sequential>
+ <property environment="env"/>
+ <resolve name="profiler.current.path" value="${profiler.info.pathvar}"/>
+ <java classname="@{classname}" dir="${profiler.info.dir}" failonerror="${java.failonerror}" fork="true" jvm="${profiler.info.jvm}">
+ <jvmarg line="${endorsed.classpath.cmd.line.arg}"/>
+ <jvmarg value="${profiler.info.jvmargs.agent}"/>
+ <jvmarg line="${profiler.info.jvmargs}"/>
+ <env key="${profiler.info.pathvar}" path="${profiler.info.agentpath}:${profiler.current.path}"/>
+ <arg line="${application.args}"/>
+ <classpath>
+ <path path="${run.classpath}"/>
+ </classpath>
+ <syspropertyset>
+ <propertyref prefix="run-sys-prop."/>
+ <mapper from="run-sys-prop.*" to="*" type="glob"/>
+ </syspropertyset>
+ <customize/>
+ </java>
+ </sequential>
+ </macrodef>
+ </target>
+ <target depends="-profile-pre-init, init, -profile-post-init, -profile-init-macrodef-profile" if="profiler.info.jvmargs.agent" name="-profile-init-check">
+ <fail unless="profiler.info.jvm">Must set JVM to use for profiling in profiler.info.jvm</fail>
+ <fail unless="profiler.info.jvmargs.agent">Must set profiler agent JVM arguments in profiler.info.jvmargs.agent</fail>
+ </target>
+ <!--
+ end of pre NB7.2 profiling section
+ -->
+ <target depends="-init-debug-args" name="-init-macrodef-nbjpda">
+ <macrodef name="nbjpdastart" uri="http://www.netbeans.org/ns/j2se-modular-project/1">
+ <attribute default="${main.class}" name="name"/>
+ <attribute default="${debug.modulepath}" name="modulepath"/>
+ <attribute default="${debug.classpath}" name="classpath"/>
+ <attribute default="" name="stopclassname"/>
+ <sequential>
+ <nbjpdastart addressproperty="jpda.address" name="@{name}" stopclassname="@{stopclassname}" transport="${debug-transport}">
+ <modulepath>
+ <path path="@{modulepath}"/>
+ </modulepath>
+ <classpath>
+ <path path="@{classpath}"/>
+ </classpath>
+ </nbjpdastart>
+ </sequential>
+ </macrodef>
+ <macrodef name="nbjpdareload" uri="http://www.netbeans.org/ns/j2se-modular-project/1">
+ <attribute default="${debug.modules.dir}" name="dir"/>
+ <sequential>
+ <nbjpdareload>
+ <fileset dir="@{dir}" includes="${fix.classes}">
+ <include name="*/${fix.includes}*.class"/>
+ </fileset>
+ </nbjpdareload>
+ </sequential>
+ </macrodef>
+ </target>
+ <target name="-init-debug-args">
+ <condition else="dt_socket" property="debug-transport-by-os" value="dt_shmem">
+ <os family="windows"/>
+ </condition>
+ <condition else="${debug-transport-by-os}" property="debug-transport" value="${debug.transport}">
+ <isset property="debug.transport"/>
+ </condition>
+ </target>
+ <target depends="-init-debug-args" name="-init-macrodef-debug">
+ <macrodef name="debug" uri="http://www.netbeans.org/ns/j2se-modular-project/1">
+ <attribute default="${module.name}" name="modulename"/>
+ <attribute default="${main.class}" name="classname"/>
+ <attribute default="${debug.modulepath}" name="modulepath"/>
+ <attribute default="${debug.classpath}" name="classpath"/>
+ <element name="customizeDebuggee" optional="true"/>
+ <sequential>
+ <j2semodularproject1:java xmlns:j2semodularproject1="http://www.netbeans.org/ns/j2se-modular-project/1" classname="@{classname}" classpath="@{classpath}" modulename="@{modulename}" modulepath="@{modulepath}">
+ <customize>
+ <jvmarg value="-agentlib:jdwp=transport=${debug-transport},address=${jpda.address}"/>
+ <customizeDebuggee/>
+ </customize>
+ </j2semodularproject1:java>
+ </sequential>
+ </macrodef>
+ </target>
+ <target depends="-init-source-module-properties" name="-init-macrodef-java">
+ <macrodef name="java" uri="http://www.netbeans.org/ns/j2se-modular-project/1">
+ <attribute default="${module.name}" name="modulename"/>
+ <attribute default="${main.class}" name="classname"/>
+ <attribute default="${run.modulepath}" name="modulepath"/>
+ <attribute default="${run.upgrademodulepath}" name="upgrademodulepath"/>
+ <attribute default="${run.classpath}" name="classpath"/>
+ <attribute default="jvm" name="jvm"/>
+ <element name="customize" optional="true"/>
+ <sequential>
+ <java classname="@{classname}" dir="${work.dir}" failonerror="${java.failonerror}" fork="true" module="@{modulename}">
+ <classpath>
+ <path path="@{classpath}"/>
+ </classpath>
+ <modulepath>
+ <path path="@{modulepath}"/>
+ </modulepath>
+ <upgrademodulepath>
+ <path path="@{upgrademodulepath}"/>
+ </upgrademodulepath>
+ <jvmarg value="-Dfile.encoding=${runtime.encoding}"/>
+ <redirector errorencoding="${runtime.encoding}" inputencoding="${runtime.encoding}" outputencoding="${runtime.encoding}"/>
+ <jvmarg line="${run.jvmargs}"/>
+ <jvmarg line="${run.jvmargs.ide}"/>
+ <syspropertyset>
+ <propertyref prefix="run-sys-prop."/>
+ <mapper from="run-sys-prop.*" to="*" type="glob"/>
+ </syspropertyset>
+ <customize/>
+ </java>
+ </sequential>
+ </macrodef>
+ </target>
+ <target name="-init-presetdef-jar">
+ <presetdef name="jar" uri="http://www.netbeans.org/ns/j2se-modular-project/1">
+ <jar compress="${jar.compress}" index="${jar.index}" jarfile="${dist.jar}" manifestencoding="UTF-8">
+ <j2semodularproject1:fileset xmlns:j2semodularproject1="http://www.netbeans.org/ns/j2se-modular-project/1" dir="${build.classes.dir}" excludes="${dist.archive.excludes}"/>
+ </jar>
+ </presetdef>
+ </target>
+ <target name="-init-ap-cmdline-properties">
+ <property name="annotation.processing.enabled" value="true"/>
+ <property name="annotation.processing.processors.list" value=""/>
+ <property name="annotation.processing.processor.options" value=""/>
+ <property name="annotation.processing.run.all.processors" value="true"/>
+ <property name="javac.processorpath" value="${javac.classpath}"/>
+ <property name="javac.test.processorpath" value="${javac.test.classpath}"/>
+ </target>
+ <target depends="-init-ap-cmdline-properties" name="-init-ap-cmdline-supported">
+ <condition else="" property="ap.processors.internal" value="-processor ${annotation.processing.processors.list}">
+ <isfalse value="${annotation.processing.run.all.processors}"/>
+ </condition>
+ <condition else="" property="ap.proc.none.internal" value="-proc:none">
+ <isfalse value="${annotation.processing.enabled}"/>
+ </condition>
+ </target>
+ <target depends="-init-ap-cmdline-properties,-init-ap-cmdline-supported" name="-init-ap-cmdline">
+ <property name="ap.cmd.line.internal" value=""/>
+ </target>
+ <target depends="-pre-init,-init-private,-init-user,-init-project,-do-init,-post-init,-init-check,-init-macrodef-property,-init-macrodef-javac-depend,-init-macrodef-test,-init-macrodef-test-debug,-init-macrodef-nbjpda,-init-macrodef-debug,-init-macrodef-java,-init-presetdef-jar,-init-ap-cmdline" name="init"/>
+ <!--
+ ===================
+ COMPILATION SECTION
+ ===================
+ -->
+ <target name="-deps-jar-init" unless="built-jar.properties">
+ <property location="${build.dir}/built-jar.properties" name="built-jar.properties"/>
+ <delete file="${built-jar.properties}" quiet="true"/>
+ </target>
+ <target if="already.built.jar.${basedir}" name="-warn-already-built-jar">
+ <echo level="warn" message="Cycle detected: notzed.jjmpeg was already built"/>
+ </target>
+ <target depends="init,-deps-jar-init" name="deps-jar" unless="no.deps">
+ <mkdir dir="${build.dir}"/>
+ <touch file="${built-jar.properties}" verbose="false"/>
+ <property file="${built-jar.properties}" prefix="already.built.jar."/>
+ <antcall target="-warn-already-built-jar"/>
+ <propertyfile file="${built-jar.properties}">
+ <entry key="${basedir}" value=""/>
+ </propertyfile>
+ <antcall target="-maybe-call-dep">
+ <param name="call.built.properties" value="${built-jar.properties}"/>
+ <param location="${project.notzed_nativez}" name="call.subproject"/>
+ <param location="${project.notzed_nativez}/build.xml" name="call.script"/>
+ <param name="call.target" value="jar"/>
+ <param name="transfer.built-jar.properties" value="${built-jar.properties}"/>
+ <param name="transfer.not.archive.disabled" value="true"/>
+ <param name="transfer.do.jlink" value="false"/>
+ </antcall>
+ </target>
+ <target depends="init,-check-automatic-build,-clean-after-automatic-build" name="-verify-automatic-build"/>
+ <target depends="init" name="-check-automatic-build">
+ <available file="${build.modules.dir}/.netbeans_automatic_build" property="netbeans.automatic.build"/>
+ </target>
+ <target depends="init" if="netbeans.automatic.build" name="-clean-after-automatic-build">
+ <antcall target="clean">
+ <param name="no.dependencies" value="true"/>
+ </antcall>
+ </target>
+ <target name="-pre-pre-compile">
+ <mkdir dir="${build.modules.dir}"/>
+ </target>
+ <target name="-pre-compile">
+ <!-- Empty placeholder for easier customization. -->
+ <!-- You can override this target in the ../build.xml file. -->
+ </target>
+ <scriptdef language="javascript" name="coalesce_keyvalue" uri="http://www.netbeans.org/ns/j2se-modular-project/1">
+ <attribute name="property"/>
+ <attribute name="value"/>
+ <attribute name="value-sep"/>
+ <attribute name="entry-sep"/>
+ <attribute name="multi-sep"/>
+ <attribute name="out-sep"/>
+
+
+ function coalesce(input, keyValueSeparator, multiSeparator, entrySeparator) {
+ var result = [];
+ var values = {};
+
+ (typeof input === "string" ? input.split(entrySeparator) : input).forEach(function(entry) {
+ var idx = entry.indexOf(keyValueSeparator);
+ if (idx < 1) {
+ result.push(entry);
+ } else {
+ var key = entry.substring(0, idx);
+ var val = entry.substring(idx + 1);
+ if (!values[key]) {
+ values[key] = [];
+ }
+ values[key].push(val.trim());
+ }
+ });
+ Object.keys(values).sort().forEach(function(k) {
+ result.push(k + keyValueSeparator + values[k].join(multiSeparator));
+ });
+ return result.join(" " + entrySeparator);
+ }
+ self.project.setProperty(attributes.get("property"),
+ coalesce(attributes.get("value"),
+ attributes.get("value-sep"),
+ attributes.get("entry-sep"),
+ attributes.get("multi-sep")
+ ));
+
+
+
+ </scriptdef>
+ <scriptdef language="javascript" name="modsource_regexp" uri="http://www.netbeans.org/ns/j2se-modular-project/1">
+ <attribute name="property"/>
+ <attribute name="filePattern"/>
+ <attribute name="modsource"/>
+ function expandGroup(grp) {
+ var exp = [];
+ var item = "";
+ var depth = 0;
+
+ for (i = 0; i < grp.length; i++) {
+ var c = grp[i];
+ switch (c) {
+ case '{':
+ if (depth++ === 0) {
+ continue;
+ }
+ break;
+ case '}':
+ if (--depth === 0) {
+ exp.push(item);
+ continue;
+ }
+ break;
+ case ',':
+ if (depth === 1) {
+ exp.push(item);
+ item = "";
+ continue;
+ }
+ default:
+ break;
+ }
+ item = item + c;
+ }
+ return exp;
+ }
+
+ function pathVariants(spec, res) {
+ res = res || [];
+ var start = spec.indexOf('{');
+ if (start === -1) {
+ res.push(spec);
+ return res;
+ }
+ var depth = 1;
+ var end;
+ for (end = start + 1; end < spec.length && depth > 0; end++) {
+ var c = spec[end];
+ switch (c) {
+ case '{': depth++; break;
+ case '}': depth--; break;
+ }
+ }
+ var prefix = spec.substring(0, start);
+ var suffix = spec.substring(end);
+ expandGroup(spec.slice(start, end)).forEach(function (item) {
+ pathVariants(prefix + item + suffix, res);
+ })
+ return res;
+ }
+
+ function toRegexp2(spec, filepattern, separator) {
+ var prefixes = [];
+ var suffixes = [];
+ pathVariants(spec).forEach(function(item) {
+ suffixes.push(item);
+ });
+ var tail = "";
+ var separatorString = separator;
+ if (separatorString == "\\") {
+ separatorString = "\\\\";
+ }
+ if (filepattern && filepattern != tail) {
+ tail = separatorString + filepattern;
+ }
+ return "([^" + separatorString +"]+)\\Q" + separator + "\\E(" + suffixes.join("|") + ")" + tail;
+ }
+ self.project.setProperty(attributes.get("property"),
+ toRegexp2(attributes.get("modsource"), attributes.get("filepattern"), self.project.getProperty("file.separator")));
+
+
+
+
+ </scriptdef>
+ <target if="do.depend.true" name="-compile-depend">
+ <pathconvert property="build.generated.subdirs">
+ <dirset dir="${build.generated.sources.dir}" erroronmissingdir="false">
+ <include name="*"/>
+ </dirset>
+ </pathconvert>
+ <j2semodularproject1:depend xmlns:j2semodularproject1="http://www.netbeans.org/ns/j2se-modular-project/1" srcdir="${src.dir}:${src.gen.dir}:${build.generated.subdirs}"/>
+ </target>
+ <target depends="init,deps-jar,-pre-pre-compile,-pre-compile,-compile-depend" if="have.sources" name="-do-compile">
+ <j2semodularproject1:javac xmlns:j2semodularproject1="http://www.netbeans.org/ns/j2se-modular-project/1" gensrcdir="${build.generated.sources.dir}"/>
+ <j2semodularproject1:modsource_regexp xmlns:j2semodularproject1="http://www.netbeans.org/ns/j2se-modular-project/1" filePattern="(.*$)" modsource="${src.dir.path}" property="src.dir.path.regexp"/>
+ <echo message="Copying resources from ${src.dir}"/>
+ <copy todir="${build.modules.dir}">
+ <fileset dir="${src.dir}" excludes="${build.classes.excludes},${excludes}" includes="${includes}"/>
+ <regexpmapper from="${src.dir.path.regexp}" to="\1/\3"/>
+ </copy>
+ <j2semodularproject1:modsource_regexp xmlns:j2semodularproject1="http://www.netbeans.org/ns/j2se-modular-project/1" filePattern="(.*$)" modsource="${src.gen.dir.path}" property="src.gen.dir.path.regexp"/>
+ <echo message="Copying resources from ${src.gen.dir}"/>
+ <copy todir="${build.modules.dir}">
+ <fileset dir="${src.gen.dir}" excludes="${build.classes.excludes},${excludes}" includes="${includes}"/>
+ <regexpmapper from="${src.gen.dir.path.regexp}" to="\1/\3"/>
+ </copy>
+ </target>
+ <target if="has.persistence.xml" name="-copy-persistence-xml">
+ <fail message="XXX: Not supported on MM projects"/>
+ <mkdir dir="${build.classes.dir}/META-INF"/>
+ <copy todir="${build.classes.dir}/META-INF">
+ <fileset dir="${meta.inf.dir}" includes="persistence.xml orm.xml"/>
+ </copy>
+ </target>
+ <target name="-post-compile">
+ <!-- Empty placeholder for easier customization. -->
+ <!-- You can override this target in the ../build.xml file. -->
+ </target>
+ <target depends="init,deps-jar,-verify-automatic-build,-pre-pre-compile,-pre-compile,-do-compile,-post-compile" description="Compile project." name="compile"/>
+ <target name="-pre-compile-single">
+ <!-- Empty placeholder for easier customization. -->
+ <!-- You can override this target in the ../build.xml file. -->
+ </target>
+ <target depends="init,deps-jar" name="-do-compile-single">
+ <fail unless="javac.includes">Must select some files in the IDE or set javac.includes</fail>
+ <j2semodularproject1:force-recompile xmlns:j2semodularproject1="http://www.netbeans.org/ns/j2se-modular-project/1"/>
+ <j2semodularproject1:javac xmlns:j2semodularproject1="http://www.netbeans.org/ns/j2se-modular-project/1" excludes="" gensrcdir="${build.generated.sources.dir}" includes="${javac.includes}, module-info.java"/>
+ </target>
+ <target name="-post-compile-single">
+ <!-- Empty placeholder for easier customization. -->
+ <!-- You can override this target in the ../build.xml file. -->
+ </target>
+ <target depends="init,deps-jar,-verify-automatic-build,-pre-pre-compile,-pre-compile-single,-do-compile-single,-post-compile-single" name="compile-single"/>
+ <!--
+ ====================
+ JAR BUILDING SECTION
+ ====================
+ -->
+ <target depends="init,compile" name="-check-module-main-class">
+ <condition property="do.module.main.class">
+ <and>
+ <available file="${module.dir}/module-info.class"/>
+ <isset property="main.class.check.available"/>
+ </and>
+ </condition>
+ </target>
+ <target depends="init" name="-pre-pre-jar">
+ <dirname file="${dist.jar}" property="dist.jar.dir"/>
+ <mkdir dir="${dist.jar.dir}"/>
+ </target>
+ <target name="-pre-jar">
+ <!-- Empty placeholder for easier customization. -->
+ <!-- You can override this target in the ../build.xml file. -->
+ </target>
+ <target name="-pre-single-jar"/>
+ <target depends="-pre-single-jar" if="module.jar.filename" name="-make-single-jar">
+ <jar basedir="${module.dir}" compress="${jar.compress}" destfile="${dist.dir}/${module.jar.filename}" excludes="${dist.archive.excludes}" manifestencoding="UTF-8"/>
+ </target>
+ <target depends="init,compile,-pre-pre-jar,-pre-jar" if="do.archive" name="-do-jar-jar" unless="do.mkdist">
+ <property location="${build.modules.dir}" name="build.modules.dir.resolved"/>
+ <dirset dir="${build.modules.dir.resolved}" id="do.jar.dirs" includes="*"/>
+ <pathconvert property="do.jar.dir.list" refid="do.jar.dirs">
+ <identitymapper/>
+ </pathconvert>
+ <j2semodularproject1:for-paths xmlns:j2semodularproject1="http://www.netbeans.org/ns/j2se-modular-project/1" paths="${do.jar.dir.list}">
+ <local name="module.jar.filename"/>
+ <local name="module.jar.name.tmp"/>
+ <basename file="${entry}" property="module.jar.name.tmp"/>
+ <property name="module.jar.filename" value="${module.jar.name.tmp}.jar"/>
+ <antcall inheritRefs="true" target="-make-single-jar">
+ <param name="module.jar.filename" value="${module.jar.filename}"/>
+ <param location="${entry}" name="module.dir"/>
+ </antcall>
+ </j2semodularproject1:for-paths>
+ <property location="${build.classes.dir}" name="build.classes.dir.resolved"/>
+ <property location="${dist.jar}" name="dist.jar.resolved"/>
+ <pathconvert property="run.classpath.with.dist.jar">
+ <path path="${run.classpath}"/>
+ <map from="${build.classes.dir.resolved}" to="${dist.jar.resolved}"/>
+ </pathconvert>
+ <pathconvert property="run.modulepath.with.dist.jar">
+ <path path="${run.modulepath}"/>
+ <map from="${build.classes.dir.resolved}" to="${dist.jar.resolved}"/>
+ </pathconvert>
+ <condition else="" property="jar.usage.message.module.path" value=" -modulepath ${run.modulepath.with.dist.jar}">
+ <and>
+ <isset property="modules.supported.internal"/>
+ <length length="0" string="${run.modulepath.with.dist.jar}" when="greater"/>
+ </and>
+ </condition>
+ <condition else="" property="jar.usage.message.class.path" value=" -cp ${run.classpath.with.dist.jar}">
+ <length length="0" string="${run.classpath.with.dist.jar}" when="greater"/>
+ </condition>
+ <condition else=" ${main.class}" property="jar.usage.message.main.class" value=" -m ${module.name}/${main.class}">
+ <isset property="named.module.internal"/>
+ </condition>
+ <condition else="" property="jar.usage.message" value="To run this application from the command line without Ant, try:${line.separator}${platform.java}${jar.usage.message.module.path}${jar.usage.message.class.path}${jar.usage.message.main.class}">
+ <isset property="main.class.available"/>
+ </condition>
+ <condition else="debug" property="jar.usage.level" value="info">
+ <isset property="main.class.available"/>
+ </condition>
+ <echo level="${jar.usage.level}" message="${jar.usage.message}"/>
+ </target>
+ <target depends="init,compile,-pre-pre-jar,-pre-jar,-do-jar-jar" name="-do-jar-without-libraries"/>
+ <target depends="init,compile,-pre-pre-jar,-pre-jar" name="-do-jar-with-libraries"/>
+ <target name="-post-jar">
+ <!-- Empty placeholder for easier customization. -->
+ <!-- You can override this target in the ../build.xml file. -->
+ </target>
+ <target depends="init,compile,-pre-jar,-do-jar-without-libraries,-do-jar-with-libraries,-post-jar" name="-do-jar"/>
+ <target depends="init,compile,-pre-jar,-do-jar,-post-jar,deploy" description="Build JAR." name="jar"/>
+ <!--
+ =================
+ DEPLOY SECTION
+ =================
+ -->
+ <target name="-pre-deploy">
+ <!-- Empty placeholder for easier customization. -->
+ <!-- You can override this target in the ../build.xml file. -->
+ </target>
+ <target depends="init" name="-check-jlink">
+ <condition property="do.jlink.internal">
+ <and>
+ <istrue value="${do.jlink}"/>
+ <isset property="do.archive"/>
+ </and>
+ </condition>
+ </target>
+ <target depends="init,-do-jar,-post-jar,-pre-deploy,-check-jlink,-main-module-set" if="do.jlink.internal" name="-do-deploy">
+ <delete dir="${dist.jlink.dir}" failonerror="false" quiet="true"/>
+ <property name="jlink.launcher.name" value="${application.title}"/>
+ <pathconvert pathsep="," property="jlink.modulelist.internal">
+ <fileset dir="${dist.dir}" includes="*.jar"/>
+ <mapper>
+ <chainedmapper>
+ <flattenmapper/>
+ <globmapper from="*.jar" to="*"/>
+ </chainedmapper>
+ </mapper>
+ </pathconvert>
+ <condition else="${jlink.modulelist.internal}" property="jlink.add.modules" value="${jlink.modulelist.internal},${jlink.additionalmodules}">
+ <and>
+ <isset property="jlink.additionalmodules"/>
+ <length length="0" string="${jlink.additionalmodules}" when="greater"/>
+ </and>
+ </condition>
+ <condition property="jlink.do.strip.internal">
+ <and>
+ <isset property="jlink.strip"/>
+ <istrue value="${jlink.strip}"/>
+ </and>
+ </condition>
+ <condition property="jlink.do.additionalparam.internal">
+ <and>
+ <isset property="jlink.additionalparam"/>
+ <length length="0" string="${jlink.additionalparam}" when="greater"/>
+ </and>
+ </condition>
+ <condition property="jlink.do.launcher.internal">
+ <and>
+ <istrue value="${jlink.launcher}"/>
+ <isset property="module.name"/>
+ <length length="0" string="${module.name}" when="greater"/>
+ <isset property="main.class.available"/>
+ </and>
+ </condition>
+ <property name="platform.jlink" value="${jdk.home}/bin/jlink"/>
+ <property name="jlink.systemmodules.internal" value="${jdk.home}/jmods"/>
+ <exec executable="${platform.jlink}">
+ <arg value="--module-path"/>
+ <arg path="${jlink.systemmodules.internal}:${run.modulepath}:${dist.dir}"/>
+ <arg value="--add-modules"/>
+ <arg value="${jlink.add.modules}"/>
+ <arg if:set="jlink.do.strip.internal" value="--strip-debug"/>
+ <arg if:set="jlink.do.launcher.internal" value="--launcher"/>
+ <arg if:set="jlink.do.launcher.internal" value="${jlink.launcher.name}=${module.name}/${main.class}"/>
+ <arg if:set="jlink.do.additionalparam.internal" line="${jlink.additionalparam}"/>
+ <arg value="--output"/>
+ <arg value="${dist.jlink.output}"/>
+ </exec>
+ </target>
+ <target name="-post-deploy">
+ <!-- Empty placeholder for easier customization. -->
+ <!-- You can override this target in the ../build.xml file. -->
+ </target>
+ <target depends="-do-jar,-post-jar,-pre-deploy,-do-deploy,-post-deploy" name="deploy"/>
+ <!--
+ =================
+ EXECUTION SECTION
+ =================
+ -->
+ <target name="-check-main-class">
+ <fail unless="main.class">No main class specified</fail>
+ </target>
+ <target depends="init,compile,-check-main-class,-main-module-check" description="Run a main class." name="run">
+ <property name="main.class.relativepath" refid="main.class.relativepath"/>
+ <pathconvert pathsep="," property="src.dir.list" refid="have.sources.set"/>
+ <j2semodularproject1:modsource_regexp xmlns:j2semodularproject1="http://www.netbeans.org/ns/j2se-modular-project/1" filePattern="(.*$)" modsource="${src.dir.path}" property="run.src.dir.path.regexp"/>
+ <j2semodularproject1:java xmlns:j2semodularproject1="http://www.netbeans.org/ns/j2se-modular-project/1">
+ <customize>
+ <arg line="${application.args}"/>
+ </customize>
+ </j2semodularproject1:java>
+ </target>
+ <target name="-main-module-set" unless="module.name">
+ <condition else="${main.class}" property="check.class.name" value="${run.class}">
+ <isset property="run.class"/>
+ </condition>
+ <condition property="run.modules.dir" value="${build.modules.dir}">
+ <not>
+ <isset property="run.modules.dir"/>
+ </not>
+ </condition>
+ <resources id="main.class.relativepath">
+ <mappedresources>
+ <string value="${check.class.name}"/>
+ <unpackagemapper from="*" to="*.class"/>
+ </mappedresources>
+ </resources>
+ <property location="${run.modules.dir}" name="run.modules.dir.location"/>
+ <pathconvert property="module.name">
+ <fileset dir="${run.modules.dir}" includes="**/${toString:main.class.relativepath}"/>
+ <regexpmapper from="\Q${run.modules.dir.location}${file.separator}\E([^${file.separator.string}]+)\Q${file.separator}\E.*\.class" to="\1"/>
+ </pathconvert>
+ </target>
+ <target depends="-main-module-set" name="-main-module-check">
+ <fail message="Could not determine module of the main class and module.name is not set">
+ <condition>
+ <or>
+ <not>
+ <isset property="module.name"/>
+ </not>
+ <length length="0" string="${module.name}" when="equal"/>
+ </or>
+ </condition>
+ </fail>
+ </target>
+ <target name="-do-not-recompile">
+ <property name="javac.includes.binary" value=""/>
+ </target>
+ <target depends="init,compile-single,-main-module-check" name="run-single">
+ <fail unless="run.class">Must select one file in the IDE or set run.class</fail>
+ <j2semodularproject1:java xmlns:j2semodularproject1="http://www.netbeans.org/ns/j2se-modular-project/1" classname="${run.class}"/>
+ </target>
+ <target depends="init,compile-test-single,-init-test-run-module-properties,-main-module-check" name="run-test-with-main">
+ <fail unless="run.class">Must select one file in the IDE or set run.class</fail>
+ <j2semodularproject1:java xmlns:j2semodularproject1="http://www.netbeans.org/ns/j2se-modular-project/1" classname="${run.class}" classpath="${run.test.classpath}" modulepath="${run.test.modulepath}">
+ <customize>
+ <jvmarg line="${run.test.jvmargs}"/>
+ </customize>
+ </j2semodularproject1:java>
+ </target>
+ <!--
+ =================
+ DEBUGGING SECTION
+ =================
+ -->
+ <target name="-debug-init">
+ <condition else="${main.class}" property="run.class" value="${debug.class}">
+ <isset property="debug.class"/>
+ </condition>
+ <fail message="debug.class or main.class property is not set" unless="run.class"/>
+ </target>
+ <target depends="init,-debug-init,-main-module-check" if="netbeans.home" name="-debug-start-debugger">
+ <j2semodularproject1:nbjpdastart xmlns:j2semodularproject1="http://www.netbeans.org/ns/j2se-modular-project/1" name="${debug.class}"/>
+ </target>
+ <target depends="init,-debug-init,-main-module-check" if="netbeans.home" name="-debug-start-debugger-main-test">
+ <j2semodularproject1:nbjpdastart xmlns:j2semodularproject1="http://www.netbeans.org/ns/j2se-modular-project/1" classpath="${debug.test.classpath}" name="${debug.class}"/>
+ </target>
+ <target depends="init,compile,-debug-init,-main-module-check" name="-debug-start-debuggee">
+ <j2semodularproject1:debug xmlns:j2semodularproject1="http://www.netbeans.org/ns/j2se-modular-project/1" classname="${run.class}">
+ <customizeDebuggee>
+ <arg line="${application.args}"/>
+ </customizeDebuggee>
+ </j2semodularproject1:debug>
+ </target>
+ <target depends="init,compile,-debug-init,-main-module-check,-debug-start-debugger,-debug-start-debuggee" description="Debug project in IDE." if="netbeans.home" name="debug"/>
+ <target depends="init,-debug-init,-main-module-check" if="netbeans.home" name="-debug-start-debugger-stepinto">
+ <j2semodularproject1:nbjpdastart xmlns:j2semodularproject1="http://www.netbeans.org/ns/j2se-modular-project/1" stopclassname="${debug.class}"/>
+ </target>
+ <target depends="init,compile,-debug-start-debugger-stepinto,-debug-start-debuggee" if="netbeans.home" name="debug-stepinto"/>
+ <target depends="init,compile-single,-debug-init,-main-module-check" if="netbeans.home" name="-debug-start-debuggee-single">
+ <fail unless="debug.class">Must select one file in the IDE or set debug.class</fail>
+ <j2semodularproject1:debug xmlns:j2semodularproject1="http://www.netbeans.org/ns/j2se-modular-project/1" classname="${debug.class}"/>
+ </target>
+ <target depends="init,compile-single,-debug-start-debugger,-debug-start-debuggee-single" if="netbeans.home" name="debug-single"/>
+ <target depends="init,compile-test-single,-debug-init,-main-module-check" if="netbeans.home" name="-debug-start-debuggee-main-test">
+ <fail unless="debug.class">Must select one file in the IDE or set debug.class</fail>
+ <j2semodularproject1:debug xmlns:j2semodularproject1="http://www.netbeans.org/ns/j2se-modular-project/1" classname="${debug.class}" classpath="${debug.test.classpath}"/>
+ </target>
+ <target depends="init,compile-test-single,-debug-start-debugger-main-test,-debug-start-debuggee-main-test" if="netbeans.home" name="debug-test-with-main"/>
+ <target depends="init" name="-pre-debug-fix">
+ <fail unless="fix.includes">Must set fix.includes</fail>
+ <property name="javac.includes" value="${fix.includes}.java"/>
+ </target>
+ <target depends="init,-pre-debug-fix,compile-single" if="netbeans.home" name="-do-debug-fix">
+ <property location="${build.modules.dir}" name="debug.modules.dir"/>
+ <j2semodularproject1:nbjpdareload xmlns:j2semodularproject1="http://www.netbeans.org/ns/j2se-modular-project/1"/>
+ </target>
+ <target depends="init,-pre-debug-fix,-do-debug-fix" if="netbeans.home" name="debug-fix"/>
+ <!--
+ =================
+ PROFILING SECTION
+ =================
+ -->
+ <!--
+ pre NB7.2 profiler integration
+ -->
+ <target depends="profile-init,compile" description="Profile a project in the IDE." if="profiler.info.jvmargs.agent" name="-profile-pre72">
+ <fail unless="netbeans.home">This target only works when run from inside the NetBeans IDE.</fail>
+ <nbprofiledirect>
+ <classpath>
+ <path path="${run.classpath}"/>
+ </classpath>
+ </nbprofiledirect>
+ <profile/>
+ </target>
+ <target depends="profile-init,compile-single" description="Profile a selected class in the IDE." if="profiler.info.jvmargs.agent" name="-profile-single-pre72">
+ <fail unless="profile.class">Must select one file in the IDE or set profile.class</fail>
+ <fail unless="netbeans.home">This target only works when run from inside the NetBeans IDE.</fail>
+ <nbprofiledirect>
+ <classpath>
+ <path path="${run.classpath}"/>
+ </classpath>
+ </nbprofiledirect>
+ <profile classname="${profile.class}"/>
+ </target>
+ <target depends="profile-init,compile-single" if="profiler.info.jvmargs.agent" name="-profile-applet-pre72">
+ <fail unless="netbeans.home">This target only works when run from inside the NetBeans IDE.</fail>
+ <nbprofiledirect>
+ <classpath>
+ <path path="${run.classpath}"/>
+ </classpath>
+ </nbprofiledirect>
+ <profile classname="sun.applet.AppletViewer">
+ <customize>
+ <arg value="${applet.url}"/>
+ </customize>
+ </profile>
+ </target>
+ <target depends="-init-macrodef-junit,profile-init,compile-test-single" if="profiler.info.jvmargs.agent" name="-profile-test-single-pre72">
+ <fail unless="netbeans.home">This target only works when run from inside the NetBeans IDE.</fail>
+ <nbprofiledirect>
+ <classpath>
+ <path path="${run.test.classpath}"/>
+ </classpath>
+ </nbprofiledirect>
+ <j2semodularproject1:junit xmlns:j2semodularproject1="http://www.netbeans.org/ns/j2se-modular-project/1" excludes="${excludes}" includes="${includes}" testincludes="${profile.class}" testmethods="">
+ <customize>
+ <jvmarg value="-agentlib:jdwp=transport=${debug-transport},address=${jpda.address}"/>
+ <env key="${profiler.info.pathvar}" path="${profiler.info.agentpath}:${profiler.current.path}"/>
+ <jvmarg value="${profiler.info.jvmargs.agent}"/>
+ <jvmarg line="${profiler.info.jvmargs}"/>
+ <classpath>
+ <path path="${run.test.classpath}"/>
+ </classpath>
+ </customize>
+ </j2semodularproject1:junit>
+ </target>
+ <!--
+ end of pre NB72 profiling section
+ -->
+ <target if="netbeans.home" name="-profile-check">
+ <condition property="profiler.configured">
+ <or>
+ <contains casesensitive="true" string="${run.jvmargs.ide}" substring="-agentpath:"/>
+ <contains casesensitive="true" string="${run.jvmargs.ide}" substring="-javaagent:"/>
+ </or>
+ </condition>
+ </target>
+ <target depends="-profile-check,-profile-pre72" description="Profile a project in the IDE." if="profiler.configured" name="profile" unless="profiler.info.jvmargs.agent">
+ <startprofiler/>
+ <antcall target="run"/>
+ </target>
+ <target depends="-profile-check,-profile-single-pre72" description="Profile a selected class in the IDE." if="profiler.configured" name="profile-single" unless="profiler.info.jvmargs.agent">
+ <fail unless="run.class">Must select one file in the IDE or set run.class</fail>
+ <startprofiler/>
+ <antcall target="run-single"/>
+ </target>
+ <target depends="-profile-test-single-pre72" description="Profile a selected test in the IDE." name="profile-test-single"/>
+ <target depends="-profile-check" description="Profile a selected test in the IDE." if="profiler.configured" name="profile-test" unless="profiler.info.jvmargs">
+ <fail unless="test.includes">Must select some files in the IDE or set test.includes</fail>
+ <startprofiler/>
+ <antcall target="test-single"/>
+ </target>
+ <target depends="-profile-check" description="Profile a selected class in the IDE." if="profiler.configured" name="profile-test-with-main">
+ <fail unless="run.class">Must select one file in the IDE or set run.class</fail>
+ <startprofiler/>
+ <antcall target="run-test-with-main"/>
+ </target>
+ <target depends="-profile-check,-profile-applet-pre72" if="profiler.configured" name="profile-applet" unless="profiler.info.jvmargs.agent">
+ <fail unless="applet.url">Must select one file in the IDE or set applet.url</fail>
+ <startprofiler/>
+ <antcall target="run-applet"/>
+ </target>
+ <!--
+ ===============
+ JAVADOC SECTION
+ ===============
+ -->
+ <target depends="init" if="have.sources" name="-javadoc-build">
+ <mkdir dir="${dist.javadoc.dir}"/>
+ <condition else="" property="javadoc.endorsed.classpath.cmd.line.arg" value="-J${endorsed.classpath.cmd.line.arg}">
+ <and>
+ <isset property="endorsed.classpath.cmd.line.arg"/>
+ <not>
+ <equals arg1="${endorsed.classpath.cmd.line.arg}" arg2=""/>
+ </not>
+ </and>
+ </condition>
+ <condition else="" property="bug5101868workaround" value="*.java">
+ <matches pattern="1\.[56](\..*)?" string="${java.version}"/>
+ </condition>
+ <condition else="" property="javadoc.html5.cmd.line.arg" value="-html5">
+ <and>
+ <isset property="javadoc.html5"/>
+ <available file="${jdk.home}${file.separator}lib${file.separator}jrt-fs.jar"/>
+ </and>
+ </condition>
+ <javadoc additionalparam="-J-Dfile.encoding=${file.encoding} ${javadoc.additionalparam}" author="${javadoc.author}" charset="UTF-8" destdir="${dist.javadoc.dir}" docencoding="UTF-8" encoding="${javadoc.encoding.used}" failonerror="true" noindex="${javadoc.noindex}" nonavbar="${javadoc.nonavbar}" notree="${javadoc.notree}" private="${javadoc.private}" source="${javac.source}" splitindex="${javadoc.splitindex}" use="${javadoc.use}" useexternalfile="true" version="${javadoc.version}" windowtitle="${javadoc.windowtitle}">
+ <classpath>
+ <path path="${javac.classpath}"/>
+ </classpath>
+ <fileset dir="${src.dir}" excludes="${bug5101868workaround},${excludes}" includes="${includes}">
+ <filename name="**/*.java"/>
+ </fileset>
+ <fileset dir="${src.gen.dir}" excludes="${bug5101868workaround},${excludes}" includes="${includes}">
+ <filename name="**/*.java"/>
+ </fileset>
+ <fileset dir="${build.generated.sources.dir}" erroronmissingdir="false">
+ <include name="**/*.java"/>
+ <exclude name="*.java"/>
+ </fileset>
+ <arg line="${javadoc.endorsed.classpath.cmd.line.arg}"/>
+ <arg line="${javadoc.html5.cmd.line.arg}"/>
+ </javadoc>
+ <copy todir="${dist.javadoc.dir}">
+ <fileset dir="${src.dir}" excludes="${excludes}" includes="${includes}">
+ <filename name="**/doc-files/**"/>
+ </fileset>
+ <fileset dir="${src.gen.dir}" excludes="${excludes}" includes="${includes}">
+ <filename name="**/doc-files/**"/>
+ </fileset>
+ <fileset dir="${build.generated.sources.dir}" erroronmissingdir="false">
+ <include name="**/doc-files/**"/>
+ </fileset>
+ </copy>
+ </target>
+ <target depends="init,-javadoc-build" if="netbeans.home" name="-javadoc-browse" unless="no.javadoc.preview">
+ <nbbrowse file="${dist.javadoc.dir}/index.html"/>
+ </target>
+ <target depends="init,-javadoc-build,-javadoc-browse" description="Build Javadoc." name="javadoc"/>
+ <!--
+ =========================
+ TEST COMPILATION SECTION
+ =========================
+ -->
+ <target depends="init,compile" if="have.tests" name="-pre-pre-compile-test">
+ <mkdir dir="${build.test.modules.dir}"/>
+ </target>
+ <target name="-pre-compile-test">
+ <!-- Empty placeholder for easier customization. -->
+ <!-- You can override this target in the ../build.xml file. -->
+ </target>
+ <target depends="-init-source-module-properties" name="-init-test-run-module-properties">
+ <fileset dir="${build.test.modules.dir}" id="run.test.packages.internal" includes="**/*.class"/>
+ <property location="${build.test.modules.dir}" name="build.test.modules.dir.abs.internal"/>
+ <pathconvert pathsep=" " property="run.test.addexports.internal" refid="run.test.packages.internal">
+ <chainedmapper>
+ <filtermapper>
+ <replacestring from="${build.test.modules.dir.abs.internal}${file.separator}" to=""/>
+ </filtermapper>
+ <regexpmapper from="^([^${file.separator.string}]*)\Q${file.separator}\E(.*)\Q${file.separator}\E.*\.class$$" to="\1${path.separator}\2"/>
+ <filtermapper>
+ <uniqfilter/>
+ <replacestring from="${file.separator}" to="."/>
+ </filtermapper>
+ <regexpmapper from="([^${file.separator.string}]+)${path.separator}(.*)" to="--add-exports \1/\2=ALL-UNNAMED"/>
+ </chainedmapper>
+ </pathconvert>
+ <property location="${build.test.modules.dir}" name="build.test.modules.location"/>
+ <pathconvert pathsep="," property="run.test.addmodules.list">
+ <map from="${build.test.modules.location}${file.separator}" to=""/>
+ <dirset dir="${build.test.modules.dir}" includes="*"/>
+ <chainedmapper>
+ <filtermapper>
+ <uniqfilter/>
+ </filtermapper>
+ </chainedmapper>
+ </pathconvert>
+ <pathconvert pathsep=" " property="run.test.patchmodules.list">
+ <dirset dir="${build.test.modules.dir}" includes="*">
+ <scriptselector language="javascript">
+ self.setSelected(!new java.io.File(file, "module-info.class").exists());
+ </scriptselector>
+ </dirset>
+ <chainedmapper>
+ <filtermapper>
+ <uniqfilter/>
+ </filtermapper>
+ <regexpmapper from=".*\Q${file.separator}\E([^${file.separator.string}]+)$" to="--patch-module \1=\0"/>
+ </chainedmapper>
+ </pathconvert>
+ <j2semodularproject1:coalesce_keyvalue xmlns:j2semodularproject1="http://www.netbeans.org/ns/j2se-modular-project/1" entry-sep="${path.separator}" multi-sep="--patch-module " property="run.test.patchmodules" value="${run.test.patchmodules.list}" value-sep="="/>
+ <condition else="" property="run.test.addmodules.internal" value="--add-modules ${run.test.addmodules.list}">
+ <isset property="run.test.addmodules.list"/>
+ </condition>
+ <pathconvert pathsep=" " property="run.test.addreads.internal">
+ <map from="${build.test.modules.location}" to=""/>
+ <dirset dir="${build.test.modules.dir}" includes="*"/>
+ <chainedmapper>
+ <regexpmapper from="^\Q${build.test.modules.location}${file.separator}\E(.*)" to="\1"/>
+ <regexpmapper from="(.*)" to="--add-reads \1=ALL-UNNAMED"/>
+ <filtermapper>
+ <uniqfilter/>
+ </filtermapper>
+ </chainedmapper>
+ </pathconvert>
+ <property name="run.test.jvmargs" value="${run.test.addmodules.internal} ${run.test.addreads.internal} ${run.test.addexports.internal} ${run.test.patchmodules}"/>
+ </target>
+ <target depends="-init-source-module-properties" name="-init-test-javac-module-properties">
+ <pathconvert pathsep=" " property="compile.test.patchmodule.internal" refid="have.tests.patchset">
+ <regexpmapper from="(.*\Q${file.separator}\E)([^${file.separator.string}]+)\Q${file.separator}\E(.*)$$" to="--patch-module \2=\1\2${file.separator.string}\3"/>
+ </pathconvert>
+ <pathconvert pathsep=" " property="compile.test.addreads">
+ <union refid="have.tests.set"/>
+ <chainedmapper>
+ <firstmatchmapper>
+ <regexpmapper from="${have.tests.test.src.dir.regexp}" to="\1"/>
+ </firstmatchmapper>
+ <regexpmapper from="(.*)" to="--add-reads \1=ALL-UNNAMED"/>
+ <filtermapper>
+ <uniqfilter/>
+ </filtermapper>
+ </chainedmapper>
+ </pathconvert>
+ <j2semodularproject1:coalesce_keyvalue xmlns:j2semodularproject1="http://www.netbeans.org/ns/j2se-modular-project/1" entry-sep="${path.separator}" multi-sep="--patch-module " property="compile.test.patchmodules" value="${compile.test.patchmodule.internal}" value-sep="="/>
+ <property name="javac.test.moduleargs" value="${compile.test.patchmodules} ${compile.test.addreads}"/>
+ </target>
+ <target depends="-init-test-javac-module-properties" name="-init-test-module-properties">
+ <property location="${build.modules.dir}" name="test.module.build.location"/>
+ <property name="test.source.modulepath" value="${test.src.dir}/*/${test.src.dir.path}"/>
+ <property name="test.compile.modulepath" value="${javac.test.modulepath}:${build.modules.dir}"/>
+ <macrodef name="test-javac" uri="http://www.netbeans.org/ns/j2se-modular-project/1">
+ <attribute default="${includes}" name="includes"/>
+ <attribute default="${excludes}" name="excludes"/>
+ <element implicit="true" name="additionalargs" optional="true"/>
+ <sequential>
+ <j2semodularproject1:javac xmlns:j2semodularproject1="http://www.netbeans.org/ns/j2se-modular-project/1" apgeneratedsrcdir="${build.test.modules.dir}" classpath="${javac.test.classpath}" debug="true" destdir="${build.test.modules.dir}" excludes="@{excludes}" includes="@{includes}" modulepath="${test.compile.modulepath}" modulesourcepath="${test.source.modulepath}" processorpath="${javac.test.processorpath}">
+ <customize>
+ <compilerarg line="${javac.test.moduleargs}"/>
+ <additionalargs/>
+ </customize>
+ </j2semodularproject1:javac>
+ </sequential>
+ </macrodef>
+ </target>
+ <target if="do.depend.true" name="-compile-test-depend">
+ <j2semodularproject1:depend xmlns:j2semodularproject1="http://www.netbeans.org/ns/j2se-modular-project/1" classpath="${javac.test.classpath}" destdir="${build.test.classes.dir}" srcdir="${test.src.dir}"/>
+ </target>
+ <target depends="init,deps-jar,compile,-init-test-module-properties,-pre-pre-compile-test,-pre-compile-test,-compile-test-depend" if="have.tests" name="-do-compile-test">
+ <j2semodularproject1:test-javac xmlns:j2semodularproject1="http://www.netbeans.org/ns/j2se-modular-project/1"/>
+ <j2semodularproject1:modsource_regexp xmlns:j2semodularproject1="http://www.netbeans.org/ns/j2se-modular-project/1" filePattern="(.*$)" modsource="${test.src.dir.path}" property="test.src.dir.path.regexp"/>
+ <echo message="Copying resources from ${test.src.dir}"/>
+ <copy todir="${build.test.modules.dir}">
+ <fileset dir="${test.src.dir}" excludes="${build.classes.excludes},${excludes}" includes="${includes}"/>
+ <regexpmapper from="${test.src.dir.path.regexp}" to="\1/\3"/>
+ </copy>
+ </target>
+ <target name="-post-compile-test">
+ <!-- Empty placeholder for easier customization. -->
+ <!-- You can override this target in the ../build.xml file. -->
+ </target>
+ <target depends="init,compile,-pre-pre-compile-test,-pre-compile-test,-do-compile-test,-post-compile-test" name="compile-test"/>
+ <target name="-pre-compile-test-single">
+ <!-- Empty placeholder for easier customization. -->
+ <!-- You can override this target in the ../build.xml file. -->
+ </target>
+ <target depends="init,deps-jar,compile,-init-test-module-properties,-pre-pre-compile-test,-pre-compile-test-single" if="have.tests" name="-do-compile-test-single">
+ <fail unless="javac.includes">Must select some files in the IDE or set javac.includes</fail>
+ <j2semodularproject1:force-recompile xmlns:j2semodularproject1="http://www.netbeans.org/ns/j2se-modular-project/1" destdir="${build.test.modules.dir}"/>
+ <j2semodularproject1:test-javac xmlns:j2semodularproject1="http://www.netbeans.org/ns/j2se-modular-project/1" includes="${javac.includes}"/>
+ <j2semodularproject1:modsource_regexp xmlns:j2semodularproject1="http://www.netbeans.org/ns/j2se-modular-project/1" filePattern="(.*$)" modsource="${test.src.dir.path}" property="test.src.dir.path.regexp"/>
+ <echo message="Copying resources from ${test.src.dir}"/>
+ <copy todir="${build.test.modules.dir}">
+ <fileset dir="${test.src.dir}" excludes="${build.classes.excludes},${excludes}" includes="${includes}"/>
+ <regexpmapper from="${test.src.dir.path.regexp}" to="\1/\3"/>
+ </copy>
+ </target>
+ <target name="-post-compile-test-single">
+ <!-- Empty placeholder for easier customization. -->
+ <!-- You can override this target in the ../build.xml file. -->
+ </target>
+ <target depends="init,compile,-pre-pre-compile-test,-pre-compile-test-single,-do-compile-test-single,-post-compile-test-single" name="compile-test-single"/>
+ <!--
+ =======================
+ TEST EXECUTION SECTION
+ =======================
+ -->
+ <target depends="init" if="have.tests" name="-pre-test-run">
+ <mkdir dir="${build.test.results.dir}"/>
+ </target>
+ <target name="-init-test-run">
+ <property name="run.modules.dir" value="${build.test.modules.dir}"/>
+ </target>
+ <target depends="init,compile-test,-init-test-run-module-properties,-pre-test-run" if="have.tests" name="-do-test-run">
+ <j2semodularproject1:test xmlns:j2semodularproject1="http://www.netbeans.org/ns/j2se-modular-project/1" includes="${includes}" testincludes="**/*Test.java"/>
+ </target>
+ <target depends="init,compile-test,-pre-test-run,-do-test-run" if="have.tests" name="-post-test-run">
+ <fail if="tests.failed" unless="ignore.failing.tests">Some tests failed; see details above.</fail>
+ </target>
+ <target depends="init" if="have.tests" name="test-report"/>
+ <target depends="init" if="netbeans.home+have.tests" name="-test-browse"/>
+ <target depends="init,compile-test,-pre-test-run,-do-test-run,test-report,-post-test-run,-test-browse" description="Run unit tests." name="test"/>
+ <target depends="init" if="have.tests" name="-pre-test-run-single">
+ <mkdir dir="${build.test.results.dir}"/>
+ </target>
+ <target depends="init,compile-test-single,-init-test-run-module-properties,-pre-test-run-single" if="have.tests" name="-do-test-run-single">
+ <fail unless="test.includes">Must select some files in the IDE or set test.includes</fail>
+ <j2semodularproject1:test xmlns:j2semodularproject1="http://www.netbeans.org/ns/j2se-modular-project/1" excludes="" includes="${test.includes}" testincludes="${test.includes}"/>
+ </target>
+ <target depends="init,compile-test-single,-pre-test-run-single,-do-test-run-single" if="have.tests" name="-post-test-run-single">
+ <fail if="tests.failed" unless="ignore.failing.tests">Some tests failed; see details above.</fail>
+ </target>
+ <target depends="init,compile-test-single,-init-test-run-module-properties,-pre-test-run-single,-do-test-run-single,-post-test-run-single" description="Run single unit test." name="test-single"/>
+ <target depends="init,compile-test-single,-pre-test-run-single" if="have.tests" name="-do-test-run-single-method">
+ <fail unless="test.class">Must select some files in the IDE or set test.class</fail>
+ <fail unless="test.method">Must select some method in the IDE or set test.method</fail>
+ <j2semodularproject1:test xmlns:j2semodularproject1="http://www.netbeans.org/ns/j2se-modular-project/1" excludes="" includes="${javac.includes}" testincludes="${test.class}" testmethods="${test.method}"/>
+ </target>
+ <target depends="init,compile-test-single,-pre-test-run-single,-do-test-run-single-method" if="have.tests" name="-post-test-run-single-method">
+ <fail if="tests.failed" unless="ignore.failing.tests">Some tests failed; see details above.</fail>
+ </target>
+ <target depends="init,compile-test-single,-init-test-run-module-properties,-pre-test-run-single,-do-test-run-single-method,-post-test-run-single-method" description="Run single unit test." name="test-single-method"/>
+ <!--
+ =======================
+ TEST DEBUGGING SECTION
+ =======================
+ -->
+ <target depends="init,compile-test-single,-init-test-run-module-properties,-pre-test-run-single" if="have.tests" name="-debug-start-debuggee-test">
+ <fail unless="test.class">Must select one file in the IDE or set test.class</fail>
+ <j2semodularproject1:test-debug xmlns:j2semodularproject1="http://www.netbeans.org/ns/j2se-modular-project/1" excludes="" includes="${javac.includes}" testClass="${test.class}" testincludes="${javac.includes}"/>
+ </target>
+ <target depends="init,compile-test-single,-init-test-run-module-properties,-pre-test-run-single" if="have.tests" name="-debug-start-debuggee-test-method">
+ <fail unless="test.class">Must select one file in the IDE or set test.class</fail>
+ <fail unless="test.method">Must select some method in the IDE or set test.method</fail>
+ <j2semodularproject1:test-debug xmlns:j2semodularproject1="http://www.netbeans.org/ns/j2se-modular-project/1" excludes="" includes="${javac.includes}" testClass="${test.class}" testMethod="${test.method}" testincludes="${test.class}" testmethods="${test.method}"/>
+ </target>
+ <target depends="init,compile-test" if="netbeans.home+have.tests" name="-debug-start-debugger-test">
+ <j2semodularproject1:nbjpdastart xmlns:j2semodularproject1="http://www.netbeans.org/ns/j2se-modular-project/1" classpath="${debug.test.classpath}" name="${test.class}"/>
+ </target>
+ <target depends="init,compile-test-single,-init-test-run-module-properties,-debug-start-debugger-test,-debug-start-debuggee-test" name="debug-test"/>
+ <target depends="init,compile-test-single,-init-test-run-module-properties,-debug-start-debugger-test,-debug-start-debuggee-test-method" name="debug-test-method"/>
+ <target depends="init,-pre-debug-fix,compile-test-single" if="netbeans.home" name="-do-debug-fix-test">
+ <property name="debug.modules.dir" value="${build.test.modules.dir}"/>
+ <j2semodularproject1:nbjpdareload xmlns:j2semodularproject1="http://www.netbeans.org/ns/j2se-modular-project/1"/>
+ </target>
+ <target depends="init,-pre-debug-fix,-do-debug-fix-test" if="netbeans.home" name="debug-fix-test"/>
+ <!--
+ =========================
+ APPLET EXECUTION SECTION
+ =========================
+ -->
+ <target name="run-applet">
+ <fail message="Applets are no longer supported by JDK 9"/>
+ </target>
+ <!--
+ =========================
+ APPLET DEBUGGING SECTION
+ =========================
+ -->
+ <target name="-debug-start-debuggee-applet">
+ <fail message="Applets are no longer supported by JDK 9"/>
+ </target>
+ <target name="debug-applet">
+ <fail message="Applets are no longer supported by JDK 9"/>
+ </target>
+ <!--
+ ===============
+ CLEANUP SECTION
+ ===============
+ -->
+ <target name="-deps-clean-init" unless="built-clean.properties">
+ <property location="${build.dir}/built-clean.properties" name="built-clean.properties"/>
+ <delete file="${built-clean.properties}" quiet="true"/>
+ </target>
+ <target if="already.built.clean.${basedir}" name="-warn-already-built-clean">
+ <echo level="warn" message="Cycle detected: notzed.jjmpeg was already built"/>
+ </target>
+ <target depends="init,-deps-clean-init" name="deps-clean" unless="no.deps">
+ <mkdir dir="${build.dir}"/>
+ <touch file="${built-clean.properties}" verbose="false"/>
+ <property file="${built-clean.properties}" prefix="already.built.clean."/>
+ <antcall target="-warn-already-built-clean"/>
+ <propertyfile file="${built-clean.properties}">
+ <entry key="${basedir}" value=""/>
+ </propertyfile>
+ <antcall target="-maybe-call-dep">
+ <param name="call.built.properties" value="${built-clean.properties}"/>
+ <param location="${project.notzed_nativez}" name="call.subproject"/>
+ <param location="${project.notzed_nativez}/build.xml" name="call.script"/>
+ <param name="call.target" value="clean"/>
+ <param name="transfer.built-clean.properties" value="${built-clean.properties}"/>
+ <param name="transfer.not.archive.disabled" value="true"/>
+ <param name="transfer.do.jlink" value="false"/>
+ </antcall>
+ </target>
+ <target depends="init" name="-do-clean">
+ <delete dir="${build.dir}"/>
+ <delete dir="${dist.jlink.output}"/>
+ <delete dir="${dist.dir}" followsymlinks="false" includeemptydirs="true"/>
+ </target>
+ <target name="-post-clean">
+ <!-- Empty placeholder for easier customization. -->
+ <!-- You can override this target in the ../build.xml file. -->
+ </target>
+ <target depends="init,deps-clean,-do-clean,-post-clean" description="Clean build products." name="clean"/>
+ <target name="-check-call-dep">
+ <property file="${call.built.properties}" prefix="already.built."/>
+ <condition property="should.call.dep">
+ <and>
+ <not>
+ <isset property="already.built.${call.subproject}"/>
+ </not>
+ <available file="${call.script}"/>
+ </and>
+ </condition>
+ </target>
+ <target depends="-check-call-dep" if="should.call.dep" name="-maybe-call-dep">
+ <ant antfile="${call.script}" inheritall="false" target="${call.target}">
+ <propertyset>
+ <propertyref prefix="transfer."/>
+ <mapper from="transfer.*" to="*" type="glob"/>
+ </propertyset>
+ </ant>
+ </target>
+</project>
--- /dev/null
+build.xml.data.CRC32=508a6882
+build.xml.script.CRC32=b55362bc
+build.xml.stylesheet.CRC32=32069288@1.6.1
+# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml.
+# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you.
+nbproject/build-impl.xml.data.CRC32=6ecd1560
+nbproject/build-impl.xml.script.CRC32=2c0bce54
+nbproject/build-impl.xml.stylesheet.CRC32=0f0529df@1.6.1
--- /dev/null
+annotation.processing.enabled=true
+annotation.processing.enabled.in.editor=false
+annotation.processing.processors.list=
+annotation.processing.run.all.processors=true
+annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output
+application.title=notzed.jjmpeg
+application.vendor=notzed
+build.classes.dir=${build.dir}/classes
+build.classes.excludes=**/*.java,**/*.form
+# This directory is removed when the project is cleaned:
+build.dir=build
+build.generated.dir=${build.dir}/generated
+build.generated.sources.dir=${build.dir}/generated-sources
+build.modules.dir=${build.dir}/modules
+# Only compile against the classpath explicitly listed here:
+build.sysclasspath=ignore
+build.test.classes.dir=${build.dir}/test/classes
+build.test.modules.dir=${build.dir}/test/modules
+build.test.results.dir=${build.dir}/test/results
+# Uncomment to specify the preferred debugger connection transport:
+#debug.transport=dt_socket
+debug.classpath=\
+ ${run.classpath}
+debug.modulepath=\
+ ${run.modulepath}
+debug.test.classpath=\
+ ${run.test.classpath}
+debug.test.modulepath=\
+ ${run.test.modulepath}
+# Files in build.classes.dir which should be excluded from distribution jar
+dist.archive.excludes=
+# This directory is removed when the project is cleaned:
+dist.dir=dist
+dist.javadoc.dir=${dist.dir}/javadoc
+dist.jlink.dir=${dist.dir}/jlink
+dist.jlink.output=${dist.jlink.dir}/notzed.jjmpeg
+endorsed.classpath=
+excludes=
+file.reference.javafx.base.jar=/data/linux-amd64/javafx-sdk-11.0.2/lib/javafx.base.jar
+file.reference.javafx.controls.jar=/data/linux-amd64/javafx-sdk-11.0.2/lib/javafx.controls.jar
+file.reference.javafx.graphics.jar=/data/linux-amd64/javafx-sdk-11.0.2/lib/javafx.graphics.jar
+includes=**
+jar.compress=false
+javac.classpath=
+# Space-separated list of extra javac options
+javac.compilerargs=-Xlint:unchecked
+javac.deprecation=false
+javac.external.vm=false
+javac.modulepath=\
+ ${file.reference.javafx.base.jar}:\
+ ${file.reference.javafx.graphics.jar}:\
+ ${file.reference.javafx.controls.jar}:\
+ ${reference.notzed_nativez.notzed_nativez_jar}
+javac.processormodulepath=
+javac.processorpath=\
+ ${javac.classpath}
+javac.source=11
+javac.target=11
+javac.test.classpath=\
+ ${javac.classpath}
+javac.test.modulepath=\
+ ${javac.modulepath}:\
+ ${build.modules.dir}
+javac.test.processorpath=\
+ ${javac.test.classpath}
+javadoc.additionalparam=
+javadoc.author=false
+javadoc.encoding=${source.encoding}
+javadoc.html5=false
+javadoc.noindex=false
+javadoc.nonavbar=false
+javadoc.notree=false
+javadoc.private=false
+javadoc.splitindex=true
+javadoc.use=true
+javadoc.version=false
+javadoc.windowtitle=
+# The jlink additional root modules to resolve
+jlink.additionalmodules=
+# The jlink additional command line parameters
+jlink.additionalparam=
+jlink.launcher=true
+jlink.launcher.name=notzed.jjmpeg
+platform.active=default_platform
+project.notzed_nativez=../nativez
+reference.notzed_nativez.notzed_nativez_jar=${project.notzed_nativez}/dist/notzed.nativez.jar
+run.classpath=
+# Space-separated list of JVM arguments used when running the project.
+# You may also define separate properties like run-sys-prop.name=value instead of -Dname=value.
+# To set system properties for unit tests define test-sys-prop.name=value:
+run.jvmargs=-Djava.library.path=bin/notzed.jjmpeg/linux-amd64/lib:../nativez/bin/notzed.nativez/linux-amd64/lib
+run.modulepath=\
+ ${javac.modulepath}:\
+ ${build.modules.dir}
+run.test.classpath=\
+ ${javac.test.classpath}
+run.test.modulepath=\
+ ${javac.test.modulepath}:\
+ ${build.test.modules.dir}
+source.encoding=UTF-8
+src.dir=src
+src.dir.path=classes
+src.gen.dir=bin/gen
+src.gen.dir.path=classes
+test.src.dir=src
+test.src.dir.path=tests
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://www.netbeans.org/ns/project/1">
+ <type>org.netbeans.modules.java.j2semodule</type>
+ <configuration>
+ <data xmlns="http://www.netbeans.org/ns/j2se-modular-project/1">
+ <name>notzed.jjmpeg</name>
+ <source-roots>
+ <root id="src.dir" pathref="src.dir.path"/>
+ <root id="src.gen.dir" pathref="src.gen.dir.path"/>
+ </source-roots>
+ <test-roots>
+ <root id="test.src.dir" pathref="test.src.dir.path"/>
+ </test-roots>
+ </data>
+ <references xmlns="http://www.netbeans.org/ns/ant-project-references/1">
+ <reference>
+ <foreign-project>notzed_nativez</foreign-project>
+ <artifact-type>jar</artifact-type>
+ <script>build.xml</script>
+ <target>jar</target>
+ <clean-target>clean</clean-target>
+ <id>notzed.nativez.jar</id>
+ </reference>
+ </references>
+ </configuration>
+</project>
--- /dev/null
+/*
+ * Copyright (C) 2017 Michael Zucchi
+ *
+ * This file is part of jjmpeg <https://www.zedzone.space/software/jjmpeg.html>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+package au.notzed.jjmpeg.awt;
+
+import au.notzed.jjmpeg.AVPixelFormat;
+import au.notzed.jjmpeg.AVPixelReader;
+import java.awt.image.BufferedImage;
+import java.awt.image.DataBufferByte;
+import java.awt.image.DataBufferInt;
+import java.awt.image.DataBufferUShort;
+import java.nio.Buffer;
+
+/**
+ * A java2d PixelReader that reads from an AVPixelReader directly.
+ * <p>
+ * There are some limitations in that the pixel reader should only
+ * convert the whole image at a time. Stripes may work in the future.
+ */
+public class JavaPixelReader implements AVPixelReader {
+
+ final AVPixelReader reader;
+
+ public JavaPixelReader(AVPixelReader reader) {
+ this.reader = reader;
+ }
+
+ private int typeToFormat(int type) {
+ switch (type) {
+ case BufferedImage.TYPE_3BYTE_BGR:
+ return AVPixelFormat.AV_PIX_FMT_BGR24;
+ case BufferedImage.TYPE_BYTE_GRAY:
+ return AVPixelFormat.AV_PIX_FMT_GRAY8;
+ case BufferedImage.TYPE_USHORT_GRAY:
+ return AVPixelFormat.AV_PIX_FMT_GRAY16;
+ case BufferedImage.TYPE_INT_BGR:
+ return AVPixelFormat.AV_PIX_FMT_RGBA;
+ case BufferedImage.TYPE_INT_ARGB:
+ return AVPixelFormat.AV_PIX_FMT_BGRA;
+ }
+ throw new RuntimeException("Unsupported Java image conversion format");
+ }
+
+ public void getPixels(int y, int h, BufferedImage dst) {
+ int type = dst.getType();
+ int fmt = typeToFormat(type);
+
+ switch (type) {
+ case BufferedImage.TYPE_3BYTE_BGR: {
+ byte[] data = ((DataBufferByte) dst.getRaster().getDataBuffer()).getData();
+ getPixels(y, h, fmt, data, 0, dst.getWidth() * 3);
+ break;
+ }
+ case BufferedImage.TYPE_BYTE_GRAY: {
+ byte[] data = ((DataBufferByte) dst.getRaster().getDataBuffer()).getData();
+ getPixels(y, h, fmt, data, 0, dst.getWidth());
+ break;
+ }
+ case BufferedImage.TYPE_USHORT_GRAY: {
+ short[] data = ((DataBufferUShort) dst.getRaster().getDataBuffer()).getData();
+ getPixels(y, h, fmt, data, 0, dst.getWidth());
+ break;
+ }
+ case BufferedImage.TYPE_INT_BGR:
+ case BufferedImage.TYPE_INT_ARGB: {
+ int[] data = ((DataBufferInt) dst.getRaster().getDataBuffer()).getData();
+
+ getPixels(y, h, fmt, data, 0, dst.getWidth());
+ break;
+ }
+ }
+ }
+
+ @Override
+ public <T extends Buffer> void getPixels(int y, int h, int fmt, T buffer, int scanlineStride) {
+ reader.getPixels(y, h, fmt, buffer, scanlineStride);
+ }
+
+ @Override
+ public void getPixels(int y, int h, int fmt, byte[] buffer, int offset, int scanlineStride) {
+ reader.getPixels(y, h, fmt, buffer, offset, scanlineStride);
+ }
+
+ @Override
+ public void getPixels(int y, int h, int fmt, short[] buffer, int offset, int scanlineStride) {
+ reader.getPixels(y, h, fmt, buffer, offset, scanlineStride);
+ }
+
+ @Override
+ public void getPixels(int y, int h, int fmt, int[] buffer, int offset, int scanlineStride) {
+ reader.getPixels(y, h, fmt, buffer, offset, scanlineStride);
+ }
+}
--- /dev/null
+/*
+ * Copyright (C) 2017 Michael Zucchi
+ *
+ * This file is part of jjmpeg <https://www.zedzone.space/software/jjmpeg.html>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+package au.notzed.jjmpeg.awt;
+
+import au.notzed.jjmpeg.AVPixelFormat;
+import au.notzed.jjmpeg.AVPixelWriter;
+import java.awt.image.BufferedImage;
+import java.awt.image.DataBufferByte;
+import java.awt.image.DataBufferInt;
+import java.awt.image.DataBufferUShort;
+import java.nio.Buffer;
+
+/**
+ *
+ */
+public class JavaPixelWriter implements AVPixelWriter {
+
+ AVPixelWriter writer;
+
+ public JavaPixelWriter(AVPixelWriter writer) {
+ this.writer = writer;
+ }
+
+ private int typeToFormat(int type) {
+ switch (type) {
+ case BufferedImage.TYPE_3BYTE_BGR:
+ return AVPixelFormat.AV_PIX_FMT_BGR24;
+ case BufferedImage.TYPE_BYTE_GRAY:
+ return AVPixelFormat.AV_PIX_FMT_GRAY8;
+ case BufferedImage.TYPE_USHORT_GRAY:
+ return AVPixelFormat.AV_PIX_FMT_GRAY16;
+ case BufferedImage.TYPE_INT_BGR:
+ return AVPixelFormat.AV_PIX_FMT_RGBA;
+ case BufferedImage.TYPE_INT_ARGB:
+ return AVPixelFormat.AV_PIX_FMT_BGRA;
+ }
+ throw new RuntimeException("Unsupported Java image conversion format");
+ }
+
+ public void setPixels(int y, int h, BufferedImage dst) {
+ int type = dst.getType();
+ int fmt = typeToFormat(type);
+
+ switch (type) {
+ case BufferedImage.TYPE_3BYTE_BGR: {
+ byte[] data = ((DataBufferByte) dst.getRaster().getDataBuffer()).getData();
+ setPixels(y, h, fmt, data, 0, dst.getWidth() * 3);
+ break;
+ }
+ case BufferedImage.TYPE_BYTE_GRAY: {
+ byte[] data = ((DataBufferByte) dst.getRaster().getDataBuffer()).getData();
+ setPixels(y, h, fmt, data, 0, dst.getWidth());
+ break;
+ }
+ case BufferedImage.TYPE_USHORT_GRAY: {
+ short[] data = ((DataBufferUShort) dst.getRaster().getDataBuffer()).getData();
+ setPixels(y, h, fmt, data, 0, dst.getWidth());
+ break;
+ }
+ case BufferedImage.TYPE_INT_BGR:
+ case BufferedImage.TYPE_INT_ARGB: {
+ int[] data = ((DataBufferInt) dst.getRaster().getDataBuffer()).getData();
+
+ setPixels(y, h, fmt, data, 0, dst.getWidth());
+ break;
+ }
+ }
+ }
+
+ @Override
+ public <T extends Buffer> void setPixels(int y, int h, int fmt, T buffer, int scanlineStride) {
+ writer.setPixels(y, h, fmt, buffer, scanlineStride);
+ }
+
+ @Override
+ public void setPixels(int y, int h, int fmt, byte[] buffer, int offset, int scanlineStride) {
+ writer.setPixels(y, h, fmt, buffer, offset, scanlineStride);
+ }
+
+ @Override
+ public void setPixels(int y, int h, int fmt, short[] buffer, int offset, int scanlineStride) {
+ writer.setPixels(y, h, fmt, buffer, offset, scanlineStride);
+ }
+
+ @Override
+ public void setPixels(int y, int h, int fmt, int[] buffer, int offset, int scanlineStride) {
+ writer.setPixels(y, h, fmt, buffer, offset, scanlineStride);
+ }
+
+}
--- /dev/null
+/*
+ * Copyright (C) 2018 Michael Zucchi
+ *
+ * This file is part of jjmpeg <https://www.zedzone.space/software/jjmpeg.html>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+module notzed.jjmpeg.awt {
+
+ requires transitive java.desktop;
+ requires transitive notzed.jjmpeg;
+
+ exports au.notzed.jjmpeg.awt;
+}
--- /dev/null
+ GNU GENERAL PUBLIC LICENSE
+ Version 3, 29 June 2007
+
+ Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
+ Everyone is permitted to copy and distribute verbatim copies
+ of this license document, but changing it is not allowed.
+
+ Preamble
+
+ The GNU General Public License is a free, copyleft license for
+software and other kinds of works.
+
+ The licenses for most software and other practical works are designed
+to take away your freedom to share and change the works. By contrast,
+the GNU General Public License is intended to guarantee your freedom to
+share and change all versions of a program--to make sure it remains free
+software for all its users. We, the Free Software Foundation, use the
+GNU General Public License for most of our software; it applies also to
+any other work released this way by its authors. You can apply it to
+your programs, too.
+
+ When we speak of free software, we are referring to freedom, not
+price. Our General Public Licenses are designed to make sure that you
+have the freedom to distribute copies of free software (and charge for
+them if you wish), that you receive source code or can get it if you
+want it, that you can change the software or use pieces of it in new
+free programs, and that you know you can do these things.
+
+ To protect your rights, we need to prevent others from denying you
+these rights or asking you to surrender the rights. Therefore, you have
+certain responsibilities if you distribute copies of the software, or if
+you modify it: responsibilities to respect the freedom of others.
+
+ For example, if you distribute copies of such a program, whether
+gratis or for a fee, you must pass on to the recipients the same
+freedoms that you received. You must make sure that they, too, receive
+or can get the source code. And you must show them these terms so they
+know their rights.
+
+ Developers that use the GNU GPL protect your rights with two steps:
+(1) assert copyright on the software, and (2) offer you this License
+giving you legal permission to copy, distribute and/or modify it.
+
+ For the developers' and authors' protection, the GPL clearly explains
+that there is no warranty for this free software. For both users' and
+authors' sake, the GPL requires that modified versions be marked as
+changed, so that their problems will not be attributed erroneously to
+authors of previous versions.
+
+ Some devices are designed to deny users access to install or run
+modified versions of the software inside them, although the manufacturer
+can do so. This is fundamentally incompatible with the aim of
+protecting users' freedom to change the software. The systematic
+pattern of such abuse occurs in the area of products for individuals to
+use, which is precisely where it is most unacceptable. Therefore, we
+have designed this version of the GPL to prohibit the practice for those
+products. If such problems arise substantially in other domains, we
+stand ready to extend this provision to those domains in future versions
+of the GPL, as needed to protect the freedom of users.
+
+ Finally, every program is threatened constantly by software patents.
+States should not allow patents to restrict development and use of
+software on general-purpose computers, but in those that do, we wish to
+avoid the special danger that patents applied to a free program could
+make it effectively proprietary. To prevent this, the GPL assures that
+patents cannot be used to render the program non-free.
+
+ The precise terms and conditions for copying, distribution and
+modification follow.
+
+ TERMS AND CONDITIONS
+
+ 0. Definitions.
+
+ "This License" refers to version 3 of the GNU General Public License.
+
+ "Copyright" also means copyright-like laws that apply to other kinds of
+works, such as semiconductor masks.
+
+ "The Program" refers to any copyrightable work licensed under this
+License. Each licensee is addressed as "you". "Licensees" and
+"recipients" may be individuals or organizations.
+
+ To "modify" a work means to copy from or adapt all or part of the work
+in a fashion requiring copyright permission, other than the making of an
+exact copy. The resulting work is called a "modified version" of the
+earlier work or a work "based on" the earlier work.
+
+ A "covered work" means either the unmodified Program or a work based
+on the Program.
+
+ To "propagate" a work means to do anything with it that, without
+permission, would make you directly or secondarily liable for
+infringement under applicable copyright law, except executing it on a
+computer or modifying a private copy. Propagation includes copying,
+distribution (with or without modification), making available to the
+public, and in some countries other activities as well.
+
+ To "convey" a work means any kind of propagation that enables other
+parties to make or receive copies. Mere interaction with a user through
+a computer network, with no transfer of a copy, is not conveying.
+
+ An interactive user interface displays "Appropriate Legal Notices"
+to the extent that it includes a convenient and prominently visible
+feature that (1) displays an appropriate copyright notice, and (2)
+tells the user that there is no warranty for the work (except to the
+extent that warranties are provided), that licensees may convey the
+work under this License, and how to view a copy of this License. If
+the interface presents a list of user commands or options, such as a
+menu, a prominent item in the list meets this criterion.
+
+ 1. Source Code.
+
+ The "source code" for a work means the preferred form of the work
+for making modifications to it. "Object code" means any non-source
+form of a work.
+
+ A "Standard Interface" means an interface that either is an official
+standard defined by a recognized standards body, or, in the case of
+interfaces specified for a particular programming language, one that
+is widely used among developers working in that language.
+
+ The "System Libraries" of an executable work include anything, other
+than the work as a whole, that (a) is included in the normal form of
+packaging a Major Component, but which is not part of that Major
+Component, and (b) serves only to enable use of the work with that
+Major Component, or to implement a Standard Interface for which an
+implementation is available to the public in source code form. A
+"Major Component", in this context, means a major essential component
+(kernel, window system, and so on) of the specific operating system
+(if any) on which the executable work runs, or a compiler used to
+produce the work, or an object code interpreter used to run it.
+
+ The "Corresponding Source" for a work in object code form means all
+the source code needed to generate, install, and (for an executable
+work) run the object code and to modify the work, including scripts to
+control those activities. However, it does not include the work's
+System Libraries, or general-purpose tools or generally available free
+programs which are used unmodified in performing those activities but
+which are not part of the work. For example, Corresponding Source
+includes interface definition files associated with source files for
+the work, and the source code for shared libraries and dynamically
+linked subprograms that the work is specifically designed to require,
+such as by intimate data communication or control flow between those
+subprograms and other parts of the work.
+
+ The Corresponding Source need not include anything that users
+can regenerate automatically from other parts of the Corresponding
+Source.
+
+ The Corresponding Source for a work in source code form is that
+same work.
+
+ 2. Basic Permissions.
+
+ All rights granted under this License are granted for the term of
+copyright on the Program, and are irrevocable provided the stated
+conditions are met. This License explicitly affirms your unlimited
+permission to run the unmodified Program. The output from running a
+covered work is covered by this License only if the output, given its
+content, constitutes a covered work. This License acknowledges your
+rights of fair use or other equivalent, as provided by copyright law.
+
+ You may make, run and propagate covered works that you do not
+convey, without conditions so long as your license otherwise remains
+in force. You may convey covered works to others for the sole purpose
+of having them make modifications exclusively for you, or provide you
+with facilities for running those works, provided that you comply with
+the terms of this License in conveying all material for which you do
+not control copyright. Those thus making or running the covered works
+for you must do so exclusively on your behalf, under your direction
+and control, on terms that prohibit them from making any copies of
+your copyrighted material outside their relationship with you.
+
+ Conveying under any other circumstances is permitted solely under
+the conditions stated below. Sublicensing is not allowed; section 10
+makes it unnecessary.
+
+ 3. Protecting Users' Legal Rights From Anti-Circumvention Law.
+
+ No covered work shall be deemed part of an effective technological
+measure under any applicable law fulfilling obligations under article
+11 of the WIPO copyright treaty adopted on 20 December 1996, or
+similar laws prohibiting or restricting circumvention of such
+measures.
+
+ When you convey a covered work, you waive any legal power to forbid
+circumvention of technological measures to the extent such circumvention
+is effected by exercising rights under this License with respect to
+the covered work, and you disclaim any intention to limit operation or
+modification of the work as a means of enforcing, against the work's
+users, your or third parties' legal rights to forbid circumvention of
+technological measures.
+
+ 4. Conveying Verbatim Copies.
+
+ You may convey verbatim copies of the Program's source code as you
+receive it, in any medium, provided that you conspicuously and
+appropriately publish on each copy an appropriate copyright notice;
+keep intact all notices stating that this License and any
+non-permissive terms added in accord with section 7 apply to the code;
+keep intact all notices of the absence of any warranty; and give all
+recipients a copy of this License along with the Program.
+
+ You may charge any price or no price for each copy that you convey,
+and you may offer support or warranty protection for a fee.
+
+ 5. Conveying Modified Source Versions.
+
+ You may convey a work based on the Program, or the modifications to
+produce it from the Program, in the form of source code under the
+terms of section 4, provided that you also meet all of these conditions:
+
+ a) The work must carry prominent notices stating that you modified
+ it, and giving a relevant date.
+
+ b) The work must carry prominent notices stating that it is
+ released under this License and any conditions added under section
+ 7. This requirement modifies the requirement in section 4 to
+ "keep intact all notices".
+
+ c) You must license the entire work, as a whole, under this
+ License to anyone who comes into possession of a copy. This
+ License will therefore apply, along with any applicable section 7
+ additional terms, to the whole of the work, and all its parts,
+ regardless of how they are packaged. This License gives no
+ permission to license the work in any other way, but it does not
+ invalidate such permission if you have separately received it.
+
+ d) If the work has interactive user interfaces, each must display
+ Appropriate Legal Notices; however, if the Program has interactive
+ interfaces that do not display Appropriate Legal Notices, your
+ work need not make them do so.
+
+ A compilation of a covered work with other separate and independent
+works, which are not by their nature extensions of the covered work,
+and which are not combined with it such as to form a larger program,
+in or on a volume of a storage or distribution medium, is called an
+"aggregate" if the compilation and its resulting copyright are not
+used to limit the access or legal rights of the compilation's users
+beyond what the individual works permit. Inclusion of a covered work
+in an aggregate does not cause this License to apply to the other
+parts of the aggregate.
+
+ 6. Conveying Non-Source Forms.
+
+ You may convey a covered work in object code form under the terms
+of sections 4 and 5, provided that you also convey the
+machine-readable Corresponding Source under the terms of this License,
+in one of these ways:
+
+ a) Convey the object code in, or embodied in, a physical product
+ (including a physical distribution medium), accompanied by the
+ Corresponding Source fixed on a durable physical medium
+ customarily used for software interchange.
+
+ b) Convey the object code in, or embodied in, a physical product
+ (including a physical distribution medium), accompanied by a
+ written offer, valid for at least three years and valid for as
+ long as you offer spare parts or customer support for that product
+ model, to give anyone who possesses the object code either (1) a
+ copy of the Corresponding Source for all the software in the
+ product that is covered by this License, on a durable physical
+ medium customarily used for software interchange, for a price no
+ more than your reasonable cost of physically performing this
+ conveying of source, or (2) access to copy the
+ Corresponding Source from a network server at no charge.
+
+ c) Convey individual copies of the object code with a copy of the
+ written offer to provide the Corresponding Source. This
+ alternative is allowed only occasionally and noncommercially, and
+ only if you received the object code with such an offer, in accord
+ with subsection 6b.
+
+ d) Convey the object code by offering access from a designated
+ place (gratis or for a charge), and offer equivalent access to the
+ Corresponding Source in the same way through the same place at no
+ further charge. You need not require recipients to copy the
+ Corresponding Source along with the object code. If the place to
+ copy the object code is a network server, the Corresponding Source
+ may be on a different server (operated by you or a third party)
+ that supports equivalent copying facilities, provided you maintain
+ clear directions next to the object code saying where to find the
+ Corresponding Source. Regardless of what server hosts the
+ Corresponding Source, you remain obligated to ensure that it is
+ available for as long as needed to satisfy these requirements.
+
+ e) Convey the object code using peer-to-peer transmission, provided
+ you inform other peers where the object code and Corresponding
+ Source of the work are being offered to the general public at no
+ charge under subsection 6d.
+
+ A separable portion of the object code, whose source code is excluded
+from the Corresponding Source as a System Library, need not be
+included in conveying the object code work.
+
+ A "User Product" is either (1) a "consumer product", which means any
+tangible personal property which is normally used for personal, family,
+or household purposes, or (2) anything designed or sold for incorporation
+into a dwelling. In determining whether a product is a consumer product,
+doubtful cases shall be resolved in favor of coverage. For a particular
+product received by a particular user, "normally used" refers to a
+typical or common use of that class of product, regardless of the status
+of the particular user or of the way in which the particular user
+actually uses, or expects or is expected to use, the product. A product
+is a consumer product regardless of whether the product has substantial
+commercial, industrial or non-consumer uses, unless such uses represent
+the only significant mode of use of the product.
+
+ "Installation Information" for a User Product means any methods,
+procedures, authorization keys, or other information required to install
+and execute modified versions of a covered work in that User Product from
+a modified version of its Corresponding Source. The information must
+suffice to ensure that the continued functioning of the modified object
+code is in no case prevented or interfered with solely because
+modification has been made.
+
+ If you convey an object code work under this section in, or with, or
+specifically for use in, a User Product, and the conveying occurs as
+part of a transaction in which the right of possession and use of the
+User Product is transferred to the recipient in perpetuity or for a
+fixed term (regardless of how the transaction is characterized), the
+Corresponding Source conveyed under this section must be accompanied
+by the Installation Information. But this requirement does not apply
+if neither you nor any third party retains the ability to install
+modified object code on the User Product (for example, the work has
+been installed in ROM).
+
+ The requirement to provide Installation Information does not include a
+requirement to continue to provide support service, warranty, or updates
+for a work that has been modified or installed by the recipient, or for
+the User Product in which it has been modified or installed. Access to a
+network may be denied when the modification itself materially and
+adversely affects the operation of the network or violates the rules and
+protocols for communication across the network.
+
+ Corresponding Source conveyed, and Installation Information provided,
+in accord with this section must be in a format that is publicly
+documented (and with an implementation available to the public in
+source code form), and must require no special password or key for
+unpacking, reading or copying.
+
+ 7. Additional Terms.
+
+ "Additional permissions" are terms that supplement the terms of this
+License by making exceptions from one or more of its conditions.
+Additional permissions that are applicable to the entire Program shall
+be treated as though they were included in this License, to the extent
+that they are valid under applicable law. If additional permissions
+apply only to part of the Program, that part may be used separately
+under those permissions, but the entire Program remains governed by
+this License without regard to the additional permissions.
+
+ When you convey a copy of a covered work, you may at your option
+remove any additional permissions from that copy, or from any part of
+it. (Additional permissions may be written to require their own
+removal in certain cases when you modify the work.) You may place
+additional permissions on material, added by you to a covered work,
+for which you have or can give appropriate copyright permission.
+
+ Notwithstanding any other provision of this License, for material you
+add to a covered work, you may (if authorized by the copyright holders of
+that material) supplement the terms of this License with terms:
+
+ a) Disclaiming warranty or limiting liability differently from the
+ terms of sections 15 and 16 of this License; or
+
+ b) Requiring preservation of specified reasonable legal notices or
+ author attributions in that material or in the Appropriate Legal
+ Notices displayed by works containing it; or
+
+ c) Prohibiting misrepresentation of the origin of that material, or
+ requiring that modified versions of such material be marked in
+ reasonable ways as different from the original version; or
+
+ d) Limiting the use for publicity purposes of names of licensors or
+ authors of the material; or
+
+ e) Declining to grant rights under trademark law for use of some
+ trade names, trademarks, or service marks; or
+
+ f) Requiring indemnification of licensors and authors of that
+ material by anyone who conveys the material (or modified versions of
+ it) with contractual assumptions of liability to the recipient, for
+ any liability that these contractual assumptions directly impose on
+ those licensors and authors.
+
+ All other non-permissive additional terms are considered "further
+restrictions" within the meaning of section 10. If the Program as you
+received it, or any part of it, contains a notice stating that it is
+governed by this License along with a term that is a further
+restriction, you may remove that term. If a license document contains
+a further restriction but permits relicensing or conveying under this
+License, you may add to a covered work material governed by the terms
+of that license document, provided that the further restriction does
+not survive such relicensing or conveying.
+
+ If you add terms to a covered work in accord with this section, you
+must place, in the relevant source files, a statement of the
+additional terms that apply to those files, or a notice indicating
+where to find the applicable terms.
+
+ Additional terms, permissive or non-permissive, may be stated in the
+form of a separately written license, or stated as exceptions;
+the above requirements apply either way.
+
+ 8. Termination.
+
+ You may not propagate or modify a covered work except as expressly
+provided under this License. Any attempt otherwise to propagate or
+modify it is void, and will automatically terminate your rights under
+this License (including any patent licenses granted under the third
+paragraph of section 11).
+
+ However, if you cease all violation of this License, then your
+license from a particular copyright holder is reinstated (a)
+provisionally, unless and until the copyright holder explicitly and
+finally terminates your license, and (b) permanently, if the copyright
+holder fails to notify you of the violation by some reasonable means
+prior to 60 days after the cessation.
+
+ Moreover, your license from a particular copyright holder is
+reinstated permanently if the copyright holder notifies you of the
+violation by some reasonable means, this is the first time you have
+received notice of violation of this License (for any work) from that
+copyright holder, and you cure the violation prior to 30 days after
+your receipt of the notice.
+
+ Termination of your rights under this section does not terminate the
+licenses of parties who have received copies or rights from you under
+this License. If your rights have been terminated and not permanently
+reinstated, you do not qualify to receive new licenses for the same
+material under section 10.
+
+ 9. Acceptance Not Required for Having Copies.
+
+ You are not required to accept this License in order to receive or
+run a copy of the Program. Ancillary propagation of a covered work
+occurring solely as a consequence of using peer-to-peer transmission
+to receive a copy likewise does not require acceptance. However,
+nothing other than this License grants you permission to propagate or
+modify any covered work. These actions infringe copyright if you do
+not accept this License. Therefore, by modifying or propagating a
+covered work, you indicate your acceptance of this License to do so.
+
+ 10. Automatic Licensing of Downstream Recipients.
+
+ Each time you convey a covered work, the recipient automatically
+receives a license from the original licensors, to run, modify and
+propagate that work, subject to this License. You are not responsible
+for enforcing compliance by third parties with this License.
+
+ An "entity transaction" is a transaction transferring control of an
+organization, or substantially all assets of one, or subdividing an
+organization, or merging organizations. If propagation of a covered
+work results from an entity transaction, each party to that
+transaction who receives a copy of the work also receives whatever
+licenses to the work the party's predecessor in interest had or could
+give under the previous paragraph, plus a right to possession of the
+Corresponding Source of the work from the predecessor in interest, if
+the predecessor has it or can get it with reasonable efforts.
+
+ You may not impose any further restrictions on the exercise of the
+rights granted or affirmed under this License. For example, you may
+not impose a license fee, royalty, or other charge for exercise of
+rights granted under this License, and you may not initiate litigation
+(including a cross-claim or counterclaim in a lawsuit) alleging that
+any patent claim is infringed by making, using, selling, offering for
+sale, or importing the Program or any portion of it.
+
+ 11. Patents.
+
+ A "contributor" is a copyright holder who authorizes use under this
+License of the Program or a work on which the Program is based. The
+work thus licensed is called the contributor's "contributor version".
+
+ A contributor's "essential patent claims" are all patent claims
+owned or controlled by the contributor, whether already acquired or
+hereafter acquired, that would be infringed by some manner, permitted
+by this License, of making, using, or selling its contributor version,
+but do not include claims that would be infringed only as a
+consequence of further modification of the contributor version. For
+purposes of this definition, "control" includes the right to grant
+patent sublicenses in a manner consistent with the requirements of
+this License.
+
+ Each contributor grants you a non-exclusive, worldwide, royalty-free
+patent license under the contributor's essential patent claims, to
+make, use, sell, offer for sale, import and otherwise run, modify and
+propagate the contents of its contributor version.
+
+ In the following three paragraphs, a "patent license" is any express
+agreement or commitment, however denominated, not to enforce a patent
+(such as an express permission to practice a patent or covenant not to
+sue for patent infringement). To "grant" such a patent license to a
+party means to make such an agreement or commitment not to enforce a
+patent against the party.
+
+ If you convey a covered work, knowingly relying on a patent license,
+and the Corresponding Source of the work is not available for anyone
+to copy, free of charge and under the terms of this License, through a
+publicly available network server or other readily accessible means,
+then you must either (1) cause the Corresponding Source to be so
+available, or (2) arrange to deprive yourself of the benefit of the
+patent license for this particular work, or (3) arrange, in a manner
+consistent with the requirements of this License, to extend the patent
+license to downstream recipients. "Knowingly relying" means you have
+actual knowledge that, but for the patent license, your conveying the
+covered work in a country, or your recipient's use of the covered work
+in a country, would infringe one or more identifiable patents in that
+country that you have reason to believe are valid.
+
+ If, pursuant to or in connection with a single transaction or
+arrangement, you convey, or propagate by procuring conveyance of, a
+covered work, and grant a patent license to some of the parties
+receiving the covered work authorizing them to use, propagate, modify
+or convey a specific copy of the covered work, then the patent license
+you grant is automatically extended to all recipients of the covered
+work and works based on it.
+
+ A patent license is "discriminatory" if it does not include within
+the scope of its coverage, prohibits the exercise of, or is
+conditioned on the non-exercise of one or more of the rights that are
+specifically granted under this License. You may not convey a covered
+work if you are a party to an arrangement with a third party that is
+in the business of distributing software, under which you make payment
+to the third party based on the extent of your activity of conveying
+the work, and under which the third party grants, to any of the
+parties who would receive the covered work from you, a discriminatory
+patent license (a) in connection with copies of the covered work
+conveyed by you (or copies made from those copies), or (b) primarily
+for and in connection with specific products or compilations that
+contain the covered work, unless you entered into that arrangement,
+or that patent license was granted, prior to 28 March 2007.
+
+ Nothing in this License shall be construed as excluding or limiting
+any implied license or other defenses to infringement that may
+otherwise be available to you under applicable patent law.
+
+ 12. No Surrender of Others' Freedom.
+
+ If conditions are imposed on you (whether by court order, agreement or
+otherwise) that contradict the conditions of this License, they do not
+excuse you from the conditions of this License. If you cannot convey a
+covered work so as to satisfy simultaneously your obligations under this
+License and any other pertinent obligations, then as a consequence you may
+not convey it at all. For example, if you agree to terms that obligate you
+to collect a royalty for further conveying from those to whom you convey
+the Program, the only way you could satisfy both those terms and this
+License would be to refrain entirely from conveying the Program.
+
+ 13. Use with the GNU Affero General Public License.
+
+ Notwithstanding any other provision of this License, you have
+permission to link or combine any covered work with a work licensed
+under version 3 of the GNU Affero General Public License into a single
+combined work, and to convey the resulting work. The terms of this
+License will continue to apply to the part which is the covered work,
+but the special requirements of the GNU Affero General Public License,
+section 13, concerning interaction through a network will apply to the
+combination as such.
+
+ 14. Revised Versions of this License.
+
+ The Free Software Foundation may publish revised and/or new versions of
+the GNU General Public License from time to time. Such new versions will
+be similar in spirit to the present version, but may differ in detail to
+address new problems or concerns.
+
+ Each version is given a distinguishing version number. If the
+Program specifies that a certain numbered version of the GNU General
+Public License "or any later version" applies to it, you have the
+option of following the terms and conditions either of that numbered
+version or of any later version published by the Free Software
+Foundation. If the Program does not specify a version number of the
+GNU General Public License, you may choose any version ever published
+by the Free Software Foundation.
+
+ If the Program specifies that a proxy can decide which future
+versions of the GNU General Public License can be used, that proxy's
+public statement of acceptance of a version permanently authorizes you
+to choose that version for the Program.
+
+ Later license versions may give you additional or different
+permissions. However, no additional obligations are imposed on any
+author or copyright holder as a result of your choosing to follow a
+later version.
+
+ 15. Disclaimer of Warranty.
+
+ THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
+APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
+HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
+OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
+THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
+IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
+ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
+
+ 16. Limitation of Liability.
+
+ IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
+WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
+THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
+GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
+USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
+DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
+PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
+EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
+SUCH DAMAGES.
+
+ 17. Interpretation of Sections 15 and 16.
+
+ If the disclaimer of warranty and limitation of liability provided
+above cannot be given local legal effect according to their terms,
+reviewing courts shall apply local law that most closely approximates
+an absolute waiver of all civil liability in connection with the
+Program, unless a warranty or assumption of liability accompanies a
+copy of the Program in return for a fee.
+
+ END OF TERMS AND CONDITIONS
+
+ How to Apply These Terms to Your New Programs
+
+ If you develop a new program, and you want it to be of the greatest
+possible use to the public, the best way to achieve this is to make it
+free software which everyone can redistribute and change under these terms.
+
+ To do so, attach the following notices to the program. It is safest
+to attach them to the start of each source file to most effectively
+state the exclusion of warranty; and each file should have at least
+the "copyright" line and a pointer to where the full notice is found.
+
+ <one line to give the program's name and a brief idea of what it does.>
+ Copyright (C) <year> <name of author>
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program 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 General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+Also add information on how to contact you by electronic and paper mail.
+
+ If the program does terminal interaction, make it output a short
+notice like this when it starts in an interactive mode:
+
+ <program> Copyright (C) <year> <name of author>
+ This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
+ This is free software, and you are welcome to redistribute it
+ under certain conditions; type `show c' for details.
+
+The hypothetical commands `show w' and `show c' should show the appropriate
+parts of the General Public License. Of course, your program's commands
+might be different; for a GUI interface, you would use an "about box".
+
+ You should also get your employer (if you work as a programmer) or school,
+if any, to sign a "copyright disclaimer" for the program, if necessary.
+For more information on this, and how to apply and follow the GNU GPL, see
+<http://www.gnu.org/licenses/>.
+
+ The GNU General Public License does not permit incorporating your program
+into proprietary programs. If your program is a subroutine library, you
+may consider it more useful to permit linking proprietary applications with
+the library. If this is what you want to do, use the GNU Lesser General
+Public License instead of this License. But first, please read
+<http://www.gnu.org/philosophy/why-not-lgpl.html>.
--- /dev/null
+/*
+ * Copyright (c) 2012 Michael Zucchi
+ *
+ * This file is part of jjmpeg, a java binding to ffmpeg's libraries.
+ *
+ * jjmpeg is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * jjmpeg 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 for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with jjmpeg. If not, see <http://www.gnu.org/licenses/>.
+ */
+package au.notzed.jjmpeg.demo.audio;
+
+import au.notzed.jjmpeg.AVChannelLayout;
+import au.notzed.jjmpeg.AVSampleFormat;
+import au.notzed.jjmpeg.AVSampleReader;
+import au.notzed.jjmpeg.io.JJMediaReader;
+import java.io.IOException;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+import java.util.TimeZone;
+import javax.sound.sampled.AudioFormat;
+import javax.sound.sampled.AudioSystem;
+import javax.sound.sampled.LineUnavailableException;
+import javax.sound.sampled.SourceDataLine;
+
+/**
+ * Plays audio files.
+ * <p>
+ * For a bit of fun one can override the output sample rate (arbitrary based
+ * on backend), output bit depth (8,16,32), and layout (stero, mono,
+ * 5.1, 7,1, etc).
+ */
+public class AudioPlay {
+
+ static void usage(String why) {
+ System.err.println();
+ System.err.print("Error: ");
+ System.err.println(why);
+ System.err.println();
+ System.err.println("Usage: AudioPlay [ --rate rate ] [ --bits bits ] [ --layout layout ] file");
+ System.err.println();
+ System.err.println(" rate output sample rate");
+ System.err.println(" bits 8, 16, or 32.");
+ System.err.println(" layout mono, stereo, downmix, quad, 2.1, 3.0, 3.1, ...");
+ System.err.println();
+ System.exit(1);
+ }
+
+ public static void main(String[] args) {
+ String path = null;
+ int outputRate = 0;
+ int outputBits = 16;
+ long outputLayout = 0;
+
+ for (int i = 0; i < args.length; i++) {
+ switch (args[i]) {
+ case "--rate":
+ outputRate = Integer.valueOf(args[++i]);
+ break;
+ case "--bits":
+ outputBits = Integer.valueOf(args[++i]);
+ break;
+ case "--layout":
+ outputLayout = AVChannelLayout.valueOf(args[++i]);
+ if (outputLayout == 0)
+ usage("Output layout invalid");
+ break;
+ default:
+ path = args[i];
+ break;
+ }
+ }
+
+ if (path == null)
+ usage("No audio file supplied");
+
+ int dstFormat;
+ AudioFormat.Encoding dstEncoding;
+ switch (outputBits) {
+ case 8:
+ dstFormat = AVSampleFormat.AV_SAMPLE_FMT_U8;
+ dstEncoding = AudioFormat.Encoding.PCM_UNSIGNED;
+ break;
+ case 16:
+ dstFormat = AVSampleFormat.AV_SAMPLE_FMT_S16;
+ dstEncoding = AudioFormat.Encoding.PCM_SIGNED;
+ break;
+ case 32:
+ dstFormat = AVSampleFormat.AV_SAMPLE_FMT_S32;
+ dstEncoding = AudioFormat.Encoding.PCM_SIGNED;
+ break;
+ default:
+ usage("Bits must be 8, 16, or 32");
+ return;
+ }
+
+ try (JJMediaReader mr = new JJMediaReader(path)) {
+ JJMediaReader.JJReaderAudio as = mr.openDefaultStream(JJMediaReader.TYPE_AUDIO);
+
+ if (as == null)
+ throw new IOException("No audio stream found");
+
+ int rate = as.getSampleRate();
+ int channels = as.getNumChannels();
+ long layout = as.getChannelLayout();
+ int fmt = as.getSampleFormat();
+
+ long dstLayout = outputLayout == 0 ? AVChannelLayout.getDefaultLayout(channels) : outputLayout;
+ int dstRate = (outputRate == 0) ? rate : outputRate;
+ int dstChannels = AVChannelLayout.getNumChannels(dstLayout);
+ int dstSampleSize = ((outputBits + 7) >> 3) * dstChannels;
+
+ AVSampleReader sampleReader = as.getFrame().getSampleReader(
+ dstLayout, dstFormat, dstRate);
+ AudioFormat format = new AudioFormat(
+ dstEncoding, dstRate, outputBits, dstChannels, dstSampleSize, dstRate, false);
+ byte[] buffer = new byte[8192];
+
+ System.err.printf("Audio: %s\n", path);
+ System.err.printf(" source format: %s %.1f Hz %s\n", AVSampleFormat.toString(fmt), (double) rate, AVChannelLayout.toString(layout));
+ System.err.printf(" output format: %s\n", format);
+
+ SimpleDateFormat time = new SimpleDateFormat("HH:mm:ss.SSS");
+ time.setTimeZone(TimeZone.getTimeZone("GMT"));
+
+ try (SourceDataLine source = AudioSystem.getSourceDataLine(format)) {
+ source.open();
+ source.start();
+
+ while (mr.readFrame() == as) {
+ int nsamples = sampleReader.getNumSamples() * dstSampleSize;
+ long stamp = as.convertPTS(mr.getPTS());
+
+ if (buffer.length < nsamples)
+ buffer = new byte[nsamples];
+
+ nsamples = sampleReader.getSamples(buffer, 0, buffer.length) * dstSampleSize;
+ source.write(buffer, 0, nsamples);
+
+ System.out.print(time.format(new Date(stamp)));
+ System.out.print("\r");
+ }
+ System.out.println();
+ }
+ } catch (IOException | LineUnavailableException ex) {
+ System.err.printf("`%s': %s\n", path, ex.getLocalizedMessage());
+ System.exit(1);
+ }
+
+ }
+
+}
--- /dev/null
+/*
+ * Copyright (C) 2019 Michael Zucchi
+ *
+ * This file is part of jjmpeg <https://www.zedzone.space/software/jjmpeg.html>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+package au.notzed.jjmpeg.demo.video;
+
+import au.notzed.jjmpeg.AVPixelFormat;
+import au.notzed.jjmpeg.awt.JavaPixelReader;
+import au.notzed.jjmpeg.io.JJMediaReader;
+import java.awt.image.BufferedImage;
+import java.io.File;
+import java.io.IOException;
+import java.util.IllegalFormatException;
+import javax.imageio.ImageIO;
+
+/**
+ * Export a video as frames.
+ * <p>
+ * This demonstrates using JavaPixelReader from the notzed.jjmpeg.awt module.
+ */
+public class VideoExport {
+
+ public static void main(String[] args) {
+ int start = 0, count = Integer.MAX_VALUE;
+ String format = "frame-%05d.jpeg";
+ String path = null;
+ String type;
+
+ for (int i = 0; i < args.length; i++) {
+ switch (args[i]) {
+ case "--start":
+ start = Integer.valueOf(args[++i]);
+ break;
+ case "--count":
+ count = Integer.valueOf(args[++i]);
+ break;
+ case "--format":
+ format = args[++i];
+ default:
+ path = args[i];
+ break;
+ }
+ }
+
+ if (path == null) {
+ System.err.println("No video supplied");
+ System.exit(1);
+ }
+
+ String base = null;
+ try {
+ base = String.format(format, 0);
+ } catch (IllegalFormatException x) {
+ System.err.println("Format invalid");
+ System.exit(1);
+ }
+
+ int dot = format.lastIndexOf('.');
+ if (dot == -1)
+ System.err.println("Unknown extension");
+ type = format.substring(dot + 1).toLowerCase();
+
+ try (JJMediaReader mr = new JJMediaReader(path)) {
+ int index = 0;
+ JJMediaReader.JJReaderVideo vs = mr.openDefaultStream(JJMediaReader.TYPE_VIDEO);
+
+ if (vs == null)
+ throw new IOException("No video stream");
+
+ int width = vs.getWidth();
+ int height = vs.getHeight();
+ BufferedImage image;
+ JavaPixelReader frameReader = new JavaPixelReader(vs.getFrame().getPixelReader(width, height, 0));
+
+ // Handle greyscale and high-bit greyscale specifically.
+ switch (vs.getPixelFormat()) {
+ case AVPixelFormat.AV_PIX_FMT_GRAY8:
+ image = new BufferedImage(width, height, BufferedImage.TYPE_BYTE_GRAY);
+ break;
+ case AVPixelFormat.AV_PIX_FMT_GRAY16:
+ case AVPixelFormat.AV_PIX_FMT_GRAY9:
+ case AVPixelFormat.AV_PIX_FMT_GRAY10:
+ case AVPixelFormat.AV_PIX_FMT_GRAY12:
+ image = new BufferedImage(width, height, BufferedImage.TYPE_USHORT_GRAY);
+ break;
+ default:
+ image = new BufferedImage(width, height, BufferedImage.TYPE_3BYTE_BGR);
+ break;
+ }
+
+ File dir = new File(base).getParentFile();
+ if (dir != null && !dir.mkdirs()) {
+ System.err.println("Unable to create directory");
+ System.exit(1);
+ }
+
+ // main loop
+ while (index < start + count && mr.readFrame() == vs) {
+ if (index >= start) {
+ String name = String.format(format, index);
+
+ System.err.println(name);
+ frameReader.getPixels(0, height, image);
+ ImageIO.write(image, type, new File(name));
+ }
+ index += 1;
+ }
+ } catch (IOException ex) {
+ System.err.printf("`%s': %s\n", path, ex.getLocalizedMessage());
+ System.exit(1);
+ }
+
+ }
+}
--- /dev/null
+/*
+ * Copyright (C) 2019 Michael Zucchi
+ *
+ * This file is part of jjmpeg <https://www.zedzone.space/software/jjmpeg.html>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+package au.notzed.jjmpeg.demo.video;
+
+import au.notzed.jjmpeg.AVIOException;
+import au.notzed.jjmpeg.fx.FXPixelReader;
+import au.notzed.jjmpeg.io.JJMediaReader;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import static java.lang.Double.min;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+import java.util.List;
+import java.util.TimeZone;
+import java.util.concurrent.CountDownLatch;
+import javafx.application.Application;
+import javafx.application.Platform;
+import javafx.beans.InvalidationListener;
+import javafx.beans.Observable;
+import javafx.geometry.Insets;
+import javafx.scene.Scene;
+import javafx.scene.control.Alert;
+import javafx.scene.control.ButtonType;
+import javafx.scene.image.ImageView;
+import javafx.scene.image.WritableImage;
+import javafx.scene.layout.AnchorPane;
+import javafx.scene.layout.Background;
+import javafx.scene.layout.BackgroundFill;
+import javafx.scene.layout.CornerRadii;
+import javafx.scene.paint.Color;
+import javafx.scene.text.Text;
+import javafx.scene.transform.Scale;
+import javafx.scene.transform.Translate;
+import javafx.stage.Stage;
+
+/**
+ * A simple JavaFX demo which plays a video.
+ * <p>
+ * This demonstrates reading into a JavaFX WritableImage via
+ * the notzed.jjmpeg.fx module and some basic video handling.
+ * <p>
+ * Audio is ignored.
+ */
+public class VideoPlay extends Application {
+
+ @Override
+ public void start(Stage stage) throws Exception {
+ List<String> args = getParameters().getUnnamed();
+
+ if (args.size() != 1) {
+ Alert a = new Alert(Alert.AlertType.ERROR, "Must supply one file.", ButtonType.CLOSE);
+ a.showAndWait();
+ return;
+ }
+
+ new Thread(() -> {
+ reader(args.get(0));
+ }).start();
+ }
+
+ @Override
+ public void stop() throws Exception {
+ super.stop();
+ cancel = true;
+ }
+
+ int width;
+ int height;
+ FXPixelReader frameReader;
+ ImageView iv;
+ WritableImage image;
+ Text label;
+ Stage stage;
+ SimpleDateFormat time;
+ long time0 = -1;
+ long stamp0;
+
+ void videoReady(JJMediaReader.JJReaderVideo vs) {
+ width = vs.getWidth();
+ height = vs.getHeight();
+ frameReader = new FXPixelReader(vs.getFrame().getPixelReader(width, height, 0));
+
+ time = new SimpleDateFormat("HH:mm:ss.SSS");
+ time.setTimeZone(TimeZone.getTimeZone("GMT"));
+
+ Platform.runLater(() -> {
+ label = new Text();
+ label.setStyle("-fx-font: 24 monospace; -fx-fill: orange; -fx-effect: dropshadow(two-pass-box, orangered, 6, 0.5, 0, 0);");
+
+ iv = new ImageView();
+ image = new WritableImage(width, height);
+
+ iv.setImage(image);
+
+ AnchorPane ap = new AnchorPane(iv, label);
+
+ AnchorPane.setLeftAnchor(label, 16.0);
+ AnchorPane.setTopAnchor(label, 16.0);
+
+ ap.setBackground(new Background(new BackgroundFill(Color.BLACK, CornerRadii.EMPTY, Insets.EMPTY)));
+
+ Scene scene = new Scene(ap, width, height);
+
+ stage = new Stage();
+ stage.setScene(scene);
+ stage.show();
+
+ // Keep image centred. Assumes AVFrame.aspectRatio = 1/1.
+ Scale fit = new Scale(1, 1);
+ Translate centre = new Translate();
+
+ iv.getTransforms().add(centre);
+ iv.getTransforms().add(fit);
+
+ InvalidationListener fitVideo = (Observable observable) -> {
+ double xs = ap.getWidth() / width;
+ double ys = ap.getHeight() / height;
+ double s = min(xs, ys);
+
+ double sw = s * width;
+ double sh = s * height;
+
+ fit.setX(s);
+ fit.setY(s);
+
+ centre.setX((ap.getWidth() - sw) * 0.5);
+ centre.setY((ap.getHeight() - sh) * 0.5);
+ };
+
+ ap.widthProperty().addListener(fitVideo);
+ ap.heightProperty().addListener(fitVideo);
+ });
+ }
+
+ /**
+ * Handle a video frame.
+ * <p>
+ * This basic example writes the image to the javfx thread synchronously
+ * to avoid garbage. Whether it is worth it is another matter.
+ * <p>
+ * It implements a simple timing mechanism which throttles the rate
+ * at which frames are read.
+ *
+ * @param vs
+ * @param stamp
+ */
+ void videoFrame(JJMediaReader.JJReaderVideo vs, long stamp) {
+ String ts = time.format(new Date(stamp));
+ CountDownLatch latch = new CountDownLatch(1);
+
+ // Display the frame. Must run on javafx thread.
+ Platform.runLater(() -> {
+ image.getPixelWriter().setPixels(0, 0, width, height, frameReader, 0, 0);
+ label.setText(ts);
+ latch.countDown();
+ });
+
+ try {
+ // Very basic timing. It works ok enough.
+ if (time0 == -1) {
+ time0 = System.currentTimeMillis();
+ stamp0 = stamp;
+ }
+
+ long diff = (stamp - stamp0) - (System.currentTimeMillis() - time0);
+ if (diff > 0)
+ Thread.sleep(diff);
+
+ // Must wait for frame to be copied to javafx
+ latch.await();
+ } catch (InterruptedException ex) {
+ }
+ }
+
+ /**
+ * Handle a video error.
+ * <p>
+ * Just spits out a dialog and quits.
+ *
+ * @param x
+ */
+ void videoError(IOException x) {
+ Alert a = new Alert(Alert.AlertType.ERROR, x.getLocalizedMessage(), ButtonType.CLOSE);
+ a.showAndWait();
+ Platform.exit();
+ }
+
+ volatile boolean cancel = false;
+
+ /**
+ * Main read loop.
+ * <p>
+ * This opens the video and reads each decoded video frame. It runs until
+ * completion or it is cancelled.
+ *
+ * @param path
+ */
+ void reader(String path) {
+ try (JJMediaReader mr = new JJMediaReader(path)) {
+ JJMediaReader.JJReaderVideo vs = mr.openDefaultStream(JJMediaReader.TYPE_VIDEO);
+
+ if (vs != null) {
+ videoReady(vs);
+
+ while (!cancel && mr.readFrame() == vs) {
+ videoFrame(vs, vs.convertPTS(mr.getPTS()));
+ }
+ } else {
+ videoError(new IOException("No video stream found"));
+ }
+
+ } catch (AVIOException | FileNotFoundException ex) {
+ videoError(ex);
+ }
+ }
+
+ public static void main(String[] args) {
+ launch(args);
+ }
+}
--- /dev/null
+/*
+ * Copyright (C) 2019 Michael Zucchi
+ *
+ * This file is part of jjmpeg <https://www.zedzone.space/software/jjmpeg.html>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+package au.notzed.jjmpeg.demo.video;
+
+import au.notzed.jjmpeg.AVPixelFormat;
+import au.notzed.jjmpeg.io.JJMediaReader;
+import java.io.IOException;
+
+/**
+ * A simple video scanner.
+ * <p>
+ * This displays some basic information then reads all (decoded) frames and
+ * counts them.
+ */
+public class VideoScan {
+
+ public static void main(String[] args) {
+ if (args.length < 1) {
+ System.err.println("No video supplied");
+ System.exit(1);
+ }
+
+ String path = args[0];
+
+ try (JJMediaReader mr = new JJMediaReader(path)) {
+ int count = 0;
+ JJMediaReader.JJReaderVideo vs = mr.openDefaultStream(JJMediaReader.TYPE_VIDEO);
+
+ if (vs == null)
+ throw new IOException("No video stream found");
+
+ int width = vs.getWidth();
+ int height = vs.getHeight();
+ String fmt = AVPixelFormat.toString(vs.getPixelFormat());
+
+ System.err.printf("Video: %s\n", path);
+ System.err.printf(" width: %d\n", width);
+ System.err.printf(" height: %d\n", height);
+ System.err.printf(" format: %s\n", fmt);
+
+ while (mr.readFrame() == vs) {
+ System.err.printf(" %08d\r", count);
+ count += 1;
+ }
+
+ System.err.printf(" frames: %d\n", count);
+ } catch (IOException ex) {
+ System.err.printf("`%s': %s\n", path, ex.getLocalizedMessage());
+ System.exit(1);
+ }
+ }
+}
--- /dev/null
+/*
+ * Copyright (C) 2019 Michael Zucchi
+ *
+ * This file is part of jjmpeg <https://www.zedzone.space/software/jjmpeg.html>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+module notzed.jjmpeg.demo {
+ requires javafx.controls;
+
+ requires notzed.jjmpeg.fx;
+ requires notzed.jjmpeg.awt;
+
+ exports au.notzed.jjmpeg.demo.video to javafx.graphics;
+}
--- /dev/null
+/*
+ * Copyright (C) 2017 Michael Zucchi
+ *
+ * This file is part of jjmpeg <https://www.zedzone.space/software/jjmpeg.html>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+package au.notzed.jjmpeg.fx;
+
+import au.notzed.jjmpeg.AVPixelFormat;
+import au.notzed.jjmpeg.AVPixelReader;
+import java.nio.Buffer;
+import java.nio.ByteBuffer;
+import java.nio.IntBuffer;
+import javafx.scene.image.PixelFormat;
+import javafx.scene.image.PixelReader;
+import javafx.scene.image.WritablePixelFormat;
+import javafx.scene.paint.Color;
+
+/**
+ * A javafx PixelReader that reads from an AVPixelReader directly.
+ * <p>
+ * There are some limitations in that the pixel reader should only
+ * convert the whole image at a time. Stripes may work in the future.
+ */
+public class FXPixelReader implements PixelReader, AVPixelReader {
+
+ AVPixelReader reader;
+
+ public FXPixelReader(AVPixelReader reader) {
+ this.reader = reader;
+ }
+
+ @Override
+ public PixelFormat getPixelFormat() {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public int getArgb(int x, int y) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public Color getColor(int x, int y) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public <T extends Buffer> void getPixels(int x, int y, int w, int h, WritablePixelFormat<T> pixelformat, T buffer, int scanlineStride) {
+ // Make sure x is 0, w == width?
+ if (buffer.hasArray()) {
+ switch (pixelformat.getType()) {
+ case BYTE_BGRA:
+ case BYTE_BGRA_PRE:
+ getPixels(y, h, AVPixelFormat.AV_PIX_FMT_BGRA, ((ByteBuffer) buffer).array(), buffer.arrayOffset() + buffer.position(), scanlineStride);
+ break;
+ case INT_ARGB:
+ case INT_ARGB_PRE:
+ getPixels(y, h, AVPixelFormat.AV_PIX_FMT_BGRA, ((IntBuffer) buffer).array(), buffer.arrayOffset() + buffer.position() / 4, scanlineStride);
+ break;
+ }
+ } else {
+ getPixels(y, h, AVPixelFormat.AV_PIX_FMT_BGRA, buffer, scanlineStride);
+ }
+ }
+
+ @Override
+ public void getPixels(int x, int y, int w, int h, WritablePixelFormat<ByteBuffer> pixelformat, byte[] buffer, int offset, int scanlineStride) {
+ getPixels(y, h, AVPixelFormat.AV_PIX_FMT_BGRA, buffer, offset, scanlineStride);
+ }
+
+ @Override
+ public void getPixels(int x, int y, int w, int h, WritablePixelFormat<IntBuffer> pixelformat, int[] buffer, int offset, int scanlineStride) {
+ getPixels(y, h, AVPixelFormat.AV_PIX_FMT_BGRA, buffer, offset, scanlineStride);
+ }
+
+ @Override
+ public <T extends Buffer> void getPixels(int y, int h, int fmt, T buffer, int scanlineStride) {
+ reader.getPixels(y, h, fmt, buffer, scanlineStride);
+ }
+
+ @Override
+ public void getPixels(int y, int h, int fmt, byte[] buffer, int offset, int scanlineStride) {
+ reader.getPixels(y, h, fmt, buffer, offset, scanlineStride);
+ }
+
+ @Override
+ public void getPixels(int y, int h, int fmt, short[] buffer, int offset, int scanlineStride) {
+ reader.getPixels(y, h, fmt, buffer, offset, scanlineStride);
+ }
+
+ @Override
+ public void getPixels(int y, int h, int fmt, int[] buffer, int offset, int scanlineStride) {
+ reader.getPixels(y, h, fmt, buffer, offset, scanlineStride);
+ }
+}
--- /dev/null
+/*
+ * Copyright (C) 2017 Michael Zucchi
+ *
+ * This file is part of jjmpeg <https://www.zedzone.space/software/jjmpeg.html>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+package au.notzed.jjmpeg.fx;
+
+import au.notzed.jjmpeg.AVPixelFormat;
+import au.notzed.jjmpeg.AVPixelWriter;
+import java.nio.Buffer;
+import java.nio.ByteBuffer;
+import java.nio.ByteOrder;
+import java.nio.IntBuffer;
+import javafx.scene.image.PixelFormat;
+import javafx.scene.image.PixelReader;
+import javafx.scene.image.PixelWriter;
+import javafx.scene.image.WritablePixelFormat;
+import javafx.scene.paint.Color;
+
+/**
+ * A javafx PixelReader that reads from an AVPixelReader directly.
+ * <p>
+ * There are some limitations in that the pixel writer should only
+ * convert the whole image at a time. Stripes may work in the future.
+ */
+public class FXPixelWriter implements PixelWriter, AVPixelWriter {
+
+ AVPixelWriter writer;
+ private final int sfmt;
+ private final int swidth;
+ private final int sheight;
+
+ public FXPixelWriter(AVPixelWriter writer, int sfmt, int swidth, int sheight) {
+ this.writer = writer;
+ this.sfmt = sfmt;
+ this.swidth = swidth;
+ this.sheight = sheight;
+ }
+
+ @Override
+ public PixelFormat getPixelFormat() {
+ return WritablePixelFormat.getByteBgraPreInstance();
+ }
+
+ @Override
+ public void setArgb(int x, int y, int argb) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public void setColor(int x, int y, Color c) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public <T extends Buffer> void setPixels(int x, int y, int w, int h, PixelFormat<T> pixelformat, T buffer, int scanlineStride) {
+ // Make sure x is 0, w == width?
+ if (buffer.hasArray()) {
+ switch (pixelformat.getType()) {
+ case BYTE_BGRA:
+ case BYTE_BGRA_PRE:
+ setPixels(y, h, AVPixelFormat.AV_PIX_FMT_BGRA, ((ByteBuffer) buffer).array(), buffer.arrayOffset() + buffer.position(), scanlineStride);
+ break;
+ case INT_ARGB:
+ case INT_ARGB_PRE:
+ setPixels(y, h, AVPixelFormat.AV_PIX_FMT_BGRA, ((IntBuffer) buffer).array(), buffer.arrayOffset() + buffer.position() / 4, scanlineStride);
+ break;
+ }
+ } else {
+ setPixels(y, h, AVPixelFormat.AV_PIX_FMT_BGRA, buffer, scanlineStride);
+ }
+ }
+
+ @Override
+ public void setPixels(int x, int y, int w, int h, PixelFormat<ByteBuffer> pixelformat, byte[] buffer, int offset, int scanlineStride) {
+ setPixels(y, h, AVPixelFormat.AV_PIX_FMT_BGRA, buffer, offset, scanlineStride);
+ }
+
+ @Override
+ public void setPixels(int x, int y, int w, int h, PixelFormat<IntBuffer> pixelformat, int[] buffer, int offset, int scanlineStride) {
+ setPixels(y, h, AVPixelFormat.AV_PIX_FMT_BGRA, buffer, offset, scanlineStride);
+ }
+
+ @Override
+ public void setPixels(int dstx, int dsty, int w, int h, PixelReader reader, int srcx, int srcy) {
+ ByteBuffer dbuffer = ByteBuffer.allocateDirect(w * h * 4).order(ByteOrder.nativeOrder());
+
+ reader.getPixels(dstx, dsty, w, h, WritablePixelFormat.getByteBgraPreInstance(), dbuffer, w * 4);
+
+ writer.setPixels(dsty, h, AVPixelFormat.AV_PIX_FMT_BGRA, dbuffer, w * 4);
+ }
+
+ @Override
+ public <T extends Buffer> void setPixels(int y, int h, int fmt, T buffer, int scanlineStride) {
+ writer.setPixels(y, h, fmt, buffer, scanlineStride);
+ }
+
+ @Override
+ public void setPixels(int y, int h, int fmt, byte[] buffer, int offset, int scanlineStride) {
+ writer.setPixels(y, h, fmt, buffer, offset, scanlineStride);
+ }
+
+ @Override
+ public void setPixels(int y, int h, int fmt, short[] buffer, int offset, int scanlineStride) {
+ writer.setPixels(y, h, fmt, buffer, offset, scanlineStride);
+ }
+
+ @Override
+ public void setPixels(int y, int h, int fmt, int[] buffer, int offset, int scanlineStride) {
+ writer.setPixels(y, h, fmt, buffer, offset, scanlineStride);
+ }
+
+}
--- /dev/null
+/*
+ * Copyright (C) 2018 Michael Zucchi
+ *
+ * This file is part of jjmpeg <https://www.zedzone.space/software/jjmpeg.html>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+module notzed.jjmpeg.fx {
+
+ requires javafx.graphics;
+ requires transitive notzed.jjmpeg;
+
+ exports au.notzed.jjmpeg.fx;
+}
--- /dev/null
+ GNU GENERAL PUBLIC LICENSE
+ Version 3, 29 June 2007
+
+ Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
+ Everyone is permitted to copy and distribute verbatim copies
+ of this license document, but changing it is not allowed.
+
+ Preamble
+
+ The GNU General Public License is a free, copyleft license for
+software and other kinds of works.
+
+ The licenses for most software and other practical works are designed
+to take away your freedom to share and change the works. By contrast,
+the GNU General Public License is intended to guarantee your freedom to
+share and change all versions of a program--to make sure it remains free
+software for all its users. We, the Free Software Foundation, use the
+GNU General Public License for most of our software; it applies also to
+any other work released this way by its authors. You can apply it to
+your programs, too.
+
+ When we speak of free software, we are referring to freedom, not
+price. Our General Public Licenses are designed to make sure that you
+have the freedom to distribute copies of free software (and charge for
+them if you wish), that you receive source code or can get it if you
+want it, that you can change the software or use pieces of it in new
+free programs, and that you know you can do these things.
+
+ To protect your rights, we need to prevent others from denying you
+these rights or asking you to surrender the rights. Therefore, you have
+certain responsibilities if you distribute copies of the software, or if
+you modify it: responsibilities to respect the freedom of others.
+
+ For example, if you distribute copies of such a program, whether
+gratis or for a fee, you must pass on to the recipients the same
+freedoms that you received. You must make sure that they, too, receive
+or can get the source code. And you must show them these terms so they
+know their rights.
+
+ Developers that use the GNU GPL protect your rights with two steps:
+(1) assert copyright on the software, and (2) offer you this License
+giving you legal permission to copy, distribute and/or modify it.
+
+ For the developers' and authors' protection, the GPL clearly explains
+that there is no warranty for this free software. For both users' and
+authors' sake, the GPL requires that modified versions be marked as
+changed, so that their problems will not be attributed erroneously to
+authors of previous versions.
+
+ Some devices are designed to deny users access to install or run
+modified versions of the software inside them, although the manufacturer
+can do so. This is fundamentally incompatible with the aim of
+protecting users' freedom to change the software. The systematic
+pattern of such abuse occurs in the area of products for individuals to
+use, which is precisely where it is most unacceptable. Therefore, we
+have designed this version of the GPL to prohibit the practice for those
+products. If such problems arise substantially in other domains, we
+stand ready to extend this provision to those domains in future versions
+of the GPL, as needed to protect the freedom of users.
+
+ Finally, every program is threatened constantly by software patents.
+States should not allow patents to restrict development and use of
+software on general-purpose computers, but in those that do, we wish to
+avoid the special danger that patents applied to a free program could
+make it effectively proprietary. To prevent this, the GPL assures that
+patents cannot be used to render the program non-free.
+
+ The precise terms and conditions for copying, distribution and
+modification follow.
+
+ TERMS AND CONDITIONS
+
+ 0. Definitions.
+
+ "This License" refers to version 3 of the GNU General Public License.
+
+ "Copyright" also means copyright-like laws that apply to other kinds of
+works, such as semiconductor masks.
+
+ "The Program" refers to any copyrightable work licensed under this
+License. Each licensee is addressed as "you". "Licensees" and
+"recipients" may be individuals or organizations.
+
+ To "modify" a work means to copy from or adapt all or part of the work
+in a fashion requiring copyright permission, other than the making of an
+exact copy. The resulting work is called a "modified version" of the
+earlier work or a work "based on" the earlier work.
+
+ A "covered work" means either the unmodified Program or a work based
+on the Program.
+
+ To "propagate" a work means to do anything with it that, without
+permission, would make you directly or secondarily liable for
+infringement under applicable copyright law, except executing it on a
+computer or modifying a private copy. Propagation includes copying,
+distribution (with or without modification), making available to the
+public, and in some countries other activities as well.
+
+ To "convey" a work means any kind of propagation that enables other
+parties to make or receive copies. Mere interaction with a user through
+a computer network, with no transfer of a copy, is not conveying.
+
+ An interactive user interface displays "Appropriate Legal Notices"
+to the extent that it includes a convenient and prominently visible
+feature that (1) displays an appropriate copyright notice, and (2)
+tells the user that there is no warranty for the work (except to the
+extent that warranties are provided), that licensees may convey the
+work under this License, and how to view a copy of this License. If
+the interface presents a list of user commands or options, such as a
+menu, a prominent item in the list meets this criterion.
+
+ 1. Source Code.
+
+ The "source code" for a work means the preferred form of the work
+for making modifications to it. "Object code" means any non-source
+form of a work.
+
+ A "Standard Interface" means an interface that either is an official
+standard defined by a recognized standards body, or, in the case of
+interfaces specified for a particular programming language, one that
+is widely used among developers working in that language.
+
+ The "System Libraries" of an executable work include anything, other
+than the work as a whole, that (a) is included in the normal form of
+packaging a Major Component, but which is not part of that Major
+Component, and (b) serves only to enable use of the work with that
+Major Component, or to implement a Standard Interface for which an
+implementation is available to the public in source code form. A
+"Major Component", in this context, means a major essential component
+(kernel, window system, and so on) of the specific operating system
+(if any) on which the executable work runs, or a compiler used to
+produce the work, or an object code interpreter used to run it.
+
+ The "Corresponding Source" for a work in object code form means all
+the source code needed to generate, install, and (for an executable
+work) run the object code and to modify the work, including scripts to
+control those activities. However, it does not include the work's
+System Libraries, or general-purpose tools or generally available free
+programs which are used unmodified in performing those activities but
+which are not part of the work. For example, Corresponding Source
+includes interface definition files associated with source files for
+the work, and the source code for shared libraries and dynamically
+linked subprograms that the work is specifically designed to require,
+such as by intimate data communication or control flow between those
+subprograms and other parts of the work.
+
+ The Corresponding Source need not include anything that users
+can regenerate automatically from other parts of the Corresponding
+Source.
+
+ The Corresponding Source for a work in source code form is that
+same work.
+
+ 2. Basic Permissions.
+
+ All rights granted under this License are granted for the term of
+copyright on the Program, and are irrevocable provided the stated
+conditions are met. This License explicitly affirms your unlimited
+permission to run the unmodified Program. The output from running a
+covered work is covered by this License only if the output, given its
+content, constitutes a covered work. This License acknowledges your
+rights of fair use or other equivalent, as provided by copyright law.
+
+ You may make, run and propagate covered works that you do not
+convey, without conditions so long as your license otherwise remains
+in force. You may convey covered works to others for the sole purpose
+of having them make modifications exclusively for you, or provide you
+with facilities for running those works, provided that you comply with
+the terms of this License in conveying all material for which you do
+not control copyright. Those thus making or running the covered works
+for you must do so exclusively on your behalf, under your direction
+and control, on terms that prohibit them from making any copies of
+your copyrighted material outside their relationship with you.
+
+ Conveying under any other circumstances is permitted solely under
+the conditions stated below. Sublicensing is not allowed; section 10
+makes it unnecessary.
+
+ 3. Protecting Users' Legal Rights From Anti-Circumvention Law.
+
+ No covered work shall be deemed part of an effective technological
+measure under any applicable law fulfilling obligations under article
+11 of the WIPO copyright treaty adopted on 20 December 1996, or
+similar laws prohibiting or restricting circumvention of such
+measures.
+
+ When you convey a covered work, you waive any legal power to forbid
+circumvention of technological measures to the extent such circumvention
+is effected by exercising rights under this License with respect to
+the covered work, and you disclaim any intention to limit operation or
+modification of the work as a means of enforcing, against the work's
+users, your or third parties' legal rights to forbid circumvention of
+technological measures.
+
+ 4. Conveying Verbatim Copies.
+
+ You may convey verbatim copies of the Program's source code as you
+receive it, in any medium, provided that you conspicuously and
+appropriately publish on each copy an appropriate copyright notice;
+keep intact all notices stating that this License and any
+non-permissive terms added in accord with section 7 apply to the code;
+keep intact all notices of the absence of any warranty; and give all
+recipients a copy of this License along with the Program.
+
+ You may charge any price or no price for each copy that you convey,
+and you may offer support or warranty protection for a fee.
+
+ 5. Conveying Modified Source Versions.
+
+ You may convey a work based on the Program, or the modifications to
+produce it from the Program, in the form of source code under the
+terms of section 4, provided that you also meet all of these conditions:
+
+ a) The work must carry prominent notices stating that you modified
+ it, and giving a relevant date.
+
+ b) The work must carry prominent notices stating that it is
+ released under this License and any conditions added under section
+ 7. This requirement modifies the requirement in section 4 to
+ "keep intact all notices".
+
+ c) You must license the entire work, as a whole, under this
+ License to anyone who comes into possession of a copy. This
+ License will therefore apply, along with any applicable section 7
+ additional terms, to the whole of the work, and all its parts,
+ regardless of how they are packaged. This License gives no
+ permission to license the work in any other way, but it does not
+ invalidate such permission if you have separately received it.
+
+ d) If the work has interactive user interfaces, each must display
+ Appropriate Legal Notices; however, if the Program has interactive
+ interfaces that do not display Appropriate Legal Notices, your
+ work need not make them do so.
+
+ A compilation of a covered work with other separate and independent
+works, which are not by their nature extensions of the covered work,
+and which are not combined with it such as to form a larger program,
+in or on a volume of a storage or distribution medium, is called an
+"aggregate" if the compilation and its resulting copyright are not
+used to limit the access or legal rights of the compilation's users
+beyond what the individual works permit. Inclusion of a covered work
+in an aggregate does not cause this License to apply to the other
+parts of the aggregate.
+
+ 6. Conveying Non-Source Forms.
+
+ You may convey a covered work in object code form under the terms
+of sections 4 and 5, provided that you also convey the
+machine-readable Corresponding Source under the terms of this License,
+in one of these ways:
+
+ a) Convey the object code in, or embodied in, a physical product
+ (including a physical distribution medium), accompanied by the
+ Corresponding Source fixed on a durable physical medium
+ customarily used for software interchange.
+
+ b) Convey the object code in, or embodied in, a physical product
+ (including a physical distribution medium), accompanied by a
+ written offer, valid for at least three years and valid for as
+ long as you offer spare parts or customer support for that product
+ model, to give anyone who possesses the object code either (1) a
+ copy of the Corresponding Source for all the software in the
+ product that is covered by this License, on a durable physical
+ medium customarily used for software interchange, for a price no
+ more than your reasonable cost of physically performing this
+ conveying of source, or (2) access to copy the
+ Corresponding Source from a network server at no charge.
+
+ c) Convey individual copies of the object code with a copy of the
+ written offer to provide the Corresponding Source. This
+ alternative is allowed only occasionally and noncommercially, and
+ only if you received the object code with such an offer, in accord
+ with subsection 6b.
+
+ d) Convey the object code by offering access from a designated
+ place (gratis or for a charge), and offer equivalent access to the
+ Corresponding Source in the same way through the same place at no
+ further charge. You need not require recipients to copy the
+ Corresponding Source along with the object code. If the place to
+ copy the object code is a network server, the Corresponding Source
+ may be on a different server (operated by you or a third party)
+ that supports equivalent copying facilities, provided you maintain
+ clear directions next to the object code saying where to find the
+ Corresponding Source. Regardless of what server hosts the
+ Corresponding Source, you remain obligated to ensure that it is
+ available for as long as needed to satisfy these requirements.
+
+ e) Convey the object code using peer-to-peer transmission, provided
+ you inform other peers where the object code and Corresponding
+ Source of the work are being offered to the general public at no
+ charge under subsection 6d.
+
+ A separable portion of the object code, whose source code is excluded
+from the Corresponding Source as a System Library, need not be
+included in conveying the object code work.
+
+ A "User Product" is either (1) a "consumer product", which means any
+tangible personal property which is normally used for personal, family,
+or household purposes, or (2) anything designed or sold for incorporation
+into a dwelling. In determining whether a product is a consumer product,
+doubtful cases shall be resolved in favor of coverage. For a particular
+product received by a particular user, "normally used" refers to a
+typical or common use of that class of product, regardless of the status
+of the particular user or of the way in which the particular user
+actually uses, or expects or is expected to use, the product. A product
+is a consumer product regardless of whether the product has substantial
+commercial, industrial or non-consumer uses, unless such uses represent
+the only significant mode of use of the product.
+
+ "Installation Information" for a User Product means any methods,
+procedures, authorization keys, or other information required to install
+and execute modified versions of a covered work in that User Product from
+a modified version of its Corresponding Source. The information must
+suffice to ensure that the continued functioning of the modified object
+code is in no case prevented or interfered with solely because
+modification has been made.
+
+ If you convey an object code work under this section in, or with, or
+specifically for use in, a User Product, and the conveying occurs as
+part of a transaction in which the right of possession and use of the
+User Product is transferred to the recipient in perpetuity or for a
+fixed term (regardless of how the transaction is characterized), the
+Corresponding Source conveyed under this section must be accompanied
+by the Installation Information. But this requirement does not apply
+if neither you nor any third party retains the ability to install
+modified object code on the User Product (for example, the work has
+been installed in ROM).
+
+ The requirement to provide Installation Information does not include a
+requirement to continue to provide support service, warranty, or updates
+for a work that has been modified or installed by the recipient, or for
+the User Product in which it has been modified or installed. Access to a
+network may be denied when the modification itself materially and
+adversely affects the operation of the network or violates the rules and
+protocols for communication across the network.
+
+ Corresponding Source conveyed, and Installation Information provided,
+in accord with this section must be in a format that is publicly
+documented (and with an implementation available to the public in
+source code form), and must require no special password or key for
+unpacking, reading or copying.
+
+ 7. Additional Terms.
+
+ "Additional permissions" are terms that supplement the terms of this
+License by making exceptions from one or more of its conditions.
+Additional permissions that are applicable to the entire Program shall
+be treated as though they were included in this License, to the extent
+that they are valid under applicable law. If additional permissions
+apply only to part of the Program, that part may be used separately
+under those permissions, but the entire Program remains governed by
+this License without regard to the additional permissions.
+
+ When you convey a copy of a covered work, you may at your option
+remove any additional permissions from that copy, or from any part of
+it. (Additional permissions may be written to require their own
+removal in certain cases when you modify the work.) You may place
+additional permissions on material, added by you to a covered work,
+for which you have or can give appropriate copyright permission.
+
+ Notwithstanding any other provision of this License, for material you
+add to a covered work, you may (if authorized by the copyright holders of
+that material) supplement the terms of this License with terms:
+
+ a) Disclaiming warranty or limiting liability differently from the
+ terms of sections 15 and 16 of this License; or
+
+ b) Requiring preservation of specified reasonable legal notices or
+ author attributions in that material or in the Appropriate Legal
+ Notices displayed by works containing it; or
+
+ c) Prohibiting misrepresentation of the origin of that material, or
+ requiring that modified versions of such material be marked in
+ reasonable ways as different from the original version; or
+
+ d) Limiting the use for publicity purposes of names of licensors or
+ authors of the material; or
+
+ e) Declining to grant rights under trademark law for use of some
+ trade names, trademarks, or service marks; or
+
+ f) Requiring indemnification of licensors and authors of that
+ material by anyone who conveys the material (or modified versions of
+ it) with contractual assumptions of liability to the recipient, for
+ any liability that these contractual assumptions directly impose on
+ those licensors and authors.
+
+ All other non-permissive additional terms are considered "further
+restrictions" within the meaning of section 10. If the Program as you
+received it, or any part of it, contains a notice stating that it is
+governed by this License along with a term that is a further
+restriction, you may remove that term. If a license document contains
+a further restriction but permits relicensing or conveying under this
+License, you may add to a covered work material governed by the terms
+of that license document, provided that the further restriction does
+not survive such relicensing or conveying.
+
+ If you add terms to a covered work in accord with this section, you
+must place, in the relevant source files, a statement of the
+additional terms that apply to those files, or a notice indicating
+where to find the applicable terms.
+
+ Additional terms, permissive or non-permissive, may be stated in the
+form of a separately written license, or stated as exceptions;
+the above requirements apply either way.
+
+ 8. Termination.
+
+ You may not propagate or modify a covered work except as expressly
+provided under this License. Any attempt otherwise to propagate or
+modify it is void, and will automatically terminate your rights under
+this License (including any patent licenses granted under the third
+paragraph of section 11).
+
+ However, if you cease all violation of this License, then your
+license from a particular copyright holder is reinstated (a)
+provisionally, unless and until the copyright holder explicitly and
+finally terminates your license, and (b) permanently, if the copyright
+holder fails to notify you of the violation by some reasonable means
+prior to 60 days after the cessation.
+
+ Moreover, your license from a particular copyright holder is
+reinstated permanently if the copyright holder notifies you of the
+violation by some reasonable means, this is the first time you have
+received notice of violation of this License (for any work) from that
+copyright holder, and you cure the violation prior to 30 days after
+your receipt of the notice.
+
+ Termination of your rights under this section does not terminate the
+licenses of parties who have received copies or rights from you under
+this License. If your rights have been terminated and not permanently
+reinstated, you do not qualify to receive new licenses for the same
+material under section 10.
+
+ 9. Acceptance Not Required for Having Copies.
+
+ You are not required to accept this License in order to receive or
+run a copy of the Program. Ancillary propagation of a covered work
+occurring solely as a consequence of using peer-to-peer transmission
+to receive a copy likewise does not require acceptance. However,
+nothing other than this License grants you permission to propagate or
+modify any covered work. These actions infringe copyright if you do
+not accept this License. Therefore, by modifying or propagating a
+covered work, you indicate your acceptance of this License to do so.
+
+ 10. Automatic Licensing of Downstream Recipients.
+
+ Each time you convey a covered work, the recipient automatically
+receives a license from the original licensors, to run, modify and
+propagate that work, subject to this License. You are not responsible
+for enforcing compliance by third parties with this License.
+
+ An "entity transaction" is a transaction transferring control of an
+organization, or substantially all assets of one, or subdividing an
+organization, or merging organizations. If propagation of a covered
+work results from an entity transaction, each party to that
+transaction who receives a copy of the work also receives whatever
+licenses to the work the party's predecessor in interest had or could
+give under the previous paragraph, plus a right to possession of the
+Corresponding Source of the work from the predecessor in interest, if
+the predecessor has it or can get it with reasonable efforts.
+
+ You may not impose any further restrictions on the exercise of the
+rights granted or affirmed under this License. For example, you may
+not impose a license fee, royalty, or other charge for exercise of
+rights granted under this License, and you may not initiate litigation
+(including a cross-claim or counterclaim in a lawsuit) alleging that
+any patent claim is infringed by making, using, selling, offering for
+sale, or importing the Program or any portion of it.
+
+ 11. Patents.
+
+ A "contributor" is a copyright holder who authorizes use under this
+License of the Program or a work on which the Program is based. The
+work thus licensed is called the contributor's "contributor version".
+
+ A contributor's "essential patent claims" are all patent claims
+owned or controlled by the contributor, whether already acquired or
+hereafter acquired, that would be infringed by some manner, permitted
+by this License, of making, using, or selling its contributor version,
+but do not include claims that would be infringed only as a
+consequence of further modification of the contributor version. For
+purposes of this definition, "control" includes the right to grant
+patent sublicenses in a manner consistent with the requirements of
+this License.
+
+ Each contributor grants you a non-exclusive, worldwide, royalty-free
+patent license under the contributor's essential patent claims, to
+make, use, sell, offer for sale, import and otherwise run, modify and
+propagate the contents of its contributor version.
+
+ In the following three paragraphs, a "patent license" is any express
+agreement or commitment, however denominated, not to enforce a patent
+(such as an express permission to practice a patent or covenant not to
+sue for patent infringement). To "grant" such a patent license to a
+party means to make such an agreement or commitment not to enforce a
+patent against the party.
+
+ If you convey a covered work, knowingly relying on a patent license,
+and the Corresponding Source of the work is not available for anyone
+to copy, free of charge and under the terms of this License, through a
+publicly available network server or other readily accessible means,
+then you must either (1) cause the Corresponding Source to be so
+available, or (2) arrange to deprive yourself of the benefit of the
+patent license for this particular work, or (3) arrange, in a manner
+consistent with the requirements of this License, to extend the patent
+license to downstream recipients. "Knowingly relying" means you have
+actual knowledge that, but for the patent license, your conveying the
+covered work in a country, or your recipient's use of the covered work
+in a country, would infringe one or more identifiable patents in that
+country that you have reason to believe are valid.
+
+ If, pursuant to or in connection with a single transaction or
+arrangement, you convey, or propagate by procuring conveyance of, a
+covered work, and grant a patent license to some of the parties
+receiving the covered work authorizing them to use, propagate, modify
+or convey a specific copy of the covered work, then the patent license
+you grant is automatically extended to all recipients of the covered
+work and works based on it.
+
+ A patent license is "discriminatory" if it does not include within
+the scope of its coverage, prohibits the exercise of, or is
+conditioned on the non-exercise of one or more of the rights that are
+specifically granted under this License. You may not convey a covered
+work if you are a party to an arrangement with a third party that is
+in the business of distributing software, under which you make payment
+to the third party based on the extent of your activity of conveying
+the work, and under which the third party grants, to any of the
+parties who would receive the covered work from you, a discriminatory
+patent license (a) in connection with copies of the covered work
+conveyed by you (or copies made from those copies), or (b) primarily
+for and in connection with specific products or compilations that
+contain the covered work, unless you entered into that arrangement,
+or that patent license was granted, prior to 28 March 2007.
+
+ Nothing in this License shall be construed as excluding or limiting
+any implied license or other defenses to infringement that may
+otherwise be available to you under applicable patent law.
+
+ 12. No Surrender of Others' Freedom.
+
+ If conditions are imposed on you (whether by court order, agreement or
+otherwise) that contradict the conditions of this License, they do not
+excuse you from the conditions of this License. If you cannot convey a
+covered work so as to satisfy simultaneously your obligations under this
+License and any other pertinent obligations, then as a consequence you may
+not convey it at all. For example, if you agree to terms that obligate you
+to collect a royalty for further conveying from those to whom you convey
+the Program, the only way you could satisfy both those terms and this
+License would be to refrain entirely from conveying the Program.
+
+ 13. Use with the GNU Affero General Public License.
+
+ Notwithstanding any other provision of this License, you have
+permission to link or combine any covered work with a work licensed
+under version 3 of the GNU Affero General Public License into a single
+combined work, and to convey the resulting work. The terms of this
+License will continue to apply to the part which is the covered work,
+but the special requirements of the GNU Affero General Public License,
+section 13, concerning interaction through a network will apply to the
+combination as such.
+
+ 14. Revised Versions of this License.
+
+ The Free Software Foundation may publish revised and/or new versions of
+the GNU General Public License from time to time. Such new versions will
+be similar in spirit to the present version, but may differ in detail to
+address new problems or concerns.
+
+ Each version is given a distinguishing version number. If the
+Program specifies that a certain numbered version of the GNU General
+Public License "or any later version" applies to it, you have the
+option of following the terms and conditions either of that numbered
+version or of any later version published by the Free Software
+Foundation. If the Program does not specify a version number of the
+GNU General Public License, you may choose any version ever published
+by the Free Software Foundation.
+
+ If the Program specifies that a proxy can decide which future
+versions of the GNU General Public License can be used, that proxy's
+public statement of acceptance of a version permanently authorizes you
+to choose that version for the Program.
+
+ Later license versions may give you additional or different
+permissions. However, no additional obligations are imposed on any
+author or copyright holder as a result of your choosing to follow a
+later version.
+
+ 15. Disclaimer of Warranty.
+
+ THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
+APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
+HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
+OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
+THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
+IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
+ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
+
+ 16. Limitation of Liability.
+
+ IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
+WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
+THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
+GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
+USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
+DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
+PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
+EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
+SUCH DAMAGES.
+
+ 17. Interpretation of Sections 15 and 16.
+
+ If the disclaimer of warranty and limitation of liability provided
+above cannot be given local legal effect according to their terms,
+reviewing courts shall apply local law that most closely approximates
+an absolute waiver of all civil liability in connection with the
+Program, unless a warranty or assumption of liability accompanies a
+copy of the Program in return for a fee.
+
+ END OF TERMS AND CONDITIONS
+
+ How to Apply These Terms to Your New Programs
+
+ If you develop a new program, and you want it to be of the greatest
+possible use to the public, the best way to achieve this is to make it
+free software which everyone can redistribute and change under these terms.
+
+ To do so, attach the following notices to the program. It is safest
+to attach them to the start of each source file to most effectively
+state the exclusion of warranty; and each file should have at least
+the "copyright" line and a pointer to where the full notice is found.
+
+ <one line to give the program's name and a brief idea of what it does.>
+ Copyright (C) <year> <name of author>
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program 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 General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+Also add information on how to contact you by electronic and paper mail.
+
+ If the program does terminal interaction, make it output a short
+notice like this when it starts in an interactive mode:
+
+ <program> Copyright (C) <year> <name of author>
+ This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
+ This is free software, and you are welcome to redistribute it
+ under certain conditions; type `show c' for details.
+
+The hypothetical commands `show w' and `show c' should show the appropriate
+parts of the General Public License. Of course, your program's commands
+might be different; for a GUI interface, you would use an "about box".
+
+ You should also get your employer (if you work as a programmer) or school,
+if any, to sign a "copyright disclaimer" for the program, if necessary.
+For more information on this, and how to apply and follow the GNU GPL, see
+<http://www.gnu.org/licenses/>.
+
+ The GNU General Public License does not permit incorporating your program
+into proprietary programs. If your program is a subroutine library, you
+may consider it more useful to permit linking proprietary applications with
+the library. If this is what you want to do, use the GNU Lesser General
+Public License instead of this License. But first, please read
+<http://www.gnu.org/philosophy/why-not-lgpl.html>.
--- /dev/null
+/*
+ * Copyright (C) 2019 Michael Zucchi
+ *
+ * This file is part of jjmpeg <https://www.zedzone.space/software/jjmpeg.html>
+ *
+ * jjmpeg is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * jjmpeg 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 for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with jjmpeg. If not, see <http://www.gnu.org/licenses/>.
+ */
+package au.notzed.jjmpeg;
+
+/**
+ */
+public class AVChannelLayout extends AVObject implements AVChannelLayoutBits {
+
+ /**
+ * Call av_get_channel_layout(name)
+ */
+ public static native long valueOf(String name);
+
+ /**
+ * Call av_get_channel_name(value)
+ */
+ public static native String toString(long value);
+
+ /**
+ * call av_get_channel_layout_nb_channels(layout)
+ *
+ * @param layout
+ * @return
+ */
+ public static native int getNumChannels(long layout);
+
+ /**
+ * call av_get_default_channel_layout(nb_channels)
+ *
+ * @param nchannels
+ * @return
+ */
+ public static native long getDefaultLayout(int nchannels);
+
+ private AVChannelLayout(long p) {
+ super(p);
+ }
+}
--- /dev/null
+/*
+ * Copyright (C) 2017 Michael Zucchi
+ *
+ * This file is part of jjmpeg <https://www.zedzone.space/software/jjmpeg.html>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+package au.notzed.jjmpeg;
+
+/**
+ *
+ */
+public class AVCodec extends AVObject implements AVCodecBits, AVDiscardBits {
+
+ private AVCodec(long p) {
+ super(p);
+ }
+
+ private static native void release(long p);
+
+ public static native int getVersion();
+
+ public static native String getConfiguration();
+
+ public static native String getLicense();
+
+ public static native void registerAll();
+
+ public static native AVCodec next(AVCodec val);
+
+ public static Iterable<AVCodec> codecs() {
+ return () -> new AVObjectIterator<>(AVCodec::next);
+ }
+
+ public static native AVCodec findDecoder(int codecID);
+
+ public static native AVCodec findDecoder(String name);
+
+ public static native AVCodec findEncoder(int codecID);
+
+ public static native AVCodec findEncoder(String name);
+
+ /*
+ Accessors
+ */
+ public native String getName();
+
+ public native String getLongName();
+
+ public native int getType();
+
+ public native int getID();
+
+ public native int getCapabilities();
+
+ public native AVRational[] getFramerates();
+
+ public native int[] getPixelFormats();
+
+ public native int[] getSampleRates();
+
+ public native int[] getSampleFormats();
+
+ public native long[] getChannelLayouts();
+
+ public native int getMaxLowres();
+}
--- /dev/null
+/*
+ * Copyright (C) 2017 Michael Zucchi
+ *
+ * This file is part of jjmpeg <https://www.zedzone.space/software/jjmpeg.html>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+package au.notzed.jjmpeg;
+
+/**
+ * AVCodecContext accessors.
+ * <p>
+ */
+public class AVCodecContext extends AVOptions implements AVCodecContextBits {
+
+ private AVCodecContext(long p) {
+ super(p);
+ }
+
+ private static native void release(long p);
+
+ /*
+ * Methods
+ */
+ /**
+ *
+ * @param codec
+ * @return
+ */
+ public static native AVCodecContext allocContext(AVCodec codec);
+
+ // avcodec_open2
+ public native void open(AVCodec codec, AVDictionary options) throws AVIOException;
+
+ public native void flushBuffers();
+
+ public native AVSize alignDimensions(AVSize input);
+
+ /**
+ * Calls avcodec_send_packet()
+ * <p>
+ * If the return value is EAGAIN or AVERROR_EOF then this function
+ * returns false, for all other error values it throws an exception.
+ *
+ * @param pkt
+ * @return true if the packet was accepted, false if a frame must be received first.
+ * @throws AVIOException
+ */
+ public native boolean sendPacket(AVPacket pkt) throws AVIOException;
+
+ /**
+ * Calls avcodec_receive_frame().
+ * <p>
+ * If the return value is EAGAIN or AVERROR_EOF then this function
+ * returns false, for all other error values it throws an exception.
+ *
+ * @param frame
+ * @return Returns true if the frame is complete, false otherwise.
+ * @throws AVIOException
+ */
+ public native boolean receiveFrame(AVFrame frame) throws AVIOException;
+
+ /**
+ * Calls avcodec_send_frame().
+ * <p>
+ * If the return value is EAGAIN or AVERROR_EOF then this function
+ * returns false, for all other error values it throws an exception.
+ *
+ * @param frame
+ * @return
+ * @throws AVIOException
+ */
+ public native boolean sendFrame(AVFrame frame) throws AVIOException;
+
+ /**
+ * Calls avcodec_receive_packet().
+ * <p>
+ * If the return value is EAGAIN or AVERROR_EOF then this function
+ * returns false, for all other error values it throws an exception.
+ *
+ * @param pkt
+ * @return
+ * @throws AVIOException
+ */
+ public native boolean receivePacket(AVPacket pkt) throws AVIOException;
+
+ /*
+ * Accessors
+ */
+ public native int getCodecType();
+
+ public native void setCodecType(int val);
+
+ public native int getCodecID();
+
+ public native void setCodecID(int val);
+
+ public native int getCodecTag();
+
+ public native void setCodecTag(int val);
+
+ public native long getBitRate();
+
+ public native void setBitRate(long val);
+
+ public native int getBitRateTolerance();
+
+ public native void setBitRateTolerance(int val);
+
+ public native int getGlobalQuality();
+
+ public native void setGlobalQuality(int val);
+
+ public native int getCompressionLevel();
+
+ public native void setCompressionLevel(int val);
+
+ /**
+ * Get the contents of flags and flags2 together as a single 64-bit value.
+ *
+ * @return
+ */
+ public native long getFlags();
+
+ /**
+ * Set or clear flags and flags2.
+ *
+ * @param mask Mask of bits to change. Only flags with a bit set here will be altered.
+ * @param flags Value to set bits to.
+ */
+ public native void setFlags(long mask, long flags);
+
+ /**
+ * Get the timebase.
+ * <p>
+ * Note that the return value is a value type (copy) not a reference.
+ *
+ * @return
+ */
+ public native AVRational getTimeBase();
+
+ public native void setTimeBase(AVRational val);
+
+ public native int getTicksPerFrame();
+
+ public native void setTicksPerFrame(int val);
+
+ public native int getDelay();
+
+ /*
+ Video only options
+ */
+ public native int getWidth();
+
+ public native void setWidth(int val);
+
+ public native int getHeight();
+
+ public native void setHeight(int val);
+
+ public native AVRational getAspectRatio();
+
+ public native void setAspectRatio(AVRational r);
+
+ // codedWidth, codedHeight
+ public native int getGOPSize();
+
+ public native void setGOPSize(int val);
+
+ public native int getPixelFormat();
+
+ public native void setPixelFormat(int val);
+
+ //
+ public native int getMaxBFrames();
+
+ public native void setMaxBFrames(int val);
+
+ public native float getBQuantFactor();
+
+ public native void setBQuantFactor(float val);
+
+ public native float getBQuantOffset();
+
+ public native void setBQuantOffset(float val);
+
+ public native boolean hasBFrames();
+
+ public native float getIQuantFactor();
+
+ public native void setIQuantFactor(float val);
+
+ public native float getIQuantOffset();
+
+ public native void setIQuantOffset(float val);
+// And a whole lot more ...
+//
+
+ public native int getMBDecision();
+
+ public native void setMBDecision(int val);
+// ...
+
+ /*
+ Audtio only options
+ */
+ public native int getSampleRate();
+
+ public native void setSampleRate(int val);
+
+ public native int getNumChannels();
+
+ public native void setNumChannels(int val);
+
+ public native int getSampleFormat();
+
+ public native void setSampleFormat(int val);
+
+ public native int getFrameSize();
+
+ public native void setFrameSize(int val);
+
+ public native int getFrameNumber();
+
+// int block_align
+// int cutoff
+ public native long getChannelLayout();
+
+ public native void setChannelLayout(long val);
+
+ public native long getRequestChannelLayout();
+
+ public native void setRequestChannelLayout(long val);
+
+// enum AVAudioServiceType audio_service_type
+// enum AVSampleFormat request_sample_fmt;
+
+ /*
+ Encoding parameters
+ */
+// float qcompress
+// float qblur
+// float qmin
+// float qmax
+// float max_qdiff
+// int rc_buffer_size
+// int rc_override_count
+// RCOverride *rc_override
+// int64_t rc_max_rate
+// int64_t rc_min_rate
+// ... more rc stuff
+// ...
+// int trellis
+// ...
+// int workaround_bugs
+ public native int getStrictStdCompliance();
+
+ public native void setStrictStdCompliance(int val);
+
+ public native int getErrorConcealment();
+
+ public native void setErrorConcealment(int val);
+// int debug
+
+ public native int getErrorRecognition();
+
+ public native void setErrorRecognition(int val);
+
+ public native int getDCTAlgo();
+
+ public native void setDCTAlgo(int val);
+
+ public native int getIDCTAlgo();
+
+ public native void setIDCTAlgo(int val);
+
+ public native int getThreadCount();
+
+ public native void setThreadCount(int val);
+// ...
+
+ public native int getProfile();
+
+ public native void setProfile(int val);
+// ...
+}
--- /dev/null
+/*
+ * Copyright (C) 2017 Michael Zucchi
+ *
+ * This file is part of jjmpeg <https://www.zedzone.space/software/jjmpeg.html>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+package au.notzed.jjmpeg;
+
+/**
+ */
+public class AVCodecID implements AVCodecIDBits {
+
+ /**
+ * Call avcodec_get_name(value)
+ */
+ public static native String toString(int value);
+
+ /**
+ * Call avcodec_get_type(value)
+ *
+ * @param value AVCodecID.
+ * @return Corresponding AVMediaType.
+ */
+ public static native int getType(int value);
+}
--- /dev/null
+/*
+ * Copyright (C) 2017 Michael Zucchi
+ *
+ * This file is part of jjmpeg <https://www.zedzone.space/software/jjmpeg.html>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+package au.notzed.jjmpeg;
+
+/**
+ *
+ */
+public class AVCodecParameters extends AVObject {
+
+ private AVCodecParameters(long p) {
+ super(p);
+ }
+
+ private static native void release(long p);
+
+ public static native AVCodecParameters alloc();
+
+ public native void copy(AVCodecParameters src);
+
+ public native void fromContext(AVCodecContext cc);
+
+ public native void toContext(AVCodecContext cc);
+
+ /* */
+ public native int getCodecType();
+
+ public native void setCodecType(int type);
+
+ public native int getCodecID();
+
+ public native void setCodecID(int id);
+
+ public native int getCodecTag();
+
+ public native void setCodecTag(int val);
+
+ public native long getBitRate();
+
+ public native void setBitRate(long val);
+
+ /*
+ Video only options
+ */
+ public native int getPixelFormat();
+
+ public native void setPixelFormat(int val);
+
+ public native int getWidth();
+
+ public native void setWidth(int val);
+
+ public native int getHeight();
+
+ public native void setHeight(int val);
+
+ public native AVRational getAspectRatio();
+
+ public native void setAspectRatio(AVRational r);
+
+ /*
+ * Audio stuff
+ */
+ public native int getSampleFormat();
+
+ public native void setSampleFormat(int val);
+
+ public native long getChannelLayout();
+
+ public native void setChannelLayout(long val);
+
+ public native int getNumChannels();
+
+ public native void setNumChannels(int val);
+
+ public native int getSampleRate();
+
+ public native void setSampleRate(int val);
+
+ // ryv?
+}
--- /dev/null
+/*
+ * Copyright (C) 2017 Michael Zucchi
+ *
+ * This file is part of jjmpeg <https://www.zedzone.space/software/jjmpeg.html>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+package au.notzed.jjmpeg;
+
+/**
+ * Interface to libavdevice.
+ * <p>
+ * This is currently a dummy object but could hold AVDeviceInfo if that was useful.
+ */
+public class AVDevice extends AVObject {
+
+ private AVDevice(long p) {
+ super(p);
+ }
+
+ private static void release(long p) {
+ }
+
+ public static native int getVersion();
+
+ public static native String getConfiguration();
+
+ public static native String getLicense();
+
+ public static native void registerAll();
+
+ public native static AVInputFormat nextAudioInputDevice(AVInputFormat last);
+
+ public static Iterable<AVInputFormat> audioInputDevices() {
+ return () -> new AVObjectIterator<>(AVDevice::nextAudioInputDevice);
+ }
+
+ public native static AVInputFormat nextVideoInputDevice(AVInputFormat last);
+
+ public static Iterable<AVInputFormat> videoInputDevices() {
+ return () -> new AVObjectIterator<>(AVDevice::nextVideoInputDevice);
+ }
+
+ public native static AVOutputFormat nextAudioOutputDevice(AVOutputFormat last);
+
+ public static Iterable<AVOutputFormat> audioOutputDevices() {
+ return () -> new AVObjectIterator<>(AVDevice::nextAudioOutputDevice);
+ }
+
+ public native static AVOutputFormat nextVideoOutputDevice(AVOutputFormat last);
+
+ public static Iterable<AVOutputFormat> videoOutputDevices() {
+ return () -> new AVObjectIterator<>(AVDevice::nextVideoOutputDevice);
+ }
+
+}
--- /dev/null
+/*
+ * Copyright (C) 2017 Michael Zucchi
+ *
+ * This file is part of jjmpeg <https://www.zedzone.space/software/jjmpeg.html>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+package au.notzed.jjmpeg;
+
+import java.util.Collection;
+import java.util.Map.Entry;
+import java.util.TreeMap;
+
+/**
+ * AVDictionary is a remarkably shithouse "ADT" inherited by ffmpeg from libav.
+ * <p>
+ * Because the pointer can be changed by any of the update functions this
+ * doesn't bother trying to wrap the C api. Instead it maintains it's own
+ * set of data and converts it to an array of strings on demand.
+ * <p>
+ * It's a tree because ... I don't know.
+ */
+public class AVDictionary extends TreeMap<String, String> {
+
+ public Object[] toArray() {
+ return entrySet().toArray();
+ }
+
+ public void setAll(Collection set) {
+ this.entrySet().retainAll(set);
+ }
+
+ public String[] toDictionary() {
+ String[] list = new String[size() * 2];
+ int i = 0;
+
+ for (Entry<String, String> e: entrySet()) {
+ list[i++] = e.getKey();
+ list[i++] = e.getValue();
+ }
+
+ return list;
+ }
+
+ public void fromDictionary(String[] set) {
+ clear();
+ if (set != null) {
+ for (int i = 0; i < set.length; i += 2) {
+ put(set[i], set[i + 1]);
+ }
+ }
+ }
+}
--- /dev/null
+/*
+ * Copyright (C) 2017 Michael Zucchi
+ *
+ * This file is part of jjmpeg <https://www.zedzone.space/software/jjmpeg.html>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+package au.notzed.jjmpeg;
+
+/**
+ *
+ */
+public class AVError implements AVErrorBits {
+
+ public static native String toString(int errno);
+}
--- /dev/null
+/*
+ * Copyright (C) 2017 Michael Zucchi
+ *
+ * This file is part of jjmpeg <https://www.zedzone.space/software/jjmpeg.html>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+package au.notzed.jjmpeg;
+
+import java.io.FileNotFoundException;
+
+/**
+ *
+ */
+public class AVFormatContext extends AVOptions {
+
+ private AVFormatContext(long p) {
+ super(p);
+ }
+
+ private static native void release(long p);
+
+ // Fields
+ public native AVInputFormat getInputFormat();
+
+ public native AVOutputFormat getOutputFormat();
+
+ // hmm?
+ //public native void setOutputFormat(AVOutputFormat val);
+
+ public native AVIOContext getIOContext();
+
+ public native void setIOContext(AVIOContext val);
+
+ /* stream info */
+ public native int getCtxFlags();
+
+ public native int getNumStreams();
+
+ public native AVStream getStream(int index);
+
+ //public native String getFilename();
+ //public native void setFilename(String name);
+ //
+ public native long getStartTime();
+
+ public native long getDuration();
+
+ public native long getBitRate();
+// packet_size
+// max_delay
+
+ public native int getFlags();
+
+ public native void setFlags(int val);
+
+ public native long getProbeSize();
+
+ public native void setProbeSize(long val);
+
+ public native long getMaxAnalyseDuration();
+
+ public native void setMaxAnalyseDuration(long val);
+// ...
+
+ public native int getVideoCodecID();
+
+ public native void setVideoCodecID(int val);
+
+ public native int getAudioCodecID();
+
+ public native void setAudioCodecID(int val);
+
+ public native int getSubtitleCodecID();
+
+ public native void setSubtitleCodecID(int val);
+// ...
+
+ public native AVDictionary getMetadata();
+
+ public native void setMetadata(AVDictionary val);
+// ...
+
+ public native void setDebug(int val);
+// ...
+
+ public native int getSeek2Any();
+
+ public native void setSeek2Any(int val);
+
+ // Native Methods
+ public static native int getVersion();
+
+ public static native String getConfiguration();
+
+ public static native String getLicense();
+
+ public static native void registerAll();
+
+ // registerInputFormat()
+ // registerOutputFormat()
+ public static native void networkInit();
+
+ public static native void networkDeinit();
+
+ //
+ static public native AVFormatContext allocContext();
+
+ public native AVStream newStream(AVCodec c);
+
+ // newProgram
+ static public native AVFormatContext allocContext(AVOutputFormat of, String format_name, String filename) throws AVIOException;
+
+ // probeInputFormat / 2 / 3
+ // probeInputBuffer / 2
+ public static native AVFormatContext openInput(String url, AVInputFormat fmt, AVDictionary options) throws AVIOException, FileNotFoundException;
+
+ // options is updated by result
+ public native void findStreamInfo(AVDictionary[] options) throws AVIOException;
+
+ // returns false on end of file
+ public native boolean readFrame(AVPacket pkt) throws AVIOException;
+
+ public native void seekFrame(int stream_index, long timestamp, int flags) throws AVIOException;
+
+ public native void seekFile(int stream_index, long min_ts, long ts, long max_ts, int flags) throws AVIOException;
+
+ public native void flush() throws AVIOException;
+
+ public native void readPlay() throws AVIOException;
+
+ public native void readPause() throws AVIOException;
+
+ // two separate ways to close!!
+ // closeInput() -> has to p <= null
+ // freeContext()
+ //
+ public native int writeHeader(AVDictionary options) throws AVIOException;
+
+ public native int initOutput(AVDictionary options) throws AVIOException;
+
+ // returns true if flushed
+ public native boolean writeFrame(AVPacket pktkt) throws AVIOException;
+
+ public native void interleavedWriteFrame(AVPacket pkt) throws AVIOException;
+
+ public native void writeUncodedFrame(int stream_index, AVFrame frame) throws AVIOException;
+
+ public native void interleavedWriteUncodedFrame(int stream_index, AVFrame frame) throws AVIOException;
+
+ public native void writeTrailer() throws AVIOException;
+
+ public native int findDefaultStreamIndex();
+}
--- /dev/null
+/*
+ * Copyright (C) 2017 Michael Zucchi
+ *
+ * This file is part of jjmpeg <https://www.zedzone.space/software/jjmpeg.html>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+package au.notzed.jjmpeg;
+
+import java.nio.Buffer;
+import java.nio.ByteBuffer;
+
+/**
+ * Accessor for a struct AVFrame.
+ * <p>
+ * Both video and audio frames are stored in the same object; various fields
+ * will only make sense for the corresponding data.
+ * <p>
+ * To read and write pixels for video frames use {@link getPixelReader} and {@link getPixelWriter}.
+ * <p>
+ * To read and write samples for audio frames use {@link getSampleReader} and {@link getSampleWriter}.
+ */
+public class AVFrame extends AVObject {
+
+ private AVFrame(long p) {
+ super(p);
+ }
+
+ private native static void release(long p);
+
+ public native static AVFrame alloc();
+
+ public native void copy(AVFrame source);
+
+ public native void copyProperties(AVFrame source);
+
+ /*
+ * Data stuff.
+ * <p>
+ * TODO: perhaps i want audio/video specific versions, as the interpretation
+ * of the fields depends upon it. It depends on whether this is easy to determine
+ * from other fields.
+ */
+ @Deprecated
+ public native ByteBuffer getPlane(int i);
+
+ @Deprecated
+ public native int getStride(int i);
+
+ /*
+ * Video stuff
+ */
+ /**
+ * Create a new AVFrame and allocate video frame information.
+ * <p>
+ * This calls av_frame_alloc(), initialises the provided fields and
+ * then calls av_frame_get_buffer().
+ *
+ * @param fmt
+ * @param width
+ * @param height
+ * @return
+ */
+ public native static AVFrame alloc(int fmt, int width, int height);
+
+ public native int getWidth();
+
+ public native void setWidth(int width);
+
+ public native int getHeight();
+
+ public native void setHeight(int height);
+
+ /**
+ * .format for video.
+ *
+ * @return
+ */
+ public native int getPixelFormat();
+
+ public native boolean isKeyFrame();
+
+ public native AVRational getAspectRatio();
+
+ public native long getPTS();
+
+ public native void setPTS(long val);
+
+ public native int getDisplayPictureNumber();
+
+ public native int getCodedPictureNumber();
+
+ public native boolean isInterlaced();
+
+ public native boolean isTopFieldFirst();
+
+ /*
+ * Audio stuff
+ */
+ public native static AVFrame alloc(int fmt, int channels, long channel_layout, int num_samples);
+
+ public native int getNumSamples();
+
+ public native void setNumSamples(int n);
+
+ /**
+ * .format for audio.
+ *
+ * @return
+ */
+ public native int getSampleFormat();
+
+ public native int getSampleRate();
+
+ public native void setSampleRate(int v);
+
+ public native long getChannelLayout();
+
+ public native void setChannelLayout(long v);
+
+ public native int getNumChannels();
+
+ public native void setNumChannels(int v);
+
+ public native int getBestEffortTimestamp();
+
+ /**
+ * Create a PixelReader for this frame. Pixel readers can convert the image format and perform scaling.
+ * <p>
+ * Multiple readers with differing options may be created from a given frame.
+ *
+ * @param dwidth target width
+ * @param dheight target height
+ * @param flags SwsContext creation flags
+ * @return A pixel reader. Note that scanlineStride is currently ignored for all getPixels() calls.
+ */
+ public AVPixelReader getPixelReader(int dwidth, int dheight, int flags) {
+ return FrameReader.alloc(this, dwidth, dheight, flags);
+ }
+
+ static class FrameReader extends AVObject implements AVPixelReader {
+
+ private FrameReader(long p) {
+ super(p);
+ }
+
+ private native static void release(long p);
+
+ public native static FrameReader alloc(AVFrame frame, int width, int height, int flags);
+
+ @Override
+ native public <T extends Buffer> void getPixels(int y, int h, int fmt, T buffer, int scanlineStride);
+
+ @Override
+ native public void getPixels(int y, int h, int fmt, byte[] buffer, int offset, int scanlineStride);
+
+ @Override
+ native public void getPixels(int y, int h, int fmt, short[] buffer, int offset, int scanlineStride);
+
+ @Override
+ native public void getPixels(int y, int h, int fmt, int[] buffer, int offset, int scanlineStride);
+ }
+
+ public AVPixelWriter getPixelWriter(int swidth, int sheight, int flags) {
+ return FrameWriter.alloc(this, swidth, sheight, flags);
+ }
+
+ static class FrameWriter extends AVObject implements AVPixelWriter {
+
+ private FrameWriter(long p) {
+ super(p);
+ }
+
+ private native static void release(long p);
+
+ public native static FrameWriter alloc(AVFrame frame, int width, int height, int flags);
+
+ @Override
+ native public <T extends Buffer> void setPixels(int y, int h, int fmt, T buffer, int scanlineStride);
+
+ @Override
+ native public void setPixels(int y, int h, int fmt, byte[] buffer, int offset, int scanlineStride);
+
+ @Override
+ native public void setPixels(int y, int h, int fmt, short[] buffer, int offset, int scanlineStride);
+
+ @Override
+ native public void setPixels(int y, int h, int fmt, int[] buffer, int offset, int scanlineStride);
+ }
+
+ /**
+ * Create a new sample reader.
+ *
+ * @param layout AVChannelLayout. Planar formats are not supported.
+ * @param fmt AVSampleFormat.
+ * @param rate sample rate
+ * @return an AVSampleReader which will retrieve samples of the given
+ * format and layout.
+ */
+ public AVSampleReader getSampleReader(long layout, int fmt, int rate) {
+ return SampleReader.alloc(this, layout, fmt, rate);
+ }
+
+ static class SampleReader extends AVObject implements AVSampleReader {
+
+ private SampleReader(long p) {
+ super(p);
+ }
+
+ private native static void release(long p);
+
+ public native static SampleReader alloc(AVFrame frame, long layout, int fmt, int rate);
+
+ @Override
+ public native int getNumSamples();
+
+ @Override
+ public native int getSamples(byte[] buffer, int offset, int length);
+
+ @Override
+ public native int getSamples(short[] buffer, int offset, int length);
+
+ @Override
+ public native int getSamples(int[] buffer, int offset, int length);
+
+ @Override
+ public native int getSamples(float[] buffer, int offset, int length);
+
+ @Override
+ public native <T extends Buffer> void getSamples(T buffer);
+
+ }
+
+ public AVSampleWriter getSampleWriter(long layout, int fmt, int rate) {
+ //return SampleReader.alloc(this, layout, fmt, rate);
+ throw new UnsupportedOperationException();
+ }
+
+}
--- /dev/null
+/*
+ * Copyright (C) 2017 Michael Zucchi
+ *
+ * This file is part of jjmpeg <https://www.zedzone.space/software/jjmpeg.html>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+package au.notzed.jjmpeg;
+
+import java.nio.ByteBuffer;
+
+/**
+ *
+ */
+public class AVIOContext extends AVOptions {
+
+ // TODO: autogen?
+ public static final int AVSEEK_SIZE = 0x10000;
+ public static final int AVSEEK_FORCE = 0x20000;
+ //
+ public static final int AVSEEK_SET = 0;
+ public static final int AVSEEK_CUR = 1;
+ public static final int AVSEEK_END = 2;
+ //
+ public static final int ALLOC_WRITE = 1;
+ public static final int ALLOC_STREAMED = 2;
+ // flags for open
+ public static final int AVIO_FLAG_READ = 1;
+ public static final int AVIO_FLAG_WRITE = 2;
+ public static final int AVIO_FLAG_READ_WRITE = 3;
+ // flags for alloc seekable
+ /**
+ * Seeking works like for a local file.
+ */
+ public static final int AVIO_SEEKABLE_NORMAL = (1 << 0);
+
+ /**
+ * Seeking by timestamp with avio_seek_time() is possible.
+ */
+ public static final int AVIO_SEEKABLE_TIME = (1 << 1);
+ /**
+ * pseudo-flag for alloc() which sets writable to avio_context_create.
+ */
+ public static final int AVIO_WRITABLE = (1 << 31);
+ /**
+ * pseudo-flaga for alloc() which sets the direct indicator on the
+ * created context.
+ */
+ public static final int AVIO_DIRECT = (1 << 30);
+
+ private AVIOContext(long p) {
+ super(p);
+ }
+
+ private static native void release(long p);
+
+ //?public native int getSeekable();
+ /**
+ * Calls avio_open.
+ * <p>
+ * TODO: should it call avio_open2?
+ *
+ * @param url
+ * @param avio_flags AVIO_FLAGS_*.
+ * @return
+ */
+ public static native AVIOContext open(String url, int avio_flags) throws AVIOException;
+
+ /**
+ *
+ * @param buffer_size
+ * @param alloc_flags combination of AVIO_SEEKABLE_*, AVIO_WRITABLE, and AVIO_DIRECT.
+ * @param handler
+ * @return
+ */
+ public static native AVIOContext alloc(int buffer_size, int alloc_flags, AVIOHandler handler);
+
+ public interface AVIOHandler {
+
+ /**
+ * Read data into dest.
+ *
+ * @param dst ByteBuffer with position and limit set to the bounds of valid data.
+ * @return The number of bytes actually read or -errno on error.
+ */
+ public int readPacket(ByteBuffer dst);
+
+ /**
+ * Write from src.
+ *
+ * @param src ByteBuffer with position and limit set to the bounds of valid data.
+ * @return Number of bytes written or -errno on error.
+ */
+ public int writePacket(ByteBuffer src);
+
+ public long seek(long offset, int whence);
+ }
+}
--- /dev/null
+/*
+ * Copyright (C) 2017 Michael Zucchi
+ *
+ * This file is part of jjmpeg <https://www.zedzone.space/software/jjmpeg.html>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+package au.notzed.jjmpeg;
+
+import java.io.IOException;
+
+/**
+ *
+ */
+public class AVIOException extends IOException {
+
+ private final int error;
+
+ public AVIOException(int error) {
+ this.error = error;
+ }
+
+ public AVIOException(int error, String msg) {
+ super(msg);
+ this.error = error;
+ }
+
+ public int getError() {
+ return error;
+ }
+
+ /**
+ * Retreieve the strerror() description of error.
+ *
+ * @return
+ */
+ public String getDescription() {
+ return AVError.toString(error);
+ }
+
+ @Override
+ public String getLocalizedMessage() {
+ return String.format("%d (%s): %s", error, getDescription(), super.getLocalizedMessage());
+ }
+
+}
--- /dev/null
+/*
+ * Copyright (C) 2017 Michael Zucchi
+ *
+ * This file is part of jjmpeg <https://www.zedzone.space/software/jjmpeg.html>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+package au.notzed.jjmpeg;
+
+/**
+ *
+ */
+public class AVInputFormat extends AVObject {
+
+ private AVInputFormat(long p) {
+ super(p);
+ }
+
+ public static native AVInputFormat findInputFormat(String name);
+
+ public static native AVInputFormat next(AVInputFormat val);
+
+ public static Iterable<AVInputFormat> formats() {
+ return () -> new AVObjectIterator<>(AVInputFormat::next);
+ }
+
+ public native void register();
+
+ public native String getName();
+
+ public native String getLongName();
+}
--- /dev/null
+/*
+ * Copyright (c) 2006 Michael Niedermayer <michaelni@gmx.at>
+ * Copyright (C) 2017 Michael Zucchi
+ *
+ * This file is part of jjmpeg <https://www.zedzone.space/software/jjmpeg.html>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+package au.notzed.jjmpeg;
+
+/**
+ *
+ */
+public interface AVLogger {
+
+ /**
+ * Print no output.
+ */
+ public static final int AV_LOG_QUIET = -8;
+
+ /**
+ * Something went really wrong and we will crash now.
+ */
+ public static final int AV_LOG_PANIC = 0;
+
+ /**
+ * Something went wrong and recovery is not possible.
+ * For example, no header was found for a format which depends
+ * on headers or an illegal combination of parameters is used.
+ */
+ public static final int AV_LOG_FATAL = 8;
+
+ /**
+ * Something went wrong and cannot losslessly be recovered.
+ * However, not all future data is affected.
+ */
+ public static final int AV_LOG_ERROR = 16;
+
+ /**
+ * Something somehow does not look correct. This may or may not
+ * lead to problems. An example would be the use of '-vstrict -2'.
+ */
+ public static final int AV_LOG_WARNING = 24;
+
+ /**
+ * Standard information.
+ */
+ public static final int AV_LOG_INFO = 32;
+
+ /**
+ * Detailed information.
+ */
+ public static final int AV_LOG_VERBOSE = 40;
+
+ /**
+ * Stuff which is only useful for libav* developers.
+ */
+ public static final int AV_LOG_DEBUG = 48;
+
+ /**
+ * Extremely verbose debugging, useful for libav* development.
+ */
+ public static final int AV_LOG_TRACE = 56;
+
+ public void log(int level, String what);
+
+}
--- /dev/null
+/*
+ * Copyright (C) 2017 Michael Zucchi
+ *
+ * This file is part of jjmpeg <https://www.zedzone.space/software/jjmpeg.html>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+package au.notzed.jjmpeg;
+
+/**
+ *
+ */
+public class AVMediaType implements AVMediaTypeBits {
+
+ /**
+ * Call av_get_media_type_string()
+ */
+ public static native String toString(int value);
+}
--- /dev/null
+/*
+ * Copyright (C) 2017 Michael Zucchi
+ *
+ * This file is part of jjmpeg <https://www.zedzone.space/software/jjmpeg.html>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+package au.notzed.jjmpeg;
+
+import au.notzed.nativez.NativeZ;
+import java.util.Iterator;
+import java.util.function.Function;
+import java.util.logging.Logger;
+
+/**
+ *
+ */
+public abstract class AVObject extends NativeZ {
+
+ protected AVObject(long p) {
+ super(p);
+ }
+
+ static {
+ System.loadLibrary("jjmpeg");
+
+ AVCodec.registerAll();
+ AVFormatContext.registerAll();
+ //AVDevice.registerAll(); // ignore failure?
+
+ AVUtil.setLogger(AVUtil.createAVLogger(Logger.getLogger("notzed.jjmpeg")));
+ }
+
+ /**
+ * Handy iterator for various uses in the library.
+ */
+ static class AVObjectIterator<T> implements Iterator<T> {
+
+ Function<T, T> nextFunc;
+ T next;
+
+ public AVObjectIterator(Function<T, T> nextFunc) {
+ this.nextFunc = nextFunc;
+ this.next = nextFunc.apply(null);
+ }
+
+ @Override
+ public boolean hasNext() {
+ return next != null;
+ }
+
+ @Override
+ public T next() {
+ T current = next;
+ next = nextFunc.apply(current);
+ return current;
+ }
+ }
+}
--- /dev/null
+/*
+ * Copyright (C) 2017 Michael Zucchi
+ *
+ * This file is part of jjmpeg <https://www.zedzone.space/software/jjmpeg.html>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+package au.notzed.jjmpeg;
+
+/**
+ * All objects that support av_opt* stuff should derive from this.
+ * <p>
+ * Quite a lot of code here, is it worth it? Should it just
+ * have set from string/serialise calls instead??
+ */
+public abstract class AVOptions extends AVObject implements AVOptionsBits {
+
+ protected AVOptions(long p) {
+ super(p);
+ }
+
+ //
+ // There is a lot of code here, is it useful, or can it just
+ // use the get/setOptions() calls?
+ //
+ public native void set(String name, String val, int flags);
+
+ public native void setInt(String name, long val, int flags);
+
+ public native void setDouble(String name, double val, int flags);
+
+ public native void setQ(String name, AVRational val, int flags);
+
+ // ??
+ public native void setBin(String name, byte[] data, int offset, int len, int flags);
+
+ public native void setImageSize(String name, AVSize size, int flags);
+
+ public native void setPixelFormat(String name, int fmt, int flags);
+
+ public native void setSampleFormat(String name, int fmt, int flags);
+
+ public native void setVideoRate(String name, AVRational val, int flags);
+
+ public native void setChannelLayout(String name, long val, int flags);
+
+ public native void setDictionary(String name, AVDictionary val, int flags);
+
+ /*
+
+ */
+ public native String get(String name, int flags);
+
+ public native long getInt(String name, int flags);
+
+ public native double getDouble(String name, int flags);
+
+ public native AVRational getQ(String name, int flags);
+
+ public native AVSize getImageSize(String name, int flags);
+
+ public native int getPixelFormat(String name, int flags);
+
+ public native int getSampleFormat(String name, int flags);
+
+ public native AVRational getVideoRate(String name, int flags);
+
+ public native long getChannelLayout(String name, int flags);
+
+ public native AVDictionary getDictionary(String name, int flags);
+
+ /**
+ * Call set_options_string(this, serialised, "=", ",")
+ *
+ * @param serialised
+ */
+ public native void setOptions(String serialised);
+
+ /**
+ * Call opt_serialise(this, opt_flags, ser_flags, &result, '=', ',')
+ *
+ * @param opt_flags
+ * @param ser_flags
+ * @return
+ */
+ public native String getOptions(int opt_flags, int ser_flags);
+
+ public native <T extends AVOptions> void copyOptions(T src);
+
+ public native AVOption nextOption(AVOption val);
+
+ public Iterable<AVOption> options() {
+ return () -> new AVObjectIterator<>(this::nextOption);
+ }
+
+ public native AVOption find(String name, String unit, int opt_flags, int search_flags);
+
+ public static class AVOption {
+
+ private final long p;
+ public final String name;
+ public final String help;
+ public final int type;
+ public final int flags;
+ public final String unit;
+
+ public AVOption(long p, String name, String help, int type, int flags, String unit) {
+ this.p = p;
+ this.name = name;
+ this.help = help;
+ this.type = type;
+ this.flags = flags;
+ this.unit = unit;
+ }
+ }
+}
--- /dev/null
+/*
+ * Copyright (C) 2017 Michael Zucchi
+ *
+ * This file is part of jjmpeg <https://www.zedzone.space/software/jjmpeg.html>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+package au.notzed.jjmpeg;
+
+/**
+ *
+ */
+public class AVOutputFormat extends AVObject {
+
+ private AVOutputFormat(long p) {
+ super(p);
+ }
+
+ public static final int AVFMT_NOFILE = 0x0001;
+ public static final int AVFMT_NEEDNUMBER = 0x0002;
+ public static final int AVFMT_GLOBALHEADER = 0x0040;
+ public static final int AVFMT_NOTIMESTAMPS = 0x0080;
+ public static final int AVFMT_VARIABLE_FPS = 0x0400;
+ public static final int AVFMT_NODIMENSIONS = 0x0800;
+ public static final int AVFMT_NOSTREAMS = 0x1000;
+ public static final int AVFMT_ALLOW_FLUSH = 0x10000;
+ public static final int AVFMT_TS_NONSTRICT = 0x20000;
+ public static final int AVFMT_TS_NEGATIVE = 0x40000;
+
+ public static native AVOutputFormat guessFormat(String short_name, String filename, String mime_type);
+
+ public native int guessCodecID(String short_name, String filename, String mime_type, int media_type);
+
+ public static native AVOutputFormat next(AVOutputFormat val);
+
+ public static Iterable<AVOutputFormat> formats() {
+ return () -> new AVObjectIterator<>(AVOutputFormat::next);
+ }
+
+ public native void register();
+
+ public native String getName();
+
+ public native String getLongName();
+
+ public native String getMimeType();
+
+ public native String getExtensions();
+
+ public native int getVideoCodec();
+
+ public native int getAudioCodec();
+
+ public native int getSubtitleCodec();
+
+ public native int getFlags();
+
+}
--- /dev/null
+/*
+ * Copyright (C) 2017 Michael Zucchi
+ *
+ * This file is part of jjmpeg <https://www.zedzone.space/software/jjmpeg.html>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+package au.notzed.jjmpeg;
+
+import java.nio.ByteBuffer;
+
+/**
+ * AVPacket stores compressed stream data.
+ * <p>
+ * This contains some data pointers and is mostly handled by
+ * libavcodec/libavformat, all we really do is pass them between
+ * encoders/decoders to/from formats.
+ */
+public class AVPacket extends AVObject implements Cloneable {
+
+ private AVPacket(long p) {
+ super(p);
+ }
+
+ /**
+ * The packet contains a keyframe
+ */
+ public static final int AV_PKT_FLAG_KEY = 0x0001;
+ /**
+ * The packet content is corrupted
+ */
+ public static final int AV_PKT_FLAG_CORRUPT = 0x0002;
+ /**
+ * Flag is used to discard packets which are required to maintain valid
+ * decoder state but are not required for output and should be dropped
+ * after decoding.
+ *
+ */
+ public static final int AV_PKT_FLAG_DISCARD = 0x0004;
+ /**
+ * The packet comes from a trusted source.
+ * <p>
+ * Otherwise-unsafe constructs such as arbitrary pointers to data
+ * outside the packet may be followed.
+ */
+ public static final int AV_PKT_FLAG_TRUSTED = 0x0008;
+
+ /**
+ * Calls av_packet_free.
+ *
+ * @param p
+ */
+ private static native void release(long p);
+
+ /**
+ * Creates a new packet (initialised) with no data.
+ * Calls av_packet_alloc
+ *
+ * @return
+ */
+ public static native AVPacket alloc();
+
+ /**
+ * Retrieve the current data buffer pointer and size.
+ * <p>
+ * This value should not be saved between calls which might update the packet.
+ * <p>
+ * TODO: do i even need this?
+ *
+ * @return
+ */
+ public native ByteBuffer getData();
+
+ /**
+ * Clear and free any data pointers and returns the packet to an initialised state.
+ * <p>
+ * It needs to be called ... at certain points I guess.
+ * <p>
+ * This calls av_packet_unref().
+ */
+ public native void clear();
+
+ @Override
+ public native AVPacket clone();
+
+ public native void rescaleTS(AVRational src, AVRational dst);
+
+ /* */
+ public native long getPTS();
+
+ public native void setPTS(long val);
+
+ public native long getDTS();
+
+ public native void setDTS(long val);
+
+ public native int getSize();
+
+ public native int getStreamIndex();
+
+ public native void setStreamIndex(int val);
+
+ public native int getFlags();
+
+ public native void setFlags(int mask, int val);
+
+ public native long getPosition();
+
+}
--- /dev/null
+/*
+ * Copyright (C) 2017 Michael Zucchi
+ *
+ * This file is part of jjmpeg <https://www.zedzone.space/software/jjmpeg.html>
+ *
+ * jjmpeg is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * jjmpeg 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 for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with jjmpeg. If not, see <http://www.gnu.org/licenses/>.
+ */
+package au.notzed.jjmpeg;
+
+/**
+ */
+public class AVPixelFormat implements AVPixelFormatBits {
+
+ /**
+ * Call av_get_pix_fmt(name)
+ */
+ public static native int valueOf(String name);
+
+ /**
+ * Call av_get_pix_fmt_name(value)
+ */
+ public static native String toString(int value);
+}
--- /dev/null
+/*
+ * Copyright (C) 2017 Michael Zucchi
+ *
+ * This file is part of jjmpeg <https://www.zedzone.space/software/jjmpeg.html>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+package au.notzed.jjmpeg;
+
+import java.nio.Buffer;
+
+/**
+ * AVPixelReader is a high level interface to SwsContext.
+ * <p>
+ * This interface allows one to retrieve pixels by bands to a specific format.
+ *
+ * @see AVFrame:getPixelReader
+ */
+public interface AVPixelReader {
+
+ /**
+ * Read pixels into a Buffer. The buffer must be a Direct*Buffer.
+ *
+ * @param <T>
+ * @param y Start scanline. Currently only 0 works.
+ * @param h End scanline output. Currently only the output height works.
+ * @param fmt Pixel format to write to.
+ * @param buffer Target for pixels.
+ * @param scanlineStride Should match the output width and may be ignored.
+ */
+ public <T extends Buffer> void getPixels(int y, int h, int fmt, T buffer, int scanlineStride);
+
+ public void getPixels(int y, int h, int fmt, byte[] buffer, int offset, int scanlineStride);
+
+ public void getPixels(int y, int h, int fmt, short[] buffer, int offset, int scanlineStride);
+
+ public void getPixels(int y, int h, int fmt, int[] buffer, int offset, int scanlineStride);
+
+}
--- /dev/null
+/*
+ * Copyright (C) 2017 Michael Zucchi
+ *
+ * This file is part of jjmpeg <https://www.zedzone.space/software/jjmpeg.html>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+package au.notzed.jjmpeg;
+
+import java.nio.Buffer;
+
+/**
+ *
+ */
+public interface AVPixelWriter {
+
+ public <T extends Buffer> void setPixels(int y, int h, int fmt, T buffer, int scanlineStride);
+
+ public void setPixels(int y, int h, int fmt, byte[] buffer, int offset, int scanlineStride);
+
+ public void setPixels(int y, int h, int fmt, short[] buffer, int offset, int scanlineStride);
+
+ public void setPixels(int y, int h, int fmt, int[] buffer, int offset, int scanlineStride);
+
+}
--- /dev/null
+/*
+ * Copyright (c) 2003 Michael Niedermayer <michaelni@gmx.at>
+ * Copyright (C) 2017 Michael Zucchi
+ *
+ * This file is part of jjmpeg <https://www.zedzone.space/software/jjmpeg.html>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+package au.notzed.jjmpeg;
+
+/**
+ * AVRational holds a rational number.
+ * <p>
+ * In previous versions of jjmpeg this was a reference type, it has
+ * changed to a value type and made a Number.
+ */
+public class AVRational extends Number implements Comparable<AVRational> {
+
+ public final int num;
+ public final int den;
+
+ public AVRational(int num, int den) {
+ this.num = num;
+ this.den = den;
+ }
+
+ /**
+ * Calls av_d2q
+ *
+ * @param d
+ * @param max
+ * @return
+ */
+ public static native AVRational d2q(double d, int max);
+
+ /**
+ * Calls av_rescale().
+ *
+ * @param a
+ * @param b
+ * @param c
+ * @return a * b / c
+ */
+ public static native long rescale(long a, long b, long c);
+
+ /**
+ *
+ * @param c
+ * @return this * c
+ */
+ public native AVRational mul(AVRational c);
+
+ /**
+ *
+ * @param c
+ * @return this / c
+ */
+ public native AVRational div(AVRational c);
+
+ public native AVRational add(AVRational c);
+
+ public native AVRational sub(AVRational c);
+
+ /**
+ * Calculate ts * (num * scale) / den
+ *
+ * @param ts
+ * @param scale
+ * @return
+ */
+ public long rescale(long ts, int scale) {
+ return rescale(ts, num * scale, den);
+ }
+
+ @Override
+ public String toString() {
+ return String.format("%d/%d", num, den);
+ }
+
+ @Override
+ public int intValue() {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public long longValue() {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public float floatValue() {
+ return (float) num / den;
+ }
+
+ @Override
+ public double doubleValue() {
+ return (double) num / den;
+ }
+
+ /**
+ * Compare two rationals.
+ *
+ * @param b Second rational
+ *
+ * Taken from avutil/rational.c
+ *
+ * @return One of the following values:
+ * <ul>
+ * <li>0 if `a == b`
+ * <li>1 if `a > b`
+ * <li>-1 if `a < b`
+ * <li>`INT_MIN` if one of the values is of the form `0 / 0`
+ * </ul>
+ */
+ @Override
+ public int compareTo(AVRational b) {
+ long tmp = num * (long) b.den - b.num * (long) den;
+
+ if (tmp != 0)
+ return (int) ((tmp ^ den ^ b.den) >> 63) | 1;
+ else if (b.den != 0 && den != 0)
+ return 0;
+ else if (num != 0 && b.num != 0)
+ return (num >> 31) - (b.num >> 31);
+ else
+ return Integer.MIN_VALUE;
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2001 Fabrice Bellard
+ *
+ * This file is part of jjmpeg, a java binding to ffmpeg's libraries.
+ *
+ * jjmpeg is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * jjmpeg 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 for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with jjmpeg. If not, see <http://www.gnu.org/licenses/>.
+ */
+package au.notzed.jjmpeg;
+
+/**
+ */
+public class AVSampleFormat implements AVSampleFormatBits {
+
+ /**
+ * Call av_get_sample_fmt(name)
+ */
+
+ public static native int valueOf(String name);
+
+ /**
+ * Call av_get_sample_fmt_name(value)
+ */
+ public static native String toString(int value);
+}
+
--- /dev/null
+/*
+ * Copyright (C) 2017 Michael Zucchi
+ *
+ * This file is part of jjmpeg <https://www.zedzone.space/software/jjmpeg.html>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+package au.notzed.jjmpeg;
+
+import java.nio.Buffer;
+
+/**
+ * High level interface to libswresample.
+ * <p>
+ * This allows reading samples directly in a desired format.
+ * <p>
+ * This is somewhat simpler than AVPixelReader as it doesn't need to support
+ * external interfaces.
+ */
+public interface AVSampleReader {
+
+ /**
+ * Retrieve the number of samples available.
+ *
+ * @return
+ */
+ public int getNumSamples();
+
+ /**
+ * Retrieve converted samples.
+ * <p>
+ *
+ * @param buffer output buffer
+ * @param offset output buffer offset
+ * @param length maximum amount to read, this must currently be at least {@link getNumSamples} * sample data size * channels.
+ * @return The number of valid samples converted.
+ * @todo pass in lengh and keep calling until drained. problem is how to track the state internally.
+ */
+ public int getSamples(byte[] buffer, int offset, int length);
+
+ public int getSamples(short[] buffer, int offset, int length);
+
+ public int getSamples(int[] buffer, int offset, int length);
+
+ public int getSamples(float[] buffer, int offset, int length);
+
+ /**
+ * Read into a direct byte buffer.
+ * <p>
+ * The remaining size of the buffer must have sufficient space for {@link getNumSamples} samples.
+ *
+ * @param <T>
+ * @param buffer The data is written to the buffer at it's current
+ * position, and the position is updated.
+ */
+ public <T extends Buffer> void getSamples(T buffer);
+
+}
--- /dev/null
+/*
+ * Copyright (C) 2017 Michael Zucchi
+ *
+ * This file is part of jjmpeg <https://www.zedzone.space/software/jjmpeg.html>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+package au.notzed.jjmpeg;
+
+import java.nio.Buffer;
+
+/**
+ * AVSampleWriter.
+ * <p>
+ * This is only a placeholder.
+ */
+public interface AVSampleWriter {
+
+ public int setSamples(byte[] buffer, int offset, int length);
+
+ public int setSamples(short[] buffer, int offset, int length);
+
+ public int setSamples(int[] buffer, int offset, int length);
+
+ public int setSamples(float[] buffer, int offset, int length);
+
+ public <T extends Buffer> void setSamples(T buffer);
+
+}
--- /dev/null
+/*
+ * Copyright (C) 2017 Michael Zucchi
+ *
+ * This file is part of jjmpeg <https://www.zedzone.space/software/jjmpeg.html>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+package au.notzed.jjmpeg;
+
+/**
+ *
+ */
+public class AVSize {
+
+ public int width;
+ public int height;
+
+ public AVSize() {
+ }
+
+ public AVSize(int width, int height) {
+ this.width = width;
+ this.height = height;
+ }
+
+}
--- /dev/null
+/*
+ * Copyright (C) 2017 Michael Zucchi
+ *
+ * This file is part of jjmpeg <https://www.zedzone.space/software/jjmpeg.html>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+package au.notzed.jjmpeg;
+
+/**
+ *
+ */
+public class AVStream extends AVObject {
+
+ private AVStream(long p) {
+ super(p);
+ }
+
+ public native int getIndex();
+
+ public native int getID();
+
+ public native void setID(int id);
+
+ public native AVRational getTimeBase();
+
+ public native void setTimeBase(AVRational value);
+
+ public native long getStartTime();
+
+ public native void setStartTime(long val);
+
+ public native long getDuration();
+
+ public native void setDuration(long val);
+
+ public native long getNumFrames();
+
+ public native void setNumFrames(long val);
+
+ public native int getDiscard();
+
+ public native void setDiscard(int val);
+
+ public native AVRational getAverageFrameRate();
+
+ public native void setAverageFrameRate(AVRational val);
+
+ public native AVRational getSampleAspectRatio();
+
+ public native void setSampleAspectRatio(AVRational val);
+
+ public native AVRational getDisplayAspectRatio();
+
+ public native void setDisplayAspectRatio(AVRational val);
+
+ public native AVCodecParameters getCodecParameters();
+
+ // not sure about this?
+ public native void setCodecParameters(AVCodecParameters val);
+}
--- /dev/null
+/*
+ * Copyright (C) 2017 Michael Zucchi
+ *
+ * This file is part of jjmpeg <https://www.zedzone.space/software/jjmpeg.html>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+package au.notzed.jjmpeg;
+
+import static java.lang.Math.min;
+import java.util.Arrays;
+import java.util.logging.Level;
+import java.util.logging.LogRecord;
+import java.util.logging.Logger;
+
+/**
+ * Static methods for other non-class based interfaces.
+ */
+public class AVUtil {
+
+ /**
+ * Call av_log_set_callback() with the provided logger.
+ *
+ * @param logger Logger callback. Use null to set the default ffmpeg callback.
+ */
+ public native static void setLogger(AVLogger logger);
+
+ private static final int levels[] = {
+ AVLogger.AV_LOG_QUIET,
+ AVLogger.AV_LOG_PANIC,
+ AVLogger.AV_LOG_FATAL,
+ AVLogger.AV_LOG_ERROR,
+ AVLogger.AV_LOG_WARNING,
+ AVLogger.AV_LOG_INFO,
+ AVLogger.AV_LOG_VERBOSE,
+ AVLogger.AV_LOG_DEBUG,
+ AVLogger.AV_LOG_TRACE
+ };
+
+ private static final Level jlevels[] = {
+ Level.SEVERE,
+ Level.SEVERE,
+ Level.SEVERE,
+ Level.SEVERE,
+ Level.WARNING,
+ Level.INFO,
+ Level.FINE,
+ Level.FINER,
+ Level.FINEST
+ };
+
+ public static AVLogger createAVLogger(Logger log) {
+ return (int l, String what) -> {
+ int jl = Arrays.binarySearch(levels, l);
+
+ // Map to java.util.logging level
+ if (jl < 0)
+ jl = -jl;
+ jl = min(jl, levels.length - 1);
+
+ if (log.isLoggable(jlevels[jl])) {
+ LogRecord lr = new LogRecord(jlevels[jl], what);
+ Throwable t = new Throwable();
+
+ // Look up the actual method name which logged the message.
+ // The LogRecord routine will uselessly just find this method instead.
+ StackTraceElement[] list = t.getStackTrace();
+ if (list.length > 1) {
+ lr.setSourceClassName(list[1].getClassName());
+ lr.setSourceMethodName(list[1].getMethodName());
+ }
+
+ log.log(lr);
+ }
+ };
+ }
+}
--- /dev/null
+/*
+ * Copyright (C) 2017 Michael Zucchi
+ *
+ * This file is part of jjmpeg <https://www.zedzone.space/software/jjmpeg.html>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+package au.notzed.jjmpeg;
+
+/**
+ * Software Audio Scaling Operations.
+ * <p>
+ * @deprecated unimplemented! Use AVFrame.getSampleReader().
+ */
+@Deprecated
+public class SwrContext extends AVObject {
+
+ public static final int SWR_DITHER_NONE = 0;
+ public static final int SWR_DITHER_RECTANGULAR = 1;
+ public static final int SWR_DITHER_TRIANGULAR = 2;
+ public static final int SWR_DITHER_TRIANGULAR_HIGHPASS = 3;
+ /* Resampling engine */
+ public static final int SWR_ENGINE_SWR = 0;
+ public static final int SWR_ENGINE_SOXR = 1;
+ /* Filtering */
+ public static final int SWR_FILTER_TYPE_CUBIC = 0;
+ public static final int SWR_FILTER_TYPE_BLACKMAN_NUTTALL = 1;
+ public static final int SWR_FILTER_TYPE_KAISER = 2;
+
+ private SwrContext(long p) {
+ super(p);
+ }
+
+ private static native void release(long p);
+
+ public static native int getVersion();
+
+ public static native String getConfiguration();
+
+ public static native String getLicense();
+
+ public native static SwrContext create();
+
+ public native static void setOptions(
+ long out_ch_layout, int out_sample_fmt, int out_sample_rate,
+ long int_ch_layout, int in_sample_fmt, int in_sample_rate); // throws some error
+
+ public native void setOptions(AVFrame out, AVFrame in);
+
+ public native void initialise();
+
+ public native int getOutSamples(int in_samples);
+
+ public native int convert(byte[][] out, int out_count, byte[][] in, int in_count);
+
+ // throws AVERROR_INPUT_CHANGED, AVERROR_OUTPUT_CHANGED
+ // or do i just reconfigure/hide it?
+ public native void convert(AVFrame out, AVFrame in);
+
+}
--- /dev/null
+/*
+ * Copyright (C) 2017 Michael Zucchi
+ *
+ * This file is part of jjmpeg <https://www.zedzone.space/software/jjmpeg.html>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+package au.notzed.jjmpeg;
+
+import java.nio.ByteBuffer;
+
+/**
+ * Software Scaling Operations.
+ * <p>
+ * See also AVFrame.getPixelReader() for a higher level implementation.
+ * <p>
+ * @deprecated Not fully implemented Use {@link AVFrame:getPixelReader}
+ */
+@Deprecated
+public class SwsContext extends AVObject {
+
+ public static final int SWS_FAST_BILINEAR = 1;
+ public static final int SWS_BILINEAR = 2;
+ public static final int SWS_BICUBIC = 4;
+ public static final int SWS_X = 8;
+ public static final int SWS_POINT = 0x10;
+ public static final int SWS_AREA = 0x20;
+ public static final int SWS_BICUBLIN = 0x40;
+ public static final int SWS_GAUSS = 0x80;
+ public static final int SWS_SINC = 0x100;
+ public static final int SWS_LANCZOS = 0x200;
+ public static final int SWS_SPLINE = 0x400;
+ // more here
+
+ private SwsContext(long p) {
+ super(p);
+ }
+
+ private static native void release(long p);
+
+ public static native int getVersion();
+
+ public static native String getConfiguration();
+
+ public static native String getLicense();
+
+ public native static SwsContext alloc(
+ int srcW, int srcH, int srcFormat,
+ int dstW, int dstH, int dstFormat,
+ int flags,
+ SwsFilter srcFilter,
+ SwsFilter dstFilter,
+ double[] params);
+
+ public native int scale(AVFrame src, int srcSliceY, int srcSliceH, AVFrame dst);
+
+ /* these aren't implemented yet, they need size and stuff passed in */
+ public native int scale(AVFrame src, int srcSliceY, int srcSliceH, int[] dst);
+
+ public native int scale(AVFrame src, int srcSliceY, int srcSliceH, byte[] dst);
+
+ public native int scale(byte[] src, int srcSliceY, int srcSliceH, AVFrame dst);
+
+ public native int scale(ByteBuffer src, int srcSliceY, int srcSliceH, AVFrame dst);
+
+ /*
+ Other than AVFrame<>AVFrame the interfaces above cannot be easily made to work.
+
+ */
+}
--- /dev/null
+/*
+ * Copyright (C) 2017 Michael Zucchi
+ *
+ * This file is part of jjmpeg <https://www.zedzone.space/software/jjmpeg.html>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+package au.notzed.jjmpeg;
+
+/**
+ * TODO: fill this out
+ *
+ * @deprecated not implemented.
+ */
+@Deprecated
+public class SwsFilter extends AVObject {
+
+ private SwsFilter(long p) {
+ super(p);
+ }
+
+ private native static void release(long p);
+
+ public static native SwsFilter create(
+ float lumaGBlur, float chromaGBlur,
+ float lumaSharpen, float chromaSharpen,
+ float chromaHShift, float chromaVShift,
+ int verbose);
+
+}
--- /dev/null
+/*
+ * Copyright (c) 2012 Michael Zucchi
+ *
+ * This file is part of jjmpeg, a java binding to ffmpeg's libraries.
+ *
+ * jjmpeg is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * jjmpeg 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 for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with jjmpeg. If not, see <http://www.gnu.org/licenses/>.
+ */
+package au.notzed.jjmpeg.io;
+
+import au.notzed.jjmpeg.AVCodec;
+import au.notzed.jjmpeg.AVCodecContext;
+import au.notzed.jjmpeg.AVCodecID;
+import au.notzed.jjmpeg.AVCodecParameters;
+import au.notzed.jjmpeg.AVDictionary;
+import au.notzed.jjmpeg.AVDiscardBits;
+import au.notzed.jjmpeg.AVError;
+import au.notzed.jjmpeg.AVFormatContext;
+import au.notzed.jjmpeg.AVFrame;
+import au.notzed.jjmpeg.AVIOException;
+import au.notzed.jjmpeg.AVInputFormat;
+import au.notzed.jjmpeg.AVMediaType;
+import au.notzed.jjmpeg.AVPacket;
+import au.notzed.jjmpeg.AVPixelFormat;
+import au.notzed.jjmpeg.AVRational;
+import au.notzed.jjmpeg.AVSampleFormat;
+import au.notzed.jjmpeg.AVStream;
+import java.io.FileNotFoundException;
+import java.util.Iterator;
+import java.util.logging.Logger;
+
+/**
+ * High level interface for scanning audio and video frames.
+ * <p>
+ * TODO: handle all frames.
+ *
+ * @author notzed
+ */
+public class JJMediaReader implements AutoCloseable {
+
+ JJReaderStream[] streams;
+ AVFormatContext format;
+ private AVPacket packet;
+ private boolean freePacket = false;
+ //
+ long seekid = -1;
+ long seekms = -1;
+ //
+
+ /**
+ * VIDEO Type indicator for openDefaultStream().
+ */
+ public static final Class<JJReaderVideo> TYPE_VIDEO = JJReaderVideo.class;
+ /**
+ * AUDIO Type indicator for openDefaultStream().
+ */
+ public static final Class<JJReaderAudio> TYPE_AUDIO = JJReaderAudio.class;
+
+ /**
+ * Create a new media reader, will scan the file for available streams.
+ *
+ * @param name
+ * @throws AVIOException
+ */
+ public JJMediaReader(String name) throws AVIOException, FileNotFoundException {
+ this(name, null, null);
+ }
+
+ public JJMediaReader(String name, AVInputFormat fmt, AVDictionary options) throws AVIOException, FileNotFoundException {
+ this(AVFormatContext.openInput(name, fmt, options));
+ }
+
+ public JJMediaReader(AVFormatContext format) throws AVIOException {
+ this.format = format;
+
+ //System.out.println("scan streams");
+ //format.setProbesize(1024 * 64);
+ //format.setMaxAnalyzeDuration(500000);
+ format.findStreamInfo(null);
+
+ // find all streams and map to something
+ int nstreams = format.getNumStreams();
+ streams = new JJReaderStream[nstreams];
+ for (int i = 0; i < nstreams; i++) {
+ AVStream s = format.getStream(i);
+ AVCodecParameters cp = s.getCodecParameters();
+ switch (cp.getCodecType()) {
+ case AVMediaType.AVMEDIA_TYPE_VIDEO:
+ streams[i] = new JJReaderVideo(s, cp);
+ break;
+ case AVMediaType.AVMEDIA_TYPE_AUDIO:
+ streams[i] = new JJReaderAudio(s, cp);
+ break;
+ default:
+ streams[i] = new JJReaderUnknown(s, cp);
+ s.setDiscard(AVDiscardBits.AVDISCARD_ALL);
+ break;
+ }
+ }
+
+ packet = AVPacket.alloc();
+ }
+
+ /**
+ * Open the first stream of the given type.
+ * <p>
+ * A note on the implementation. The complexity here is to
+ * ensure runtime type checking works in a generic context.
+ * <p>
+ * Is it worth it?
+ * <p>
+ * TODO: ignore open failures and go to the next one?
+ *
+ * @param <T>
+ * @param type
+ * @return
+ * @throws AVIOException
+ */
+ public <T extends JJReaderStream> T openDefaultStream(Class<T> type) throws AVIOException {
+ for (JJReaderStream rs : streams) {
+ if (type.isInstance(rs)) {
+ T m = type.cast(rs);
+ if (!m.isOpened())
+ m.open();
+ return m;
+ }
+ }
+ return null;
+ }
+
+ public Iterable<? extends JJReaderStream> streams() {
+ return () -> {
+ return new Iterator<JJReaderStream>() {
+ int i = 0;
+
+ @Override
+ public boolean hasNext() {
+ return i < streams.length;
+ }
+
+ @Override
+ public JJReaderStream next() {
+ return streams[i++];
+ }
+ };
+ };
+ }
+
+ public void release() {
+ for (JJReaderStream m : streams) {
+ m.release();
+ }
+ format.release();
+ packet.release();
+ }
+
+ @Override
+ public void close() {
+ release();
+ }
+
+ /**
+ * Get source AVFormatContext.
+ *
+ * @return
+ */
+ public AVFormatContext getFormat() {
+ return format;
+ }
+ long pts;
+
+ /**
+ * Retrieve (calculated) pts of the last frame decoded.
+ * <p>
+ * Well be -1 at EOF
+ *
+ * @return
+ */
+ public long getPTS() {
+ return pts;
+ }
+
+ /**
+ * call flushBuffers() on all opened streams codecs.
+ * <p>
+ * e.g. after a seek.
+ */
+ public void flushCodec() {
+ for (JJReaderStream rs : streams) {
+ rs.flushCodec();
+ }
+ }
+
+ private long currentVideoMS() {
+ for (JJReaderStream r : streams) {
+ if (r instanceof JJReaderVideo) {
+ return r.convertPTS(getPTS());
+ }
+ }
+ return -1;
+ }
+
+ /**
+ * Attempt to seek to the nearest millisecond.
+ * <p>
+ * The next frame will have pts (in milliseconds) >= stamp.
+ *
+ * @param stamp
+ * @throws AVIOException
+ */
+ public void seekMS(long stamp) throws AVIOException {
+ // This is an attempt at an optimisation, for small seeks (< 1 second)
+ // just parse/discard frames.
+ // This is going to be faster on many codecs than a flush/seek which will probably
+ // have to jump through more frames after a keyframe anyway
+ long current = currentVideoMS();
+ if (current != -1 && (stamp - current) >= 0 && (stamp - current) < 1000) {
+ seekms = stamp;
+ } else {
+ format.seekFile(-1, 0, stamp * 1000, stamp * 1000, 0);
+ seekms = stamp;
+
+ flushCodec();
+ }
+ }
+
+ /**
+ * Seek in stream units
+ * <p>
+ * The next frame will have pts >= stamp
+ *
+ * @param stamp
+ * @throws AVIOException
+ */
+ public void seek(long stamp) throws AVIOException {
+ format.seekFile(-1, 0, stamp, stamp, 0);
+ seekid = stamp;
+
+ flushCodec();
+ }
+
+ /**
+ * Reads and decodes packets until data is ready in one of the opened streams.
+ *
+ * @return
+ */
+ public JJReaderStream readFrame() throws AVIOException {
+
+ if (freePacket) {
+ packet.clear();
+ }
+ freePacket = false;
+
+ while (format.readFrame(packet)) {
+ try {
+ int index = packet.getStreamIndex();
+ JJReaderStream ms = streams[index];
+
+ if (ms != null) {
+ if (ms.isOpened() && ms.decode(packet)) {
+ pts = packet.getDTS();
+
+ // If seeking, attempt to get to the exact frame
+ if (seekid != -1
+ && pts < seekid) {
+ continue;
+ } else if (seekms != -1
+ && ms.convertPTS(pts) < seekms) {
+ continue;
+ }
+ seekid = -1;
+ seekms = -1;
+ freePacket = true;
+ return ms;
+ }
+ }
+ } finally {
+ if (!freePacket) {
+ packet.clear();
+ }
+ }
+ }
+
+ return null;
+ }
+
+ JJReaderStream last;
+
+ public JJReaderStream readFrameX() throws AVIOException {
+ if (freePacket) {
+ packet.clear();
+ }
+ freePacket = false;
+
+ // Drain all frames from last stream first
+ if (last != null && last.c.receiveFrame(last.frame)) {
+ last.frameIndex += 1;
+ pts = packet.getDTS();
+ return last;
+ }
+ last = null;
+
+ while (format.readFrame(packet)) {
+ try {
+ int index = packet.getStreamIndex();
+ JJReaderStream ms = streams[index];
+
+ if (ms != null && ms.isOpened()) {
+ ms.c.sendPacket(packet);
+ while (ms.c.receiveFrame(ms.frame)) {
+ ms.frameIndex += 1;
+ pts = packet.getDTS();
+
+ // If seeking, attempt to get to the exact frame
+ if (seekid != -1
+ && pts < seekid) {
+ continue;
+ } else if (seekms != -1
+ && ms.convertPTS(pts) < seekms) {
+ continue;
+ }
+ last = ms;
+ seekid = -1;
+ seekms = -1;
+ freePacket = true;
+ return ms;
+ }
+ }
+ } finally {
+ if (!freePacket) {
+ packet.clear();
+ }
+ }
+ }
+
+ return null;
+ }
+
+ static public abstract class JJReaderStream {
+
+ AVStream stream;
+ AVCodecContext c;
+ AVCodecParameters cp;
+ int streamID = -1;
+ protected AVCodec codec;
+ protected boolean opened = false;
+ // timebase
+ AVRational tb;
+ // start pts
+ long startpts;
+ // start ms
+ long startms;
+ //
+ long duration;
+ long durationms;
+ // Raw decoded frame
+ final AVFrame frame;
+ // Incremented every time a frame is decoded
+ long frameIndex;
+
+ public JJReaderStream(AVStream stream, AVCodecParameters cp) throws AVIOException {
+ this.stream = stream;
+
+ this.cp = cp;
+ // Hmm, what if i want to override CodedID?
+ codec = AVCodec.findDecoder(cp.getCodecID());
+ if (codec == null)
+ throw new AVIOException(AVError.AVERROR_DECODER_NOT_FOUND);
+
+ c = AVCodecContext.allocContext(codec);
+
+ frame = AVFrame.alloc();
+
+ tb = stream.getTimeBase();
+
+ startpts = stream.getStartTime();
+ startms = tb.rescale(startpts, 1000);
+ duration = stream.getDuration();
+ durationms = tb.rescale(duration, 1000);
+ }
+
+ public void open() throws AVIOException {
+ cp.toContext(c);
+ c.setCodecID(codec.getID());
+ c.open(codec, null);
+
+ opened = true;
+ }
+
+ public void release() {
+ if (codec != null) {
+ codec.release();
+ c.release();
+ }
+ frame.release();
+ stream.release();
+ }
+
+ /**
+ * Retrieve the codec paramters.
+ * <p>
+ * These may be modified before the codec context is opened.
+ *
+ * @return
+ */
+ public AVCodecParameters getCodecParameters() {
+ return cp;
+ }
+
+ public AVStream getStream() {
+ return stream;
+ }
+
+ public AVCodec getCodec() {
+ return codec;
+ }
+
+ /**
+ * Retrieve duration of sequence, in milliseconds.
+ *
+ * @return
+ */
+ public long getDurationMS() {
+ return durationms;
+ }
+
+ /**
+ * Get duration in timebase units (i.e. frames?)
+ *
+ * @return
+ */
+ public long getDuration() {
+ return duration;
+ }
+
+ public boolean isOpened() {
+ return opened;
+ }
+
+ /**
+ * Convert the 'pts' provided to milliseconds relative to the start of the stream.
+ *
+ * @param pts
+ * @return
+ */
+ public long convertPTS(long pts) {
+ return tb.rescale(pts, 1000) - startms;
+ }
+
+ /**
+ * Decode a packet. Returns true if data is now ready.
+ * <p>
+ * It is ok to call this on an unopened stream: return false.
+ * <p>
+ * TODO: this is now common across different formats, up-class the code.
+ *
+ * @param packet
+ * @return
+ */
+ public boolean decode(AVPacket packet) throws AVIOException {
+ boolean done = false;
+ if (isOpened()) {
+ if (packet != null && packet.getSize() == 0) {
+ Logger.getLogger("jjmpeg.io")
+ .fine(()
+ -> String.format("stream %d packet size 0", streamID));
+ return done;
+ }
+
+ c.sendPacket(packet);
+ done = c.receiveFrame(frame);
+
+ frameIndex += 1;
+ }
+ return done;
+ }
+
+ /**
+ * Retrieve the decoded frame. This is only valid after a call to decode() returns true.
+ *
+ * @return
+ */
+ public AVFrame getFrame() {
+ return frame;
+ }
+
+ public long getFrameIndex() {
+ return frameIndex;
+ }
+
+ /**
+ * Retreive the AVMEDIA_TYPE_* for this stream.
+ *
+ * @return
+ */
+ abstract public int getType();
+
+ void flushCodec() {
+ if (opened) {
+ c.flushBuffers();
+ }
+ }
+ }
+
+ public class JJReaderUnknown extends JJReaderStream {
+
+ public JJReaderUnknown(AVStream stream, AVCodecParameters cp) throws AVIOException {
+ super(stream, cp);
+ }
+
+ @Override
+ public boolean decode(AVPacket packet) throws AVIOException {
+ return false;
+ }
+
+ @Override
+ public void open() throws AVIOException {
+ throw new AVIOException(AVError.AVERROR_UNKNOWN, "Unknown stream type");
+ }
+
+ @Override
+ public int getType() {
+ return AVMediaType.AVMEDIA_TYPE_UNKNOWN;
+ }
+
+ @Override
+ void flushCodec() {
+ }
+ }
+
+ static public class JJReaderVideo extends JJReaderStream {
+
+ public JJReaderVideo(AVStream stream, AVCodecParameters cp) throws AVIOException {
+ super(stream, cp);
+ }
+
+ @Override
+ public void open() throws AVIOException {
+ if (cp.getPixelFormat() == AVPixelFormat.AV_PIX_FMT_NONE) {
+ throw new AVIOException(AVError.AVERROR_INVALIDDATA, "No decodable video present");
+ }
+
+ Logger.getLogger("jjmpeg.io")
+ .fine(() -> {
+ return String.format("Open video reader\n"
+ + " video %dx%d %s [aspect %s]\n"
+ + " codec %s\n",
+ cp.getWidth(),
+ cp.getHeight(),
+ AVPixelFormat.toString(cp.getPixelFormat()),
+ cp.getAspectRatio(),
+ AVCodecID.toString(cp.getCodecID()));
+ });
+
+ super.open();
+ }
+
+ @Override
+ public void release() {
+ super.release();
+
+ if (c != null)
+ c.release();
+ }
+
+ @Override
+ public int getType() {
+ return AVMediaType.AVMEDIA_TYPE_VIDEO;
+ }
+
+ public int getWidth() {
+ return c.getWidth();
+ }
+
+ public int getHeight() {
+ return c.getHeight();
+ }
+
+ public int getPixelFormat() {
+ return c.getPixelFormat();
+ }
+
+ @Override
+ public String toString() {
+ AVRational fr = stream.getAverageFrameRate();
+
+ return String.format("[Video %6.3fs %dx%d @ %d/%d %s]", getDurationMS() * 1E-3, cp.getWidth(), cp.getHeight(), fr.num, fr.den, AVPixelFormat.toString(cp.getPixelFormat()));
+ }
+ }
+
+ static public class JJReaderAudio extends JJReaderStream {
+
+ public JJReaderAudio(AVStream stream, AVCodecParameters cp) throws AVIOException {
+ super(stream, cp);
+ }
+
+ @Override
+ public void open() throws AVIOException {
+ Logger.getLogger("jjmpeg.io")
+ .fine(() -> {
+ return String.format("Open audio reader\n"
+ + " audio x%d %dHz %s\n"
+ + " codec %s\n",
+ cp.getNumChannels(),
+ cp.getSampleRate(),
+ AVSampleFormat.toString(cp.getSampleFormat()),
+ AVCodecID.toString(cp.getCodecID()));
+ });
+
+ super.open();
+ }
+
+ @Override
+ public int getType() {
+ return AVMediaType.AVMEDIA_TYPE_AUDIO;
+ }
+
+ public int getSampleFormat() {
+ return c.getSampleFormat();
+ }
+
+ public int getSampleRate() {
+ return c.getSampleRate();
+ }
+
+ public int getNumChannels() {
+ return c.getNumChannels();
+ }
+
+ public long getChannelLayout() {
+ return c.getChannelLayout();
+ }
+
+ @Override
+ public String toString() {
+ return String.format("[Audio %d @ %dHz %s]", cp.getNumChannels(), cp.getSampleRate(), AVSampleFormat.toString(cp.getSampleFormat()));
+ }
+ }
+}
--- /dev/null
+/*
+ * Based on Libavformat API example: Output a media file in any supported
+ * libavformat format. The default codecs are used.
+ *
+ * Copyright (c) 2003 Fabrice Bellard
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+ /*
+ * See: http://cekirdek.pardus.org.tr/~ismail/ffmpeg-docs/output-example_8c-source.html
+ */
+package au.notzed.jjmpeg.io;
+
+import au.notzed.jjmpeg.AVCodec;
+import au.notzed.jjmpeg.AVCodecContext;
+import au.notzed.jjmpeg.AVFormatContext;
+import au.notzed.jjmpeg.AVFrame;
+import au.notzed.jjmpeg.AVOutputFormat;
+import au.notzed.jjmpeg.AVPacket;
+import au.notzed.jjmpeg.AVRational;
+import au.notzed.jjmpeg.AVStream;
+import au.notzed.jjmpeg.AVCodecID;
+import au.notzed.jjmpeg.AVError;
+import au.notzed.jjmpeg.AVIOContext;
+import au.notzed.jjmpeg.AVPixelFormat;
+import au.notzed.jjmpeg.AVIOException;
+import au.notzed.jjmpeg.AVMediaType;
+import au.notzed.jjmpeg.AVSampleFormat;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.logging.Logger;
+
+/**
+ * High level av file writer interface
+ * <p>
+ * @author notzed
+ */
+public class JJMediaWriter {
+
+ List<JJWriterStream> streams = new ArrayList<>();
+ String filename;
+ AVFormatContext oc;
+ AVIOContext output; // need to keep ref around
+
+ /**
+ * Create a new stream for writing to a file.
+ * <p>
+ * Once created, call addVideoStream, (addAudioStream) and so on, before calling open().
+ * Frames are then added using the various addFrame() methods until finished,
+ * and then call close().
+ *
+ * @param filename
+ * <p>
+ * @throws AVInvalidFormatException
+ */
+ public JJMediaWriter(String filename) throws AVIOException {
+ this.filename = filename;
+
+ /* allocate the output media context */
+ oc = AVFormatContext.allocContext(null, null, filename);
+
+ // Caller now calls addVideoStream, etc.
+ }
+
+ /**
+ * Get the output format being used.
+ * <p>
+ * @return
+ */
+ public AVOutputFormat getFormat() {
+ return oc.getOutputFormat();
+ }
+
+ /**
+ * The stream must be opened after adding streams and before writing to them.
+ * <p>
+ * @throws AVInvalidFormatException
+ * @throws AVInvalidCodecException
+ * @throws AVIOException
+ */
+ public void open() throws AVIOException {
+ /* now that all the parameters are set, we can open the audio and
+ video codecs and allocate the necessary encode buffers */
+ for (JJWriterStream sd: streams) {
+ sd.open();
+ }
+
+ /* open the output file, if needed */
+ //if (!(format->flags & AVFMT_NOFILE)) {
+ output = AVIOContext.open(filename, AVIOContext.AVIO_FLAG_WRITE);
+ oc.setIOContext(output);
+
+ /* write the stream header, if any */
+ oc.writeHeader(null);
+ }
+
+ /**
+ * Add a stream using the default video codec for this stream.
+ * The streamid is the index of the stream in the streams list.
+ * <p>
+ * @param width
+ * @param height
+ * @param frame_rate
+ * @param bit_rate
+ * <p>
+ * @return
+ */
+ public JJWriterVideo addVideoStream(int width, int height, int frame_rate, long bit_rate) throws AVIOException {
+ return addVideoStream(getFormat().getVideoCodec(), streams.size(), width, height, 1, frame_rate, bit_rate);
+ }
+
+ public JJWriterVideo addVideoStream(int width, int height, int frame_rate_num, int frame_rate_den, long bit_rate) throws AVIOException {
+ return addVideoStream(getFormat().getVideoCodec(), streams.size(), width, height, frame_rate_num, frame_rate_den, bit_rate);
+ }
+
+ public JJWriterVideo addVideoStream(int codec_id, int streamid, int width, int height, int frame_rate_den, long bit_rate) throws AVIOException {
+ return addVideoStream(codec_id, streamid, width, height, 1, frame_rate_den, bit_rate);
+ }
+
+ /**
+ * Add a video stream.
+ * <p>
+ * @param codec_id
+ * @param width
+ * @param height
+ * @param frame_rate
+ * @param bit_rate
+ * <p>
+ * @return
+ * @throws AVInvalidStreamException
+ */
+ public JJWriterVideo addVideoStream(int codec_id, int streamid, int width, int height, int frame_rate_num, int frame_rate_den, long bit_rate) throws AVIOException {
+ AVCodecContext c;
+ AVStream st;
+
+ // TODO: all this crap should probably go into JJWriterVideo constructor
+ AVCodec codec = AVCodec.findEncoder(codec_id);
+
+ c = AVCodecContext.allocContext(codec);
+
+ st = oc.newStream(codec);
+ if (st == null) {
+ throw new AVIOException(AVError.AVERROR_STREAM_NOT_FOUND);
+ }
+ st.setID(streams.size());
+
+ c.setCodecID(codec_id);
+ c.setCodecType(AVMediaType.AVMEDIA_TYPE_VIDEO);
+ /* put sample parameters */
+ c.setBitRate(bit_rate);
+
+ /* resolution must be a multiple of two */
+ c.setWidth(width);
+ c.setHeight(height);
+ /* time base: this is the fundamental unit of time (in seconds) in terms
+ of which frame timestamps are represented. for fixed-fps content,
+ timebase should be 1/framerate and timestamp increments should be
+ identically 1. */
+ st.setTimeBase(new AVRational(frame_rate_num, frame_rate_den));
+ c.setTimeBase(new AVRational(frame_rate_num, frame_rate_den));
+ c.setGOPSize(12);
+ /* emit one intra frame every twelve frames at most */
+
+ c.setPixelFormat(AVPixelFormat.AV_PIX_FMT_YUV420P);
+ if (codec_id == AVCodecID.AV_CODEC_ID_MPEG2VIDEO) {
+ /* just for testing, we also add B frames */
+ c.setMaxBFrames(2);
+ }
+ if (codec_id == AVCodecID.AV_CODEC_ID_MPEG1VIDEO) {
+ /* Needed to avoid using macroblocks in which some coeffs overflow.
+ This does not happen with normal video, it just happens here as
+ the motion of the chroma plane does not match the luma plane. */
+ c.setMBDecision(2);
+ }
+ // FIXME: some formats want stream headers to be separate
+ if ((oc.getOutputFormat().getFlags() & AVOutputFormat.AVFMT_GLOBALHEADER) != 0) {
+ c.setFlags(AVCodecContext.AV_CODEC_FLAG_GLOBAL_HEADER, AVCodecContext.AV_CODEC_FLAG_GLOBAL_HEADER);
+ }
+
+ Logger.getLogger("jjmpeg.io")
+ .fine(()
+ -> String.format("add avideo stream %s %d [%dx%d %s aspect %s]\n",
+ codec.getName(), c.getBitRate(),
+ c.getWidth(), c.getHeight(), AVPixelFormat.toString(c.getPixelFormat()),
+ c.getAspectRatio()));
+
+ JJWriterVideo sd = new JJWriterVideo(st, c);
+ streams.add(sd);
+
+ return sd;
+ }
+
+ /**
+ * Add a new audio stream.
+ * <p>
+ * @param codec_id
+ * @param streamid
+ * @param fmt
+ * @param sample_rate
+ * @param bit_rate
+ * <p>
+ * @return
+ * @throws AVInvalidStreamException
+ */
+ public JJWriterAudio addAudioStream(int codec_id, int streamid, int fmt, int sample_rate, int channels, long bit_rate) throws AVIOException {
+ AVCodecContext c;
+ AVStream st;
+
+ AVCodec codec = AVCodec.findEncoder(codec_id);
+
+ c = AVCodecContext.allocContext(codec);
+
+ st = oc.newStream(codec);
+ if (st == null) {
+ throw new AVIOException(AVError.AVERROR_STREAM_NOT_FOUND);
+ }
+
+ c.setCodecID(codec_id);
+ c.setCodecType(AVMediaType.AVMEDIA_TYPE_AUDIO);
+
+ c.setSampleFormat(fmt);
+ c.setBitRate(bit_rate);
+ c.setSampleRate(sample_rate);
+
+ c.setNumChannels(channels);
+ c.setChannelLayout(4);
+
+ if ((oc.getOutputFormat().getFlags() & AVOutputFormat.AVFMT_GLOBALHEADER) != 0) {
+ c.setFlags(AVCodecContext.AV_CODEC_FLAG_GLOBAL_HEADER, AVCodecContext.AV_CODEC_FLAG_GLOBAL_HEADER);
+ }
+
+ Logger.getLogger("jjmpeg.io")
+ .fine(()
+ -> String.format("add audio stream audio %s %d [x%d %dHz %s]\n",
+ codec.getName(), c.getBitRate(),
+ c.getNumChannels(), c.getSampleRate(), AVSampleFormat.toString(c.getSampleFormat())));
+
+ JJWriterAudio as = new JJWriterAudio(st, c);
+
+ streams.add(as);
+
+ return as;
+ }
+
+ public void flush() throws AVIOException {
+ for (JJWriterStream sd: streams) {
+ sd.addFrame(null);
+ }
+ }
+
+ /**
+ * Close the file, completing the stream and freeing resources.
+ */
+ public void close() throws AVIOException {
+
+ flush();
+ /* write the trailer, if any. the trailer must be written
+ * before you close the CodecContexts open when you wrote the
+ * header; otherwise write_trailer may try to use memory that
+ * was freed on av_codec_close() */
+ oc.writeTrailer();
+
+ /* close each codec */
+ for (JJWriterStream sd: streams) {
+ sd.close();
+ }
+
+ /* close the output file */
+ //output.close();
+
+ /* free the stream */
+ oc.release();
+ }
+
+ public abstract class JJWriterStream {
+
+ AVStream stream;
+ AVCodecContext c;
+ AVPacket packet;
+ boolean opened;
+ AVFrame frame;
+
+ public JJWriterStream(AVStream stream, AVCodecContext c) {
+ this.stream = stream;
+ this.c = c;
+ this.packet = AVPacket.alloc();
+ }
+
+ /**
+ * Retrieve the av stream.
+ * <p>
+ * @return
+ */
+ public AVStream getStream() {
+ return stream;
+ }
+
+ /**
+ * Retrieve the codec context for this stream.
+ * <p>
+ * This may be modified before opening.
+ * <p>
+ * @return
+ */
+ public AVCodecContext getContext() {
+ return c;
+ }
+
+ public void open() throws AVIOException {
+ AVCodec codec = AVCodec.findEncoder(c.getCodecID());
+
+ c.open(codec, null);
+
+ stream.getCodecParameters().fromContext(c);
+
+ opened = true;
+ }
+
+ public void addFrame(AVFrame frame) throws AVIOException {
+ if (c.sendFrame(frame)) {
+ while (c.receivePacket(packet)) {
+ packet.rescaleTS(c.getTimeBase(), stream.getTimeBase());
+ packet.setStreamIndex(stream.getIndex());
+ oc.interleavedWriteFrame(packet);
+ }
+ }
+ }
+
+ void close() {
+ stream.release();
+ packet.release();
+ }
+ }
+
+ /**
+ * Represents a video stream.
+ */
+ public class JJWriterVideo extends JJWriterStream {
+
+ int nextPTS;
+
+ public JJWriterVideo(AVStream stream, AVCodecContext c) {
+ super(stream, c);
+ }
+
+ @Override
+ public void open() throws AVIOException {
+ super.open();
+
+ frame = AVFrame.alloc(c.getPixelFormat(), c.getWidth(), c.getHeight());
+ }
+
+ @Override
+ void close() {
+ super.close();
+
+ frame.release();
+ }
+
+ public AVFrame getFrame() {
+ return frame;
+ }
+
+ /**
+ * Write next video frame.
+ * <p>
+ * @param frame Video frame to write, or null to flush buffers.
+ * <p>
+ * @throws AVEncodingError
+ * @throws AVIOException
+ */
+ public void addFrame(AVFrame frame) throws AVIOException {
+ if (frame != null)
+ frame.setPTS(nextPTS++);
+ super.addFrame(frame);
+ }
+
+ }
+
+ public class JJWriterAudio extends JJWriterStream {
+
+ public JJWriterAudio(AVStream stream, AVCodecContext c) {
+ super(stream, c);
+ }
+
+ @Override
+ public void open() throws AVIOException {
+ super.open();
+
+ // TODO: pcm hack stuff
+ if (c.getFrameSize() <= 1) {
+ }
+
+ // ??? unchecked
+ frame = AVFrame.alloc(c.getSampleFormat(), c.getNumChannels(), 2048);
+ }
+
+ @Override
+ void close() {
+ super.close();
+ }
+ }
+}
--- /dev/null
+/*
+ * Copyright (C) 2018 Michael Zucchi
+ *
+ * This file is part of jjmpeg <https://www.zedzone.space/software/jjmpeg.html>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+module notzed.jjmpeg {
+ requires java.logging;
+ requires notzed.nativez;
+
+ exports au.notzed.jjmpeg;
+ exports au.notzed.jjmpeg.io;
+
+ opens au.notzed.jjmpeg to notzed.nativez;
+}
--- /dev/null
+#!/usr/bin/perl
+
+#
+# Copyright (C) 2017 Michael Zucchi
+#
+# This file is part of jjmpeg <https://www.zedzone.space/software/jjmpeg.html>
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program 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 General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+#
+
+$ff = "/opt/ffmpeg/3.4";
+
+$inc = "";
+$start = "";
+$stop = "";
+# keep all comments
+$keepc = 1;
+$shift = "";
+$interface = "";
+$class = "";
+$type = "int";
+
+@defines = ();
+%process = ();
+
+# read global options
+while ($#ARGV >= 0) {
+ $cmd = shift;
+ if ($cmd =~ m/-I(.*)/) {
+ if ($1 ne "") {
+ $path = $1;
+ } else {
+ $path = shift;
+ }
+ $inc = $inc." -I".$path;
+ } elsif ($cmd eq "-f") {
+ $ff = shift;
+ } elsif ($cmd eq "-c") {
+ $keepc = 1;
+ } elsif ($cmd eq "-interface") {
+ $class = "interface ".shift();
+ } elsif ($cmd eq "-class") {
+ $class = "class ".shift();
+ } elsif ($cmd eq "-type") {
+ $type = shift;
+ } elsif ($cmd eq "-shift") {
+ $shift = shift;
+ } elsif ($cmd eq "-header") {
+ $header = shift;
+ } elsif ($cmd eq "-d") {
+ $define = shift;
+
+ if ($type eq "long") {
+ $ctype = "(int64_t)";
+ $cfmt = "0x%lxL";
+ } else {
+ $ctype = "";
+ $cfmt = "0x%x";
+ }
+
+ $process{$define} = {
+ "type" => "$type",
+ "class" => "$class",
+ "header" => "$header",
+ "define" => "$define",
+ "ctype" => $ctype,
+ "cfmt" => $cfmt,
+ "shift" => "$shift",
+ };
+ push @defines, $define;
+ } else {
+ $output = $cmd;
+ }
+}
+
+die ("No class defined") if ($class eq "");
+die ("No output defined") if ($output eq "");
+
+print STDERR "Creating $output for $class\n";
+
+open (C,">$output")|| die("Unable to open $output");
+
+print C "#include <stdio.h>\n";
+%included = ();
+foreach $define (@defines) {
+ %proc = %{$process{$define}};
+
+ if ($proc{"header"} ne "" && !$included{$proc{header}}) {
+ print C "#include <$proc{header}>\n";
+ $included{$proc{header}} = 1;
+ }
+}
+
+print C "int main(int argc, char **argv) {\n";
+$date = `date`;
+chop $date;
+
+print C "\tprintf(\"\\n/* This file was autogenerated on $date: */\\n\");\n";
+%included = ();
+foreach $define (@defines) {
+ %proc = %{$process{$define}};
+
+ if ($proc{"header"} ne "" && !$included{$proc{header}}) {
+ print C "printf(\"/* from $ff/include/$proc{header} */\\n\");\n";
+ $included{$proc{header}} = 1;
+ }
+}
+
+print C "\tprintf(\"\\npackage au.notzed.jjmpeg;\\n\");\n";
+print C "\tprintf(\"public $class {\\n\");\n";
+
+foreach $define (@defines) {
+ %proc = %{$process{$define}};
+
+ scan ($process{$define});
+}
+
+print C "\tprintf(\"}\\n\");\n";
+print C "}\n";
+
+exit 0;
+
+sub scanCopyright {
+ my $h = $_[0];
+ my $copyright = "";
+
+ open IN,"<$h" || die("Can't find include file: $h");
+ while (<IN>) {
+ if (m@(copyright.*)@i) {
+ $copyright .= "\\t * $1\\n";
+ }
+ }
+ close IN;
+ print C "printf(\"\\n\t/*\\n\\t * from $h\\n\");\n";
+ if ($copyright ne "") {
+ print C "printf(\"\\t *\\n%s\", \"$copyright\");\n";
+ }
+ print C "printf(\"\\t */\\n\\n\");\n";
+}
+
+sub scan {
+ my %o = %{$_[0]};
+ my $d = $o{define};
+ my $lastc = "";
+ my $h = $ff."/include/".$o{header};
+
+ print STDOUT "Scanning for $d in $h\n";
+
+ scanCopyright($h);
+
+ open (IN,"cpp -dD -CC -I$ff/include $inc $ff/include/$o{header}|") || die("Can't find include file: $h");
+ while (<IN>) {
+ # handle multi-line comments
+ if ($keepc && m@(/\*\*.*)@) {
+ $lastc = "\t".$1."\\n";
+ $lastc =~ s/<//g;
+ until (m@\*/@) {
+ $_ = <IN>;
+ chop;
+ $lastc .= "\t".$_."\\n";
+ }
+ }
+ if (m/#define ($d\w*)/) {
+ my $def = $1;
+ #print $1."\n";
+ if ($lastc ne "") {
+ #$lastc =~ s@\t+@\t@g;
+ print C "\tprintf(\"%s\", \"$lastc\");\n";
+ } elsif (m@///< (.*)@ || m@/\*\|<(.*)\*@) {
+ # handle single-line comments, perhaps these should override
+ print C "\tprintf(\"\\t/**\\n\\t * $1\\n\\t */\\n\");\n";
+ }
+
+ print C "\tprintf(\"\\tpublic final static $o{type} $def = $o{cfmt};\\n\", $o{ctype}$def$o{shift});\n";
+
+ $lastc = "";
+ }
+ }
+ close IN;
+
+}
--- /dev/null
+#!/usr/bin/perl
+
+#
+# Copyright (C) 2017 Michael Zucchi
+#
+# This file is part of jjmpeg <https://www.zedzone.space/software/jjmpeg.html>
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program 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 General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+#
+
+$inc = "";
+
+while ($ARGV[0] =~ m/^-I(.*)/) {
+ shift;
+ if ($1 ne "") {
+ $path = $1;
+ } else {
+ $path = shift;
+ }
+ $inc = $inc." -I".$path;
+}
+
+$t = $ARGV[0];
+$d = $ARGV[1];
+$h = $ARGV[2];
+$c = $ARGV[3];
+
+open (C,">$c")|| die("Unable to open $c");
+
+print C "#include <stdio.h>\n";
+print C "#include <$h>\n";
+print C "int main(int argc, char **argv) {\n";
+$date = `date`;
+chop $date;
+print C "printf(\"\\n/* This file was autogenerated on $date */\\n\");\n";
+print C "printf(\"/* from $h */\\n\");\n";
+print C "printf(\"package au.notzed.jjmpeg;\\n\");\n";
+print C "printf(\"public interface $t"."Bits {\\n\");\n";
+
+scanCopyright($h);
+
+open (IN,"cpp -dD -C $inc $h|") || die("Can't find include file: $h");
+
+while (<IN>) {
+ last if m/^enum $t ?\{/;
+}
+
+while (<IN>) {
+ last if m/^\};/;
+
+ if (m@///< (.*)@) {
+ s@\*/@@g;
+ s@/\*@@g;
+ print C "\tprintf(\"\\t/**\\n\\t * $1\\n\\t */\\n\");\n";
+ }
+
+ if (m/($d\w*) = (0x[0-9x]+)/) {
+ $id = hex($2);
+ print C "\tprintf(\"\\tpublic final static int $1 = 0x%x;\\n\", $1);\n";
+ } elsif (m/^\s*($d\w*) *= *([-0-9]+)/) {
+ $id = int($2);
+ print C "\tprintf(\"\\tpublic final static int $1 = %d;\\n\", $1);\n";
+ } elsif (m/^\s*($d\w*) *= *($d\w*)/) {
+ print C "\tprintf(\"\\tpublic final static int $1 = $2;\\n\");\n";
+ } elsif (m/^\s*($d\w*)/) {
+ print C "\tprintf(\"\\tpublic final static int $1 = 0x%x;\\n\", $1);\n";
+ } elsif (m/^#\s*define\s+($d\w*)\s+\w+/) {
+ print C "\tprintf(\"\\tpublic final static int $1 = 0x%x;\\n\", $1); // #define\n";
+ }
+}
+
+#print C "\tprintf(\"\\t/* extra host-specific endianness */\\n\");\n";
+while (<IN>) {
+ if (m/^#\s*define\s+($d\w*)\s+\w+/) {
+ print C "\tprintf(\"\\tpublic final static int $1 = 0x%x;\\n\", $1); // #define\n";
+ }
+}
+
+print C "printf(\"}\\n\");\n";
+print C "}\n";
+close C;
+
+close IN;
+
+exit 0;
+
+sub scanCopyright {
+ my $h = $_[0];
+ my $copyright = "";
+
+ open IN,"<$h" || die("Can't find include file: $h");
+ while (<IN>) {
+ if (m@(copyright.*)@i) {
+ $copyright .= "\\t * $1\\n";
+ }
+ }
+ close IN;
+ print C "printf(\"\\n\t/*\\n\\t * from $h\\n\");\n";
+ if ($copyright ne "") {
+ print C "printf(\"\\t *\\n%s\", \"$copyright\");\n";
+ }
+ print C "printf(\"\\t */\\n\\n\");\n";
+}
--- /dev/null
+#
+# Copyright (C) 2017 Michael Zucchi
+#
+# This file is part of jjmpeg <https://www.zedzone.space/software/jjmpeg.html>
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program 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 General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+#
+
+extract_enum=src/notzed.jjmpeg/gen/extract-enum.pl
+extract_defines=src/notzed.jjmpeg/gen/extract-defines.pl
+
+# Relative to module!
+notzed.jjmpeg_JAVA_GENERATED = \
+ au/notzed/jjmpeg/AVChannelLayoutBits.java \
+ au/notzed/jjmpeg/AVCodecBits.java \
+ au/notzed/jjmpeg/AVCodecContextBits.java \
+ au/notzed/jjmpeg/AVCodecIDBits.java \
+ au/notzed/jjmpeg/AVDiscardBits.java \
+ au/notzed/jjmpeg/AVErrorBits.java \
+ au/notzed/jjmpeg/AVMediaTypeBits.java \
+ au/notzed/jjmpeg/AVOptionsBits.java \
+ au/notzed/jjmpeg/AVPixelFormatBits.java \
+ au/notzed/jjmpeg/AVSampleFormatBits.java
+
+HOST_CC=cc
+HOST_CPPFLAGS=-I$(FFMPEG_HOME)/include
+
+$(notzed.jjmpeg_genjavadir)/%.java: $(notzed.jjmpeg_gendir)/%-gen
+ @install -d $(@D)
+ $< > $@ || ( rm $@ ; exit 1)
+
+$(notzed.jjmpeg_gendir)/%-gen: $(notzed.jjmpeg_gendir)/%-gen.c
+ $(HOST_CC) $(HOST_CPPFLAGS) -o $@ $<
+
+# dependent on itself as it contains buisiness logic in the rules
+tmp:=$(notzed.jjmpeg_gendir)/au/notzed/jjmpeg
+dep:=src/notzed.jjmpeg/gen/gen.make
+
+$(tmp)/AVCodecIDBits-gen.c: $(extract_enum) $(dep)
+ @install -d $(@D)
+ perl $(extract_enum) -I$(FFMPEG_HOME)/include AVCodecID AV_CODEC_ID_ $(FFMPEG_HOME)/include/libavcodec/avcodec.h $@
+
+$(tmp)/AVPixelFormatBits-gen.c: $(extract_enum) $(dep)
+ @install -d $(@D)
+ perl $(extract_enum) -I$(FFMPEG_HOME)/include AVPixelFormat AV_PIX_FMT_ $(FFMPEG_HOME)/include/libavutil/pixfmt.h $@
+
+$(tmp)/AVSampleFormatBits-gen.c: $(extract_enum) $(dep)
+ @install -d $(@D)
+ perl $(extract_enum) -I$(FFMPEG_HOME)/include AVSampleFormat AV_SAMPLE_FMT_ $(FFMPEG_HOME)/include/libavutil/samplefmt.h $@
+
+$(tmp)/AVMediaTypeBits-gen.c: $(extract_enum) $(dep)
+ @install -d $(@D)
+ perl $(extract_enum) -I$(FFMPEG_HOME)/include AVMediaType AVMEDIA_TYPE_ $(FFMPEG_HOME)/include/libavutil/avutil.h $@
+
+$(tmp)/AVDiscardBits-gen.c: $(extract_enum) $(dep)
+ @install -d $(@D)
+ perl $(extract_enum) -I$(FFMPEG_HOME)/include AVDiscard AVDISCARD_ $(FFMPEG_HOME)/include/libavcodec/avcodec.h $@
+
+$(tmp)/AVChannelLayoutBits-gen.c: $(extract_enum) $(dep)
+ @install -d $(@D)
+ perl $(extract_defines) -f $(FFMPEG_HOME) -interface AVChannelLayoutBits -header libavutil/channel_layout.h -type long -d AV_CH_LAYOUT_ $@
+
+$(tmp)/AVErrorBits-gen.c: $(extract_defines) $(dep)
+ @install -d $(@D)
+ perl $(extract_defines) -f $(FFMPEG_HOME) -interface AVErrorBits -header libavutil/avutil.h -d AVERROR_ $@
+
+$(tmp)/AVCodecContextBits-gen.c: $(extract_defines) $(dep)
+ @install -d $(@D)
+ perl $(extract_defines) -c -f ${FFMPEG_HOME} \
+ -interface AVCodecContextBits -header libavcodec/avcodec.h \
+ -type long -d AV_CODEC_FLAG_ -shift "<<32" -d AV_CODEC_FLAG2_ \
+ -shift "" -type int -d AV_INPUT_BUFFER_ \
+ $@
+
+$(tmp)/AVCodecBits-gen.c: $(extract_defines) $(dep)
+ @install -d $(@D)
+ perl $(extract_defines) -c -interface AVCodecBits -f $(FFMPEG_HOME) -header libavcodec/avcodec.h -d AV_CODEC_CAP_ $@
+
+$(tmp)/AVOptionsBits-gen.c: $(extract_defines) $(dep)
+ @install -d $(@D)
+ perl $(extract_defines) -c -interface AVOptionsBits -f $(FFMPEG_HOME) -header libavutil/opt.h -d AV_OPT_ $@
--- /dev/null
+#!/usr/bin/perl
+
+$ffmpeg_home = "/opt/ffmpeg/4.0";
+
+$args = "$0 ".join " ", @ARGV;
+
+while ($#ARGV >= 0) {
+ my $cmd = shift;
+ if ($cmd eq "-f") {
+ $ffmpeg_home = shift;
+ } else {
+ $in = $cmd;
+ }
+}
+
+die ("No input file") if ! -f $in;
+
+$header = "";
+$librart = "";
+@functions = ();
+@headers = ();
+%proto = ();
+$last_library = "";
+$mode = "";
+
+open IN,"<$in";
+
+while (<IN>) {
+ chop;
+
+ if (m/^#/) {
+ next;
+ } elsif (m/^header (.*) (.*) \{/) {
+ $library = $1;
+ $header = $2;
+ push @headers, $header;
+
+ %proto = ();
+ open PROTO, "cproto -x -I$ffmpeg_home/include $ffmpeg_home/include/$header|";
+
+ while (<PROTO>) {
+ chop;
+ $cproto = $_;
+ if (m/([a-zA-Z0-9_]*)\(/) {
+ $func = $1;
+ $proto{$func} = $cproto;
+ }
+ }
+ close PROTO;
+
+ if ($library ne $last_library) {
+ push @functions, "#$library";
+ $last_library = $library;
+ }
+ $mode = "proto";
+ } elsif (m/^java (.*) (.*) \{/) {
+ # wouldn't it be nice to get this from the .class ...
+ $name = $1;
+ $class = $2;
+ $mode = "java";
+ push @classes,"#$name:$class";
+ } elsif (m/^}$/) {
+ $mode = "";
+ } elsif ($mode eq "proto") {
+ if (m/\s*([a-zA-Z0-9_]+)/) {
+ my $func= $1;
+ my $cproto = $proto{$func};
+
+ die ("No function $func in $header") if !defined($cproto);
+
+ push @functions, $cproto;
+ }
+ } elsif ($mode eq "java") {
+ if (m/(static)? *([\w<>]*) *, *([\[\w<>\(\)\/;]*)/) {
+ push @classes,"$1,$2,$3";
+ }
+ }
+}
+close IN;
+
+$date = `date`;
+chop $date;
+print "/* This file was autogenerated on $date: */\n";
+print "/* $0 $args */\n";
+
+if ($#headers >= 0) {
+ # Handle C prototype mappings
+ foreach $h (@headers) {
+ print "#include <$h>\n";
+ }
+
+ print "static struct functable {\n";
+ foreach $func (@functions) {
+ if ($func =~ m/^\#(.+)/) {
+ print "\t/* lib$1 */\n";
+ } else {
+ $dfunc = $func;
+ $dfunc =~ s/([a-zA-Z0-9_]*)(\(.*;)/(*\1)\2/;
+ print "\t$dfunc\n";
+ }
+ }
+ print "} fn;\n";
+ print "static const char *fn_names =\n";
+ foreach $func (@functions) {
+ if ($func =~ m/^(\#.+)/) {
+ print "\t\"$func\\0\"\n";
+ } else {
+ $func =~ m/([a-zA-Z0-9_]*)\(/;
+ print "\t\"$1\\0\"\n";
+ }
+ }
+ print "\t;\n";
+}
+
+if ($#classes >= 0) {
+ # Handle java defines
+ $name = "";
+ $class = "";
+ print "static struct {\n";
+ foreach $func (@classes) {
+ if ($func =~ m/^#(.+):(.+)/) {
+ $name = $1;
+ $class = $2;
+ print "\t// $class\n";
+ print "\tjclass $name"."_classid;\n";
+ printf "#define $name"."_classid java.$name"."_classid\n";
+ } elsif ($func =~ m/(.*),(.+),\((.*)\).*/) {
+ my $method = $2;
+ my $args = $3;
+
+ $args =~ s/L.*?;/l/g;
+ $args =~ s/\[/_/g;
+ $args =~ tr/A-Z/a-z/;
+
+ $method =~ s/<init>/new/;
+
+ print "\tjmethodID $name"."_$method"."_$args;\n";
+ print "#define $name"."_$method"."_$args java.$name"."_$method"."_$args\n";
+ } elsif ($func =~ m/(.*),(.+),(.+)/) {
+ my $field = $2;
+ my $type = $3;
+
+ print "\tjfieldID $name"."_$field;\n";
+ print "#define $name"."_$field java.$name"."_$field\n";
+ } else {
+ die("can't parse java signature $func");
+ }
+ }
+ print "} java;\n";
+ print "static const char *java_names =\n";
+ foreach $func (@classes) {
+ if ($func =~ m/^#(.+):(.+)/) {
+ $name = $1;
+ $class = $2;
+
+ print "\t\"#$class\\0\"\n";
+ } elsif ($func =~ m/static,(.*),(.*\(.*\).*)/) {
+ print "\t\":$1\\0$2\\0\"\n";
+ } elsif ($func =~ m/,(.*),(.*\(.*\).*)/) {
+ print "\t\".$1\\0$2\\0\"\n";
+ } elsif ($func =~ m/static,(.*),(.*)/) {
+ print "\t\";$1\\0$2\\0\"\n";
+ } elsif ($func =~ m/,(.*),(.*)/) {
+ print "\t\",$1\\0$2\\0\"\n";
+ }
+ }
+ print "\t;\n";
+}
--- /dev/null
+/*
+ * Copyright (C) 2017 Michael Zucchi
+ *
+ * This file is part of jjmpeg <https://www.zedzone.space/software/jjmpeg.html>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <stdint.h>
+
+#include "au_notzed_jjmpeg_AVCodec.h"
+
+#include "jjmpeg.h"
+
+#include "jj-avcodec.h"
+#undef DLCALL
+#define DLCALL(x) (fn.x)
+
+jint AVCodec_OnLoad(JavaVM *vmi, JNIEnv *env) {
+ return jj_ResolveFunctions(env, fn_names, &fn);
+}
+
+/* ********************************************************************** */
+/* Fields */
+
+GET_string(AVCodec, Name, name)
+GET_string(AVCodec, LongName, long_name)
+GET_prim(jint, AVCodec, ID, id)
+GET_prim(jint, AVCodec, Capabilities, capabilities)
+GET_prim(jint, AVCodec, MaxLowres, max_lowres)
+
+JNIEXPORT jobjectArray JNICALL Java_au_notzed_jjmpeg_AVCodec_getFramerates
+(JNIEnv *env, jobject jo) {
+ AVCodec *o = NativeZ_getP(env, jo);
+ jobjectArray ret = NULL;
+
+ if (o->supported_framerates) {
+ int len = 0;
+
+ while (o->supported_framerates[len].den != 0)
+ len++;
+ ret = AVRational_newArray(env, len);
+ for (int i=0;i<len;i++)
+ (*env)->SetObjectArrayElement(env, ret, i, AVRational_new(env, o->supported_framerates[i]));
+ }
+
+ return ret;
+}
+
+JNIEXPORT jobjectArray JNICALL Java_au_notzed_jjmpeg_AVCodec_getPixelFormats
+(JNIEnv *env, jobject jo) {
+ AVCodec *o = NativeZ_getP(env, jo);
+
+ return jjnewIntArrayT(env, o->pix_fmts, -1);
+}
+
+JNIEXPORT jintArray JNICALL Java_au_notzed_jjmpeg_AVCodec_getSampleRates
+(JNIEnv *env, jobject jo) {
+ AVCodec *o = NativeZ_getP(env, jo);
+
+ return jjnewIntArrayT(env, o->supported_samplerates, 0);
+}
+
+JNIEXPORT jobjectArray JNICALL Java_au_notzed_jjmpeg_AVCodec_getSampleFormats
+(JNIEnv *env, jobject jo) {
+ AVCodec *o = NativeZ_getP(env, jo);
+
+ return jjnewIntArrayT(env, o->sample_fmts, -1);
+}
+
+JNIEXPORT jlongArray JNICALL Java_au_notzed_jjmpeg_AVCodec_getChannelLayouts
+(JNIEnv *env, jobject jo) {
+ AVCodec *o = NativeZ_getP(env, jo);
+ jlongArray ret = NULL;
+
+ if (o->pix_fmts) {
+ int len = 0;
+
+ while (o->channel_layouts[len])
+ len++;
+ ret = (*env)->NewLongArray(env, len);
+ (*env)->SetLongArrayRegion(env, ret, 0, len, o->channel_layouts);
+ }
+
+ return ret;
+}
+
+/* ********************************************************************** */
+/* Methods */
+
+JNIEXPORT void JNICALL Java_au_notzed_jjmpeg_AVCodec_release
+(JNIEnv *env, jclass jc, jlong p) {
+}
+
+/* *** */
+
+JNIEXPORT jint JNICALL Java_au_notzed_jjmpeg_AVCodec_getVersion
+(JNIEnv *env, jclass jc) {
+ return DLCALL(avcodec_version)();
+}
+
+JNIEXPORT jstring JNICALL Java_au_notzed_jjmpeg_AVCodec_getConfiguration
+(JNIEnv *env, jclass jc) {
+ return nativez_NewString(env, DLCALL(avcodec_configuration)());
+}
+
+JNIEXPORT jstring JNICALL Java_au_notzed_jjmpeg_AVCodec_getLicense
+(JNIEnv *env, jclass jc) {
+ return nativez_NewString(env, DLCALL(avcodec_license)());
+}
+
+/* *** */
+
+JNIEXPORT void JNICALL Java_au_notzed_jjmpeg_AVCodec_registerAll
+(JNIEnv *env, jclass jc) {
+ DLCALL(avcodec_register_all)();
+}
+
+JNIEXPORT jobject JNICALL Java_au_notzed_jjmpeg_AVCodec_next
+(JNIEnv *env, jclass jc, jobject jo) {
+ AVCodec *o = NativeZ_getP(env, jo);
+ o = DLCALL(av_codec_next)(o);
+ return NativeZ_refer(env, jc, o);
+}
+
+JNIEXPORT jobject JNICALL Java_au_notzed_jjmpeg_AVCodec_findDecoder__I
+(JNIEnv *env, jclass jc, jint id) {
+ AVCodec *o = DLCALL(avcodec_find_decoder)(id);
+ return NativeZ_refer(env, jc, o);
+}
+
+JNIEXPORT jobject JNICALL Java_au_notzed_jjmpeg_AVCodec_findDecoder__Ljava_lang_String_2
+(JNIEnv *env, jclass jc, jstring jname) {
+ const char *name = nativez_GetString(env, jname);
+ AVCodec *o;
+
+ o = DLCALL(avcodec_find_decoder_by_name)(name);
+ nativez_ReleaseString(env, jname, name);
+ return NativeZ_refer(env, jc, o);
+}
+
+JNIEXPORT jobject JNICALL Java_au_notzed_jjmpeg_AVCodec_findEncoder__I
+(JNIEnv *env, jclass jc, jint id) {
+ return NativeZ_refer(env, jc, DLCALL(avcodec_find_encoder)(id));
+}
+
+JNIEXPORT jobject JNICALL Java_au_notzed_jjmpeg_AVCodec_findEncoder__Ljava_lang_String_2
+(JNIEnv *env, jclass jc, jstring jname) {
+ const char *name = nativez_GetString(env, jname);
+ AVCodec *o;
+
+ o = DLCALL(avcodec_find_encoder_by_name)(name);
+ nativez_ReleaseString(env, jname, name);
+ return NativeZ_refer(env, jc, o);
+}
--- /dev/null
+header avcodec libavcodec/avcodec.h {
+ avcodec_version
+ avcodec_configuration
+ avcodec_license
+
+ avcodec_register_all
+
+ av_codec_next
+
+ avcodec_find_decoder
+ avcodec_find_decoder_by_name
+ avcodec_find_encoder
+ avcodec_find_encoder_by_name
+}
--- /dev/null
+/*
+ * Copyright (C) 2017 Michael Zucchi
+ *
+ * This file is part of jjmpeg <https://www.zedzone.space/software/jjmpeg.html>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <stdint.h>
+
+#include "au_notzed_jjmpeg_AVCodecContext.h"
+
+#include "jjmpeg.h"
+#include "jj-avcodeccontext.h"
+
+#undef DLCALL
+#define DLCALL(x) (fn.x)
+
+jint AVCodecContext_OnLoad(JavaVM *vmi, JNIEnv *env) {
+ return jj_ResolveFunctions(env, fn_names, &fn);
+}
+
+/* ********************************************************************** */
+/* Fields */
+
+/* General options */
+
+GS_int(AVCodecContext, CodecType, codec_type)
+GS_int(AVCodecContext, CodecID, codec_id)
+GS_int(AVCodecContext, CodecTag, codec_tag)
+GS_long(AVCodecContext, BitRate, bit_rate)
+GS_int(AVCodecContext, BitRateTolerance, bit_rate_tolerance)
+GS_int(AVCodecContext, GlobalQuality, global_quality)
+GS_int(AVCodecContext, CompressionLevel, compression_level)
+//GS_int(AVCodecContext, Flags1, flags)
+//GS_int(AVCodecContext, Flags2, flags2)
+
+JNIEXPORT jlong JNICALL MAKE_JJNAME(AVCodecContext, getFlags)
+(JNIEnv *env , jobject jo) {
+ AVCodecContext *o = NativeZ_getP(env, jo);
+ uint64_t flags;
+
+ flags = (uint64_t)o->flags | ((uint64_t)o->flags2 << 32);
+
+ return flags;
+}
+
+JNIEXPORT void JNICALL MAKE_JJNAME(AVCodecContext, setFlags)
+ (JNIEnv *env, jobject jo, jlong mask, jlong flags) {
+ AVCodecContext *o = NativeZ_getP(env, jo);
+ int mask1 = (int)mask;
+ int mask2 = (int)(mask>>32);
+ int flags1 = (int)flags;
+ int flags2 = (int)(flags>>32);
+
+ o->flags = (o->flags & ~mask1) | (mask1 & flags1);
+ o->flags2 = (o->flags2 & ~mask2) | (mask2 & flags2);
+}
+
+JNIEXPORT jobject JNICALL MAKE_JJNAME(AVCodecContext, getTimeBase)
+(JNIEnv *env , jobject jo) {
+ AVCodecContext *o = NativeZ_getP(env, jo);
+ return AVRational_new(env, o->time_base);
+}
+
+JNIEXPORT void JNICALL MAKE_JJNAME(AVCodecContext, setTimeBase)
+(JNIEnv *env, jobject jo, jobject jtb) {
+ AVCodecContext *o = NativeZ_getP(env, jo);
+ o->time_base = AVRational_get(env, jtb);
+}
+
+GS_int(AVCodecContext, TicksPerFrame, ticks_per_frame)
+GET_prim(jint, AVCodecContext, Delay, delay)
+
+/* Video options */
+GS_int(AVCodecContext, Width, width)
+GS_int(AVCodecContext, Height, height)
+GS_value(AVRational_new, AVRational_get, AVCodecContext, AspectRatio, sample_aspect_ratio)
+GS_int(AVCodecContext, GOPSize, gop_size)
+
+GS_int(AVCodecContext, PixelFormat, pix_fmt)
+
+GS_int(AVCodecContext, MaxBFrames, max_b_frames)
+GS_float(AVCodecContext, BQuantFactor, b_quant_factor)
+GS_float(AVCodecContext, BQuantOffset, b_quant_offset)
+
+GET_bool(AVCodecContext, hasBFrames, has_b_frames)
+
+GS_float(AVCodecContext, IQuantFactor, i_quant_factor)
+GS_float(AVCodecContext, IQuantOffset, i_quant_offset)
+
+GS_int(AVCodecContext, MBDecision, mb_decision)
+
+/* Audio options */
+GS_int(AVCodecContext, SampleRate, sample_rate)
+GS_int(AVCodecContext, NumChannels, channels)
+GS_int(AVCodecContext, SampleFormat, sample_fmt)
+GS_int(AVCodecContext, FrameSize, frame_size)
+GET_prim(jint, AVCodecContext, FrameNumber, frame_number)
+GS_long(AVCodecContext, ChannelLayout, channel_layout)
+GS_long(AVCodecContext, RequestChannelLayout, request_channel_layout)
+GS_int(AVCodecContext, StrictStdCompliance, strict_std_compliance)
+
+GS_int(AVCodecContext, ErrorConcealment, error_concealment)
+GS_int(AVCodecContext, ErrorRecognition, err_recognition) // !!
+
+GS_int(AVCodecContext, DCTAlgo, dct_algo)
+GS_int(AVCodecContext, IDCTAlgo, idct_algo)
+
+GS_int(AVCodecContext, ThreadCount, thread_count)
+GS_int(AVCodecContext, Profile, profile)
+
+/* ********************************************************************** */
+/* Methods */
+
+JNIEXPORT void JNICALL Java_au_notzed_jjmpeg_AVCodecContext_release
+(JNIEnv *env, jclass jc, jlong p) {
+ AVCodecContext *cc = (void *)(intptr_t)p;
+
+ DLCALL(avcodec_free_context)(&cc);
+}
+
+JNIEXPORT jobject JNICALL Java_au_notzed_jjmpeg_AVCodecContext_allocContext
+(JNIEnv *env, jclass jc, jobject jcodec) {
+ AVCodec *codec = NativeZ_getP(env, jcodec);
+ AVCodecContext *cc = DLCALL(avcodec_alloc_context3)(codec);
+
+ // NULL means what? Out of memory?
+
+ return NativeZ_create(env, jc, cc);
+}
+
+JNIEXPORT void JNICALL Java_au_notzed_jjmpeg_AVCodecContext_open
+(JNIEnv *env, jobject jcc, jobject jcodec, jobject jdict) {
+ AVCodecContext *cc = NativeZ_getP(env, jcc);
+ AVCodec *codec = NativeZ_getP(env, jcodec);
+ AVDictionary *dict = AVDictionary_get(env, jdict);
+ int res;
+
+ res = DLCALL(avcodec_open2)(cc, codec, &dict);
+
+ AVDictionary_set(env, jdict, dict, 1);
+
+ if (res < 0)
+ jjthrowAVIOException(env, res, "Opening Codec");
+}
+
+/* *** */
+
+JNIEXPORT jobject JNICALL Java_au_notzed_jjmpeg_AVCodecContext_alignDimensions
+(JNIEnv *env, jobject jcc, jobject jdims) {
+ AVCodecContext *cc = NativeZ_getP(env, jcc);
+ AVSize dims = AVSize_get(env, jdims);
+
+ DLCALL(avcodec_align_dimensions)(cc, &dims.width, &dims.height);
+
+ return AVSize_new(env, dims);
+}
+
+/* *** */
+
+JNIEXPORT void JNICALL Java_au_notzed_jjmpeg_AVCodecContext_flushBuffers
+(JNIEnv *env, jobject jcc) {
+ AVCodecContext *cc = NativeZ_getP(env, jcc);
+
+ DLCALL(avcodec_flush_buffers)(cc);
+}
+
+static jboolean returnError(JNIEnv *env, int res, const char *what) {
+ if (res < 0) {
+ if (AVUNERROR(res) != EAGAIN && res != AVERROR_EOF)
+ jjthrowAVIOException(env, res, what);
+ return JNI_FALSE;
+ }
+ return JNI_TRUE;
+}
+
+JNIEXPORT jboolean JNICALL Java_au_notzed_jjmpeg_AVCodecContext_sendPacket
+(JNIEnv *env, jobject jcc, jobject jpacket) {
+ AVCodecContext *cc = NativeZ_getP(env, jcc);
+ AVPacket *packet = NativeZ_getP(env, jpacket);
+ int res;
+
+ res = DLCALL(avcodec_send_packet)(cc, packet);
+ return returnError(env, res, "avcodec_send_packet");
+}
+
+JNIEXPORT jboolean JNICALL Java_au_notzed_jjmpeg_AVCodecContext_receivePacket
+(JNIEnv *env, jobject jcc, jobject jpacket) {
+ AVCodecContext *cc = NativeZ_getP(env, jcc);
+ AVPacket *packet = NativeZ_getP(env, jpacket);
+ int res;
+
+ res = DLCALL(avcodec_receive_packet)(cc, packet);
+ return returnError(env, res, "avcodec_receive_packet");
+}
+
+JNIEXPORT jboolean JNICALL Java_au_notzed_jjmpeg_AVCodecContext_sendFrame
+(JNIEnv *env, jobject jcc, jobject jframe) {
+ AVCodecContext *cc = NativeZ_getP(env, jcc);
+ AVFrame *frame = NativeZ_getP(env, jframe);
+ int res;
+
+ res = DLCALL(avcodec_send_frame)(cc, frame);
+ return returnError(env, res, "avcodec_send_frame");
+}
+
+JNIEXPORT jboolean JNICALL Java_au_notzed_jjmpeg_AVCodecContext_receiveFrame
+(JNIEnv *env, jobject jcc, jobject jframe) {
+ AVCodecContext *cc = NativeZ_getP(env, jcc);
+ AVFrame *frame = NativeZ_getP(env, jframe);
+ int res;
+
+ res = DLCALL(avcodec_receive_frame)(cc, frame);
+ return returnError(env, res, "avcodec_receive_frame");
+}
--- /dev/null
+header avcodec libavcodec/avcodec.h {
+ avcodec_alloc_context3
+ avcodec_free_context
+ avcodec_open2
+ avcodec_flush_buffers
+
+ avcodec_align_dimensions
+
+ avcodec_send_packet
+ avcodec_receive_packet
+ avcodec_send_frame
+ avcodec_receive_frame
+}
--- /dev/null
+/*
+ * Copyright (C) 2017 Michael Zucchi
+ *
+ * This file is part of jjmpeg <https://www.zedzone.space/software/jjmpeg.html>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <stdint.h>
+
+#include "au_notzed_jjmpeg_AVCodecParameters.h"
+
+#include "jjmpeg.h"
+
+#include "jj-avcodecparameters.h"
+#undef DLCALL
+#define DLCALL(x) (fn.x)
+
+jint AVCodecParameters_OnLoad(JavaVM *vmi, JNIEnv *env) {
+ return jj_ResolveFunctions(env, fn_names, &fn);
+}
+
+/* ********************************************************************** */
+/* Fields */
+
+GS_int(AVCodecParameters, CodecType, codec_type)
+GS_int(AVCodecParameters, CodecID, codec_id)
+GS_int(AVCodecParameters, CodecTag, codec_tag)
+GS_long(AVCodecParameters, BitRate, bit_rate)
+GS_int(AVCodecParameters, PixelFormat, format)
+GS_int(AVCodecParameters, Width, width)
+GS_int(AVCodecParameters, Height, height)
+GS_value(AVRational_new, AVRational_get, AVCodecParameters, AspectRatio, sample_aspect_ratio)
+
+GS_int(AVCodecParameters, SampleFormat, format)
+GS_long(AVCodecParameters, ChannelLayout, channel_layout)
+GS_int(AVCodecParameters, NumChannels, channels)
+GS_int(AVCodecParameters, SampleRate, sample_rate)
+
+/* ********************************************************************** */
+/* Methods */
+
+JNIEXPORT void JNICALL Java_au_notzed_jjmpeg_AVCodecParameters_release
+(JNIEnv *env, jclass jc, jlong jcp) {
+ AVCodecParameters *cp = (void *)(uintptr_t)jcp;
+
+ DLCALL(avcodec_parameters_free)(&cp);
+}
+
+JNIEXPORT jobject JNICALL Java_au_notzed_jjmpeg_AVCodecParameters_alloc
+(JNIEnv *env, jclass jc) {
+ return NativeZ_create(env, jc, DLCALL(avcodec_parameters_alloc)());
+}
+
+/* **************************************** */
+
+JNIEXPORT void JNICALL Java_au_notzed_jjmpeg_AVCodecParameters_copy
+(JNIEnv *env, jobject jdst, jobject jsrc) {
+ AVCodecParameters *dst = NativeZ_getP(env, jdst);
+ AVCodecParameters *src = NativeZ_getP(env, jsrc);
+
+ DLCALL(avcodec_parameters_copy)(dst, src);
+}
+
+JNIEXPORT void JNICALL Java_au_notzed_jjmpeg_AVCodecParameters_fromContext
+(JNIEnv *env, jobject jdst, jobject jsrc) {
+ AVCodecParameters *dst = NativeZ_getP(env, jdst);
+ AVCodecContext *src = NativeZ_getP(env, jsrc);
+
+ DLCALL(avcodec_parameters_from_context)(dst, src);
+}
+
+JNIEXPORT void JNICALL Java_au_notzed_jjmpeg_AVCodecParameters_toContext
+(JNIEnv *env, jobject jsrc, jobject jdst) {
+ AVCodecParameters *src = NativeZ_getP(env, jsrc);
+ AVCodecContext *dst = NativeZ_getP(env, jdst);
+
+ DLCALL(avcodec_parameters_to_context)(dst, src);
+}
+
--- /dev/null
+header avcodec libavcodec/avcodec.h {
+ avcodec_parameters_alloc
+ avcodec_parameters_free
+ avcodec_parameters_copy
+ avcodec_parameters_from_context
+ avcodec_parameters_to_context
+}
--- /dev/null
+/*
+ * Copyright (C) 2017 Michael Zucchi
+ *
+ * This file is part of jjmpeg <https://www.zedzone.space/software/jjmpeg.html>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+/*
+ libavdevice
+
+ This is an optional library, if not present then any calls return NullPointerException.
+ */
+#include <stdint.h>
+
+#include "au_notzed_jjmpeg_AVDevice.h"
+
+#include "jjmpeg.h"
+#include "jj-avdevice.h"
+
+jint AVDevice_OnLoad(JavaVM *vmi, JNIEnv *env) {
+ if (jj_ResolveReferences(env, java_names, &java))
+ return -1;
+ jj_ResolveFunctions(env, fn_names, &fn);
+ return 0;
+}
+
+/* ********************************************************************** */
+/* Methods */
+
+JNIEXPORT jint JNICALL Java_au_notzed_jjmpeg_AVDevice_getVersion
+(JNIEnv *env, jclass jc) {
+ DLCHECK_RET(env, avdevice_version, -1);
+ return DLCALL(avdevice_version)();
+}
+
+JNIEXPORT jstring JNICALL Java_au_notzed_jjmpeg_AVDevice_getConfiguration
+(JNIEnv *env, jclass jc) {
+ DLCHECK_RET(env, avdevice_configuration, NULL);
+ return nativez_NewString(env, DLCALL(avdevice_configuration)());
+}
+
+JNIEXPORT jstring JNICALL Java_au_notzed_jjmpeg_AVDevice_getLicense
+(JNIEnv *env, jclass jc) {
+ DLCHECK_RET(env, avdevice_license, NULL);
+ return nativez_NewString(env, DLCALL(avdevice_license)());
+}
+
+/* *** */
+
+JNIEXPORT void JNICALL Java_au_notzed_jjmpeg_AVDevice_registerAll
+(JNIEnv *env, jclass jc) {
+ DLCHECK_RET(env, avdevice_register_all, );
+ DLCALL(avdevice_register_all)();
+}
+
+/* *** */
+
+JNIEXPORT jobject JNICALL Java_au_notzed_jjmpeg_AVDevice_nextAudioInputDevice
+(JNIEnv *env, jclass jc, jobject jiformat) {
+ AVInputFormat *iformat = NativeZ_getP(env, jiformat);
+
+ DLCHECK_RET(env, av_input_audio_device_next, NULL);
+
+ iformat = DLCALL(av_input_audio_device_next)(iformat);
+ return NativeZ_refer(env, AVInputFormat_classid, iformat);
+}
+
+JNIEXPORT jobject JNICALL Java_au_notzed_jjmpeg_AVDevice_nextVideoInputDevice
+(JNIEnv *env, jclass jc, jobject jiformat) {
+ AVInputFormat *iformat = NativeZ_getP(env, jiformat);
+
+ DLCHECK_RET(env, av_input_video_device_next, NULL);
+
+ iformat = DLCALL(av_input_video_device_next)(iformat);
+ return NativeZ_refer(env, AVInputFormat_classid, iformat);
+}
+
+JNIEXPORT jobject JNICALL Java_au_notzed_jjmpeg_AVDevice_nextAudioOutputDevice
+(JNIEnv *env, jclass jc, jobject joformat) {
+ AVOutputFormat *oformat = NativeZ_getP(env, joformat);
+
+ DLCHECK_RET(env, av_output_audio_device_next, NULL);
+
+ oformat = DLCALL(av_output_audio_device_next)(oformat);
+ return NativeZ_refer(env, AVOutputFormat_classid, oformat);
+}
+
+JNIEXPORT jobject JNICALL Java_au_notzed_jjmpeg_AVDevice_nextVideoOutputDevice
+(JNIEnv *env, jclass jc, jobject joformat) {
+ AVOutputFormat *oformat = NativeZ_getP(env, joformat);
+
+ DLCHECK_RET(env, av_output_video_device_next, NULL);
+
+ oformat = DLCALL(av_output_video_device_next)(oformat);
+ return NativeZ_refer(env, AVOutputFormat_classid, oformat);
+}
--- /dev/null
+header avdevice libavdevice/avdevice.h {
+ avdevice_version
+ avdevice_configuration
+ avdevice_license
+ avdevice_register_all
+ av_input_audio_device_next
+ av_input_video_device_next
+ av_output_audio_device_next
+ av_output_video_device_next
+}
+
+java AVInputFormat au/notzed/jjmpeg/AVInputFormat {
+}
+
+java AVOutputFormat au/notzed/jjmpeg/AVOutputFormat {
+}
\ No newline at end of file
--- /dev/null
+/*
+ * Copyright (C) 2017 Michael Zucchi
+ *
+ * This file is part of jjmpeg <https://www.zedzone.space/software/jjmpeg.html>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <stdint.h>
+
+#include "au_notzed_jjmpeg_AVFormatContext.h"
+
+#include "jjmpeg.h"
+#include "jj-avformatcontext.h"
+
+/*
+ Note: AVFormatContext.opaque is used to store a pointer to the free function to use.
+
+ avformat_open_input() requires the use of avformat_close_input().
+
+ avformat_alloc_context() and avformat_alloc_output_context2()
+ require the use of avformat_free_context().
+ */
+
+jint AVFormatContext_OnLoad(JavaVM *vmi, JNIEnv *env) {
+ return jj_ResolveReferences(env, java_names, &java)
+ || jj_ResolveFunctions(env, fn_names, &fn);
+}
+
+/* ********************************************************************** */
+/* Fields */
+
+REF_object(AVInputFormat, AVFormatContext, InputFormat, iformat)
+REF_object(AVOutputFormat, AVFormatContext, OutputFormat, oformat)
+GS_object(AVIOContext, AVFormatContext, IOContext, pb)
+
+GET_prim(jint, AVFormatContext, CtxFlags, ctx_flags)
+GET_prim(jint, AVFormatContext, NumStreams, nb_streams)
+
+JNIEXPORT jobject JNICALL MAKE_JJNAME(AVFormatContext, getStream)
+(JNIEnv *env, jobject jo, jint index) {
+ AVFormatContext *o = NativeZ_getP(env, jo);
+
+ if (index >= 0 && index < o->nb_streams)
+ return NativeZ_refer(env, AVStream_classid, o->streams[index]);
+
+ nativez_ThrowException(env, "java/lang/ArrayIndexOutOfBoundsException", "index outside of nb_streams");
+ return NULL;
+}
+
+GET_prim(jlong, AVFormatContext, StartTime, start_time)
+GET_prim(jlong, AVFormatContext, Duration, duration)
+GET_prim(jlong, AVFormatContext, BitRate, bit_rate)
+
+GS_int(AVFormatContext, Flags, flags)
+
+GS_long(AVFormatContext, ProbeSize, probesize)
+GS_long(AVFormatContext, MaxAnalyseDuration, max_analyze_duration)
+
+GS_int(AVFormatContext, VideoCodecID, video_codec_id)
+GS_int(AVFormatContext, AudioCodecID, audio_codec_id)
+GS_int(AVFormatContext, SubtitleCodecID, subtitle_codec_id)
+
+// Groan
+JNIEXPORT jobject JNICALL Java_au_notzed_jjmpeg_AVFormatContext_getMetadata
+(JNIEnv *env, jobject jo) {
+ AVFormatContext *o = NativeZ_getP(env, jo);
+ jobject jdict = AVDictionary_new(env);
+
+ AVDictionary_set(env, jdict, o->metadata, 0);
+
+ return jdict;
+}
+
+JNIEXPORT void JNICALL Java_au_notzed_jjmpeg_AVFormatContext_setMetadata
+(JNIEnv *env, jobject jo, jobject jdict) {
+ AVFormatContext *o = NativeZ_getP(env, jo);
+ AVDictionary *dict = AVDictionary_get(env, jdict);
+
+ // if (check exception) return;
+
+ DLCALL(av_dict_free)(&o->metadata);
+ o->metadata = dict;
+}
+
+
+SET_prim(jint, AVFormatContext, Debug, debug)
+GS_int(AVFormatContext, Seek2Any, seek2any)
+
+/* ********************************************************************** */
+/* Methods */
+
+JNIEXPORT void JNICALL MAKE_JJNAME(AVFormatContext, release)
+(JNIEnv *env, jclass jc, jlong p) {
+ AVFormatContext *o = (void *)p;
+
+ // And of course they take different parameters.
+ if (o->opaque == DLCALL(avformat_free_context))
+ DLCALL(avformat_free_context)(o);
+ else if (o->opaque == DLCALL(avformat_close_input))
+ DLCALL(avformat_close_input)(&o);
+}
+
+JNIEXPORT jint JNICALL Java_au_notzed_jjmpeg_AVFormatContext_getVersion
+(JNIEnv *env, jclass jc) {
+ return DLCALL(avformat_version)();
+}
+
+JNIEXPORT jstring JNICALL Java_au_notzed_jjmpeg_AVFormatContext_getConfiguration
+(JNIEnv *env, jclass jc) {
+ return nativez_NewString(env, DLCALL(avformat_configuration)());
+}
+
+JNIEXPORT jstring JNICALL Java_au_notzed_jjmpeg_AVFormatContext_getLicense
+(JNIEnv *env, jclass jc) {
+ return nativez_NewString(env, DLCALL(avformat_license)());
+}
+
+JNIEXPORT void JNICALL Java_au_notzed_jjmpeg_AVFormatContext_registerAll
+(JNIEnv *env, jclass jc) {
+ DLCALL(av_register_all)();
+}
+
+JNIEXPORT void JNICALL Java_au_notzed_jjmpeg_AVFormatContext_networkInit
+(JNIEnv *env, jclass jc) {
+ DLCALL(avformat_network_init)();
+}
+
+JNIEXPORT void JNICALL Java_au_notzed_jjmpeg_AVFormatContext_networkDeinit
+(JNIEnv *env, jclass jc) {
+ DLCALL(avformat_network_deinit)();
+}
+
+JNIEXPORT jobject JNICALL Java_au_notzed_jjmpeg_AVFormatContext_allocContext__
+(JNIEnv *env, jclass jc) {
+ AVFormatContext *ctx = DLCALL(avformat_alloc_context)();
+
+ if (ctx) {
+ ctx->opaque = DLCALL(avformat_free_context);
+ return NativeZ_create(env, jc, ctx);
+ }
+
+ nativez_ThrowOutOfMemoryError(env, "Allocating context");
+ return NULL;
+}
+
+JNIEXPORT jobject JNICALL Java_au_notzed_jjmpeg_AVFormatContext_newStream
+(JNIEnv *env, jobject jo, jobject jc) {
+ AVFormatContext *o = NativeZ_getP(env, jo);
+ AVCodec *c = NativeZ_getP(env, jc);
+
+ // avformatcontext manages the memory
+ AVStream *s = DLCALL(avformat_new_stream)(o, c);
+ if (s)
+ return NativeZ_refer(env, AVStream_classid, s);
+
+ nativez_ThrowOutOfMemoryError(env, "Allocating stream");
+ return NULL;
+}
+
+JNIEXPORT jobject JNICALL Java_au_notzed_jjmpeg_AVFormatContext_allocContext__Lau_notzed_jjmpeg_AVOutputFormat_2Ljava_lang_String_2Ljava_lang_String_2
+(JNIEnv *env, jclass jc, jobject joformat, jstring jformat_name, jstring jfilename) {
+ AVOutputFormat *oformat = NativeZ_getP(env, joformat);
+ const char *format_name = nativez_GetString(env, jformat_name);
+ const char *filename = nativez_GetString(env, jfilename);
+ int res;
+ AVFormatContext *ctx = NULL;
+
+ res = DLCALL(avformat_alloc_output_context2)(&ctx, oformat, format_name, filename);
+
+ nativez_ReleaseString(env, jformat_name, format_name);
+ nativez_ReleaseString(env, jfilename, filename);
+
+ // One assumes ctx==NULL is enough to indicate error
+ if (ctx) {
+ ctx->opaque = DLCALL(avformat_free_context);
+ return NativeZ_create(env, jc, ctx);
+ }
+
+ jjthrowAVIOException(env, res, "allocOutputContext");
+ return NULL;
+}
+
+JNIEXPORT jobject JNICALL Java_au_notzed_jjmpeg_AVFormatContext_openInput
+(JNIEnv *env, jclass jc, jstring jname, jobject jiformat, jobject joptions) {
+ if (!nativez_NonNull(env, "name == NULL", jname)) return NULL;
+ const char *name = nativez_GetString(env, jname);
+ AVFormatContext *ctx = NULL;
+ AVInputFormat *iformat = NativeZ_getP(env, jiformat);
+ AVDictionary *options = AVDictionary_get(env, joptions);
+ int res;
+ jobject jret = NULL;
+
+ // TODO: this is supposed to take a user-supplied context, ok that's easy.
+ // Problem is it frees any data if it fails. Nice one.
+ // So need to clear the 'P' value if it fails?
+ // Messy messy.
+ // Just implement the obvious case first
+
+ res = DLCALL(avformat_open_input)(&ctx, name, iformat, &options);
+
+ AVDictionary_set(env, joptions, options, 1);
+
+ switch (res) {
+ case 0:
+ ctx->opaque = DLCALL(avformat_close_input);
+ jret = NativeZ_create(env, jc, ctx);
+ break;
+ case AVERROR(ENOENT):
+ nativez_ThrowException(env, "java/io/FileNotFoundException", name);
+ break;
+ default:
+ jjthrowAVIOException(env, res, name);
+ break;
+ }
+
+ nativez_ReleaseString(env, jname, name);
+
+ return jret;
+}
+
+JNIEXPORT void JNICALL Java_au_notzed_jjmpeg_AVFormatContext_findStreamInfo
+(JNIEnv *env, jobject jo, jobjectArray joptions) {
+ AVFormatContext *o = NativeZ_getP(env, jo);
+ AVDictionary **options = NULL;
+ jsize len = 0;
+ int res;
+
+ if (joptions) {
+ len = (*env)->GetArrayLength(env, joptions);
+ if (len != o->nb_streams) {
+ nativez_ThrowException(env, "java/lang/ArrayIndexOutOfBoundsException", "index outside of nb_streams");
+ return;
+ }
+
+ options = alloca(sizeof(*options) * len);
+ for (int i=0;i<len;i++)
+ options[i] = AVDictionary_get(env, (*env)->GetObjectArrayElement(env, joptions, i));
+ }
+
+ res = DLCALL(avformat_find_stream_info)(o, options);
+
+ if (res >= 0) {
+ for (int i=0;i<len;i++) {
+ AVDictionary_set(env, (*env)->GetObjectArrayElement(env, joptions, i), options[i], 1);
+ }
+ return;
+ }
+
+ jjthrowAVIOException(env, res, "findStreamInfo");
+}
+
+JNIEXPORT jboolean JNICALL Java_au_notzed_jjmpeg_AVFormatContext_readFrame
+(JNIEnv *env, jobject jo, jobject jpkt) {
+ AVFormatContext *o = NativeZ_getP(env, jo);
+ AVPacket *pkt = NativeZ_getP(env, jpkt);
+ int res;
+
+ res = DLCALL(av_read_frame)(o, pkt);
+
+ if (res >= 0)
+ return JNI_TRUE;
+
+ if (res == AVERROR_EOF)
+ return JNI_FALSE;
+
+ jjthrowAVIOException(env, res, "readFrame");
+ return JNI_FALSE;
+}
+
+JNIEXPORT void JNICALL Java_au_notzed_jjmpeg_AVFormatContext_seekFrame
+(JNIEnv *env, jobject jo, jint stream_index, jlong timestamp, jint flags) {
+ AVFormatContext *o = NativeZ_getP(env, jo);
+ int res;
+
+ res = DLCALL(av_seek_frame)(o, stream_index, timestamp, flags);
+
+ if (res >= 0)
+ return;
+
+ jjthrowAVIOException(env, res, "seekFrame");
+}
+
+JNIEXPORT void JNICALL Java_au_notzed_jjmpeg_AVFormatContext_seekFile
+(JNIEnv *env, jobject jo, jint stream_index, jlong min_ts, jlong ts, jlong max_ts, jint flags) {
+ AVFormatContext *o = NativeZ_getP(env, jo);
+ int res;
+
+ res = DLCALL(avformat_seek_file)(o, stream_index, min_ts, ts, max_ts, flags);
+ if (res >= 0)
+ return;
+
+ jjthrowAVIOException(env, res, "seekFile");
+}
+
+JNIEXPORT void JNICALL Java_au_notzed_jjmpeg_AVFormatContext_flush
+(JNIEnv *env, jobject jo) {
+ AVFormatContext *o = NativeZ_getP(env, jo);
+ int res;
+
+ res = DLCALL(avformat_flush)(o);
+ if (res >= 0)
+ return;
+
+ jjthrowAVIOException(env, res, "flush");
+}
+
+JNIEXPORT void JNICALL Java_au_notzed_jjmpeg_AVFormatContext_readPlay
+(JNIEnv *env, jobject jo) {
+ AVFormatContext *o = NativeZ_getP(env, jo);
+ int res;
+
+ res = DLCALL(av_read_play)(o);
+ if (res >= 0)
+ return;
+
+ jjthrowAVIOException(env, res, "readPlay");
+}
+
+JNIEXPORT void JNICALL Java_au_notzed_jjmpeg_AVFormatContext_readPause
+(JNIEnv *env, jobject jo) {
+ AVFormatContext *o = NativeZ_getP(env, jo);
+ int res;
+
+ res = DLCALL(av_read_pause)(o);
+ if (res >= 0)
+ return;
+
+ jjthrowAVIOException(env, res, "readPause");
+}
+
+JNIEXPORT jint JNICALL Java_au_notzed_jjmpeg_AVFormatContext_writeHeader
+(JNIEnv *env, jobject jo, jobject joptions) {
+ AVFormatContext *o = NativeZ_getP(env, jo);
+ AVDictionary *options = AVDictionary_get(env, joptions);
+ int res;
+
+ res = DLCALL(avformat_write_header)(o, &options);
+
+ AVDictionary_set(env, joptions, options, 1);
+
+ if (res >= 0)
+ return res;
+
+ jjthrowAVIOException(env, res, "writeHeader");
+ return res;
+}
+
+JNIEXPORT jint JNICALL Java_au_notzed_jjmpeg_AVFormatContext_initOutput
+(JNIEnv *env, jobject jo, jobject joptions) {
+ AVFormatContext *o = NativeZ_getP(env, jo);
+ AVDictionary *options = AVDictionary_get(env, joptions);
+ int res;
+
+ res = DLCALL(avformat_init_output)(o, &options);
+
+ AVDictionary_set(env, joptions, options, 1);
+
+ if (res >= 0)
+ return res;
+
+ jjthrowAVIOException(env, res, "initOutput");
+ return res;
+}
+
+JNIEXPORT jboolean JNICALL Java_au_notzed_jjmpeg_AVFormatContext_writeFrame
+(JNIEnv *env, jobject jo, jobject jpkt) {
+ AVFormatContext *o = NativeZ_getP(env, jo);
+ AVPacket *pkt = NativeZ_getP(env, jpkt);
+ int res;
+
+ res = DLCALL(av_write_frame)(o, pkt);
+
+ if (res >= 0) // 1 == flushed == true
+ return res;
+
+ jjthrowAVIOException(env, res, "writeFrame");
+ return 0;
+}
+
+JNIEXPORT void JNICALL Java_au_notzed_jjmpeg_AVFormatContext_interleavedWriteFrame
+(JNIEnv *env, jobject jo, jobject jpkt) {
+ AVFormatContext *o = NativeZ_getP(env, jo);
+ AVPacket *pkt = NativeZ_getP(env, jpkt);
+ int res;
+
+ // TODO: this function takes ownership of the packet!
+ // CHECK: It either makes a ref+ or a copy, so this should be ok with java
+ res = DLCALL(av_interleaved_write_frame)(o, pkt);
+ if (res >= 0)
+ return;
+
+ jjthrowAVIOException(env, res, "interleavedWriteFrame");
+}
+
+JNIEXPORT void JNICALL Java_au_notzed_jjmpeg_AVFormatContext_writeUncodedFrame
+(JNIEnv *env, jobject jo, jint stream_index, jobject jframe) {
+ AVFormatContext *o = NativeZ_getP(env, jo);
+ AVFrame *frame = NativeZ_getP(env, jframe);
+ int res;
+
+ res = DLCALL(av_write_uncoded_frame)(o, stream_index, frame);
+ if (res >= 0)
+ return;
+
+ jjthrowAVIOException(env, res, "writeUncodedFrame");
+}
+
+JNIEXPORT void JNICALL Java_au_notzed_jjmpeg_AVFormatContext_interleavedWriteUncodedFrame
+ (JNIEnv *env, jobject jo, jint stream_index, jobject jframe) {
+ AVFormatContext *o = NativeZ_getP(env, jo);
+ AVFrame *frame = NativeZ_getP(env, jframe);
+ int res;
+
+ res = DLCALL(av_interleaved_write_uncoded_frame)(o, stream_index, frame);
+ if (res >= 0)
+ return;
+
+ jjthrowAVIOException(env, res, "interleavedWriteUncodedFrame");
+}
+
+JNIEXPORT void JNICALL Java_au_notzed_jjmpeg_AVFormatContext_writeTrailer
+(JNIEnv *env, jobject jo) {
+ AVFormatContext *o = NativeZ_getP(env, jo);
+ int res;
+
+ res = DLCALL(av_write_trailer)(o);
+ if (res >= 0)
+ return;
+
+ jjthrowAVIOException(env, res, "writeTrailer");
+}
+
+JNIEXPORT jint JNICALL Java_au_notzed_jjmpeg_AVFormatContext_findDefaultStreamIndex
+(JNIEnv *env, jobject jo) {
+ AVFormatContext *o = NativeZ_getP(env, jo);
+
+ return DLCALL(av_find_default_stream_index)(o);
+}
+
+// TODO: av_get_output_timestamp
+
--- /dev/null
+header avformat libavformat/avformat.h {
+ avformat_version
+ avformat_configuration
+ avformat_license
+ av_register_all
+ avformat_network_init
+ avformat_network_deinit
+ avformat_alloc_context
+ avformat_free_context
+ avformat_new_stream
+ avformat_alloc_output_context2
+ avformat_open_input
+ avformat_find_stream_info
+ av_read_frame
+ av_seek_frame
+ avformat_seek_file
+ avformat_flush
+ av_read_play
+ av_read_pause
+ avformat_close_input
+ avformat_write_header
+ avformat_init_output
+ av_write_frame
+ av_interleaved_write_frame
+ av_write_uncoded_frame
+ av_interleaved_write_uncoded_frame
+ av_write_trailer
+ av_find_default_stream_index
+}
+
+header avutil libavutil/dict.h {
+ av_dict_free
+}
+
+java AVInputFormat au/notzed/jjmpeg/AVInputFormat {
+}
+
+java AVOutputFormat au/notzed/jjmpeg/AVOutputFormat {
+}
+
+java AVIOContext au/notzed/jjmpeg/AVIOContext {
+}
+
+java AVStream au/notzed/jjmpeg/AVStream {
+}
--- /dev/null
+/*
+ * Copyright (C) 2017 Michael Zucchi
+ *
+ * This file is part of jjmpeg <https://www.zedzone.space/software/jjmpeg.html>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <stdint.h>
+
+#include "au_notzed_jjmpeg_AVFrame.h"
+#include "au_notzed_jjmpeg_AVFrame_FrameReader.h"
+#include "au_notzed_jjmpeg_AVFrame_FrameWriter.h"
+#include "au_notzed_jjmpeg_AVFrame_SampleReader.h"
+
+#include "jjmpeg.h"
+
+#include "jj-avframe.h"
+#undef DLCALL
+#define DLCALL(x) (fn.x)
+
+#define MAX(a, b) ((a)>(b)?(a):(b))
+
+jint AVFrame_OnLoad(JavaVM *vmi, JNIEnv *env) {
+ return jj_ResolveFunctions(env, fn_names, &fn);
+}
+
+/* ********************************************************************** */
+/* Fields */
+
+/**
+ TODO: how do we know this is a video or audio frame?
+*/
+
+static int getPlaneCount(const AVPixFmtDescriptor *desc) {
+ if (desc->flags & (AV_PIX_FMT_FLAG_PAL | AV_PIX_FMT_FLAG_PSEUDOPAL)) {
+ return 2;
+ } else {
+ int nplanes = 0;
+
+ for (int i=0;i<desc->nb_components;i++)
+ nplanes = MAX(nplanes, desc->comp[i].plane+1);
+
+ return nplanes;
+ }
+}
+
+JNIEXPORT jobject JNICALL Java_au_notzed_jjmpeg_AVFrame_getPlane
+(JNIEnv *env, jobject jframe, jint index) {
+ AVFrame *frame = NativeZ_getP(env, jframe);
+
+ // TODO: do i want a more descriptive object here, e.g. VideoPlane or something
+
+ // Video frame only!
+
+ const AVPixFmtDescriptor *desc = DLCALL(av_pix_fmt_desc_get)(frame->format);
+ int nplanes = getPlaneCount(desc);
+
+ if ((unsigned int)index >= nplanes) {
+ nativez_ThrowException(env, "java/lang/ArrayIndexOutOfBoundsException", "Index out of range");
+ return NULL;
+ }
+
+ if (desc->flags & (AV_PIX_FMT_FLAG_PAL | AV_PIX_FMT_FLAG_PSEUDOPAL)) {
+ // Plane 0 is index byte, Plane 1 is palette.
+ switch (index) {
+ case 0:
+ return nativez_NewDirectBuffer(env, frame->data[0], frame->height * frame->linesize[0]);
+ case 1:
+ return nativez_NewDirectBuffer(env, frame->data[1], 256*4);
+ }
+ return NULL; // for compiler only
+ } else {
+ //? int av_image_get_buffer_size(enum AVPixelFormat pix_fmt, int width, int height, int align);
+ int shift = (index == 1 || index == 2) ? desc->log2_chroma_h : 0;
+ int height = (frame->height + (1<<shift) - 1) >> shift;
+
+ return nativez_NewDirectBuffer(env, frame->data[index], height * frame->linesize[index]);
+ }
+}
+
+JNIEXPORT jint JNICALL Java_au_notzed_jjmpeg_AVFrame_getStride
+(JNIEnv *env, jobject jframe, jint index) {
+ AVFrame *frame = NativeZ_getP(env, jframe);
+
+ if ((unsigned int)index >= AV_NUM_DATA_POINTERS) {
+ nativez_ThrowException(env, "java/lang/ArrayIndexOutOfBoundsException", "Index out of range");
+ return 0;
+ }
+
+ return frame->linesize[index];
+}
+
+/* ********************************************************************** */
+
+GS_int(AVFrame, Width, width)
+GS_int(AVFrame, Height, height)
+
+JNIEXPORT jint JNICALL Java_au_notzed_jjmpeg_AVFrame_getPixelFormat
+(JNIEnv *env, jobject jframe) {
+ AVFrame *frame = NativeZ_getP(env, jframe);
+
+ // TODO: check is image
+
+ return frame->format;
+}
+
+GET_bool(AVFrame, isKeyFrame, key_frame)
+GS_long(AVFrame, PTS, pts)
+GET_value(AVRational_new, AVFrame, AspectRatio, sample_aspect_ratio)
+GET_prim(jint, AVFrame, DisplayPictureNumber, display_picture_number)
+GET_prim(jint, AVFrame, CodedPictureNumber, coded_picture_number)
+GET_bool(AVFrame, isInterlaced, interlaced_frame)
+GET_bool(AVFrame, isTopFieldFirst, top_field_first)
+
+/* ********************************************************************** */
+/* Audio */
+
+GS_int(AVFrame, NumSamples, nb_samples)
+
+JNIEXPORT jint JNICALL Java_au_notzed_jjmpeg_AVFrame_getSampleFormat
+(JNIEnv *env, jobject jframe) {
+ AVFrame *frame = NativeZ_getP(env, jframe);
+
+ // TODO: check is audio
+
+ return frame->format;
+}
+
+GS_int(AVFrame, SampleRate, sample_rate)
+GS_long(AVFrame, ChannelLayout, channel_layout)
+GS_int(AVFrame, NumChannels, channels)
+
+GET_prim(jint, AVFrame, BestEffortTimestamp, best_effort_timestamp)
+
+/* ********************************************************************** */
+/* Methods */
+
+JNIEXPORT void JNICALL Java_au_notzed_jjmpeg_AVFrame_release
+(JNIEnv *env, jclass jc, jlong p) {
+ AVFrame *frame = (void *)(uintptr_t)p;
+
+ DLCALL(av_frame_free)(&frame);
+}
+
+JNIEXPORT jobject JNICALL Java_au_notzed_jjmpeg_AVFrame_alloc__
+(JNIEnv *env, jclass jc) {
+ return NativeZ_create(env, jc, DLCALL(av_frame_alloc)());
+}
+
+JNIEXPORT jobject JNICALL Java_au_notzed_jjmpeg_AVFrame_alloc__III
+(JNIEnv *env, jclass jc, jint jfmt, jint width, jint height) {
+ AVFrame *f = DLCALL(av_frame_alloc)();
+
+ if (f) {
+ int res;
+
+ f->format = jfmt;
+ f->width = width;
+ f->height = height;
+
+ res = DLCALL(av_frame_get_buffer)(f, 0);
+ if (res == 0)
+ return NativeZ_create(env, jc, f);
+
+ DLCALL(av_frame_free)(&f);
+ jjthrowAVIOException(env, res, "Allocating video frame data");
+ return NULL;
+ }
+
+ nativez_ThrowOutOfMemoryError(env, "Allocating frame");
+ return NULL;
+}
+
+JNIEXPORT jobject JNICALL Java_au_notzed_jjmpeg_AVFrame_alloc__IIJI
+(JNIEnv *env, jclass jc, jint jfmt, jint channels, jlong channel_layout, jint nsamples) {
+ AVFrame *f = DLCALL(av_frame_alloc)();
+
+ if (f) {
+ int res;
+
+ f->format = jfmt;
+ f->nb_samples = nsamples;
+ f->channels = channels;
+ f->channel_layout = channel_layout;
+
+ res = DLCALL(av_frame_get_buffer)(f, 0);
+ if (res == 0)
+ return NativeZ_create(env, jc, f);
+
+ DLCALL(av_frame_free)(&f);
+ jjthrowAVIOException(env, res, "Allocating audio frame data");
+ return NULL;
+ }
+
+ nativez_ThrowOutOfMemoryError(env, "Allocating frame");
+ return NULL;
+}
+
+/* **************************************** */
+JNIEXPORT void JNICALL Java_au_notzed_jjmpeg_AVFrame_copy
+(JNIEnv *env, jobject jdst, jobject jsrc) {
+ AVFrame *dst = NativeZ_getP(env, jdst);
+ AVFrame *src = NativeZ_getP(env, jsrc);
+ int res;
+
+ res = DLCALL(av_frame_copy)(dst, src);
+ // FIXME: this is not an i/o error
+ if (res < 0)
+ jjthrowAVIOException(env, res, "Frame copy failed");
+}
+
+JNIEXPORT void JNICALL Java_au_notzed_jjmpeg_AVFrame_copyProperties
+(JNIEnv *env, jobject jdst, jobject jsrc) {
+ AVFrame *dst = NativeZ_getP(env, jdst);
+ AVFrame *src = NativeZ_getP(env, jsrc);
+ int res;
+
+ res = DLCALL(av_frame_copy_props)(dst, src);
+ // FIXME: this is not an i/o error
+ if (res < 0)
+ jjthrowAVIOException(env, res, "Frame properties copy failed");
+}
+
+
+/* ********************************************************************** */
+/* FrameReader */
+
+typedef struct FrameReader {
+ // The initialisation values
+ int dwidth, dheight;
+ int flags;
+
+ // Current context
+ struct SwsContext *ctx;
+
+ jobject jframe; // reference
+ AVFrame *frame;
+} FrameReader;
+
+JNIEXPORT void JNICALL Java_au_notzed_jjmpeg_AVFrame_00024FrameReader_release
+(JNIEnv *env, jclass jc, jlong ifr) {
+ FrameReader *fr = (void *)(intptr_t)ifr;
+
+ (*env)->DeleteGlobalRef(env, fr->jframe);
+ DLCALL(sws_freeContext)(fr->ctx);
+ free(fr);
+}
+
+JNIEXPORT jobject JNICALL Java_au_notzed_jjmpeg_AVFrame_00024FrameReader_alloc
+(JNIEnv *env, jclass jc, jobject jframe, jint width, jint height, jint flags) {
+ FrameReader *pr = calloc(1, sizeof(*pr));
+ AVFrame *frame = NativeZ_getP(env, jframe);
+
+ pr->dwidth = width;
+ pr->dheight = height;
+ pr->flags = flags;
+
+ pr->jframe = (*env)->NewGlobalRef(env, jframe);
+ pr->frame = frame;
+
+ return NativeZ_create(env, jc, pr);
+}
+
+// stride?
+static void read_image
+(JNIEnv *env, FrameReader *pr, int dstY, int dstHeight, enum AVPixelFormat dfmt, void *pixels, size_t length, size_t offset) {
+ AVFrame *frame = pr->frame;
+ int srcY = dstY * frame->height / pr->dheight;
+ int srcHeight = (dstY+dstHeight) * frame->height / pr->dheight - srcY;
+ int strides[4];
+ uint8_t *data[4];
+ int res;
+
+ res = DLCALL(av_image_fill_linesizes)(strides, dfmt, pr->dwidth);
+ res = DLCALL(av_image_fill_pointers)(data, dfmt, dstHeight, pixels + offset, strides);
+
+ if (res > 0 && res <= length - offset) {
+ res = DLCALL(sws_scale)(pr->ctx,
+ (const uint8_t * const*)frame->data, frame->linesize,
+ srcY, srcHeight,
+ data, strides);
+ } else {
+ nativez_ThrowException(env, "java/nio/BufferOverflowException", NULL);
+ }
+}
+
+static int check_format(int fmt) {
+ // FIXME: this should also set "srcRange" on swscontext - except getCachedContext inits it too early
+ switch (fmt) {
+ case AV_PIX_FMT_YUVJ420P:
+ return AV_PIX_FMT_YUV420P;
+ case AV_PIX_FMT_YUVJ422P:
+ return AV_PIX_FMT_YUV422P;
+ case AV_PIX_FMT_YUVJ444P:
+ return AV_PIX_FMT_YUV444P;
+ case AV_PIX_FMT_YUVJ440P:
+ return AV_PIX_FMT_YUV440P;
+ default:
+ return fmt;
+ }
+}
+
+JNIEXPORT void JNICALL Java_au_notzed_jjmpeg_AVFrame_00024FrameReader_getPixels__IIILjava_nio_Buffer_2I
+(JNIEnv *env, jobject jpr, jint dstY, jint dstHeight, jint dfmt, jobject jbuffer, jint stride) {
+ FrameReader *pr = NativeZ_getP(env, jpr);
+ AVFrame *frame = pr->frame;
+
+ pr->ctx = DLCALL(sws_getCachedContext)(pr->ctx,
+ frame->width, frame->height, check_format(frame->format),
+ pr->dwidth, pr->dheight, dfmt,
+ pr->flags, NULL, NULL, NULL);
+ if (!pr->ctx) {
+ // FIXME: placeholder exception
+ nativez_ThrowException(env, "java/lang/RuntimeException", "Unable to create scale context");
+ return;
+ }
+
+ void *pixels = (*env)->GetDirectBufferAddress(env, jbuffer);
+ jsize length = (*env)->GetDirectBufferCapacity(env, jbuffer);
+ jint offset = nativez_BufferPosition(env, jbuffer);
+
+ if (!pixels || length < 0) {
+ nativez_ThrowException(env, "java/lang/UnsupportedOperationException", "Must be a direct buffer");
+ return;
+ }
+
+ read_image(env, pr, dstY, dstHeight, dfmt, pixels, length, offset);
+}
+
+static void read_image_primitive
+(JNIEnv *env, jobject jpr, int dstY, int dstHeight, jint dfmt, jarray jbuffer, jint offset, jint stride, int shift) {
+ FrameReader *pr = NativeZ_getP(env, jpr);
+ AVFrame *frame = pr->frame;
+
+ pr->ctx = DLCALL(sws_getCachedContext)(pr->ctx,
+ frame->width, frame->height, check_format(frame->format),
+ pr->dwidth, pr->dheight, dfmt,
+ pr->flags, NULL, NULL, NULL);
+ if (!pr->ctx) {
+ // FIXME: placeholder exception
+ nativez_ThrowException(env, "java/lang/RuntimeException", "Unable to create scale context");
+ return;
+ }
+
+ offset <<= shift;
+ stride <<= shift;
+
+ jsize length = (*env)->GetArrayLength(env, jbuffer) << shift;
+ void *pixels;
+
+ pixels = (*env)->GetPrimitiveArrayCritical(env, jbuffer, NULL);
+ read_image(env, pr, dstY, dstHeight, dfmt, pixels, length, offset);
+ (*env)->ReleasePrimitiveArrayCritical(env, jbuffer, pixels, 0);
+}
+
+JNIEXPORT void JNICALL Java_au_notzed_jjmpeg_AVFrame_00024FrameReader_getPixels__III_3BII
+(JNIEnv *env, jobject jc, jint dstY, jint dstHeight, jint jfmt, jbyteArray jdata, jint offset, jint stride) {
+ read_image_primitive(env, jc, dstY, dstHeight, jfmt, jdata, offset, stride, 0);
+}
+
+JNIEXPORT void JNICALL Java_au_notzed_jjmpeg_AVFrame_00024FrameReader_getPixels__III_3SII
+(JNIEnv *env, jobject jc, jint dstY, jint dstHeight, jint jfmt, jshortArray jdata, jint offset, jint stride) {
+ read_image_primitive(env, jc, dstY, dstHeight, jfmt, jdata, offset, stride, 1);
+}
+
+JNIEXPORT void JNICALL Java_au_notzed_jjmpeg_AVFrame_00024FrameReader_getPixels__III_3III
+(JNIEnv *env, jobject jc, jint dstY, jint dstHeight, jint jfmt, jintArray jdata, jint offset, jint stride) {
+ read_image_primitive(env, jc, dstY, dstHeight, jfmt, jdata, offset, stride, 2);
+}
+
+/* ********************************************************************** */
+/* FrameWriter */
+
+typedef struct FrameWriter {
+ // The initialisation values
+ int swidth, sheight;
+ int flags;
+
+ // Current context
+ struct SwsContext *ctx;
+
+ jobject jframe; // reference
+ AVFrame *frame;
+} FrameWriter;
+
+JNIEXPORT void JNICALL Java_au_notzed_jjmpeg_AVFrame_00024FrameWriter_release
+(JNIEnv *env, jclass jc, jlong ifr) {
+ FrameWriter *fr = (void *)(intptr_t)ifr;
+
+ (*env)->DeleteGlobalRef(env, fr->jframe);
+ DLCALL(sws_freeContext)(fr->ctx);
+ free(fr);
+}
+
+JNIEXPORT jobject JNICALL Java_au_notzed_jjmpeg_AVFrame_00024FrameWriter_alloc
+(JNIEnv *env, jclass jc, jobject jframe, jint width, jint height, jint flags) {
+ FrameWriter *pr = calloc(1, sizeof(*pr));
+ AVFrame *frame = NativeZ_getP(env, jframe);
+
+ pr->swidth = width;
+ pr->sheight = height;
+ pr->flags = flags;
+
+ pr->jframe = (*env)->NewGlobalRef(env, jframe);
+ pr->frame = frame;
+
+ return NativeZ_create(env, jc, pr);
+}
+
+// stride?
+static void write_image
+(JNIEnv *env, FrameWriter *pr, int srcY, int srcHeight, enum AVPixelFormat sfmt, void *pixels, size_t length, size_t offset) {
+ AVFrame *frame = pr->frame;
+ int strides[4];
+ uint8_t *data[4];
+ int res;
+
+ res = DLCALL(av_image_fill_linesizes)(strides, sfmt, pr->swidth);
+ res = DLCALL(av_image_fill_pointers)(data, sfmt, srcHeight, pixels + offset, strides);
+
+ if (res > 0 && res <= length - offset) {
+ res = DLCALL(sws_scale)(pr->ctx,
+ (const uint8_t * const *)data, strides,
+ srcY, srcHeight,
+ frame->data, frame->linesize);
+ } else {
+ nativez_ThrowException(env, "java/nio/BufferOverflowException", NULL);
+ }
+}
+
+JNIEXPORT void JNICALL Java_au_notzed_jjmpeg_AVFrame_00024FrameWriter_setPixels__IIILjava_nio_Buffer_2I
+(JNIEnv *env, jobject jpr, jint srcY, jint srcHeight, jint sfmt, jobject jbuffer, jint stride) {
+ FrameWriter *pr = NativeZ_getP(env, jpr);
+ AVFrame *frame = pr->frame;
+
+ pr->ctx = DLCALL(sws_getCachedContext)(pr->ctx,
+ pr->swidth, pr->sheight, sfmt,
+ frame->width, frame->height, frame->format,
+ pr->flags, NULL, NULL, NULL);
+ if (!pr->ctx) {
+ // FIXME: placeholder exception
+ nativez_ThrowException(env, "java/lang/RuntimeException", "Unable to create scale context");
+ return;
+ }
+
+ void *pixels = (*env)->GetDirectBufferAddress(env, jbuffer);
+ jsize length = (*env)->GetDirectBufferCapacity(env, jbuffer);
+ jint offset = nativez_BufferPosition(env, jbuffer);
+
+ if (!pixels || length < 0) {
+ nativez_ThrowException(env, "java/lang/UnsupportedOperationException", "Must be a direct buffer");
+ return;
+ }
+
+ write_image(env, pr, srcY, srcHeight, sfmt, pixels, length, offset);
+}
+
+static void write_image_primitive
+(JNIEnv *env, jobject jpr, int srcY, int srcHeight, jint sfmt, jarray jbuffer, jint offset, jint stride, int shift) {
+ FrameWriter *pr = NativeZ_getP(env, jpr);
+ AVFrame *frame = pr->frame;
+
+ pr->ctx = DLCALL(sws_getCachedContext)(pr->ctx,
+ pr->swidth, pr->sheight, sfmt,
+ frame->width, frame->height, frame->format,
+ pr->flags, NULL, NULL, NULL);
+ if (!pr->ctx) {
+ // FIXME: placeholder exception
+ nativez_ThrowException(env, "java/lang/RuntimeException", "Unable to create scale context");
+ return;
+ }
+
+ offset <<= shift;
+ stride <<= shift;
+
+ jsize length = (*env)->GetArrayLength(env, jbuffer) << shift;
+ void *pixels;
+
+ pixels = (*env)->GetPrimitiveArrayCritical(env, jbuffer, NULL);
+ write_image(env, pr, srcY, srcHeight, sfmt, pixels, length, offset);
+ (*env)->ReleasePrimitiveArrayCritical(env, jbuffer, pixels, 0);
+}
+
+JNIEXPORT void JNICALL Java_au_notzed_jjmpeg_AVFrame_00024FrameWriter_setPixels__III_3BII
+(JNIEnv *env, jobject jc, jint srcY, jint srcHeight, jint jfmt, jbyteArray jdata, jint offset, jint stride) {
+ write_image_primitive(env, jc, srcY, srcHeight, jfmt, jdata, offset, stride, 0);
+}
+
+JNIEXPORT void JNICALL Java_au_notzed_jjmpeg_AVFrame_00024FrameWriter_setPixels__III_3SII
+(JNIEnv *env, jobject jc, jint srcY, jint srcHeight, jint jfmt, jshortArray jdata, jint offset, jint stride) {
+ write_image_primitive(env, jc, srcY, srcHeight, jfmt, jdata, offset, stride, 1);
+}
+
+JNIEXPORT void JNICALL Java_au_notzed_jjmpeg_AVFrame_00024FrameWriter_setPixels__III_3III
+(JNIEnv *env, jobject jc, jint srcY, jint srcHeight, jint jfmt, jintArray jdata, jint offset, jint stride) {
+ write_image_primitive(env, jc, srcY, srcHeight, jfmt, jdata, offset, stride, 2);
+}
+
+/* ********************************************************************** */
+/* SampleReader */
+
+typedef struct SampleReader {
+ // Current context
+ struct SwrContext *ctx;
+
+ // Cache of current settings
+ jlong src_layout, dst_layout;
+ jint src_fmt, dst_fmt;
+ jint src_rate, dst_rate;
+
+ // per sample byte size
+ int dst_size;
+
+ jobject jframe; // reference
+ AVFrame *frame;
+} SampleReader;
+
+static int update_rate(JNIEnv *env, SampleReader *pr) {
+ AVFrame *frame = pr->frame;
+
+ if (pr->ctx == NULL
+ || frame->sample_rate != pr->src_rate
+ || frame->format != pr->src_fmt
+ || frame->channel_layout != pr->src_layout) {
+ pr->ctx = DLCALL(swr_alloc_set_opts)
+ (pr->ctx,
+ pr->dst_layout, pr->dst_fmt, pr->dst_rate,
+ frame->channel_layout, frame->format, frame->sample_rate,
+ 0, NULL);
+
+ if (!pr->ctx) {
+ nativez_ThrowException(env, "java/lang/UnsupportedOperationException", "Unsupported rate/format conversion");
+ return -1;
+ }
+
+ pr->src_layout = frame->channel_layout;
+ pr->src_fmt = frame->format;
+ pr->src_rate = frame->sample_rate;
+
+ DLCALL(swr_init)(pr->ctx);
+ }
+
+ return 0;
+}
+
+JNIEXPORT void JNICALL Java_au_notzed_jjmpeg_AVFrame_00024SampleReader_release
+(JNIEnv *env, jclass jc, jlong ifr) {
+ SampleReader *fr = (void *)(intptr_t)ifr;
+
+ (*env)->DeleteGlobalRef(env, fr->jframe);
+ DLCALL(swr_free)(&fr->ctx);
+ free(fr);
+}
+
+JNIEXPORT jobject JNICALL Java_au_notzed_jjmpeg_AVFrame_00024SampleReader_alloc
+(JNIEnv *env, jclass jc, jobject jframe, jlong layout, jint fmt, jint rate) {
+
+ if (DLCALL(av_sample_fmt_is_planar)(layout)) {
+ nativez_ThrowException(env, "java/lang/UnsupportedOperationException", "Unsupported rate/format conversion");
+ return NULL;
+ }
+
+ SampleReader *pr = calloc(1, sizeof(*pr));
+ AVFrame *frame = NativeZ_getP(env, jframe);
+
+ pr->jframe = (*env)->NewGlobalRef(env, jframe);
+ pr->frame = frame;
+ pr->dst_layout = layout;
+ pr->dst_fmt = fmt;
+ pr->dst_rate = rate;
+
+ pr->dst_size = DLCALL(av_get_bytes_per_sample)(pr->dst_fmt) * DLCALL(av_get_channel_layout_nb_channels)(pr->dst_layout);
+
+ return NativeZ_create(env, jc, pr);
+}
+
+JNIEXPORT jint JNICALL Java_au_notzed_jjmpeg_AVFrame_00024SampleReader_getNumSamples
+(JNIEnv *env, jobject jpr) {
+ SampleReader *pr = NativeZ_getP(env, jpr);
+
+ if (update_rate(env, pr) == 0)
+ return DLCALL(swr_get_out_samples)(pr->ctx, pr->frame->nb_samples);
+
+ return 0;
+}
+
+static int read_samples(JNIEnv *env, SampleReader *pr, uint8_t *samples, jsize size) {
+ AVFrame *frame = pr->frame;
+ int nsamples = DLCALL(swr_get_out_samples)(pr->ctx, pr->frame->nb_samples);
+ int required = pr->dst_size * nsamples;
+ int res;
+
+ if (required > size) {
+ nativez_ThrowException(env, "java/nio/BufferOverflowException", NULL);
+ return 0;
+ }
+
+ res = DLCALL(swr_convert)(pr->ctx,
+ (uint8_t **)&samples, nsamples,
+ (const uint8_t **)frame->data, frame->nb_samples);
+
+ if (res < 0)
+ nativez_ThrowException(env, "java/lang/RuntimeException", "swr_convert failed");
+
+ return res;
+}
+
+JNIEXPORT void JNICALL Java_au_notzed_jjmpeg_AVFrame_00024SampleReader_getSamples__Ljava_nio_Buffer_2
+(JNIEnv *env, jobject jpr, jobject jbuffer) {
+ SampleReader *pr = NativeZ_getP(env, jpr);
+ int res;
+
+ if (update_rate(env, pr) != 0)
+ return;
+
+ uint8_t *samples = (*env)->GetDirectBufferAddress(env, jbuffer);
+ jsize length = nativez_BufferLimit(env, jbuffer);
+ jint offset = nativez_BufferPosition(env, jbuffer);
+
+ if (!samples) {
+ nativez_ThrowException(env, "java/lang/UnsupportedOperationException", "Buffer must be direct");
+ return;
+ }
+
+ res = read_samples(env, pr, samples + offset, length - offset);
+ if (res > 0)
+ nativez_BufferSetPosition(env, jbuffer, offset + res * pr->dst_size);
+}
+
+static int read_samples_primitive(JNIEnv *env, jobject jpr, jarray jbuffer, jint offset, jsize size, int shift) {
+ SampleReader *pr = NativeZ_getP(env, jpr);
+ int res;
+
+ if (update_rate(env, pr) != 0)
+ return 0;
+
+ offset <<= shift;
+ size <<= shift;
+
+ jsize length = (*env)->GetArrayLength(env, jbuffer) << shift;
+ uint8_t *samples;
+
+ if (size + offset > length) {
+ nativez_ThrowException(env, "java/nio/BufferOverflowException", NULL);
+ return 0;
+ }
+
+ samples = (*env)->GetPrimitiveArrayCritical(env, jbuffer, NULL);
+ res = read_samples(env, pr, samples + offset, size);
+ (*env)->ReleasePrimitiveArrayCritical(env, jbuffer, samples, 0);
+
+ return res;
+}
+
+JNIEXPORT jint JNICALL Java_au_notzed_jjmpeg_AVFrame_00024SampleReader_getSamples___3BII
+(JNIEnv *env, jobject jpr, jbyteArray samples, jint offset, jint size) {
+ return read_samples_primitive(env, jpr, samples, offset, size, 0);
+}
+
+JNIEXPORT jint JNICALL Java_au_notzed_jjmpeg_AVFrame_00024SampleReader_getSamples___3SII
+(JNIEnv *env, jobject jpr, jshortArray samples, jint offset, jint size) {
+ return read_samples_primitive(env, jpr, samples, offset, size, 1);
+}
+
+JNIEXPORT jint JNICALL Java_au_notzed_jjmpeg_AVFrame_00024SampleReader_getSamples___3III
+(JNIEnv *env, jobject jpr, jintArray samples, jint offset, jint size) {
+ return read_samples_primitive(env, jpr, samples, offset, size, 2);
+}
+
+JNIEXPORT jint JNICALL Java_au_notzed_jjmpeg_AVFrame_00024SampleReader_getSamples___3FII
+(JNIEnv *env, jobject jpr, jfloatArray samples, jint offset, jint size) {
+ return read_samples_primitive(env, jpr, samples, offset, size, 2);
+}
--- /dev/null
+header avutil libavutil/frame.h {
+ av_frame_alloc
+ av_frame_free
+ av_frame_copy_props
+ av_frame_copy
+
+ av_frame_get_buffer
+}
+
+header avutil libavutil/imgutils.h {
+ av_pix_fmt_desc_get
+ av_image_fill_linesizes
+ av_image_fill_pointers
+}
+
+header avutil libavutil/samplefmt.h {
+ av_sample_fmt_is_planar
+ av_get_bytes_per_sample
+
+}
+
+header avutil libavutil/channel_layout.h {
+ av_get_channel_layout_nb_channels
+}
+
+header swscale libswscale/swscale.h {
+ sws_getCachedContext
+ sws_freeContext
+ sws_scale
+}
+
+header swresample libswresample/swresample.h {
+ swr_alloc_set_opts
+ swr_free
+ swr_init
+ swr_convert
+ swr_get_out_samples
+}
\ No newline at end of file
--- /dev/null
+/*
+ * Copyright (C) 2017 Michael Zucchi
+ *
+ * This file is part of jjmpeg <https://www.zedzone.space/software/jjmpeg.html>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "au_notzed_jjmpeg_AVIOContext.h"
+
+#include "jjmpeg.h"
+
+#include "jj-aviocontext.h"
+
+jint AVIOContext_OnLoad(JavaVM *vmi, JNIEnv *env) {
+ return jj_ResolveReferences(env, java_names, &java)
+ || jj_ResolveFunctions(env, fn_names, &fn);
+}
+
+/* ********************************************************************** */
+
+struct jj_io {
+ // AVIOHandler global reference
+ jobject jhandler;
+ // direct ByteBuffer for this data
+ // I don't think this will work looking at avio*.c
+ //jobject jbuffer;
+ //uint8_t *buffer;
+};
+
+static int jj_read_packet(void *opaque, uint8_t *buf, int buf_size) {
+ JNIEnv *env = nativez_AttachCurrentThread();
+
+ if (env) {
+ struct jj_io *jjio = opaque;
+ //size_t position = (buf - jjio->buffer);
+ jvalue args[1];
+
+ //jjbufferSetLimit(env, jjio->jbuffer, (int)(position + buf_size));
+ //jjbufferSetPosition(env, jjio->jbuffer, (int)(position));
+ //args[0].l = jjio->jbuffer;
+
+ args[0].l = nativez_NewDirectBuffer(env, buf, buf_size);
+
+ return (*env)->CallIntMethodA(env, jjio->jhandler, AVIOHandler_readPacket_l, args);
+ } else {
+ return AVERROR(EIO);
+ }
+}
+
+static int jj_write_packet(void *opaque, uint8_t *buf, int buf_size) {
+ JNIEnv *env = nativez_AttachCurrentThread();
+
+ if (env) {
+ struct jj_io *jjio = opaque;
+ //size_t position = (buf - jjio->buffer);
+ jvalue args[1];
+
+ //jjbufferSetLimit(env, jjio->jbuffer, (int)(position + buf_size));
+ //jjbufferSetPosition(env, jjio->jbuffer, (int)(position));
+ //args[0].l = jjio->jbuffer;
+
+ args[0].l = nativez_NewDirectBuffer(env, buf, buf_size);
+
+ return (*env)->CallIntMethodA(env, jjio->jhandler, AVIOHandler_writePacket_l, args);
+ } else {
+ return AVERROR(EIO);
+ }
+}
+
+static int64_t jj_seek(void *opaque, int64_t offset, int whence) {
+ JNIEnv *env = nativez_AttachCurrentThread();
+
+ if (env) {
+ struct jj_io *jjio = opaque;
+ jvalue args[2];
+
+ args[0].j = offset;
+ args[1].i = whence;
+
+ return (*env)->CallLongMethodA(env, jjio->jhandler, AVIOHandler_seek_ji, args);
+ } else {
+ return AVERROR(EIO);
+ }
+}
+
+JNIEXPORT void JNICALL Java_au_notzed_jjmpeg_AVIOContext_release
+(JNIEnv *env, jclass jc, jlong jic) {
+ AVIOContext *ic = (void *)(uintptr_t)jic;
+
+ if (ic->read_packet == jj_read_packet) {
+ struct jj_io *jjio = ic->opaque;
+
+ (*env)->DeleteGlobalRef(env, jjio->jhandler);
+ //(*env)->DeleteGlobalRef(env, jjio->jbuffer);
+ //DLCALL(av_free)(jjio->buffer);
+ free(jjio);
+
+ DLCALL(av_free)(ic->buffer);
+ DLCALL(avio_context_free)(&ic);
+ } else {
+ DLCALL(avio_close)(ic);
+ }
+}
+
+JNIEXPORT jobject JNICALL Java_au_notzed_jjmpeg_AVIOContext_open
+(JNIEnv *env, jclass jc, jstring jurl, jint flags) {
+ const char *url = nativez_GetString(env, jurl);
+ AVIOContext *ic = NULL;
+ int res;
+
+ res = DLCALL(avio_open)(&ic, url, flags);
+ if (res < 0)
+ jjthrowAVIOException(env, res, url);
+ nativez_ReleaseString(env, jurl, url);
+
+ return NativeZ_create(env, jc, ic);
+}
+
+JNIEXPORT jobject JNICALL Java_au_notzed_jjmpeg_AVIOContext_alloc
+(JNIEnv *env, jclass jc, jint buffer_size, jint jflags, jobject jhandler) {
+ AVIOContext *io = NULL;
+ struct jj_io *jjio;
+ uint8_t *buffer;
+
+ jjio = malloc(sizeof(*jjio));
+ if (jjio) {
+ buffer = DLCALL(av_malloc)(buffer_size);
+ if (buffer) {
+ int write_flag = (jflags & au_notzed_jjmpeg_AVIOContext_AVIO_WRITABLE) != 0;
+
+ jjio->jhandler = (*env)->NewGlobalRef(env, jhandler);
+ //jjio->jbuffer = jjnewDirectBuffer(env, jjio->buffer, buffer_size);
+
+ io = DLCALL(avio_alloc_context)(buffer, buffer_size, write_flag, jjio,
+ jj_read_packet,
+ jj_write_packet,
+ jj_seek);
+ if (io) {
+ io->seekable = jflags & 3;
+ io->direct = (jflags & au_notzed_jjmpeg_AVIOContext_AVIO_DIRECT) != 0;
+ } else {
+ nativez_ThrowOutOfMemoryError(env, "Allocating io context");
+ free(buffer);
+ free(jjio);
+ }
+ } else {
+ nativez_ThrowOutOfMemoryError(env, "Allocating buffer");
+ free(jjio);
+ }
+ } else {
+ nativez_ThrowOutOfMemoryError(env, "Allocating handler");
+ }
+
+ return NativeZ_create(env, jc, io);
+}
--- /dev/null
+header avformat libavformat/avio.h {
+
+ avio_alloc_context
+ avio_context_free
+
+ avio_open
+ avio_close
+}
+
+header avutil libavutil/mem.h {
+ av_malloc
+ av_free
+}
+
+java AVIOHandler au/notzed/jjmpeg/AVIOContext$AVIOHandler {
+ readPacket, (Ljava/nio/ByteBuffer;)I
+ writePacket, (Ljava/nio/ByteBuffer;)I
+ seek, (JI)J
+}
--- /dev/null
+/*
+ * Copyright (C) 2017 Michael Zucchi
+ *
+ * This file is part of jjmpeg <https://www.zedzone.space/software/jjmpeg.html>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+/*
+ Several of the smaller objects together here.
+ */
+
+#include <stdint.h>
+
+#include "au_notzed_jjmpeg_AVInputFormat.h"
+#include "au_notzed_jjmpeg_AVOutputFormat.h"
+#include "au_notzed_jjmpeg_AVRational.h"
+#include "au_notzed_jjmpeg_SwsContext.h"
+
+#include "au_notzed_jjmpeg_AVCodecID.h"
+#include "au_notzed_jjmpeg_AVPixelFormat.h"
+#include "au_notzed_jjmpeg_AVSampleFormat.h"
+#include "au_notzed_jjmpeg_AVChannelLayout.h"
+#include "au_notzed_jjmpeg_AVMediaType.h"
+
+#include "au_notzed_jjmpeg_AVError.h"
+
+#include "jjmpeg.h"
+
+#include "jj-avmisc.h"
+#undef DLCALL
+#define DLCALL(x) (fn.x)
+
+jint AVMisc_OnLoad(JavaVM *vmi, JNIEnv *env) {
+ return jj_ResolveFunctions(env, fn_names, &fn);
+}
+
+/* ********************************************************************** */
+/* AVInputFormat */
+
+GET_string(AVInputFormat, Name, name)
+GET_string(AVInputFormat, LongName, long_name)
+
+JNIEXPORT jobject JNICALL Java_au_notzed_jjmpeg_AVInputFormat_findInputFormat
+(JNIEnv *env, jclass jc, jstring jname) {
+ const char *name = nativez_GetString(env, jname);
+ AVInputFormat *iformat;
+
+ iformat = DLCALL(av_find_input_format)(name);
+
+ nativez_ReleaseString(env, jname, name);
+
+ return NativeZ_refer(env, jc, iformat);
+}
+
+JNIEXPORT jobject JNICALL Java_au_notzed_jjmpeg_AVInputFormat_next
+(JNIEnv *env, jclass jc, jobject jiformat) {
+ AVInputFormat *iformat = NativeZ_getP(env, jiformat);
+
+ iformat = DLCALL(av_iformat_next)(iformat);
+
+ return NativeZ_refer(env, jc, iformat);
+}
+
+JNIEXPORT void JNICALL Java_au_notzed_jjmpeg_AVInputFormat_register
+(JNIEnv *env, jobject jiformat) {
+ AVInputFormat *iformat = NativeZ_getP(env, jiformat);
+
+ DLCALL(av_register_input_format)(iformat);
+}
+
+/* ********************************************************************** */
+/* AVOutputFormat */
+
+GET_string(AVOutputFormat, Name, name)
+GET_string(AVOutputFormat, LongName, long_name)
+GET_string(AVOutputFormat, MimeType, mime_type)
+GET_string(AVOutputFormat, Extensions, extensions)
+
+GET_prim(jint, AVOutputFormat, VideoCodec, video_codec)
+GET_prim(jint, AVOutputFormat, AudioCodec, audio_codec)
+GET_prim(jint, AVOutputFormat, SubtitleCodec, subtitle_codec)
+
+GET_prim(jint, AVOutputFormat, Flags, flags)
+
+JNIEXPORT jobject JNICALL Java_au_notzed_jjmpeg_AVOutputFormat_guessFormat
+(JNIEnv *env, jclass jc, jstring jname, jstring jfile, jstring jmime) {
+ const char *name = nativez_GetString(env, jname);
+ const char *file = nativez_GetString(env, jfile);
+ const char *mime = nativez_GetString(env, jmime);
+ AVOutputFormat *oformat;
+
+ oformat = DLCALL(av_guess_format)(name, file, mime);
+
+ nativez_ReleaseString(env, jname, name);
+ nativez_ReleaseString(env, jfile, file);
+ nativez_ReleaseString(env, jmime, mime);
+
+ return NativeZ_refer(env, jc, oformat);
+}
+
+JNIEXPORT jint JNICALL Java_au_notzed_jjmpeg_AVOutputFormat_guessCodecID
+(JNIEnv *env, jobject joformat, jstring jname, jstring jfile, jstring jmime, jint jtype) {
+ AVOutputFormat *oformat = NativeZ_getP(env, joformat);
+ const char *name = nativez_GetString(env, jname);
+ const char *file = nativez_GetString(env, jfile);
+ const char *mime = nativez_GetString(env, jmime);
+ enum AVCodecID codecID;
+
+ codecID = DLCALL(av_guess_codec)(oformat, name, file, mime, jtype);
+
+ nativez_ReleaseString(env, jname, name);
+ nativez_ReleaseString(env, jfile, file);
+ nativez_ReleaseString(env, jmime, mime);
+
+ return codecID;
+}
+
+JNIEXPORT jobject JNICALL Java_au_notzed_jjmpeg_AVOutputFormat_next
+(JNIEnv *env, jclass jc, jobject joformat) {
+ AVOutputFormat *oformat = NativeZ_getP(env, joformat);
+
+ oformat = DLCALL(av_oformat_next)(oformat);
+
+ return NativeZ_refer(env, jc, oformat);
+}
+
+JNIEXPORT void JNICALL Java_au_notzed_jjmpeg_AVOutputFormat_register
+(JNIEnv *env, jobject joformat) {
+ AVOutputFormat *oformat = NativeZ_getP(env, joformat);
+
+ DLCALL(av_register_output_format)(oformat);
+}
+
+/* ********************************************************************** */
+/* AVRational */
+
+JNIEXPORT jobject JNICALL Java_au_notzed_jjmpeg_AVRational_d2q
+(JNIEnv *env, jclass jc, jdouble jd, jint jmax) {
+ AVRational r = DLCALL(av_d2q)(jd, jmax);
+
+ return AVRational_new(env, r);
+}
+
+JNIEXPORT jlong JNICALL Java_au_notzed_jjmpeg_AVRational_rescale
+(JNIEnv *env, jclass jc, jlong a, jlong b, jlong c) {
+ return DLCALL(av_rescale)(a, b, c);
+}
+
+JNIEXPORT jobject JNICALL Java_au_notzed_jjmpeg_AVRational_mul
+(JNIEnv *env, jobject jb, jobject jc) {
+ AVRational b = AVRational_get(env, jb);
+ AVRational c = AVRational_get(env, jc);
+ AVRational a = DLCALL(av_mul_q)(b, c);
+
+ return AVRational_new(env, a);
+}
+
+JNIEXPORT jobject JNICALL Java_au_notzed_jjmpeg_AVRational_div
+(JNIEnv *env, jobject jb, jobject jc) {
+ AVRational b = AVRational_get(env, jb);
+ AVRational c = AVRational_get(env, jc);
+ AVRational a = DLCALL(av_div_q)(b, c);
+
+ return AVRational_new(env, a);
+}
+
+JNIEXPORT jobject JNICALL Java_au_notzed_jjmpeg_AVRational_add
+(JNIEnv *env, jobject jb, jobject jc) {
+ AVRational b = AVRational_get(env, jb);
+ AVRational c = AVRational_get(env, jc);
+ AVRational a = DLCALL(av_add_q)(b, c);
+
+ return AVRational_new(env, a);
+}
+
+JNIEXPORT jobject JNICALL Java_au_notzed_jjmpeg_AVRational_sub
+(JNIEnv *env, jobject jb, jobject jc) {
+ AVRational b = AVRational_get(env, jb);
+ AVRational c = AVRational_get(env, jc);
+ AVRational a = DLCALL(av_sub_q)(b, c);
+
+ return AVRational_new(env, a);
+}
+
+/* ********************************************************************** */
+/* AVError */
+
+JNIEXPORT jstring JNICALL Java_au_notzed_jjmpeg_AVError_toString
+(JNIEnv *env, jclass jc, jint jval) {
+ char errormsg[AV_ERROR_MAX_STRING_SIZE];
+
+ DLCALL(av_strerror)(jval, errormsg, sizeof(errormsg));
+
+ return nativez_NewString(env, errormsg);
+}
+
+/* ********************************************************************** */
+/* AVPixelFormat */
+
+JNIEXPORT jint JNICALL Java_au_notzed_jjmpeg_AVPixelFormat_valueOf
+(JNIEnv *env, jclass jc, jstring jname) {
+ const char *name = nativez_GetString(env, jname);
+ enum AVPixelFormat fmt = DLCALL(av_get_pix_fmt)(name);
+ nativez_ReleaseString(env, jname, name);
+ return fmt;
+}
+
+JNIEXPORT jstring JNICALL Java_au_notzed_jjmpeg_AVPixelFormat_toString
+(JNIEnv *env, jclass jc, jint jval) {
+ const char *name = DLCALL(av_get_pix_fmt_name)(jval);
+
+ if (!name)
+ name = "none";
+
+ return nativez_NewString(env, name);
+}
+
+/* ********************************************************************** */
+/* AVSampleFormat */
+
+JNIEXPORT jint JNICALL Java_au_notzed_jjmpeg_AVSampleFormat_valueOf
+(JNIEnv *env, jclass jc, jstring jname) {
+ const char *name = nativez_GetString(env, jname);
+ enum AVSampleFormat fmt = DLCALL(av_get_sample_fmt)(name);
+ nativez_ReleaseString(env, jname, name);
+ return fmt;
+}
+
+JNIEXPORT jstring JNICALL Java_au_notzed_jjmpeg_AVSampleFormat_toString
+(JNIEnv *env, jclass jc, jint jval) {
+ const char *name = DLCALL(av_get_sample_fmt_name)(jval);
+ return nativez_NewString(env, name);
+}
+
+/* ********************************************************************** */
+/* AVChannelLayout */
+
+JNIEXPORT jlong JNICALL Java_au_notzed_jjmpeg_AVChannelLayout_valueOf
+(JNIEnv *env, jclass jc, jstring jname) {
+ const char *name = nativez_GetString(env, jname);
+ enum AVSampleFormat fmt = DLCALL(av_get_channel_layout)(name);
+ nativez_ReleaseString(env, jname, name);
+ return fmt;
+}
+
+JNIEXPORT jstring JNICALL Java_au_notzed_jjmpeg_AVChannelLayout_toString
+(JNIEnv *env, jclass jc, jlong jval) {
+ //const char *name = DLCALL(av_get_channel_name)(jval); // only handles 1 channel at a time
+ char name[256];
+
+ DLCALL(av_get_channel_layout_string)(name, sizeof(name), 0, jval);
+
+ return nativez_NewString(env, name);
+}
+
+JNIEXPORT jint JNICALL Java_au_notzed_jjmpeg_AVChannelLayout_getNumChannels
+(JNIEnv *env, jclass jc, jlong jval) {
+ return DLCALL(av_get_channel_layout_nb_channels)(jval);
+}
+
+JNIEXPORT jlong JNICALL Java_au_notzed_jjmpeg_AVChannelLayout_getDefaultLayout
+(JNIEnv *env, jclass jc, jint jval) {
+ return DLCALL(av_get_default_channel_layout)(jval);
+}
+
+/* ********************************************************************** */
+/* AVMediaType */
+
+JNIEXPORT jstring JNICALL Java_au_notzed_jjmpeg_AVMediaType_toString
+(JNIEnv *env, jclass jc, jint jval) {
+ const char *name = DLCALL(av_get_media_type_string)(jval);
+ return nativez_NewString(env, name);
+}
+
+/* ********************************************************************** */
+/* AVCodecID */
+
+JNIEXPORT jstring JNICALL Java_au_notzed_jjmpeg_AVCodecID_toString
+(JNIEnv *env, jclass jc, jint jval) {
+ const char *name = DLCALL(avcodec_get_name)(jval);
+ return nativez_NewString(env, name);
+}
+
+JNIEXPORT jint JNICALL Java_au_notzed_jjmpeg_AVCodecID_getType
+(JNIEnv *env, jclass jc, jint jval) {
+ return DLCALL(avcodec_get_type)(jval);
+}
+
+/* ********************************************************************** */
+/* SwsContext */
+
+JNIEXPORT jint JNICALL Java_au_notzed_jjmpeg_SwsContext_getVersion
+(JNIEnv *env, jclass jc) {
+ return DLCALL(swscale_version)();
+}
+
+JNIEXPORT jstring JNICALL Java_au_notzed_jjmpeg_SwsContext_getConfiguration
+(JNIEnv *env, jclass jc) {
+ return nativez_NewString(env, DLCALL(swscale_configuration)());
+}
+
+JNIEXPORT jstring JNICALL Java_au_notzed_jjmpeg_SwsContext_getLicense
+(JNIEnv *env, jclass jc) {
+ return nativez_NewString(env, DLCALL(swscale_license)());
+}
+
+/* *** */
+
+// FIXME: implement filters
+JNIEXPORT jobject JNICALL Java_au_notzed_jjmpeg_SwsContext_alloc
+(JNIEnv *env, jclass jc, jint srcW, jint srcH, jint srcFormat, jint dstW, jint dstH, jint dstFormat, jint flags, jobject jsrcFilter, jobject jdstFilter, jdoubleArray jparams) {
+ jdouble *params = NULL;
+ struct SwsContext *ctx;
+
+ if (jparams) {
+ jsize len = (*env)->GetArrayLength(env, jparams);
+
+ params = alloca(sizeof(*params) * len);
+ (*env)->GetDoubleArrayRegion(env, jparams, 0, len, params);
+ }
+
+ ctx = DLCALL(sws_getContext)(srcW, srcH, srcFormat, dstW, dstH, dstFormat, flags, NULL, NULL, params);
+ if (!ctx) {
+ jjthrowAVIOException(env, 0, "Unable to create SWS Context");
+ return NULL;
+ }
+
+ return NativeZ_create(env, jc, ctx);
+}
+
+JNIEXPORT jint JNICALL Java_au_notzed_jjmpeg_SwsContext_scale__Lau_notzed_jjmpeg_AVFrame_2IILau_notzed_jjmpeg_AVFrame_2
+(JNIEnv *env, jobject jctx, jobject jsrc, jint sliceY, jint sliceH, jobject jdst) {
+ struct SwsContext *ctx = NativeZ_getP(env, jctx);
+ AVFrame *src = NativeZ_getP(env, jsrc);
+ AVFrame *dst = NativeZ_getP(env, jdst);
+
+ return DLCALL(sws_scale)(ctx, (const uint8_t * const *)src->data, src->linesize,
+ sliceY, sliceH,
+ dst->data, dst->linesize);
+}
+
+/*
+static int scaleToArray(JNIEnv *env, SwsContext *sws, AVFrame *src, jint srcSliceY, jint srcSliceH, jarray jdst, int dsize, enum AVPixelFormat dfmt, jint dwidth, jint dheight) {
+ struct AVPicture dst;
+ void *cdst;
+ int res = -1;
+ jsize alength = (*env)->GetArrayLength(env, jdst) * dsize;
+ int linesizes[4];
+ uint8_t datas[4];
+
+ res = DLCALL(av_image_fill_linesizes)(linesizes, dfmt, dwidth);
+
+ cdst = (*env)->GetPrimitiveArrayCritical(env, jdst, NULL);
+
+ if (!cdst)
+ // FIXME: exception
+ return -1;
+
+ res = DLCALL(av_image_fill_pointers)(data, dfmt, dheight, cdst, linesizes);
+ // erorr handling
+ // size checking (res is size if positive)
+
+
+ res = DLCALL(sws_scale)(sws, (const uint8_t * const *)src->data, src->linesize,
+ sliceY, sliceH,
+ datas, linesizes);
+
+ (*env)->ReleasePrimitiveArrayCritical(env, jdst, cdst, 0);
+
+ return res;
+ }*/
+
+JNIEXPORT jint JNICALL Java_au_notzed_jjmpeg_SwsContext_scale__Lau_notzed_jjmpeg_AVFrame_2II_3I
+(JNIEnv *env, jobject jctx, jobject jsrc, jint sliceY, jint sliceH, jintArray jdst) {
+ //struct SwsContext *ctx = NativeZ_getP(env, jctx);
+ //AVFrame *src = NativeZ_getP(env, jsrc);
+
+ //scaleToArray(env, ctx, sliceY, sliceH, jdst, 4,
+ // I need to think about this some more, it needs width/height pixformat
+ // -> this is in swscontext but private.
+ return 0;
+}
+
+JNIEXPORT jint JNICALL Java_au_notzed_jjmpeg_SwsContext_scale__Lau_notzed_jjmpeg_AVFrame_2II_3B
+(JNIEnv *env, jobject jctx, jobject jsrc, jint sliceY, jint slliceH, jbyteArray jdst) {
+ //struct SwsContext *ctx = NativeZ_getP(env, jctx);
+ //AVFrame *src = NativeZ_getP(env, jsrc);
+ return 0;
+}
+
+JNIEXPORT jint JNICALL Java_au_notzed_jjmpeg_SwsContext_scale___3BIILau_notzed_jjmpeg_AVFrame_2
+(JNIEnv *env, jobject jctx, jbyteArray jsrc, jint sliceY, jint sliceH, jobject jdst) {
+ //struct SwsContext *ctx = NativeZ_getP(env, jctx);
+ //AVFrame *dst = NativeZ_getP(env, jdst);
+ return 0;
+}
+
+JNIEXPORT jint JNICALL Java_au_notzed_jjmpeg_SwsContext_scale__Ljava_nio_ByteBuffer_2IILau_notzed_jjmpeg_AVFrame_2
+(JNIEnv *env, jobject jctx, jobject jsrc, jint sliceY, jint sliceH, jobject jdst) {
+ //struct SwsContext *ctx = NativeZ_getP(env, jctx);
+ return 0;
+}
+
--- /dev/null
+header avformat libavformat/avformat.h {
+ av_register_input_format
+ av_find_input_format
+ av_iformat_next
+
+ av_register_output_format
+ av_oformat_next
+ av_guess_format
+ av_guess_codec
+}
+
+header avcodec libavcodec/avcodec.h {
+ avcodec_get_type
+ avcodec_get_name
+}
+
+header avutil libavutil/samplefmt.h {
+ av_get_sample_fmt_name
+ av_get_sample_fmt
+}
+
+header avutil libavutil/channel_layout.h {
+ av_get_channel_name
+ av_get_channel_layout
+ av_get_channel_layout_nb_channels
+ av_get_channel_layout_string
+ av_get_default_channel_layout
+}
+
+header avutil libavutil/imgutils.h {
+ av_get_pix_fmt
+ av_get_pix_fmt_name
+
+ av_get_media_type_string
+
+ av_rescale
+ av_d2q
+ av_mul_q
+ av_div_q
+ av_add_q
+ av_sub_q
+
+# TBD: for swscale
+ av_image_fill_linesizes
+ av_image_fill_pointers
+
+ av_strerror
+}
+
+header swscale libswscale/swscale.h {
+ swscale_version
+ swscale_configuration
+ swscale_license
+ sws_getContext
+ sws_freeContext
+ sws_scale
+}
--- /dev/null
+/*
+ * Copyright (C) 2017 Michael Zucchi
+ *
+ * This file is part of jjmpeg <https://www.zedzone.space/software/jjmpeg.html>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <stdint.h>
+
+#include "au_notzed_jjmpeg_AVOptions.h"
+
+#include "jjmpeg.h"
+#include "jj-avoptions.h"
+
+jint AVOptions_OnLoad(JavaVM *vmi, JNIEnv *env) {
+ return jj_ResolveReferences(env, java_names, &java)
+ || jj_ResolveFunctions(env, fn_names, &fn);
+}
+
+#define GETP(name) void *name = NativeZ_getP(env, j ## name)
+#define STRING(name) const char *name = nativez_GetString(env, j ## name)
+#define RSTRING(name) nativez_ReleaseString(env, j ## name, name)
+
+/* ********************************************************************** */
+/* Setters */
+
+#define CHECKSET(env, name, res) checkSet(env, name, res)
+
+static void checkSet(JNIEnv *env, const char *name, int res) {
+ if (res != 0) {
+ char *msg = alloca(strlen(name) + 32);
+
+ sprintf(msg, "set `%s' failed", name);
+ jjthrowAVIOException(env, res, msg);
+ }
+}
+
+#if 1
+JNIEXPORT void JNICALL Java_au_notzed_jjmpeg_AVOptions_set
+(JNIEnv *env, jobject jo, jstring jname, jstring jval, jint flags) {
+ GETP(o);
+ STRING(name); STRING(val);
+ CHECKSET(env, name, DLCALL(av_opt_set)(o, name, val, flags));
+ RSTRING(name); RSTRING(val);
+}
+
+JNIEXPORT void JNICALL Java_au_notzed_jjmpeg_AVOptions_setInt
+(JNIEnv *env, jobject jo, jstring jname, jlong val, jint flags) {
+ GETP(o);
+ STRING(name);
+ CHECKSET(env, name, DLCALL(av_opt_set_int)(o, name, val, flags));
+ RSTRING(name);
+}
+
+JNIEXPORT void JNICALL Java_au_notzed_jjmpeg_AVOptions_setDouble
+(JNIEnv *env, jobject jo, jstring jname, jdouble val, jint flags) {
+ GETP(o);
+ STRING(name);
+ CHECKSET(env, name, DLCALL(av_opt_set_double)(o, name, val, flags));
+ RSTRING(name);
+}
+
+JNIEXPORT void JNICALL Java_au_notzed_jjmpeg_AVOptions_setQ
+(JNIEnv *env, jobject jo, jstring jname, jobject jval, jint flags) {
+ GETP(o);
+ STRING(name);
+ AVRational val = AVRational_get(env, jval);
+ CHECKSET(env, name, DLCALL(av_opt_set_q)(o, name, val, flags));
+ RSTRING(name);
+}
+
+JNIEXPORT void JNICALL Java_au_notzed_jjmpeg_AVOptions_setBin
+(JNIEnv *env, jobject jo, jstring jname, jbyteArray jval, jint offset, jint len, jint flags) {
+ // not implemented
+}
+
+JNIEXPORT void JNICALL Java_au_notzed_jjmpeg_AVOptions_setImageSize
+(JNIEnv *env, jobject jo, jstring jname, jobject jval, jint flags) {
+ GETP(o);
+ STRING(name);
+ AVSize val = AVSize_get(env, jval);
+ CHECKSET(env, name, DLCALL(av_opt_set_image_size)(o, name, val.width, val.height, flags));
+ RSTRING(name);
+}
+
+JNIEXPORT void JNICALL Java_au_notzed_jjmpeg_AVOptions_setPixelFormat
+(JNIEnv *env, jobject jo, jstring jname, jint jval, jint flags) {
+ GETP(o);
+ STRING(name);
+ CHECKSET(env, name, DLCALL(av_opt_set_pixel_fmt)(o, name, jval, flags));
+ RSTRING(name);
+}
+
+JNIEXPORT void JNICALL Java_au_notzed_jjmpeg_AVOptions_setSampleFormat
+(JNIEnv *env, jobject jo, jstring jname, jint jval, jint flags) {
+ GETP(o);
+ STRING(name);
+ CHECKSET(env, name, DLCALL(av_opt_set_sample_fmt)(o, name, jval, flags));
+ RSTRING(name);
+}
+
+JNIEXPORT void JNICALL Java_au_notzed_jjmpeg_AVOptions_setVideoRate
+(JNIEnv *env, jobject jo, jstring jname, jobject jval, jint flags) {
+ GETP(o);
+ STRING(name);
+ AVRational val = AVRational_get(env, jval);
+ CHECKSET(env, name, DLCALL(av_opt_set_video_rate)(o, name, val, flags));
+ RSTRING(name);
+}
+
+JNIEXPORT void JNICALL Java_au_notzed_jjmpeg_AVOptions_setChannelLayout
+(JNIEnv *env, jobject jo, jstring jname, jlong val, jint flags) {
+ GETP(o);
+ STRING(name);
+ CHECKSET(env, name, DLCALL(av_opt_set_channel_layout)(o, name, val, flags));
+ RSTRING(name);
+}
+
+JNIEXPORT void JNICALL Java_au_notzed_jjmpeg_AVOptions_setDictionary
+(JNIEnv *env, jobject jo, jstring jname, jobject jval, jint flags) {
+ GETP(o);
+ AVDictionary *val = AVDictionary_get(env, jval);
+ STRING(name);
+ CHECKSET(env, name, DLCALL(av_opt_set_dict_val)(o, name, val, flags));
+ RSTRING(name);
+ DLCALL(av_dict_free)(&val);
+}
+#endif
+
+/* ********************************************************************** */
+/* Getters, guessed it didn't you. */
+
+#define CHECKGET(env, name, res) checkGet(env, name, res)
+
+static void checkGet(JNIEnv *env, const char *name, int res) {
+ if (res != 0) {
+ char *msg = alloca(strlen(name) + 32);
+
+ sprintf(msg, "set `%s' failed", name);
+ jjthrowAVIOException(env, res, msg);
+ }
+}
+
+#if 1
+// Hmm, this also gets 'binary' values, assume the value is a string here
+// and a binary in the other one
+
+JNIEXPORT jstring JNICALL Java_au_notzed_jjmpeg_AVOptions_get
+(JNIEnv *env, jobject jo, jstring jname, jint flags) {
+ GETP(o);
+ STRING(name);
+ char *val;
+ CHECKGET(env, name, DLCALL(av_opt_get)(o, name, flags, (uint8_t **)&val));
+ jstring jval = nativez_NewString(env, val);
+ DLCALL(av_free)(val);
+ RSTRING(name);
+ return jval;
+}
+
+JNIEXPORT jlong JNICALL Java_au_notzed_jjmpeg_AVOptions_getInt
+(JNIEnv *env, jobject jo, jstring jname, jint flags) {
+ GETP(o);
+ STRING(name);
+ int64_t val;
+ CHECKGET(env, name, DLCALL(av_opt_get_int)(o, name, flags, &val));
+ RSTRING(name);
+ return val;
+}
+
+JNIEXPORT jdouble JNICALL Java_au_notzed_jjmpeg_AVOptions_getDouble
+(JNIEnv *env, jobject jo, jstring jname, jint flags) {
+ GETP(o);
+ STRING(name);
+ double val;
+ CHECKGET(env, name, DLCALL(av_opt_get_double)(o, name, flags, &val));
+ RSTRING(name);
+ return val;
+}
+
+JNIEXPORT jobject JNICALL Java_au_notzed_jjmpeg_AVOptions_getQ
+(JNIEnv *env, jobject jo, jstring jname, jint flags) {
+ GETP(o);
+ STRING(name);
+ AVRational val;
+ CHECKGET(env, name, DLCALL(av_opt_get_q)(o, name, flags, &val));
+ RSTRING(name);
+ return AVRational_new(env, val);
+}
+
+JNIEXPORT jintArray JNICALL Java_au_notzed_jjmpeg_AVOptions_getImageSize
+(JNIEnv *env, jobject jo, jstring jname, jint flags) {
+ GETP(o);
+ STRING(name);
+ AVSize val;
+ CHECKGET(env, name, DLCALL(av_opt_get_image_size)(o, name, flags, &val.width, &val.height));
+ RSTRING(name);
+ return AVSize_new(env, val);
+}
+
+JNIEXPORT jint JNICALL Java_au_notzed_jjmpeg_AVOptions_getPixelFormat
+(JNIEnv *env, jobject jo, jstring jname, jint flags) {
+ GETP(o);
+ STRING(name);
+ enum AVPixelFormat val;
+ CHECKGET(env, name, DLCALL(av_opt_get_pixel_fmt)(o, name, flags, &val));
+ RSTRING(name);
+ return val;
+}
+
+JNIEXPORT jint JNICALL Java_au_notzed_jjmpeg_AVOptions_getSampleFormat
+(JNIEnv *env, jobject jo, jstring jname, jint flags) {
+ GETP(o);
+ STRING(name);
+ enum AVSampleFormat val;
+ CHECKGET(env, name, DLCALL(av_opt_get_sample_fmt)(o, name, flags, &val));
+ RSTRING(name);
+ return val;
+}
+
+JNIEXPORT jobject JNICALL Java_au_notzed_jjmpeg_AVOptions_getVideoRate
+(JNIEnv *env, jobject jo, jstring jname, jint flags) {
+ GETP(o);
+ STRING(name);
+ AVRational val;
+ CHECKGET(env, name, DLCALL(av_opt_get_video_rate)(o, name, flags, &val));
+ RSTRING(name);
+ return AVRational_new(env, val);
+}
+
+JNIEXPORT jlong JNICALL Java_au_notzed_jjmpeg_AVOptions_getChannelLayout
+(JNIEnv *env, jobject jo, jstring jname, jint flags) {
+ GETP(o);
+ STRING(name);
+ int64_t val;
+ CHECKGET(env, name, DLCALL(av_opt_get_channel_layout)(o, name, flags, &val));
+ RSTRING(name);
+ return val;
+}
+
+JNIEXPORT jobject JNICALL Java_au_notzed_jjmpeg_AVOptions_getDictionary
+(JNIEnv *env, jobject jo, jstring jname, jint flags) {
+ GETP(o);
+ STRING(name);
+ AVDictionary *val;
+ CHECKGET(env, name, DLCALL(av_opt_get_dict_val)(o, name, flags, &val));
+ jobject jval = AVDictionary_new(env);
+ AVDictionary_set(env, jval, val, 1);
+ RSTRING(name);
+ return jval;
+}
+#endif
+
+/* ********************************************************************** */
+/* Other methods */
+
+JNIEXPORT void JNICALL Java_au_notzed_jjmpeg_AVOptions_setOptions
+(JNIEnv *env, jobject jo, jstring joptions) {
+ GETP(o);
+ STRING(options);
+ int res = DLCALL(av_set_options_string)(o, options, "=", ",");
+
+ RSTRING(options);
+ CHECKSET(env, "options", res);
+}
+
+JNIEXPORT jstring JNICALL Java_au_notzed_jjmpeg_AVOptions_getOptions
+(JNIEnv *env, jobject jo, jint opt_flags, jint ser_flags) {
+ GETP(o);
+ char *val = NULL;
+ int res = DLCALL(av_opt_serialize)(o, opt_flags, ser_flags, &val, '=', ',');
+ jstring jval = nativez_NewString(env, val);
+
+ CHECKGET(env, "options", res);
+
+ DLCALL(av_free)(val);
+ return jval;
+}
+
+JNIEXPORT void JNICALL Java_au_notzed_jjmpeg_AVOptions_copyOptions
+(JNIEnv *env, jobject jdst, jobject jsrc) {
+ GETP(dst); GETP(src);
+ DLCALL(av_opt_copy)(dst, src);
+}
+
+static jobject AVOption_create(JNIEnv *env, const AVOption *o) {
+ if (o) {
+ jvalue args[] = {
+ { .j = (intptr_t)o },
+ { .l = nativez_NewString(env, o->name) },
+ { .l = nativez_NewString(env, o->help) },
+ { .i = o->type },
+ { .i = o->flags },
+ { .l = nativez_NewString(env, o->unit) },
+ };
+
+ return (*env)->NewObjectA(env, AVOption_classid, AVOption_new_jlliil, args);
+ } else {
+ return NULL;
+ }
+}
+
+JNIEXPORT jobject JNICALL Java_au_notzed_jjmpeg_AVOptions_nextOption
+(JNIEnv *env, jobject jo, jobject jopt) {
+ GETP(o);
+ const AVOption *prev = jopt ? (void *)(intptr_t)(*env)->GetLongField(env, jopt, AVOption_p) : NULL;
+
+ prev = DLCALL(av_opt_next)(o, prev);
+ return AVOption_create(env, prev);
+}
+
+JNIEXPORT jobject JNICALL Java_au_notzed_jjmpeg_AVOptions_find
+(JNIEnv *env, jobject jo, jstring jname, jstring junit, jint opt_flags, jint search_flags) {
+ GETP(o); STRING(name); STRING(unit);
+ const AVOption *opt = DLCALL(av_opt_find)(o, name, unit, opt_flags, search_flags);
+ RSTRING(unit); RSTRING(name);
+ return AVOption_create(env, opt);
+}
--- /dev/null
+header avutil libavutil/opt.h {
+ av_free
+ av_dict_free
+
+ av_set_options_string
+ av_opt_serialize
+ av_opt_copy
+ av_opt_next
+ av_opt_find
+
+ av_opt_set
+ av_opt_set_int
+ av_opt_set_double
+ av_opt_set_q
+ av_opt_set_bin
+ av_opt_set_image_size
+ av_opt_set_pixel_fmt
+ av_opt_set_sample_fmt
+ av_opt_set_video_rate
+ av_opt_set_channel_layout
+ av_opt_set_dict_val
+
+ av_opt_get
+ av_opt_get_int
+ av_opt_get_double
+ av_opt_get_q
+ av_opt_get_image_size
+ av_opt_get_pixel_fmt
+ av_opt_get_sample_fmt
+ av_opt_get_video_rate
+ av_opt_get_channel_layout
+ av_opt_get_dict_val
+}
+
+java AVOption au/notzed/jjmpeg/AVOptions$AVOption {
+ <init>, (JLjava/lang/String;Ljava/lang/String;IILjava/lang/String;)V
+ p, J
+}
--- /dev/null
+/*
+ * Copyright (C) 2017 Michael Zucchi
+ *
+ * This file is part of jjmpeg <https://www.zedzone.space/software/jjmpeg.html>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <stdint.h>
+
+#include "au_notzed_jjmpeg_AVPacket.h"
+
+#include "jjmpeg.h"
+#include "jj-avpacket.h"
+
+jint AVPacket_OnLoad(JavaVM *vmi, JNIEnv *env) {
+ return jj_ResolveReferences(env, java_names, &java)
+ || jj_ResolveFunctions(env, fn_names, &fn);
+}
+
+/* ********************************************************************** */
+/* Fields */
+
+GS_long(AVPacket, PTS, pts)
+GS_long(AVPacket, DTS, dts)
+GET_prim(jint, AVPacket, Size, size)
+GS_int(AVPacket, StreamIndex, stream_index)
+GET_prim(jint, AVPacket, Flags, flags)
+
+JNIEXPORT void JNICALL MAKE_JJNAME(AVPacket, setFlags)
+ (JNIEnv *env, jobject jo, jint mask, jint flags) {
+ AVCodecContext *o = NativeZ_getP(env, jo);
+
+ o->flags = (o->flags & ~mask) | (mask & flags);
+}
+
+GET_prim(jlong, AVPacket, Position, pos)
+
+/* ********************************************************************** */
+/* Methods */
+
+JNIEXPORT void JNICALL Java_au_notzed_jjmpeg_AVPacket_release
+(JNIEnv *env, jclass jc, jlong jpacket) {
+ AVPacket *packet = (void *)(intptr_t)jpacket;
+
+ DLCALL(av_packet_free)(&packet);
+}
+
+JNIEXPORT jobject JNICALL Java_au_notzed_jjmpeg_AVPacket_alloc
+(JNIEnv *env, jclass jc) {
+ AVPacket *packet = DLCALL(av_packet_alloc)();
+
+ //if (!packet) // outofmemoryerror?
+
+ return NativeZ_create(env, jc, packet);
+}
+
+/* **************************************** */
+
+JNIEXPORT jobject JNICALL Java_au_notzed_jjmpeg_AVPacket_getData
+(JNIEnv *env, jobject jpacket) {
+ AVPacket *packet = NativeZ_getP(env, jpacket);
+
+ if (packet->data)
+ return nativez_NewDirectBuffer(env, packet->data, packet->size);
+
+ return NULL;
+}
+
+JNIEXPORT void JNICALL Java_au_notzed_jjmpeg_AVPacket_clear
+(JNIEnv *env, jobject jpacket) {
+ AVPacket *packet = NativeZ_getP(env, jpacket);
+
+ DLCALL(av_packet_unref)(packet);
+}
+
+JNIEXPORT jobject JNICALL Java_au_notzed_jjmpeg_AVPacket_clone
+(JNIEnv *env, jobject jpacket) {
+ AVPacket *packet = NativeZ_getP(env, jpacket);
+ AVPacket *dst = DLCALL(av_packet_clone)(packet);
+
+ // if !dst ...
+ return NativeZ_create(env, AVPacket_classid, dst);
+}
+
+JNIEXPORT void JNICALL Java_au_notzed_jjmpeg_AVPacket_rescaleTS
+(JNIEnv *env, jobject jpacket, jobject jsrc, jobject jdst) {
+ AVPacket *packet = NativeZ_getP(env, jpacket);
+ AVRational src = AVRational_get(env, jsrc);
+ AVRational dst = AVRational_get(env, jdst);
+
+ DLCALL(av_packet_rescale_ts)(packet, src, dst);
+}
--- /dev/null
+header avcodec libavcodec/avcodec.h {
+ av_packet_alloc
+ av_packet_free
+ av_packet_unref
+ av_packet_clone
+ av_packet_rescale_ts
+}
+
+java AVPacket au/notzed/jjmpeg/AVPacket {
+}
--- /dev/null
+/*
+ * Copyright (C) 2017 Michael Zucchi
+ *
+ * This file is part of jjmpeg <https://www.zedzone.space/software/jjmpeg.html>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <stdint.h>
+
+#include <libavformat/avformat.h>
+
+#include "au_notzed_jjmpeg_AVStream.h"
+
+#include "jjmpeg.h"
+#include "jj-avstream.h"
+
+jint AVStream_OnLoad(JavaVM *vmi, JNIEnv *env) {
+ return jj_ResolveReferences(env, java_names, &java);
+}
+
+/* ********************************************************************** */
+/* Fields */
+
+GET_prim(jint, AVStream, Index, index)
+GS_int(AVStream, ID, id)
+
+GS_value(AVRational_new, AVRational_get, AVStream, TimeBase, time_base)
+
+GS_long(AVStream, StartTime, start_time)
+GS_long(AVStream, Duration, duration)
+GS_long(AVStream, NumFrames, nb_frames)
+
+GS_int(AVStream, Discard, discard)
+
+GS_value(AVRational_new, AVRational_get, AVStream, AverageFrameRate, avg_frame_rate)
+GS_value(AVRational_new, AVRational_get, AVStream, SampleAspectRatio, sample_aspect_ratio)
+GS_value(AVRational_new, AVRational_get, AVStream, DisplayAspectRatio, display_aspect_ratio)
+
+REF_object(AVCodecParameters, AVStream, CodecParameters, codecpar)
--- /dev/null
+
+java AVCodecParameters au/notzed/jjmpeg/AVCodecParameters {
+}
+
--- /dev/null
+/*
+ * Copyright (C) 2017 Michael Zucchi
+ *
+ * This file is part of jjmpeg <https://www.zedzone.space/software/jjmpeg.html>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "au_notzed_jjmpeg_AVUtil.h"
+
+#include "jjmpeg.h"
+#include "jj-avutil.h"
+
+jint AVUtil_OnLoad(JavaVM *vmi, JNIEnv *env) {
+ return jj_ResolveReferences(env, java_names, &java)
+ || jj_ResolveFunctions(env, fn_names, &fn);
+}
+
+static jobject jlogger_ref;
+
+static void log_callback(void*ptr, int level, const char*fmt, va_list vl) {
+ JNIEnv *env = nativez_AttachCurrentThread();
+
+ if (env) {
+ char log[1024];
+ int prefix = 1;
+ int res;
+
+ res = DLCALL(av_log_format_line2)(ptr, level, fmt, vl, log, sizeof(log), &prefix);
+ if (res > 1) {
+ jvalue args[2];
+
+ // Strip trailing \r\n
+ if (log[--res] == '\n')
+ log[res] = 0;
+ if (log[--res] == '\r')
+ log[res] = 0;
+
+ args[0].i = level;
+ args[1].l = nativez_NewString(env, log);
+
+ (*env)->CallVoidMethodA(env, jlogger_ref, AVLogger_log_il, args);
+ }
+ }
+}
+
+JNIEXPORT void JNICALL Java_au_notzed_jjmpeg_AVUtil_setLogger
+(JNIEnv *env, jclass jc, jobject jlogger) {
+ if (jlogger_ref) {
+ (*env)->DeleteGlobalRef(env, jlogger_ref);
+ jlogger_ref = NULL;
+ }
+
+ if (jlogger) {
+ jlogger_ref = (*env)->NewGlobalRef(env, jlogger);
+ DLCALL(av_log_set_callback)(log_callback);
+ } else {
+ DLCALL(av_log_set_callback)(DLCALL(av_log_default_callback));
+ }
+}
--- /dev/null
+header avutil libavutil/log.h {
+ av_log_set_callback
+ av_log_default_callback
+ av_log_format_line2
+ av_default_item_name
+}
+
+java AVLogger au/notzed/jjmpeg/AVLogger {
+ log, (ILjava/lang/String;)V
+}
--- /dev/null
+/*
+ * Copyright (C) 2017 Michael Zucchi
+ *
+ * This file is part of jjmpeg <https://www.zedzone.space/software/jjmpeg.html>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <jni.h>
+
+#include <libavutil/version.h>
+#include <libavcodec/version.h>
+#include <libavformat/version.h>
+#include <libavdevice/version.h>
+#include <libswscale/version.h>
+#include <libswresample/version.h>
+
+#include "jjmpeg.h"
+#include "jjmpeg-jni.h"
+
+#define D(x)
+
+static int fail(const char *ctx, const char *what) __attribute__ ((noinline));
+
+#undef DLSO
+#define DLSO(name, v, flags) { #name, v, flags }
+
+static NZLibTable libtable[] = {
+ DLSO(avutil, LIBAVUTIL_VERSION_MAJOR, 0),
+ DLSO(avcodec, LIBAVCODEC_VERSION_MAJOR, 0),
+ DLSO(avformat, LIBAVFORMAT_VERSION_MAJOR, 0),
+ DLSO(swscale, LIBSWSCALE_VERSION_MAJOR, 0), // noncore?
+ DLSO(swresample, LIBSWRESAMPLE_VERSION_MAJOR, 0), // noncore?
+ DLSO(avdevice, LIBAVDEVICE_VERSION_MAJOR, DLSO_NONCORE),
+
+ { 0 }
+};
+
+typedef jint (*onLoad)(JavaVM *, JNIEnv *);
+
+static onLoad ctors[] = {
+ nativez_OnLoad,
+ AVOptions_OnLoad,
+
+ AVUtil_OnLoad,
+
+ AVCodec_OnLoad,
+ AVCodecContext_OnLoad,
+ AVCodecParameters_OnLoad,
+ AVDevice_OnLoad,
+ AVFormatContext_OnLoad,
+ AVFrame_OnLoad,
+ AVIOContext_OnLoad,
+ AVMisc_OnLoad,
+ AVPacket_OnLoad,
+ AVStream_OnLoad,
+};
+
+jint JNI_OnLoad(JavaVM *vmi, void *reserved) {
+ JNIEnv *env;
+
+ D(printf("libjjmpeg.so: OnLoad()\n"));
+
+ if ((*vmi)->GetEnv(vmi, (void *)&env, JNI_VERSION_1_4) < 0)
+ return 0;
+
+ if (jj_ResolveReferences(env, java_names, &java) != 0
+ || jj_ResolveLibraries(env, libtable) != 0
+ || jj_ResolveFunctions(env, fn_names, &fn) != 0)
+ return -1;
+
+ /* Call other onload functions */
+ for (int i=0;i<sizeof(ctors)/sizeof(*ctors);i++) {
+ int res = ctors[i](vmi, env);
+ if (res != 0)
+ return -1;
+ }
+
+ return JNI_VERSION_1_4;
+}
+
+/* ********************************************************************** */
+
+static int fail(const char *ctx, const char *what) {
+ fprintf(stderr, "%s: %s\n", ctx, what);
+ perror(ctx);
+ fflush(stderr);
+ return -1;
+}
+
+// temporary
+#include <dlfcn.h>
+
+int jj_ResolveLibraries(JNIEnv *env, NZLibTable *table) {
+ char name[64];
+
+ for (int i=0;table[i].name;i++) {
+ void *lib;
+
+ sprintf(name, "lib%s.so", table[i].name);
+
+ lib = dlopen(name, RTLD_LAZY | RTLD_GLOBAL);
+ if (!lib) {
+ return fail("open library", name);
+ }
+
+ table[i].ptr = lib;
+ }
+ return 0;
+}
+
+static int jj_ResolveFunctionsX(JNIEnv *env, const NZLibTable *table, const char *fn_names, void *fnp) {
+ void *lib = NULL;
+ const char *name = fn_names;
+ int index = 0;
+ const char *lib_name = "";
+ void **fn = fnp;
+
+ while (*name) {
+ const char *next = name + strlen(name) + 1;
+
+ if (*name == '#') {
+ lib = NULL;
+ lib_name = name+1;
+ for (int i=0;table[i].name;i++) {
+ if (strcmp(table[i].name, lib_name) == 0) {
+ lib = table[i].ptr;
+ break;
+ }
+ }
+ } else if (lib) {
+ void *entry = dlsym(lib, name);
+
+ fn[index++] = entry;
+ if (!entry) {
+ return fail("resolve function", name);
+ }
+ } else {
+ return fail("find function library", lib_name);
+ }
+
+ name = next;
+ }
+
+ return 0;
+}
+
+int jj_ResolveFunctions(JNIEnv *env, const char *fn_names, void *fnp) {
+ return jj_ResolveFunctionsX(env, libtable, fn_names, fnp);
+}
+
+int jj_ResolveReferences(JNIEnv *env, const char *jn_names, void *jnp) {
+ jclass jc = NULL;
+
+ const char *name = jn_names;
+ int index = 0;
+ void **jn = jnp;
+ const char *cname = "?";
+
+ while (*name) {
+ const char *next = name + strlen(name) + 1;
+
+ switch (*name) {
+ case '#': // class
+ jc = (*env)->FindClass(env, name + 1);
+ jn[index] = jc = (*env)->NewGlobalRef(env, jc);
+ cname = name + 1;
+ break;
+ case ',': // field
+ jn[index] = (*env)->GetFieldID(env, jc, name+1, next);
+ break;
+ case ';': // static field
+ jn[index] = (*env)->GetStaticFieldID(env, jc, name+1, next);
+ break;
+ case '.': // method
+ jn[index] = (*env)->GetMethodID(env, jc, name+1, next);
+ break;
+ case ':': // static method
+ jn[index] = (*env)->GetStaticMethodID(env, jc, name+1, next);
+ break;
+ default:
+ return fail("Invalid table", name);
+ }
+
+ if (!jn[index])
+ return fail(cname, name+1);
+
+ if (*name != '#')
+ next = next + strlen(next) + 1;
+ name = next;
+ index += 1;
+ }
+
+ return 0;
+}
+
+/* ********************************************************************** */
+
+void jjthrowAVIOException(JNIEnv *env, int error, const char *msg) {
+ jvalue jargs[2];
+ jthrowable jex;
+
+ jargs[0].i = error;
+ jargs[1].l = nativez_NewString(env, msg);
+
+ jex = (*env)->NewObjectA(env, AVIOException_classid, AVIOException_new_il, jargs);
+ if (jex)
+ (*env)->Throw(env, jex);
+}
+
+/* ********************************************************************** */
+
+jstring jjnewIntArrayT(JNIEnv *env, const int *ap, int terminal) {
+ jintArray ret = NULL;
+
+ if (ap) {
+ int len = 0;
+
+ while (ap[len] != terminal)
+ len++;
+ ret = (*env)->NewIntArray(env, len);
+ (*env)->SetIntArrayRegion(env, ret, 0, len, (const jint *)ap);
+ }
+ return ret;
+}
+
+/* ********************************************************************** */
+
+jobject AVRational_new(JNIEnv *env, const AVRational cr) {
+ jvalue args[] = {
+ { .i = cr.num },
+ { .i = cr.den }
+ };
+
+ return (*env)->NewObjectA(env, AVRational_classid, AVRational_new_ii, args);
+}
+
+jobjectArray AVRational_newArray(JNIEnv *env, int len) {
+ return (*env)->NewObjectArray(env, len, AVRational_classid, NULL);
+}
+
+AVRational AVRational_get(JNIEnv *env, jobject jr) {
+ AVRational cr;
+
+ cr.num = (*env)->GetIntField(env, jr, AVRational_num);
+ cr.den = (*env)->GetIntField(env, jr, AVRational_den);
+
+ return cr;
+}
+
+/* ********************************************************************** */
+
+jobject AVSize_new(JNIEnv *env, const AVSize cr) {
+ jvalue args[] = {
+ { .i = cr.width },
+ { .i = cr.height }
+ };
+
+ return (*env)->NewObjectA(env, AVSize_classid, AVSize_new_ii, args);
+}
+
+AVSize AVSize_get(JNIEnv *env, jobject jr) {
+ AVSize cr;
+
+ cr.width = (*env)->GetIntField(env, jr, AVSize_width);
+ cr.height = (*env)->GetIntField(env, jr, AVSize_height);
+
+ return cr;
+}
+
+/* ********************************************************************** */
+
+/* Peek inside this snot interface */
+struct AVDictionary {
+ int count;
+ AVDictionaryEntry *elems;
+};
+
+jobject AVDictionary_new(JNIEnv *env) {
+ return (*env)->NewObjectA(env, AVDictionary_classid, AVDictionary_new_, NULL);
+}
+
+jobject AVDictionary_newArray(JNIEnv *env, int len) {
+ return (*env)->NewObjectArray(env, len, AVDictionary_classid, NULL);
+}
+
+AVDictionary *AVDictionary_get(JNIEnv *env, jobject jdict) {
+ AVDictionary *m = NULL;
+ if (jdict) {
+ jobjectArray jlist = (*env)->CallObjectMethodA(env, jdict, AVDictionary_toArray_, NULL);
+ jsize size = (*env)->GetArrayLength(env, jlist);
+
+ if (size) {
+ m = DLCALL(av_malloc)(sizeof(*m));
+ m->count = size;
+ m->elems = DLCALL(av_malloc)(sizeof(*m->elems) * size);
+
+ for (int i=0;i<size;i++) {
+ jobject jentry = (*env)->GetObjectArrayElement(env, jlist, i);
+ jstring jkey = (*env)->CallObjectMethodA(env, jentry, Entry_getKey_, NULL);
+ jstring jvalue = (*env)->CallObjectMethodA(env, jentry, Entry_getValue_, NULL);
+ const char *key = nativez_GetString(env, jkey);
+ const char *value = nativez_GetString(env, jvalue);
+
+ m->elems[i].key = DLCALL(av_strdup)(key);
+ m->elems[i].value = DLCALL(av_strdup)(value);
+
+ nativez_ReleaseString(env, jkey, key);
+ nativez_ReleaseString(env, jvalue, value);
+ }
+ }
+ }
+
+ return m;
+}
+
+void AVDictionary_set(JNIEnv *env, jobject jdict, AVDictionary *dict, int free) {
+ if (jdict) {
+ (*env)->CallVoidMethodA(env, jdict, AVDictionary_clear_, NULL);
+ if (dict && dict->count) {
+ jvalue args[2];
+
+ for (int i=0;i<dict->count;i++) {
+ args[0].l = nativez_NewString(env, dict->elems[i].key);
+ args[1].l = nativez_NewString(env, dict->elems[i].value);
+
+ (*env)->CallObjectMethodA(env, jdict, AVDictionary_put_ll, args);
+ }
+ }
+ }
+ if (free)
+ DLCALL(av_dict_free)(&dict);
+}
+
--- /dev/null
+header avutil libavutil/opt.h {
+ av_malloc
+ av_mallocz
+ av_dict_free
+ av_strdup
+
+ av_strerror
+}
+
+java AVIOException au/notzed/jjmpeg/AVIOException {
+ <init>,(I)V
+ <init>,(ILjava/lang/String;)V
+}
+
+java AVRational au/notzed/jjmpeg/AVRational {
+ <init>,(II)V
+ num,I
+ den,I
+}
+
+java AVSize au/notzed/jjmpeg/AVSize {
+ <init>, (II)V
+ width, I
+ height, I
+}
+
+java AVDictionary au/notzed/jjmpeg/AVDictionary {
+ <init>,()V
+ toArray, ()[Ljava/lang/Object;
+ clear, ()V
+ put, (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
+}
+
+java Buffer java/nio/Buffer {
+ hasArray,()Z
+ array,()Ljava/lang/Object;
+ arrayOffset, ()I
+ position,()I
+ position, (I)Ljava/nio/Buffer;
+ limit, (I)Ljava/nio/Buffer;
+}
+
+#java ByteBuffer java/nio/ByteBuffer {
+# order, (Ljava/nio/ByteOrder;)Ljava/nio/ByteBuffer;
+#}
+
+java Entry java/util/Map$Entry {
+ getKey, ()Ljava/lang/Object;
+ getValue, ()Ljava/lang/Object;
+}
+
+#java NativeZ au/notzed/nativez/NativeZ {
+# static create, (Ljava/lang/Class;J)Lau/notzed/nativez/NativeZ;
+# static register, (Lau/notzed/nativez/NativeZ;)Lau/notzed/nativez/NativeZ;
+# static resolve, (Ljava/lang/Class;J)Lau/notzed/nativez/NativeZ;
+# static refer, (Ljava/lang/Class;J)Lau/notzed/nativez/NativeZ;
+# p, J
+#}
--- /dev/null
+/*
+ * Copyright (C) 2017 Michael Zucchi
+ *
+ * This file is part of jjmpeg <https://www.zedzone.space/software/jjmpeg.html>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef _JJMPEG_H
+#define _JJMPEG_H
+
+#include "nativez.h"
+
+/* Macros for accessor creation */
+
+#define MAKE_JJNAME(jclass, method) \
+ Java_au_notzed_jjmpeg_ ## jclass ## _ ## method
+
+#define GET_prim(jprim, jclass, jname, cname) \
+ JNIEXPORT jprim JNICALL \
+ MAKE_JJNAME(jclass, get ## jname) \
+ (JNIEnv *env, jobject jo) { \
+ jclass *o = NativeZ_getP(env, jo); \
+ return o->cname; \
+ }
+
+#define SET_prim(jprim, jclass, jname, cname) \
+ JNIEXPORT void JNICALL \
+ MAKE_JJNAME(jclass, set ## jname) \
+ (JNIEnv *env, jobject jo, jprim jval) { \
+ jclass *o = NativeZ_getP(env, jo); \
+ o->cname = jval; \
+ }
+
+#define GS_int(jclass, jname, cname) \
+ GET_prim(jint, jclass, jname, cname) \
+ SET_prim(jint, jclass, jname, cname)
+
+#define GS_float(jclass, jname, cname) \
+ GET_prim(jfloat, jclass, jname, cname) \
+ SET_prim(jfloat, jclass, jname, cname)
+
+#define GS_long(jclass, jname, cname) \
+ GET_prim(jlong, jclass, jname, cname) \
+ SET_prim(jlong, jclass, jname, cname)
+
+#define GET_bool(jclass, jname, cname) \
+ JNIEXPORT jboolean JNICALL \
+ MAKE_JJNAME(jclass, jname) \
+ (JNIEnv *env, jobject jo) { \
+ jclass *o = NativeZ_getP(env, jo); \
+ return o->cname; \
+ }
+
+#define GET_object(oclass, jclass, jname, cname) \
+ JNIEXPORT jobject JNICALL \
+ MAKE_JJNAME(jclass, get ## jname) \
+ (JNIEnv *env, jobject jo) { \
+ jclass *o = NativeZ_getP(env, jo); \
+ return NativeZ_resolve(env, oclass ## _classid, o->cname); \
+ }
+
+#define SET_object(jclass, jname, cname) \
+ JNIEXPORT void JNICALL \
+ MAKE_JJNAME(jclass, set ## jname) \
+ (JNIEnv *env, jobject jo, jobject jval) { \
+ jclass *o = NativeZ_getP(env, jo); \
+ o->cname = NativeZ_getP(env, jval); \
+ }
+
+#define GS_object(oclass, jclass, jname, cname) \
+ GET_object(oclass, jclass, jname, cname) \
+ SET_object(jclass, jname, cname)
+
+#define REF_object(oclass, jclass, jname, cname) \
+ JNIEXPORT jobject JNICALL \
+ MAKE_JJNAME(jclass, get ## jname) \
+ (JNIEnv *env, jobject jo) { \
+ jclass *o = NativeZ_getP(env, jo); \
+ return NativeZ_refer(env, oclass ## _classid, o->cname); \
+ }
+
+#define GET_enum(eclass, jclass, jname, cname) \
+ JNIEXPORT jobject JNICALL \
+ MAKE_JJNAME(jclass, get ## jname) \
+ (JNIEnv *env, jobject jo) { \
+ jclass *o = NativeZ_getP(env, jo); \
+ return eclass ## _resolve(env, o->cname); \
+ }
+
+#define SET_enum(eclass, jclass, jname, cname) \
+ JNIEXPORT void JNICALL \
+ MAKE_JJNAME(jclass, set ## jname) \
+ (JNIEnv *env, jobject jo, jobject jval) { \
+ jclass *o = NativeZ_getP(env, jo); \
+ o->cname = eclass ## _value(env, jval); \
+ }
+
+#define GS_enum(eclass, jclass, jname, cname) \
+ GET_enum(eclass, jclass, jname, cname) \
+ SET_enum(eclass, jclass, jname, cname)
+
+#define GET_string(jclass, jname, cname) \
+ JNIEXPORT jstring JNICALL \
+ MAKE_JJNAME(jclass, get ## jname) \
+ (JNIEnv *env, jobject jo) { \
+ jclass *o = NativeZ_getP(env, jo); \
+ return nativez_NewString(env, o->cname); \
+ }
+
+// Not sure about this
+/*
+#define SET_string(jclass, jname, cname) \
+ JNIEXPORT void JNICALL \
+ MAKE_JJNAME(jclass, set ## jname) \
+ (JNIEnv *env, jobject jo, jobject jval) { \
+ jclass *o = NativeZ_getP(env, jo); \
+ const char *val = jjgetString(env, jval); \
+ c->cname = av_strdup(val); \
+ jjreleaseString(env, jval, val); \
+ }
+*/
+
+#define GET_value(rnew, jclass, jname, cname) \
+ JNIEXPORT jobject JNICALL \
+ MAKE_JJNAME(jclass, get ## jname) \
+ (JNIEnv *env, jobject jo) { \
+ jclass *o = NativeZ_getP(env, jo); \
+ return rnew(env, o->cname); \
+ }
+
+#define SET_value(rget, jclass, jname, cname) \
+ JNIEXPORT void JNICALL \
+ MAKE_JJNAME(jclass, set ## jname) \
+ (JNIEnv *env, jobject jo, jobject jval) { \
+ jclass *o = NativeZ_getP(env, jo); \
+ o->cname = rget(env, jval); \
+}
+
+#define GS_value(rnew, rget, jclass, jname, cname) \
+ GET_value(rnew, jclass, jname, cname) \
+ SET_value(rget, jclass, jname, cname)
+
+/* jni table helpers */
+#define JJCLASS(name) JCLASS( name ## _classid, "au/notzed/jjmpeg/" #name )
+
+/**
+ * Create a new array from a terminated integer (/ enum) array
+ *
+ * @param ap Array pointer, may be NULL.
+ * @param terminal Terminating value.
+ */
+jstring jjnewIntArrayT(JNIEnv *env, const int *ap, int terminal);
+
+void jjthrowAVIOException(JNIEnv *env, int error, const char *msg);
+
+/* forward references */
+typedef struct AVRational AVRational;
+typedef struct AVDictionary AVDictionary;
+enum AVPixelFormat;
+enum AVSampleFormat;
+enum AVMediaType;
+
+/* Type Helpers */
+
+// Nasty stuff
+jobject AVDictionary_new(JNIEnv *env);
+jobjectArray AVDictionary_newArray(JNIEnv *env, int len);
+AVDictionary *AVDictionary_get(JNIEnv *env, jobject jdict);
+void AVDictionary_set(JNIEnv *env, jobject jdict, AVDictionary *dict, int free);
+
+// Pass by value
+jobject AVRational_new(JNIEnv *env, AVRational cr);
+jobjectArray AVRational_newArray(JNIEnv *env, int len);
+AVRational AVRational_get(JNIEnv *env, jobject jr);
+
+typedef struct AVSize AVSize;
+struct AVSize {
+ int width;
+ int height;
+};
+
+jobject AVSize_new(JNIEnv *env, AVSize size);
+AVSize AVSize_get(JNIEnv *env, jobject jr);
+
+/* Constructors */
+jint AVOptions_OnLoad(JavaVM *vmi, JNIEnv *env);
+
+jint AVCodecContext_OnLoad(JavaVM *vmi, JNIEnv *env);
+jint AVCodecParameters_OnLoad(JavaVM *vmi, JNIEnv *env);
+jint AVCodec_OnLoad(JavaVM *vmi, JNIEnv *env);
+jint AVDevice_OnLoad(JavaVM *vmi, JNIEnv *env);
+jint AVFormatContext_OnLoad(JavaVM *vmi, JNIEnv *env);
+jint AVFrame_OnLoad(JavaVM *vmi, JNIEnv *env);
+jint AVIOContext_OnLoad(JavaVM *vmi, JNIEnv *env);
+jint AVMisc_OnLoad(JavaVM *vmi, JNIEnv *env);
+jint AVPacket_OnLoad(JavaVM *vmi, JNIEnv *env);
+jint AVStream_OnLoad(JavaVM *vmi, JNIEnv *env);
+
+jint AVUtil_OnLoad(JavaVM *vmi, JNIEnv *env);
+
+/* temporary */
+int jj_ResolveFunctions(JNIEnv *env, const char *fn_names, void *fnp);
+int jj_ResolveLibraries(JNIEnv *env, NZLibTable *table);
+int jj_ResolveReferences(JNIEnv *env, const char *jn_names, void *jnp);
+#undef DLCALL
+#define DLCALL(x) (fn.x)
+#undef DLCHECK_RET
+#define DLCHECK_RET(env, x, ret) do { if (!nativez_NonNull(env, #x, (void *)fn.x)) { return ret; } } while (0)
+
+#endif
--- /dev/null
+#
+# Copyright (C) 2017,2019 Michael Zucchi
+#
+# This file is part of jjmpeg <https://www.zedzone.space/software/jjmpeg.html>
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program 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 General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+#
+
+notzed.jjmpeg_JNI_LIBRARIES = jjmpeg
+
+jjmpeg_SOURCES = \
+ jjmpeg-jni.c \
+ jj-avcodec.c \
+ jj-avcodeccontext.c \
+ jj-avcodecparameters.c \
+ jj-avdevice.c \
+ jj-avformatcontext.c \
+ jj-avframe.c \
+ jj-aviocontext.c \
+ jj-avmisc.c \
+ jj-avoptions.c \
+ jj-avpacket.c \
+ jj-avstream.c \
+ jj-avutil.c
+
+linux-amd64_jjmpeg_LDFLAGS = -ldl
+
+jjmpeg_LDLIBS=-L$(NATIVEZ_HOME)/lib -lnativez $($(TARGET)_jjmpeg_LDFLAGS)
+jjmpeg_CPPFLAGS=-I$(FFMPEG_HOME)/include -I$(NATIVEZ_HOME)/include -I$(notzed.jjmpeg_jnidir)
+jjmpeg_CFLAGS=-Wall -Wmissing-prototypes -Wno-pointer-sign
+
+jjmpeg_DEFS = \
+ jjmpeg-jni.def \
+ jj-avcodeccontext.def \
+ jj-avcodec.def \
+ jj-avcodecparameters.def \
+ jj-avdevice.def \
+ jj-avformatcontext.def \
+ jj-avframe.def \
+ jj-aviocontext.def \
+ jj-avmisc.def \
+ jj-avoptions.def \
+ jj-avpacket.def \
+ jj-avstream.def \
+ jj-avutil.def
+
+jjmpeg_makedep=$(notzed.jjmpeg_objdir)/$(1).o: $(notzed.jjmpeg_jnidir)/$(1).h
+
+$(foreach def,$(jjmpeg_DEFS),$(eval $(call jjmpeg_makedep,$(def:.def=))))
+
+$(notzed.jjmpeg_jnidir)/%.h: src/notzed.jjmpeg/jni/%.def
+ @install -d $(@D)
+ src/notzed.jjmpeg/jni/extract-proto.pl -f "$(FFMPEG_HOME)" $< > $@ || ( rm $@ ; exit 1)
--- /dev/null
+ GNU GENERAL PUBLIC LICENSE
+ Version 3, 29 June 2007
+
+ Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
+ Everyone is permitted to copy and distribute verbatim copies
+ of this license document, but changing it is not allowed.
+
+ Preamble
+
+ The GNU General Public License is a free, copyleft license for
+software and other kinds of works.
+
+ The licenses for most software and other practical works are designed
+to take away your freedom to share and change the works. By contrast,
+the GNU General Public License is intended to guarantee your freedom to
+share and change all versions of a program--to make sure it remains free
+software for all its users. We, the Free Software Foundation, use the
+GNU General Public License for most of our software; it applies also to
+any other work released this way by its authors. You can apply it to
+your programs, too.
+
+ When we speak of free software, we are referring to freedom, not
+price. Our General Public Licenses are designed to make sure that you
+have the freedom to distribute copies of free software (and charge for
+them if you wish), that you receive source code or can get it if you
+want it, that you can change the software or use pieces of it in new
+free programs, and that you know you can do these things.
+
+ To protect your rights, we need to prevent others from denying you
+these rights or asking you to surrender the rights. Therefore, you have
+certain responsibilities if you distribute copies of the software, or if
+you modify it: responsibilities to respect the freedom of others.
+
+ For example, if you distribute copies of such a program, whether
+gratis or for a fee, you must pass on to the recipients the same
+freedoms that you received. You must make sure that they, too, receive
+or can get the source code. And you must show them these terms so they
+know their rights.
+
+ Developers that use the GNU GPL protect your rights with two steps:
+(1) assert copyright on the software, and (2) offer you this License
+giving you legal permission to copy, distribute and/or modify it.
+
+ For the developers' and authors' protection, the GPL clearly explains
+that there is no warranty for this free software. For both users' and
+authors' sake, the GPL requires that modified versions be marked as
+changed, so that their problems will not be attributed erroneously to
+authors of previous versions.
+
+ Some devices are designed to deny users access to install or run
+modified versions of the software inside them, although the manufacturer
+can do so. This is fundamentally incompatible with the aim of
+protecting users' freedom to change the software. The systematic
+pattern of such abuse occurs in the area of products for individuals to
+use, which is precisely where it is most unacceptable. Therefore, we
+have designed this version of the GPL to prohibit the practice for those
+products. If such problems arise substantially in other domains, we
+stand ready to extend this provision to those domains in future versions
+of the GPL, as needed to protect the freedom of users.
+
+ Finally, every program is threatened constantly by software patents.
+States should not allow patents to restrict development and use of
+software on general-purpose computers, but in those that do, we wish to
+avoid the special danger that patents applied to a free program could
+make it effectively proprietary. To prevent this, the GPL assures that
+patents cannot be used to render the program non-free.
+
+ The precise terms and conditions for copying, distribution and
+modification follow.
+
+ TERMS AND CONDITIONS
+
+ 0. Definitions.
+
+ "This License" refers to version 3 of the GNU General Public License.
+
+ "Copyright" also means copyright-like laws that apply to other kinds of
+works, such as semiconductor masks.
+
+ "The Program" refers to any copyrightable work licensed under this
+License. Each licensee is addressed as "you". "Licensees" and
+"recipients" may be individuals or organizations.
+
+ To "modify" a work means to copy from or adapt all or part of the work
+in a fashion requiring copyright permission, other than the making of an
+exact copy. The resulting work is called a "modified version" of the
+earlier work or a work "based on" the earlier work.
+
+ A "covered work" means either the unmodified Program or a work based
+on the Program.
+
+ To "propagate" a work means to do anything with it that, without
+permission, would make you directly or secondarily liable for
+infringement under applicable copyright law, except executing it on a
+computer or modifying a private copy. Propagation includes copying,
+distribution (with or without modification), making available to the
+public, and in some countries other activities as well.
+
+ To "convey" a work means any kind of propagation that enables other
+parties to make or receive copies. Mere interaction with a user through
+a computer network, with no transfer of a copy, is not conveying.
+
+ An interactive user interface displays "Appropriate Legal Notices"
+to the extent that it includes a convenient and prominently visible
+feature that (1) displays an appropriate copyright notice, and (2)
+tells the user that there is no warranty for the work (except to the
+extent that warranties are provided), that licensees may convey the
+work under this License, and how to view a copy of this License. If
+the interface presents a list of user commands or options, such as a
+menu, a prominent item in the list meets this criterion.
+
+ 1. Source Code.
+
+ The "source code" for a work means the preferred form of the work
+for making modifications to it. "Object code" means any non-source
+form of a work.
+
+ A "Standard Interface" means an interface that either is an official
+standard defined by a recognized standards body, or, in the case of
+interfaces specified for a particular programming language, one that
+is widely used among developers working in that language.
+
+ The "System Libraries" of an executable work include anything, other
+than the work as a whole, that (a) is included in the normal form of
+packaging a Major Component, but which is not part of that Major
+Component, and (b) serves only to enable use of the work with that
+Major Component, or to implement a Standard Interface for which an
+implementation is available to the public in source code form. A
+"Major Component", in this context, means a major essential component
+(kernel, window system, and so on) of the specific operating system
+(if any) on which the executable work runs, or a compiler used to
+produce the work, or an object code interpreter used to run it.
+
+ The "Corresponding Source" for a work in object code form means all
+the source code needed to generate, install, and (for an executable
+work) run the object code and to modify the work, including scripts to
+control those activities. However, it does not include the work's
+System Libraries, or general-purpose tools or generally available free
+programs which are used unmodified in performing those activities but
+which are not part of the work. For example, Corresponding Source
+includes interface definition files associated with source files for
+the work, and the source code for shared libraries and dynamically
+linked subprograms that the work is specifically designed to require,
+such as by intimate data communication or control flow between those
+subprograms and other parts of the work.
+
+ The Corresponding Source need not include anything that users
+can regenerate automatically from other parts of the Corresponding
+Source.
+
+ The Corresponding Source for a work in source code form is that
+same work.
+
+ 2. Basic Permissions.
+
+ All rights granted under this License are granted for the term of
+copyright on the Program, and are irrevocable provided the stated
+conditions are met. This License explicitly affirms your unlimited
+permission to run the unmodified Program. The output from running a
+covered work is covered by this License only if the output, given its
+content, constitutes a covered work. This License acknowledges your
+rights of fair use or other equivalent, as provided by copyright law.
+
+ You may make, run and propagate covered works that you do not
+convey, without conditions so long as your license otherwise remains
+in force. You may convey covered works to others for the sole purpose
+of having them make modifications exclusively for you, or provide you
+with facilities for running those works, provided that you comply with
+the terms of this License in conveying all material for which you do
+not control copyright. Those thus making or running the covered works
+for you must do so exclusively on your behalf, under your direction
+and control, on terms that prohibit them from making any copies of
+your copyrighted material outside their relationship with you.
+
+ Conveying under any other circumstances is permitted solely under
+the conditions stated below. Sublicensing is not allowed; section 10
+makes it unnecessary.
+
+ 3. Protecting Users' Legal Rights From Anti-Circumvention Law.
+
+ No covered work shall be deemed part of an effective technological
+measure under any applicable law fulfilling obligations under article
+11 of the WIPO copyright treaty adopted on 20 December 1996, or
+similar laws prohibiting or restricting circumvention of such
+measures.
+
+ When you convey a covered work, you waive any legal power to forbid
+circumvention of technological measures to the extent such circumvention
+is effected by exercising rights under this License with respect to
+the covered work, and you disclaim any intention to limit operation or
+modification of the work as a means of enforcing, against the work's
+users, your or third parties' legal rights to forbid circumvention of
+technological measures.
+
+ 4. Conveying Verbatim Copies.
+
+ You may convey verbatim copies of the Program's source code as you
+receive it, in any medium, provided that you conspicuously and
+appropriately publish on each copy an appropriate copyright notice;
+keep intact all notices stating that this License and any
+non-permissive terms added in accord with section 7 apply to the code;
+keep intact all notices of the absence of any warranty; and give all
+recipients a copy of this License along with the Program.
+
+ You may charge any price or no price for each copy that you convey,
+and you may offer support or warranty protection for a fee.
+
+ 5. Conveying Modified Source Versions.
+
+ You may convey a work based on the Program, or the modifications to
+produce it from the Program, in the form of source code under the
+terms of section 4, provided that you also meet all of these conditions:
+
+ a) The work must carry prominent notices stating that you modified
+ it, and giving a relevant date.
+
+ b) The work must carry prominent notices stating that it is
+ released under this License and any conditions added under section
+ 7. This requirement modifies the requirement in section 4 to
+ "keep intact all notices".
+
+ c) You must license the entire work, as a whole, under this
+ License to anyone who comes into possession of a copy. This
+ License will therefore apply, along with any applicable section 7
+ additional terms, to the whole of the work, and all its parts,
+ regardless of how they are packaged. This License gives no
+ permission to license the work in any other way, but it does not
+ invalidate such permission if you have separately received it.
+
+ d) If the work has interactive user interfaces, each must display
+ Appropriate Legal Notices; however, if the Program has interactive
+ interfaces that do not display Appropriate Legal Notices, your
+ work need not make them do so.
+
+ A compilation of a covered work with other separate and independent
+works, which are not by their nature extensions of the covered work,
+and which are not combined with it such as to form a larger program,
+in or on a volume of a storage or distribution medium, is called an
+"aggregate" if the compilation and its resulting copyright are not
+used to limit the access or legal rights of the compilation's users
+beyond what the individual works permit. Inclusion of a covered work
+in an aggregate does not cause this License to apply to the other
+parts of the aggregate.
+
+ 6. Conveying Non-Source Forms.
+
+ You may convey a covered work in object code form under the terms
+of sections 4 and 5, provided that you also convey the
+machine-readable Corresponding Source under the terms of this License,
+in one of these ways:
+
+ a) Convey the object code in, or embodied in, a physical product
+ (including a physical distribution medium), accompanied by the
+ Corresponding Source fixed on a durable physical medium
+ customarily used for software interchange.
+
+ b) Convey the object code in, or embodied in, a physical product
+ (including a physical distribution medium), accompanied by a
+ written offer, valid for at least three years and valid for as
+ long as you offer spare parts or customer support for that product
+ model, to give anyone who possesses the object code either (1) a
+ copy of the Corresponding Source for all the software in the
+ product that is covered by this License, on a durable physical
+ medium customarily used for software interchange, for a price no
+ more than your reasonable cost of physically performing this
+ conveying of source, or (2) access to copy the
+ Corresponding Source from a network server at no charge.
+
+ c) Convey individual copies of the object code with a copy of the
+ written offer to provide the Corresponding Source. This
+ alternative is allowed only occasionally and noncommercially, and
+ only if you received the object code with such an offer, in accord
+ with subsection 6b.
+
+ d) Convey the object code by offering access from a designated
+ place (gratis or for a charge), and offer equivalent access to the
+ Corresponding Source in the same way through the same place at no
+ further charge. You need not require recipients to copy the
+ Corresponding Source along with the object code. If the place to
+ copy the object code is a network server, the Corresponding Source
+ may be on a different server (operated by you or a third party)
+ that supports equivalent copying facilities, provided you maintain
+ clear directions next to the object code saying where to find the
+ Corresponding Source. Regardless of what server hosts the
+ Corresponding Source, you remain obligated to ensure that it is
+ available for as long as needed to satisfy these requirements.
+
+ e) Convey the object code using peer-to-peer transmission, provided
+ you inform other peers where the object code and Corresponding
+ Source of the work are being offered to the general public at no
+ charge under subsection 6d.
+
+ A separable portion of the object code, whose source code is excluded
+from the Corresponding Source as a System Library, need not be
+included in conveying the object code work.
+
+ A "User Product" is either (1) a "consumer product", which means any
+tangible personal property which is normally used for personal, family,
+or household purposes, or (2) anything designed or sold for incorporation
+into a dwelling. In determining whether a product is a consumer product,
+doubtful cases shall be resolved in favor of coverage. For a particular
+product received by a particular user, "normally used" refers to a
+typical or common use of that class of product, regardless of the status
+of the particular user or of the way in which the particular user
+actually uses, or expects or is expected to use, the product. A product
+is a consumer product regardless of whether the product has substantial
+commercial, industrial or non-consumer uses, unless such uses represent
+the only significant mode of use of the product.
+
+ "Installation Information" for a User Product means any methods,
+procedures, authorization keys, or other information required to install
+and execute modified versions of a covered work in that User Product from
+a modified version of its Corresponding Source. The information must
+suffice to ensure that the continued functioning of the modified object
+code is in no case prevented or interfered with solely because
+modification has been made.
+
+ If you convey an object code work under this section in, or with, or
+specifically for use in, a User Product, and the conveying occurs as
+part of a transaction in which the right of possession and use of the
+User Product is transferred to the recipient in perpetuity or for a
+fixed term (regardless of how the transaction is characterized), the
+Corresponding Source conveyed under this section must be accompanied
+by the Installation Information. But this requirement does not apply
+if neither you nor any third party retains the ability to install
+modified object code on the User Product (for example, the work has
+been installed in ROM).
+
+ The requirement to provide Installation Information does not include a
+requirement to continue to provide support service, warranty, or updates
+for a work that has been modified or installed by the recipient, or for
+the User Product in which it has been modified or installed. Access to a
+network may be denied when the modification itself materially and
+adversely affects the operation of the network or violates the rules and
+protocols for communication across the network.
+
+ Corresponding Source conveyed, and Installation Information provided,
+in accord with this section must be in a format that is publicly
+documented (and with an implementation available to the public in
+source code form), and must require no special password or key for
+unpacking, reading or copying.
+
+ 7. Additional Terms.
+
+ "Additional permissions" are terms that supplement the terms of this
+License by making exceptions from one or more of its conditions.
+Additional permissions that are applicable to the entire Program shall
+be treated as though they were included in this License, to the extent
+that they are valid under applicable law. If additional permissions
+apply only to part of the Program, that part may be used separately
+under those permissions, but the entire Program remains governed by
+this License without regard to the additional permissions.
+
+ When you convey a copy of a covered work, you may at your option
+remove any additional permissions from that copy, or from any part of
+it. (Additional permissions may be written to require their own
+removal in certain cases when you modify the work.) You may place
+additional permissions on material, added by you to a covered work,
+for which you have or can give appropriate copyright permission.
+
+ Notwithstanding any other provision of this License, for material you
+add to a covered work, you may (if authorized by the copyright holders of
+that material) supplement the terms of this License with terms:
+
+ a) Disclaiming warranty or limiting liability differently from the
+ terms of sections 15 and 16 of this License; or
+
+ b) Requiring preservation of specified reasonable legal notices or
+ author attributions in that material or in the Appropriate Legal
+ Notices displayed by works containing it; or
+
+ c) Prohibiting misrepresentation of the origin of that material, or
+ requiring that modified versions of such material be marked in
+ reasonable ways as different from the original version; or
+
+ d) Limiting the use for publicity purposes of names of licensors or
+ authors of the material; or
+
+ e) Declining to grant rights under trademark law for use of some
+ trade names, trademarks, or service marks; or
+
+ f) Requiring indemnification of licensors and authors of that
+ material by anyone who conveys the material (or modified versions of
+ it) with contractual assumptions of liability to the recipient, for
+ any liability that these contractual assumptions directly impose on
+ those licensors and authors.
+
+ All other non-permissive additional terms are considered "further
+restrictions" within the meaning of section 10. If the Program as you
+received it, or any part of it, contains a notice stating that it is
+governed by this License along with a term that is a further
+restriction, you may remove that term. If a license document contains
+a further restriction but permits relicensing or conveying under this
+License, you may add to a covered work material governed by the terms
+of that license document, provided that the further restriction does
+not survive such relicensing or conveying.
+
+ If you add terms to a covered work in accord with this section, you
+must place, in the relevant source files, a statement of the
+additional terms that apply to those files, or a notice indicating
+where to find the applicable terms.
+
+ Additional terms, permissive or non-permissive, may be stated in the
+form of a separately written license, or stated as exceptions;
+the above requirements apply either way.
+
+ 8. Termination.
+
+ You may not propagate or modify a covered work except as expressly
+provided under this License. Any attempt otherwise to propagate or
+modify it is void, and will automatically terminate your rights under
+this License (including any patent licenses granted under the third
+paragraph of section 11).
+
+ However, if you cease all violation of this License, then your
+license from a particular copyright holder is reinstated (a)
+provisionally, unless and until the copyright holder explicitly and
+finally terminates your license, and (b) permanently, if the copyright
+holder fails to notify you of the violation by some reasonable means
+prior to 60 days after the cessation.
+
+ Moreover, your license from a particular copyright holder is
+reinstated permanently if the copyright holder notifies you of the
+violation by some reasonable means, this is the first time you have
+received notice of violation of this License (for any work) from that
+copyright holder, and you cure the violation prior to 30 days after
+your receipt of the notice.
+
+ Termination of your rights under this section does not terminate the
+licenses of parties who have received copies or rights from you under
+this License. If your rights have been terminated and not permanently
+reinstated, you do not qualify to receive new licenses for the same
+material under section 10.
+
+ 9. Acceptance Not Required for Having Copies.
+
+ You are not required to accept this License in order to receive or
+run a copy of the Program. Ancillary propagation of a covered work
+occurring solely as a consequence of using peer-to-peer transmission
+to receive a copy likewise does not require acceptance. However,
+nothing other than this License grants you permission to propagate or
+modify any covered work. These actions infringe copyright if you do
+not accept this License. Therefore, by modifying or propagating a
+covered work, you indicate your acceptance of this License to do so.
+
+ 10. Automatic Licensing of Downstream Recipients.
+
+ Each time you convey a covered work, the recipient automatically
+receives a license from the original licensors, to run, modify and
+propagate that work, subject to this License. You are not responsible
+for enforcing compliance by third parties with this License.
+
+ An "entity transaction" is a transaction transferring control of an
+organization, or substantially all assets of one, or subdividing an
+organization, or merging organizations. If propagation of a covered
+work results from an entity transaction, each party to that
+transaction who receives a copy of the work also receives whatever
+licenses to the work the party's predecessor in interest had or could
+give under the previous paragraph, plus a right to possession of the
+Corresponding Source of the work from the predecessor in interest, if
+the predecessor has it or can get it with reasonable efforts.
+
+ You may not impose any further restrictions on the exercise of the
+rights granted or affirmed under this License. For example, you may
+not impose a license fee, royalty, or other charge for exercise of
+rights granted under this License, and you may not initiate litigation
+(including a cross-claim or counterclaim in a lawsuit) alleging that
+any patent claim is infringed by making, using, selling, offering for
+sale, or importing the Program or any portion of it.
+
+ 11. Patents.
+
+ A "contributor" is a copyright holder who authorizes use under this
+License of the Program or a work on which the Program is based. The
+work thus licensed is called the contributor's "contributor version".
+
+ A contributor's "essential patent claims" are all patent claims
+owned or controlled by the contributor, whether already acquired or
+hereafter acquired, that would be infringed by some manner, permitted
+by this License, of making, using, or selling its contributor version,
+but do not include claims that would be infringed only as a
+consequence of further modification of the contributor version. For
+purposes of this definition, "control" includes the right to grant
+patent sublicenses in a manner consistent with the requirements of
+this License.
+
+ Each contributor grants you a non-exclusive, worldwide, royalty-free
+patent license under the contributor's essential patent claims, to
+make, use, sell, offer for sale, import and otherwise run, modify and
+propagate the contents of its contributor version.
+
+ In the following three paragraphs, a "patent license" is any express
+agreement or commitment, however denominated, not to enforce a patent
+(such as an express permission to practice a patent or covenant not to
+sue for patent infringement). To "grant" such a patent license to a
+party means to make such an agreement or commitment not to enforce a
+patent against the party.
+
+ If you convey a covered work, knowingly relying on a patent license,
+and the Corresponding Source of the work is not available for anyone
+to copy, free of charge and under the terms of this License, through a
+publicly available network server or other readily accessible means,
+then you must either (1) cause the Corresponding Source to be so
+available, or (2) arrange to deprive yourself of the benefit of the
+patent license for this particular work, or (3) arrange, in a manner
+consistent with the requirements of this License, to extend the patent
+license to downstream recipients. "Knowingly relying" means you have
+actual knowledge that, but for the patent license, your conveying the
+covered work in a country, or your recipient's use of the covered work
+in a country, would infringe one or more identifiable patents in that
+country that you have reason to believe are valid.
+
+ If, pursuant to or in connection with a single transaction or
+arrangement, you convey, or propagate by procuring conveyance of, a
+covered work, and grant a patent license to some of the parties
+receiving the covered work authorizing them to use, propagate, modify
+or convey a specific copy of the covered work, then the patent license
+you grant is automatically extended to all recipients of the covered
+work and works based on it.
+
+ A patent license is "discriminatory" if it does not include within
+the scope of its coverage, prohibits the exercise of, or is
+conditioned on the non-exercise of one or more of the rights that are
+specifically granted under this License. You may not convey a covered
+work if you are a party to an arrangement with a third party that is
+in the business of distributing software, under which you make payment
+to the third party based on the extent of your activity of conveying
+the work, and under which the third party grants, to any of the
+parties who would receive the covered work from you, a discriminatory
+patent license (a) in connection with copies of the covered work
+conveyed by you (or copies made from those copies), or (b) primarily
+for and in connection with specific products or compilations that
+contain the covered work, unless you entered into that arrangement,
+or that patent license was granted, prior to 28 March 2007.
+
+ Nothing in this License shall be construed as excluding or limiting
+any implied license or other defenses to infringement that may
+otherwise be available to you under applicable patent law.
+
+ 12. No Surrender of Others' Freedom.
+
+ If conditions are imposed on you (whether by court order, agreement or
+otherwise) that contradict the conditions of this License, they do not
+excuse you from the conditions of this License. If you cannot convey a
+covered work so as to satisfy simultaneously your obligations under this
+License and any other pertinent obligations, then as a consequence you may
+not convey it at all. For example, if you agree to terms that obligate you
+to collect a royalty for further conveying from those to whom you convey
+the Program, the only way you could satisfy both those terms and this
+License would be to refrain entirely from conveying the Program.
+
+ 13. Use with the GNU Affero General Public License.
+
+ Notwithstanding any other provision of this License, you have
+permission to link or combine any covered work with a work licensed
+under version 3 of the GNU Affero General Public License into a single
+combined work, and to convey the resulting work. The terms of this
+License will continue to apply to the part which is the covered work,
+but the special requirements of the GNU Affero General Public License,
+section 13, concerning interaction through a network will apply to the
+combination as such.
+
+ 14. Revised Versions of this License.
+
+ The Free Software Foundation may publish revised and/or new versions of
+the GNU General Public License from time to time. Such new versions will
+be similar in spirit to the present version, but may differ in detail to
+address new problems or concerns.
+
+ Each version is given a distinguishing version number. If the
+Program specifies that a certain numbered version of the GNU General
+Public License "or any later version" applies to it, you have the
+option of following the terms and conditions either of that numbered
+version or of any later version published by the Free Software
+Foundation. If the Program does not specify a version number of the
+GNU General Public License, you may choose any version ever published
+by the Free Software Foundation.
+
+ If the Program specifies that a proxy can decide which future
+versions of the GNU General Public License can be used, that proxy's
+public statement of acceptance of a version permanently authorizes you
+to choose that version for the Program.
+
+ Later license versions may give you additional or different
+permissions. However, no additional obligations are imposed on any
+author or copyright holder as a result of your choosing to follow a
+later version.
+
+ 15. Disclaimer of Warranty.
+
+ THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
+APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
+HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
+OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
+THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
+IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
+ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
+
+ 16. Limitation of Liability.
+
+ IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
+WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
+THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
+GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
+USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
+DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
+PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
+EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
+SUCH DAMAGES.
+
+ 17. Interpretation of Sections 15 and 16.
+
+ If the disclaimer of warranty and limitation of liability provided
+above cannot be given local legal effect according to their terms,
+reviewing courts shall apply local law that most closely approximates
+an absolute waiver of all civil liability in connection with the
+Program, unless a warranty or assumption of liability accompanies a
+copy of the Program in return for a fee.
+
+ END OF TERMS AND CONDITIONS
+
+ How to Apply These Terms to Your New Programs
+
+ If you develop a new program, and you want it to be of the greatest
+possible use to the public, the best way to achieve this is to make it
+free software which everyone can redistribute and change under these terms.
+
+ To do so, attach the following notices to the program. It is safest
+to attach them to the start of each source file to most effectively
+state the exclusion of warranty; and each file should have at least
+the "copyright" line and a pointer to where the full notice is found.
+
+ <one line to give the program's name and a brief idea of what it does.>
+ Copyright (C) <year> <name of author>
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program 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 General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+Also add information on how to contact you by electronic and paper mail.
+
+ If the program does terminal interaction, make it output a short
+notice like this when it starts in an interactive mode:
+
+ <program> Copyright (C) <year> <name of author>
+ This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
+ This is free software, and you are welcome to redistribute it
+ under certain conditions; type `show c' for details.
+
+The hypothetical commands `show w' and `show c' should show the appropriate
+parts of the General Public License. Of course, your program's commands
+might be different; for a GUI interface, you would use an "about box".
+
+ You should also get your employer (if you work as a programmer) or school,
+if any, to sign a "copyright disclaimer" for the program, if necessary.
+For more information on this, and how to apply and follow the GNU GPL, see
+<http://www.gnu.org/licenses/>.
+
+ The GNU General Public License does not permit incorporating your program
+into proprietary programs. If your program is a subroutine library, you
+may consider it more useful to permit linking proprietary applications with
+the library. If this is what you want to do, use the GNU Lesser General
+Public License instead of this License. But first, please read
+<http://www.gnu.org/philosophy/why-not-lgpl.html>.