#ifndef MID2253_CONST_H
#define MID2253_CONST_H


#ifdef ISDLLBUILD
    #define MID2253_API extern "C" __declspec(dllexport)
#else
#ifdef __cplusplus
    #define MID2253_API extern "C" __declspec(dllimport)
#else
    #define MID2253_API __declspec(dllimport)
#endif
#endif

#define MID2253_DEFAULT_BITRATE 2500
#define MID2253_MINIMUM_BITRATE 100
#define MID2253_MAXIMUM_BITRATE 20000


typedef enum
{
    MID2253_RECMODE_VIDEO = 0,  // only record video (muxed: .MP4 for MPEG4/H264, .AVI for uncompressed)
    MID2253_RECMODE_AV    = 1,  // audio plus video (.MP4 for MPEG4/H264, .AVI for uncompressed, TS with audio for TS streams)
    MID2253_RECMODE_VES   = 2,  // only record video elementary stream (AVI mux is used for uncompressed)
} MID2253_RECMODE;

typedef enum
{
    MID2253_MP4MODE_STANDARD = 0,    // same as MID2253_RECMODE_VIDEO.
    MID2253_MP4MODE_STREAMABLE = 1,  // streamable fragmented MP4 (May not play on standard players).
} MID2253_MP4MODE; // for use with MID2253_RECMODE_VIDEO only.  Affects MPEG-4 and/or H-264 only.


// Important Note: MID2253_AUDENC only applies to 
//                 AVI muxed streams (UYVY, Y800 and MJPEG).
//                 The audio encoding setting will be ignored when the streamtype is H264 or MPEG4
//                 AAC encoding is used for H264/MPEG4 .MP4 recordings.
typedef enum
{
    MID2253_AUDENC_PCM = 0,  // "no" audio encoding.
    MID2253_AUDENC_G711_ULAW = 2, 
    MID2253_AUDENC_G711_ALAW = 3, 
} MID2253_AUDENC;


typedef enum
{
    MID2253_STYPE_MPEG4 = 0,
    MID2253_STYPE_H264 = 1,
    MID2253_STYPE_MJPEG = 2,
	MID2253_STYPE_UYVY = 3,
    MID2253_STYPE_Y800 = 4, /* monochrome Y8. */
	MID2253_STYPE_M4TS = 5, /* MPEG4 in MPEG transport stream */
	MID2253_STYPE_H4TS = 6, /* H264 in MPEG transport stream */
	MID2253_STYPE_YUY2 = 7,
    MID2253_STYPE_RGB565 = 8,  // RGB565 is available only for callback (s2253_StartCallback). 
                               // RGB565 is not recommended for preview as most video cards
                               // support YUV natively.
    MID2253_STYPE_RGB24 = 9,   // Please note the following caveats:
                               // RGB24 available only for callback. 
                               // Sensoray only supports one RGB24 stream/channel
                               // at a time at a maximum size of 640x480.
    MID2253_STYPE_M2PS = 10, /* MPEG-2 in MPEG program stream, feature flagged */
    MID2253_STYPE_LAST = 10,// last type
} MID2253_STREAMTYPE;

typedef enum {
    S2253_OUTFORMAT_MPEG4 = 0,        /* MPEG-4 SP elementary stream */
    S2253_OUTFORMAT_H264 = 1,         /* h.264 elementary stream */
    S2253_OUTFORMAT_JPEG = 2,         /* JPEG images */
    S2253_OUTFORMAT_UYVY = 3,         /* YUV 422 packed */
    S2253_OUTFORMAT_YUV420PSEMI =4 ,  /* YUV 420 semi-planar (Y in one plane, CrCb in another) */
    S2253_OUTFORMAT_Y8 = 5,           /* Y8 grayscale */
    S2253_OUTFORMAT_MPEG2 = 6,        /* MPEG-2 main profile elementary stream */
    S2253_OUTFORMAT_NOVIDEO = 9,      /* no video, just audio over STREAM A or B endpoint.  not yet implemented */
    S2253_OUTFORMAT_MP4 = 0x100,  /* MP4 fragmented muxed stream */
    S2253_OUTFORMAT_MPEG_TS = 0x200, /* MPEG Transport stream */
    S2253_OUTFORMAT_MPEG_PS = 0x300, /* MPEG Program stream */
} MID2253_DECODETYPE;  // note: not all types and combinations supported.


