unit DVBCore;

interface
uses windows, sysutils;

const

DVB_HDRVER_TP_INFO =$105;
DVB_HDRVER_NET_INFO =$100;
DVB_HDRVER_PLG_INFO =$101;
DVB_HDRVER_TUNER_INFO =$102;
DVB_HDRVER_HW_DISPLAY =$100;
DVB_HDRVER_DS_DISPLAY =$100;
DVB_HDRVER_FILE_PLAYBACK =$101;
DVB_HDRVER_EPG_EVENT =$100;

(* errors *)
DVB_ERROR_NONE = 0; (* kein Fehler*)
DVB_ERROR_DRIVER = 1; (* Treiberzugriffsfehler*)
DVB_ERROR_HARDWARE = 2; (* Hardware-Fehler*)
DVB_ERROR_PARAMETER = 3; (* ungültiger Parameter*)
DVB_ERROR_TIMEOUT = 4; (* Timeout*)
DVB_ERROR_STATE = 5; (* Zustandsfehler*)
DVB_ERROR_RESOURCES = 6; (* Mangel an Ressourcen*)
DVB_ERROR_GENERAL = 7; (* allgemeiner Fehler*)
DVB_ERROR_PAT_INVALID = 1000; // Error in Program Association Table
DVB_ERROR_NO_SIGNAL = 1001; // No signal after setting tuner
DVB_ERROR_NOT_SUPPORTED =1002;// function isn't supported
DVB_ERROR_CANCELED = 1003; // canceled

//***************************** GENERAL FUNCTIONS *************************************************************************

const

DVBDEV_FLAG_DEVTYPE_MASK = $0003;
DVBDEV_FLAG_DVB_S = $0001;
DVBDEV_FLAG_DVB_C = $0002;
DVBDEV_FLAG_DVB_T = $0003;

DVBDEV_FLAG_SETUP_SUPP = $0004;
DVBDEV_FLAG_CSDISEQC_SUPP = $0008;
DVBDEV_FLAG_UCSDISEQC_SUPP = $1000;
DVBDEV_FLAG_RAWDISEQC_SUPP = $0010;
DVBDEV_FLAG_HWMPEG2 = $0020;
DVBDEV_FLAG_LEVEL_SUPP = $0040;
DVBDEV_FLAG_QUALITY_SUPP = $0080;
DVBDEV_FLAG_HWOSD = $0100;
DVBDEV_FLAG_HWCSA = $0200;
DVBDEV_FLAG_HWCI = $0400;
DVBDEV_FLAG_HWPLAYBACK = $0800;
DVBDEV_FLAG_RC_SUPP = $1000;
DVBDEV_FLAG_INTEGRATED = $80000000;

type
DVBDevice = packed record
Name: array[0..255] of char;//Device Name. max 255 characters
Flags: Cardinal; //combination of DVBDEVICE_FLAG_*
Reserved1: Cardinal;
Reserved2: Cardinal;
Reserved3: Cardinal;
Reserved4: Cardinal;
end;

DVBDevList = packed record
Count: Cardinal;
Current: Cardinal;
Dev: array[0..199] of DVBDevice;
end;

PDVBDevList = ^DVBDevList;

//TypeIndex is from 0 to DVBDevList.Count-1
//DevIndex is from DVBDevList.Dev[x].Count-1
//SetupData is array of 32 bytes. Some devices can use setup data to save settings.
//SetupData must be saved after DVBDevSetup somewhere and restored before call DVBOpen or next DVBDevSetup.
function DVBGetDevList(DevList: PDVBDevList): DWORD; stdcall; external 'DVBCore.dll';
function DVBDevSetup(Index: Cardinal; SetupData: PByteArray; AppWindow: HWND): DWORD; stdcall; external 'DVBCore.dll';
function DVBOpen(Index: Cardinal; SetupData: PByteArray): DWORD; stdcall; external 'DVBCore.dll';

//Get Version of DVBCore
function DVBGetCoreVer(Str: PByteArray = NIL): DWORD; stdcall; external 'DVBCore.dll';

//Close DVB hardware
procedure DVBClose(ShutDown: BOOL = true); stdcall; external 'DVBCore.dll';

//****************************** MAIN CONTROL FUNCTION OF DVBCORE *********************************************************

const

(* Valid options for DVBParams. May be mixed*)
SET_DISEQ = $0000001; //SetUp DiSEq data
SET_TUNER = $0000002; //SetUp Tuner data
SET_PIDS = $0000004; //SetUp PIDs Audio, Video, PCR

// Be sure you supplied all PIDs before start capture.
// if all 3 PIDs (Audio, Video, PCR) not equal zero then capture starts in Audio/Video mode.
// if Video or PCR PID equals to zero then capture starts in Audio-only mode.
// if Audio PID equals to zero then capture doesn't starts.

SET_STARTCAPTURE = $0000018; //Start Capture AV
SET_STOPCAPTURE = $0000008; //Stop Capture AV
SET_COPYALLDATA = $0010000; //Copy whole TP_INFO structure to internal DVBCore Cache

GET_PATINFO = $0000100; //Get Program Association Table (PMT PIDs, Channel IDs)
GET_CATINFO = $0000200; //Get Condotion Access Table (All EMM PIDs)
GET_PMTINFO = $0000400; //Get Program Map Table for specified channel (Audio, Video, PCR, ECM PIDs)
GET_SDTINFO = $0000800;
GET_ALLPMTINFO = $0001000; //Same as before but for all channels from current transponder
GET_ALLTABLESINFO = GET_PATINFO or GET_CATINFO or GET_ALLPMTINFO or GET_SDTINFO;
GET_TUNERDISEQINFO = $0002000; //Get current parameters from Tuner and DiSEq (allways from cache)
GET_ALLINFO = GET_PATINFO or GET_CATINFO or GET_ALLPMTINFO or GET_SDTINFO or GET_TUNERDISEQINFO;
GET_TRYFROMCACHE = $0100000; //Try Get info from DVBCore cache if data exists, otherwise get it from stream
GET_ONLYFROMCACHE = $0200000; //Allways get info from cache (even it's invalid. Check appropriate flags to make sure data is valid)
SET_FASTMODE = $1000000; //Fast getting info. Call DVBParams(NULL,SET_FASTMODE) after last use this mode!

