summaryrefslogtreecommitdiff
path: root/dvb-spec/API/dvb_api/demux.h
blob: 62cbf0a58041f5a6c69c4a83ca5fe462479c460b (plain)
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
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
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
/* * demux.h * * Copyright (c) 2000 Nokia Research Center
 * Tampere, FINLAND
 *
 * Project:
 * Universal Broadcast Access
 *
 * Contains:
 * Type definitions of a Linux kernel-level API for filtering MPEG-2 TS
 * packets and MPEG-2 sections. Support for PES packet filtering will be
 * added later.
 *
 * History:
 * 12.01.2000/JPL File created - Initial version.
 * 18.02.2000/JPL Minor corrections.
 * 21.02.2000/JPL DMX_NAME_SIZE and dmx_in_use() removed, typos fixed,
 * some names changed.
 * 23.02.2000/JPL Added a parameter indicating the callback source in
 * the callback functions.
 * 10.03.2000/JPL Added the macros DMX_DIR_ENTRY() and DMX_FE_ENTRY().
 * 15.03.2000/JPL Added the capabilities field to dmx_demux_t.
 * 22.03.2000/JPL Corrected the callback parameter in the
 * allocate_x_feed() functions.
 * 03.04.2000/JPL Added support for optional resource conflict resolution 
 * and scarce resource handling. 
 * 05.04.2000/JPL Changed the dmx_resolve_conflict() to use resource 
 * type as a parameter. 
 * 12.04.2000/JPL Added a second buffer parameter for dmx_x_callback() 
 * functions to better handle buffer wrapping. 
 * 26.04.2000/JPL Added functions for section-level descrambling. 
 * 03.09.2000/JPL Removed support for conflict resolution and scarce 
 * resource handling. Otherwise only minor changes to 
 * data structures and function prototypes. 
 * 
 *
 * Author:
 * Juha-Pekka Luoma (JPL)
 * Nokia Research Center
 *
 * Notes:
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * 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 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.
 *
 */
/* $Id$ */ 

#ifndef __DEMUX_H 
#define __DEMUX_H 

#ifndef __KERNEL__ 
#define __KERNEL__ 
#endif 

#include <linux/types.h> /* __u8, __u16, ... */ 
#include <linux/list.h> /* list_entry(), struct list_head */ 
#include <linux/time.h> /* struct timespec */ 
#include <linux/errno.h> /* Function return values */ 

/*--------------------------------------------------------------------------*/ 
/* 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 16 
#endif 
/*
 * dmx_success_t: Success codes for the Demux Callback API. 
 */ 

typedef enum { 
  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 */ 
} dmx_success_t; 

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

struct dmx_ts_feed_s { 
        int is_filtering; /* Set to non-zero when filtering in progress */
        struct dmx_demux_s* parent; /* Back-pointer */
        void* priv; /* Pointer to private data of the API client */ 
        int (*set) (struct dmx_ts_feed_s* feed, 
		    __u16 pid,
		    size_t callback_length, 
		    size_t circular_buffer_size, 
		    int descramble, 
		    struct timespec timeout); 
        int (*start_filtering) (struct dmx_ts_feed_s* feed); 
        int (*stop_filtering) (struct dmx_ts_feed_s* feed); 
};
typedef struct dmx_ts_feed_s dmx_ts_feed_t; 

/*--------------------------------------------------------------------------*/ 
/* PES packet reception (not supported yet) */
/*--------------------------------------------------------------------------*/ 

typedef void dmx_pes_feed_t; 
typedef void dmx_pes_filter_t; 

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

typedef struct { 
        __u8 filter_value [DMX_MAX_FILTER_SIZE]; 
        __u8 filter_mask [DMX_MAX_FILTER_SIZE]; 
        struct dmx_section_feed_s* parent; /* Back-pointer */ 
        void* priv; /* Pointer to private data of the API client */ 
} dmx_section_filter_t;

struct dmx_section_feed_s { 
        int is_filtering; /* Set to non-zero when filtering in progress */ 
        struct dmx_demux_s* parent; /* Back-pointer */
        void* priv; /* Pointer to private data of the API client */ 
        int (*set) (struct dmx_section_feed_s* feed, 
		    __u16 pid, 
		    size_t circular_buffer_size, 
		    int descramble, 
		    int check_crc); 
        int (*allocate_filter) (struct dmx_section_feed_s* feed, 
				dmx_section_filter_t** filter); 
        int (*release_filter) (struct dmx_section_feed_s* feed, 
			       dmx_section_filter_t* filter); 
        int (*start_filtering) (struct dmx_section_feed_s* feed); 
        int (*stop_filtering) (struct dmx_section_feed_s* feed); 
};
typedef struct dmx_section_feed_s dmx_section_feed_t; 

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

typedef int (*dmx_ts_cb) ( __u8 * buffer1, 
			   size_t buffer1_length,
			   __u8 * buffer2, 
			   size_t buffer2_length,
			   dmx_ts_feed_t* source, 
			   dmx_success_t success); 

