Commit Graph

41 Commits

Author SHA1 Message Date
Mark Johnston
5c2b216a1c mixer: Fix default_unit switching with mixers that have no devices
Apparently it's possible for a mixer to have no devices:

$ mixer -f /dev/mixer2
pcm2:mixer: <USB audio> at ? kld snd_uaudio (rec)
$

If this is the default sound device, an attempt to change the default
unit using mixer -d fails with a segfault because mod_dunit is called
with a NULL device pointer, which is dereferenced to get the parent
mixer.

ctl_dunit seems to be a dummy, i.e., we don't actually need it and can
simply pass the mixer to mod_dunit() directly.  This patch removes that
structure and associated indirection to fix the crash.

Reviewed by:	christos, hselasky
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D38060
2023-01-16 08:02:54 -05:00
Kyle Evans
4014365e42 mixer: remove volume backwards compat, add % interpretation
The current situation is fairly confusing, where an integer is interpreted
as a percent until you slap a decimal on it and magically it becomes an
absolute value.

Let's have a flag day in 14.0 and remove this shim entirely.  Setting with
percent can still be useful, so allow a trailing '%' to indicate as such.
As a side effect, we tighten down the format allowed in the volume a little
bit by ensuring there's no trailing garbage after the value once it's
separated into left and right components.

Reviewed by:	christos, hselasky, pauamma_gundo.com (manpages)
Relnotes:	yes
Differential Revision:	https://reviews.freebsd.org/D35101
2022-06-17 22:50:58 -05:00
Hans Petter Selasky
f250ff5ff3 mixer(8): Improve shorthand volume parsing.
The initial patch had a bug where the full volume syntax, floating point values,
:, + and -, wasn't accepted.

While at it move some defines to enum's.

Fixes:			da3d4469ef
Submitted by:		christos@
Differential Revision:	https://reviews.freebsd.org/D34617
Sponsored by:		NVIDIA Networking
2022-03-20 20:19:16 +01:00
Hans Petter Selasky
da3d4469ef mixer(8): Add shorthand syntax for setting the volume.
dev.volume=X[.X] can now also be written as dev=X[.X] .

Requested by:		hselasky@ and bsduck (FreeBSD forums)
Submitted by:		christos@
Differential Revision:	https://reviews.freebsd.org/D34612
Sponsored by:		NVIDIA Networking
2022-03-20 17:32:46 +01:00
Hans Petter Selasky
60bdfe9869 mixer(8): Remove [.volume] string from default printout.
Submitted by:		christos@
Differential Revision:	https://reviews.freebsd.org/D34591
Sponsored by:		NVIDIA Networking
2022-03-20 17:32:43 +01:00
Hans Petter Selasky
aa92785a5b mixer(8): Add -h option to show usage.
Differential Revision:	https://reviews.freebsd.org/D32508
Submitted by:	christos@
Sponsored by:	NVIDIA Networking
2021-10-16 10:40:37 +02:00
Hans Petter Selasky
67829b6307 mixer(8): Print usage to standard error.
Differential Revision:	https://reviews.freebsd.org/D32507
Submitted by:	christos@
Sponsored by:	NVIDIA Networking
2021-10-15 15:56:37 +02:00
Hans Petter Selasky
63dcf7fda2 mixer(8): Fix mixer status line for /dev/dspX.vpY mixer devices.
In some cases when passing /dev/dspX.vpY as mixer devices, m->ci.longname and
m->ci.hw_info will be empty. Don't print any brackets and parentheses
in this case.

Differential Revision:	https://reviews.freebsd.org/D32500
Submitted by:	christos@
Sponsored by:	NVIDIA Networking
2021-10-15 11:13:29 +02:00
Hans Petter Selasky
8fc722a572 mixer(8): Compile fix for when the "char" type is unsigned.
Differential Revision:	https://reviews.freebsd.org/D31636
Sponsored by:	NVIDIA Networking
2021-09-22 20:58:47 +02:00
Hans Petter Selasky
903873ce15 Implement and use new mixer(3) library for FreeBSD.
Wiki article: https://wiki.freebsd.org/SummerOfCode2021Projects/SoundMixerImprovements
This project was part of Google Summer of Code 2021.

Submitted by:	christos@
Differential Revision:	https://reviews.freebsd.org/D31636
Sponsored by:	NVIDIA Networking
2021-09-22 19:43:56 +02:00
Mateusz Piotrowski
babc4e8145 mixer(8): Report an error if the passed value is an empty string
This patch fixes a bug that made the mixer command enter
an infinite loop when instructed to set the value of a device
to an empty string (e.g., `mixer vol ""`).

Additionally, some tests for mixer(8) are being added.

PR:		240039
Reviewed by:	hselasky, mav
Approved by:	src (hselasky, mav)
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D21409
2019-08-25 17:55:31 +00:00
Pedro F. Giffuni
2b223a01ef mixer(8): Prevent possible sscanf() overflow.
Fix %s buffer sizes in sscanf().

Obtained from:	DragonflyBSD (git dab952e2)
MFC after:	5 days
2017-04-29 19:12:44 +00:00
Conrad Meyer
02dc4f1751 mixer(8): Style: Tag no-return usage() as __dead2
Coverity really should have figured this out from the exit(3) call at the end
of the routine, but just make it explicit.

No functional change.

