unit ECustomProperty;

interface

uses Windows, DirectShow9;

const IID_ICustomProp: TGUID = (D1:$89E5D015; D2:$223B; D3:$404D; D4:($8B, $D8, $01, $9A, $59, $87, $5B, $7E));

const C_Unknown  = 0;
      C_Contrast = 1;
      C_7620     = 2;
      C_9630     = 3;
      C_2610     = 4;
      C_3610     = 5;
      C_3620     = 6;
      C_AnalogCamera = 7;
      C_Analog700= 7;
      C_9121     = 8;
      C_5610     = 9;
      C_5620     = 10;
      C_2620     = 11;
      C_2630     = 12;
      C_M3100    = 13;
      C_MT9D111  = 14;
      C_Analog500= 15;

const REQADD_RESERVED			= 0;  //
      REQADD_INTERPOLATION= 1;  //  Режим интерполяции
      REQADD_NOISE			  = 2;  //  Уровень шумоподавления
      REQADD_AGAIN			  = 3;  //  Включение дополнительного усиления
      REQADD_SNAPSHOT			= 4;  //  SnapShot режим
      REQADD_SLAVEMODE		= 5;  //  Включение вдущиго/ведомого режима
      REQADD_RESERVED6		= 6;  //
      REQADD_RESERVED7		= 7;  //
      REQADD_JPEGQUALITY	= 8;  // JPEG Quality
      REQADD_RESERVED9		= 9;  //
      REQADD_CANCELFRAME	= 10;  // 10-CancelFrame

type
  tagEVSVideoProcAmpProperty = (
    EVSVideoProcAmp_Brightness,
    EVSVideoProcAmp_Contrast,
    EVSVideoProcAmp_BalanceRed,
    EVSVideoProcAmp_Saturation,
    EVSVideoProcAmp_Sharpness,
    EVSVideoProcAmp_Gamma,
    EVSVideoProcAmp_ColorEnable,
    EVSVideoProcAmp_BalanceBlue,
    EVSVideoProcAmp_BlackLevelControlMode,
    EVSVideoProcAmp_Gain
  );

  tagEVSCameraControlProperty = (
    EVSCameraControl_XPan,
    EVSCameraControl_YPan,
    EVSCameraControl_LoopAE,
    EVSCameraControl_Zoom,
    EVSCameraControl_Exposure,
    EVSCameraControl_TLine,
    EVSCameraControl_LevelAE
  );

  tagEVSAnalogCameraControlProperty = (
    EVSAnalogCameraControl_Gain_ADC,
    EVSAnalogCameraControl_BlackLevel_ADC,
    EVSAnalogCameraControl_BlackLevel_Manual,
    EVSAnalogCameraControl_BlackLevel_Mode,
    EVSAnalogCameraControl_Exposure,
    EVSAnalogCameraControl_Iris,
    EVSAnalogCameraControl_Focus
  );

type
  RegCustomProerty =
    (
      REQ_GET_DEVICE_ID   = 0,  // Get Device ID
      REQ_GET_STATE       = 1,  // Get State
      REQ_SET_VIDEO_INPUT = 2,  // Set Video Input 0-3 (for Contrast USB)
      REQ_RESERVED1       = 3,  // Reserved
      REQ_RESERVED2       = 4,  // Reserved
      REQ_SET_PORTD       = 5,  // Set PORTD
      REQ_SET_VIDEO_OUTPUT= 6,  // Set Video Output 0-3 (for Contrast USB)
      REQ_ADDITIONAL_MODE = 7   // Установка дополнительных режимов
    );
  TRegCustomProerty = RegCustomProerty;

  PKSPropertyCustomPropS = ^TKSPropertyCustomPropS;
  KSPROPERTY_CUSTOM_PROP_S = record
    Property_     : KSPROPERTY;
    Value1        : Longint;    // value to get or set
    Value2        : Longint;    // ------- // --------
    Value3        : Longint;    // ------- // --------
  end;
  PKSPROPERTY_CUSTOM_PROP_S = ^KSPROPERTY_CUSTOM_PROP_S;
  TKSPropertyCustomPropS = KSPROPERTY_CUSTOM_PROP_S;