(**)
(* Tip: You may mix some flags. for example: (SET_DISEQ | SET_TUNER | GET_ALLINFO| SET_PIDS) *)
(* It will setup DiSEq and Tuner then gat all info about this transponder, then setup PIDS of first channel.*)
(**)
LNB_VOLT00 = 0; (* zero volt (power off)*)
LNB_POWEROFF = 0; (* zero volt (power off)*)
LNB_VOLT13 = 13; (* 13 volt (vertical polarisation)*)
LNB_POL_VERT = 13; (* 13 volt (vertical polarisation)*)
LNB_VOLT18 = 18; (* 18 volt (horizontal polarisation)*)
LNB_POL_HORZ = 18; (* 18 volt (horizontal polarisation)*)

VITERBI_AUTO = 0; (* DVB-S: automtic detection of viterbi rate*)
VITERBI_RATE_1_2 = 1; (* DVB-S: viterbi rate: 1/2*)
VITERBI_RATE_2_3 = 2; (* DVB-S: viterbi rate: 2/3*)
VITERBI_RATE_3_4 = 3; (* DVB-S: viterbi rate: 3/4*)
VITERBI_RATE_4_5 = 4; (* DVB-S: viterbi rate: 4/5*)
VITERBI_RATE_5_6 = 5; (* DVB-S: viterbi rate: 5/6*)
VITERBI_RATE_6_7 = 6; (* DVB-S: viterbi rate: 6/7*)
VITERBI_RATE_7_8 = 7; (* DVB-S: viterbi rate: 7/8*)
VITERBI_RATE_8_9 = 8; (* DVB-S: viterbi rate: 8/9*)

DVB_C_QAM_16 =0; // DVB-C: Modulation: 16-QAM
DVB_C_QAM_32 =1; // DVB-C: Modulation: 32-QAM
DVB_C_QAM_64 =2; // DVB-C: Modulation: 64-QAM (default)
DVB_C_QAM_128 =3; // DVB-C: Modulation: 128-QAM
DVB_C_QAM_256 =4; // DVB-C: Modulation: 256-QAM


DISEQC_NONE = $00;
DISEQC_SIMPLE = $10;
DISEQC_V1_0 = $20;
DISEQC_V1_1 = $30;
DISEQC_GOTOPOS = $40;

// DiSEqC v1.0 Constants
DISEQC_HIGH_NIBLE = $F0;
DISEQC_LOW_BAND = $00;
DISEQC_HIGH_BAND = $01;
DISEQC_VERTICAL = $00;
DISEQC_HORIZONTAL = $02;
DISEQC_POSITION_A = $00;
DISEQC_POSITION_B = $04;
DISEQC_OPTION_A = $00;
DISEQC_OPTION_B = $08;

//For simple DiSEqC management mode
DISEQC_V1_0_LNB1 = DISEQC_V1_0 or DISEQC_POSITION_A or DISEQC_OPTION_A;
DISEQC_V1_0_LNB2 = DISEQC_V1_0 or DISEQC_POSITION_B or DISEQC_OPTION_A;
DISEQC_V1_0_LNB3 = DISEQC_V1_0 or DISEQC_POSITION_A or DISEQC_OPTION_B;
DISEQC_V1_0_LNB4 = DISEQC_V1_0 or DISEQC_POSITION_B or DISEQC_OPTION_B;
// This is for DiSEqC v1.1
// DISEQC_V1_1_LNB1 = DISEQC_V1_1 or 0;
//...
// DISEQC_V1_1_LNB16 = DISEQC_V1_1 or 15;

DISEQC_SIMPLE_LNB1 = DISEQC_SIMPLE or DISEQC_POSITION_A;
DISEQC_SIMPLE_LNB2 = DISEQC_SIMPLE or DISEQC_POSITION_B;


SPECTRAL_INVERSION_AUTO = 2; (* automatic detection of spectral inversion*)
SPECTRAL_INVERSION_ON = 0; (* spectral inversion*)
SPECTRAL_INVERSION_OFF = 1; (* no spectral inversion*)

(* const for wDataValid*)
PAT_VALID =1; //info about PAT is valid
CAT_VALID =2; //info about Condition Access in current structure is valid
PMT_VALID =4;
SDT_VALID =8;

(*const for wCount, wChCount*)
CURRENT_NONE = $FFFF;

TPI_CA_COUNT =64;
TPI_AUD_COUNT =16;
TXT_MGZ_COUNT =4;
TPI_CH_COUNT =128;
TPI_NAME_LEN =64;

//For AUD_PID->dwFlags
DVB_AUDIO_ISO11172 =$00;
DVB_AUDIO_ISO13818 =$01;
DVB_AUDIO_AC3 =$02;
DVB_AUDIO_TYPEMASK =$0F;

type

CA_INFO = packed record
wCount: WORD; (*Quantity of PIDs*)
wCurrent: WORD; //Current PID. For current EMM dont use this field. use Channel.wEMMCurrent instead!
wCA_Type: packed array [0..TPI_CA_COUNT-1] of WORD; (*Type of CA system (i.e. Viaccess = 0x0500)*)
wPID: packed array [0..TPI_CA_COUNT-1] of WORD; (*PID for CA*)
end;

AUD_PID = packed record
wCount: WORD; (*Quantity of PIDs*)
wCurrent: WORD; (*Current PID*)
wPID: packed array [0..TPI_AUD_COUNT-1] of WORD; (*PID Smile*)
dwFlags: packed array [0..TPI_AUD_COUNT-1] of DWORD; //see DVB_AUDIO_*
end;

TXT_MGZ = packed record
wCount: WORD; //Quantity of Magazines
wCurrent: WORD; //Current Magazine
wOpt: packed array [0..TXT_MGZ_COUNT-1] of WORD; //Option bits: 0-7 page number, 8-10 - magazine number, 11-15 - Teletext Type
dwLang: packed array [0..TXT_MGZ_COUNT-1] of DWORD; //Language ID for Magazine
end;

CH_INFO = packed record
wDataValid: WORD; //Flag for validating data in all fields except wSID and wPMT (validate these fields by TP_INFO.wDataValid)
dwUserFlags: DWORD; //User defined flags or variable;
wSID: WORD; //Channel ID
wPMT: WORD; //PID for Program Map Table
wTeletext: WORD; //Teletext PID. 0 if none
wType: WORD;
wScrambled: WORD;
Ch_Name: packed array [0..TPI_NAME_LEN-1] of char; (*Channel Name*)
Prov_Name: packed array [0..TPI_NAME_LEN-1] of char; (*Provider Name*)
wPCR: WORD; //PID for Program Clock Reference
wVideo: WORD; //Video PID
Audio: AUD_PID; //Array of Audio PIDs
TxtMgz: TXT_MGZ; //Array of Teletext Magazines
wEMMCurrent: WORD; //Current EMM pid for current channel
ECM: CA_INFO; //Array or ECM PIDs
//Date: tDatetime;
end;

