📄 decoder.cpp
字号:
/* Copyright (C) 1995, Tektronix Inc. All Rights Reserved. * * Usage Restrictions * * License is granted to copy, to use, and to make and to use derivative * works for research and evaluation purposes only. * * Disclaimer of Warranty * * These software programs are available to the user without any license * fee or royalty on an "as is" basis. Tektronix Inc. disclaims any and * all warranties, whether express, implied, or statuary, including any * implied warranties or merchantability or of fitness for a particular * purpose. In no event shall the copyright-holder be liable for any * incidental, punitive, or consequential damages of any kind whatsoever * arising from the use of these programs. * * This disclaimer of warranty extends to the user of these programs and * user's customers, employees, agents, transferees, successors, and * assigns. * * The Tektronix Inc. does not represent or warrant that the programs * furnished hereunder are free of infringement of any third-party * patents.*//* Decoder class implementation *///#include "stdAfx.h"#include "Decoder.H"#include "TSConsumer.H"#include "SectionConsumers.H"#include "PESConsumer.H"Decoder::Decoder (EventManager* m){ manager = m; tscons = new TSConsumer(this, new TS()); net_pid = NULL; head_crec = NULL; packet_number = 0;}void Decoder::install_netpid (int id){ // if id is a new net_pid, then destroy old consumer and install new one if (id != net_pid) { net_pid = id; add_cons(net_pid, new PriConsumer(this, new PriSection())); } // else do nothing}void Decoder::install_dir (Directory* d){ // switch to new directory dir = d; // loop through all programs in dir and build new list ConsumerRecord* new_head_crec = NULL; ProgramRecord* prec = dir->head_prec; while (prec) { Program* prog = prec->program; new_head_crec = install_prog_on_new_list (prog, new_head_crec); prec = prec->next_prec; } // now save old head_crec and install new head_crec ConsumerRecord* old_head_crec = head_crec; head_crec = new_head_crec; add_cons(0, new PATConsumer(this, new PATSection)); add_cons(1, new CAConsumer(this, new CASection)); // now look for things on old list to clean up ConsumerRecord* crec = old_head_crec;
ConsumerRecord* crecTmp;
if(crec)
crecTmp = crec->next_crec; while (crec) { delete crec; crec = crecTmp;
if(crec)
crecTmp = crec->next_crec; }}void Decoder::install_prog (Program* newprog){ // find and remove existing program from dir Program* oldprog = dir->get_program(newprog->program_number); if (oldprog) dir->remove_program(oldprog); // add newprog to dir dir->add_program(newprog); // now install program on consumer list install_prog_on_current_list (newprog);}void Decoder::connect (InputPort* ip){ iport = ip; // connect tsport tscons->connect(ip); // payload Consumers connect just before they are used}void Decoder::flush (){ ConsumerRecord* crec = head_crec; while (crec) { crec->cons->flush(); crec = crec->next_crec; }}void Decoder::read_packet (){ tscons->read_ts_packet(); packet_number++;}Directory* Decoder::get_dir (){ return dir;}int Decoder::get_networkpid (){ return net_pid;}EventManager* Decoder::get_manager (){ return manager;}TS* Decoder::get_ts (){ return tscons->ts;}TS* Decoder::get_ts (int pid){ ConsumerRecord* crec = find_crec(pid); if (crec == NULL) return NULL; return crec->ts;}PES* Decoder::get_pes (int pid){ ConsumerRecord* crec = find_crec(pid); PESConsumer* pescons = (PESConsumer*) crec->cons; return pescons->pes;}void Decoder::add_cons (int id, Consumer* cons){ ConsumerRecord* new_crec = new ConsumerRecord(id, cons); new_crec->next_crec = head_crec; head_crec = new_crec;}Consumer* Decoder::get_cons (int id){ // look down list ConsumerRecord* crec = find_crec(id); if (crec == NULL) return NULL; return crec->cons;}void Decoder::print_pids (){ ConsumerRecord* crec = head_crec; while (crec) { printf("%d ", crec->pid); crec = crec->next_crec; }}void Decoder::install_prog_on_current_list (Program* prog){ // put map table consumer on list if not there already ConsumerRecord* map_crec = find_crec(prog->pid); if (!map_crec) // place new program map consumer on consumer list { map_crec = new ConsumerRecord(prog->pid, new MapConsumer(this, new MapSection(prog))); map_crec->next_crec = head_crec; head_crec = map_crec; } // put children estreams on list if not there already EStreamRecord* erec = prog->head_erec; while (erec) { EStream* estream = erec->estream; ConsumerRecord* crec = find_crec(estream->pid); if (!crec) { crec = new ConsumerRecord(estream->pid, new PESConsumer(this, new PES)); crec->next_crec = head_crec; head_crec = crec; } erec = erec->next_erec; }}ConsumerRecord* Decoder::install_prog_on_new_list (Program* prog, ConsumerRecord* head_of_list){ /* Takes a program and a consumer list Checks to see of any consumers already exist on the current installed comsumer list. These get moved over to the new list. Otherwise new consumers are created and placed on the new list */ // put map table consumer on list if not there already ConsumerRecord* map_crec = find_and_remove_crec(prog->pid); if (!map_crec) // place new program map consumer on consumer list { map_crec = new ConsumerRecord(prog->pid, new MapConsumer(this, new MapSection(prog))); } map_crec->next_crec = head_of_list; head_of_list = map_crec; // put children estreams on list if not there already EStreamRecord* erec = prog->head_erec; while (erec) { EStream* estream = erec->estream; ConsumerRecord* crec = find_and_remove_crec(estream->pid); if (!crec) { crec = new ConsumerRecord(estream->pid, new PESConsumer(this, new PES)); } crec->next_crec = head_of_list; head_of_list = crec; erec = erec->next_erec; } return head_of_list;}ConsumerRecord* Decoder::find_crec (int id){ ConsumerRecord* crec = head_crec; while (crec) { if (crec->pid == id) { return crec; } crec = crec->next_crec; } return NULL;}ConsumerRecord* Decoder::find_and_remove_crec (int id){ ConsumerRecord* cur_crec = head_crec; ConsumerRecord* prev_crec; while (cur_crec) { if (cur_crec->pid == id) { if (cur_crec == head_crec) { head_crec = head_crec->next_crec; } else { prev_crec->next_crec = cur_crec->next_crec; } return cur_crec; } prev_crec = cur_crec; cur_crec = cur_crec->next_crec; } return NULL;}ConsumerRecord::ConsumerRecord (int i, Consumer* c){ pid = i; ts = new TS(); ts->pid = pid; cons = c; next_crec = NULL;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -