dvbdemux.h 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. /*
  2. * libdvbdemux - a DVB demux library
  3. *
  4. * Copyright (C) 2005 Andrew de Quincey (adq_dvb@lidskialf.net)
  5. *
  6. * This library is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU Lesser General Public
  8. * License as published by the Free Software Foundation; either
  9. * version 2.1 of the License, or (at your option) any later version.
  10. *
  11. * This library is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * Lesser General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser General Public
  17. * License along with this library; if not, write to the Free Software
  18. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
  19. */
  20. #ifndef LIBDVBDEMUX_H
  21. #define LIBDVBDEMUX_H 1
  22. #ifdef __cplusplus
  23. extern "C"
  24. {
  25. #endif
  26. #include <stdint.h>
  27. /**
  28. * Source of the data to be demuxed.
  29. *
  30. * FRONTEND. The data will be read from the frontend on the adapter.
  31. *
  32. * DVR. The data will be read from the DVR device of the adapter (of course,
  33. * you need to write data TO the DVR device as well).
  34. */
  35. #define DVBDEMUX_INPUT_FRONTEND 0
  36. #define DVBDEMUX_INPUT_DVR 1
  37. /**
  38. * Destination of the demuxed data.
  39. *
  40. * DECODER. Sends the data directly to a hardware decoder (if present).
  41. *
  42. * DEMUX. Sends the PID stream to the current demux file descriptor. HOWEVER, the
  43. * data will be the payload *only* - transport stream headers will be stripped.
  44. *
  45. * DVR sends the data to the DVR device. The data will be the complete transport
  46. * stream packets with headers intact. Note: if multiple filters specify
  47. * DVBDEMUX_OUTPUT_DVR, the individual PID streams will be re-multiplexed
  48. * together.
  49. */
  50. #define DVBDEMUX_OUTPUT_DECODER 0
  51. #define DVBDEMUX_OUTPUT_DEMUX 1
  52. #define DVBDEMUX_OUTPUT_DVR 2
  53. #define DVBDEMUX_OUTPUT_TS_DEMUX 3
  54. /**
  55. * PES types.
  56. */
  57. #define DVBDEMUX_PESTYPE_AUDIO 0
  58. #define DVBDEMUX_PESTYPE_VIDEO 1
  59. #define DVBDEMUX_PESTYPE_TELETEXT 2
  60. #define DVBDEMUX_PESTYPE_SUBTITLE 3
  61. #define DVBDEMUX_PESTYPE_PCR 4
  62. /**
  63. * Open a demux device. Can be called multiple times. These let you setup a
  64. * single filter per FD. It can can also be read() from if you use a section
  65. * filter, or create a pes_filter or raw_filter with output DVBDEMUX_OUTPUT_DEMUX.
  66. *
  67. * @param adapter Index of the DVB adapter.
  68. * @param demuxdevice Index of the demux device on that adapter (usually 0).
  69. * @param nonblocking If 1, frontend will be opened in nonblocking mode.
  70. * @return A unix file descriptor on success, or -1 on failure.
  71. */
  72. extern int dvbdemux_open_demux(int adapter, int demuxdevice, int nonblocking);
  73. /**
  74. * Open a DVR device. May be opened for writing or reading once.
  75. * It is used to either write() transport stream data to be demuxed
  76. * (if input == DVBDEMUX_INPUT_DVR), or to read() a stream of demuxed data
  77. * (if output == DVBDEMUX_OUTPUT_DVR).
  78. *
  79. * Note, all demux filters with output set to DVBDEMUX_OUTPUT_DVR will be
  80. * multiplexed together and output their data on this device.
  81. *
  82. * @param adapter Index of the DVB adapter.
  83. * @param dvrdevice Index of the dvr device on that adapter (usually 0)
  84. * @param readonly If 1, frontend will be opened in readonly mode only.
  85. * @param nonblocking If 1, frontend will be opened in nonblocking mode.
  86. * @return A unix file descriptor on success, or -1 on failure.
  87. */
  88. extern int dvbdemux_open_dvr(int adapter, int dvrdevice, int readonly, int nonblocking);
  89. /**
  90. * Set filter for the first 18 bytes of decoded SI table sections. Note that
  91. * bytes 1 and 2 are _not_ filtered since they contain the length field.
  92. *
  93. * Conceptually, the driver computes the following for each filtered bit.
  94. *
  95. * (filter[X].bit[Y] & mask[X].bit[Y]) == (header[X].bit[Y] & mask[X].bit[Y])
  96. *
  97. * Any sections which do not match this criteria for every bit will be discarded.
  98. *
  99. * The SI data is always read from the frontend, and is always returned by
  100. * read()ing the demux fd. FIXME: check this statement!
  101. *
  102. * @param fd FD as opened with dvbdemux_open_demux() above.
  103. * @param pid PID of the stream.
  104. * @param filter The filter values of the first 18 bytes of the desired sections.
  105. * @param mask Bitmask indicating which bits in the filter array should be tested
  106. * (if a bit is 1, it will be tested).
  107. * @param start If 1, the filter will be started immediately. Otherwise you must
  108. * call dvbdemux_start() manually.
  109. * @param checkcrc If 1, the driver will check the CRC on the table sections.
  110. * Any bad sections will be dropped.
  111. * @return 0 on success, nonzero on failure.
  112. */
  113. extern int dvbdemux_set_section_filter(int fd, int pid,
  114. uint8_t filter[18], uint8_t mask[18],
  115. int start, int checkcrc);
  116. /**
  117. * Set filter for a stream of PES data. This call can only used for cards
  118. * equipped with a hardware decoder.
  119. *
  120. * @param fd FD as opened with dvbdemux_open_demux() above.
  121. * @param pid PID of the stream.
  122. * @param input One of DVBDEMUX_INPUT_*.
  123. * @param output One of DVBDEMUX_OUTPUT_*.
  124. * @param pestype One of DVBDEMUX_PESTYPE_* - this tells the decoder the type
  125. * of data in this stream.
  126. * @param start If 1, the filter will be started immediately. Otherwise you must
  127. * call dvbdemux_start() manually.
  128. * @return 0 on success, nonzero on failure.
  129. */
  130. extern int dvbdemux_set_pes_filter(int fd, int pid,
  131. int input, int output,
  132. int pestype,
  133. int start);
  134. /**
  135. * Create a pid filter - this will extract transport stream packets for a
  136. * specified PID.
  137. *
  138. * Note: The wildcard PID can only be used on "budget" cards.
  139. *
  140. * @param fd FD as opened with dvbdemux_open_demux() above.
  141. * @param pid PID to retrieve, or use -1 as a wildcard for ALL PIDs.
  142. * @param input One of DVBDEMUX_INPUT_*.
  143. * @param output One of DVBDEMUX_OUTPUT_*.
  144. * @param start If 1, the filter will be started immediately. Otherwise you must
  145. * call dvbdemux_start() manually.
  146. * @return 0 on success, nonzero on failure.
  147. */
  148. extern int dvbdemux_set_pid_filter(int fd, int pid,
  149. int input, int output,
  150. int start);
  151. /**
  152. * Start a demux going.
  153. *
  154. * @param fd FD as opened with dvbdemux_open_demux() above.
  155. * @return 0 on success, nonzero on failure.
  156. */
  157. extern int dvbdemux_start(int fd);
  158. /**
  159. * Stop a demux.
  160. *
  161. * @param fd FD as opened with dvbdemux_open_demux() above.
  162. * @return 0 on success, nonzero on failure.
  163. */
  164. extern int dvbdemux_stop(int fd);
  165. /**
  166. * Retrieve the current STC from the demux. This call can only used for cards
  167. * equipped with a hardware decoder.
  168. *
  169. * @param fd FD as opened with dvbdemux_open_demux() above.
  170. * @param stc Where to put the retrieved STC value (in 90kHz clock).
  171. * @return 0 on success, nonzero on failure.
  172. */
  173. extern int dvbdemux_get_stc(int fd, uint64_t *stc);
  174. /**
  175. * Change the internal buffer size used by the demuxer. The default buffer size
  176. * is 8192 bytes. Can only be used if the demux in question is stopped.
  177. *
  178. * @param fd FD as opened with dvbdemux_open_demux() above.
  179. * @param bufsize New buffer size to use.
  180. * @return 0 on success, nonzero on failure.
  181. */
  182. extern int dvbdemux_set_buffer(int fd, int bufsize);
  183. #ifdef __cplusplus
  184. }
  185. #endif
  186. #endif // LIBDVBDEMUX_H