DirectShow render window shows black if graph started when host Tab is not visible (TVideoWindow)

1.4k views Asked by At

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?

1

There are 1 answers

1
haz On

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