Re: How to know when WriteStreamSample has written the sample to d
- From: Fredrik <cfb@xxxxxxx>
- Date: Wed, 18 Mar 2009 07:36:24 -0700
Thanks again!
However I still think we are talking about different reason for the buffering.
Like I said it's nothing about the timestamp not arriving in the correct
order. The problem is when the disk doesn't keep up. Then the "output buffer"
does grow what seems infinite and causes our application to crash when the
machine is out of memory.
I don't understand why the writer should wait for more samples when it
already has a 10 MB buffer with samples ready to be written to file? Like I
said the file that is beeing exported to asf already have all frames in the
timestamp order.
/Fredrik
"Alessandro Angeli" wrote:
From: "Fredrik".
to 10MB. However I have found out that the wmwriter[...]
writes some bytes mote than what I give it in the
WriteStreamSample. It doesn't seem to be a linear
The file does not just contain raw data. It starts with
several KiBs of header and, if you added metadata, also all
of the metadata, then, for each sample, a few extra bytes to
frame it and, if you added data unit extensions, also the
data extensions. The index is the only thing you do not have
to worry about, because it is only written at the end.
Compensating for the exact overhead is hard, because the ASF
syntax is hard (you can download the specs from
microsoft.com).
In any case, your technique is not guaranteed to work and,
when it doesn't, it has a good chance of deadlocking your
application. If the writer is not writing out the data, it
means it is waiting for you to write more but, if you stop
writing waiting for the writer to write, then you both will
wait forever.
The writer does not write out the data based on how long it
has been since the last write or the amount of data in the
buffers, but it writes the data when the buffered streams
are more or less in sync. If you keep the streams in sync or
you tell the writer to ignore the async (that is, tell the
writer you are a live source), the writer will write data
steadily without too much buffering.
Thanks for your hint about writerTime, I will check it
out.
The writer time is the sync point the writer is waiting all
the streams to reach before writing out the data, so that it
can properly interleave the samples (that is, the samples
from all of the streams are not written out in the order you
gave them, but in the order thart keeps samples with close
timestamps close in the file).
Let's say that A3 means sample with timestamp 3 of stream A.
If you have 2 streams, the order the samples should be in
the file is: A0 B0 A1 B1 A2 B2...
If you give them to the writer in a different order (A0 A1
B0 A3 B1 A4 A5 B2...), the writer has to buffer them,
waiting for the slowest stream (B) to catch up with the
fastest (A), so that it can reorder the samples. E.g. If the
tolerance is 2, when you write A5, the buffers would contain
A0 A1 A2 A3 A4 A5 and B0 B1, so the writer can write up to
A3 (B1 + 2) as A0 B0 A1 B1 A2 A3, but then it must keep
buffering waiting for you to write some more of B.
The buffering is not infinite: it's max size is proportional
to the tolerance (3 secs by default) and, when it is full,
the writer will reject further samples.
To avoid the buffering to grow too much, you must make sure
you are writing the samples more or less in sync or you must
tell the writer you are a live source (but, if you do and
your streams are not in sync, then you may end up with
problems during playback).
--
// Alessandro Angeli
// MVP :: DirectShow / MediaFoundation
// mvpnews at riseoftheants dot com
// http://www.riseoftheants.com/mmx/faq.htm
- Follow-Ups:
- Re: How to know when WriteStreamSample has written the sample to d
- From: Alessandro Angeli
- Re: How to know when WriteStreamSample has written the sample to d
- References:
- How to know when WriteStreamSample has written the sample to disk?
- From: Fredrik
- Re: How to know when WriteStreamSample has written the sample to disk?
- From: Alessandro Angeli
- Re: How to know when WriteStreamSample has written the sample to d
- From: Fredrik
- Re: How to know when WriteStreamSample has written the sample to d
- From: tunah1
- Re: How to know when WriteStreamSample has written the sample to d
- From: Fredrik
- Re: How to know when WriteStreamSample has written the sample to d
- From: Alessandro Angeli
- How to know when WriteStreamSample has written the sample to disk?
- Prev by Date: Re: Unexpected break of live stream about once in 12 hours of broadcasting
- Next by Date: Re: How to know when WriteStreamSample has written the sample to d
- Previous by thread: Re: How to know when WriteStreamSample has written the sample to d
- Next by thread: Re: How to know when WriteStreamSample has written the sample to d
- Index(es):
Relevant Pages
|