libdvbv5: move DVB scan handler code to a separate file
authorMauro Carvalho Chehab <m.chehab@samsung.com>
Thu, 14 Nov 2013 00:54:13 +0000 (22:54 -0200)
committerMauro Carvalho Chehab <m.chehab@samsung.com>
Wed, 27 Nov 2013 11:24:16 +0000 (09:24 -0200)
This were polluting the DVB descriptors API. They don't belong
to it anymore, with the new descriptors parsing code.

Move to a separate file.

It should be noticed that, right now, the DVB scan code is
not producing a valid scan file anymore, as those structs are
not properly initialized.

Latter patches will fix that.

Signed-off-by: Mauro Carvalho Chehab <m.chehab@samsung.com>
lib/include/descriptors.h
lib/include/dvb-scan-table-handler.h [new file with mode: 0644]
lib/libdvbv5/descriptors.c
lib/libdvbv5/dvb-file.c
lib/libdvbv5/dvb-scan-table-handler.c [new file with mode: 0644]
lib/libdvbv5/dvb-scan.c
utils/dvb/dvbv5-scan.c
utils/dvb/dvbv5-zap.c

index e537ed6..166f415 100644 (file)
@@ -299,124 +299,5 @@ enum extension_descriptors {
        service_relocated_descriptor                    = 0x0b,
 };
 
-struct pmt_table {
-       uint16_t program_number, pcr_pid;
-       unsigned char version;
-};
-
-struct el_pid {
-       uint8_t  type;
-       uint16_t pid;
-};
-
-struct pid_table {
-       uint16_t service_id;
-       uint16_t pid;
-       struct pmt_table pmt_table;
-       unsigned video_pid_len, audio_pid_len, other_el_pid_len;
-       uint16_t *video_pid;
-       uint16_t *audio_pid;
-       struct el_pid *other_el_pid;
-};
-
-struct pat_table {
-       uint16_t  ts_id;
-       unsigned char version;
-       struct pid_table *pid_table;
-       unsigned pid_table_len;
-};
-
-struct transport_table {
-       uint16_t tr_id;
-};
-
-struct lcn_table {
-       uint16_t service_id;
-       uint16_t lcn;
-};
-
-struct nit_table {
-       uint16_t network_id;
-       unsigned char version;
-       char *network_name, *network_alias;
-       struct transport_table *tr_table;
-       unsigned tr_table_len;
-       unsigned virtual_channel;
-       unsigned area_code;
-
-       /* Network Parameters */
-       uint32_t delivery_system;
-       uint32_t guard_interval;
-       uint32_t fec_inner, fec_outer;
-       uint32_t pol;
-       uint32_t modulation;
-       uint32_t rolloff;
-       uint32_t symbol_rate;
-       uint32_t bandwidth;
-       uint32_t code_rate_hp;
-       uint32_t code_rate_lp;
-       uint32_t transmission_mode;
-       uint32_t hierarchy;
-       uint32_t plp_id;
-       uint32_t system_id;
-
-       unsigned has_dvbt:1;
-       unsigned is_hp:1;
-       unsigned has_time_slicing:1;
-       unsigned has_mpe_fec:1;
-       unsigned has_other_frequency:1;
-       unsigned is_in_depth_interleaver:1;
-
-       char *orbit;
-       uint32_t *frequency;
-       unsigned frequency_len;
-
-       uint32_t *other_frequency;
-       unsigned other_frequency_len;
-
-       uint16_t *partial_reception;
-       unsigned partial_reception_len;
-
-       struct lcn_table *lcn;
-       unsigned lcn_len;
-};
-
-struct service_table {
-       uint16_t service_id;
-       char running;
-       char scrambled;
-       unsigned char type;
-       char *service_name, *service_alias;
-       char *provider_name, *provider_alias;
-};
-
-struct sdt_table {
-       unsigned char version;
-       uint16_t ts_id;
-       struct service_table *service_table;
-       unsigned service_table_len;
-};
-struct dvb_v5_descriptors {
-       int verbose;
-       uint32_t delivery_system;
-
-       struct pat_table pat_table;
-       struct nit_table nit_table;
-       struct sdt_table sdt_table;
-
-       /* Used by descriptors to know where to update a PMT/Service/TS */
-       unsigned cur_pmt;
-       unsigned cur_service;
-       unsigned cur_ts;
-};
-
-void parse_descriptor(struct dvb_v5_fe_parms *parms, enum dvb_tables type,
-               struct dvb_v5_descriptors *dvb_desc,
-               const unsigned char *buf, int len);
-
-int has_descriptor(struct dvb_v5_descriptors *dvb_desc,
-               unsigned char needed_descriptor,
-               const unsigned char *buf, int len);
-
 
 #endif
