mptsd reads mpegts streams from udp/multicast or http and combines them into one multiple program stream that is suitable for outputting to DVB-C modulator. Tested with Dektec DTE-3114 Quad QAM Modulator and used in production in small DVB-C networks. https://georgi.unixsol.org/programs/mptsd/

sleep.c 1.7KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. /*
  2. * mptsd sleep calibration
  3. * Copyright (C) 2010-2011 Unix Solutions Ltd.
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License version 2
  7. * as published by the Free Software Foundation.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program; if not, write to the Free Software
  16. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
  17. */
  18. #include <unistd.h>
  19. #include <string.h>
  20. #include <signal.h>
  21. #include <sys/time.h>
  22. #include <errno.h>
  23. #include <math.h>
  24. #include "libfuncs/log.h"
  25. #include "config.h"
  26. void * calibrate_sleep(void *_config) {
  27. struct timeval tv1, tv2;
  28. unsigned long diff = 0, loops = 0;
  29. CONFIG *conf = _config;
  30. if (!conf->quiet) {
  31. LOGf("\tCalibrating sleep timeout...\n");
  32. LOGf("\tRequest timeout : %ld us\n", conf->output_tmout);
  33. }
  34. do {
  35. gettimeofday(&tv1, NULL);
  36. usleep(1);
  37. gettimeofday(&tv2, NULL);
  38. diff += timeval_diff_usec(&tv1, &tv2) - 1;
  39. } while (loops++ != 3000);
  40. conf->usleep_overhead = diff / loops;
  41. conf->output_tmout -= conf->usleep_overhead;
  42. if (!conf->quiet) {
  43. LOGf("\tusleep(1) overhead: %ld us\n", conf->usleep_overhead);
  44. LOGf("\tOutput pkt tmout : %ld us\n", conf->output_tmout);
  45. }
  46. if (conf->output_tmout < 0) {
  47. LOGf("usleep overhead is too high! Make sure the kernel is compiled with CONFIG_HIGH_RES_TIMERS.\n");
  48. conf->output_tmout = 0;
  49. }
  50. pthread_exit(0);
  51. }