static int ScanFrontendTuningHandler( scan_t *p_scan, void *p_privdata, const scan_tuner_config_t *p_cfg ) { access_t *p_access = (access_t *) p_privdata; access_sys_t *sys = p_access->p_sys; VLC_UNUSED(p_scan); var_SetInteger( p_access, "dvb-frequency", p_cfg->i_frequency ); var_SetInteger( p_access, "dvb-bandwidth", p_cfg->i_bandwidth ); if ( p_cfg->polarization != SCAN_POLARIZATION_NONE ) var_SetInteger( p_access, "dvb-voltage", p_cfg->polarization == SCAN_POLARIZATION_HORIZONTAL ? 18 : 13 ); if ( p_cfg->i_symbolrate ) var_SetInteger( p_access, "dvb-srate", p_cfg->i_symbolrate ); msg_Dbg( p_access, "Scanning frequency %d", p_cfg->i_frequency ); msg_Dbg( p_access, " bandwidth %d", p_cfg->i_bandwidth ); /* Setting frontend parameters for tuning the hardware */ if( FrontendSet( VLC_OBJECT(p_access), &sys->dvb ) < 0 ) { msg_Err( p_access, "Failed to tune the frontend" ); return VLC_EGENERIC; } return VLC_SUCCESS; }
/***************************************************************************** * dvb_Open *****************************************************************************/ void dvb_Open( void ) { char psz_tmp[128]; msg_Dbg( NULL, "compiled with DVB API version %d.%d", DVB_API_VERSION, DVB_API_VERSION_MINOR ); if ( i_frequency ) { sprintf( psz_tmp, "/dev/dvb/adapter%d/frontend%d", i_adapter, i_fenum ); if( (i_frontend = open(psz_tmp, O_RDWR | O_NONBLOCK)) < 0 ) { msg_Err( NULL, "opening device %s failed (%s)", psz_tmp, strerror(errno) ); exit(1); } FrontendSet(true); } else { i_frontend = -1; } sprintf( psz_tmp, "/dev/dvb/adapter%d/dvr%d", i_adapter, i_fenum ); if( (i_dvr = open(psz_tmp, O_RDONLY | O_NONBLOCK)) < 0 ) { msg_Err( NULL, "opening device %s failed (%s)", psz_tmp, strerror(errno) ); exit(1); } if ( ioctl( i_dvr, DMX_SET_BUFFER_SIZE, i_dvr_buffer_size ) < 0 ) { msg_Warn( NULL, "couldn't set %s buffer size (%s)", psz_tmp, strerror(errno) ); } ev_io_init(&dvr_watcher, DVRRead, i_dvr, EV_READ); ev_io_start(event_loop, &dvr_watcher); if ( i_frontend != -1 ) { ev_io_init(&frontend_watcher, FrontendRead, i_frontend, EV_READ); ev_io_start(event_loop, &frontend_watcher); } ev_timer_init(&lock_watcher, FrontendLockCb, i_frontend_timeout_duration / 1000000., i_frontend_timeout_duration / 1000000.); ev_timer_init(&mute_watcher, DVRMuteCb, DVR_READ_TIMEOUT / 1000000., DVR_READ_TIMEOUT / 1000000.); en50221_Init(); }
static void DVRMuteCb(struct ev_loop *loop, struct ev_timer *w, int revents) { msg_Warn( NULL, "no DVR output, resetting" ); ev_timer_stop(loop, w); switch (i_print_type) { case PRINT_XML: fprintf(print_fh, "<EVENT type=\"reset\" cause=\"dvr\" />\n"); break; case PRINT_TEXT: fprintf(print_fh, "reset cause: dvr\n"); break; default: break; } if ( i_frequency ) FrontendSet(false); en50221_Reset(); }
/***************************************************************************** * dvb_Open *****************************************************************************/ void dvb_Open( void ) { char psz_tmp[128]; msg_Dbg( NULL, "using linux-dvb API version %d.%d", DVB_API_VERSION, DVB_API_VERSION_MINOR ); i_wallclock = mdate(); sprintf( psz_tmp, "/dev/dvb/adapter%d/frontend%d", i_adapter, i_fenum ); if( (i_frontend = open(psz_tmp, O_RDWR | O_NONBLOCK)) < 0 ) { msg_Err( NULL, "opening device %s failed (%s)", psz_tmp, strerror(errno) ); exit(1); } FrontendSet(true); sprintf( psz_tmp, "/dev/dvb/adapter%d/dvr%d", i_adapter, i_fenum ); if( (i_dvr = open(psz_tmp, O_RDONLY | O_NONBLOCK)) < 0 ) { msg_Err( NULL, "opening device %s failed (%s)", psz_tmp, strerror(errno) ); exit(1); } if ( ioctl( i_dvr, DMX_SET_BUFFER_SIZE, DVR_BUFFER_SIZE ) < 0 ) { msg_Warn( NULL, "couldn't set %s buffer size (%s)", psz_tmp, strerror(errno) ); } en50221_Init(); i_ca_next_event = mdate() + CA_POLL_PERIOD; }
/***************************************************************************** * dvb_Reset *****************************************************************************/ void dvb_Reset( void ) { if ( i_frequency ) FrontendSet(true); }
/***************************************************************************** * dvb_Read *****************************************************************************/ block_t *dvb_Read( mtime_t i_poll_timeout ) { struct pollfd ufds[4]; int i_ret, i_nb_fd = 2; block_t *p_blocks = NULL; memset( ufds, 0, sizeof(ufds) ); ufds[0].fd = i_dvr; ufds[0].events = POLLIN; ufds[1].fd = i_frontend; ufds[1].events = POLLERR | POLLPRI; if ( i_comm_fd != -1 ) { ufds[i_nb_fd].fd = i_comm_fd; ufds[i_nb_fd].events = POLLIN; i_nb_fd++; } if ( i_ca_handle && i_ca_type == CA_CI_LINK ) { ufds[i_nb_fd].fd = i_ca_handle; ufds[i_nb_fd].events = POLLIN; i_nb_fd++; } i_ret = poll( ufds, i_nb_fd, (i_poll_timeout + 999) / 1000 ); i_wallclock = mdate(); if ( i_ret < 0 ) { if( errno != EINTR ) msg_Err( NULL, "poll error: %s", strerror(errno) ); return NULL; } if ( ufds[1].revents ) FrontendPoll(); if ( ufds[0].revents ) { p_blocks = DVRRead(); i_wallclock = mdate(); } if ( p_blocks != NULL ) i_last_packet = i_wallclock; else if ( !i_frontend_timeout && i_wallclock > i_last_packet + DVR_READ_TIMEOUT ) { msg_Warn( NULL, "no DVR output, resetting" ); FrontendSet(false); en50221_Reset(); } if ( i_ca_handle && i_ca_type == CA_CI_LINK ) { if ( ufds[i_nb_fd - 1].revents ) { en50221_Read(); i_ca_next_event = i_wallclock + CA_POLL_PERIOD; } else if ( i_wallclock > i_ca_next_event ) { en50221_Poll(); i_ca_next_event = i_wallclock + CA_POLL_PERIOD; } } if ( i_frontend_timeout && i_wallclock > i_frontend_timeout ) { if ( i_quit_timeout_duration ) { msg_Err( NULL, "no lock" ); switch (i_print_type) { case PRINT_XML: printf("</TS>\n"); break; default: break; } exit(EXIT_STATUS_FRONTEND_TIMEOUT); } msg_Warn( NULL, "no lock, tuning again" ); FrontendSet(false); } if ( i_comm_fd != -1 && ufds[2].revents ) comm_Read(); return p_blocks; }
/***************************************************************************** * dvb_Reset *****************************************************************************/ void dvb_Reset( void ) { FrontendSet(true); }