tomcast reads mpeg transport streams over http or udp (multicast or unicast) and outputs them to chosen multicast group. Basically a simple http2multicast daemon designed to work 24/7.
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.

web_pages.c 3.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. /*
  2. * mptsd internal web pages
  3. * Copyright (C) 2010-2011 Unix Solutions Ltd.
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License version 2
  7. * as published by the Free Software Foundation.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program; if not, write to the Free Software
  16. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
  17. */
  18. #include <stdlib.h>
  19. #include <string.h>
  20. #include <sys/types.h>
  21. #include <sys/stat.h>
  22. #include <fcntl.h>
  23. #include <ctype.h>
  24. #include <unistd.h>
  25. #include "libfuncs/io.h"
  26. #include "libfuncs/log.h"
  27. #include "libfuncs/list.h"
  28. #include "libfuncs/http_response.h"
  29. #include "config.h"
  30. extern struct config *config;
  31. void cmd_index(int clientsock) {
  32. send_200_ok(clientsock);
  33. send_header_textplain(clientsock);
  34. fdputs(clientsock, "\nHi from tomcast.\n");
  35. }
  36. void cmd_status(int clientsock) {
  37. send_200_ok(clientsock);
  38. send_header_textplain(clientsock);
  39. fdputs(clientsock, "\n");
  40. LNODE *l, *tmp;
  41. struct config *cfg = get_config();
  42. time_t now = time(NULL);
  43. fdputsf(clientsock, "%-10s %-20s %8s %10s %-18s %-64s %s\n",
  44. "# Status",
  45. "DestAddr",
  46. "ConnTime",
  47. "ReadBytes",
  48. "ChanName",
  49. "ChanSource",
  50. "ProxyStatus"
  51. );
  52. pthread_mutex_lock(&cfg->channels_lock);
  53. list_lock(cfg->restreamer);
  54. list_for_each(cfg->restreamer, l, tmp) {
  55. char dest[32];
  56. int conn_status = 0;
  57. RESTREAMER *r = l->data;
  58. pthread_rwlock_rdlock(&r->lock);
  59. snprintf(dest, sizeof(dest), "%s:%d", r->channel->dest_host, r->channel->dest_port);
  60. if (r->connected && r->conn_ts > 0 && r->read_bytes >= 1316)
  61. conn_status = 1;
  62. fdputsf(clientsock, "%-10s %-20s %8lu %10llu %-18s %-64s %s\n",
  63. conn_status ? "CONN_OK" : "CONN_ERROR",
  64. dest,
  65. r->conn_ts ? now - r->conn_ts : 0,
  66. r->read_bytes,
  67. r->channel->name,
  68. r->channel->source,
  69. r->status
  70. );
  71. pthread_rwlock_unlock(&r->lock);
  72. }
  73. list_unlock(cfg->restreamer);
  74. pthread_mutex_unlock(&cfg->channels_lock);
  75. }
  76. void cmd_getconfig(int clientsock) {
  77. send_200_ok(clientsock);
  78. send_header_textplain(clientsock);
  79. fdputs(clientsock, "\n");
  80. LNODE *l, *tmp;
  81. struct config *cfg = get_config();
  82. pthread_mutex_lock(&cfg->channels_lock);
  83. list_lock(cfg->restreamer);
  84. list_for_each(cfg->restreamer, l, tmp) {
  85. RESTREAMER *r = l->data;
  86. pthread_rwlock_rdlock(&r->lock);
  87. int i;
  88. for (i = 0; i < r->channel->num_src; i++) {
  89. fdputsf(clientsock, "%s\t%s:%d\t%s\n",
  90. r->channel->name,
  91. r->channel->dest_host,
  92. r->channel->dest_port,
  93. r->channel->sources[i]
  94. );
  95. }
  96. pthread_rwlock_unlock(&r->lock);
  97. }
  98. list_unlock(cfg->restreamer);
  99. pthread_mutex_unlock(&cfg->channels_lock);
  100. }
  101. void cmd_reconnect(int clientsock) {
  102. send_200_ok(clientsock);
  103. send_header_textplain(clientsock);
  104. struct config *cfg = get_config();
  105. pthread_mutex_lock(&cfg->channels_lock);
  106. fdputsf(clientsock, "\nReconnecting %d inputs.\n", cfg->chanconf->items);
  107. pthread_mutex_unlock(&cfg->channels_lock);
  108. do_reconnect(1);
  109. }
  110. void cmd_reload(int clientsock) {
  111. send_200_ok(clientsock);
  112. send_header_textplain(clientsock);
  113. fdputs(clientsock, "\nReloading config\n");
  114. do_reconf(1);
  115. }