dmxdev.h 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. /*
  2. * dmxdev.h
  3. *
  4. * Copyright (C) 2000 Ralph Metzler & Marcus Metzler
  5. * for convergence integrated media GmbH
  6. *
  7. * This program is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU Lesser General Public License
  9. * as published by the Free Software Foundation; either version 2.1
  10. * of the License, or (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. */
  18. #ifndef _DMXDEV_H_
  19. #define _DMXDEV_H_
  20. #include <linux/types.h>
  21. #include <linux/spinlock.h>
  22. #include <linux/time.h>
  23. #include <linux/timer.h>
  24. #include <linux/wait.h>
  25. #include <linux/fs.h>
  26. #include <linux/string.h>
  27. #include <linux/mutex.h>
  28. #include <linux/slab.h>
  29. #include <linux/dvb/dmx.h>
  30. #include <media/dvbdev.h>
  31. #include <media/demux.h>
  32. #include <media/dvb_ringbuffer.h>
  33. #include <media/dvb_vb2.h>
  34. /**
  35. * enum dmxdev_type - type of demux filter type.
  36. *
  37. * @DMXDEV_TYPE_NONE: no filter set.
  38. * @DMXDEV_TYPE_SEC: section filter.
  39. * @DMXDEV_TYPE_PES: Program Elementary Stream (PES) filter.
  40. */
  41. enum dmxdev_type {
  42. DMXDEV_TYPE_NONE,
  43. DMXDEV_TYPE_SEC,
  44. DMXDEV_TYPE_PES,
  45. };
  46. /**
  47. * enum dmxdev_state - state machine for the dmxdev.
  48. *
  49. * @DMXDEV_STATE_FREE: indicates that the filter is freed.
  50. * @DMXDEV_STATE_ALLOCATED: indicates that the filter was allocated
  51. * to be used.
  52. * @DMXDEV_STATE_SET: indicates that the filter parameters are set.
  53. * @DMXDEV_STATE_GO: indicates that the filter is running.
  54. * @DMXDEV_STATE_DONE: indicates that a packet was already filtered
  55. * and the filter is now disabled.
  56. * Set only if %DMX_ONESHOT. See
  57. * &dmx_sct_filter_params.
  58. * @DMXDEV_STATE_TIMEDOUT: Indicates a timeout condition.
  59. */
  60. enum dmxdev_state {
  61. DMXDEV_STATE_FREE,
  62. DMXDEV_STATE_ALLOCATED,
  63. DMXDEV_STATE_SET,
  64. DMXDEV_STATE_GO,
  65. DMXDEV_STATE_DONE,
  66. DMXDEV_STATE_TIMEDOUT
  67. };
  68. /**
  69. * struct dmxdev_feed - digital TV dmxdev feed
  70. *
  71. * @pid: Program ID to be filtered
  72. * @ts: pointer to &struct dmx_ts_feed
  73. * @next: &struct list_head pointing to the next feed.
  74. */
  75. struct dmxdev_feed {
  76. u16 pid;
  77. struct dmx_ts_feed *ts;
  78. struct list_head next;
  79. };
  80. /**
  81. * struct dmxdev_filter - digital TV dmxdev filter
  82. *
  83. * @filter: a union describing a dmxdev filter.
  84. * Currently used only for section filters.
  85. * @filter.sec: a &struct dmx_section_filter pointer.
  86. * For section filter only.
  87. * @feed: a union describing a dmxdev feed.
  88. * Depending on the filter type, it can be either
  89. * @feed.ts or @feed.sec.
  90. * @feed.ts: a &struct list_head list.
  91. * For TS and PES feeds.
  92. * @feed.sec: a &struct dmx_section_feed pointer.
  93. * For section feed only.
  94. * @params: a union describing dmxdev filter parameters.
  95. * Depending on the filter type, it can be either
  96. * @params.sec or @params.pes.
  97. * @params.sec: a &struct dmx_sct_filter_params embedded struct.
  98. * For section filter only.
  99. * @params.pes: a &struct dmx_pes_filter_params embedded struct.
  100. * For PES filter only.
  101. * @type: type of the dmxdev filter, as defined by &enum dmxdev_type.
  102. * @state: state of the dmxdev filter, as defined by &enum dmxdev_state.
  103. * @dev: pointer to &struct dmxdev.
  104. * @buffer: an embedded &struct dvb_ringbuffer buffer.
  105. * @vb2_ctx: control struct for VB2 handler
  106. * @mutex: protects the access to &struct dmxdev_filter.
  107. * @timer: &struct timer_list embedded timer, used to check for
  108. * feed timeouts.
  109. * Only for section filter.
  110. * @todo: index for the @secheader.
  111. * Only for section filter.
  112. * @secheader: buffer cache to parse the section header.
  113. * Only for section filter.
  114. */
  115. struct dmxdev_filter {
  116. union {
  117. struct dmx_section_filter *sec;
  118. } filter;
  119. union {
  120. /* list of TS and PES feeds (struct dmxdev_feed) */
  121. struct list_head ts;
  122. struct dmx_section_feed *sec;
  123. } feed;
  124. union {
  125. struct dmx_sct_filter_params sec;
  126. struct dmx_pes_filter_params pes;
  127. } params;
  128. enum dmxdev_type type;
  129. enum dmxdev_state state;
  130. struct dmxdev *dev;
  131. struct dvb_ringbuffer buffer;
  132. struct dvb_vb2_ctx vb2_ctx;
  133. struct mutex mutex;
  134. /* only for sections */
  135. struct timer_list timer;
  136. int todo;
  137. u8 secheader[3];
  138. };
  139. /**
  140. * struct dmxdev - Describes a digital TV demux device.
  141. *
  142. * @dvbdev: pointer to &struct dvb_device associated with
  143. * the demux device node.
  144. * @dvr_dvbdev: pointer to &struct dvb_device associated with
  145. * the dvr device node.
  146. * @filter: pointer to &struct dmxdev_filter.
  147. * @demux: pointer to &struct dmx_demux.
  148. * @filternum: number of filters.
  149. * @capabilities: demux capabilities as defined by &enum dmx_demux_caps.
  150. * @may_do_mmap: flag used to indicate if the device may do mmap.
  151. * @exit: flag to indicate that the demux is being released.
  152. * @dvr_orig_fe: pointer to &struct dmx_frontend.
  153. * @dvr_buffer: embedded &struct dvb_ringbuffer for DVB output.
  154. * @dvr_vb2_ctx: control struct for VB2 handler
  155. * @mutex: protects the usage of this structure.
  156. * @lock: protects access to &dmxdev->filter->data.
  157. */
  158. struct dmxdev {
  159. struct dvb_device *dvbdev;
  160. struct dvb_device *dvr_dvbdev;
  161. struct dmxdev_filter *filter;
  162. struct dmx_demux *demux;
  163. int filternum;
  164. int capabilities;
  165. unsigned int may_do_mmap:1;
  166. unsigned int exit:1;
  167. #define DMXDEV_CAP_DUPLEX 1
  168. struct dmx_frontend *dvr_orig_fe;
  169. struct dvb_ringbuffer dvr_buffer;
  170. #define DVR_BUFFER_SIZE (10*188*1024)
  171. struct dvb_vb2_ctx dvr_vb2_ctx;
  172. struct mutex mutex;
  173. spinlock_t lock;
  174. };
  175. /**
  176. * dvb_dmxdev_init - initializes a digital TV demux and registers both demux
  177. * and DVR devices.
  178. *
  179. * @dmxdev: pointer to &struct dmxdev.
  180. * @adap: pointer to &struct dvb_adapter.
  181. */
  182. int dvb_dmxdev_init(struct dmxdev *dmxdev, struct dvb_adapter *adap);
  183. /**
  184. * dvb_dmxdev_release - releases a digital TV demux and unregisters it.
  185. *
  186. * @dmxdev: pointer to &struct dmxdev.
  187. */
  188. void dvb_dmxdev_release(struct dmxdev *dmxdev);
  189. #endif /* _DMXDEV_H_ */