static int parse(struct arguments *args, struct dvb_v5_fe_parms *parms, char *channel, int *vpid, int *apid, int *sid) { struct dvb_file *dvb_file; struct dvb_entry *entry; int i; uint32_t sys; /* This is used only when reading old formats */ switch (parms->current_sys) { case SYS_DVBT: case SYS_DVBS: case SYS_DVBC_ANNEX_A: case SYS_ATSC: sys = parms->current_sys; break; case SYS_DVBC_ANNEX_C: sys = SYS_DVBC_ANNEX_A; break; case SYS_DVBC_ANNEX_B: sys = SYS_ATSC; break; case SYS_ISDBT: sys = SYS_DVBT; break; default: sys = SYS_UNDEFINED; break; } dvb_file = read_file_format(args->confname, sys, args->input_format); if (!dvb_file) return -2; for (entry = dvb_file->first_entry; entry != NULL; entry = entry->next) { if (!strcmp(entry->channel, channel)) break; if (entry->vchannel && !strcmp(entry->vchannel, channel)) break; } /* * Give a second shot, using a case insensitive seek */ if (!entry) { for (entry = dvb_file->first_entry; entry != NULL; entry = entry->next) { if (!strcasecmp(entry->channel, channel)) break; } } if (!entry) { ERROR("Can't find channel"); return -3; } if (entry->video_pid) { if (args->n_vpid < entry->video_pid_len) *vpid = entry->video_pid[args->n_vpid]; else *vpid = entry->video_pid[0]; } if (entry->audio_pid) { if (args->n_apid < entry->audio_pid_len) *apid = entry->audio_pid[args->n_apid]; else *apid = entry->audio_pid[0]; } if (entry->other_el_pid) { int i, type = -1; for (i = 0; i < entry->other_el_pid_len; i++) { if (type != entry->other_el_pid[i].type) { type = entry->other_el_pid[i].type; if (i) printf("\n"); printf("service has pid type %02x: ", type); } printf(" %d", entry->other_el_pid[i].pid); } printf("\n"); } *sid = entry->service_id; /* First of all, set the delivery system */ for (i = 0; i < entry->n_props; i++) if (entry->props[i].cmd == DTV_DELIVERY_SYSTEM) dvb_set_compat_delivery_system(parms, entry->props[i].u.data); /* Copy data into parms */ for (i = 0; i < entry->n_props; i++) { uint32_t data = entry->props[i].u.data; /* Don't change the delivery system */ if (entry->props[i].cmd == DTV_DELIVERY_SYSTEM) continue; dvb_fe_store_parm(parms, entry->props[i].cmd, data); if (parms->current_sys == SYS_ISDBT) { dvb_fe_store_parm(parms, DTV_ISDBT_PARTIAL_RECEPTION, 0); dvb_fe_store_parm(parms, DTV_ISDBT_SOUND_BROADCASTING, 0); dvb_fe_store_parm(parms, DTV_ISDBT_LAYER_ENABLED, 0x07); if (entry->props[i].cmd == DTV_CODE_RATE_HP) { dvb_fe_store_parm(parms, DTV_ISDBT_LAYERA_FEC, data); dvb_fe_store_parm(parms, DTV_ISDBT_LAYERB_FEC, data); dvb_fe_store_parm(parms, DTV_ISDBT_LAYERC_FEC, data); } else if (entry->props[i].cmd == DTV_MODULATION) { dvb_fe_store_parm(parms, DTV_ISDBT_LAYERA_MODULATION, data); dvb_fe_store_parm(parms, DTV_ISDBT_LAYERB_MODULATION, data); dvb_fe_store_parm(parms, DTV_ISDBT_LAYERC_MODULATION, data); } } if (parms->current_sys == SYS_ATSC && entry->props[i].cmd == DTV_MODULATION) { if (data != VSB_8 && data != VSB_16) dvb_fe_store_parm(parms, DTV_DELIVERY_SYSTEM, SYS_DVBC_ANNEX_B); } } #if 0 /* HACK to test the write file function */ write_dvb_file("dvb_channels.conf", dvb_file); #endif dvb_file_free(dvb_file); return 0; }
bool Frontend::Tune( Transponder &t ) { if( !IsPresent( )) { LogWarn( "device not present '%s'", name.c_str( )); return false; } Lock( ); if( transponder ) { if( transponder == &t ) { usecount++; Unlock( ); return true; } Log( "Frontend busy" ); Unlock( ); return false; } if( !Open( )) { Unlock( ); return false; } state = State_Tuning; transponder = &t; usecount++; Unlock( ); t.SetState( Transponder::State_Tuning ); Log( "Tuning %s", t.toString( ).c_str( )); uint8_t signal, noise; LogWarn( "dvb_set_compat_delivery_system %d", t.GetDelSys( )); int r = dvb_set_compat_delivery_system( fe, t.GetDelSys( )); if( r != 0 ) { LogError( "dvb_set_compat_delivery_system return %d", r ); goto fail; } SetTuneParams( t ); t.GetParams( fe ); LogWarn( "dvb_estimate_freq_shift"); dvb_estimate_freq_shift( fe ); r = dvb_fe_set_parms( fe ); if( r != 0 ) { LogError( "dvb_fe_set_parms failed with %d.", r ); dvb_fe_prt_parms( fe ); goto fail; } dvb_fe_prt_parms( fe ); /* As the DVB core emulates it, better to always use auto */ dvb_fe_store_parm(fe, DTV_INVERSION, INVERSION_AUTO); uint32_t freq; dvb_fe_retrieve_parm(fe, DTV_FREQUENCY, &freq); dvb_fe_prt_parms(fe); if( !GetLockStatus( signal, noise, tune_timeout )) { LogError( "Tuning failed" ); goto fail; } t.SetState( Transponder::State_Tuned ); t.SetSignal( signal, noise ); return true; fail: t.SetState( Transponder::State_TuningFailed ); t.SaveConfig( ); Release( ); return false; }
static int run_scan(struct arguments *args, struct dvb_v5_fe_parms *parms) { struct dvb_file *dvb_file = NULL, *dvb_file_new = NULL; struct dvb_entry *entry; int i, rc, count = 0, dmx_fd, shift; uint32_t freq, sys; /* This is used only when reading old formats */ switch (parms->current_sys) { case SYS_DVBT: case SYS_DVBS: case SYS_DVBC_ANNEX_A: case SYS_ATSC: sys = parms->current_sys; break; case SYS_DVBC_ANNEX_C: sys = SYS_DVBC_ANNEX_A; break; case SYS_DVBC_ANNEX_B: sys = SYS_ATSC; break; case SYS_ISDBT: sys = SYS_DVBT; break; default: sys = SYS_UNDEFINED; break; } dvb_file = dvb_read_file_format(args->confname, sys, args->input_format); if (!dvb_file) return -2; dmx_fd = open(args->demux_dev, O_RDWR); if (dmx_fd < 0) { perror("openening pat demux failed"); return -3; } for (entry = dvb_file->first_entry; entry != NULL; entry = entry->next) { struct dvb_v5_descriptors *dvb_desc = NULL; /* First of all, set the delivery system */ for (i = 0; i < entry->n_props; i++) if (entry->props[i].cmd == DTV_DELIVERY_SYSTEM) dvb_set_compat_delivery_system(parms, entry->props[i].u.data); /* Copy data into parms */ for (i = 0; i < entry->n_props; i++) { uint32_t data = entry->props[i].u.data; /* Don't change the delivery system */ if (entry->props[i].cmd == DTV_DELIVERY_SYSTEM) continue; dvb_fe_store_parm(parms, entry->props[i].cmd, data); if (parms->current_sys == SYS_ISDBT) { dvb_fe_store_parm(parms, DTV_ISDBT_PARTIAL_RECEPTION, 0); dvb_fe_store_parm(parms, DTV_ISDBT_SOUND_BROADCASTING, 0); dvb_fe_store_parm(parms, DTV_ISDBT_LAYER_ENABLED, 0x07); if (entry->props[i].cmd == DTV_CODE_RATE_HP) { dvb_fe_store_parm(parms, DTV_ISDBT_LAYERA_FEC, data); dvb_fe_store_parm(parms, DTV_ISDBT_LAYERB_FEC, data); dvb_fe_store_parm(parms, DTV_ISDBT_LAYERC_FEC, data); } else if (entry->props[i].cmd == DTV_MODULATION) { dvb_fe_store_parm(parms, DTV_ISDBT_LAYERA_MODULATION, data); dvb_fe_store_parm(parms, DTV_ISDBT_LAYERB_MODULATION, data); dvb_fe_store_parm(parms, DTV_ISDBT_LAYERC_MODULATION, data); } } if (parms->current_sys == SYS_ATSC && entry->props[i].cmd == DTV_MODULATION) { if (data != VSB_8 && data != VSB_16) dvb_fe_store_parm(parms, DTV_DELIVERY_SYSTEM, SYS_DVBC_ANNEX_B); } } /* * If the channel file has duplicated frequencies, or some * entries without any frequency at all, discard. */ freq = 0; for (i = 0; i < entry->n_props; i++) { if (entry->props[i].cmd == DTV_FREQUENCY) { freq = entry->props[i].u.data; break; } } if (!freq) continue; shift = estimate_freq_shift(parms); if (dvb_desc && !new_freq_is_needed(dvb_file->first_entry, entry, freq, dvb_desc->nit_table.pol, shift)) continue; rc = dvb_fe_set_parms(parms); if (rc < 0) { PERROR("dvb_fe_set_parms failed"); return -1; } /* As the DVB core emulates it, better to always use auto */ dvb_fe_store_parm(parms, DTV_INVERSION, INVERSION_AUTO); dvb_fe_retrieve_parm(parms, DTV_FREQUENCY, &freq); count++; dvb_log("Scanning frequency #%d %d", count, freq); if (verbose) dvb_fe_prt_parms(parms); rc = check_frontend(args, parms); if (rc < 0) continue; dvb_desc = dvb_get_ts_tables(parms, dmx_fd, parms->current_sys, args->other_nit, args->timeout_multiply, verbose); if (!dvb_desc) continue; for (i = 0; i < dvb_desc->sdt_table.service_table_len; i++) { struct service_table *service_table = &dvb_desc->sdt_table.service_table[i]; entry->vchannel = dvb_vchannel(dvb_desc, i); printf("Service #%d (%d)", i, service_table->service_id); if (service_table->service_name) printf(" %s", service_table->service_name); if (entry->vchannel) printf(" channel %s", entry->vchannel); printf("\n"); } store_dvb_channel(&dvb_file_new, parms, dvb_desc, args->get_detected, args->get_nit); if (!args->dont_add_new_freqs) add_other_freq_entries(dvb_file, parms, dvb_desc); dvb_free_ts_tables(dvb_desc); } if (dvb_file_new) write_file_format(args->output, dvb_file_new, parms->current_sys, args->output_format); dvb_file_free(dvb_file); if (dvb_file_new) dvb_file_free(dvb_file_new); close(dmx_fd); return 0; }
static int parse(struct arguments *args, struct dvb_v5_fe_parms *parms, char *channel, int *vpid, int *apid, int *sid) { struct dvb_file *dvb_file; struct dvb_entry *entry; int i; uint32_t sys; /* This is used only when reading old formats */ switch (parms->current_sys) { case SYS_DVBT: case SYS_DVBS: case SYS_DVBC_ANNEX_A: case SYS_ATSC: sys = parms->current_sys; break; case SYS_DVBC_ANNEX_C: sys = SYS_DVBC_ANNEX_A; break; case SYS_DVBC_ANNEX_B: sys = SYS_ATSC; break; case SYS_ISDBT: case SYS_DTMB: sys = SYS_DVBT; break; default: sys = SYS_UNDEFINED; break; } dvb_file = dvb_read_file_format(args->confname, sys, args->input_format); if (!dvb_file) return -2; for (entry = dvb_file->first_entry; entry != NULL; entry = entry->next) { if (entry->channel && !strcmp(entry->channel, channel)) break; if (entry->vchannel && !strcmp(entry->vchannel, channel)) break; } /* * Give a second shot, using a case insensitive seek */ if (!entry) { for (entry = dvb_file->first_entry; entry != NULL; entry = entry->next) { if (entry->channel && !strcasecmp(entry->channel, channel)) break; } } /* * When this tool is used to just tune to a channel, to monitor it or * to capture all PIDs, all it needs is a frequency. * So, let the tool to accept a frequency as the tuning channel on those * cases. * This way, a file in "channel" format can be used instead of a zap file. * It is also easier to use it for testing purposes. */ if (!entry && (args->traffic_monitor || args->all_pids || args->exit_after_tuning)) { uint32_t f, freq = atoi(channel); if (freq) { for (entry = dvb_file->first_entry; entry != NULL; entry = entry->next) { dvb_retrieve_entry_prop(entry, DTV_FREQUENCY, &f); if (f == freq) break; } } } if (!entry) { ERROR(_("Can't find channel")); dvb_file_free(dvb_file); return -3; } /* * Both the DVBv5 format and the command line parameters may * specify the LNBf. If both have the definition, use the one * provided by the command line parameter, overriding the one * stored in the channel file. */ if (entry->lnb && !parms->lnb) { int lnb = dvb_sat_search_lnb(entry->lnb); if (lnb == -1) { PERROR(_("unknown LNB %s\n"), entry->lnb); dvb_file_free(dvb_file); return -1; } parms->lnb = dvb_sat_get_lnb(lnb); } if (entry->video_pid) { if (args->n_vpid < entry->video_pid_len) *vpid = entry->video_pid[args->n_vpid]; else *vpid = entry->video_pid[0]; } if (entry->audio_pid) { if (args->n_apid < entry->audio_pid_len) *apid = entry->audio_pid[args->n_apid]; else *apid = entry->audio_pid[0]; } if (entry->other_el_pid) { int i, type = -1; for (i = 0; i < entry->other_el_pid_len; i++) { if (type != entry->other_el_pid[i].type) { type = entry->other_el_pid[i].type; if (i) fprintf(stderr, "\n"); fprintf(stderr, _("service has pid type %02x: "), type); } fprintf(stderr, " %d", entry->other_el_pid[i].pid); } fprintf(stderr, "\n"); } *sid = entry->service_id; /* First of all, set the delivery system */ dvb_retrieve_entry_prop(entry, DTV_DELIVERY_SYSTEM, &sys); dvb_set_compat_delivery_system(parms, sys); /* Copy data into parms */ for (i = 0; i < entry->n_props; i++) { uint32_t data = entry->props[i].u.data; /* Don't change the delivery system */ if (entry->props[i].cmd == DTV_DELIVERY_SYSTEM) continue; dvb_fe_store_parm(parms, entry->props[i].cmd, data); if (parms->current_sys == SYS_ISDBT) { dvb_fe_store_parm(parms, DTV_ISDBT_PARTIAL_RECEPTION, 0); dvb_fe_store_parm(parms, DTV_ISDBT_SOUND_BROADCASTING, 0); dvb_fe_store_parm(parms, DTV_ISDBT_LAYER_ENABLED, 0x07); if (entry->props[i].cmd == DTV_CODE_RATE_HP) { dvb_fe_store_parm(parms, DTV_ISDBT_LAYERA_FEC, data); dvb_fe_store_parm(parms, DTV_ISDBT_LAYERB_FEC, data); dvb_fe_store_parm(parms, DTV_ISDBT_LAYERC_FEC, data); } else if (entry->props[i].cmd == DTV_MODULATION) { dvb_fe_store_parm(parms, DTV_ISDBT_LAYERA_MODULATION, data); dvb_fe_store_parm(parms, DTV_ISDBT_LAYERB_MODULATION, data); dvb_fe_store_parm(parms, DTV_ISDBT_LAYERC_MODULATION, data); } } if (parms->current_sys == SYS_ATSC && entry->props[i].cmd == DTV_MODULATION) { if (data != VSB_8 && data != VSB_16) dvb_fe_store_parm(parms, DTV_DELIVERY_SYSTEM, SYS_DVBC_ANNEX_B); } } dvb_file_free(dvb_file); return 0; }