Hello Alessandro,
Post by Alessandro AngeliI haven't used waveIn in a long time, but I am quite sure
you are mistaken about the way waveInClose() works.
According to the docs and the source code, waveInClose()
will fail if there are queued buffers so, if waveInClose()
succeeds, you will not receive data notifications
anymore and you can safely clean up.
Neither happens. At least,not if I may trust my debugging-output.
I must say I used waveInStop() and waveInClose() in that order. When
executing these commands I can see a debugging-message I printed after the
above sequence, and after that I see the last MM_WIM_DATA and MM_WIM_CLOSE
come by.
In other words : the single buffer I'm using is still being filled and
returned to the user *after* the waveInClose command returns successfully.
Post by Alessandro AngeliBefore calling waveInClose() you are supposed to call
waveInReset()
Only if you want to loose the data recorded from the last MM_WIM_DATA up
until the moment that command is issued (very noticable when recording an
16KByte block at 8 bit per sample and 11025 samples a sec :-) ). Calling
waveInStop() instead does not have that drawback.
Post by Alessandro AngeliIt is possible that a buggy driver can keep sending data
notifications after a successful waveInClose()
Hmmmm .... I've run the exact same code on two different versions of Windows
(98se and XP) with quite different hardware & drivers, and in both (four, if
I allso count the waveInReset method) cases I got the above-described result
(data and close window-messages after the waveInClose() command terminates
successfully.
But you made me aware of something : I do not use the
waveInUnprepareHeader() command, as I simply close the recording-device and
discard the used data-stuctures and buffers. I should look into that a bit
more.
Regards,
Rudy Wieser
-- Origional message
Post by Alessandro AngeliFrom: "R.Wieser"
Post by R.WieserTo be honest, all my googeling into the waveInOpen command and family
did not reveal any explanation to why *both* the MM_WIM_xxx and
WIM_xxx exist.
They are not the same thing: the MM_WIM set are standard window messages
while the WIM set are custom messages passed to the callback. Of course
they are all just UINTs and so they gave them the same values, but they
are different namespaces.
Post by R.WieserPost by Alessandro Angelibut my guess is that the original designers of the API
almost 20 years ago thought that, if don't have room
for a user-defined message param in the case of
MM_WIM_DATA,
But there is : the dwUser field in the WAVEHDR structure. Unless
that one has been added in later years ofcourse.
IIRC from the Win16 SDK, it's always been there. It's just not a window
message param. It can serve the same purpose of course, but whoever
designed this API seem to have valued consistency over practicality.
[...]
Post by R.WieserOr have I missed something in this regard ? Is there a standard way
to do that clean-up house-keeping after a recording-channel is
ordered to close ?
I haven't used waveIn in a long time, but I am quite sure you are
mistaken about the way waveInClose() works. According to the docs and
the source code, waveInClose() will fail if there are queued buffers so,
if waveInClose() succeeds, you will not receive data notifications
anymore and you can safely clean up.
Before calling waveInClose() you are supposed to call waveInReset() to
remove all buffers from the queue, then waveInUnprepareHeader() and only
after that you can safely call waveInClose(), which should succeed at
this point, meaning you can clean up your stuff.
Notice that the waveIn API is just a lightweight wrapper for the waveIn
device driver. It is possible that a buggy driver can keep sending data
notifications after a successful waveInClose() but, if that is the case,
then the close notification is in no way more reliable (it is still sent
by the driver).
--
// Alessandro Angeli
// MVP :: DirectShow / MediaFoundation
// mvpnews at riseoftheants dot com
// http://www.riseoftheants.com/mmx/faq.htm