dmxdev.h 5.9 KB

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