Re: How to know when WriteStreamSample has written the sample to d

Tech-Archive recommends: Fix windows errors by optimizing your registry



Thanks for your hint about writerTime, I will check it out.

What I have done now is to count every byte that is written with
WriteStreamSample. Then I compare it to the actual file size using
GetFileSize in the IWMWriterFileSink2 interface. When the bytes sent to
WriteStreamSample is > GefileSize + 10MB i sleep until it's not. The idea
with this is to limit the outputbuffer 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 increase, it's getting a
little bigger all the time. Anyone has an idea why this happens? What is the
extra data that is written to the asf-file when using writestreamsample? It
would be really good if I could compensate for this to prevent the
outputbuffer from increasing.
To put it simple:
When I write 1024 bytes 10000 times with writeStreamSample the resulting
file size is 10460944 bytes.
1024 bytes 100 000 times and the file size becomes 104716944 bytes.
1024 bytes 1 000 000 times and the file size = 1047260944 bytes.

As you can see the file size is not directly proportional to the data
written but it increases with larger files. Like I said I have disabled the
indexing.

/Fredrik

"tunah1@xxxxxxxxx" wrote:

On 14 Mar, 14:30, Fredrik <c...@xxxxxxx> wrote:
Thank you for your answer.

The problem is not the timestamps. They are read from source file in the
correct order and written to the asf-file. Like I said the problem is that
when we are writing to a slow disk, the writer operation is slower than the
filereader.
This means that the wmwriter starts buffering and it's eating memory until
the machine is out of it. That's what I must prevent.
I was hoping that it's somehow possible to control that buffering but I have
come up empty reading the docs.
One solution could for example be if there was a possiblity to monitor the
"buffering" and stop pushing samples with writestreamsample when the buffer
is getting high.

Like I said it should be ideal to get the reader to be synhronous (I know
the packets from the source file always arrives in the correct order) but I
have not figured out how to do it. There's doesnt seem to be any callback for
when samples are written or when the output buffer is growing.

There's of course not an option that the writer starts dropping samples, the
whole idea iis that an file in our own format should be exported to an
asf-file.

Do you have any idea of how this could be done or is there really no way to
do this with the wmfsdk?

I've written capture functionality using IWMWriterAdvanced. While
doing so I had a bunch of debug logging to make sure nothing went
wrong. One thing I noticed is the following:

// Write sample
wmWriterAdvanced->WriteStreamSample( ... );
QWORD writerTime = 0;
wmWriterAdvanced->GetWriterTime(&writerTime);
If you print writerTime here, you'll probably find that it doesn't
change every time that you call WriteStreamSample.
It will change when the thread that does the actual writing updates
it, though. Atleast that's what I can gather looking at the output.
I suppose you could check the writer time if you want to block until
samples are actually written.
If it doesn't help you, perhaps take a look at the
IWMWriterAdvanced::GetStatistics . Maybe you can introduce some
waiting based on the contents of that structure.

.