aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndreas Oberritter <obi@linuxtv.org>2005-09-09 16:02:26 -0400
committerLinus Torvalds <torvalds@g5.osdl.org>2005-09-09 16:57:37 -0400
commitdad4a73071532448f6cee29791476494a8eb3a58 (patch)
treec6e13388aa45cadde1545bb63ac9fd44149d188f
parentdb574d7d6e38fe37bbb97e2b0a0363b5d2ffa203 (diff)
[PATCH] dvb: core: dvb_demux formatting fixes
Formatting fixes (Lindent + some handwork). Signed-off-by: Andreas Oberritter <obi@linuxtv.org> Signed-off-by: Johannes Stezenbach <js@linuxtv.org> Signed-off-by: Andrew Morton <akpm@osdl.org> Signed-off-by: Linus Torvalds <torvalds@osdl.org>
-rw-r--r--drivers/media/dvb/dvb-core/dvb_demux.c469
-rw-r--r--drivers/media/dvb/dvb-core/dvb_demux.h107
2 files changed, 283 insertions, 293 deletions
diff --git a/drivers/media/dvb/dvb-core/dvb_demux.c b/drivers/media/dvb/dvb-core/dvb_demux.c
index 528ca463a6dd..dc476dda2b71 100644
--- a/drivers/media/dvb/dvb-core/dvb_demux.c
+++ b/drivers/media/dvb/dvb-core/dvb_demux.c
@@ -38,55 +38,52 @@
38*/ 38*/
39// #define DVB_DEMUX_SECTION_LOSS_LOG 39// #define DVB_DEMUX_SECTION_LOSS_LOG
40 40
41
42/****************************************************************************** 41/******************************************************************************
43 * static inlined helper functions 42 * static inlined helper functions
44 ******************************************************************************/ 43 ******************************************************************************/
45 44
46
47static inline u16 section_length(const u8 *buf) 45static inline u16 section_length(const u8 *buf)
48{ 46{
49 return 3+((buf[1]&0x0f)<<8)+buf[2]; 47 return 3 + ((buf[1] & 0x0f) << 8) + buf[2];
50} 48}
51 49
52
53static inline u16 ts_pid(const u8 *buf) 50static inline u16 ts_pid(const u8 *buf)
54{ 51{
55 return ((buf[1]&0x1f)<<8)+buf[2]; 52 return ((buf[1] & 0x1f) << 8) + buf[2];
56} 53}
57 54
58
59static inline u8 payload(const u8 *tsp) 55static inline u8 payload(const u8 *tsp)
60{ 56{
61 if (!(tsp[3] & 0x10)) // no payload? 57 if (!(tsp[3] & 0x10)) // no payload?
62 return 0; 58 return 0;
63 if (tsp[3] & 0x20) { // adaptation field? 59
64 if (tsp[4] > 183) // corrupted data? 60 if (tsp[3] & 0x20) { // adaptation field?
61 if (tsp[4] > 183) // corrupted data?
65 return 0; 62 return 0;
66 else 63 else
67 return 184-1-tsp[4]; 64 return 184 - 1 - tsp[4];
68 } 65 }
66
69 return 184; 67 return 184;
70} 68}
71 69
72 70static u32 dvb_dmx_crc32(struct dvb_demux_feed *f, const u8 *src, size_t len)
73static u32 dvb_dmx_crc32 (struct dvb_demux_feed *f, const u8 *src, size_t len)
74{ 71{
75 return (f->feed.sec.crc_val = crc32_be (f->feed.sec.crc_val, src, len)); 72 return (f->feed.sec.crc_val = crc32_be(f->feed.sec.crc_val, src, len));
76} 73}
77 74
78 75static void dvb_dmx_memcopy(struct dvb_demux_feed *f, u8 *d, const u8 *s,
79static void dvb_dmx_memcopy (struct dvb_demux_feed *f, u8 *d, const u8 *s, size_t len) 76 size_t len)
80{ 77{
81 memcpy (d, s, len); 78 memcpy(d, s, len);
82} 79}
83 80
84
85/****************************************************************************** 81/******************************************************************************
86 * Software filter functions 82 * Software filter functions
87 ******************************************************************************/ 83 ******************************************************************************/
88 84
89static inline int dvb_dmx_swfilter_payload (struct dvb_demux_feed *feed, const u8 *buf) 85static inline int dvb_dmx_swfilter_payload(struct dvb_demux_feed *feed,
86 const u8 *buf)
90{ 87{
91 int count = payload(buf); 88 int count = payload(buf);
92 int p; 89 int p;
@@ -96,32 +93,31 @@ static inline int dvb_dmx_swfilter_payload (struct dvb_demux_feed *feed, const u
96 if (count == 0) 93 if (count == 0)
97 return -1; 94 return -1;
98 95
99 p = 188-count; 96 p = 188 - count;
100 97
101 /* 98 /*
102 cc=buf[3]&0x0f; 99 cc = buf[3] & 0x0f;
103 ccok=((dvbdmxfeed->cc+1)&0x0f)==cc ? 1 : 0; 100 ccok = ((feed->cc + 1) & 0x0f) == cc;
104 dvbdmxfeed->cc=cc; 101 feed->cc = cc;
105 if (!ccok) 102 if (!ccok)
106 printk("missed packet!\n"); 103 printk("missed packet!\n");
107 */ 104 */
108 105
109 if (buf[1] & 0x40) // PUSI ? 106 if (buf[1] & 0x40) // PUSI ?
110 feed->peslen = 0xfffa; 107 feed->peslen = 0xfffa;
111 108
112 feed->peslen += count; 109 feed->peslen += count;
113 110
114 return feed->cb.ts (&buf[p], count, NULL, 0, &feed->feed.ts, DMX_OK); 111 return feed->cb.ts(&buf[p], count, NULL, 0, &feed->feed.ts, DMX_OK);
115} 112}
116 113
117 114static int dvb_dmx_swfilter_sectionfilter(struct dvb_demux_feed *feed,
118static int dvb_dmx_swfilter_sectionfilter (struct dvb_demux_feed *feed, 115 struct dvb_demux_filter *f)
119 struct dvb_demux_filter *f)
120{ 116{
121 u8 neq = 0; 117 u8 neq = 0;
122 int i; 118 int i;
123 119
124 for (i=0; i<DVB_DEMUX_MASK_MAX; i++) { 120 for (i = 0; i < DVB_DEMUX_MASK_MAX; i++) {
125 u8 xor = f->filter.filter_value[i] ^ feed->feed.sec.secbuf[i]; 121 u8 xor = f->filter.filter_value[i] ^ feed->feed.sec.secbuf[i];
126 122
127 if (f->maskandmode[i] & xor) 123 if (f->maskandmode[i] & xor)
@@ -133,12 +129,11 @@ static int dvb_dmx_swfilter_sectionfilter (struct dvb_demux_feed *feed,
133 if (f->doneq && !neq) 129 if (f->doneq && !neq)
134 return 0; 130 return 0;
135 131
136 return feed->cb.sec (feed->feed.sec.secbuf, feed->feed.sec.seclen, 132 return feed->cb.sec(feed->feed.sec.secbuf, feed->feed.sec.seclen,
137 NULL, 0, &f->filter, DMX_OK); 133 NULL, 0, &f->filter, DMX_OK);
138} 134}
139 135
140 136static inline int dvb_dmx_swfilter_section_feed(struct dvb_demux_feed *feed)
141static inline int dvb_dmx_swfilter_section_feed (struct dvb_demux_feed *feed)
142{ 137{
143 struct dvb_demux *demux = feed->demux; 138 struct dvb_demux *demux = feed->demux;
144 struct dvb_demux_filter *f = feed->filter; 139 struct dvb_demux_filter *f = feed->filter;
@@ -168,26 +163,24 @@ static inline int dvb_dmx_swfilter_section_feed (struct dvb_demux_feed *feed)
168 return 0; 163 return 0;
169} 164}
170 165
171
172static void dvb_dmx_swfilter_section_new(struct dvb_demux_feed *feed) 166static void dvb_dmx_swfilter_section_new(struct dvb_demux_feed *feed)
173{ 167{
174 struct dmx_section_feed *sec = &feed->feed.sec; 168 struct dmx_section_feed *sec = &feed->feed.sec;
175 169
176#ifdef DVB_DEMUX_SECTION_LOSS_LOG 170#ifdef DVB_DEMUX_SECTION_LOSS_LOG
177 if(sec->secbufp < sec->tsfeedp) 171 if (sec->secbufp < sec->tsfeedp) {
178 {
179 int i, n = sec->tsfeedp - sec->secbufp; 172 int i, n = sec->tsfeedp - sec->secbufp;
180 173
181 /* section padding is done with 0xff bytes entirely. 174 /*
182 ** due to speed reasons, we won't check all of them 175 * Section padding is done with 0xff bytes entirely.
183 ** but just first and last 176 * Due to speed reasons, we won't check all of them
184 */ 177 * but just first and last.
185 if(sec->secbuf[0] != 0xff || sec->secbuf[n-1] != 0xff) 178 */
186 { 179 if (sec->secbuf[0] != 0xff || sec->secbuf[n - 1] != 0xff) {
187 printk("dvb_demux.c section ts padding loss: %d/%d\n", 180 printk("dvb_demux.c section ts padding loss: %d/%d\n",
188 n, sec->tsfeedp); 181 n, sec->tsfeedp);
189 printk("dvb_demux.c pad data:"); 182 printk("dvb_demux.c pad data:");
190 for(i = 0; i < n; i++) 183 for (i = 0; i < n; i++)
191 printk(" %02x", sec->secbuf[i]); 184 printk(" %02x", sec->secbuf[i]);
192 printk("\n"); 185 printk("\n");
193 } 186 }
@@ -199,82 +192,81 @@ static void dvb_dmx_swfilter_section_new(struct dvb_demux_feed *feed)
199} 192}
200 193
201/* 194/*
202** Losless Section Demux 1.4.1 by Emard 195 * Losless Section Demux 1.4.1 by Emard
203** Valsecchi Patrick: 196 * Valsecchi Patrick:
204** - middle of section A (no PUSI) 197 * - middle of section A (no PUSI)
205** - end of section A and start of section B 198 * - end of section A and start of section B
206** (with PUSI pointing to the start of the second section) 199 * (with PUSI pointing to the start of the second section)
207** 200 *
208** In this case, without feed->pusi_seen you'll receive a garbage section 201 * In this case, without feed->pusi_seen you'll receive a garbage section
209** consisting of the end of section A. Basically because tsfeedp 202 * consisting of the end of section A. Basically because tsfeedp
210** is incemented and the use=0 condition is not raised 203 * is incemented and the use=0 condition is not raised
211** when the second packet arrives. 204 * when the second packet arrives.
212** 205 *
213** Fix: 206 * Fix:
214** when demux is started, let feed->pusi_seen = 0 to 207 * when demux is started, let feed->pusi_seen = 0 to
215** prevent initial feeding of garbage from the end of 208 * prevent initial feeding of garbage from the end of
216** previous section. When you for the first time see PUSI=1 209 * previous section. When you for the first time see PUSI=1
217** then set feed->pusi_seen = 1 210 * then set feed->pusi_seen = 1
218*/ 211 */
219static int dvb_dmx_swfilter_section_copy_dump(struct dvb_demux_feed *feed, const u8 *buf, u8 len) 212static int dvb_dmx_swfilter_section_copy_dump(struct dvb_demux_feed *feed,
213 const u8 *buf, u8 len)
220{ 214{
221 struct dvb_demux *demux = feed->demux; 215 struct dvb_demux *demux = feed->demux;
222 struct dmx_section_feed *sec = &feed->feed.sec; 216 struct dmx_section_feed *sec = &feed->feed.sec;
223 u16 limit, seclen, n; 217 u16 limit, seclen, n;
224 218
225 if(sec->tsfeedp >= DMX_MAX_SECFEED_SIZE) 219 if (sec->tsfeedp >= DMX_MAX_SECFEED_SIZE)
226 return 0; 220 return 0;
227 221
228 if(sec->tsfeedp + len > DMX_MAX_SECFEED_SIZE) 222 if (sec->tsfeedp + len > DMX_MAX_SECFEED_SIZE) {
229 {
230#ifdef DVB_DEMUX_SECTION_LOSS_LOG 223#ifdef DVB_DEMUX_SECTION_LOSS_LOG
231 printk("dvb_demux.c section buffer full loss: %d/%d\n", 224 printk("dvb_demux.c section buffer full loss: %d/%d\n",
232 sec->tsfeedp + len - DMX_MAX_SECFEED_SIZE, DMX_MAX_SECFEED_SIZE); 225 sec->tsfeedp + len - DMX_MAX_SECFEED_SIZE,
226 DMX_MAX_SECFEED_SIZE);
233#endif 227#endif
234 len = DMX_MAX_SECFEED_SIZE - sec->tsfeedp; 228 len = DMX_MAX_SECFEED_SIZE - sec->tsfeedp;
235 } 229 }
236 230
237 if(len <= 0) 231 if (len <= 0)
238 return 0; 232 return 0;
239 233
240 demux->memcopy(feed, sec->secbuf_base + sec->tsfeedp, buf, len); 234 demux->memcopy(feed, sec->secbuf_base + sec->tsfeedp, buf, len);
241 sec->tsfeedp += len; 235 sec->tsfeedp += len;
242 236
243 /* ----------------------------------------------------- 237 /*
244 ** Dump all the sections we can find in the data (Emard) 238 * Dump all the sections we can find in the data (Emard)
245 */ 239 */
246
247 limit = sec->tsfeedp; 240 limit = sec->tsfeedp;
248 if(limit > DMX_MAX_SECFEED_SIZE) 241 if (limit > DMX_MAX_SECFEED_SIZE)
249 return -1; /* internal error should never happen */ 242 return -1; /* internal error should never happen */
250 243
251 /* to be sure always set secbuf */ 244 /* to be sure always set secbuf */
252 sec->secbuf = sec->secbuf_base + sec->secbufp; 245 sec->secbuf = sec->secbuf_base + sec->secbufp;
253 246
254 for(n = 0; sec->secbufp + 2 < limit; n++) 247 for (n = 0; sec->secbufp + 2 < limit; n++) {
255 {
256 seclen = section_length(sec->secbuf); 248 seclen = section_length(sec->secbuf);
257 if(seclen <= 0 || seclen > DMX_MAX_SECFEED_SIZE 249 if (seclen <= 0 || seclen > DMX_MAX_SECFEED_SIZE
258 || seclen + sec->secbufp > limit) 250 || seclen + sec->secbufp > limit)
259 return 0; 251 return 0;
260 sec->seclen = seclen; 252 sec->seclen = seclen;
261 sec->crc_val = ~0; 253 sec->crc_val = ~0;
262 /* dump [secbuf .. secbuf+seclen) */ 254 /* dump [secbuf .. secbuf+seclen) */
263 if(feed->pusi_seen) 255 if (feed->pusi_seen)
264 dvb_dmx_swfilter_section_feed(feed); 256 dvb_dmx_swfilter_section_feed(feed);
265#ifdef DVB_DEMUX_SECTION_LOSS_LOG 257#ifdef DVB_DEMUX_SECTION_LOSS_LOG
266 else 258 else
267 printk("dvb_demux.c pusi not seen, discarding section data\n"); 259 printk("dvb_demux.c pusi not seen, discarding section data\n");
268#endif 260#endif
269 sec->secbufp += seclen; /* secbufp and secbuf moving together is */ 261 sec->secbufp += seclen; /* secbufp and secbuf moving together is */
270 sec->secbuf += seclen; /* redundand but saves pointer arithmetic */ 262 sec->secbuf += seclen; /* redundant but saves pointer arithmetic */
271 } 263 }
272 264
273 return 0; 265 return 0;
274} 266}
275 267
276 268static int dvb_dmx_swfilter_section_packet(struct dvb_demux_feed *feed,
277static int dvb_dmx_swfilter_section_packet(struct dvb_demux_feed *feed, const u8 *buf) 269 const u8 *buf)
278{ 270{
279 u8 p, count; 271 u8 p, count;
280 int ccok, dc_i = 0; 272 int ccok, dc_i = 0;
@@ -282,10 +274,10 @@ static int dvb_dmx_swfilter_section_packet(struct dvb_demux_feed *feed, const u8
282 274
283 count = payload(buf); 275 count = payload(buf);
284 276
285 if (count == 0) /* count == 0 if no payload or out of range */ 277 if (count == 0) /* count == 0 if no payload or out of range */
286 return -1; 278 return -1;
287 279
288 p = 188 - count; /* payload start */ 280 p = 188 - count; /* payload start */
289 281
290 cc = buf[3] & 0x0f; 282 cc = buf[3] & 0x0f;
291 ccok = ((feed->cc + 1) & 0x0f) == cc; 283 ccok = ((feed->cc + 1) & 0x0f) == cc;
@@ -299,51 +291,53 @@ static int dvb_dmx_swfilter_section_packet(struct dvb_demux_feed *feed, const u8
299 291
300 if (!ccok || dc_i) { 292 if (!ccok || dc_i) {
301#ifdef DVB_DEMUX_SECTION_LOSS_LOG 293#ifdef DVB_DEMUX_SECTION_LOSS_LOG
302 printk("dvb_demux.c discontinuity detected %d bytes lost\n", count); 294 printk("dvb_demux.c discontinuity detected %d bytes lost\n",
303 /* those bytes under sume circumstances will again be reported 295 count);
304 ** in the following dvb_dmx_swfilter_section_new 296 /*
305 */ 297 * those bytes under sume circumstances will again be reported
298 * in the following dvb_dmx_swfilter_section_new
299 */
306#endif 300#endif
307 /* Discontinuity detected. Reset pusi_seen = 0 to 301 /*
308 ** stop feeding of suspicious data until next PUSI=1 arrives 302 * Discontinuity detected. Reset pusi_seen = 0 to
309 */ 303 * stop feeding of suspicious data until next PUSI=1 arrives
304 */
310 feed->pusi_seen = 0; 305 feed->pusi_seen = 0;
311 dvb_dmx_swfilter_section_new(feed); 306 dvb_dmx_swfilter_section_new(feed);
312 } 307 }
313 308
314 if (buf[1] & 0x40) { 309 if (buf[1] & 0x40) {
315 // PUSI=1 (is set), section boundary is here 310 /* PUSI=1 (is set), section boundary is here */
316 if (count > 1 && buf[p] < count) { 311 if (count > 1 && buf[p] < count) {
317 const u8 *before = buf+p+1; 312 const u8 *before = &buf[p + 1];
318 u8 before_len = buf[p]; 313 u8 before_len = buf[p];
319 const u8 *after = before+before_len; 314 const u8 *after = &before[before_len];
320 u8 after_len = count-1-before_len; 315 u8 after_len = count - 1 - before_len;
321 316
322 dvb_dmx_swfilter_section_copy_dump(feed, before, before_len); 317 dvb_dmx_swfilter_section_copy_dump(feed, before,
318 before_len);
323 /* before start of new section, set pusi_seen = 1 */ 319 /* before start of new section, set pusi_seen = 1 */
324 feed->pusi_seen = 1; 320 feed->pusi_seen = 1;
325 dvb_dmx_swfilter_section_new(feed); 321 dvb_dmx_swfilter_section_new(feed);
326 dvb_dmx_swfilter_section_copy_dump(feed, after, after_len); 322 dvb_dmx_swfilter_section_copy_dump(feed, after,
323 after_len);
327 } 324 }
328#ifdef DVB_DEMUX_SECTION_LOSS_LOG 325#ifdef DVB_DEMUX_SECTION_LOSS_LOG
329 else 326 else if (count > 0)
330 if (count > 0) 327 printk("dvb_demux.c PUSI=1 but %d bytes lost\n", count);
331 printk("dvb_demux.c PUSI=1 but %d bytes lost\n", count);
332#endif 328#endif
333 } else { 329 } else {
334 // PUSI=0 (is not set), no section boundary 330 /* PUSI=0 (is not set), no section boundary */
335 const u8 *entire = buf+p; 331 dvb_dmx_swfilter_section_copy_dump(feed, &buf[p], count);
336 u8 entire_len = count;
337
338 dvb_dmx_swfilter_section_copy_dump(feed, entire, entire_len);
339 } 332 }
333
340 return 0; 334 return 0;
341} 335}
342 336
343 337static inline void dvb_dmx_swfilter_packet_type(struct dvb_demux_feed *feed,
344static inline void dvb_dmx_swfilter_packet_type(struct dvb_demux_feed *feed, const u8 *buf) 338 const u8 *buf)
345{ 339{
346 switch(feed->type) { 340 switch (feed->type) {
347 case DMX_TYPE_TS: 341 case DMX_TYPE_TS:
348 if (!feed->feed.ts.is_filtering) 342 if (!feed->feed.ts.is_filtering)
349 break; 343 break;
@@ -351,7 +345,8 @@ static inline void dvb_dmx_swfilter_packet_type(struct dvb_demux_feed *feed, con
351 if (feed->ts_type & TS_PAYLOAD_ONLY) 345 if (feed->ts_type & TS_PAYLOAD_ONLY)
352 dvb_dmx_swfilter_payload(feed, buf); 346 dvb_dmx_swfilter_payload(feed, buf);
353 else 347 else
354 feed->cb.ts(buf, 188, NULL, 0, &feed->feed.ts, DMX_OK); 348 feed->cb.ts(buf, 188, NULL, 0, &feed->feed.ts,
349 DMX_OK);
355 } 350 }
356 if (feed->ts_type & TS_DECODER) 351 if (feed->ts_type & TS_DECODER)
357 if (feed->demux->write_to_decoder) 352 if (feed->demux->write_to_decoder)
@@ -362,7 +357,7 @@ static inline void dvb_dmx_swfilter_packet_type(struct dvb_demux_feed *feed, con
362 if (!feed->feed.sec.is_filtering) 357 if (!feed->feed.sec.is_filtering)
363 break; 358 break;
364 if (dvb_dmx_swfilter_section_packet(feed, buf) < 0) 359 if (dvb_dmx_swfilter_section_packet(feed, buf) < 0)
365 feed->feed.sec.seclen = feed->feed.sec.secbufp=0; 360 feed->feed.sec.seclen = feed->feed.sec.secbufp = 0;
366 break; 361 break;
367 362
368 default: 363 default:
@@ -378,7 +373,7 @@ static inline void dvb_dmx_swfilter_packet_type(struct dvb_demux_feed *feed, con
378static void dvb_dmx_swfilter_packet(struct dvb_demux *demux, const u8 *buf) 373static void dvb_dmx_swfilter_packet(struct dvb_demux *demux, const u8 *buf)
379{ 374{
380 struct dvb_demux_feed *feed; 375 struct dvb_demux_feed *feed;
381 struct list_head *pos, *head=&demux->feed_list; 376 struct list_head *pos, *head = &demux->feed_list;
382 u16 pid = ts_pid(buf); 377 u16 pid = ts_pid(buf);
383 int dvr_done = 0; 378 int dvr_done = 0;
384 379
@@ -404,21 +399,21 @@ static void dvb_dmx_swfilter_packet(struct dvb_demux *demux, const u8 *buf)
404 } 399 }
405} 400}
406 401
407void dvb_dmx_swfilter_packets(struct dvb_demux *demux, const u8 *buf, size_t count) 402void dvb_dmx_swfilter_packets(struct dvb_demux *demux, const u8 *buf,
403 size_t count)
408{ 404{
409 spin_lock(&demux->lock); 405 spin_lock(&demux->lock);
410 406
411 while (count--) { 407 while (count--) {
412 if(buf[0] == 0x47) { 408 if (buf[0] == 0x47)
413 dvb_dmx_swfilter_packet(demux, buf); 409 dvb_dmx_swfilter_packet(demux, buf);
414 }
415 buf += 188; 410 buf += 188;
416 } 411 }
417 412
418 spin_unlock(&demux->lock); 413 spin_unlock(&demux->lock);
419} 414}
420EXPORT_SYMBOL(dvb_dmx_swfilter_packets);
421 415
416EXPORT_SYMBOL(dvb_dmx_swfilter_packets);
422 417
423void dvb_dmx_swfilter(struct dvb_demux *demux, const u8 *buf, size_t count) 418void dvb_dmx_swfilter(struct dvb_demux *demux, const u8 *buf, size_t count)
424{ 419{
@@ -426,8 +421,10 @@ void dvb_dmx_swfilter(struct dvb_demux *demux, const u8 *buf, size_t count)
426 421
427 spin_lock(&demux->lock); 422 spin_lock(&demux->lock);
428 423
429 if ((i = demux->tsbufp)) { 424 if (demux->tsbufp) {
430 if (count < (j=188-i)) { 425 i = demux->tsbufp;
426 j = 188 - i;
427 if (count < j) {
431 memcpy(&demux->tsbuf[i], buf, count); 428 memcpy(&demux->tsbuf[i], buf, count);
432 demux->tsbufp += count; 429 demux->tsbufp += count;
433 goto bailout; 430 goto bailout;
@@ -441,13 +438,13 @@ void dvb_dmx_swfilter(struct dvb_demux *demux, const u8 *buf, size_t count)
441 438
442 while (p < count) { 439 while (p < count) {
443 if (buf[p] == 0x47) { 440 if (buf[p] == 0x47) {
444 if (count-p >= 188) { 441 if (count - p >= 188) {
445 dvb_dmx_swfilter_packet(demux, buf+p); 442 dvb_dmx_swfilter_packet(demux, &buf[p]);
446 p += 188; 443 p += 188;
447 } else { 444 } else {
448 i = count-p; 445 i = count - p;
449 memcpy(demux->tsbuf, buf+p, i); 446 memcpy(demux->tsbuf, &buf[p], i);
450 demux->tsbufp=i; 447 demux->tsbufp = i;
451 goto bailout; 448 goto bailout;
452 } 449 }
453 } else 450 } else
@@ -457,24 +454,29 @@ void dvb_dmx_swfilter(struct dvb_demux *demux, const u8 *buf, size_t count)
457bailout: 454bailout:
458 spin_unlock(&demux->lock); 455 spin_unlock(&demux->lock);
459} 456}
457
460EXPORT_SYMBOL(dvb_dmx_swfilter); 458EXPORT_SYMBOL(dvb_dmx_swfilter);
461 459
462void dvb_dmx_swfilter_204(struct dvb_demux *demux, const u8 *buf, size_t count) 460void dvb_dmx_swfilter_204(struct dvb_demux *demux, const u8 *buf, size_t count)
463{ 461{
464 int p = 0,i, j; 462 int p = 0, i, j;
465 u8 tmppack[188]; 463 u8 tmppack[188];
464
466 spin_lock(&demux->lock); 465 spin_lock(&demux->lock);
467 466
468 if ((i = demux->tsbufp)) { 467 if (demux->tsbufp) {
469 if (count < (j=204-i)) { 468 i = demux->tsbufp;
469 j = 204 - i;
470 if (count < j) {
470 memcpy(&demux->tsbuf[i], buf, count); 471 memcpy(&demux->tsbuf[i], buf, count);
471 demux->tsbufp += count; 472 demux->tsbufp += count;
472 goto bailout; 473 goto bailout;
473 } 474 }
474 memcpy(&demux->tsbuf[i], buf, j); 475 memcpy(&demux->tsbuf[i], buf, j);
475 if ((demux->tsbuf[0] == 0x47)|(demux->tsbuf[0]==0xB8)) { 476 if ((demux->tsbuf[0] == 0x47) | (demux->tsbuf[0] == 0xB8)) {
476 memcpy(tmppack, demux->tsbuf, 188); 477 memcpy(tmppack, demux->tsbuf, 188);
477 if (tmppack[0] == 0xB8) tmppack[0] = 0x47; 478 if (tmppack[0] == 0xB8)
479 tmppack[0] = 0x47;
478 dvb_dmx_swfilter_packet(demux, tmppack); 480 dvb_dmx_swfilter_packet(demux, tmppack);
479 } 481 }
480 demux->tsbufp = 0; 482 demux->tsbufp = 0;
@@ -482,16 +484,17 @@ void dvb_dmx_swfilter_204(struct dvb_demux *demux, const u8 *buf, size_t count)
482 } 484 }
483 485
484 while (p < count) { 486 while (p < count) {
485 if ((buf[p] == 0x47)|(buf[p] == 0xB8)) { 487 if ((buf[p] == 0x47) | (buf[p] == 0xB8)) {
486 if (count-p >= 204) { 488 if (count - p >= 204) {
487 memcpy(tmppack, buf+p, 188); 489 memcpy(tmppack, &buf[p], 188);
488 if (tmppack[0] == 0xB8) tmppack[0] = 0x47; 490 if (tmppack[0] == 0xB8)
491 tmppack[0] = 0x47;
489 dvb_dmx_swfilter_packet(demux, tmppack); 492 dvb_dmx_swfilter_packet(demux, tmppack);
490 p += 204; 493 p += 204;
491 } else { 494 } else {
492 i = count-p; 495 i = count - p;
493 memcpy(demux->tsbuf, buf+p, i); 496 memcpy(demux->tsbuf, &buf[p], i);
494 demux->tsbufp=i; 497 demux->tsbufp = i;
495 goto bailout; 498 goto bailout;
496 } 499 }
497 } else { 500 } else {
@@ -502,14 +505,14 @@ void dvb_dmx_swfilter_204(struct dvb_demux *demux, const u8 *buf, size_t count)
502bailout: 505bailout:
503 spin_unlock(&demux->lock); 506 spin_unlock(&demux->lock);
504} 507}
505EXPORT_SYMBOL(dvb_dmx_swfilter_204);
506 508
509EXPORT_SYMBOL(dvb_dmx_swfilter_204);
507 510
508static struct dvb_demux_filter * dvb_dmx_filter_alloc(struct dvb_demux *demux) 511static struct dvb_demux_filter *dvb_dmx_filter_alloc(struct dvb_demux *demux)
509{ 512{
510 int i; 513 int i;
511 514
512 for (i=0; i<demux->filternum; i++) 515 for (i = 0; i < demux->filternum; i++)
513 if (demux->filter[i].state == DMX_STATE_FREE) 516 if (demux->filter[i].state == DMX_STATE_FREE)
514 break; 517 break;
515 518
@@ -521,11 +524,11 @@ static struct dvb_demux_filter * dvb_dmx_filter_alloc(struct dvb_demux *demux)
521 return &demux->filter[i]; 524 return &demux->filter[i];
522} 525}
523 526
524static struct dvb_demux_feed * dvb_dmx_feed_alloc(struct dvb_demux *demux) 527static struct dvb_demux_feed *dvb_dmx_feed_alloc(struct dvb_demux *demux)
525{ 528{
526 int i; 529 int i;
527 530
528 for (i=0; i<demux->feednum; i++) 531 for (i = 0; i < demux->feednum; i++)
529 if (demux->feed[i].state == DMX_STATE_FREE) 532 if (demux->feed[i].state == DMX_STATE_FREE)
530 break; 533 break;
531 534
@@ -553,7 +556,7 @@ static void dvb_demux_feed_add(struct dvb_demux_feed *feed)
553 spin_lock_irq(&feed->demux->lock); 556 spin_lock_irq(&feed->demux->lock);
554 if (dvb_demux_feed_find(feed)) { 557 if (dvb_demux_feed_find(feed)) {
555 printk(KERN_ERR "%s: feed already in list (type=%x state=%x pid=%x)\n", 558 printk(KERN_ERR "%s: feed already in list (type=%x state=%x pid=%x)\n",
556 __FUNCTION__, feed->type, feed->state, feed->pid); 559 __FUNCTION__, feed->type, feed->state, feed->pid);
557 goto out; 560 goto out;
558 } 561 }
559 562
@@ -567,7 +570,7 @@ static void dvb_demux_feed_del(struct dvb_demux_feed *feed)
567 spin_lock_irq(&feed->demux->lock); 570 spin_lock_irq(&feed->demux->lock);
568 if (!(dvb_demux_feed_find(feed))) { 571 if (!(dvb_demux_feed_find(feed))) {
569 printk(KERN_ERR "%s: feed not in list (type=%x state=%x pid=%x)\n", 572 printk(KERN_ERR "%s: feed not in list (type=%x state=%x pid=%x)\n",
570 __FUNCTION__, feed->type, feed->state, feed->pid); 573 __FUNCTION__, feed->type, feed->state, feed->pid);
571 goto out; 574 goto out;
572 } 575 }
573 576
@@ -576,17 +579,17 @@ out:
576 spin_unlock_irq(&feed->demux->lock); 579 spin_unlock_irq(&feed->demux->lock);
577} 580}
578 581
579static int dmx_ts_feed_set (struct dmx_ts_feed* ts_feed, u16 pid, int ts_type, 582static int dmx_ts_feed_set(struct dmx_ts_feed *ts_feed, u16 pid, int ts_type,
580 enum dmx_ts_pes pes_type, size_t circular_buffer_size, 583 enum dmx_ts_pes pes_type,
581 struct timespec timeout) 584 size_t circular_buffer_size, struct timespec timeout)
582{ 585{
583 struct dvb_demux_feed *feed = (struct dvb_demux_feed *) ts_feed; 586 struct dvb_demux_feed *feed = (struct dvb_demux_feed *)ts_feed;
584 struct dvb_demux *demux = feed->demux; 587 struct dvb_demux *demux = feed->demux;
585 588
586 if (pid > DMX_MAX_PID) 589 if (pid > DMX_MAX_PID)
587 return -EINVAL; 590 return -EINVAL;
588 591
589 if (down_interruptible (&demux->mutex)) 592 if (down_interruptible(&demux->mutex))
590 return -ERESTARTSYS; 593 return -ERESTARTSYS;
591 594
592 if (ts_type & TS_DECODER) { 595 if (ts_type & TS_DECODER) {
@@ -615,7 +618,7 @@ static int dmx_ts_feed_set (struct dmx_ts_feed* ts_feed, u16 pid, int ts_type,
615 618
616 if (feed->buffer_size) { 619 if (feed->buffer_size) {
617#ifdef NOBUFS 620#ifdef NOBUFS
618 feed->buffer=NULL; 621 feed->buffer = NULL;
619#else 622#else
620 feed->buffer = vmalloc(feed->buffer_size); 623 feed->buffer = vmalloc(feed->buffer_size);
621 if (!feed->buffer) { 624 if (!feed->buffer) {
@@ -631,14 +634,13 @@ static int dmx_ts_feed_set (struct dmx_ts_feed* ts_feed, u16 pid, int ts_type,
631 return 0; 634 return 0;
632} 635}
633 636
634 637static int dmx_ts_feed_start_filtering(struct dmx_ts_feed *ts_feed)
635static int dmx_ts_feed_start_filtering(struct dmx_ts_feed* ts_feed)
636{ 638{
637 struct dvb_demux_feed *feed = (struct dvb_demux_feed *) ts_feed; 639 struct dvb_demux_feed *feed = (struct dvb_demux_feed *)ts_feed;
638 struct dvb_demux *demux = feed->demux; 640 struct dvb_demux *demux = feed->demux;
639 int ret; 641 int ret;
640 642
641 if (down_interruptible (&demux->mutex)) 643 if (down_interruptible(&demux->mutex))
642 return -ERESTARTSYS; 644 return -ERESTARTSYS;
643 645
644 if (feed->state != DMX_STATE_READY || feed->type != DMX_TYPE_TS) { 646 if (feed->state != DMX_STATE_READY || feed->type != DMX_TYPE_TS) {
@@ -665,13 +667,13 @@ static int dmx_ts_feed_start_filtering(struct dmx_ts_feed* ts_feed)
665 return 0; 667 return 0;
666} 668}
667 669
668static int dmx_ts_feed_stop_filtering(struct dmx_ts_feed* ts_feed) 670static int dmx_ts_feed_stop_filtering(struct dmx_ts_feed *ts_feed)
669{ 671{
670 struct dvb_demux_feed *feed = (struct dvb_demux_feed *) ts_feed; 672 struct dvb_demux_feed *feed = (struct dvb_demux_feed *)ts_feed;
671 struct dvb_demux *demux = feed->demux; 673 struct dvb_demux *demux = feed->demux;
672 int ret; 674 int ret;
673 675
674 if (down_interruptible (&demux->mutex)) 676 if (down_interruptible(&demux->mutex))
675 return -ERESTARTSYS; 677 return -ERESTARTSYS;
676 678
677 if (feed->state < DMX_STATE_GO) { 679 if (feed->state < DMX_STATE_GO) {
@@ -695,13 +697,14 @@ static int dmx_ts_feed_stop_filtering(struct dmx_ts_feed* ts_feed)
695 return ret; 697 return ret;
696} 698}
697 699
698static int dvbdmx_allocate_ts_feed (struct dmx_demux *dmx, struct dmx_ts_feed **ts_feed, 700static int dvbdmx_allocate_ts_feed(struct dmx_demux *dmx,
699 dmx_ts_cb callback) 701 struct dmx_ts_feed **ts_feed,
702 dmx_ts_cb callback)
700{ 703{
701 struct dvb_demux *demux = (struct dvb_demux *) dmx; 704 struct dvb_demux *demux = (struct dvb_demux *)dmx;
702 struct dvb_demux_feed *feed; 705 struct dvb_demux_feed *feed;
703 706
704 if (down_interruptible (&demux->mutex)) 707 if (down_interruptible(&demux->mutex))
705 return -ERESTARTSYS; 708 return -ERESTARTSYS;
706 709
707 if (!(feed = dvb_dmx_feed_alloc(demux))) { 710 if (!(feed = dvb_dmx_feed_alloc(demux))) {
@@ -724,7 +727,6 @@ static int dvbdmx_allocate_ts_feed (struct dmx_demux *dmx, struct dmx_ts_feed **
724 (*ts_feed)->stop_filtering = dmx_ts_feed_stop_filtering; 727 (*ts_feed)->stop_filtering = dmx_ts_feed_stop_filtering;
725 (*ts_feed)->set = dmx_ts_feed_set; 728 (*ts_feed)->set = dmx_ts_feed_set;
726 729
727
728 if (!(feed->filter = dvb_dmx_filter_alloc(demux))) { 730 if (!(feed->filter = dvb_dmx_filter_alloc(demux))) {
729 feed->state = DMX_STATE_FREE; 731 feed->state = DMX_STATE_FREE;
730 up(&demux->mutex); 732 up(&demux->mutex);
@@ -740,22 +742,22 @@ static int dvbdmx_allocate_ts_feed (struct dmx_demux *dmx, struct dmx_ts_feed **
740 return 0; 742 return 0;
741} 743}
742 744
743static int dvbdmx_release_ts_feed(struct dmx_demux *dmx, struct dmx_ts_feed *ts_feed) 745static int dvbdmx_release_ts_feed(struct dmx_demux *dmx,
746 struct dmx_ts_feed *ts_feed)
744{ 747{
745 struct dvb_demux *demux = (struct dvb_demux *) dmx; 748 struct dvb_demux *demux = (struct dvb_demux *)dmx;
746 struct dvb_demux_feed *feed = (struct dvb_demux_feed *) ts_feed; 749 struct dvb_demux_feed *feed = (struct dvb_demux_feed *)ts_feed;
747 750
748 if (down_interruptible (&demux->mutex)) 751 if (down_interruptible(&demux->mutex))
749 return -ERESTARTSYS; 752 return -ERESTARTSYS;
750 753
751 if (feed->state == DMX_STATE_FREE) { 754 if (feed->state == DMX_STATE_FREE) {
752 up(&demux->mutex); 755 up(&demux->mutex);
753 return -EINVAL; 756 return -EINVAL;
754 } 757 }
755
756#ifndef NOBUFS 758#ifndef NOBUFS
757 vfree(feed->buffer); 759 vfree(feed->buffer);
758 feed->buffer=0; 760 feed->buffer = NULL;
759#endif 761#endif
760 762
761 feed->state = DMX_STATE_FREE; 763 feed->state = DMX_STATE_FREE;
@@ -772,19 +774,18 @@ static int dvbdmx_release_ts_feed(struct dmx_demux *dmx, struct dmx_ts_feed *ts_
772 return 0; 774 return 0;
773} 775}
774 776
775
776/****************************************************************************** 777/******************************************************************************
777 * dmx_section_feed API calls 778 * dmx_section_feed API calls
778 ******************************************************************************/ 779 ******************************************************************************/
779 780
780static int dmx_section_feed_allocate_filter(struct dmx_section_feed* feed, 781static int dmx_section_feed_allocate_filter(struct dmx_section_feed *feed,
781 struct dmx_section_filter** filter) 782 struct dmx_section_filter **filter)
782{ 783{
783 struct dvb_demux_feed *dvbdmxfeed = (struct dvb_demux_feed *) feed; 784 struct dvb_demux_feed *dvbdmxfeed = (struct dvb_demux_feed *)feed;
784 struct dvb_demux *dvbdemux = dvbdmxfeed->demux; 785 struct dvb_demux *dvbdemux = dvbdmxfeed->demux;
785 struct dvb_demux_filter *dvbdmxfilter; 786 struct dvb_demux_filter *dvbdmxfilter;
786 787
787 if (down_interruptible (&dvbdemux->mutex)) 788 if (down_interruptible(&dvbdemux->mutex))
788 return -ERESTARTSYS; 789 return -ERESTARTSYS;
789 790
790 dvbdmxfilter = dvb_dmx_filter_alloc(dvbdemux); 791 dvbdmxfilter = dvb_dmx_filter_alloc(dvbdemux);
@@ -808,18 +809,17 @@ static int dmx_section_feed_allocate_filter(struct dmx_section_feed* feed,
808 return 0; 809 return 0;
809} 810}
810 811
811 812static int dmx_section_feed_set(struct dmx_section_feed *feed,
812static int dmx_section_feed_set(struct dmx_section_feed* feed, 813 u16 pid, size_t circular_buffer_size,
813 u16 pid, size_t circular_buffer_size, 814 int check_crc)
814 int check_crc)
815{ 815{
816 struct dvb_demux_feed *dvbdmxfeed = (struct dvb_demux_feed *) feed; 816 struct dvb_demux_feed *dvbdmxfeed = (struct dvb_demux_feed *)feed;
817 struct dvb_demux *dvbdmx = dvbdmxfeed->demux; 817 struct dvb_demux *dvbdmx = dvbdmxfeed->demux;
818 818
819 if (pid > 0x1fff) 819 if (pid > 0x1fff)
820 return -EINVAL; 820 return -EINVAL;
821 821
822 if (down_interruptible (&dvbdmx->mutex)) 822 if (down_interruptible(&dvbdmx->mutex))
823 return -ERESTARTSYS; 823 return -ERESTARTSYS;
824 824
825 dvb_demux_feed_add(dvbdmxfeed); 825 dvb_demux_feed_add(dvbdmxfeed);
@@ -831,7 +831,7 @@ static int dmx_section_feed_set(struct dmx_section_feed* feed,
831#ifdef NOBUFS 831#ifdef NOBUFS
832 dvbdmxfeed->buffer = NULL; 832 dvbdmxfeed->buffer = NULL;
833#else 833#else
834 dvbdmxfeed->buffer=vmalloc(dvbdmxfeed->buffer_size); 834 dvbdmxfeed->buffer = vmalloc(dvbdmxfeed->buffer_size);
835 if (!dvbdmxfeed->buffer) { 835 if (!dvbdmxfeed->buffer) {
836 up(&dvbdmx->mutex); 836 up(&dvbdmx->mutex);
837 return -ENOMEM; 837 return -ENOMEM;
@@ -843,7 +843,6 @@ static int dmx_section_feed_set(struct dmx_section_feed* feed,
843 return 0; 843 return 0;
844} 844}
845 845
846
847static void prepare_secfilters(struct dvb_demux_feed *dvbdmxfeed) 846static void prepare_secfilters(struct dvb_demux_feed *dvbdmxfeed)
848{ 847{
849 int i; 848 int i;
@@ -851,12 +850,12 @@ static void prepare_secfilters(struct dvb_demux_feed *dvbdmxfeed)
851 struct dmx_section_filter *sf; 850 struct dmx_section_filter *sf;
852 u8 mask, mode, doneq; 851 u8 mask, mode, doneq;
853 852
854 if (!(f=dvbdmxfeed->filter)) 853 if (!(f = dvbdmxfeed->filter))
855 return; 854 return;
856 do { 855 do {
857 sf = &f->filter; 856 sf = &f->filter;
858 doneq = 0; 857 doneq = 0;
859 for (i=0; i<DVB_DEMUX_MASK_MAX; i++) { 858 for (i = 0; i < DVB_DEMUX_MASK_MAX; i++) {
860 mode = sf->filter_mode[i]; 859 mode = sf->filter_mode[i];
861 mask = sf->filter_mask[i]; 860 mask = sf->filter_mask[i];
862 f->maskandmode[i] = mask & mode; 861 f->maskandmode[i] = mask & mode;
@@ -866,14 +865,13 @@ static void prepare_secfilters(struct dvb_demux_feed *dvbdmxfeed)
866 } while ((f = f->next)); 865 } while ((f = f->next));
867} 866}
868 867
869
870static int dmx_section_feed_start_filtering(struct dmx_section_feed *feed) 868static int dmx_section_feed_start_filtering(struct dmx_section_feed *feed)
871{ 869{
872 struct dvb_demux_feed *dvbdmxfeed = (struct dvb_demux_feed *) feed; 870 struct dvb_demux_feed *dvbdmxfeed = (struct dvb_demux_feed *)feed;
873 struct dvb_demux *dvbdmx = dvbdmxfeed->demux; 871 struct dvb_demux *dvbdmx = dvbdmxfeed->demux;
874 int ret; 872 int ret;
875 873
876 if (down_interruptible (&dvbdmx->mutex)) 874 if (down_interruptible(&dvbdmx->mutex))
877 return -ERESTARTSYS; 875 return -ERESTARTSYS;
878 876
879 if (feed->is_filtering) { 877 if (feed->is_filtering) {
@@ -912,14 +910,13 @@ static int dmx_section_feed_start_filtering(struct dmx_section_feed *feed)
912 return 0; 910 return 0;
913} 911}
914 912
915 913static int dmx_section_feed_stop_filtering(struct dmx_section_feed *feed)
916static int dmx_section_feed_stop_filtering(struct dmx_section_feed* feed)
917{ 914{
918 struct dvb_demux_feed *dvbdmxfeed = (struct dvb_demux_feed *) feed; 915 struct dvb_demux_feed *dvbdmxfeed = (struct dvb_demux_feed *)feed;
919 struct dvb_demux *dvbdmx = dvbdmxfeed->demux; 916 struct dvb_demux *dvbdmx = dvbdmxfeed->demux;
920 int ret; 917 int ret;
921 918
922 if (down_interruptible (&dvbdmx->mutex)) 919 if (down_interruptible(&dvbdmx->mutex))
923 return -ERESTARTSYS; 920 return -ERESTARTSYS;
924 921
925 if (!dvbdmx->stop_feed) { 922 if (!dvbdmx->stop_feed) {
@@ -938,15 +935,14 @@ static int dmx_section_feed_stop_filtering(struct dmx_section_feed* feed)
938 return ret; 935 return ret;
939} 936}
940 937
941
942static int dmx_section_feed_release_filter(struct dmx_section_feed *feed, 938static int dmx_section_feed_release_filter(struct dmx_section_feed *feed,
943 struct dmx_section_filter* filter) 939 struct dmx_section_filter *filter)
944{ 940{
945 struct dvb_demux_filter *dvbdmxfilter = (struct dvb_demux_filter *) filter, *f; 941 struct dvb_demux_filter *dvbdmxfilter = (struct dvb_demux_filter *)filter, *f;
946 struct dvb_demux_feed *dvbdmxfeed = (struct dvb_demux_feed *) feed; 942 struct dvb_demux_feed *dvbdmxfeed = (struct dvb_demux_feed *)feed;
947 struct dvb_demux *dvbdmx = dvbdmxfeed->demux; 943 struct dvb_demux *dvbdmx = dvbdmxfeed->demux;
948 944
949 if (down_interruptible (&dvbdmx->mutex)) 945 if (down_interruptible(&dvbdmx->mutex))
950 return -ERESTARTSYS; 946 return -ERESTARTSYS;
951 947
952 if (dvbdmxfilter->feed != dvbdmxfeed) { 948 if (dvbdmxfilter->feed != dvbdmxfeed) {
@@ -963,7 +959,7 @@ static int dmx_section_feed_release_filter(struct dmx_section_feed *feed,
963 if (f == dvbdmxfilter) { 959 if (f == dvbdmxfilter) {
964 dvbdmxfeed->filter = dvbdmxfilter->next; 960 dvbdmxfeed->filter = dvbdmxfilter->next;
965 } else { 961 } else {
966 while(f->next != dvbdmxfilter) 962 while (f->next != dvbdmxfilter)
967 f = f->next; 963 f = f->next;
968 f->next = f->next->next; 964 f->next = f->next->next;
969 } 965 }
@@ -978,10 +974,10 @@ static int dvbdmx_allocate_section_feed(struct dmx_demux *demux,
978 struct dmx_section_feed **feed, 974 struct dmx_section_feed **feed,
979 dmx_section_cb callback) 975 dmx_section_cb callback)
980{ 976{
981 struct dvb_demux *dvbdmx = (struct dvb_demux *) demux; 977 struct dvb_demux *dvbdmx = (struct dvb_demux *)demux;
982 struct dvb_demux_feed *dvbdmxfeed; 978 struct dvb_demux_feed *dvbdmxfeed;
983 979
984 if (down_interruptible (&dvbdmx->mutex)) 980 if (down_interruptible(&dvbdmx->mutex))
985 return -ERESTARTSYS; 981 return -ERESTARTSYS;
986 982
987 if (!(dvbdmxfeed = dvb_dmx_feed_alloc(dvbdmx))) { 983 if (!(dvbdmxfeed = dvb_dmx_feed_alloc(dvbdmx))) {
@@ -999,7 +995,7 @@ static int dvbdmx_allocate_section_feed(struct dmx_demux *demux,
999 dvbdmxfeed->filter = NULL; 995 dvbdmxfeed->filter = NULL;
1000 dvbdmxfeed->buffer = NULL; 996 dvbdmxfeed->buffer = NULL;
1001 997
1002 (*feed)=&dvbdmxfeed->feed.sec; 998 (*feed) = &dvbdmxfeed->feed.sec;
1003 (*feed)->is_filtering = 0; 999 (*feed)->is_filtering = 0;
1004 (*feed)->parent = demux; 1000 (*feed)->parent = demux;
1005 (*feed)->priv = NULL; 1001 (*feed)->priv = NULL;
@@ -1017,21 +1013,21 @@ static int dvbdmx_allocate_section_feed(struct dmx_demux *demux,
1017static int dvbdmx_release_section_feed(struct dmx_demux *demux, 1013static int dvbdmx_release_section_feed(struct dmx_demux *demux,
1018 struct dmx_section_feed *feed) 1014 struct dmx_section_feed *feed)
1019{ 1015{
1020 struct dvb_demux_feed *dvbdmxfeed = (struct dvb_demux_feed *) feed; 1016 struct dvb_demux_feed *dvbdmxfeed = (struct dvb_demux_feed *)feed;
1021 struct dvb_demux *dvbdmx = (struct dvb_demux *) demux; 1017 struct dvb_demux *dvbdmx = (struct dvb_demux *)demux;
1022 1018
1023 if (down_interruptible (&dvbdmx->mutex)) 1019 if (down_interruptible(&dvbdmx->mutex))
1024 return -ERESTARTSYS; 1020 return -ERESTARTSYS;
1025 1021
1026 if (dvbdmxfeed->state==DMX_STATE_FREE) { 1022 if (dvbdmxfeed->state == DMX_STATE_FREE) {
1027 up(&dvbdmx->mutex); 1023 up(&dvbdmx->mutex);
1028 return -EINVAL; 1024 return -EINVAL;
1029 } 1025 }
1030#ifndef NOBUFS 1026#ifndef NOBUFS
1031 vfree(dvbdmxfeed->buffer); 1027 vfree(dvbdmxfeed->buffer);
1032 dvbdmxfeed->buffer=0; 1028 dvbdmxfeed->buffer = NULL;
1033#endif 1029#endif
1034 dvbdmxfeed->state=DMX_STATE_FREE; 1030 dvbdmxfeed->state = DMX_STATE_FREE;
1035 1031
1036 dvb_demux_feed_del(dvbdmxfeed); 1032 dvb_demux_feed_del(dvbdmxfeed);
1037 1033
@@ -1041,14 +1037,13 @@ static int dvbdmx_release_section_feed(struct dmx_demux *demux,
1041 return 0; 1037 return 0;
1042} 1038}
1043 1039
1044
1045/****************************************************************************** 1040/******************************************************************************
1046 * dvb_demux kernel data API calls 1041 * dvb_demux kernel data API calls
1047 ******************************************************************************/ 1042 ******************************************************************************/
1048 1043
1049static int dvbdmx_open(struct dmx_demux *demux) 1044static int dvbdmx_open(struct dmx_demux *demux)
1050{ 1045{
1051 struct dvb_demux *dvbdemux = (struct dvb_demux *) demux; 1046 struct dvb_demux *dvbdemux = (struct dvb_demux *)demux;
1052 1047
1053 if (dvbdemux->users >= MAX_DVB_DEMUX_USERS) 1048 if (dvbdemux->users >= MAX_DVB_DEMUX_USERS)
1054 return -EUSERS; 1049 return -EUSERS;
@@ -1057,10 +1052,9 @@ static int dvbdmx_open(struct dmx_demux *demux)
1057 return 0; 1052 return 0;
1058} 1053}
1059 1054
1060
1061static int dvbdmx_close(struct dmx_demux *demux) 1055static int dvbdmx_close(struct dmx_demux *demux)
1062{ 1056{
1063 struct dvb_demux *dvbdemux = (struct dvb_demux *) demux; 1057 struct dvb_demux *dvbdemux = (struct dvb_demux *)demux;
1064 1058
1065 if (dvbdemux->users == 0) 1059 if (dvbdemux->users == 0)
1066 return -ENODEV; 1060 return -ENODEV;
@@ -1070,15 +1064,14 @@ static int dvbdmx_close(struct dmx_demux *demux)
1070 return 0; 1064 return 0;
1071} 1065}
1072 1066
1073
1074static int dvbdmx_write(struct dmx_demux *demux, const char *buf, size_t count) 1067static int dvbdmx_write(struct dmx_demux *demux, const char *buf, size_t count)
1075{ 1068{
1076 struct dvb_demux *dvbdemux=(struct dvb_demux *) demux; 1069 struct dvb_demux *dvbdemux = (struct dvb_demux *)demux;
1077 1070
1078 if ((!demux->frontend) || (demux->frontend->source != DMX_MEMORY_FE)) 1071 if ((!demux->frontend) || (demux->frontend->source != DMX_MEMORY_FE))
1079 return -EINVAL; 1072 return -EINVAL;
1080 1073
1081 if (down_interruptible (&dvbdemux->mutex)) 1074 if (down_interruptible(&dvbdemux->mutex))
1082 return -ERESTARTSYS; 1075 return -ERESTARTSYS;
1083 dvb_dmx_swfilter(dvbdemux, buf, count); 1076 dvb_dmx_swfilter(dvbdemux, buf, count);
1084 up(&dvbdemux->mutex); 1077 up(&dvbdemux->mutex);
@@ -1088,10 +1081,10 @@ static int dvbdmx_write(struct dmx_demux *demux, const char *buf, size_t count)
1088 return count; 1081 return count;
1089} 1082}
1090 1083
1091 1084static int dvbdmx_add_frontend(struct dmx_demux *demux,
1092static int dvbdmx_add_frontend(struct dmx_demux *demux, struct dmx_frontend *frontend) 1085 struct dmx_frontend *frontend)
1093{ 1086{
1094 struct dvb_demux *dvbdemux = (struct dvb_demux *) demux; 1087 struct dvb_demux *dvbdemux = (struct dvb_demux *)demux;
1095 struct list_head *head = &dvbdemux->frontend_list; 1088 struct list_head *head = &dvbdemux->frontend_list;
1096 1089
1097 list_add(&(frontend->connectivity_list), head); 1090 list_add(&(frontend->connectivity_list), head);
@@ -1099,13 +1092,13 @@ static int dvbdmx_add_frontend(struct dmx_demux *demux, struct dmx_frontend *fro
1099 return 0; 1092 return 0;
1100} 1093}
1101 1094
1102 1095static int dvbdmx_remove_frontend(struct dmx_demux *demux,
1103static int dvbdmx_remove_frontend(struct dmx_demux *demux, struct dmx_frontend *frontend) 1096 struct dmx_frontend *frontend)
1104{ 1097{
1105 struct dvb_demux *dvbdemux = (struct dvb_demux *) demux; 1098 struct dvb_demux *dvbdemux = (struct dvb_demux *)demux;
1106 struct list_head *pos, *n, *head = &dvbdemux->frontend_list; 1099 struct list_head *pos, *n, *head = &dvbdemux->frontend_list;
1107 1100
1108 list_for_each_safe (pos, n, head) { 1101 list_for_each_safe(pos, n, head) {
1109 if (DMX_FE_ENTRY(pos) == frontend) { 1102 if (DMX_FE_ENTRY(pos) == frontend) {
1110 list_del(pos); 1103 list_del(pos);
1111 return 0; 1104 return 0;
@@ -1115,25 +1108,25 @@ static int dvbdmx_remove_frontend(struct dmx_demux *demux, struct dmx_frontend *
1115 return -ENODEV; 1108 return -ENODEV;
1116} 1109}
1117 1110
1118 1111static struct list_head *dvbdmx_get_frontends(struct dmx_demux *demux)
1119static struct list_head * dvbdmx_get_frontends(struct dmx_demux *demux)
1120{ 1112{
1121 struct dvb_demux *dvbdemux = (struct dvb_demux *) demux; 1113 struct dvb_demux *dvbdemux = (struct dvb_demux *)demux;
1122 1114
1123 if (list_empty(&dvbdemux->frontend_list)) 1115 if (list_empty(&dvbdemux->frontend_list))
1124 return NULL; 1116 return NULL;
1117
1125 return &dvbdemux->frontend_list; 1118 return &dvbdemux->frontend_list;
1126} 1119}
1127 1120
1128 1121static int dvbdmx_connect_frontend(struct dmx_demux *demux,
1129static int dvbdmx_connect_frontend(struct dmx_demux *demux, struct dmx_frontend *frontend) 1122 struct dmx_frontend *frontend)
1130{ 1123{
1131 struct dvb_demux *dvbdemux = (struct dvb_demux *) demux; 1124 struct dvb_demux *dvbdemux = (struct dvb_demux *)demux;
1132 1125
1133 if (demux->frontend) 1126 if (demux->frontend)
1134 return -EINVAL; 1127 return -EINVAL;
1135 1128
1136 if (down_interruptible (&dvbdemux->mutex)) 1129 if (down_interruptible(&dvbdemux->mutex))
1137 return -ERESTARTSYS; 1130 return -ERESTARTSYS;
1138 1131
1139 demux->frontend = frontend; 1132 demux->frontend = frontend;
@@ -1141,12 +1134,11 @@ static int dvbdmx_connect_frontend(struct dmx_demux *demux, struct dmx_frontend
1141 return 0; 1134 return 0;
1142} 1135}
1143 1136
1144
1145static int dvbdmx_disconnect_frontend(struct dmx_demux *demux) 1137static int dvbdmx_disconnect_frontend(struct dmx_demux *demux)
1146{ 1138{
1147 struct dvb_demux *dvbdemux = (struct dvb_demux *) demux; 1139 struct dvb_demux *dvbdemux = (struct dvb_demux *)demux;
1148 1140
1149 if (down_interruptible (&dvbdemux->mutex)) 1141 if (down_interruptible(&dvbdemux->mutex))
1150 return -ERESTARTSYS; 1142 return -ERESTARTSYS;
1151 1143
1152 demux->frontend = NULL; 1144 demux->frontend = NULL;
@@ -1154,44 +1146,42 @@ static int dvbdmx_disconnect_frontend(struct dmx_demux *demux)
1154 return 0; 1146 return 0;
1155} 1147}
1156 1148
1157 1149static int dvbdmx_get_pes_pids(struct dmx_demux *demux, u16 * pids)
1158static int dvbdmx_get_pes_pids(struct dmx_demux *demux, u16 *pids)
1159{ 1150{
1160 struct dvb_demux *dvbdemux = (struct dvb_demux *) demux; 1151 struct dvb_demux *dvbdemux = (struct dvb_demux *)demux;
1161 1152
1162 memcpy(pids, dvbdemux->pids, 5*sizeof(u16)); 1153 memcpy(pids, dvbdemux->pids, 5 * sizeof(u16));
1163 return 0; 1154 return 0;
1164} 1155}
1165 1156
1166
1167int dvb_dmx_init(struct dvb_demux *dvbdemux) 1157int dvb_dmx_init(struct dvb_demux *dvbdemux)
1168{ 1158{
1169 int i; 1159 int i;
1170 struct dmx_demux *dmx = &dvbdemux->dmx; 1160 struct dmx_demux *dmx = &dvbdemux->dmx;
1171 1161
1172 dvbdemux->users = 0; 1162 dvbdemux->users = 0;
1173 dvbdemux->filter = vmalloc(dvbdemux->filternum*sizeof(struct dvb_demux_filter)); 1163 dvbdemux->filter = vmalloc(dvbdemux->filternum * sizeof(struct dvb_demux_filter));
1174 1164
1175 if (!dvbdemux->filter) 1165 if (!dvbdemux->filter)
1176 return -ENOMEM; 1166 return -ENOMEM;
1177 1167
1178 dvbdemux->feed = vmalloc(dvbdemux->feednum*sizeof(struct dvb_demux_feed)); 1168 dvbdemux->feed = vmalloc(dvbdemux->feednum * sizeof(struct dvb_demux_feed));
1179 if (!dvbdemux->feed) { 1169 if (!dvbdemux->feed) {
1180 vfree(dvbdemux->filter); 1170 vfree(dvbdemux->filter);
1181 return -ENOMEM; 1171 return -ENOMEM;
1182 } 1172 }
1183 for (i=0; i<dvbdemux->filternum; i++) { 1173 for (i = 0; i < dvbdemux->filternum; i++) {
1184 dvbdemux->filter[i].state = DMX_STATE_FREE; 1174 dvbdemux->filter[i].state = DMX_STATE_FREE;
1185 dvbdemux->filter[i].index = i; 1175 dvbdemux->filter[i].index = i;
1186 } 1176 }
1187 for (i=0; i<dvbdemux->feednum; i++) { 1177 for (i = 0; i < dvbdemux->feednum; i++) {
1188 dvbdemux->feed[i].state = DMX_STATE_FREE; 1178 dvbdemux->feed[i].state = DMX_STATE_FREE;
1189 dvbdemux->feed[i].index = i; 1179 dvbdemux->feed[i].index = i;
1190 } 1180 }
1191 1181
1192 INIT_LIST_HEAD(&dvbdemux->frontend_list); 1182 INIT_LIST_HEAD(&dvbdemux->frontend_list);
1193 1183
1194 for (i=0; i<DMX_TS_PES_OTHER; i++) { 1184 for (i = 0; i < DMX_TS_PES_OTHER; i++) {
1195 dvbdemux->pesfilter[i] = NULL; 1185 dvbdemux->pesfilter[i] = NULL;
1196 dvbdemux->pids[i] = 0xffff; 1186 dvbdemux->pids[i] = 0xffff;
1197 } 1187 }
@@ -1205,11 +1195,11 @@ int dvb_dmx_init(struct dvb_demux *dvbdemux)
1205 if (!dvbdemux->check_crc32) 1195 if (!dvbdemux->check_crc32)
1206 dvbdemux->check_crc32 = dvb_dmx_crc32; 1196 dvbdemux->check_crc32 = dvb_dmx_crc32;
1207 1197
1208 if (!dvbdemux->memcopy) 1198 if (!dvbdemux->memcopy)
1209 dvbdemux->memcopy = dvb_dmx_memcopy; 1199 dvbdemux->memcopy = dvb_dmx_memcopy;
1210 1200
1211 dmx->frontend = NULL; 1201 dmx->frontend = NULL;
1212 dmx->priv = (void *) dvbdemux; 1202 dmx->priv = dvbdemux;
1213 dmx->open = dvbdmx_open; 1203 dmx->open = dvbdmx_open;
1214 dmx->close = dvbdmx_close; 1204 dmx->close = dvbdmx_close;
1215 dmx->write = dvbdmx_write; 1205 dmx->write = dvbdmx_write;
@@ -1230,12 +1220,13 @@ int dvb_dmx_init(struct dvb_demux *dvbdemux)
1230 1220
1231 return 0; 1221 return 0;
1232} 1222}
1233EXPORT_SYMBOL(dvb_dmx_init);
1234 1223
1224EXPORT_SYMBOL(dvb_dmx_init);
1235 1225
1236void dvb_dmx_release(struct dvb_demux *dvbdemux) 1226void dvb_dmx_release(struct dvb_demux *dvbdemux)
1237{ 1227{
1238 vfree(dvbdemux->filter); 1228 vfree(dvbdemux->filter);
1239 vfree(dvbdemux->feed); 1229 vfree(dvbdemux->feed);
1240} 1230}
1231
1241EXPORT_SYMBOL(dvb_dmx_release); 1232EXPORT_SYMBOL(dvb_dmx_release);
diff --git a/drivers/media/dvb/dvb-core/dvb_demux.h b/drivers/media/dvb/dvb-core/dvb_demux.h
index d149f2a96d09..0cc888339d52 100644
--- a/drivers/media/dvb/dvb-core/dvb_demux.h
+++ b/drivers/media/dvb/dvb-core/dvb_demux.h
@@ -20,7 +20,6 @@
20 * 20 *
21 */ 21 */
22 22
23
24#ifndef _DVB_DEMUX_H_ 23#ifndef _DVB_DEMUX_H_
25#define _DVB_DEMUX_H_ 24#define _DVB_DEMUX_H_
26 25
@@ -44,98 +43,98 @@
44#define DVB_DEMUX_MASK_MAX 18 43#define DVB_DEMUX_MASK_MAX 18
45 44
46struct dvb_demux_filter { 45struct dvb_demux_filter {
47 struct dmx_section_filter filter; 46 struct dmx_section_filter filter;
48 u8 maskandmode [DMX_MAX_FILTER_SIZE]; 47 u8 maskandmode[DMX_MAX_FILTER_SIZE];
49 u8 maskandnotmode [DMX_MAX_FILTER_SIZE]; 48 u8 maskandnotmode[DMX_MAX_FILTER_SIZE];
50 int doneq; 49 int doneq;
51 50
52 struct dvb_demux_filter *next; 51 struct dvb_demux_filter *next;
53 struct dvb_demux_feed *feed; 52 struct dvb_demux_feed *feed;
54 int index; 53 int index;
55 int state; 54 int state;
56 int type; 55 int type;
57 56
58 u16 hw_handle; 57 u16 hw_handle;
59 struct timer_list timer; 58 struct timer_list timer;
60}; 59};
61 60
62
63#define DMX_FEED_ENTRY(pos) list_entry(pos, struct dvb_demux_feed, list_head) 61#define DMX_FEED_ENTRY(pos) list_entry(pos, struct dvb_demux_feed, list_head)
64 62
65struct dvb_demux_feed { 63struct dvb_demux_feed {
66 union { 64 union {
67 struct dmx_ts_feed ts; 65 struct dmx_ts_feed ts;
68 struct dmx_section_feed sec; 66 struct dmx_section_feed sec;
69 } feed; 67 } feed;
70 68
71 union { 69 union {
72 dmx_ts_cb ts; 70 dmx_ts_cb ts;
73 dmx_section_cb sec; 71 dmx_section_cb sec;
74 } cb; 72 } cb;
75 73
76 struct dvb_demux *demux; 74 struct dvb_demux *demux;
77 void *priv; 75 void *priv;
78 int type; 76 int type;
79 int state; 77 int state;
80 u16 pid; 78 u16 pid;
81 u8 *buffer; 79 u8 *buffer;
82 int buffer_size; 80 int buffer_size;
83 81
84 struct timespec timeout; 82 struct timespec timeout;
85 struct dvb_demux_filter *filter; 83 struct dvb_demux_filter *filter;
86 84
87 int ts_type; 85 int ts_type;
88 enum dmx_ts_pes pes_type; 86 enum dmx_ts_pes pes_type;
89 87
90 int cc; 88 int cc;
91 int pusi_seen; /* prevents feeding of garbage from previous section */ 89 int pusi_seen; /* prevents feeding of garbage from previous section */
92 90
93 u16 peslen; 91 u16 peslen;
94 92
95 struct list_head list_head; 93 struct list_head list_head;
96 unsigned int index; /* a unique index for each feed (can be used as hardware pid filter index) */ 94 unsigned int index; /* a unique index for each feed (can be used as hardware pid filter index) */
97}; 95};
98 96
99struct dvb_demux { 97struct dvb_demux {
100 struct dmx_demux dmx; 98 struct dmx_demux dmx;
101 void *priv; 99 void *priv;
102 int filternum; 100 int filternum;
103 int feednum; 101 int feednum;
104 int (*start_feed) (struct dvb_demux_feed *feed); 102 int (*start_feed)(struct dvb_demux_feed *feed);
105 int (*stop_feed) (struct dvb_demux_feed *feed); 103 int (*stop_feed)(struct dvb_demux_feed *feed);
106 int (*write_to_decoder) (struct dvb_demux_feed *feed, 104 int (*write_to_decoder)(struct dvb_demux_feed *feed,
107 const u8 *buf, size_t len); 105 const u8 *buf, size_t len);
108 u32 (*check_crc32) (struct dvb_demux_feed *feed, 106 u32 (*check_crc32)(struct dvb_demux_feed *feed,
109 const u8 *buf, size_t len); 107 const u8 *buf, size_t len);
110 void (*memcopy) (struct dvb_demux_feed *feed, u8 *dst, 108 void (*memcopy)(struct dvb_demux_feed *feed, u8 *dst,
111 const u8 *src, size_t len); 109 const u8 *src, size_t len);
112 110
113 int users; 111 int users;
114#define MAX_DVB_DEMUX_USERS 10 112#define MAX_DVB_DEMUX_USERS 10
115 struct dvb_demux_filter *filter; 113 struct dvb_demux_filter *filter;
116 struct dvb_demux_feed *feed; 114 struct dvb_demux_feed *feed;
117 115
118 struct list_head frontend_list; 116 struct list_head frontend_list;
119 117
120 struct dvb_demux_feed *pesfilter[DMX_TS_PES_OTHER]; 118 struct dvb_demux_feed *pesfilter[DMX_TS_PES_OTHER];
121 u16 pids[DMX_TS_PES_OTHER]; 119 u16 pids[DMX_TS_PES_OTHER];
122 int playing; 120 int playing;
123 int recording; 121 int recording;
124 122
125#define DMX_MAX_PID 0x2000 123#define DMX_MAX_PID 0x2000
126 struct list_head feed_list; 124 struct list_head feed_list;
127 u8 tsbuf[204]; 125 u8 tsbuf[204];
128 int tsbufp; 126 int tsbufp;
129 127
130 struct semaphore mutex; 128 struct semaphore mutex;
131 spinlock_t lock; 129 spinlock_t lock;
132}; 130};
133 131
134
135int dvb_dmx_init(struct dvb_demux *dvbdemux); 132int dvb_dmx_init(struct dvb_demux *dvbdemux);
136void dvb_dmx_release(struct dvb_demux *dvbdemux); 133void dvb_dmx_release(struct dvb_demux *dvbdemux);
137void dvb_dmx_swfilter_packets(struct dvb_demux *dvbdmx, const u8 *buf, size_t count); 134void dvb_dmx_swfilter_packets(struct dvb_demux *dvbdmx, const u8 *buf,
135 size_t count);
138void dvb_dmx_swfilter(struct dvb_demux *demux, const u8 *buf, size_t count); 136void dvb_dmx_swfilter(struct dvb_demux *demux, const u8 *buf, size_t count);
139void dvb_dmx_swfilter_204(struct dvb_demux *demux, const u8 *buf, size_t count); 137void dvb_dmx_swfilter_204(struct dvb_demux *demux, const u8 *buf,
138 size_t count);
140 139
141#endif /* _DVB_DEMUX_H_ */ 140#endif /* _DVB_DEMUX_H_ */