TP_INFO = packed record
HdrVer: DWORD; //Structure version. Please check this for sure data is in expected form*)
wDataValid: WORD; //Flag for validating data in wChCount, wChCurrent, all EMMs, all wPMT and all wSID*)
dwUserFlags: DWORD; //User defined flags or variable
DiSEqData: packed array [0..31] of BYTE; //Data for DiSEq
bDiSEqLen: BYTE; //Length of DiSEq Data
bDiSEqToneburst:BYTE;
dwSymbRate: DWORD; //Symbol Rate of Transponder (DVB-S and DVB-C only)
dwFreq: DWORD; //Frequency
dwLNB_Power: DWORD; //Power for LNB (DVB-S only)
dwInversion: DWORD; //Spectral Inversion
dwLOF: DWORD; //LOF for DVB-S, QAM for DVB-C
bF22KHz: BOOL; //ON/OFF 22KHz (DVB-S only)
dwViterbi: DWORD; //Viterbi Rate (DVB-S only)
wChCount: WORD; //Quantity of Channels of current transponder
wChCurrent: WORD; //Current Channel
Channel: packed array [0..TPI_CH_COUNT-1] of CH_INFO; //Channel Map
EMM: CA_INFO;//Array of EMM PIDs
wSatID: WORD; //it's a position of Satellite in degrees. i.e.: 0360, 0192, 0050..
//mustbe filled by application before set-up tuner if it supports DiSEqC plugins.
wNetID: WORD; //Network ID
wTSID: WORD; //Transport Stream ID
end;

pTP_INFO = ^TP_INFO;

(*Main management function to SET/GET parameters about transponder and channels*)
function DVBParams(TP_Info: pTP_INFO; Options: DWORD): DWORD; stdcall; external 'DVBCore.dll';

//**************************** NETWORK INFO *******************************************************************************

const

DVB_FEC_NOTDEFINED =0;
DVB_FEC_12 =1;
DVB_FEC_23 =2;
DVB_FEC_34 =3;
DVB_FEC_56 =4;
DVB_FEC_78 =5;
DVB_FEC_NOCODING =15;

DVB_MOD_NOTDEFINED =0;
DVB_MOD_QPSK =1;

DVB_POL_LINEAR_HORZ =0;
DVB_POL_LINEAR_VERT =1;
DVB_POL_CIRCULAR_LEFT =2;
DVB_POL_CIRCULAR_RIGHT =3;

type
TPN_INFO = packed record
dwFreq: DWORD;
dwSymbRate: DWORD;
wOrbPos: WORD;
wNumber: WORD;
bWestEast: BYTE;
bPolar: BYTE;
bMod: BYTE;
bFEC: BYTE;
end;

NET_INFO = packed record
HdrVer: DWORD;
NetID: WORD;
NetName: packed array[0..127] of char;
wCount: WORD;
Transponder: packed array[0..99] of TPN_INFO;
end;

pNET_INFO = ^NET_INFO;

function DVBGetNetInfo(NITInfo: pNET_INFO): DWORD; stdcall; external 'DVBCore.dll';

//**************************** AV Control Functions ***********************************************************************

const

DVBAV_SETVIDEOOUT =1; //Set Video Output Mode. Param points to DWORD type of output.
DVBAV_SETAUDIOVOL =2; //Set Audio Volume. Param is pointer to 2 bytes: Param[0] - left volume, Param[1] - right volume. values 0..100 are acceptable
DVBAV_SETAUDIOMUTE =3; //Mute/Unmute Audio. Param points to DWORD 0 - unmute, 1 - mute
DVBAV_GETVIDEOSTATE =4; //Get Video State. Param points to structure VIDEOSTATE
DVBAV_SETVIDEOSTANDARD =5;
DVBAV_SHOWTESTBAR =6;

DVB_AVOPT_NO_VOUT =0; //disable analog Output
DVB_AVOPT_CVBS_RGB_OUT =1; //Composite and RGB Out
DVB_AVOPT_CVBS_YC_OUT =2; //Composite and S-Video Out
DVB_AVOPT_YC_OUT =3; //Only S-Video Out

DVB_AVOPT_AUDIOUNMUTE =0;
DVB_AVOPT_AUDIOMUTE =1;

DVB_AVOPT_VS_PAL_MODE =0;
DVB_AVOPT_VS_NTSC_MODE =1;
// DVB_AVOPT_VS_AUTO_MODE =2; Seems doesnt work.

DVB_AVOPT_TEST_BAR_OFF =0;
DVB_AVOPT_TEST_BAR_1 =1;
DVB_AVOPT_TEST_BAR_2 =2;

type

VIDEOSTATE = packed record
ProcessingState: WORD;
CommandID: WORD;
dummy1: WORD;
dummy2: WORD;
RateBuffFullness: WORD;
dummy3: WORD;
BytesDecoded: WORD;
SkippedPictures: WORD;
RepeatedPictures: WORD;
MostRecentPTS: WORD;
LastPicture: WORD;
InitDone: WORD;
FreezeIndex: WORD;
FindIndex: WORD;
DistanceI: WORD;
ThresholdPTS: WORD;
dummy4: WORD;
dummy5: WORD;
DisablePTSFilt: WORD;
HSize: WORD;
VSize: WORD;
AspectRatio: WORD;
FrameRate: WORD;
BitRate: WORD;
VBVBuffSize: WORD;
ConstParamFlag: WORD;
IntraQ: WORD;
NonIntraQ: WORD;
FrameInterval: WORD;
HeaderBackup: WORD;
RedHeaderFlag: WORD;
SeqExtension: WORD;
GOPTimeCode1: WORD;
GOPTimeCode2: WORD;
ClosedGOP: WORD;
PICHeadTempRef: WORD;
SegHeaderExt: WORD;
ColorDesc: WORD;
ColorPrim: WORD;
TransferChar: WORD;
MatrixCoeff: WORD;
DisplayHSize: WORD;
DisplayVSize: WORD;
GOPHeader: WORD;
TimeCodeW1: WORD;
TimeCodeW2: WORD;
end;

//SET/GET AV Options
function DVBAVControl(Param: Pointer; Options: DWORD): DWORD; stdcall; external 'DVBCore.dll';

//****************************************** FILTER FUNCTIONS *************************************************************

const