// error constants 
#define MID2253_SUCCESS             0
#define MID2253_ERR_NONE            0
#define MID2253_ERR_UNSPECIFIED     -1
#define MID2253_ERR_NOTRUNNING      -2   // not running
#define MID2253_ERR_RUNNING         -3   // attempt to set configuration or start graph while graph 
                                         // already running
#define MID2253_ERR_INVALIDFILE     -4   // invalid file
#define MID2253_ERR_DIRECTX         -5   // directX error( other specific directX errors are possible)
#define MID2253_ERR_NODEVICE		-6   // device not present
#define MID2253_ERR_NOTINITIALIZED  -7	 // initialization function failed or not called
#define MID2253_ERR_TIMEOUT         -8   //timeout
#define MID2253_ERR_CONFIGURATION   -9   // invalid configuration(using StartSnapshot with H264 stream type for instance)
#define MID2253_ERR_OUTOFRANGE      -10  // out of range or invalid value
// errors below are DirectShow errors.  It may be possible to get extra error info
// by calling S2253_GetLastError
#define MID2253_ERR_ADDFILT_SG       -11  // sample grabber filter not registered or other error adding sample grabber
#define MID2253_ERR_ADDFILT_NULLREND -12  // null filter not registered or other error adding sample grabber
#define MID2253_ERR_CONNECT_SG       -13  // connection to SG error
#define MID2253_ERR_CONNECT_NULLREND -14  // connection to null renderer error
#define MID2253_ERR_ADDFILT_XB       -15  // could not add 2253 crossbar (is driver properly installed?)
#define MID2253_ERR_ADDFILT_2253     -16  // could not add 2253 filter. could also mean device not present.
#define MID2253_ERR_ADDFILT_YUV      -17  // could not add YUV decoder filter (Note: YUV decoding not available for 64 bit)
#define MID2253_ERR_ADDFILT_FILEWRITER -18 // could not add file writing filter
#define MID2253_ERR_CONNECT_YUV        -19  // could not connect to YUV decoder filter
#define MID2253_ERR_CONNECT_FILEWRITER -20  // could not connect to file writer filter
#define MID2253_ERR_ADDFILT_LIVESOURCE -21  // could not add live source filter
#define MID2253_ERR_CONNECT_LIVESOURCE -22  // could not add live source filter
#define MID2253_ERR_QUERY_LIVESOURCE   -23  // could not query interface
#define MID2253_ERR_ADDFILT_MUX        -24  // could not add mux filter
#define MID2253_ERR_CONNECT_MUX        -25  // could not connect mux filter
#define MID2253_ERR_FILTERGRAPH        -26  // could not create filter graph
#define MID2253_ERR_ADD_RENDERER       -27 // could not add video renderer
#define MID2253_ERR_RENDERER           -28 // could not render the graph
#define MID2253_ERR_ADD_PUSHSOURCE     -29 // push source filter not registered error
#define MID2253_ERR_CONNECT_PUSHSOURCE -30 // connect to push source filter (for decoding from files) error
#define MID2253_ERR_ADDFILT_ACCESSDENIED -31 // access denied to filter. Launch privacy settings
typedef enum
{
	MID2253_VIDSYS_PAL=1,
	MID2253_VIDSYS_NTSC=2
} MID2253_VIDSYS;


