Only in tvheadend: build.Linux Only in tvheadend: config.default diff -crB '--exclude=.git' '--exclude=epg.c' '--exclude=dvb_tables.c' '--exclude=cwc.c' tvheadend-vanilla/src/dvb/dvb.h tvheadend/src/dvb/dvb.h *** tvheadend-vanilla/src/dvb/dvb.h Mon Jan 9 18:03:24 2012 --- tvheadend/src/dvb/dvb.h Mon Jan 9 18:05:15 2012 *************** *** 204,209 **** --- 204,210 ---- int tda_unc_is_delta; /* 1 if we believe FE_READ_UNCORRECTED_BLOCKS * return dela values */ + int tda_opened; } th_dvb_adapter_t; diff -crB '--exclude=.git' '--exclude=epg.c' '--exclude=dvb_tables.c' '--exclude=cwc.c' tvheadend-vanilla/src/dvb/dvb_adapter.c tvheadend/src/dvb/dvb_adapter.c *** tvheadend-vanilla/src/dvb/dvb_adapter.c Mon Jan 9 18:03:35 2012 --- tvheadend/src/dvb/dvb_adapter.c Mon Jan 9 18:06:03 2012 *************** *** 63,68 **** --- 63,70 ---- tda->tda_allpids_dmx_fd = -1; tda->tda_dump_fd = -1; + tda->tda_opened = 0; + tda->tda_fe_fd = -1; return tda; } *************** *** 177,184 **** void dvb_adapter_set_dump_muxes(th_dvb_adapter_t *tda, int on) { ! if(tda->tda_dump_muxes == on) ! return; lock_assert(&global_lock); --- 179,185 ---- void dvb_adapter_set_dump_muxes(th_dvb_adapter_t *tda, int on) { ! if(tda->tda_dump_muxes == on) return; lock_assert(&global_lock); *************** *** 281,286 **** --- 282,288 ---- tda->tda_fe_fd = fe; + tda->tda_opened = 1; tda->tda_fe_info = malloc(sizeof(struct dvb_frontend_info)); *************** *** 420,436 **** return; } if(!tda->tda_idlescan && TAILQ_FIRST(&tda->tda_scan_queues[0]) == NULL) { /* Idlescan is disabled and no muxes are bad */ ! if(!tda->tda_qmon) ! return; // Quality monitoring is disabled ! ! /* If the currently tuned mux is ok, we can stick to it */ ! tdmi = tda->tda_mux_current; ! if(tdmi != NULL && tdmi->tdmi_quality > 90) return; } /* Alternate between the other two (bad and OK) */ --- 422,453 ---- return; } + if (tda->tda_opened == 0) + return; // Tuner is closed + if(!tda->tda_idlescan && TAILQ_FIRST(&tda->tda_scan_queues[0]) == NULL) { /* Idlescan is disabled and no muxes are bad */ ! if(tda->tda_qmon) // Check if quality monitoring is enabled ! { ! /* If the currently tuned mux is ok, we can stick to it */ ! tdmi = tda->tda_mux_current; ! if(tdmi != NULL && tdmi->tdmi_quality > 90) ! { ! //dvb_fe_stop(tdmi); ! tda->tda_fe_fd = tvh_close(tda->tda_fe_fd); // Close DVB file descriptor if tuner is in idle state ! tda->tda_opened = 0; ! return; ! } ! } ! else ! { ! //dvb_fe_stop(tdmi); ! tda->tda_fe_fd = tvh_close(tda->tda_fe_fd); // Close DVB file descriptor if tuner is in idle state ! tda->tda_opened = 0; return; + } } /* Alternate between the other two (bad and OK) */ diff -crB '--exclude=.git' '--exclude=epg.c' '--exclude=dvb_tables.c' '--exclude=cwc.c' tvheadend-vanilla/src/dvb/dvb_fe.c tvheadend/src/dvb/dvb_fe.c *** tvheadend-vanilla/src/dvb/dvb_fe.c Mon Jan 9 18:03:41 2012 --- tvheadend/src/dvb/dvb_fe.c Mon Jan 9 18:06:09 2012 *************** *** 422,442 **** char buf[256]; int r; ! lock_assert(&global_lock); ! if(tda->tda_mux_current == tdmi) ! return 0; if(tdmi->tdmi_scan_queue != NULL) { TAILQ_REMOVE(tdmi->tdmi_scan_queue, tdmi, tdmi_scan_link); tdmi->tdmi_scan_queue = NULL; } - - if(tda->tda_mux_current != NULL) - dvb_fe_stop(tda->tda_mux_current); - if(tda->tda_type == FE_QPSK) { --- 422,448 ---- char buf[256]; int r; ! char fname[256]; lock_assert(&global_lock); ! if(!tda->tda_opened) ! { ! snprintf(fname, sizeof(fname), "%s/frontend0", tda->tda_rootpath); ! tda->tda_fe_fd = tvh_open(fname, O_RDWR | O_NONBLOCK, 0); ! if (tda->tda_fe_fd != -1) ! tda->tda_opened = 1; ! else ! tda->tda_opened = 0; ! } ! ! if(tda->tda_mux_current != NULL) ! dvb_fe_stop(tda->tda_mux_current); if(tdmi->tdmi_scan_queue != NULL) { TAILQ_REMOVE(tdmi->tdmi_scan_queue, tdmi, tdmi_scan_link); tdmi->tdmi_scan_queue = NULL; } if(tda->tda_type == FE_QPSK) { diff -crB '--exclude=.git' '--exclude=epg.c' '--exclude=dvb_tables.c' '--exclude=cwc.c' tvheadend-vanilla/src/tvheadend.h tvheadend/src/tvheadend.h *** tvheadend-vanilla/src/tvheadend.h Mon Dec 19 19:27:32 2011 --- tvheadend/src/tvheadend.h Thu Dec 15 15:32:52 2011 *************** *** 412,417 **** --- 412,419 ---- int tvh_open(const char *pathname, int flags, mode_t mode); + int tvh_close(int fd); + int tvh_socket(int domain, int type, int protocol); void hexdump(const char *pfx, const uint8_t *data, int len); diff -crB '--exclude=.git' '--exclude=epg.c' '--exclude=dvb_tables.c' '--exclude=cwc.c' tvheadend-vanilla/src/wrappers.c tvheadend/src/wrappers.c *** tvheadend-vanilla/src/wrappers.c Mon Dec 19 19:27:32 2011 --- tvheadend/src/wrappers.c Mon Jan 9 18:08:25 2012 *************** *** 1,4 **** --- 1,5 ---- #include + #include #include /* See NOTES */ #include #include "tvheadend.h" *************** *** 16,21 **** --- 17,32 ---- return fd; } + int + tvh_close(int fd) + { + pthread_mutex_lock(&fork_lock); + fd = close(fd); + if (fd == 0) + fd = -1; + pthread_mutex_unlock(&fork_lock); + return fd; + } int tvh_socket(int domain, int type, int protocol)