demux.h 8.6 KB
Newer Older
L
Linus Torvalds 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
/*
 * demux.h
 *
 * Copyright (c) 2002 Convergence GmbH
 *
 * based on code:
 * Copyright (c) 2000 Nokia Research Center
 *                    Tampere, FINLAND
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public License
 * as published by the Free Software Foundation; either version 2.1
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 *
 */

#ifndef __DEMUX_H
#define __DEMUX_H

#include <linux/types.h>
#include <linux/errno.h>
#include <linux/list.h>
#include <linux/time.h>
33
#include <linux/dvb/dmx.h>
L
Linus Torvalds 已提交
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50

/*--------------------------------------------------------------------------*/
/* Common definitions */
/*--------------------------------------------------------------------------*/

/*
 * DMX_MAX_FILTER_SIZE: Maximum length (in bytes) of a section/PES filter.
 */

#ifndef DMX_MAX_FILTER_SIZE
#define DMX_MAX_FILTER_SIZE 18
#endif

/*
 * DMX_MAX_SECFEED_SIZE: Maximum length (in bytes) of a private section feed filter.
 */

51 52 53
#ifndef DMX_MAX_SECTION_SIZE
#define DMX_MAX_SECTION_SIZE 4096
#endif
L
Linus Torvalds 已提交
54
#ifndef DMX_MAX_SECFEED_SIZE
55
#define DMX_MAX_SECFEED_SIZE (DMX_MAX_SECTION_SIZE + 188)
L
Linus Torvalds 已提交
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82
#endif


/*
 * enum dmx_success: Success codes for the Demux Callback API.
 */

enum dmx_success {
  DMX_OK = 0, /* Received Ok */
  DMX_LENGTH_ERROR, /* Incorrect length */
  DMX_OVERRUN_ERROR, /* Receiver ring buffer overrun */
  DMX_CRC_ERROR, /* Incorrect CRC */
  DMX_FRAME_ERROR, /* Frame alignment error */
  DMX_FIFO_ERROR, /* Receiver FIFO overrun */
  DMX_MISSED_ERROR /* Receiver missed packet */
} ;

/*--------------------------------------------------------------------------*/
/* TS packet reception */
/*--------------------------------------------------------------------------*/

/* TS filter type for set() */

#define TS_PACKET       1   /* send TS packets (188 bytes) to callback (default) */
#define	TS_PAYLOAD_ONLY 2   /* in case TS_PACKET is set, only send the TS
			       payload (<=184 bytes per packet) to callback */
#define TS_DECODER      4   /* send stream to built-in decoder (if present) */
83 84
#define TS_DEMUX        8   /* in case TS_PACKET is set, send the TS to
			       the demux device, not to the dvr device */
L
Linus Torvalds 已提交
85 86 87 88 89 90

/* PES type for filters which write to built-in decoder */
/* these should be kept identical to the types in dmx.h */

enum dmx_ts_pes
{  /* also send packets to decoder (if it exists) */
91
	DMX_TS_PES_AUDIO0,
L
Linus Torvalds 已提交
92 93 94 95 96
	DMX_TS_PES_VIDEO0,
	DMX_TS_PES_TELETEXT0,
	DMX_TS_PES_SUBTITLE0,
	DMX_TS_PES_PCR0,

97
	DMX_TS_PES_AUDIO1,
L
Linus Torvalds 已提交
98 99 100 101 102
	DMX_TS_PES_VIDEO1,
	DMX_TS_PES_TELETEXT1,
	DMX_TS_PES_SUBTITLE1,
	DMX_TS_PES_PCR1,

103
	DMX_TS_PES_AUDIO2,
L
Linus Torvalds 已提交
104 105 106 107 108
	DMX_TS_PES_VIDEO2,
	DMX_TS_PES_TELETEXT2,
	DMX_TS_PES_SUBTITLE2,
	DMX_TS_PES_PCR2,

109
	DMX_TS_PES_AUDIO3,
L
Linus Torvalds 已提交
110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125
	DMX_TS_PES_VIDEO3,
	DMX_TS_PES_TELETEXT3,
	DMX_TS_PES_SUBTITLE3,
	DMX_TS_PES_PCR3,

