Info/MPEG/Constants.pm

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