de.humatic.dsj
Class DSJUtils

java.lang.Object
  extended by de.humatic.dsj.DSJUtils

public class DSJUtils
extends java.lang.Object

Helper methods, data plotting utilities etc.


Constructor Summary
DSJUtils()
           
 
Method Summary
static byte[] base64decode(byte[] source)
          Base64 decode utility, based on public domain Base64 library http://iharder.sourceforge.net/current/java/base64/
static byte[] base64encode(byte[] source)
          Base64 encode utility, based on public domain Base64 library http://iharder.sourceforge.net/current/java/base64/
static byte[] base64encode(byte[] source, int from, int to)
           
static byte[] byteArrayFromHexString(java.lang.String hex)
           
static java.lang.String byteArrayToHexString(byte[] data)
           
static void centerFrame(java.awt.Frame f, java.awt.GraphicsDevice gd)
           
static java.lang.String decHex(byte b)
          Data logging utility, returns a String containing the decimal value followed by a two character hex string representation of the given byte.
static java.lang.String decHex(int i)
          Data logging utility, returns a String containing the decimal value followed by a two character hex string representation of the given int's lowest byte.
static void dump(byte[] data)
          Data logging utility, all variations of dump(...) print a byte array or parts of it in standard hex dump format to System.err or what has been set as the log stream via DSEnvironment.setLogStream(...).
static void dump(byte[] data, int from, int upTo)
           
static void dump(int level, byte[] data)
           
static void dump(int level, byte[] data, int from, int upTo)
           
static void dump(int level, java.lang.String prefix, byte[] data)
           
static void dump(int level, java.lang.String prefix, byte[] data, int from, int upTo)
           
static void dump(java.lang.String prefix, byte[] data)
           
static void dump(java.lang.String prefix, byte[] data, int from, int upTo)
           
static int endianFlip16(int in)
           
static int endianFlip32(int in)
           
static long endianFlip64(long in)
           
static int findBytes(byte[] data, int start, int maxIdx, byte[] compare, int num)
           
static int findFCC_BE(byte[] data, java.lang.String fourCC)
           
static int findFCC(byte[] data, int startPos, java.lang.String fourCC, boolean bigEndian)
          Returns the index at which the 4 bytes making up the int representation of the four char code argument appear in the given array, with the search starting at %startPos.
static int findFCC(byte[] data, java.lang.String fourCC)
          Returns the index at which the 4 bytes making up the int representation of the four char code argument appear in the given array or -1 if not found.
static int findInt(byte[] data, int lookup)
          Returns the index at which the 4 bytes making up %lookup appear in the given array or -1 if not found.
static float fromFix(int i)
           
static int[] getBasicFileStats(java.lang.String filePath)
          Returns an int[10] holding basic information on a media file:
0 - duration in msec,
1 - reserved,
2 - video width,
3 - video height,
4 - video fps*100,
5 - video FourCC or biCompression member of the BitmapInfoHeader
6 - audio samplerate,
7 - audio bitwidth,
8 - audio channels,
9 - audio wFormatTag
static int getBits_LE(byte[] data, int startBit, int numBits)
          Reads up to %numBits bits starting at %startBit from the given byte array into an little endian int.
static int getBits(byte[] data, int startBit, int numBits)
          Reads up to %numBits bits starting at %startBit from the given byte array into an big endian int.
static long getBits64_LE(byte[] data, int startBit, int numBits)
          Reads up to %numBits bits starting at %startBit from the given byte array into an little endian long.
static long getBits64(byte[] data, int startBit, int numBits)
          Reads up to %numBits bits starting at %startBit from the given byte array into an big endian long.
static int getEventType(java.beans.PropertyChangeEvent event)
          Returns the DSFiltergraph event type of a PropertyChangeEvent sent to listeners.
static int getEventValue_int(java.beans.PropertyChangeEvent event)
          Returns the DSFiltergraph event (int) value of a PropertyChangeEvent sent to listeners.
static int getExpGolombLength(byte[] data, int pos)
          Returns the total bitlength of the expGolomb coded field at bitposition %pos.
