/* * ISO 13818 stream multiplexer / additional repeater tool * Copyright (C) 2001 Convergence Integrated Media GmbH Berlin * Copyright (C) 2005 Oskar Schirmer (schirmer@scara.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; either version 2 of the License, or * (at your option) any later version. * * 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ /* * Module: Repeater * Purpose: Additional tool to repeat and pipe an input stream. * * This tool accepts a (time1,time2,filename) tuple via stdin, * opens the filename, assuming it contains a ISO 13818 Transport Stream, * and sends it packet-wise to stdout timed in such a way, that * all pakets are sent equally distributed within time2 msec. * As long as no further tuple is provided, after time1 msec the same * file is sent over and over again. */ #include #include "global.h" #define D(x) /* x */ #define MAX_ANOTATE (16 * 256) static boolean quit; static int cmdf, outf, nextf; static int combln, comlln; static byte combuf[MAX_DATA_COMB]; static int pollc; static int dati, dato; static byte data[MAX_ANOTATE]; static t_msec nextrdelay, nextfdelay; static off_t nextpackets; t_msec msec_now (void) { #define MSEC_EXPONENT 21 static long last; static int local_delta; struct timeval tv; gettimeofday (&tv,NULL); if ((tv.tv_sec & (~((1L << MSEC_EXPONENT) - 1))) != last) { last = tv.tv_sec & (~((1L << MSEC_EXPONENT) - 1)); local_delta += 1000 * (1L << MSEC_EXPONENT); } return ((tv.tv_sec & ((1L << MSEC_EXPONENT) - 1)) * 1000 + tv.tv_usec / 1000 + local_delta); } static void command_help (char *command, char *errmsg) { fprintf (stderr, "%s\nUsage:\t%s [OPTIONS...] []\n" " -d \ttime in msec after which the sending shall be repeated\n" " -t