/** VIDEO levels */
#define MID2253_LEVEL_CONTRAST		1
#define	MID2253_LEVEL_BRIGHTNESS	2
#define MID2253_LEVEL_SATURATION	4
#define MID2253_LEVEL_HUE			8
#define MID2253_LEVEL_HCENTER		16
#define MID2253_LEVEL_VCENTER		32
#define MID2253_LEVEL_FIELDMODE		64
#define MID2253_LEVEL_AUTOGAIN      128
#define MID2253_LEVEL_AUTOBRIGHTNESS 256
#define MID2253_LEVEL_COMBFILTER    512
#define MID2253_LEVEL_LUMAFILTER    1024
#define MID2253_LEVEL_CHROMAFILTER  2048
/** COMBFILTER values:  (write-only)
 *   0 - Disabled
 *   1 - Chrominance Comb Filter (CE) enabled
 *   2 - Chrominance Adaptive Comb Filter (ACE) enabled
 *   3 - Both CE and ACE enabled
 ** LUMAFILTER values:  (write-only)
 *       luminance filter stop band bandwidth (MHz)
 *   0 - 1.2244 or 1.4170 (WCF)  (default)
 *   1 - 0.8782 or 1.0303 (WCF)
 *   2 - 0.7297 or 0.8438 (WCF)
 *   3 - 0.4986 or 0.5537 (WCF)  
 *    value is selected by WCF setting in CHROMAFILTER
 ** CHROMAFILTER values:  (write-only)
 *       chrominance output bandwidth (MHz)
 *   0 - 1.2244
 *   1 - 0.8782
 *   2 - 0.7297
 *   3 - 0.4986
 *   4 - 1.4170 (WCF)  (default)
 *   5 - 1.0303 (WCF)
 *   6 - 0.8438 (WCF)
 *   7 - 0.5537 (WCF)
 *   WCF is Wideband Chrominance Filter
 */

/** General Status information
 * @param bIsRecording true if currently recording
 * @param bIsPlaying true if video playing(for debug)      
 * @param iFilesize current recorded file size
 * @param szFilepath current filepath being recorded
 */
typedef struct 
{ 
    ULONG       iFilesize;              // current recorded size(megs)
    char        szFilepath[MAX_PATH];   // current filepath (char
    wchar_t     wcFilepath[MAX_PATH];   // current filepath (unicode)
    BOOL        bIsRecording;           // true if currently recording

    BOOL        bIsRunning;          // true if video streaming(preview)
} MID2253STATUS; 

// for .NET. doesn't allow marshalling of both ascii and unicode


// GMT time from January 1, 1970 (unix time)
// see manual
typedef struct mid2253_user_clock
{
    UINT64 sec;
    UINT32 usec;
} MID2253_USER_CLOCK;

typedef enum mid2253_osd_type
{
	MID2253_OSDTYPE_TEXT = 1,  // text overlay
	MID2253_OSDTYPE_BMP, // BMP file overlay
    MID2253_OSDTYPE_LONGTEXT, // large text overlay
	MID2253_OSDTYPE_STYLEDTEXT, // styled text overlay
	MID2253_OSDTYPE_RECT, // rectangle overlay
} MID2253_OSD_TYPE;

#define MID2253_MAX_OSDTEXT 80

typedef struct mid2253_osd_text
{
    int osdOn;       //OSD on if != 0, 1=8x14 font, 2=16x16 font
    int osdChan;     // osd channel to update.  osdChan=0 for stream A, osdChan=1 for stream B, osdChan=2 for output
    int transparent; //transparent OSD if !=0, 1=100%, 2=50%, 3=25%
    int positionTop; //see xoff, yoff below
    int ddmm;     //date format 0=mm-dd 1=dd-mm 2=mmm-dd, 3=dd-mmm- 4=mmm dd, 5=ddmmm, 6=dd.mm.
    int year2;    // year display mode (year2 = 1 means 2 digits, year2=0 means 4 digits)
    int fraction; // whether to display fraction of seconds
    unsigned char line[MID2253_MAX_OSDTEXT]; // ascii string of text (null terminated)
    int xoffset; //x offset: if positionTop=1, relative to top. if positionTop=0, relative to bottom
    int yoffset; //y offset: if positionTop=1, relative to top. if positionTop=0, relative to bottom
} MID2253_OSD_TEXT;

#define MID2253_MAX_OSDLONGTEXT 160