diff --git a/lib/include/dvb-scan-table-handler.h b/lib/include/dvb-scan-table-handler.h
new file mode 100644 (file)
index 0000000..1a4a7d4
--- /dev/null
@@ -0,0 +1,168 @@
+/*
+ * Copyright (c) 2013 - Mauro Carvalho Chehab <m.chehab@samsung.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation version 2
+ * of the License.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ * Or, point your browser to http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
+ */
+
+#include <inttypes.h>
+#include <stddef.h>
+#include <stdlib.h>
+#include <stdio.h>
+
+#include "descriptors.h"
+#include "dvb-fe.h"
+#include "dvb-scan.h"
+#include "dvb-frontend.h"
+#include "dvb-v5-std.h"
+#include "dvb-log.h"
+
+#include "descriptors/pat.h"
+#include "descriptors/pmt.h"
+#include "descriptors/nit.h"
+#include "descriptors/sdt.h"
+#include "descriptors/eit.h"
+#include "descriptors/vct.h"
+#include "descriptors/desc_language.h"
+#include "descriptors/desc_network_name.h"
+#include "descriptors/desc_cable_delivery.h"
+#include "descriptors/desc_sat.h"
+#include "descriptors/desc_terrestrial_delivery.h"
+#include "descriptors/desc_service.h"
+#include "descriptors/desc_service_list.h"
+#include "descriptors/desc_frequency_list.h"
+#include "descriptors/desc_event_short.h"
+#include "descriptors/desc_event_extended.h"
+#include "descriptors/desc_atsc_service_location.h"
+#include "descriptors/desc_hierarchy.h"
+
+struct pmt_table {
+       uint16_t program_number, pcr_pid;
+       unsigned char version;
+};
+
+struct el_pid {
+       uint8_t  type;
+       uint16_t pid;
+};
+
+struct pid_table {
+       uint16_t service_id;
+       uint16_t pid;
+       struct pmt_table pmt_table;
+       unsigned video_pid_len, audio_pid_len, other_el_pid_len;
+       uint16_t *video_pid;
+       uint16_t *audio_pid;
+       struct el_pid *other_el_pid;
+};
+
+struct pat_table {
+       uint16_t  ts_id;
+       unsigned char version;
+       struct pid_table *pid_table;
+       unsigned pid_table_len;
+};
+
+struct transport_table {
+       uint16_t tr_id;
+};
+
+struct lcn_table {
+       uint16_t service_id;
+       uint16_t lcn;
+};
+
+struct nit_table {
+       uint16_t network_id;
+       unsigned char version;
+       char *network_name, *network_alias;
+       struct transport_table *tr_table;
+       unsigned tr_table_len;
+       unsigned virtual_channel;
+       unsigned area_code;
+
+       /* Network Parameters */
+       uint32_t delivery_system;
+       uint32_t guard_interval;
+       uint32_t fec_inner, fec_outer;
+       uint32_t pol;
+       uint32_t modulation;
+       uint32_t rolloff;
+       uint32_t symbol_rate;
+       uint32_t bandwidth;
+       uint32_t code_rate_hp;
+       uint32_t code_rate_lp;
+       uint32_t transmission_mode;
+       uint32_t hierarchy;
+       uint32_t plp_id;
+       uint32_t system_id;
+
+       unsigned has_dvbt:1;
+       unsigned is_hp:1;
+       unsigned has_time_slicing:1;
+       unsigned has_mpe_fec:1;
+       unsigned has_other_frequency:1;
+       unsigned is_in_depth_interleaver:1;
+
+       char *orbit;
+       uint32_t *frequency;
+       unsigned frequency_len;
+
+       uint32_t *other_frequency;
+       unsigned other_frequency_len;
+
+       uint16_t *partial_reception;
+       unsigned partial_reception_len;
+
+       struct lcn_table *lcn;
+       unsigned lcn_len;
+};
+
+struct service_table {
+       uint16_t service_id;
+       char running;
+       char scrambled;
+       unsigned char type;
+       char *service_name, *service_alias;
+       char *provider_name, *provider_alias;
+};
+
+struct sdt_table {
+       unsigned char version;
+       uint16_t ts_id;
+       struct service_table *service_table;
+       unsigned service_table_len;
+};
+struct dvb_v5_descriptors {
+       int verbose;
+       uint32_t delivery_system;
+
+       struct pat_table pat_table;
+       struct nit_table nit_table;
+       struct sdt_table sdt_table;
+
+       /* Used by descriptors to know where to update a PMT/Service/TS */
+       unsigned cur_pmt;
+       unsigned cur_service;
+       unsigned cur_ts;
+};
+
+void parse_descriptor(struct dvb_v5_fe_parms *parms, enum dvb_tables type,
+               struct dvb_v5_descriptors *dvb_desc,
+               const unsigned char *buf, int len);
+
+int has_descriptor(struct dvb_v5_descriptors *dvb_desc,
+               unsigned char needed_descriptor,
+               const unsigned char *buf, int len);
index 845c8a8..f7dfb7e 100644 (file)
@@ -82,15 +82,6 @@ const struct dvb_table_init dvb_table_initializers[] = {
 char *default_charset = "iso-8859-1";
 char *output_charset = "utf-8";
 
-static char *table[] = {
-       [PAT] = "PAT",
-       [PMT] = "PMT",
-       [NIT] = "NIT",
-       [SDT] = "SDT",
-       [TVCT] = "TVCT",
-       [CVCT] = "CVCT",
-};
-
 void dvb_parse_descriptors(struct dvb_v5_fe_parms *parms, const uint8_t *buf, uint16_t section_length, struct dvb_desc **head_desc)
 {
        const uint8_t *ptr = buf;
@@ -313,22 +304,6 @@ const struct dvb_descriptor dvb_descriptors[] = {
        [atsc_genre_descriptor] = { "atsc_genre_descriptor", NULL, NULL, NULL, 0 },
 };
 
-static const char *extension_descriptors[] = {
-       [image_icon_descriptor] = "image_icon_descriptor",
-       [cpcm_delivery_signalling_descriptor] = "cpcm_delivery_signalling_descriptor",
-       [CP_descriptor] = "CP_descriptor",
-       [CP_identifier_descriptor] = "CP_identifier_descriptor",
-       [T2_delivery_system_descriptor] = "T2_delivery_system_descriptor",
-       [SH_delivery_system_descriptor] = "SH_delivery_system_descriptor",
-       [supplementary_audio_descriptor] = "supplementary_audio_descriptor",
-       [network_change_notify_descriptor] = "network_change_notify_descriptor",
-       [message_descriptor] = "message_descriptor",
-       [target_region_descriptor] = "target_region_descriptor",
-       [target_region_name_descriptor] = "target_region_name_descriptor",
-       [service_relocated_descriptor] = "service_relocated_descriptor",
-};
-
-
 uint32_t bcd(uint32_t bcd)
 {
        uint32_t ret = 0, mult = 1;
@@ -359,661 +334,6 @@ int bcd_to_int(const unsigned char *bcd, int bits)
        return ret;
 }
 
-static int add_frequency(struct nit_table *nit_table, uint32_t freq)
-{
-       unsigned n = nit_table->frequency_len;
-
-       nit_table->frequency = realloc(nit_table->frequency,
-                       (n + 1) * sizeof(*nit_table->frequency));
-
-       if (!nit_table->frequency)
-               return -ENOMEM;
-
-       nit_table->frequency[n] = freq;
-       nit_table->frequency_len++;
-
-       return 0;
-}
-
-static void parse_NIT_ISDBT(struct nit_table *nit_table,
-               const unsigned char *buf, int dlen,
-               int verbose)
-{
-       uint64_t freq;
-       static const uint32_t interval[] = {
-               [0] = GUARD_INTERVAL_1_32,
-               [1] = GUARD_INTERVAL_1_16,
-               [2] = GUARD_INTERVAL_1_8,
-               [3] = GUARD_INTERVAL_1_4,
-       };
-       static const char *interval_name[] = {
-               [GUARD_INTERVAL_1_4] =    "1/4",
-               [GUARD_INTERVAL_1_8] =    "1/8",
-               [GUARD_INTERVAL_1_16] =   "1/16",
-               [GUARD_INTERVAL_1_32] =   "1/32",
-       };
-       static const uint32_t mode[] = {
-               [0] = TRANSMISSION_MODE_2K,     /* Mode 1 */
-               [1] = TRANSMISSION_MODE_4K,     /* Mode 2 */
-               [2] = TRANSMISSION_MODE_8K,     /* Mode 3 */
-               [3] = TRANSMISSION_MODE_AUTO    /* Reserved */
-       };
-       static const char *tm_name[] = {
-               [TRANSMISSION_MODE_2K] =   "2K",
-               [TRANSMISSION_MODE_4K] =   "4K",
-               [TRANSMISSION_MODE_8K] =   "8K",
-               [TRANSMISSION_MODE_AUTO] = "AUTO",
-       };
-       int i, isdbt_mode, guard;
-
-       buf += 2;
-       nit_table->delivery_system = SYS_ISDBT;
-       isdbt_mode = buf[0] >> 6;
-       guard = buf[0] >> 4 & 0x3;
-       nit_table->area_code = ((buf[0] << 8) | buf[1]) & 0x0fff;
-       nit_table->guard_interval = interval[guard];
-       nit_table->transmission_mode = mode[isdbt_mode];
-       if (verbose)
-               printf("Area code: %d, mode %d (%s), guard interval: %s\n",
-                               nit_table->area_code,
-                               isdbt_mode + 1,
-                               tm_name[nit_table->transmission_mode],
-                               interval_name[nit_table->guard_interval]);
-       for (i = 2; i < dlen; i += 2) {
-               buf += 2;
-               /*
-                * The spec is not very clear about that, but some tests
-                * showed how this is supported to be calculated.
-                */
-               freq = ((buf[0] << 8 | buf[1]) * 1000000l) / 7; /* Hz */
-               add_frequency(nit_table, freq);
-
-               if (verbose)
-                       printf("Frequency %" PRId64 "\n", freq);
-       }
-}
-
-static const unsigned dvbc_dvbs_freq_inner[] = {
-       [0]  = FEC_AUTO,
-       [1]  = FEC_1_2,
-       [2]  = FEC_2_3,
-       [3]  = FEC_3_4,
-       [4]  = FEC_5_6,
-       [5]  = FEC_7_8,
-       [6]  = FEC_8_9,
-       [7]  = FEC_3_5,
-       [8]  = FEC_4_5,
-       [9]  = FEC_9_10,
-       [10 ...14] = FEC_AUTO,  /* Currently, undefined */
-       [15] = FEC_NONE,
-};
-
-static void parse_NIT_DVBS(struct nit_table *nit_table,
-               const unsigned char *buf, int dlen,
-               int verbose)
-{
-       unsigned orbit, west;
-       uint32_t freq;
-
-       static const unsigned polarization[] = {
-               [0] = POLARIZATION_H,
-               [1] = POLARIZATION_V,
-               [2] = POLARIZATION_L,
-               [3] = POLARIZATION_R
-       };
-       static const unsigned rolloff[] = {
-               [0] = ROLLOFF_35,
-               [1] = ROLLOFF_25,
-               [2] = ROLLOFF_20,
-               [3] = ROLLOFF_AUTO,     /* Reserved */
-       };
-       static const unsigned modulation[] = {
-               [0] = QAM_AUTO,
-               [1] = QPSK,
-               [2] = PSK_8,
-               [3] = QAM_16
-       };
-
-       freq =  bcd_to_int(&buf[2], 32) * 10; /* KHz */
-       add_frequency(nit_table, freq);
-
-       orbit = bcd_to_int(&buf[6], 16);
-       west = buf[8] >> 7;
-       asprintf(&nit_table->orbit, "%d%c", orbit, west ? 'W' : 'E');
-
-       nit_table->pol = polarization[(buf[8] >> 5) & 0x3];
-       nit_table->modulation = modulation[(buf[8] >> 3) & 0x3];
-       if (buf[8] & 1) {
-               nit_table->delivery_system = SYS_DVBS2;
-               nit_table->rolloff = rolloff[(buf[8] >> 1) & 0x3];
-       } else {
-               nit_table->delivery_system = SYS_DVBS;
-               nit_table->rolloff = ROLLOFF_35;
-       }
-       nit_table->symbol_rate = bcd_to_int(&buf[9], 28) * 100; /* Bauds */
-       nit_table->fec_inner = dvbc_dvbs_freq_inner[buf[12] & 0x07];
-
-       if (verbose) {
-               printf("DVB-%s orbit %s, freq %d, pol %d, modulation %d, rolloff %d\n",
-                               (nit_table->delivery_system == SYS_DVBS) ? "S" : "S2",
-                               nit_table->orbit, freq,
-                               nit_table->pol, nit_table->modulation,
-                               nit_table->rolloff);
-               printf("Symbol rate %d, fec_inner %d\n",
-                               nit_table->symbol_rate, nit_table->fec_inner);
-       }
-}
-
-static void parse_NIT_DVBC(struct nit_table *nit_table,
-               const unsigned char *buf, int dlen,
-               int verbose)
-{
-       uint32_t freq;
-       static const unsigned modulation[] = {
-               [0] = QAM_AUTO,
-               [1] = QAM_16,
-               [2] = QAM_32,
-               [3] = QAM_64,
-               [4] = QAM_128,
-               [5] = QAM_256,
-               [6 ...255] = QAM_AUTO   /* Reserved for future usage*/
-       };
-
-       freq = bcd_to_int(&buf[2], 32) * 100; /* KHz */
-       add_frequency(nit_table, freq);
-
-       nit_table->fec_outer = dvbc_dvbs_freq_inner[buf[7] & 0x07];
-       nit_table->modulation = modulation[buf[8]];
-       nit_table->symbol_rate = bcd_to_int(&buf[9], 28) * 100; /* Bauds */
-       nit_table->fec_inner = dvbc_dvbs_freq_inner[buf[12] & 0x07];
-
-       nit_table->delivery_system = SYS_DVBC_ANNEX_A;
-
-       if (verbose) {
-               printf("DVB-C freq %d, modulation %d, Symbol rate %d\n",
-                               freq,
-                               nit_table->modulation,
-                               nit_table->symbol_rate);
-               printf("fec_inner %d, fec_inner %d\n",
-                               nit_table->fec_inner, nit_table->fec_outer);
-       }
-}
-
-static void parse_NIT_DVBT(struct nit_table *nit_table,
-               const unsigned char *buf, int dlen,
-               int verbose)
-{
-       uint32_t freq;
-       static const unsigned bw[] = {
-               [0] = 8000000,
-               [1] = 7000000,
-               [2] = 6000000,
-               [3] = 5000000,
-               [4 ...7] = 0,           /* Reserved */
-       };
-       static const unsigned modulation[] = {
-               [0] = QPSK,
-               [1] = QAM_16,
-               [2] = QAM_32,
-               [3] = QAM_AUTO  /* Reserved */
-       };
-       static const unsigned hierarchy[] = {
-               [0] = HIERARCHY_NONE,
-               [1] = HIERARCHY_1,
-               [2] = HIERARCHY_2,
-               [3] = HIERARCHY_4,
-       };
-       static const unsigned code_rate[] = {
-               [0] = FEC_1_2,
-               [1] = FEC_2_3,
-               [2] = FEC_3_4,
-               [3] = FEC_5_6,
-               [4] = FEC_7_8,
-               [5 ...7] = FEC_AUTO,    /* Reserved */
-       };
-       static const uint32_t interval[] = {
-               [0] = GUARD_INTERVAL_1_32,
-               [1] = GUARD_INTERVAL_1_16,
-               [2] = GUARD_INTERVAL_1_8,
-               [3] = GUARD_INTERVAL_1_4,
-       };
-       static const unsigned transmission_mode[] = {
-               [0] = TRANSMISSION_MODE_2K,
-               [1] = TRANSMISSION_MODE_8K,
-               [2] = TRANSMISSION_MODE_4K,
-               [3] = TRANSMISSION_MODE_AUTO,   /* Reserved */
-       };
-
-       freq = (buf[2] << 24) | (buf[3] << 16) | (buf[4] << 8)  |  buf[5];
-       freq *= 10; /* Hz */
-       add_frequency(nit_table, freq);
-
-       nit_table->has_dvbt = 1;
-       if (nit_table->delivery_system != SYS_DVBT2)
-               nit_table->delivery_system = SYS_DVBT;
-       nit_table->bandwidth = bw[(buf[6] >> 5) & 0x07];
-       nit_table->is_hp = (buf[6] & 0x10) ? 1 : 0;
-       nit_table->has_time_slicing = (buf[6] & 0x08) ? 0 : 1;
-       nit_table->has_mpe_fec = (buf[6] & 0x04) ? 0 : 1;
-
-       nit_table->modulation = modulation[buf[7] >> 6];
-       nit_table->hierarchy = hierarchy[(buf[7] >> 3) & 0x03];
-       nit_table->is_in_depth_interleaver = (buf[7] & 0x20) ? 1 : 0;
-       nit_table->code_rate_hp = code_rate[buf[7] & 0x07];
-       nit_table->code_rate_lp = code_rate[(buf[8] >> 5) & 0x07];
-       nit_table->guard_interval = interval[(buf[8] >> 3) & 0x03];
-       nit_table->transmission_mode = transmission_mode[(buf[8] >> 1) & 0x02];
-       nit_table->has_other_frequency = buf[8] & 0x01;
-
-       if (verbose) {
-               printf("DVB-T freq %d, bandwidth %d modulation %d\n",
-                               freq,
-                               nit_table->bandwidth,
-                               nit_table->modulation);
-               printf("hierarchy %d, code rate HP %d, LP %d, guard interval %d\n",
-                               nit_table->hierarchy,
-                               nit_table->code_rate_hp,
-                               nit_table->code_rate_lp,
-                               nit_table->guard_interval);
-               printf("transmission mode %d\n", nit_table->transmission_mode);
-       }
-}
-
-static void parse_NIT_DVBT2(struct nit_table *nit_table,
-               const unsigned char *buf, int dlen,
-               int verbose)
-{
-       static const unsigned bw[] = {
-               [0] =  8000000,
-               [1] =  7000000,
-               [2] =  6000000,
-               [3] =  5000000,
-               [4] = 10000000,
-               [5] =  1712000,
-               [6 ...15] = 0,          /* Reserved */
-       };
-       static const uint32_t interval[] = {
-               [0] = GUARD_INTERVAL_1_32,
-               [1] = GUARD_INTERVAL_1_16,
-               [2] = GUARD_INTERVAL_1_8,
-               [3] = GUARD_INTERVAL_1_4,
-               [4] = GUARD_INTERVAL_1_128,
-               [5] = GUARD_INTERVAL_19_128,
-               [6] = GUARD_INTERVAL_19_256,
-               [7 ...15] = GUARD_INTERVAL_AUTO /* Reserved */
-       };
-       static const unsigned transmission_mode[] = {
-               [0] = TRANSMISSION_MODE_2K,
-               [1] = TRANSMISSION_MODE_8K,
-               [2] = TRANSMISSION_MODE_4K,
-               [3] = TRANSMISSION_MODE_1K,
-               [4] = TRANSMISSION_MODE_16K,
-               [5] = TRANSMISSION_MODE_32K,
-               [6 ...7] = TRANSMISSION_MODE_AUTO,      /* Reserved */
-       };
-
-       nit_table->delivery_system = SYS_DVBT2;
-
-
-       buf += 2;
-       nit_table->plp_id = buf[0];
-       nit_table->system_id = buf[1] << 8 | buf[2];
-
-       buf += 2;
-       dlen -= 4;
-       if (dlen <= 0)
-               return;
-
-       nit_table->bandwidth = bw[(buf[0] >> 2) & 0x0f];
-       nit_table->guard_interval = interval[buf[1] >> 5];
-       nit_table->transmission_mode = transmission_mode[(buf[1] >> 2) & 0x07];
-       nit_table->has_other_frequency = buf[1] & 0x02 ? 1 : 0;
-
-       /* FIXME: add a parser for the cell tables */
-       return;
-}
-
-static void parse_freq_list(struct nit_table *nit_table,
-               const unsigned char *buf, int dlen,
-               int verbose)
-{
-       int i;
-       uint32_t freq;
-
-       buf += 3;
-       for (i = 3; i < dlen; i += 4) {
-               freq = (buf[0] << 24) | (buf[1] << 16) | (buf[2] << 8) | buf[3];
-               freq *= 10;     /* Hz */
-               add_frequency(nit_table, freq);
-
-               if (verbose)
-                       printf("Frequency %d\n", freq);
-               buf += 4;
-       }
-}
-
-static void parse_partial_reception(struct nit_table *nit_table,
-               const unsigned char *buf, int dlen,
-               int verbose)
-{
-       int i;
-       uint16_t **pid = &nit_table->partial_reception;
-       unsigned *n = &nit_table->partial_reception_len;
-
-       buf += 2;
-       for (i = 0; i < dlen; i += 2) {
-               *pid = realloc(*pid, (*n + 1) * sizeof(**pid));
-               nit_table->partial_reception[*n] = buf[i] << 8 | buf[i + 1];
-               if (verbose)
-                       printf("Service 0x%04x has partial reception\n",
-                                       nit_table->partial_reception[*n]);
-               buf += 2;
-               (*n)++;
-       }
-}
-
-static int parse_extension_descriptor(enum dvb_tables type,
-               struct dvb_v5_descriptors *dvb_desc,
-               const unsigned char *buf, int dlen)
-{
-       unsigned char ext = buf[0];
-       int i;
-
-       if (dlen < 1)
-               return 0;
-
-       /* buf[0] will point to the first useful data */
-       buf++;
-       dlen--;
-
-       if (dvb_desc->verbose) {
-               printf("Extension descriptor %s (0x%02x), len %d",
-                               extension_descriptors[ext], ext, dlen);
-               for (i = 0; i < dlen; i++) {
-                       if (!(i % 16))
-                               printf("\n\t");
-                       printf("%02x ", (uint8_t) *(buf + i));
-               }
-               printf("\n");
-       }
-       switch(ext) {
-               case T2_delivery_system_descriptor:
-                       if (type != NIT)
-                               return 1;
-
-                       parse_NIT_DVBT2(&dvb_desc->nit_table, buf, dlen,
-                                       dvb_desc->verbose);
-                       break;
-       }
-
-       return 0;
-};
-
-static void parse_net_name(struct dvb_v5_fe_parms *parms, struct nit_table *nit_table,
-               const unsigned char *buf, int dlen, int verbose)
-{
-       parse_string(parms, &nit_table->network_name, &nit_table->network_alias,
-                       &buf[2], dlen, default_charset, output_charset);
-       if (verbose) {
-               printf("Network");
-               if (nit_table->network_name)
-                       printf(" %s", nit_table->network_name);
-               if (nit_table->network_alias)
-                       printf(" (%s)", nit_table->network_alias);
-               if (!nit_table->network_name && !nit_table->network_alias)
-                       printf(" unknown");
-               printf("\n");
-       }
-}
-
-
-static void parse_lcn(struct nit_table *nit_table,
-               const unsigned char *buf, int dlen, int verbose)
-{
-       int i, n = nit_table->lcn_len;
-       const unsigned char *p = &buf[2];
-
-
-       for (i = 0; i < dlen; i+= 4, p+= 4) {
-               struct lcn_table **lcn = &nit_table->lcn;
-
-               *lcn = realloc(*lcn, (n + 1) * sizeof(**lcn));
-               (*lcn)[n].service_id = p[0] << 8 | p[1];
-               (*lcn)[n].lcn = (p[2] << 8 | p[3]) & 0x3ff;
-               nit_table->lcn_len++;
-               n++;
-
-               if (verbose)
-                       printf("Service ID: 0x%04x, LCN: %d\n",
-                                       (*lcn)[n].service_id,
-                                       (*lcn)[n].lcn);
-       }
-}
-
-static void parse_service(struct dvb_v5_fe_parms *parms, struct service_table *service_table,
-               const unsigned char *buf, int dlen, int verbose)
-{
-       service_table->type = buf[2];
-       parse_string(parms, &service_table->provider_name,
-                       &service_table->provider_alias,
-                       &buf[4], buf[3],
-                       default_charset, output_charset);
-       buf += 4 + buf[3];
-       parse_string(parms, &service_table->service_name,
-                       &service_table->service_alias,
-                       &buf[1], buf[0],
-                       default_charset, output_charset);
-       if (verbose) {
-               if (service_table->provider_name)
-                       printf("Provider %s", service_table->provider_name);
-               if (service_table->provider_alias)
-                       printf("(%s)", service_table->provider_alias);
-               if (service_table->provider_name || service_table->provider_alias)
-                       printf("\n");
-               if (service_table->service_name)
-                       printf("Service %s", service_table->service_name);
-               if (service_table->service_alias)
-                       printf("(%s)", service_table->service_alias);
-               if (!service_table->provider_name &&
-                               !service_table->service_alias &&
-                               !service_table->service_name &&
-                               !service_table->service_alias)
-                       printf("Service 0x%04x", service_table->service_id);
-               printf("\n");
-       }
-}
-
-void parse_descriptor(struct dvb_v5_fe_parms *parms, enum dvb_tables type,
-               struct dvb_v5_descriptors *dvb_desc,
-               const unsigned char *buf, int len)
-{
-       int i;
-
-       if (len == 0)
-               return;
-
-       if (dvb_desc->verbose)
-               printf("Descriptors table len %d\n", len);
-       do {
-               int dlen = buf[1];
-               int err = 0;
-
-               if (dlen > len) {
-                       fprintf(stderr, "descriptor size %d is longer than %d!\n",
-                                       dlen, len);
-                       return;
-               }
-               if (dvb_desc->verbose) {
-                       printf("%s (0x%02x), len %d",
-                                       dvb_descriptors[buf[0]].name, buf[0], buf[1]);
-                       for (i = 0; i < dlen; i++) {
-                               if (!(i % 16))
-                                       printf("\n\t");
-                               printf("%02x ", (uint8_t) *(buf + i + 2));
-                       }
-                       printf("\n");
-               }
-               switch(buf[0]) {
-                       case extension_descriptor:
-                               err = parse_extension_descriptor(type, dvb_desc,
-                                               &buf[2], dlen);
-                               break;
-                       case iso639_language_descriptor:
-                               {
-                                       int i;
-                                       const unsigned char *p = &buf[2];
-
-                                       if (dvb_desc->verbose) {
-                                               for (i = 0; i < dlen; i+= 4, p += 4) {
-                                                       printf("Language = %c%c%c, amode = %d\n",
-                                                                       p[0], p[1], p[2], p[3]);
-                                               }
-                                       }
-                                       break;
-                               }
-                       case AAC_descriptor:
-                               if (dvb_desc->verbose)
-                                       printf("AAC descriptor with len %d\n", dlen);
-                               break;
-                       case stream_identifier_descriptor:
-                               /* Don't need to parse it */
-                               if (dvb_desc->verbose)
-                                       printf("Component tag 0x%02x\n", buf[2]);
-                               break;
-                       case network_name_descriptor:
-                               if (type != NIT) {
-                                       err = 1;
-                                       break;
-                               }
-                               parse_net_name(parms, &dvb_desc->nit_table, buf, dlen,
-                                               dvb_desc->verbose);
-                               break;
-
-                               /* DVB NIT decoders */
-                       case satellite_delivery_system_descriptor:
-                               if (type != NIT) {
-                                       err = 1;
-                                       break;
-                               }
-                               parse_NIT_DVBS(&dvb_desc->nit_table, buf, dlen,
-                                               dvb_desc->verbose);
-                               break;
-                       case cable_delivery_system_descriptor:
-                               if (type != NIT) {
-                                       err = 1;
-                                       break;
-                               }
-                               parse_NIT_DVBC(&dvb_desc->nit_table, buf, dlen,
-                                               dvb_desc->verbose);
-                               break;
-                       case terrestrial_delivery_system_descriptor:
-                               if (type != NIT) {
-                                       err = 1;
-                                       break;
-                               }
-                               parse_NIT_DVBT(&dvb_desc->nit_table, buf, dlen,
-                                               dvb_desc->verbose);
-                               break;
-
-                               /* ISDBT NIT decoders */
-                       case ISDBT_delivery_system_descriptor:
-                               if (type != NIT) {
-                                       err = 1;
-                                       break;
-                               }
-
-                               parse_NIT_ISDBT(&dvb_desc->nit_table, buf, dlen,
-                                               dvb_desc->verbose);
-                               break;
-                       case partial_reception_descriptor:
-                               if (type != NIT) {
-                                       err = 1;
-                                       break;
-                               }
-                               parse_partial_reception(&dvb_desc->nit_table, buf, dlen,
-                                               dvb_desc->verbose);
-                               break;
-
-                               /* LCN decoder */
-                       case logical_channel_number_descriptor:
-                               {
-                                       /*
-                                        * According with SCTE 57 2011, descriptor 0x83
-                                        * is the extended video descriptor. We don't need
-                                        * it, but don't print an error for this condition.
-                                        */
-                                       if (type == PMT)
-                                               break;
-                                       if (type != NIT) {
-                                               err = 1;
-                                               break;
-                                       }
-                                       parse_lcn(&dvb_desc->nit_table, buf, dlen,
-                                                       dvb_desc->verbose);
-                                       break;
-                               }
-
-                       case TS_Information_descriptior:
-                               if (type != NIT) {
-                                       err = 1;
-                                       break;
-                               }
-                               dvb_desc->nit_table.virtual_channel = buf[2];
-                               if (dvb_desc->verbose)
-                                       printf("Virtual channel = %d\n", buf[2]);
-                               break;
-
-                       case frequency_list_descriptor:
-                               if (type != NIT) {
-                                       err = 1;
-                                       break;
-                               }
-                               parse_freq_list(&dvb_desc->nit_table, buf, dlen,
-                                               dvb_desc->verbose);
-                               break;
-
-                       case service_descriptor: {
-                                                        if (type != SDT) {
-                                                                err = 1;
-                                                                break;
-                                                        }
-                                                        parse_service(parms, &dvb_desc->sdt_table.service_table[dvb_desc->cur_service],
-                                                                        buf, dlen, dvb_desc->verbose);
-                                                        break;
-                                                }
-                       default:
-                                                break;
-               }
-               if (err) {
-                       fprintf(stderr,
-                                       "descriptor %s is invalid on %s table\n",
-                                       dvb_descriptors[buf[0]].name, table[type]);
-               }
-               buf += dlen + 2;
-               len -= dlen + 2;
-       } while (len > 0);
-}
-
-int has_descriptor(struct dvb_v5_descriptors *dvb_desc,
-               unsigned char needed_descriptor,
-               const unsigned char *buf, int len)
-{
-       if (len == 0)
-               return 0;
-
-       do {
-               int dlen = buf[1];
-
-               if (buf[0] == needed_descriptor)
-                       return 1;
-
-               buf += dlen + 2;
-               len -= dlen + 2;
-       } while (len > 0);
-
-       return 0;
-}
-
 void hexdump(struct dvb_v5_fe_parms *parms, const char *prefix, const unsigned char *data, int length)
 {
        if (!data)
@@ -1051,126 +371,4 @@ void hexdump(struct dvb_v5_fe_parms *parms, const char *prefix, const unsigned c
                ascii[j] = '\0';
                dvb_log("%s%s %s %s", prefix, hex, spaces, ascii);
        }
-
-       /*int i, j;*/
-       /*char tmp[64];*/
-       /*char ascii[32];*/
-       /*for (i = 0, j = 0; i < len; i++, j++) {*/
-       /*if (i && !(i % 16)) {*/
-       /*dvb_log("%s%s", prefix, tmp);*/
-       /*j = 0;*/
-       /*}*/
-       /*sprintf( tmp + j * 3, "%02x ", (uint8_t) *(buf + i));*/
-       /*}*/
-       /*if (i && (i % 16))*/
-       /*dvb_log("%s%s", prefix, tmp);*/
-}
-
-#if 0
-/* TODO: remove those stuff */
-
-case ds_alignment_descriptor:
-case registration_descriptor:
-case service_list_descriptor:
-case stuffing_descriptor:
-case VBI_data_descriptor:
-case VBI_teletext_descriptor:
-case bouquet_name_descriptor:
-case country_availability_descriptor:
-case linkage_descriptor:
-case NVOD_reference_descriptor:
-case time_shifted_service_descriptor:
-case short_event_descriptor:
-case extended_event_descriptor:
-case time_shifted_event_descriptor:
-case component_descriptor:
-case mosaic_descriptor:
-case CA_identifier_descriptor:
-case content_descriptor:
-case parental_rating_descriptor:
-case teletext_descriptor:
-case telephone_descriptor:
-case local_time_offset_descriptor:
-case subtitling_descriptor:
-case multilingual_network_name_descriptor:
-case multilingual_bouquet_name_descriptor:
-case multilingual_service_name_descriptor:
-case multilingual_component_descriptor:
-case private_data_specifier_descriptor:
-case service_move_descriptor:
-case short_smoothing_buffer_descriptor:
-case partial_transport_stream_descriptor:
-case data_broadcast_descriptor:
-case scrambling_descriptor:
-case data_broadcast_id_descriptor:
-case transport_stream_descriptor:
-case DSNG_descriptor:
-case PDC_descriptor:
-case AC_3_descriptor:
-case ancillary_data_descriptor:
-case cell_list_descriptor:
-case cell_frequency_link_descriptor:
-case announcement_support_descriptor:
-case application_signalling_descriptor:
-case adaptation_field_data_descriptor:
-case service_identifier_descriptor:
-case service_availability_descriptor:
-case default_authority_descriptor:
-case related_content_descriptor:
-case TVA_id_descriptor:
-case content_identifier_descriptor:
-case time_slice_fec_identifier_descriptor:
-case ECM_repetition_rate_descriptor:
-case S2_satellite_delivery_system_descriptor:
-case enhanced_AC_3_descriptor:
-case DTS_descriptor:
-case XAIT_location_descriptor:
-case FTA_content_management_descriptor:
-case extension_descriptor:
-
-case CUE_identifier_descriptor:
-case component_name_descriptor:
-case conditional_access_descriptor:
-case copyright_descriptor:
-case carousel_id_descriptor:
-case association_tag_descriptor:
-case deferred_association_tags_descriptor:
-case AVC_video_descriptor:
-case AVC_timing_and_HRD_descriptor:
-case hierarchical_transmission_descriptor:
-case digital_copy_control_descriptor:
-case network_identifier_descriptor:
-case partial_transport_stream_time_descriptor:
-case audio_component_descriptor:
-case hyperlink_descriptor:
-case target_area_descriptor:
-case data_contents_descriptor:
-case video_decode_control_descriptor:
-case download_content_descriptor:
-case CA_EMM_TS_descriptor:
-case CA_contract_information_descriptor:
-case CA_service_descriptor:
-case extended_broadcaster_descriptor:
-case logo_transmission_descriptor:
-case basic_local_event_descriptor:
-case reference_descriptor:
-case node_relation_descriptor:
-case short_node_information_descriptor:
-case STC_reference_descriptor:
-case series_descriptor:
-case event_group_descriptor:
-case SI_parameter_descriptor:
-case broadcaster_Name_Descriptor:
-case component_group_descriptor:
-case SI_prime_TS_descriptor:
-case board_information_descriptor:
-case LDT_linkage_descriptor:
-case connected_transmission_descriptor:
-case content_availability_descriptor:
-case service_group_descriptor:
-case carousel_compatible_composite_Descriptor:
-case conditional_playback_descriptor:
-case emergency_information_descriptor:
-case data_component_descriptor:
-case system_management_descriptor:
-#endif
+}
\ No newline at end of file
index f43a9f9..72464b7 100644 (file)
@@ -26,6 +26,7 @@
 #include "dvb-file.h"
 #include "dvb-v5-std.h"
 #include "dvb-scan.h"
+#include "dvb-scan-table-handler.h"
 
 /*
  * Generic parse function for all formats each channel is contained into
diff --git a/lib/libdvbv5/dvb-scan-table-handler.c b/lib/libdvbv5/dvb-scan-table-handler.c
new file mode 100644 (file)
index 0000000..f578ae2
--- /dev/null
@@ -0,0 +1,52 @@
+/*
+ * Copyright (c) 2013 - Mauro Carvalho Chehab <m.chehab@samsung.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation version 2
+ * of the License.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ * Or, point your browser to http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
+ */
+
+#include <inttypes.h>
+#include <stddef.h>
+#include <stdlib.h>
+#include <stdio.h>
+
+#include "descriptors.h"
+#include "dvb-fe.h"
+#include "dvb-scan.h"
+#include "parse_string.h"
+#include "dvb-frontend.h"
+#include "dvb-v5-std.h"
+#include "dvb-log.h"
+
+#include "descriptors/pat.h"
+#include "descriptors/pmt.h"
+#include "descriptors/nit.h"
+#include "descriptors/sdt.h"
+#include "descriptors/eit.h"
+#include "descriptors/vct.h"
+#include "descriptors/desc_language.h"
+#include "descriptors/desc_network_name.h"
+#include "descriptors/desc_cable_delivery.h"
+#include "descriptors/desc_sat.h"
+#include "descriptors/desc_terrestrial_delivery.h"
+#include "descriptors/desc_service.h"
+#include "descriptors/desc_service_list.h"
+#include "descriptors/desc_frequency_list.h"
+#include "descriptors/desc_event_short.h"
+#include "descriptors/desc_event_extended.h"
+#include "descriptors/desc_atsc_service_location.h"
+#include "descriptors/desc_hierarchy.h"
+
+#include "dvb-scan-table-handler.h"
index ac1e8f9..e74d7d9 100644 (file)
@@ -50,6 +50,7 @@
 #include "descriptors/nit.h"
 #include "descriptors/sdt.h"
 #include "descriptors/vct.h"
+#include "dvb-scan-table-handler.h"
 
 static int poll(struct dvb_v5_fe_parms *parms, int fd, unsigned int seconds)
 {
@@ -203,11 +204,12 @@ int dvb_read_section_with_id(struct dvb_v5_fe_parms *parms, int dmx_fd,
        return 0;
 }
 
-struct dvb_v5_descriptors *dvb_get_ts_tables(struct dvb_v5_fe_parms *parms, int dmx_fd,
-               uint32_t delivery_system,
-               unsigned other_nit,
-               unsigned timeout_multiply,
-               int verbose)
+struct dvb_v5_descriptors *dvb_get_ts_tables(struct dvb_v5_fe_parms *parms,
+                                            int dmx_fd,
+                                            uint32_t delivery_system,
+                                            unsigned other_nit,
+                                            unsigned timeout_multiply,
+                                            int verbose)
 {
        int rc;
        unsigned pat_pmt_time, sdt_time, nit_time, vct_time;
index 4ffa790..e6c918e 100644 (file)
@@ -37,6 +37,7 @@
 #include "dvb-demux.h"
 #include "dvb-v5-std.h"
 #include "dvb-scan.h"
+#include "dvb-scan-table-handler.h"
 
 #define PROGRAM_NAME   "dvbv5-scan"
 #define DEFAULT_OUTPUT  "dvb_channel.conf"
index d6c1152..30eb946 100644 (file)
@@ -40,6 +40,7 @@
 #include "dvb-file.h"
 #include "dvb-demux.h"
 #include "dvb-scan.h"
+#include "dvb-scan-table-handler.h"
 
 #define CHANNEL_FILE   "channels.conf"
 #define PROGRAM_NAME   "dvbv5-zap"