void mpegts_set_service(MpegTSContext *ts, int sid, SetServiceCallback *set_service_cb, void *opaque) { ts->set_service_cb = set_service_cb; ts->set_service_opaque = opaque; ts->req_sid = sid; ts->pat_filter = mpegts_open_section_filter(ts, PAT_PID, pat_cb, ts, 1); }
static void pat_cb(MpegTSFilter *filter, const uint8_t *section, int section_len) { MpegTSContext *ts = filter->u.section_filter.opaque; SectionHeader h1, *h = &h1; const uint8_t *p, *p_end; int sid, pmt_pid; #ifdef DEBUG_SI av_log(ts->stream, AV_LOG_DEBUG, "PAT:\n"); av_hex_dump_log(ts->stream, AV_LOG_DEBUG, (uint8_t *)section, section_len); #endif p_end = section + section_len - 4; p = section; if (parse_section_header(h, &p, p_end) < 0) return; if (h->tid != PAT_TID) return; clear_programs(ts); for(;;) { sid = get16(&p, p_end); if (sid < 0) break; pmt_pid = get16(&p, p_end) & 0x1fff; if (pmt_pid < 0) break; #ifdef DEBUG_SI av_log(ts->stream, AV_LOG_DEBUG, "sid=0x%x pid=0x%x\n", sid, pmt_pid); #endif if (sid == 0x0000) { /* NIT info */ } else { av_new_program(ts->stream, sid); ts->stop_parse--; mpegts_open_section_filter(ts, pmt_pid, pmt_cb, ts, 1); add_pat_entry(ts, sid); add_pid_to_pmt(ts, sid, 0); //add pat pid to program add_pid_to_pmt(ts, sid, pmt_pid); } } /* not found */ ts->stop_parse++; mpegts_close_filter(ts, filter); }
static void pat_cb(void *opaque, const uint8_t *section, int section_len) { MpegTSContext *ts = opaque; SectionHeader h1, *h = &h1; const uint8_t *p, *p_end; int sid, pmt_pid; #ifdef DEBUG_SI printf("PAT:\n"); av_hex_dump(stdout, (uint8_t *)section, section_len); #endif p_end = section + section_len - 4; p = section; if (parse_section_header(h, &p, p_end) < 0) return; if (h->tid != PAT_TID) return; for(;;) { sid = get16(&p, p_end); if (sid < 0) break; pmt_pid = get16(&p, p_end) & 0x1fff; if (pmt_pid < 0) break; #ifdef DEBUG_SI printf("sid=0x%x pid=0x%x\n", sid, pmt_pid); #endif if (sid == 0x0000) { /* NIT info */ } else { if (ts->req_sid == sid) { ts->pmt_filter = mpegts_open_section_filter(ts, pmt_pid, pmt_cb, ts, 1); goto found; } } } /* not found */ ts->set_service_cb(ts->set_service_opaque, -1); found: mpegts_close_filter(ts, ts->pat_filter); ts->pat_filter = NULL; }
/* scan services in a transport stream by looking at the SDT */ static void mpegts_scan_sdt(MpegTSContext *ts) { mpegts_open_section_filter(ts, SDT_PID, sdt_cb, ts, 1); }
static void mpegts_set_service(MpegTSContext *ts) { mpegts_open_section_filter(ts, PAT_PID, pat_cb, ts, 1); }
/* scan services in a transport stream by looking at the PAT (better than nothing !) */ void mpegts_scan_pat(MpegTSContext *ts) { ts->pat_filter = mpegts_open_section_filter(ts, PAT_PID, pat_scan_cb, ts, 1); }