Reported by:	Coverity
CID:		1304866 (false positive double-close of 'baz')
Sponsored by:	EMC / Isilon Storage Division
2016-05-11 17:27:27 +00:00
Alexander Motin
19e79b284d Return proper error message if recording device is not specified.
MFC after:	1 week
2012-01-27 09:15:55 +00:00
Ed Schouten
4d4fda8051 Mark global functions and/or variables in mixer(8) static where possible.
This allows compilers and static analyzers to do more thorough analysis.
2011-11-06 19:02:13 +00:00
Jung-uk Kim
57067fb903 Fix a typo. 2008-03-15 01:36:20 +00:00
Jung-uk Kim
e68adf0bb6 Clean up code and fix style(9) nits. 2008-03-15 01:20:05 +00:00
Jung-uk Kim
35ebab0a33 - Check device masks and bypass printing headers if capable device does
not exist.  /etc/rc.d/mixer tried to restore non-existent recording
source because /var/var/db/mixer*-state contains '=rec' for example.
- Remove hardcoded mixer2 and mixer3 and do the right thing.
- Replace getopt(3) with hand-rolled option parser.  It was not able
to handle 'mixer -rec mic' although it is a valid command.
- Make '-s' and '-S' mutualy exclusive as mixer(8) says.
- Do not re-read recording source unless it has been modified.
2008-03-15 01:09:47 +00:00
Ariff Abdullah
90f0732d68 - Fix possible memory leak due to repetetive strdup(3) without matching
free(3).
- print_recsrc() should honor shortflag and give appropriate output for
  later consumption by /etc/rc.d/mixer. This will ensure that recording
  device selections survived across reboot. Output everything to stdout
  instead if stderr.

MFC after:	3 days
2006-01-01 20:19:49 +00:00
Matthew N. Dodd
a103924701 Add the -S flag which produces the -s output without
mixing field separators.
2005-04-13 07:11:54 +00:00
Peter Grehan
5cfe0423e6 Userland signed char fixes for PPC build. Problems were using a char
return for getopt() and comparing to -1, ditto with fgetc() and EOF,
and using the kg_nice value from <sys/user.h>

Submitted by: Stefan Farfeleder <stefan@fafoe.narf.at>
Reviewed by: obrien, bde (a while back)
Tested lightly on: ppc, i386, make universe
2004-01-22 07:23:36 +00:00
Greg Lehey
a0a031aa9e Print out the current recording devices in the default printout.
Discussed with: cg

Break some particularly long lines.

Still not enough for:  bde.
2003-06-15 08:46:04 +00:00
David E. O'Brien
b728350ee6 Use __FBSDID over rcsid[]. Protect copyright[] where needed. 2003-05-03 21:06:42 +00:00
Matthew N. Dodd
22baecf2bd Implement relative mixer adjustment.
PR:		46679 (similar functionality)
2003-04-09 15:25:52 +00:00
Juli Mallett
59bfb1ea42 Print old mixer levels when setting new ones. 2002-12-30 04:23:08 +00:00
Dima Dorfman
0cbc94d0e8 Constify and set WARNS=2.
Submitted by:	Mike Barcroft <mike@q9media.com
Reviewed by:	md5(1)
2001-06-25 21:06:15 +00:00
George C A Reid
5c7f33e12c Change the behaviour of mixer slightly such that not explicitly specifying
a mixer device will set/get the master volume levels

PR:		25156
Submitted by:	Tony Finch <dot@dotat.at>
Reviewed by:	cg, nik
2001-04-09 11:10:34 +00:00
Kris Kennaway
4887d15929 Fix format string warnings 2000-11-27 07:57:44 +00:00
Maxim Sobolev
68a1b9058a Several cleanups:
- use getopt(3) to parse command line arguments instead of home-made incomplete
  parser;
- be more verbose when error in command line encountered (i.e. incorrect
  playing/recording device, incorrect recsrc syntax).
2000-08-15 05:42:39 +00:00
Jordan K. Hubbard
7a1203480c I've always wanted to be able to dump out the current values of
the mixer in a format suitable for saving and handing off to
mixer(1) at some future date to restore the settings.
Add a -s flag to do this.
2000-05-20 23:25:08 +00:00
Peter Wemm
e4ba692011 remove #ifdef FreeBSD -> <machine/soundcard.h> special case as we have it
in the standard location now.
1999-09-04 15:20:48 +00:00
Peter Wemm
97d92980a9 $Id$ -> $FreeBSD$ 1999-08-28 01:35:59 +00:00
John-Mark Gurney
2dff393b54 fix a core dump problem when you don't give -f a parameter... also compare
results of strcmp against 0 instead of !'ing results...

Closes PR: 6538
1998-05-07 14:13:16 +00:00
Philippe Charnier
5848fd5f35 According to Bruce, err(-1,..) is bogus. Change it to err(1,..). More commits
to come in this area.
1997-10-01 06:34:09 +00:00
Philippe Charnier
cd94e9c368 Use err(3). 1997-09-29 06:38:49 +00:00
Andrey A. Chernov
c997889e4b Compact usage string, devices list can be too long 1997-09-23 23:24:13 +00:00
John-Mark Gurney
eddcf96d7d major modifications to the mixer. currently it doesn't report errors
that it encounters (such as invalid device), but does print usage upon
this error...

but otherwise allows complex commands such as:
mixer -f /dev/mixer4 synth line 50 -rec mic +rec line =rec cd ^rec mix
1997-09-19 13:38:51 +00:00
Mike Pritchard
493f8e953b Make mixer print out all of the current mixer settings by defualt
instead of making the user run a separate command for each
setting they are interested in.  Closes PR#432.
1996-01-31 18:01:22 +00:00
Mike Pritchard
d1968b90c7 Fixed to not core dump if not enough arguments are given
with the +rec and -rec options.
1996-01-15 09:11:17 +00:00
Rodney W. Grimes
709e8f9ae1 Remove trailing whitespace. 1995-05-30 03:57:47 +00:00
Andrey A. Chernov
ae0de42130 non-X mixer, useful into rc.local 1995-02-15 17:33:04 +00:00