aboutsummaryrefslogtreecommitdiffstats
path: root/sound/core/pcm_lib.c (follow)
AgeCommit message (Collapse)AuthorFilesLines
2010-05-25ALSA: pcm: fix delta calculation at boundary wraparoundClemens Ladisch1-1/+3
In the cleanup of the hw_ptr update functions in 2.6.33, the calculation of the delta value was changed to use the modulo operator to protect against a negative difference due to the pointer wrapping around at the boundary. However, the ptr variables are unsigned, so a negative difference would result in the two complement's value which has no relation to the actual difference relative to the boundary; the result is typically some value near LONG_MAX-boundary. Furthermore, even if the modulo operation would be done with signed types, the result of a negative dividend could be negative. The invalid delta value is then caught by the following checks, but this means that the pointer update is ignored. To fix this, use a range check as in the other pointer calculations. Signed-off-by: Clemens Ladisch <clemens@ladisch.de> Cc: <stable@kernel.org> Signed-off-by: Takashi Iwai <tiwai@suse.de>
2010-05-21ALSA: pcm: fix the fix of the runtime->boundary calculationClemens Ladisch1-2/+7
Commit 7910b4a1db63fefc3d291853d33c34c5b6352e8e in 2.6.34 changed the runtime->boundary calculation to make this value a multiple of both the buffer_size and the period_size, because the latter is assumed by the runtime->hw_ptr_interrupt calculation. However, due to the lack of a ioctl that could read the software parameters before they are set, the kernel requires that alsa-lib calculates the boundary value, too. The changed algorithm leads to a different boundary value used by alsa-lib, which makes, e.g., mplayer fail to play a 44.1 kHz file because the silence_size parameter is now invalid; bug report: <https://bugtrack.alsa-project.org/alsa-bug/view.php?id=5015>. This patch reverts the change to the boundary calculation, and instead fixes the hw_ptr_interrupt calculation to be period-aligned regardless of the boundary value. Signed-off-by: Clemens Ladisch <clemens@ladisch.de> Cc: <stable@kernel.org> Signed-off-by: Takashi Iwai <tiwai@suse.de>
2010-03-26ALSA: pcm_lib - fix xrun functionalityJarkko Nikula1-2/+4
The commit 4d96eb255c53ab5e39b37fd4d484ea3dc39ab456 broke the interrupt time xrun functionality (stream stop etc.) if the CONFIG_SND_PCM_XRUN_DEBUG is not set. This is because the xrun() is null defined without it. Fix this by letting the function xrun() to be always defined as it was before. Signed-off-by: Jarkko Nikula <jhnikula@gmail.com> Cc: Jaroslav Kysela <perex@perex.cz> Signed-off-by: Takashi Iwai <tiwai@suse.de>
2010-01-26Merge remote branch 'alsa/devel' into topic/miscTakashi Iwai1-2/+5
2010-01-26ALSA: pcm_lib - return back hw_ptr_interruptJaroslav Kysela1-2/+5
Clemens Ladisch noted for hw_ptr_removal in "cleanup & merge hw_ptr update functions" commit: "It is possible for the status/delay ioctls to be called when the sound card's pointer register alreay shows a position at the beginning of the new period, but immediately before the interrupt is actually executed. (This happens regularly on a SMP machine with mplayer.) When that happens, the code thinks that the position must be at least one period ahead of the current position and drops an entire buffer of data." Return back the hw_ptr_interrupt variable. The last interrupt pointer is always computed from the latest hw_ptr instead of tracking it separately (in this case all hw_ptr checks and modifications might influence also hw_ptr_interrupt and it is difficult to keep it consistent). Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2010-01-21Merge remote branch 'alsa/devel' into topic/miscTakashi Iwai1-10/+10
2010-01-21ALSA: pcm_core: Fix wake_up() optimizationJaroslav Kysela1-10/+10
This change fixes the "ALSA: pcm_lib - optimize wake_up() calls for PCM I/O" commit. New sleeping queue is introduced to separate user space and kernel space wake_ups. runtime->nowake is renamed to twake (transfer wake). Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2010-01-13Merge branch 'devel' of git.alsa-project.org:alsa-kernel into topic/miscTakashi Iwai1-3/+5
2010-01-13ALSA: pcm_lib - fix wrong delta print for jiffies checkJaroslav Kysela1-3/+5
The previous jiffies delta was 0 in all cases. Use hw_ptr variable to store and print original value. Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2010-01-12Merge commit alsa/devel into topic/miscTakashi Iwai1-196/+222
Conflicts: include/sound/version.h
2010-01-08Merge branch 'topic/hda' of git://git.kernel.org/pub/scm/linux/kernel/git/tiwai/sound-2.6 into develJaroslav Kysela1-2/+2
2010-01-08ALSA: pcm_lib: fix "something must be really wrong" conditionJaroslav Kysela1-1/+1
When runtime->periods == 1 or when pointer crosses end of ring buffer, the delta might be greater than buffer_size. Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2010-01-07ALSA: pcm_lib - optimize wake_up() calls for PCM I/OJaroslav Kysela1-10/+20
As noted by pl bossart <bossart.nospam@gmail.com>, the PCM I/O routines (snd_pcm_lib_write1, snd_pcm_lib_read1) should block wake_up() calls until all samples are not processed. Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2010-01-07ALSA: pcm_lib - cleanup & merge hw_ptr update functionsJaroslav Kysela1-182/+97
Do general cleanup in snd_pcm_update_hw_ptr*() routines and merge them. The main change is hw_ptr_interrupt variable removal to simplify code logic. This variable can be computed directly from hw_ptr. Ensure that updated hw_ptr is not lower than previous one (it was possible with old code in some obscure situations when interrupt was delayed or the lowlevel driver returns wrong ring buffer position value). Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2010-01-07ALSA: pcm_lib - add possibility to log last 10 DMA ring buffer positionsJaroslav Kysela1-23/+117
In some debug cases, it might be usefull to see previous ring buffer positions to determine position problems from the lowlevel drivers. Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2010-01-07ALSA: pcm_lib.c - convert second xrun_debug() parameter to use definesJaroslav Kysela1-10/+17
To increase code readability, convert send xrun_debug() argument to use defines. Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2009-12-22ALSA: refine rate selection in snd_interval_ratnum()Krzysztof Helt1-3/+17
Refine the rate selection by choosing the rate closer to the requested one in case of selecting single frequency. Previously, the higher rate was always selected. Also, fix problem with the best_diff unsigned int value wrapping (turning negative). Signed-off-by: Krzysztof Helt <krzysztof.h1@wp.pl> Signed-off-by: Takashi Iwai <tiwai@suse.de>
2009-12-21ALSA: fix incorrect rounding direction in snd_interval_ratnum()Krzysztof Helt1-2/+2
The direction of rounding is incorrect in the snd_interval_ratnum() It was detected with following parameters (sb8 driver playing 8kHz stereo file): - num is always 1000000 - requested frequency rate is from 7999 to 7999 (single frequency) The first loop calculates div_down(num, freq->min) which is 125. Thus, a frequency range's minimum value is 1000000 / 125 = 8000 Hz. The second loop calculates div_up(num, freq->max) which is 126 The frequency range's maximum value is 1000000 / 126 = 7936 Hz. The range maximum is lower than the range minimum so the function fails due to empty result range. Signed-off-by: Krzysztof Helt <krzysztof.h1@wp.pl> Signed-off-by: Takashi Iwai <tiwai@suse.de>
2009-09-10Merge branch 'topic/pcm-drain-nonblock' into for-linusTakashi Iwai1-4/+8
* topic/pcm-drain-nonblock: ALSA: pcm - Increase protocol version ALSA: pcm - Fix drain behavior in non-blocking mode
2009-08-25Merge branch 'fix/misc' of git://git.kernel.org/pub/scm/linux/kernel/git/tiwai/sound-2.6Linus Torvalds1-31/+8
* 'fix/misc' of git://git.kernel.org/pub/scm/linux/kernel/git/tiwai/sound-2.6: sound: pcm_lib: fix unsorted list constraint handling sound: vx222: fix input level control range check ALSA: ali5451: fix timeout handling in snd_ali_{codecs,timer}_ready()
2009-08-25sound: pcm_lib: fix unsorted list constraint handlingClemens Ladisch1-31/+8
snd_interval_list() expected a sorted list but did not document this, so there are drivers that give it an unsorted list. To fix this, change the algorithm to work with any list. This fixes the "Slave PCM not usable" error with USB devices that have multiple alternate settings with sample rates in decreasing order, such as the Philips Askey VC010 WebCam. http://bugzilla.kernel.org/show_bug.cgi?id=14028 Reported-and-tested-by: Andrzej <adkadk@gmail.com> Signed-off-by: Clemens Ladisch <clemens@ladisch.de> Cc: <stable@kernel.org> Signed-off-by: Takashi Iwai <tiwai@suse.de>
2009-08-20ALSA: pcm - Fix drain behavior in non-blocking modeTakashi Iwai1-4/+8
The current PCM core has the following problems regarding PCM draining in non-blocking mode: - the current f_flags isn't checked in snd_pcm_drain(), thus changing the mode dynamically via snd_pcm_nonblock() after open doesn't work. - calling drain in non-blocking mode just return -EAGAIN error, but doesn't provide any way to sync with draining. This patch fixes these issues. - check file->f_flags in snd_pcm_drain() properly - when O_NONBLOCK is set, PCM core sets the stream(s) to DRAIN state but quits ioctl immediately without waiting the whole drain; the caller can sync the drain manually via poll() Signed-off-by: Takashi Iwai <tiwai@suse.de>
2009-07-23ALSA: pcm - Fix hwptr buffer-size overlap bugTakashi Iwai1-1/+1
The fix 79452f0a28aa5a40522c487b42a5fc423647ad98 introduced another bug due to the missing offset for the overlapped hwptr. When the hwptr goes back to zero, the delta value has to be corrected with the buffer size. Otherwise this causes looping sounds. Signed-off-by: Takashi Iwai <tiwai@suse.de>
2009-07-23ALSA: pcm - Fix warnings in debug loggingsTakashi Iwai1-12/+12
Add proper cast. Signed-off-by: Takashi Iwai <tiwai@suse.de>
2009-07-23ALSA: pcm - Add logging of hwptr updates and interrupt updatesTakashi Iwai1-0/+25
Added the logging functionality to xrun_debug to record the hwptr updates via snd_pcm_update_hw_ptr() and snd_pcm_update_hwptr_interrupt(), corresponding to 16 and 8, respectively. For example, # echo 9 > /proc/asound/card0/pcm0p/xrun_debug will record the position and other parameters at each period interrupt together with the normal XRUN debugging. Signed-off-by: Takashi Iwai <tiwai@suse.de>
2009-07-22ALSA: pcm - Fix regressions with VMwareTakashi Iwai1-1/+10
VMware tends to report PCM positions and period updates at utterly wrong timing. This screws up the recent PCM core code that tries to correct the position based on the irq timing. Now, when a backward irq position is detected, skip the update instead of rebasing. (This is almost the old behavior before 2.6.30.) Signed-off-by: Takashi Iwai <tiwai@suse.de>
2009-06-10Merge branch 'topic/pcm-jiffies-check' into for-linusTakashi Iwai1-19/+70
* topic/pcm-jiffies-check: ALSA: pcm - A helper function to compose PCM stream name for debug prints ALSA: pcm - Fix update of runtime->hw_ptr_interrupt ALSA: pcm - Fix a typo in hw_ptr update check ALSA: PCM midlevel: lower jiffies check margin using runtime->delay value ALSA: PCM midlevel: Do not update hw_ptr_jiffies when hw_ptr is not changed ALSA: PCM midlevel: introduce mask for xrun_debug() macro ALSA: PCM midlevel: improve fifo_size handling
2009-06-08ALSA: pcm - A helper function to compose PCM stream name for debug printsTakashi Iwai1-6/+17
Use a common helper function for the PCM stream name displayed in XRUN and buffer-pointer debug prints. Signed-off-by: Takashi Iwai <tiwai@suse.de>
2009-06-07ALSA: pcm - Fix update of runtime->hw_ptr_interruptTakashi Iwai1-1/+2
The commit 13f040f9e55d41e92e485389123654971e03b819 made another regression, the missing update of runtime->hw_ptr_interrupt. Since this field is only checked in snd_pcmupdate__hw_ptr_interrupt(), not in snd_pcm_update_hw_ptr(), it must be updated before the hw_ptr change check. Signed-off-by: Takashi Iwai <tiwai@suse.de>
2009-06-06ALSA: pcm - Fix a typo in hw_ptr update checkJaroslav Kysela1-1/+1
Fix a typo in the commit 13f040f9e55d41e92e485389123654971e03b819 ALSA: PCM midlevel: Do not update hw_ptr_jiffies when hw_ptr is not changed which causes obvious problems with PA. Signed-off-by: Takashi Iwai <tiwai@suse.de>
2009-06-05ALSA: Clean up 64bit division functionsTakashi Iwai1-1/+2
Replace the house-made div64_32() with the standard div_u64*() functions. Signed-off-by: Takashi Iwai <tiwai@suse.de>
2009-05-29ALSA: PCM midlevel: lower jiffies check margin using runtime->delay valueJaroslav Kysela1-2/+10
When hardware has large FIFO, it is necessary to lower jiffies margin by count of queued samples. Signed-off-by: Jaroslav Kysela <perex@perex.cz> Signed-off-by: Takashi Iwai <tiwai@suse.de>
2009-05-29ALSA: PCM midlevel: Do not update hw_ptr_jiffies when hw_ptr is not changedJaroslav Kysela1-2/+14
Some hardware might have bigger FIFOs and DMA pointer value will be updated in large chunks. Do not update hw_ptr_jiffies and position timestamp when hw_ptr value was not changed. Signed-off-by: Jaroslav Kysela <perex@perex.cz> Signed-off-by: Takashi Iwai <tiwai@suse.de>
2009-05-29ALSA: PCM midlevel: introduce mask for xrun_debug() macroJaroslav Kysela1-9/+9
For debugging purposes, it is better to separate actions. Bit-values: 1: show bad PCM ring buffer pointer 2: show also stack (to debug kernel latency issues) 4: check pointer against system jiffies Example: 5: show bad PCM ring buffer pointer and do jiffies check Signed-off-by: Jaroslav Kysela <perex@perex.cz> Signed-off-by: Takashi Iwai <tiwai@suse.de>
2009-05-29ALSA: PCM midlevel: improve fifo_size handlingJaroslav Kysela1-0/+19
Move the fifo_size assignment to hw->ioctl callback to allow lowlevel drivers overwrite the default behaviour. fifo_size is in frames not bytes as specified in asound.h and alsa-lib's documentation, but most hardware have fixed byte based FIFOs. Introduce internal SNDRV_PCM_INFO_FIFO_IN_FRAMES. Signed-off-by: Jaroslav Kysela <perex@perex.cz> Signed-off-by: Takashi Iwai <tiwai@suse.de>
2009-05-27ALSA: Enable PCM hw_ptr_jiffies check only in xrun_debug modeTakashi Iwai1-1/+8
The PCM hw_ptr jiffies check results sometimes in problems when a hardware doesn't give smooth hw_ptr updates. So far, au88x0 and some other drivers appear not working due to this strict check. However, this check is a nice debug tool, and the capability should be still kept. Hence, we disable this check now as default unless the user enables it by setting the xrun_debug mode to the specific stream via a proc file. Signed-off-by: Takashi Iwai <tiwai@suse.de>
2009-05-27ALSA: Fix invalid jiffies check after pauseTakashi Iwai1-1/+0
The hw_ptr_jiffies has to be reset properly to avoid the invalid check of jiffies delta in snd_pcm_update_hw_ptr*() functions. Especailly this patch fixes the bogus jiffies check after the puase and resume. This patch is a modified version of the original patch by Jaroslav. Signed-off-by: Takashi Iwai <tiwai@suse.de>
2009-04-28ALSA: pcm core - Avoid jiffies check for devices with BATCH flagTakashi Iwai1-0/+7
The hardware devices with SNDRV_PCM_INFO_BATCH flag can't give the precise current position. And such hardwares have often big FIFO in addition to the ring buffer, and it screws up the jiffies check in pcm_lib.c. This patch adds a simple check of info flag so that the driver skips the jiffies check in snd_pcm_period_elapsed() when BATCH flag is set. Signed-off-by: Takashi Iwai <tiwai@suse.de>
2009-04-10[ALSA] pcm-midlevel: Add more strict buffer position checks based on jiffiesJaroslav Kysela1-8/+39
Some drivers like Intel8x0 or Intel HDA are broken for some hardware variants. This patch adds more strict buffer position checks based on jiffies when internal hw_ptr is updated. Enable xrun_debug to see mangling of wrong positions. As a side effect, the hw_ptr interrupt update routine might do slightly better job when many interrupts are lost. Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2009-03-20ALSA: pcm - Safer boundary checksTakashi Iwai1-4/+5
Make the boundary checks a bit safer. These caese are rare or theoretically won't happen, but nothing bad to keep the checks safer... Signed-off-by: Takashi Iwai <tiwai@suse.de>
2009-03-19ALSA: pcm - Fix delta calculation at boundary overlapTakashi Iwai1-2/+7
When the hw_ptr_interrupt reaches the boundary, it must check whether the hw_base was already lapped and corret the delta value appropriately. Also, rebasing the hw_ptr needs a correction because buffer_size isn't always aligned to period_size. Signed-off-by: Takashi Iwai <tiwai@suse.de>
2009-03-19ALSA: pcm - Reset invalid position even without debug optionTakashi Iwai1-3/+7
Always reset the invalind hw_ptr position returned by the pointer callback. The behavior should be consitent independently from the debug option. Also, add the printk_ratelimit() check to avoid flooding debug prints. Signed-off-by: Takashi Iwai <tiwai@suse.de>
2009-03-19ALSA: pcm - avoid unnecessary inlineTakashi Iwai1-5/+6
Remove unnecessary explicit inlininig of internal functions. Let compiler optimize. Signed-off-by: Takashi Iwai <tiwai@suse.de>
2009-03-19ALSA: pcm - Fix a typo in error messagesTakashi Iwai1-1/+1
Fix a typo in error messages; forgotten after a copy&paste error. Signed-off-by: Takashi Iwai <tiwai@suse.de>
2009-03-09ALSA: Rewrite hw_ptr updatersTakashi Iwai1-45/+83
Clean up and improve snd_pcm_update_hw_ptr*() functions. snd_pcm_update_hw_ptr() tries to detect the unexpected hwptr jumps more strictly to avoid the position mess-up, which often results in the bad quality I/O with pulseaudio. The hw-ptr skip error messages are printed when xrun proc is set to non-zero. Signed-off-by: Takashi Iwai <tiwai@suse.de>
2008-10-16ALSA: kernel docs: fix sound/core/ kernel-docRandy Dunlap1-24/+24
Add kernel-doc function short descriptions to sound/core functions that are missing this short description. Mostly this involves moving some of the function description onto the @funcname line. Also correct a few variable names and fix other kernel-doc notation. Signed-off-by: Randy Dunlap <randy.dunlap@oracle.com> Signed-off-by: Takashi Iwai <tiwai@suse.de>
2008-08-13ALSA: Kill snd_assert() in sound/core/*Takashi Iwai1-41/+61
Kill snd_assert() in sound/core/*, either removed or replaced with if () with snd_BUG_ON(). Signed-off-by: Takashi Iwai <tiwai@suse.de> Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2008-01-31[ALSA] PCM interface - rename SNDRV_PCM_TSTAMP_MMAP to SNDRV_PCM_TSTAMP_ENABLEJaroslav Kysela1-2/+2
Change semantics for SNDRV_PCM_TSTAMP_MMAP. Doing timestamping only in the interrupt handler might cause that hw_ptr is not related to actual timestamp. With this change, grab timestamp at every hw_ptr update to have always valid timestamp + ring buffer position pair. With this change, SNDRV_PCM_TSTAMP_MMAP was renamed to SNDRV_PCM_TSTAMP_ENABLE. It's no regression (I think). Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2008-01-31[ALSA] Remove sound/driver.hTakashi Iwai1-1/+0
This header file exists only for some hacks to adapt alsa-driver tree. It's useless for building in the kernel. Let's move a few lines in it to sound/core.h and remove it. With this patch, sound/driver.h isn't removed but has just a single compile warning to include it. This should be really killed in future. Signed-off-by: Takashi Iwai <tiwai@suse.de> Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2008-01-31[ALSA] Remove PCM sleep_min and tickTakashi Iwai1-110/+3
The 'tick' in PCM is set (again) via sw_params. And, nobody uses this feature at all except for a command line option of aplay. (This is literally 'nobody', as I checked alsa-lib API calls in all programs in major distros.) Above all, if we need finer wake-ups for the position update, it's basically an issue that the driver should solve, not tuned by each application. Signed-off-by: Takashi Iwai <tiwai@suse.de> Signed-off-by: Jaroslav Kysela <perex@perex.cz>