0

I liked OBS-Studio's virtual camera feature.

I tried to understand its working but could not understand properly. I only understood that it is built using DirectShow. Project contains OutputFilter, OutputPin, CaptureFilter and CapturePin

class OutputFilter : public IBaseFilter {
    // ...
    friend class OutputPin;
    IFilterGraph *graph;
    ComPtr<OutputPin> pin;
    // ...
}

class OutputPin : public IPin, public IAMStreamConfig, public IKsPropertySet {
    // ...
    friend class OutputFilter;
    // ...
}

class CaptureFilter : public IBaseFilter {
    // ...
    friend class CapturePin;
    ComPtr<IFilterGraph> graph;
    ComPtr<CapturePin> pin;
    // ...
}

class CapturePin : public IPin, public IMemInputPin {
    // ...
    CaptureFilter *filter;
    // ...
}

How data is moving across these filters and pins when we are enabling virtual camera?

Alok
  • 7,734
  • 8
  • 55
  • 100

1 Answers1

1

They are using a shared memory server. Basically, they have a rendering filter that copies the incoming bitmaps into the shared memory. And then they have a capture filter that reads the bitmaps from the shared memory. You can see some of their code here: win-dshow

Escovado
  • 116
  • 10
  • Thanks for the answer. Is `OutputFilter` mentioned in my question working as rendering filter which you mentioned in your answer? Is `CaptureFilter` mentioned in my question same as capture filter mentioned in your answer? – Alok Jul 13 '21 at 05:19
  • Use the DirectShow baseclasses: You need a rendering filter based on CBaseRenderer with an input pin based on CRendererInputPin that copies the bitmaps into the shared memory. And then you need a capture filter that's based on CSource with an output pin based on CSourceStream thar reads the bitmaps from the shared memory. – Escovado Jul 14 '21 at 14:34
  • P.S. The CSourceStream pin has to implement the IKsPropertySet and IAMStreamConfig interfaces. – Escovado Jul 14 '21 at 14:50