> Actually, an AVStream driver should always timestamp its frames by
fetching the current stream time from the master clock that is assigned
to the filter by the graph. It shouldn’t try to generate its own
timestamps.
Sorry Tim, but I would disagree.
Imagine an USB device which is a stupid source of AVI file.
To play this AVI correctly, the frames should be timestamped according to AVI
file (by incrementing the next frame’s media time by
AviHeader->MillisecondsPerFrame on each frame) and not to the master clock,
isn’t it so? it is so for any AVI file, regardless of its source.
For me, the whole DirectShow’s concept of master clock is mainly to synchronize
video renderer with audio renderer. Usually, audio renderer is a master clock
source, and video renderer is master clock consumer. So, master clock is mainly
used by video renderer to adjust its display rate to the soundtrack.
Yes, if the stream source is realtime, then usually the source is the master
clock provider and also the timestamper. In this case, both audio and video
renderers will make their best to synchronize with the realtime source (by
tweaking the soundcard’s clock if supported, by tweaking the USB HC’s frame
clock if the audio destination is an USB device, and such).
Another consideration.
Imagine the user-mode DirectShow graph which plays an AVI file. In this
situation, each frame’s media time will be stamped by the AVI splitter, by
incrementing by MillisecondsPerFrame.
The source stamps the media time in the packets. The master clock is used not
in stamping, but in interpreting the stamps. The stamps are defined as
“media time”, and master clock answers the question “what is the implementation
of this media time? what clock is used to measure the media time?”. Master
clock is not about “what are the media time values for the packets?”.
Now let’s consider the source which uses USB isoch pipe. For me, it looks
logical to timestamp each packet (DirectShow’s “media sample”) according to the
ideal frame rate taken from the device setup or protocol definition (like
25fps or so), and also provide the master clock by taking it from the USB stack
below (the USB HC’s frame clock).
In this case, if the destination is also on the same USB bus (USB headphones),
then it will be able to notice (I don’t know the exact details of DShow’s
Default DirectSound Device, possibly it is smart enough for such a thing) that
the graph’s master clock is taken from the same USB stack and same USB HC chip,
and will have a chance to not do any clock tweaking, SRC or such.
Even if it will do SRC - then it will notice that both clocks - graph’s master
and its “natural” clock - are always the same (since they are taken from the
same source), so SRC will be a no-op.
And, if the destination is some other sound output device, then it will have
the chance to adjust its clock to be the slave of the graph’s master (the USB
HC clock of the USB bus attaching the source device), or, if the hardware does
not support the clock tweaking, then SRC will be used.
So, for me, it looks 100% valid to set the timestamps in the frames (“media
samples”) in the USB source driver according to the idealized frame rate
taken from the protocol definition (like 25fps or so - exactly 40ms per
sample).
Also, the source can be smart enough to notice if DShow have chosen some other
clock as master, not it’s provided clock. In this case, the USB source can use
USB IOCTLs to tweak the USB HC’s frame clock speed to match the external
source, which also means no SRC and absolute synchronization.
–
Maxim Shatskih, Windows DDK MVP
StorageCraft Corporation
xxxxx@storagecraft.com
http://www.storagecraft.com