Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * dvb_demux.c - DVB kernel demux API |
| 3 | * |
| 4 | * Copyright (C) 2000-2001 Ralph Metzler <ralph@convergence.de> |
| 5 | * & Marcus Metzler <marcus@convergence.de> |
| 6 | * for convergence integrated media GmbH |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or |
| 9 | * modify it under the terms of the GNU Lesser General Public License |
| 10 | * as published by the Free Software Foundation; either version 2.1 |
| 11 | * of the License, or (at your option) any later version. |
| 12 | * |
| 13 | * This program is distributed in the hope that it will be useful, |
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | * GNU General Public License for more details. |
| 17 | * |
| 18 | * You should have received a copy of the GNU Lesser General Public License |
| 19 | * along with this program; if not, write to the Free Software |
| 20 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
| 21 | * |
| 22 | */ |
| 23 | |
Alexey Dobriyan | a99bbaf | 2009-10-04 16:11:37 +0400 | [diff] [blame] | 24 | #include <linux/sched.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 25 | #include <linux/spinlock.h> |
| 26 | #include <linux/slab.h> |
| 27 | #include <linux/vmalloc.h> |
| 28 | #include <linux/module.h> |
| 29 | #include <linux/poll.h> |
| 30 | #include <linux/string.h> |
| 31 | #include <linux/crc32.h> |
| 32 | #include <asm/uaccess.h> |
Abylay Ospan | 26b9d6c | 2009-11-01 18:46:53 -0300 | [diff] [blame] | 33 | #include <asm/div64.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 34 | |
| 35 | #include "dvb_demux.h" |
| 36 | |
| 37 | #define NOBUFS |
| 38 | /* |
| 39 | ** #define DVB_DEMUX_SECTION_LOSS_LOG to monitor payload loss in the syslog |
| 40 | */ |
| 41 | // #define DVB_DEMUX_SECTION_LOSS_LOG |
| 42 | |
Abylay Ospan | 0d83463 | 2009-06-06 09:31:34 -0300 | [diff] [blame] | 43 | static int dvb_demux_tscheck; |
| 44 | module_param(dvb_demux_tscheck, int, 0644); |
| 45 | MODULE_PARM_DESC(dvb_demux_tscheck, |
| 46 | "enable transport stream continuity and TEI check"); |
| 47 | |
Abylay Ospan | 26b9d6c | 2009-11-01 18:46:53 -0300 | [diff] [blame] | 48 | static int dvb_demux_speedcheck; |
| 49 | module_param(dvb_demux_speedcheck, int, 0644); |
| 50 | MODULE_PARM_DESC(dvb_demux_speedcheck, |
| 51 | "enable transport stream speed check"); |
| 52 | |
Michael Krufky | ae53020 | 2012-05-21 17:47:15 -0300 | [diff] [blame] | 53 | static int dvb_demux_feed_err_pkts = 1; |
| 54 | module_param(dvb_demux_feed_err_pkts, int, 0644); |
| 55 | MODULE_PARM_DESC(dvb_demux_feed_err_pkts, |
| 56 | "when set to 0, drop packets with the TEI bit set (1 by default)"); |
| 57 | |
Abylay Ospan | 0d83463 | 2009-06-06 09:31:34 -0300 | [diff] [blame] | 58 | #define dprintk_tscheck(x...) do { \ |
| 59 | if (dvb_demux_tscheck && printk_ratelimit()) \ |
| 60 | printk(x); \ |
| 61 | } while (0) |
| 62 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 63 | /****************************************************************************** |
| 64 | * static inlined helper functions |
| 65 | ******************************************************************************/ |
| 66 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 67 | static inline u16 section_length(const u8 *buf) |
| 68 | { |
Andreas Oberritter | dad4a73 | 2005-09-09 13:02:26 -0700 | [diff] [blame] | 69 | return 3 + ((buf[1] & 0x0f) << 8) + buf[2]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 70 | } |
| 71 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 72 | static inline u16 ts_pid(const u8 *buf) |
| 73 | { |
Andreas Oberritter | dad4a73 | 2005-09-09 13:02:26 -0700 | [diff] [blame] | 74 | return ((buf[1] & 0x1f) << 8) + buf[2]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 75 | } |
| 76 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 77 | static inline u8 payload(const u8 *tsp) |
| 78 | { |
Andreas Oberritter | dad4a73 | 2005-09-09 13:02:26 -0700 | [diff] [blame] | 79 | if (!(tsp[3] & 0x10)) // no payload? |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 80 | return 0; |
Andreas Oberritter | dad4a73 | 2005-09-09 13:02:26 -0700 | [diff] [blame] | 81 | |
| 82 | if (tsp[3] & 0x20) { // adaptation field? |
| 83 | if (tsp[4] > 183) // corrupted data? |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 84 | return 0; |
| 85 | else |
Andreas Oberritter | dad4a73 | 2005-09-09 13:02:26 -0700 | [diff] [blame] | 86 | return 184 - 1 - tsp[4]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 87 | } |
Andreas Oberritter | dad4a73 | 2005-09-09 13:02:26 -0700 | [diff] [blame] | 88 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 89 | return 184; |
| 90 | } |
| 91 | |
Andreas Oberritter | dad4a73 | 2005-09-09 13:02:26 -0700 | [diff] [blame] | 92 | static u32 dvb_dmx_crc32(struct dvb_demux_feed *f, const u8 *src, size_t len) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 93 | { |
Andreas Oberritter | dad4a73 | 2005-09-09 13:02:26 -0700 | [diff] [blame] | 94 | return (f->feed.sec.crc_val = crc32_be(f->feed.sec.crc_val, src, len)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 95 | } |
| 96 | |
Andreas Oberritter | dad4a73 | 2005-09-09 13:02:26 -0700 | [diff] [blame] | 97 | static void dvb_dmx_memcopy(struct dvb_demux_feed *f, u8 *d, const u8 *s, |
| 98 | size_t len) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 99 | { |
Andreas Oberritter | dad4a73 | 2005-09-09 13:02:26 -0700 | [diff] [blame] | 100 | memcpy(d, s, len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 101 | } |
| 102 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 103 | /****************************************************************************** |
| 104 | * Software filter functions |
| 105 | ******************************************************************************/ |
| 106 | |
Andreas Oberritter | dad4a73 | 2005-09-09 13:02:26 -0700 | [diff] [blame] | 107 | static inline int dvb_dmx_swfilter_payload(struct dvb_demux_feed *feed, |
| 108 | const u8 *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 109 | { |
| 110 | int count = payload(buf); |
| 111 | int p; |
| 112 | //int ccok; |
| 113 | //u8 cc; |
| 114 | |
| 115 | if (count == 0) |
| 116 | return -1; |
| 117 | |
Andreas Oberritter | dad4a73 | 2005-09-09 13:02:26 -0700 | [diff] [blame] | 118 | p = 188 - count; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 119 | |
| 120 | /* |
Andreas Oberritter | dad4a73 | 2005-09-09 13:02:26 -0700 | [diff] [blame] | 121 | cc = buf[3] & 0x0f; |
| 122 | ccok = ((feed->cc + 1) & 0x0f) == cc; |
| 123 | feed->cc = cc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 124 | if (!ccok) |
| 125 | printk("missed packet!\n"); |
| 126 | */ |
| 127 | |
Andreas Oberritter | dad4a73 | 2005-09-09 13:02:26 -0700 | [diff] [blame] | 128 | if (buf[1] & 0x40) // PUSI ? |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 129 | feed->peslen = 0xfffa; |
| 130 | |
| 131 | feed->peslen += count; |
| 132 | |
Andreas Oberritter | dad4a73 | 2005-09-09 13:02:26 -0700 | [diff] [blame] | 133 | return feed->cb.ts(&buf[p], count, NULL, 0, &feed->feed.ts, DMX_OK); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 134 | } |
| 135 | |
Andreas Oberritter | dad4a73 | 2005-09-09 13:02:26 -0700 | [diff] [blame] | 136 | static int dvb_dmx_swfilter_sectionfilter(struct dvb_demux_feed *feed, |
| 137 | struct dvb_demux_filter *f) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 138 | { |
| 139 | u8 neq = 0; |
| 140 | int i; |
| 141 | |
Andreas Oberritter | dad4a73 | 2005-09-09 13:02:26 -0700 | [diff] [blame] | 142 | for (i = 0; i < DVB_DEMUX_MASK_MAX; i++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 143 | u8 xor = f->filter.filter_value[i] ^ feed->feed.sec.secbuf[i]; |
| 144 | |
| 145 | if (f->maskandmode[i] & xor) |
| 146 | return 0; |
| 147 | |
| 148 | neq |= f->maskandnotmode[i] & xor; |
| 149 | } |
| 150 | |
| 151 | if (f->doneq && !neq) |
| 152 | return 0; |
| 153 | |
Andreas Oberritter | dad4a73 | 2005-09-09 13:02:26 -0700 | [diff] [blame] | 154 | return feed->cb.sec(feed->feed.sec.secbuf, feed->feed.sec.seclen, |
| 155 | NULL, 0, &f->filter, DMX_OK); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 156 | } |
| 157 | |
Andreas Oberritter | dad4a73 | 2005-09-09 13:02:26 -0700 | [diff] [blame] | 158 | static inline int dvb_dmx_swfilter_section_feed(struct dvb_demux_feed *feed) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 159 | { |
| 160 | struct dvb_demux *demux = feed->demux; |
| 161 | struct dvb_demux_filter *f = feed->filter; |
| 162 | struct dmx_section_feed *sec = &feed->feed.sec; |
| 163 | int section_syntax_indicator; |
| 164 | |
| 165 | if (!sec->is_filtering) |
| 166 | return 0; |
| 167 | |
| 168 | if (!f) |
| 169 | return 0; |
| 170 | |
| 171 | if (sec->check_crc) { |
| 172 | section_syntax_indicator = ((sec->secbuf[1] & 0x80) != 0); |
| 173 | if (section_syntax_indicator && |
| 174 | demux->check_crc32(feed, sec->secbuf, sec->seclen)) |
| 175 | return -1; |
| 176 | } |
| 177 | |
| 178 | do { |
| 179 | if (dvb_dmx_swfilter_sectionfilter(feed, f) < 0) |
| 180 | return -1; |
| 181 | } while ((f = f->next) && sec->is_filtering); |
| 182 | |
| 183 | sec->seclen = 0; |
| 184 | |
| 185 | return 0; |
| 186 | } |
| 187 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 188 | static void dvb_dmx_swfilter_section_new(struct dvb_demux_feed *feed) |
| 189 | { |
| 190 | struct dmx_section_feed *sec = &feed->feed.sec; |
| 191 | |
| 192 | #ifdef DVB_DEMUX_SECTION_LOSS_LOG |
Andreas Oberritter | dad4a73 | 2005-09-09 13:02:26 -0700 | [diff] [blame] | 193 | if (sec->secbufp < sec->tsfeedp) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 194 | int i, n = sec->tsfeedp - sec->secbufp; |
| 195 | |
Andreas Oberritter | dad4a73 | 2005-09-09 13:02:26 -0700 | [diff] [blame] | 196 | /* |
| 197 | * Section padding is done with 0xff bytes entirely. |
| 198 | * Due to speed reasons, we won't check all of them |
| 199 | * but just first and last. |
| 200 | */ |
| 201 | if (sec->secbuf[0] != 0xff || sec->secbuf[n - 1] != 0xff) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 202 | printk("dvb_demux.c section ts padding loss: %d/%d\n", |
| 203 | n, sec->tsfeedp); |
| 204 | printk("dvb_demux.c pad data:"); |
Andreas Oberritter | dad4a73 | 2005-09-09 13:02:26 -0700 | [diff] [blame] | 205 | for (i = 0; i < n; i++) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 206 | printk(" %02x", sec->secbuf[i]); |
| 207 | printk("\n"); |
| 208 | } |
| 209 | } |
| 210 | #endif |
| 211 | |
| 212 | sec->tsfeedp = sec->secbufp = sec->seclen = 0; |
| 213 | sec->secbuf = sec->secbuf_base; |
| 214 | } |
| 215 | |
| 216 | /* |
Andreas Oberritter | dad4a73 | 2005-09-09 13:02:26 -0700 | [diff] [blame] | 217 | * Losless Section Demux 1.4.1 by Emard |
| 218 | * Valsecchi Patrick: |
| 219 | * - middle of section A (no PUSI) |
| 220 | * - end of section A and start of section B |
| 221 | * (with PUSI pointing to the start of the second section) |
| 222 | * |
| 223 | * In this case, without feed->pusi_seen you'll receive a garbage section |
| 224 | * consisting of the end of section A. Basically because tsfeedp |
| 225 | * is incemented and the use=0 condition is not raised |
| 226 | * when the second packet arrives. |
| 227 | * |
| 228 | * Fix: |
| 229 | * when demux is started, let feed->pusi_seen = 0 to |
| 230 | * prevent initial feeding of garbage from the end of |
| 231 | * previous section. When you for the first time see PUSI=1 |
| 232 | * then set feed->pusi_seen = 1 |
| 233 | */ |
| 234 | static int dvb_dmx_swfilter_section_copy_dump(struct dvb_demux_feed *feed, |
| 235 | const u8 *buf, u8 len) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 236 | { |
| 237 | struct dvb_demux *demux = feed->demux; |
| 238 | struct dmx_section_feed *sec = &feed->feed.sec; |
| 239 | u16 limit, seclen, n; |
| 240 | |
Andreas Oberritter | dad4a73 | 2005-09-09 13:02:26 -0700 | [diff] [blame] | 241 | if (sec->tsfeedp >= DMX_MAX_SECFEED_SIZE) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 242 | return 0; |
| 243 | |
Andreas Oberritter | dad4a73 | 2005-09-09 13:02:26 -0700 | [diff] [blame] | 244 | if (sec->tsfeedp + len > DMX_MAX_SECFEED_SIZE) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 245 | #ifdef DVB_DEMUX_SECTION_LOSS_LOG |
| 246 | printk("dvb_demux.c section buffer full loss: %d/%d\n", |
Andreas Oberritter | dad4a73 | 2005-09-09 13:02:26 -0700 | [diff] [blame] | 247 | sec->tsfeedp + len - DMX_MAX_SECFEED_SIZE, |
| 248 | DMX_MAX_SECFEED_SIZE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 249 | #endif |
| 250 | len = DMX_MAX_SECFEED_SIZE - sec->tsfeedp; |
| 251 | } |
| 252 | |
Andreas Oberritter | dad4a73 | 2005-09-09 13:02:26 -0700 | [diff] [blame] | 253 | if (len <= 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 254 | return 0; |
| 255 | |
| 256 | demux->memcopy(feed, sec->secbuf_base + sec->tsfeedp, buf, len); |
| 257 | sec->tsfeedp += len; |
| 258 | |
Andreas Oberritter | dad4a73 | 2005-09-09 13:02:26 -0700 | [diff] [blame] | 259 | /* |
| 260 | * Dump all the sections we can find in the data (Emard) |
| 261 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 262 | limit = sec->tsfeedp; |
Andreas Oberritter | dad4a73 | 2005-09-09 13:02:26 -0700 | [diff] [blame] | 263 | if (limit > DMX_MAX_SECFEED_SIZE) |
| 264 | return -1; /* internal error should never happen */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 265 | |
| 266 | /* to be sure always set secbuf */ |
| 267 | sec->secbuf = sec->secbuf_base + sec->secbufp; |
| 268 | |
Andreas Oberritter | dad4a73 | 2005-09-09 13:02:26 -0700 | [diff] [blame] | 269 | for (n = 0; sec->secbufp + 2 < limit; n++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 270 | seclen = section_length(sec->secbuf); |
Mark Adams | b3967d6 | 2005-11-08 21:35:50 -0800 | [diff] [blame] | 271 | if (seclen <= 0 || seclen > DMX_MAX_SECTION_SIZE |
Andreas Oberritter | dad4a73 | 2005-09-09 13:02:26 -0700 | [diff] [blame] | 272 | || seclen + sec->secbufp > limit) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 273 | return 0; |
| 274 | sec->seclen = seclen; |
| 275 | sec->crc_val = ~0; |
| 276 | /* dump [secbuf .. secbuf+seclen) */ |
Andreas Oberritter | dad4a73 | 2005-09-09 13:02:26 -0700 | [diff] [blame] | 277 | if (feed->pusi_seen) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 278 | dvb_dmx_swfilter_section_feed(feed); |
| 279 | #ifdef DVB_DEMUX_SECTION_LOSS_LOG |
| 280 | else |
| 281 | printk("dvb_demux.c pusi not seen, discarding section data\n"); |
| 282 | #endif |
Andreas Oberritter | dad4a73 | 2005-09-09 13:02:26 -0700 | [diff] [blame] | 283 | sec->secbufp += seclen; /* secbufp and secbuf moving together is */ |
| 284 | sec->secbuf += seclen; /* redundant but saves pointer arithmetic */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 285 | } |
| 286 | |
| 287 | return 0; |
| 288 | } |
| 289 | |
Andreas Oberritter | dad4a73 | 2005-09-09 13:02:26 -0700 | [diff] [blame] | 290 | static int dvb_dmx_swfilter_section_packet(struct dvb_demux_feed *feed, |
| 291 | const u8 *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 292 | { |
| 293 | u8 p, count; |
| 294 | int ccok, dc_i = 0; |
| 295 | u8 cc; |
| 296 | |
| 297 | count = payload(buf); |
| 298 | |
Andreas Oberritter | dad4a73 | 2005-09-09 13:02:26 -0700 | [diff] [blame] | 299 | if (count == 0) /* count == 0 if no payload or out of range */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 300 | return -1; |
| 301 | |
Andreas Oberritter | dad4a73 | 2005-09-09 13:02:26 -0700 | [diff] [blame] | 302 | p = 188 - count; /* payload start */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 303 | |
| 304 | cc = buf[3] & 0x0f; |
| 305 | ccok = ((feed->cc + 1) & 0x0f) == cc; |
| 306 | feed->cc = cc; |
| 307 | |
| 308 | if (buf[3] & 0x20) { |
| 309 | /* adaption field present, check for discontinuity_indicator */ |
| 310 | if ((buf[4] > 0) && (buf[5] & 0x80)) |
| 311 | dc_i = 1; |
| 312 | } |
| 313 | |
| 314 | if (!ccok || dc_i) { |
| 315 | #ifdef DVB_DEMUX_SECTION_LOSS_LOG |
Andreas Oberritter | dad4a73 | 2005-09-09 13:02:26 -0700 | [diff] [blame] | 316 | printk("dvb_demux.c discontinuity detected %d bytes lost\n", |
| 317 | count); |
| 318 | /* |
| 319 | * those bytes under sume circumstances will again be reported |
| 320 | * in the following dvb_dmx_swfilter_section_new |
| 321 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 322 | #endif |
Andreas Oberritter | dad4a73 | 2005-09-09 13:02:26 -0700 | [diff] [blame] | 323 | /* |
| 324 | * Discontinuity detected. Reset pusi_seen = 0 to |
| 325 | * stop feeding of suspicious data until next PUSI=1 arrives |
| 326 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 327 | feed->pusi_seen = 0; |
| 328 | dvb_dmx_swfilter_section_new(feed); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 329 | } |
| 330 | |
| 331 | if (buf[1] & 0x40) { |
Andreas Oberritter | dad4a73 | 2005-09-09 13:02:26 -0700 | [diff] [blame] | 332 | /* PUSI=1 (is set), section boundary is here */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 333 | if (count > 1 && buf[p] < count) { |
Andreas Oberritter | dad4a73 | 2005-09-09 13:02:26 -0700 | [diff] [blame] | 334 | const u8 *before = &buf[p + 1]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 335 | u8 before_len = buf[p]; |
Andreas Oberritter | dad4a73 | 2005-09-09 13:02:26 -0700 | [diff] [blame] | 336 | const u8 *after = &before[before_len]; |
| 337 | u8 after_len = count - 1 - before_len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 338 | |
Andreas Oberritter | dad4a73 | 2005-09-09 13:02:26 -0700 | [diff] [blame] | 339 | dvb_dmx_swfilter_section_copy_dump(feed, before, |
| 340 | before_len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 341 | /* before start of new section, set pusi_seen = 1 */ |
| 342 | feed->pusi_seen = 1; |
| 343 | dvb_dmx_swfilter_section_new(feed); |
Andreas Oberritter | dad4a73 | 2005-09-09 13:02:26 -0700 | [diff] [blame] | 344 | dvb_dmx_swfilter_section_copy_dump(feed, after, |
| 345 | after_len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 346 | } |
| 347 | #ifdef DVB_DEMUX_SECTION_LOSS_LOG |
Andreas Oberritter | dad4a73 | 2005-09-09 13:02:26 -0700 | [diff] [blame] | 348 | else if (count > 0) |
| 349 | printk("dvb_demux.c PUSI=1 but %d bytes lost\n", count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 350 | #endif |
| 351 | } else { |
Andreas Oberritter | dad4a73 | 2005-09-09 13:02:26 -0700 | [diff] [blame] | 352 | /* PUSI=0 (is not set), no section boundary */ |
| 353 | dvb_dmx_swfilter_section_copy_dump(feed, &buf[p], count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 354 | } |
Andreas Oberritter | dad4a73 | 2005-09-09 13:02:26 -0700 | [diff] [blame] | 355 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 356 | return 0; |
| 357 | } |
| 358 | |
Andreas Oberritter | dad4a73 | 2005-09-09 13:02:26 -0700 | [diff] [blame] | 359 | static inline void dvb_dmx_swfilter_packet_type(struct dvb_demux_feed *feed, |
| 360 | const u8 *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 361 | { |
Andreas Oberritter | dad4a73 | 2005-09-09 13:02:26 -0700 | [diff] [blame] | 362 | switch (feed->type) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 363 | case DMX_TYPE_TS: |
| 364 | if (!feed->feed.ts.is_filtering) |
| 365 | break; |
| 366 | if (feed->ts_type & TS_PACKET) { |
| 367 | if (feed->ts_type & TS_PAYLOAD_ONLY) |
| 368 | dvb_dmx_swfilter_payload(feed, buf); |
| 369 | else |
Andreas Oberritter | dad4a73 | 2005-09-09 13:02:26 -0700 | [diff] [blame] | 370 | feed->cb.ts(buf, 188, NULL, 0, &feed->feed.ts, |
| 371 | DMX_OK); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 372 | } |
| 373 | if (feed->ts_type & TS_DECODER) |
| 374 | if (feed->demux->write_to_decoder) |
| 375 | feed->demux->write_to_decoder(feed, buf, 188); |
| 376 | break; |
| 377 | |
| 378 | case DMX_TYPE_SEC: |
| 379 | if (!feed->feed.sec.is_filtering) |
| 380 | break; |
| 381 | if (dvb_dmx_swfilter_section_packet(feed, buf) < 0) |
Andreas Oberritter | dad4a73 | 2005-09-09 13:02:26 -0700 | [diff] [blame] | 382 | feed->feed.sec.seclen = feed->feed.sec.secbufp = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 383 | break; |
| 384 | |
| 385 | default: |
| 386 | break; |
| 387 | } |
| 388 | } |
| 389 | |
| 390 | #define DVR_FEED(f) \ |
| 391 | (((f)->type == DMX_TYPE_TS) && \ |
| 392 | ((f)->feed.ts.is_filtering) && \ |
Andreas Oberritter | 4a24ce3 | 2008-04-22 14:45:47 -0300 | [diff] [blame] | 393 | (((f)->ts_type & (TS_PACKET | TS_DEMUX)) == TS_PACKET)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 394 | |
| 395 | static void dvb_dmx_swfilter_packet(struct dvb_demux *demux, const u8 *buf) |
| 396 | { |
| 397 | struct dvb_demux_feed *feed; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 398 | u16 pid = ts_pid(buf); |
| 399 | int dvr_done = 0; |
| 400 | |
Abylay Ospan | 26b9d6c | 2009-11-01 18:46:53 -0300 | [diff] [blame] | 401 | if (dvb_demux_speedcheck) { |
| 402 | struct timespec cur_time, delta_time; |
| 403 | u64 speed_bytes, speed_timedelta; |
| 404 | |
| 405 | demux->speed_pkts_cnt++; |
| 406 | |
| 407 | /* show speed every SPEED_PKTS_INTERVAL packets */ |
| 408 | if (!(demux->speed_pkts_cnt % SPEED_PKTS_INTERVAL)) { |
| 409 | cur_time = current_kernel_time(); |
| 410 | |
| 411 | if (demux->speed_last_time.tv_sec != 0 && |
| 412 | demux->speed_last_time.tv_nsec != 0) { |
| 413 | delta_time = timespec_sub(cur_time, |
| 414 | demux->speed_last_time); |
| 415 | speed_bytes = (u64)demux->speed_pkts_cnt |
| 416 | * 188 * 8; |
| 417 | /* convert to 1024 basis */ |
| 418 | speed_bytes = 1000 * div64_u64(speed_bytes, |
| 419 | 1024); |
| 420 | speed_timedelta = |
| 421 | (u64)timespec_to_ns(&delta_time); |
| 422 | speed_timedelta = div64_u64(speed_timedelta, |
| 423 | 1000000); /* nsec -> usec */ |
| 424 | printk(KERN_INFO "TS speed %llu Kbits/sec \n", |
| 425 | div64_u64(speed_bytes, |
| 426 | speed_timedelta)); |
Peter Senna Tschudin | c2c9036 | 2012-09-07 11:24:44 -0300 | [diff] [blame] | 427 | } |
Abylay Ospan | 26b9d6c | 2009-11-01 18:46:53 -0300 | [diff] [blame] | 428 | |
| 429 | demux->speed_last_time = cur_time; |
| 430 | demux->speed_pkts_cnt = 0; |
Peter Senna Tschudin | c2c9036 | 2012-09-07 11:24:44 -0300 | [diff] [blame] | 431 | } |
| 432 | } |
Abylay Ospan | 26b9d6c | 2009-11-01 18:46:53 -0300 | [diff] [blame] | 433 | |
Michael Krufky | ae53020 | 2012-05-21 17:47:15 -0300 | [diff] [blame] | 434 | if (buf[1] & 0x80) { |
| 435 | dprintk_tscheck("TEI detected. " |
| 436 | "PID=0x%x data1=0x%x\n", |
| 437 | pid, buf[1]); |
| 438 | /* data in this packet cant be trusted - drop it unless |
| 439 | * module option dvb_demux_feed_err_pkts is set */ |
| 440 | if (!dvb_demux_feed_err_pkts) |
| 441 | return; |
| 442 | } else /* if TEI bit is set, pid may be wrong- skip pkt counter */ |
John Smith | 5144f5b | 2013-03-05 18:02:43 -0300 | [diff] [blame] | 443 | if (demux->cnt_storage && dvb_demux_tscheck) { |
| 444 | /* check pkt counter */ |
| 445 | if (pid < MAX_PID) { |
| 446 | if (buf[3] & 0x10) |
| 447 | demux->cnt_storage[pid] = |
| 448 | (demux->cnt_storage[pid] + 1) & 0xf; |
| 449 | |
| 450 | if ((buf[3] & 0xf) != demux->cnt_storage[pid]) { |
| 451 | dprintk_tscheck("TS packet counter mismatch. PID=0x%x expected 0x%x got 0x%x\n", |
Abylay Ospan | 0d83463 | 2009-06-06 09:31:34 -0300 | [diff] [blame] | 452 | pid, demux->cnt_storage[pid], |
| 453 | buf[3] & 0xf); |
John Smith | 5144f5b | 2013-03-05 18:02:43 -0300 | [diff] [blame] | 454 | demux->cnt_storage[pid] = buf[3] & 0xf; |
| 455 | } |
| 456 | } |
| 457 | /* end check */ |
Peter Senna Tschudin | c2c9036 | 2012-09-07 11:24:44 -0300 | [diff] [blame] | 458 | } |
Abylay Ospan | 0d83463 | 2009-06-06 09:31:34 -0300 | [diff] [blame] | 459 | |
Trent Piepho | 7948261 | 2007-10-10 05:37:39 -0300 | [diff] [blame] | 460 | list_for_each_entry(feed, &demux->feed_list, list_head) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 461 | if ((feed->pid != pid) && (feed->pid != 0x2000)) |
| 462 | continue; |
| 463 | |
| 464 | /* copy each packet only once to the dvr device, even |
| 465 | * if a PID is in multiple filters (e.g. video + PCR) */ |
| 466 | if ((DVR_FEED(feed)) && (dvr_done++)) |
| 467 | continue; |
| 468 | |
Andreas Oberritter | a4afd65 | 2009-07-14 20:48:37 -0300 | [diff] [blame] | 469 | if (feed->pid == pid) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 470 | dvb_dmx_swfilter_packet_type(feed, buf); |
Andreas Oberritter | a4afd65 | 2009-07-14 20:48:37 -0300 | [diff] [blame] | 471 | else if (feed->pid == 0x2000) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 472 | feed->cb.ts(buf, 188, NULL, 0, &feed->feed.ts, DMX_OK); |
| 473 | } |
| 474 | } |
| 475 | |
Andreas Oberritter | dad4a73 | 2005-09-09 13:02:26 -0700 | [diff] [blame] | 476 | void dvb_dmx_swfilter_packets(struct dvb_demux *demux, const u8 *buf, |
| 477 | size_t count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 478 | { |
Mauro Carvalho Chehab | 2810016 | 2009-02-16 15:27:44 -0300 | [diff] [blame] | 479 | spin_lock(&demux->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 480 | |
| 481 | while (count--) { |
Andreas Oberritter | dad4a73 | 2005-09-09 13:02:26 -0700 | [diff] [blame] | 482 | if (buf[0] == 0x47) |
| 483 | dvb_dmx_swfilter_packet(demux, buf); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 484 | buf += 188; |
| 485 | } |
| 486 | |
Mauro Carvalho Chehab | 2810016 | 2009-02-16 15:27:44 -0300 | [diff] [blame] | 487 | spin_unlock(&demux->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 488 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 489 | |
Andreas Oberritter | dad4a73 | 2005-09-09 13:02:26 -0700 | [diff] [blame] | 490 | EXPORT_SYMBOL(dvb_dmx_swfilter_packets); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 491 | |
Marko Ristola | 38e009a | 2011-04-08 12:40:51 -0300 | [diff] [blame] | 492 | static inline int find_next_packet(const u8 *buf, int pos, size_t count, |
| 493 | const int pktsize) |
| 494 | { |
| 495 | int start = pos, lost; |
| 496 | |
| 497 | while (pos < count) { |
| 498 | if (buf[pos] == 0x47 || |
| 499 | (pktsize == 204 && buf[pos] == 0xB8)) |
| 500 | break; |
| 501 | pos++; |
| 502 | } |
| 503 | |
| 504 | lost = pos - start; |
| 505 | if (lost) { |
| 506 | /* This garbage is part of a valid packet? */ |
| 507 | int backtrack = pos - pktsize; |
| 508 | if (backtrack >= 0 && (buf[backtrack] == 0x47 || |
| 509 | (pktsize == 204 && buf[backtrack] == 0xB8))) |
| 510 | return backtrack; |
| 511 | } |
| 512 | |
| 513 | return pos; |
| 514 | } |
| 515 | |
| 516 | /* Filter all pktsize= 188 or 204 sized packets and skip garbage. */ |
| 517 | static inline void _dvb_dmx_swfilter(struct dvb_demux *demux, const u8 *buf, |
| 518 | size_t count, const int pktsize) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 519 | { |
| 520 | int p = 0, i, j; |
Marko Ristola | 38e009a | 2011-04-08 12:40:51 -0300 | [diff] [blame] | 521 | const u8 *q; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 522 | |
Mauro Carvalho Chehab | 2810016 | 2009-02-16 15:27:44 -0300 | [diff] [blame] | 523 | spin_lock(&demux->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 524 | |
Marko Ristola | 38e009a | 2011-04-08 12:40:51 -0300 | [diff] [blame] | 525 | if (demux->tsbufp) { /* tsbuf[0] is now 0x47. */ |
Andreas Oberritter | dad4a73 | 2005-09-09 13:02:26 -0700 | [diff] [blame] | 526 | i = demux->tsbufp; |
Marko Ristola | 38e009a | 2011-04-08 12:40:51 -0300 | [diff] [blame] | 527 | j = pktsize - i; |
Andreas Oberritter | dad4a73 | 2005-09-09 13:02:26 -0700 | [diff] [blame] | 528 | if (count < j) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 529 | memcpy(&demux->tsbuf[i], buf, count); |
| 530 | demux->tsbufp += count; |
| 531 | goto bailout; |
| 532 | } |
| 533 | memcpy(&demux->tsbuf[i], buf, j); |
Marko Ristola | 38e009a | 2011-04-08 12:40:51 -0300 | [diff] [blame] | 534 | if (demux->tsbuf[0] == 0x47) /* double check */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 535 | dvb_dmx_swfilter_packet(demux, demux->tsbuf); |
| 536 | demux->tsbufp = 0; |
| 537 | p += j; |
| 538 | } |
| 539 | |
Marko Ristola | 38e009a | 2011-04-08 12:40:51 -0300 | [diff] [blame] | 540 | while (1) { |
| 541 | p = find_next_packet(buf, p, count, pktsize); |
| 542 | if (p >= count) |
| 543 | break; |
| 544 | if (count - p < pktsize) |
| 545 | break; |
| 546 | |
| 547 | q = &buf[p]; |
| 548 | |
| 549 | if (pktsize == 204 && (*q == 0xB8)) { |
| 550 | memcpy(demux->tsbuf, q, 188); |
| 551 | demux->tsbuf[0] = 0x47; |
| 552 | q = demux->tsbuf; |
| 553 | } |
| 554 | dvb_dmx_swfilter_packet(demux, q); |
| 555 | p += pktsize; |
| 556 | } |
| 557 | |
| 558 | i = count - p; |
| 559 | if (i) { |
| 560 | memcpy(demux->tsbuf, &buf[p], i); |
| 561 | demux->tsbufp = i; |
| 562 | if (pktsize == 204 && demux->tsbuf[0] == 0xB8) |
| 563 | demux->tsbuf[0] = 0x47; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 564 | } |
| 565 | |
| 566 | bailout: |
Mauro Carvalho Chehab | 2810016 | 2009-02-16 15:27:44 -0300 | [diff] [blame] | 567 | spin_unlock(&demux->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 568 | } |
Andreas Oberritter | dad4a73 | 2005-09-09 13:02:26 -0700 | [diff] [blame] | 569 | |
Marko Ristola | 38e009a | 2011-04-08 12:40:51 -0300 | [diff] [blame] | 570 | void dvb_dmx_swfilter(struct dvb_demux *demux, const u8 *buf, size_t count) |
| 571 | { |
| 572 | _dvb_dmx_swfilter(demux, buf, count, 188); |
| 573 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 574 | EXPORT_SYMBOL(dvb_dmx_swfilter); |
| 575 | |
| 576 | void dvb_dmx_swfilter_204(struct dvb_demux *demux, const u8 *buf, size_t count) |
| 577 | { |
Marko Ristola | 38e009a | 2011-04-08 12:40:51 -0300 | [diff] [blame] | 578 | _dvb_dmx_swfilter(demux, buf, count, 204); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 579 | } |
| 580 | EXPORT_SYMBOL(dvb_dmx_swfilter_204); |
| 581 | |
Michael Krufky | 8e15670 | 2011-08-27 18:46:37 -0300 | [diff] [blame] | 582 | void dvb_dmx_swfilter_raw(struct dvb_demux *demux, const u8 *buf, size_t count) |
| 583 | { |
| 584 | spin_lock(&demux->lock); |
| 585 | |
| 586 | demux->feed->cb.ts(buf, count, NULL, 0, &demux->feed->feed.ts, DMX_OK); |
| 587 | |
| 588 | spin_unlock(&demux->lock); |
| 589 | } |
| 590 | EXPORT_SYMBOL(dvb_dmx_swfilter_raw); |
| 591 | |
Andreas Oberritter | dad4a73 | 2005-09-09 13:02:26 -0700 | [diff] [blame] | 592 | static struct dvb_demux_filter *dvb_dmx_filter_alloc(struct dvb_demux *demux) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 593 | { |
| 594 | int i; |
| 595 | |
Andreas Oberritter | dad4a73 | 2005-09-09 13:02:26 -0700 | [diff] [blame] | 596 | for (i = 0; i < demux->filternum; i++) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 597 | if (demux->filter[i].state == DMX_STATE_FREE) |
| 598 | break; |
| 599 | |
| 600 | if (i == demux->filternum) |
| 601 | return NULL; |
| 602 | |
| 603 | demux->filter[i].state = DMX_STATE_ALLOCATED; |
| 604 | |
| 605 | return &demux->filter[i]; |
| 606 | } |
| 607 | |
Andreas Oberritter | dad4a73 | 2005-09-09 13:02:26 -0700 | [diff] [blame] | 608 | static struct dvb_demux_feed *dvb_dmx_feed_alloc(struct dvb_demux *demux) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 609 | { |
| 610 | int i; |
| 611 | |
Andreas Oberritter | dad4a73 | 2005-09-09 13:02:26 -0700 | [diff] [blame] | 612 | for (i = 0; i < demux->feednum; i++) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 613 | if (demux->feed[i].state == DMX_STATE_FREE) |
| 614 | break; |
| 615 | |
| 616 | if (i == demux->feednum) |
| 617 | return NULL; |
| 618 | |
| 619 | demux->feed[i].state = DMX_STATE_ALLOCATED; |
| 620 | |
| 621 | return &demux->feed[i]; |
| 622 | } |
| 623 | |
| 624 | static int dvb_demux_feed_find(struct dvb_demux_feed *feed) |
| 625 | { |
| 626 | struct dvb_demux_feed *entry; |
| 627 | |
| 628 | list_for_each_entry(entry, &feed->demux->feed_list, list_head) |
| 629 | if (entry == feed) |
| 630 | return 1; |
| 631 | |
| 632 | return 0; |
| 633 | } |
| 634 | |
| 635 | static void dvb_demux_feed_add(struct dvb_demux_feed *feed) |
| 636 | { |
| 637 | spin_lock_irq(&feed->demux->lock); |
| 638 | if (dvb_demux_feed_find(feed)) { |
| 639 | printk(KERN_ERR "%s: feed already in list (type=%x state=%x pid=%x)\n", |
Harvey Harrison | 46b4f7c | 2008-04-08 23:20:00 -0300 | [diff] [blame] | 640 | __func__, feed->type, feed->state, feed->pid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 641 | goto out; |
| 642 | } |
| 643 | |
| 644 | list_add(&feed->list_head, &feed->demux->feed_list); |
| 645 | out: |
| 646 | spin_unlock_irq(&feed->demux->lock); |
| 647 | } |
| 648 | |
| 649 | static void dvb_demux_feed_del(struct dvb_demux_feed *feed) |
| 650 | { |
| 651 | spin_lock_irq(&feed->demux->lock); |
| 652 | if (!(dvb_demux_feed_find(feed))) { |
| 653 | printk(KERN_ERR "%s: feed not in list (type=%x state=%x pid=%x)\n", |
Harvey Harrison | 46b4f7c | 2008-04-08 23:20:00 -0300 | [diff] [blame] | 654 | __func__, feed->type, feed->state, feed->pid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 655 | goto out; |
| 656 | } |
| 657 | |
| 658 | list_del(&feed->list_head); |
| 659 | out: |
| 660 | spin_unlock_irq(&feed->demux->lock); |
| 661 | } |
| 662 | |
Andreas Oberritter | dad4a73 | 2005-09-09 13:02:26 -0700 | [diff] [blame] | 663 | static int dmx_ts_feed_set(struct dmx_ts_feed *ts_feed, u16 pid, int ts_type, |
| 664 | enum dmx_ts_pes pes_type, |
| 665 | size_t circular_buffer_size, struct timespec timeout) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 666 | { |
Andreas Oberritter | dad4a73 | 2005-09-09 13:02:26 -0700 | [diff] [blame] | 667 | struct dvb_demux_feed *feed = (struct dvb_demux_feed *)ts_feed; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 668 | struct dvb_demux *demux = feed->demux; |
| 669 | |
| 670 | if (pid > DMX_MAX_PID) |
| 671 | return -EINVAL; |
| 672 | |
Ingo Molnar | 3593cab | 2006-02-07 06:49:14 -0200 | [diff] [blame] | 673 | if (mutex_lock_interruptible(&demux->mutex)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 674 | return -ERESTARTSYS; |
| 675 | |
| 676 | if (ts_type & TS_DECODER) { |
Mauro Carvalho Chehab | fde04ab | 2013-04-04 13:25:30 -0300 | [diff] [blame] | 677 | if (pes_type >= DMX_PES_OTHER) { |
Ingo Molnar | 3593cab | 2006-02-07 06:49:14 -0200 | [diff] [blame] | 678 | mutex_unlock(&demux->mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 679 | return -EINVAL; |
| 680 | } |
| 681 | |
| 682 | if (demux->pesfilter[pes_type] && |
| 683 | demux->pesfilter[pes_type] != feed) { |
Ingo Molnar | 3593cab | 2006-02-07 06:49:14 -0200 | [diff] [blame] | 684 | mutex_unlock(&demux->mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 685 | return -EINVAL; |
| 686 | } |
| 687 | |
| 688 | demux->pesfilter[pes_type] = feed; |
| 689 | demux->pids[pes_type] = pid; |
| 690 | } |
| 691 | |
| 692 | dvb_demux_feed_add(feed); |
| 693 | |
| 694 | feed->pid = pid; |
| 695 | feed->buffer_size = circular_buffer_size; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 696 | feed->timeout = timeout; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 697 | feed->ts_type = ts_type; |
| 698 | feed->pes_type = pes_type; |
| 699 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 700 | if (feed->buffer_size) { |
| 701 | #ifdef NOBUFS |
Andreas Oberritter | dad4a73 | 2005-09-09 13:02:26 -0700 | [diff] [blame] | 702 | feed->buffer = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 703 | #else |
| 704 | feed->buffer = vmalloc(feed->buffer_size); |
| 705 | if (!feed->buffer) { |
Ingo Molnar | 3593cab | 2006-02-07 06:49:14 -0200 | [diff] [blame] | 706 | mutex_unlock(&demux->mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 707 | return -ENOMEM; |
| 708 | } |
| 709 | #endif |
| 710 | } |
| 711 | |
| 712 | feed->state = DMX_STATE_READY; |
Ingo Molnar | 3593cab | 2006-02-07 06:49:14 -0200 | [diff] [blame] | 713 | mutex_unlock(&demux->mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 714 | |
| 715 | return 0; |
| 716 | } |
| 717 | |
Andreas Oberritter | dad4a73 | 2005-09-09 13:02:26 -0700 | [diff] [blame] | 718 | static int dmx_ts_feed_start_filtering(struct dmx_ts_feed *ts_feed) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 719 | { |
Andreas Oberritter | dad4a73 | 2005-09-09 13:02:26 -0700 | [diff] [blame] | 720 | struct dvb_demux_feed *feed = (struct dvb_demux_feed *)ts_feed; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 721 | struct dvb_demux *demux = feed->demux; |
| 722 | int ret; |
| 723 | |
Ingo Molnar | 3593cab | 2006-02-07 06:49:14 -0200 | [diff] [blame] | 724 | if (mutex_lock_interruptible(&demux->mutex)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 725 | return -ERESTARTSYS; |
| 726 | |
| 727 | if (feed->state != DMX_STATE_READY || feed->type != DMX_TYPE_TS) { |
Ingo Molnar | 3593cab | 2006-02-07 06:49:14 -0200 | [diff] [blame] | 728 | mutex_unlock(&demux->mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 729 | return -EINVAL; |
| 730 | } |
| 731 | |
| 732 | if (!demux->start_feed) { |
Ingo Molnar | 3593cab | 2006-02-07 06:49:14 -0200 | [diff] [blame] | 733 | mutex_unlock(&demux->mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 734 | return -ENODEV; |
| 735 | } |
| 736 | |
| 737 | if ((ret = demux->start_feed(feed)) < 0) { |
Ingo Molnar | 3593cab | 2006-02-07 06:49:14 -0200 | [diff] [blame] | 738 | mutex_unlock(&demux->mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 739 | return ret; |
| 740 | } |
| 741 | |
| 742 | spin_lock_irq(&demux->lock); |
| 743 | ts_feed->is_filtering = 1; |
| 744 | feed->state = DMX_STATE_GO; |
| 745 | spin_unlock_irq(&demux->lock); |
Ingo Molnar | 3593cab | 2006-02-07 06:49:14 -0200 | [diff] [blame] | 746 | mutex_unlock(&demux->mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 747 | |
| 748 | return 0; |
| 749 | } |
| 750 | |
Andreas Oberritter | dad4a73 | 2005-09-09 13:02:26 -0700 | [diff] [blame] | 751 | static int dmx_ts_feed_stop_filtering(struct dmx_ts_feed *ts_feed) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 752 | { |
Andreas Oberritter | dad4a73 | 2005-09-09 13:02:26 -0700 | [diff] [blame] | 753 | struct dvb_demux_feed *feed = (struct dvb_demux_feed *)ts_feed; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 754 | struct dvb_demux *demux = feed->demux; |
| 755 | int ret; |
| 756 | |
Simon Arlott | c278850 | 2007-03-10 06:21:25 -0300 | [diff] [blame] | 757 | mutex_lock(&demux->mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 758 | |
| 759 | if (feed->state < DMX_STATE_GO) { |
Ingo Molnar | 3593cab | 2006-02-07 06:49:14 -0200 | [diff] [blame] | 760 | mutex_unlock(&demux->mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 761 | return -EINVAL; |
| 762 | } |
| 763 | |
| 764 | if (!demux->stop_feed) { |
Ingo Molnar | 3593cab | 2006-02-07 06:49:14 -0200 | [diff] [blame] | 765 | mutex_unlock(&demux->mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 766 | return -ENODEV; |
| 767 | } |
| 768 | |
| 769 | ret = demux->stop_feed(feed); |
| 770 | |
| 771 | spin_lock_irq(&demux->lock); |
| 772 | ts_feed->is_filtering = 0; |
| 773 | feed->state = DMX_STATE_ALLOCATED; |
| 774 | spin_unlock_irq(&demux->lock); |
Ingo Molnar | 3593cab | 2006-02-07 06:49:14 -0200 | [diff] [blame] | 775 | mutex_unlock(&demux->mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 776 | |
| 777 | return ret; |
| 778 | } |
| 779 | |
Andreas Oberritter | dad4a73 | 2005-09-09 13:02:26 -0700 | [diff] [blame] | 780 | static int dvbdmx_allocate_ts_feed(struct dmx_demux *dmx, |
| 781 | struct dmx_ts_feed **ts_feed, |
| 782 | dmx_ts_cb callback) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 783 | { |
Andreas Oberritter | dad4a73 | 2005-09-09 13:02:26 -0700 | [diff] [blame] | 784 | struct dvb_demux *demux = (struct dvb_demux *)dmx; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 785 | struct dvb_demux_feed *feed; |
| 786 | |
Ingo Molnar | 3593cab | 2006-02-07 06:49:14 -0200 | [diff] [blame] | 787 | if (mutex_lock_interruptible(&demux->mutex)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 788 | return -ERESTARTSYS; |
| 789 | |
| 790 | if (!(feed = dvb_dmx_feed_alloc(demux))) { |
Ingo Molnar | 3593cab | 2006-02-07 06:49:14 -0200 | [diff] [blame] | 791 | mutex_unlock(&demux->mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 792 | return -EBUSY; |
| 793 | } |
| 794 | |
| 795 | feed->type = DMX_TYPE_TS; |
| 796 | feed->cb.ts = callback; |
| 797 | feed->demux = demux; |
| 798 | feed->pid = 0xffff; |
| 799 | feed->peslen = 0xfffa; |
| 800 | feed->buffer = NULL; |
| 801 | |
| 802 | (*ts_feed) = &feed->feed.ts; |
| 803 | (*ts_feed)->parent = dmx; |
| 804 | (*ts_feed)->priv = NULL; |
| 805 | (*ts_feed)->is_filtering = 0; |
| 806 | (*ts_feed)->start_filtering = dmx_ts_feed_start_filtering; |
| 807 | (*ts_feed)->stop_filtering = dmx_ts_feed_stop_filtering; |
| 808 | (*ts_feed)->set = dmx_ts_feed_set; |
| 809 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 810 | if (!(feed->filter = dvb_dmx_filter_alloc(demux))) { |
| 811 | feed->state = DMX_STATE_FREE; |
Ingo Molnar | 3593cab | 2006-02-07 06:49:14 -0200 | [diff] [blame] | 812 | mutex_unlock(&demux->mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 813 | return -EBUSY; |
| 814 | } |
| 815 | |
| 816 | feed->filter->type = DMX_TYPE_TS; |
| 817 | feed->filter->feed = feed; |
| 818 | feed->filter->state = DMX_STATE_READY; |
| 819 | |
Ingo Molnar | 3593cab | 2006-02-07 06:49:14 -0200 | [diff] [blame] | 820 | mutex_unlock(&demux->mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 821 | |
| 822 | return 0; |
| 823 | } |
| 824 | |
Andreas Oberritter | dad4a73 | 2005-09-09 13:02:26 -0700 | [diff] [blame] | 825 | static int dvbdmx_release_ts_feed(struct dmx_demux *dmx, |
| 826 | struct dmx_ts_feed *ts_feed) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 827 | { |
Andreas Oberritter | dad4a73 | 2005-09-09 13:02:26 -0700 | [diff] [blame] | 828 | struct dvb_demux *demux = (struct dvb_demux *)dmx; |
| 829 | struct dvb_demux_feed *feed = (struct dvb_demux_feed *)ts_feed; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 830 | |
Simon Arlott | c278850 | 2007-03-10 06:21:25 -0300 | [diff] [blame] | 831 | mutex_lock(&demux->mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 832 | |
| 833 | if (feed->state == DMX_STATE_FREE) { |
Ingo Molnar | 3593cab | 2006-02-07 06:49:14 -0200 | [diff] [blame] | 834 | mutex_unlock(&demux->mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 835 | return -EINVAL; |
| 836 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 837 | #ifndef NOBUFS |
| 838 | vfree(feed->buffer); |
Andreas Oberritter | dad4a73 | 2005-09-09 13:02:26 -0700 | [diff] [blame] | 839 | feed->buffer = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 840 | #endif |
| 841 | |
| 842 | feed->state = DMX_STATE_FREE; |
| 843 | feed->filter->state = DMX_STATE_FREE; |
| 844 | |
| 845 | dvb_demux_feed_del(feed); |
| 846 | |
| 847 | feed->pid = 0xffff; |
| 848 | |
Mauro Carvalho Chehab | fde04ab | 2013-04-04 13:25:30 -0300 | [diff] [blame] | 849 | if (feed->ts_type & TS_DECODER && feed->pes_type < DMX_PES_OTHER) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 850 | demux->pesfilter[feed->pes_type] = NULL; |
| 851 | |
Ingo Molnar | 3593cab | 2006-02-07 06:49:14 -0200 | [diff] [blame] | 852 | mutex_unlock(&demux->mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 853 | return 0; |
| 854 | } |
| 855 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 856 | /****************************************************************************** |
| 857 | * dmx_section_feed API calls |
| 858 | ******************************************************************************/ |
| 859 | |
Andreas Oberritter | dad4a73 | 2005-09-09 13:02:26 -0700 | [diff] [blame] | 860 | static int dmx_section_feed_allocate_filter(struct dmx_section_feed *feed, |
| 861 | struct dmx_section_filter **filter) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 862 | { |
Andreas Oberritter | dad4a73 | 2005-09-09 13:02:26 -0700 | [diff] [blame] | 863 | struct dvb_demux_feed *dvbdmxfeed = (struct dvb_demux_feed *)feed; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 864 | struct dvb_demux *dvbdemux = dvbdmxfeed->demux; |
| 865 | struct dvb_demux_filter *dvbdmxfilter; |
| 866 | |
Ingo Molnar | 3593cab | 2006-02-07 06:49:14 -0200 | [diff] [blame] | 867 | if (mutex_lock_interruptible(&dvbdemux->mutex)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 868 | return -ERESTARTSYS; |
| 869 | |
| 870 | dvbdmxfilter = dvb_dmx_filter_alloc(dvbdemux); |
| 871 | if (!dvbdmxfilter) { |
Ingo Molnar | 3593cab | 2006-02-07 06:49:14 -0200 | [diff] [blame] | 872 | mutex_unlock(&dvbdemux->mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 873 | return -EBUSY; |
| 874 | } |
| 875 | |
| 876 | spin_lock_irq(&dvbdemux->lock); |
| 877 | *filter = &dvbdmxfilter->filter; |
| 878 | (*filter)->parent = feed; |
| 879 | (*filter)->priv = NULL; |
| 880 | dvbdmxfilter->feed = dvbdmxfeed; |
| 881 | dvbdmxfilter->type = DMX_TYPE_SEC; |
| 882 | dvbdmxfilter->state = DMX_STATE_READY; |
| 883 | dvbdmxfilter->next = dvbdmxfeed->filter; |
| 884 | dvbdmxfeed->filter = dvbdmxfilter; |
| 885 | spin_unlock_irq(&dvbdemux->lock); |
| 886 | |
Ingo Molnar | 3593cab | 2006-02-07 06:49:14 -0200 | [diff] [blame] | 887 | mutex_unlock(&dvbdemux->mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 888 | return 0; |
| 889 | } |
| 890 | |
Andreas Oberritter | dad4a73 | 2005-09-09 13:02:26 -0700 | [diff] [blame] | 891 | static int dmx_section_feed_set(struct dmx_section_feed *feed, |
| 892 | u16 pid, size_t circular_buffer_size, |
| 893 | int check_crc) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 894 | { |
Andreas Oberritter | dad4a73 | 2005-09-09 13:02:26 -0700 | [diff] [blame] | 895 | struct dvb_demux_feed *dvbdmxfeed = (struct dvb_demux_feed *)feed; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 896 | struct dvb_demux *dvbdmx = dvbdmxfeed->demux; |
| 897 | |
| 898 | if (pid > 0x1fff) |
| 899 | return -EINVAL; |
| 900 | |
Ingo Molnar | 3593cab | 2006-02-07 06:49:14 -0200 | [diff] [blame] | 901 | if (mutex_lock_interruptible(&dvbdmx->mutex)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 902 | return -ERESTARTSYS; |
| 903 | |
| 904 | dvb_demux_feed_add(dvbdmxfeed); |
| 905 | |
| 906 | dvbdmxfeed->pid = pid; |
| 907 | dvbdmxfeed->buffer_size = circular_buffer_size; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 908 | dvbdmxfeed->feed.sec.check_crc = check_crc; |
| 909 | |
| 910 | #ifdef NOBUFS |
| 911 | dvbdmxfeed->buffer = NULL; |
| 912 | #else |
Andreas Oberritter | dad4a73 | 2005-09-09 13:02:26 -0700 | [diff] [blame] | 913 | dvbdmxfeed->buffer = vmalloc(dvbdmxfeed->buffer_size); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 914 | if (!dvbdmxfeed->buffer) { |
Ingo Molnar | 3593cab | 2006-02-07 06:49:14 -0200 | [diff] [blame] | 915 | mutex_unlock(&dvbdmx->mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 916 | return -ENOMEM; |
| 917 | } |
| 918 | #endif |
| 919 | |
| 920 | dvbdmxfeed->state = DMX_STATE_READY; |
Ingo Molnar | 3593cab | 2006-02-07 06:49:14 -0200 | [diff] [blame] | 921 | mutex_unlock(&dvbdmx->mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 922 | return 0; |
| 923 | } |
| 924 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 925 | static void prepare_secfilters(struct dvb_demux_feed *dvbdmxfeed) |
| 926 | { |
| 927 | int i; |
| 928 | struct dvb_demux_filter *f; |
| 929 | struct dmx_section_filter *sf; |
| 930 | u8 mask, mode, doneq; |
| 931 | |
Andreas Oberritter | dad4a73 | 2005-09-09 13:02:26 -0700 | [diff] [blame] | 932 | if (!(f = dvbdmxfeed->filter)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 933 | return; |
| 934 | do { |
| 935 | sf = &f->filter; |
| 936 | doneq = 0; |
Andreas Oberritter | dad4a73 | 2005-09-09 13:02:26 -0700 | [diff] [blame] | 937 | for (i = 0; i < DVB_DEMUX_MASK_MAX; i++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 938 | mode = sf->filter_mode[i]; |
| 939 | mask = sf->filter_mask[i]; |
| 940 | f->maskandmode[i] = mask & mode; |
| 941 | doneq |= f->maskandnotmode[i] = mask & ~mode; |
| 942 | } |
| 943 | f->doneq = doneq ? 1 : 0; |
| 944 | } while ((f = f->next)); |
| 945 | } |
| 946 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 947 | static int dmx_section_feed_start_filtering(struct dmx_section_feed *feed) |
| 948 | { |
Andreas Oberritter | dad4a73 | 2005-09-09 13:02:26 -0700 | [diff] [blame] | 949 | struct dvb_demux_feed *dvbdmxfeed = (struct dvb_demux_feed *)feed; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 950 | struct dvb_demux *dvbdmx = dvbdmxfeed->demux; |
| 951 | int ret; |
| 952 | |
Ingo Molnar | 3593cab | 2006-02-07 06:49:14 -0200 | [diff] [blame] | 953 | if (mutex_lock_interruptible(&dvbdmx->mutex)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 954 | return -ERESTARTSYS; |
| 955 | |
| 956 | if (feed->is_filtering) { |
Ingo Molnar | 3593cab | 2006-02-07 06:49:14 -0200 | [diff] [blame] | 957 | mutex_unlock(&dvbdmx->mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 958 | return -EBUSY; |
| 959 | } |
| 960 | |
| 961 | if (!dvbdmxfeed->filter) { |
Ingo Molnar | 3593cab | 2006-02-07 06:49:14 -0200 | [diff] [blame] | 962 | mutex_unlock(&dvbdmx->mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 963 | return -EINVAL; |
| 964 | } |
| 965 | |
| 966 | dvbdmxfeed->feed.sec.tsfeedp = 0; |
| 967 | dvbdmxfeed->feed.sec.secbuf = dvbdmxfeed->feed.sec.secbuf_base; |
| 968 | dvbdmxfeed->feed.sec.secbufp = 0; |
| 969 | dvbdmxfeed->feed.sec.seclen = 0; |
| 970 | |
| 971 | if (!dvbdmx->start_feed) { |
Ingo Molnar | 3593cab | 2006-02-07 06:49:14 -0200 | [diff] [blame] | 972 | mutex_unlock(&dvbdmx->mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 973 | return -ENODEV; |
| 974 | } |
| 975 | |
| 976 | prepare_secfilters(dvbdmxfeed); |
| 977 | |
| 978 | if ((ret = dvbdmx->start_feed(dvbdmxfeed)) < 0) { |
Ingo Molnar | 3593cab | 2006-02-07 06:49:14 -0200 | [diff] [blame] | 979 | mutex_unlock(&dvbdmx->mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 980 | return ret; |
| 981 | } |
| 982 | |
| 983 | spin_lock_irq(&dvbdmx->lock); |
| 984 | feed->is_filtering = 1; |
| 985 | dvbdmxfeed->state = DMX_STATE_GO; |
| 986 | spin_unlock_irq(&dvbdmx->lock); |
| 987 | |
Ingo Molnar | 3593cab | 2006-02-07 06:49:14 -0200 | [diff] [blame] | 988 | mutex_unlock(&dvbdmx->mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 989 | return 0; |
| 990 | } |
| 991 | |
Andreas Oberritter | dad4a73 | 2005-09-09 13:02:26 -0700 | [diff] [blame] | 992 | static int dmx_section_feed_stop_filtering(struct dmx_section_feed *feed) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 993 | { |
Andreas Oberritter | dad4a73 | 2005-09-09 13:02:26 -0700 | [diff] [blame] | 994 | struct dvb_demux_feed *dvbdmxfeed = (struct dvb_demux_feed *)feed; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 995 | struct dvb_demux *dvbdmx = dvbdmxfeed->demux; |
| 996 | int ret; |
| 997 | |
Simon Arlott | c278850 | 2007-03-10 06:21:25 -0300 | [diff] [blame] | 998 | mutex_lock(&dvbdmx->mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 999 | |
| 1000 | if (!dvbdmx->stop_feed) { |
Ingo Molnar | 3593cab | 2006-02-07 06:49:14 -0200 | [diff] [blame] | 1001 | mutex_unlock(&dvbdmx->mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1002 | return -ENODEV; |
| 1003 | } |
| 1004 | |
| 1005 | ret = dvbdmx->stop_feed(dvbdmxfeed); |
| 1006 | |
| 1007 | spin_lock_irq(&dvbdmx->lock); |
| 1008 | dvbdmxfeed->state = DMX_STATE_READY; |
| 1009 | feed->is_filtering = 0; |
| 1010 | spin_unlock_irq(&dvbdmx->lock); |
| 1011 | |
Ingo Molnar | 3593cab | 2006-02-07 06:49:14 -0200 | [diff] [blame] | 1012 | mutex_unlock(&dvbdmx->mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1013 | return ret; |
| 1014 | } |
| 1015 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1016 | static int dmx_section_feed_release_filter(struct dmx_section_feed *feed, |
Andreas Oberritter | dad4a73 | 2005-09-09 13:02:26 -0700 | [diff] [blame] | 1017 | struct dmx_section_filter *filter) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1018 | { |
Andreas Oberritter | dad4a73 | 2005-09-09 13:02:26 -0700 | [diff] [blame] | 1019 | struct dvb_demux_filter *dvbdmxfilter = (struct dvb_demux_filter *)filter, *f; |
| 1020 | struct dvb_demux_feed *dvbdmxfeed = (struct dvb_demux_feed *)feed; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1021 | struct dvb_demux *dvbdmx = dvbdmxfeed->demux; |
| 1022 | |
Simon Arlott | c278850 | 2007-03-10 06:21:25 -0300 | [diff] [blame] | 1023 | mutex_lock(&dvbdmx->mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1024 | |
| 1025 | if (dvbdmxfilter->feed != dvbdmxfeed) { |
Ingo Molnar | 3593cab | 2006-02-07 06:49:14 -0200 | [diff] [blame] | 1026 | mutex_unlock(&dvbdmx->mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1027 | return -EINVAL; |
| 1028 | } |
| 1029 | |
| 1030 | if (feed->is_filtering) |
| 1031 | feed->stop_filtering(feed); |
| 1032 | |
| 1033 | spin_lock_irq(&dvbdmx->lock); |
| 1034 | f = dvbdmxfeed->filter; |
| 1035 | |
| 1036 | if (f == dvbdmxfilter) { |
| 1037 | dvbdmxfeed->filter = dvbdmxfilter->next; |
| 1038 | } else { |
Andreas Oberritter | dad4a73 | 2005-09-09 13:02:26 -0700 | [diff] [blame] | 1039 | while (f->next != dvbdmxfilter) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1040 | f = f->next; |
| 1041 | f->next = f->next->next; |
| 1042 | } |
| 1043 | |
| 1044 | dvbdmxfilter->state = DMX_STATE_FREE; |
| 1045 | spin_unlock_irq(&dvbdmx->lock); |
Ingo Molnar | 3593cab | 2006-02-07 06:49:14 -0200 | [diff] [blame] | 1046 | mutex_unlock(&dvbdmx->mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1047 | return 0; |
| 1048 | } |
| 1049 | |
| 1050 | static int dvbdmx_allocate_section_feed(struct dmx_demux *demux, |
| 1051 | struct dmx_section_feed **feed, |
| 1052 | dmx_section_cb callback) |
| 1053 | { |
Andreas Oberritter | dad4a73 | 2005-09-09 13:02:26 -0700 | [diff] [blame] | 1054 | struct dvb_demux *dvbdmx = (struct dvb_demux *)demux; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1055 | struct dvb_demux_feed *dvbdmxfeed; |
| 1056 | |
Ingo Molnar | 3593cab | 2006-02-07 06:49:14 -0200 | [diff] [blame] | 1057 | if (mutex_lock_interruptible(&dvbdmx->mutex)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1058 | return -ERESTARTSYS; |
| 1059 | |
| 1060 | if (!(dvbdmxfeed = dvb_dmx_feed_alloc(dvbdmx))) { |
Ingo Molnar | 3593cab | 2006-02-07 06:49:14 -0200 | [diff] [blame] | 1061 | mutex_unlock(&dvbdmx->mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1062 | return -EBUSY; |
| 1063 | } |
| 1064 | |
| 1065 | dvbdmxfeed->type = DMX_TYPE_SEC; |
| 1066 | dvbdmxfeed->cb.sec = callback; |
| 1067 | dvbdmxfeed->demux = dvbdmx; |
| 1068 | dvbdmxfeed->pid = 0xffff; |
| 1069 | dvbdmxfeed->feed.sec.secbuf = dvbdmxfeed->feed.sec.secbuf_base; |
| 1070 | dvbdmxfeed->feed.sec.secbufp = dvbdmxfeed->feed.sec.seclen = 0; |
| 1071 | dvbdmxfeed->feed.sec.tsfeedp = 0; |
| 1072 | dvbdmxfeed->filter = NULL; |
| 1073 | dvbdmxfeed->buffer = NULL; |
| 1074 | |
Andreas Oberritter | dad4a73 | 2005-09-09 13:02:26 -0700 | [diff] [blame] | 1075 | (*feed) = &dvbdmxfeed->feed.sec; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1076 | (*feed)->is_filtering = 0; |
| 1077 | (*feed)->parent = demux; |
| 1078 | (*feed)->priv = NULL; |
| 1079 | |
| 1080 | (*feed)->set = dmx_section_feed_set; |
| 1081 | (*feed)->allocate_filter = dmx_section_feed_allocate_filter; |
| 1082 | (*feed)->start_filtering = dmx_section_feed_start_filtering; |
| 1083 | (*feed)->stop_filtering = dmx_section_feed_stop_filtering; |
| 1084 | (*feed)->release_filter = dmx_section_feed_release_filter; |
| 1085 | |
Ingo Molnar | 3593cab | 2006-02-07 06:49:14 -0200 | [diff] [blame] | 1086 | mutex_unlock(&dvbdmx->mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1087 | return 0; |
| 1088 | } |
| 1089 | |
| 1090 | static int dvbdmx_release_section_feed(struct dmx_demux *demux, |
| 1091 | struct dmx_section_feed *feed) |
| 1092 | { |
Andreas Oberritter | dad4a73 | 2005-09-09 13:02:26 -0700 | [diff] [blame] | 1093 | struct dvb_demux_feed *dvbdmxfeed = (struct dvb_demux_feed *)feed; |
| 1094 | struct dvb_demux *dvbdmx = (struct dvb_demux *)demux; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1095 | |
Simon Arlott | c278850 | 2007-03-10 06:21:25 -0300 | [diff] [blame] | 1096 | mutex_lock(&dvbdmx->mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1097 | |
Andreas Oberritter | dad4a73 | 2005-09-09 13:02:26 -0700 | [diff] [blame] | 1098 | if (dvbdmxfeed->state == DMX_STATE_FREE) { |
Ingo Molnar | 3593cab | 2006-02-07 06:49:14 -0200 | [diff] [blame] | 1099 | mutex_unlock(&dvbdmx->mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1100 | return -EINVAL; |
| 1101 | } |
| 1102 | #ifndef NOBUFS |
| 1103 | vfree(dvbdmxfeed->buffer); |
Andreas Oberritter | dad4a73 | 2005-09-09 13:02:26 -0700 | [diff] [blame] | 1104 | dvbdmxfeed->buffer = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1105 | #endif |
Andreas Oberritter | dad4a73 | 2005-09-09 13:02:26 -0700 | [diff] [blame] | 1106 | dvbdmxfeed->state = DMX_STATE_FREE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1107 | |
| 1108 | dvb_demux_feed_del(dvbdmxfeed); |
| 1109 | |
| 1110 | dvbdmxfeed->pid = 0xffff; |
| 1111 | |
Ingo Molnar | 3593cab | 2006-02-07 06:49:14 -0200 | [diff] [blame] | 1112 | mutex_unlock(&dvbdmx->mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1113 | return 0; |
| 1114 | } |
| 1115 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1116 | /****************************************************************************** |
| 1117 | * dvb_demux kernel data API calls |
| 1118 | ******************************************************************************/ |
| 1119 | |
| 1120 | static int dvbdmx_open(struct dmx_demux *demux) |
| 1121 | { |
Andreas Oberritter | dad4a73 | 2005-09-09 13:02:26 -0700 | [diff] [blame] | 1122 | struct dvb_demux *dvbdemux = (struct dvb_demux *)demux; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1123 | |
| 1124 | if (dvbdemux->users >= MAX_DVB_DEMUX_USERS) |
| 1125 | return -EUSERS; |
| 1126 | |
| 1127 | dvbdemux->users++; |
| 1128 | return 0; |
| 1129 | } |
| 1130 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1131 | static int dvbdmx_close(struct dmx_demux *demux) |
| 1132 | { |
Andreas Oberritter | dad4a73 | 2005-09-09 13:02:26 -0700 | [diff] [blame] | 1133 | struct dvb_demux *dvbdemux = (struct dvb_demux *)demux; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1134 | |
| 1135 | if (dvbdemux->users == 0) |
| 1136 | return -ENODEV; |
| 1137 | |
| 1138 | dvbdemux->users--; |
| 1139 | //FIXME: release any unneeded resources if users==0 |
| 1140 | return 0; |
| 1141 | } |
| 1142 | |
Al Viro | 947a080 | 2008-06-22 14:20:19 -0300 | [diff] [blame] | 1143 | static int dvbdmx_write(struct dmx_demux *demux, const char __user *buf, size_t count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1144 | { |
Andreas Oberritter | dad4a73 | 2005-09-09 13:02:26 -0700 | [diff] [blame] | 1145 | struct dvb_demux *dvbdemux = (struct dvb_demux *)demux; |
Al Viro | 947a080 | 2008-06-22 14:20:19 -0300 | [diff] [blame] | 1146 | void *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1147 | |
| 1148 | if ((!demux->frontend) || (demux->frontend->source != DMX_MEMORY_FE)) |
| 1149 | return -EINVAL; |
| 1150 | |
Julia Lawall | c6cfe05 | 2010-05-22 05:21:02 -0300 | [diff] [blame] | 1151 | p = memdup_user(buf, count); |
| 1152 | if (IS_ERR(p)) |
| 1153 | return PTR_ERR(p); |
Al Viro | 947a080 | 2008-06-22 14:20:19 -0300 | [diff] [blame] | 1154 | if (mutex_lock_interruptible(&dvbdemux->mutex)) { |
| 1155 | kfree(p); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1156 | return -ERESTARTSYS; |
Al Viro | 947a080 | 2008-06-22 14:20:19 -0300 | [diff] [blame] | 1157 | } |
| 1158 | dvb_dmx_swfilter(dvbdemux, p, count); |
| 1159 | kfree(p); |
Ingo Molnar | 3593cab | 2006-02-07 06:49:14 -0200 | [diff] [blame] | 1160 | mutex_unlock(&dvbdemux->mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1161 | |
| 1162 | if (signal_pending(current)) |
| 1163 | return -EINTR; |
| 1164 | return count; |
| 1165 | } |
| 1166 | |
Andreas Oberritter | dad4a73 | 2005-09-09 13:02:26 -0700 | [diff] [blame] | 1167 | static int dvbdmx_add_frontend(struct dmx_demux *demux, |
| 1168 | struct dmx_frontend *frontend) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1169 | { |
Andreas Oberritter | dad4a73 | 2005-09-09 13:02:26 -0700 | [diff] [blame] | 1170 | struct dvb_demux *dvbdemux = (struct dvb_demux *)demux; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1171 | struct list_head *head = &dvbdemux->frontend_list; |
| 1172 | |
| 1173 | list_add(&(frontend->connectivity_list), head); |
| 1174 | |
| 1175 | return 0; |
| 1176 | } |
| 1177 | |
Andreas Oberritter | dad4a73 | 2005-09-09 13:02:26 -0700 | [diff] [blame] | 1178 | static int dvbdmx_remove_frontend(struct dmx_demux *demux, |
| 1179 | struct dmx_frontend *frontend) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1180 | { |
Andreas Oberritter | dad4a73 | 2005-09-09 13:02:26 -0700 | [diff] [blame] | 1181 | struct dvb_demux *dvbdemux = (struct dvb_demux *)demux; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1182 | struct list_head *pos, *n, *head = &dvbdemux->frontend_list; |
| 1183 | |
Andreas Oberritter | dad4a73 | 2005-09-09 13:02:26 -0700 | [diff] [blame] | 1184 | list_for_each_safe(pos, n, head) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1185 | if (DMX_FE_ENTRY(pos) == frontend) { |
| 1186 | list_del(pos); |
| 1187 | return 0; |
| 1188 | } |
| 1189 | } |
| 1190 | |
| 1191 | return -ENODEV; |
| 1192 | } |
| 1193 | |
Andreas Oberritter | dad4a73 | 2005-09-09 13:02:26 -0700 | [diff] [blame] | 1194 | static struct list_head *dvbdmx_get_frontends(struct dmx_demux *demux) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1195 | { |
Andreas Oberritter | dad4a73 | 2005-09-09 13:02:26 -0700 | [diff] [blame] | 1196 | struct dvb_demux *dvbdemux = (struct dvb_demux *)demux; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1197 | |
| 1198 | if (list_empty(&dvbdemux->frontend_list)) |
| 1199 | return NULL; |
Andreas Oberritter | dad4a73 | 2005-09-09 13:02:26 -0700 | [diff] [blame] | 1200 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1201 | return &dvbdemux->frontend_list; |
| 1202 | } |
| 1203 | |
Andreas Oberritter | dad4a73 | 2005-09-09 13:02:26 -0700 | [diff] [blame] | 1204 | static int dvbdmx_connect_frontend(struct dmx_demux *demux, |
| 1205 | struct dmx_frontend *frontend) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1206 | { |
Andreas Oberritter | dad4a73 | 2005-09-09 13:02:26 -0700 | [diff] [blame] | 1207 | struct dvb_demux *dvbdemux = (struct dvb_demux *)demux; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1208 | |
| 1209 | if (demux->frontend) |
| 1210 | return -EINVAL; |
| 1211 | |
Simon Arlott | c278850 | 2007-03-10 06:21:25 -0300 | [diff] [blame] | 1212 | mutex_lock(&dvbdemux->mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1213 | |
| 1214 | demux->frontend = frontend; |
Ingo Molnar | 3593cab | 2006-02-07 06:49:14 -0200 | [diff] [blame] | 1215 | mutex_unlock(&dvbdemux->mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1216 | return 0; |
| 1217 | } |
| 1218 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1219 | static int dvbdmx_disconnect_frontend(struct dmx_demux *demux) |
| 1220 | { |
Andreas Oberritter | dad4a73 | 2005-09-09 13:02:26 -0700 | [diff] [blame] | 1221 | struct dvb_demux *dvbdemux = (struct dvb_demux *)demux; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1222 | |
Simon Arlott | c278850 | 2007-03-10 06:21:25 -0300 | [diff] [blame] | 1223 | mutex_lock(&dvbdemux->mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1224 | |
| 1225 | demux->frontend = NULL; |
Ingo Molnar | 3593cab | 2006-02-07 06:49:14 -0200 | [diff] [blame] | 1226 | mutex_unlock(&dvbdemux->mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1227 | return 0; |
| 1228 | } |
| 1229 | |
Andreas Oberritter | dad4a73 | 2005-09-09 13:02:26 -0700 | [diff] [blame] | 1230 | static int dvbdmx_get_pes_pids(struct dmx_demux *demux, u16 * pids) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1231 | { |
Andreas Oberritter | dad4a73 | 2005-09-09 13:02:26 -0700 | [diff] [blame] | 1232 | struct dvb_demux *dvbdemux = (struct dvb_demux *)demux; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1233 | |
Andreas Oberritter | dad4a73 | 2005-09-09 13:02:26 -0700 | [diff] [blame] | 1234 | memcpy(pids, dvbdemux->pids, 5 * sizeof(u16)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1235 | return 0; |
| 1236 | } |
| 1237 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1238 | int dvb_dmx_init(struct dvb_demux *dvbdemux) |
| 1239 | { |
Andreas Oberritter | 9365346 | 2005-09-09 13:02:23 -0700 | [diff] [blame] | 1240 | int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1241 | struct dmx_demux *dmx = &dvbdemux->dmx; |
| 1242 | |
Abylay Ospan | 0d83463 | 2009-06-06 09:31:34 -0300 | [diff] [blame] | 1243 | dvbdemux->cnt_storage = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1244 | dvbdemux->users = 0; |
Andreas Oberritter | dad4a73 | 2005-09-09 13:02:26 -0700 | [diff] [blame] | 1245 | dvbdemux->filter = vmalloc(dvbdemux->filternum * sizeof(struct dvb_demux_filter)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1246 | |
| 1247 | if (!dvbdemux->filter) |
| 1248 | return -ENOMEM; |
| 1249 | |
Andreas Oberritter | dad4a73 | 2005-09-09 13:02:26 -0700 | [diff] [blame] | 1250 | dvbdemux->feed = vmalloc(dvbdemux->feednum * sizeof(struct dvb_demux_feed)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1251 | if (!dvbdemux->feed) { |
| 1252 | vfree(dvbdemux->filter); |
Mauro Carvalho Chehab | adefdce | 2010-02-01 10:35:22 -0300 | [diff] [blame] | 1253 | dvbdemux->filter = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1254 | return -ENOMEM; |
| 1255 | } |
Andreas Oberritter | dad4a73 | 2005-09-09 13:02:26 -0700 | [diff] [blame] | 1256 | for (i = 0; i < dvbdemux->filternum; i++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1257 | dvbdemux->filter[i].state = DMX_STATE_FREE; |
| 1258 | dvbdemux->filter[i].index = i; |
| 1259 | } |
Andreas Oberritter | dad4a73 | 2005-09-09 13:02:26 -0700 | [diff] [blame] | 1260 | for (i = 0; i < dvbdemux->feednum; i++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1261 | dvbdemux->feed[i].state = DMX_STATE_FREE; |
| 1262 | dvbdemux->feed[i].index = i; |
| 1263 | } |
Andreas Oberritter | db574d7 | 2005-09-09 13:02:26 -0700 | [diff] [blame] | 1264 | |
Abylay Ospan | ab6a21f | 2010-03-06 14:58:01 -0300 | [diff] [blame] | 1265 | dvbdemux->cnt_storage = vmalloc(MAX_PID + 1); |
| 1266 | if (!dvbdemux->cnt_storage) |
| 1267 | printk(KERN_WARNING "Couldn't allocate memory for TS/TEI check. Disabling it\n"); |
Mauro Carvalho Chehab | bc081cc | 2010-02-01 11:50:42 -0300 | [diff] [blame] | 1268 | |
Andreas Oberritter | db574d7 | 2005-09-09 13:02:26 -0700 | [diff] [blame] | 1269 | INIT_LIST_HEAD(&dvbdemux->frontend_list); |
| 1270 | |
Mauro Carvalho Chehab | fde04ab | 2013-04-04 13:25:30 -0300 | [diff] [blame] | 1271 | for (i = 0; i < DMX_PES_OTHER; i++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1272 | dvbdemux->pesfilter[i] = NULL; |
| 1273 | dvbdemux->pids[i] = 0xffff; |
| 1274 | } |
| 1275 | |
| 1276 | INIT_LIST_HEAD(&dvbdemux->feed_list); |
| 1277 | |
| 1278 | dvbdemux->playing = 0; |
| 1279 | dvbdemux->recording = 0; |
| 1280 | dvbdemux->tsbufp = 0; |
| 1281 | |
| 1282 | if (!dvbdemux->check_crc32) |
| 1283 | dvbdemux->check_crc32 = dvb_dmx_crc32; |
| 1284 | |
Andreas Oberritter | dad4a73 | 2005-09-09 13:02:26 -0700 | [diff] [blame] | 1285 | if (!dvbdemux->memcopy) |
| 1286 | dvbdemux->memcopy = dvb_dmx_memcopy; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1287 | |
| 1288 | dmx->frontend = NULL; |
Andreas Oberritter | dad4a73 | 2005-09-09 13:02:26 -0700 | [diff] [blame] | 1289 | dmx->priv = dvbdemux; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1290 | dmx->open = dvbdmx_open; |
| 1291 | dmx->close = dvbdmx_close; |
| 1292 | dmx->write = dvbdmx_write; |
| 1293 | dmx->allocate_ts_feed = dvbdmx_allocate_ts_feed; |
| 1294 | dmx->release_ts_feed = dvbdmx_release_ts_feed; |
| 1295 | dmx->allocate_section_feed = dvbdmx_allocate_section_feed; |
| 1296 | dmx->release_section_feed = dvbdmx_release_section_feed; |
| 1297 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1298 | dmx->add_frontend = dvbdmx_add_frontend; |
| 1299 | dmx->remove_frontend = dvbdmx_remove_frontend; |
| 1300 | dmx->get_frontends = dvbdmx_get_frontends; |
| 1301 | dmx->connect_frontend = dvbdmx_connect_frontend; |
| 1302 | dmx->disconnect_frontend = dvbdmx_disconnect_frontend; |
| 1303 | dmx->get_pes_pids = dvbdmx_get_pes_pids; |
| 1304 | |
Ingo Molnar | 3593cab | 2006-02-07 06:49:14 -0200 | [diff] [blame] | 1305 | mutex_init(&dvbdemux->mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1306 | spin_lock_init(&dvbdemux->lock); |
| 1307 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1308 | return 0; |
| 1309 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1310 | |
Andreas Oberritter | dad4a73 | 2005-09-09 13:02:26 -0700 | [diff] [blame] | 1311 | EXPORT_SYMBOL(dvb_dmx_init); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1312 | |
Andreas Oberritter | 9365346 | 2005-09-09 13:02:23 -0700 | [diff] [blame] | 1313 | void dvb_dmx_release(struct dvb_demux *dvbdemux) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1314 | { |
Abylay Ospan | 0d83463 | 2009-06-06 09:31:34 -0300 | [diff] [blame] | 1315 | vfree(dvbdemux->cnt_storage); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1316 | vfree(dvbdemux->filter); |
| 1317 | vfree(dvbdemux->feed); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1318 | } |
Andreas Oberritter | dad4a73 | 2005-09-09 13:02:26 -0700 | [diff] [blame] | 1319 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1320 | EXPORT_SYMBOL(dvb_dmx_release); |