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