From: Mauro Carvalho Chehab Date: Wed, 4 Jan 2012 16:09:56 +0000 (-0200) Subject: utils/dvb: Add a file converter X-Git-Tag: v4l-utils-0.9.0-test1~116 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=94f7226a8d57e8af36e2f5efc505b16d3bac91c4;p=platform%2Fupstream%2Fv4l-utils.git utils/dvb: Add a file converter Signed-off-by: Mauro Carvalho Chehab --- diff --git a/utils/dvb/Makefile b/utils/dvb/Makefile index ff193dc..7224ca7 100644 --- a/utils/dvb/Makefile +++ b/utils/dvb/Makefile @@ -1,4 +1,4 @@ -TARGETS = dvb-fe-tool dvbv5-zap dvbv5-scan +TARGETS = dvb-fe-tool dvbv5-zap dvbv5-scan dvb-format-convert all: $(TARGETS) @@ -12,6 +12,11 @@ dvbv5-scan: dvbv5-scan.o dvb-fe.o dvb-demux.o dvb-file.o \ dvb-zap-format.o dvb-legacy-channel-format.o \ parse_string.o descriptors.o libscan.o +dvb-format-convert: dvb-format-convert.o dvb-file.o \ + dvb-zap-format.o dvb-legacy-channel-format.o \ + dvb-fe.o + + $(CC) $(LDFLAGS) -o $@ $^ dvb-v5.h: diff --git a/utils/dvb/dvb-format-convert.c b/utils/dvb/dvb-format-convert.c new file mode 100644 index 0000000..94a442c --- /dev/null +++ b/utils/dvb/dvb-format-convert.c @@ -0,0 +1,130 @@ +/* + * Copyright (c) 2011 - Mauro Carvalho Chehab + * + * 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 +#include +#include +#include +#include +#include +#include +#include +#include + +#include "dvb-file.h" +#include "dvb-demux.h" +#include "libscan.h" + +static int convert_file(const char *fname, const char *delsys, + int format, const char *fout) +{ + struct dvb_file *dvb_file = NULL; + uint32_t sys; + + printf("Reading file %s\n", fname); + switch (format) { + case 1: /* DVB channel/transponder old format */ + dvb_file = parse_format_oneline(fname, " \n", SYS_UNDEFINED, + channel_formats); + break; + case 2: /* DVB old zap format */ + if (!delsys) { + fprintf(stderr, "Delivery system need to be specified, for zap format\n"); + return -1; + } + if (!strcasecmp(delsys, "DVB-T")) + sys = SYS_DVBT; + else if (!strcasecmp(delsys, "DVB-C")) + sys = SYS_DVBC_ANNEX_A; + else if (!strcasecmp(delsys, "DVB-S")) + sys = SYS_DVBS; + else if (!strcasecmp(delsys, "ATSC")) + sys = SYS_ATSC; + else { + fprintf(stderr, "Delivery system unknown\n"); + return -1; + } + dvb_file = parse_format_oneline(fname, ":", sys, zap_formats); + break; + } + if (!dvb_file) + return -2; + + printf("Writing file %s\n", fout); + write_dvb_file(fout, dvb_file); + + dvb_file_free(dvb_file); + return 0; +} + +static char *usage = + "usage:\n" + " dvb-format-convert [options] \n" + " scan DVB services using the channel file\n" + " -v : be (very) verbose\n" + " -o file : output filename (use -o - for stdout)\n" + " -O : uses old channel format\n" + " -z : uses zap services file, discarding video/audio pid's\n" + " -s : delivery system (DVB-T, DVB-C, DVB-S or ATSC) for zap format\n" + " -h -? : display this help and exit\n\n" + "-O or -z parameters are mandatory\n"; + +int main(int argc, char **argv) +{ + char *confname = NULL, *outfile = NULL, *delsys; + int adapter = 0; + int opt, format = 0; + + while ((opt = getopt(argc, argv, "H?hzOs:")) != -1) { + switch (opt) { + case 'O': + format = 1; + break; + case 'z': + format = 2; + break; + case 's': + delsys = optarg; + break; + case '?': + case 'h': + default: + fprintf(stderr, usage, argv[0]); + return -1; + }; + } + + if (!format) { + fprintf(stderr, usage, argv[0]); + return -1; + } + + if (optind < argc + 1) { + confname = argv[optind]; + outfile = argv[optind + 1]; + } + + if (!confname) { + fprintf(stderr, usage, argv[0]); + return -1; + } + + return convert_file(confname, delsys, format, outfile); +}