demux.h 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  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. struct dmx_ts_feed {
  73. int is_filtering; /* Set to non-zero when filtering in progress */
  74. struct dmx_demux *parent; /* Back-pointer */
  75. void *priv; /* Pointer to private data of the API client */
  76. int (*set) (struct dmx_ts_feed *feed,
  77. u16 pid,
  78. int type,
  79. enum dmx_ts_pes pes_type,
  80. size_t circular_buffer_size,
  81. struct timespec timeout);
  82. int (*start_filtering) (struct dmx_ts_feed* feed);
  83. int (*stop_filtering) (struct dmx_ts_feed* feed);
  84. };
  85. /*--------------------------------------------------------------------------*/
  86. /* Section reception */
  87. /*--------------------------------------------------------------------------*/
  88. struct dmx_section_filter {
  89. u8 filter_value [DMX_MAX_FILTER_SIZE];
  90. u8 filter_mask [DMX_MAX_FILTER_SIZE];
  91. u8 filter_mode [DMX_MAX_FILTER_SIZE];
  92. struct dmx_section_feed* parent; /* Back-pointer */
  93. void* priv; /* Pointer to private data of the API client */
  94. };
  95. struct dmx_section_feed {
  96. int is_filtering; /* Set to non-zero when filtering in progress */
  97. struct dmx_demux* parent; /* Back-pointer */
  98. void* priv; /* Pointer to private data of the API client */
  99. int check_crc;
  100. u32 crc_val;
  101. u8 *secbuf;
  102. u8 secbuf_base[DMX_MAX_SECFEED_SIZE];
  103. u16 secbufp, seclen, tsfeedp;
  104. int (*set) (struct dmx_section_feed* feed,
  105. u16 pid,
  106. size_t circular_buffer_size,
  107. int check_crc);
  108. int (*allocate_filter) (struct dmx_section_feed* feed,
  109. struct dmx_section_filter** filter);
  110. int (*release_filter) (struct dmx_section_feed* feed,
  111. struct dmx_section_filter* filter);
  112. int (*start_filtering) (struct dmx_section_feed* feed);
  113. int (*stop_filtering) (struct dmx_section_feed* feed);
  114. };
  115. /*--------------------------------------------------------------------------*/
  116. /* Callback functions */
  117. /*--------------------------------------------------------------------------*/
  118. typedef int (*dmx_ts_cb) ( const u8 * buffer1,
  119. size_t buffer1_length,
  120. const u8 * buffer2,
  121. size_t buffer2_length,
  122. struct dmx_ts_feed* source,
  123. enum dmx_success success);
  124. typedef int (*dmx_section_cb) ( const u8 * buffer1,
  125. size_t buffer1_len,
  126. const u8 * buffer2,
  127. size_t buffer2_len,
  128. struct dmx_section_filter * source,
  129. enum dmx_success success);
  130. /*--------------------------------------------------------------------------*/
  131. /* DVB Front-End */
  132. /*--------------------------------------------------------------------------*/
  133. enum dmx_frontend_source {
  134. DMX_MEMORY_FE,
  135. DMX_FRONTEND_0,
  136. DMX_FRONTEND_1,
  137. DMX_FRONTEND_2,
  138. DMX_FRONTEND_3,
  139. DMX_STREAM_0, /* external stream input, e.g. LVDS */
  140. DMX_STREAM_1,
  141. DMX_STREAM_2,
  142. DMX_STREAM_3
  143. };
  144. struct dmx_frontend {
  145. struct list_head connectivity_list; /* List of front-ends that can
  146. be connected to a particular
  147. demux */
  148. enum dmx_frontend_source source;
  149. };
  150. /*--------------------------------------------------------------------------*/
  151. /* MPEG-2 TS Demux */
  152. /*--------------------------------------------------------------------------*/
  153. /*
  154. * Flags OR'ed in the capabilities field of struct dmx_demux.
  155. */
  156. #define DMX_TS_FILTERING 1
  157. #define DMX_PES_FILTERING 2
  158. #define DMX_SECTION_FILTERING 4
  159. #define DMX_MEMORY_BASED_FILTERING 8 /* write() available */
  160. #define DMX_CRC_CHECKING 16
  161. #define DMX_TS_DESCRAMBLING 32
  162. /*
  163. * Demux resource type identifier.
  164. */
  165. /*
  166. * DMX_FE_ENTRY(): Casts elements in the list of registered
  167. * front-ends from the generic type struct list_head
  168. * to the type * struct dmx_frontend
  169. *.
  170. */
  171. #define DMX_FE_ENTRY(list) list_entry(list, struct dmx_frontend, connectivity_list)
  172. struct dmx_demux {
  173. u32 capabilities; /* Bitfield of capability flags */
  174. struct dmx_frontend* frontend; /* Front-end connected to the demux */
  175. void* priv; /* Pointer to private data of the API client */
  176. int (*open) (struct dmx_demux* demux);
  177. int (*close) (struct dmx_demux* demux);
  178. int (*write) (struct dmx_demux* demux, const char __user *buf, size_t count);
  179. int (*allocate_ts_feed) (struct dmx_demux* demux,
  180. struct dmx_ts_feed** feed,
  181. dmx_ts_cb callback);
  182. int (*release_ts_feed) (struct dmx_demux* demux,
  183. struct dmx_ts_feed* feed);
  184. int (*allocate_section_feed) (struct dmx_demux* demux,
  185. struct dmx_section_feed** feed,
  186. dmx_section_cb callback);
  187. int (*release_section_feed) (struct dmx_demux* demux,
  188. struct dmx_section_feed* feed);
  189. int (*add_frontend) (struct dmx_demux* demux,
  190. struct dmx_frontend* frontend);
  191. int (*remove_frontend) (struct dmx_demux* demux,
  192. struct dmx_frontend* frontend);
  193. struct list_head* (*get_frontends) (struct dmx_demux* demux);
  194. int (*connect_frontend) (struct dmx_demux* demux,
  195. struct dmx_frontend* frontend);
  196. int (*disconnect_frontend) (struct dmx_demux* demux);
  197. int (*get_pes_pids) (struct dmx_demux* demux, u16 *pids);
  198. int (*get_caps) (struct dmx_demux* demux, struct dmx_caps *caps);
  199. int (*set_source) (struct dmx_demux* demux, const dmx_source_t *src);
  200. int (*get_stc) (struct dmx_demux* demux, unsigned int num,
  201. u64 *stc, unsigned int *base);
  202. };
  203. #endif /* #ifndef __DEMUX_H */