| 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 | #include <stdio.h> |
|---|
| 41 | #include <ctype.h> |
|---|
| 42 | #include "rat_types.h" |
|---|
| 43 | #include "mbus_engine.h" |
|---|
| 44 | #include "mbus_ui.h" |
|---|
| 45 | #include "mbus.h" |
|---|
| 46 | #include "ui_control.h" |
|---|
| 47 | #include "net.h" |
|---|
| 48 | #include "util.h" |
|---|
| 49 | #include "transmit.h" |
|---|
| 50 | #include "audio.h" |
|---|
| 51 | #include "codec.h" |
|---|
| 52 | #include "channel.h" |
|---|
| 53 | #include "rtcp_pckt.h" |
|---|
| 54 | #include "rtcp_db.h" |
|---|
| 55 | #include "repair.h" |
|---|
| 56 | #include "crypt.h" |
|---|
| 57 | #include "session.h" |
|---|
| 58 | #include "rat_time.h" |
|---|
| 59 | |
|---|
| 60 | extern int should_exit; |
|---|
| 61 | |
|---|
| 62 | static struct mbus *mbus_base = NULL; |
|---|
| 63 | static struct mbus *mbus_chan = NULL; |
|---|
| 64 | |
|---|
| 65 | |
|---|
| 66 | |
|---|
| 67 | static void rx_toggle_input_port(char *srce, char *args, session_struct *sp) |
|---|
| 68 | { |
|---|
| 69 | UNUSED(srce); |
|---|
| 70 | |
|---|
| 71 | if ((strlen(args) != 1) || (args[0] != ' ')) { |
|---|
| 72 | printf("mbus: toggle_input_port does not require parameters\n"); |
|---|
| 73 | return; |
|---|
| 74 | } |
|---|
| 75 | |
|---|
| 76 | audio_next_iport(sp->audio_fd); |
|---|
| 77 | sp->input_mode = audio_get_iport(sp->audio_fd); |
|---|
| 78 | ui_update_input_port(sp); |
|---|
| 79 | } |
|---|
| 80 | |
|---|
| 81 | static void rx_toggle_output_port(char *srce, char *args, session_struct *sp) |
|---|
| 82 | { |
|---|
| 83 | UNUSED(srce); |
|---|
| 84 | |
|---|
| 85 | if ((strlen(args) != 1) || (args[0] != ' ')) { |
|---|
| 86 | printf("mbus: toggle_output_port does not require parameters\n"); |
|---|
| 87 | return; |
|---|
| 88 | } |
|---|
| 89 | |
|---|
| 90 | audio_next_oport(sp->audio_fd); |
|---|
| 91 | sp->output_mode = audio_get_oport(sp->audio_fd); |
|---|
| 92 | ui_update_output_port(sp); |
|---|
| 93 | } |
|---|
| 94 | |
|---|
| 95 | static void rx_get_audio(char *srce, char *args, session_struct *sp) |
|---|
| 96 | { |
|---|
| 97 | UNUSED(srce); |
|---|
| 98 | |
|---|
| 99 | if ((strlen(args) != 1) || (args[0] != ' ')) { |
|---|
| 100 | printf("mbus: get_audio does not require parameters\n"); |
|---|
| 101 | return; |
|---|
| 102 | } |
|---|
| 103 | |
|---|
| 104 | if (sp->have_device) { |
|---|
| 105 | |
|---|
| 106 | return; |
|---|
| 107 | } |
|---|
| 108 | |
|---|
| 109 | if (audio_device_take(sp) == FALSE) { |
|---|
| 110 | |
|---|
| 111 | } |
|---|
| 112 | } |
|---|
| 113 | |
|---|
| 114 | static void rx_powermeter(char *srce, char *args, session_struct *sp) |
|---|
| 115 | { |
|---|
| 116 | int i; |
|---|
| 117 | |
|---|
| 118 | UNUSED(srce); |
|---|
| 119 | |
|---|
| 120 | mbus_parse_init(mbus_chan, args); |
|---|
| 121 | if (mbus_parse_int(mbus_chan, &i)) { |
|---|
| 122 | sp->meter = i; |
|---|
| 123 | ui_input_level(0); |
|---|
| 124 | ui_output_level(0); |
|---|
| 125 | } else { |
|---|
| 126 | printf("mbus: usage \"powermeter <boolean>\"\n"); |
|---|
| 127 | } |
|---|
| 128 | mbus_parse_done(mbus_chan); |
|---|
| 129 | } |
|---|
| 130 | |
|---|
| 131 | static void rx_silence(char *srce, char *args, session_struct *sp) |
|---|
| 132 | { |
|---|
| 133 | int i; |
|---|
| 134 | |
|---|
| 135 | UNUSED(srce); |
|---|
| 136 | |
|---|
| 137 | mbus_parse_init(mbus_chan, args); |
|---|
| 138 | if (mbus_parse_int(mbus_chan, &i)) { |
|---|
| 139 | sp->detect_silence = i; |
|---|
| 140 | } else { |
|---|
| 141 | printf("mbus: usage \"silence <boolean>\"\n"); |
|---|
| 142 | } |
|---|
| 143 | mbus_parse_done(mbus_chan); |
|---|
| 144 | } |
|---|
| 145 | |
|---|
| 146 | static void rx_lecture(char *srce, char *args, session_struct *sp) |
|---|
| 147 | { |
|---|
| 148 | int i; |
|---|
| 149 | |
|---|
| 150 | UNUSED(srce); |
|---|
| 151 | |
|---|
| 152 | mbus_parse_init(mbus_chan, args); |
|---|
| 153 | if (mbus_parse_int(mbus_chan, &i)) { |
|---|
| 154 | sp->lecture = i; |
|---|
| 155 | } else { |
|---|
| 156 | printf("mbus: usage \"lecture <boolean>\"\n"); |
|---|
| 157 | } |
|---|
| 158 | mbus_parse_done(mbus_chan); |
|---|
| 159 | } |
|---|
| 160 | |
|---|
| 161 | static void rx_sync(char *srce, char *args, session_struct *sp) |
|---|
| 162 | { |
|---|
| 163 | int i; |
|---|
| 164 | |
|---|
| 165 | UNUSED(srce); |
|---|
| 166 | |
|---|
| 167 | mbus_parse_init(mbus_chan, args); |
|---|
| 168 | if (mbus_parse_int(mbus_chan, &i)) { |
|---|
| 169 | sp->sync_on = i; |
|---|
| 170 | } else { |
|---|
| 171 | printf("mbus: usage \"agc <boolean>\"\n"); |
|---|
| 172 | } |
|---|
| 173 | mbus_parse_done(mbus_chan); |
|---|
| 174 | } |
|---|
| 175 | |
|---|
| 176 | static void rx_agc(char *srce, char *args, session_struct *sp) |
|---|
| 177 | { |
|---|
| 178 | int i; |
|---|
| 179 | |
|---|
| 180 | UNUSED(srce); |
|---|
| 181 | |
|---|
| 182 | mbus_parse_init(mbus_chan, args); |
|---|
| 183 | if (mbus_parse_int(mbus_chan, &i)) { |
|---|
| 184 | sp->agc_on = i; |
|---|
| 185 | } else { |
|---|
| 186 | printf("mbus: usage \"agc <boolean>\"\n"); |
|---|
| 187 | } |
|---|
| 188 | mbus_parse_done(mbus_chan); |
|---|
| 189 | } |
|---|
| 190 | |
|---|
| 191 | static void rx_rate(char *srce, char *args, session_struct *sp) |
|---|
| 192 | { |
|---|
| 193 | int i; |
|---|
| 194 | |
|---|
| 195 | UNUSED(srce); |
|---|
| 196 | |
|---|
| 197 | mbus_parse_init(mbus_chan, args); |
|---|
| 198 | if (mbus_parse_int(mbus_chan, &i)) { |
|---|
| 199 | collator_set_units(sp->collator, i); |
|---|
| 200 | } else { |
|---|
| 201 | printf("mbus: usage \"rate <integer>\"\n"); |
|---|
| 202 | } |
|---|
| 203 | mbus_parse_done(mbus_chan); |
|---|
| 204 | } |
|---|
| 205 | |
|---|
| 206 | static void rx_input_mute(char *srce, char *args, session_struct *sp) |
|---|
| 207 | { |
|---|
| 208 | int i; |
|---|
| 209 | |
|---|
| 210 | UNUSED(srce); |
|---|
| 211 | |
|---|
| 212 | mbus_parse_init(mbus_chan, args); |
|---|
| 213 | if (mbus_parse_int(mbus_chan, &i)) { |
|---|
| 214 | if (i) { |
|---|
| 215 | tx_stop(sp); |
|---|
| 216 | } else { |
|---|
| 217 | tx_start(sp); |
|---|
| 218 | } |
|---|
| 219 | ui_update_input_port(sp); |
|---|
| 220 | } else { |
|---|
| 221 | printf("mbus: usage \"input_mute <boolean>\"\n"); |
|---|
| 222 | } |
|---|
| 223 | mbus_parse_done(mbus_chan); |
|---|
| 224 | } |
|---|
| 225 | |
|---|
| 226 | static void rx_input_gain(char *srce, char *args, session_struct *sp) |
|---|
| 227 | { |
|---|
| 228 | int i; |
|---|
| 229 | |
|---|
| 230 | UNUSED(srce); |
|---|
| 231 | |
|---|
| 232 | mbus_parse_init(mbus_chan, args); |
|---|
| 233 | if (mbus_parse_int(mbus_chan, &i)) { |
|---|
| 234 | sp->input_gain = i; |
|---|
| 235 | if (sp->have_device) { |
|---|
| 236 | audio_set_gain(sp->audio_fd, sp->input_gain); |
|---|
| 237 | tx_igain_update(sp); |
|---|
| 238 | } |
|---|
| 239 | } else { |
|---|
| 240 | printf("mbus: usage \"input_gain <integer>\"\n"); |
|---|
| 241 | } |
|---|
| 242 | mbus_parse_done(mbus_chan); |
|---|
| 243 | } |
|---|
| 244 | |
|---|
| 245 | static void rx_input_port(char *srce, char *args, session_struct *sp) |
|---|
| 246 | { |
|---|
| 247 | char *s; |
|---|
| 248 | |
|---|
| 249 | UNUSED(srce); |
|---|
| 250 | |
|---|
| 251 | mbus_parse_init(mbus_chan, args); |
|---|
| 252 | if (mbus_parse_str(mbus_chan, &s)) { |
|---|
| 253 | s = mbus_decode_str(s); |
|---|
| 254 | if (strcmp(s, "microphone") == 0) { |
|---|
| 255 | audio_set_iport(sp->audio_fd, AUDIO_MICROPHONE); |
|---|
| 256 | } |
|---|
| 257 | if (strcmp(s, "cd") == 0) { |
|---|
| 258 | audio_set_iport(sp->audio_fd, AUDIO_CD); |
|---|
| 259 | } |
|---|
| 260 | if (strcmp(s, "line_in") == 0) { |
|---|
| 261 | audio_set_iport(sp->audio_fd, AUDIO_LINE_IN); |
|---|
| 262 | } |
|---|
| 263 | } else { |
|---|
| 264 | printf("mbus: usage \"input_port <port>\"\n"); |
|---|
| 265 | } |
|---|
| 266 | mbus_parse_done(mbus_chan); |
|---|
| 267 | sp->input_mode = audio_get_iport(sp->audio_fd); |
|---|
| 268 | ui_update_input_port(sp); |
|---|
| 269 | } |
|---|
| 270 | |
|---|
| 271 | static void rx_output_mute(char *srce, char *args, session_struct *sp) |
|---|
| 272 | { |
|---|
| 273 | int i; |
|---|
| 274 | |
|---|
| 275 | UNUSED(srce); |
|---|
| 276 | |
|---|
| 277 | mbus_parse_init(mbus_chan, args); |
|---|
| 278 | if (mbus_parse_int(mbus_chan, &i)) { |
|---|
| 279 | sp->playing_audio = !i; |
|---|
| 280 | ui_update_output_port(sp); |
|---|
| 281 | } else { |
|---|
| 282 | printf("mbus: usage \"output_mute <boolean>\"\n"); |
|---|
| 283 | } |
|---|
| 284 | mbus_parse_done(mbus_chan); |
|---|
| 285 | } |
|---|
| 286 | |
|---|
| 287 | static void rx_output_gain(char *srce, char *args, session_struct *sp) |
|---|
| 288 | { |
|---|
| 289 | int i; |
|---|
| 290 | |
|---|
| 291 | UNUSED(srce); |
|---|
| 292 | |
|---|
| 293 | mbus_parse_init(mbus_chan, args); |
|---|
| 294 | if (mbus_parse_int(mbus_chan, &i)) { |
|---|
| 295 | sp->output_gain = i; |
|---|
| 296 | audio_set_volume(sp->audio_fd, sp->output_gain); |
|---|
| 297 | } else { |
|---|
| 298 | printf("mbus: usage \"output_gain <integer>\"\n"); |
|---|
| 299 | } |
|---|
| 300 | mbus_parse_done(mbus_chan); |
|---|
| 301 | } |
|---|
| 302 | |
|---|
| 303 | static void rx_output_port(char *srce, char *args, session_struct *sp) |
|---|
| 304 | { |
|---|
| 305 | char *s; |
|---|
| 306 | |
|---|
| 307 | UNUSED(srce); |
|---|
| 308 | |
|---|
| 309 | mbus_parse_init(mbus_chan, args); |
|---|
| 310 | if (mbus_parse_str(mbus_chan, &s)) { |
|---|
| 311 | s = mbus_decode_str(s); |
|---|
| 312 | if (strcmp(s, "speaker") == 0) { |
|---|
| 313 | audio_set_oport(sp->audio_fd, AUDIO_SPEAKER); |
|---|
| 314 | } |
|---|
| 315 | if (strcmp(s, "headphone") == 0) { |
|---|
| 316 | audio_set_oport(sp->audio_fd, AUDIO_HEADPHONE); |
|---|
| 317 | } |
|---|
| 318 | if (strcmp(s, "line_out") == 0) { |
|---|
| 319 | audio_set_oport(sp->audio_fd, AUDIO_LINE_OUT); |
|---|
| 320 | } |
|---|
| 321 | } else { |
|---|
| 322 | printf("mbus: usage \"output_port <port>\"\n"); |
|---|
| 323 | } |
|---|
| 324 | mbus_parse_done(mbus_chan); |
|---|
| 325 | sp->output_mode = audio_get_oport(sp->audio_fd); |
|---|
| 326 | ui_update_output_port(sp); |
|---|
| 327 | } |
|---|
| 328 | |
|---|
| 329 | static void rx_repair(char *srce, char *args, session_struct *sp) |
|---|
| 330 | { |
|---|
| 331 | char *s; |
|---|
| 332 | |
|---|
| 333 | UNUSED(srce); |
|---|
| 334 | |
|---|
| 335 | mbus_parse_init(mbus_chan, args); |
|---|
| 336 | if (mbus_parse_str(mbus_chan, &s)) { |
|---|
| 337 | s = mbus_decode_str(s); |
|---|
| 338 | if (strcmp(s, "None") == 0) sp->repair = REPAIR_NONE; |
|---|
| 339 | if (strcmp(s, "Packet Repetition") == 0) sp->repair = REPAIR_REPEAT; |
|---|
| 340 | if (strcmp(s, "Pattern Matching") == 0) sp->repair = REPAIR_PATTERN_MATCH; |
|---|
| 341 | } else { |
|---|
| 342 | printf("mbus: usage \"repair None|Repetition\"\n"); |
|---|
| 343 | } |
|---|
| 344 | mbus_parse_done(mbus_chan); |
|---|
| 345 | } |
|---|
| 346 | |
|---|
| 347 | static void rx_update_key(char *srce, char *args, session_struct *sp) |
|---|
| 348 | { |
|---|
| 349 | char *key; |
|---|
| 350 | |
|---|
| 351 | UNUSED(sp); |
|---|
| 352 | UNUSED(srce); |
|---|
| 353 | |
|---|
| 354 | mbus_parse_init(mbus_chan, args); |
|---|
| 355 | if (mbus_parse_str(mbus_chan, &key)) { |
|---|
| 356 | Set_Key(mbus_decode_str(key)); |
|---|
| 357 | } else { |
|---|
| 358 | printf("mbus: usage \"update_key <key>\"\n"); |
|---|
| 359 | } |
|---|
| 360 | mbus_parse_done(mbus_chan); |
|---|
| 361 | } |
|---|
| 362 | |
|---|
| 363 | static void rx_play_stop(char *srce, char *args, session_struct *sp) |
|---|
| 364 | { |
|---|
| 365 | UNUSED(srce); |
|---|
| 366 | |
|---|
| 367 | if ((strlen(args) != 1) || (args[0] != ' ')) { |
|---|
| 368 | printf("mbus: play-stop does not require parameters\n"); |
|---|
| 369 | return; |
|---|
| 370 | } |
|---|
| 371 | if (sp->in_file != NULL) { |
|---|
| 372 | fclose(sp->in_file); |
|---|
| 373 | } |
|---|
| 374 | sp->in_file = NULL; |
|---|
| 375 | } |
|---|
| 376 | |
|---|
| 377 | static void rx_play_file(char *srce, char *args, session_struct *sp) |
|---|
| 378 | { |
|---|
| 379 | char *file; |
|---|
| 380 | |
|---|
| 381 | UNUSED(srce); |
|---|
| 382 | |
|---|
| 383 | mbus_parse_init(mbus_chan, args); |
|---|
| 384 | if (mbus_parse_str(mbus_chan, &file)) { |
|---|
| 385 | file = mbus_decode_str(file); |
|---|
| 386 | sp->in_file = fopen(file, "r"); |
|---|
| 387 | } else { |
|---|
| 388 | printf("mbus: usage \"play_file <filename>\"\n"); |
|---|
| 389 | } |
|---|
| 390 | mbus_parse_done(mbus_chan); |
|---|
| 391 | } |
|---|
| 392 | |
|---|
| 393 | static void rx_rec_stop(char *srce, char *args, session_struct *sp) |
|---|
| 394 | { |
|---|
| 395 | UNUSED(srce); |
|---|
| 396 | |
|---|
| 397 | if ((strlen(args) != 1) || (args[0] != ' ')) { |
|---|
| 398 | printf("mbus: rec-stop does not require parameters\n"); |
|---|
| 399 | return; |
|---|
| 400 | } |
|---|
| 401 | if (sp->out_file != NULL) { |
|---|
| 402 | fclose(sp->out_file); |
|---|
| 403 | } |
|---|
| 404 | sp->out_file = NULL; |
|---|
| 405 | } |
|---|
| 406 | |
|---|
| 407 | static void rx_rec_file(char *srce, char *args, session_struct *sp) |
|---|
| 408 | { |
|---|
| 409 | char *file; |
|---|
| 410 | |
|---|
| 411 | UNUSED(srce); |
|---|
| 412 | |
|---|
| 413 | mbus_parse_init(mbus_chan, args); |
|---|
| 414 | if (mbus_parse_str(mbus_chan, &file)) { |
|---|
| 415 | file = mbus_decode_str(file); |
|---|
| 416 | sp->out_file = fopen(file, "w"); |
|---|
| 417 | } else { |
|---|
| 418 | printf("mbus: usage \"rec_file <filename>\"\n"); |
|---|
| 419 | } |
|---|
| 420 | mbus_parse_done(mbus_chan); |
|---|
| 421 | } |
|---|
| 422 | |
|---|
| 423 | static void rx_source_name(char *srce, char *args, session_struct *sp) |
|---|
| 424 | { |
|---|
| 425 | char *arg, *cname; |
|---|
| 426 | |
|---|
| 427 | UNUSED(srce); |
|---|
| 428 | |
|---|
| 429 | mbus_parse_init(mbus_chan, args); |
|---|
| 430 | if (mbus_parse_str(mbus_chan, &cname) && (strcmp(mbus_decode_str(cname), sp->db->my_dbe->sentry->cname) == 0) && mbus_parse_str(mbus_chan, &arg)) { |
|---|
| 431 | rtcp_set_attribute(sp, RTCP_SDES_NAME, mbus_decode_str(arg)); |
|---|
| 432 | } else { |
|---|
| 433 | printf("mbus: usage \"source_name <cname> <name>\"\n"); |
|---|
| 434 | } |
|---|
| 435 | mbus_parse_done(mbus_chan); |
|---|
| 436 | } |
|---|
| 437 | |
|---|
| 438 | static void rx_source_email(char *srce, char *args, session_struct *sp) |
|---|
| 439 | { |
|---|
| 440 | char *arg, *cname; |
|---|
| 441 | |
|---|
| 442 | UNUSED(srce); |
|---|
| 443 | |
|---|
| 444 | mbus_parse_init(mbus_chan, args); |
|---|
| 445 | if (mbus_parse_str(mbus_chan, &cname) && (strcmp(mbus_decode_str(cname), sp->db->my_dbe->sentry->cname) == 0) && mbus_parse_str(mbus_chan, &arg)) { |
|---|
| 446 | rtcp_set_attribute(sp, RTCP_SDES_EMAIL, mbus_decode_str(arg)); |
|---|
| 447 | } else { |
|---|
| 448 | printf("mbus: usage \"source_email <cname> <email>\"\n"); |
|---|
| 449 | } |
|---|
| 450 | mbus_parse_done(mbus_chan); |
|---|
| 451 | } |
|---|
| 452 | |
|---|
| 453 | static void rx_source_phone(char *srce, char *args, session_struct *sp) |
|---|
| 454 | { |
|---|
| 455 | char *arg, *cname; |
|---|
| 456 | |
|---|
| 457 | UNUSED(srce); |
|---|
| 458 | |
|---|
| 459 | mbus_parse_init(mbus_chan, args); |
|---|
| 460 | if (mbus_parse_str(mbus_chan, &cname) && (strcmp(mbus_decode_str(cname), sp->db->my_dbe->sentry->cname) == 0) && mbus_parse_str(mbus_chan, &arg)) { |
|---|
| 461 | rtcp_set_attribute(sp, RTCP_SDES_PHONE, mbus_decode_str(arg)); |
|---|
| 462 | } else { |
|---|
| 463 | printf("mbus: usage \"source_phone <cname> <phone>\"\n"); |
|---|
| 464 | } |
|---|
| 465 | mbus_parse_done(mbus_chan); |
|---|
| 466 | } |
|---|
| 467 | |
|---|
| 468 | static void rx_source_loc(char *srce, char *args, session_struct *sp) |
|---|
| 469 | { |
|---|
| 470 | char *arg, *cname; |
|---|
| 471 | |
|---|
| 472 | UNUSED(srce); |
|---|
| 473 | |
|---|
| 474 | mbus_parse_init(mbus_chan, args); |
|---|
| 475 | if (mbus_parse_str(mbus_chan, &cname) && (strcmp(mbus_decode_str(cname), sp->db->my_dbe->sentry->cname) == 0) && mbus_parse_str(mbus_chan, &arg)) { |
|---|
| 476 | rtcp_set_attribute(sp, RTCP_SDES_LOC, mbus_decode_str(arg)); |
|---|
| 477 | } else { |
|---|
| 478 | printf("mbus: usage \"source_loc <cname> <loc>\"\n"); |
|---|
| 479 | } |
|---|
| 480 | mbus_parse_done(mbus_chan); |
|---|
| 481 | } |
|---|
| 482 | |
|---|
| 483 | static void rx_source_mute(char *srce, char *args, session_struct *sp) |
|---|
| 484 | { |
|---|
| 485 | rtcp_dbentry *e; |
|---|
| 486 | char *cname; |
|---|
| 487 | int i; |
|---|
| 488 | |
|---|
| 489 | UNUSED(srce); |
|---|
| 490 | |
|---|
| 491 | mbus_parse_init(mbus_chan, args); |
|---|
| 492 | if (mbus_parse_str(mbus_chan, &cname) && mbus_parse_int(mbus_chan, &i)) { |
|---|
| 493 | for (e = sp->db->ssrc_db; e != NULL; e = e->next) { |
|---|
| 494 | if (strcmp(e->sentry->cname, mbus_decode_str(cname)) == 0) { |
|---|
| 495 | e->mute = i; |
|---|
| 496 | } |
|---|
| 497 | } |
|---|
| 498 | } else { |
|---|
| 499 | printf("mbus: usage \"source_mute <cname> <bool>\"\n"); |
|---|
| 500 | } |
|---|
| 501 | mbus_parse_done(mbus_chan); |
|---|
| 502 | } |
|---|
| 503 | |
|---|
| 504 | |
|---|
| 505 | static void rx_source_playout(char *srce, char *args, session_struct *sp) |
|---|
| 506 | { |
|---|
| 507 | rtcp_dbentry *e; |
|---|
| 508 | char *cname; |
|---|
| 509 | int playout; |
|---|
| 510 | |
|---|
| 511 | UNUSED(srce); |
|---|
| 512 | |
|---|
| 513 | mbus_parse_init(mbus_chan, args); |
|---|
| 514 | if (mbus_parse_str(mbus_chan, &cname) && mbus_parse_int(mbus_chan, &playout)) { |
|---|
| 515 | for (e = sp->db->ssrc_db; e != NULL; e = e->next) { |
|---|
| 516 | if (strcmp(e->sentry->cname, mbus_decode_str(cname)) == 0) break; |
|---|
| 517 | } |
|---|
| 518 | e->video_playout_received = TRUE; |
|---|
| 519 | e->video_playout = playout; |
|---|
| 520 | } else { |
|---|
| 521 | printf("mbus: usage \"source_playout <cname> <playout>\"\n"); |
|---|
| 522 | } |
|---|
| 523 | mbus_parse_done(mbus_chan); |
|---|
| 524 | } |
|---|
| 525 | |
|---|
| 526 | static void |
|---|
| 527 | rx_interleaving(char *srce, char *args, session_struct *sp) |
|---|
| 528 | { |
|---|
| 529 | int units, separation, cc_pt; |
|---|
| 530 | char config[80]; |
|---|
| 531 | |
|---|
| 532 | UNUSED(srce); |
|---|
| 533 | |
|---|
| 534 | mbus_parse_init(mbus_chan, args); |
|---|
| 535 | if (mbus_parse_int(mbus_chan, &units) && |
|---|
| 536 | mbus_parse_int(mbus_chan, &separation)) { |
|---|
| 537 | cc_pt = get_cc_pt(sp,"INTERLEAVER"); |
|---|
| 538 | sprintf(config, "%d/%d", units, separation); |
|---|
| 539 | debug_msg("config %s\n", config); |
|---|
| 540 | config_channel_coder(sp, cc_pt, config); |
|---|
| 541 | } else { |
|---|
| 542 | printf("mbus: usage \"interleaving <codec> <separation in units>\"\n"); |
|---|
| 543 | } |
|---|
| 544 | mbus_parse_done(mbus_chan); |
|---|
| 545 | ui_update_interleaving(sp); |
|---|
| 546 | } |
|---|
| 547 | |
|---|
| 548 | static codec_t* |
|---|
| 549 | validate_redundant_codec(codec_t *primary, codec_t *redundant) |
|---|
| 550 | { |
|---|
| 551 | assert(primary != NULL); |
|---|
| 552 | |
|---|
| 553 | if ((redundant == NULL) || |
|---|
| 554 | (!codec_compatible(primary, redundant)) || |
|---|
| 555 | (redundant->unit_len > primary->unit_len)) { |
|---|
| 556 | return primary; |
|---|
| 557 | } |
|---|
| 558 | return redundant; |
|---|
| 559 | } |
|---|
| 560 | |
|---|
| 561 | static void |
|---|
| 562 | rx_redundancy(char *srce, char *args, session_struct *sp) |
|---|
| 563 | { |
|---|
| 564 | char *codec; |
|---|
| 565 | int offset, cc_pt; |
|---|
| 566 | char config[80]; |
|---|
| 567 | codec_t *rcp, *pcp; |
|---|
| 568 | |
|---|
| 569 | UNUSED(srce); |
|---|
| 570 | |
|---|
| 571 | mbus_parse_init(mbus_chan, args); |
|---|
| 572 | if (mbus_parse_str(mbus_chan, &codec) && |
|---|
| 573 | mbus_parse_int(mbus_chan, &offset)) { |
|---|
| 574 | if (offset<=0) offset = 0;; |
|---|
| 575 | pcp = get_codec(sp->encodings[0]); |
|---|
| 576 | debug_msg(codec); |
|---|
| 577 | rcp = get_codec(codec_matching(mbus_decode_str(codec), pcp->freq, pcp->channels)); |
|---|
| 578 | assert(rcp != NULL); |
|---|
| 579 | |
|---|
| 580 | rcp = validate_redundant_codec(pcp,rcp); |
|---|
| 581 | sprintf(config,"%s/0/%s/%d", pcp->name, rcp->name, offset); |
|---|
| 582 | debug_msg("config %s\n", config); |
|---|
| 583 | cc_pt = get_cc_pt(sp,"REDUNDANCY"); |
|---|
| 584 | config_channel_coder(sp, cc_pt, config); |
|---|
| 585 | } else { |
|---|
| 586 | printf("mbus: usage \"redundancy <codec> <offset in units>\"\n"); |
|---|
| 587 | } |
|---|
| 588 | mbus_parse_done(mbus_chan); |
|---|
| 589 | ui_update_redundancy(sp); |
|---|
| 590 | } |
|---|
| 591 | |
|---|
| 592 | static void |
|---|
| 593 | rx_primary(char *srce, char *args, session_struct *sp) |
|---|
| 594 | { |
|---|
| 595 | static int virgin = 1; |
|---|
| 596 | char *short_name, *sfreq, *schan; |
|---|
| 597 | int pt, freq, channels; |
|---|
| 598 | codec_t *next_cp, *cp; |
|---|
| 599 | |
|---|
| 600 | UNUSED(srce); |
|---|
| 601 | |
|---|
| 602 | pt = -1; |
|---|
| 603 | next_cp = NULL; |
|---|
| 604 | |
|---|
| 605 | mbus_parse_init(mbus_chan, args); |
|---|
| 606 | if (mbus_parse_str(mbus_chan, &short_name) && |
|---|
| 607 | mbus_parse_str(mbus_chan, &schan) && |
|---|
| 608 | mbus_parse_str(mbus_chan, &sfreq)) { |
|---|
| 609 | mbus_decode_str(short_name); |
|---|
| 610 | mbus_decode_str(schan); |
|---|
| 611 | mbus_decode_str(sfreq); |
|---|
| 612 | mbus_parse_done(mbus_chan); |
|---|
| 613 | } else { |
|---|
| 614 | printf("mbus: usage \"primary <codec> <freq> <channels>\"\n"); |
|---|
| 615 | mbus_parse_done(mbus_chan); |
|---|
| 616 | return; |
|---|
| 617 | } |
|---|
| 618 | |
|---|
| 619 | if (strcasecmp(schan, "mono") == 0) { |
|---|
| 620 | channels = 1; |
|---|
| 621 | } else if (strcasecmp(schan, "stereo") == 0) { |
|---|
| 622 | channels = 2; |
|---|
| 623 | } else { |
|---|
| 624 | channels = 0; |
|---|
| 625 | } |
|---|
| 626 | |
|---|
| 627 | freq = atoi(sfreq) * 1000; |
|---|
| 628 | |
|---|
| 629 | if (-1 != (pt = codec_matching(short_name, freq, channels))) { |
|---|
| 630 | next_cp = get_codec(pt); |
|---|
| 631 | cp = get_codec(sp->encodings[0]); |
|---|
| 632 | assert(next_cp != NULL); |
|---|
| 633 | assert(cp != NULL); |
|---|
| 634 | if (codec_compatible(next_cp, cp)) { |
|---|
| 635 | sp->encodings[0] = pt; |
|---|
| 636 | ui_update_primary(sp); |
|---|
| 637 | ui_update_redundancy(sp); |
|---|
| 638 | } else { |
|---|
| 639 | |
|---|
| 640 | sp->next_encoding = pt; |
|---|
| 641 | if (virgin) { |
|---|
| 642 | audio_device_reconfigure(sp); |
|---|
| 643 | virgin = 0; |
|---|
| 644 | } |
|---|
| 645 | } |
|---|
| 646 | } |
|---|
| 647 | } |
|---|
| 648 | |
|---|
| 649 | static void |
|---|
| 650 | rx_sampling(char *srce, char *args, session_struct *sp) |
|---|
| 651 | { |
|---|
| 652 | int channels, freq, pt; |
|---|
| 653 | char *sfreq, *schan; |
|---|
| 654 | |
|---|
| 655 | UNUSED(srce); |
|---|
| 656 | UNUSED(sp); |
|---|
| 657 | |
|---|
| 658 | freq = channels = 0; |
|---|
| 659 | mbus_parse_init(mbus_chan, args); |
|---|
| 660 | if (mbus_parse_str(mbus_chan, &sfreq) && |
|---|
| 661 | mbus_parse_str(mbus_chan, &schan)) { |
|---|
| 662 | mbus_decode_str(sfreq); |
|---|
| 663 | mbus_decode_str(schan); |
|---|
| 664 | if (strcasecmp(schan, "mono") == 0) { |
|---|
| 665 | channels = 1; |
|---|
| 666 | } else if (strcasecmp(schan, "stereo") == 0) { |
|---|
| 667 | channels = 2; |
|---|
| 668 | } |
|---|
| 669 | freq = atoi(sfreq) * 1000; |
|---|
| 670 | } |
|---|
| 671 | |
|---|
| 672 | pt = codec_first_with(freq, channels); |
|---|
| 673 | if (pt != -1) { |
|---|
| 674 | ui_codecs(pt); |
|---|
| 675 | } else { |
|---|
| 676 | printf("mbus: usage \"sampling <freq> <channels>\"\n"); |
|---|
| 677 | } |
|---|
| 678 | |
|---|
| 679 | mbus_parse_done(mbus_chan); |
|---|
| 680 | } |
|---|
| 681 | |
|---|
| 682 | static void rx_playout_limit(char *srce, char *args, session_struct *sp) |
|---|
| 683 | { |
|---|
| 684 | int i; |
|---|
| 685 | |
|---|
| 686 | UNUSED(srce); |
|---|
| 687 | mbus_parse_init(mbus_chan, args); |
|---|
| 688 | if (mbus_parse_int(mbus_chan, &i) && (1 == i || 0 == i)) { |
|---|
| 689 | sp->limit_playout = i; |
|---|
| 690 | } else { |
|---|
| 691 | printf("mbus: usage \"playout.limit <bool>\"\n"); |
|---|
| 692 | } |
|---|
| 693 | mbus_parse_done(mbus_chan); |
|---|
| 694 | } |
|---|
| 695 | |
|---|
| 696 | static void rx_playout_min(char *srce, char *args, session_struct *sp) |
|---|
| 697 | { |
|---|
| 698 | int i; |
|---|
| 699 | |
|---|
| 700 | UNUSED(srce); |
|---|
| 701 | |
|---|
| 702 | mbus_parse_init(mbus_chan, args); |
|---|
| 703 | if (mbus_parse_int(mbus_chan, &i)) { |
|---|
| 704 | sp->min_playout = i; |
|---|
| 705 | } else { |
|---|
| 706 | printf("mbus: usage \"playout.min <integer>\"\n"); |
|---|
| 707 | } |
|---|
| 708 | mbus_parse_done(mbus_chan); |
|---|
| 709 | } |
|---|
| 710 | |
|---|
| 711 | static void rx_playout_max(char *srce, char *args, session_struct *sp) |
|---|
| 712 | { |
|---|
| 713 | int i; |
|---|
| 714 | |
|---|
| 715 | UNUSED(srce); |
|---|
| 716 | |
|---|
| 717 | mbus_parse_init(mbus_chan, args); |
|---|
| 718 | if (mbus_parse_int(mbus_chan, &i)) { |
|---|
| 719 | sp->max_playout = i; |
|---|
| 720 | } else { |
|---|
| 721 | printf("mbus: usage \"playout.max <integer>\"\n"); |
|---|
| 722 | } |
|---|
| 723 | mbus_parse_done(mbus_chan); |
|---|
| 724 | } |
|---|
| 725 | |
|---|
| 726 | static void rx_auto_convert(char *srce, char *args, session_struct *sp) |
|---|
| 727 | { |
|---|
| 728 | int i; |
|---|
| 729 | |
|---|
| 730 | UNUSED(srce); |
|---|
| 731 | |
|---|
| 732 | mbus_parse_init(mbus_chan, args); |
|---|
| 733 | if (mbus_parse_int(mbus_chan, &i)) { |
|---|
| 734 | assert(i==0||i==1); |
|---|
| 735 | sp->auto_convert = i; |
|---|
| 736 | } else { |
|---|
| 737 | printf("mbus: usage \"auto_convert <boolean>\"\n"); |
|---|
| 738 | } |
|---|
| 739 | mbus_parse_done(mbus_chan); |
|---|
| 740 | } |
|---|
| 741 | |
|---|
| 742 | static void rx_channel_code(char *srce, char *args, session_struct *sp) |
|---|
| 743 | { |
|---|
| 744 | char *channel; |
|---|
| 745 | |
|---|
| 746 | UNUSED(srce); |
|---|
| 747 | |
|---|
| 748 | mbus_parse_init(mbus_chan, args); |
|---|
| 749 | if (mbus_parse_str(mbus_chan, &channel)) { |
|---|
| 750 | channel = mbus_decode_str(channel); |
|---|
| 751 | switch(channel[0]) { |
|---|
| 752 | case 'N': |
|---|
| 753 | channel_set_coder(sp, get_cc_pt(sp, "VANILLA")); |
|---|
| 754 | break; |
|---|
| 755 | case 'R': |
|---|
| 756 | channel_set_coder(sp, get_cc_pt(sp, "REDUNDANCY")); |
|---|
| 757 | break; |
|---|
| 758 | case 'I': |
|---|
| 759 | channel_set_coder(sp, get_cc_pt(sp, "INTERLEAVER")); |
|---|
| 760 | break; |
|---|
| 761 | default: |
|---|
| 762 | printf("%s %d: scheme %s not recognized.\n",__FILE__,__LINE__,channel); |
|---|
| 763 | } |
|---|
| 764 | } else { |
|---|
| 765 | printf("mbus: usage \"channel_code <scheme>\"\n"); |
|---|
| 766 | } |
|---|
| 767 | mbus_parse_done(mbus_chan); |
|---|
| 768 | } |
|---|
| 769 | |
|---|
| 770 | static void rx_settings(char *srce, char *args, session_struct *sp) |
|---|
| 771 | { |
|---|
| 772 | UNUSED(args); |
|---|
| 773 | UNUSED(srce); |
|---|
| 774 | ui_update(sp); |
|---|
| 775 | } |
|---|
| 776 | |
|---|
| 777 | static void rx_quit(char *srce, char *args, session_struct *sp) |
|---|
| 778 | { |
|---|
| 779 | UNUSED(args); |
|---|
| 780 | UNUSED(srce); |
|---|
| 781 | UNUSED(sp); |
|---|
| 782 | ui_quit(); |
|---|
| 783 | should_exit = TRUE; |
|---|
| 784 | } |
|---|
| 785 | |
|---|
| 786 | static void rx_init(char *srce, char *args, session_struct *sp) |
|---|
| 787 | { |
|---|
| 788 | UNUSED(args); |
|---|
| 789 | UNUSED(srce); |
|---|
| 790 | sp->wait_on_startup = FALSE; |
|---|
| 791 | } |
|---|
| 792 | |
|---|
| 793 | static void rx_alive(char *srce, char *args, session_struct *sp) |
|---|
| 794 | { |
|---|
| 795 | |
|---|
| 796 | UNUSED(args); |
|---|
| 797 | UNUSED(srce); |
|---|
| 798 | } |
|---|
| 799 | |
|---|
| 800 | const char *rx_cmnd[] = { |
|---|
| 801 | "get_audio", |
|---|
| 802 | "toggle.input.port", |
|---|
| 803 | "toggle.output.port", |
|---|
| 804 | "powermeter", |
|---|
| 805 | "silence", |
|---|
| 806 | "lecture", |
|---|
| 807 | "agc", |
|---|
| 808 | "sync", |
|---|
| 809 | "rate", |
|---|
| 810 | "input.mute", |
|---|
| 811 | "input.gain", |
|---|
| 812 | "input.port", |
|---|
| 813 | "output.mute", |
|---|
| 814 | "output.gain", |
|---|
| 815 | "output.port", |
|---|
| 816 | "repair", |
|---|
| 817 | "update.key", |
|---|
| 818 | "play.stop", |
|---|
| 819 | "play.file", |
|---|
| 820 | "rec.stop", |
|---|
| 821 | "rec.file", |
|---|
| 822 | "source.name", |
|---|
| 823 | "source.email", |
|---|
| 824 | "source.phone", |
|---|
| 825 | "source.loc", |
|---|
| 826 | "source.mute", |
|---|
| 827 | "source.playout", |
|---|
| 828 | "interleaving", |
|---|
| 829 | "redundancy", |
|---|
| 830 | "primary", |
|---|
| 831 | "sampling", |
|---|
| 832 | "playout.limit", |
|---|
| 833 | "playout.min", |
|---|
| 834 | "playout.max", |
|---|
| 835 | "auto.convert", |
|---|
| 836 | "channel.code", |
|---|
| 837 | "settings", |
|---|
| 838 | "quit", |
|---|
| 839 | "init", |
|---|
| 840 | "alive", |
|---|
| 841 | "" |
|---|
| 842 | }; |
|---|
| 843 | |
|---|
| 844 | static void (*rx_func[])(char *srce, char *args, session_struct *sp) = { |
|---|
| 845 | rx_get_audio, |
|---|
| 846 | rx_toggle_input_port, |
|---|
| 847 | rx_toggle_output_port, |
|---|
| 848 | rx_powermeter, |
|---|
| 849 | rx_silence, |
|---|
| 850 | rx_lecture, |
|---|
| 851 | rx_agc, |
|---|
| 852 | rx_sync, |
|---|
| 853 | rx_rate, |
|---|
| 854 | rx_input_mute, |
|---|
| 855 | rx_input_gain, |
|---|
| 856 | rx_input_port, |
|---|
| 857 | rx_output_mute, |
|---|
| 858 | rx_output_gain, |
|---|
| 859 | rx_output_port, |
|---|
| 860 | rx_repair, |
|---|
| 861 | rx_update_key, |
|---|
| 862 | rx_play_stop, |
|---|
| 863 | rx_play_file, |
|---|
| 864 | rx_rec_stop, |
|---|
| 865 | rx_rec_file, |
|---|
| 866 | rx_source_name, |
|---|
| 867 | rx_source_email, |
|---|
| 868 | rx_source_phone, |
|---|
| 869 | rx_source_loc, |
|---|
| 870 | rx_source_mute, |
|---|
| 871 | rx_source_playout, |
|---|
| 872 | rx_interleaving, |
|---|
| 873 | rx_redundancy, |
|---|
| 874 | rx_primary, |
|---|
| 875 | rx_sampling, |
|---|
| 876 | rx_playout_limit, |
|---|
| 877 | rx_playout_min, |
|---|
| 878 | rx_playout_max, |
|---|
| 879 | rx_auto_convert, |
|---|
| 880 | rx_channel_code, |
|---|
| 881 | rx_settings, |
|---|
| 882 | rx_quit, |
|---|
| 883 | rx_init, |
|---|
| 884 | rx_alive |
|---|
| 885 | }; |
|---|
| 886 | |
|---|
| 887 | void mbus_engine_rx(char *srce, char *cmnd, char *args, void *data) |
|---|
| 888 | { |
|---|
| 889 | int i; |
|---|
| 890 | |
|---|
| 891 | for (i=0; strlen(rx_cmnd[i]) != 0; i++) { |
|---|
| 892 | if (strcmp(rx_cmnd[i], cmnd) == 0) { |
|---|
| 893 | rx_func[i](srce, args, (session_struct *) data); |
|---|
| 894 | return; |
|---|
| 895 | } |
|---|
| 896 | } |
|---|
| 897 | debug_msg("Unknown mbus command: %s %s\n", cmnd, args); |
|---|
| 898 | } |
|---|
| 899 | |
|---|
| 900 | void mbus_engine_tx(int channel, char *dest, char *cmnd, char *args, int reliable) |
|---|
| 901 | { |
|---|
| 902 | if (channel == 0) { |
|---|
| 903 | mbus_send(mbus_base, dest, cmnd, args, reliable); |
|---|
| 904 | } else { |
|---|
| 905 | mbus_send(mbus_chan, dest, cmnd, args, reliable); |
|---|
| 906 | } |
|---|
| 907 | } |
|---|
| 908 | |
|---|
| 909 | void mbus_engine_tx_queue(int channel, char *cmnd, char *args) |
|---|
| 910 | { |
|---|
| 911 | if (channel == 0) { |
|---|
| 912 | mbus_qmsg(mbus_base, cmnd, args); |
|---|
| 913 | } else { |
|---|
| 914 | mbus_qmsg(mbus_chan, cmnd, args); |
|---|
| 915 | } |
|---|
| 916 | } |
|---|
| 917 | |
|---|
| 918 | void mbus_engine_init(char *name_engine, int channel) |
|---|
| 919 | { |
|---|
| 920 | mbus_base = mbus_init(0, mbus_engine_rx, NULL); mbus_addr(mbus_base, name_engine); |
|---|
| 921 | if (channel == 0) { |
|---|
| 922 | mbus_chan = mbus_base; |
|---|
| 923 | } else { |
|---|
| 924 | mbus_chan = mbus_init((short)channel, mbus_engine_rx, NULL); mbus_addr(mbus_chan, name_engine); |
|---|
| 925 | } |
|---|
| 926 | } |
|---|
| 927 | |
|---|
| 928 | int mbus_engine_fd(int channel) |
|---|
| 929 | { |
|---|
| 930 | if (channel == 0) { |
|---|
| 931 | return mbus_fd(mbus_base); |
|---|
| 932 | } else { |
|---|
| 933 | return mbus_fd(mbus_chan); |
|---|
| 934 | } |
|---|
| 935 | } |
|---|
| 936 | |
|---|
| 937 | struct mbus *mbus_engine(int channel) |
|---|
| 938 | { |
|---|
| 939 | if (channel == 0) { |
|---|
| 940 | return mbus_base; |
|---|
| 941 | } else { |
|---|
| 942 | return mbus_chan; |
|---|
| 943 | } |
|---|
| 944 | } |
|---|
| 945 | |
|---|
| 946 | void mbus_engine_retransmit(void) |
|---|
| 947 | { |
|---|
| 948 | mbus_retransmit(mbus_base); |
|---|
| 949 | mbus_retransmit(mbus_chan); |
|---|
| 950 | } |
|---|
| 951 | |
|---|
| 952 | int mbus_engine_waiting(void) |
|---|
| 953 | { |
|---|
| 954 | return mbus_waiting_acks(mbus_base) | mbus_waiting_acks(mbus_chan); |
|---|
| 955 | } |
|---|