blob: a77064d6e2c490a1089102b435f0c7fda5a3974f [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * dmxdev.h
3 *
4 * Copyright (C) 2000 Ralph Metzler & Marcus Metzler
5 * for convergence integrated media GmbH
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public License
9 * as published by the Free Software Foundation; either version 2.1
10 * of the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
Linus Torvalds1da177e2005-04-16 15:20:36 -070017 */
18
19#ifndef _DMXDEV_H_
20#define _DMXDEV_H_
21
22#include <linux/types.h>
23#include <linux/spinlock.h>
24#include <linux/kernel.h>
Mauro Carvalho Chehabb2409b62012-10-19 07:29:17 -030025#include <linux/time.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070026#include <linux/timer.h>
27#include <linux/wait.h>
28#include <linux/fs.h>
29#include <linux/string.h>
Ingo Molnar3593cab2006-02-07 06:49:14 -020030#include <linux/mutex.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090031#include <linux/slab.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070032
33#include <linux/dvb/dmx.h>
34
35#include "dvbdev.h"
36#include "demux.h"
Andreas Oberritter34731df2006-03-14 17:31:01 -030037#include "dvb_ringbuffer.h"
Satendra Singh Thakur57868ac2017-12-18 22:35:53 -050038#include "dvb_vb2.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070039
Mauro Carvalho Chehabe7446382017-09-20 12:10:48 -040040/**
41 * enum dmxdev_type - type of demux filter type.
42 *
43 * @DMXDEV_TYPE_NONE: no filter set.
44 * @DMXDEV_TYPE_SEC: section filter.
45 * @DMXDEV_TYPE_PES: Program Elementary Stream (PES) filter.
46 */
Andreas Oberritterbbad7dc2006-03-10 15:21:58 -030047enum dmxdev_type {
Linus Torvalds1da177e2005-04-16 15:20:36 -070048 DMXDEV_TYPE_NONE,
49 DMXDEV_TYPE_SEC,
50 DMXDEV_TYPE_PES,
51};
52
Mauro Carvalho Chehabe7446382017-09-20 12:10:48 -040053/**
54 * enum dmxdev_state - state machine for the dmxdev.
55 *
56 * @DMXDEV_STATE_FREE: indicates that the filter is freed.
57 * @DMXDEV_STATE_ALLOCATED: indicates that the filter was allocated
58 * to be used.
59 * @DMXDEV_STATE_SET: indicates that the filter parameters are set.
60 * @DMXDEV_STATE_GO: indicates that the filter is running.
61 * @DMXDEV_STATE_DONE: indicates that a packet was already filtered
62 * and the filter is now disabled.
63 * Set only if %DMX_ONESHOT. See
64 * &dmx_sct_filter_params.
65 * @DMXDEV_STATE_TIMEDOUT: Indicates a timeout condition.
66 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070067enum dmxdev_state {
68 DMXDEV_STATE_FREE,
69 DMXDEV_STATE_ALLOCATED,
70 DMXDEV_STATE_SET,
71 DMXDEV_STATE_GO,
72 DMXDEV_STATE_DONE,
73 DMXDEV_STATE_TIMEDOUT
74};
75
Mauro Carvalho Chehabe7446382017-09-20 12:10:48 -040076/**
77 * struct dmxdev_feed - digital TV dmxdev feed
78 *
79 * @pid: Program ID to be filtered
80 * @ts: pointer to &struct dmx_ts_feed
81 * @next: &struct list_head pointing to the next feed.
82 */
83
Andreas Oberritter1cb662a2009-07-14 20:28:50 -030084struct dmxdev_feed {
85 u16 pid;
86 struct dmx_ts_feed *ts;
87 struct list_head next;
88};
89
Mauro Carvalho Chehabe7446382017-09-20 12:10:48 -040090/**
91 * struct dmxdev_filter - digital TV dmxdev filter
92 *
Mauro Carvalho Chehab3483d3a2017-09-26 16:46:16 -040093 * @filter: a union describing a dmxdev filter.
94 * Currently used only for section filters.
95 * @filter.sec: a &struct dmx_section_filter pointer.
96 * For section filter only.
97 * @feed: a union describing a dmxdev feed.
98 * Depending on the filter type, it can be either
99 * @feed.ts or @feed.sec.
100 * @feed.ts: a &struct list_head list.
101 * For TS and PES feeds.
102 * @feed.sec: a &struct dmx_section_feed pointer.
103 * For section feed only.
104 * @params: a union describing dmxdev filter parameters.
105 * Depending on the filter type, it can be either
106 * @params.sec or @params.pes.
107 * @params.sec: a &struct dmx_sct_filter_params embedded struct.
108 * For section filter only.
109 * @params.pes: a &struct dmx_pes_filter_params embedded struct.
110 * For PES filter only.
Mauro Carvalho Chehabe7446382017-09-20 12:10:48 -0400111 * @type: type of the dmxdev filter, as defined by &enum dmxdev_type.
112 * @state: state of the dmxdev filter, as defined by &enum dmxdev_state.
113 * @dev: pointer to &struct dmxdev.
114 * @buffer: an embedded &struct dvb_ringbuffer buffer.
115 * @mutex: protects the access to &struct dmxdev_filter.
116 * @timer: &struct timer_list embedded timer, used to check for
117 * feed timeouts.
118 * Only for section filter.
119 * @todo: index for the @secheader.
120 * Only for section filter.
121 * @secheader: buffer cache to parse the section header.
122 * Only for section filter.
123 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124struct dmxdev_filter {
Mauro Carvalho Chehabafd1a0c2005-12-12 00:37:27 -0800125 union {
126 struct dmx_section_filter *sec;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127 } filter;
128
Mauro Carvalho Chehabafd1a0c2005-12-12 00:37:27 -0800129 union {
Andreas Oberritter1cb662a2009-07-14 20:28:50 -0300130 /* list of TS and PES feeds (struct dmxdev_feed) */
131 struct list_head ts;
Mauro Carvalho Chehabafd1a0c2005-12-12 00:37:27 -0800132 struct dmx_section_feed *sec;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700133 } feed;
134
Mauro Carvalho Chehabafd1a0c2005-12-12 00:37:27 -0800135 union {
136 struct dmx_sct_filter_params sec;
137 struct dmx_pes_filter_params pes;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700138 } params;
139
Andreas Oberritterbbad7dc2006-03-10 15:21:58 -0300140 enum dmxdev_type type;
Mauro Carvalho Chehabafd1a0c2005-12-12 00:37:27 -0800141 enum dmxdev_state state;
142 struct dmxdev *dev;
Andreas Oberritter34731df2006-03-14 17:31:01 -0300143 struct dvb_ringbuffer buffer;
Satendra Singh Thakur57868ac2017-12-18 22:35:53 -0500144 struct dvb_vb2_ctx vb2_ctx;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145
Ingo Molnar3593cab2006-02-07 06:49:14 -0200146 struct mutex mutex;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147
Mauro Carvalho Chehabafd1a0c2005-12-12 00:37:27 -0800148 /* only for sections */
149 struct timer_list timer;
150 int todo;
151 u8 secheader[3];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700152};
153
Mauro Carvalho Chehabe7446382017-09-20 12:10:48 -0400154/**
155 * struct dmxdev - Describes a digital TV demux device.
156 *
157 * @dvbdev: pointer to &struct dvb_device associated with
158 * the demux device node.
159 * @dvr_dvbdev: pointer to &struct dvb_device associated with
160 * the dvr device node.
161 * @filter: pointer to &struct dmxdev_filter.
162 * @demux: pointer to &struct dmx_demux.
163 * @filternum: number of filters.
164 * @capabilities: demux capabilities as defined by &enum dmx_demux_caps.
165 * @exit: flag to indicate that the demux is being released.
166 * @dvr_orig_fe: pointer to &struct dmx_frontend.
167 * @dvr_buffer: embedded &struct dvb_ringbuffer for DVB output.
168 * @mutex: protects the usage of this structure.
169 * @lock: protects access to &dmxdev->filter->data.
170 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700171struct dmxdev {
172 struct dvb_device *dvbdev;
173 struct dvb_device *dvr_dvbdev;
174
Mauro Carvalho Chehabafd1a0c2005-12-12 00:37:27 -0800175 struct dmxdev_filter *filter;
Mauro Carvalho Chehabafd1a0c2005-12-12 00:37:27 -0800176 struct dmx_demux *demux;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700177
Mauro Carvalho Chehabafd1a0c2005-12-12 00:37:27 -0800178 int filternum;
179 int capabilities;
Markus Rechberger57861b42007-04-14 10:19:18 -0300180
181 unsigned int exit:1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700182#define DMXDEV_CAP_DUPLEX 1
Mauro Carvalho Chehabafd1a0c2005-12-12 00:37:27 -0800183 struct dmx_frontend *dvr_orig_fe;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700184
Andreas Oberritter34731df2006-03-14 17:31:01 -0300185 struct dvb_ringbuffer dvr_buffer;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700186#define DVR_BUFFER_SIZE (10*188*1024)
187
Satendra Singh Thakur57868ac2017-12-18 22:35:53 -0500188 struct dvb_vb2_ctx dvr_vb2_ctx;
189
Ingo Molnar3593cab2006-02-07 06:49:14 -0200190 struct mutex mutex;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700191 spinlock_t lock;
192};
193
Mauro Carvalho Chehabe7446382017-09-20 12:10:48 -0400194/**
195 * dvb_dmxdev_init - initializes a digital TV demux and registers both demux
196 * and DVR devices.
197 *
198 * @dmxdev: pointer to &struct dmxdev.
199 * @adap: pointer to &struct dvb_adapter.
200 */
201int dvb_dmxdev_init(struct dmxdev *dmxdev, struct dvb_adapter *adap);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700202
Mauro Carvalho Chehabe7446382017-09-20 12:10:48 -0400203/**
204 * dvb_dmxdev_release - releases a digital TV demux and unregisters it.
205 *
206 * @dmxdev: pointer to &struct dmxdev.
207 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700208void dvb_dmxdev_release(struct dmxdev *dmxdev);
209
210#endif /* _DMXDEV_H_ */