typedef int (*dmx_section_cb) (	__u8 * buffer1,
				size_t buffer_len,
				__u8 * buffer2, 
				size_t buffer2_len,
			       	dmx_section_filter_t * source,
			       	dmx_success_t success);

typedef int (*dmx_pes_cb) ( __u8 * buffer1, 
			    size_t buffer1_len,
			    __u8 * buffer2,
			    size_t buffer2_len,
			    dmx_pes_filter_t* source, 
			    dmx_success_t success); 

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

typedef enum { 
        DMX_OTHER_FE = 0, 
	DMX_SATELLITE_FE, 
	DMX_CABLE_FE, 
	DMX_TERRESTRIAL_FE, 
	DMX_LVDS_FE, 
	DMX_ASI_FE /* DVB-ASI interface */
} dmx_frontend_source_t; 

typedef struct { 
        /* The following char* fields point to NULL terminated strings */ 
        char* id;                    /* Unique front-end identifier */ 
        char* vendor;                /* Name of the front-end vendor */ 
        char* model;                 /* Name of the front-end model */ 
        struct list_head connectivity_list; /* List of front-ends that can 
					       be connected to a particular 
					       demux */ 
        void* priv;     /* Pointer to private data of the API client */ 
} dmx_frontend_t;

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

/* 
 * Flags OR'ed in the capabilites field of struct dmx_demux_s. 
 */ 

#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 
#define DMX_SECTION_PAYLOAD_DESCRAMBLING        64 
#define DMX_MAC_ADDRESS_DESCRAMBLING            128 

/* 
 * 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 * dmx_frontend_t
 *. 
*/

#define DMX_FE_ENTRY(list) list_entry(list, dmx_frontend_t, connectivity_list) 

struct dmx_demux_s { 
        /* The following char* fields point to NULL terminated strings */ 
        char* id;                    /* Unique demux identifier */ 
        char* vendor;                /* Name of the demux vendor */ 
        char* model;                 /* Name of the demux model */ 
        __u32 capabilites;           /* Bitfield of capability flags */ 
        dmx_frontend_t* frontend;    /* Front-end connected to the demux */ 
        struct list_head reg_list;   /* List of registered demuxes */
        void* priv;                  /* Pointer to private data of the API client */ 
        int (*open) (struct dmx_demux_s* demux); 
        int (*close) (struct dmx_demux_s* demux); 
        int (*write) (struct dmx_demux_s* demux, const char* buf, size_t count); 
        int (*allocate_ts_feed) (struct dmx_demux_s* demux, 
				 dmx_ts_feed_t** feed, 
				 dmx_ts_cb callback); 
        int (*release_ts_feed) (struct dmx_demux_s* demux, 
				dmx_ts_feed_t* feed); 
        int (*allocate_pes_feed) (struct dmx_demux_s* demux, 
				  dmx_pes_feed_t** feed, 
				  dmx_pes_cb callback); 
        int (*release_pes_feed) (struct dmx_demux_s* demux, 
				 dmx_pes_feed_t* feed); 
        int (*allocate_section_feed) (struct dmx_demux_s* demux, 
				      dmx_section_feed_t** feed, 
				      dmx_section_cb callback); 
        int (*release_section_feed) (struct dmx_demux_s* demux,
				     dmx_section_feed_t* feed); 
        int (*descramble_mac_address) (struct dmx_demux_s* demux, 
				       __u8* buffer1, 
				       size_t buffer1_length, 
				       __u8* buffer2, 
				       size_t buffer2_length,
				       __u16 pid); 
        int (*descramble_section_payload) (struct dmx_demux_s* demux,
					   __u8* buffer1, 
					   size_t buffer1_length,
					   __u8* buffer2, size_t buffer2_length,
					   __u16 pid); 
        int (*add_frontend) (struct dmx_demux_s* demux, 
			     dmx_frontend_t* frontend); 
        int (*remove_frontend) (struct dmx_demux_s* demux,
				dmx_frontend_t* frontend); 
        struct list_head* (*get_frontends) (struct dmx_demux_s* demux); 
        int (*connect_frontend) (struct dmx_demux_s* demux, 
				 dmx_frontend_t* frontend); 
        int (*disconnect_frontend) (struct dmx_demux_s* demux); 
}; 
typedef struct dmx_demux_s dmx_demux_t; 

/*--------------------------------------------------------------------------*/ 
/* Demux directory */ 
/*--------------------------------------------------------------------------*/ 

/* 
 * DMX_DIR_ENTRY(): Casts elements in the list of registered 
 * demuxes from the generic type struct list_head* to the type dmx_demux_t
 *. 
 */ 

#define DMX_DIR_ENTRY(list) list_entry(list, dmx_demux_t, reg_list)

int dmx_register_demux (dmx_demux_t* demux); 
int dmx_unregister_demux (dmx_demux_t* demux); 
struct list_head* dmx_get_demuxes (void); 

#endif /* #ifndef __DEMUX_H */