static int[] getExtendedFileStats(java.lang.String filePath)
          Returns an int[34] holding extended information on a media file and its video and audio characteristics.
static java.awt.image.BufferedImage getMediaIcon(java.lang.String filePath, int time, int w, int h)
          Returns an icon image for the given time and in the specified dimension from the mediafile at %path.
static int getNextLineBreak(java.lang.String str, int from)
           
static boolean getScreenSaverActive()
           
static int getVIntLength(byte b)
           
static org.w3c.dom.Document grf2xgr(java.lang.String grfPath)
          Returns an xml representation of a filtergraph stored in a.grf file.
static java.lang.String hex(byte b)
          Data logging utility, returns a two character hex string representation of the given byte.
static java.lang.String hex(int i)
          Data logging utility, returns a hex string representation of the given int.
static byte[] hexStringToByteArray(java.lang.String hex)
           
static boolean isMulticast(java.lang.String ip)
          Returns true if the given IP4-Address, which should be in standard dot decimal form (exp.: 230.0.0.1) is a multicast address.
static boolean isUncompressedVideo(int subType)
           
static void log(int level, java.lang.String dbg)
          Writes %dbg to the active log stream if the current logging level is higher than %level.
static void log(java.lang.String dbg)
          Writes %dbg to the active log stream (see DSEnvironment.setLogStream(...)).
static void logDecHex(int indention, java.lang.String desc, int val)
          Data logging utility, writes a String containing the decimal value followed by a two character hex string representation of the given int's lowest byte to the active log stream.
static void logErr(java.lang.Exception e, java.lang.String addInfo)
           
static void logErr(int level, java.lang.Exception e, java.lang.String addInfo)
           
static void logln(int level, java.lang.String dbg)
          Writes %dbg + a linebreak to the active log stream if the current logging level is higher than %level.
static void logln(java.lang.String dbg)
          Writes %dbg + a linebreak to the active log stream.
static void loglnDecHex(int indention, java.lang.String desc, int val)
          Data logging utility, writes a String containing the decimal value followed by a two character hex string representation of the given int's lowest byte + a linebreak to the active log stream.
static boolean MPEGStart(byte[] data, int pos)
          Returns true if there's a 0 0 1 mpeg start code at %pos in the given byte[].
static boolean MPEGStart(byte[] data, int pos, int startCodeLength)
           
static java.lang.String msecToSMPTE(int msecTime, float fps, boolean drop)
           
static java.lang.String parseURL(java.lang.String url, int part, java.lang.String def)
          Parses URL strings into protocol, host and port and resource parts.
static void plotBytes(byte[] data, int from, int num)
           
static int[] readBCD(byte[] data, int pos, int num)
           
static double readDouble_LE(byte[] data, int pos)
          Reads 64 bits into a double from %data at position %start, little endian.
static double readDouble(byte[] data, int pos)
          Reads 64 bits into a double from %data at position %start.
static int[] readEBML_int(byte[] data, int pos)
          Reads a variable size coded int from position pos in data and returns an int[2] holding the read value and its coded length.
static int[] readEBML_sint(byte[] data, int pos)
           
static int readExpGolomb(byte[] data, int pos)
          Reads the expGolomb coded value at bitposition %pos from the given byte array.
static int readInt_LE(byte[] data, int start)
          Reads 32 little endian bits into a int from %data at position %start.
static int readInt_LE(byte[] data, int start, int numBytes)
          Reads %numBytes*8 little endian bits into a int from %data at position %start.
static int readInt(byte[] data, int start)
          Reads 32 big endian bits into a int from %data at position %start.
static int readInt(byte[] data, int start, int numBytes)
          Reads %numBytes*8 big endian bits into a int from %data at position %start.
static long readLong_LE(byte[] data, int start)
          Reads 64 little endian bits into a long from %data at position %start.
static long readLong_LE(byte[] data, int start, int numBytes)
          Reads %numBytes*8 little endian bits into a long from %data at position %start.
static long readLong(byte[] data, int start)
          Reads 64 bits big endian into a long from %data at position %start.
static long readLong(byte[] data, int start, int numBytes)
          Reads %numBytes*8 big endian bits into a long from %data at position %start.
