summaryrefslogtreecommitdiff
path: root/Documentation/DocBook/dvb/kdapi.xml
blob: 6c67481eaa4b8f20292d5ab9d2cdcdc4398d9f3f (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
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
<title>Kernel Demux API</title>
<para>The kernel demux API defines a driver-internal interface for registering low-level,
hardware specific driver to a hardware independent demux layer. It is only of interest for
DVB device driver writers. The header file for this API is named <emphasis role="tt">demux.h</emphasis> and located in
<emphasis role="tt">drivers/media/dvb/dvb-core</emphasis>.
</para>
<para>Maintainer note: This section must be reviewed. It is probably out of date.
</para>

<section id="kernel_demux_data_types">
<title>Kernel Demux Data Types</title>


<section id="dmx_success_t">
<title>dmx_success_t</title>
 <programlisting>
 typedef enum {
   DMX_OK = 0, /&#x22C6; Received Ok &#x22C6;/
   DMX_LENGTH_ERROR, /&#x22C6; Incorrect length &#x22C6;/
   DMX_OVERRUN_ERROR, /&#x22C6; Receiver ring buffer overrun &#x22C6;/
   DMX_CRC_ERROR, /&#x22C6; Incorrect CRC &#x22C6;/
   DMX_FRAME_ERROR, /&#x22C6; Frame alignment error &#x22C6;/
   DMX_FIFO_ERROR, /&#x22C6; Receiver FIFO overrun &#x22C6;/
   DMX_MISSED_ERROR /&#x22C6; Receiver missed packet &#x22C6;/
 } dmx_success_t;
</programlisting>

</section>
<section id="ts_filter_types">
<title>TS filter types</title>
 <programlisting>
 /&#x22C6;--------------------------------------------------------------------------&#x22C6;/
 /&#x22C6; TS packet reception &#x22C6;/
 /&#x22C6;--------------------------------------------------------------------------&#x22C6;/

 /&#x22C6; TS filter type for set_type() &#x22C6;/

 #define TS_PACKET       1   /&#x22C6; send TS packets (188 bytes) to callback (default) &#x22C6;/
 #define TS_PAYLOAD_ONLY 2   /&#x22C6; in case TS_PACKET is set, only send the TS
				payload (&#x003C;=184 bytes per packet) to callback &#x22C6;/
 #define TS_DECODER      4   /&#x22C6; send stream to built-in decoder (if present) &#x22C6;/
</programlisting>

</section>
<section id="dmx_ts_pes_t">
<title>dmx_ts_pes_t</title>
<para>The structure
</para>
<programlisting>
 typedef enum
 {
	 DMX_TS_PES_AUDIO,   /&#x22C6; also send packets to audio decoder (if it exists) &#x22C6;/
	 DMX_TS_PES_VIDEO,   /&#x22C6; ... &#x22C6;/
	 DMX_TS_PES_TELETEXT,
	 DMX_TS_PES_SUBTITLE,
	 DMX_TS_PES_PCR,
	 DMX_TS_PES_OTHER,
 } dmx_ts_pes_t;
</programlisting>
<para>describes the PES type for filters which write to a built-in decoder. The correspond (and
should be kept identical) to the types in the demux device.
</para>
<programlisting>
 struct dmx_ts_feed_s {
	 int is_filtering; /&#x22C6; Set to non-zero when filtering in progress &#x22C6;/
	 struct dmx_demux_s&#x22C6; parent; /&#x22C6; Back-pointer &#x22C6;/
	 void&#x22C6; priv; /&#x22C6; Pointer to private data of the API client &#x22C6;/
	 int (&#x22C6;set) (struct dmx_ts_feed_s&#x22C6; feed,
		     __u16 pid,
		     size_t callback_length,
		     size_t circular_buffer_size,
		     int descramble,
		     struct timespec timeout);
	 int (&#x22C6;start_filtering) (struct dmx_ts_feed_s&#x22C6; feed);
	 int (&#x22C6;stop_filtering) (struct dmx_ts_feed_s&#x22C6; feed);
	 int (&#x22C6;set_type) (struct dmx_ts_feed_s&#x22C6; feed,
			  int type,
			  dmx_ts_pes_t pes_type);
 };

 typedef struct dmx_ts_feed_s dmx_ts_feed_t;
</programlisting>
 <programlisting>
 /&#x22C6;--------------------------------------------------------------------------&#x22C6;/
 /&#x22C6; PES packet reception (not supported yet) &#x22C6;/
 /&#x22C6;--------------------------------------------------------------------------&#x22C6;/

 typedef struct dmx_pes_filter_s {
	 struct dmx_pes_s&#x22C6; parent; /&#x22C6; Back-pointer &#x22C6;/
	 void&#x22C6; priv; /&#x22C6; Pointer to private data of the API client &#x22C6;/
 } dmx_pes_filter_t;
</programlisting>
 <programlisting>
 typedef struct dmx_pes_feed_s {
	 int is_filtering; /&#x22C6; Set to non-zero when filtering in progress &#x22C6;/
	 struct dmx_demux_s&#x22C6; parent; /&#x22C6; Back-pointer &#x22C6;/
	 void&#x22C6; priv; /&#x22C6; Pointer to private data of the API client &#x22C6;/
	 int (&#x22C6;set) (struct dmx_pes_feed_s&#x22C6; feed,
		     __u16 pid,
		     size_t circular_buffer_size,
		     int descramble,
		     struct timespec timeout);
	 int (&#x22C6;start_filtering) (struct dmx_pes_feed_s&#x22C6; feed);
	 int (&#x22C6;stop_filtering) (struct dmx_pes_feed_s&#x22C6; feed);
	 int (&#x22C6;allocate_filter) (struct dmx_pes_feed_s&#x22C6; feed,
				 dmx_pes_filter_t&#x22C6;&#x22C6; filter);
	 int (&#x22C6;release_filter) (struct dmx_pes_feed_s&#x22C6; feed,
				dmx_pes_filter_t&#x22C6; filter);
 } dmx_pes_feed_t;
</programlisting>
 <programlisting>
 typedef struct {
	 __u8 filter_value [DMX_MAX_FILTER_SIZE];
	 __u8 filter_mask [DMX_MAX_FILTER_SIZE];
	 struct dmx_section_feed_s&#x22C6; parent; /&#x22C6; Back-pointer &#x22C6;/
	 void&#x22C6; priv; /&#x22C6; Pointer to private data of the API client &#x22C6;/
 } dmx_section_filter_t;
</programlisting>
 <programlisting>
 struct dmx_section_feed_s {
	 int is_filtering; /&#x22C6; Set to non-zero when filtering in progress &#x22C6;/
	 struct dmx_demux_s&#x22C6; parent; /&#x22C6; Back-pointer &#x22C6;/
	 void&#x22C6; priv; /&#x22C6; Pointer to private data of the API client &#x22C6;/
	 int (&#x22C6;set) (struct dmx_section_feed_s&#x22C6; feed,
		     __u16 pid,
		     size_t circular_buffer_size,
		     int descramble,
		     int check_crc);
	 int (&#x22C6;allocate_filter) (struct dmx_section_feed_s&#x22C6; feed,
				 dmx_section_filter_t&#x22C6;&#x22C6; filter);
	 int (&#x22C6;release_filter) (struct dmx_section_feed_s&#x22C6; feed,
				dmx_section_filter_t&#x22C6; filter);
	 int (&#x22C6;start_filtering) (struct dmx_section_feed_s&#x22C6; feed);
	 int (&#x22C6;stop_filtering) (struct dmx_section_feed_s&#x22C6; feed);
 };
 typedef struct dmx_section_feed_s dmx_section_feed_t;

 /&#x22C6;--------------------------------------------------------------------------&#x22C6;/
 /&#x22C6; Callback functions &#x22C6;/
 /&#x22C6;--------------------------------------------------------------------------&#x22C6;/

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

 typedef int (&#x22C6;dmx_section_cb) ( __u8 &#x22C6; buffer1,
				 size_t buffer1_len,
				 __u8 &#x22C6; buffer2,
				 size_t buffer2_len,
				 dmx_section_filter_t &#x22C6; source,
				 dmx_success_t success);

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

 /&#x22C6;--------------------------------------------------------------------------&#x22C6;/
 /&#x22C6; DVB Front-End &#x22C6;/
 /&#x22C6;--------------------------------------------------------------------------&#x22C6;/

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

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

 /&#x22C6;--------------------------------------------------------------------------&#x22C6;/
 /&#x22C6; MPEG-2 TS Demux &#x22C6;/
 /&#x22C6;--------------------------------------------------------------------------&#x22C6;/

 /&#x22C6;
  &#x22C6; Flags OR'ed in the capabilites field of struct dmx_demux_s.
  &#x22C6;/

 #define DMX_TS_FILTERING                        1
 #define DMX_PES_FILTERING                       2
 #define DMX_SECTION_FILTERING                   4
 #define DMX_MEMORY_BASED_FILTERING              8    /&#x22C6; write() available &#x22C6;/
 #define DMX_CRC_CHECKING                        16
 #define DMX_TS_DESCRAMBLING                     32
 #define DMX_SECTION_PAYLOAD_DESCRAMBLING        64
 #define DMX_MAC_ADDRESS_DESCRAMBLING            128
</programlisting>

</section>
<section id="demux_demux_t">
<title>demux_demux_t</title>
 <programlisting>
 /&#x22C6;
  &#x22C6; DMX_FE_ENTRY(): Casts elements in the list of registered
  &#x22C6; front-ends from the generic type struct list_head
  &#x22C6; to the type &#x22C6; dmx_frontend_t
  &#x22C6;.
 &#x22C6;/

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

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


	 /&#x22C6; added because js cannot keep track of these himself &#x22C6;/
	 int (&#x22C6;get_pes_pids) (struct dmx_demux_s&#x22C6; demux, __u16 &#x22C6;pids);
 };
 typedef struct dmx_demux_s dmx_demux_t;
</programlisting>

</section>
<section id="demux_directory">
<title>Demux directory</title>
 <programlisting>
 /&#x22C6;
  &#x22C6; DMX_DIR_ENTRY(): Casts elements in the list of registered
  &#x22C6; demuxes from the generic type struct list_head&#x22C6; to the type dmx_demux_t
  &#x22C6;.
  &#x22C6;/

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

 int dmx_register_demux (dmx_demux_t&#x22C6; demux);
 int dmx_unregister_demux (dmx_demux_t&#x22C6; demux);
 struct list_head&#x22C6; dmx_get_demuxes (void);
</programlisting>
 </section></section>
<section id="demux_directory_api">
<title>Demux Directory API</title>
<para>The demux directory is a Linux kernel-wide facility for registering and accessing the
MPEG-2 TS demuxes in the system. Run-time registering and unregistering of demux drivers
is possible using this API.
</para>
<para>All demux drivers in the directory implement the abstract interface dmx_demux_t.
</para>

<section
role="subsection"><title>dmx_register_demux()</title>
<para>DESCRIPTION
</para>
<informaltable><tgroup cols="1"><tbody><row><entry
 align="char">
<para>This function makes a demux driver interface available to the Linux kernel. It is
 usually called by the init_module() function of the kernel module that contains
 the demux driver. The caller of this function is responsible for allocating
 dynamic or static memory for the demux structure and for initializing its fields
 before calling this function. The memory allocated for the demux structure
 must not be freed before calling dmx_unregister_demux(),</para>
</entry>
 </row></tbody></tgroup></informaltable>
<para>SYNOPSIS
</para>
<informaltable><tgroup cols="1"><tbody><row><entry
 align="char">
<para>int dmx_register_demux ( dmx_demux_t &#x22C6;demux )</para>
</entry>
 </row></tbody></tgroup></informaltable>
<para>PARAMETERS
</para>
<informaltable><tgroup cols="2"><tbody><row><entry
 align="char">
<para>dmx_demux_t*
 demux</para>
</entry><entry
 align="char">
<para>Pointer to the demux structure.</para>
</entry>
 </row></tbody></tgroup></informaltable>
<para>RETURNS
</para>
<informaltable><tgroup cols="2"><tbody><row><entry
 align="char">
<para>0</para>
</entry><entry
 align="char">
<para>The function was completed without errors.</para>
</entry>
 </row><row><entry
 align="char">
<para>-EEXIST</para>
</entry><entry
 align="char">
<para>A demux with the same value of the id field already stored
 in the directory.</para>
</entry>
 </row><row><entry
 align="char">
<para>-ENOSPC</para>
</entry><entry
 align="char">
<para>No space left in the directory.</para>
</entry>
 </row></tbody></tgroup></informaltable>

</section><section
role="subsection"><title>dmx_unregister_demux()</title>
<para>DESCRIPTION
</para>
<informaltable><tgroup cols="1"><tbody><row><entry
 align="char">
<para>This function is called to indicate that the given demux interface is no
 longer available. The caller of this function is responsible for freeing the
 memory of the demux structure, if it was dynamically allocated before calling
 dmx_register_demux(). The cleanup_module() function of the kernel module
 that contains the demux driver should call this function. Note that this function
 fails if the demux is currently in use, i.e., release_demux() has not been called
 for the interface.</para>
</entry>
 </row></tbody></tgroup></informaltable>
<para>SYNOPSIS
</para>
<informaltable><tgroup cols="1"><tbody><row><entry
 align="char">
<para>int dmx_unregister_demux ( dmx_demux_t &#x22C6;demux )</para>
</entry>
 </row></tbody></tgroup></informaltable>
<para>PARAMETERS
</para>
<informaltable><tgroup cols="2"><tbody><row><entry
 align="char">
<para>dmx_demux_t*
 demux</para>
</entry><entry
 align="char">
<para>Pointer to the demux structure which is to be
 unregistered.</para>
</entry>
 </row></tbody></tgroup></informaltable>
<para>RETURNS
</para>
<informaltable><tgroup cols="2"><tbody><row><entry
 align="char">
<para>0</para>
</entry><entry
 align="char">
<para>The function was completed without errors.</para>
</entry>
 </row><row><entry
 align="char">
<para>ENODEV</para>
</entry><entry
 align="char">
<para>The specified demux is not registered in the demux
 directory.</para>
</entry>
 </row><row><entry
 align="char">
<para>EBUSY</para>
</entry><entry
 align="char">
<para>The specified demux is currently in use.</para>
</entry>
 </row></tbody></tgroup></informaltable>

</section><section
role="subsection"><title>dmx_get_demuxes()</title>
<para>DESCRIPTION
</para>
<informaltable><tgroup cols="1"><tbody><row><entry
 align="char">
<para>Provides the caller with the list of registered demux interfaces, using the
 standard list structure defined in the include file linux/list.h. The include file
 demux.h defines the macro DMX_DIR_ENTRY() for converting an element of
 the generic type struct list_head* to the type dmx_demux_t*. The caller must
 not free the memory of any of the elements obtained via this function call.</para>
</entry>
 </row></tbody></tgroup></informaltable>
<para>SYNOPSIS
</para>
<informaltable><tgroup cols="1"><tbody><row><entry
 align="char">
<para>struct list_head &#x22C6;dmx_get_demuxes ()</para>
</entry>
 </row></tbody></tgroup></informaltable>
<para>PARAMETERS
</para>
<informaltable><tgroup cols="2"><tbody><row><entry
 align="char">
<para>none</para>
</entry>
 </row></tbody></tgroup></informaltable>
<para>RETURNS
</para>
<informaltable><tgroup cols="2"><tbody><row><entry
 align="char">
<para>struct list_head *</para>
</entry><entry
 align="char">
<para>A list of demux interfaces, or NULL in the case of an
 empty list.</para>
</entry>
 </row></tbody></tgroup></informaltable>
 </section></section>
<section id="demux_api">
<title>Demux API</title>
<para>The demux API should be implemented for each demux in the system. It is used to select
the TS source of a demux and to manage the demux resources. When the demux
client allocates a resource via the demux API, it receives a pointer to the API of that
resource.
</para>
<para>Each demux receives its TS input from a DVB front-end or from memory, as set via the
demux API. In a system with more than one front-end, the API can be used to select one of
the DVB front-ends as a TS source for a demux, unless this is fixed in the HW platform. The
demux API only controls front-ends regarding their connections with demuxes; the APIs
used to set the other front-end parameters, such as tuning, are not defined in this
document.
</para>
<para>The functions that implement the abstract interface demux should be defined static or
module private and registered to the Demux Directory for external access. It is not necessary
to implement every function in the demux_t struct, however (for example, a demux interface
might support Section filtering, but not TS or PES filtering). The API client is expected to
check the value of any function pointer before calling the function: the value of NULL means
&#8220;function not available&#8221;.
</para>
<para>Whenever the functions of the demux API modify shared data, the possibilities of lost
update and race condition problems should be addressed, e.g. by protecting parts of code with
mutexes. This is especially important on multi-processor hosts.
</para>
<para>Note that functions called from a bottom half context must not sleep, at least in the 2.2.x
kernels. Even a simple memory allocation can result in a kernel thread being put to sleep if
swapping is needed. For example, the Linux kernel calls the functions of a network device
interface from a bottom half context. Thus, if a demux API function is called from network
device code, the function must not sleep.
</para>


<section id="kdapi_fopen">
<title>open()</title>
<para>DESCRIPTION
</para>
<informaltable><tgroup cols="1"><tbody><row><entry
 align="char">
<para>This function reserves the demux for use by the caller and, if necessary,
 initializes the demux. When the demux is no longer needed, the function close()
 should be called. It should be possible for multiple clients to access the demux
 at the same time. Thus, the function implementation should increment the
 demux usage count when open() is called and decrement it when close() is
 called.</para>
</entry>
 </row></tbody></tgroup></informaltable>
<para>SYNOPSIS
</para>
<informaltable><tgroup cols="1"><tbody><row><entry
 align="char">
<para>int open ( demux_t&#x22C6; demux );</para>
</entry>
 </row></tbody></tgroup></informaltable>
<para>PARAMETERS
</para>
<informaltable><tgroup cols="2"><tbody><row><entry
 align="char">
<para>demux_t* demux</para>
</entry><entry
 align="char">
<para>Pointer to the demux API and instance data.</para>
</entry>
 </row></tbody></tgroup></informaltable>
<para>RETURNS
</para>
<informaltable><tgroup cols="2"><tbody><row><entry
 align="char">
<para>0</para>
</entry><entry
 align="char">
<para>The function was completed without errors.</para>
</entry>
 </row><row><entry
 align="char">
<para>-EUSERS</para>
</entry><entry
 align="char">
<para>Maximum usage count reached.</para>
</entry>
 </row><row><entry
 align="char">
<para>-EINVAL</para>
</entry><entry
 align="char">
<para>Bad parameter.</para>
</entry>
 </row></tbody></tgroup></informaltable>

</section>
<section id="kdapi_fclose">
<title>close()</title>
<para>DESCRIPTION
</para>
<informaltable><tgroup cols="1"><tbody><row><entry
 align="char">
<para>This function reserves the demux for use by the caller and, if necessary,
 initializes the demux. When the demux is no longer needed, the function close()
 should be called. It should be possible for multiple clients to access the demux
 at the same time. Thus, the function implementation should increment the
 demux usage count when open() is called and decrement it when close() is
 called.</para>
</entry>
 </row></tbody></tgroup></informaltable>
<para>SYNOPSIS
</para>
<informaltable><tgroup cols="1"><tbody><row><entry
 align="char">
<para>int close(demux_t&#x22C6; demux);</para>
</entry>
 </row></tbody></tgroup></informaltable>
<para>PARAMETERS
</para>
<informaltable><tgroup cols="2"><tbody><row><entry
 align="char">
<para>demux_t* demux</para>
</entry><entry
 align="char">
<para>Pointer to the demux API and instance data.</para>
</entry>
 </row></tbody></tgroup></informaltable>
<para>RETURNS
</para>
<informaltable><tgroup cols="2"><tbody><row><entry
 align="char">
<para>0</para>
</entry><entry
 align="char">
<para>The function was completed without errors.</para>
</entry>
 </row><row><entry
 align="char">
<para>-ENODEV</para>
</entry><entry
 align="char">
<para>The demux was not in use.</para>
</entry>
 </row><row><entry
 align="char">
<para>-EINVAL</para>
</entry><entry
 align="char">
<para>Bad parameter.</para>
</entry>
 </row></tbody></tgroup></informaltable>

</section>
<section id="kdapi_fwrite">
<title>write()</title>
<para>DESCRIPTION
</para>
<informaltable><tgroup cols="1"><tbody><row><entry
 align="char">
<para>This function provides the demux driver with a memory buffer containing TS
 packets. Instead of receiving TS packets from the DVB front-end, the demux
 driver software will read packets from memory. Any clients of this demux
 with active TS, PES or Section filters will receive filtered data via the Demux
 callback API (see 0). The function returns when all the data in the buffer has
 been consumed by the demux. Demux hardware typically cannot read TS from
 memory. If this is the case, memory-based filtering has to be implemented
 entirely in software.</para>
</entry>
 </row></tbody></tgroup></informaltable>
<para>SYNOPSIS
</para>
<informaltable><tgroup cols="1"><tbody><row><entry
 align="char">
<para>int write(demux_t&#x22C6; demux, const char&#x22C6; buf, size_t
 count);</para>
</entry>
 </row></tbody></tgroup></informaltable>
<para>PARAMETERS
</para>
<informaltable><tgroup cols="2"><tbody><row><entry
 align="char">
<para>demux_t* demux</para>
</entry><entry
 align="char">
<para>Pointer to the demux API and instance data.</para>
</entry>
 </row><row><entry
 align="char">
<para>const char* buf</para>
</entry><entry
 align="char">
<para>Pointer to the TS data in kernel-space memory.</para>
</entry>
 </row><row><entry
 align="char">
<para>size_t length</para>
</entry><entry
 align="char">
<para>Length of the TS data.</para>
</entry>
 </row></tbody></tgroup></informaltable>
<para>RETURNS
</para>
<informaltable><tgroup cols="2"><tbody><row><entry
 align="char">
<para>0</para>
</entry><entry
 align="char">
<para>The function was completed without errors.</para>
</entry>
 </row><row><entry
 align="char">
<para>-ENOSYS</para>
</entry><entry
 align="char">
<para>The command is not implemented.</para>
</entry>
 </row><row><entry
 align="char">
<para>-EINVAL</para>
</entry><entry
 align="char">
<para>Bad parameter.</para>
</entry>
 </row></tbody></tgroup></informaltable>

</section><section
role="subsection"><title>allocate_ts_feed()</title>
<para>DESCRIPTION
</para>
<informaltable><tgroup cols="1"><tbody><row><entry
 align="char">
<para>Allocates a new TS feed, which is used to filter the TS packets carrying a
 certain PID. The TS feed normally corresponds to a hardware PID filter on the
 demux chip.</para>
</entry>
 </row></tbody></tgroup></informaltable>
<para>SYNOPSIS
</para>
<informaltable><tgroup cols="1"><tbody><row><entry
 align="char">
<para>int allocate_ts_feed(dmx_demux_t&#x22C6; demux,
 dmx_ts_feed_t&#x22C6;&#x22C6; feed, dmx_ts_cb callback);</para>
</entry>
 </row></tbody></tgroup></informaltable>
<para>PARAMETERS
</para>
<informaltable><tgroup cols="2"><tbody><row><entry
 align="char">
<para>demux_t* demux</para>
</entry><entry
 align="char">
<para>Pointer to the demux API and instance data.</para>
</entry>
 </row><row><entry
 align="char">
<para>dmx_ts_feed_t**
 feed</para>
</entry><entry
 align="char">
<para>Pointer to the TS feed API and instance data.</para>
</entry>
 </row><row><entry
 align="char">
<para>dmx_ts_cb callback</para>
</entry><entry
 align="char">
<para>Pointer to the callback function for passing received TS
 packet</para>
</entry>
 </row></tbody></tgroup></informaltable>
<para>RETURNS
</para>
<informaltable><tgroup cols="2"><tbody><row><entry
 align="char">
<para>0</para>
</entry><entry
 align="char">
<para>The function was completed without errors.</para>
</entry>
 </row><row><entry
 align="char">
<para>-EBUSY</para>
</entry><entry
 align="char">
<para>No more TS feeds available.</para>
</entry>
 </row><row><entry
 align="char">
<para>-ENOSYS</para>
</entry><entry
 align="char">
<para>The command is not implemented.</para>
</entry>
 </row><row><entry
 align="char">
<para>-EINVAL</para>
</entry><entry
 align="char">
<para>Bad parameter.</para>
</entry>
 </row></tbody></tgroup></informaltable>

</section><section
role="subsection"><title>release_ts_feed()</title>
<para>DESCRIPTION
</para>
<informaltable><tgroup cols="1"><tbody><row><entry
 align="char">
<para>Releases the resources allocated with allocate_ts_feed(). Any filtering in
 progress on the TS feed should be stopped before calling this function.</para>
</entry>
 </row></tbody></tgroup></informaltable>
<para>SYNOPSIS
</para>
<informaltable><tgroup cols="1"><tbody><row><entry
 align="char">
<para>int release_ts_feed(dmx_demux_t&#x22C6; demux,
 dmx_ts_feed_t&#x22C6; feed);</para>
</entry>
 </row></tbody></tgroup></informaltable>
<para>PARAMETERS
</para>
<informaltable><tgroup cols="2"><tbody><row><entry
 align="char">
<para>demux_t* demux</para>
</entry><entry
 align="char">
<para>Pointer to the demux API and instance data.</para>
</entry>
 </row><row><entry
 align="char">
<para>dmx_ts_feed_t* feed</para>
</entry><entry
 align="char">
<para>Pointer to the TS feed API and instance data.</para>
</entry>
 </row></tbody></tgroup></informaltable>
<para>RETURNS
</para>
<informaltable><tgroup cols="2"><tbody><row><entry
 align="char">
<para>0</para>
</entry><entry
 align="char">
<para>The function was completed without errors.</para>
</entry>
 </row><row><entry
 align="char">
<para>-EINVAL</para>
</entry><entry
 align="char">
<para>Bad parameter.</para>
</entry>
 </row></tbody></tgroup></informaltable>

</section><section
role="subsection"><title>allocate_section_feed()</title>
<para>DESCRIPTION
</para>
<informaltable><tgroup cols="1"><tbody><row><entry
 align="char">
<para>Allocates a new section feed, i.e. a demux resource for filtering and receiving
 sections. On platforms with hardware support for section filtering, a section
 feed is directly mapped to the demux HW. On other platforms, TS packets are
 first PID filtered in hardware and a hardware section filter then emulated in
 software. The caller obtains an API pointer of type dmx_section_feed_t as an
 out parameter. Using this API the caller can set filtering parameters and start
 receiving sections.</para>
</entry>
 </row></tbody></tgroup></informaltable>
<para>SYNOPSIS
</para>
<informaltable><tgroup cols="1"><tbody><row><entry
 align="char">
<para>int allocate_section_feed(dmx_demux_t&#x22C6; demux,
 dmx_section_feed_t &#x22C6;&#x22C6;feed, dmx_section_cb callback);</para>
</entry>
 </row></tbody></tgroup></informaltable>
<para>PARAMETERS
</para>
<informaltable><tgroup cols="2"><tbody><row><entry
 align="char">
<para>demux_t *demux</para>
</entry><entry
 align="char">
<para>Pointer to the demux API and instance data.</para>
</entry>
 </row><row><entry
 align="char">
<para>dmx_section_feed_t
 **feed</para>
</entry><entry
 align="char">
<para>Pointer to the section feed API and instance data.</para>
</entry>
 </row><row><entry
 align="char">
<para>dmx_section_cb
 callback</para>
</entry><entry
 align="char">
<para>Pointer to the callback function for passing received
 sections.</para>
</entry>
 </row></tbody></tgroup></informaltable>
<para>RETURNS
</para>
<informaltable><tgroup cols="2"><tbody><row><entry
 align="char">
<para>0</para>
</entry><entry
 align="char">
<para>The function was completed without errors.</para>
</entry>
 </row><row><entry
 align="char">
<para>-EBUSY</para>
</entry><entry
 align="char">
<para>No more section feeds available.</para>
</entry>
 </row><row><entry
 align="char">
<para>-ENOSYS</para>
</entry><entry
 align="char">
<para>The command is not implemented.</para>
</entry>
 </row><row><entry
 align="char">
<para>-EINVAL</para>
</entry><entry
 align="char">
<para>Bad parameter.</para>
</entry>
 </row></tbody></tgroup></informaltable>

</section><section
role="subsection"><title>release_section_feed()</title>
<para>DESCRIPTION
</para>
<informaltable><tgroup cols="1"><tbody><row><entry
 align="char">
<para>Releases the resources allocated with allocate_section_feed(), including
 allocated filters. Any filtering in progress on the section feed should be stopped
 before calling this function.</para>
</entry>
 </row></tbody></tgroup></informaltable>
<para>SYNOPSIS
</para>
<informaltable><tgroup cols="1"><tbody><row><entry
 align="char">
<para>int release_section_feed(dmx_demux_t&#x22C6; demux,
 dmx_section_feed_t &#x22C6;feed);</para>
</entry>
 </row></tbody></tgroup></informaltable>
<para>PARAMETERS
</para>
<informaltable><tgroup cols="2"><tbody><row><entry
 align="char">
<para>demux_t *demux</para>
</entry><entry
 align="char">
<para>Pointer to the demux API and instance data.</para>
</entry>
 </row><row><entry
 align="char">
<para>dmx_section_feed_t
 *feed</para>
</entry><entry
 align="char">
<para>Pointer to the section feed API and instance data.</para>
</entry>
 </row></tbody></tgroup></informaltable>
<para>RETURNS
</para>
<informaltable><tgroup cols="2"><tbody><row><entry
 align="char">
<para>0</para>
</entry><entry
 align="char">
<para>The function was completed without errors.</para>
</entry>
 </row><row><entry
 align="char">
<para>-EINVAL</para>
</entry><entry
 align="char">
<para>Bad parameter.</para>
</entry>
 </row></tbody></tgroup></informaltable>

</section><section
role="subsection"><title>descramble_mac_address()</title>
<para>DESCRIPTION
</para>
<informaltable><tgroup cols="1"><tbody><row><entry
 align="char">
<para>This function runs a descrambling algorithm on the destination MAC
 address field of a DVB Datagram Section, replacing the original address
 with its un-encrypted version. Otherwise, the description on the function
 descramble_section_payload() applies also to this function.</para>
</entry>
 </row></tbody></tgroup></informaltable>
<para>SYNOPSIS
</para>
<informaltable><tgroup cols="1"><tbody><row><entry
 align="char">
<para>int descramble_mac_address(dmx_demux_t&#x22C6; demux, __u8
 &#x22C6;buffer1, size_t buffer1_length, __u8 &#x22C6;buffer2,
 size_t buffer2_length, __u16 pid);</para>
</entry>
 </row></tbody></tgroup></informaltable>
<para>PARAMETERS
</para>
<informaltable><tgroup cols="2"><tbody><row><entry
 align="char">
<para>dmx_demux_t
 *demux</para>
</entry><entry
 align="char">
<para>Pointer to the demux API and instance data.</para>
</entry>
 </row><row><entry
 align="char">
<para>__u8 *buffer1</para>
</entry><entry
 align="char">
<para>Pointer to the first byte of the section.</para>
</entry>
 </row><row><entry
 align="char">
<para>size_t buffer1_length</para>
</entry><entry
 align="char">
<para>Length of the section data, including headers and CRC,
 in buffer1.</para>
</entry>
 </row><row><entry
 align="char">
<para>__u8* buffer2</para>
</entry><entry
 align="char">
<para>Pointer to the tail of the section data, or NULL. The
 pointer has a non-NULL value if the section wraps past
 the end of a circular buffer.</para>
</entry>
 </row><row><entry
 align="char">
<para>size_t buffer2_length</para>
</entry><entry
 align="char">
<para>Length of the section data, including headers and CRC,
 in buffer2.</para>
</entry>
 </row><row><entry
 align="char">
<para>__u16 pid</para>
</entry><entry
 align="char">
<para>The PID on which the section was received. Useful
 for obtaining the descrambling key, e.g. from a DVB
 Common Access facility.</para>
</entry>
 </row></tbody></tgroup></informaltable>
<para>RETURNS
</para>
<informaltable><tgroup cols="2"><tbody><row><entry
 align="char">
<para>0</para>
</entry><entry
 align="char">
<para>The function was completed without errors.</para>
</entry>
 </row><row><entry
 align="char">
<para>-ENOSYS</para>
</entry><entry
 align="char">
<para>No descrambling facility available.</para>
</entry>
 </row><row><entry
 align="char">
<para>-EINVAL</para>
</entry><entry
 align="char">
<para>Bad parameter.</para>
</entry>
 </row></tbody></tgroup></informaltable>

</section><section
role="subsection"><title>descramble_section_payload()</title>
<para>DESCRIPTION
</para>
<informaltable><tgroup cols="1"><tbody><row><entry
 align="char">
<para>This function runs a descrambling algorithm on the payload of a DVB
 Datagram Section, replacing the original payload with its un-encrypted
 version. The function will be called from the demux API implementation;
 the API client need not call this function directly. Section-level scrambling
 algorithms are currently standardized only for DVB-RCC (return channel
 over 2-directional cable TV network) systems. For all other DVB networks,
 encryption schemes are likely to be proprietary to each data broadcaster. Thus,
 it is expected that this function pointer will have the value of NULL (i.e.,
 function not available) in most demux API implementations. Nevertheless, it
 should be possible to use the function pointer as a hook for dynamically adding
 a &#8220;plug-in&#8221; descrambling facility to a demux driver.</para>
</entry>
 </row><row><entry
 align="char">
<para>While this function is not needed with hardware-based section descrambling,
 the descramble_section_payload function pointer can be used to override the
 default hardware-based descrambling algorithm: if the function pointer has a
 non-NULL value, the corresponding function should be used instead of any
 descrambling hardware.</para>
</entry>
 </row></tbody></tgroup></informaltable>
<para>SYNOPSIS
</para>
<informaltable><tgroup cols="1"><tbody><row><entry
 align="char">
<para>int descramble_section_payload(dmx_demux_t&#x22C6; demux,
 __u8 &#x22C6;buffer1, size_t buffer1_length, __u8 &#x22C6;buffer2,
 size_t buffer2_length, __u16 pid);</para>
</entry>
 </row></tbody></tgroup></informaltable>
<para>PARAMETERS
</para>
<informaltable><tgroup cols="2"><tbody><row><entry
 align="char">
<para>dmx_demux_t
 *demux</para>
</entry><entry
 align="char">
<para>Pointer to the demux API and instance data.</para>
</entry>
 </row><row><entry
 align="char">
<para>__u8 *buffer1</para>
</entry><entry
 align="char">
<para>Pointer to the first byte of the section.</para>
</entry>
 </row><row><entry
 align="char">
<para>size_t buffer1_length</para>
</entry><entry
 align="char">
<para>Length of the section data, including headers and CRC,
 in buffer1.</para>
</entry>
 </row><row><entry
 align="char">
<para>__u8 *buffer2</para>
</entry><entry
 align="char">
<para>Pointer to the tail of the section data, or NULL. The
 pointer has a non-NULL value if the section wraps past
 the end of a circular buffer.</para>
</entry>
 </row><row><entry
 align="char">
<para>size_t buffer2_length</para>
</entry><entry
 align="char">
<para>Length of the section data, including headers and CRC,
 in buffer2.</para>
</entry>
 </row><row><entry
 align="char">
<para>__u16 pid</para>
</entry><entry
 align="char">
<para>The PID on which the section was received. Useful
 for obtaining the descrambling key, e.g. from a DVB
 Common Access facility.</para>
</entry>
 </row></tbody></tgroup></informaltable>
<para>RETURNS
</para>
<informaltable><tgroup cols="2"><tbody><row><entry
 align="char">
<para>0</para>
</entry><entry
 align="char">
<para>The function was completed without errors.</para>
</entry>
 </row><row><entry
 align="char">
<para>-ENOSYS</para>
</entry><entry
 align="char">
<para>No descrambling facility available.</para>
</entry>
 </row><row><entry
 align="char">
<para>-EINVAL</para>
</entry><entry
 align="char">
<para>Bad parameter.</para>
</entry>
 </row></tbody></tgroup></informaltable>

</section><section
role="subsection"><title>add_frontend()</title>
<para>DESCRIPTION
</para>
<informaltable><tgroup cols="1"><tbody><row><entry
 align="char">
<para>Registers a connectivity between a demux and a front-end, i.e., indicates that
 the demux can be connected via a call to connect_frontend() to use the given
 front-end as a TS source. The client of this function has to allocate dynamic or
 static memory for the frontend structure and initialize its fields before calling
 this function. This function is normally called during the driver initialization.
 The caller must not free the memory of the frontend struct before successfully
 calling remove_frontend().</para>
</entry>
 </row></tbody></tgroup></informaltable>
<para>SYNOPSIS
</para>
<informaltable><tgroup cols="1"><tbody><row><entry
 align="char">
<para>int add_frontend(dmx_demux_t &#x22C6;demux, dmx_frontend_t
 &#x22C6;frontend);</para>
</entry>
 </row></tbody></tgroup></informaltable>
<para>PARAMETERS
</para>
<informaltable><tgroup cols="2"><tbody><row><entry
 align="char">
<para>dmx_demux_t*
 demux</para>
</entry><entry
 align="char">
<para>Pointer to the demux API and instance data.</para>
</entry>
 </row><row><entry
 align="char">
<para>dmx_frontend_t*
 frontend</para>
</entry><entry
 align="char">
<para>Pointer to the front-end instance data.</para>
</entry>
 </row></tbody></tgroup></informaltable>
<para>RETURNS
</para>
<informaltable><tgroup cols="2"><tbody><row><entry
 align="char">
<para>0</para>
</entry><entry
 align="char">
<para>The function was completed without errors.</para>
</entry>
 </row><row><entry
 align="char">
<para>-EEXIST</para>
</entry><entry
 align="char">
<para>A front-end with the same value of the id field already
 registered.</para>
</entry>
 </row><row><entry
 align="char">
<para>-EINUSE</para>
</entry><entry
 align="char">
<para>The demux is in use.</para>
</entry>
 </row><row><entry
 align="char">
<para>-ENOMEM</para>
</entry><entry
 align="char">
<para>No more front-ends can be added.</para>
</entry>
 </row><row><entry
 align="char">
<para>-EINVAL</para>
</entry><entry
 align="char">
<para>Bad parameter.</para>
</entry>
 </row></tbody></tgroup></informaltable>

</section><section
role="subsection"><title>remove_frontend()</title>
<para>DESCRIPTION
</para>
<informaltable><tgroup cols="1"><tbody><row><entry
 align="char">
<para>Indicates that the given front-end, registered by a call to add_frontend(), can
 no longer be connected as a TS source by this demux. The function should be
 called when a front-end driver or a demux driver is removed from the system.
 If the front-end is in use, the function fails with the return value of -EBUSY.
 After successfully calling this function, the caller can free the memory of
 the frontend struct if it was dynamically allocated before the add_frontend()
 operation.</para>
</entry>
 </row></tbody></tgroup></informaltable>
<para>SYNOPSIS
</para>
<informaltable><tgroup cols="1"><tbody><row><entry
 align="char">
<para>int remove_frontend(dmx_demux_t&#x22C6; demux,
 dmx_frontend_t&#x22C6; frontend);</para>
</entry>
 </row></tbody></tgroup></informaltable>
<para>PARAMETERS
</para>
<informaltable><tgroup cols="2"><tbody><row><entry
 align="char">
<para>dmx_demux_t*
 demux</para>
</entry><entry
 align="char">
<para>Pointer to the demux API and instance data.</para>
</entry>
 </row><row><entry
 align="char">
<para>dmx_frontend_t*
 frontend</para>
</entry><entry
 align="char">
<para>Pointer to the front-end instance data.</para>
</entry>
 </row></tbody></tgroup></informaltable>
<para>RETURNS
</para>
<informaltable><tgroup cols="2"><tbody><row><entry
 align="char">
<para>0</para>
</entry><entry
 align="char">
<para>The function was completed without errors.</para>
</entry>
 </row><row><entry
 align="char">
<para>-EINVAL</para>
</entry><entry
 align="char">
<para>Bad parameter.</para>
</entry>
 </row><row><entry
 align="char">
<para>-EBUSY</para>
</entry><entry
 align="char">
<para>The front-end is in use, i.e. a call to connect_frontend()
 has not been followed by a call to disconnect_frontend().</para>
</entry>
 </row></tbody></tgroup></informaltable>

</section><section
role="subsection"><title>get_frontends()</title>
<para>DESCRIPTION
</para>
<informaltable><tgroup cols="1"><tbody><row><entry
 align="char">
<para>Provides the APIs of the front-ends that have been registered for this demux.
 Any of the front-ends obtained with this call can be used as a parameter for
 connect_frontend().</para>
</entry>
 </row><row><entry
 align="char">
<para>The include file demux.h contains the macro DMX_FE_ENTRY() for
 converting an element of the generic type struct list_head* to the type
 dmx_frontend_t*. The caller must not free the memory of any of the elements
 obtained via this function call.</para>
</entry>
 </row></tbody></tgroup></informaltable>
<para>SYNOPSIS
</para>
<informaltable><tgroup cols="1"><tbody><row><entry
 align="char">
<para>struct list_head&#x22C6; get_frontends(dmx_demux_t&#x22C6; demux);</para>
</entry>
 </row></tbody></tgroup></informaltable>
<para>PARAMETERS
</para>
<informaltable><tgroup cols="2"><tbody><row><entry
 align="char">
<para>dmx_demux_t*
 demux</para>
</entry><entry
 align="char">
<para>Pointer to the demux API and instance data.</para>
</entry>
 </row></tbody></tgroup></informaltable>
<para>RETURNS
</para>
<informaltable><tgroup cols="2"><tbody><row><entry
 align="char">
<para>dmx_demux_t*</para>
</entry><entry
 align="char">
<para>A list of front-end interfaces, or NULL in the case of an
 empty list.</para>
</entry>
 </row></tbody></tgroup></informaltable>

</section><section
role="subsection"><title>connect_frontend()</title>
<para>DESCRIPTION
</para>
<informaltable><tgroup cols="1"><tbody><row><entry
 align="char">
<para>Connects the TS output of the front-end to the input of the demux. A demux
 can only be connected to a front-end registered to the demux with the function
 add_frontend().</para>
</entry>
 </row><row><entry
 align="char">
<para>It may or may not be possible to connect multiple demuxes to the same
 front-end, depending on the capabilities of the HW platform. When not used,
 the front-end should be released by calling disconnect_frontend().</para>
</entry>
 </row></tbody></tgroup></informaltable>
<para>SYNOPSIS
</para>
<informaltable><tgroup cols="1"><tbody><row><entry
 align="char">
<para>int connect_frontend(dmx_demux_t&#x22C6; demux,
 dmx_frontend_t&#x22C6; frontend);</para>
</entry>
 </row></tbody></tgroup></informaltable>
<para>PARAMETERS
</para>
<informaltable><tgroup cols="2"><tbody><row><entry
 align="char">
<para>dmx_demux_t*
 demux</para>
</entry><entry
 align="char">
<para>Pointer to the demux API and instance data.</para>
</entry>
 </row><row><entry
 align="char">
<para>dmx_frontend_t*
 frontend</para>
</entry><entry
 align="char">
<para>Pointer to the front-end instance data.</para>
</entry>
 </row></tbody></tgroup></informaltable>
<para>RETURNS
</para>
<informaltable><tgroup cols="2"><tbody><row><entry
 align="char">
<para>0</para>
</entry><entry
 align="char">
<para>The function was completed without errors.</para>
</entry>
 </row><row><entry
 align="char">
<para>-EINVAL</para>
</entry><entry
 align="char">
<para>Bad parameter.</para>
</entry>
 </row><row><entry
 align="char">
<para>-EBUSY</para>
</entry><entry
 align="char">
<para>The front-end is in use.</para>
</entry>
 </row></tbody></tgroup></informaltable>

</section><section
role="subsection"><title>disconnect_frontend()</title>
<para>DESCRIPTION
</para>
<informaltable><tgroup cols="1"><tbody><row><entry
 align="char">
<para>Disconnects the demux and a front-end previously connected by a
 connect_frontend() call.</para>
</entry>
 </row></tbody></tgroup></informaltable>
<para>SYNOPSIS
</para>
<informaltable><tgroup cols="1"><tbody><row><entry
 align="char">
<para>int disconnect_frontend(dmx_demux_t&#x22C6; demux);</para>
</entry>
 </row></tbody></tgroup></informaltable>
<para>PARAMETERS
</para>
<informaltable><tgroup cols="2"><tbody><row><entry
 align="char">
<para>dmx_demux_t*
 demux</para>
</entry><entry
 align="char">
<para>Pointer to the demux API and instance data.</para>
</entry>
 </row></tbody></tgroup></informaltable>
<para>RETURNS
</para>
<informaltable><tgroup cols="2"><tbody><row><entry
 align="char">
<para>0</para>
</entry><entry
 align="char">
<para>The function was completed without errors.</para>
</entry>
 </row><row><entry
 align="char">
<para>-EINVAL</para>
</entry><entry
 align="char">
<para>Bad parameter.</para>
</entry>
 </row></tbody></tgroup></informaltable>
 </section></section>
<section id="demux_callback_api">
<title>Demux Callback API</title>
<para>This kernel-space API comprises the callback functions that deliver filtered data to the
demux client. Unlike the other APIs, these API functions are provided by the client and called
from the demux code.
</para>
<para>The function pointers of this abstract interface are not packed into a structure as in the
other demux APIs, because the callback functions are registered and used independent
of each other. As an example, it is possible for the API client to provide several
callback functions for receiving TS packets and no callbacks for PES packets or
sections.
</para>
<para>The functions that implement the callback API need not be re-entrant: when a demux
driver calls one of these functions, the driver is not allowed to call the function again before
the original call returns. If a callback is triggered by a hardware interrupt, it is recommended
to use the Linux &#8220;bottom half&#8221; mechanism or start a tasklet instead of making the callback
function call directly from a hardware interrupt.
</para>

<section
role="subsection"><title>dmx_ts_cb()</title>
<para>DESCRIPTION
</para>
<informaltable><tgroup cols="1"><tbody><row><entry
 align="char">
<para>This function, provided by the client of the demux API, is called from the
 demux code. The function is only called when filtering on this TS feed has
 been enabled using the start_filtering() function.</para>
</entry>
 </row><row><entry
 align="char">
<para>Any TS packets that match the filter settings are copied to a circular buffer. The
 filtered TS packets are delivered to the client using this callback function. The
 size of the circular buffer is controlled by the circular_buffer_size parameter
 of the set() function in the TS Feed API. It is expected that the buffer1 and
 buffer2 callback parameters point to addresses within the circular buffer, but
 other implementations are also possible. Note that the called party should not
 try to free the memory the buffer1 and buffer2 parameters point to.</para>
</entry>
 </row><row><entry
 align="char">
<para>When this function is called, the buffer1 parameter typically points to the
 start of the first undelivered TS packet within a circular buffer. The buffer2
 buffer parameter is normally NULL, except when the received TS packets have
 crossed the last address of the circular buffer and &#8221;wrapped&#8221; to the beginning
 of the buffer. In the latter case the buffer1 parameter would contain an address
 within the circular buffer, while the buffer2 parameter would contain the first
 address of the circular buffer.</para>
</entry>
 </row><row><entry
 align="char">
<para>The number of bytes delivered with this function (i.e. buffer1_length +
 buffer2_length) is usually equal to the value of callback_length parameter
 given in the set() function, with one exception: if a timeout occurs before
 receiving callback_length bytes of TS data, any undelivered packets are
 immediately delivered to the client by calling this function. The timeout
 duration is controlled by the set() function in the TS Feed API.</para>
</entry>
 </row><row><entry
 align="char">
<para>If a TS packet is received with errors that could not be fixed by the TS-level
 forward error correction (FEC), the Transport_error_indicator flag of the TS
 packet header should be set. The TS packet should not be discarded, as
 the error can possibly be corrected by a higher layer protocol. If the called
 party is slow in processing the callback, it is possible that the circular buffer
 eventually fills up. If this happens, the demux driver should discard any TS
 packets received while the buffer is full. The error should be indicated to the
 client on the next callback by setting the success parameter to the value of
 DMX_OVERRUN_ERROR.</para>
</entry>
 </row><row><entry
 align="char">
<para>The type of data returned to the callback can be selected by the new
 function int (*set_type) (struct dmx_ts_feed_s* feed, int type, dmx_ts_pes_t
 pes_type) which is part of the dmx_ts_feed_s struct (also cf. to the
 include file ost/demux.h) The type parameter decides if the raw TS packet
 (TS_PACKET) or just the payload (TS_PACKET&#8212;TS_PAYLOAD_ONLY)
 should be returned. If additionally the TS_DECODER bit is set the stream
 will also be sent to the hardware MPEG decoder. In this case, the second
 flag decides as what kind of data the stream should be interpreted. The
 possible choices are one of DMX_TS_PES_AUDIO, DMX_TS_PES_VIDEO,
 DMX_TS_PES_TELETEXT, DMX_TS_PES_SUBTITLE,
 DMX_TS_PES_PCR, or DMX_TS_PES_OTHER.</para>
</entry>
 </row></tbody></tgroup></informaltable>
<para>SYNOPSIS
</para>
<informaltable><tgroup cols="1"><tbody><row><entry
 align="char">
<para>int dmx_ts_cb(__u8&#x22C6; buffer1, size_t buffer1_length,
 __u8&#x22C6; buffer2, size_t buffer2_length, dmx_ts_feed_t&#x22C6;
 source, dmx_success_t success);</para>
</entry>
 </row></tbody></tgroup></informaltable>
<para>PARAMETERS
</para>
<informaltable><tgroup cols="2"><tbody><row><entry
 align="char">
<para>__u8* buffer1</para>
</entry><entry
 align="char">
<para>Pointer to the start of the filtered TS packets.</para>
</entry>
 </row><row><entry
 align="char">
<para>size_t buffer1_length</para>
</entry><entry
 align="char">
<para>Length of the TS data in buffer1.</para>
</entry>
 </row><row><entry
 align="char">
<para>__u8* buffer2</para>
</entry><entry
 align="char">
<para>Pointer to the tail of the filtered TS packets, or NULL.</para>
</entry>
 </row><row><entry
 align="char">
<para>size_t buffer2_length</para>
</entry><entry
 align="char">
<para>Length of the TS data in buffer2.</para>
</entry>
 </row><row><entry
 align="char">
<para>dmx_ts_feed_t*
 source</para>
</entry><entry
 align="char">
<para>Indicates which TS feed is the source of the callback.</para>
</entry>
 </row><row><entry
 align="char">
<para>dmx_success_t
 success</para>
</entry><entry
 align="char">
<para>Indicates if there was an error in TS reception.</para>
</entry>
 </row></tbody></tgroup></informaltable>
<para>RETURNS
</para>
<informaltable><tgroup cols="2"><tbody><row><entry
 align="char">
<para>0</para>
</entry><entry
 align="char">
<para>Continue filtering.</para>
</entry>
 </row><row><entry
 align="char">
<para>-1</para>
</entry><entry
 align="char">
<para>Stop filtering - has the same effect as a call to
 stop_filtering() on the TS Feed API.</para>
</entry>
 </row></tbody></tgroup></informaltable>

</section><section
role="subsection"><title>dmx_section_cb()</title>
<para>DESCRIPTION
</para>
<informaltable><tgroup cols="1"><tbody><row><entry
 align="char">
<para>This function, provided by the client of the demux API, is called from the
 demux code. The function is only called when filtering of sections has been
 enabled using the function start_filtering() of the section feed API. When the
 demux driver has received a complete section that matches at least one section
 filter, the client is notified via this callback function. Normally this function is
 called for each received section; however, it is also possible to deliver multiple
 sections with one callback, for example when the system load is high. If an
 error occurs while receiving a section, this function should be called with
 the corresponding error type set in the success field, whether or not there is
 data to deliver. The Section Feed implementation should maintain a circular
 buffer for received sections. However, this is not necessary if the Section Feed
 API is implemented as a client of the TS Feed API, because the TS Feed
 implementation then buffers the received data. The size of the circular buffer
 can be configured using the set() function in the Section Feed API. If there
 is no room in the circular buffer when a new section is received, the section
 must be discarded. If this happens, the value of the success parameter should
 be DMX_OVERRUN_ERROR on the next callback.</para>
</entry>
 </row></tbody></tgroup></informaltable>
<para>SYNOPSIS
</para>
<informaltable><tgroup cols="1"><tbody><row><entry
 align="char">
<para>int dmx_section_cb(__u8&#x22C6; buffer1, size_t
 buffer1_length, __u8&#x22C6; buffer2, size_t
 buffer2_length, dmx_section_filter_t&#x22C6; source,
 dmx_success_t success);</para>
</entry>
 </row></tbody></tgroup></informaltable>
<para>PARAMETERS
</para>
<informaltable><tgroup cols="2"><tbody><row><entry
 align="char">
<para>__u8* buffer1</para>
</entry><entry
 align="char">
<para>Pointer to the start of the filtered section, e.g. within the
 circular buffer of the demux driver.</para>
</entry>
 </row><row><entry
 align="char">
<para>size_t buffer1_length</para>
</entry><entry
 align="char">
<para>Length of the filtered section data in buffer1, including
 headers and CRC.</para>
</entry>
 </row><row><entry
 align="char">
<para>__u8* buffer2</para>
</entry><entry
 align="char">
<para>Pointer to the tail of the filtered section data, or NULL.
 Useful to handle the wrapping of a circular buffer.</para>
</entry>
 </row><row><entry
 align="char">
<para>size_t buffer2_length</para>
</entry><entry
 align="char">
<para>Length of the filtered section data in buffer2, including
 headers and CRC.</para>
</entry>
 </row><row><entry
 align="char">
<para>dmx_section_filter_t*
 filter</para>
</entry><entry
 align="char">
<para>Indicates the filter that triggered the callback.</para>
</entry>
 </row><row><entry
 align="char">
<para>dmx_success_t
 success</para>
</entry><entry
 align="char">
<para>Indicates if there was an error in section reception.</para>
</entry>
 </row></tbody></tgroup></informaltable>
<para>RETURNS
</para>
<informaltable><tgroup cols="2"><tbody><row><entry
 align="char">
<para>0</para>
</entry><entry
 align="char">
<para>Continue filtering.</para>
</entry>
 </row><row><entry
 align="char">
<para>-1</para>
</entry><entry
 align="char">
<para>Stop filtering - has the same effect as a call to
 stop_filtering() on the Section Feed API.</para>
</entry>
 </row></tbody></tgroup></informaltable>
 </section></section>
<section id="ts_feed_api">
<title>TS Feed API</title>
<para>A TS feed is typically mapped to a hardware PID filter on the demux chip.
Using this API, the client can set the filtering properties to start/stop filtering TS
packets on a particular TS feed. The API is defined as an abstract interface of the type
dmx_ts_feed_t.
</para>
<para>The functions that implement the interface should be defined static or module private. The
client can get the handle of a TS feed API by calling the function allocate_ts_feed() in the
demux API.
</para>

<section
role="subsection"><title>set()</title>
<para>DESCRIPTION
</para>
<informaltable><tgroup cols="1"><tbody><row><entry
 align="char">
<para>This function sets the parameters of a TS feed. Any filtering in progress on the
 TS feed must be stopped before calling this function.</para>
</entry>
 </row></tbody></tgroup></informaltable>
<para>SYNOPSIS
</para>
<informaltable><tgroup cols="1"><tbody><row><entry
 align="char">
<para>int set ( dmx_ts_feed_t&#x22C6; feed, __u16 pid, size_t
 callback_length, size_t circular_buffer_size, int
 descramble, struct timespec timeout);</para>
</entry>
 </row></tbody></tgroup></informaltable>
<para>PARAMETERS
</para>
<informaltable><tgroup cols="2"><tbody><row><entry
 align="char">
<para>dmx_ts_feed_t* feed</para>
</entry><entry
 align="char">
<para>Pointer to the TS feed API and instance data.</para>
</entry>
 </row><row><entry
 align="char">
<para>__u16 pid</para>
</entry><entry
 align="char">
<para>PID value to filter. Only the TS packets carrying the
 specified PID will be passed to the API client.</para>
</entry>
 </row><row><entry
 align="char">
<para>size_t
 callback_length</para>
</entry><entry
 align="char">
<para>Number of bytes to deliver with each call to the
 dmx_ts_cb() callback function. The value of this
 parameter should be a multiple of 188.</para>
</entry>
 </row><row><entry
 align="char">
<para>size_t
 circular_buffer_size</para>
</entry><entry
 align="char">
<para>Size of the circular buffer for the filtered TS packets.</para>
</entry>
 </row><row><entry
 align="char">
<para>int descramble</para>
</entry><entry
 align="char">
<para>If non-zero, descramble the filtered TS packets.</para>
</entry>
 </row><row><entry
 align="char">
<para>struct timespec
 timeout</para>
</entry><entry
 align="char">
<para>Maximum time to wait before delivering received TS
 packets to the client.</para>
</entry>
 </row></tbody></tgroup></informaltable>
<para>RETURNS
</para>
<informaltable><tgroup cols="2"><tbody><row><entry
 align="char">
<para>0</para>
</entry><entry
 align="char">
<para>The function was completed without errors.</para>
</entry>
 </row><row><entry
 align="char">
<para>-ENOMEM</para>
</entry><entry
 align="char">
<para>Not enough memory for the requested buffer size.</para>
</entry>
 </row><row><entry
 align="char">
<para>-ENOSYS</para>
</entry><entry
 align="char">
<para>No descrambling facility available for TS.</para>
</entry>
 </row><row><entry
 align="char">
<para>-EINVAL</para>
</entry><entry
 align="char">
<para>Bad parameter.</para>
</entry>
 </row></tbody></tgroup></informaltable>

</section><section
role="subsection"><title>start_filtering()</title>
<para>DESCRIPTION
</para>
<informaltable><tgroup cols="1"><tbody><row><entry
 align="char">
<para>Starts filtering TS packets on this TS feed, according to its settings. The PID
 value to filter can be set by the API client. All matching TS packets are
 delivered asynchronously to the client, using the callback function registered
 with allocate_ts_feed().</para>
</entry>
 </row></tbody></tgroup></informaltable>
<para>SYNOPSIS
</para>
<informaltable><tgroup cols="1"><tbody><row><entry
 align="char">
<para>int start_filtering(dmx_ts_feed_t&#x22C6; feed);</para>
</entry>
 </row></tbody></tgroup></informaltable>
<para>PARAMETERS
</para>
<informaltable><tgroup cols="2"><tbody><row><entry
 align="char">
<para>dmx_ts_feed_t* feed</para>
</entry><entry
 align="char">
<para>Pointer to the TS feed API and instance data.</para>
</entry>
 </row></tbody></tgroup></informaltable>
<para>RETURNS
</para>
<informaltable><tgroup cols="2"><tbody><row><entry
 align="char">
<para>0</para>
</entry><entry
 align="char">
<para>The function was completed without errors.</para>
</entry>
 </row><row><entry
 align="char">
<para>-EINVAL</para>
</entry><entry
 align="char">
<para>Bad parameter.</para>
</entry>
 </row></tbody></tgroup></informaltable>

</section><section
role="subsection"><title>stop_filtering()</title>
<para>DESCRIPTION
</para>
<informaltable><tgroup cols="1"><tbody><row><entry
 align="char">
<para>Stops filtering TS packets on this TS feed.</para>
</entry>
 </row></tbody></tgroup></informaltable>
<para>SYNOPSIS
</para>
<informaltable><tgroup cols="1"><tbody><row><entry
 align="char">
<para>int stop_filtering(dmx_ts_feed_t&#x22C6; feed);</para>
</entry>
 </row></tbody></tgroup></informaltable>
<para>PARAMETERS
</para>
<informaltable><tgroup cols="2"><tbody><row><entry
 align="char">
<para>dmx_ts_feed_t* feed</para>
</entry><entry
 align="char">
<para>Pointer to the TS feed API and instance data.</para>
</entry>
 </row></tbody></tgroup></informaltable>
<para>RETURNS
</para>
<informaltable><tgroup cols="2"><tbody><row><entry
 align="char">
<para>0</para>
</entry><entry
 align="char">
<para>The function was completed without errors.</para>
</entry>
 </row><row><entry
 align="char">
<para>-EINVAL</para>
</entry><entry
 align="char">
<para>Bad parameter.</para>
</entry>
 </row></tbody></tgroup></informaltable>
 </section></section>
<section id="section_feed_api">
<title>Section Feed API</title>
<para>A section feed is a resource consisting of a PID filter and a set of section filters. Using this
API, the client can set the properties of a section feed and to start/stop filtering. The API is
defined as an abstract interface of the type dmx_section_feed_t. The functions that implement
the interface should be defined static or module private. The client can get the handle of
a section feed API by calling the function allocate_section_feed() in the demux
API.
</para>
<para>On demux platforms that provide section filtering in hardware, the Section Feed API
implementation provides a software wrapper for the demux hardware. Other platforms may
support only PID filtering in hardware, requiring that TS packets are converted to sections in
software. In the latter case the Section Feed API implementation can be a client of the TS
Feed API.
</para>

</section>
<section id="kdapi_set">
<title>set()</title>
<para>DESCRIPTION
</para>
<informaltable><tgroup cols="1"><tbody><row><entry
 align="char">
<para>This function sets the parameters of a section feed. Any filtering in progress on
 the section feed must be stopped before calling this function. If descrambling
 is enabled, the payload_scrambling_control and address_scrambling_control
 fields of received DVB datagram sections should be observed. If either one is
 non-zero, the section should be descrambled either in hardware or using the
 functions descramble_mac_address() and descramble_section_payload() of the
 demux API. Note that according to the MPEG-2 Systems specification, only
 the payloads of private sections can be scrambled while the rest of the section
 data must be sent in the clear.</para>
</entry>
 </row></tbody></tgroup></informaltable>
<para>SYNOPSIS
</para>
<informaltable><tgroup cols="1"><tbody><row><entry
 align="char">
<para>int set(dmx_section_feed_t&#x22C6; feed, __u16 pid, size_t
 circular_buffer_size, int descramble, int
 check_crc);</para>
</entry>
 </row></tbody></tgroup></informaltable>
<para>PARAMETERS
</para>
<informaltable><tgroup cols="2"><tbody><row><entry
 align="char">
<para>dmx_section_feed_t*
 feed</para>
</entry><entry
 align="char">
<para>Pointer to the section feed API and instance data.</para>
</entry>
 </row><row><entry
 align="char">
<para>__u16 pid</para>
</entry><entry
 align="char">
<para>PID value to filter; only the TS packets carrying the
 specified PID will be accepted.</para>
</entry>
 </row><row><entry
 align="char">
<para>size_t
 circular_buffer_size</para>
</entry><entry
 align="char">
<para>Size of the circular buffer for filtered sections.</para>
</entry>
 </row><row><entry
 align="char">
<para>int descramble</para>
</entry><entry
 align="char">
<para>If non-zero, descramble any sections that are scrambled.</para>
</entry>
 </row><row><entry
 align="char">
<para>int check_crc</para>
</entry><entry
 align="char">
<para>If non-zero, check the CRC values of filtered sections.</para>
</entry>
 </row></tbody></tgroup></informaltable>
<para>RETURNS
</para>
<informaltable><tgroup cols="2"><tbody><row><entry
 align="char">
<para>0</para>
</entry><entry
 align="char">
<para>The function was completed without errors.</para>
</entry>
 </row><row><entry
 align="char">
<para>-ENOMEM</para>
</entry><entry
 align="char">
<para>Not enough memory for the requested buffer size.</para>
</entry>
 </row><row><entry
 align="char">
<para>-ENOSYS</para>
</entry><entry
 align="char">
<para>No descrambling facility available for sections.</para>
</entry>
 </row><row><entry
 align="char">
<para>-EINVAL</para>
</entry><entry
 align="char">
<para>Bad parameters.</para>
</entry>
 </row></tbody></tgroup></informaltable>

</section><section
role="subsection"><title>allocate_filter()</title>
<para>DESCRIPTION
</para>
<informaltable><tgroup cols="1"><tbody><row><entry
 align="char">
<para>This function is used to allocate a section filter on the demux. It should only be
 called when no filtering is in progress on this section feed. If a filter cannot be
 allocated, the function fails with -ENOSPC. See in section ?? for the format of
 the section filter.</para>
</entry>
 </row><row><entry
 align="char">
<para>The bitfields filter_mask and filter_value should only be modified when no
 filtering is in progress on this section feed. filter_mask controls which bits of
 filter_value are compared with the section headers/payload. On a binary value
 of 1 in filter_mask, the corresponding bits are compared. The filter only accepts
 sections that are equal to filter_value in all the tested bit positions. Any changes
 to the values of filter_mask and filter_value are guaranteed to take effect only
 when the start_filtering() function is called next time. The parent pointer in
 the struct is initialized by the API implementation to the value of the feed
 parameter. The priv pointer is not used by the API implementation, and can
 thus be freely utilized by the caller of this function. Any data pointed to by the
 priv pointer is available to the recipient of the dmx_section_cb() function call.</para>
</entry>
 </row><row><entry
 align="char">
<para>While the maximum section filter length (DMX_MAX_FILTER_SIZE) is
 currently set at 16 bytes, hardware filters of that size are not available on all
 platforms. Therefore, section filtering will often take place first in hardware,
 followed by filtering in software for the header bytes that were not covered
 by a hardware filter. The filter_mask field can be checked to determine how
 many bytes of the section filter are actually used, and if the hardware filter will
 suffice. Additionally, software-only section filters can optionally be allocated
 to clients when all hardware section filters are in use. Note that on most demux
 hardware it is not possible to filter on the section_length field of the section
 header &#8211; thus this field is ignored, even though it is included in filter_value and
 filter_mask fields.</para>
</entry>
 </row></tbody></tgroup></informaltable>
<para>SYNOPSIS
</para>
<informaltable><tgroup cols="1"><tbody><row><entry
 align="char">
<para>int allocate_filter(dmx_section_feed_t&#x22C6; feed,
 dmx_section_filter_t&#x22C6;&#x22C6; filter);</para>
</entry>
 </row></tbody></tgroup></informaltable>
<para>PARAMETERS
</para>
<informaltable><tgroup cols="2"><tbody><row><entry
 align="char">
<para>dmx_section_feed_t*
 feed</para>
</entry><entry
 align="char">
<para>Pointer to the section feed API and instance data.</para>
</entry>
 </row><row><entry
 align="char">
<para>dmx_section_filter_t**
 filter</para>
</entry><entry
 align="char">
<para>Pointer to the allocated filter.</para>
</entry>
 </row></tbody></tgroup></informaltable>
<para>RETURNS
</para>
<informaltable><tgroup cols="2"><tbody><row><entry
 align="char">
<para>0</para>
</entry><entry
 align="char">
<para>The function was completed without errors.</para>
</entry>
 </row><row><entry
 align="char">
<para>-ENOSPC</para>
</entry><entry
 align="char">
<para>No filters of given type and length available.</para>
</entry>
 </row><row><entry
 align="char">
<para>-EINVAL</para>
</entry><entry
 align="char">
<para>Bad parameters.</para>
</entry>
 </row></tbody></tgroup></informaltable>

</section><section
role="subsection"><title>release_filter()</title>
<para>DESCRIPTION
</para>
<informaltable><tgroup cols="1"><tbody><row><entry
 align="char">
<para>This function releases all the resources of a previously allocated section filter.
 The function should not be called while filtering is in progress on this section
 feed. After calling this function, the caller should not try to dereference the
 filter pointer.</para>
</entry>
 </row></tbody></tgroup></informaltable>
<para>SYNOPSIS
</para>
<informaltable><tgroup cols="1"><tbody><row><entry
 align="char">
<para>int release_filter ( dmx_section_feed_t&#x22C6; feed,
 dmx_section_filter_t&#x22C6; filter);</para>
</entry>
 </row></tbody></tgroup></informaltable>
<para>PARAMETERS
</para>
<informaltable><tgroup cols="2"><tbody><row><entry
 align="char">
<para>dmx_section_feed_t*
 feed</para>
</entry><entry
 align="char">
<para>Pointer to the section feed API and instance data.</para>
</entry>
 </row><row><entry
 align="char">
<para>dmx_section_filter_t*
 filter</para>
</entry><entry
 align="char">
<para>I/O Pointer to the instance data of a section filter.</para>
</entry>
 </row></tbody></tgroup></informaltable>
<para>RETURNS
</para>
<informaltable><tgroup cols="2"><tbody><row><entry
 align="char">
<para>0</para>
</entry><entry
 align="char">
<para>The function was completed without errors.</para>
</entry>
 </row><row><entry
 align="char">
<para>-ENODEV</para>
</entry><entry
 align="char">
<para>No such filter allocated.</para>
</entry>
 </row><row><entry
 align="char">
<para>-EINVAL</para>
</entry><entry
 align="char">
<para>Bad parameter.</para>
</entry>
 </row></tbody></tgroup></informaltable>

</section><section
role="subsection"><title>start_filtering()</title>
<para>DESCRIPTION
</para>
<informaltable><tgroup cols="1"><tbody><row><entry
 align="char">
<para>Starts filtering sections on this section feed, according to its settings. Sections
 are first filtered based on their PID and then matched with the section
 filters allocated for this feed. If the section matches the PID filter and
 at least one section filter, it is delivered to the API client. The section
 is delivered asynchronously using the callback function registered with
 allocate_section_feed().</para>
</entry>
 </row></tbody></tgroup></informaltable>
<para>SYNOPSIS
</para>
<informaltable><tgroup cols="1"><tbody><row><entry
 align="char">
<para>int start_filtering ( dmx_section_feed_t&#x22C6; feed );</para>
</entry>
 </row></tbody></tgroup></informaltable>
<para>PARAMETERS
</para>
<informaltable><tgroup cols="2"><tbody><row><entry
 align="char">
<para>dmx_section_feed_t*
 feed</para>
</entry><entry
 align="char">
<para>Pointer to the section feed API and instance data.</para>
</entry>
 </row></tbody></tgroup></informaltable>
<para>RETURNS
</para>
<informaltable><tgroup cols="2"><tbody><row><entry
 align="char">
<para>0</para>
</entry><entry
 align="char">
<para>The function was completed without errors.</para>
</entry>
 </row><row><entry
 align="char">
<para>-EINVAL</para>
</entry><entry
 align="char">
<para>Bad parameter.</para>
</entry>
 </row></tbody></tgroup></informaltable>

</section><section
role="subsection"><title>stop_filtering()</title>
<para>DESCRIPTION
</para>
<informaltable><tgroup cols="1"><tbody><row><entry
 align="char">
<para>Stops filtering sections on this section feed. Note that any changes to the
 filtering parameters (filter_value, filter_mask, etc.) should only be made when
 filtering is stopped.</para>
</entry>
 </row></tbody></tgroup></informaltable>
<para>SYNOPSIS
</para>
<informaltable><tgroup cols="1"><tbody><row><entry
 align="char">
<para>int stop_filtering ( dmx_section_feed_t&#x22C6; feed );</para>
</entry>
 </row></tbody></tgroup></informaltable>
<para>PARAMETERS
</para>
<informaltable><tgroup cols="2"><tbody><row><entry
 align="char">
<para>dmx_section_feed_t*
 feed</para>
</entry><entry
 align="char">
<para>Pointer to the section feed API and instance data.</para>
</entry>
 </row></tbody></tgroup></informaltable>
<para>RETURNS
</para>
<informaltable><tgroup cols="2"><tbody><row><entry
 align="char">
<para>0</para>
</entry><entry
 align="char">
<para>The function was completed without errors.</para>
</entry>
 </row><row><entry
 align="char">
<para>-EINVAL</para>
</entry><entry
 align="char">
<para>Bad parameter.</para>
</entry>
 </row></tbody></tgroup></informaltable>

</section>