mpeg_es.h 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  1. /*
  2. * Copyright (c) 2013-2014 - Andre Roth <neolynx@gmail.com>
  3. *
  4. * This program is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU General Public License
  6. * as published by the Free Software Foundation version 2
  7. * of the License.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program; if not, write to the Free Software
  16. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  17. * Or, point your browser to http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
  18. *
  19. */
  20. #ifndef _MPEG_ES_H
  21. #define _MPEG_ES_H
  22. /**
  23. * @file mpeg_es.h
  24. * @ingroup dvb_table
  25. * @brief Provides the table parser for the MPEG-TS Elementary Stream
  26. * @copyright GNU General Public License version 2 (GPLv2)
  27. * @author Andre Roth
  28. *
  29. * @par Relevant specs
  30. * The table described herein is defined in ISO 13818-2
  31. *
  32. * @see
  33. * http://dvd.sourceforge.net/dvdinfo/mpeghdrs.html
  34. *
  35. * @par Bug Report
  36. * Please submit bug reports and patches to linux-media@vger.kernel.org
  37. */
  38. #include <stdint.h>
  39. #include <unistd.h> /* ssize_t */
  40. /**
  41. * @def DVB_MPEG_ES_PIC_START
  42. * @brief Picture Start
  43. * @ingroup dvb_table
  44. * @def DVB_MPEG_ES_USER_DATA
  45. * @brief User Data
  46. * @ingroup dvb_table
  47. * @def DVB_MPEG_ES_SEQ_START
  48. * @brief Sequence Start
  49. * @ingroup dvb_table
  50. * @def DVB_MPEG_ES_SEQ_EXT
  51. * @brief Extension
  52. * @ingroup dvb_table
  53. * @def DVB_MPEG_ES_GOP
  54. * @brief Group Of Pictures
  55. * @ingroup dvb_table
  56. * @def DVB_MPEG_ES_SLICES
  57. * @brief Slices
  58. * @ingroup dvb_table
  59. */
  60. #define DVB_MPEG_ES_PIC_START 0x00
  61. #define DVB_MPEG_ES_USER_DATA 0xb2
  62. #define DVB_MPEG_ES_SEQ_START 0xb3
  63. #define DVB_MPEG_ES_SEQ_EXT 0xb5
  64. #define DVB_MPEG_ES_GOP 0xb8
  65. #define DVB_MPEG_ES_SLICES 0x01 ... 0xaf
  66. /**
  67. * @struct dvb_mpeg_es_seq_start
  68. * @brief MPEG ES Sequence header
  69. * @ingroup dvb_table
  70. *
  71. * @param type DVB_MPEG_ES_SEQ_START
  72. * @param sync Sync bytes
  73. * @param framerate Framerate
  74. * @param aspect Aspect ratio
  75. * @param height Height
  76. * @param width Width
  77. * @param qm_nonintra Load non-intra quantizer matrix
  78. * @param qm_intra Load intra quantizer matrix
  79. * @param constrained Constrained parameters flag
  80. * @param vbv VBV buffer size
  81. * @param one Should be 1
  82. * @param bitrate Bitrate
  83. */
  84. struct dvb_mpeg_es_seq_start {
  85. union {
  86. uint32_t bitfield;
  87. struct {
  88. uint32_t type:8;
  89. uint32_t sync:24;
  90. } __attribute__((packed));
  91. } __attribute__((packed));
  92. union {
  93. uint32_t bitfield2;
  94. struct {
  95. uint32_t framerate:4;
  96. uint32_t aspect:4;
  97. uint32_t height:12;
  98. uint32_t width:12;
  99. } __attribute__((packed));
  100. } __attribute__((packed));
  101. union {
  102. uint32_t bitfield3;
  103. struct {
  104. uint32_t qm_nonintra:1;
  105. uint32_t qm_intra:1;
  106. uint32_t constrained:1;
  107. uint32_t vbv:10; // Size of video buffer verifier = 16*1024*vbv buf size
  108. uint32_t one:1;
  109. uint32_t bitrate:18;
  110. } __attribute__((packed));
  111. } __attribute__((packed));
  112. } __attribute__((packed));
  113. /**
  114. * @struct dvb_mpeg_es_pic_start
  115. * @brief MPEG ES Picture start header
  116. * @ingroup dvb_table
  117. *
  118. * @param type DVB_MPEG_ES_PIC_START
  119. * @param sync Sync bytes
  120. * @param dummy Unused
  121. * @param vbv_delay VBV delay
  122. * @param coding_type Frame type (enum dvb_mpeg_es_frame_t)
  123. * @param temporal_ref Temporal sequence number
  124. */
  125. struct dvb_mpeg_es_pic_start {
  126. union {
  127. uint32_t bitfield;
  128. struct {
  129. uint32_t type:8;
  130. uint32_t sync:24;
  131. } __attribute__((packed));
  132. } __attribute__((packed));
  133. union {
  134. uint32_t bitfield2;
  135. struct {
  136. uint32_t dummy:3;
  137. uint32_t vbv_delay:16;
  138. uint32_t coding_type:3;
  139. uint32_t temporal_ref:10;
  140. } __attribute__((packed));
  141. } __attribute__((packed));
  142. } __attribute__((packed));
  143. /**
  144. * @enum dvb_mpeg_es_frame_t
  145. * @brief MPEG frame types
  146. * @ingroup dvb_table
  147. *
  148. * @var DVB_MPEG_ES_FRAME_UNKNOWN
  149. * @brief Unknown frame
  150. * @var DVB_MPEG_ES_FRAME_I
  151. * @brief I frame
  152. * @var DVB_MPEG_ES_FRAME_P
  153. * @brief P frame
  154. * @var DVB_MPEG_ES_FRAME_B
  155. * @brief B frame
  156. * @var DVB_MPEG_ES_FRAME_D
  157. * @brief D frame
  158. */
  159. enum dvb_mpeg_es_frame_t
  160. {
  161. DVB_MPEG_ES_FRAME_UNKNOWN,
  162. DVB_MPEG_ES_FRAME_I,
  163. DVB_MPEG_ES_FRAME_P,
  164. DVB_MPEG_ES_FRAME_B,
  165. DVB_MPEG_ES_FRAME_D
  166. };
  167. /**
  168. * @brief Vector that translates from enum dvb_mpeg_es_frame_t to string.
  169. * @ingroup dvb_table
  170. */
  171. extern const char *dvb_mpeg_es_frame_names[5];
  172. struct dvb_v5_fe_parms;
  173. #ifdef __cplusplus
  174. extern "C" {
  175. #endif
  176. /**
  177. * @brief Initialize a struct dvb_mpeg_es_seq_start from buffer
  178. * @ingroup dvb_table
  179. *
  180. * @param buf Buffer
  181. * @param buflen Length of buffer
  182. * @param seq_start Pointer to allocated struct dvb_mpeg_es_seq_start
  183. *
  184. * @return If buflen too small, return -1, 0 otherwise.
  185. *
  186. * This function copies the length of struct dvb_mpeg_es_seq_start
  187. * to seq_start and fixes endianness. seq_start has to be allocated
  188. * with malloc.
  189. */
  190. int dvb_mpeg_es_seq_start_init (const uint8_t *buf, ssize_t buflen,
  191. struct dvb_mpeg_es_seq_start *seq_start);
  192. /**
  193. * @brief Print details of struct dvb_mpeg_es_seq_start
  194. * @ingroup dvb_table
  195. *
  196. * @param parms struct dvb_v5_fe_parms for log functions
  197. * @param seq_start Pointer to struct dvb_mpeg_es_seq_start to print
  198. *
  199. * This function prints the fields of struct dvb_mpeg_es_seq_start
  200. */
  201. void dvb_mpeg_es_seq_start_print(struct dvb_v5_fe_parms *parms,
  202. struct dvb_mpeg_es_seq_start *seq_start);
  203. /**
  204. * @brief Initialize a struct dvb_mpeg_es_pic_start from buffer
  205. * @ingroup dvb_table
  206. *
  207. * @param buf Buffer
  208. * @param buflen Length of buffer
  209. * @param pic_start Pointer to allocated structdvb_mpeg_es_pic_start
  210. *
  211. * @return If buflen too small, return -1, 0 otherwise.
  212. *
  213. * This function copies the length of struct dvb_mpeg_es_pic_start
  214. * to pic_start and fixes endianness. seq_start has to be allocated
  215. * with malloc.
  216. */
  217. int dvb_mpeg_es_pic_start_init (const uint8_t *buf, ssize_t buflen,
  218. struct dvb_mpeg_es_pic_start *pic_start);
  219. /**
  220. * @brief Print details of struct dvb_mpeg_es_pic_start
  221. * @ingroup dvb_table
  222. *
  223. * @param parms struct dvb_v5_fe_parms for log functions
  224. * @param pic_start Pointer to struct dvb_mpeg_es_pic_start to print
  225. *
  226. * This function prints the fields of struct dvb_mpeg_es_pic_start
  227. */
  228. void dvb_mpeg_es_pic_start_print(struct dvb_v5_fe_parms *parms,
  229. struct dvb_mpeg_es_pic_start *pic_start);
  230. #ifdef __cplusplus
  231. }
  232. #endif
  233. #endif