//Filter Types
FT_NO_FILTER_TYPE =0;
FT_STREAMING_FILTER =1; //Main type of Filter
FT_PIPING_FILTER =2;
FT_SECTION_FILTER =3;
FT_PES_FILTER =4;

//Alternative Section Filter. Behaviour is the same as FT_SECTION_FILTER but might be mixed
//with FT_STREAMING_FILTER from one PID. Also multiple masks suppirted!
//I strongly suggest use this kind of filter instead FT_SECTION_FILTER.
FT_ALT_SECTION_FILTER =100;

//Experimetal Alternative High-Speed Section filter.
//I not recommend use it now.
//Need some more testings for compatibility.
FT_ALT_HS_SECTION_FILTER =101;

//Capture full TS packets (i.e. 188 bytes per packet)
//SkyStar-1 doesn't support this filter!
//You may grab it from SS1, but these packets will be emulated.
FT_TS_STREAMING_FILTER =90;


FT_CMD_CLOSE =$80000001; //Filter to be closed
FT_CMD_CHANNEL_WILLBE_CHANGED =$80000100; //Channel is going to change
FT_CMD_CHANNEL_CHANGED =$80000101; //Channel was changed
FT_CMD_STOPCAPTURE =$80000102; //Stop Capture AV
FT_CMD_STARTCAPTURE =$80000103; //Start Capture AV
FT_CMD_TRANSPONDER_WILLBE_CHANGED =$80000104; //This Event may be used for plugin that controls LNB switches. Satellite ID (SatID = tenths of degrees genarally) passed as parameter.
FT_CMD_TRANSPONDER_CHANGED =$80000105;
FT_CMD_DISEQC_WILLBE_CHANGED =$80000106;
FT_CMD_DISEQC_CHANGED =$80000107;
FT_CMD_NEW_CK =$80000200; // New CommonKey for descrambler(ECD). Buf - is pointer to new key structure.
FT_CMD_GET_PIDFILTERLIST =$80000201; // DEBUG. Get list of PID filters. Param is pointer to DWORD[64]
FT_CMD_NUKE_IDLE_FILTERS =$80000202; // DEBUG. Nuke filter which have gave 0 pakets in specified time. Param - time in milliseconds
FT_CMD_CANCEL_SCAN_TP =$80000203; // Cancel scan current TP when scanning in fast mode (need calling from separate thread to stop).

FT_ERRREP_DIRECTSHOW =$80001001; // DirectShow Error. Buf - is pointer to error string.

FT_CMD_USER =$F0000000; // to 0xFFFFFFFF User defined commands

// Pass HOOK_MAINSTREAM value to DVBAddFilter to hook main AV stream
// ATTENTION: AV stream is very high loaded. Use it carefully..
HOOK_MAINSTREAM_PS =$4000;
HOOK_MAINSTREAM_AVPES =$4010; //Only For SkyStar-1
HOOK_COMMANDS =$4001; //Filter to recieve commands FT_CMD_*
HOOK_ACTIVEPIDS_TS =$4002; //Filter to recieve filtered Stream with All active PIDs. HUGE TRAFFIC!
HOOK_ACTIVEPIDS_TS_EX =$4003; //Filter to recieve filtered Stream with All active PIDs. HUGE TRAFFIC!
HOOK_RAWSTREAM=$4004;

type
(* Type of callback function for filter implementation*)
LPCB_STREAMHOOK = procedure(Buf: PByteArray; Len: Cardinal; hFilter: DWORD); stdcall;

//Add PID parser
function DVBAddFilter(wPID: WORD; StreamHook: LPCB_STREAMHOOK; FilterType: DWORD =FT_STREAMING_FILTER {or FT_ALT_SECTION_FILTER}; pbFilterData: pBYTE = Nil; pbFilterMask: pBYTE = Nil; bLength: BYTE = 0): DWORD; stdcall; external 'DVBCore.dll';

//Delete PID parser
function DVBDelFilter(hFilter: DWORD): BOOL; stdcall; external 'DVBCore.dll';

//Send command directly to FirmWare (i.e. CW for discrambler)
procedure DVBSendSAACmd(CmdBuf: pWORD; CmdLen: integer); stdcall; external 'DVBCore.dll';

//Send Message to Filter(s)
procedure DVBSendFltMsg(hFilter, Msg, Param: DWORD); stdcall; external 'DVBCore.dll';

//********************************* REMOTE CONTROL FUNCTIONS *********************************************
// only RC5 standard supported.

// functions for easy keys management.
function DVB_RC5_KEYCODE(a: dword): dword;
function DVB_RC5_DEVADDR(a: dword): dword;
function DVB_RC5_KEYPUSHED(a: dword): boolean;
function DVB_RC5_KEYRELEASED(a: dword): boolean;

const
// Several RC5 Keycodes. Just for note. Actual code assignment depends on used Remote Control
DVB_RC5KEY_0 =$00;
DVB_RC5KEY_1 =$01;
DVB_RC5KEY_2 =$02;
DVB_RC5KEY_3 =$03;
DVB_RC5KEY_4 =$04;
DVB_RC5KEY_5 =$05;
DVB_RC5KEY_6 =$06;
DVB_RC5KEY_7 =$07;
DVB_RC5KEY_8 =$08;
DVB_RC5KEY_9 =$09;
DVB_RC5KEY_TV =$0F;
DVB_RC5KEY_RADIO =$0C;
DVB_RC5KEY_UP =$20;
DVB_RC5KEY_LEFT =$11;
DVB_RC5KEY_RIGHT =$10;
DVB_RC5KEY_DOWN =$21;
DVB_RC5KEY_FULLSCR =$2E;
DVB_RC5KEY_MUTE =$0D;
DVB_RC5KEY_SOURCE =$22;
DVB_RC5KEY_RESERVED =$1E;
DVB_RC5KEY_MINIMIZE =$26;

//Pass IRCallBack = NULL to disable remote control
function DVBSetRemoteControl(IRCallBack: LPCB_STREAMHOOK; wRCDevAddr: WORD = $FFFF): DWORD; stdcall; external 'DVBCore.dll';

//********************************* TUNER FUNCTIONS ***********************************************************************

const

// for Type field
DVB_FE_UNKNOWN =0;
DVB_FE_SATELLITE =DVBDEV_FLAG_DVB_S;
DVB_FE_CABLE =DVBDEV_FLAG_DVB_C;
DVB_FE_TERRESTRIAL =DVBDEV_FLAG_DVB_T;

type

