videohubctrl can be used to control Blackmagic Design Videohub SDI router device over the network.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

display.c 5.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. /*
  2. * === Display functions ===
  3. *
  4. * Blackmagic Design Videohub control application
  5. * Copyright (C) 2014 Unix Solutions Ltd.
  6. * Written by Georgi Chorbadzhiyski
  7. *
  8. * Released under MIT license.
  9. * See LICENSE-MIT.txt for license terms.
  10. *
  11. */
  12. #include <stdio.h>
  13. #include <string.h>
  14. #include "data.h"
  15. #include "cmd.h"
  16. #include "util.h"
  17. #include "display.h"
  18. static void printf_line(int len) {
  19. int i;
  20. printf(" ");
  21. for (i = 0; i < len; i++)
  22. printf("-");
  23. printf("\n");
  24. }
  25. static char format_status(char *status) {
  26. if (!strlen(status)) return ' ';
  27. if (streq(status, "BNC")) return 'B';
  28. if (streq(status, "Optical")) return 'o';
  29. if (streq(status, "None")) return 'x';
  30. return '?';
  31. }
  32. void print_device_info(struct videohub_data *d) {
  33. int len = 59;
  34. printf("Device info\n");
  35. printf_line(len);
  36. printf(" | %-26s | %-26s |\n", "Device address", d->dev_host);
  37. printf(" | %-26s | %-26s |\n", "Device port", d->dev_port);
  38. printf(" | %-26s | %-26s |\n", "Model name", d->device.model_name);
  39. printf(" | %-26s | %-26s |\n", "Unique ID", d->device.unique_id);
  40. printf(" | %-26s | %-26s |\n", "Protocol", d->device.protocol_ver);
  41. printf(" | %-26s | %-26u |\n", "Video inputs", d->inputs.num);
  42. printf(" | %-26s | %-26u |\n", "Video outputs", d->outputs.num);
  43. if (d->device.num_serial_ports)
  44. printf(" | %-26s | %-26u |\n", "Serial ports", d->device.num_serial_ports);
  45. if (d->device.num_video_processing_units)
  46. printf(" | %-26s | %-26u |\n", "Video processing units", d->device.num_video_processing_units);
  47. if (d->mon_outputs.num)
  48. printf(" | %-26s | %-26u |\n", "Video monitoring outputs", d->mon_outputs.num);
  49. printf_line(len);
  50. printf("\n");
  51. }
  52. void print_device_video_inputs(struct videohub_data *d) {
  53. unsigned int i, r, len = 68;
  54. if (!d->inputs.num)
  55. return;
  56. printf("Video inputs\n");
  57. printf_line(len);
  58. printf(" | ## | %-24s | n | %-24s | s |\n", "Video input name", "Routed to output");
  59. printf_line(len);
  60. for(i = 0; i < d->inputs.num; i++) {
  61. unsigned int num_outputs = 0, routed_to = 0;
  62. for(r = 0; r < d->outputs.num; r++) {
  63. if (d->outputs.port[r].routed_to == i) {
  64. num_outputs++;
  65. if (num_outputs == 1)
  66. routed_to = r; // The first output
  67. }
  68. }
  69. printf(" | %2d | %-24s | %d | ", i + 1, d->inputs.port[i].name,
  70. num_outputs);
  71. if (num_outputs == 0) {
  72. printf("%-24s | %c |\n", "-", format_status(d->inputs.port[i].status));
  73. } else {
  74. printf("%-24s | %c |\n", d->outputs.port[routed_to].name, format_status(d->inputs.port[i].status));
  75. bool first_skipped = false;
  76. for(r = 0; r < d->outputs.num; r++) {
  77. if (d->outputs.port[r].routed_to == i) {
  78. if (!first_skipped) {
  79. first_skipped = true;
  80. continue;
  81. }
  82. printf(" | %2s | %-24s | %s | %-24s | %c |\n",
  83. " ", " ", " ", d->outputs.port[r].name, ' ');
  84. }
  85. }
  86. }
  87. }
  88. printf_line(len);
  89. printf("\n");
  90. }
  91. static char port_lock_symbol(enum port_lock p) {
  92. switch(p) {
  93. case PORT_UNLOCKED : return ' ';
  94. case PORT_LOCKED : return 'O';
  95. case PORT_LOCKED_OTHER: return 'L';
  96. }
  97. return '?';
  98. }
  99. void print_device_video_outputs(struct videohub_data *d) {
  100. unsigned int i, len = 68;
  101. if (!d->outputs.num)
  102. return;
  103. printf("Video outputs\n");
  104. printf_line(len);
  105. printf(" | ## | x | %-24s | %-24s | s |\n", "Video output name", "Connected video input");
  106. printf_line(len);
  107. for(i = 0; i < d->outputs.num; i++) {
  108. printf(" | %2d | %c | %-24s | %-24s | %c |\n",
  109. i + 1,
  110. port_lock_symbol(d->outputs.port[i].lock),
  111. d->outputs.port[i].name,
  112. d->inputs.port[d->outputs.port[i].routed_to].name,
  113. format_status(d->outputs.port[i].status)
  114. );
  115. }
  116. printf_line(len);
  117. printf("\n");
  118. }
  119. void print_device_monitoring_outputs(struct videohub_data *d) {
  120. unsigned int i, len = 64;
  121. if (!d->mon_outputs.num)
  122. return;
  123. printf("Monitoring outputs\n");
  124. printf_line(len);
  125. printf(" | ## | x | %-24s | %-24s |\n", "Monitoring output name", "Connected video input");
  126. printf_line(len);
  127. for(i = 0; i < d->mon_outputs.num; i++) {
  128. printf(" | %2d | %c | %-24s | %-24s |\n",
  129. i + 1,
  130. port_lock_symbol(d->mon_outputs.port[i].lock),
  131. d->mon_outputs.port[i].name,
  132. d->inputs.port[d->mon_outputs.port[i].routed_to].name
  133. );
  134. }
  135. printf_line(len);
  136. printf("\n");
  137. }
  138. static void __print_opt(struct videohub_data *d, enum vcmd vcmd) {
  139. unsigned int i, last = 0;
  140. struct videohub_commands *v = &videohub_commands[vcmd];
  141. struct port_set *s_port = !v->ports1 ? NULL : (void *)d + v->ports1;
  142. const char *p = v->opt_prefix;
  143. for(i = 0; i < s_port->num; i++) {
  144. switch (v->type) {
  145. case PARSE_LABEL:
  146. printf(" --%s-name %2d \"%s\" \\\n", p, i + 1, s_port->port[i].name);
  147. break;
  148. case PARSE_ROUTE:
  149. printf(" --%s-input %2d %2d \\\n", p, i + 1, s_port->port[i].routed_to + 1);
  150. break;
  151. case PARSE_LOCK:
  152. last = i + 1 < s_port->num;
  153. if (s_port->port[i].lock != PORT_UNLOCKED) {
  154. printf(" --%s-unlock %2d --%s-lock %2d%s\n",
  155. p, i + 1, p, i + 1, last ? " \\" : "");
  156. } else {
  157. printf(" --%s-unlock %2d%s\n", p, i + 1, last ? " \\" : "");
  158. }
  159. default: break;
  160. }
  161. }
  162. }
  163. void print_device_backup(struct videohub_data *d) {
  164. unsigned int i;
  165. printf("videohubctrl \\\n");
  166. for (i = 0; i < NUM_COMMANDS; i++) {
  167. if (videohub_commands[i].type == PARSE_LABEL)
  168. __print_opt(d, videohub_commands[i].cmd);
  169. }
  170. for (i = 0; i < NUM_COMMANDS; i++) {
  171. if (videohub_commands[i].type == PARSE_ROUTE)
  172. __print_opt(d, videohub_commands[i].cmd);
  173. }
  174. for (i = 0; i < NUM_COMMANDS; i++) {
  175. if (videohub_commands[i].type == PARSE_LOCK)
  176. __print_opt(d, videohub_commands[i].cmd);
  177. }
  178. printf("\n");
  179. }