I am writing a simple as possible demo application which reads the incoming data from a WebCam and both displays it to the screen and (optionally at the toggle of a button) records the video stream to the disk. To do this I implemented a standard WMF pipeline architecture from the WebCam which acts as a media source to an EVR which acts as the media sink. In order to implement the file capture functionality, I modified a simple MFT (the FrameCounter MFT) to also write the incoming samples to a Sink Writer if the Sink Writer object is available. Thus all data travels from the source to the sink via the MFT and, if a Sink Writer is available to the MFT, it will also write the sample data to the Sink Writer was well.
The MFT does in place processing and releases the sample just before returning from its output processing loop. The write to the sink writer just uses the same input sample in its WriteSample() call before the release happens.
The problem is that this code works. I expected to have to make a copy of the sample in the MFT and give that to the Sink Writer so that it could release it. This raises the following questions..
Does the Sink Writer make its own copy of the sample or add its own reference to the sample? Does it release the sample given to it? It is my understanding that the Sink Writer can queue these samples for some time (if it wishes) before writing them. What is the general treatment of samples in the Sink Writers WriteSample() call.
Is it just a fluke that this is working now and am I creating problems for later or on slower machines? Is the technique described above valid? If not, what would be the recommended approach. I have experienced no odd run-time errors with this.
I was under the impression that when capturing data from a web cam that the timestamp on the sample needed to be rebased before writing it out. In other words, the first sample written had to have a timestamp of 0 and every subsequent sample timestamp adjusted based off of that. This does not appear to be necessary in this case. Is this time base reset a requirement (was it ever)? I note that the sample code in the FileCapture demo takes care to do this. Have Microsoft improved the Sink Writer in recent versions to cope with this?
I am working on Windows 10 in C# using WMF.Net. I realize this may be a special case with the CLR and its garbage collection – however, I would appreciate any WMF insights (in any language) you may be able to offer. The Sink Writer output format is H.264 – if that matters.