3

I have a Delphi 6 application that uses the DirectShow DSPACK component suite. It has a TVideoWindow component that will render the images from a filter graph. The TVideoWindow component is on a Tab in a page component. If the Tab is visible when I run the Filter Graph the video shows just fine. Also, I can switch to another Tab and come back and the video is still fine. However, if I run the Filter Graph when the Tab is not visible, then when I switch to that Tab the video window area is black. I tried switching to another Tab and back, minimizing the host form and restoring it, and it stays black. I am wondering if this is a window/component handle life-cycle problem? How can I fix this?

Robert Oschler
  • 14,153
  • 18
  • 94
  • 227
  • I have had this problem too. Never fixed it unfortunately – Simon Jan 08 '12 at 05:31
  • What about deferring start (actually, VMR/EVR initialization) until the hosting window is visible? – Roman R. Jan 09 '12 at 09:47
  • @RomanR. - I added code that does that. It works somewhat but it's not bulletproof. I used information from this post to determine if the window is visible: http://stackoverflow.com/questions/646527/how-can-i-tell-if-a-delphi-control-is-currently-visible . It helps, but I still sometimes get the "black window". I'm still tweaking the code. – Robert Oschler Jan 09 '12 at 14:00

1 Answers1

2

This problem does not happen when using COM objects directly such as setting the EVR to a hidden Panel that is subsequently shown. I'd suggest that time spent getting rid of the TVideoWindow and using renders such as the VMR9 and EVR directly would be more productive. You don't have to get rid of DSPack to do this, something along the lines of

  FDisplayControl: IMFVideoDisplayControl;
  FEVR: IBaseFilter;
  R: TNormalizedRect;
  R: TRect;

  hr := Succeeded(CoCreateInstance(CLSID_EnhancedVideoRenderer, nil, CLSCTX_INPROC, IID_IBaseFilter, FEVR));
  if (hr <> S_OK) then
  begin
    showmessage(GetErrorString(hr) + ' (Could not create the enhanced video renderer : ' + inttohex(hr,8) + ')');
    Exit;
  end;
  (FilterGraph as IFilterGraph2).AddFilter().AddFilter(FEVR, PWideChar(WideString('EVR')));
  (FEVR as IMFGetService).GetService(MR_VIDEO_RENDER_SERVICE, IID_IMFVideoDisplayControl, FDisplayControl);
  FDisplayControl.SetVideoWindow(Panel.Handle);
  NR.Left := 0;
  NR.Top := 0;
  NR.Right := 1;
  NR.Bottom := 1;
  R := ClientRect;
  FDisplayControl.SetVideoPosition(@nr, @r);
  FDisplayControl.SetAspectRatioMode(MFVideoARMode_None);

Note: the above requires EVR.pas

haz
  • 116
  • 3