|
42 | 42 | /*** DOCUMENTATION
|
43 | 43 | <function name="VOLUME" language="en_US">
|
44 | 44 | <synopsis>
|
45 |
| - Set the TX or RX volume of a channel. |
| 45 | + Set or get the TX or RX volume of a channel. |
46 | 46 | </synopsis>
|
47 | 47 | <syntax>
|
48 | 48 | <parameter name="direction" required="true">
|
@@ -221,9 +221,55 @@ static int volume_write(struct ast_channel *chan, const char *cmd, char *data, c
|
221 | 221 | return 0;
|
222 | 222 | }
|
223 | 223 |
|
| 224 | +static int volume_read(struct ast_channel *chan, const char *cmd, char *data, char *buffer, size_t buflen) |
| 225 | +{ |
| 226 | + struct ast_datastore *datastore = NULL; |
| 227 | + struct volume_information *vi = NULL; |
| 228 | + |
| 229 | + /* Separate options from argument */ |
| 230 | + |
| 231 | + AST_DECLARE_APP_ARGS(args, |
| 232 | + AST_APP_ARG(direction); |
| 233 | + AST_APP_ARG(options); |
| 234 | + ); |
| 235 | + |
| 236 | + if (!chan) { |
| 237 | + ast_log(LOG_WARNING, "No channel was provided to %s function.\n", cmd); |
| 238 | + return -1; |
| 239 | + } |
| 240 | + |
| 241 | + AST_STANDARD_APP_ARGS(args, data); |
| 242 | + |
| 243 | + ast_channel_lock(chan); |
| 244 | + if (!(datastore = ast_channel_datastore_find(chan, &volume_datastore, NULL))) { |
| 245 | + ast_channel_unlock(chan); |
| 246 | + return -1; /* no active audiohook, nothing to read */ |
| 247 | + } else { |
| 248 | + ast_channel_unlock(chan); |
| 249 | + vi = datastore->data; |
| 250 | + } |
| 251 | + |
| 252 | + /* Obtain current gain using volume information structure */ |
| 253 | + if (ast_strlen_zero(args.direction)) { |
| 254 | + ast_log(LOG_ERROR, "Direction must be specified for VOLUME function\n"); |
| 255 | + return -1; |
| 256 | + } |
| 257 | + |
| 258 | + if (!strcasecmp(args.direction, "tx")) { |
| 259 | + snprintf(buffer, buflen, "%f", vi->tx_gain); |
| 260 | + } else if (!strcasecmp(args.direction, "rx")) { |
| 261 | + snprintf(buffer, buflen, "%f", vi->rx_gain); |
| 262 | + } else { |
| 263 | + ast_log(LOG_ERROR, "Direction must be either RX or TX\n"); |
| 264 | + } |
| 265 | + |
| 266 | + return 0; |
| 267 | +} |
| 268 | + |
224 | 269 | static struct ast_custom_function volume_function = {
|
225 | 270 | .name = "VOLUME",
|
226 | 271 | .write = volume_write,
|
| 272 | + .read = volume_read, |
227 | 273 | };
|
228 | 274 |
|
229 | 275 | static int unload_module(void)
|
|
0 commit comments