source: src-qt4/xtrafiles/local/share/pcbsd/scripts/sound-dev-changed.sh @ 25ff000

releng/10.0.1releng/10.0.2
Last change on this file since 25ff000 was 25ff000, checked in by Kris Moore <kris@…>, 6 months ago

After devd notifies us of a new audio device and we switch to it, also switch
pulseaudio to using it by default

  • Property mode set to 100755
File size: 1.8 KB
Line 
1#!/bin/sh
2
3# Action can be add / del
4action=$1
5cdev=$2
6
7regen_ossconf()
8{
9PCM_OSS_CONF_DIR=/compat/linux/etc/alsa/pcm/
10PCM_OSS_CONF=${PCM_OSS_CONF_DIR}pcm-oss.conf
11
12if [ ! -d $PCM_OSS_CONF_DIR ]; then
13  return
14fi
15
16PCM=`egrep -o 'pcm[0-9]+' /dev/sndstat | egrep -o '[0-9]+'`
17OSSCONF=`cat <<EOF
18# pcm-oss plugin configuration
19# generated by ${0}
20
21pcm.oss {
22        type oss
23        device /dev/dsp
24        hint {
25                description "Open Sound System"
26        }
27}
28
29ctl.oss {
30        type oss
31        device /dev/mixer
32        hint {
33                description "Open Sound System"
34        }
35}
36EOF`
37
38for NUM in $PCM; do
39  UNIT_DESC=`sysctl -in dev.pcm.${NUM}.%desc`
40 
41  OSSCONF_UNITS=${OSSCONF_UNITS}`cat <<EOF
42
43 
44pcm.oss${NUM} {
45        type oss
46        device /dev/dsp${NUM}
47        hint {
48                description "oss${NUM}: ${UNIT_DESC}"
49        }
50}
51
52ctl.oss${NUM} {
53        type oss
54        device /dev/mixer${NUM}
55        hint {
56                description "oss${NUM}: ${UNIT_DESC}"
57        }
58}
59EOF`
60done
61
62echo "${OSSCONF}${OSSCONF_UNITS}" > $PCM_OSS_CONF
63}
64
65set_new_dev()
66{
67   # Dont keep changing the device at bootup, wait until after the system loads before enabling this
68   ps -axoargs | grep -q "^/usr/libexec/getty "
69   if [ $? -ne 0 ] ; then
70      return
71   fi
72
73   mixerNum=`echo ${cdev} | egrep -o '[0-9]+'`
74
75   # Can new dev play?
76   cat /dev/sndstat | grep pcm${mixerNum} | grep -q play
77   if [ $? -ne 0 ] ; then
78      return
79   fi
80
81   # make new device the default one
82   sysctl hw.snd.default_unit=$mixerNum
83
84   # Look for pulseaudio daemons to change audio sinks on
85   for user in `ps -auwwx | grep 'pulseaudio --start' | grep -v 'grep' | awk '{print $1}'`
86   do
87      su $user -c "pactl set-default-sink $mixerNum"
88   done
89
90}
91
92# Update device based upon action
93case $action in
94   add) set_new_dev ;;
95     *) ;;
96esac
97
98# Re-Create the linux OSS conf
99regen_ossconf
100
101exit 0
Note: See TracBrowser for help on using the repository browser.