	DMX_TS_PES_OTHER
};

#define DMX_TS_PES_AUDIO    DMX_TS_PES_AUDIO0
#define DMX_TS_PES_VIDEO    DMX_TS_PES_VIDEO0
#define DMX_TS_PES_TELETEXT DMX_TS_PES_TELETEXT0
#define DMX_TS_PES_SUBTITLE DMX_TS_PES_SUBTITLE0
#define DMX_TS_PES_PCR      DMX_TS_PES_PCR0


struct dmx_ts_feed {
126 127 128 129
	int is_filtering; /* Set to non-zero when filtering in progress */
	struct dmx_demux *parent; /* Back-pointer */
	void *priv; /* Pointer to private data of the API client */
	int (*set) (struct dmx_ts_feed *feed,
L
Linus Torvalds 已提交
130 131 132 133 134
		    u16 pid,
		    int type,
		    enum dmx_ts_pes pes_type,
		    size_t circular_buffer_size,
		    struct timespec timeout);
135 136
	int (*start_filtering) (struct dmx_ts_feed* feed);
	int (*stop_filtering) (struct dmx_ts_feed* feed);
L
Linus Torvalds 已提交
137 138 139 140 141 142 143
};

/*--------------------------------------------------------------------------*/
/* Section reception */
/*--------------------------------------------------------------------------*/

struct dmx_section_filter {
144 145 146 147 148
	u8 filter_value [DMX_MAX_FILTER_SIZE];
	u8 filter_mask [DMX_MAX_FILTER_SIZE];
	u8 filter_mode [DMX_MAX_FILTER_SIZE];
	struct dmx_section_feed* parent; /* Back-pointer */
	void* priv; /* Pointer to private data of the API client */
L
Linus Torvalds 已提交
149 150 151
};

struct dmx_section_feed {
152 153 154
	int is_filtering; /* Set to non-zero when filtering in progress */
	struct dmx_demux* parent; /* Back-pointer */
	void* priv; /* Pointer to private data of the API client */
L
Linus Torvalds 已提交
155

156
	int check_crc;
L
Linus Torvalds 已提交
157 158
	u32 crc_val;

159 160 161
	u8 *secbuf;
	u8 secbuf_base[DMX_MAX_SECFEED_SIZE];
	u16 secbufp, seclen, tsfeedp;
L
Linus Torvalds 已提交
162

163
	int (*set) (struct dmx_section_feed* feed,
L
Linus Torvalds 已提交
164 165 166
		    u16 pid,
		    size_t circular_buffer_size,
		    int check_crc);
167
	int (*allocate_filter) (struct dmx_section_feed* feed,
L
Linus Torvalds 已提交
168
				struct dmx_section_filter** filter);
169
	int (*release_filter) (struct dmx_section_feed* feed,
L
Linus Torvalds 已提交
170
			       struct dmx_section_filter* filter);
171 172
	int (*start_filtering) (struct dmx_section_feed* feed);
	int (*stop_filtering) (struct dmx_section_feed* feed);
L
Linus Torvalds 已提交
173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209
};

/*--------------------------------------------------------------------------*/
/* Callback functions */
/*--------------------------------------------------------------------------*/

typedef int (*dmx_ts_cb) ( const u8 * buffer1,
			   size_t buffer1_length,
			   const u8 * buffer2,
			   size_t buffer2_length,
			   struct dmx_ts_feed* source,
			   enum dmx_success success);

typedef int (*dmx_section_cb) (	const u8 * buffer1,
				size_t buffer1_len,
				const u8 * buffer2,
				size_t buffer2_len,
				struct dmx_section_filter * source,
				enum dmx_success success);

/*--------------------------------------------------------------------------*/
/* DVB Front-End */
/*--------------------------------------------------------------------------*/