//Tuner Hardware Info/Capabilities
DVB_TUNER_INFO = packed record
HdrVer: DWORD;
Lock: DWORD;
nAFC: integer; // Frequency derivation in kHz
BER: DOUBLE; // Viterbi Bit Error Rate
Streaming: BYTE; // 1 - streaming, 0 - not streaming (since last call of DVBGetTunerInfo)
SNR_SQE: BYTE; // 0..255 - Gives an idea of the S/N of the channel
Level: WORD; // Level 0..100
Quality: WORD; // Quality 0..100
FreqMin: DWORD; // Min Supported Frequency
FreqMax: DWORD; // Max Supported Frequency
SRMin: DWORD; // Min Supported SymbolRate
SRMax: DWORD; // Max Supported SymbolRate
BandWidth: DWORD; // Bandwidth (i have no idea about what is it)
GapMin: DWORD; // Min of Gap (i have no idea about what is it)
GapMax: DWORD; // Max of Gap (i have no idea about what is it)

dwType: DWORD; // Type of card
Capabilities: DWORD;

//below are only for DVB-T cards
//i don't know meaning of these fields. i haven't TERRESTRIAL card

InitBit: BOOL;
SyncWord: WORD;
Length: BYTE;
FrameNr: BYTE;
Constellation: BYTE;
Hierarchy: BYTE;
CodeRateHP: BYTE;
CodeRateLP: BYTE;
Guard: BYTE;
Mode: BYTE;
ReservedX: WORD;
BCH_Code: WORD;
TPS_Lock: BOOL;
TPS_Valid: BOOL;
TimeSync: BOOL;
AFC_Lock: BOOL;
Freq_Offset:integer;
end;

pDVB_TUNER_INFO = ^DVB_TUNER_INFO;

//Get Info about Tuner state and capabilities
function DVBGetTunerInfo(TunerInfo: pDVB_TUNER_INFO): DWORD; stdcall; external 'DVBCore.dll';


//*************************************** OSD ***********************************************************
//TT OSD API. OSD in TT implementation is not so useful as i expected. OSD Memory is too small Sad(
//So, i decided not to work on it and include it as is..
//Seams, there is no way to increase OSD memory without intervention into FirmWare.

const

//for field trans
OSDTT_TRANSP_FLAG =1;
OSDTT_PALETTE_FLAG =2;

//for field colordepth
OSDTT_NOPALET =0; // No palette
OSDTT_PAL1BIT =2; // 2 colors for 1 Bit Palette
OSDTT_PAL2BIT =4; // 4 colors for 2 bit palette
OSDTT_PAL4BIT =16; // 16 colors for 4 bit palette
OSDTT_PAL8BIT =256; // 256 colors for 16 bit palette

//for field DisplayType
OSDTT_BITMAP1 =0; // 1 bit bitmap
OSDTT_BITMAP2 =1; // 2 bit bitmap
OSDTT_BITMAP4 =2; // 4 bit bitmap
OSDTT_BITMAP8 =3; // 8 bit bitmap
OSDTT_BITMAP1HR =4; // 1 Bit bitmap half resolution
OSDTT_BITMAP2HR =5; // 2 bit bitmap half resolution
OSDTT_BITMAP4HR =6; // 4 bit bitmap half resolution
OSDTT_BITMAP8HR =7; // 8 bit bitmap half resolution
OSDTT_YCRCB422 =8; // 4:2:2 YCRCB Graphic Display
OSDTT_YCRCB444 =9; // 4:4:4 YCRCB Graphic Display
OSDTT_YCRCB444HR =10; // 4:4:4 YCRCB graphic half resolution
OSDTT_VIDEOTSIZE =11; // Full Size MPEG Video Display
OSDTT_VIDEOHSIZE =12; // MPEG Video Display Half Resolution
OSDTT_VIDEOQSIZE =13; // MPEG Video Display Quarter Resolution
OSDTT_VIDEOESIZE =14; // MPEG Video Display Eighth Resolution
OSDTT_CURSOR =15; // Cursor

//TT functions as is...
function DVBOSDTTCreateWindow(windownr: BYTE; DisplayType: DWORD; width, height: DWORD): DWORD; stdcall; external 'DVBCore.dll';
function DVBOSDTTDestroyWindow(windownr: BYTE): DWORD; stdcall; external 'DVBCore.dll';
function DVBOSDTTResetBlend(windownr: BYTE): DWORD; stdcall; external 'DVBCore.dll';
function DVBOSDTTSetColorBlend(windownr: BYTE): DWORD; stdcall; external 'DVBCore.dll';
function DVBOSDTTSetWindowBlend(windownr, blending: BYTE): DWORD; stdcall; external 'DVBCore.dll';
function DVBOSDTTSetBlend(windownr: BYTE; colordepth, index: DWORD; blending: BYTE): DWORD; stdcall; external 'DVBCore.dll';
function DVBOSDTTSetColor(windownr: BYTE; colordepth: DWORD; index, colorHi, colorLo: WORD): DWORD; stdcall; external 'DVBCore.dll';
function DVBOSDTTBringToTop(windownr: BYTE): DWORD; stdcall; external 'DVBCore.dll';
function DVBOSDTTSetFont(windownr, fontsize: BYTE; colorFG, colorBG: WORD): DWORD; stdcall; external 'DVBCore.dll';
function DVBOSDTTWriteText(windownr: BYTE; X, Y: WORD; length: BYTE; cText: pchar): DWORD; stdcall; external 'DVBCore.dll';
function DVBOSDTTHideWindow(windownr: BYTE): DWORD; stdcall; external 'DVBCore.dll';
function DVBOSDTTMoveWindowRel(windownr: BYTE; X, Y: WORD): DWORD; stdcall; external 'DVBCore.dll';
function DVBOSDTTMoveWindowAbs(windownr: BYTE; X, Y: WORD): DWORD; stdcall; external 'DVBCore.dll';
function DVBOSDTTSetWindowTrans(windownr: BYTE; trans: WORD): DWORD; stdcall; external 'DVBCore.dll';
function DVBOSDTTLoadBMP(FileName: pchar): DWORD; stdcall; external 'DVBCore.dll';
function DVBOSDTTBlitBitmap(windownr:BYTE; x, y, trans: WORD): DWORD; stdcall; external 'DVBCore.dll';
function DVBOSDTTReleaseBitmap: DWORD; stdcall; external 'DVBCore.dll';
function DVBOSDTTDrawLine(windownr: BYTE; X, Y, dx, dy, colornr: WORD): DWORD; stdcall; external 'DVBCore.dll';
function DVBOSDTTDrawBlock(windownr: BYTE; X, Y, dx, dy, colornr: WORD): DWORD; stdcall; external 'DVBCore.dll';

