From eddc6bd7739a6d006c3b0a3278935173bc0183ff Mon Sep 17 00:00:00 2001 From: Mauro Carvalho Chehab Date: Tue, 24 Jan 2012 15:00:59 -0200 Subject: [PATCH] dvb: Move the generic read/write routines to the library Instead of having them only for dvb-format-convert, move them to the library. This way, they can be used by the other tools. Signed-off-by: Mauro Carvalho Chehab --- utils/dvb/dvb-fe-tool.c | 21 ++------- utils/dvb/dvb-file.c | 104 +++++++++++++++++++++++++++++++++++++++++ utils/dvb/dvb-file.h | 17 +++++++ utils/dvb/dvb-format-convert.c | 76 ++---------------------------- 4 files changed, 129 insertions(+), 89 deletions(-) diff --git a/utils/dvb/dvb-fe-tool.c b/utils/dvb/dvb-fe-tool.c index 18c2988..747f3cf 100644 --- a/utils/dvb/dvb-fe-tool.c +++ b/utils/dvb/dvb-fe-tool.c @@ -47,24 +47,9 @@ static error_t parse_opt(int k, char *arg, struct argp_state *state) frontend = atoi(arg); break; case 'd': - for (i = 0; i < ARRAY_SIZE(delivery_system_name); i++) - if (delivery_system_name[i] && - !strcasecmp(arg, delivery_system_name[i])) - break; - if (i < ARRAY_SIZE(delivery_system_name)) { - delsys = i; - break; - } - /* Not found. Print all possible values */ - fprintf(stderr, "Delivery system %s is not known. Valid values are:\n", - arg); - for (i = 0; i < ARRAY_SIZE(delivery_system_name) - 1; i++) { - fprintf(stderr, "%-15s", delivery_system_name[i]); - if (!((i + 1) % 5)) - fprintf(stderr, "\n"); - } - fprintf(stderr, "\n"); - return ARGP_ERR_UNKNOWN; + delsys = parse_delsys(arg); + if (delsys < 0) + return ARGP_ERR_UNKNOWN; break; case 's': set_params = arg; diff --git a/utils/dvb/dvb-file.c b/utils/dvb/dvb-file.c index 1c5cece..b7d2d68 100644 --- a/utils/dvb/dvb-file.c +++ b/utils/dvb/dvb-file.c @@ -953,3 +953,107 @@ int store_dvb_channel(struct dvb_file **dvb_file, return 0; } + +enum file_formats parse_format(const char *name) +{ + if (!strcasecmp(name, "ZAP")) + return FILE_ZAP; + if (!strcasecmp(name, "CHANNEL")) + return FILE_CHANNEL; + if (!strcasecmp(name, "DVBV5")) + return FILE_DVBV5; + + fprintf(stderr, "File format %s is unknown\n", name); + return FILE_UNKNOWN; +} + +int parse_delsys(const char *name) +{ + int i; + + /* Check for DVBv5 names */ + for (i = 0; i < ARRAY_SIZE(delivery_system_name); i++) + if (delivery_system_name[i] && + !strcasecmp(name, delivery_system_name[i])) + break; + if (i < ARRAY_SIZE(delivery_system_name)) + return i; + + /* Also accept DVB- format */ + if (!strcasecmp(name, "DVB-T")) + return SYS_DVBT; + if (!strcasecmp(name, "DVB-C")) + return SYS_DVBC_ANNEX_A; + if (!strcasecmp(name, "DVB-S")) + return SYS_DVBS; + if (!strcasecmp(name, "ISDB-T")) + return SYS_ISDBT; + + /* Not found. Print all possible values, "by the book" */ + fprintf(stderr, "Delivery system %s is not known. Valid values are:\n", + name); + for (i = 0; i < ARRAY_SIZE(delivery_system_name) - 1; i++) { + fprintf(stderr, "%-15s", delivery_system_name[i]); + if (!((i + 1) % 5)) + fprintf(stderr, "\n"); + } + + fprintf(stderr, "Delivery system unknown\n"); + return -1; +} + +struct dvb_file *read_file_format(const char *fname, + uint32_t delsys, + enum file_formats format) +{ + struct dvb_file *dvb_file; + + switch (format) { + case FILE_CHANNEL: /* DVB channel/transponder old format */ + dvb_file = parse_format_oneline(fname, + SYS_UNDEFINED, + &channel_file_format); + break; + case FILE_ZAP: + dvb_file = parse_format_oneline(fname, + delsys, + &channel_file_zap_format); + break; + case FILE_DVBV5: + dvb_file = read_dvb_file(fname); + default: + return NULL; + } + + return dvb_file; +} + +int write_file_format(const char *fname, + struct dvb_file *dvb_file, + uint32_t delsys, + enum file_formats format) +{ + int ret; + + switch (format) { + case FILE_CHANNEL: /* DVB channel/transponder old format */ + ret = write_format_oneline(fname, + dvb_file, + SYS_UNDEFINED, + &channel_file_format); + break; + case FILE_ZAP: + ret = write_format_oneline(fname, + dvb_file, + delsys, + &channel_file_zap_format); + break; + case FILE_DVBV5: + ret = write_dvb_file(fname, dvb_file); + default: + return -1; + } + + return ret; +} + diff --git a/utils/dvb/dvb-file.h b/utils/dvb/dvb-file.h index 5f9e6e5..9fa5e54 100644 --- a/utils/dvb/dvb-file.h +++ b/utils/dvb/dvb-file.h @@ -65,6 +65,14 @@ struct parse_file { struct parse_struct formats[]; }; +/* Known file formats */ +enum file_formats { + FILE_UNKNOWN, + FILE_ZAP, + FILE_CHANNEL, + FILE_DVBV5, +}; + #define PTABLE(a) .table = a, .size=ARRAY_SIZE(a) /* FAKE DTV codes, for internal usage */ @@ -133,3 +141,12 @@ int store_dvb_channel(struct dvb_file **dvb_file, struct dvb_v5_fe_parms *parms, struct dvb_descriptors *dvb_desc, int get_detected, int get_nit); +int parse_delsys(const char *name); +enum file_formats parse_format(const char *name); +struct dvb_file *read_file_format(const char *fname, + uint32_t delsys, + enum file_formats format); +int write_file_format(const char *fname, + struct dvb_file *dvb_file, + uint32_t delsys, + enum file_formats format); diff --git a/utils/dvb/dvb-format-convert.c b/utils/dvb/dvb-format-convert.c index 14c6cb7..b20a178 100644 --- a/utils/dvb/dvb-format-convert.c +++ b/utils/dvb/dvb-format-convert.c @@ -37,13 +37,6 @@ #define PROGRAM_NAME "dvb-format-convert" -enum file_formats { - FILE_UNKNOWN, - FILE_ZAP, - FILE_CHANNEL, - FILE_DVBV5, -}; - struct arguments { char *input_file, *output_file; enum file_formats input_format, output_format; @@ -60,34 +53,6 @@ static const struct argp_option options[] = { const char *argp_program_version = PROGRAM_NAME " version " V4L_UTILS_VERSION; const char *argp_program_bug_address = "Mauro Carvalho Chehab "; -enum file_formats parse_format(const char *name) -{ - if (!strcasecmp(name, "ZAP")) - return FILE_ZAP; - if (!strcasecmp(name, "CHANNEL")) - return FILE_CHANNEL; - if (!strcasecmp(name, "DVBV5")) - return FILE_DVBV5; - - fprintf(stderr, "File format %s is unknown\n", name); - return FILE_UNKNOWN; -} - -int parse_delsys(const char *name) -{ - if (!strcasecmp(name, "DVB-T")) - return SYS_DVBT; - if (!strcasecmp(name, "DVB-C")) - return SYS_DVBC_ANNEX_A; - if (!strcasecmp(name, "DVB-S")) - return SYS_DVBS; - if (!strcasecmp(name, "ATSC")) - return SYS_ATSC; - - fprintf(stderr, "Delivery system unknown\n"); - return -1; -} - static error_t parse_opt(int k, char *optarg, struct argp_state *state) { struct arguments *args = state->input; @@ -113,44 +78,13 @@ static int convert_file(struct arguments *args) int ret; printf("Reading file %s\n", args->input_file); - switch (args->input_format) { - case FILE_CHANNEL: /* DVB channel/transponder old format */ - dvb_file = parse_format_oneline(args->input_file, - SYS_UNDEFINED, - &channel_file_format); - break; - case FILE_ZAP: - dvb_file = parse_format_oneline(args->input_file, - (uint32_t)args->delsys, - &channel_file_zap_format); - break; - case FILE_DVBV5: - dvb_file = read_dvb_file(args->input_file); - default: - return -1; - } - if (!dvb_file) - return -2; + + dvb_file = read_file_format(args->input_file, args->delsys, + args->input_format); printf("Writing file %s\n", args->output_file); - switch (args->output_format) { - case FILE_CHANNEL: /* DVB channel/transponder old format */ - ret = write_format_oneline(args->output_file, - dvb_file, - SYS_UNDEFINED, - &channel_file_format); - break; - case FILE_ZAP: - ret = write_format_oneline(args->output_file, - dvb_file, - (uint32_t)args->delsys, - &channel_file_zap_format); - break; - case FILE_DVBV5: - ret = write_dvb_file(args->output_file, dvb_file); - default: - return -1; - } + ret = write_file_format(args->output_file, dvb_file, + args->delsys, args->output_format); return ret; } -- 2.7.4