| 1 | ##------------------------------------------------------------------------ | ||
| 2 | ## Package: MPEG::Info::Constants | ||
| 3 | ## Author: Benjamin R. Ginter | ||
| 4 | ## Notice: Copyright (c) 2001 Benjamin R. Ginter | ||
| 5 | ## Purpose: MPEG codes, blocks, constants... | ||
| 6 | ## Comments: None | ||
| 7 | ## CVS: $Header: /cvsroot/MPEG/Info/Info/Constants.pm,v 1.1 2002/02/05 09:20:13 synaptic Exp $ | ||
| 8 | ##------------------------------------------------------------------------ | ||
| 9 | |||
| 10 | package MPEG::Info::Constants; | ||
| 11 | use 5.006; | ||
| 12 | use strict; | ||
| 13 | use warnings; | ||
| 14 | |||
| 15 | require Exporter; | ||
| 16 | |||
| 17 | our @ISA = qw( Exporter); | ||
| 18 | |||
| 19 | ##------------------------------------------------------------------------ | ||
| 20 | ## FRAME_RATE | ||
| 21 | ## | ||
| 22 | ## A lookup table of all the standard frame rates. Some rates adhere to | ||
| 23 | ## a particular profile that ensures compatibility with VLSI capabilities | ||
| 24 | ## of the early to mid 1990s. | ||
| 25 | ## | ||
| 26 | ## CPB | ||
| 27 | ## Constrained Parameters Bitstreams, an MPEG-1 set of sampling and | ||
| 28 | ## bitstream parameters designed to normalize decoder computational | ||
| 29 | ## complexity, buffer size, and memory bandwidth while still addressing | ||
| 30 | ## the widest possible range of applications. | ||
| 31 | ## | ||
| 32 | ## Main Level | ||
| 33 | ## MPEG-2 Video Main Profile and Main Level is analogous to MPEG-1's | ||
| 34 | ## CPB, with sampling limits at CCIR 601 parameters (720x480x30 Hz or | ||
| 35 | ## 720x576x24 Hz). | ||
| 36 | ## | ||
| 37 | ##------------------------------------------------------------------------ | ||
| 38 | our $FRAME_RATE = | ||
| 39 | [ 0, | ||
| 40 | 24000/1001, ## 3-2 pulldown NTSC (CPB/Main Level) | ||
| 41 | 24, ## Film (CPB/Main Level) | ||
| 42 | 25, ## PAL/SECAM or 625/60 video | ||
| 43 | 30000/1001, ## NTSC (CPB/Main Level) | ||
| 44 | 30, ## drop-frame NTSC or component 525/60 (CPB/Main Level) | ||
| 45 | 50, ## double-rate PAL | ||
| 46 | 60000/1001, ## double-rate NTSC | ||
| 47 | 60, ## double-rate, drop-frame NTSC/component 525/60 video | ||
| 48 | ]; | ||
| 49 | |||
| 50 | ##------------------------------------------------------------------------ | ||
| 51 | ## ASPECT_RATIO -- INCOMPLETE? | ||
| 52 | ## | ||
| 53 | ## This lookup table maps the header aspect ratio index to a common name. | ||
| 54 | ## These are just the defined ratios for CPB I believe. As I understand | ||
| 55 | ## it, a stream that doesn't adhere to one of these aspect ratios is | ||
| 56 | ## technically considered non-compliant. | ||
| 57 | ##------------------------------------------------------------------------ | ||
| 58 | our $ASPECT_RATIO = [ 'Forbidden', | ||
| 59 | '1/1 (VGA)', | ||
| 60 | '4/3 (TV)', | ||
| 61 | '16/9 (Large TV)', | ||
| 62 | '2.21/1 (Cinema)', | ||
| 63 | ]; | ||
| 64 | |||
| 65 | ##------------------------------------------------------------------------ | ||
| 66 | ## The MPEG Audio Bit Rate Lookup Table | ||
| 67 | ## | ||
| 68 | ## MPEG Version [hashref] | ||
| 69 | ## | | ||
| 70 | ## +-- MPEG Layer [hashref] | ||
| 71 | ## | | ||
| 72 | ## +-- Bitrates [arrayref] | ||
| 73 | ##------------------------------------------------------------------------ | ||
| 74 | our $AUDIO_BITRATE = { | ||
| 75 | 1 => { | ||
| 76 | 1 => [ 0, 32, 64, 96, 128, 160, 192, 224, 256, 288, 320, 352, 384, 416, 448, 0 ], | ||
| 77 | 2 => [ 0, 32, 48, 56, 64, 80, 96, 112, 128, 160, 192, 224, 256, 320, 384, 0 ], | ||
| 78 | 3 => [ 0, 32, 40, 48, 56, 64, 80, 96, 112, 128, 160, 192, 224, 256, 320, 0 ], | ||
| 79 | }, | ||
| 80 | 2 => { | ||
| 81 | 1 => [ 0, 32, 48, 56, 64, 80, 96, 112, 128, 144, 160, 176, 192, 224, 256, 0 ], | ||
| 82 | 2 => [ 0, 8, 16, 24, 32, 40, 48, 56, 64, 80, 96, 112, 128, 144, 160, 0 ], | ||
| 83 | 3 => [ 0, 8, 16, 24, 32, 40, 48, 56, 64, 80, 96, 112, 128, 144, 160, 0 ], | ||
| 84 | }, | ||
| 85 | }; | ||
| 86 | |||
| 87 | ##------------------------------------------------------------------------ | ||
| 88 | ## The MPEG Audio Sampling Rate Lookup Table | ||
| 89 | ## | ||
| 90 | ## MPEG Layer [hashref] | ||
| 91 | ## | | ||
| 92 | ## +-- Sampling Rate [arrayref] | ||
| 93 | ## | ||
| 94 | ##------------------------------------------------------------------------ | ||
| 95 | our $AUDIO_SAMPLING_RATE = { | ||
| 96 | 1 => [ 44100, 48000, 32000, 0 ], | ||
| 97 | 2 => [ 22050, 24000, 16000, 0 ], | ||
| 98 | 3 => [ 11025, 12000, 8000, 0 ], ## mpeg2.5 | ||
| 99 | }; | ||
| 100 | |||
| 101 | |||
| 102 | |||
| 103 | ##------------------------------------------------------------------------ | ||
| 104 | ## START_CODE | ||
| 105 | ## | ||
| 106 | ## Start Codes, with 'slice' occupying 0x01..0xAF | ||
| 107 | ## No inlining here but easy lookups when codes are encountered. Only | ||
| 108 | ## really useful for debugging or dumping the bitstream structure. | ||
| 109 | ##------------------------------------------------------------------------ | ||
| 110 | our $START_CODE = { | ||
| 111 | 0x00 => 'picture_start_code', | ||
| 112 | ( map { $_ => 'slice_start_code' } ( 0x01..0xAF ) ), | ||
| 113 | 0xB0 => 'reserved', | ||
| 114 | 0xB1 => 'reserved', | ||
| 115 | 0xB2 => 'user_data_start_code', | ||
| 116 | 0xB3 => 'sequence_header_code', | ||
| 117 | 0xB4 => 'sequence_error_code', | ||
| 118 | 0xB5 => 'extension_start_code', | ||
| 119 | 0xB6 => 'reserved', | ||
| 120 | 0xB7 => 'sequence end', | ||
| 121 | 0xB8 => 'group of pictures', | ||
| 122 | }; | ||
| 123 | |||
| 124 | ##------------------------------------------------------------------------ | ||
| 125 | ## INLINED START CODES | ||
| 126 | ## | ||
| 127 | ## These should get inlined for a big speed boost. We should only need | ||
| 128 | ## these codes. | ||
| 129 | ##------------------------------------------------------------------------ | ||
| 130 | use constant PICTURE => 0x00; | ||
| 131 | use constant USERDATA => 0xB2; | ||
| 132 | use constant SEQ_HEAD => 0xB3; | ||
| 133 | use constant SEQ_ERR => 0xB4; | ||
| 134 | use constant EXT_START => 0xB5; | ||
| 135 | use constant SEQ_END => 0xB7; | ||
| 136 | use constant GOP => 0xB8; | ||
| 137 | |||
| 138 | use constant SEQ_START_CODE => 0xB3; | ||
| 139 | use constant PACK_PKT => 0xBA; | ||
| 140 | use constant SYS_PKT => 0xBB; | ||
| 141 | use constant PADDING_PKT => 0xBE; | ||
| 142 | |||
| 143 | use constant AUDIO_PKT => 0xC0; | ||
| 144 | use constant VIDEO_PKT => 0xE0; | ||
| 145 | |||
| 146 | |||
| 147 | |||
| 148 | ##------------------------------------------------------------------------ | ||
| 149 | ## FRAME TYPES | ||
| 150 | ##------------------------------------------------------------------------ | ||
| 151 | our $FRAME_TYPES = [ qw( Bad I P B ) ]; | ||
| 152 | |||
| 153 | ##------------------------------------------------------------------------ | ||
| 154 | ## STREAM_ID | ||
| 155 | ## | ||
| 156 | ## Stream Identifiers | ||
| 157 | ##------------------------------------------------------------------------ | ||
| 158 | our $STREAM_ID = { | ||
| 159 | 0xB9 => 'Program End', | ||
| 160 | 0xBA => 'Pack Header', | ||
| 161 | 0xBB => 'System Header', | ||
| 162 | 0xBC => 'Program Stream Map', | ||
| 163 | 0xBD => 'Private Stream 1', | ||
| 164 | 0xBE => 'Padding Stream', | ||
| 165 | 0xBF => 'Private Stream 2', | ||
| 166 | ( map { $_ => 'MPEG-1 or MPEG-2 Audio Stream' } ( 0xC0..0xDF ) ), | ||
| 167 | ( map { $_ => 'MPEG-1 or MPEG-2 Video Stream' } ( 0xE0..0xEF ) ), | ||
| 168 | 0xF0 => 'ECM Stream', | ||
| 169 | 0xF1 => 'EMM Stream', | ||
| 170 | 0xF2 => 'ITU-T Rec. H.222.0 | ISO/IEC 13818-1 Annex A or ISO/IEC 13818-6_DSMCC_stream', | ||
| 171 | 0xF3 => 'ISO/IEC_13522_stream', | ||
| 172 | 0xF4 => 'ITU-T Rec. H.222.1 type A', | ||
| 173 | 0xF5 => 'ITU-T Rec. H.222.1 type B', | ||
| 174 | 0xF6 => 'ITU-T Rec. H.222.1 type C', | ||
| 175 | 0xF7 => 'ITU-T Rec. H.222.1 type D', | ||
| 176 | 0xF8 => 'ITU-T Rec. H.222.1 type E', | ||
| 177 | 0xF9 => 'Ancillary Stream', | ||
| 178 | ( map { $_ => 'Reserved' } ( 0xFA..0xFE ) ), | ||
| 179 | 0xFF => 'Program Stream Directory', | ||
| 180 | }; | ||
| 181 | |||
| 182 | ##------------------------------------------------------------------------ | ||
| 183 | ## EXTENSION_CODE | ||
| 184 | ## | ||
| 185 | ## | ||
| 186 | ##------------------------------------------------------------------------ | ||
| 187 | our $EXTENSION_CODE = [ | ||
| 188 | 'Reserved', # 0000 | ||
| 189 | 'Sequence Extension ID', # 0001 | ||
| 190 | 'Sequence Display Extension ID', # 0010 | ||
| 191 | 'Quant Matrix Extension ID', # 0011 | ||
| 192 | 'Reserved', # 0100 | ||
| 193 | 'Sequence Scalable Extension ID', # 0101 | ||
| 194 | 'Reserved', # 0110 | ||
| 195 | 'Picture Display Extension ID', # 0111 | ||
| 196 | 'Picture Coding Extension ID', # 1000 | ||
| 197 | 'Picture Spatial Scalable Extension ID', # 1001 | ||
| 198 | 'Picture Temporal Scalable Extension ID', # 1010 | ||
| 199 | 'Reserved' x 5 # 1011, 1100, 1101, 1110, 1111 | ||
| 200 | ]; | ||
| 201 | |||
| 202 | ##------------------------------------------------------------------------ | ||
| 203 | ## IMAGE FORMATS | ||
| 204 | ## | ||
| 205 | ## Names of various image/video resolutions. | ||
| 206 | ##------------------------------------------------------------------------ | ||
| 207 | our $IMAGE_FORMATS = { | ||
| 208 | 352 => { 240 => 'SIF. CD WhiteBook Movies, video games.', | ||
| 209 | 480 => 'HHR. VHS equivalent', }, | ||
| 210 | 480 => { 480 => 'Bandlimited (4.2 Mhz) broadcast NTSC.', }, | ||
| 211 | 544 => { 480 => 'Laserdisc, D-2, Bandlimited PAL/SECAM.', }, | ||
| 212 | 640 => { 480 => 'Square pixel NTSC', }, | ||
| 213 | 720 => { 480 => 'CCIR 601. Studio D-1. Upper limit of Main Level.' }, | ||
| 214 | }; | ||
| 215 | |||
| 216 | |||
| 217 | |||
| 218 | ##------------------------------------------------------------------------ | ||
| 219 | ## Items to export into callers namespace by default. Note: do not export | ||
| 220 | ## names by default without a very good reason. Use EXPORT_OK instead. | ||
| 221 | ## Do not simply export all your public functions/methods/constants. | ||
| 222 | ##------------------------------------------------------------------------ | ||
| 223 | ## This allows declaration use MPEG::Info::Constants ':all'; | ||
| 224 | ## If you do not need this, moving things directly into @EXPORT or | ||
| 225 | ## @EXPORT_OK will save memory. | ||
| 226 | ##------------------------------------------------------------------------ | ||
| 227 | our %EXPORT_TAGS = ( 'all' => [ qw() ] ); | ||
| 228 | |||
| 229 | our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } ); | ||
| 230 | |||
| 231 | our @EXPORT = qw( SEQ_START_CODE $FRAME_RATE $ASPECT_RATIO | ||
| 232 | $START_CODE $STREAM_ID | ||
| 233 | $AUDIO_BITRATE $AUDIO_SAMPLING_RATE | ||
| 234 | |||
| 235 | PICTURE USERDATA SEQ_HEAD SEQ_ERR EXT_START SEQ_END GOP | ||
| 236 | SEQ_START_CODE PACK_PKT SYS_PKT PADDING_PKT | ||
| 237 | AUDIO_PKT VIDEO_PKT | ||
| 238 | ); | ||
| 239 | |||
| 240 | ##------------------------------------------------------------------------ | ||
| 241 | ## Preloaded methods go here. | ||
| 242 | ##------------------------------------------------------------------------ | ||
| 243 | 1; | ||
| 244 |