demux.h 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281
  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. #include <linux/dvb/dmx.h>
  32. /*--------------------------------------------------------------------------*/
  33. /* Common definitions */
  34. /*--------------------------------------------------------------------------*/
  35. /*
  36. * DMX_MAX_FILTER_SIZE: Maximum length (in bytes) of a section/PES filter.
  37. */
  38. #ifndef DMX_MAX_FILTER_SIZE
  39. #define DMX_MAX_FILTER_SIZE 18
  40. #endif
  41. /*
  42. * DMX_MAX_SECFEED_SIZE: Maximum length (in bytes) of a private section feed filter.
  43. */
  44. #ifndef DMX_MAX_SECTION_SIZE
  45. #define DMX_MAX_SECTION_SIZE 4096
  46. #endif
  47. #ifndef DMX_MAX_SECFEED_SIZE
  48. #define DMX_MAX_SECFEED_SIZE (DMX_MAX_SECTION_SIZE + 188)
  49. #endif
  50. /*
  51. * enum dmx_success: Success codes for the Demux Callback API.
  52. */
  53. enum dmx_success {
  54. DMX_OK = 0, /* Received Ok */
  55. DMX_LENGTH_ERROR, /* Incorrect length */
  56. DMX_OVERRUN_ERROR, /* Receiver ring buffer overrun */
  57. DMX_CRC_ERROR, /* Incorrect CRC */
  58. DMX_FRAME_ERROR, /* Frame alignment error */
  59. DMX_FIFO_ERROR, /* Receiver FIFO overrun */
  60. DMX_MISSED_ERROR /* Receiver missed packet */
  61. } ;
  62. /*--------------------------------------------------------------------------*/
  63. /* TS packet reception */
  64. /*--------------------------------------------------------------------------*/
  65. /* TS filter type for set() */
  66. #define TS_PACKET 1 /* send TS packets (188 bytes) to callback (default) */
  67. #define TS_PAYLOAD_ONLY 2 /* in case TS_PACKET is set, only send the TS
  68. payload (<=184 bytes per packet) to callback */
  69. #define TS_DECODER 4 /* send stream to built-in decoder (if present) */
  70. #define TS_DEMUX 8 /* in case TS_PACKET is set, send the TS to
  71. the demux device, not to the dvr device */
  72. /* PES type for filters which write to built-in decoder */
  73. /* these should be kept identical to the types in dmx.h */
  74. enum dmx_ts_pes
  75. { /* also send packets to decoder (if it exists) */
  76. DMX_TS_PES_AUDIO0,
  77. DMX_TS_PES_VIDEO0,
  78. DMX_TS_PES_TELETEXT0,
  79. DMX_TS_PES_SUBTITLE0,
  80. DMX_TS_PES_PCR0,
  81. DMX_TS_PES_AUDIO1,
  82. DMX_TS_PES_VIDEO1,
  83. DMX_TS_PES_TELETEXT1,
  84. DMX_TS_PES_SUBTITLE1,
  85. DMX_TS_PES_PCR1,
  86. DMX_TS_PES_AUDIO2,
  87. DMX_TS_PES_VIDEO2,
  88. DMX_TS_PES_TELETEXT2,
  89. DMX_TS_PES_SUBTITLE2,
  90. DMX_TS_PES_PCR2,
  91. DMX_TS_PES_AUDIO3,
  92. DMX_TS_PES_VIDEO3,
  93. DMX_TS_PES_TELETEXT3,
  94. DMX_TS_PES_SUBTITLE3,
  95. DMX_TS_PES_PCR3,
  96. DMX_TS_PES_OTHER
  97. };
  98. #define DMX_TS_PES_AUDIO DMX_TS_PES_AUDIO0
  99. #define DMX_TS_PES_VIDEO DMX_TS_PES_VIDEO0
  100. #define DMX_TS_PES_TELETEXT DMX_TS_PES_TELETEXT0
  101. #define DMX_TS_PES_SUBTITLE DMX_TS_PES_SUBTITLE0
  102. #define DMX_TS_PES_PCR DMX_TS_PES_PCR0
  103. struct dmx_ts_feed {
  104. int is_filtering; /* Set to non-zero when filtering in progress */
  105. struct dmx_demux *parent; /* Back-pointer */
  106. void *priv; /* Pointer to private data of the API client */
  107. int (*set) (struct dmx_ts_feed *feed,
  108. u16 pid,
  109. int type,
  110. enum dmx_ts_pes pes_type,
  111. size_t circular_buffer_size,
  112. struct timespec timeout);
  113. int (*start_filtering) (struct dmx_ts_feed* feed);
  114. int (*stop_filtering) (struct dmx_ts_feed* feed);
  115. };
  116. /*--------------------------------------------------------------------------*/
  117. /* Section reception */
  118. /*--------------------------------------------------------------------------*/
  119. struct dmx_section_filter {
  120. u8 filter_value [DMX_MAX_FILTER_SIZE];
  121. u8 filter_mask [DMX_MAX_FILTER_SIZE];
  122. u8 filter_mode [DMX_MAX_FILTER_SIZE];
  123. struct dmx_section_feed* parent; /* Back-pointer */
  124. void* priv; /* Pointer to private data of the API client */
  125. };
  126. struct dmx_section_feed {
  127. int is_filtering; /* Set to non-zero when filtering in progress */
  128. struct dmx_demux* parent; /* Back-pointer */
  129. void* priv; /* Pointer to private data of the API client */
  130. int check_crc;
  131. u32 crc_val;
  132. u8 *secbuf;
  133. u8 secbuf_base[DMX_MAX_SECFEED_SIZE];
  134. u16 secbufp, seclen, tsfeedp;
  135. int (*set) (struct dmx_section_feed* feed,
  136. u16 pid,
  137. size_t circular_buffer_size,
  138. int check_crc);
  139. int (*allocate_filter) (struct dmx_section_feed* feed,
  140. struct dmx_section_filter** filter);
  141. int (*release_filter) (struct dmx_section_feed* feed,
  142. struct dmx_section_filter* filter);
  143. int (*start_filtering) (struct dmx_section_feed* feed);
  144. int (*stop_filtering) (struct dmx_section_feed* feed);
  145. };
  146. /*--------------------------------------------------------------------------*/
  147. /* Callback functions */
  148. /*--------------------------------------------------------------------------*/
  149. typedef int (*dmx_ts_cb) ( const u8 * buffer1,
  150. size_t buffer1_length,
  151. const u8 * buffer2,
  152. size_t buffer2_length,
  153. struct dmx_ts_feed* source,
  154. enum dmx_success success);
  155. typedef int (*dmx_section_cb) ( const u8 * buffer1,
  156. size_t buffer1_len,
  157. const u8 * buffer2,
  158. size_t buffer2_len,
  159. struct dmx_section_filter * source,
  160. enum dmx_success success);
  161. /*--------------------------------------------------------------------------*/
  162. /* DVB Front-End */
  163. /*--------------------------------------------------------------------------*/
  164. enum dmx_frontend_source {
  165. DMX_MEMORY_FE,
  166. DMX_FRONTEND_0,
  167. DMX_FRONTEND_1,
  168. DMX_FRONTEND_2,
  169. DMX_FRONTEND_3,
  170. DMX_STREAM_0, /* external stream input, e.g. LVDS */
  171. DMX_STREAM_1,
  172. DMX_STREAM_2,
  173. DMX_STREAM_3
  174. };
  175. struct dmx_frontend {
  176. struct list_head connectivity_list; /* List of front-ends that can
  177. be connected to a particular
  178. demux */
  179. enum dmx_frontend_source source;
  180. };
  181. /*--------------------------------------------------------------------------*/
  182. /* MPEG-2 TS Demux */
  183. /*--------------------------------------------------------------------------*/
  184. /*
  185. * Flags OR'ed in the capabilities field of struct dmx_demux.
  186. */
  187. #define DMX_TS_FILTERING 1
  188. #define DMX_PES_FILTERING 2
  189. #define DMX_SECTION_FILTERING 4
  190. #define DMX_MEMORY_BASED_FILTERING 8 /* write() available */
  191. #define DMX_CRC_CHECKING 16
  192. #define DMX_TS_DESCRAMBLING 32
  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. void* priv; /* Pointer to private data of the API client */
  207. int (*open) (struct dmx_demux* demux);
  208. int (*close) (struct dmx_demux* demux);
  209. int (*write) (struct dmx_demux* demux, const char __user *buf, size_t count);
  210. int (*allocate_ts_feed) (struct dmx_demux* demux,
  211. struct dmx_ts_feed** feed,
  212. dmx_ts_cb callback);
  213. int (*release_ts_feed) (struct dmx_demux* demux,
  214. struct dmx_ts_feed* feed);
  215. int (*allocate_section_feed) (struct dmx_demux* demux,
  216. struct dmx_section_feed** feed,
  217. dmx_section_cb callback);
  218. int (*release_section_feed) (struct dmx_demux* demux,
  219. struct dmx_section_feed* feed);
  220. int (*add_frontend) (struct dmx_demux* demux,
  221. struct dmx_frontend* frontend);
  222. int (*remove_frontend) (struct dmx_demux* demux,
  223. struct dmx_frontend* frontend);
  224. struct list_head* (*get_frontends) (struct dmx_demux* demux);
  225. int (*connect_frontend) (struct dmx_demux* demux,
  226. struct dmx_frontend* frontend);
  227. int (*disconnect_frontend) (struct dmx_demux* demux);
  228. int (*get_pes_pids) (struct dmx_demux* demux, u16 *pids);
  229. int (*get_caps) (struct dmx_demux* demux, struct dmx_caps *caps);
  230. int (*set_source) (struct dmx_demux* demux, const dmx_source_t *src);
  231. int (*get_stc) (struct dmx_demux* demux, unsigned int num,
  232. u64 *stc, unsigned int *base);
  233. };
  234. #endif /* #ifndef __DEMUX_H */