//integral function. It loads BMP, blits to window then release.
function DVBOSDLoadBMPToWnd(FileName: pchar; windownr:BYTE; x, y, trans: WORD): DWORD; stdcall; external 'DVBCore.dll';

//********************************** HARDWRE DISPLAY FUNCTIONS ************************************************************

const

DVB_HWDISP_CREATE =$0001;
DVB_HWDISP_CLOSE =$0002;
DVB_HWDISP_GETWND =$0004;
DVB_HWDISP_GETPARENT =$0008;
DVB_HWDISP_GETDDPOINTER =$0010;
DVB_HWDISP_SETTVNORMVALUES =$0020;
DVB_HWDISP_GETDDMODE =$0040;
DVB_HWDISP_GETVGA =$0080;
DVB_HWDISP_SETTVRATIO =$0100;
DVB_HWDISP_SETMOVE =$0200;
DVB_HWDISP_SETBOB =$0400;
DVB_HWDISP_SETMAX =$0800;
DVB_HWDISP_SETCAPTION =$1000;
DVB_HWDISP_PURGECAPTION =$2000;
DVB_HWDISP_SETPICPARAMS =$4000;
DVB_HWDISP_GETPICPARAMS =$8000;

DVB_HWDISP_SETBOBDEF =$10000;
DVB_HWDISP_SETMAXDEF =$20000;

DVB_HWDISPMODE_AUTO =0;
DVB_HWDISPMODE_OVERLAY =1;
DVB_HWDISPMODE_SURFACE =2;
DVB_HWDISPMODE_INLAY =3; //only FullScreen

DVB_HWDISP_PAL =0;
DVB_HWDISP_NTSC =1;
DVB_HWDISP_AUTO =2;

DVB_HWDISP_RATIO_FREE =0;
DVB_HWDISP_RATIO_4_3 =1;
DVB_HWDISP_RATIO_16_9 =2;

DVB_HWDISPNORM_MAX =2;

type
HW_DISPLAY = packed record
HdrVer: DWORD;
hParentWindow: HWND;
hVideoWindow: HWND;
vDDPointer: Pointer;
X: integer;
Y: integer;
Width: integer;
Height: integer;
bFullScreen: BOOL;
bOddEven: BOOL;
dwStyle: DWORD;
dwDDMode: DWORD;
dwTVSys: DWORD;
dwTVRatio: DWORD;
wOffsetX: WORD;
wBorderX: WORD;
wOffsetY: WORD;
wBorderY: WORD;
dwVGAHeight: DWORD;
dwVGAWidth: DWORD;
dwVGARGBBitCount: DWORD;
dwVGARefreshRate: DWORD;
bMove: BOOL;
bBOB: BOOL;
bMAX: BOOL;
nBrightness: BYTE;
nContrast: BYTE;
nSaturation: BYTE;
nDummy: BYTE;
end;
pHW_DISPLAY = ^HW_DISPLAY;

function DVBHWDisplay(Display: pHW_DISPLAY; Options: DWORD): DWORD; stdcall; external 'DVBCore.dll';

//********************************** DIRECTSHOW DISPLAY FUNCTIONS ***********************************************************

const

DVB_DSDISP_NOTACTIVE =0;
DVB_DSDISP_CREATE =1;
DVB_DSDISP_CLOSE =2;
DVB_DSDISP_STOP =3;
DVB_DSDISP_PLAY =4;
DVB_DSDISP_GETSTATE =5;
DVB_DSDISP_WINDOW =6;
DVB_DSDISP_FULLSCREEN=7;
DVB_DSDISP_SHOWCURSOR=8;
DVB_DSDISP_HIDECURSOR=9;

type
DS_FLT_INFO = packed record
Name: array[0..99] of char;
HasProperties: BOOL;
lpISPP: DWORD;
lpIBF: DWORD;
dwReserved: DWORD;
end;

DS_DISPLAY = packed record
HdrVer: DWORD;
hParentWindow: HWND; //currently unsupported
hVideoWindow: HWND; //currently unsupported
dwOrigWidth: DWORD; //currently unsupported
dwOrigHeight: DWORD; //currently unsupported
dwAspectRatio: DWORD; //currently unsupported
State: DWORD; //can be one of DVB_DSDISP_NOTACTIVE, DVB_DSDISP_STOP or DVB_DSDISP_PLAY
FullScreen: DWORD; //0 - means no fullscreen
pIGraphBuilder: DWORD; //currently unsupported
dummy1: DWORD; //reserved
dummy2: DWORD; //reserved
XGRName: array[0..499] of char;
FilterCount: integer;
Filter: array[0..19] of DS_FLT_INFO;
end;

pDS_DISPLAY = ^DS_DISPLAY;

function DVBDSDisplay(Display: pDS_DISPLAY; Options: DWORD): DWORD; stdcall; external 'DVBCore.dll';

//********************************* PLAYBACK FUNCTIONS *******************************************

const

// Stream Types for wStreamType
// New Names
DVB_ST_MP2 =$001; // MPEG1/2-LayerII Audio-Frames (*.mp2)
DVB_ST_AVPES =$003; // packetized Audio- and Video-PES (*.pva)
DVB_ST_PS =$004; // Audio- and Video-Program-Stream (*.mpeg)
DVB_ST_AUTO =$100; // Autodetect.

//wPlayMode types
DVB_PM_Stop =0;
DVB_PM_Playback =2; // dwPlayOpt - begin position in ms
DVB_PM_PlaybackPause =3;
DVB_PM_PlaybackSlow =4; // dwPlayOpt - how many times a picture is repeated
DVB_PM_PlaybackFast =5; // dwPlayOpt = 1 for play I- and P-frames; dwPlayOpt = 0 for play I-frames only
DVB_PM_Close =6; // CloseFile. It's allowed open new file without close previous one. Old file will be closed then new will be opened

ONLY_I_AND_P_FRAMES =1; // for dwPlayOpt if wPlayMode = DVB_PM_PlaybackFast

//Options
DVB_FP_PLAYBACK =$100;
DVB_FP_GETSTATUS =$200;
DVB_FP_SETPOSITION =$400;

// allowed playback state transitions (functions return FALSE otherwise):
// from Stop to Playback
// from Playback to Stop, PlaybackPause, PlaybackSlow, PlaybackFast, PlaybackPause
// from PlaybackPause to Stop, Playback, PlaybackSlow, PlaybackFast
// from PlaybackFast to Stop, PlaybackPause, PlaybackSlow, Playback
// from PlaybackSlow to Stop, PlaybackPause, Playback, PlaybackFast

