demux.h 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301
  1. /*
  2. * demux.h
  3. *
  4. * Copyright (c) 2002 Convergence GmbH
  5. *
  6. * based on code:
  7. * Copyright (c) 2000 Nokia Research Center
  8. * Tampere, FINLAND
  9. *
  10. * This program is free software; you can redistribute it and/or
  11. * modify it under the terms of the GNU Lesser General Public License
  12. * as published by the Free Software Foundation; either version 2.1
  13. * of the License, or (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU Lesser General Public License
  21. * along with this program; if not, write to the Free Software
  22. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  23. *
  24. */
  25. #ifndef __DEMUX_H
  26. #define __DEMUX_H
  27. #include <linux/types.h>
  28. #include <linux/errno.h>
  29. #include <linux/list.h>
  30. #include <linux/time.h>
  31. /*--------------------------------------------------------------------------*/
  32. /* Common definitions */
  33. /*--------------------------------------------------------------------------*/
  34. /*
  35. * DMX_MAX_FILTER_SIZE: Maximum length (in bytes) of a section/PES filter.
  36. */
  37. #ifndef DMX_MAX_FILTER_SIZE
  38. #define DMX_MAX_FILTER_SIZE 18
  39. #endif
  40. /*
  41. * DMX_MAX_SECFEED_SIZE: Maximum length (in bytes) of a private section feed filter.
  42. */
  43. #ifndef DMX_MAX_SECFEED_SIZE
  44. #define DMX_MAX_SECFEED_SIZE 4096
  45. #endif
  46. /*
  47. * enum dmx_success: Success codes for the Demux Callback API.
  48. */
  49. enum dmx_success {
  50. DMX_OK = 0, /* Received Ok */
  51. DMX_LENGTH_ERROR, /* Incorrect length */
  52. DMX_OVERRUN_ERROR, /* Receiver ring buffer overrun */
  53. DMX_CRC_ERROR, /* Incorrect CRC */
  54. DMX_FRAME_ERROR, /* Frame alignment error */
  55. DMX_FIFO_ERROR, /* Receiver FIFO overrun */
  56. DMX_MISSED_ERROR /* Receiver missed packet */
  57. } ;
  58. /*--------------------------------------------------------------------------*/
  59. /* TS packet reception */
  60. /*--------------------------------------------------------------------------*/
  61. /* TS filter type for set() */
  62. #define TS_PACKET 1 /* send TS packets (188 bytes) to callback (default) */
  63. #define TS_PAYLOAD_ONLY 2 /* in case TS_PACKET is set, only send the TS
  64. payload (<=184 bytes per packet) to callback */
  65. #define TS_DECODER 4 /* send stream to built-in decoder (if present) */
  66. /* PES type for filters which write to built-in decoder */
  67. /* these should be kept identical to the types in dmx.h */
  68. enum dmx_ts_pes
  69. { /* also send packets to decoder (if it exists) */
  70. DMX_TS_PES_AUDIO0,
  71. DMX_TS_PES_VIDEO0,
  72. DMX_TS_PES_TELETEXT0,
  73. DMX_TS_PES_SUBTITLE0,
  74. DMX_TS_PES_PCR0,
  75. DMX_TS_PES_AUDIO1,
  76. DMX_TS_PES_VIDEO1,
  77. DMX_TS_PES_TELETEXT1,
  78. DMX_TS_PES_SUBTITLE1,
  79. DMX_TS_PES_PCR1,
  80. DMX_TS_PES_AUDIO2,
  81. DMX_TS_PES_VIDEO2,
  82. DMX_TS_PES_TELETEXT2,
  83. DMX_TS_PES_SUBTITLE2,
  84. DMX_TS_PES_PCR2,
  85. DMX_TS_PES_AUDIO3,
  86. DMX_TS_PES_VIDEO3,
  87. DMX_TS_PES_TELETEXT3,
  88. DMX_TS_PES_SUBTITLE3,
  89. DMX_TS_PES_PCR3,
  90. DMX_TS_PES_OTHER
  91. };
  92. #define DMX_TS_PES_AUDIO DMX_TS_PES_AUDIO0
  93. #define DMX_TS_PES_VIDEO DMX_TS_PES_VIDEO0
  94. #define DMX_TS_PES_TELETEXT DMX_TS_PES_TELETEXT0
  95. #define DMX_TS_PES_SUBTITLE DMX_TS_PES_SUBTITLE0
  96. #define DMX_TS_PES_PCR DMX_TS_PES_PCR0
  97. struct dmx_ts_feed {
  98. int is_filtering; /* Set to non-zero when filtering in progress */
  99. struct dmx_demux *parent; /* Back-pointer */
  100. void *priv; /* Pointer to private data of the API client */
  101. int (*set) (struct dmx_ts_feed *feed,
  102. u16 pid,
  103. int type,
  104. enum dmx_ts_pes pes_type,
  105. size_t callback_length,
  106. size_t circular_buffer_size,
  107. int descramble,
  108. struct timespec timeout);
  109. int (*start_filtering) (struct dmx_ts_feed* feed);
  110. int (*stop_filtering) (struct dmx_ts_feed* feed);
  111. };
  112. /*--------------------------------------------------------------------------*/
  113. /* Section reception */
  114. /*--------------------------------------------------------------------------*/
  115. struct dmx_section_filter {
  116. u8 filter_value [DMX_MAX_FILTER_SIZE];
  117. u8 filter_mask [DMX_MAX_FILTER_SIZE];
  118. u8 filter_mode [DMX_MAX_FILTER_SIZE];
  119. struct dmx_section_feed* parent; /* Back-pointer */
  120. void* priv; /* Pointer to private data of the API client */
  121. };
  122. struct dmx_section_feed {
  123. int is_filtering; /* Set to non-zero when filtering in progress */
  124. struct dmx_demux* parent; /* Back-pointer */
  125. void* priv; /* Pointer to private data of the API client */
  126. int check_crc;
  127. u32 crc_val;
  128. u8 *secbuf;
  129. u8 secbuf_base[DMX_MAX_SECFEED_SIZE];
  130. u16 secbufp, seclen, tsfeedp;
  131. int (*set) (struct dmx_section_feed* feed,
  132. u16 pid,
  133. size_t circular_buffer_size,
  134. int descramble,
  135. int check_crc);
  136. int (*allocate_filter) (struct dmx_section_feed* feed,
  137. struct dmx_section_filter** filter);
  138. int (*release_filter) (struct dmx_section_feed* feed,
  139. struct dmx_section_filter* filter);
  140. int (*start_filtering) (struct dmx_section_feed* feed);
  141. int (*stop_filtering) (struct dmx_section_feed* feed);
  142. };
  143. /*--------------------------------------------------------------------------*/
  144. /* Callback functions */
  145. /*--------------------------------------------------------------------------*/
  146. typedef int (*dmx_ts_cb) ( const u8 * buffer1,
  147. size_t buffer1_length,
  148. const u8 * buffer2,
  149. size_t buffer2_length,
  150. struct dmx_ts_feed* source,
  151. enum dmx_success success);
  152. typedef int (*dmx_section_cb) ( const u8 * buffer1,
  153. size_t buffer1_len,
  154. const u8 * buffer2,
  155. size_t buffer2_len,
  156. struct dmx_section_filter * source,
  157. enum dmx_success success);
  158. /*--------------------------------------------------------------------------*/
  159. /* DVB Front-End */
  160. /*--------------------------------------------------------------------------*/
  161. enum dmx_frontend_source {
  162. DMX_MEMORY_FE,
  163. DMX_FRONTEND_0,
  164. DMX_FRONTEND_1,
  165. DMX_FRONTEND_2,
  166. DMX_FRONTEND_3,
  167. DMX_STREAM_0, /* external stream input, e.g. LVDS */
  168. DMX_STREAM_1,
  169. DMX_STREAM_2,
  170. DMX_STREAM_3
  171. };
  172. struct dmx_frontend {
  173. struct list_head connectivity_list; /* List of front-ends that can
  174. be connected to a particular
  175. demux */
  176. void* priv; /* Pointer to private data of the API client */
  177. enum dmx_frontend_source source;
  178. };
  179. /*--------------------------------------------------------------------------*/
  180. /* MPEG-2 TS Demux */
  181. /*--------------------------------------------------------------------------*/
  182. /*
  183. * Flags OR'ed in the capabilites field of struct dmx_demux.
  184. */
  185. #define DMX_TS_FILTERING 1
  186. #define DMX_PES_FILTERING 2
  187. #define DMX_SECTION_FILTERING 4
  188. #define DMX_MEMORY_BASED_FILTERING 8 /* write() available */
  189. #define DMX_CRC_CHECKING 16
  190. #define DMX_TS_DESCRAMBLING 32
  191. #define DMX_SECTION_PAYLOAD_DESCRAMBLING 64
  192. #define DMX_MAC_ADDRESS_DESCRAMBLING 128
  193. /*
  194. * Demux resource type identifier.
  195. */
  196. /*
  197. * DMX_FE_ENTRY(): Casts elements in the list of registered
  198. * front-ends from the generic type struct list_head
  199. * to the type * struct dmx_frontend
  200. *.
  201. */
  202. #define DMX_FE_ENTRY(list) list_entry(list, struct dmx_frontend, connectivity_list)
  203. struct dmx_demux {
  204. u32 capabilities; /* Bitfield of capability flags */
  205. struct dmx_frontend* frontend; /* Front-end connected to the demux */
  206. struct list_head reg_list; /* List of registered demuxes */
  207. void* priv; /* Pointer to private data of the API client */
  208. int users; /* Number of users */
  209. int (*open) (struct dmx_demux* demux);
  210. int (*close) (struct dmx_demux* demux);
  211. int (*write) (struct dmx_demux* demux, const char* buf, size_t count);
  212. int (*allocate_ts_feed) (struct dmx_demux* demux,
  213. struct dmx_ts_feed** feed,
  214. dmx_ts_cb callback);
  215. int (*release_ts_feed) (struct dmx_demux* demux,
  216. struct dmx_ts_feed* feed);
  217. int (*allocate_section_feed) (struct dmx_demux* demux,
  218. struct dmx_section_feed** feed,
  219. dmx_section_cb callback);
  220. int (*release_section_feed) (struct dmx_demux* demux,
  221. struct dmx_section_feed* feed);
  222. int (*descramble_mac_address) (struct dmx_demux* demux,
  223. u8* buffer1,
  224. size_t buffer1_length,
  225. u8* buffer2,
  226. size_t buffer2_length,
  227. u16 pid);
  228. int (*descramble_section_payload) (struct dmx_demux* demux,
  229. u8* buffer1,
  230. size_t buffer1_length,
  231. u8* buffer2, size_t buffer2_length,
  232. u16 pid);
  233. int (*add_frontend) (struct dmx_demux* demux,
  234. struct dmx_frontend* frontend);
  235. int (*remove_frontend) (struct dmx_demux* demux,
  236. struct dmx_frontend* frontend);
  237. struct list_head* (*get_frontends) (struct dmx_demux* demux);
  238. int (*connect_frontend) (struct dmx_demux* demux,
  239. struct dmx_frontend* frontend);
  240. int (*disconnect_frontend) (struct dmx_demux* demux);
  241. int (*get_pes_pids) (struct dmx_demux* demux, u16 *pids);
  242. int (*get_stc) (struct dmx_demux* demux, unsigned int num,
  243. u64 *stc, unsigned int *base);
  244. };
  245. /*--------------------------------------------------------------------------*/
  246. /* Demux directory */
  247. /*--------------------------------------------------------------------------*/
  248. /*
  249. * DMX_DIR_ENTRY(): Casts elements in the list of registered
  250. * demuxes from the generic type struct list_head* to the type struct dmx_demux
  251. *.
  252. */
  253. #define DMX_DIR_ENTRY(list) list_entry(list, struct dmx_demux, reg_list)
  254. #endif /* #ifndef __DEMUX_H */