static void process_tdt(int tdt_fd) { int size; uint8_t sibuf[4096]; // read the section if ((size = read(tdt_fd, sibuf, sizeof(sibuf))) < 0) { return; } // parse section struct section *section = section_codec(sibuf, size); if (section == NULL) { return; } // parse TDT struct dvb_tdt_section *tdt = dvb_tdt_section_codec(section); if (tdt == NULL) { return; } // done gnutv_ca_new_dvbtime(dvbdate_to_unixtime(tdt->utc_time)); }
static void process_pat(int pat_fd, struct gnutv_dvb_params *params, int *pmt_fd, struct pollfd *pollfd) { int size; uint8_t sibuf[4096]; // read the section if ((size = read(pat_fd, sibuf, sizeof(sibuf))) < 0) { return; } // parse section struct section *section = section_codec(sibuf, size); if (section == NULL) { return; } // parse section_ext struct section_ext *section_ext = section_ext_decode(section, 0); if (section_ext == NULL) { return; } if (pat_version == section_ext->version_number) { return; } // parse PAT struct mpeg_pat_section *pat = mpeg_pat_section_codec(section_ext); if (pat == NULL) { return; } // try and find the requested program struct mpeg_pat_program *cur_program; mpeg_pat_section_programs_for_each(pat, cur_program) { if (cur_program->program_number == params->channel.service_id) { // close old PMT fd if (*pmt_fd != -1) close(*pmt_fd); // create PMT filter if ((*pmt_fd = create_section_filter(params->adapter_id, params->demux_id, cur_program->pid, stag_mpeg_program_map)) < 0) { return; } pollfd->fd = *pmt_fd; pollfd->events = POLLIN|POLLPRI|POLLERR; gnutv_data_new_pat(cur_program->pid); // we have a new PMT pid data_pmt_version = -1; ca_pmt_version = -1; break; } } // remember the PAT version pat_version = section_ext->version_number; }
/* * Get the next UTC date packet from the TDT section */ int dvb_scan_date(time_t *rx_time, unsigned int to) { int tdt_fd; uint8_t filter[18]; uint8_t mask[18]; unsigned char sibuf[4096]; int size; // open the demuxer if ((tdt_fd = dvbdemux_open_demux(adapter, 0, 0)) < 0) { return -1; } // create a section filter for the TDT memset(filter, 0, sizeof(filter)); memset(mask, 0, sizeof(mask)); filter[0] = stag_dvb_time_date; mask[0] = 0xFF; if (dvbdemux_set_section_filter(tdt_fd, TRANSPORT_TDT_PID, filter, mask, 1, 1)) { close(tdt_fd); return -1; } // poll for data struct pollfd pollfd; pollfd.fd = tdt_fd; pollfd.events = POLLIN|POLLERR|POLLPRI; if (poll(&pollfd, 1, to * 1000) != 1) { close(tdt_fd); return -1; } // read it if ((size = read(tdt_fd, sibuf, sizeof(sibuf))) < 0) { close(tdt_fd); return -1; } // parse section struct section *section = section_codec(sibuf, size); if (section == NULL) { close(tdt_fd); return -1; } // parse TDT struct dvb_tdt_section *tdt = dvb_tdt_section_codec(section); if (tdt == NULL) { close(tdt_fd); return -1; } // done *rx_time = dvbdate_to_unixtime(tdt->utc_time); close(tdt_fd); return 0; }
void parse_events(uint8_t *buf, int len, list<event_data> &events) { struct section *section; struct section_ext *section_ext = NULL; if ((section = section_codec(buf, len)) == NULL) { return; } switch(section->table_id) { case stag_dvb_event_information_nownext_actual: case stag_dvb_event_information_nownext_other: case 0x50: case 0x51: case 0x52: case 0x53: case 0x54: case 0x55: case 0x56: case 0x57: case 0x58: case 0x59: case 0x5a: case 0x5b: case 0x5c: case 0x5d: case 0x5e: case 0x5f: case 0x60: case 0x61: case 0x62: case 0x63: case 0x64: case 0x65: case 0x66: case 0x67: case 0x68: case 0x69: case 0x6a: case 0x6b: case 0x6c: case 0x6d: case 0x6e: case 0x6f: { struct dvb_eit_section *eit; struct dvb_eit_event *cur_event; struct descriptor *curd; time_t start_time; if ((section_ext = section_ext_decode(section, 1)) == NULL) { return; } if ((eit = dvb_eit_section_codec(section_ext)) == NULL) { return; } dvb_eit_section_events_for_each(eit, cur_event) { event_data E = event_data(); start_time = dvbdate_to_unixtime(cur_event->start_time); E.set_service_id(dvb_eit_section_service_id(eit)); E.set_event_id(cur_event->event_id); E.set_duration(dvbduration_to_seconds(cur_event->duration)); E.set_running_status(cur_event->running_status); E.set_start_time((int) start_time); dvb_eit_event_descriptors_for_each(cur_event, curd) { parse_event_descriptor(curd, E); } AddIntoEventList(events, E); } break; }
static void process_pmt(int pmt_fd, struct gnutv_dvb_params *params) { int size; uint8_t sibuf[4096]; // read the section if ((size = read(pmt_fd, sibuf, sizeof(sibuf))) < 0) { return; } // parse section struct section *section = section_codec(sibuf, size); if (section == NULL) { return; } // parse section_ext struct section_ext *section_ext = section_ext_decode(section, 0); if (section_ext == NULL) { return; } if ((section_ext->table_id_ext != params->channel.service_id) || ((section_ext->version_number == data_pmt_version) && (section_ext->version_number == ca_pmt_version))) { return; } // parse PMT struct mpeg_pmt_section *pmt = mpeg_pmt_section_codec(section_ext); if (pmt == NULL) { return; } // do data handling if (section_ext->version_number != data_pmt_version) { if (gnutv_data_new_pmt(pmt) == 1) data_pmt_version = pmt->head.version_number; } // do ca handling if (section_ext->version_number != ca_pmt_version) { if (gnutv_ca_new_pmt(pmt) == 1) ca_pmt_version = pmt->head.version_number; } }
/* * Get the next date packet from the STT section */ int atsc_scan_date(time_t *rx_time, unsigned int to) { int stt_fd; uint8_t filter[18]; uint8_t mask[18]; unsigned char sibuf[4096]; int size; // open the demuxer if ((stt_fd = dvbdemux_open_demux(adapter, 0, 0)) < 0) { return -1; } // create a section filter for the STT memset(filter, 0, sizeof(filter)); memset(mask, 0, sizeof(mask)); filter[0] = stag_atsc_system_time; mask[0] = 0xFF; if (dvbdemux_set_section_filter(stt_fd, ATSC_BASE_PID, filter, mask, 1, 1)) { close(stt_fd); return -1; } // poll for data struct pollfd pollfd; pollfd.fd = stt_fd; pollfd.events = POLLIN|POLLERR|POLLPRI; if (poll(&pollfd, 1, to * 1000) != 1) { close(stt_fd); return -1; } // read it if ((size = read(stt_fd, sibuf, sizeof(sibuf))) < 0) { close(stt_fd); return -1; } // parse section struct section *section = section_codec(sibuf, size); if (section == NULL) { close(stt_fd); return -1; } struct section_ext *section_ext = section_ext_decode(section, 0); if (section_ext == NULL) { close(stt_fd); return -1; } struct atsc_section_psip *psip = atsc_section_psip_decode(section_ext); if (psip == NULL) { close(stt_fd); return -1; } // parse STT struct atsc_stt_section *stt = atsc_stt_section_codec(psip); if (stt == NULL) { close(stt_fd); return -1; } // done *rx_time = atsctime_to_unixtime(stt->system_time); close(stt_fd); return 0; }
uint8_t dtv_time::get_tot(time_t & t,time_t & t_off) { #ifdef TSI_LIVE stream_t my_stream; #endif uint16_t real_read_len; struct dvb_tot_section *tot; struct descriptor *curd; time_t dvbtime; struct section *section = NULL; int retry_counter = 0; int res,time_zone; memset(&sbuf,0,sizeof(section_usr)); real_read_len = READ_LEN; my_stream.buffer = sbuf.databuf; my_stream.read_len = 188; my_stream.ops = 0; my_stream.PID_type = PSI; my_stream.buff_idx = TSI_TIME_BUFFINDEX; my_stream.time_out = 100;//set the timeout to 2 seconds my_stream.type = 1; tsi_add_pid_to_filter(PID_TOT,PSI,my_stream.buff_idx); while(1) { pthread_testcancel(); res = find_section_live(PID_TOT,&sbuf,&my_stream,3); if(res==0) { // printf("%s: %d sbuf.section_bufs->len:%d\n",__FUNCTION__,__LINE__,sbuf.section_bufs->len); if(_dvb_crc32(section_buf_data(sbuf.section_bufs),sbuf.section_bufs->len)) { // printf("get_tot crc error!!!!\n"); sbuf.continuities = 0; sbuf.i = 0; sbuf.section_status = 0; sbuf.sz = 0; memset(&sbuf.tsvals,0,sizeof(struct transport_values)); memset(sbuf.databuf,0,DATA_BUF_SIZE); sbuf.used = 0; if(sbuf.section_bufs!=NULL) section_buf_reset(sbuf.section_bufs); continue; } section = section_codec(section_buf_data(sbuf.section_bufs),sbuf.section_bufs->len); if (section == NULL) { section_buf_reset(sbuf.section_bufs); if(sbuf.section_bufs!=NULL) { free(sbuf.section_bufs); sbuf.section_bufs = NULL; } continue; } if(section->table_id!=0x73) { // section_buf_reset(sbuf.section_bufs); sbuf.continuities = 0; sbuf.i = 0; sbuf.section_status = 0; sbuf.sz = 0; memset(&sbuf.tsvals,0,sizeof(struct transport_values)); memset(sbuf.databuf,0,DATA_BUF_SIZE); sbuf.used = 0; if(sbuf.section_bufs!=NULL) section_buf_reset(sbuf.section_bufs); continue; } if(section->syntax_indicator==1) { section_buf_reset(sbuf.section_bufs); continue; } if ((tot = dvb_tot_section_codec(section)) == NULL) { fprintf(stderr, "SCT XXXX TOT section decode error\n"); if(sbuf.section_bufs!=NULL) { free(sbuf.section_bufs); sbuf.section_bufs = NULL; } continue; } dvbtime = dvbdate_to_unixtime(tot->utc_time); dvb_tot_section_descriptors_for_each(tot, curd) { struct dvb_local_time_offset_descriptor *dx; struct dvb_local_time_offset *cur; dx = dvb_local_time_offset_descriptor_codec(curd); if (dx == NULL) { fprintf(stderr, "DSC XXXX dvb_local_time_offset_descriptor decode error\n"); if(sbuf.section_bufs!=NULL) { free(sbuf.section_bufs); sbuf.section_bufs = NULL; } continue; } dvb_local_time_offset_descriptor_offsets_for_each(dx, cur) { // printf("DSC country_code:%.3s country_region_id:%i " // "local_time_offset_polarity:%i local_time_offset:%i " // "time_of_change:%i next_time_offset:%d\n", // cur->country_code, cur->country_region_id, // cur->local_time_offset_polarity, // dvbhhmm_to_seconds(cur->local_time_offset), // (int)dvbdate_to_unixtime(cur->time_of_change), // dvbhhmm_to_seconds(cur->next_time_offset)); time_t offset = dvbhhmm_to_seconds(cur->local_time_offset); //dvbtime+=offset; t = dvbtime; t += offset; time_zone = (offset/3600); t_off = offset; // printf("offset:%d time_zone:%d\n",offset,time_zone); if(sbuf.section_bufs!=NULL) { free(sbuf.section_bufs); sbuf.section_bufs = NULL; } tsi_remove_pid_from_filter(PID_TOT); return 0; } } } else {
static void linuxdvb_ca_process_capmt_queue ( void *aux ) { linuxdvb_ca_t *lca = aux; linuxdvb_ca_capmt_t *lcc; struct section *section; struct section_ext *result; struct mpeg_pmt_section *pmt; uint8_t capmt[4096]; int size, i; lcc = TAILQ_FIRST(&lca->lca_capmt_queue); if (!lcc) return; if (!(section = section_codec(lcc->data, lcc->len))){ tvherror("en50221", "failed to decode PMT section"); goto done; } if (!(result = section_ext_decode(section, 0))){ tvherror("en50221", "failed to decode PMT ext_section"); goto done; } if (!(pmt = mpeg_pmt_section_codec(result))){ tvherror("en50221", "failed to decode PMT"); goto done; } size = en50221_ca_format_pmt(pmt, capmt, sizeof(capmt), 0, lcc->list_mgmt, lcc->cmd_id); if (size < 0) { tvherror("en50221", "Failed to format CAPMT"); } if (en50221_app_ca_pmt(lca->lca_ca_resource, lca->lca_ca_session_number, capmt, size)) { tvherror("en50221", "Failed to send CAPMT"); } tvhtrace("en50221", "%s CAPMT sent (%s)", ca_pmt_cmd_id2str(lcc->cmd_id), ca_pmt_list_mgmt2str(lcc->list_mgmt)); tvhlog_hexdump("en50221", capmt, size); done: i = (lcc->cmd_id == CA_PMT_CMD_ID_QUERY) ? lca->lca_capmt_query_interval : lca->lca_capmt_interval; TAILQ_REMOVE(&lca->lca_capmt_queue, lcc, lcc_link); free(lcc->data); free(lcc); if (!TAILQ_EMPTY(&lca->lca_capmt_queue)) { gtimer_arm_ms(&lca->lca_capmt_queue_timer, linuxdvb_ca_process_capmt_queue, lca, i); } }