type

FILE_PLAYBACK = packed record
HdrVer: DWORD;
wStreamType: WORD; // currently only ST_AudioMp2 and ST_AudioVideoPPES types supported
wPlayMode: WORD; // see DVB_PM_* constants. Also changed after DVB_FP_GETSTATUS
dwPlayOpt: DWORD; // depends on wPlayMode. See comments for DVB_PM_*
dwTotalTime: DWORD; //
dwDataRate: DWORD; //
dwElapsedTime: DWORD; //
ullFilePos: int64; // > Changed after DVB_FP_GETSTATUS
ullFileSize: int64; // >
end;

pFILE_PLAYBACK = ^FILE_PLAYBACK;

//SoftMode and recording mustbe turned off (TP_INFO.dwStreamType = ST_NONE, then DVBParams must be
//called with SET_FORMAT option) before playback!
//FileName mustbe NOT NULL for open a new file and mustbe NULL for operations on current file
function DVBFilePlayback(FilePlayback: pFILE_PLAYBACK; FileName: PChar; Options: DWORD): DWORD; stdcall; external 'DVBCore.dll';


//****************************** Electronic Program Guide ****************************************

const
DVB_EPG_STOP =$0000;
DVB_EPG_START =$0001;
DVB_EPG_GETEVENTS =$0002;
DVB_EPG_GETNEWEVENTS =$0102;
DVB_EPG_GETCHLIST =$0003; //only wSID, wNetID and dwEventCount are valid in structure EPG_EVENT
DVB_EPG_GETNEWCHLIST =$0103; //only wSID, wNetID and dwEventCount are valid in structure EPG_EVENT

DVB_EPG_GET_BYCOOKIE =$0010; //Get events sequentally dwBeginTime must be (DWORD *Cookie) to get event by event
//First Call must have *Cookie = 0
//EPGProc must points to EPG_EVENT structure.
//If there is no more events in queue then DVBEPG returns DVB_ERROR_RESOURCES.

DVB_EPG_EXCLEVENT =$0011;
DVB_EPG_MINTIME =$0012;

DVB_EPG_PRESENT =$1000;
DVB_EPG_FOLLOWING =$2000;

//Running Status
DVB_EPG_RS_UNDEFINED =0;
DVB_EPG_RS_SOONSTARTS =1;
DVB_EPG_RS_PAUSING =2;
DVB_EPG_RS_RUNNING =3;

type
EPG_DESCR = packed record
Lang: DWORD; //Language ID according ISO 639-2 (three bytes on language name plus zero byte)
EventName: PChar; //Event name
ShortDescr: PChar; //Short Description
ItemizedDescr: PChar; //Itemized Description in form: item: text
ExtendedDescr: PChar; //Extended Description
end;

EPG_EVENT = packed record
HdrVer: DWORD;
dwStartTime: DWORD; //Start time of event in UNIX form
dwDuration: DWORD; //Duration of event in UNIX form
dwEventCount: DWORD; //only for DVB_EPG_GETCHLIST.
wSID: WORD; //Channel ID
wNetID: WORD; //Network ID
wEventID: WORD; //Event ID
wRunningStatus: WORD; //see DVB_EPG_RS*
wLangCount: WORD; //Count of languages of description
Descr: array[0..4] of EPG_DESCR; //Event Descriptions
end;

pEPG_EVENT = ^EPG_EVENT;

LPCB_EPGPROC = function (EPGEvent: pEPG_EVENT): BOOL; stdcall;

function DVBEPG(Cmd: DWORD; EPGProc: LPCB_EPGPROC = nil; wSID: WORD =0; wNetID: WORD=0; dwBeginTime: DWORD=0; dwEndTime: DWORD=$FFFFFFFF):DWORD; stdcall; external 'DVBCore.dll';

//********************************* SERVICE FUNCTIONS *********************************************************************
//These functions aren't intended to use. Simple, ignore it.

function DVB7146GetReg(dwReg: DWORD): DWORD; stdcall; external 'DVBCore.dll';
procedure DVB7146SetReg(dwReg, dwValue, dwUpload: DWORD); stdcall; external 'DVBCore.dll';
function DVB7146DEBIOutW(wReg, wData: WORD): BOOL; stdcall; external 'DVBCore.dll';
function DVB7146DEBIInW(wReg: WORD): WORD; stdcall; external 'DVBCore.dll';
function DVB7146DEBIGetLastError: DWORD; stdcall; external 'DVBCore.dll';

//************************************************************************************************
//Don't use this function in final release of application!!
//There are lot of incompatibilities with other functions and plugins!!!
//This is only for debugging purposes.

function DVBDbgSetChannel( wDiSEqC: BYTE;
dwFreq: DWORD;
dwSymbRate: DWORD;
dwLOF: DWORD;
bLNBPower: BOOL;
bPol: BOOL;
bBand: BOOL;
wAPID: WORD;
wVPID: WORD=0;
wPCR: WORD=0;
wAC3PID: WORD=0;
wCAType: WORD=0;
wEMM: WORD=0;
wECM: WORD=0;
bNeedCapture: BOOL = false): DWORD; stdcall; external 'DVBCore.dll';

//these constants are valid for wDiSEqC parameter:
// DISEQC_NONE
// DISEQC_SIMPLE_LNB1
// DISEQC_SIMPLE_LNB2
// DISEQC_V1_0_LNB1
// DISEQC_V1_0_LNB2
// DISEQC_V1_0_LNB3
// DISEQC_V1_0_LNB4

//************************ COMMON INTERFACE FUNCTIONS ********************************************

const

FT_CI_SLOT_EMPTY =$81000000;
FT_CI_SLOT_MODULE_INSERTED =$81000001;
FT_CI_SLOT_MODULE_OK =$81000002;

FT_CI_PSI_COMPLETE =$81000010;
FT_CI_SWITCH_PRG_INALID_DATA =$81000011;
FT_CI_SWITCH_PRG_NO_CA =$81000012;
FT_CI_SWITCH_PRG_OK =$81000013;

FT_CI_DISPLAY_OFF =$81000020;
FT_CI_DISPLAY_STRING =$81000021;
FT_CI_DISPLAY_LIST =$81000022;
FT_CI_DISPLAY_MENU =$81000023;
FT_CI_INPUT_REQUEST =$81000024;

