summaryrefslogtreecommitdiff
path: root/xmlrpc/sh/rtp-controller.sh
blob: 52e85f0a3c4562b8fb1caf7c3bcb4e722dbf37bb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
#!/bin/sh
#
# rtp-controller.sh
# Copyright (C) 2006,2007,2008  vidal_joshur at gva.es
# Copyright (C) 2006-2011  mariodebian at gmail
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
#

#
#  rtp controller script for TCOS
#

export DISPLAY=:0
VOLUME=85
VOLUME_MIC=75

if [ -e /conf/tcos-run-functions ]; then
  # running in thin client
  STANDALONE=0
  export XAUTHORITY=/root/.Xauthority

  DAEMONIZE="/sbin/daemonize.sh"
  PACTL="/sbin/pactl-controller.sh"
  MASTER=$(/sbin/soundctl.sh --getlevel Master 2>/dev/null | sed 's/%//g')
  MASTER_FRONT=$(/sbin/soundctl.sh --getlevel "Master Front" 2>/dev/null | sed 's/%//g')
  PCM=$(/sbin/soundctl.sh --getlevel PCM 2>/dev/null | sed 's/%//g')
  FRONT=$(/sbin/soundctl.sh --getlevel Front 2>/dev/null | sed 's/%//g')
  MIC=$(/sbin/soundctl.sh --getlevel Mic 2>/dev/null | sed 's/%//g')
  FRONT_MIC=$(/sbin/soundctl.sh --getlevel "Front Mic" 2>/dev/null | sed 's/%//g')
  REAR_MIC=$(/sbin/soundctl.sh --getlevel "Rear Mic" 2>/dev/null | sed 's/%//g')
  MIXER="tmixer -c 0 "
else
  STANDALONE=1
  #STANDALONE_USER=$(w | awk '{ if ($3 == ":0" || $2 == ":0") print $1 }' |head -1)
  STANDALONE_USER=$(/usr/lib/tcos/tcos-last --user 2>/dev/null)
  if [ "${STANDALONE_USER}" = "" ]; then echo "error: no standalone user connected"; exit 1; fi
  DBUS_HANDLER="/usr/lib/tcos/tcos-dbus-helper --username=${STANDALONE_USER} "
  DAEMONIZE="/usr/lib/tcos/daemonize.sh"
  PACTL="/usr/lib/tcos/pactl-controller.sh"
  MASTER=$(/usr/lib/tcos/soundctl.sh --getlevel Master 2>/dev/null | sed 's/%//g')
  MASTER_FRONT=$(/usr/lib/tcos/soundctl.sh --getlevel "Master Front" 2>/dev/null | sed 's/%//g')
  PCM=$(/usr/lib/tcos/soundctl.sh --getlevel PCM 2>/dev/null | sed 's/%//g')
  FRONT=$(/usr/lib/tcos/soundctl.sh --getlevel Front 2>/dev/null | sed 's/%//g')
  MIC=$(/usr/lib/tcos/soundctl.sh --getlevel Mic 2>/dev/null | sed 's/%//g')
  FRONT_MIC=$(/usr/lib/tcos/soundctl.sh --getlevel "Front Mic" 2>/dev/null | sed 's/%//g')
  REAR_MIC=$(/usr/lib/tcos/soundctl.sh --getlevel "Rear Mic" 2>/dev/null | sed 's/%//g')
  MIXER="/usr/lib/tcos/tmixer -c 0 "
fi

set_volume() {
  [ "$MASTER" = "unknow" ] && MASTER=$VOLUME
  [ "$MASTER_FRONT" = "unknow" ] && MASTER_FRONT=$VOLUME
  [ "$PCM" = "unknow" ] && PCM=$VOLUME
  [ "$FRONT" = "unknow" ] && FRONT=$VOLUME

  $MIXER sset 'PCM' 'on' >/dev/null 2>&1
  $MIXER sset 'Master' 'on' >/dev/null 2>&1
  $MIXER sset 'Master Front' 'on' >/dev/null 2>&1
  $MIXER sset 'Front' 'on' >/dev/null 2>&1
  [ $PCM -lt $VOLUME ] && $MIXER sset 'PCM' $VOLUME >/dev/null 2>&1
  [ $MASTER -lt $VOLUME ] && $MIXER sset 'Master' $VOLUME >/dev/null 2>&1
  [ $MASTER_FRONT -lt $VOLUME ] && $MIXER sset 'Master Front' $VOLUME >/dev/null 2>&1
  [ $FRONT -lt $VOLUME ] && $MIXER sset 'Front' $VOLUME >/dev/null 2>&1
}