typedef struct mid2253_osd_longtext
{
    int osdOn;       //OSD on if != 0, 1=8x14 font, 2=16x16 font
    int osdChan;     // osd channel to update.  osdChan=0 for stream A, osdChan=1 for stream B, osdChan=2 for output
    int transparent; //transparent OSD if !=0, 1=100%, 2=50%, 3=25%
    int positionTop; //see xoff, yoff below
    int ddmm;     //date format 0=mm-dd 1=dd-mm 2=mmm-dd, 3=dd-mmm- 4=mmm dd, 5=ddmmm, 6=dd.mm.
    int year2;    // year display mode (year2 = 1 means 2 digits, year2=0 means 4 digits)
    int fraction; // whether to display fraction of seconds
    int xoffset; //x offset: if positionTop=1, relative to top. if positionTop=0, relative to bottom
    int yoffset; //y offset: if positionTop=1, relative to top. if positionTop=0, relative to bottom
    unsigned char line[MID2253_MAX_OSDLONGTEXT]; // ascii string of text (null terminated)
} MID2253_OSD_LONGTEXT;

typedef struct mid2253_osd_styledtext
{
	int osdOn;		// OSD on if != 0
	int osdChan;	// osd channel to update.  osdChan=0 for stream A, osdChan=1 for stream B, osdChan=2 for output
	int id;			// region id: 0..7
	int xoffset;	// x offset: relative to left
	int yoffset;	// y offset: relative to top
	LPSTR font;     // font name
	int size;       // point size of text
	int style;		// bit[0]: bold, bit[1]: italic, bit[2]: outline, bit[3]: underline, bit[4]: shadow
	int outline;	// outline style: 0=transparent, 1..7=shaded, 8=black
	int background; // background style: 0=transparent, 1..7=shaded, 8=black
	int color;      // RGB888 color for text (only used for osdChan=2 or background=8)
	LPSTR line;     // pointer to UTF8 text (null terminated) (pointer may be NULL, which will update xoffset and yoffset only)
} MID2253_OSD_STYLEDTEXT;

#define MID2253_STYLE_BOLD 1
#define MID2253_STYLE_ITALIC 2
#define MID2253_STYLE_OUTLINE 4
#define MID2253_STYLE_UNDERLINE 8 
#define MID2253_STYLE_SHADOW 16

typedef struct mid2253_osd_rect
{
	int osdOn;		// OSD on if != 0
	int osdChan;	// osd channel to update.  osdChan=0 for stream A, osdChan=1 for stream B, osdChan=2 for output
	int id;			// region id: 0..15
	int xoffset;	// x offset: relative to left
	int yoffset;	// y offset: relative to top
	int width;		// width of rectangle
	int height;		// height of rectangle
	int color;      // RGB888 color for rectangle (only used for osdChan=2)
} MID2253_OSD_RECT;


typedef struct mid2253_osd_bmp
{
	int osdOn;		// OSD on if != 0
	int osdChan;	// osd channel to update.  osdChan=0 for stream A, osdChan=1 for stream B, osdChan=2 for output, osdChan=3 for both streams
	int id;			// region id: 0..15
	int xoffset;	// x offset: relative to left
	int yoffset;	// y offset: relative to top
	void *bmp;		// pointer to bitmap image data (as loaded from file)
} MID2253_OSD_BMP;

typedef union mid2253_osd_data
{
    struct mid2253_osd_text osdtext; // text structure
	struct mid2253_osd_longtext osdlongtext; // large text structure
    struct mid2253_osd_bmp  osdbmp;  // BMP file structure
	struct mid2253_osd_styledtext osdstyledtext; // styled text structure
    struct mid2253_osd_rect  osdrect;  // rectangle structure
} MID2253_OSD_DATA;

typedef enum {
    MID2253_GPIO_LOW,
    MID2253_GPIO_HIGH,
    MID2253_GPIO_CHANGE,
} MID2253_GPIO_SIGNAL;

typedef enum {
    MID2253_AUDIO_MIC = 0,
    MID2253_AUDIO_LINE = 1
} MID2253_AUDIO_INPUT;

