demux.h 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278
  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. /* PES type for filters which write to built-in decoder */
  71. /* these should be kept identical to the types in dmx.h */
  72. enum dmx_ts_pes
  73. { /* also send packets to decoder (if it exists) */
  74. DMX_TS_PES_AUDIO0,
  75. DMX_TS_PES_VIDEO0,
  76. DMX_TS_PES_TELETEXT0,
  77. DMX_TS_PES_SUBTITLE0,
  78. DMX_TS_PES_PCR0,
  79. DMX_TS_PES_AUDIO1,
  80. DMX_TS_PES_VIDEO1,
  81. DMX_TS_PES_TELETEXT1,
  82. DMX_TS_PES_SUBTITLE1,
  83. DMX_TS_PES_PCR1,
  84. DMX_TS_PES_AUDIO2,
  85. DMX_TS_PES_VIDEO2,
  86. DMX_TS_PES_TELETEXT2,
  87. DMX_TS_PES_SUBTITLE2,
  88. DMX_TS_PES_PCR2,
  89. DMX_TS_PES_AUDIO3,
  90. DMX_TS_PES_VIDEO3,
  91. DMX_TS_PES_TELETEXT3,
  92. DMX_TS_PES_SUBTITLE3,
  93. DMX_TS_PES_PCR3,
  94. DMX_TS_PES_OTHER
  95. };
  96. #define DMX_TS_PES_AUDIO DMX_TS_PES_AUDIO0
  97. #define DMX_TS_PES_VIDEO DMX_TS_PES_VIDEO0
  98. #define DMX_TS_PES_TELETEXT DMX_TS_PES_TELETEXT0
  99. #define DMX_TS_PES_SUBTITLE DMX_TS_PES_SUBTITLE0
  100. #define DMX_TS_PES_PCR DMX_TS_PES_PCR0
  101. struct dmx_ts_feed {
  102. int is_filtering; /* Set to non-zero when filtering in progress */
  103. struct dmx_demux *parent; /* Back-pointer */
  104. void *priv; /* Pointer to private data of the API client */
  105. int (*set) (struct dmx_ts_feed *feed,
  106. u16 pid,
  107. int type,
  108. enum dmx_ts_pes pes_type,
  109. size_t circular_buffer_size,
  110. struct timespec timeout);
  111. int (*start_filtering) (struct dmx_ts_feed* feed);
  112. int (*stop_filtering) (struct dmx_ts_feed* feed);
  113. };
  114. /*--------------------------------------------------------------------------*/
  115. /* Section reception */
  116. /*--------------------------------------------------------------------------*/
  117. struct dmx_section_filter {
  118. u8 filter_value [DMX_MAX_FILTER_SIZE];
  119. u8 filter_mask [DMX_MAX_FILTER_SIZE];
  120. u8 filter_mode [DMX_MAX_FILTER_SIZE];
  121. struct dmx_section_feed* parent; /* Back-pointer */
  122. void* priv; /* Pointer to private data of the API client */
  123. };
  124. struct dmx_section_feed {
  125. int is_filtering; /* Set to non-zero when filtering in progress */
  126. struct dmx_demux* parent; /* Back-pointer */
  127. void* priv; /* Pointer to private data of the API client */
  128. int check_crc;
  129. u32 crc_val;
  130. u8 *secbuf;
  131. u8 secbuf_base[DMX_MAX_SECFEED_SIZE];
  132. u16 secbufp, seclen, tsfeedp;
  133. int (*set) (struct dmx_section_feed* feed,
  134. u16 pid,
  135. size_t circular_buffer_size,
  136. int check_crc);
  137. int (*allocate_filter) (struct dmx_section_feed* feed,
  138. struct dmx_section_filter** filter);
  139. int (*release_filter) (struct dmx_section_feed* feed,
  140. struct dmx_section_filter* filter);
  141. int (*start_filtering) (struct dmx_section_feed* feed);
  142. int (*stop_filtering) (struct dmx_section_feed* feed);
  143. };
  144. /*--------------------------------------------------------------------------*/
  145. /* Callback functions */
  146. /*--------------------------------------------------------------------------*/
  147. typedef int (*dmx_ts_cb) ( const u8 * buffer1,
  148. size_t buffer1_length,
  149. const u8 * buffer2,
  150. size_t buffer2_length,
  151. struct dmx_ts_feed* source,
  152. enum dmx_success success);
  153. typedef int (*dmx_section_cb) ( const u8 * buffer1,
  154. size_t buffer1_len,
  155. const u8 * buffer2,
  156. size_t buffer2_len,
  157. struct dmx_section_filter * source,
  158. enum dmx_success success);
  159. /*--------------------------------------------------------------------------*/
  160. /* DVB Front-End */
  161. /*--------------------------------------------------------------------------*/
  162. enum dmx_frontend_source {
  163. DMX_MEMORY_FE,
  164. DMX_FRONTEND_0,
  165. DMX_FRONTEND_1,
  166. DMX_FRONTEND_2,
  167. DMX_FRONTEND_3,
  168. DMX_STREAM_0, /* external stream input, e.g. LVDS */
  169. DMX_STREAM_1,
  170. DMX_STREAM_2,
  171. DMX_STREAM_3
  172. };
  173. struct dmx_frontend {
  174. struct list_head connectivity_list; /* List of front-ends that can
  175. be connected to a particular
  176. demux */
  177. enum dmx_frontend_source source;
  178. };
  179. /*--------------------------------------------------------------------------*/
  180. /* MPEG-2 TS Demux */
  181. /*--------------------------------------------------------------------------*/
  182. /*
  183. * Flags OR'ed in the capabilities 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. /*
  192. * Demux resource type identifier.
  193. */
  194. /*
  195. * DMX_FE_ENTRY(): Casts elements in the list of registered
  196. * front-ends from the generic type struct list_head
  197. * to the type * struct dmx_frontend
  198. *.
  199. */
  200. #define DMX_FE_ENTRY(list) list_entry(list, struct dmx_frontend, connectivity_list)
  201. struct dmx_demux {
  202. u32 capabilities; /* Bitfield of capability flags */
  203. struct dmx_frontend* frontend; /* Front-end connected to the demux */
  204. void* priv; /* Pointer to private data of the API client */
  205. int (*open) (struct dmx_demux* demux);
  206. int (*close) (struct dmx_demux* demux);
  207. int (*write) (struct dmx_demux* demux, const char* buf, size_t count);
  208. int (*allocate_ts_feed) (struct dmx_demux* demux,
  209. struct dmx_ts_feed** feed,
  210. dmx_ts_cb callback);
  211. int (*release_ts_feed) (struct dmx_demux* demux,
  212. struct dmx_ts_feed* feed);
  213. int (*allocate_section_feed) (struct dmx_demux* demux,
  214. struct dmx_section_feed** feed,
  215. dmx_section_cb callback);
  216. int (*release_section_feed) (struct dmx_demux* demux,
  217. struct dmx_section_feed* feed);
  218. int (*add_frontend) (struct dmx_demux* demux,
  219. struct dmx_frontend* frontend);
  220. int (*remove_frontend) (struct dmx_demux* demux,
  221. struct dmx_frontend* frontend);
  222. struct list_head* (*get_frontends) (struct dmx_demux* demux);
  223. int (*connect_frontend) (struct dmx_demux* demux,
  224. struct dmx_frontend* frontend);
  225. int (*disconnect_frontend) (struct dmx_demux* demux);
  226. int (*get_pes_pids) (struct dmx_demux* demux, u16 *pids);
  227. int (*get_caps) (struct dmx_demux* demux, struct dmx_caps *caps);
  228. int (*set_source) (struct dmx_demux* demux, const dmx_source_t *src);
  229. int (*get_stc) (struct dmx_demux* demux, unsigned int num,
  230. u64 *stc, unsigned int *base);
  231. };
  232. #endif /* #ifndef __DEMUX_H */