HDA-Intel: present up to 8 HDMI/DP outputs via "hdmi" device

Some new AMD cards have HDA codecs presenting 6 connected HDMI/DP pin
nodes (plus 1 unconnected pin node) according to the ALSA card database.

Example:
http://www.alsa-project.org/db/?f=de3ced7af41de0ed54d218650e5e2f16c511787b

Bump the maximum number of presented HDMI outputs per card via the
"hdmi" PCM from 4 to 8 (so that the last possible device is DEV=7).

Note that HDMI PCM devices DEV=4..7 use shared PCM device numbers, so
HDA cards that have over 4 audio PCM devices or multiple S/PDIF or modem
devices will have their remaining PCM devices misrepresented as HDMI
devices.

Signed-off-by: Anssi Hannula <anssi.hannula@iki.fi>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
snd_tlv_convert_from_dB: fix decreasing gain across entries

Currently, for a TLV consisting of TLV_DB_SCALE_ITEMs, if e.g. alsamixer
calls snd_mixer_selem_set_playback_dB() with a value that is in-between
two TLV_DB_SCALE_ITEMs, and xdir is negative, the selected raw hardware
value is the minimum in the first range above that value, rather than the
maximum in the last range below that value.

The user-visible symptom is that in alsamixer, pressing the down key to
reduce the value sticks at certain points, and cannot be incrementally
reduced any further, although directly selecting a much lower value (e.g.
by pressing 0..9) works as expected. This is triggered e.g. by
sound/soc/codec/max98090.c's max98090_hp_tlv[].

Fix this by checking whether xdir is positive or not, rather than
checking whether it has a non-zero value. The code to select the previous
range's max value is already present. This matches how xdir is used in
other parts of the code.

Signed-off-by: Stephen Warren <swarren@nvidia.com>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
remove unnecessary/obsolete compat/hsearch_r.c

The usage of hsearch functions where removed long time
ago in commit 273d115de05574251bdd661747ecb68449a5cf1d.
This patch highly increases portability for non-glibc systems.

Remove the complete compat directory as requested by
Takashi Iwai.

Signed-off-by: Waldemar Brodkorb <wbx@openadk.org>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
local.h: include sys/types.h to fix issues with pcm.h

sys/types.h is required for the u_int_XX types used by pcm.h.
since a change in pcm.h is not desired, we add the inclusion
to the header that includes pcm.h during build.

Signed-off-by: John Spencer <maillist-alsa@barfooze.de>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
test/chmap: Add missing usage text for -s option

Signed-off-by: Takashi Iwai <tiwai@suse.de>
include/global.h - don't define timeval and timespec structures for !glibc

On request from John Spencer <maillist-alsa@barfooze.de> .

Signed-off-by: Jaroslav Kysela <perex@perex.cz>
conf.c: use portable way to initialize recursive mutex

PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP is not in POSIX, as _NP
(non-portable) suggests.

exposing such a symbol in musl libc would lock in the ABI for all
times and makes it impossible to do future changes to the under-
lying struct without hideous symbol versioning hacks.

use the portable way instead: pthread_once was designed for such
cases.

Signed-off-by: Timo Teräs <timo.teras@iki.fi>
Tested-by: John Spencer <maillist-alsa@barfooze.de>
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
pcm_file: fix SEGFAULT if file option is missing while infile is not.

Commit 5c5f1358123af69155267463a0b6254ad9cbecc4 requires both file and
infile options to be missing to report a failure.
In fact, only file option is mandatory and should be checked there.
Otherwise, NULL file triggers segfault in
snd_pcm_file_replace_fname() called from
snd_pcm_file_open_output_file().
infile option is optional, so don't report fatal error if it's missing.

Signed-off-by: Andrey Mazo <mazo@telum.ru>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
pcm_file: fixed memory leak.

Valgrind report for this leak was:

Command: aplay -Dfile:'/tmp/qqq',raw qqq.wav

14 bytes in 1 blocks are definitely lost in loss record 1 of 2
   at 0x402BF5C: malloc (in /usr/lib/valgrind/vgpreload_memcheck-x86-linux.so)
   by 0x40D7557: snd_pcm_file_hw_params (in /usr/lib/libasound.so.2.0.0)
   by 0x40BA093: _snd_pcm_hw_params_internal (in /usr/lib/libasound.so.2.0.0)
   by 0x40AB831: snd_pcm_hw_params (in /usr/lib/libasound.so.2.0.0)
   by 0x804C523: ??? (in /usr/bin/aplay)
   by 0x804E5B7: ??? (in /usr/bin/aplay)
   by 0x804FC8C: ??? (in /usr/bin/aplay)
   by 0x80520FB: ??? (in /usr/bin/aplay)
   by 0x4184942: (below main) (libc-start.c:226)

Signed-off-by: Andrey Mazo <mazo@telum.ru>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
pcm_file: don't touch infile on playback and output file on capture.

Commit 1d80c5b901baf7e1b7998dfa518532fbd64e4283 message describes
behaviour in case of specified infile option as
'No file writes will take place in this case'.
But this is clearly not the case as output file gets truncated while
running `arecord -Dtestin >/dev/null`, where "testin" is defined as
pcm.testin {
	type file
	slave.pcm null
	file "/tmp/qqqq.out"
	infile "/tmp/qqqq.in"
	format "raw"
}

