demux.h 8.7 KB

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