001package net.filebot.mediainfo;
002
003import static java.util.Collections.*;
004
005import java.lang.reflect.Method;
006
007import com.sun.jna.FunctionMapper;
008import com.sun.jna.Library;
009import com.sun.jna.Native;
010import com.sun.jna.NativeLibrary;
011import com.sun.jna.Platform;
012import com.sun.jna.Pointer;
013import com.sun.jna.WString;
014
015public interface MediaInfoLibrary extends Library {
016
017        // libmediainfo for linux depends on libzen, so we need to load dependencies first, because we know where our native libs are (e.g. Java Web Start Cache).
018        // if we do not, the system will look for dependencies, but only in the library path
019
020        // Ensure JNA 4.x compatibility (i.e. use JNA package on Linux)
021        @SuppressWarnings("deprecation")
022        Library LIB_ZEN = Platform.isLinux() ? (Library) Native.loadLibrary("zen", Library.class) : null;
023
024        // Ensure JNA 4.x compatibility (i.e. use JNA package on Linux)
025        @SuppressWarnings("deprecation")
026        MediaInfoLibrary INSTANCE = (MediaInfoLibrary) Native.loadLibrary("mediainfo", MediaInfoLibrary.class, singletonMap(OPTION_FUNCTION_MAPPER, new FunctionMapper() {
027
028                @Override
029                public String getFunctionName(NativeLibrary lib, Method method) {
030                        // MediaInfo_New(), MediaInfo_Open() ...
031                        return "MediaInfo_" + method.getName();
032                }
033        }));
034
035        /**
036         * Create a new handle.
037         *
038         * @return handle
039         */
040        Pointer New();
041
042        /**
043         * Open a file and collect information about it (technical information and tags).
044         *
045         * @param handle
046         * @param file
047         *            full name of the file to open
048         * @return 1 if file was opened, 0 if file was not not opened
049         */
050        int Open(Pointer handle, WString file);
051
052        /**
053         * Configure or get information about MediaInfo.
054         *
055         * @param handle
056         * @param option
057         *            The name of option
058         * @param value
059         *            The value of option
060         * @return Depends on the option: by default "" (nothing) means No, other means Yes
061         */
062        WString Option(Pointer handle, WString option, WString value);
063
064        /**
065         * Get all details about a file.
066         *
067         * @param handle
068         * @return All details about a file in one string
069         */
070        WString Inform(Pointer handle);
071
072        /**
073         * Get a piece of information about a file (parameter is a string).
074         *
075         * @param handle
076         * @param streamKind
077         *            Kind of stream (general, video, audio...)
078         * @param streamNumber
079         *            Stream number in Kind of stream (first, second...)
080         * @param parameter
081         *            Parameter you are looking for in the stream (Codec, width, bitrate...), in string format ("Codec", "Width"...)
082         * @param infoKind
083         *            Kind of information you want about the parameter (the text, the measure, the help...)
084         * @param searchKind
085         *            Where to look for the parameter
086         * @return a string about information you search, an empty string if there is a problem
087         */
088        WString Get(Pointer handle, int streamKind, int streamNumber, WString parameter, int infoKind, int searchKind);
089
090        /**
091         * Get a piece of information about a file (parameter is an integer).
092         *
093         * @param handle
094         * @param streamKind
095         *            Kind of stream (general, video, audio...)
096         * @param streamNumber
097         *            Stream number in Kind of stream (first, second...)
098         * @param parameter
099         *            Parameter you are looking for in the stream (Codec, width, bitrate...), in integer format (first parameter, second parameter...)
100         * @param infoKind
101         *            Kind of information you want about the parameter (the text, the measure, the help...)
102         * @return a string about information you search, an empty string if there is a problem
103         */
104        WString GetI(Pointer handle, int streamKind, int streamNumber, int parameterIndex, int infoKind);
105
106        /**
107         * Count of streams of a stream kind (StreamNumber not filled), or count of piece of information in this stream.
108         *
109         * @param handle
110         * @param streamKind
111         *            Kind of stream (general, video, audio...)
112         * @param streamNumber
113         *            Stream number in this kind of stream (first, second...)
114         * @return number of streams of the given stream kind
115         */
116        int Count_Get(Pointer handle, int streamKind, int streamNumber);
117
118        /**
119         * Close a file opened before with Open().
120         *
121         * @param handle
122         */
123        void Close(Pointer handle);
124
125        /**
126         * Dispose of a handle created with New().
127         *
128         * @param handle
129         */
130        void Delete(Pointer handle);
131
132        /**
133         * Open_Buffer_Init
134         */
135        int Open_Buffer_Init(Pointer handle, long length, long offset);
136
137        /**
138         * Open_Buffer_Continue
139         */
140        int Open_Buffer_Continue(Pointer handle, Pointer buffer, int size);
141
142        /**
143         * Open_Buffer_Continue_GoTo_Get
144         */
145        long Open_Buffer_Continue_GoTo_Get(Pointer handle);
146
147        /**
148         * Open_Buffer_Finalize
149         */
150        int Open_Buffer_Finalize(Pointer handle);
151
152}