DVB_CI_SLOT_EMPTY =0;
DVB_CI_SLOT_MODULE_INSERTED =1;
DVB_CI_SLOT_MODULE_OK =2;

DVB_CI_PRG_NOTREADY =0;
DVB_CI_PRG_PSI_COMPLETE =1;
DVB_CI_PRG_INALID_DATA =2;
DVB_CI_PRG_NO_CA =3;
DVB_CI_PTG_SWITCH_OK =4;

function DVBCIOpen: DWORD; stdcall; external 'DVBCore.dll';
function DVBCIClose: DWORD; stdcall; external 'DVBCore.dll';
function DVBCIEnterMenu(Slot: DWORD): DWORD; stdcall; external 'DVBCore.dll';
function DVBCIGetDisplayInfo(Slot: DWORD; Buf: Pointer; BufSize: DWORD; ActualSize: PDWORD; nType: PDWORD; Counter: PDWORD): DWORD; stdcall; external 'DVBCore.dll';
function DVBCIGetSlotInfo(Slot: DWORD; Name: Pointer; NameLen: DWORD; SlotStatus: PDWORD; PrgStatus: PDWORD; InMenu: PBOOL; AnswLen: PDWORD): DWORD; stdcall; external 'DVBCore.dll';
function DVBCIGetCA(Slot: DWORD; CASupp: Pointer; BufSize: DWORD; ActualSize: PDWORD): DWORD; stdcall; external 'DVBCore.dll';
function DVBCISendAnswer(Slot: DWORD; Key: DWORD; Buf: Pointer; Len: DWORD): DWORD; stdcall; external 'DVBCore.dll';

//*************************************************************************************************************************


//**********************************************
// *
// DVBCore DirectShow Filter related stuffs *
// *
//**********************************************

const

CLSID_DVBCoreSrc: TGUID ='{FACE0501-DECC-11CF-A66B-00AA00BF96AA}';
IID_IDVBCoreSrc: TGUID ='{FACE0511-DECC-11CF-A66B-00AA00BF96AA}';

// DirectShow events.
FT_EVT_AVFORMAT_READY = $82000001; // Param = 0 for Audio, Param = 1 for Video;
FT_EVT_AVFORMAT_CHANGED = $82000002; // Param = 0 for Audio, Param = 1 for Video;

// TIMESHIFT FUNCTIONS
// TimeShift can work only in DirectShow Mode. Thus management only through COM Interface.
// All Positions/Sizes are in Units.
// 1 Unit ~ 7400 bytes

type
IDVBCoreSrc = interface(IUnknown)
['{FACE0511-DECC-11CF-A66B-00AA00BF96AA}']

//Bytes related functions.
//All positions in bytes, but real positions will be automatic rounded to unit size.

function SetBufSize64 (FileName: PChar;
Size: int64;
ResultSize: PInt64
): HResult; stdcall;

function GetTimes64 (HeadPos, //Head in PTS
MaxPlayPos, //Maximal available position for playback in PTS
PlayPos, //Current playback position in PTS
MaxRecPos, //Maximal available position for recording in PTS
RecPos: PInt64 //Current recording position in PTS
): HResult; stdcall;

//Blocks related functions.
function GetPositions(BufferSize, //Length of buffer [in units]
MaxPlayPos, //Maximal available position for playback [in units]
PlayPos, //Current playback position
MaxRecPos, //Maximal available position for recording [in units]
RecPos: PInteger //Current recording position
): HResult; stdcall;

function SetPlayPos(PlayPos: integer): HResult; stdcall;
function SetRecPos(RecPos: integer): HResult; stdcall;
function SetRecSpeed(Speed: integer): HResult; stdcall;
end;


//**********************************************
// *
// MyTheatre related stuffs *
// *
//**********************************************

type
MTEPG_EVENT = packed record
Sync: THandle; //Sync Event which must be created as Manual-reset event.
EPGEvent: EPG_EVENT;
end;

pMTEPG_EVENT = ^MTEPG_EVENT;

const

MT_CMD_NEW_EPG_EVENT = $90000001;
// This filter command may be used by external EPG parser to
// add event into MyTheatre EPG DataBase (see function DVBSendFltMsg)
// Param must be pointer to MTEPG_EVENT structure
//
// to send EPG event to MT you need:
// 1) fill MTEPG_EVENT structure
// 2) Call DVBSendFltMsg(0, MT_CMD_NEW_EPG_EVENT, @MTEPG_EVENT);
// 3) wait for MTEPG_EVENT.Sync signalyze
// 4) reset event MTEPG_EVENT.Sync
// 5) go to 1)


// Command To Refresh Channel List of MyTheatre
MT_CMD_CHLIST_RECREATE = $90000002;

// Sitch channel by CHID. Param is CHID.
MT_CMD_SWITCH_CHAN_BY_CHID = $90000003;

// Sitch channel by Number. Param is Channel Number.
MT_CMD_SWITCH_CHAN_BY_NUM = $90000004;

type
PLG_INFO = packed record
hdrVer: DWORD; //Version of structure
dwShortCut: DWORD; //ShortCut for this plugin. actual type is Delphi's TShortCut
dwTTL: DWORD; //reserved. not used.
Name: packed array[0..99] of char;
end;

pPLG_INFO = ^PLG_INFO;

//Type of Plugin Functions
//MustBe named DVBPLGInit in Plugin dll
LPF_DVBPLGInit =function(CardType: DWORD; Handle: HWND; ExtraInfo: Pointer=nil): BOOL;stdcall;
//MustBe named DVBPLGCall in Plugin dll
LPF_DVBPLGCall =function(Code: DWORD =0; ExtraInfo: Pointer = nil): BOOL; stdcall;
//MustBe named DVBPLGGetInfo in Plugin dll
LPF_DVBPLGGetInfo =function(PLG_Info: pPLG_INFO): BOOL; stdcall;
//MustBe named DVBPLGClose in Plugin dll
LPF_DVBPLGClose =function(Reason: DWORD =0): BOOL;stdcall;

implementation

function DVB_RC5_KEYCODE(a: dword): dword;
begin
Result:=a and $3F;
end;

function DVB_RC5_DEVADDR(a: dword): dword;
begin
Result:=((a shr 6) and $001f);
end;

function DVB_RC5_KEYPUSHED(a: dword): boolean;
begin
Result:=(a and $8000)<>0;
end;

function DVB_RC5_KEYRELEASED(a: dword): boolean;
begin
Result:=not DVB_RC5_KEYPUSHED(a);
end;

end.