4 * Copyright (c) 2002 Convergence GmbH
7 * Copyright (c) 2000 Nokia Research Center
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.
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.
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.
29 #include <linux/types.h>
30 #include <linux/errno.h>
31 #include <linux/list.h>
32 #include <linux/time.h>
33 #include <linux/dvb/dmx.h>
35 /*--------------------------------------------------------------------------*/
36 /* Common definitions */
37 /*--------------------------------------------------------------------------*/
40 * DMX_MAX_FILTER_SIZE: Maximum length (in bytes) of a section/PES filter.
43 #ifndef DMX_MAX_FILTER_SIZE
44 #define DMX_MAX_FILTER_SIZE 18
48 * DMX_MAX_SECFEED_SIZE: Maximum length (in bytes) of a private section feed filter.
51 #ifndef DMX_MAX_SECTION_SIZE
52 #define DMX_MAX_SECTION_SIZE 4096
54 #ifndef DMX_MAX_SECFEED_SIZE
55 #define DMX_MAX_SECFEED_SIZE (DMX_MAX_SECTION_SIZE + 188)
60 * enum dmx_success: Success codes for the Demux Callback API.
64 DMX_OK = 0, /* Received Ok */
65 DMX_LENGTH_ERROR, /* Incorrect length */
66 DMX_OVERRUN_ERROR, /* Receiver ring buffer overrun */
67 DMX_CRC_ERROR, /* Incorrect CRC */
68 DMX_FRAME_ERROR, /* Frame alignment error */
69 DMX_FIFO_ERROR, /* Receiver FIFO overrun */
70 DMX_MISSED_ERROR /* Receiver missed packet */
73 /*--------------------------------------------------------------------------*/
74 /* TS packet reception */
75 /*--------------------------------------------------------------------------*/
77 /* TS filter type for set() */
79 #define TS_PACKET 1 /* send TS packets (188 bytes) to callback (default) */
80 #define TS_PAYLOAD_ONLY 2 /* in case TS_PACKET is set, only send the TS
81 payload (<=184 bytes per packet) to callback */
82 #define TS_DECODER 4 /* send stream to built-in decoder (if present) */
83 #define TS_DEMUX 8 /* in case TS_PACKET is set, send the TS to
84 the demux device, not to the dvr device */
87 int is_filtering; /* Set to non-zero when filtering in progress */
88 struct dmx_demux *parent; /* Back-pointer */
89 void *priv; /* Pointer to private data of the API client */
90 int (*set) (struct dmx_ts_feed *feed,
93 enum dmx_ts_pes pes_type,
94 size_t circular_buffer_size,
95 struct timespec timeout);
96 int (*start_filtering) (struct dmx_ts_feed* feed);
97 int (*stop_filtering) (struct dmx_ts_feed* feed);
100 /*--------------------------------------------------------------------------*/
101 /* Section reception */
102 /*--------------------------------------------------------------------------*/
104 struct dmx_section_filter {
105 u8 filter_value [DMX_MAX_FILTER_SIZE];
106 u8 filter_mask [DMX_MAX_FILTER_SIZE];
107 u8 filter_mode [DMX_MAX_FILTER_SIZE];
108 struct dmx_section_feed* parent; /* Back-pointer */
109 void* priv; /* Pointer to private data of the API client */
112 struct dmx_section_feed {
113 int is_filtering; /* Set to non-zero when filtering in progress */
114 struct dmx_demux* parent; /* Back-pointer */
115 void* priv; /* Pointer to private data of the API client */
121 u8 secbuf_base[DMX_MAX_SECFEED_SIZE];
122 u16 secbufp, seclen, tsfeedp;
124 int (*set) (struct dmx_section_feed* feed,
126 size_t circular_buffer_size,
128 int (*allocate_filter) (struct dmx_section_feed* feed,
129 struct dmx_section_filter** filter);
130 int (*release_filter) (struct dmx_section_feed* feed,
131 struct dmx_section_filter* filter);
132 int (*start_filtering) (struct dmx_section_feed* feed);
133 int (*stop_filtering) (struct dmx_section_feed* feed);
136 /*--------------------------------------------------------------------------*/
137 /* Callback functions */
138 /*--------------------------------------------------------------------------*/
140 typedef int (*dmx_ts_cb) ( const u8 * buffer1,
141 size_t buffer1_length,
143 size_t buffer2_length,
144 struct dmx_ts_feed* source,
145 enum dmx_success success);
147 typedef int (*dmx_section_cb) ( const u8 * buffer1,
151 struct dmx_section_filter * source,
152 enum dmx_success success);
154 /*--------------------------------------------------------------------------*/
156 /*--------------------------------------------------------------------------*/
158 enum dmx_frontend_source {
164 DMX_STREAM_0, /* external stream input, e.g. LVDS */
170 struct dmx_frontend {
171 struct list_head connectivity_list; /* List of front-ends that can
172 be connected to a particular
174 enum dmx_frontend_source source;
177 /*--------------------------------------------------------------------------*/
178 /* MPEG-2 TS Demux */
179 /*--------------------------------------------------------------------------*/
182 * Flags OR'ed in the capabilities field of struct dmx_demux.
185 #define DMX_TS_FILTERING 1
186 #define DMX_PES_FILTERING 2
187 #define DMX_SECTION_FILTERING 4
188 #define DMX_MEMORY_BASED_FILTERING 8 /* write() available */
189 #define DMX_CRC_CHECKING 16
190 #define DMX_TS_DESCRAMBLING 32
193 * Demux resource type identifier.
197 * DMX_FE_ENTRY(): Casts elements in the list of registered
198 * front-ends from the generic type struct list_head
199 * to the type * struct dmx_frontend
203 #define DMX_FE_ENTRY(list) list_entry(list, struct dmx_frontend, connectivity_list)
206 * struct dmx_demux - Structure that contains the demux capabilities and
209 * @capabilities: Bitfield of capability flags
211 * @frontend: Front-end connected to the demux
213 * @priv: Pointer to private data of the API client
215 * @open: This function reserves the demux for use by the caller and, if
216 * necessary, initializes the demux. When the demux is no longer needed,
217 * the function @close should be called. It should be possible for
218 * multiple clients to access the demux at the same time. Thus, the
219 * function implementation should increment the demux usage count when
220 * @open is called and decrement it when @close is called.
221 * The @demux function parameter contains a pointer to the demux API and
225 * -EUSERS, if maximum usage count was reached;
226 * -EINVAL, on bad parameter.
228 * @close: This function reserves the demux for use by the caller and, if
229 * necessary, initializes the demux. When the demux is no longer needed,
230 * the function @close should be called. It should be possible for
231 * multiple clients to access the demux at the same time. Thus, the
232 * function implementation should increment the demux usage count when
233 * @open is called and decrement it when @close is called.
234 * The @demux function parameter contains a pointer to the demux API and
238 * -ENODEV, if demux was not in use (e. g. no users);
239 * -EINVAL, on bad parameter.
241 * @write: This function provides the demux driver with a memory buffer
242 * containing TS packets. Instead of receiving TS packets from the DVB
243 * front-end, the demux driver software will read packets from memory.
244 * Any clients of this demux with active TS, PES or Section filters will
245 * receive filtered data via the Demux callback API (see 0). The function
246 * returns when all the data in the buffer has been consumed by the demux.
247 * Demux hardware typically cannot read TS from memory. If this is the
248 * case, memory-based filtering has to be implemented entirely in software.
249 * The @demux function parameter contains a pointer to the demux API and
251 * The @buf function parameter contains a pointer to the TS data in
252 * kernel-space memory.
253 * The @count function parameter contains the length of the TS data.
256 * -ERESTARTSYS, if mutex lock was interrupted;
257 * -EINTR, if a signal handling is pending;
258 * -ENODEV, if demux was removed;
259 * -EINVAL, on bad parameter.
261 * @allocate_ts_feed: Allocates a new TS feed, which is used to filter the TS
262 * packets carrying a certain PID. The TS feed normally corresponds to a
263 * hardware PID filter on the demux chip.
264 * The @demux function parameter contains a pointer to the demux API and
266 * The @feed function parameter contains a pointer to the TS feed API and
268 * The @callback function parameter contains a pointer to the callback
269 * function for passing received TS packet.
272 * -ERESTARTSYS, if mutex lock was interrupted;
273 * -EBUSY, if no more TS feeds is available;
274 * -EINVAL, on bad parameter.
276 * @release_ts_feed: Releases the resources allocated with @allocate_ts_feed.
277 * Any filtering in progress on the TS feed should be stopped before
278 * calling this function.
279 * The @demux function parameter contains a pointer to the demux API and
281 * The @feed function parameter contains a pointer to the TS feed API and
285 * -EINVAL on bad parameter.
287 * @allocate_section_feed: Allocates a new section feed, i.e. a demux resource
288 * for filtering and receiving sections. On platforms with hardware
289 * support for section filtering, a section feed is directly mapped to
290 * the demux HW. On other platforms, TS packets are first PID filtered in
291 * hardware and a hardware section filter then emulated in software. The
292 * caller obtains an API pointer of type dmx_section_feed_t as an out
293 * parameter. Using this API the caller can set filtering parameters and
294 * start receiving sections.
295 * The @demux function parameter contains a pointer to the demux API and
297 * The @feed function parameter contains a pointer to the TS feed API and
299 * The @callback function parameter contains a pointer to the callback
300 * function for passing received TS packet.
303 * -EBUSY, if no more TS feeds is available;
304 * -EINVAL, on bad parameter.
306 * @release_section_feed: Releases the resources allocated with
307 * @allocate_section_feed, including allocated filters. Any filtering in
308 * progress on the section feed should be stopped before calling this
310 * The @demux function parameter contains a pointer to the demux API and
312 * The @feed function parameter contains a pointer to the TS feed API and
316 * -EINVAL, on bad parameter.
318 * @add_frontend: Registers a connectivity between a demux and a front-end,
319 * i.e., indicates that the demux can be connected via a call to
320 * @connect_frontend to use the given front-end as a TS source. The
321 * client of this function has to allocate dynamic or static memory for
322 * the frontend structure and initialize its fields before calling this
323 * function. This function is normally called during the driver
324 * initialization. The caller must not free the memory of the frontend
325 * struct before successfully calling @remove_frontend.
326 * The @demux function parameter contains a pointer to the demux API and
328 * The @frontend function parameter contains a pointer to the front-end
332 * -EINVAL, on bad parameter.
334 * @remove_frontend: Indicates that the given front-end, registered by a call
335 * to @add_frontend, can no longer be connected as a TS source by this
336 * demux. The function should be called when a front-end driver or a demux
337 * driver is removed from the system. If the front-end is in use, the
338 * function fails with the return value of -EBUSY. After successfully
339 * calling this function, the caller can free the memory of the frontend
340 * struct if it was dynamically allocated before the @add_frontend
342 * The @demux function parameter contains a pointer to the demux API and
344 * The @frontend function parameter contains a pointer to the front-end
348 * -ENODEV, if the front-end was not found,
349 * -EINVAL, on bad parameter.
351 * @get_frontends: Provides the APIs of the front-ends that have been
352 * registered for this demux. Any of the front-ends obtained with this
353 * call can be used as a parameter for @connect_frontend. The include
354 * file demux.h contains the macro DMX_FE_ENTRY() for converting an
355 * element of the generic type struct &list_head * to the type
356 * struct &dmx_frontend *. The caller must not free the memory of any of
357 * the elements obtained via this function call.
358 * The @demux function parameter contains a pointer to the demux API and
360 * It returns a struct list_head pointer to the list of front-end
361 * interfaces, or NULL in the case of an empty list.
363 * @connect_frontend: Connects the TS output of the front-end to the input of
364 * the demux. A demux can only be connected to a front-end registered to
365 * the demux with the function @add_frontend. It may or may not be
366 * possible to connect multiple demuxes to the same front-end, depending
367 * on the capabilities of the HW platform. When not used, the front-end
368 * should be released by calling @disconnect_frontend.
369 * The @demux function parameter contains a pointer to the demux API and
371 * The @frontend function parameter contains a pointer to the front-end
375 * -EINVAL, on bad parameter.
377 * @disconnect_frontend: Disconnects the demux and a front-end previously
378 * connected by a @connect_frontend call.
379 * The @demux function parameter contains a pointer to the demux API and
383 * -EINVAL on bad parameter.
388 struct dmx_frontend* frontend;
390 int (*open) (struct dmx_demux* demux);
391 int (*close) (struct dmx_demux* demux);
392 int (*write) (struct dmx_demux* demux, const char __user *buf, size_t count);
393 int (*allocate_ts_feed) (struct dmx_demux* demux,
394 struct dmx_ts_feed** feed,
396 int (*release_ts_feed) (struct dmx_demux* demux,
397 struct dmx_ts_feed* feed);
398 int (*allocate_section_feed) (struct dmx_demux* demux,
399 struct dmx_section_feed** feed,
400 dmx_section_cb callback);
401 int (*release_section_feed) (struct dmx_demux* demux,
402 struct dmx_section_feed* feed);
403 int (*add_frontend) (struct dmx_demux* demux,
404 struct dmx_frontend* frontend);
405 int (*remove_frontend) (struct dmx_demux* demux,
406 struct dmx_frontend* frontend);
407 struct list_head* (*get_frontends) (struct dmx_demux* demux);
408 int (*connect_frontend) (struct dmx_demux* demux,
409 struct dmx_frontend* frontend);
410 int (*disconnect_frontend) (struct dmx_demux* demux);
412 int (*get_pes_pids) (struct dmx_demux* demux, u16 *pids);
414 /* private: Not used upstream and never documented */
416 int (*get_caps) (struct dmx_demux* demux, struct dmx_caps *caps);
417 int (*set_source) (struct dmx_demux* demux, const dmx_source_t *src);
420 int (*get_stc) (struct dmx_demux* demux, unsigned int num,
421 u64 *stc, unsigned int *base);
424 #endif /* #ifndef __DEMUX_H */