Besides that, the existing behaviour is rather counterintuitive,
requiring both output and input files to exist and making access to them
regardless of playback or capture intention.
Also, it's very confusing to get output file truncated while trying to
just capture from the device.

Current changeset introduces the following behaviour:
 - output file ("file" option) is only (p)open()'ed for writing
   only on playback to the device
 - any data is written to the output file descriptor
   (provided with "file" option) only on playback to the device
 - input file ("infile" option) is only open()'ed for reading only on
   capture from the device
 - any data is read from the input file descriptor
   (provided with the "infile" option) only on capture from the device

Signed-off-by: Andrey Mazo <mazo@telum.ru>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
pcm_file: document new argument to snd_pcm_file_open().

Document function argument, added in commit
4081be0b87ab9fa53a8906e66bc240f18a7a9a54.

Signed-off-by: Andrey Mazo <mazo@telum.ru>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
dmix: Don't use assert() and abort()

We seem to still have some races at closing a dmix stream, but
aborting is the worst option.  Let's make not melt down.

Reference: https://bugzilla.novell.com/show_bug.cgi?id=852446
Signed-off-by: Takashi Iwai <tiwai@suse.de>
minor malloc changes

replace malloc + memset with calloc since calloc may skip the memset if
returned memory comes directly from sbrk()

use malloc instead of malloc if first thing done with allocated memory is
to flip all bits to 1.

Signed-off-by: Olivier Langlois <olivier@trillion01.com>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
alsa-lib: minor typo in pcm doc

Added a missing 'f' in the word 'diferent'

Signed-off-by: Olivier Langlois <olivier@trillion01.com>
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
control_hw: fix potential memory leak

Signed-off-by: Ivan Sorokin <vanyacpp@gmail.com>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
pcm: initialize pcm_dmix monotonic field

not doing so, leaves the pcm object in an inconsistent state since
'info' field is copied from the slave which is then used when
snd_pcm_hw_params_is_monotonic() is called.

For instance, when using dmix with aplay and an underrun is occuring, the following
info is returned:

underrun!!! (at least 1248687948.256 ms long)
Status:
  state       : XRUN
  trigger_time: 1390347762.628483000
  tstamp      : 1390347766.184350000
  delay       : -635
  avail       : 15687
  avail_max   : 15675

now is computed from CLOCK_MONOTONIC while pcm status tstamps are from gettimeofday().

After the fix, underruns are still occuring on my setup but at least the displayed info
is correct:

underrun!!! (at least 7630.409 ms long)
Status:
  state       : XRUN
  trigger_time: 7652.739201431
  tstamp      : 7660.369600636
  delay       : -624
  avail       : 15676
  avail_max   : 15664

Signed-off-by: Olivier Langlois <olivier@trillion01.com>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
pcm: initialize monotonic field for dshare and dsnoop, too

Just like the previous fix for dmix, we need update for dshare and
dsnoop plugins.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
pcm: use CLOCK_REALTIME for non-monotonic ts

gettimeofday() is the same than clock_gettime(CLOCK_REALTIME)
except for the loss of precision and the double unnecessary
conversion timespec <-> timeval.

Signed-off-by: Olivier Langlois <olivier@trillion01.com>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
alsa-lib: heavy pcm atomics cleanup

The following patch comes from the realization that at least ARM code
for atomics is quite broken and nobody has cared for a decade.

A quick dive shows that only snd_atomic_{read,write}_{begin,end}
appear to be used widely. These are implemented using wmb/rmb.

Only other use of atomic functions is in pcm_meter.c.
The #SND_PCM_TYPE_METER plugin type appears rarely, if ever, used.
I presume these days anyone who wants a meter/scope will do in pulseaudio
layer instead of alsa.

It would seem better fit to have pcm_meter in alsa-plugins instead
of alsa-lib, but I guess that would be an ABI break...

So instead, I'm proposing here

1. Removal of all hand-crafted atomics from iatomic.h apart from barriers,
   which are used in snd_atomic_{read,write}_{begin,end}.

2. Using __sync_synchronize as the default fallback for barriers. This
   has been available since gcc 4.1, so it shouldn't be a problem.

3. Defining the few atomics used by pcm_meter.c withing pcm_meter.c
   itself, using gcc atomic builtins[1].

4. Since gcc atomic builtins are available only since gcc 4.7, add a check for
   that in gcc configure.in, and don't build pcm meter plugin if using
   older gcc.

The last point has the impact, that if there actually is someone who 1)
uses the meter plugin 2) wants to upgrade to 2014 alsa-lib 3) but
does not want to use a 2012+ gcc - that someone will be inconvenienced.

Finally remove the unneeded configure check for cpu type. We can
trust the gcc to set right flags for us.

[1] http://gcc.gnu.org/onlinedocs/gcc/_005f_005fatomic-Builtins.html

Signed-off-by: Riku Voipio <riku.voipio@linaro.org>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
conf: Add basic infrastructure for 2.1 surround sound

For now, we do 2.1 over 5.1, because that's what ALSA allows per default.

Signed-off-by: David Henningsson <david.henningsson@canonical.com>
Signed-off-by: Takashi Iwai <tiwai@suse.de>