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 | * |
Hamad Kadmany | d432f71 | 2013-01-17 17:36:17 +0200 | [diff] [blame] | 8 | * Copyright (c) 2012-2013, The Linux Foundation. All rights reserved. |
Hamad Kadmany | 32cb982 | 2012-05-10 08:47:44 +0300 | [diff] [blame] | 9 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10 | * This program is free software; you can redistribute it and/or |
| 11 | * modify it under the terms of the GNU Lesser General Public License |
| 12 | * as published by the Free Software Foundation; either version 2.1 |
| 13 | * of the License, or (at your option) any later version. |
| 14 | * |
| 15 | * This program is distributed in the hope that it will be useful, |
| 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 18 | * GNU General Public License for more details. |
| 19 | * |
| 20 | * You should have received a copy of the GNU Lesser General Public License |
| 21 | * along with this program; if not, write to the Free Software |
| 22 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
| 23 | * |
| 24 | */ |
| 25 | |
Alexey Dobriyan | a99bbaf | 2009-10-04 16:11:37 +0400 | [diff] [blame] | 26 | #include <linux/sched.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 27 | #include <linux/spinlock.h> |
| 28 | #include <linux/slab.h> |
| 29 | #include <linux/vmalloc.h> |
| 30 | #include <linux/module.h> |
| 31 | #include <linux/poll.h> |
| 32 | #include <linux/string.h> |
| 33 | #include <linux/crc32.h> |
| 34 | #include <asm/uaccess.h> |
Abylay Ospan | 26b9d6c | 2009-11-01 18:46:53 -0300 | [diff] [blame] | 35 | #include <asm/div64.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 36 | |
| 37 | #include "dvb_demux.h" |
| 38 | |
| 39 | #define NOBUFS |
| 40 | /* |
| 41 | ** #define DVB_DEMUX_SECTION_LOSS_LOG to monitor payload loss in the syslog |
| 42 | */ |
| 43 | // #define DVB_DEMUX_SECTION_LOSS_LOG |
| 44 | |
Abylay Ospan | 0d83463 | 2009-06-06 09:31:34 -0300 | [diff] [blame] | 45 | static int dvb_demux_tscheck; |
| 46 | module_param(dvb_demux_tscheck, int, 0644); |
| 47 | MODULE_PARM_DESC(dvb_demux_tscheck, |
| 48 | "enable transport stream continuity and TEI check"); |
| 49 | |
Abylay Ospan | 26b9d6c | 2009-11-01 18:46:53 -0300 | [diff] [blame] | 50 | static int dvb_demux_speedcheck; |
| 51 | module_param(dvb_demux_speedcheck, int, 0644); |
| 52 | MODULE_PARM_DESC(dvb_demux_speedcheck, |
| 53 | "enable transport stream speed check"); |
| 54 | |
Hamad Kadmany | 32cb982 | 2012-05-10 08:47:44 +0300 | [diff] [blame] | 55 | /* counter advancing for each new dvb-demux device */ |
| 56 | static int dvb_demux_index; |
| 57 | |
| 58 | static int dvb_demux_performancecheck; |
| 59 | module_param(dvb_demux_performancecheck, int, 0644); |
| 60 | MODULE_PARM_DESC(dvb_demux_performancecheck, |
| 61 | "enable transport stream performance check, reported through debugfs"); |
| 62 | |
Abylay Ospan | 0d83463 | 2009-06-06 09:31:34 -0300 | [diff] [blame] | 63 | #define dprintk_tscheck(x...) do { \ |
| 64 | if (dvb_demux_tscheck && printk_ratelimit()) \ |
| 65 | printk(x); \ |
| 66 | } while (0) |
| 67 | |
Hamad Kadmany | e1dba20 | 2013-04-10 18:37:25 +0300 | [diff] [blame] | 68 | static const struct dvb_dmx_video_patterns mpeg2_seq_hdr = { |
| 69 | {0x00, 0x00, 0x01, 0xB3}, |
| 70 | {0xFF, 0xFF, 0xFF, 0xFF}, |
| 71 | 4, |
| 72 | DMX_IDX_MPEG_SEQ_HEADER |
| 73 | }; |
| 74 | |
| 75 | static const struct dvb_dmx_video_patterns mpeg2_gop = { |
| 76 | {0x00, 0x00, 0x01, 0xB8}, |
| 77 | {0xFF, 0xFF, 0xFF, 0xFF}, |
| 78 | 4, |
| 79 | DMX_IDX_MPEG_GOP |
| 80 | }; |
| 81 | |
| 82 | static const struct dvb_dmx_video_patterns mpeg2_iframe = { |
| 83 | {0x00, 0x00, 0x01, 0x00, 0x00, 0x08}, |
| 84 | {0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x38}, |
| 85 | 6, |
| 86 | DMX_IDX_MPEG_I_FRAME_START |
| 87 | }; |
| 88 | |
| 89 | static const struct dvb_dmx_video_patterns mpeg2_pframe = { |
| 90 | {0x00, 0x00, 0x01, 0x00, 0x00, 0x10}, |
| 91 | {0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x38}, |
| 92 | 6, |
| 93 | DMX_IDX_MPEG_P_FRAME_START |
| 94 | }; |
| 95 | |
| 96 | static const struct dvb_dmx_video_patterns mpeg2_bframe = { |
| 97 | {0x00, 0x00, 0x01, 0x00, 0x00, 0x18}, |
| 98 | {0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x38}, |
| 99 | 6, |
| 100 | DMX_IDX_MPEG_B_FRAME_START |
| 101 | }; |
| 102 | |
| 103 | static const struct dvb_dmx_video_patterns h264_sps = { |
| 104 | {0x00, 0x00, 0x01, 0x07}, |
| 105 | {0xFF, 0xFF, 0xFF, 0x1F}, |
| 106 | 4, |
| 107 | DMX_IDX_H264_SPS |
| 108 | }; |
| 109 | |
| 110 | static const struct dvb_dmx_video_patterns h264_pps = { |
| 111 | {0x00, 0x00, 0x01, 0x08}, |
| 112 | {0xFF, 0xFF, 0xFF, 0x1F}, |
| 113 | 4, |
| 114 | DMX_IDX_H264_PPS |
| 115 | }; |
| 116 | |
| 117 | static const struct dvb_dmx_video_patterns h264_idr = { |
| 118 | {0x00, 0x00, 0x01, 0x05, 0x80}, |
| 119 | {0xFF, 0xFF, 0xFF, 0x1F, 0x80}, |
| 120 | 5, |
| 121 | DMX_IDX_H264_IDR_START |
| 122 | }; |
| 123 | |
| 124 | static const struct dvb_dmx_video_patterns h264_non_idr = { |
| 125 | {0x00, 0x00, 0x01, 0x01, 0x80}, |
| 126 | {0xFF, 0xFF, 0xFF, 0x1F, 0x80}, |
| 127 | 5, |
| 128 | DMX_IDX_H264_NON_IDR_START |
| 129 | }; |
| 130 | |
| 131 | static const struct dvb_dmx_video_patterns vc1_seq_hdr = { |
| 132 | {0x00, 0x00, 0x01, 0x0F}, |
| 133 | {0xFF, 0xFF, 0xFF, 0xFF}, |
| 134 | 4, |
| 135 | DMX_IDX_VC1_SEQ_HEADER |
| 136 | }; |
| 137 | |
| 138 | static const struct dvb_dmx_video_patterns vc1_entry_point = { |
| 139 | {0x00, 0x00, 0x01, 0x0E}, |
| 140 | {0xFF, 0xFF, 0xFF, 0xFF}, |
| 141 | 4, |
| 142 | DMX_IDX_VC1_ENTRY_POINT |
| 143 | }; |
| 144 | |
| 145 | static const struct dvb_dmx_video_patterns vc1_frame = { |
| 146 | {0x00, 0x00, 0x01, 0x0D}, |
| 147 | {0xFF, 0xFF, 0xFF, 0xFF}, |
| 148 | 4, |
| 149 | DMX_IDX_VC1_FRAME_START |
| 150 | }; |
| 151 | |
| 152 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 153 | /****************************************************************************** |
| 154 | * static inlined helper functions |
| 155 | ******************************************************************************/ |
| 156 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 157 | static inline u16 section_length(const u8 *buf) |
| 158 | { |
Andreas Oberritter | dad4a73 | 2005-09-09 13:02:26 -0700 | [diff] [blame] | 159 | return 3 + ((buf[1] & 0x0f) << 8) + buf[2]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 160 | } |
| 161 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 162 | static inline u16 ts_pid(const u8 *buf) |
| 163 | { |
Andreas Oberritter | dad4a73 | 2005-09-09 13:02:26 -0700 | [diff] [blame] | 164 | return ((buf[1] & 0x1f) << 8) + buf[2]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 165 | } |
| 166 | |
Hamad Kadmany | d0abf31 | 2013-05-13 18:56:06 +0300 | [diff] [blame] | 167 | static inline u16 ts_scrambling_ctrl(const u8 *buf) |
| 168 | { |
| 169 | return (buf[3] >> 6) & 0x3; |
| 170 | } |
| 171 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 172 | static inline u8 payload(const u8 *tsp) |
| 173 | { |
Andreas Oberritter | dad4a73 | 2005-09-09 13:02:26 -0700 | [diff] [blame] | 174 | if (!(tsp[3] & 0x10)) // no payload? |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 175 | return 0; |
Andreas Oberritter | dad4a73 | 2005-09-09 13:02:26 -0700 | [diff] [blame] | 176 | |
| 177 | if (tsp[3] & 0x20) { // adaptation field? |
| 178 | if (tsp[4] > 183) // corrupted data? |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 179 | return 0; |
| 180 | else |
Andreas Oberritter | dad4a73 | 2005-09-09 13:02:26 -0700 | [diff] [blame] | 181 | return 184 - 1 - tsp[4]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 182 | } |
Andreas Oberritter | dad4a73 | 2005-09-09 13:02:26 -0700 | [diff] [blame] | 183 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 184 | return 184; |
| 185 | } |
| 186 | |
Andreas Oberritter | dad4a73 | 2005-09-09 13:02:26 -0700 | [diff] [blame] | 187 | 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] | 188 | { |
Andreas Oberritter | dad4a73 | 2005-09-09 13:02:26 -0700 | [diff] [blame] | 189 | 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] | 190 | } |
| 191 | |
Andreas Oberritter | dad4a73 | 2005-09-09 13:02:26 -0700 | [diff] [blame] | 192 | static void dvb_dmx_memcopy(struct dvb_demux_feed *f, u8 *d, const u8 *s, |
| 193 | size_t len) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 194 | { |
Andreas Oberritter | dad4a73 | 2005-09-09 13:02:26 -0700 | [diff] [blame] | 195 | memcpy(d, s, len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 196 | } |
| 197 | |
Hamad Kadmany | 32cb982 | 2012-05-10 08:47:44 +0300 | [diff] [blame] | 198 | static u32 dvb_dmx_calc_time_delta(struct timespec past_time) |
| 199 | { |
| 200 | struct timespec curr_time, delta_time; |
| 201 | u64 delta_time_us; |
| 202 | |
| 203 | curr_time = current_kernel_time(); |
| 204 | delta_time = timespec_sub(curr_time, past_time); |
| 205 | delta_time_us = ((s64)delta_time.tv_sec * USEC_PER_SEC) + |
| 206 | delta_time.tv_nsec / 1000; |
| 207 | |
| 208 | return (u32)delta_time_us; |
| 209 | } |
| 210 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 211 | /****************************************************************************** |
| 212 | * Software filter functions |
| 213 | ******************************************************************************/ |
| 214 | |
Hamad Kadmany | c37dee8 | 2013-04-10 18:14:48 +0300 | [diff] [blame] | 215 | /* |
| 216 | * Check if two patterns are identical, taking mask into consideration. |
| 217 | * @pattern1: the first byte pattern to compare. |
| 218 | * @pattern2: the second byte pattern to compare. |
| 219 | * @mask: the bit mask to use. |
| 220 | * @pattern_size: the length of both patterns and the mask, in bytes. |
| 221 | * |
| 222 | * Return: 1 if patterns match, 0 otherwise. |
| 223 | */ |
| 224 | static inline int dvb_dmx_patterns_match(const u8 *pattern1, const u8 *pattern2, |
| 225 | const u8 *mask, size_t pattern_size) |
| 226 | { |
| 227 | int i; |
| 228 | |
| 229 | /* |
| 230 | * Assumption: it is OK to access pattern1, pattern2 and mask. |
| 231 | * This function performs no sanity checks to keep things fast. |
| 232 | */ |
| 233 | |
| 234 | for (i = 0; i < pattern_size; i++) |
| 235 | if ((pattern1[i] & mask[i]) != (pattern2[i] & mask[i])) |
| 236 | return 0; |
| 237 | |
| 238 | return 1; |
| 239 | } |
| 240 | |
| 241 | /* |
| 242 | * dvb_dmx_video_pattern_search - |
| 243 | * search for framing patterns in a given buffer. |
| 244 | * |
| 245 | * Optimized version: first search for a common substring, e.g. 0x00 0x00 0x01. |
| 246 | * If this string is found, go over all the given patterns (all must start |
| 247 | * with this string) and search for their ending in the buffer. |
| 248 | * |
| 249 | * Assumption: the patterns we look for do not spread over more than two |
| 250 | * buffers. |
| 251 | * |
| 252 | * @paterns: the full patterns information to look for. |
| 253 | * @patterns_num: the number of patterns to look for. |
| 254 | * @buf: the buffer to search. |
| 255 | * @buf_size: the size of the buffer to search. we search the entire buffer. |
| 256 | * @prefix_size_masks: a bit mask (per pattern) of possible prefix sizes to use |
| 257 | * when searching for a pattern that started at the last buffer. |
| 258 | * Updated in this function for use in the next lookup. |
| 259 | * @results: lookup results (offset, type, used_prefix_size) per found pattern, |
| 260 | * up to DVB_DMX_MAX_FOUND_PATTERNS. |
| 261 | * |
| 262 | * Return: |
| 263 | * Number of patterns found (up to DVB_DMX_MAX_FOUND_PATTERNS). |
| 264 | * 0 if pattern was not found. |
| 265 | * error value on failure. |
| 266 | */ |
| 267 | int dvb_dmx_video_pattern_search( |
Hamad Kadmany | e1dba20 | 2013-04-10 18:37:25 +0300 | [diff] [blame] | 268 | const struct dvb_dmx_video_patterns |
| 269 | *patterns[DVB_DMX_MAX_SEARCH_PATTERN_NUM], |
Hamad Kadmany | c37dee8 | 2013-04-10 18:14:48 +0300 | [diff] [blame] | 270 | int patterns_num, |
| 271 | const u8 *buf, |
| 272 | size_t buf_size, |
| 273 | struct dvb_dmx_video_prefix_size_masks *prefix_size_masks, |
| 274 | struct dvb_dmx_video_patterns_results *results) |
| 275 | { |
| 276 | int i, j; |
| 277 | unsigned int current_size; |
| 278 | u32 prefix; |
| 279 | int found = 0; |
| 280 | int start_offset = 0; |
| 281 | /* the starting common substring to look for */ |
| 282 | u8 string[] = {0x00, 0x00, 0x01}; |
| 283 | /* the mask for the starting string */ |
| 284 | u8 string_mask[] = {0xFF, 0xFF, 0xFF}; |
| 285 | /* the size of the starting string (in bytes) */ |
| 286 | size_t string_size = 3; |
| 287 | |
| 288 | if ((patterns == NULL) || (patterns_num <= 0) || (buf == NULL)) |
| 289 | return -EINVAL; |
| 290 | |
| 291 | memset(results, 0, sizeof(struct dvb_dmx_video_patterns_results)); |
| 292 | |
| 293 | /* |
| 294 | * handle prefix - disregard string, simply check all patterns, |
| 295 | * looking for a matching suffix at the very beginning of the buffer. |
| 296 | */ |
| 297 | for (j = 0; (j < patterns_num) && !found; j++) { |
| 298 | prefix = prefix_size_masks->size_mask[j]; |
| 299 | current_size = 32; |
| 300 | while (prefix) { |
| 301 | if (prefix & (0x1 << (current_size - 1))) { |
| 302 | /* |
| 303 | * check that we don't look further |
| 304 | * than buf_size boundary |
| 305 | */ |
Hamad Kadmany | e1dba20 | 2013-04-10 18:37:25 +0300 | [diff] [blame] | 306 | if ((int)(patterns[j]->size - current_size) > |
Hamad Kadmany | c37dee8 | 2013-04-10 18:14:48 +0300 | [diff] [blame] | 307 | buf_size) |
| 308 | break; |
| 309 | |
| 310 | if (dvb_dmx_patterns_match( |
Hamad Kadmany | e1dba20 | 2013-04-10 18:37:25 +0300 | [diff] [blame] | 311 | (patterns[j]->pattern + current_size), |
| 312 | buf, (patterns[j]->mask + current_size), |
| 313 | (patterns[j]->size - current_size))) { |
Hamad Kadmany | c37dee8 | 2013-04-10 18:14:48 +0300 | [diff] [blame] | 314 | |
| 315 | /* |
| 316 | * pattern found using prefix at the |
| 317 | * very beginning of the buffer, so |
| 318 | * offset is 0, but we already zeroed |
| 319 | * everything in the beginning of the |
| 320 | * function. that's why the next line |
| 321 | * is commented. |
| 322 | */ |
| 323 | /* results->info[found].offset = 0; */ |
| 324 | results->info[found].type = |
Hamad Kadmany | e1dba20 | 2013-04-10 18:37:25 +0300 | [diff] [blame] | 325 | patterns[j]->type; |
Hamad Kadmany | c37dee8 | 2013-04-10 18:14:48 +0300 | [diff] [blame] | 326 | results->info[found].used_prefix_size = |
| 327 | current_size; |
| 328 | found++; |
| 329 | /* |
| 330 | * save offset to start looking from |
| 331 | * in the buffer, to avoid reusing the |
| 332 | * data of a pattern we already found. |
| 333 | */ |
Hamad Kadmany | e1dba20 | 2013-04-10 18:37:25 +0300 | [diff] [blame] | 334 | start_offset = (patterns[j]->size - |
Hamad Kadmany | c37dee8 | 2013-04-10 18:14:48 +0300 | [diff] [blame] | 335 | current_size); |
| 336 | |
| 337 | if (found >= DVB_DMX_MAX_FOUND_PATTERNS) |
| 338 | goto next_prefix_lookup; |
| 339 | /* |
| 340 | * we don't want to search for the same |
| 341 | * pattern with several possible prefix |
| 342 | * sizes if we have already found it, |
| 343 | * so we break from the inner loop. |
| 344 | * since we incremented 'found', we |
| 345 | * will not search for additional |
| 346 | * patterns using a prefix - that would |
| 347 | * imply ambiguous patterns where one |
| 348 | * pattern can be included in another. |
| 349 | * the for loop will exit. |
| 350 | */ |
| 351 | break; |
| 352 | } |
| 353 | } |
| 354 | prefix &= ~(0x1 << (current_size - 1)); |
| 355 | current_size--; |
| 356 | } |
| 357 | } |
| 358 | |
| 359 | /* |
| 360 | * Search buffer for entire pattern, starting with the string. |
| 361 | * Note the external for loop does not execute if buf_size is |
| 362 | * smaller than string_size (the cast to int is required, since |
| 363 | * size_t is unsigned). |
| 364 | */ |
| 365 | for (i = start_offset; i < (int)(buf_size - string_size + 1); i++) { |
| 366 | if (dvb_dmx_patterns_match(string, (buf + i), string_mask, |
| 367 | string_size)) { |
| 368 | /* now search for patterns: */ |
| 369 | for (j = 0; j < patterns_num; j++) { |
| 370 | /* avoid overflow to next buffer */ |
Hamad Kadmany | e1dba20 | 2013-04-10 18:37:25 +0300 | [diff] [blame] | 371 | if ((i + patterns[j]->size) > buf_size) |
Hamad Kadmany | c37dee8 | 2013-04-10 18:14:48 +0300 | [diff] [blame] | 372 | continue; |
| 373 | |
| 374 | if (dvb_dmx_patterns_match( |
Hamad Kadmany | e1dba20 | 2013-04-10 18:37:25 +0300 | [diff] [blame] | 375 | (patterns[j]->pattern + string_size), |
Hamad Kadmany | c37dee8 | 2013-04-10 18:14:48 +0300 | [diff] [blame] | 376 | (buf + i + string_size), |
Hamad Kadmany | e1dba20 | 2013-04-10 18:37:25 +0300 | [diff] [blame] | 377 | (patterns[j]->mask + string_size), |
| 378 | (patterns[j]->size - string_size))) { |
Hamad Kadmany | c37dee8 | 2013-04-10 18:14:48 +0300 | [diff] [blame] | 379 | |
| 380 | results->info[found].offset = i; |
| 381 | results->info[found].type = |
Hamad Kadmany | e1dba20 | 2013-04-10 18:37:25 +0300 | [diff] [blame] | 382 | patterns[j]->type; |
Hamad Kadmany | c37dee8 | 2013-04-10 18:14:48 +0300 | [diff] [blame] | 383 | /* |
| 384 | * save offset to start next prefix |
| 385 | * lookup, to avoid reusing the data |
| 386 | * of any pattern we already found. |
| 387 | */ |
Hamad Kadmany | e1dba20 | 2013-04-10 18:37:25 +0300 | [diff] [blame] | 388 | if ((i + patterns[j]->size) > |
Hamad Kadmany | c37dee8 | 2013-04-10 18:14:48 +0300 | [diff] [blame] | 389 | start_offset) |
| 390 | start_offset = (i + |
Hamad Kadmany | e1dba20 | 2013-04-10 18:37:25 +0300 | [diff] [blame] | 391 | patterns[j]->size); |
Hamad Kadmany | c37dee8 | 2013-04-10 18:14:48 +0300 | [diff] [blame] | 392 | /* |
| 393 | * did not use a prefix to find this |
| 394 | * pattern, but we zeroed everything |
| 395 | * in the beginning of the function. |
| 396 | * So no need to zero used_prefix_size |
| 397 | * for results->info[found] |
| 398 | */ |
| 399 | |
| 400 | found++; |
| 401 | if (found >= DVB_DMX_MAX_FOUND_PATTERNS) |
| 402 | goto next_prefix_lookup; |
| 403 | /* |
| 404 | * theoretically we don't have to break |
| 405 | * here, but we don't want to search |
| 406 | * for the other matching patterns on |
| 407 | * the very same same place in the |
| 408 | * buffer. That would mean the |
| 409 | * (pattern & mask) combinations are |
| 410 | * not unique. So we break from inner |
| 411 | * loop and move on to the next place |
| 412 | * in the buffer. |
| 413 | */ |
| 414 | break; |
| 415 | } |
| 416 | } |
| 417 | } |
| 418 | } |
| 419 | |
| 420 | next_prefix_lookup: |
| 421 | /* check for possible prefix sizes for the next buffer */ |
| 422 | for (j = 0; j < patterns_num; j++) { |
| 423 | prefix_size_masks->size_mask[j] = 0; |
Hamad Kadmany | e1dba20 | 2013-04-10 18:37:25 +0300 | [diff] [blame] | 424 | for (i = 1; i < patterns[j]->size; i++) { |
Hamad Kadmany | c37dee8 | 2013-04-10 18:14:48 +0300 | [diff] [blame] | 425 | /* |
| 426 | * avoid looking outside of the buffer |
| 427 | * or reusing previously used data. |
| 428 | */ |
| 429 | if (i > (buf_size - start_offset)) |
| 430 | break; |
| 431 | |
Hamad Kadmany | e1dba20 | 2013-04-10 18:37:25 +0300 | [diff] [blame] | 432 | if (dvb_dmx_patterns_match(patterns[j]->pattern, |
Hamad Kadmany | c37dee8 | 2013-04-10 18:14:48 +0300 | [diff] [blame] | 433 | (buf + buf_size - i), |
Hamad Kadmany | e1dba20 | 2013-04-10 18:37:25 +0300 | [diff] [blame] | 434 | patterns[j]->mask, i)) { |
Hamad Kadmany | c37dee8 | 2013-04-10 18:14:48 +0300 | [diff] [blame] | 435 | prefix_size_masks->size_mask[j] |= |
| 436 | (1 << (i - 1)); |
| 437 | } |
| 438 | } |
| 439 | } |
| 440 | |
| 441 | return found; |
| 442 | } |
| 443 | EXPORT_SYMBOL(dvb_dmx_video_pattern_search); |
| 444 | |
Gilad Broner | acb4b87 | 2013-05-30 18:55:59 +0300 | [diff] [blame] | 445 | /** |
| 446 | * dvb_dmx_notify_section_event() - Notify demux event for all filters of a |
| 447 | * specified section feed. |
| 448 | * |
| 449 | * @feed: dvb_demux_feed object |
| 450 | * @event: demux event to notify |
| 451 | * @should_lock: specifies whether the function should lock the demux |
| 452 | * |
| 453 | * Caller is responsible for locking the demux properly, either by doing the |
| 454 | * locking itself and setting 'should_lock' to 0, or have the function do it |
| 455 | * by setting 'should_lock' to 1. |
| 456 | */ |
| 457 | int dvb_dmx_notify_section_event(struct dvb_demux_feed *feed, |
| 458 | struct dmx_data_ready *event, int should_lock) |
| 459 | { |
| 460 | struct dvb_demux_filter *f; |
| 461 | |
| 462 | if (feed == NULL || event == NULL || feed->type != DMX_TYPE_SEC) |
| 463 | return -EINVAL; |
| 464 | |
| 465 | if (!should_lock && !spin_is_locked(&feed->demux->lock)) |
| 466 | return -EINVAL; |
| 467 | |
| 468 | if (should_lock) |
| 469 | spin_lock(&feed->demux->lock); |
| 470 | |
| 471 | f = feed->filter; |
| 472 | while (f && feed->feed.sec.is_filtering) { |
| 473 | feed->data_ready_cb.sec(&f->filter, event); |
| 474 | f = f->next; |
| 475 | } |
| 476 | |
| 477 | if (should_lock) |
| 478 | spin_unlock(&feed->demux->lock); |
| 479 | |
| 480 | return 0; |
| 481 | } |
| 482 | EXPORT_SYMBOL(dvb_dmx_notify_section_event); |
| 483 | |
Gilad Broner | 180f65f | 2013-05-09 18:55:42 +0300 | [diff] [blame] | 484 | static int dvb_dmx_check_pes_end(struct dvb_demux_feed *feed) |
| 485 | { |
| 486 | struct dmx_data_ready data; |
| 487 | |
| 488 | if (!feed->pusi_seen) |
| 489 | return 0; |
| 490 | |
| 491 | data.status = DMX_OK_PES_END; |
| 492 | data.data_length = 0; |
| 493 | data.pes_end.start_gap = 0; |
| 494 | data.pes_end.actual_length = feed->peslen; |
| 495 | data.pes_end.disc_indicator_set = 0; |
| 496 | data.pes_end.pes_length_mismatch = 0; |
| 497 | data.pes_end.stc = 0; |
| 498 | data.pes_end.tei_counter = feed->pes_tei_counter; |
| 499 | data.pes_end.cont_err_counter = feed->pes_cont_err_counter; |
| 500 | data.pes_end.ts_packets_num = feed->pes_ts_packets_num; |
| 501 | |
| 502 | return feed->data_ready_cb.ts(&feed->feed.ts, &data); |
| 503 | } |
| 504 | |
Andreas Oberritter | dad4a73 | 2005-09-09 13:02:26 -0700 | [diff] [blame] | 505 | static inline int dvb_dmx_swfilter_payload(struct dvb_demux_feed *feed, |
| 506 | const u8 *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 507 | { |
| 508 | int count = payload(buf); |
| 509 | int p; |
Hamad Kadmany | d432f71 | 2013-01-17 17:36:17 +0200 | [diff] [blame] | 510 | int ccok; |
| 511 | u8 cc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 512 | |
| 513 | if (count == 0) |
| 514 | return -1; |
| 515 | |
Andreas Oberritter | dad4a73 | 2005-09-09 13:02:26 -0700 | [diff] [blame] | 516 | p = 188 - count; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 517 | |
Andreas Oberritter | dad4a73 | 2005-09-09 13:02:26 -0700 | [diff] [blame] | 518 | cc = buf[3] & 0x0f; |
Hamad Kadmany | eb75d1c | 2012-07-29 13:17:28 +0300 | [diff] [blame] | 519 | if (feed->first_cc) |
| 520 | ccok = 1; |
| 521 | else |
| 522 | ccok = ((feed->cc + 1) & 0x0f) == cc; |
| 523 | |
| 524 | feed->first_cc = 0; |
Andreas Oberritter | dad4a73 | 2005-09-09 13:02:26 -0700 | [diff] [blame] | 525 | feed->cc = cc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 526 | |
Hamad Kadmany | 32cb982 | 2012-05-10 08:47:44 +0300 | [diff] [blame] | 527 | /* PUSI ? */ |
| 528 | if (buf[1] & 0x40) { |
Gilad Broner | 180f65f | 2013-05-09 18:55:42 +0300 | [diff] [blame] | 529 | dvb_dmx_check_pes_end(feed); |
Hamad Kadmany | 32cb982 | 2012-05-10 08:47:44 +0300 | [diff] [blame] | 530 | feed->pusi_seen = 1; |
Hamad Kadmany | 4f87794 | 2012-07-15 15:06:01 +0300 | [diff] [blame] | 531 | feed->peslen = 0; |
Hamad Kadmany | d432f71 | 2013-01-17 17:36:17 +0200 | [diff] [blame] | 532 | feed->pes_tei_counter = 0; |
| 533 | feed->pes_ts_packets_num = 0; |
| 534 | feed->pes_cont_err_counter = 0; |
Hamad Kadmany | 32cb982 | 2012-05-10 08:47:44 +0300 | [diff] [blame] | 535 | } |
| 536 | |
| 537 | if (feed->pusi_seen == 0) |
| 538 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 539 | |
Hamad Kadmany | d432f71 | 2013-01-17 17:36:17 +0200 | [diff] [blame] | 540 | feed->pes_ts_packets_num++; |
| 541 | feed->pes_cont_err_counter += !ccok; |
| 542 | feed->pes_tei_counter += (buf[1] & 0x80) ? 1 : 0; |
| 543 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 544 | feed->peslen += count; |
| 545 | |
Andreas Oberritter | dad4a73 | 2005-09-09 13:02:26 -0700 | [diff] [blame] | 546 | 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] | 547 | } |
| 548 | |
Andreas Oberritter | dad4a73 | 2005-09-09 13:02:26 -0700 | [diff] [blame] | 549 | static int dvb_dmx_swfilter_sectionfilter(struct dvb_demux_feed *feed, |
| 550 | struct dvb_demux_filter *f) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 551 | { |
| 552 | u8 neq = 0; |
| 553 | int i; |
| 554 | |
Andreas Oberritter | dad4a73 | 2005-09-09 13:02:26 -0700 | [diff] [blame] | 555 | for (i = 0; i < DVB_DEMUX_MASK_MAX; i++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 556 | u8 xor = f->filter.filter_value[i] ^ feed->feed.sec.secbuf[i]; |
| 557 | |
| 558 | if (f->maskandmode[i] & xor) |
| 559 | return 0; |
| 560 | |
| 561 | neq |= f->maskandnotmode[i] & xor; |
| 562 | } |
| 563 | |
| 564 | if (f->doneq && !neq) |
| 565 | return 0; |
| 566 | |
Andreas Oberritter | dad4a73 | 2005-09-09 13:02:26 -0700 | [diff] [blame] | 567 | return feed->cb.sec(feed->feed.sec.secbuf, feed->feed.sec.seclen, |
| 568 | NULL, 0, &f->filter, DMX_OK); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 569 | } |
| 570 | |
Andreas Oberritter | dad4a73 | 2005-09-09 13:02:26 -0700 | [diff] [blame] | 571 | 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] | 572 | { |
| 573 | struct dvb_demux *demux = feed->demux; |
| 574 | struct dvb_demux_filter *f = feed->filter; |
| 575 | struct dmx_section_feed *sec = &feed->feed.sec; |
| 576 | int section_syntax_indicator; |
| 577 | |
| 578 | if (!sec->is_filtering) |
| 579 | return 0; |
| 580 | |
| 581 | if (!f) |
| 582 | return 0; |
| 583 | |
| 584 | if (sec->check_crc) { |
Hamad Kadmany | 32cb982 | 2012-05-10 08:47:44 +0300 | [diff] [blame] | 585 | struct timespec pre_crc_time; |
| 586 | |
| 587 | if (dvb_demux_performancecheck) |
| 588 | pre_crc_time = current_kernel_time(); |
| 589 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 590 | section_syntax_indicator = ((sec->secbuf[1] & 0x80) != 0); |
| 591 | if (section_syntax_indicator && |
Hamad Kadmany | 32cb982 | 2012-05-10 08:47:44 +0300 | [diff] [blame] | 592 | demux->check_crc32(feed, sec->secbuf, sec->seclen)) { |
| 593 | if (dvb_demux_performancecheck) |
| 594 | demux->total_crc_time += |
| 595 | dvb_dmx_calc_time_delta(pre_crc_time); |
Hamad Kadmany | 4f87794 | 2012-07-15 15:06:01 +0300 | [diff] [blame] | 596 | |
| 597 | /* Notify on CRC error */ |
| 598 | feed->cb.sec(NULL, 0, NULL, 0, |
| 599 | &f->filter, DMX_CRC_ERROR); |
| 600 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 601 | return -1; |
Hamad Kadmany | 32cb982 | 2012-05-10 08:47:44 +0300 | [diff] [blame] | 602 | } |
| 603 | |
| 604 | if (dvb_demux_performancecheck) |
| 605 | demux->total_crc_time += |
| 606 | dvb_dmx_calc_time_delta(pre_crc_time); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 607 | } |
| 608 | |
| 609 | do { |
| 610 | if (dvb_dmx_swfilter_sectionfilter(feed, f) < 0) |
| 611 | return -1; |
| 612 | } while ((f = f->next) && sec->is_filtering); |
| 613 | |
| 614 | sec->seclen = 0; |
| 615 | |
| 616 | return 0; |
| 617 | } |
| 618 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 619 | static void dvb_dmx_swfilter_section_new(struct dvb_demux_feed *feed) |
| 620 | { |
| 621 | struct dmx_section_feed *sec = &feed->feed.sec; |
| 622 | |
| 623 | #ifdef DVB_DEMUX_SECTION_LOSS_LOG |
Andreas Oberritter | dad4a73 | 2005-09-09 13:02:26 -0700 | [diff] [blame] | 624 | if (sec->secbufp < sec->tsfeedp) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 625 | int i, n = sec->tsfeedp - sec->secbufp; |
| 626 | |
Andreas Oberritter | dad4a73 | 2005-09-09 13:02:26 -0700 | [diff] [blame] | 627 | /* |
| 628 | * Section padding is done with 0xff bytes entirely. |
| 629 | * Due to speed reasons, we won't check all of them |
| 630 | * but just first and last. |
| 631 | */ |
| 632 | if (sec->secbuf[0] != 0xff || sec->secbuf[n - 1] != 0xff) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 633 | printk("dvb_demux.c section ts padding loss: %d/%d\n", |
| 634 | n, sec->tsfeedp); |
| 635 | printk("dvb_demux.c pad data:"); |
Andreas Oberritter | dad4a73 | 2005-09-09 13:02:26 -0700 | [diff] [blame] | 636 | for (i = 0; i < n; i++) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 637 | printk(" %02x", sec->secbuf[i]); |
| 638 | printk("\n"); |
| 639 | } |
| 640 | } |
| 641 | #endif |
| 642 | |
| 643 | sec->tsfeedp = sec->secbufp = sec->seclen = 0; |
| 644 | sec->secbuf = sec->secbuf_base; |
| 645 | } |
| 646 | |
| 647 | /* |
Andreas Oberritter | dad4a73 | 2005-09-09 13:02:26 -0700 | [diff] [blame] | 648 | * Losless Section Demux 1.4.1 by Emard |
| 649 | * Valsecchi Patrick: |
| 650 | * - middle of section A (no PUSI) |
| 651 | * - end of section A and start of section B |
| 652 | * (with PUSI pointing to the start of the second section) |
| 653 | * |
| 654 | * In this case, without feed->pusi_seen you'll receive a garbage section |
| 655 | * consisting of the end of section A. Basically because tsfeedp |
| 656 | * is incemented and the use=0 condition is not raised |
| 657 | * when the second packet arrives. |
| 658 | * |
| 659 | * Fix: |
| 660 | * when demux is started, let feed->pusi_seen = 0 to |
| 661 | * prevent initial feeding of garbage from the end of |
| 662 | * previous section. When you for the first time see PUSI=1 |
| 663 | * then set feed->pusi_seen = 1 |
| 664 | */ |
| 665 | static int dvb_dmx_swfilter_section_copy_dump(struct dvb_demux_feed *feed, |
| 666 | const u8 *buf, u8 len) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 667 | { |
| 668 | struct dvb_demux *demux = feed->demux; |
| 669 | struct dmx_section_feed *sec = &feed->feed.sec; |
| 670 | u16 limit, seclen, n; |
| 671 | |
Andreas Oberritter | dad4a73 | 2005-09-09 13:02:26 -0700 | [diff] [blame] | 672 | if (sec->tsfeedp >= DMX_MAX_SECFEED_SIZE) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 673 | return 0; |
| 674 | |
Andreas Oberritter | dad4a73 | 2005-09-09 13:02:26 -0700 | [diff] [blame] | 675 | if (sec->tsfeedp + len > DMX_MAX_SECFEED_SIZE) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 676 | #ifdef DVB_DEMUX_SECTION_LOSS_LOG |
| 677 | printk("dvb_demux.c section buffer full loss: %d/%d\n", |
Andreas Oberritter | dad4a73 | 2005-09-09 13:02:26 -0700 | [diff] [blame] | 678 | sec->tsfeedp + len - DMX_MAX_SECFEED_SIZE, |
| 679 | DMX_MAX_SECFEED_SIZE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 680 | #endif |
| 681 | len = DMX_MAX_SECFEED_SIZE - sec->tsfeedp; |
| 682 | } |
| 683 | |
Andreas Oberritter | dad4a73 | 2005-09-09 13:02:26 -0700 | [diff] [blame] | 684 | if (len <= 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 685 | return 0; |
| 686 | |
| 687 | demux->memcopy(feed, sec->secbuf_base + sec->tsfeedp, buf, len); |
| 688 | sec->tsfeedp += len; |
| 689 | |
Andreas Oberritter | dad4a73 | 2005-09-09 13:02:26 -0700 | [diff] [blame] | 690 | /* |
| 691 | * Dump all the sections we can find in the data (Emard) |
| 692 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 693 | limit = sec->tsfeedp; |
Andreas Oberritter | dad4a73 | 2005-09-09 13:02:26 -0700 | [diff] [blame] | 694 | if (limit > DMX_MAX_SECFEED_SIZE) |
| 695 | return -1; /* internal error should never happen */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 696 | |
| 697 | /* to be sure always set secbuf */ |
| 698 | sec->secbuf = sec->secbuf_base + sec->secbufp; |
| 699 | |
Andreas Oberritter | dad4a73 | 2005-09-09 13:02:26 -0700 | [diff] [blame] | 700 | for (n = 0; sec->secbufp + 2 < limit; n++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 701 | seclen = section_length(sec->secbuf); |
Mark Adams | b3967d6 | 2005-11-08 21:35:50 -0800 | [diff] [blame] | 702 | if (seclen <= 0 || seclen > DMX_MAX_SECTION_SIZE |
Andreas Oberritter | dad4a73 | 2005-09-09 13:02:26 -0700 | [diff] [blame] | 703 | || seclen + sec->secbufp > limit) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 704 | return 0; |
| 705 | sec->seclen = seclen; |
| 706 | sec->crc_val = ~0; |
| 707 | /* dump [secbuf .. secbuf+seclen) */ |
Andreas Oberritter | dad4a73 | 2005-09-09 13:02:26 -0700 | [diff] [blame] | 708 | if (feed->pusi_seen) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 709 | dvb_dmx_swfilter_section_feed(feed); |
| 710 | #ifdef DVB_DEMUX_SECTION_LOSS_LOG |
| 711 | else |
| 712 | printk("dvb_demux.c pusi not seen, discarding section data\n"); |
| 713 | #endif |
Andreas Oberritter | dad4a73 | 2005-09-09 13:02:26 -0700 | [diff] [blame] | 714 | sec->secbufp += seclen; /* secbufp and secbuf moving together is */ |
| 715 | sec->secbuf += seclen; /* redundant but saves pointer arithmetic */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 716 | } |
| 717 | |
| 718 | return 0; |
| 719 | } |
| 720 | |
Andreas Oberritter | dad4a73 | 2005-09-09 13:02:26 -0700 | [diff] [blame] | 721 | static int dvb_dmx_swfilter_section_packet(struct dvb_demux_feed *feed, |
| 722 | const u8 *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 723 | { |
| 724 | u8 p, count; |
| 725 | int ccok, dc_i = 0; |
| 726 | u8 cc; |
| 727 | |
| 728 | count = payload(buf); |
| 729 | |
Andreas Oberritter | dad4a73 | 2005-09-09 13:02:26 -0700 | [diff] [blame] | 730 | if (count == 0) /* count == 0 if no payload or out of range */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 731 | return -1; |
| 732 | |
Andreas Oberritter | dad4a73 | 2005-09-09 13:02:26 -0700 | [diff] [blame] | 733 | p = 188 - count; /* payload start */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 734 | |
| 735 | cc = buf[3] & 0x0f; |
Hamad Kadmany | eb75d1c | 2012-07-29 13:17:28 +0300 | [diff] [blame] | 736 | if (feed->first_cc) |
| 737 | ccok = 1; |
| 738 | else |
| 739 | ccok = ((feed->cc + 1) & 0x0f) == cc; |
| 740 | |
Hamad Kadmany | 1101b00 | 2013-04-11 11:55:16 +0300 | [diff] [blame] | 741 | /* discard TS packets holding sections with TEI bit set */ |
| 742 | if (buf[1] & 0x80) |
| 743 | return -EINVAL; |
| 744 | |
Hamad Kadmany | eb75d1c | 2012-07-29 13:17:28 +0300 | [diff] [blame] | 745 | feed->first_cc = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 746 | feed->cc = cc; |
| 747 | |
| 748 | if (buf[3] & 0x20) { |
| 749 | /* adaption field present, check for discontinuity_indicator */ |
| 750 | if ((buf[4] > 0) && (buf[5] & 0x80)) |
| 751 | dc_i = 1; |
| 752 | } |
| 753 | |
| 754 | if (!ccok || dc_i) { |
| 755 | #ifdef DVB_DEMUX_SECTION_LOSS_LOG |
Andreas Oberritter | dad4a73 | 2005-09-09 13:02:26 -0700 | [diff] [blame] | 756 | printk("dvb_demux.c discontinuity detected %d bytes lost\n", |
| 757 | count); |
| 758 | /* |
| 759 | * those bytes under sume circumstances will again be reported |
| 760 | * in the following dvb_dmx_swfilter_section_new |
| 761 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 762 | #endif |
Andreas Oberritter | dad4a73 | 2005-09-09 13:02:26 -0700 | [diff] [blame] | 763 | /* |
| 764 | * Discontinuity detected. Reset pusi_seen = 0 to |
| 765 | * stop feeding of suspicious data until next PUSI=1 arrives |
| 766 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 767 | feed->pusi_seen = 0; |
| 768 | dvb_dmx_swfilter_section_new(feed); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 769 | } |
| 770 | |
| 771 | if (buf[1] & 0x40) { |
Andreas Oberritter | dad4a73 | 2005-09-09 13:02:26 -0700 | [diff] [blame] | 772 | /* PUSI=1 (is set), section boundary is here */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 773 | if (count > 1 && buf[p] < count) { |
Andreas Oberritter | dad4a73 | 2005-09-09 13:02:26 -0700 | [diff] [blame] | 774 | const u8 *before = &buf[p + 1]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 775 | u8 before_len = buf[p]; |
Andreas Oberritter | dad4a73 | 2005-09-09 13:02:26 -0700 | [diff] [blame] | 776 | const u8 *after = &before[before_len]; |
| 777 | u8 after_len = count - 1 - before_len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 778 | |
Andreas Oberritter | dad4a73 | 2005-09-09 13:02:26 -0700 | [diff] [blame] | 779 | dvb_dmx_swfilter_section_copy_dump(feed, before, |
| 780 | before_len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 781 | /* before start of new section, set pusi_seen = 1 */ |
| 782 | feed->pusi_seen = 1; |
| 783 | dvb_dmx_swfilter_section_new(feed); |
Andreas Oberritter | dad4a73 | 2005-09-09 13:02:26 -0700 | [diff] [blame] | 784 | dvb_dmx_swfilter_section_copy_dump(feed, after, |
| 785 | after_len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 786 | } |
| 787 | #ifdef DVB_DEMUX_SECTION_LOSS_LOG |
Andreas Oberritter | dad4a73 | 2005-09-09 13:02:26 -0700 | [diff] [blame] | 788 | else if (count > 0) |
| 789 | printk("dvb_demux.c PUSI=1 but %d bytes lost\n", count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 790 | #endif |
| 791 | } else { |
Andreas Oberritter | dad4a73 | 2005-09-09 13:02:26 -0700 | [diff] [blame] | 792 | /* PUSI=0 (is not set), no section boundary */ |
| 793 | dvb_dmx_swfilter_section_copy_dump(feed, &buf[p], count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 794 | } |
Andreas Oberritter | dad4a73 | 2005-09-09 13:02:26 -0700 | [diff] [blame] | 795 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 796 | return 0; |
| 797 | } |
| 798 | |
Hamad Kadmany | e1dba20 | 2013-04-10 18:37:25 +0300 | [diff] [blame] | 799 | static int dvb_demux_save_idx_event(struct dvb_demux_feed *feed, |
| 800 | struct dmx_index_event_info *idx_event, |
| 801 | int traverse_from_tail) |
| 802 | { |
| 803 | struct dmx_index_entry *idx_entry; |
| 804 | struct dmx_index_entry *curr_entry; |
| 805 | struct list_head *pos; |
| 806 | |
| 807 | /* get entry from free list */ |
| 808 | if (list_empty(&feed->rec_info->idx_info.free_list)) { |
| 809 | printk(KERN_ERR "%s: index free list is empty\n", __func__); |
| 810 | return -ENOMEM; |
| 811 | } |
| 812 | |
| 813 | idx_entry = list_first_entry(&feed->rec_info->idx_info.free_list, |
| 814 | struct dmx_index_entry, next); |
| 815 | list_del(&idx_entry->next); |
| 816 | |
| 817 | idx_entry->event = *idx_event; |
| 818 | |
| 819 | pos = &feed->rec_info->idx_info.ready_list; |
| 820 | if (traverse_from_tail) { |
| 821 | list_for_each_entry_reverse(curr_entry, |
| 822 | &feed->rec_info->idx_info.ready_list, next) { |
| 823 | if (curr_entry->event.match_tsp_num <= |
| 824 | idx_event->match_tsp_num) { |
| 825 | pos = &curr_entry->next; |
| 826 | break; |
| 827 | } |
| 828 | } |
| 829 | } else { |
| 830 | list_for_each_entry(curr_entry, |
| 831 | &feed->rec_info->idx_info.ready_list, next) { |
| 832 | if (curr_entry->event.match_tsp_num > |
| 833 | idx_event->match_tsp_num) { |
| 834 | pos = &curr_entry->next; |
| 835 | break; |
| 836 | } |
| 837 | } |
| 838 | } |
| 839 | |
| 840 | if (traverse_from_tail) |
| 841 | list_add(&idx_entry->next, pos); |
| 842 | else |
| 843 | list_add_tail(&idx_entry->next, pos); |
| 844 | |
| 845 | return 0; |
| 846 | } |
| 847 | |
| 848 | int dvb_demux_push_idx_event(struct dvb_demux_feed *feed, |
| 849 | struct dmx_index_event_info *idx_event) |
| 850 | { |
| 851 | int ret; |
| 852 | |
| 853 | spin_lock(&feed->demux->lock); |
| 854 | ret = dvb_demux_save_idx_event(feed, idx_event, 1); |
| 855 | spin_unlock(&feed->demux->lock); |
| 856 | |
| 857 | return ret; |
| 858 | } |
| 859 | EXPORT_SYMBOL(dvb_demux_push_idx_event); |
| 860 | |
| 861 | static inline void dvb_dmx_notify_indexing(struct dvb_demux_feed *feed) |
| 862 | { |
| 863 | struct dmx_data_ready dmx_data_ready; |
| 864 | struct dmx_index_entry *curr_entry; |
| 865 | struct list_head *n, *pos; |
| 866 | |
| 867 | dmx_data_ready.status = DMX_OK_IDX; |
| 868 | |
| 869 | list_for_each_safe(pos, n, &feed->rec_info->idx_info.ready_list) { |
| 870 | curr_entry = list_entry(pos, struct dmx_index_entry, next); |
| 871 | |
| 872 | if ((feed->rec_info->idx_info.min_pattern_tsp_num == (u64)-1) || |
| 873 | (curr_entry->event.match_tsp_num <= |
| 874 | feed->rec_info->idx_info.min_pattern_tsp_num)) { |
| 875 | dmx_data_ready.idx_event = curr_entry->event; |
| 876 | feed->data_ready_cb.ts(&feed->feed.ts, &dmx_data_ready); |
| 877 | list_del(&curr_entry->next); |
| 878 | list_add_tail(&curr_entry->next, |
| 879 | &feed->rec_info->idx_info.free_list); |
| 880 | } |
| 881 | } |
| 882 | } |
| 883 | |
| 884 | void dvb_dmx_notify_idx_events(struct dvb_demux_feed *feed) |
| 885 | { |
| 886 | spin_lock(&feed->demux->lock); |
| 887 | dvb_dmx_notify_indexing(feed); |
| 888 | spin_unlock(&feed->demux->lock); |
| 889 | } |
| 890 | EXPORT_SYMBOL(dvb_dmx_notify_idx_events); |
| 891 | |
| 892 | static void dvb_dmx_process_pattern_result(struct dvb_demux_feed *feed, |
| 893 | struct dvb_dmx_video_patterns_results *patterns, int pattern, |
| 894 | u64 curr_stc, u64 prev_stc, |
| 895 | u64 curr_match_tsp, u64 prev_match_tsp, |
| 896 | u64 curr_pusi_tsp, u64 prev_pusi_tsp) |
| 897 | { |
| 898 | int mpeg_frame_start; |
| 899 | int h264_frame_start; |
| 900 | int vc1_frame_start; |
| 901 | int seq_start; |
| 902 | u64 frame_end_in_seq; |
| 903 | struct dmx_index_event_info idx_event; |
| 904 | |
| 905 | idx_event.pid = feed->pid; |
| 906 | if (patterns->info[pattern].used_prefix_size) { |
| 907 | idx_event.match_tsp_num = prev_match_tsp; |
| 908 | idx_event.last_pusi_tsp_num = prev_pusi_tsp; |
| 909 | idx_event.stc = prev_stc; |
| 910 | } else { |
| 911 | idx_event.match_tsp_num = curr_match_tsp; |
| 912 | idx_event.last_pusi_tsp_num = curr_pusi_tsp; |
| 913 | idx_event.stc = curr_stc; |
| 914 | } |
| 915 | |
| 916 | /* notify on frame-end if needed */ |
| 917 | if (feed->prev_frame_valid) { |
| 918 | if (feed->prev_frame_type & DMX_IDX_MPEG_I_FRAME_START) { |
| 919 | idx_event.type = DMX_IDX_MPEG_I_FRAME_END; |
| 920 | frame_end_in_seq = DMX_IDX_MPEG_FIRST_SEQ_FRAME_END; |
| 921 | } else if (feed->prev_frame_type & DMX_IDX_MPEG_P_FRAME_START) { |
| 922 | idx_event.type = DMX_IDX_MPEG_P_FRAME_END; |
| 923 | frame_end_in_seq = DMX_IDX_MPEG_FIRST_SEQ_FRAME_END; |
| 924 | } else if (feed->prev_frame_type & DMX_IDX_MPEG_B_FRAME_START) { |
| 925 | idx_event.type = DMX_IDX_MPEG_B_FRAME_END; |
| 926 | frame_end_in_seq = DMX_IDX_MPEG_FIRST_SEQ_FRAME_END; |
| 927 | } else if (feed->prev_frame_type & DMX_IDX_H264_IDR_START) { |
| 928 | idx_event.type = DMX_IDX_H264_IDR_END; |
| 929 | frame_end_in_seq = DMX_IDX_H264_FIRST_SPS_FRAME_END; |
| 930 | } else if (feed->prev_frame_type & DMX_IDX_H264_NON_IDR_START) { |
| 931 | idx_event.type = DMX_IDX_H264_NON_IDR_END; |
| 932 | frame_end_in_seq = DMX_IDX_H264_FIRST_SPS_FRAME_END; |
| 933 | } else { |
| 934 | idx_event.type = DMX_IDX_VC1_FRAME_END; |
| 935 | frame_end_in_seq = DMX_IDX_VC1_FIRST_SEQ_FRAME_END; |
| 936 | } |
| 937 | |
| 938 | if (feed->idx_params.types & idx_event.type) |
| 939 | dvb_demux_save_idx_event(feed, &idx_event, 1); |
| 940 | |
| 941 | if (feed->first_frame_in_seq_notified && |
| 942 | feed->idx_params.types & frame_end_in_seq) { |
| 943 | idx_event.type = frame_end_in_seq; |
| 944 | dvb_demux_save_idx_event(feed, &idx_event, 1); |
| 945 | feed->first_frame_in_seq_notified = 0; |
| 946 | } |
| 947 | } |
| 948 | |
| 949 | seq_start = patterns->info[pattern].type & |
| 950 | (DMX_IDX_MPEG_SEQ_HEADER | DMX_IDX_H264_SPS | |
| 951 | DMX_IDX_VC1_SEQ_HEADER); |
| 952 | |
| 953 | /* did we find start of sequence/SPS? */ |
| 954 | if (seq_start) { |
| 955 | feed->first_frame_in_seq = 1; |
| 956 | feed->first_frame_in_seq_notified = 0; |
| 957 | feed->prev_frame_valid = 0; |
| 958 | idx_event.type = patterns->info[pattern].type; |
| 959 | if (feed->idx_params.types & idx_event.type) |
| 960 | dvb_demux_save_idx_event(feed, &idx_event, 1); |
| 961 | return; |
| 962 | } |
| 963 | |
| 964 | mpeg_frame_start = patterns->info[pattern].type & |
| 965 | (DMX_IDX_MPEG_I_FRAME_START | |
| 966 | DMX_IDX_MPEG_P_FRAME_START | |
| 967 | DMX_IDX_MPEG_B_FRAME_START); |
| 968 | |
| 969 | h264_frame_start = patterns->info[pattern].type & |
| 970 | (DMX_IDX_H264_IDR_START | DMX_IDX_H264_NON_IDR_START); |
| 971 | |
| 972 | vc1_frame_start = patterns->info[pattern].type & |
| 973 | DMX_IDX_VC1_FRAME_START; |
| 974 | |
| 975 | if (!mpeg_frame_start && !h264_frame_start && !vc1_frame_start) { |
| 976 | /* neither sequence nor frame, notify on the entry if needed */ |
| 977 | idx_event.type = patterns->info[pattern].type; |
| 978 | if (feed->idx_params.types & idx_event.type) |
| 979 | dvb_demux_save_idx_event(feed, &idx_event, 1); |
| 980 | feed->prev_frame_valid = 0; |
| 981 | return; |
| 982 | } |
| 983 | |
| 984 | /* notify on first frame in sequence/sps if needed */ |
| 985 | if (feed->first_frame_in_seq) { |
| 986 | feed->first_frame_in_seq = 0; |
| 987 | feed->first_frame_in_seq_notified = 1; |
| 988 | if (mpeg_frame_start) |
| 989 | idx_event.type = DMX_IDX_MPEG_FIRST_SEQ_FRAME_START; |
| 990 | else if (h264_frame_start) |
| 991 | idx_event.type = DMX_IDX_H264_FIRST_SPS_FRAME_START; |
| 992 | else |
| 993 | idx_event.type = DMX_IDX_VC1_FIRST_SEQ_FRAME_START; |
| 994 | |
| 995 | if (feed->idx_params.types & idx_event.type) |
| 996 | dvb_demux_save_idx_event(feed, &idx_event, 1); |
| 997 | } |
| 998 | |
| 999 | /* notify on frame start if needed */ |
| 1000 | idx_event.type = patterns->info[pattern].type; |
| 1001 | if (feed->idx_params.types & idx_event.type) |
| 1002 | dvb_demux_save_idx_event(feed, &idx_event, 1); |
| 1003 | |
| 1004 | feed->prev_frame_valid = 1; |
| 1005 | feed->prev_frame_type = patterns->info[pattern].type; |
| 1006 | } |
| 1007 | |
| 1008 | void dvb_dmx_process_idx_pattern(struct dvb_demux_feed *feed, |
| 1009 | struct dvb_dmx_video_patterns_results *patterns, int pattern, |
| 1010 | u64 curr_stc, u64 prev_stc, |
| 1011 | u64 curr_match_tsp, u64 prev_match_tsp, |
| 1012 | u64 curr_pusi_tsp, u64 prev_pusi_tsp) |
| 1013 | { |
| 1014 | spin_lock(&feed->demux->lock); |
| 1015 | dvb_dmx_process_pattern_result(feed, |
| 1016 | patterns, pattern, |
| 1017 | curr_stc, prev_stc, |
| 1018 | curr_match_tsp, prev_match_tsp, |
| 1019 | curr_pusi_tsp, prev_pusi_tsp); |
| 1020 | spin_unlock(&feed->demux->lock); |
| 1021 | } |
| 1022 | EXPORT_SYMBOL(dvb_dmx_process_idx_pattern); |
| 1023 | |
| 1024 | static void dvb_dmx_index(struct dvb_demux_feed *feed, |
| 1025 | const u8 *buf, |
| 1026 | const u8 timestamp[TIMESTAMP_LEN]) |
| 1027 | { |
| 1028 | int i; |
| 1029 | int p; |
| 1030 | u64 stc; |
| 1031 | int found_patterns; |
| 1032 | int count = payload(buf); |
| 1033 | u64 min_pattern_tsp_num; |
| 1034 | struct dvb_demux_feed *tmp_feed; |
| 1035 | struct dvb_demux *demux = feed->demux; |
| 1036 | struct dmx_index_event_info idx_event; |
| 1037 | struct dvb_dmx_video_patterns_results patterns; |
| 1038 | |
| 1039 | if (feed->demux->convert_ts) |
| 1040 | feed->demux->convert_ts(feed, timestamp, &stc); |
| 1041 | else |
| 1042 | stc = 0; |
| 1043 | |
| 1044 | idx_event.pid = feed->pid; |
| 1045 | idx_event.stc = stc; |
| 1046 | idx_event.match_tsp_num = feed->rec_info->ts_output_count; |
| 1047 | |
| 1048 | /* PUSI ? */ |
| 1049 | if (buf[1] & 0x40) { |
| 1050 | feed->curr_pusi_tsp_num = feed->rec_info->ts_output_count; |
| 1051 | if (feed->idx_params.types & DMX_IDX_PUSI) { |
| 1052 | idx_event.type = DMX_IDX_PUSI; |
| 1053 | idx_event.last_pusi_tsp_num = |
| 1054 | feed->curr_pusi_tsp_num; |
| 1055 | dvb_demux_save_idx_event(feed, &idx_event, 1); |
| 1056 | } |
| 1057 | } |
| 1058 | |
| 1059 | /* |
| 1060 | * if we still did not encounter a TS packet with PUSI indication, |
| 1061 | * we cannot report index entries yet as we need to provide |
| 1062 | * the TS packet number with PUSI indication preceeding the TS |
| 1063 | * packet pointed by the reported index entry. |
| 1064 | */ |
| 1065 | if (feed->curr_pusi_tsp_num == (u64)-1) { |
| 1066 | dvb_dmx_notify_indexing(feed); |
| 1067 | return; |
| 1068 | } |
| 1069 | |
| 1070 | if ((feed->idx_params.types & DMX_IDX_RAI) && /* index RAI? */ |
| 1071 | (buf[3] & 0x20) && /* adaptation field exists? */ |
| 1072 | (buf[4] > 0) && /* adaptation field len > 0 ? */ |
| 1073 | (buf[5] & 0x40)) { /* RAI is set? */ |
| 1074 | idx_event.type = DMX_IDX_RAI; |
| 1075 | idx_event.last_pusi_tsp_num = |
| 1076 | feed->curr_pusi_tsp_num; |
| 1077 | dvb_demux_save_idx_event(feed, &idx_event, 1); |
| 1078 | } |
| 1079 | |
| 1080 | /* |
| 1081 | * if no pattern search is required, or the TS packet has no payload, |
| 1082 | * pattern search is not executed. |
| 1083 | */ |
| 1084 | if (!feed->pattern_num || !count) { |
| 1085 | dvb_dmx_notify_indexing(feed); |
| 1086 | return; |
| 1087 | } |
| 1088 | |
| 1089 | p = 188 - count; /* payload start */ |
| 1090 | |
| 1091 | found_patterns = |
| 1092 | dvb_dmx_video_pattern_search(feed->patterns, |
| 1093 | feed->pattern_num, &buf[p], count, |
| 1094 | &feed->prefix_size, &patterns); |
| 1095 | |
| 1096 | for (i = 0; i < found_patterns; i++) |
| 1097 | dvb_dmx_process_pattern_result(feed, &patterns, i, |
| 1098 | stc, feed->prev_stc, |
| 1099 | feed->rec_info->ts_output_count, feed->prev_tsp_num, |
| 1100 | feed->curr_pusi_tsp_num, feed->prev_pusi_tsp_num); |
| 1101 | |
| 1102 | feed->prev_tsp_num = feed->rec_info->ts_output_count; |
| 1103 | feed->prev_pusi_tsp_num = feed->curr_pusi_tsp_num; |
| 1104 | feed->prev_stc = stc; |
| 1105 | feed->last_pattern_tsp_num = feed->rec_info->ts_output_count; |
| 1106 | |
| 1107 | /* |
| 1108 | * it is possible to have a TS packet that has a prefix of |
| 1109 | * a video pattern but the video pattern is not identified yet |
| 1110 | * until we get the next TS packet of that PID. When we get |
| 1111 | * the next TS packet of that PID, pattern-search would |
| 1112 | * detect that we have a new index entry that starts in the |
| 1113 | * previous TS packet. |
| 1114 | * In order to notify the user on index entries with match_tsp_num |
| 1115 | * in ascending order, index events with match_tsp_num up to |
| 1116 | * the last_pattern_tsp_num are notified now to the user, |
| 1117 | * the rest can't be notified now as we might hit the above |
| 1118 | * scenario and cause the events not to be notified with |
| 1119 | * ascending order of match_tsp_num. |
| 1120 | */ |
| 1121 | if (feed->rec_info->idx_info.pattern_search_feeds_num == 1) { |
| 1122 | /* |
| 1123 | * optimization for case we have only one PID |
| 1124 | * with video pattern search, in this case |
| 1125 | * min_pattern_tsp_num is simply updated to the new |
| 1126 | * TS packet number of the PID with pattern search. |
| 1127 | */ |
| 1128 | feed->rec_info->idx_info.min_pattern_tsp_num = |
| 1129 | feed->last_pattern_tsp_num; |
| 1130 | dvb_dmx_notify_indexing(feed); |
| 1131 | return; |
| 1132 | } |
| 1133 | |
| 1134 | /* |
| 1135 | * if we have more than one PID with pattern search, |
| 1136 | * min_pattern_tsp_num needs to be updated now based on |
| 1137 | * last_pattern_tsp_num of all PIDs with pattern search. |
| 1138 | */ |
| 1139 | min_pattern_tsp_num = (u64)-1; |
| 1140 | i = feed->rec_info->idx_info.pattern_search_feeds_num; |
| 1141 | list_for_each_entry(tmp_feed, &demux->feed_list, list_head) { |
| 1142 | if ((tmp_feed->state != DMX_STATE_GO) || |
| 1143 | (tmp_feed->type != DMX_TYPE_TS) || |
| 1144 | (tmp_feed->feed.ts.buffer.ringbuff != |
| 1145 | feed->feed.ts.buffer.ringbuff)) |
| 1146 | continue; |
| 1147 | |
| 1148 | if ((tmp_feed->last_pattern_tsp_num != (u64)-1) && |
| 1149 | ((min_pattern_tsp_num == (u64)-1) || |
| 1150 | (tmp_feed->last_pattern_tsp_num < |
| 1151 | min_pattern_tsp_num))) |
| 1152 | min_pattern_tsp_num = tmp_feed->last_pattern_tsp_num; |
| 1153 | |
| 1154 | if (tmp_feed->pattern_num) { |
| 1155 | i--; |
| 1156 | if (i == 0) |
| 1157 | break; |
| 1158 | } |
| 1159 | } |
| 1160 | |
| 1161 | feed->rec_info->idx_info.min_pattern_tsp_num = min_pattern_tsp_num; |
| 1162 | |
| 1163 | /* notify all index entries up to min_pattern_tsp_num */ |
| 1164 | dvb_dmx_notify_indexing(feed); |
| 1165 | } |
| 1166 | |
Hamad Kadmany | 32cb982 | 2012-05-10 08:47:44 +0300 | [diff] [blame] | 1167 | static inline void dvb_dmx_swfilter_output_packet( |
| 1168 | struct dvb_demux_feed *feed, |
Hamad Kadmany | 9e5ce47 | 2012-11-22 13:47:07 +0200 | [diff] [blame] | 1169 | const u8 *buf, |
| 1170 | const u8 timestamp[TIMESTAMP_LEN]) |
Hamad Kadmany | 32cb982 | 2012-05-10 08:47:44 +0300 | [diff] [blame] | 1171 | { |
Hamad Kadmany | 32cb982 | 2012-05-10 08:47:44 +0300 | [diff] [blame] | 1172 | /* |
| 1173 | * if we output 192 packet with timestamp at head of packet, |
| 1174 | * output the timestamp now before the 188 TS packet |
| 1175 | */ |
Hamad Kadmany | 9e5ce47 | 2012-11-22 13:47:07 +0200 | [diff] [blame] | 1176 | if (feed->tsp_out_format == DMX_TSP_FORMAT_192_HEAD) |
| 1177 | feed->cb.ts(timestamp, TIMESTAMP_LEN, NULL, |
| 1178 | 0, &feed->feed.ts, DMX_OK); |
Hamad Kadmany | 32cb982 | 2012-05-10 08:47:44 +0300 | [diff] [blame] | 1179 | |
| 1180 | feed->cb.ts(buf, 188, NULL, 0, &feed->feed.ts, DMX_OK); |
| 1181 | |
| 1182 | /* |
| 1183 | * if we output 192 packet with timestamp at tail of packet, |
| 1184 | * output the timestamp now after the 188 TS packet |
| 1185 | */ |
Hamad Kadmany | 9e5ce47 | 2012-11-22 13:47:07 +0200 | [diff] [blame] | 1186 | if (feed->tsp_out_format == DMX_TSP_FORMAT_192_TAIL) |
| 1187 | feed->cb.ts(timestamp, TIMESTAMP_LEN, NULL, |
| 1188 | 0, &feed->feed.ts, DMX_OK); |
Hamad Kadmany | e1dba20 | 2013-04-10 18:37:25 +0300 | [diff] [blame] | 1189 | |
| 1190 | if (feed->idx_params.enable) |
| 1191 | dvb_dmx_index(feed, buf, timestamp); |
| 1192 | |
| 1193 | feed->rec_info->ts_output_count++; |
Hamad Kadmany | 32cb982 | 2012-05-10 08:47:44 +0300 | [diff] [blame] | 1194 | } |
| 1195 | |
| 1196 | static inline void dvb_dmx_configure_decoder_fullness( |
| 1197 | struct dvb_demux *demux, |
| 1198 | int initialize) |
| 1199 | { |
| 1200 | struct dvb_demux_feed *feed; |
| 1201 | int j; |
| 1202 | |
| 1203 | for (j = 0; j < demux->feednum; j++) { |
| 1204 | feed = &demux->feed[j]; |
| 1205 | |
| 1206 | if ((feed->state != DMX_STATE_GO) || |
| 1207 | (feed->type != DMX_TYPE_TS) || |
| 1208 | !(feed->ts_type & TS_DECODER)) |
| 1209 | continue; |
| 1210 | |
| 1211 | if (initialize) { |
| 1212 | if (demux->decoder_fullness_init) |
| 1213 | demux->decoder_fullness_init(feed); |
| 1214 | } else { |
| 1215 | if (demux->decoder_fullness_abort) |
| 1216 | demux->decoder_fullness_abort(feed); |
| 1217 | } |
| 1218 | } |
| 1219 | } |
| 1220 | |
| 1221 | static inline int dvb_dmx_swfilter_buffer_check( |
| 1222 | struct dvb_demux *demux, |
| 1223 | u16 pid) |
| 1224 | { |
| 1225 | int desired_space; |
| 1226 | int ret; |
| 1227 | struct dmx_ts_feed *ts; |
| 1228 | struct dvb_demux_filter *f; |
| 1229 | struct dvb_demux_feed *feed; |
| 1230 | int was_locked; |
| 1231 | int i, j; |
| 1232 | |
| 1233 | if (likely(spin_is_locked(&demux->lock))) |
| 1234 | was_locked = 1; |
| 1235 | else |
| 1236 | was_locked = 0; |
| 1237 | |
| 1238 | /* |
| 1239 | * Check that there's enough free space for data output. |
| 1240 | * If there no space, wait for it (block). |
| 1241 | * Since this function is called while spinlock |
| 1242 | * is aquired, the lock should be released first. |
| 1243 | * Once we get control back, lock is aquired back |
| 1244 | * and checks that the filter is still valid. |
| 1245 | */ |
| 1246 | for (j = 0; j < demux->feednum; j++) { |
| 1247 | feed = &demux->feed[j]; |
| 1248 | |
| 1249 | if (demux->sw_filter_abort) |
| 1250 | return -ENODEV; |
| 1251 | |
| 1252 | if ((feed->state != DMX_STATE_GO) || |
| 1253 | ((feed->pid != pid) && (feed->pid != 0x2000))) |
| 1254 | continue; |
| 1255 | |
Gilad Broner | 4e66375 | 2013-03-03 13:41:10 +0200 | [diff] [blame] | 1256 | if (feed->secure_mode.is_secured && |
| 1257 | !dvb_dmx_is_rec_feed(feed)) |
| 1258 | return 0; |
| 1259 | |
Hamad Kadmany | 32cb982 | 2012-05-10 08:47:44 +0300 | [diff] [blame] | 1260 | if (feed->type == DMX_TYPE_TS) { |
| 1261 | desired_space = 192; /* upper bound */ |
| 1262 | ts = &feed->feed.ts; |
| 1263 | |
| 1264 | if (feed->ts_type & TS_PACKET) { |
| 1265 | if (likely(was_locked)) |
| 1266 | spin_unlock(&demux->lock); |
| 1267 | |
| 1268 | ret = demux->buffer_ctrl.ts(ts, desired_space); |
| 1269 | |
| 1270 | if (likely(was_locked)) |
| 1271 | spin_lock(&demux->lock); |
| 1272 | |
| 1273 | if (ret < 0) |
| 1274 | continue; |
| 1275 | } |
| 1276 | |
| 1277 | if (demux->sw_filter_abort) |
| 1278 | return -ENODEV; |
| 1279 | |
| 1280 | if (!ts->is_filtering) |
| 1281 | continue; |
| 1282 | |
| 1283 | if ((feed->ts_type & TS_DECODER) && |
| 1284 | (demux->decoder_fullness_wait)) { |
| 1285 | if (likely(was_locked)) |
| 1286 | spin_unlock(&demux->lock); |
| 1287 | |
| 1288 | ret = demux->decoder_fullness_wait( |
| 1289 | feed, |
| 1290 | desired_space); |
| 1291 | |
| 1292 | if (likely(was_locked)) |
| 1293 | spin_lock(&demux->lock); |
| 1294 | |
| 1295 | if (ret < 0) |
| 1296 | continue; |
| 1297 | } |
| 1298 | |
| 1299 | continue; |
| 1300 | } |
| 1301 | |
| 1302 | /* else - section case */ |
| 1303 | desired_space = feed->feed.sec.tsfeedp + 188; /* upper bound */ |
| 1304 | for (i = 0; i < demux->filternum; i++) { |
| 1305 | if (demux->sw_filter_abort) |
| 1306 | return -EPERM; |
| 1307 | |
| 1308 | if (!feed->feed.sec.is_filtering) |
| 1309 | continue; |
| 1310 | |
| 1311 | f = &demux->filter[i]; |
| 1312 | if (f->feed != feed) |
| 1313 | continue; |
| 1314 | |
| 1315 | if (likely(was_locked)) |
| 1316 | spin_unlock(&demux->lock); |
| 1317 | |
| 1318 | ret = demux->buffer_ctrl.sec(&f->filter, desired_space); |
| 1319 | |
| 1320 | if (likely(was_locked)) |
| 1321 | spin_lock(&demux->lock); |
| 1322 | |
| 1323 | if (ret < 0) |
| 1324 | break; |
| 1325 | } |
| 1326 | } |
| 1327 | |
| 1328 | return 0; |
| 1329 | } |
| 1330 | |
Andreas Oberritter | dad4a73 | 2005-09-09 13:02:26 -0700 | [diff] [blame] | 1331 | static inline void dvb_dmx_swfilter_packet_type(struct dvb_demux_feed *feed, |
Hamad Kadmany | 9e5ce47 | 2012-11-22 13:47:07 +0200 | [diff] [blame] | 1332 | const u8 *buf, const u8 timestamp[TIMESTAMP_LEN]) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1333 | { |
Hamad Kadmany | d0abf31 | 2013-05-13 18:56:06 +0300 | [diff] [blame] | 1334 | u16 pid = ts_pid(buf); |
| 1335 | u8 scrambling_bits = ts_scrambling_ctrl(buf); |
| 1336 | struct dmx_data_ready dmx_data_ready; |
| 1337 | |
| 1338 | /* |
| 1339 | * Notify on scrambling status change only when we move |
| 1340 | * from clear (0) to non-clear and vise-versa |
| 1341 | */ |
| 1342 | if ((scrambling_bits && !feed->scrambling_bits) || |
| 1343 | (!scrambling_bits && feed->scrambling_bits)) { |
| 1344 | dmx_data_ready.status = DMX_OK_SCRAMBLING_STATUS; |
| 1345 | dmx_data_ready.data_length = 0; |
| 1346 | dmx_data_ready.scrambling_bits.pid = pid; |
| 1347 | dmx_data_ready.scrambling_bits.old_value = |
| 1348 | feed->scrambling_bits; |
| 1349 | dmx_data_ready.scrambling_bits.new_value = scrambling_bits; |
| 1350 | |
| 1351 | if (feed->type == DMX_TYPE_SEC) |
Gilad Broner | acb4b87 | 2013-05-30 18:55:59 +0300 | [diff] [blame] | 1352 | dvb_dmx_notify_section_event(feed, &dmx_data_ready, 0); |
Hamad Kadmany | d0abf31 | 2013-05-13 18:56:06 +0300 | [diff] [blame] | 1353 | else |
| 1354 | feed->data_ready_cb.ts(&feed->feed.ts, &dmx_data_ready); |
| 1355 | } |
| 1356 | |
| 1357 | feed->scrambling_bits = scrambling_bits; |
| 1358 | |
Andreas Oberritter | dad4a73 | 2005-09-09 13:02:26 -0700 | [diff] [blame] | 1359 | switch (feed->type) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1360 | case DMX_TYPE_TS: |
| 1361 | if (!feed->feed.ts.is_filtering) |
| 1362 | break; |
| 1363 | if (feed->ts_type & TS_PACKET) { |
Gilad Broner | 4e66375 | 2013-03-03 13:41:10 +0200 | [diff] [blame] | 1364 | if (feed->ts_type & TS_PAYLOAD_ONLY) { |
| 1365 | if (!feed->secure_mode.is_secured) |
| 1366 | dvb_dmx_swfilter_payload(feed, buf); |
| 1367 | } else { |
Hamad Kadmany | 9e5ce47 | 2012-11-22 13:47:07 +0200 | [diff] [blame] | 1368 | dvb_dmx_swfilter_output_packet(feed, |
| 1369 | buf, timestamp); |
Gilad Broner | 4e66375 | 2013-03-03 13:41:10 +0200 | [diff] [blame] | 1370 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1371 | } |
Gilad Broner | 4e66375 | 2013-03-03 13:41:10 +0200 | [diff] [blame] | 1372 | if ((feed->ts_type & TS_DECODER) && |
| 1373 | !feed->secure_mode.is_secured) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1374 | if (feed->demux->write_to_decoder) |
| 1375 | feed->demux->write_to_decoder(feed, buf, 188); |
| 1376 | break; |
| 1377 | |
| 1378 | case DMX_TYPE_SEC: |
Gilad Broner | 4e66375 | 2013-03-03 13:41:10 +0200 | [diff] [blame] | 1379 | if (!feed->feed.sec.is_filtering || |
| 1380 | feed->secure_mode.is_secured) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1381 | break; |
| 1382 | if (dvb_dmx_swfilter_section_packet(feed, buf) < 0) |
Andreas Oberritter | dad4a73 | 2005-09-09 13:02:26 -0700 | [diff] [blame] | 1383 | feed->feed.sec.seclen = feed->feed.sec.secbufp = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1384 | break; |
| 1385 | |
| 1386 | default: |
| 1387 | break; |
| 1388 | } |
| 1389 | } |
| 1390 | |
| 1391 | #define DVR_FEED(f) \ |
| 1392 | (((f)->type == DMX_TYPE_TS) && \ |
| 1393 | ((f)->feed.ts.is_filtering) && \ |
Andreas Oberritter | 4a24ce3 | 2008-04-22 14:45:47 -0300 | [diff] [blame] | 1394 | (((f)->ts_type & (TS_PACKET | TS_DEMUX)) == TS_PACKET)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1395 | |
Hamad Kadmany | e1dba20 | 2013-04-10 18:37:25 +0300 | [diff] [blame] | 1396 | static void dvb_dmx_swfilter_one_packet(struct dvb_demux *demux, const u8 *buf, |
Hamad Kadmany | 9e5ce47 | 2012-11-22 13:47:07 +0200 | [diff] [blame] | 1397 | const u8 timestamp[TIMESTAMP_LEN]) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1398 | { |
| 1399 | struct dvb_demux_feed *feed; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1400 | u16 pid = ts_pid(buf); |
| 1401 | int dvr_done = 0; |
| 1402 | |
Abylay Ospan | 26b9d6c | 2009-11-01 18:46:53 -0300 | [diff] [blame] | 1403 | if (dvb_demux_speedcheck) { |
| 1404 | struct timespec cur_time, delta_time; |
| 1405 | u64 speed_bytes, speed_timedelta; |
| 1406 | |
| 1407 | demux->speed_pkts_cnt++; |
| 1408 | |
| 1409 | /* show speed every SPEED_PKTS_INTERVAL packets */ |
| 1410 | if (!(demux->speed_pkts_cnt % SPEED_PKTS_INTERVAL)) { |
| 1411 | cur_time = current_kernel_time(); |
| 1412 | |
| 1413 | if (demux->speed_last_time.tv_sec != 0 && |
| 1414 | demux->speed_last_time.tv_nsec != 0) { |
| 1415 | delta_time = timespec_sub(cur_time, |
| 1416 | demux->speed_last_time); |
| 1417 | speed_bytes = (u64)demux->speed_pkts_cnt |
| 1418 | * 188 * 8; |
| 1419 | /* convert to 1024 basis */ |
| 1420 | speed_bytes = 1000 * div64_u64(speed_bytes, |
| 1421 | 1024); |
| 1422 | speed_timedelta = |
| 1423 | (u64)timespec_to_ns(&delta_time); |
| 1424 | speed_timedelta = div64_u64(speed_timedelta, |
| 1425 | 1000000); /* nsec -> usec */ |
| 1426 | printk(KERN_INFO "TS speed %llu Kbits/sec \n", |
| 1427 | div64_u64(speed_bytes, |
| 1428 | speed_timedelta)); |
| 1429 | }; |
| 1430 | |
| 1431 | demux->speed_last_time = cur_time; |
| 1432 | demux->speed_pkts_cnt = 0; |
| 1433 | }; |
| 1434 | }; |
| 1435 | |
Abylay Ospan | ab6a21f | 2010-03-06 14:58:01 -0300 | [diff] [blame] | 1436 | if (demux->cnt_storage && dvb_demux_tscheck) { |
Abylay Ospan | 0d83463 | 2009-06-06 09:31:34 -0300 | [diff] [blame] | 1437 | /* check pkt counter */ |
| 1438 | if (pid < MAX_PID) { |
| 1439 | if (buf[1] & 0x80) |
| 1440 | dprintk_tscheck("TEI detected. " |
| 1441 | "PID=0x%x data1=0x%x\n", |
| 1442 | pid, buf[1]); |
| 1443 | |
| 1444 | if ((buf[3] & 0xf) != demux->cnt_storage[pid]) |
| 1445 | dprintk_tscheck("TS packet counter mismatch. " |
| 1446 | "PID=0x%x expected 0x%x " |
| 1447 | "got 0x%x\n", |
| 1448 | pid, demux->cnt_storage[pid], |
| 1449 | buf[3] & 0xf); |
| 1450 | |
| 1451 | demux->cnt_storage[pid] = ((buf[3] & 0xf) + 1)&0xf; |
| 1452 | }; |
| 1453 | /* end check */ |
| 1454 | }; |
Abylay Ospan | 0d83463 | 2009-06-06 09:31:34 -0300 | [diff] [blame] | 1455 | |
Hamad Kadmany | 32cb982 | 2012-05-10 08:47:44 +0300 | [diff] [blame] | 1456 | if (demux->playback_mode == DMX_PB_MODE_PULL) |
| 1457 | if (dvb_dmx_swfilter_buffer_check(demux, pid) < 0) |
| 1458 | return; |
| 1459 | |
Trent Piepho | 7948261 | 2007-10-10 05:37:39 -0300 | [diff] [blame] | 1460 | list_for_each_entry(feed, &demux->feed_list, list_head) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1461 | if ((feed->pid != pid) && (feed->pid != 0x2000)) |
| 1462 | continue; |
| 1463 | |
| 1464 | /* copy each packet only once to the dvr device, even |
| 1465 | * if a PID is in multiple filters (e.g. video + PCR) */ |
| 1466 | if ((DVR_FEED(feed)) && (dvr_done++)) |
| 1467 | continue; |
| 1468 | |
Andreas Oberritter | a4afd65 | 2009-07-14 20:48:37 -0300 | [diff] [blame] | 1469 | if (feed->pid == pid) |
Hamad Kadmany | 9e5ce47 | 2012-11-22 13:47:07 +0200 | [diff] [blame] | 1470 | dvb_dmx_swfilter_packet_type(feed, buf, timestamp); |
Hamad Kadmany | 32cb982 | 2012-05-10 08:47:44 +0300 | [diff] [blame] | 1471 | else if ((feed->pid == 0x2000) && |
| 1472 | (feed->feed.ts.is_filtering)) |
Hamad Kadmany | 9e5ce47 | 2012-11-22 13:47:07 +0200 | [diff] [blame] | 1473 | dvb_dmx_swfilter_output_packet(feed, buf, timestamp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1474 | } |
| 1475 | } |
Hamad Kadmany | e1dba20 | 2013-04-10 18:37:25 +0300 | [diff] [blame] | 1476 | |
| 1477 | void dvb_dmx_swfilter_packet(struct dvb_demux *demux, const u8 *buf, |
| 1478 | const u8 timestamp[TIMESTAMP_LEN]) |
| 1479 | { |
| 1480 | spin_lock(&demux->lock); |
| 1481 | dvb_dmx_swfilter_one_packet(demux, buf, timestamp); |
| 1482 | spin_unlock(&demux->lock); |
| 1483 | } |
Hamad Kadmany | 81cee05 | 2012-11-29 14:15:57 +0200 | [diff] [blame] | 1484 | EXPORT_SYMBOL(dvb_dmx_swfilter_packet); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1485 | |
Hamad Kadmany | 94bc0ab | 2012-08-02 10:07:21 +0300 | [diff] [blame] | 1486 | void dvb_dmx_swfilter_section_packets(struct dvb_demux *demux, const u8 *buf, |
| 1487 | size_t count) |
| 1488 | { |
| 1489 | struct dvb_demux_feed *feed; |
| 1490 | u16 pid = ts_pid(buf); |
| 1491 | struct timespec pre_time; |
| 1492 | |
| 1493 | if (dvb_demux_performancecheck) |
| 1494 | pre_time = current_kernel_time(); |
| 1495 | |
| 1496 | spin_lock(&demux->lock); |
| 1497 | |
| 1498 | demux->sw_filter_abort = 0; |
| 1499 | |
| 1500 | while (count--) { |
| 1501 | if (buf[0] != 0x47) { |
| 1502 | buf += 188; |
| 1503 | continue; |
| 1504 | } |
| 1505 | |
| 1506 | if (demux->playback_mode == DMX_PB_MODE_PULL) |
| 1507 | if (dvb_dmx_swfilter_buffer_check(demux, pid) < 0) |
| 1508 | break; |
| 1509 | |
| 1510 | list_for_each_entry(feed, &demux->feed_list, list_head) { |
| 1511 | if (feed->pid != pid) |
| 1512 | continue; |
| 1513 | |
| 1514 | if (!feed->feed.sec.is_filtering) |
| 1515 | continue; |
| 1516 | |
| 1517 | if (dvb_dmx_swfilter_section_packet(feed, buf) < 0) { |
| 1518 | feed->feed.sec.seclen = 0; |
| 1519 | feed->feed.sec.secbufp = 0; |
| 1520 | } |
| 1521 | } |
| 1522 | buf += 188; |
| 1523 | } |
| 1524 | |
| 1525 | spin_unlock(&demux->lock); |
| 1526 | |
| 1527 | if (dvb_demux_performancecheck) |
| 1528 | demux->total_process_time += dvb_dmx_calc_time_delta(pre_time); |
| 1529 | } |
| 1530 | EXPORT_SYMBOL(dvb_dmx_swfilter_section_packets); |
| 1531 | |
Andreas Oberritter | dad4a73 | 2005-09-09 13:02:26 -0700 | [diff] [blame] | 1532 | void dvb_dmx_swfilter_packets(struct dvb_demux *demux, const u8 *buf, |
| 1533 | size_t count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1534 | { |
Hamad Kadmany | 32cb982 | 2012-05-10 08:47:44 +0300 | [diff] [blame] | 1535 | struct timespec pre_time; |
Hamad Kadmany | 9e5ce47 | 2012-11-22 13:47:07 +0200 | [diff] [blame] | 1536 | u8 timestamp[TIMESTAMP_LEN] = {0}; |
Hamad Kadmany | 32cb982 | 2012-05-10 08:47:44 +0300 | [diff] [blame] | 1537 | |
| 1538 | if (dvb_demux_performancecheck) |
| 1539 | pre_time = current_kernel_time(); |
| 1540 | |
Mauro Carvalho Chehab | 2810016 | 2009-02-16 15:27:44 -0300 | [diff] [blame] | 1541 | spin_lock(&demux->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1542 | |
Hamad Kadmany | 32cb982 | 2012-05-10 08:47:44 +0300 | [diff] [blame] | 1543 | demux->sw_filter_abort = 0; |
| 1544 | dvb_dmx_configure_decoder_fullness(demux, 1); |
| 1545 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1546 | while (count--) { |
Andreas Oberritter | dad4a73 | 2005-09-09 13:02:26 -0700 | [diff] [blame] | 1547 | if (buf[0] == 0x47) |
Hamad Kadmany | e1dba20 | 2013-04-10 18:37:25 +0300 | [diff] [blame] | 1548 | dvb_dmx_swfilter_one_packet(demux, buf, timestamp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1549 | buf += 188; |
| 1550 | } |
| 1551 | |
Mauro Carvalho Chehab | 2810016 | 2009-02-16 15:27:44 -0300 | [diff] [blame] | 1552 | spin_unlock(&demux->lock); |
Hamad Kadmany | 32cb982 | 2012-05-10 08:47:44 +0300 | [diff] [blame] | 1553 | |
| 1554 | if (dvb_demux_performancecheck) |
| 1555 | demux->total_process_time += dvb_dmx_calc_time_delta(pre_time); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1556 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1557 | |
Andreas Oberritter | dad4a73 | 2005-09-09 13:02:26 -0700 | [diff] [blame] | 1558 | EXPORT_SYMBOL(dvb_dmx_swfilter_packets); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1559 | |
Marko Ristola | 38e009a | 2011-04-08 12:40:51 -0300 | [diff] [blame] | 1560 | static inline int find_next_packet(const u8 *buf, int pos, size_t count, |
Hamad Kadmany | 32cb982 | 2012-05-10 08:47:44 +0300 | [diff] [blame] | 1561 | const int pktsize, const int leadingbytes) |
Marko Ristola | 38e009a | 2011-04-08 12:40:51 -0300 | [diff] [blame] | 1562 | { |
| 1563 | int start = pos, lost; |
| 1564 | |
| 1565 | while (pos < count) { |
Hamad Kadmany | 32cb982 | 2012-05-10 08:47:44 +0300 | [diff] [blame] | 1566 | if ((buf[pos] == 0x47 && !leadingbytes) || |
| 1567 | (pktsize == 204 && buf[pos] == 0xB8) || |
| 1568 | (pktsize == 192 && leadingbytes && |
| 1569 | (pos+leadingbytes < count) && |
| 1570 | buf[pos+leadingbytes] == 0x47)) |
Marko Ristola | 38e009a | 2011-04-08 12:40:51 -0300 | [diff] [blame] | 1571 | break; |
| 1572 | pos++; |
| 1573 | } |
| 1574 | |
| 1575 | lost = pos - start; |
| 1576 | if (lost) { |
| 1577 | /* This garbage is part of a valid packet? */ |
| 1578 | int backtrack = pos - pktsize; |
| 1579 | if (backtrack >= 0 && (buf[backtrack] == 0x47 || |
Hamad Kadmany | 32cb982 | 2012-05-10 08:47:44 +0300 | [diff] [blame] | 1580 | (pktsize == 204 && buf[backtrack] == 0xB8) || |
| 1581 | (pktsize == 192 && |
| 1582 | buf[backtrack+leadingbytes] == 0x47))) |
Marko Ristola | 38e009a | 2011-04-08 12:40:51 -0300 | [diff] [blame] | 1583 | return backtrack; |
| 1584 | } |
| 1585 | |
| 1586 | return pos; |
| 1587 | } |
| 1588 | |
| 1589 | /* Filter all pktsize= 188 or 204 sized packets and skip garbage. */ |
| 1590 | static inline void _dvb_dmx_swfilter(struct dvb_demux *demux, const u8 *buf, |
Hamad Kadmany | 32cb982 | 2012-05-10 08:47:44 +0300 | [diff] [blame] | 1591 | size_t count, const int pktsize, const int leadingbytes) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1592 | { |
| 1593 | int p = 0, i, j; |
Marko Ristola | 38e009a | 2011-04-08 12:40:51 -0300 | [diff] [blame] | 1594 | const u8 *q; |
Hamad Kadmany | 32cb982 | 2012-05-10 08:47:44 +0300 | [diff] [blame] | 1595 | struct timespec pre_time; |
Hamad Kadmany | 9e5ce47 | 2012-11-22 13:47:07 +0200 | [diff] [blame] | 1596 | u8 timestamp[TIMESTAMP_LEN]; |
Hamad Kadmany | 32cb982 | 2012-05-10 08:47:44 +0300 | [diff] [blame] | 1597 | |
| 1598 | if (dvb_demux_performancecheck) |
| 1599 | pre_time = current_kernel_time(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1600 | |
Mauro Carvalho Chehab | 2810016 | 2009-02-16 15:27:44 -0300 | [diff] [blame] | 1601 | spin_lock(&demux->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1602 | |
Hamad Kadmany | 32cb982 | 2012-05-10 08:47:44 +0300 | [diff] [blame] | 1603 | demux->sw_filter_abort = 0; |
| 1604 | dvb_dmx_configure_decoder_fullness(demux, 1); |
| 1605 | |
Marko Ristola | 38e009a | 2011-04-08 12:40:51 -0300 | [diff] [blame] | 1606 | if (demux->tsbufp) { /* tsbuf[0] is now 0x47. */ |
Andreas Oberritter | dad4a73 | 2005-09-09 13:02:26 -0700 | [diff] [blame] | 1607 | i = demux->tsbufp; |
Marko Ristola | 38e009a | 2011-04-08 12:40:51 -0300 | [diff] [blame] | 1608 | j = pktsize - i; |
Andreas Oberritter | dad4a73 | 2005-09-09 13:02:26 -0700 | [diff] [blame] | 1609 | if (count < j) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1610 | memcpy(&demux->tsbuf[i], buf, count); |
| 1611 | demux->tsbufp += count; |
| 1612 | goto bailout; |
| 1613 | } |
| 1614 | memcpy(&demux->tsbuf[i], buf, j); |
Hamad Kadmany | 9e5ce47 | 2012-11-22 13:47:07 +0200 | [diff] [blame] | 1615 | |
| 1616 | if (pktsize == 192) { |
| 1617 | if (leadingbytes) |
Hamad Kadmany | 1c287d7 | 2013-05-19 10:09:15 +0300 | [diff] [blame] | 1618 | memcpy(timestamp, &demux->tsbuf[p], |
| 1619 | TIMESTAMP_LEN); |
Hamad Kadmany | 9e5ce47 | 2012-11-22 13:47:07 +0200 | [diff] [blame] | 1620 | else |
Hamad Kadmany | 1c287d7 | 2013-05-19 10:09:15 +0300 | [diff] [blame] | 1621 | memcpy(timestamp, &demux->tsbuf[188], |
| 1622 | TIMESTAMP_LEN); |
Hamad Kadmany | 9e5ce47 | 2012-11-22 13:47:07 +0200 | [diff] [blame] | 1623 | } else { |
| 1624 | memset(timestamp, 0, TIMESTAMP_LEN); |
| 1625 | } |
| 1626 | |
Hamad Kadmany | 32cb982 | 2012-05-10 08:47:44 +0300 | [diff] [blame] | 1627 | if (pktsize == 192 && |
| 1628 | leadingbytes && |
| 1629 | demux->tsbuf[leadingbytes] == 0x47) /* double check */ |
Hamad Kadmany | e1dba20 | 2013-04-10 18:37:25 +0300 | [diff] [blame] | 1630 | dvb_dmx_swfilter_one_packet(demux, |
Hamad Kadmany | 9e5ce47 | 2012-11-22 13:47:07 +0200 | [diff] [blame] | 1631 | demux->tsbuf + TIMESTAMP_LEN, timestamp); |
Hamad Kadmany | 32cb982 | 2012-05-10 08:47:44 +0300 | [diff] [blame] | 1632 | else if (demux->tsbuf[0] == 0x47) /* double check */ |
Hamad Kadmany | e1dba20 | 2013-04-10 18:37:25 +0300 | [diff] [blame] | 1633 | dvb_dmx_swfilter_one_packet(demux, |
| 1634 | demux->tsbuf, timestamp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1635 | demux->tsbufp = 0; |
| 1636 | p += j; |
| 1637 | } |
| 1638 | |
Marko Ristola | 38e009a | 2011-04-08 12:40:51 -0300 | [diff] [blame] | 1639 | while (1) { |
Hamad Kadmany | 32cb982 | 2012-05-10 08:47:44 +0300 | [diff] [blame] | 1640 | p = find_next_packet(buf, p, count, pktsize, leadingbytes); |
| 1641 | |
| 1642 | if (demux->sw_filter_abort) |
| 1643 | goto bailout; |
| 1644 | |
Marko Ristola | 38e009a | 2011-04-08 12:40:51 -0300 | [diff] [blame] | 1645 | if (p >= count) |
| 1646 | break; |
| 1647 | if (count - p < pktsize) |
| 1648 | break; |
| 1649 | |
| 1650 | q = &buf[p]; |
| 1651 | |
| 1652 | if (pktsize == 204 && (*q == 0xB8)) { |
| 1653 | memcpy(demux->tsbuf, q, 188); |
| 1654 | demux->tsbuf[0] = 0x47; |
| 1655 | q = demux->tsbuf; |
| 1656 | } |
Hamad Kadmany | 32cb982 | 2012-05-10 08:47:44 +0300 | [diff] [blame] | 1657 | |
Hamad Kadmany | 9e5ce47 | 2012-11-22 13:47:07 +0200 | [diff] [blame] | 1658 | if (pktsize == 192) { |
| 1659 | if (leadingbytes) { |
| 1660 | q = &buf[p+leadingbytes]; |
| 1661 | memcpy(timestamp, &buf[p], TIMESTAMP_LEN); |
| 1662 | } else { |
Hamad Kadmany | e1dba20 | 2013-04-10 18:37:25 +0300 | [diff] [blame] | 1663 | memcpy(timestamp, &buf[p+188], TIMESTAMP_LEN); |
Hamad Kadmany | 9e5ce47 | 2012-11-22 13:47:07 +0200 | [diff] [blame] | 1664 | } |
| 1665 | } else { |
| 1666 | memset(timestamp, 0, TIMESTAMP_LEN); |
| 1667 | } |
Hamad Kadmany | 32cb982 | 2012-05-10 08:47:44 +0300 | [diff] [blame] | 1668 | |
Hamad Kadmany | e1dba20 | 2013-04-10 18:37:25 +0300 | [diff] [blame] | 1669 | dvb_dmx_swfilter_one_packet(demux, q, timestamp); |
Marko Ristola | 38e009a | 2011-04-08 12:40:51 -0300 | [diff] [blame] | 1670 | p += pktsize; |
| 1671 | } |
| 1672 | |
| 1673 | i = count - p; |
| 1674 | if (i) { |
| 1675 | memcpy(demux->tsbuf, &buf[p], i); |
| 1676 | demux->tsbufp = i; |
| 1677 | if (pktsize == 204 && demux->tsbuf[0] == 0xB8) |
| 1678 | demux->tsbuf[0] = 0x47; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1679 | } |
| 1680 | |
| 1681 | bailout: |
Mauro Carvalho Chehab | 2810016 | 2009-02-16 15:27:44 -0300 | [diff] [blame] | 1682 | spin_unlock(&demux->lock); |
Hamad Kadmany | 32cb982 | 2012-05-10 08:47:44 +0300 | [diff] [blame] | 1683 | |
| 1684 | if (dvb_demux_performancecheck) |
| 1685 | demux->total_process_time += dvb_dmx_calc_time_delta(pre_time); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1686 | } |
Andreas Oberritter | dad4a73 | 2005-09-09 13:02:26 -0700 | [diff] [blame] | 1687 | |
Marko Ristola | 38e009a | 2011-04-08 12:40:51 -0300 | [diff] [blame] | 1688 | void dvb_dmx_swfilter(struct dvb_demux *demux, const u8 *buf, size_t count) |
| 1689 | { |
Hamad Kadmany | 32cb982 | 2012-05-10 08:47:44 +0300 | [diff] [blame] | 1690 | _dvb_dmx_swfilter(demux, buf, count, 188, 0); |
Marko Ristola | 38e009a | 2011-04-08 12:40:51 -0300 | [diff] [blame] | 1691 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1692 | EXPORT_SYMBOL(dvb_dmx_swfilter); |
| 1693 | |
| 1694 | void dvb_dmx_swfilter_204(struct dvb_demux *demux, const u8 *buf, size_t count) |
| 1695 | { |
Hamad Kadmany | 32cb982 | 2012-05-10 08:47:44 +0300 | [diff] [blame] | 1696 | _dvb_dmx_swfilter(demux, buf, count, 204, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1697 | } |
| 1698 | EXPORT_SYMBOL(dvb_dmx_swfilter_204); |
| 1699 | |
Hamad Kadmany | 32cb982 | 2012-05-10 08:47:44 +0300 | [diff] [blame] | 1700 | void dvb_dmx_swfilter_format( |
| 1701 | struct dvb_demux *demux, |
| 1702 | const u8 *buf, |
| 1703 | size_t count, |
| 1704 | enum dmx_tsp_format_t tsp_format) |
| 1705 | { |
| 1706 | switch (tsp_format) { |
| 1707 | case DMX_TSP_FORMAT_188: |
| 1708 | _dvb_dmx_swfilter(demux, buf, count, 188, 0); |
| 1709 | break; |
| 1710 | |
| 1711 | case DMX_TSP_FORMAT_192_TAIL: |
| 1712 | _dvb_dmx_swfilter(demux, buf, count, 192, 0); |
| 1713 | break; |
| 1714 | |
| 1715 | case DMX_TSP_FORMAT_192_HEAD: |
Hamad Kadmany | 9e5ce47 | 2012-11-22 13:47:07 +0200 | [diff] [blame] | 1716 | _dvb_dmx_swfilter(demux, buf, count, 192, TIMESTAMP_LEN); |
Hamad Kadmany | 32cb982 | 2012-05-10 08:47:44 +0300 | [diff] [blame] | 1717 | break; |
| 1718 | |
| 1719 | case DMX_TSP_FORMAT_204: |
| 1720 | _dvb_dmx_swfilter(demux, buf, count, 204, 0); |
| 1721 | break; |
| 1722 | |
| 1723 | default: |
| 1724 | printk(KERN_ERR "%s: invalid TS packet format (format=%d)\n", |
| 1725 | __func__, |
| 1726 | tsp_format); |
| 1727 | break; |
| 1728 | } |
| 1729 | } |
| 1730 | EXPORT_SYMBOL(dvb_dmx_swfilter_format); |
| 1731 | |
Andreas Oberritter | dad4a73 | 2005-09-09 13:02:26 -0700 | [diff] [blame] | 1732 | 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] | 1733 | { |
| 1734 | int i; |
| 1735 | |
Andreas Oberritter | dad4a73 | 2005-09-09 13:02:26 -0700 | [diff] [blame] | 1736 | for (i = 0; i < demux->filternum; i++) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1737 | if (demux->filter[i].state == DMX_STATE_FREE) |
| 1738 | break; |
| 1739 | |
| 1740 | if (i == demux->filternum) |
| 1741 | return NULL; |
| 1742 | |
| 1743 | demux->filter[i].state = DMX_STATE_ALLOCATED; |
| 1744 | |
| 1745 | return &demux->filter[i]; |
| 1746 | } |
| 1747 | |
Andreas Oberritter | dad4a73 | 2005-09-09 13:02:26 -0700 | [diff] [blame] | 1748 | 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] | 1749 | { |
| 1750 | int i; |
| 1751 | |
Andreas Oberritter | dad4a73 | 2005-09-09 13:02:26 -0700 | [diff] [blame] | 1752 | for (i = 0; i < demux->feednum; i++) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1753 | if (demux->feed[i].state == DMX_STATE_FREE) |
| 1754 | break; |
| 1755 | |
| 1756 | if (i == demux->feednum) |
| 1757 | return NULL; |
| 1758 | |
| 1759 | demux->feed[i].state = DMX_STATE_ALLOCATED; |
| 1760 | |
| 1761 | return &demux->feed[i]; |
| 1762 | } |
| 1763 | |
Hamad Kadmany | e1dba20 | 2013-04-10 18:37:25 +0300 | [diff] [blame] | 1764 | const struct dvb_dmx_video_patterns *dvb_dmx_get_pattern(u64 dmx_idx_pattern) |
| 1765 | { |
| 1766 | switch (dmx_idx_pattern) { |
| 1767 | case DMX_IDX_MPEG_SEQ_HEADER: |
| 1768 | return &mpeg2_seq_hdr; |
| 1769 | |
| 1770 | case DMX_IDX_MPEG_GOP: |
| 1771 | return &mpeg2_gop; |
| 1772 | |
| 1773 | case DMX_IDX_MPEG_I_FRAME_START: |
| 1774 | return &mpeg2_iframe; |
| 1775 | |
| 1776 | case DMX_IDX_MPEG_P_FRAME_START: |
| 1777 | return &mpeg2_pframe; |
| 1778 | |
| 1779 | case DMX_IDX_MPEG_B_FRAME_START: |
| 1780 | return &mpeg2_bframe; |
| 1781 | |
| 1782 | case DMX_IDX_H264_SPS: |
| 1783 | return &h264_sps; |
| 1784 | |
| 1785 | case DMX_IDX_H264_PPS: |
| 1786 | return &h264_pps; |
| 1787 | |
| 1788 | case DMX_IDX_H264_IDR_START: |
| 1789 | return &h264_idr; |
| 1790 | |
| 1791 | case DMX_IDX_H264_NON_IDR_START: |
| 1792 | return &h264_non_idr; |
| 1793 | |
| 1794 | case DMX_IDX_VC1_SEQ_HEADER: |
| 1795 | return &vc1_seq_hdr; |
| 1796 | |
| 1797 | case DMX_IDX_VC1_ENTRY_POINT: |
| 1798 | return &vc1_entry_point; |
| 1799 | |
| 1800 | case DMX_IDX_VC1_FRAME_START: |
| 1801 | return &vc1_frame; |
| 1802 | |
| 1803 | default: |
| 1804 | return NULL; |
| 1805 | } |
| 1806 | } |
| 1807 | EXPORT_SYMBOL(dvb_dmx_get_pattern); |
| 1808 | |
| 1809 | static void dvb_dmx_init_idx_state(struct dvb_demux_feed *feed) |
| 1810 | { |
| 1811 | feed->prev_tsp_num = (u64)-1; |
| 1812 | feed->curr_pusi_tsp_num = (u64)-1; |
| 1813 | feed->prev_pusi_tsp_num = (u64)-1; |
| 1814 | feed->prev_frame_valid = 0; |
| 1815 | feed->first_frame_in_seq = 0; |
| 1816 | feed->first_frame_in_seq_notified = 0; |
| 1817 | feed->last_pattern_tsp_num = (u64)-1; |
| 1818 | feed->pattern_num = 0; |
| 1819 | memset(&feed->prefix_size, 0, |
| 1820 | sizeof(struct dvb_dmx_video_prefix_size_masks)); |
| 1821 | |
| 1822 | if (feed->idx_params.types & |
| 1823 | (DMX_IDX_MPEG_SEQ_HEADER | |
| 1824 | DMX_IDX_MPEG_FIRST_SEQ_FRAME_START | |
| 1825 | DMX_IDX_MPEG_FIRST_SEQ_FRAME_END)) { |
| 1826 | feed->patterns[feed->pattern_num] = |
| 1827 | dvb_dmx_get_pattern(DMX_IDX_MPEG_SEQ_HEADER); |
| 1828 | feed->pattern_num++; |
| 1829 | } |
| 1830 | |
| 1831 | if ((feed->pattern_num < DVB_DMX_MAX_SEARCH_PATTERN_NUM) && |
| 1832 | (feed->idx_params.types & DMX_IDX_MPEG_GOP)) { |
| 1833 | feed->patterns[feed->pattern_num] = |
| 1834 | dvb_dmx_get_pattern(DMX_IDX_MPEG_GOP); |
| 1835 | feed->pattern_num++; |
| 1836 | } |
| 1837 | |
| 1838 | /* MPEG2 I-frame */ |
| 1839 | if ((feed->pattern_num < DVB_DMX_MAX_SEARCH_PATTERN_NUM) && |
| 1840 | (feed->idx_params.types & |
| 1841 | (DMX_IDX_MPEG_I_FRAME_START | DMX_IDX_MPEG_I_FRAME_END | |
| 1842 | DMX_IDX_MPEG_P_FRAME_END | DMX_IDX_MPEG_B_FRAME_END | |
| 1843 | DMX_IDX_MPEG_FIRST_SEQ_FRAME_START | |
| 1844 | DMX_IDX_MPEG_FIRST_SEQ_FRAME_END))) { |
| 1845 | feed->patterns[feed->pattern_num] = |
| 1846 | dvb_dmx_get_pattern(DMX_IDX_MPEG_I_FRAME_START); |
| 1847 | feed->pattern_num++; |
| 1848 | } |
| 1849 | |
| 1850 | /* MPEG2 P-frame */ |
| 1851 | if ((feed->pattern_num < DVB_DMX_MAX_SEARCH_PATTERN_NUM) && |
| 1852 | (feed->idx_params.types & |
| 1853 | (DMX_IDX_MPEG_P_FRAME_START | DMX_IDX_MPEG_P_FRAME_END | |
| 1854 | DMX_IDX_MPEG_I_FRAME_END | DMX_IDX_MPEG_B_FRAME_END | |
| 1855 | DMX_IDX_MPEG_FIRST_SEQ_FRAME_START | |
| 1856 | DMX_IDX_MPEG_FIRST_SEQ_FRAME_END))) { |
| 1857 | feed->patterns[feed->pattern_num] = |
| 1858 | dvb_dmx_get_pattern(DMX_IDX_MPEG_P_FRAME_START); |
| 1859 | feed->pattern_num++; |
| 1860 | } |
| 1861 | |
| 1862 | /* MPEG2 B-frame */ |
| 1863 | if ((feed->pattern_num < DVB_DMX_MAX_SEARCH_PATTERN_NUM) && |
| 1864 | (feed->idx_params.types & |
| 1865 | (DMX_IDX_MPEG_B_FRAME_START | DMX_IDX_MPEG_B_FRAME_END | |
| 1866 | DMX_IDX_MPEG_I_FRAME_END | DMX_IDX_MPEG_P_FRAME_END | |
| 1867 | DMX_IDX_MPEG_FIRST_SEQ_FRAME_START | |
| 1868 | DMX_IDX_MPEG_FIRST_SEQ_FRAME_END))) { |
| 1869 | feed->patterns[feed->pattern_num] = |
| 1870 | dvb_dmx_get_pattern(DMX_IDX_MPEG_B_FRAME_START); |
| 1871 | feed->pattern_num++; |
| 1872 | } |
| 1873 | |
| 1874 | if ((feed->pattern_num < DVB_DMX_MAX_SEARCH_PATTERN_NUM) && |
| 1875 | (feed->idx_params.types & |
| 1876 | (DMX_IDX_H264_SPS | |
| 1877 | DMX_IDX_H264_FIRST_SPS_FRAME_START | |
| 1878 | DMX_IDX_H264_FIRST_SPS_FRAME_END))) { |
| 1879 | feed->patterns[feed->pattern_num] = |
| 1880 | dvb_dmx_get_pattern(DMX_IDX_H264_SPS); |
| 1881 | feed->pattern_num++; |
| 1882 | } |
| 1883 | |
| 1884 | if ((feed->pattern_num < DVB_DMX_MAX_SEARCH_PATTERN_NUM) && |
| 1885 | (feed->idx_params.types & DMX_IDX_H264_PPS)) { |
| 1886 | feed->patterns[feed->pattern_num] = |
| 1887 | dvb_dmx_get_pattern(DMX_IDX_H264_PPS); |
| 1888 | feed->pattern_num++; |
| 1889 | } |
| 1890 | |
| 1891 | /* H264 IDR */ |
| 1892 | if ((feed->pattern_num < DVB_DMX_MAX_SEARCH_PATTERN_NUM) && |
| 1893 | (feed->idx_params.types & |
| 1894 | (DMX_IDX_H264_IDR_START | DMX_IDX_H264_IDR_END | |
| 1895 | DMX_IDX_H264_NON_IDR_END | |
Hamad Kadmany | 65f0e93 | 2013-06-19 13:06:52 +0300 | [diff] [blame] | 1896 | DMX_IDX_H264_FIRST_SPS_FRAME_START | |
Hamad Kadmany | e1dba20 | 2013-04-10 18:37:25 +0300 | [diff] [blame] | 1897 | DMX_IDX_H264_FIRST_SPS_FRAME_END))) { |
| 1898 | feed->patterns[feed->pattern_num] = |
| 1899 | dvb_dmx_get_pattern(DMX_IDX_H264_IDR_START); |
| 1900 | feed->pattern_num++; |
| 1901 | } |
| 1902 | |
| 1903 | /* H264 non-IDR */ |
| 1904 | if ((feed->pattern_num < DVB_DMX_MAX_SEARCH_PATTERN_NUM) && |
| 1905 | (feed->idx_params.types & |
| 1906 | (DMX_IDX_H264_NON_IDR_START | DMX_IDX_H264_NON_IDR_END | |
| 1907 | DMX_IDX_H264_IDR_END | |
Hamad Kadmany | 65f0e93 | 2013-06-19 13:06:52 +0300 | [diff] [blame] | 1908 | DMX_IDX_H264_FIRST_SPS_FRAME_START | |
Hamad Kadmany | e1dba20 | 2013-04-10 18:37:25 +0300 | [diff] [blame] | 1909 | DMX_IDX_H264_FIRST_SPS_FRAME_END))) { |
| 1910 | feed->patterns[feed->pattern_num] = |
| 1911 | dvb_dmx_get_pattern(DMX_IDX_H264_NON_IDR_START); |
| 1912 | feed->pattern_num++; |
| 1913 | } |
| 1914 | |
| 1915 | if ((feed->pattern_num < DVB_DMX_MAX_SEARCH_PATTERN_NUM) && |
| 1916 | (feed->idx_params.types & |
| 1917 | (DMX_IDX_VC1_SEQ_HEADER | |
| 1918 | DMX_IDX_VC1_FIRST_SEQ_FRAME_START | |
| 1919 | DMX_IDX_VC1_FIRST_SEQ_FRAME_END))) { |
| 1920 | feed->patterns[feed->pattern_num] = |
| 1921 | dvb_dmx_get_pattern(DMX_IDX_VC1_SEQ_HEADER); |
| 1922 | feed->pattern_num++; |
| 1923 | } |
| 1924 | |
| 1925 | if ((feed->pattern_num < DVB_DMX_MAX_SEARCH_PATTERN_NUM) && |
| 1926 | (feed->idx_params.types & DMX_IDX_VC1_ENTRY_POINT)) { |
| 1927 | feed->patterns[feed->pattern_num] = |
| 1928 | dvb_dmx_get_pattern(DMX_IDX_VC1_ENTRY_POINT); |
| 1929 | feed->pattern_num++; |
| 1930 | } |
| 1931 | |
| 1932 | /* VC1 frame */ |
| 1933 | if ((feed->pattern_num < DVB_DMX_MAX_SEARCH_PATTERN_NUM) && |
| 1934 | (feed->idx_params.types & |
| 1935 | (DMX_IDX_VC1_FRAME_START | DMX_IDX_VC1_FRAME_END | |
| 1936 | DMX_IDX_VC1_FIRST_SEQ_FRAME_START | |
| 1937 | DMX_IDX_VC1_FIRST_SEQ_FRAME_END))) { |
| 1938 | feed->patterns[feed->pattern_num] = |
| 1939 | dvb_dmx_get_pattern(DMX_IDX_VC1_FRAME_START); |
| 1940 | feed->pattern_num++; |
| 1941 | } |
| 1942 | |
| 1943 | if (feed->pattern_num) |
| 1944 | feed->rec_info->idx_info.pattern_search_feeds_num++; |
| 1945 | } |
| 1946 | |
| 1947 | static struct dvb_demux_rec_info *dvb_dmx_alloc_rec_info( |
| 1948 | struct dmx_ts_feed *ts_feed) |
| 1949 | { |
| 1950 | int i; |
| 1951 | struct dvb_demux_feed *feed = (struct dvb_demux_feed *)ts_feed; |
| 1952 | struct dvb_demux *demux = feed->demux; |
| 1953 | struct dvb_demux_rec_info *rec_info; |
| 1954 | struct dvb_demux_feed *tmp_feed; |
| 1955 | |
| 1956 | /* check if this feed share recording buffer with other active feeds */ |
| 1957 | list_for_each_entry(tmp_feed, &demux->feed_list, list_head) { |
| 1958 | if ((tmp_feed->state == DMX_STATE_GO) && |
| 1959 | (tmp_feed->type == DMX_TYPE_TS) && |
| 1960 | (tmp_feed != feed) && |
| 1961 | (tmp_feed->feed.ts.buffer.ringbuff == |
| 1962 | ts_feed->buffer.ringbuff)) { |
| 1963 | /* indexing information is shared between the feeds */ |
| 1964 | tmp_feed->rec_info->ref_count++; |
| 1965 | return tmp_feed->rec_info; |
| 1966 | } |
| 1967 | } |
| 1968 | |
| 1969 | /* Need to allocate a new indexing info */ |
| 1970 | for (i = 0; i < demux->feednum; i++) |
| 1971 | if (!demux->rec_info_pool[i].ref_count) |
| 1972 | break; |
| 1973 | |
| 1974 | if (i == demux->feednum) |
| 1975 | return NULL; |
| 1976 | |
| 1977 | rec_info = &demux->rec_info_pool[i]; |
| 1978 | rec_info->ref_count++; |
| 1979 | INIT_LIST_HEAD(&rec_info->idx_info.free_list); |
| 1980 | INIT_LIST_HEAD(&rec_info->idx_info.ready_list); |
| 1981 | |
| 1982 | for (i = 0; i < DMX_IDX_EVENT_QUEUE_SIZE; i++) |
| 1983 | list_add(&rec_info->idx_info.events[i].next, |
| 1984 | &rec_info->idx_info.free_list); |
| 1985 | |
| 1986 | rec_info->ts_output_count = 0; |
| 1987 | rec_info->idx_info.min_pattern_tsp_num = (u64)-1; |
| 1988 | rec_info->idx_info.pattern_search_feeds_num = 0; |
| 1989 | |
| 1990 | return rec_info; |
| 1991 | } |
| 1992 | |
| 1993 | static void dvb_dmx_free_rec_info(struct dmx_ts_feed *ts_feed) |
| 1994 | { |
| 1995 | struct dvb_demux_feed *feed = (struct dvb_demux_feed *)ts_feed; |
| 1996 | |
| 1997 | if (!feed->rec_info || !feed->rec_info->ref_count) { |
| 1998 | printk(KERN_ERR "%s: invalid idx info state\n", __func__); |
| 1999 | return; |
| 2000 | } |
| 2001 | |
| 2002 | feed->rec_info->ref_count--; |
| 2003 | |
| 2004 | return; |
| 2005 | } |
| 2006 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2007 | static int dvb_demux_feed_find(struct dvb_demux_feed *feed) |
| 2008 | { |
| 2009 | struct dvb_demux_feed *entry; |
| 2010 | |
| 2011 | list_for_each_entry(entry, &feed->demux->feed_list, list_head) |
| 2012 | if (entry == feed) |
| 2013 | return 1; |
| 2014 | |
| 2015 | return 0; |
| 2016 | } |
| 2017 | |
| 2018 | static void dvb_demux_feed_add(struct dvb_demux_feed *feed) |
| 2019 | { |
| 2020 | spin_lock_irq(&feed->demux->lock); |
| 2021 | if (dvb_demux_feed_find(feed)) { |
| 2022 | 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] | 2023 | __func__, feed->type, feed->state, feed->pid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2024 | goto out; |
| 2025 | } |
| 2026 | |
| 2027 | list_add(&feed->list_head, &feed->demux->feed_list); |
| 2028 | out: |
| 2029 | spin_unlock_irq(&feed->demux->lock); |
| 2030 | } |
| 2031 | |
| 2032 | static void dvb_demux_feed_del(struct dvb_demux_feed *feed) |
| 2033 | { |
| 2034 | spin_lock_irq(&feed->demux->lock); |
| 2035 | if (!(dvb_demux_feed_find(feed))) { |
| 2036 | 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] | 2037 | __func__, feed->type, feed->state, feed->pid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2038 | goto out; |
| 2039 | } |
| 2040 | |
| 2041 | list_del(&feed->list_head); |
| 2042 | out: |
| 2043 | spin_unlock_irq(&feed->demux->lock); |
| 2044 | } |
| 2045 | |
Andreas Oberritter | dad4a73 | 2005-09-09 13:02:26 -0700 | [diff] [blame] | 2046 | static int dmx_ts_feed_set(struct dmx_ts_feed *ts_feed, u16 pid, int ts_type, |
| 2047 | enum dmx_ts_pes pes_type, |
| 2048 | size_t circular_buffer_size, struct timespec timeout) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2049 | { |
Andreas Oberritter | dad4a73 | 2005-09-09 13:02:26 -0700 | [diff] [blame] | 2050 | struct dvb_demux_feed *feed = (struct dvb_demux_feed *)ts_feed; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2051 | struct dvb_demux *demux = feed->demux; |
| 2052 | |
| 2053 | if (pid > DMX_MAX_PID) |
| 2054 | return -EINVAL; |
| 2055 | |
Ingo Molnar | 3593cab | 2006-02-07 06:49:14 -0200 | [diff] [blame] | 2056 | if (mutex_lock_interruptible(&demux->mutex)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2057 | return -ERESTARTSYS; |
| 2058 | |
| 2059 | if (ts_type & TS_DECODER) { |
| 2060 | if (pes_type >= DMX_TS_PES_OTHER) { |
Ingo Molnar | 3593cab | 2006-02-07 06:49:14 -0200 | [diff] [blame] | 2061 | mutex_unlock(&demux->mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2062 | return -EINVAL; |
| 2063 | } |
| 2064 | |
| 2065 | if (demux->pesfilter[pes_type] && |
| 2066 | demux->pesfilter[pes_type] != feed) { |
Ingo Molnar | 3593cab | 2006-02-07 06:49:14 -0200 | [diff] [blame] | 2067 | mutex_unlock(&demux->mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2068 | return -EINVAL; |
| 2069 | } |
| 2070 | |
| 2071 | demux->pesfilter[pes_type] = feed; |
| 2072 | demux->pids[pes_type] = pid; |
| 2073 | } |
| 2074 | |
| 2075 | dvb_demux_feed_add(feed); |
| 2076 | |
| 2077 | feed->pid = pid; |
| 2078 | feed->buffer_size = circular_buffer_size; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2079 | feed->timeout = timeout; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2080 | feed->ts_type = ts_type; |
| 2081 | feed->pes_type = pes_type; |
| 2082 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2083 | if (feed->buffer_size) { |
| 2084 | #ifdef NOBUFS |
Andreas Oberritter | dad4a73 | 2005-09-09 13:02:26 -0700 | [diff] [blame] | 2085 | feed->buffer = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2086 | #else |
| 2087 | feed->buffer = vmalloc(feed->buffer_size); |
| 2088 | if (!feed->buffer) { |
Ingo Molnar | 3593cab | 2006-02-07 06:49:14 -0200 | [diff] [blame] | 2089 | mutex_unlock(&demux->mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2090 | return -ENOMEM; |
| 2091 | } |
| 2092 | #endif |
| 2093 | } |
| 2094 | |
| 2095 | feed->state = DMX_STATE_READY; |
Ingo Molnar | 3593cab | 2006-02-07 06:49:14 -0200 | [diff] [blame] | 2096 | mutex_unlock(&demux->mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2097 | |
| 2098 | return 0; |
| 2099 | } |
| 2100 | |
Andreas Oberritter | dad4a73 | 2005-09-09 13:02:26 -0700 | [diff] [blame] | 2101 | 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] | 2102 | { |
Andreas Oberritter | dad4a73 | 2005-09-09 13:02:26 -0700 | [diff] [blame] | 2103 | struct dvb_demux_feed *feed = (struct dvb_demux_feed *)ts_feed; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2104 | struct dvb_demux *demux = feed->demux; |
| 2105 | int ret; |
| 2106 | |
Ingo Molnar | 3593cab | 2006-02-07 06:49:14 -0200 | [diff] [blame] | 2107 | if (mutex_lock_interruptible(&demux->mutex)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2108 | return -ERESTARTSYS; |
| 2109 | |
| 2110 | if (feed->state != DMX_STATE_READY || feed->type != DMX_TYPE_TS) { |
Ingo Molnar | 3593cab | 2006-02-07 06:49:14 -0200 | [diff] [blame] | 2111 | mutex_unlock(&demux->mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2112 | return -EINVAL; |
| 2113 | } |
| 2114 | |
| 2115 | if (!demux->start_feed) { |
Ingo Molnar | 3593cab | 2006-02-07 06:49:14 -0200 | [diff] [blame] | 2116 | mutex_unlock(&demux->mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2117 | return -ENODEV; |
| 2118 | } |
| 2119 | |
Hamad Kadmany | eb75d1c | 2012-07-29 13:17:28 +0300 | [diff] [blame] | 2120 | feed->first_cc = 1; |
Hamad Kadmany | d0abf31 | 2013-05-13 18:56:06 +0300 | [diff] [blame] | 2121 | feed->scrambling_bits = 0; |
Hamad Kadmany | eb75d1c | 2012-07-29 13:17:28 +0300 | [diff] [blame] | 2122 | |
Hamad Kadmany | e1dba20 | 2013-04-10 18:37:25 +0300 | [diff] [blame] | 2123 | if ((feed->ts_type & TS_PACKET) && |
| 2124 | !(feed->ts_type & TS_PAYLOAD_ONLY)) { |
| 2125 | feed->rec_info = dvb_dmx_alloc_rec_info(ts_feed); |
| 2126 | if (!feed->rec_info) { |
| 2127 | mutex_unlock(&demux->mutex); |
| 2128 | return -ENOMEM; |
| 2129 | } |
| 2130 | dvb_dmx_init_idx_state(feed); |
| 2131 | } else { |
| 2132 | feed->pattern_num = 0; |
| 2133 | feed->rec_info = NULL; |
| 2134 | } |
| 2135 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2136 | if ((ret = demux->start_feed(feed)) < 0) { |
Hamad Kadmany | e1dba20 | 2013-04-10 18:37:25 +0300 | [diff] [blame] | 2137 | dvb_dmx_free_rec_info(ts_feed); |
| 2138 | feed->rec_info = NULL; |
Ingo Molnar | 3593cab | 2006-02-07 06:49:14 -0200 | [diff] [blame] | 2139 | mutex_unlock(&demux->mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2140 | return ret; |
| 2141 | } |
| 2142 | |
| 2143 | spin_lock_irq(&demux->lock); |
| 2144 | ts_feed->is_filtering = 1; |
| 2145 | feed->state = DMX_STATE_GO; |
| 2146 | spin_unlock_irq(&demux->lock); |
Ingo Molnar | 3593cab | 2006-02-07 06:49:14 -0200 | [diff] [blame] | 2147 | mutex_unlock(&demux->mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2148 | |
| 2149 | return 0; |
| 2150 | } |
| 2151 | |
Andreas Oberritter | dad4a73 | 2005-09-09 13:02:26 -0700 | [diff] [blame] | 2152 | 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] | 2153 | { |
Andreas Oberritter | dad4a73 | 2005-09-09 13:02:26 -0700 | [diff] [blame] | 2154 | struct dvb_demux_feed *feed = (struct dvb_demux_feed *)ts_feed; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2155 | struct dvb_demux *demux = feed->demux; |
| 2156 | int ret; |
| 2157 | |
Simon Arlott | c278850 | 2007-03-10 06:21:25 -0300 | [diff] [blame] | 2158 | mutex_lock(&demux->mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2159 | |
| 2160 | if (feed->state < DMX_STATE_GO) { |
Ingo Molnar | 3593cab | 2006-02-07 06:49:14 -0200 | [diff] [blame] | 2161 | mutex_unlock(&demux->mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2162 | return -EINVAL; |
| 2163 | } |
| 2164 | |
| 2165 | if (!demux->stop_feed) { |
Ingo Molnar | 3593cab | 2006-02-07 06:49:14 -0200 | [diff] [blame] | 2166 | mutex_unlock(&demux->mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2167 | return -ENODEV; |
| 2168 | } |
| 2169 | |
| 2170 | ret = demux->stop_feed(feed); |
| 2171 | |
| 2172 | spin_lock_irq(&demux->lock); |
| 2173 | ts_feed->is_filtering = 0; |
| 2174 | feed->state = DMX_STATE_ALLOCATED; |
| 2175 | spin_unlock_irq(&demux->lock); |
Hamad Kadmany | e1dba20 | 2013-04-10 18:37:25 +0300 | [diff] [blame] | 2176 | |
| 2177 | if (feed->rec_info) { |
| 2178 | if (feed->pattern_num) |
| 2179 | feed->rec_info->idx_info.pattern_search_feeds_num--; |
| 2180 | dvb_dmx_free_rec_info(ts_feed); |
| 2181 | feed->rec_info = NULL; |
| 2182 | } |
| 2183 | |
Ingo Molnar | 3593cab | 2006-02-07 06:49:14 -0200 | [diff] [blame] | 2184 | mutex_unlock(&demux->mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2185 | |
| 2186 | return ret; |
| 2187 | } |
| 2188 | |
Hamad Kadmany | 1ea84a9 | 2012-06-04 13:34:13 +0300 | [diff] [blame] | 2189 | static int dmx_ts_feed_decoder_buff_status(struct dmx_ts_feed *ts_feed, |
| 2190 | struct dmx_buffer_status *dmx_buffer_status) |
| 2191 | { |
| 2192 | struct dvb_demux_feed *feed = (struct dvb_demux_feed *)ts_feed; |
| 2193 | struct dvb_demux *demux = feed->demux; |
| 2194 | int ret; |
| 2195 | |
Liron Kuch | 41543b7 | 2012-11-26 13:27:22 +0200 | [diff] [blame] | 2196 | mutex_lock(&demux->mutex); |
Hamad Kadmany | 1ea84a9 | 2012-06-04 13:34:13 +0300 | [diff] [blame] | 2197 | |
| 2198 | if (feed->state < DMX_STATE_GO) { |
Liron Kuch | 41543b7 | 2012-11-26 13:27:22 +0200 | [diff] [blame] | 2199 | mutex_unlock(&demux->mutex); |
Hamad Kadmany | 1ea84a9 | 2012-06-04 13:34:13 +0300 | [diff] [blame] | 2200 | return -EINVAL; |
| 2201 | } |
| 2202 | |
| 2203 | if (!demux->decoder_buffer_status) { |
Liron Kuch | 41543b7 | 2012-11-26 13:27:22 +0200 | [diff] [blame] | 2204 | mutex_unlock(&demux->mutex); |
Hamad Kadmany | 1ea84a9 | 2012-06-04 13:34:13 +0300 | [diff] [blame] | 2205 | return -ENODEV; |
| 2206 | } |
| 2207 | |
| 2208 | ret = demux->decoder_buffer_status(feed, dmx_buffer_status); |
| 2209 | |
Liron Kuch | 41543b7 | 2012-11-26 13:27:22 +0200 | [diff] [blame] | 2210 | mutex_unlock(&demux->mutex); |
| 2211 | |
| 2212 | return ret; |
| 2213 | } |
| 2214 | |
| 2215 | static int dmx_ts_feed_reuse_decoder_buffer(struct dmx_ts_feed *ts_feed, |
| 2216 | int cookie) |
| 2217 | { |
| 2218 | struct dvb_demux_feed *feed = (struct dvb_demux_feed *)ts_feed; |
| 2219 | struct dvb_demux *demux = feed->demux; |
| 2220 | int ret; |
| 2221 | |
| 2222 | mutex_lock(&demux->mutex); |
| 2223 | |
| 2224 | if (feed->state < DMX_STATE_GO) { |
| 2225 | mutex_unlock(&demux->mutex); |
| 2226 | return -EINVAL; |
| 2227 | } |
| 2228 | |
| 2229 | if (!demux->reuse_decoder_buffer) { |
| 2230 | mutex_unlock(&demux->mutex); |
| 2231 | return -ENODEV; |
| 2232 | } |
| 2233 | |
| 2234 | ret = demux->reuse_decoder_buffer(feed, cookie); |
| 2235 | |
| 2236 | mutex_unlock(&demux->mutex); |
Hamad Kadmany | 1ea84a9 | 2012-06-04 13:34:13 +0300 | [diff] [blame] | 2237 | |
| 2238 | return ret; |
| 2239 | } |
| 2240 | |
Hamad Kadmany | 4f87794 | 2012-07-15 15:06:01 +0300 | [diff] [blame] | 2241 | static int dmx_ts_feed_data_ready_cb(struct dmx_ts_feed *feed, |
| 2242 | dmx_ts_data_ready_cb callback) |
| 2243 | { |
| 2244 | struct dvb_demux_feed *dvbdmxfeed = (struct dvb_demux_feed *)feed; |
| 2245 | struct dvb_demux *dvbdmx = dvbdmxfeed->demux; |
| 2246 | |
| 2247 | mutex_lock(&dvbdmx->mutex); |
| 2248 | |
| 2249 | if (dvbdmxfeed->state == DMX_STATE_GO) { |
| 2250 | mutex_unlock(&dvbdmx->mutex); |
| 2251 | return -EINVAL; |
| 2252 | } |
| 2253 | |
| 2254 | dvbdmxfeed->data_ready_cb.ts = callback; |
| 2255 | |
| 2256 | mutex_unlock(&dvbdmx->mutex); |
| 2257 | return 0; |
| 2258 | } |
| 2259 | |
Hamad Kadmany | 04e59fb | 2013-01-29 18:37:35 +0200 | [diff] [blame] | 2260 | static int dmx_ts_set_secure_mode(struct dmx_ts_feed *feed, |
| 2261 | struct dmx_secure_mode *secure_mode) |
| 2262 | { |
| 2263 | struct dvb_demux_feed *dvbdmxfeed = (struct dvb_demux_feed *)feed; |
| 2264 | struct dvb_demux *dvbdmx = dvbdmxfeed->demux; |
Gilad Broner | 4e66375 | 2013-03-03 13:41:10 +0200 | [diff] [blame] | 2265 | int ret = 0; |
Hamad Kadmany | 04e59fb | 2013-01-29 18:37:35 +0200 | [diff] [blame] | 2266 | |
| 2267 | mutex_lock(&dvbdmx->mutex); |
| 2268 | |
Hamad Kadmany | 04e59fb | 2013-01-29 18:37:35 +0200 | [diff] [blame] | 2269 | if ((dvbdmxfeed->state == DMX_STATE_GO) && |
Gilad Broner | 4e66375 | 2013-03-03 13:41:10 +0200 | [diff] [blame] | 2270 | dvbdmxfeed->demux->set_secure_mode) { |
| 2271 | ret = dvbdmxfeed->demux->set_secure_mode(dvbdmxfeed, |
| 2272 | secure_mode); |
| 2273 | if (!ret) |
| 2274 | dvbdmxfeed->secure_mode = *secure_mode; |
| 2275 | } else { |
| 2276 | dvbdmxfeed->secure_mode = *secure_mode; |
| 2277 | } |
Hamad Kadmany | 04e59fb | 2013-01-29 18:37:35 +0200 | [diff] [blame] | 2278 | |
| 2279 | mutex_unlock(&dvbdmx->mutex); |
Gilad Broner | 4e66375 | 2013-03-03 13:41:10 +0200 | [diff] [blame] | 2280 | return ret; |
Hamad Kadmany | 04e59fb | 2013-01-29 18:37:35 +0200 | [diff] [blame] | 2281 | } |
| 2282 | |
Hamad Kadmany | c37dee8 | 2013-04-10 18:14:48 +0300 | [diff] [blame] | 2283 | static int dmx_ts_set_video_codec( |
Liron Kuch | d4cc3b0 | 2012-05-17 16:31:58 +0300 | [diff] [blame] | 2284 | struct dmx_ts_feed *ts_feed, |
Hamad Kadmany | c37dee8 | 2013-04-10 18:14:48 +0300 | [diff] [blame] | 2285 | enum dmx_video_codec video_codec) |
Liron Kuch | d4cc3b0 | 2012-05-17 16:31:58 +0300 | [diff] [blame] | 2286 | { |
| 2287 | struct dvb_demux_feed *feed = (struct dvb_demux_feed *)ts_feed; |
| 2288 | |
Hamad Kadmany | c37dee8 | 2013-04-10 18:14:48 +0300 | [diff] [blame] | 2289 | feed->video_codec = video_codec; |
Liron Kuch | d4cc3b0 | 2012-05-17 16:31:58 +0300 | [diff] [blame] | 2290 | |
| 2291 | return 0; |
| 2292 | } |
| 2293 | |
Hamad Kadmany | e1dba20 | 2013-04-10 18:37:25 +0300 | [diff] [blame] | 2294 | static int dmx_ts_set_idx_params(struct dmx_ts_feed *ts_feed, |
| 2295 | struct dmx_indexing_params *idx_params) |
| 2296 | { |
| 2297 | struct dvb_demux_feed *feed = (struct dvb_demux_feed *)ts_feed; |
| 2298 | struct dvb_demux *dvbdmx = feed->demux; |
| 2299 | |
| 2300 | mutex_lock(&dvbdmx->mutex); |
| 2301 | |
| 2302 | if ((feed->state == DMX_STATE_GO) && |
| 2303 | !feed->rec_info) { |
| 2304 | mutex_unlock(&dvbdmx->mutex); |
| 2305 | return -EINVAL; |
| 2306 | } |
| 2307 | feed->idx_params = *idx_params; |
| 2308 | |
| 2309 | if (feed->state == DMX_STATE_GO) { |
| 2310 | spin_lock_irq(&dvbdmx->lock); |
| 2311 | if (feed->pattern_num) |
| 2312 | feed->rec_info->idx_info.pattern_search_feeds_num--; |
| 2313 | dvb_dmx_init_idx_state(feed); |
| 2314 | spin_unlock_irq(&dvbdmx->lock); |
| 2315 | } |
| 2316 | |
| 2317 | mutex_unlock(&dvbdmx->mutex); |
| 2318 | |
| 2319 | return 0; |
| 2320 | } |
| 2321 | |
Gilad Broner | a81f42e | 2013-04-07 16:38:47 +0300 | [diff] [blame] | 2322 | static int dvbdmx_ts_feed_oob_cmd(struct dmx_ts_feed *ts_feed, |
| 2323 | struct dmx_oob_command *cmd) |
| 2324 | { |
| 2325 | struct dvb_demux_feed *feed = (struct dvb_demux_feed *)ts_feed; |
| 2326 | struct dmx_data_ready data; |
| 2327 | struct dvb_demux *dvbdmx = feed->demux; |
Gilad Broner | 180f65f | 2013-05-09 18:55:42 +0300 | [diff] [blame] | 2328 | int ret = 0; |
| 2329 | int secure_non_rec = feed->secure_mode.is_secured && |
| 2330 | !dvb_dmx_is_rec_feed(feed); |
Gilad Broner | a81f42e | 2013-04-07 16:38:47 +0300 | [diff] [blame] | 2331 | |
| 2332 | mutex_lock(&dvbdmx->mutex); |
| 2333 | |
| 2334 | if (feed->state != DMX_STATE_GO) { |
| 2335 | mutex_unlock(&dvbdmx->mutex); |
| 2336 | return -EINVAL; |
| 2337 | } |
| 2338 | |
Gilad Broner | 180f65f | 2013-05-09 18:55:42 +0300 | [diff] [blame] | 2339 | /* Decoder & non-recording secure feeds are handled by plug-in */ |
| 2340 | if ((feed->ts_type & TS_DECODER) || secure_non_rec) { |
Gilad Broner | a81f42e | 2013-04-07 16:38:47 +0300 | [diff] [blame] | 2341 | if (feed->demux->oob_command) |
| 2342 | ret = feed->demux->oob_command(feed, cmd); |
Gilad Broner | 180f65f | 2013-05-09 18:55:42 +0300 | [diff] [blame] | 2343 | } |
Gilad Broner | a81f42e | 2013-04-07 16:38:47 +0300 | [diff] [blame] | 2344 | |
Gilad Broner | 180f65f | 2013-05-09 18:55:42 +0300 | [diff] [blame] | 2345 | if (!(feed->ts_type & (TS_PAYLOAD_ONLY | TS_PACKET)) || |
| 2346 | secure_non_rec) { |
Gilad Broner | a81f42e | 2013-04-07 16:38:47 +0300 | [diff] [blame] | 2347 | mutex_unlock(&dvbdmx->mutex); |
| 2348 | return ret; |
| 2349 | } |
| 2350 | |
| 2351 | data.data_length = 0; |
| 2352 | |
| 2353 | switch (cmd->type) { |
| 2354 | case DMX_OOB_CMD_EOS: |
Gilad Broner | 180f65f | 2013-05-09 18:55:42 +0300 | [diff] [blame] | 2355 | if (feed->ts_type & TS_PAYLOAD_ONLY) |
| 2356 | dvb_dmx_check_pes_end(feed); |
Gilad Broner | a81f42e | 2013-04-07 16:38:47 +0300 | [diff] [blame] | 2357 | |
Gilad Broner | a81f42e | 2013-04-07 16:38:47 +0300 | [diff] [blame] | 2358 | data.status = DMX_OK_EOS; |
| 2359 | ret = feed->data_ready_cb.ts(&feed->feed.ts, &data); |
| 2360 | break; |
| 2361 | |
| 2362 | case DMX_OOB_CMD_MARKER: |
| 2363 | data.status = DMX_OK_MARKER; |
| 2364 | data.marker.id = cmd->params.marker.id; |
| 2365 | ret = feed->data_ready_cb.ts(&feed->feed.ts, &data); |
| 2366 | break; |
| 2367 | |
| 2368 | default: |
| 2369 | ret = -EINVAL; |
| 2370 | break; |
| 2371 | } |
| 2372 | |
| 2373 | mutex_unlock(&dvbdmx->mutex); |
| 2374 | return ret; |
| 2375 | } |
| 2376 | |
Hamad Kadmany | d0abf31 | 2013-05-13 18:56:06 +0300 | [diff] [blame] | 2377 | static int dvbdmx_ts_get_scrambling_bits(struct dmx_ts_feed *ts_feed, |
| 2378 | u8 *value) |
| 2379 | { |
| 2380 | struct dvb_demux_feed *feed = (struct dvb_demux_feed *)ts_feed; |
| 2381 | struct dvb_demux *demux = feed->demux; |
| 2382 | |
| 2383 | spin_lock(&demux->lock); |
| 2384 | |
| 2385 | if (!ts_feed->is_filtering) { |
| 2386 | spin_unlock(&demux->lock); |
| 2387 | return -EINVAL; |
| 2388 | } |
| 2389 | |
| 2390 | *value = feed->scrambling_bits; |
| 2391 | spin_unlock(&demux->lock); |
| 2392 | |
| 2393 | return 0; |
| 2394 | } |
| 2395 | |
Hamad Kadmany | 0402d06 | 2013-05-02 15:52:07 +0300 | [diff] [blame] | 2396 | static int dvbdmx_ts_insertion_insert_buffer(struct dmx_ts_feed *ts_feed, |
| 2397 | char *data, size_t size) |
| 2398 | { |
| 2399 | struct dvb_demux_feed *feed = (struct dvb_demux_feed *)ts_feed; |
| 2400 | struct dvb_demux *demux = feed->demux; |
| 2401 | |
| 2402 | spin_lock(&demux->lock); |
| 2403 | if (!ts_feed->is_filtering) { |
| 2404 | spin_unlock(&demux->lock); |
| 2405 | return 0; |
| 2406 | } |
| 2407 | |
| 2408 | feed->cb.ts(data, size, NULL, 0, ts_feed, DMX_OK); |
| 2409 | |
| 2410 | spin_unlock(&demux->lock); |
| 2411 | |
| 2412 | return 0; |
| 2413 | } |
| 2414 | |
Hamad Kadmany | 9e5ce47 | 2012-11-22 13:47:07 +0200 | [diff] [blame] | 2415 | static int dmx_ts_set_tsp_out_format( |
| 2416 | struct dmx_ts_feed *ts_feed, |
| 2417 | enum dmx_tsp_format_t tsp_format) |
| 2418 | { |
| 2419 | struct dvb_demux_feed *feed = (struct dvb_demux_feed *)ts_feed; |
| 2420 | struct dvb_demux *dvbdmx = feed->demux; |
| 2421 | |
| 2422 | mutex_lock(&dvbdmx->mutex); |
| 2423 | |
| 2424 | if (feed->state == DMX_STATE_GO) { |
| 2425 | mutex_unlock(&dvbdmx->mutex); |
| 2426 | return -EINVAL; |
| 2427 | } |
| 2428 | |
| 2429 | feed->tsp_out_format = tsp_format; |
| 2430 | mutex_unlock(&dvbdmx->mutex); |
| 2431 | return 0; |
| 2432 | } |
| 2433 | |
Andreas Oberritter | dad4a73 | 2005-09-09 13:02:26 -0700 | [diff] [blame] | 2434 | static int dvbdmx_allocate_ts_feed(struct dmx_demux *dmx, |
| 2435 | struct dmx_ts_feed **ts_feed, |
| 2436 | dmx_ts_cb callback) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2437 | { |
Andreas Oberritter | dad4a73 | 2005-09-09 13:02:26 -0700 | [diff] [blame] | 2438 | struct dvb_demux *demux = (struct dvb_demux *)dmx; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2439 | struct dvb_demux_feed *feed; |
| 2440 | |
Ingo Molnar | 3593cab | 2006-02-07 06:49:14 -0200 | [diff] [blame] | 2441 | if (mutex_lock_interruptible(&demux->mutex)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2442 | return -ERESTARTSYS; |
| 2443 | |
| 2444 | if (!(feed = dvb_dmx_feed_alloc(demux))) { |
Ingo Molnar | 3593cab | 2006-02-07 06:49:14 -0200 | [diff] [blame] | 2445 | mutex_unlock(&demux->mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2446 | return -EBUSY; |
| 2447 | } |
| 2448 | |
| 2449 | feed->type = DMX_TYPE_TS; |
| 2450 | feed->cb.ts = callback; |
| 2451 | feed->demux = demux; |
| 2452 | feed->pid = 0xffff; |
Hamad Kadmany | 4f87794 | 2012-07-15 15:06:01 +0300 | [diff] [blame] | 2453 | feed->peslen = 0; |
Hamad Kadmany | d432f71 | 2013-01-17 17:36:17 +0200 | [diff] [blame] | 2454 | feed->pes_tei_counter = 0; |
| 2455 | feed->pes_ts_packets_num = 0; |
| 2456 | feed->pes_cont_err_counter = 0; |
Hamad Kadmany | 04e59fb | 2013-01-29 18:37:35 +0200 | [diff] [blame] | 2457 | feed->secure_mode.is_secured = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2458 | feed->buffer = NULL; |
Hamad Kadmany | 9e5ce47 | 2012-11-22 13:47:07 +0200 | [diff] [blame] | 2459 | feed->tsp_out_format = DMX_TSP_FORMAT_188; |
Hamad Kadmany | e1dba20 | 2013-04-10 18:37:25 +0300 | [diff] [blame] | 2460 | feed->idx_params.enable = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2461 | |
Hamad Kadmany | 32cb982 | 2012-05-10 08:47:44 +0300 | [diff] [blame] | 2462 | /* default behaviour - pass first PES data even if it is |
| 2463 | * partial PES data from previous PES that we didn't receive its header. |
| 2464 | * Override this to 0 in your start_feed function in order to handle |
| 2465 | * first PES differently. |
| 2466 | */ |
| 2467 | feed->pusi_seen = 1; |
| 2468 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2469 | (*ts_feed) = &feed->feed.ts; |
| 2470 | (*ts_feed)->parent = dmx; |
| 2471 | (*ts_feed)->priv = NULL; |
| 2472 | (*ts_feed)->is_filtering = 0; |
| 2473 | (*ts_feed)->start_filtering = dmx_ts_feed_start_filtering; |
| 2474 | (*ts_feed)->stop_filtering = dmx_ts_feed_stop_filtering; |
| 2475 | (*ts_feed)->set = dmx_ts_feed_set; |
Hamad Kadmany | c37dee8 | 2013-04-10 18:14:48 +0300 | [diff] [blame] | 2476 | (*ts_feed)->set_video_codec = dmx_ts_set_video_codec; |
Hamad Kadmany | e1dba20 | 2013-04-10 18:37:25 +0300 | [diff] [blame] | 2477 | (*ts_feed)->set_idx_params = dmx_ts_set_idx_params; |
Hamad Kadmany | 9e5ce47 | 2012-11-22 13:47:07 +0200 | [diff] [blame] | 2478 | (*ts_feed)->set_tsp_out_format = dmx_ts_set_tsp_out_format; |
Hamad Kadmany | 1ea84a9 | 2012-06-04 13:34:13 +0300 | [diff] [blame] | 2479 | (*ts_feed)->get_decoder_buff_status = dmx_ts_feed_decoder_buff_status; |
Liron Kuch | 41543b7 | 2012-11-26 13:27:22 +0200 | [diff] [blame] | 2480 | (*ts_feed)->reuse_decoder_buffer = dmx_ts_feed_reuse_decoder_buffer; |
Hamad Kadmany | 4f87794 | 2012-07-15 15:06:01 +0300 | [diff] [blame] | 2481 | (*ts_feed)->data_ready_cb = dmx_ts_feed_data_ready_cb; |
Hamad Kadmany | c853010 | 2012-07-23 11:43:09 +0300 | [diff] [blame] | 2482 | (*ts_feed)->notify_data_read = NULL; |
Hamad Kadmany | 04e59fb | 2013-01-29 18:37:35 +0200 | [diff] [blame] | 2483 | (*ts_feed)->set_secure_mode = dmx_ts_set_secure_mode; |
Gilad Broner | a81f42e | 2013-04-07 16:38:47 +0300 | [diff] [blame] | 2484 | (*ts_feed)->oob_command = dvbdmx_ts_feed_oob_cmd; |
Hamad Kadmany | d0abf31 | 2013-05-13 18:56:06 +0300 | [diff] [blame] | 2485 | (*ts_feed)->get_scrambling_bits = dvbdmx_ts_get_scrambling_bits; |
Hamad Kadmany | 0402d06 | 2013-05-02 15:52:07 +0300 | [diff] [blame] | 2486 | (*ts_feed)->ts_insertion_init = NULL; |
| 2487 | (*ts_feed)->ts_insertion_terminate = NULL; |
| 2488 | (*ts_feed)->ts_insertion_insert_buffer = |
| 2489 | dvbdmx_ts_insertion_insert_buffer; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2490 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2491 | if (!(feed->filter = dvb_dmx_filter_alloc(demux))) { |
| 2492 | feed->state = DMX_STATE_FREE; |
Ingo Molnar | 3593cab | 2006-02-07 06:49:14 -0200 | [diff] [blame] | 2493 | mutex_unlock(&demux->mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2494 | return -EBUSY; |
| 2495 | } |
| 2496 | |
| 2497 | feed->filter->type = DMX_TYPE_TS; |
| 2498 | feed->filter->feed = feed; |
| 2499 | feed->filter->state = DMX_STATE_READY; |
| 2500 | |
Ingo Molnar | 3593cab | 2006-02-07 06:49:14 -0200 | [diff] [blame] | 2501 | mutex_unlock(&demux->mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2502 | |
| 2503 | return 0; |
| 2504 | } |
| 2505 | |
Andreas Oberritter | dad4a73 | 2005-09-09 13:02:26 -0700 | [diff] [blame] | 2506 | static int dvbdmx_release_ts_feed(struct dmx_demux *dmx, |
| 2507 | struct dmx_ts_feed *ts_feed) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2508 | { |
Andreas Oberritter | dad4a73 | 2005-09-09 13:02:26 -0700 | [diff] [blame] | 2509 | struct dvb_demux *demux = (struct dvb_demux *)dmx; |
| 2510 | struct dvb_demux_feed *feed = (struct dvb_demux_feed *)ts_feed; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2511 | |
Simon Arlott | c278850 | 2007-03-10 06:21:25 -0300 | [diff] [blame] | 2512 | mutex_lock(&demux->mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2513 | |
| 2514 | if (feed->state == DMX_STATE_FREE) { |
Ingo Molnar | 3593cab | 2006-02-07 06:49:14 -0200 | [diff] [blame] | 2515 | mutex_unlock(&demux->mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2516 | return -EINVAL; |
| 2517 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2518 | #ifndef NOBUFS |
| 2519 | vfree(feed->buffer); |
Andreas Oberritter | dad4a73 | 2005-09-09 13:02:26 -0700 | [diff] [blame] | 2520 | feed->buffer = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2521 | #endif |
| 2522 | |
| 2523 | feed->state = DMX_STATE_FREE; |
| 2524 | feed->filter->state = DMX_STATE_FREE; |
| 2525 | |
| 2526 | dvb_demux_feed_del(feed); |
| 2527 | |
| 2528 | feed->pid = 0xffff; |
| 2529 | |
| 2530 | if (feed->ts_type & TS_DECODER && feed->pes_type < DMX_TS_PES_OTHER) |
| 2531 | demux->pesfilter[feed->pes_type] = NULL; |
| 2532 | |
Ingo Molnar | 3593cab | 2006-02-07 06:49:14 -0200 | [diff] [blame] | 2533 | mutex_unlock(&demux->mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2534 | return 0; |
| 2535 | } |
| 2536 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2537 | /****************************************************************************** |
| 2538 | * dmx_section_feed API calls |
| 2539 | ******************************************************************************/ |
| 2540 | |
Andreas Oberritter | dad4a73 | 2005-09-09 13:02:26 -0700 | [diff] [blame] | 2541 | static int dmx_section_feed_allocate_filter(struct dmx_section_feed *feed, |
| 2542 | struct dmx_section_filter **filter) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2543 | { |
Andreas Oberritter | dad4a73 | 2005-09-09 13:02:26 -0700 | [diff] [blame] | 2544 | struct dvb_demux_feed *dvbdmxfeed = (struct dvb_demux_feed *)feed; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2545 | struct dvb_demux *dvbdemux = dvbdmxfeed->demux; |
| 2546 | struct dvb_demux_filter *dvbdmxfilter; |
| 2547 | |
Ingo Molnar | 3593cab | 2006-02-07 06:49:14 -0200 | [diff] [blame] | 2548 | if (mutex_lock_interruptible(&dvbdemux->mutex)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2549 | return -ERESTARTSYS; |
| 2550 | |
| 2551 | dvbdmxfilter = dvb_dmx_filter_alloc(dvbdemux); |
| 2552 | if (!dvbdmxfilter) { |
Ingo Molnar | 3593cab | 2006-02-07 06:49:14 -0200 | [diff] [blame] | 2553 | mutex_unlock(&dvbdemux->mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2554 | return -EBUSY; |
| 2555 | } |
| 2556 | |
| 2557 | spin_lock_irq(&dvbdemux->lock); |
| 2558 | *filter = &dvbdmxfilter->filter; |
| 2559 | (*filter)->parent = feed; |
| 2560 | (*filter)->priv = NULL; |
| 2561 | dvbdmxfilter->feed = dvbdmxfeed; |
| 2562 | dvbdmxfilter->type = DMX_TYPE_SEC; |
| 2563 | dvbdmxfilter->state = DMX_STATE_READY; |
| 2564 | dvbdmxfilter->next = dvbdmxfeed->filter; |
| 2565 | dvbdmxfeed->filter = dvbdmxfilter; |
| 2566 | spin_unlock_irq(&dvbdemux->lock); |
| 2567 | |
Ingo Molnar | 3593cab | 2006-02-07 06:49:14 -0200 | [diff] [blame] | 2568 | mutex_unlock(&dvbdemux->mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2569 | return 0; |
| 2570 | } |
| 2571 | |
Andreas Oberritter | dad4a73 | 2005-09-09 13:02:26 -0700 | [diff] [blame] | 2572 | static int dmx_section_feed_set(struct dmx_section_feed *feed, |
| 2573 | u16 pid, size_t circular_buffer_size, |
| 2574 | int check_crc) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2575 | { |
Andreas Oberritter | dad4a73 | 2005-09-09 13:02:26 -0700 | [diff] [blame] | 2576 | struct dvb_demux_feed *dvbdmxfeed = (struct dvb_demux_feed *)feed; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2577 | struct dvb_demux *dvbdmx = dvbdmxfeed->demux; |
| 2578 | |
| 2579 | if (pid > 0x1fff) |
| 2580 | return -EINVAL; |
| 2581 | |
Ingo Molnar | 3593cab | 2006-02-07 06:49:14 -0200 | [diff] [blame] | 2582 | if (mutex_lock_interruptible(&dvbdmx->mutex)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2583 | return -ERESTARTSYS; |
| 2584 | |
| 2585 | dvb_demux_feed_add(dvbdmxfeed); |
| 2586 | |
| 2587 | dvbdmxfeed->pid = pid; |
| 2588 | dvbdmxfeed->buffer_size = circular_buffer_size; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2589 | dvbdmxfeed->feed.sec.check_crc = check_crc; |
| 2590 | |
| 2591 | #ifdef NOBUFS |
| 2592 | dvbdmxfeed->buffer = NULL; |
| 2593 | #else |
Andreas Oberritter | dad4a73 | 2005-09-09 13:02:26 -0700 | [diff] [blame] | 2594 | dvbdmxfeed->buffer = vmalloc(dvbdmxfeed->buffer_size); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2595 | if (!dvbdmxfeed->buffer) { |
Ingo Molnar | 3593cab | 2006-02-07 06:49:14 -0200 | [diff] [blame] | 2596 | mutex_unlock(&dvbdmx->mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2597 | return -ENOMEM; |
| 2598 | } |
| 2599 | #endif |
| 2600 | |
| 2601 | dvbdmxfeed->state = DMX_STATE_READY; |
Ingo Molnar | 3593cab | 2006-02-07 06:49:14 -0200 | [diff] [blame] | 2602 | mutex_unlock(&dvbdmx->mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2603 | return 0; |
| 2604 | } |
| 2605 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2606 | static void prepare_secfilters(struct dvb_demux_feed *dvbdmxfeed) |
| 2607 | { |
| 2608 | int i; |
| 2609 | struct dvb_demux_filter *f; |
| 2610 | struct dmx_section_filter *sf; |
| 2611 | u8 mask, mode, doneq; |
| 2612 | |
Andreas Oberritter | dad4a73 | 2005-09-09 13:02:26 -0700 | [diff] [blame] | 2613 | if (!(f = dvbdmxfeed->filter)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2614 | return; |
| 2615 | do { |
| 2616 | sf = &f->filter; |
| 2617 | doneq = 0; |
Andreas Oberritter | dad4a73 | 2005-09-09 13:02:26 -0700 | [diff] [blame] | 2618 | for (i = 0; i < DVB_DEMUX_MASK_MAX; i++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2619 | mode = sf->filter_mode[i]; |
| 2620 | mask = sf->filter_mask[i]; |
| 2621 | f->maskandmode[i] = mask & mode; |
| 2622 | doneq |= f->maskandnotmode[i] = mask & ~mode; |
| 2623 | } |
| 2624 | f->doneq = doneq ? 1 : 0; |
| 2625 | } while ((f = f->next)); |
| 2626 | } |
| 2627 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2628 | static int dmx_section_feed_start_filtering(struct dmx_section_feed *feed) |
| 2629 | { |
Andreas Oberritter | dad4a73 | 2005-09-09 13:02:26 -0700 | [diff] [blame] | 2630 | struct dvb_demux_feed *dvbdmxfeed = (struct dvb_demux_feed *)feed; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2631 | struct dvb_demux *dvbdmx = dvbdmxfeed->demux; |
| 2632 | int ret; |
| 2633 | |
Ingo Molnar | 3593cab | 2006-02-07 06:49:14 -0200 | [diff] [blame] | 2634 | if (mutex_lock_interruptible(&dvbdmx->mutex)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2635 | return -ERESTARTSYS; |
| 2636 | |
| 2637 | if (feed->is_filtering) { |
Ingo Molnar | 3593cab | 2006-02-07 06:49:14 -0200 | [diff] [blame] | 2638 | mutex_unlock(&dvbdmx->mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2639 | return -EBUSY; |
| 2640 | } |
| 2641 | |
| 2642 | if (!dvbdmxfeed->filter) { |
Ingo Molnar | 3593cab | 2006-02-07 06:49:14 -0200 | [diff] [blame] | 2643 | mutex_unlock(&dvbdmx->mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2644 | return -EINVAL; |
| 2645 | } |
| 2646 | |
| 2647 | dvbdmxfeed->feed.sec.tsfeedp = 0; |
| 2648 | dvbdmxfeed->feed.sec.secbuf = dvbdmxfeed->feed.sec.secbuf_base; |
| 2649 | dvbdmxfeed->feed.sec.secbufp = 0; |
| 2650 | dvbdmxfeed->feed.sec.seclen = 0; |
Hamad Kadmany | eb75d1c | 2012-07-29 13:17:28 +0300 | [diff] [blame] | 2651 | dvbdmxfeed->first_cc = 1; |
Hamad Kadmany | d0abf31 | 2013-05-13 18:56:06 +0300 | [diff] [blame] | 2652 | dvbdmxfeed->scrambling_bits = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2653 | |
| 2654 | if (!dvbdmx->start_feed) { |
Ingo Molnar | 3593cab | 2006-02-07 06:49:14 -0200 | [diff] [blame] | 2655 | mutex_unlock(&dvbdmx->mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2656 | return -ENODEV; |
| 2657 | } |
| 2658 | |
| 2659 | prepare_secfilters(dvbdmxfeed); |
| 2660 | |
| 2661 | if ((ret = dvbdmx->start_feed(dvbdmxfeed)) < 0) { |
Ingo Molnar | 3593cab | 2006-02-07 06:49:14 -0200 | [diff] [blame] | 2662 | mutex_unlock(&dvbdmx->mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2663 | return ret; |
| 2664 | } |
| 2665 | |
| 2666 | spin_lock_irq(&dvbdmx->lock); |
| 2667 | feed->is_filtering = 1; |
| 2668 | dvbdmxfeed->state = DMX_STATE_GO; |
| 2669 | spin_unlock_irq(&dvbdmx->lock); |
| 2670 | |
Ingo Molnar | 3593cab | 2006-02-07 06:49:14 -0200 | [diff] [blame] | 2671 | mutex_unlock(&dvbdmx->mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2672 | return 0; |
| 2673 | } |
| 2674 | |
Andreas Oberritter | dad4a73 | 2005-09-09 13:02:26 -0700 | [diff] [blame] | 2675 | static int dmx_section_feed_stop_filtering(struct dmx_section_feed *feed) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2676 | { |
Andreas Oberritter | dad4a73 | 2005-09-09 13:02:26 -0700 | [diff] [blame] | 2677 | struct dvb_demux_feed *dvbdmxfeed = (struct dvb_demux_feed *)feed; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2678 | struct dvb_demux *dvbdmx = dvbdmxfeed->demux; |
| 2679 | int ret; |
| 2680 | |
Simon Arlott | c278850 | 2007-03-10 06:21:25 -0300 | [diff] [blame] | 2681 | mutex_lock(&dvbdmx->mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2682 | |
| 2683 | if (!dvbdmx->stop_feed) { |
Ingo Molnar | 3593cab | 2006-02-07 06:49:14 -0200 | [diff] [blame] | 2684 | mutex_unlock(&dvbdmx->mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2685 | return -ENODEV; |
| 2686 | } |
| 2687 | |
| 2688 | ret = dvbdmx->stop_feed(dvbdmxfeed); |
| 2689 | |
| 2690 | spin_lock_irq(&dvbdmx->lock); |
| 2691 | dvbdmxfeed->state = DMX_STATE_READY; |
| 2692 | feed->is_filtering = 0; |
| 2693 | spin_unlock_irq(&dvbdmx->lock); |
| 2694 | |
Ingo Molnar | 3593cab | 2006-02-07 06:49:14 -0200 | [diff] [blame] | 2695 | mutex_unlock(&dvbdmx->mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2696 | return ret; |
| 2697 | } |
| 2698 | |
Hamad Kadmany | 4f87794 | 2012-07-15 15:06:01 +0300 | [diff] [blame] | 2699 | |
| 2700 | static int dmx_section_feed_data_ready_cb(struct dmx_section_feed *feed, |
| 2701 | dmx_section_data_ready_cb callback) |
| 2702 | { |
| 2703 | struct dvb_demux_feed *dvbdmxfeed = (struct dvb_demux_feed *)feed; |
| 2704 | struct dvb_demux *dvbdmx = dvbdmxfeed->demux; |
| 2705 | |
| 2706 | mutex_lock(&dvbdmx->mutex); |
| 2707 | |
| 2708 | if (dvbdmxfeed->state == DMX_STATE_GO) { |
| 2709 | mutex_unlock(&dvbdmx->mutex); |
| 2710 | return -EINVAL; |
| 2711 | } |
| 2712 | |
| 2713 | dvbdmxfeed->data_ready_cb.sec = callback; |
| 2714 | |
| 2715 | mutex_unlock(&dvbdmx->mutex); |
| 2716 | return 0; |
| 2717 | } |
| 2718 | |
Hamad Kadmany | 04e59fb | 2013-01-29 18:37:35 +0200 | [diff] [blame] | 2719 | static int dmx_section_set_secure_mode(struct dmx_section_feed *feed, |
| 2720 | struct dmx_secure_mode *secure_mode) |
| 2721 | { |
| 2722 | struct dvb_demux_feed *dvbdmxfeed = (struct dvb_demux_feed *)feed; |
| 2723 | struct dvb_demux *dvbdmx = dvbdmxfeed->demux; |
| 2724 | |
| 2725 | mutex_lock(&dvbdmx->mutex); |
| 2726 | |
| 2727 | dvbdmxfeed->secure_mode = *secure_mode; |
| 2728 | if ((dvbdmxfeed->state == DMX_STATE_GO) && |
| 2729 | dvbdmxfeed->demux->set_secure_mode) |
| 2730 | dvbdmxfeed->demux->set_secure_mode(dvbdmxfeed, secure_mode); |
| 2731 | |
| 2732 | mutex_unlock(&dvbdmx->mutex); |
| 2733 | return 0; |
| 2734 | } |
| 2735 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2736 | static int dmx_section_feed_release_filter(struct dmx_section_feed *feed, |
Andreas Oberritter | dad4a73 | 2005-09-09 13:02:26 -0700 | [diff] [blame] | 2737 | struct dmx_section_filter *filter) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2738 | { |
Andreas Oberritter | dad4a73 | 2005-09-09 13:02:26 -0700 | [diff] [blame] | 2739 | struct dvb_demux_filter *dvbdmxfilter = (struct dvb_demux_filter *)filter, *f; |
| 2740 | struct dvb_demux_feed *dvbdmxfeed = (struct dvb_demux_feed *)feed; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2741 | struct dvb_demux *dvbdmx = dvbdmxfeed->demux; |
| 2742 | |
Simon Arlott | c278850 | 2007-03-10 06:21:25 -0300 | [diff] [blame] | 2743 | mutex_lock(&dvbdmx->mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2744 | |
| 2745 | if (dvbdmxfilter->feed != dvbdmxfeed) { |
Ingo Molnar | 3593cab | 2006-02-07 06:49:14 -0200 | [diff] [blame] | 2746 | mutex_unlock(&dvbdmx->mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2747 | return -EINVAL; |
| 2748 | } |
| 2749 | |
| 2750 | if (feed->is_filtering) |
| 2751 | feed->stop_filtering(feed); |
| 2752 | |
| 2753 | spin_lock_irq(&dvbdmx->lock); |
| 2754 | f = dvbdmxfeed->filter; |
| 2755 | |
| 2756 | if (f == dvbdmxfilter) { |
| 2757 | dvbdmxfeed->filter = dvbdmxfilter->next; |
| 2758 | } else { |
Andreas Oberritter | dad4a73 | 2005-09-09 13:02:26 -0700 | [diff] [blame] | 2759 | while (f->next != dvbdmxfilter) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2760 | f = f->next; |
| 2761 | f->next = f->next->next; |
| 2762 | } |
| 2763 | |
| 2764 | dvbdmxfilter->state = DMX_STATE_FREE; |
| 2765 | spin_unlock_irq(&dvbdmx->lock); |
Ingo Molnar | 3593cab | 2006-02-07 06:49:14 -0200 | [diff] [blame] | 2766 | mutex_unlock(&dvbdmx->mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2767 | return 0; |
| 2768 | } |
| 2769 | |
Gilad Broner | a81f42e | 2013-04-07 16:38:47 +0300 | [diff] [blame] | 2770 | static int dvbdmx_section_feed_oob_cmd(struct dmx_section_feed *section_feed, |
| 2771 | struct dmx_oob_command *cmd) |
| 2772 | { |
| 2773 | struct dvb_demux_feed *feed = (struct dvb_demux_feed *)section_feed; |
| 2774 | struct dvb_demux *dvbdmx = feed->demux; |
| 2775 | struct dmx_data_ready data; |
Gilad Broner | acb4b87 | 2013-05-30 18:55:59 +0300 | [diff] [blame] | 2776 | int ret = 0; |
Gilad Broner | a81f42e | 2013-04-07 16:38:47 +0300 | [diff] [blame] | 2777 | |
| 2778 | data.data_length = 0; |
| 2779 | |
| 2780 | mutex_lock(&dvbdmx->mutex); |
| 2781 | |
| 2782 | if (feed->state != DMX_STATE_GO) { |
| 2783 | mutex_unlock(&dvbdmx->mutex); |
| 2784 | return -EINVAL; |
| 2785 | } |
| 2786 | |
| 2787 | /* Secure section feeds are handled by the plug-in */ |
| 2788 | if (feed->secure_mode.is_secured) { |
| 2789 | if (feed->demux->oob_command) |
| 2790 | ret = feed->demux->oob_command(feed, cmd); |
| 2791 | else |
| 2792 | ret = 0; |
| 2793 | |
| 2794 | mutex_unlock(&dvbdmx->mutex); |
| 2795 | return ret; |
| 2796 | } |
| 2797 | |
| 2798 | switch (cmd->type) { |
| 2799 | case DMX_OOB_CMD_EOS: |
| 2800 | data.status = DMX_OK_EOS; |
Gilad Broner | a81f42e | 2013-04-07 16:38:47 +0300 | [diff] [blame] | 2801 | break; |
| 2802 | |
| 2803 | case DMX_OOB_CMD_MARKER: |
| 2804 | data.status = DMX_OK_MARKER; |
| 2805 | data.marker.id = cmd->params.marker.id; |
Gilad Broner | a81f42e | 2013-04-07 16:38:47 +0300 | [diff] [blame] | 2806 | break; |
| 2807 | |
| 2808 | default: |
| 2809 | ret = -EINVAL; |
| 2810 | break; |
| 2811 | } |
| 2812 | |
Gilad Broner | acb4b87 | 2013-05-30 18:55:59 +0300 | [diff] [blame] | 2813 | if (!ret) |
| 2814 | ret = dvb_dmx_notify_section_event(feed, &data, 1); |
| 2815 | |
Gilad Broner | a81f42e | 2013-04-07 16:38:47 +0300 | [diff] [blame] | 2816 | mutex_unlock(&dvbdmx->mutex); |
| 2817 | return ret; |
| 2818 | } |
| 2819 | |
Hamad Kadmany | d0abf31 | 2013-05-13 18:56:06 +0300 | [diff] [blame] | 2820 | static int dvbdmx_section_get_scrambling_bits( |
| 2821 | struct dmx_section_feed *section_feed, u8 *value) |
| 2822 | { |
| 2823 | struct dvb_demux_feed *feed = (struct dvb_demux_feed *)section_feed; |
| 2824 | struct dvb_demux *demux = feed->demux; |
| 2825 | |
| 2826 | spin_lock(&demux->lock); |
| 2827 | |
| 2828 | if (!section_feed->is_filtering) { |
| 2829 | spin_unlock(&demux->lock); |
| 2830 | return -EINVAL; |
| 2831 | } |
| 2832 | |
| 2833 | *value = feed->scrambling_bits; |
| 2834 | spin_unlock(&demux->lock); |
| 2835 | |
| 2836 | return 0; |
| 2837 | } |
| 2838 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2839 | static int dvbdmx_allocate_section_feed(struct dmx_demux *demux, |
| 2840 | struct dmx_section_feed **feed, |
| 2841 | dmx_section_cb callback) |
| 2842 | { |
Andreas Oberritter | dad4a73 | 2005-09-09 13:02:26 -0700 | [diff] [blame] | 2843 | struct dvb_demux *dvbdmx = (struct dvb_demux *)demux; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2844 | struct dvb_demux_feed *dvbdmxfeed; |
| 2845 | |
Ingo Molnar | 3593cab | 2006-02-07 06:49:14 -0200 | [diff] [blame] | 2846 | if (mutex_lock_interruptible(&dvbdmx->mutex)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2847 | return -ERESTARTSYS; |
| 2848 | |
| 2849 | if (!(dvbdmxfeed = dvb_dmx_feed_alloc(dvbdmx))) { |
Ingo Molnar | 3593cab | 2006-02-07 06:49:14 -0200 | [diff] [blame] | 2850 | mutex_unlock(&dvbdmx->mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2851 | return -EBUSY; |
| 2852 | } |
| 2853 | |
| 2854 | dvbdmxfeed->type = DMX_TYPE_SEC; |
| 2855 | dvbdmxfeed->cb.sec = callback; |
| 2856 | dvbdmxfeed->demux = dvbdmx; |
| 2857 | dvbdmxfeed->pid = 0xffff; |
Hamad Kadmany | 04e59fb | 2013-01-29 18:37:35 +0200 | [diff] [blame] | 2858 | dvbdmxfeed->secure_mode.is_secured = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2859 | dvbdmxfeed->feed.sec.secbuf = dvbdmxfeed->feed.sec.secbuf_base; |
| 2860 | dvbdmxfeed->feed.sec.secbufp = dvbdmxfeed->feed.sec.seclen = 0; |
| 2861 | dvbdmxfeed->feed.sec.tsfeedp = 0; |
| 2862 | dvbdmxfeed->filter = NULL; |
| 2863 | dvbdmxfeed->buffer = NULL; |
| 2864 | |
Andreas Oberritter | dad4a73 | 2005-09-09 13:02:26 -0700 | [diff] [blame] | 2865 | (*feed) = &dvbdmxfeed->feed.sec; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2866 | (*feed)->is_filtering = 0; |
| 2867 | (*feed)->parent = demux; |
| 2868 | (*feed)->priv = NULL; |
| 2869 | |
| 2870 | (*feed)->set = dmx_section_feed_set; |
| 2871 | (*feed)->allocate_filter = dmx_section_feed_allocate_filter; |
| 2872 | (*feed)->start_filtering = dmx_section_feed_start_filtering; |
| 2873 | (*feed)->stop_filtering = dmx_section_feed_stop_filtering; |
| 2874 | (*feed)->release_filter = dmx_section_feed_release_filter; |
Hamad Kadmany | 4f87794 | 2012-07-15 15:06:01 +0300 | [diff] [blame] | 2875 | (*feed)->data_ready_cb = dmx_section_feed_data_ready_cb; |
Hamad Kadmany | c853010 | 2012-07-23 11:43:09 +0300 | [diff] [blame] | 2876 | (*feed)->notify_data_read = NULL; |
Hamad Kadmany | 04e59fb | 2013-01-29 18:37:35 +0200 | [diff] [blame] | 2877 | (*feed)->set_secure_mode = dmx_section_set_secure_mode; |
Gilad Broner | a81f42e | 2013-04-07 16:38:47 +0300 | [diff] [blame] | 2878 | (*feed)->oob_command = dvbdmx_section_feed_oob_cmd; |
Hamad Kadmany | d0abf31 | 2013-05-13 18:56:06 +0300 | [diff] [blame] | 2879 | (*feed)->get_scrambling_bits = dvbdmx_section_get_scrambling_bits; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2880 | |
Ingo Molnar | 3593cab | 2006-02-07 06:49:14 -0200 | [diff] [blame] | 2881 | mutex_unlock(&dvbdmx->mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2882 | return 0; |
| 2883 | } |
| 2884 | |
| 2885 | static int dvbdmx_release_section_feed(struct dmx_demux *demux, |
| 2886 | struct dmx_section_feed *feed) |
| 2887 | { |
Andreas Oberritter | dad4a73 | 2005-09-09 13:02:26 -0700 | [diff] [blame] | 2888 | struct dvb_demux_feed *dvbdmxfeed = (struct dvb_demux_feed *)feed; |
| 2889 | struct dvb_demux *dvbdmx = (struct dvb_demux *)demux; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2890 | |
Simon Arlott | c278850 | 2007-03-10 06:21:25 -0300 | [diff] [blame] | 2891 | mutex_lock(&dvbdmx->mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2892 | |
Andreas Oberritter | dad4a73 | 2005-09-09 13:02:26 -0700 | [diff] [blame] | 2893 | if (dvbdmxfeed->state == DMX_STATE_FREE) { |
Ingo Molnar | 3593cab | 2006-02-07 06:49:14 -0200 | [diff] [blame] | 2894 | mutex_unlock(&dvbdmx->mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2895 | return -EINVAL; |
| 2896 | } |
| 2897 | #ifndef NOBUFS |
| 2898 | vfree(dvbdmxfeed->buffer); |
Andreas Oberritter | dad4a73 | 2005-09-09 13:02:26 -0700 | [diff] [blame] | 2899 | dvbdmxfeed->buffer = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2900 | #endif |
Andreas Oberritter | dad4a73 | 2005-09-09 13:02:26 -0700 | [diff] [blame] | 2901 | dvbdmxfeed->state = DMX_STATE_FREE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2902 | |
| 2903 | dvb_demux_feed_del(dvbdmxfeed); |
| 2904 | |
| 2905 | dvbdmxfeed->pid = 0xffff; |
| 2906 | |
Ingo Molnar | 3593cab | 2006-02-07 06:49:14 -0200 | [diff] [blame] | 2907 | mutex_unlock(&dvbdmx->mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2908 | return 0; |
| 2909 | } |
| 2910 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2911 | /****************************************************************************** |
| 2912 | * dvb_demux kernel data API calls |
| 2913 | ******************************************************************************/ |
| 2914 | |
| 2915 | static int dvbdmx_open(struct dmx_demux *demux) |
| 2916 | { |
Andreas Oberritter | dad4a73 | 2005-09-09 13:02:26 -0700 | [diff] [blame] | 2917 | struct dvb_demux *dvbdemux = (struct dvb_demux *)demux; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2918 | |
| 2919 | if (dvbdemux->users >= MAX_DVB_DEMUX_USERS) |
| 2920 | return -EUSERS; |
| 2921 | |
| 2922 | dvbdemux->users++; |
| 2923 | return 0; |
| 2924 | } |
| 2925 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2926 | static int dvbdmx_close(struct dmx_demux *demux) |
| 2927 | { |
Andreas Oberritter | dad4a73 | 2005-09-09 13:02:26 -0700 | [diff] [blame] | 2928 | struct dvb_demux *dvbdemux = (struct dvb_demux *)demux; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2929 | |
| 2930 | if (dvbdemux->users == 0) |
| 2931 | return -ENODEV; |
| 2932 | |
| 2933 | dvbdemux->users--; |
| 2934 | //FIXME: release any unneeded resources if users==0 |
| 2935 | return 0; |
| 2936 | } |
| 2937 | |
Hamad Kadmany | 32cb982 | 2012-05-10 08:47:44 +0300 | [diff] [blame] | 2938 | static int dvbdmx_write(struct dmx_demux *demux, const char *buf, size_t count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2939 | { |
Andreas Oberritter | dad4a73 | 2005-09-09 13:02:26 -0700 | [diff] [blame] | 2940 | struct dvb_demux *dvbdemux = (struct dvb_demux *)demux; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2941 | |
| 2942 | if ((!demux->frontend) || (demux->frontend->source != DMX_MEMORY_FE)) |
| 2943 | return -EINVAL; |
| 2944 | |
Hamad Kadmany | 32cb982 | 2012-05-10 08:47:44 +0300 | [diff] [blame] | 2945 | dvb_dmx_swfilter_format(dvbdemux, buf, count, dvbdemux->tsp_format); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2946 | |
| 2947 | if (signal_pending(current)) |
| 2948 | return -EINTR; |
| 2949 | return count; |
| 2950 | } |
| 2951 | |
Hamad Kadmany | 32cb982 | 2012-05-10 08:47:44 +0300 | [diff] [blame] | 2952 | static int dvbdmx_write_cancel(struct dmx_demux *demux) |
| 2953 | { |
| 2954 | struct dvb_demux *dvbdmx = (struct dvb_demux *)demux; |
| 2955 | |
| 2956 | spin_lock_irq(&dvbdmx->lock); |
| 2957 | |
| 2958 | /* cancel any pending wait for decoder's buffers */ |
| 2959 | dvbdmx->sw_filter_abort = 1; |
| 2960 | dvbdmx->tsbufp = 0; |
| 2961 | dvb_dmx_configure_decoder_fullness(dvbdmx, 0); |
| 2962 | |
| 2963 | spin_unlock_irq(&dvbdmx->lock); |
| 2964 | |
| 2965 | return 0; |
| 2966 | } |
| 2967 | |
| 2968 | static int dvbdmx_set_playback_mode(struct dmx_demux *demux, |
| 2969 | enum dmx_playback_mode_t mode, |
| 2970 | dmx_ts_fullness ts_fullness_callback, |
| 2971 | dmx_section_fullness sec_fullness_callback) |
| 2972 | { |
| 2973 | struct dvb_demux *dvbdmx = (struct dvb_demux *)demux; |
| 2974 | |
| 2975 | mutex_lock(&dvbdmx->mutex); |
| 2976 | |
| 2977 | dvbdmx->playback_mode = mode; |
| 2978 | dvbdmx->buffer_ctrl.ts = ts_fullness_callback; |
| 2979 | dvbdmx->buffer_ctrl.sec = sec_fullness_callback; |
| 2980 | |
| 2981 | mutex_unlock(&dvbdmx->mutex); |
| 2982 | |
| 2983 | return 0; |
| 2984 | } |
| 2985 | |
Andreas Oberritter | dad4a73 | 2005-09-09 13:02:26 -0700 | [diff] [blame] | 2986 | static int dvbdmx_add_frontend(struct dmx_demux *demux, |
| 2987 | struct dmx_frontend *frontend) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2988 | { |
Andreas Oberritter | dad4a73 | 2005-09-09 13:02:26 -0700 | [diff] [blame] | 2989 | struct dvb_demux *dvbdemux = (struct dvb_demux *)demux; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2990 | struct list_head *head = &dvbdemux->frontend_list; |
| 2991 | |
| 2992 | list_add(&(frontend->connectivity_list), head); |
| 2993 | |
| 2994 | return 0; |
| 2995 | } |
| 2996 | |
Andreas Oberritter | dad4a73 | 2005-09-09 13:02:26 -0700 | [diff] [blame] | 2997 | static int dvbdmx_remove_frontend(struct dmx_demux *demux, |
| 2998 | struct dmx_frontend *frontend) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2999 | { |
Andreas Oberritter | dad4a73 | 2005-09-09 13:02:26 -0700 | [diff] [blame] | 3000 | struct dvb_demux *dvbdemux = (struct dvb_demux *)demux; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3001 | struct list_head *pos, *n, *head = &dvbdemux->frontend_list; |
| 3002 | |
Andreas Oberritter | dad4a73 | 2005-09-09 13:02:26 -0700 | [diff] [blame] | 3003 | list_for_each_safe(pos, n, head) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3004 | if (DMX_FE_ENTRY(pos) == frontend) { |
| 3005 | list_del(pos); |
| 3006 | return 0; |
| 3007 | } |
| 3008 | } |
| 3009 | |
| 3010 | return -ENODEV; |
| 3011 | } |
| 3012 | |
Andreas Oberritter | dad4a73 | 2005-09-09 13:02:26 -0700 | [diff] [blame] | 3013 | static struct list_head *dvbdmx_get_frontends(struct dmx_demux *demux) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3014 | { |
Andreas Oberritter | dad4a73 | 2005-09-09 13:02:26 -0700 | [diff] [blame] | 3015 | struct dvb_demux *dvbdemux = (struct dvb_demux *)demux; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3016 | |
| 3017 | if (list_empty(&dvbdemux->frontend_list)) |
| 3018 | return NULL; |
Andreas Oberritter | dad4a73 | 2005-09-09 13:02:26 -0700 | [diff] [blame] | 3019 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3020 | return &dvbdemux->frontend_list; |
| 3021 | } |
| 3022 | |
Andreas Oberritter | dad4a73 | 2005-09-09 13:02:26 -0700 | [diff] [blame] | 3023 | static int dvbdmx_connect_frontend(struct dmx_demux *demux, |
| 3024 | struct dmx_frontend *frontend) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3025 | { |
Andreas Oberritter | dad4a73 | 2005-09-09 13:02:26 -0700 | [diff] [blame] | 3026 | struct dvb_demux *dvbdemux = (struct dvb_demux *)demux; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3027 | |
| 3028 | if (demux->frontend) |
| 3029 | return -EINVAL; |
| 3030 | |
Simon Arlott | c278850 | 2007-03-10 06:21:25 -0300 | [diff] [blame] | 3031 | mutex_lock(&dvbdemux->mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3032 | |
| 3033 | demux->frontend = frontend; |
Ingo Molnar | 3593cab | 2006-02-07 06:49:14 -0200 | [diff] [blame] | 3034 | mutex_unlock(&dvbdemux->mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3035 | return 0; |
| 3036 | } |
| 3037 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3038 | static int dvbdmx_disconnect_frontend(struct dmx_demux *demux) |
| 3039 | { |
Andreas Oberritter | dad4a73 | 2005-09-09 13:02:26 -0700 | [diff] [blame] | 3040 | struct dvb_demux *dvbdemux = (struct dvb_demux *)demux; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3041 | |
Simon Arlott | c278850 | 2007-03-10 06:21:25 -0300 | [diff] [blame] | 3042 | mutex_lock(&dvbdemux->mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3043 | |
| 3044 | demux->frontend = NULL; |
Ingo Molnar | 3593cab | 2006-02-07 06:49:14 -0200 | [diff] [blame] | 3045 | mutex_unlock(&dvbdemux->mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3046 | return 0; |
| 3047 | } |
| 3048 | |
Andreas Oberritter | dad4a73 | 2005-09-09 13:02:26 -0700 | [diff] [blame] | 3049 | static int dvbdmx_get_pes_pids(struct dmx_demux *demux, u16 * pids) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3050 | { |
Andreas Oberritter | dad4a73 | 2005-09-09 13:02:26 -0700 | [diff] [blame] | 3051 | struct dvb_demux *dvbdemux = (struct dvb_demux *)demux; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3052 | |
Andreas Oberritter | dad4a73 | 2005-09-09 13:02:26 -0700 | [diff] [blame] | 3053 | memcpy(pids, dvbdemux->pids, 5 * sizeof(u16)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3054 | return 0; |
| 3055 | } |
| 3056 | |
Gilad Broner | a81f42e | 2013-04-07 16:38:47 +0300 | [diff] [blame] | 3057 | static int dvbdmx_get_tsp_size(struct dmx_demux *demux) |
| 3058 | { |
| 3059 | int tsp_size; |
| 3060 | struct dvb_demux *dvbdemux = (struct dvb_demux *)demux; |
| 3061 | |
| 3062 | mutex_lock(&dvbdemux->mutex); |
| 3063 | tsp_size = dvbdemux->ts_packet_size; |
| 3064 | mutex_unlock(&dvbdemux->mutex); |
| 3065 | |
| 3066 | return tsp_size; |
| 3067 | } |
| 3068 | |
Hamad Kadmany | 32cb982 | 2012-05-10 08:47:44 +0300 | [diff] [blame] | 3069 | static int dvbdmx_set_tsp_format( |
| 3070 | struct dmx_demux *demux, |
| 3071 | enum dmx_tsp_format_t tsp_format) |
| 3072 | { |
| 3073 | struct dvb_demux *dvbdemux = (struct dvb_demux *)demux; |
| 3074 | |
| 3075 | if ((tsp_format > DMX_TSP_FORMAT_204) || |
| 3076 | (tsp_format < DMX_TSP_FORMAT_188)) |
| 3077 | return -EINVAL; |
| 3078 | |
| 3079 | mutex_lock(&dvbdemux->mutex); |
| 3080 | |
| 3081 | dvbdemux->tsp_format = tsp_format; |
Hamad Kadmany | 168203b | 2013-01-28 15:22:46 +0200 | [diff] [blame] | 3082 | switch (tsp_format) { |
| 3083 | case DMX_TSP_FORMAT_188: |
| 3084 | dvbdemux->ts_packet_size = 188; |
| 3085 | break; |
| 3086 | case DMX_TSP_FORMAT_192_TAIL: |
| 3087 | case DMX_TSP_FORMAT_192_HEAD: |
| 3088 | dvbdemux->ts_packet_size = 192; |
| 3089 | break; |
| 3090 | case DMX_TSP_FORMAT_204: |
| 3091 | dvbdemux->ts_packet_size = 204; |
| 3092 | break; |
| 3093 | } |
| 3094 | |
Hamad Kadmany | 32cb982 | 2012-05-10 08:47:44 +0300 | [diff] [blame] | 3095 | mutex_unlock(&dvbdemux->mutex); |
| 3096 | return 0; |
| 3097 | } |
| 3098 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3099 | int dvb_dmx_init(struct dvb_demux *dvbdemux) |
| 3100 | { |
Andreas Oberritter | 9365346 | 2005-09-09 13:02:23 -0700 | [diff] [blame] | 3101 | int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3102 | struct dmx_demux *dmx = &dvbdemux->dmx; |
| 3103 | |
Abylay Ospan | 0d83463 | 2009-06-06 09:31:34 -0300 | [diff] [blame] | 3104 | dvbdemux->cnt_storage = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3105 | dvbdemux->users = 0; |
Andreas Oberritter | dad4a73 | 2005-09-09 13:02:26 -0700 | [diff] [blame] | 3106 | dvbdemux->filter = vmalloc(dvbdemux->filternum * sizeof(struct dvb_demux_filter)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3107 | |
| 3108 | if (!dvbdemux->filter) |
| 3109 | return -ENOMEM; |
| 3110 | |
Andreas Oberritter | dad4a73 | 2005-09-09 13:02:26 -0700 | [diff] [blame] | 3111 | dvbdemux->feed = vmalloc(dvbdemux->feednum * sizeof(struct dvb_demux_feed)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3112 | if (!dvbdemux->feed) { |
| 3113 | vfree(dvbdemux->filter); |
Mauro Carvalho Chehab | adefdce | 2010-02-01 10:35:22 -0300 | [diff] [blame] | 3114 | dvbdemux->filter = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3115 | return -ENOMEM; |
| 3116 | } |
Hamad Kadmany | 32cb982 | 2012-05-10 08:47:44 +0300 | [diff] [blame] | 3117 | |
Hamad Kadmany | e1dba20 | 2013-04-10 18:37:25 +0300 | [diff] [blame] | 3118 | dvbdemux->rec_info_pool = vmalloc(dvbdemux->feednum * |
| 3119 | sizeof(struct dvb_demux_rec_info)); |
| 3120 | if (!dvbdemux->rec_info_pool) { |
| 3121 | vfree(dvbdemux->feed); |
| 3122 | vfree(dvbdemux->filter); |
| 3123 | dvbdemux->feed = NULL; |
| 3124 | dvbdemux->filter = NULL; |
| 3125 | return -ENOMEM; |
| 3126 | } |
| 3127 | |
Hamad Kadmany | 32cb982 | 2012-05-10 08:47:44 +0300 | [diff] [blame] | 3128 | dvbdemux->total_process_time = 0; |
| 3129 | dvbdemux->total_crc_time = 0; |
| 3130 | snprintf(dvbdemux->alias, |
| 3131 | MAX_DVB_DEMUX_NAME_LEN, |
| 3132 | "demux%d", |
| 3133 | dvb_demux_index++); |
| 3134 | |
Hamad Kadmany | 4b5b730 | 2012-11-15 09:01:41 +0200 | [diff] [blame] | 3135 | dvbdemux->dmx.debugfs_demux_dir = |
| 3136 | debugfs_create_dir(dvbdemux->alias, NULL); |
Hamad Kadmany | 32cb982 | 2012-05-10 08:47:44 +0300 | [diff] [blame] | 3137 | |
Hamad Kadmany | 4b5b730 | 2012-11-15 09:01:41 +0200 | [diff] [blame] | 3138 | if (dvbdemux->dmx.debugfs_demux_dir != NULL) { |
Hamad Kadmany | 32cb982 | 2012-05-10 08:47:44 +0300 | [diff] [blame] | 3139 | debugfs_create_u32( |
| 3140 | "total_processing_time", |
Hamad Kadmany | a1dde82 | 2013-03-28 08:23:26 +0200 | [diff] [blame] | 3141 | S_IRUGO | S_IWUSR | S_IWGRP, |
Hamad Kadmany | 4b5b730 | 2012-11-15 09:01:41 +0200 | [diff] [blame] | 3142 | dvbdemux->dmx.debugfs_demux_dir, |
Hamad Kadmany | 32cb982 | 2012-05-10 08:47:44 +0300 | [diff] [blame] | 3143 | &dvbdemux->total_process_time); |
| 3144 | |
| 3145 | debugfs_create_u32( |
| 3146 | "total_crc_time", |
Hamad Kadmany | a1dde82 | 2013-03-28 08:23:26 +0200 | [diff] [blame] | 3147 | S_IRUGO | S_IWUSR | S_IWGRP, |
Hamad Kadmany | 4b5b730 | 2012-11-15 09:01:41 +0200 | [diff] [blame] | 3148 | dvbdemux->dmx.debugfs_demux_dir, |
Hamad Kadmany | 32cb982 | 2012-05-10 08:47:44 +0300 | [diff] [blame] | 3149 | &dvbdemux->total_crc_time); |
| 3150 | } |
| 3151 | |
Andreas Oberritter | dad4a73 | 2005-09-09 13:02:26 -0700 | [diff] [blame] | 3152 | for (i = 0; i < dvbdemux->filternum; i++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3153 | dvbdemux->filter[i].state = DMX_STATE_FREE; |
| 3154 | dvbdemux->filter[i].index = i; |
| 3155 | } |
Hamad Kadmany | e1dba20 | 2013-04-10 18:37:25 +0300 | [diff] [blame] | 3156 | |
Andreas Oberritter | dad4a73 | 2005-09-09 13:02:26 -0700 | [diff] [blame] | 3157 | for (i = 0; i < dvbdemux->feednum; i++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3158 | dvbdemux->feed[i].state = DMX_STATE_FREE; |
| 3159 | dvbdemux->feed[i].index = i; |
Hamad Kadmany | e1dba20 | 2013-04-10 18:37:25 +0300 | [diff] [blame] | 3160 | |
| 3161 | dvbdemux->rec_info_pool[i].ref_count = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3162 | } |
Andreas Oberritter | db574d7 | 2005-09-09 13:02:26 -0700 | [diff] [blame] | 3163 | |
Abylay Ospan | ab6a21f | 2010-03-06 14:58:01 -0300 | [diff] [blame] | 3164 | dvbdemux->cnt_storage = vmalloc(MAX_PID + 1); |
| 3165 | if (!dvbdemux->cnt_storage) |
| 3166 | 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] | 3167 | |
Andreas Oberritter | db574d7 | 2005-09-09 13:02:26 -0700 | [diff] [blame] | 3168 | INIT_LIST_HEAD(&dvbdemux->frontend_list); |
| 3169 | |
Andreas Oberritter | dad4a73 | 2005-09-09 13:02:26 -0700 | [diff] [blame] | 3170 | for (i = 0; i < DMX_TS_PES_OTHER; i++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3171 | dvbdemux->pesfilter[i] = NULL; |
| 3172 | dvbdemux->pids[i] = 0xffff; |
| 3173 | } |
| 3174 | |
| 3175 | INIT_LIST_HEAD(&dvbdemux->feed_list); |
| 3176 | |
| 3177 | dvbdemux->playing = 0; |
| 3178 | dvbdemux->recording = 0; |
| 3179 | dvbdemux->tsbufp = 0; |
| 3180 | |
Hamad Kadmany | 32cb982 | 2012-05-10 08:47:44 +0300 | [diff] [blame] | 3181 | dvbdemux->tsp_format = DMX_TSP_FORMAT_188; |
Hamad Kadmany | 168203b | 2013-01-28 15:22:46 +0200 | [diff] [blame] | 3182 | dvbdemux->ts_packet_size = 188; |
Hamad Kadmany | 32cb982 | 2012-05-10 08:47:44 +0300 | [diff] [blame] | 3183 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3184 | if (!dvbdemux->check_crc32) |
| 3185 | dvbdemux->check_crc32 = dvb_dmx_crc32; |
| 3186 | |
Andreas Oberritter | dad4a73 | 2005-09-09 13:02:26 -0700 | [diff] [blame] | 3187 | if (!dvbdemux->memcopy) |
| 3188 | dvbdemux->memcopy = dvb_dmx_memcopy; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3189 | |
| 3190 | dmx->frontend = NULL; |
Andreas Oberritter | dad4a73 | 2005-09-09 13:02:26 -0700 | [diff] [blame] | 3191 | dmx->priv = dvbdemux; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3192 | dmx->open = dvbdmx_open; |
| 3193 | dmx->close = dvbdmx_close; |
| 3194 | dmx->write = dvbdmx_write; |
Hamad Kadmany | 32cb982 | 2012-05-10 08:47:44 +0300 | [diff] [blame] | 3195 | dmx->write_cancel = dvbdmx_write_cancel; |
| 3196 | dmx->set_playback_mode = dvbdmx_set_playback_mode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3197 | dmx->allocate_ts_feed = dvbdmx_allocate_ts_feed; |
| 3198 | dmx->release_ts_feed = dvbdmx_release_ts_feed; |
| 3199 | dmx->allocate_section_feed = dvbdmx_allocate_section_feed; |
| 3200 | dmx->release_section_feed = dvbdmx_release_section_feed; |
Hamad Kadmany | ec6202d | 2012-09-20 07:58:57 +0300 | [diff] [blame] | 3201 | dmx->map_buffer = NULL; |
| 3202 | dmx->unmap_buffer = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3203 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3204 | dmx->add_frontend = dvbdmx_add_frontend; |
| 3205 | dmx->remove_frontend = dvbdmx_remove_frontend; |
| 3206 | dmx->get_frontends = dvbdmx_get_frontends; |
| 3207 | dmx->connect_frontend = dvbdmx_connect_frontend; |
| 3208 | dmx->disconnect_frontend = dvbdmx_disconnect_frontend; |
| 3209 | dmx->get_pes_pids = dvbdmx_get_pes_pids; |
| 3210 | |
Hamad Kadmany | 32cb982 | 2012-05-10 08:47:44 +0300 | [diff] [blame] | 3211 | dmx->set_tsp_format = dvbdmx_set_tsp_format; |
Gilad Broner | a81f42e | 2013-04-07 16:38:47 +0300 | [diff] [blame] | 3212 | dmx->get_tsp_size = dvbdmx_get_tsp_size; |
Hamad Kadmany | 32cb982 | 2012-05-10 08:47:44 +0300 | [diff] [blame] | 3213 | |
Ingo Molnar | 3593cab | 2006-02-07 06:49:14 -0200 | [diff] [blame] | 3214 | mutex_init(&dvbdemux->mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3215 | spin_lock_init(&dvbdemux->lock); |
| 3216 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3217 | return 0; |
| 3218 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3219 | |
Andreas Oberritter | dad4a73 | 2005-09-09 13:02:26 -0700 | [diff] [blame] | 3220 | EXPORT_SYMBOL(dvb_dmx_init); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3221 | |
Andreas Oberritter | 9365346 | 2005-09-09 13:02:23 -0700 | [diff] [blame] | 3222 | void dvb_dmx_release(struct dvb_demux *dvbdemux) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3223 | { |
Hamad Kadmany | 4b5b730 | 2012-11-15 09:01:41 +0200 | [diff] [blame] | 3224 | if (dvbdemux->dmx.debugfs_demux_dir != NULL) |
| 3225 | debugfs_remove_recursive(dvbdemux->dmx.debugfs_demux_dir); |
Hamad Kadmany | 32cb982 | 2012-05-10 08:47:44 +0300 | [diff] [blame] | 3226 | |
Hamad Kadmany | 4b5b730 | 2012-11-15 09:01:41 +0200 | [diff] [blame] | 3227 | dvb_demux_index--; |
Abylay Ospan | 0d83463 | 2009-06-06 09:31:34 -0300 | [diff] [blame] | 3228 | vfree(dvbdemux->cnt_storage); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3229 | vfree(dvbdemux->filter); |
| 3230 | vfree(dvbdemux->feed); |
Hamad Kadmany | e1dba20 | 2013-04-10 18:37:25 +0300 | [diff] [blame] | 3231 | vfree(dvbdemux->rec_info_pool); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3232 | } |
Andreas Oberritter | dad4a73 | 2005-09-09 13:02:26 -0700 | [diff] [blame] | 3233 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3234 | EXPORT_SYMBOL(dvb_dmx_release); |