difference between OSS mmap and alsa mmap? [alsa-oss]
Hi,
the last thing i can see not working correctly in alsa-oss is the mmap emulation [may closed source apps use OSS with mmap emu]. jcdutton told me on irc that this is due to the differences in OSS mmaping and ALSA mmaping and it might not be possible to resolve these issues..
Well, since i don't know anything about mmap'ing device files, i would be glad if somebody could point me to sources of information about mmap'ing device files and especially the differences in handling of ALSA and OSS..
P.S.: the test case here is running Enemy Territory with aoss. Try it and you will see how alsa-oss' mmap emu fails badly [only some craacks and little chunks of audio audible]..
Signature · 10 lines
Palimm Palimm! http://affenbande.org/~tapas/wiki ------------------------------------------------------- This SF.Net email sponsored by Black Hat Briefings & Training. Attend Black Hat Briefings & Training, Las Vegas July 24-29 - digital self defense, top technical experts, no vendor pitches, unmatched networking opportunities. Visit www.blackhat.com
Quoted 4 lines
the last thing i can see not working correctly in alsa-oss is the mmap emulati on [may closed source apps use OSS with mmap emu]. jcdutton told me on irc tha t this is due to the differences in OSS mmaping and ALSA mmaping and it might not be possible to resolve these issues..
i don't think its possible. the OSS mmap API provides raw ptr access to the DMA area of the h/w. you cannot intercede when an app just uses pointer indirection and advance to read/write data. ALSA's API does the same, of course, but access is bounded by two calls that allow correct handling for devices where the DMA area is a bit more complex than the OSS model allows for (e.g. 2 devices, or a device that can't support mmap in hardware, or a dmix device, or ...)
--p
-------------------------------------------------------
This SF.Net email sponsored by Black Hat Briefings & Training. Attend Black Hat Briefings & Training, Las Vegas July 24-29 - digital self defense, top technical experts, no vendor pitches, unmatched networking opportunities. Visit www.blackhat.com
At Mon, 05 Jul 2004 09:13:46 -0400,
Quoted 6 lines · Paul Davis
Quoted 5 lines
the last thing i can see not working correctly in alsa-oss is the mmap emulati on [may closed source apps use OSS with mmap emu]. jcdutton told me on irc tha t this is due to the differences in OSS mmaping and ALSA mmaping and it might not be possible to resolve these issues..
Quoted 7 lines
i don't think its possible. the OSS mmap API provides raw ptr access to the DMA area of the h/w. you cannot intercede when an app just uses pointer indirection and advance to read/write data. ALSA's API does the same, of course, but access is bounded by two calls that allow correct handling for devices where the DMA area is a bit more complex than the OSS model allows for (e.g. 2 devices, or a device that can't support mmap in hardware, or a dmix device, or ...)
A hack would be to call mmap_avail() in oss's GETSPACE (or similar) ioctls. But, right, I don't think that the "perfect" emulation is possible on all hardwares as it is now, too.
Takashi
-------------------------------------------------------
This SF.Net email sponsored by Black Hat Briefings & Training. Attend Black Hat Briefings & Training, Las Vegas July 24-29 - digital self defense, top technical experts, no vendor pitches, unmatched networking opportunities. Visit www.blackhat.com
Quoted 17 lines · On Mon, 05 Jul 2004 15:19:57 +0200 Takashi Iwai <[email protected]> wrote:
At Mon, 05 Jul 2004 09:13:46 -0400,
Quoted 7 lines · Paul Davis
Quoted 6 lines
the last thing i can see not working correctly in alsa-oss is the mmap emulati on [may closed source apps use OSS with mmap emu]. jcdutton told me on irc tha t this is due to the differences in OSS mmaping and ALSA mmaping and it might not be possible to resolve these issues..
Quoted 7 lines
i don't think its possible. the OSS mmap API provides raw ptr access to the DMA area of the h/w. you cannot intercede when an app just uses pointer indirection and advance to read/write data. ALSA's API does the same, of course, but access is bounded by two calls that allow correct handling for devices where the DMA area is a bit more complex than the OSS model allows for (e.g. 2 devices, or a device that can't support mmap in hardware, or a dmix device, or ...)
Quoted 3 lines
A hack would be to call
mmap_avail()in oss's GETSPACE (or similar) ioctls. But, right, I don't think that the "perfect" emulation is possible on all hardwares as it is now, too.
btw: i might prove my ignorance with this question, but i have to ask:
what makes the kernel oss emu handle mmap so good? it's an emulation, too, i suppose.. so what is the big difference in these two emulations, that in one case it works well [kernel oss emu] and in the other it seems almost impossible [libaoss.so]..
flo
-------------------------------------------------------
SF.Net email is sponsored by Shop4tech.com-Lowest price on Blank Media 100pk Sonic DVD-R 4x for only $29 -100pk Sonic DVD+R for only $33 Save 50% off Retail on Ink & Toner - Free Shipping and Free Gift.
http://www.shop4tech.com/z/Inkjet_Cartridges/9_108_r285
Quoted 7 lines · On Tue, 24 Aug 2004 13:57:10 +0200 Florian Schmidt <[email protected]> wrote:
btw: i might prove my ignorance with this question, but i have to ask:
what makes the kernel oss emu handle mmap so good? it's an emulation, too, i suppose.. so what is the big difference in these two emulations, that in one case it works well [kernel oss emu] and in the other it seems almost impossible [libaoss.so]..
besies the, of course, obvious fact that one lives in kernel space and the other in user space..
flo
-------------------------------------------------------
SF.Net email is sponsored by Shop4tech.com-Lowest price on Blank Media 100pk Sonic DVD-R 4x for only $29 -100pk Sonic DVD+R for only $33 Save 50% off Retail on Ink & Toner - Free Shipping and Free Gift.
http://www.shop4tech.com/z/Inkjet_Cartridges/9_108_r285
Quoted 3 lines · Florian Schmidt
btw: i might prove my ignorance with this question, but i have to ask:
what makes the kernel oss emu handle mmap so good? it's an emulation,
Nothing. It allows direct uncontrollable access to the ring buffer. Only some hardware is supported.
Quoted 3 lines
too, i suppose.. so what is the big difference in these two emulations, that in one case it works well [kernel oss emu] and in the other it seems almost impossible [libaoss.so]..
The libaoss should work at least for direct buffers in very similar way. Unfortunately, there is one problem for dmix and other plugins (rate, conversions) which RELY on the mmap_begin/mmap_commit sequence. The mmap_commit initiates the real mixing. Unfortunately, if you have the uncontrollable mmap access (OSS), you don't know exactly which data were changed. Thus we may only guess which sample regions needs to be flushed using the mmap_commit method.
So resume: If you have access to direct DMA buffer (hw:X,Y devices), the behavior should be same. Unfortunately, all next processing like mixing, conversions needs more work. OSS API has no control for transferred samples for mmap mode. Applications can do anything they want with the ring buffer.
OSS API is evil in this area. But they must solve same problem for their virtual mixing devices. Again, I think that they must introduce some extra latency to solve the mmap problems. I can imagine that they might have two serialized (FIFO) ring buffers. One for application and the second one for the real hardware. The real output delay won't be one ring buffer, but two ring buffers in this case. Perhaps, we might try this way.
Jaroslav
-----
Jaroslav Kysela <[email protected]>
Linux Kernel Sound Maintainer
ALSA Project, SUSE Labs
-------------------------------------------------------
SF.Net email is sponsored by Shop4tech.com-Lowest price on Blank Media 100pk Sonic DVD-R 4x for only $29 -100pk Sonic DVD+R for only $33 Save 50% off Retail on Ink & Toner - Free Shipping and Free Gift.
http://www.shop4tech.com/z/Inkjet_Cartridges/9_108_r285
Quoted 23 lines · Jaroslav Kysela
Quoted 3 lines · Florian Schmidt
btw: i might prove my ignorance with this question, but i have to ask:
what makes the kernel oss emu handle mmap so good? it's an emulation,
Nothing. It allows direct uncontrollable access to the ring buffer. Only some hardware is supported.
Quoted 3 lines
too, i suppose.. so what is the big difference in these two emulations, that in one case it works well [kernel oss emu] and in the other it seems almost impossible [libaoss.so]..
The libaoss should work at least for direct buffers in very similar way. Unfortunately, there is one problem for dmix and other plugins (rate, conversions) which RELY on the mmap_begin/mmap_commit sequence. The
mmap_commitinitiates the real mixing. Unfortunately, if you have the
uncontrollable mmap access (OSS), you don't know exactly which data were
changed. Thus we may only guess which sample regions needs to be flushed using themmap_commitmethod.
Quoted 6 lines
So resume: If you have access to direct DMA buffer (hw:X,Y devices), the behavior should be same. Unfortunately, all next processing like mixing, conversions needs more work. OSS API has no control for transferred samples for mmap mode. Applications can do anything they want with the ring buffer.
OSS API is evil in this area. But they must solve same problem for their virtual mixing devices. Again, I think that they must introduce some extra latency to solve the mmap problems. I can imagine that they might have two serialized (FIFO) ring buffers. One for application and the second one for the real hardware. The real output delay won't be one ring buffer, but two ring buffers in this case. Perhaps, we might try this way.
Jaroslav
One runs into the same issues with writing an ALSA driver for wine.
Windows ASIO just lets the application write directly to the hardware ring buffer, much the same way that OSS does.
I also think that the best way to handle this is to use double buffering.
So the user app writes to a ring buffer, and alsa just copies one period at a time to the hardware buffer each time periods_elapsed is called.
This will introduce latency, but the latency will be small, and acceptable in my view, until applications switch to using alsa direct.
If an interrupt is missed, samples will just get lost.
Recently, some latency profiling code is being developed for the linux kernel, so soon we will be able to track and fix all those places in the kernel that hold onto the CPU for >1ms. Once all the critical sections in the kernel are fixed, low latency will be reliable for everyone.
James
-------------------------------------------------------
SF.Net email is sponsored by Shop4tech.com-Lowest price on Blank Media 100pk Sonic DVD-R 4x for only $29 -100pk Sonic DVD+R for only $33 Save 50% off Retail on Ink & Toner - Free Shipping and Free Gift.
http://www.shop4tech.com/z/Inkjet_Cartridges/9_108_r285
Quoted 3 lines
I also think that the best way to handle this is to use double buffering. So the user app writes to a ring buffer, and alsa just copies one period at a time to the hardware buffer each time
periods_elapsedis called.
this doesn't work. the whole point of the OSS mmap model is that the app always has access to the entire hardware buffer, not just the current period. this is why its so hard to make it work correctly in emulation mode.
--p
-------------------------------------------------------
SF.Net email is sponsored by Shop4tech.com-Lowest price on Blank Media 100pk Sonic DVD-R 4x for only $29 -100pk Sonic DVD+R for only $33 Save 50% off Retail on Ink & Toner - Free Shipping and Free Gift.
http://www.shop4tech.com/z/Inkjet_Cartridges/9_108_r285