int scan_Next( scan_t *p_scan, scan_configuration_t *p_cfg ) { double f_position; int i_ret; if( scan_IsCancelled( p_scan ) ) return VLC_EGENERIC; memset( p_cfg, 0, sizeof(*p_cfg) ); switch( p_scan->parameter.type ) { case SCAN_DVB_T: i_ret = ScanDvbTNext( p_scan, p_cfg, &f_position ); break; case SCAN_DVB_C: i_ret = ScanDvbCNext( p_scan, p_cfg, &f_position ); break; default: i_ret = VLC_EGENERIC; break; } if( i_ret ) return i_ret; char *psz_text; int i_service = 0; for( int i = 0; i < p_scan->i_service; i++ ) { if( p_scan->pp_service[i]->type != SERVICE_UNKNOWN ) i_service++; } if( asprintf( &psz_text, _("%.1f MHz (%d services)"), (double)p_cfg->i_frequency / 1000000, i_service ) >= 0 ) { const mtime_t i_eta = f_position > 0.005 ? (mdate() - p_scan->i_time_start) * ( 1.0 / f_position - 1.0 ) : -1; char psz_eta[MSTRTIME_MAX_SIZE]; if( i_eta >= 0 ) msg_Info( p_scan->p_obj, "Scan ETA %s | %f", secstotimestr( psz_eta, i_eta/1000000 ), f_position * 100 ); if( p_scan->p_dialog == NULL ) p_scan->p_dialog = dialog_ProgressCreate( p_scan->p_obj, _("Scanning DVB"), psz_text, _("Cancel") ); if( p_scan->p_dialog != NULL ) dialog_ProgressSet( p_scan->p_dialog, psz_text, f_position ); free( psz_text ); } p_scan->i_index++; return VLC_SUCCESS; }
static int ScanReadCallback( scan_t *p_scan, void *p_privdata, unsigned i_probe_timeout, size_t i_packets_max, uint8_t *p_packet, size_t *pi_count ) { access_t *p_access = (access_t *) p_privdata; access_sys_t *p_sys = p_access->p_sys; *pi_count = 0; /* Initialize file descriptor sets */ struct pollfd ufds[2]; ufds[0].fd = p_sys->dvb.i_handle; ufds[0].events = POLLIN; ufds[1].fd = p_sys->dvb.i_frontend_handle; ufds[1].events = POLLPRI; frontend_status_t status; FrontendGetStatus( &p_sys->dvb, &status ); bool b_has_lock = status.b_has_lock; mtime_t i_scan_start = mdate(); for( ; *pi_count == 0; ) { /* Find if some data is available */ int i_ret; mtime_t i_timeout = b_has_lock ? i_probe_timeout: DVB_SCAN_MAX_LOCK_TIME; do { mtime_t i_poll_timeout = i_scan_start - mdate() + i_timeout; i_ret = 0; if( vlc_killed() || scan_IsCancelled( p_scan ) ) break; if( i_poll_timeout >= 0 ) i_ret = vlc_poll_i11e( ufds, 2, i_poll_timeout / 1000 ); } while( i_ret < 0 && errno == EINTR ); if( i_ret < 0 ) { return VLC_EGENERIC; } else if( i_ret == 0 ) { return VLC_ENOITEM; } if( ufds[1].revents ) { FrontendPoll( VLC_OBJECT(p_access), &p_sys->dvb ); FrontendGetStatus( &p_sys->dvb, &status ); if( status.b_has_lock && !b_has_lock ) { i_scan_start = mdate(); b_has_lock = true; } } if ( ufds[0].revents ) { ssize_t i_read = read( p_sys->dvb.i_handle, p_packet, TS_PACKET_SIZE * i_packets_max ); if( i_read < 0 ) { msg_Warn( p_access, "read failed: %s", vlc_strerror_c(errno) ); break; } else { *pi_count = i_read / TS_PACKET_SIZE; } } } return VLC_SUCCESS; }