/*  Copyright (c) MediaArea.net SARL. All Rights Reserved.
 *
 *  Use of this source code is governed by a BSD-style license that can
 *  be found in the License.html file in the root of the source tree.
 */

//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//
// Microsoft Visual J# wrapper for MediaInfo Library
// See MediaInfo.h for help
//
// To make it working, you must put MediaInfo.Dll
// in the executable folder
//
// Warning : not tested with J# 64-bit, will not work!
//
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

import System.Runtime.InteropServices.*;
import System.IntPtr;

public enum StreamKind
{
    General,
    Visual,
    Audio,
    Text,
    Chapters,
    Image,
    Menu,
    Max
}

public enum InfoKind
{
    Name,
    Text,
    Measure,
    Options,
    NameText,
    MeasureText,
    Info,
    HowTo,
    Max
}

public enum InfoOptions
{
    ShowInInform,
    Reserved,
    ShowInSupported,
    TypeOfValue,
    Max
}

public class MediaInfo
{
    /**@attribute DllImport("MediaInfo.dll")*/
    public static native IntPtr MediaInfo_New();
    /**@attribute DllImport("MediaInfo.dll")*/
    public static native void MediaInfo_Delete(IntPtr Handle);
    /**@attribute DllImport("MediaInfo.dll")*/
    public static native int MediaInfo_Open(IntPtr Handle, /** @attribute MarshalAs(UnmanagedType.LPWStr)*/ String File);
    /**@attribute DllImport("MediaInfo.dll")*/
    public static native void MediaInfo_Close(IntPtr Handle);
    /**@attribute DllImport("MediaInfo.dll")*/
    public static native IntPtr MediaInfo_Inform(IntPtr Handle, int Options); //WARNING : This is a wchar* value
    /**@attribute DllImport("MediaInfo.dll")*/
    public static native IntPtr MediaInfo_GetI(IntPtr Handle, StreamKind StreamKind, int StreamNumber, int Parameter, InfoKind KindOfInfo); //WARNING : This is a wchar* value, see MediaInfoDLL.h for enumeration values
    /**@attribute DllImport("MediaInfo.dll")*/
    public static native IntPtr MediaInfo_Get(IntPtr Handle, StreamKind StreamKind, int StreamNumber, /** @attribute MarshalAs(UnmanagedType.LPWStr)*/ String Parameter, InfoKind KindOfInfo, InfoKind KindOfSearch); //WARNING : This is a wchar* value, see MediaInfoDLL.h for enumeration values
    /**@attribute DllImport("MediaInfo.dll")*/
    public static native IntPtr MediaInfo_Option(IntPtr Handle, /** @attribute MarshalAs(UnmanagedType.LPWStr)*/ String Option, /** @attribute MarshalAs(UnmanagedType.LPWStr)*/ String Value); //WARNING : This is a wchar* value, see MediaInfoDLL.h for enumeration values
    /**@attribute DllImport("MediaInfo.dll")*/
    public static native int MediaInfo_State_Get(IntPtr Handle); //see MediaInfoDLL.h for details
    /**@attribute DllImport("MediaInfo.dll")*/
    public static native int MediaInfo_Count_Get(IntPtr Handle, StreamKind StreamKind, int StreamNumber); //see MediaInfoDLL.h for enumeration values

    //MediaInfo class
    public MediaInfo() { Handle = MediaInfo_New(); }
    void Dispose(boolean disposing) { MediaInfo_Delete(Handle); }
    public int Open(String FileName) { return MediaInfo_Open(Handle, FileName); }
    public void Close() { MediaInfo_Close(Handle); }
    public String Inform() { return Marshal.PtrToStringUni(MediaInfo_Inform(Handle, 0)); }
    public String Get(StreamKind StreamKind, int StreamNumber, String Parameter, InfoKind KindOfInfo, InfoKind KindOfSearch) { return Marshal.PtrToStringUni(MediaInfo_Get(Handle, StreamKind, StreamNumber, Parameter, KindOfInfo, KindOfSearch)); }
    public String Get(StreamKind StreamKind, int StreamNumber, int Parameter, InfoKind KindOfInfo) { return Marshal.PtrToStringUni(MediaInfo_GetI(Handle, StreamKind, StreamNumber, Parameter, KindOfInfo)); }
    public String Option(String Option, String Value) { return Marshal.PtrToStringUni(MediaInfo_Option(Handle, Option, Value)); }
    public int State_Get() { return MediaInfo_State_Get(Handle); }
    public int Count_Get(StreamKind StreamKind, int StreamNumber) { return MediaInfo_Count_Get(Handle, StreamKind, StreamNumber); }
    private IntPtr Handle;

    //Default values, if you know how to set default values in J#, say me
    public String Get(StreamKind StreamKind, int StreamNumber, String Parameter, InfoKind KindOfInfo) { return Get(StreamKind, StreamNumber, Parameter, KindOfInfo, InfoKind.Name); }
    public String Get(StreamKind StreamKind, int StreamNumber, String Parameter) { return Get(StreamKind, StreamNumber, Parameter, InfoKind.Text, InfoKind.Name); }
    public String Get(StreamKind StreamKind, int StreamNumber, int Parameter) { return Get(StreamKind, StreamNumber, Parameter, InfoKind.Text); }
    public String Option(String Option) { return Option(Option, ""); }
    public int Count_Get(StreamKind StreamKind) { return Count_Get(StreamKind, -1); }
}