set_mic() {
  [ "$MIC" = "unknow" ] && MIC=$VOLUME_MIC
  [ "$FRONT_MIC" = "unknow" ] && FRONT_MIC=$VOLUME_MIC
  [ "$REAR_MIC" = "unknow" ] && REAR_MIC=$VOLUME_MIC

  $MIXER sset 'Mic' 'on' >/dev/null 2>&1
  $MIXER sset 'Front Mic' 'on' >/dev/null 2>&1
  $MIXER sset 'Rear Mic' 'on' >/dev/null 2>&1
  $MIXER sset 'Mic Boost (+20dB)' 'off' >/dev/null 2>&1
  $MIXER sset 'Mic Boost' 'off' >/dev/null 2>&1
  $MIXER sset 'Front Mic Boost' 'off' >/dev/null 2>&1
  $MIXER sset 'Rear Mic Boost' 'off' >/dev/null 2>&1
  $MIXER sset 'Mic Boost (+20dB)' 0% >/dev/null 2>&1
  $MIXER sset 'Mic Boost' 0% >/dev/null 2>&1
  $MIXER sset 'Front Mic Boost' 0% >/dev/null 2>&1
  $MIXER sset 'Rear Mic Boost' 0% >/dev/null 2>&1
  $MIXER sset 'Mic' $VOLUME_MIC >/dev/null 2>&1
  $MIXER sset 'Front Mic' $VOLUME_MIC >/dev/null 2>&1
  $MIXER sset 'Rear Mic' $VOLUME_MIC >/dev/null 2>&1
  $MIXER sset 'Capture' cap >/dev/null 2>&1
  $MIXER sset 'Capture,0' cap >/dev/null 2>&1
  $MIXER sset 'Capture,1' cap >/dev/null 2>&1
  $MIXER sset 'Capture,2' cap >/dev/null 2>&1
  $MIXER sset 'Capture,3' cap >/dev/null 2>&1
  $MIXER sset 'Capture' 90% >/dev/null 2>&1
  $MIXER sset 'Capture,0' 90% >/dev/null 2>&1
  $MIXER sset 'Capture,1' 90% >/dev/null 2>&1
  $MIXER sset 'Capture,2' 90% >/dev/null 2>&1
  $MIXER sset 'Capture,3' 90% >/dev/null 2>&1
}

set_mute_mic() {
  $MIXER sset 'Mic' 'off' >/dev/null 2>&1
  $MIXER sset 'Front Mic' 'off' >/dev/null 2>&1
  $MIXER sset 'Rear Mic' 'off' >/dev/null 2>&1
  $MIXER sset 'Capture' nocap >/dev/null 2>&1
  $MIXER sset 'Capture,0' nocap >/dev/null 2>&1
  $MIXER sset 'Capture,1' nocap >/dev/null 2>&1
  $MIXER sset 'Capture,2' nocap >/dev/null 2>&1
  $MIXER sset 'Capture,3' nocap >/dev/null 2>&1
}

# version must be > 0.9.10 or 1.0
version=$(pulseaudio --version 2>/dev/null | awk '{print $2}' | awk -F"." '{if ((int($2) >= 9) && (int($3) >= 10) || (int($1)>=1)) printf "yes"}')

for arg in $1; do
  case $arg in
     startrtp-recv)
        set_volume
        set_mute_mic
        if [ ! -z $version ]; then
            $DAEMONIZE "$PACTL" "start-recv $2"
            if [ $? = 0 ]; then echo "ok"; else echo "error: starting pulse recv module"; fi
        else
            echo "error: pulseaudio version not supported"
        fi
     ;;
     stoprtp-recv)
        if [ ! -z $version ]; then
           index=$(pactl list | grep -B1 "module-rtp-recv" | head -1 | awk '{printf $3}' | sed 's/#//g')
           $DAEMONIZE "$PACTL" "stop-recv $index"
            if [ $? = 0 ]; then echo "ok"; else echo "error: stopping pulse recv module"; fi
        else
            echo "error: pulseaudio version not supported"
        fi
     ;;
     startrtp-send)
        set_volume
        set_mic
        if [ ! -z $version ]; then
            $DAEMONIZE "$PACTL" "start-send $2"
            if [ $? = 0 ]; then echo "ok"; else echo "error: starting pulse send module"; fi
        else
            echo "error: starting pulse send module, incorrect pulseaudio version"
        fi
     ;;
     stoprtp-send)
        set_mute_mic
        if [ ! -z $version ]; then
           index=$(pactl list | grep -B1 "module-rtp-send" | head -1 | awk '{printf $3}' | sed 's/#//g')
           $DAEMONIZE "$PACTL" "stop-send $index"
            if [ $? = 0 ]; then echo "ok"; else echo "error: stopping pulse send module"; fi
        else
            echo "error: stopping pulse send module, incorrect pulseaudio version"
        fi
     ;;
     startrtp-chat)
        set_volume
        set_mic
        if [ ! -z $version ]; then
            $DAEMONIZE "$PACTL" "start-chat $2"
            if [ $? = 0 ]; then echo "ok"; else echo "error: starting pulse chat mode"; fi
        else
            echo "error: starting pulse chat mode, incorrect pulseaudio version"
        fi
     ;;
     stoprtp-chat)
        set_mute_mic
        if [ ! -z $version ]; then
           index_send=$(pactl list | grep -B1 "module-rtp-send" | head -1 | awk '{printf $3}' | sed 's/#//g')
           index_recv=$(pactl list | grep -B1 "module-rtp-recv" | head -1 | awk '{printf $3}' | sed 's/#//g')
           $DAEMONIZE "$PACTL" "stop-chat $index_send $index_recv"
            if [ $? = 0 ]; then echo "ok"; else echo "error: stopping pulse chat mode"; fi
        else
            echo "error: stopping pulse chat mode, incorrect pulseaudio version"
        fi
     ;;
     *)
       echo "error"
     ;;
  esac

done