enum dmx_frontend_source {
	DMX_MEMORY_FE,
	DMX_FRONTEND_0,
	DMX_FRONTEND_1,
	DMX_FRONTEND_2,
	DMX_FRONTEND_3,
	DMX_STREAM_0,    /* external stream input, e.g. LVDS */
	DMX_STREAM_1,
	DMX_STREAM_2,
	DMX_STREAM_3
};

struct dmx_frontend {
210
	struct list_head connectivity_list; /* List of front-ends that can
L
Linus Torvalds 已提交
211 212
					       be connected to a particular
					       demux */
213
	enum dmx_frontend_source source;
L
Linus Torvalds 已提交
214 215 216 217 218 219 220
};

/*--------------------------------------------------------------------------*/
/* MPEG-2 TS Demux */
/*--------------------------------------------------------------------------*/

/*
221
 * Flags OR'ed in the capabilities field of struct dmx_demux.
L
Linus Torvalds 已提交
222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244
 */

#define DMX_TS_FILTERING                        1
#define DMX_PES_FILTERING                       2
#define DMX_SECTION_FILTERING                   4
#define DMX_MEMORY_BASED_FILTERING              8    /* write() available */
#define DMX_CRC_CHECKING                        16
#define DMX_TS_DESCRAMBLING                     32

/*
 * Demux resource type identifier.
*/

/*
 * DMX_FE_ENTRY(): Casts elements in the list of registered
 * front-ends from the generic type struct list_head
 * to the type * struct dmx_frontend
 *.
*/

#define DMX_FE_ENTRY(list) list_entry(list, struct dmx_frontend, connectivity_list)

struct dmx_demux {
245 246 247 248 249
	u32 capabilities;            /* Bitfield of capability flags */
	struct dmx_frontend* frontend;    /* Front-end connected to the demux */
	void* priv;                  /* Pointer to private data of the API client */
	int (*open) (struct dmx_demux* demux);
	int (*close) (struct dmx_demux* demux);
250
	int (*write) (struct dmx_demux* demux, const char __user *buf, size_t count);
251
	int (*allocate_ts_feed) (struct dmx_demux* demux,
L
Linus Torvalds 已提交
252 253
				 struct dmx_ts_feed** feed,
				 dmx_ts_cb callback);
254
	int (*release_ts_feed) (struct dmx_demux* demux,
L
Linus Torvalds 已提交
255
				struct dmx_ts_feed* feed);
256
	int (*allocate_section_feed) (struct dmx_demux* demux,
L
Linus Torvalds 已提交
257 258
				      struct dmx_section_feed** feed,
				      dmx_section_cb callback);
259
	int (*release_section_feed) (struct dmx_demux* demux,
L
Linus Torvalds 已提交
260
				     struct dmx_section_feed* feed);
261
	int (*add_frontend) (struct dmx_demux* demux,
L
Linus Torvalds 已提交
262
			     struct dmx_frontend* frontend);
263
	int (*remove_frontend) (struct dmx_demux* demux,
L
Linus Torvalds 已提交
264
				struct dmx_frontend* frontend);
265 266
	struct list_head* (*get_frontends) (struct dmx_demux* demux);
	int (*connect_frontend) (struct dmx_demux* demux,
L
Linus Torvalds 已提交
267
				 struct dmx_frontend* frontend);
268
	int (*disconnect_frontend) (struct dmx_demux* demux);
L
Linus Torvalds 已提交
269

270
	int (*get_pes_pids) (struct dmx_demux* demux, u16 *pids);
L
Linus Torvalds 已提交
271

272 273 274 275
	int (*get_caps) (struct dmx_demux* demux, struct dmx_caps *caps);

	int (*set_source) (struct dmx_demux* demux, const dmx_source_t *src);

276
	int (*get_stc) (struct dmx_demux* demux, unsigned int num,
L
Linus Torvalds 已提交
277 278 279 280
			u64 *stc, unsigned int *base);
};

#endif /* #ifndef __DEMUX_H */