static short readShort_LE(byte[] data, int start)
          Reads a short from %data at position %start, lttle endian.
static short readShort(byte[] data, int start)
          Reads a short from %data at position %start.
static void setBase64EncoderLineBreak(java.lang.String lb)
          Change Base64Encoder's linebreak sequence.
static void setBase64EncoderLineLength(int ll)
          Change number of characters after which the Base64Encoder will insert the set linbreak sequence.
static void setScreenSaverActive(boolean active)
           
static void showFilterList(DSFiltergraph dsfg)
           
static int subTypeFromFCC(java.lang.String fcc)
          Converts a four char code (like 'mp4v') to its packed 32 bit representation.
static int subTypeFromFCC(java.lang.String fcc, boolean bigEndian)
           
static int subTypeFromMIME(java.lang.String MIME)
           
static java.lang.String toFCC_BE(int packedFCC)
           
static java.lang.String toFCC(int packedFCC)
          Returns the four char code represented by %packedFCC as a String.
static int toFix(float f)
           
static java.lang.String urlDecode(java.lang.String encoded)
           
static void writeDouble(double value, byte[] data, int pos)
           
static int writeEBML_uint(int val, byte[] data, int pos)
           
static int writeEBML_vint(long val, byte[] data, int pos)
          Writes a variable length (1 - 8 bytes) ebml value at %pos and returns the number of bytes taken.
static void writeFloat(float value, byte[] data, int pos)
           
static void writeInt_LE(int value, byte[] data, int pos)
           
static void writeInt(int value, byte[] data, int pos)
           
static void writeLong_LE(long value, byte[] data, int pos)
           
static void writeLong(long value, byte[] data, int pos)
           
static void writeShort_LE(short value, byte[] data, int pos)
           
static void writeShort(short value, byte[] data, int pos)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DSJUtils

public DSJUtils()
Method Detail

isUncompressedVideo

public static boolean isUncompressedVideo(int subType)

getBasicFileStats

public static int[] getBasicFileStats(java.lang.String filePath)
Returns an int[10] holding basic information on a media file:
0 - duration in msec,
1 - reserved,
2 - video width,
3 - video height,
4 - video fps*100,
5 - video FourCC or biCompression member of the BitmapInfoHeader
6 - audio samplerate,
7 - audio bitwidth,
8 - audio channels,
9 - audio wFormatTag


getExtendedFileStats

public static int[] getExtendedFileStats(java.lang.String filePath)
Returns an int[34] holding extended information on a media file and its video and audio characteristics. Most of the additional fields (when compared to getBasicFileStats(..)) will only carry information when native media types use the extended VideoInfo2, MPEG2VideoInfo or WAVEFORMATEXTENSIBLE format types (and the fields have been set in those)

0 - duration in msec,
1 - basic streamtype (DSMediaType.SST_.., if known),

2 - video width,
3 - video height,
4 - video fps*100,
5 - video FourCC or biCompression member of the BitmapInfoHeader
6 - video bit depth
7 - video bitrate
8 - video biterror rate
9 - video interlace flags
10 - video copy protection flags
11 - video aspect ratio X
12 - video aspect ratio Y
13 - video control flags
14 - video profile
15 - video level
16 - video flags
17 - reserved

18 - audio samplerate,
19 - audio bitwidth,
20 - audio channels,
21 - audio wFormatTag
22 - audio average bytes per second
23 - audio block align
24 - audio channel mask
25 - audio SubFormat GUID Data1
26 - audio samples per block
27 - audio valid bits per sample
28 - may carry a FourCC if format tag is WF_UNKNOWN (0)
29 - mpeg layer (MPEG1WAVEFORMAT only)
30 - mpeg bitrate (MPEG1WAVEFORMAT only)
31 - mpeg flags (MPEG1WAVEFORMAT only)
32, 33 reserved


getMediaIcon

public static java.awt.image.BufferedImage getMediaIcon(java.lang.String filePath,
                                                        int time,
                                                        int w,
                                                        int h)
                                                 throws DSJException
