⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 main.pas

📁 一个很不错的代码
💻 PAS
字号:
unit Main;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ComCtrls, DSPack, Buttons, StdCtrls, DirectShow9, DSUtil;

type
  IKTVSender = interface(IUnKnown)
    ['{A632B270-30CE-4073-BAD6-8D5779617550}']
    function SetMulticastIP(MulticastIP: PChar): HRESULT; stdcall;
    function GetMulticastIP(out MulticastIP: PChar): HRESULT; stdcall;
    function GetLocalIPs(out LocalIPs: PChar): HRESULT; stdcall;
    function SetLocalIP(LocalIP: PChar): HRESULT; stdcall;
    function GetLocalIP(out LocalIP: PChar): HRESULT; stdcall;
    function SetMulticastPort(MulticastPort: Integer): HRESULT; stdcall;
    function GetMulticastPort(out MulticastPort: Integer): HRESULT; stdcall;
    function SetUserID(UserID: Integer): HRESULT; stdcall;
    function GetUserID(out UserID: Integer): HRESULT; stdcall;
    function Authorise(Company, Code: PChar): HRESULT; stdcall;
  end;

  TMainForm = class(TForm)
    Label1: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    Label4: TLabel;
    Label5: TLabel;
    ComboBox1: TComboBox;
    Button1: TButton;
    VideoWindow1: TVideoWindow;
    Button3: TButton;
    ComboBox2: TComboBox;
    FilterGraph1: TFilterGraph;
    Filter1: TFilter;
    Filter3: TFilter;
    Filter5: TFilter;
    Label9: TLabel;
    OpenDialog1: TOpenDialog;
    FilterGraph3: TFilterGraph;
    Filter6: TFilter;
    Edit1: TEdit;
    SpeedButton1: TSpeedButton;
    Button2: TButton;
    Button4: TButton;
    DSTrackBar1: TDSTrackBar;
    procedure FormCreate(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure ComboBox2Change(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure Button3Click(Sender: TObject);
    procedure ComboBox1Change(Sender: TObject);
    procedure SpeedButton1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure Button4Click(Sender: TObject);
  private
    { Private declarations }
    VideoDev: TSysDevEnum;
    KTVSender: IKTVSender;
  public
    { Public declarations }
  end;

var
  MainForm: TMainForm;

implementation

{$R *.dfm}

procedure TMainForm.FormCreate(Sender: TObject);
var
  I: Integer;
  P: PChar;
begin
  VideoDev := TSysDevEnum.Create(CLSID_VideoInputDeviceCategory);
  for I := 0 to VideoDev.CountFilters - 1 do
    ComboBox1.AddItem(VideoDev.Filters[I].FriendlyName, nil);
  ComboBox1.ItemIndex := 0;

  FilterGraph1.ClearGraph;
  FilterGraph1.Active := True;
  Filter3.QueryInterface(IKTVSender, KTVSender);
  if KTVSender <> nil then
  begin
    KTVSender.GetLocalIPs(P);
    ComboBox2.Items.Text := P;
    KTVSender.GetMulticastIP(P);
    Label3.Caption := '组播IP: ' + P;
    KTVSender.GetLocalIP(P);
    Label4.Caption := '本机IP: ' + P;
    ComboBox2.ItemIndex := ComboBox2.Items.IndexOf(P);
    KTVSender.GetMulticastPort(I);
    Label5.Caption := '端  口: ' + IntToStr(I);
    KTVSender := nil;
  end;
  FilterGraph1.ClearGraph;
  FilterGraph1.Active := False;
end;

procedure TMainForm.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  FilterGraph1.ClearGraph;
  FilterGraph1.Active := False;
  FilterGraph3.ClearGraph;
  FilterGraph3.Active := False;
  VideoDev.Free;
end;

procedure TMainForm.ComboBox2Change(Sender: TObject);
var
  P: PChar;
begin
  if not FilterGraph1.Active then
  begin
    FilterGraph1.ClearGraph;
    FilterGraph1.Active := True;
    Filter3.QueryInterface(IKTVSender, KTVSender);
    if KTVSender <> nil then
    begin
      P := PChar(ComboBox2.Items[ComboBox2.ItemIndex]);
      KTVSender.SetLocalIP(P);
      KTVSender.GetLocalIP(P);
      Label4.Caption := '本机IP: ' + P;
      KTVSender := nil;
    end;
    FilterGraph1.ClearGraph;
    FilterGraph1.Active := False;
  end
  else
  begin
    Filter3.QueryInterface(IKTVSender, KTVSender);
    if KTVSender <> nil then
    begin
      P := PChar(ComboBox2.Items[ComboBox2.ItemIndex]);
      KTVSender.SetLocalIP(P);
      KTVSender.GetLocalIP(P);
      Label4.Caption := '本机IP: ' + P;
      KTVSender := nil;
    end;
  end;

  if not FilterGraph3.Active then
  begin
    FilterGraph3.ClearGraph;
    FilterGraph3.Active := True;
    Filter6.QueryInterface(IKTVSender, KTVSender);
    if KTVSender <> nil then
    begin
      P := PChar(ComboBox2.Items[ComboBox2.ItemIndex]);
      KTVSender.SetLocalIP(P);
      KTVSender.GetLocalIP(P);
      Label4.Caption := '本机IP: ' + P;
      KTVSender := nil;
    end;
    FilterGraph3.ClearGraph;
    FilterGraph3.Active := False;
  end
  else
  begin
    Filter6.QueryInterface(IKTVSender, KTVSender);
    if KTVSender <> nil then
    begin
      P := PChar(ComboBox2.Items[ComboBox2.ItemIndex]);
      KTVSender.SetLocalIP(P);
      KTVSender.GetLocalIP(P);
      Label4.Caption := '本机IP: ' + P;
      KTVSender := nil;
    end;
  end;
end;

procedure TMainForm.Button1Click(Sender: TObject);
var
  I: Integer;
  P: PChar;
begin
  Button1.Enabled := False;
  Button2.Enabled := False;
  Button3.Enabled := True;
  Button4.Enabled := False;
  FilterGraph1.ClearGraph;
  FilterGraph1.Active := False;
  Filter5.BaseFilter.Moniker := VideoDev.GetMoniker(ComboBox1.ItemIndex);
  FilterGraph1.Active := True;
  Filter3.QueryInterface(IKTVSender, KTVSender);
  if KTVSender <> nil then
  begin
    KTVSender.GetMulticastIP(P);
    Label3.Caption := '组播IP: ' + P;
    P := PChar(ComboBox2.Items[ComboBox2.ItemIndex]);
    KTVSender.SetLocalIP(P);
    KTVSender.GetLocalIP(P);
    Label4.Caption := '本机IP: ' + P;
    KTVSender.GetMulticastPort(I);
    Label5.Caption := '端  口: ' + IntToStr(I);
    KTVSender.Authorise('', '');
    KTVSender := nil;
    (FilterGraph1 as ICaptureGraphBuilder2).RenderStream(@PIN_CATEGORY_CAPTURE, nil, Filter5 as IBaseFilter, Filter1 as IBaseFilter, Filter3 as IBaseFilter);
    (FilterGraph1 as ICaptureGraphBuilder2).RenderStream(@PIN_CATEGORY_PREVIEW, nil, Filter5 as IBaseFilter, nil, VideoWindow1 as IBaseFilter);
    FilterGraph1.Play;
    Exit;
  end;
  FilterGraph1.ClearGraph;
  FilterGraph1.Active := False;
end;

procedure TMainForm.Button3Click(Sender: TObject);
begin
  Button1.Enabled := True;
  Button2.Enabled := True;
  Button3.Enabled := False;
  Button4.Enabled := False;
  FilterGraph1.ClearGraph;
  FilterGraph1.Active := False;
end;

procedure TMainForm.ComboBox1Change(Sender: TObject);
begin
  if FilterGraph1.Active then
    Button1Click(nil);
end;

procedure TMainForm.SpeedButton1Click(Sender: TObject);
begin
  if OpenDialog1.Execute then
  begin
    Edit1.Text := OpenDialog1.FileName;
  end;
end;

procedure TMainForm.Button2Click(Sender: TObject);
var
  I: Integer;
  P: PChar;
begin
  Button1.Enabled := False;
  Button2.Enabled := False;
  Button3.Enabled := False;
  Button4.Enabled := True;
  FilterGraph3.ClearGraph;
  FilterGraph3.Active := False;
  if FileExists(Edit1.Text) then
  begin
    FilterGraph3.Active := True;
    Filter6.QueryInterface(IKTVSender, KTVSender);
    if KTVSender <> nil then
    begin
      KTVSender.GetMulticastIP(P);
      Label3.Caption := '组播IP: ' + P;
      P := PChar(ComboBox2.Items[ComboBox2.ItemIndex]);
      KTVSender.SetLocalIP(P);
      KTVSender.GetLocalIP(P);
      Label4.Caption := '本机IP: ' + P;
      KTVSender.GetMulticastPort(I);
      Label5.Caption := '端  口: ' + IntToStr(I);
      KTVSender.Authorise('', '');
      KTVSender := nil;
    end;
    FilterGraph3.RenderFile(Edit1.Text);
    FilterGraph3.Play;
  end;
end;

procedure TMainForm.Button4Click(Sender: TObject);
begin
  Button1.Enabled := True;
  Button2.Enabled := True;
  Button3.Enabled := False;
  Button4.Enabled := False;
  FilterGraph3.ClearGraph;
  FilterGraph3.Active := False;
end;

end.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -