using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;

namespace CHTest
{
    public struct RECT
    {
        public int left;
        public int top;
        public int right;
        public int bottom;
    }
    class DvrshMethod
    {
        [System.Runtime.InteropServices.UnmanagedFunctionPointerAttribute(System.Runtime.InteropServices.CallingConvention.Cdecl)]
        public delegate void RAWSTREAM_DIRECT_CALLBACK(int channelNumber, IntPtr DataBuf, int FrameType, int width, int height, IntPtr context); 
       [System.Runtime.InteropServices.UnmanagedFunctionPointerAttribute(System.Runtime.InteropServices.CallingConvention.Cdecl)]
        public delegate void VIDEOSTATUS_CALLBACK(int channelNumber, int FrameType, IntPtr context);
       
        [System.Runtime.InteropServices.UnmanagedFunctionPointerAttribute(System.Runtime.InteropServices.CallingConvention.Cdecl)]
       public delegate void RAWAUDIO_DIRECT_CALLBACK(int channelNumber, IntPtr DataBuf, int FrameType, int size, IntPtr context);

        [DllImport("hwsys.dll")]
        public static extern int InitHwDSPs();
        [DllImport("hwsys.dll")]
        public static extern int DeInitHwDSPs();
        [DllImport("hwsys.dll")]
        public static extern int StartVideoPreview(int hChannel, IntPtr WndHandle, ref RECT rect);
        [DllImport("hwsys.dll")]
        public static extern int SaveCaptureImage(int hChannel, System.String path);
        [DllImport("hwsys.dll")]
        public static extern int GetVideoTotalChannels();
        [DllImport("hwsys.dll")]
        public static extern int GetCurrSystemDevice();
        [DllImport("hwsys.dll")]
        public static extern int GetAudioTotalChannels();
        [DllImport("hwsys.dll")]
        public static extern int VideoChannelOpen(int nChannel, int videoIndex, int w, int h, int fps);
        [DllImport("hwsys.dll")]
        public static extern int StopVideoCapture(int nChannel);
        [DllImport("hwsys.dll")]
        public static extern int OpenVideoColorSetting(int nChannel);
        [DllImport("hwsys.dll")]
        public static extern int GetVideoMaxResIndex(int nChannel);
        [DllImport("hwsys.dll")]
        public static extern int SetVideoPara(int hChannel,int Brightness, int Contrast, int Saturation, int Hue);
        [DllImport("hwsys.dll")]
        public static extern int RegisterRAWDirectCallback(int nChannel,RAWSTREAM_DIRECT_CALLBACK StreamDirectReadCallback, IntPtr Context);
        [DllImport("hwsys.dll")]
        public static extern int RegisterVideoStatusCallback(int nChannel,VIDEOSTATUS_CALLBACK StreamDirectReadCallback, IntPtr Context);
        [DllImport("hwsys.dll")]
        public static extern int GetVideoMaxResWidthByIndex(int videoIndex, int ResIndex);
        [DllImport("hwsys.dll")]
        public static extern int GetVideoMaxResHeightByIndex(int videoIndex, int ResIndex);
        [DllImport("hwsys.dll")]
        public static extern int GetVideoMaxResFpsByIndex(int videoIndex, int ResIndex);
        [DllImport("hwsys.dll")]
        public static extern void ChangeYUVToRGB(IntPtr yuvdata, IntPtr rgbdata, int width, int height);
        [DllImport("hwsys.dll")]
        public static extern void ChangeYUVToGrayRGB(IntPtr yuvdata, IntPtr rgbdata, int width, int height);
        [DllImport("hwsys.dll")]
        public static extern void SetMax_VideoSize(int width, int height);

        [DllImport("hwsys.dll")]
        public static extern int AudioChannelOpen(int nChannel,int audioIndex,int buffsize);

        [DllImport("hwsys.dll")]
        public static extern int StopAudioCapture(int nChannel);

        [DllImport("hwsys.dll")]
        public static extern int RegisterAudioDirectCallback(int nChannel, RAWAUDIO_DIRECT_CALLBACK RawAudioDirectReadCallback, IntPtr Context);


        [DllImport("hwsys.dll")]
        public static extern int AudioOutOpen(int nChannel, IntPtr WndHandle);

        [DllImport("hwsys.dll")]
        public static extern int AudioOutPause(int nChannel);
        [DllImport("hwsys.dll")]
        public static extern int AudioOutPlay(int nChannel);


        [DllImport("hwsys.dll", CallingConvention = CallingConvention.Winapi, CharSet = CharSet.Auto)]
        public static extern int GetVideoNameByIndex(int videoIndex, ref byte strname);
        
        [DllImport("hwsys.dll", CallingConvention = CallingConvention.Winapi, CharSet = CharSet.Auto)]
        public static extern int GetAudioNameByIndex(int videoIndex, ref byte strname);

        [DllImport("kernel32.dll", CharSet = CharSet.Auto)]
        public static extern void OutputDebugString(string message);
        [DllImport("kernel32.dll", EntryPoint = "CopyMemory", SetLastError = false)]
        public static extern void CopyMemory(IntPtr dest, IntPtr src, uint count);
    }
}