typedef enum {
    MID2253_AUDBR_96	= 96,
	MID2253_AUDBR_128	= 128,
	MID2253_AUDBR_192	= 192,
	MID2253_AUDBR_224	= 224,
	MID2253_AUDBR_256	= 256
} MID2253_AUDIO_BITRATE;

typedef enum {
    MID2253_AUDCH_MONO_MIXED	= 1,
	MID2253_AUDCH_STEREO		= 2, // default
	MID2253_AUDCH_MONO_LEFT		= 3,
	MID2253_AUDCH_MONO_RIGHT	= 4
} MID2253_AUDIO_CHANNELS;


#define MID2253_OVERLAY_UPDATE_DISPLAY 1
#define MID2253_OVERLAY_UPDATE_POSITION 2
#define MID2253_OVERLAY_UPDATE_TRANSPARENT 4


typedef struct {
    unsigned char id;
    unsigned char transparent;
    unsigned char update;
    unsigned char reserved;
    int xOffset;
    int yOffset;
    unsigned int length;
} MID2253_OVL_STRUCT;

typedef enum {
    MID2253_OUTPUT_IDLE, // black screen
    MID2253_OUTPUT_PASSTHRU, // capture
    MID2253_OUTPUT_COLORBARS,
    MID2253_OUTPUT_FLASH,// display 1 white frame, then switch to IDLE
    MID2253_OUTPUT_STREAM, //decode mode (switched to this mode automatically when)
                           // decoding a file
} MID2253_OUTPUT_MODE;


// additional parameters
typedef enum
{
    MID2253_PARAM_FIRMWARE,
	MID2253_PARAM_BOOTLOADER,
	MID2253_PARAM_EEPROM,
	MID2253_PARAM_CPULOAD,
} MID2253_PARAM;

typedef enum {
    MID2253_H264_BASELINE = 66,   // baseline profile
    MID2253_H264_MAIN = 77,       // main profile
    MID2253_H264_HIGH = 100       // high profile   (default)
} MID2253_H264_PROFILE;


typedef enum {
    MID2253_H264_1_0 = 10,  // 1.0
    MID2253_H264_1B = 9,    // 1B
    MID2253_H264_1_1 = 11,  // 1.1
    MID2253_H264_1_2 = 12,  // 1.2
    MID2253_H264_1_3 = 13,  // 1.3
    MID2253_H264_2_0 = 20,  // 2.0
    MID2253_H264_2_1 = 21,  // 2.1
    MID2253_H264_2_2 = 22,  // 2.2
    MID2253_H264_3_0 = 30,  // 3.0
    MID2253_H264_3_1 = 31,  // 3.1
    MID2253_H264_3_2 = 32,  // 3.2
    MID2253_H264_4_0 = 40,  // 4.0  (default)
    MID2253_H264_4_1 = 41,  // 4.1
    MID2253_H264_4_2 = 42,  // 4.2
    MID2253_H264_5_0 = 50   // 5.0
} MID2253_H264_LEVEL;


typedef enum
{
    MID2253_PREVIEWTYPE_DEFAULT = 0, // DLL chooses best available setting. 
	                                 // VMR7 will be chosen for WinXp-Win10
									 // VMR9 will be chosen for Windows 11 (as of SDK 1.2.49)
    MID2253_PREVIEWTYPE_VMR9 = 1,    // Force use of VMR 9.
    MID2253_PREVIEWTYPE_VMR7 = 2,    // Force use of VMR 7.
    MID2253_PREVIEWTYPE_LEGACY = 3, //  legacy renderer only supported as pop-up window.
                                    //XP and later versions of Windows support at least VMR7.
	MID2253_PREVIEWTYPE_EVR = 4,	// EVR. Note must create and set HWND (no pop-up window support)
} MID2253_PREVIEWTYPE;


typedef struct mid2253_versions
{
    UINT32 dll;
	UINT32 driver;
    UINT32 reserved[6]; // reserved for future use
} MID2253_VERSIONS;

#endif
