home *** CD-ROM | disk | FTP | other *** search
/ Chip 2005 June / ccd0605.iso / LINUX / gopchop-1.1.7.tar.tar / gopchop-1.1.7.tar / gopchop-1.1.7 / src / mpeg2structs.h < prev    next >
C/C++ Source or Header  |  2005-05-01  |  10KB  |  353 lines

  1. /*
  2. #
  3. # MPEG2 data structures for MPEG2Parser class
  4. #
  5. # $Id: mpeg2structs.h,v 1.13 2005/05/01 07:46:12 keescook Exp $
  6. #
  7. # Copyright (C) 2001-2003 Kees Cook
  8. # kees@outflux.net, http://outflux.net/
  9. # This program is free software; you can redistribute it and/or
  10. # modify it under the terms of the GNU General Public License
  11. # as published by the Free Software Foundation; either version 2
  12. # of the License, or (at your option) any later version.
  13. # This program is distributed in the hope that it will be useful,
  14. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  16. # GNU General Public License for more details.
  17. # You should have received a copy of the GNU General Public License
  18. # along with this program; if not, write to the Free Software
  19. # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  20. # http://www.gnu.org/copyleft/gpl.html
  21. #
  22. */
  23.  
  24. #ifndef _MPEG2STRUCTS_H_
  25. #define _MPEG2STRUCTS_H_
  26.  
  27. #include <inttypes.h>
  28.  
  29. #ifndef TRUE
  30. # define TRUE 1
  31. #endif
  32. #ifndef FALSE
  33. # define FALSE 0
  34. #endif
  35.  
  36. /*
  37.    This problem with these damn compilers is that I can't
  38.    specify an arbitrary bit layout structure.  It always
  39.    grows to a different size.  If someone know how to portably
  40.    control that problem let me know, and I can stop using bit masks
  41.    to get at my data.  :)
  42. */
  43.  
  44.  
  45. #define PICTURE_CODING_MASK             0x38
  46. #define PICTURE_CODING_SHIFT            0x03
  47. #define PICTURE_CODING_INTRA            0x01
  48. #define PICTURE_CODING_PREDICTIVE       0x02
  49. #define PICTURE_CODING_BIDIRECTIONAL    0x03
  50.  
  51. typedef struct
  52. {
  53.     uint8_t  start_code[4];
  54.     uint8_t  bits[2];
  55.     /*  only stuff I want to get to is picture_coding_type
  56.     uint16_t temporal_reference:10;
  57.     uint8_t  picture_coding_type:3;
  58.      */
  59. }
  60. picture_header;
  61.  
  62. #define GOP_FLAG_MASK    0x60
  63. #define GOP_FLAG_CLOSED    0x40
  64. #define GOP_FLAG_BROKEN    0x20
  65.  
  66. typedef struct
  67. {
  68.     uint8_t start_code[4];
  69.     uint8_t bits[4];
  70.     /*
  71.     uint32_t time_code:25;
  72.     uint8_t  closed_gop:1;
  73.     uint8_t  broken_link:1;
  74.     uint8_t  unknown:5;
  75.      */
  76. }
  77. group_of_pictures_header;
  78.  
  79. typedef struct
  80. {
  81.     uint8_t     start_code[4];
  82.     uint8_t     bits[8];
  83.  
  84.     /*
  85.     uint32_t    horizontal_size_value:12;
  86.     uint32_t    vertical_size_value:12;
  87.     uint32_t    aspect_ratio_information:4;
  88.     uint32_t    frame_rate_code:4;
  89.  
  90.     uint32_t    bit_rate_code:18;
  91.     uint32_t    marker1:1;
  92.     uint32_t    vbv_buffer_size_value:10;
  93.     uint32_t    constrained_parameters_flag:1;
  94.     uint32_t    load_intra_quantiser_matrix:1;
  95.  
  96.     uint8_t     intra_quantiser_matrix[64]; // optional
  97.     uint32_t    load_non_intra_quantiser_matrix:1;
  98.     uint8_t     non_intra_quantiser_matrix[64]; // optional
  99.      */
  100. }
  101. sequence_header;
  102.  
  103. typedef struct
  104. {
  105.     uint8_t     start_code[4];
  106.     uint8_t     profile_and_level_indication;
  107.  
  108.     /*
  109.     uint8_t     progressive_sequence:1;
  110.     uint8_t     chroma_format:2;
  111.     uint8_t     horizontal_size_extension:2;
  112.     uint8_t     vertical_size_extension:2;
  113.     uint8_t     bit_rate_extension:12;
  114.     uint8_t     vbv_buffer_size_extension:8;
  115.     uint8_t     low_delay:1;
  116.     uint8_t     frame_rate_extension_n:2;
  117.     uint8_t     frame_rate_extension_d:5;
  118.  
  119.      */
  120. }
  121. sequence_extension_header;
  122.  
  123.  
  124. #define ES_TYPE_WEIRD   0
  125. #define ES_TYPE_VIDEO   1
  126. #define ES_TYPE_AUDIO   2
  127.  
  128. typedef struct
  129. {
  130.     uint8_t start_code[3];
  131.     uint8_t stream_id;
  132.     uint8_t PES_packet_length[2];
  133. }
  134. PES_packet_header_t;
  135.  
  136. typedef struct
  137. {
  138.     uint8_t bits[2];
  139.     /*
  140.     uint8_t         marker0:2; // 10
  141.     uint8_t         PES_scrambling_control:2;
  142.     uint8_t         PES_priority:1;
  143.     uint8_t         data_alignment_indicator:1;
  144.     uint8_t         copyright:1;
  145.     uint8_t         original_or_copy:1;
  146.  
  147.     uint8_t         PTS_DTS_flags:2;
  148.     uint8_t         ESCR_flag:1;
  149.     uint8_t         ES_rate_flag:1;
  150.     uint8_t         DSM_trick_mode_flag:1;
  151.     uint8_t         additional_copy_info_flag:1;
  152.     uint8_t         PES_CRC_flag:1;
  153.     uint8_t         PES_extension_flag:1;
  154.      */
  155.     uint8_t PES_header_data_length;
  156. }
  157. PES_packet_internals_t;
  158.  
  159. typedef struct
  160. {
  161.     uint8_t marker_bit:1;
  162.     uint8_t data:7;
  163. }
  164. PES_packet_additional_copy_info_t;
  165.  
  166. #define GET_BITS(byte,mask,shiftdown)    (((byte)&(mask))>>(shiftdown))
  167.  
  168. #define PPE_PES_private_data_flag(x)    GET_BITS(x,0x80,7)
  169. #define PPE_pack_header_field_flag(x)    GET_BITS(x,0x40,6)
  170. #define PPE_program_packet_sequence_counter_flag(x)    GET_BITS(x,0x20,5)
  171. #define PPE_P_STD_buffer_flag(x)        GET_BITS(x,0x10,5)
  172. #define PPE_PES_extension_flag_2(x)        GET_BITS(x,0x01,0)
  173. typedef struct
  174. {
  175.     uint8_t bits[1];
  176.     /*
  177.     uint8_t         PES_private_data_flag:1;
  178.     uint8_t         pack_header_field_flag:1;
  179.     uint8_t         program_packet_sequence_counter_flag:1;
  180.     uint8_t         P_STD_buffer_flag:1;
  181.     uint8_t         reserved:3;
  182.     uint8_t         PES_extension_flag_2:1;
  183.      */
  184. }
  185. PES_packet_extension_t;
  186.  
  187. typedef struct
  188. {
  189.     uint8_t marker0:1;
  190.     uint8_t program_packet_sequence_counter:7;
  191.  
  192.     uint8_t marker1:1;
  193.     uint8_t MPEG1_MPEG2_identifier:1;
  194.     uint8_t original_stuff_length:6;
  195. }
  196. PES_packet_extension_program_packet_sequence_counter_t;
  197.  
  198. #define PES_TYPE_picture_start              0x00
  199. // slice start: 0x01 - 0xAF
  200. // reserved: 0xB0 - 0xB1
  201. #define PES_TYPE_user_data_start            0xB2
  202. #define PES_TYPE_sequence_header            0xB3
  203. #define PES_TYPE_sequence_error             0xB4
  204. #define PES_TYPE_extension_start            0xB5
  205. // reserved: 0xB6
  206. #define PES_TYPE_sequence_end               0xB7
  207. #define PES_TYPE_group_start                0xB8
  208. #define PES_TYPE_program_end                0xB9
  209. #define PES_TYPE_pack_start                 0xBA
  210. #define PES_TYPE_system_header              0xBB
  211. #define PES_TYPE_program_stream_map         0xBC    /* PES simple */
  212. #define PES_TYPE_private_stream_1           0xBD    /* PES complex */
  213. #define PES_TYPE_padding_stream             0xBE    /* PES simple */
  214. #define PES_TYPE_private_stream_2           0xBF    /* PES simple */
  215. #define PES_TYPE_ECM_stream                 0xF0    /* PES simple */
  216. #define PES_TYPE_EMM_stream                 0xF1    /* PES simple */
  217. #define PES_TYPE_DSMCC_stream               0xF2    /* PES simple */
  218. #define PES_TYPE_ISO_13522                  0xF3    /* PES complex */
  219. #define PES_TYPE_H2221A                     0xF4    /* PES complex */
  220. #define PES_TYPE_H2221B                     0xF5    /* PES complex */
  221. #define PES_TYPE_H2221C                     0xF6    /* PES complex */
  222. #define PES_TYPE_H2221D                     0xF7    /* PES complex */
  223. #define PES_TYPE_H2221E                     0xF8    /* PES simple */
  224. #define PES_TYPE_ancillary_stream           0xF9    /* PES complex */
  225. // reserved: 0xFA - 0xFE                        /* PES complex */
  226. #define PES_TYPE_program_stream_directory   0xFF    /* PES simple */
  227.  
  228. #define PES_TYPE_audio                      0xC0    /* PES complex */
  229. #define PES_TYPE_MASK_audio                 0xE0
  230.  
  231. #define PES_TYPE_video                      0xE0    /* PES complex */
  232. #define PES_TYPE_MASK_video                 0xF0
  233.  
  234.  
  235. //                            xxxxx     xxxxx
  236. // subtitles: 0x20..0x3F   00100000..00111111
  237. #define DVD_AUDIO_TYPE_sub              0x20
  238. #define DVD_AUDIO_TYPE_MASK_sub         0xE0
  239. //                            xxxxx     xxxxx
  240. // AC3:       0x80..0x9F   10000000..10011111
  241. #define DVD_AUDIO_TYPE_ac3              0x80
  242. #define DVD_AUDIO_TYPE_MASK_ac3         0xE0
  243. //                            xxxxx     xxxxx 
  244. // PCM:       0xA0..0xBF   10100000..10111111
  245. #define DVD_AUDIO_TYPE_pcm              0xA0
  246. #define DVD_AUDIO_TYPE_MASK_pcm         0xE0
  247.  
  248. // frame rates from the sequence header
  249. #define FPS_23_9    1   // 0001 -- 24000/1001
  250. #define FPS_24      2   // 0010 -- 24
  251. #define FPS_25      3   // 0011 -- 25
  252. #define FPS_29_9    4   // 0100 -- 30000/1001
  253. #define FPS_30      5   // 0101 -- 30
  254. #define FPS_50      6   // 0110 -- 50
  255. #define FPS_59_9    7   // 0111 -- 60000/1001
  256. #define FPS_60      8   // 1000 -- 60
  257.  
  258. // aspect ratio values from the sequence header
  259. #define ASPECT_1        1
  260. #define ASPECT_3_4      2
  261. #define ASPECT_9_16     3
  262. #define ASPECT_1_221    4
  263.  
  264. typedef struct
  265. {
  266.     uint8_t start_code[4];
  267.     uint8_t header_length[2];
  268.     // uint16_t header_length;
  269.  
  270.     uint8_t bits[6];
  271.     /*
  272.     uint32_t        marker0:1; // 1
  273.     uint32_t        rate_bound:22;
  274.     uint32_t        marker1:1; // 1
  275.     uint32_t        audio_bound:6;
  276.     uint32_t        fixed_flag:1;
  277.     uint32_t        CSPS_flag:1;
  278.  
  279.     uint8_t         system_audio_lock_flag:1;
  280.     uint8_t         system_video_lock_flag:1;
  281.     uint8_t         marker2:1; // 1
  282.     uint8_t         video_bound:5;
  283.  
  284.     uint8_t         packet_rate_restriction_flag:1;
  285.     uint8_t         reserved:7;
  286.      */
  287.  
  288. }
  289. system_header_t;
  290.  
  291. typedef struct
  292. {
  293.     uint8_t stream_id;
  294.     // 1011 1000: P_STD map to all audio streams
  295.     // 1011 1001: P_STD map to all video streams
  296.     // otherwise, must be >= 1011 1100
  297.     //
  298.     uint8_t bits[2];
  299.     /*
  300.     uint16_t        marker0:2; // 11
  301.     uint16_t        P_STD_buffer_bound_scale:1;
  302.     uint16_t        P_STD_buffer_size_bound:13;
  303.      */
  304. }
  305. stream_id_t;
  306.  
  307. typedef struct
  308. {
  309.     /*
  310.     uint32_t        marker0:2; // 01
  311.     uint32_t        system_clock_reference_base_hi:3;
  312.     uint32_t        marker1:1; // 1
  313.     uint32_t        system_clock_reference_base_mid:15;
  314.     uint32_t        marker2:1; // 1
  315.     uint32_t        system_clock_reference_base_low:15;
  316.     uint16_t        marker3:1; // 1
  317.     uint16_t        system_clock_reference_extension:9;
  318.     uint16_t        marker4:1; // 1
  319.     uint32_t        program_mux_rate:22;
  320.     uint32_t        marker5:1; // 1
  321.     uint32_t        marker6:1; // 1
  322.     uint8_t reserved:5;
  323.     uint8_t pack_stuffing_length:3;
  324.      */
  325.     uint8_t bits[10];
  326. }
  327. pack_header_t;
  328.  
  329. typedef struct
  330. {
  331.     /*
  332.     uint32_t        marker0:4; // 0010
  333.     uint32_t        system_clock_reference_base_hi:3;
  334.     uint32_t        marker1:1; // 1
  335.     uint32_t        system_clock_reference_base_mid:15;
  336.     uint32_t        marker2:1; // 1
  337.     uint32_t        system_clock_reference_base_low:15;
  338.     uint16_t        marker3:1; // 1
  339.     uint16_t        marker4:1; // 1
  340.     uint32_t        program_mux_rate:22;
  341.     uint32_t        marker6:1; // 1
  342.      */
  343.     uint8_t bits[8];
  344. }
  345. pack_header_MPEG1_t;
  346.  
  347. #endif //  _MPEG2STRUCTS_H_
  348.  
  349. /* vi:set ai ts=4 sw=4 expandtab: */
  350.