procedure SetCustomProperty(const MyObjectHandle: THandle; Request: TRegCustomProerty; Value: Array of Integer);
procedure GetCustomProperty(const MyObjectHandle: THandle; Request: TRegCustomProerty; var Value: Array of Integer);


implementation

procedure SetCustomProperty(const MyObjectHandle: THandle; Request: TRegCustomProerty; Value: Array of Integer);
var BytesReturned: Longint;
    MyProperty: TKSPropertyCustomPropS;
begin
  MyProperty.Property_.Set_ := IID_ICustomProp;
  MyProperty.Property_.Id := Cardinal(Request);
  MyProperty.Property_.Flags := KSPROPERTY_TYPE_SET;
  MyProperty.Value1 := Value[0];
  if High(Value)>=1 then MyProperty.Value2 := Value[1] else MyProperty.Value2 := 0;
  if High(Value)>=2 then MyProperty.Value3 := Value[2] else MyProperty.Value3 := 0;
  KsSynchronousDeviceControl(MyObjectHandle,
                             IOCTL_KS_PROPERTY,
                             @MyProperty,
                             sizeof(MyProperty),
                             @MyProperty,
                             sizeof(MyProperty),
                             @BytesReturned);
end;

procedure GetCustomProperty(const MyObjectHandle: THandle; Request: TRegCustomProerty; var Value: Array of Integer);
var BytesReturned: Longint;
    MyProperty: TKSPropertyCustomPropS;
begin
  if Request = RegCustomProerty(3) then
    begin
      MyProperty.Property_.Set_ := IID_ICustomProp;
      MyProperty.Property_.Id := Cardinal(Request)+1;
      MyProperty.Property_.Flags := KSPROPERTY_TYPE_SET;
      MyProperty.Value1 := Value[0];
      if High(Value)>=1 then MyProperty.Value2 := Value[1] else MyProperty.Value2 := 0;
      if High(Value)>=2 then MyProperty.Value3 := Value[2] else MyProperty.Value3 := 0;
      KsSynchronousDeviceControl(MyObjectHandle,
                                 IOCTL_KS_PROPERTY,
                                 @MyProperty,
                                 sizeof(MyProperty),
                                 @MyProperty,
                                 sizeof(MyProperty),
                                 @BytesReturned);
      MyProperty.Property_.Id := Cardinal(Request);
      MyProperty.Property_.Flags := KSPROPERTY_TYPE_GET;
      KsSynchronousDeviceControl(MyObjectHandle,
                                 IOCTL_KS_PROPERTY,
                                 @MyProperty,
                                 sizeof(MyProperty),
                                 @MyProperty,
                                 sizeof(MyProperty),
                                 @BytesReturned);
      Value[0] := MyProperty.Value1;
      if High(Value)>=1 then Value[1] := MyProperty.Value2;
      if High(Value)>=2 then Value[2] := MyProperty.Value3;
    end
   else
    begin
      MyProperty.Property_.Set_ := IID_ICustomProp;
      MyProperty.Property_.Id := Cardinal(Request);
      MyProperty.Property_.Flags := KSPROPERTY_TYPE_GET;
      KsSynchronousDeviceControl(MyObjectHandle,
                                 IOCTL_KS_PROPERTY,
                                 @MyProperty,
                                 sizeof(MyProperty),
                                 @MyProperty,
                                 sizeof(MyProperty),
                                 @BytesReturned);
      Value[0] := MyProperty.Value1;
      if High(Value)>=1 then Value[1] := MyProperty.Value2;
      if High(Value)>=2 then Value[2] := MyProperty.Value3;
    end;
end;

end.



