vdr  2.4.1
filter.c
Go to the documentation of this file.
1 /*
2  * filter.c: Section filter
3  *
4  * See the main source file 'vdr.c' for copyright information and
5  * how to reach the author.
6  *
7  * $Id: filter.c 4.3 2017/05/07 15:20:45 kls Exp $
8  */
9 
10 #include "filter.h"
11 #include "sections.h"
12 
13 // --- cSectionSyncer --------------------------------------------------------
14 
16 {
17  Reset();
18 }
19 
21 {
22  currentVersion = -1;
23  currentSection = -1;
24  synced = false;
25  complete = false;
26  memset(sections, 0x00, sizeof(sections));
27 }
28 
30 {
32  synced = false;
33  complete = false;
34 }
35 
36 bool cSectionSyncer::Sync(uchar Version, int Number, int LastNumber)
37 {
38  if (Version != currentVersion) {
39  Reset();
40  currentVersion = Version;
41  }
42  if (!synced) {
43  if (Number != 0)
44  return false;
45  else
46  synced = true;
47  }
48  currentSection = Number;
49  bool Result = !GetSectionFlag(Number);
50  SetSectionFlag(Number, true);
51  if (Number == LastNumber)
52  complete = true;
53  return Result;
54 }
55 
56 // --- cFilterData -----------------------------------------------------------
57 
59 {
60  pid = 0;
61  tid = 0;
62  mask = 0;
63  sticky = false;
64 }
65 
66 cFilterData::cFilterData(u_short Pid, u_char Tid, u_char Mask, bool Sticky)
67 {
68  pid = Pid;
69  tid = Tid;
70  mask = Mask;
71  sticky = Sticky;
72 }
73 
75 {
76  pid = FilterData.pid;
77  tid = FilterData.tid;
78  mask = FilterData.mask;
79  sticky = FilterData.sticky;
80  return *this;
81 }
82 
83 bool cFilterData::Is(u_short Pid, u_char Tid, u_char Mask)
84 {
85  return pid == Pid && tid == Tid && mask == Mask;
86 }
87 
88 bool cFilterData::Matches(u_short Pid, u_char Tid)
89 {
90  return pid == Pid && tid == (Tid & mask);
91 }
92 
93 // --- cFilter ---------------------------------------------------------------
94 
96 {
97  sectionHandler = NULL;
98  on = false;
99 }
100 
101 cFilter::cFilter(u_short Pid, u_char Tid, u_char Mask)
102 {
103  sectionHandler = NULL;
104  on = false;
105  Set(Pid, Tid, Mask);
106 }
107 
109 {
110  if (sectionHandler)
111  sectionHandler->Detach(this);
112 }
113 
115 {
116  return sectionHandler ? sectionHandler->Source() : 0;
117 }
118 
120 {
121  return sectionHandler ? sectionHandler->Transponder() : 0;
122 }
123 
125 {
126  return sectionHandler ? sectionHandler->Channel() : NULL;
127 }
128 
129 void cFilter::SetStatus(bool On)
130 {
131  if (sectionHandler && on != On) {
132  cFilterData *fd = data.First();
133  while (fd) {
134  if (On)
135  sectionHandler->Add(fd);
136  else {
137  sectionHandler->Del(fd);
138  if (!fd->sticky) {
139  cFilterData *next = data.Next(fd);
140  data.Del(fd);
141  fd = next;
142  continue;
143  }
144  }
145  fd = data.Next(fd);
146  }
147  on = On;
148  }
149 }
150 
151 bool cFilter::Matches(u_short Pid, u_char Tid)
152 {
153  if (on) {
154  for (cFilterData *fd = data.First(); fd; fd = data.Next(fd)) {
155  if (fd->Matches(Pid, Tid))
156  return true;
157  }
158  }
159  return false;
160 }
161 
162 void cFilter::Set(u_short Pid, u_char Tid, u_char Mask)
163 {
164  Add(Pid, Tid, Mask, true);
165 }
166 
167 void cFilter::Add(u_short Pid, u_char Tid, u_char Mask, bool Sticky)
168 {
169  cFilterData *fd = new cFilterData(Pid, Tid, Mask, Sticky);
170  data.Add(fd);
171  if (sectionHandler && on)
172  sectionHandler->Add(fd);
173 }
174 
175 void cFilter::Del(u_short Pid, u_char Tid, u_char Mask)
176 {
177  for (cFilterData *fd = data.First(); fd; fd = data.Next(fd)) {
178  if (fd->Is(Pid, Tid, Mask)) {
179  if (sectionHandler && on)
180  sectionHandler->Del(fd);
181  data.Del(fd);
182  return;
183  }
184  }
185 }
cFilter::SetStatus
virtual void SetStatus(bool On)
Turns this filter on or off, depending on the value of On.
Definition: filter.c:129
cSectionHandler::Transponder
int Transponder(void)
Definition: sections.c:69
filter.h
cSectionHandler::Add
void Add(const cFilterData *FilterData)
Definition: sections.c:79
cFilter::Transponder
int Transponder(void)
Returns the transponder of the data delivered to this filter.
Definition: filter.c:119
cSectionSyncer::complete
bool complete
Definition: filter.h:21
cFilter::Set
void Set(u_short Pid, u_char Tid, u_char Mask=0xFF)
Sets the given filter data by calling Add() with Sticky = true.
Definition: filter.c:162
cSectionSyncer::GetSectionFlag
bool GetSectionFlag(uchar Section)
Definition: filter.h:24
cFilterData::cFilterData
cFilterData(void)
Definition: filter.c:58
sections.h
cFilterData::Matches
bool Matches(u_short Pid, u_char Tid)
Definition: filter.c:88
cSectionHandler::Channel
const cChannel * Channel(void)
Definition: sections.c:74
cListObject::next
cListObject * next
Definition: tools.h:496
cFilterData::operator=
cFilterData & operator=(const cFilterData &FilterData)
Definition: filter.c:74
cFilterData
Definition: filter.h:33
cListBase::Add
void Add(cListObject *Object, cListObject *After=NULL)
Definition: tools.c:2152
cSectionSyncer::cSectionSyncer
cSectionSyncer(void)
Definition: filter.c:15
cFilter::Del
void Del(u_short Pid, u_char Tid, u_char Mask=0xFF)
Deletes the given filter data from this filter.
Definition: filter.c:175
SI::u_char
unsigned char u_char
Definition: headers.h:38
cSectionSyncer::Repeat
void Repeat(void)
Definition: filter.c:29
cSectionHandler::Detach
void Detach(cFilter *Filter)
Definition: sections.c:129
cListBase::Del
void Del(cListObject *Object, bool DeleteObject=true)
Definition: tools.c:2184
cSectionHandler::Source
int Source(void)
Definition: sections.c:64
cSectionHandler::Del
void Del(const cFilterData *FilterData)
Definition: sections.c:101
cFilterData::pid
u_short pid
Definition: filter.h:35
cFilter::~cFilter
virtual ~cFilter()
Definition: filter.c:108
uchar
unsigned char uchar
Definition: tools.h:31
cFilter::Channel
const cChannel * Channel(void)
Returns the channel of the data delivered to this filter.
Definition: filter.c:124
cSectionSyncer::SetSectionFlag
void SetSectionFlag(uchar Section, bool On)
Definition: filter.h:23
cSectionSyncer::sections
uchar sections[32]
Definition: filter.h:22
cList::First
const T * First(void) const
Returns the first element in this list, or NULL if the list is empty.
Definition: tools.h:606
cSectionSyncer::Reset
void Reset(void)
Definition: filter.c:20
cFilter::Add
void Add(u_short Pid, u_char Tid, u_char Mask=0xFF, bool Sticky=false)
Adds the given filter data to this filter.
Definition: filter.c:167
cChannel
Definition: channels.h:89
cFilterData::mask
u_char mask
Definition: filter.h:37
cSectionSyncer::currentSection
int currentSection
Definition: filter.h:19
cSectionSyncer::synced
bool synced
Definition: filter.h:20
cSectionSyncer::currentVersion
int currentVersion
Definition: filter.h:18
cSectionSyncer::Sync
bool Sync(uchar Version, int Number, int LastNumber)
Definition: filter.c:36
cFilterData::tid
u_char tid
Definition: filter.h:36
cFilterData::Is
bool Is(u_short Pid, u_char Tid, u_char Mask)
Definition: filter.c:83
cFilter::on
bool on
Definition: filter.h:54
cList::Next
const T * Next(const T *Object) const
< Returns the element immediately before Object in this list, or NULL if Object is the first element ...
Definition: tools.h:613
cFilter::cFilter
cFilter(void)
Definition: filter.c:95
cFilter::Source
int Source(void)
Returns the source of the data delivered to this filter.
Definition: filter.c:114
cFilter::sectionHandler
cSectionHandler * sectionHandler
Definition: filter.h:52
cFilter::Matches
bool Matches(u_short Pid, u_char Tid)
Indicates whether this filter wants to receive data from the given Pid/Tid.
Definition: filter.c:151
cFilter::data
cList< cFilterData > data
Definition: filter.h:53
cFilterData::sticky
bool sticky
Definition: filter.h:38