From: Kin-Wai Koo Date: Sun, 20 Jan 2019 12:32:41 +0000 (+0800) Subject: Changes to make tvheadend work in a container while talking to HDHomerun X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1fa1c1cb997d12ea128919c4b125a8097fee847c;p=thirdparty%2Ftvheadend.git Changes to make tvheadend work in a container while talking to HDHomerun --- diff --git a/src/config.c b/src/config.c index 8aaf58ac9..9bbea9925 100644 --- a/src/config.c +++ b/src/config.c @@ -1707,6 +1707,9 @@ config_boot config.iptv_tpool_count = 2; config.date_mask = strdup(""); config.label_formatting = 0; + config.hdhomerun_ip = strdup(""); + config.local_ip = strdup(""); + config.local_port = 0; idclass_register(&config_class); @@ -1843,6 +1846,8 @@ void config_done ( void ) free(config.picon_path); free(config.cors_origin); free(config.date_mask); + free(config.hdhomerun_ip); + free(config.local_ip); file_unlock(config_lock, config_lock_fd); } @@ -2135,6 +2140,43 @@ const idclass_t config_class = { .opts = PO_RDONLY | PO_HIDDEN | PO_EXPERT, .group = 1 }, + { + .type = PT_STR, + .id = "hdhomerun_ip", + .name = N_("HDHomerun IP Address"), + .desc = N_("IP address of the HDHomerun device. This is needed if you " + "plan to run TVheadend in a container and you want to stream " + "from an HDHomerun without enabling host networking for " + "the container."), + .off = offsetof(config_t, hdhomerun_ip), + .opts = PO_HIDDEN | PO_EXPERT, + .group = 1 + }, + { + .type = PT_STR, + .id = "local_ip", + .name = N_("Local IP Address"), + .desc = N_("IP address of the HDHomerun device. This is needed if you " + "plan to run TVheadend in a container and you want to stream " + "from an HDHomerun without enabling host networking for " + "the container."), + .off = offsetof(config_t, local_ip), + .opts = PO_HIDDEN | PO_EXPERT, + .group = 1 + }, + { + .type = PT_INT, + .id = "local_port", + .name = N_("Local Socket Port Number"), + .desc = N_("Port number of the UDP listener. This listener listens " + "for traffic from the HDHomerun device. This is needed if " + "you plan to run TVheadend in a container and you want to " + "stream from an HDHomerun without enabling host networking " + "for the container."), + .off = offsetof(config_t, local_port), + .opts = PO_HIDDEN | PO_EXPERT, + .group = 1 + }, { .type = PT_STR, .id = "language_ui", diff --git a/src/config.h b/src/config.h index 19ada3c97..07e05b22a 100644 --- a/src/config.h +++ b/src/config.h @@ -70,6 +70,9 @@ typedef struct config { char *date_mask; int label_formatting; uint32_t ticket_expires; + char *hdhomerun_ip; + char *local_ip; + int local_port; } config_t; extern const idclass_t config_class; diff --git a/src/input/mpegts/tvhdhomerun/tvhdhomerun.c b/src/input/mpegts/tvhdhomerun/tvhdhomerun.c index 87aa870d7..cf1184214 100644 --- a/src/input/mpegts/tvhdhomerun/tvhdhomerun.c +++ b/src/input/mpegts/tvhdhomerun/tvhdhomerun.c @@ -30,6 +30,8 @@ #include #include +#include "config.h" + #ifdef HDHOMERUN_TAG_DEVICE_AUTH_BIN #define hdhomerun_discover_find_devices_custom \ hdhomerun_discover_find_devices_custom_v2 @@ -382,6 +384,24 @@ static void tvhdhomerun_device_create(struct hdhomerun_discover_device_t *dInfo) htsmsg_destroy(conf); } +static uint32_t +tvhdhomerun_ip( void ) +{ + static int homerun_ip_initialized = 0; + static uint32_t ip = 0; + + if (!homerun_ip_initialized) + { + if ((*config.hdhomerun_ip != 0) && inet_pton(AF_INET, config.hdhomerun_ip, &ip)) + { + tvhinfo(LS_TVHDHOMERUN, "HDHomerun IP set to %s", config.hdhomerun_ip); + ip = ntohl(ip); + } + homerun_ip_initialized = 1; + } + return ip; +} + static void * tvhdhomerun_device_discovery_thread( void *aux ) { @@ -391,7 +411,7 @@ tvhdhomerun_device_discovery_thread( void *aux ) while (tvheadend_is_running()) { numDevices = - hdhomerun_discover_find_devices_custom(0, + hdhomerun_discover_find_devices_custom(tvhdhomerun_ip(), HDHOMERUN_DEVICE_TYPE_TUNER, HDHOMERUN_DEVICE_ID_WILDCARD, result_list, diff --git a/src/input/mpegts/tvhdhomerun/tvhdhomerun_frontend.c b/src/input/mpegts/tvhdhomerun/tvhdhomerun_frontend.c index 3f7a90161..bf401ee54 100644 --- a/src/input/mpegts/tvhdhomerun/tvhdhomerun_frontend.c +++ b/src/input/mpegts/tvhdhomerun/tvhdhomerun_frontend.c @@ -26,6 +26,9 @@ #include "tcp.h" #include "tvhdhomerun_private.h" +#include +#include "config.h" + static int tvhdhomerun_frontend_get_weight ( mpegts_input_t *mi, mpegts_mux_t *mm, int flags, int weight ) { @@ -91,6 +94,10 @@ tvhdhomerun_frontend_input_thread ( void *aux ) /* local IP */ /* TODO: this is nasty */ local_ip = hdhomerun_device_get_local_machine_addr(hfe->hf_hdhomerun_tuner); + if ((*config.local_ip != 0) && inet_pton(AF_INET, config.local_ip, &local_ip)) + { + local_ip = ntohl(local_ip); + } /* first setup a local socket for the device to stream to */ sockfd = tvh_socket(AF_INET, SOCK_DGRAM, 0); @@ -126,7 +133,7 @@ tvhdhomerun_frontend_input_thread ( void *aux ) memset(&sock_addr, 0, sizeof(sock_addr)); sock_addr.sin_family = AF_INET; sock_addr.sin_addr.s_addr = htonl(INADDR_ANY); - sock_addr.sin_port = 0; + sock_addr.sin_port = config.local_port==0?0:htons(config.local_port); if(bind(sockfd, (struct sockaddr *) &sock_addr, sizeof(sock_addr)) != 0) { tvherror(LS_TVHDHOMERUN, "failed bind socket: %d", errno); close(sockfd);