From 57483e1195edf780d98db93011fc51cfc9a01ae5 Mon Sep 17 00:00:00 2001 From: Johannes Hack Date: Tue, 23 Apr 2024 12:31:47 +0200 Subject: [PATCH 01/15] Boilerplate changes - add nit rewrite parameters - add Cable Delivery System Descriptor - adjusted Automake - enabled rewrite by configure - log NIT_REWRITE during startup --- configure.ac | 18 ++++++++++++++++ src/Makefile.am | 3 +++ src/log.c | 3 +++ src/mumudvb.c | 10 +++++++++ src/rewrite.c | 42 +++++++++++++++++++++++++++++++++++- src/rewrite.h | 10 +++++++++ src/rewrite_nit.c | 54 +++++++++++++++++++++++++++++++++++++++++++++++ src/ts.h | 28 ++++++++++++++++++++++++ 8 files changed, 167 insertions(+), 1 deletion(-) create mode 100644 src/rewrite_nit.c diff --git a/configure.ac b/configure.ac index e33d6d3c..f42241a8 100644 --- a/configure.ac +++ b/configure.ac @@ -153,6 +153,18 @@ then AC_DEFINE(TUNE_OLD, 1, Define if you want the old code for tuning) fi +AC_ARG_ENABLE([rewrite_nit_support], + [AS_HELP_STRING([--enable-rewrite_nit_support], + [Build with rewrite NIT support (default disabled)])], + [], + [enable_rewrite_nit_support="no"]) + +if test "${enable_rewrite_nit_support}" = "yes" +then + AC_DEFINE(REWRITE_NIT_SUPPORT, 1, Define if you want to rewrite the NIT Table) +fi +AM_CONDITIONAL([BUILD_REWRITE_NIT], [test "${enable_rewrite_nit_support}" = "yes"]) + # Checks for header files. AC_HEADER_RESOLV AC_CHECK_HEADERS([arpa/inet.h fcntl.h netdb.h netinet/in.h stdint.h stdlib.h string.h sys/ioctl.h sys/socket.h sys/time.h syslog.h unistd.h values.h]) @@ -220,6 +232,12 @@ if test "${enable_tune_old}" = "yes" ; then echo "Build with old tuning code: yes" fi +if test "${enable_rewrite_nit_support}" = "yes" ; then + echo "Build with rewrite nit support: yes" +else + echo "Build with rewrite nit support: no" +fi + echo "" echo "Debugging" echo "" diff --git a/src/Makefile.am b/src/Makefile.am index d90df742..ea84a229 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -38,3 +38,6 @@ SOURCES_scamsupport = \ scam_send.h \ $(NULL) +if BUILD_REWRITE_NIT +mumudvb_SOURCES += rewrite_nit.c +endif diff --git a/src/log.c b/src/log.c index 7faa1fe3..39f4b204 100644 --- a/src/log.c +++ b/src/log.c @@ -989,6 +989,9 @@ void print_info () #ifdef DVBT2 "Built with support for DVB-T2.\n" #endif +#ifdef REWRITE_NIT_SUPPORT + "Built with rewrite nit support.\n" +#endif #endif "---------\n" "Originally based on dvbstream 0.6 by (C) Dave Chapman 2001-2004\n" diff --git a/src/mumudvb.c b/src/mumudvb.c index 6f0f8c7b..6c03d81e 100644 --- a/src/mumudvb.c +++ b/src/mumudvb.c @@ -1636,6 +1636,16 @@ int main (int argc, char **argv) { eit_rewrite_new_global_packet(actual_ts_packet, &rewrite_vars); } +#ifdef REWRITE_NIT_SUPPORT + /******************************************************/ + //NIT rewrite + /******************************************************/ + if ((pid == 0x10) && //This is a NIT PID + rewrite_vars.rewrite_nit == OPTION_ON) //AND we asked for rewrite + { + + } +#endif // REWRITE_NIT_SUPPORT /******************************************************/ diff --git a/src/rewrite.c b/src/rewrite.c index 2cdbf4dd..f89fe50b 100644 --- a/src/rewrite.c +++ b/src/rewrite.c @@ -47,6 +47,12 @@ static char *log_module="Rewrite: "; void init_rewr_v(rewrite_parameters_t *rewr_p) { *rewr_p=(rewrite_parameters_t){ +#ifdef REWRITE_NIT_SUPPORT + .rewrite_nit = OPTION_UNDEFINED, + .nit_version = -1, + .nit_needs_update = true, + .full_nit = NULL, +#endif .rewrite_pmt = OPTION_UNDEFINED, .rewrite_pat = OPTION_UNDEFINED, .pat_version=-1, @@ -129,7 +135,27 @@ int rewrite_init(rewrite_parameters_t *rewr_p) pthread_mutex_init(&rewr_p->full_eit->packetmutex,NULL); } -return 0; +#ifdef REWRITE_NIT_SUPPORT + /*****************************************************/ + //NIT rewriting + //memory allocation for MPEG2-TS + //packet structures + /*****************************************************/ + + if (rewr_p->rewrite_nit == OPTION_ON) { + rewr_p->full_nit = malloc(sizeof(mumudvb_ts_packet_t)); + if (rewr_p->full_nit == NULL) { + log_message(log_module, MSG_ERROR, "Problem with malloc : %s file : %s line %d\n", + strerror(errno), __FILE__, __LINE__); + set_interrupted(ERROR_MEMORY << 8); + return 1; + } + memset(rewr_p->full_nit, 0, sizeof(mumudvb_ts_packet_t)); //we clear it + pthread_mutex_init(&rewr_p->full_nit->packetmutex, NULL); + } +#endif + + return 0; } @@ -214,6 +240,20 @@ int read_rewrite_configuration(rewrite_parameters_t *rewrite_vars, char *substri else rewrite_vars->sdt_force_eit = OPTION_OFF; } +#ifdef REWRITE_NIT_SUPPORT + else if (!strcmp (substring, "rewrite_nit")) + { + substring = strtok (NULL, delimiteurs); + if(atoi (substring)) + { + rewrite_vars->rewrite_nit = OPTION_ON; + log_message( log_module, MSG_INFO, + "You have enabled the NIT Rewriting\n"); + } + else + rewrite_vars->rewrite_nit = OPTION_OFF; + } +#endif else return 0; //Nothing concerning rewrite, we return 0 to explore the other possibilities diff --git a/src/rewrite.h b/src/rewrite.h index b657dcc7..f3ca4f9c 100644 --- a/src/rewrite.h +++ b/src/rewrite.h @@ -78,6 +78,16 @@ typedef struct eit_packet_t{ * This structure contain the parameters needed for rewriting */ typedef struct rewrite_parameters_t{ +#ifdef REWRITE_NIT_SUPPORT + /** Do we rewrite the NIT pid */ + option_status_t rewrite_nit; + /** The actual version of the NIT pid */ + int nit_version; + bool nit_needs_update; + /** The Complete NIT PID which we are storing */ + mumudvb_ts_packet_t *full_nit; + +#endif /**Do we rewrite the PMT pid ?*/ option_status_t rewrite_pmt; diff --git a/src/rewrite_nit.c b/src/rewrite_nit.c new file mode 100644 index 00000000..b4fd1fa5 --- /dev/null +++ b/src/rewrite_nit.c @@ -0,0 +1,54 @@ +/** + * @file rewrite_nit.c + * @brief Patches NIT frequencies + * in order to know which programs are actually being broadcast, we need to reference an external + * configuration file. This config needs to be provided by the user in the format defined as follows: + * for each frequency to be kept: + * rewrite_nit=1 + * freq_patch=0x03300000->0x07700000 + * freq_patch=0x04500000->0x07780000 + * freq_patch=0x04660000->0x07860000 # TSID 10000 + * freq_patch=0x05620000->0x07940000 # TSID 10017 + * + * frequency entries without corresponding new mapping are discarded along with their entries + */ + +#include +#include +#include + +#include "autoconf.h" +#include "errors.h" +#include "log.h" +#include "mumudvb.h" +#include "rewrite.h" +#include "ts.h" /* nit_t*/ + +static char *log_module = "NIT rewrite: "; + + +typedef enum { + QAM_NOT_DEFINED, /* 0x0 */ + QAM16, /* 0x01 */ + QAM32, /* 0x02 */ + QAM64, /* 0x03 */ + QAM128, /* 0x04 */ + QAM256, /* 0x05 */ + QAM_RESERVED /* for future use: 0x06 to 0xFF */ +} modrate_t; + + +typedef struct nit_freq_map { + uint32_t oldfreq; /* in MHz, BCD coded */ + uint32_t newfreq; /* in MHz, BCD coded */ + modrate_t modulation; /* QAM modulation */ + uint32_t symbrate; /* in kSymb/sec */ +} nit_freq_map_t; + + + + + + + +void nit_rewrite_new_global_packet(unsigned char *ts_packet, rewrite_parameters_t *rewrite_vars) { return; } \ No newline at end of file diff --git a/src/ts.h b/src/ts.h index 83af76f3..fbefa280 100644 --- a/src/ts.h +++ b/src/ts.h @@ -676,6 +676,34 @@ typedef struct { #endif } descr_sat_delivery_t; +/** @brief 0x44 cable_delivery_system_descriptor */ +typedef struct { + uint8_t descriptor_tag :8; + uint8_t descriptor_length :8; + uint8_t frequency_4 :8; + uint8_t frequency_3 :8; + uint8_t frequency_2 :8; + uint8_t frequency_1 :8; + uint8_t reserved_future_use_1 :8; +#ifdef __BIG_ENDIAN__ + uint8_t reserved_future_use_2 :4; + uint8_t FEC_outer :4; +#else + uint8_t FEC_outer :4; + uint8_t reserved_future_use_2 :4; +#endif + uint8_t modulation_type :8; + uint8_t symbol_rate_12 :8; + uint8_t symbol_rate_34 :8; + uint8_t symbol_rate_56 :8; +#ifdef __BIG_ENDIAN__ + uint8_t symbol_rate_7 :4; + uint8_t FEC_inner :4; +#else + uint8_t FEC_inner :4; + uint8_t symbol_rate_7 :4; +#endif +} descr_cable_delivery_t; /*************************************************** * ATSC PSIP tables * From d27b84debf26520d0212bf08dca76561583c8be4 Mon Sep 17 00:00:00 2001 From: Johannes Hack Date: Thu, 17 Oct 2024 14:10:14 +0200 Subject: [PATCH 02/15] fn read_rewrite_nit_config --- doc/README.asciidoc | 1 + doc/README_CONF.asciidoc | 4 ++- doc/html/README.html | 13 +++++----- doc/html/README_CONF.html | 24 +++++++++++++---- src/mumudvb.c | 6 +++++ src/rewrite.h | 1 + src/rewrite_nit.c | 54 +++++++++++++++++++++++++++++++++++++++ 7 files changed, 91 insertions(+), 12 deletions(-) diff --git a/doc/README.asciidoc b/doc/README.asciidoc index d6a3fac6..01cb8432 100644 --- a/doc/README.asciidoc +++ b/doc/README.asciidoc @@ -111,6 +111,7 @@ The `[configure options]` specific to MuMuDVB are: --enable-duma Debbuging DUMA library (default disabled) --enable-android Support for Android (default disabled) --disable-dvb-support Build without Linux DVB-API support, even on systems where the headers are present + --enable-rewrite_nit_support Build with rewrite nit support --------------------------------------------------------------------- [NOTE] diff --git a/doc/README_CONF.asciidoc b/doc/README_CONF.asciidoc index a1a31e97..70a26673 100644 --- a/doc/README_CONF.asciidoc +++ b/doc/README_CONF.asciidoc @@ -222,7 +222,9 @@ Packets sending parameters |rewrite_pmt | Do we rewrite the PMT PID | 0 | 0 or 1 | See README, important if you don't stream all PIDs |rewrite_eit sort_eit | Do we rewrite/sort the EIT PID | 0 | 0 or 1 | See README |sdt_force_eit | Do we force the EIT_schedule_flag and EIT_present_following_flag in SDT | 0 | 0 or 1 | Set to 0 if you don't understand -|rtp_header | Send the stream with the rtp headers (except for HTTP unicast) | 0 | 0 or 1 | +|rtp_header | Send the stream with the rtp headers (except for HTTP unicast) | 0 | 0 or 1 | +|rewrite_nit | Patch certain frequencies in the nit table | 0 | 0 or 1 | see freq_patch and configure options +|freq_patch | Map the old frequency given as a hexadecimal value to a new frequency. For example `freq_patch=0x03300000->0x07700000` will rewrite the nit entry with the frequency 330MHz to 770MHz| | `%x->%x` | rewrite_nit needs to be enabled |================================================================================================================== Logs parameters diff --git a/doc/html/README.html b/doc/html/README.html index d37f15f7..82b97885 100644 --- a/doc/html/README.html +++ b/doc/html/README.html @@ -4,7 +4,7 @@ - + MuMuDVB - README