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?
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