Returns an icon image for the given time and in the specified dimension from the mediafile at %path. Set either w or h to -1 to get an icon with the file's original aspect ratio.
Please note that this method does not include any file type filters, but will attempt to get an icon from any file you throw at it. While it is not going to crash over non video files, it will take time to determine, that it is not possible to get the desired image. Application code should possibly provide file type filtering according to its needs before invoking this method.
Note 2: You will only be able to get icons from files, that decoder filters are installed for. Some video formats may take significantly more time to grab thumbnails from than others.

Throws:
DSJException

getEventType

public static int getEventType(java.beans.PropertyChangeEvent event)
Returns the DSFiltergraph event type of a PropertyChangeEvent sent to listeners.


getEventValue_int

public static int getEventValue_int(java.beans.PropertyChangeEvent event)
Returns the DSFiltergraph event (int) value of a PropertyChangeEvent sent to listeners. Most events carry a single value, which this method will return. Additionally it may return the int in slot 0 of eventual int[] event values. Returns -1 on error.


hex

public static java.lang.String hex(byte b)
Data logging utility, returns a two character hex string representation of the given byte.


decHex

public static java.lang.String decHex(byte b)
Data logging utility, returns a String containing the decimal value followed by a two character hex string representation of the given byte.


hex

public static java.lang.String hex(int i)
Data logging utility, returns a hex string representation of the given int.


decHex

public static java.lang.String decHex(int i)
Data logging utility, returns a String containing the decimal value followed by a two character hex string representation of the given int's lowest byte.


loglnDecHex

public static void loglnDecHex(int indention,
                               java.lang.String desc,
                               int val)
Data logging utility, writes a String containing the decimal value followed by a two character hex string representation of the given int's lowest byte + a linebreak to the active log stream.


logDecHex

public static void logDecHex(int indention,
                             java.lang.String desc,
                             int val)
Data logging utility, writes a String containing the decimal value followed by a two character hex string representation of the given int's lowest byte to the active log stream.


dump

public static void dump(byte[] data)
Data logging utility, all variations of dump(...) print a byte array or parts of it in standard hex dump format to System.err or what has been set as the log stream via DSEnvironment.setLogStream(...).


dump

public static void dump(byte[] data,
                        int from,
                        int upTo)

dump

public static void dump(java.lang.String prefix,
                        byte[] data)

dump

public static void dump(java.lang.String prefix,
                        byte[] data,
                        int from,
                        int upTo)

dump

public static void dump(int level,
                        byte[] data)

dump

public static void dump(int level,
                        byte[] data,
                        int from,
                        int upTo)

dump

public static void dump(int level,
                        java.lang.String prefix,
                        byte[] data)

dump

public static void dump(int level,
                        java.lang.String prefix,
                        byte[] data,
                        int from,
                        int upTo)

getBits

public static int getBits(byte[] data,
                          int startBit,
                          int numBits)
Reads up to %numBits bits starting at %startBit from the given byte array into an big endian int.


getBits_LE

public static int getBits_LE(byte[] data,
                             int startBit,
                             int numBits)
Reads up to %numBits bits starting at %startBit from the given byte array into an little endian int.


getBits64

public static long getBits64(byte[] data,
                             int startBit,
                             int numBits)
Reads up to %numBits bits starting at %startBit from the given byte array into an big endian long.


getBits64_LE

public static long getBits64_LE(byte[] data,
                                int startBit,
                                int numBits)
Reads up to %numBits bits starting at %startBit from the given byte array into an little endian long.


readShort

public static short readShort(byte[] data,
                              int start)
Reads a short from %data at position %start.


readShort_LE

public static short readShort_LE(byte[] data,
                                 int start)
Reads a short from %data at position %start, lttle endian.


readInt

public static int readInt(byte[] data,
                          int start)
Reads 32 big endian bits into a int from %data at position %start.


readInt

public static int readInt(byte[] data,
                          int start,
                          int numBytes)
Reads %numBytes*8 big endian bits into a int from %data at position %start.


readInt_LE

public static int readInt_LE(byte[] data,
                             int start)
Reads 32 little endian bits into a int from %data at position %start.


readInt_LE

