int tune(int aid, int sid) { adapter *ad = get_adapter(aid); int rv = 0; SPid *p; if (!ad) return -400; mutex_lock(&ad->mutex); ad->last_sort = getTick(); if (sid == ad->master_sid && ad->do_tune) { ad->tp.switch_type = ad->switch_type; ad->tp.uslot = ad->uslot; ad->tp.ufreq = ad->ufreq; ad->tp.pin = ad->pin; ad->tp.committed_no = ad->committed_no; ad->tp.uncommitted_no = ad->uncommitted_no; rv = ad->tune(ad->id, &ad->tp); ad->status = 0; ad->status_cnt = 0; set_socket_pos(ad->sock, 0); // flush the existing buffer ad->rlen = 0; if (ad->sid_cnt > 1) // the master changed the frequency { close_streams_for_adapter(aid, sid); if (update_pids(aid)) { mutex_unlock(&ad->mutex); return -503; } } #ifdef TABLES_H p = find_pid(aid, 0); if (!p || p->flags == 3) // add pid 0 if not explicitly added { LOG( "Adding pid 0 to the list of pids as not explicitly added for adapter %d", aid); mark_pid_add(-1, aid, 0); } #endif } else LOG("not tuning for SID %d (do_tune=%d, master_sid=%d)", sid, ad->do_tune, ad->master_sid); if (rv < 0) mark_pids_deleted(aid, sid, NULL); if (update_pids(aid)) { mutex_unlock(&ad->mutex); return -503; } mutex_unlock(&ad->mutex); return rv; }
int mark_pids_add(int sid, int aid, char *pids) { int i, la; adapter *ad; char *arg[MAX_PIDS + 2]; int pid; ad = get_adapter(aid); if (!ad) return -1; if (!pids) return -1; LOG("adding pids to adapter %d, sid %d, pids=%s", aid, sid, pids ? pids : "NULL"); la = split(arg, pids, MAX_PIDS, ','); for (i = 0; i < la; i++) { pid = map_intd(arg[i], NULL, -1); if (pid == -1) continue; if (mark_pid_add(sid, aid, pid) < 0) return -1; } dump_pids(aid); return 0; }
int process_pat(adapter *ad, unsigned char *b) { int pat_len = 0, i, tid = 0, sid, pid, ver, csid = 0; int64_t pid_key = TABLES_ITEM + ((1 + ad->id) << 24) + 0; int16_t *pids; unsigned char *init_b = b; SPid *p; if (((b[1] & 0x1F) != 0) || (b[2] != 0)) return 0; if (b[0] != 0x47) return 0; if ((b[1] & 0x40) && ((b[4] != 0) || (b[5] != 0))) return 0; // p = find_pid(ad->id, 0); // if(!p) // return 0; tid = b[8] * 256 + b[9]; ver = b[10] & 0x3E; if ((ad->transponder_id == tid) && (ad->pat_ver == ver)) //pat already processed return 0; if (!(pat_len = assemble_packet(&b, ad, 1))) return 0; tid = b[3] * 256 + b[4]; ver = b[5] & 0x3E; if (((ad->transponder_id != tid) || (ad->pat_ver != ver)) && (pat_len > 0) && (pat_len < 1500)) { ad->pat_processed = 0; } if (ad->pat_processed) return 0; ad->pat_ver = ver; ad->transponder_id = tid; #ifndef DISABLE_DVBAPI dvbapi_delete_keys_for_adapter(ad->id); #endif // LOG("tid %d pat_len %d: %02X %02X %02X %02X %02X %02X %02X %02X", tid, pat_len, b[0], b[1], b[2], b[3], b[4], b[5], b[6], b[7]); setItem(pid_key, b, 1, 0); setItemSize(pid_key, 8192 * sizeof(*pids)); pids = (int16_t *) getItem(pid_key); memset(pids, 0, 8192 * sizeof(*pids)); pat_len -= 9; b += 8; LOGL(2, "PAT Adapter %d, Transponder ID %d, len %d, version %d", ad->id, tid, pat_len, ad->pat_ver); if (pat_len > 1500) return 0; for (i = 0; i < pat_len; i += 4) { sid = b[i] * 256 + b[i + 1]; pid = (b[i + 2] & 0x1F) * 256 + b[i + 3]; LOGL(2, "Adapter %d, PMT sid %d (%04X), pid %d", ad->id, sid, sid, pid); if (sid > 0) { pids[pid] = -TYPE_PMT; p = find_pid(ad->id, pid); if (!p) mark_pid_add(-1, ad->id, pid); if ((p = find_pid(ad->id, pid))) { p->type = TYPE_PMT; csid = pid; if (p->flags == 3) p->flags = 1; } } } update_pids(ad->id); ad->pat_processed = 1; return csid; }