directshow手动连接dspack下AsyncEx Filter错误

时间:2022-06-03 18:26:51
我调用dspack下的AsyncEx,本想改成网络的,但不好改,而且我把DSPACK例子编译后,在gharpedit中是正确的,但程序中手工连接filter 错误,搞了N天了,还是行不通,还有如何手工连接Infinite Pin Tee Filter,忘高手解答!

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, DSPack, StdCtrls, directshow9,ActiveX,dsutil;
const
  CLISD_AsyncEx: TGUID = '{3E0FA044-926C-42D9-BA12-EF16E980913B}'

  IID_IStreamLoad: TGUID = '{3E0FA056-926C-43d9-BA18-EF16E980913B}';
  //Infinite Pin Tee Filter
  CLISD_OutTee: TGUID = '{F8388A40-D5BB-11D0-BE5A-0080C706568E}';
  //Video Renderer
  CLISD_Video_Renderer: TGUID = '{70E102B0-5556-11CE-97C0-00AA0055595A}';
  //VMR Video Renderer
  CLISD_VMR_Video_Renderer: TGUID = '{6BC1CFFA-8FC1-4261-AC22-CFB4CC38DB50}';

  //-------------MPEG1/MPEG2 Media System Filter ------------------------
  //Moonlight-Elecard MPEG2 Demultiplexer 
  CLISD_Moonlight_MPEG2Demultiplexer: TGUID = '{731B8592-4001-46D4-B1A5-33EC792B4501}';
  //Moonlight-Elecard MPEG2 Video Decoder 
  CLISD_Moonlight_MPEG2Decoder: TGUID = '{F50B3F13-19C4-11CF-AA9A-02608C9BABA2}';
  //Mpeg1 Video Decoder
  CLISD_Mpeg1Decoder: TGUID = '{FEB50740-7BEF-11CE-9BD9-0000E202599C}';

  CLSID_FILE_SOURCE:TGUID = '{E436EBB5-524F-11CE-9F53-0020AF0BA770}';
type
  TForm1 = class(TForm)
    Button1: TButton;
    FilterGraph1: TFilterGraph;
    VideoWindow1: TVideoWindow;
    procedure FormCreate(Sender: TObject);
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
    procedure PlaySystem(nFile: string; FilterGraphs: TFilterGraph; Handle: HWND);
  public
    { Public declarations }
  end;
  IStreamLoad = interface(IUnknown)['{3E0FA056-926C-43d9-BA18-EF16E980913B}']
    function LoadFromStream(f_Stream: TStream): HRESULT; stdcall;
  end;
var
  Form1: TForm1;

implementation

{$R *.dfm}

var FileSource, DVD_Split, DVD_Decode, OutTee, JFSFilter, Vdo: IBaseFilter;

procedure TForm1.FormCreate(Sender: TObject);
begin
     //

end;

procedure TForm1.PlaySystem(nFile: string; FilterGraphs: TFilterGraph;
  Handle: HWND);
var
  ppPinsIn: IPin;
  ppPinsOut: IPin;
  isOk: boolean;
  hr: DWORD; pfLoader: IFileSourceFilter;
  redenpin: IPin;
  VideoWindow:IVideoWindow;
  MediaType:TAMMediaType;
begin
  if not FilterGraphs.Active then FilterGraphs.Active := true;
  if (FilterGraphs.State = gsPaused) or (FilterGraphs.State = gsPlaying) then FilterGraphs.Stop;
  FilterGraphs.ClearGraph;

  if (isOk) and (CoCreateInstance(CLISD_AsyncEx, nil, CLSCTX_INPROC, TGUID(IID_IBaseFilter), FileSource) = s_ok) then
    (FilterGraphs as IGraphBuilder).AddFilter(FileSource,'AsyncEx')
  else isOk := False;

  if (isOk) and (CoCreateInstance(CLISD_Moonlight_MPEG2Demultiplexer, nil, CLSCTX_INPROC, TGUID(IID_IBaseFilter), DVD_Split) = s_ok) then
    (FilterGraphs as IGraphBuilder).AddFilter(DVD_Split, 'Moonlight-Elecard MPEG2 Demultiplexer')
  else isOk := False;

  if (isOk) and (CoCreateInstance(CLISD_Moonlight_MPEG2Decoder, nil, CLSCTX_INPROC, TGUID(IID_IBaseFilter), DVD_Decode) = s_ok) then
    (FilterGraphs as IGraphBuilder).AddFilter(DVD_Decode, 'Moonlight-Elecard MPEG2 Video Decoder')
  else isOk := False;

  if (isOk) and (CoCreateInstance(CLISD_VMR_Video_Renderer, nil, CLSCTX_INPROC, TGUID(IID_IBaseFilter), Vdo) = s_ok) then
    (FilterGraphs as IGraphBuilder).AddFilter(Vdo, 'VMR Video Renderer')
  else isOk := False;

  if Succeeded(FileSource.QueryInterface(IID_IFilesourcefilter, pfLoader)) then
  begin
    hr := pfLoader.Load(StringToOleStr('c:\00000001.mpg'), nil);
    if FAILED(hr) then isOk := False;
    if isOk then
    begin
      pfLoader := nil;
      FilterGraphs.stop;

      ppPinsOut:=GetOutPin(FileSource,0);
      redenpin:=ppPinsOut;
      redenpin.ConnectionMediaType(MediaType);
      ppPinsIn:=GetInPin(DVD_Split,0);
      ppPinsOut.Disconnect;
      ppPinsIn.Disconnect;

      //在这hr返回错误
      hr := (FilterGraphs as IGraphBuilder).ConnectDirect(ppPinsOut, ppPinsIn,@MediaType);
      if Failed(hr) then showmessage('error');
      ppPinsOut:=nil;
      ppPinsIn:=nil;

      ppPinsOut:=GetOutPin(DVD_Split,0);
      ppPinsIn:=GetInPin(DVD_Decode,0);
      //ppPinsOut.Disconnect;
      //ppPinsIn.Disconnect;
      hr := (FilterGraphs as IGraphBuilder).ConnectDirect(ppPinsOut, ppPinsIn,@MediaType);
      if Failed(hr) then showmessage('error');

      ppPinsOut:=GetOutPin(DVD_Decode,0);
      ppPinsIn:=GetInPin(Vdo,0);
      ppPinsOut.Disconnect;
      ppPinsIn.Disconnect;
      hr := (FilterGraphs as IGraphBuilder).ConnectDirect(ppPinsOut, ppPinsIn,@MediaType);
      if Failed(hr) then showmessage('error');

      (FilterGraphs as IGraphBuilder).Render(redenpin);
      FilterGraphs.Play;

    end;
  end;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  PlaySystem('C:\00000001.mpg', FilterGraph1, self.Handle);
end;

end.

1 个解决方案

#1


该回复于2012-04-13 11:35:26被版主删除

#1


该回复于2012-04-13 11:35:26被版主删除