public static int readInt_LE(byte[] data,
                             int start,
                             int numBytes)
Reads %numBytes*8 little endian bits into a int from %data at position %start.


readLong

public static long readLong(byte[] data,
                            int start)
Reads 64 bits big endian into a long from %data at position %start.


readLong

public static long readLong(byte[] data,
                            int start,
                            int numBytes)
Reads %numBytes*8 big endian bits into a long from %data at position %start.


readLong_LE

public static long readLong_LE(byte[] data,
                               int start)
Reads 64 little endian bits into a long from %data at position %start.


readLong_LE

public static long readLong_LE(byte[] data,
                               int start,
                               int numBytes)
Reads %numBytes*8 little endian bits into a long from %data at position %start.


readDouble_LE

public static double readDouble_LE(byte[] data,
                                   int pos)
Reads 64 bits into a double from %data at position %start, little endian.


readDouble

public static double readDouble(byte[] data,
                                int pos)
Reads 64 bits into a double from %data at position %start.


getExpGolombLength

public static int getExpGolombLength(byte[] data,
                                     int pos)
Returns the total bitlength of the expGolomb coded field at bitposition %pos.


readExpGolomb

public static int readExpGolomb(byte[] data,
                                int pos)
Reads the expGolomb coded value at bitposition %pos from the given byte array.


readBCD

public static int[] readBCD(byte[] data,
                            int pos,
                            int num)

readEBML_int

public static int[] readEBML_int(byte[] data,
                                 int pos)
Reads a variable size coded int from position pos in data and returns an int[2] holding the read value and its coded length. If the ebml field is longer than 4 bytes, the upper bits of the read value will be in a third array slot.


readEBML_sint

public static int[] readEBML_sint(byte[] data,
                                  int pos)

getVIntLength

public static int getVIntLength(byte b)

findBytes

public static int findBytes(byte[] data,
                            int start,
                            int maxIdx,
                            byte[] compare,
                            int num)

findInt

public static int findInt(byte[] data,
                          int lookup)
Returns the index at which the 4 bytes making up %lookup appear in the given array or -1 if not found.


findFCC

public static int findFCC(byte[] data,
                          java.lang.String fourCC)
Returns the index at which the 4 bytes making up the int representation of the four char code argument appear in the given array or -1 if not found.


findFCC_BE

public static int findFCC_BE(byte[] data,
                             java.lang.String fourCC)

findFCC

public static int findFCC(byte[] data,
                          int startPos,
                          java.lang.String fourCC,
                          boolean bigEndian)
Returns the index at which the 4 bytes making up the int representation of the four char code argument appear in the given array, with the search starting at %startPos. Returns -1 if not found. The int value of the four char code can optionally be formed big endian.


writeShort

public static void writeShort(short value,
                              byte[] data,
                              int pos)

writeShort_LE

public static void writeShort_LE(short value,
                                 byte[] data,
                                 int pos)

writeInt

public static void writeInt(int value,
                            byte[] data,
                            int pos)

writeInt_LE

public static void writeInt_LE(int value,
                               byte[] data,
                               int pos)

writeLong

public static void writeLong(long value,
                             byte[] data,
                             int pos)

writeLong_LE

public static void writeLong_LE(long value,
                                byte[] data,
                                int pos)

writeFloat

public static void writeFloat(float value,
                              byte[] data,
                              int pos)

writeDouble

public static void writeDouble(double value,
                               byte[] data,
                               int pos)

writeEBML_vint

public static int writeEBML_vint(long val,
                                 byte[] data,
                                 int pos)
Writes a variable length (1 - 8 bytes) ebml value at %pos and returns the number of bytes taken.


writeEBML_uint

public static int writeEBML_uint(int val,
                                 byte[] data,
                                 int pos)

endianFlip16

public static int endianFlip16(int in)

endianFlip32

public static int endianFlip32(int in)

endianFlip64

public static long endianFlip64(long in)

subTypeFromFCC

public static int subTypeFromFCC(java.lang.String fcc)
Converts a four char code (like 'mp4v') to its packed 32 bit representation.


subTypeFromFCC

public static int subTypeFromFCC(java.lang.String fcc,
                                 boolean bigEndian)

toFCC

public static java.lang.String toFCC(int packedFCC)
Returns the four char code represented by %packedFCC as a String.


toFCC_BE

public static java.lang.String toFCC_BE(int packedFCC)

byteArrayFromHexString

public static byte[] byteArrayFromHexString(java.lang.String hex)

byteArrayToHexString

public static java.lang.String byteArrayToHexString(byte[] data)

subTypeFromMIME

public static int subTypeFromMIME(java.lang.String MIME)

isMulticast

public static boolean isMulticast(java.lang.String ip)
Returns true if the given IP4-Address, which should be in standard dot decimal form (exp.: 230.0.0.1) is a multicast address.


MPEGStart

public static boolean MPEGStart(byte[] data,
                                int pos)
Returns true if there's a 0 0 1 mpeg start code at %pos in the given byte[].


MPEGStart

public static boolean MPEGStart(byte[] data,
                                int pos,
                                int startCodeLength)

toFix

public static int toFix(float f)

fromFix

public static float fromFix(int i)

setScreenSaverActive

public static void setScreenSaverActive(boolean active)
                                 throws DSJException
Throws:
DSJException

getScreenSaverActive

public static boolean getScreenSaverActive()
                                    throws DSJException
Throws:
DSJException

centerFrame

public static void centerFrame(java.awt.Frame f,
                               java.awt.GraphicsDevice gd)

plotBytes

public static void plotBytes(byte[] data,
                             int from,
                             int num)

showFilterList

public static void showFilterList(DSFiltergraph dsfg)

hexStringToByteArray

public static byte[] hexStringToByteArray(java.lang.String hex)

setBase64EncoderLineLength

public static void setBase64EncoderLineLength(int ll)
Change number of characters after which the Base64Encoder will insert the set linbreak sequence. -1 to avoid all breaks. Default is 76. Argument must be an even multiplier of 4.


setBase64EncoderLineBreak

public static void setBase64EncoderLineBreak(java.lang.String lb)
Change Base64Encoder's linebreak sequence. Default is "\\n".


base64decode

public static byte[] base64decode(byte[] source)
Base64 decode utility, based on public domain Base64 library http://iharder.sourceforge.net/current/java/base64/


base64encode

public static byte[] base64encode(byte[] source)
Base64 encode utility, based on public domain Base64 library http://iharder.sourceforge.net/current/java/base64/


base64encode

public static byte[] base64encode(byte[] source,
                                  int from,
                                  int to)

urlDecode

public static java.lang.String urlDecode(java.lang.String encoded)

grf2xgr

public static org.w3c.dom.Document grf2xgr(java.lang.String grfPath)
                                    throws java.io.IOException
Returns an xml representation of a filtergraph stored in a.grf file. This produces xml similiar to the "Save as XML" output of the DX8 version of GraphEdit.

Throws:
java.io.IOException

msecToSMPTE

public static java.lang.String msecToSMPTE(int msecTime,
                                           float fps,
                                           boolean drop)

parseURL

public static java.lang.String parseURL(java.lang.String url,
                                        int part,
                                        java.lang.String def)
Parses URL strings into protocol, host and port and resource parts. While the same functionality is available in java.net.URL it remains impossible to construct a java URL object for protocols unknown to java.net.URL (like for example rtmp://).


getNextLineBreak

public static int getNextLineBreak(java.lang.String str,
                                   int from)

log

public static void log(java.lang.String dbg)
Writes %dbg to the active log stream (see DSEnvironment.setLogStream(...)).


log

public static void log(int level,
                       java.lang.String dbg)
Writes %dbg to the active log stream if the current logging level is higher than %level.


logln

public static void logln(java.lang.String dbg)
Writes %dbg + a linebreak to the active log stream.


logln

public static void logln(int level,
                         java.lang.String dbg)
Writes %dbg + a linebreak to the active log stream if the current logging level is higher than %level.


logErr

public static void logErr(java.lang.Exception e,
                          java.lang.String addInfo)

logErr

public static void logErr(int level,
                          java.lang.Exception e,
                          java.lang.String addInfo)