Image/ExifTool/MISB.pm untested

filter: Statementstmt 0.0% 0 / 109 Branchbran 0.0% 0 / 24 Conditioncond 0.0% 0 / 11 MC/DCmcdc 0.0% 0 / 7 Subroutinesub 0.0% 0 / 6 Podpod 0.0% 0 / 3 totaltotal 0.0% 0 / 160 CC 13 SCAR 38.9
CC
13
Cov
0%
ParseMISB
72.0
ProcessKLV
42.0
BEGIN
2.0
CRAP 49.1
1 #------------------------------------------------------------------------------
2 # File: MISB.pm
3 #
4 # Description: Read Motion Industry Standards Board metadata
5 #
6 # Revisions: 2022/10/08 - P. Harvey Created
7 #
8 # References: 1) https://dokumen.tips/documents/nato-standardization-agreement-stanag-4609-ed-3.html
9 # 2) https://upload.wikimedia.org/wikipedia/commons/1/19/MISB_Standard_0601.pdf
10 # 3) https://dokumen.tips/documents/misb-st-010211-standard-security-metadata-universal-standard-describes-the-use.html
11 #------------------------------------------------------------------------------
12  
13 package Image::ExifTool::MISB;
14  
15 use strict;
16 use vars qw($VERSION);
17 use Image::ExifTool qw(:DataAccess :Utils);
18  
19 $VERSION = '1.00';
20  
21 sub ProcessKLV($$$);
22  
23 my %timeInfo = (
24 Groups => { 2 => 'Time' },
25 Format => 'int64u',
26 ValueConv => 'ConvertUnixTime($val/1e6, 0, 6) . "Z"',
27 PrintConv => '$self->ConvertDateTime($val)',
28 );
29 my %latInfo = (
30 Format => 'int32s',
31 ValueConv => '$val * 90 / 0x7fffffff',
32 PrintConv => 'Image::ExifTool::GPS::ToDMS($self, $val, 1, "N")',
33 );
34 my %lonInfo = (
35 Format => 'int32s',
36 ValueConv => '$val * 180 / 0x7fffffff',
37 PrintConv => 'Image::ExifTool::GPS::ToDMS($self, $val, 1, "E")',
38 );
39 my %altInfo = (
40 Format => 'int16u',
41 ValueConv => '$val * 19900 / 0xffff - 900',
42 PrintConv => 'sprintf("%.2f m", $val)',
43 );
44  
45 # default format based on size of unknown KLV information
46 my %defaultFormat = (
47 1 => 'int8u',
48 2 => 'int16u',
49 4 => 'int32u',
50 8 => 'int64u',
51 );
52  
53 %Image::ExifTool::MISB::Main = (
54 GROUPS => { 0 => 'MISB', 1 => 'MISB', 2 => 'Other' },
55 VARS => { LONG_TAGS => 2 },
56 NOTES => q{
57 These tags are extracted from STANAG-4609 MISB (Motion Industry Standards
58 Board) KLV-format metadata in M2TS videos.
59 },
60 '060e2b34020b01010e01030101000000' => {
61 Name => 'UASDataLink',
62 SubDirectory => { TagTable => 'Image::ExifTool::MISB::UASDatalink' },
63 },
64 '060e2b3402030101434e415644494147' => { # "CNAVDIAG" written by ChurchillNavigation ION
65 Name => 'ChurchillNav',
66 SubDirectory => {
67 TagTable => 'Image::ExifTool::MISB::ChurchillNav',
68 ByteOrder => 'LittleEndian', # !!
69 },
70 },
71 '060E2B34030101010E01030302000000' => { # (NC)
72 Name => 'Security',
73 SubDirectory => { TagTable => 'Image::ExifTool::MISB::Security' },
74 },
75 '<other>' => {
76 Name => 'Unknown',
77 SubDirectory => { TagTable => 'Image::ExifTool::MISB::Unknown' },
78 },
79 );
80  
81 # UAS datalink local set tags (ref 2, MISB ST 0601.11)
82 %Image::ExifTool::MISB::UASDatalink = (
83 GROUPS => { 0 => 'MISB', 1 => 'MISB', 2 => 'Location' },
84 PROCESS_PROC => \&ProcessKLV,
85 NOTES => 'Tags extracted from the MISB ST 0601.11 UAS Datalink local set.',
86 1 => { Name => 'Checksum', Format => 'int16u' },
87 2 => { Name => 'GPSDateTime', %timeInfo },
88 3 => { Name => 'MissionID', Format => 'string' },
89 4 => { Name => 'TailNumber', Format => 'string' },
90 5 => { Name => 'GPSTrack', Format => 'int16u', ValueConv => '$val * 360 / 0xffff' },
91 6 => { Name => 'PitchAngle', Format => 'int16s', ValueConv => '$val * 20 / 0x7fff' },
92 7 => { Name => 'RollAngle', Format => 'int16s', ValueConv => '$val * 50 / 0x7fff' },
93 8 => { Name => 'TrueAirspeed', Format => 'int8u', PrintConv => '"$val m/s"' },
94 9 => { Name => 'IndicatedAirspeed', Format => 'int8u', PrintConv => '"$val m/s"' },
95 10 => { Name => 'ProjectIDCode', Format => 'string' },
96 11 => { Name => 'SensorName', Format => 'string' },
97 12 => { Name => 'ImageCoordinateSystem', Format => 'string' },
98 13 => { Name => 'GPSLatitude', %latInfo },
99 14 => { Name => 'GPSLongitude', %lonInfo },
100 15 => { Name => 'GPSAltitude', %altInfo },
101 16 => { Name => 'HorizontalFieldOfView', Format => 'int16u', ValueConv => '$val * 180 / 0xffff' },
102 17 => { Name => 'VerticalFieldOfView', Format => 'int16u', ValueConv => '$val * 180 / 0xffff' },
103 18 => { Name => 'SensorRelativeAzimuthAngle',Format=> 'int32u', ValueConv => '$val * 360 / 0xffffffff' },
104 19 => { Name => 'SensorRelativeElevationAngle',Format=>'int32s',ValueConv => '$val * 180 / 0x7fffffff' },
105 20 => { Name => 'SensorRelativeRollAngle', Format => 'int32u', ValueConv => '$val * 360 / 0xffffffff' },
106 21 => { Name => 'SlantRange', Format => 'int32u', ValueConv => '$val * 5000000 / 0xffffffff' },
107 22 => { Name => 'TargetWidth', Format => 'int16u', ValueConv => '$val * 10000 / 0xffff' },
108 23 => { Name => 'FrameCenterLatitude', %latInfo },
109 24 => { Name => 'FrameCenterLongitude', %lonInfo },
110 25 => { Name => 'FrameCenterElevation', %altInfo },
111 26 => { Name => 'OffsetCornerLatitude1', Format => 'int16s', ValueConv => '$val * .075 / 0x7fff' },
112 27 => { Name => 'OffsetCornerLongitude1', Format => 'int16s', ValueConv => '$val * .075 / 0x7fff' },
113 28 => { Name => 'OffsetCornerLatitude2', Format => 'int16s', ValueConv => '$val * .075 / 0x7fff' },
114 29 => { Name => 'OffsetCornerLongitude2', Format => 'int16s', ValueConv => '$val * .075 / 0x7fff' },
115 30 => { Name => 'OffsetCornerLatitude3', Format => 'int16s', ValueConv => '$val * .075 / 0x7fff' },
116 31 => { Name => 'OffsetCornerLongitude3', Format => 'int16s', ValueConv => '$val * .075 / 0x7fff' },
117 32 => { Name => 'OffsetCornerLatitude4', Format => 'int16s', ValueConv => '$val * .075 / 0x7fff' },
118 33 => { Name => 'OffsetCornerLongitude4', Format => 'int16s', ValueConv => '$val * .075 / 0x7fff' },
119 34 => { Name => 'IcingDetected', Format => 'int8u', PrintConv => { 0 => 'n/a', 1 => 'No', 2 => 'Yes' } },
120 35 => { Name => 'WindDirection', Format => 'int16u', ValueConv => '$val * 360 / 0xffff' },
121 36 => { Name => 'WindSpeed', Format => 'int8u', ValueConv => '$val * 100 / 0xff', Notes => 'm/s' },
122 37 => { Name => 'StaticPressure', Format => 'int16u', ValueConv => '$val * 5000 / 0xffff', Notes => 'mbar' },
123 38 => { Name => 'DensityAltitude', Format => 'int16u', ValueConv => '$val * 19900 / 0xffff - 900' },
124 39 => { Name => 'AirTemperature', Format => 'int8s' },
125 40 => { Name => 'TargetLocationLatitude', %latInfo },
126 41 => { Name => 'TargetLocationLongitude', %lonInfo },
127 42 => { Name => 'TargetLocationElevation', %altInfo },
128 43 => { Name => 'TargetTrackGateWidth', Format => 'int8u' },
129 44 => { Name => 'TargetTrackGateHeight', Format => 'int8u' },
130 45 => { Name => 'TargetErrorEstimateCE90', Format => 'int16u' },
131 46 => { Name => 'TargetErrorEstimateLE90', Format => 'int16u' },
132 47 => { Name => 'GenericFlagData01',
133 Format => 'int8u',
134 PrintConv => { BITMASK => {
135 0 => 'Laser range',
136 1 => 'Auto-track',
137 2 => 'IR polarity black',
138 3 => 'Icing detected',
139 4 => 'Slant range measured',
140 5 => 'Image invalid',
141 }},
142 },
143 48 => { Name => 'SecurityLocalMetadataSet', SubDirectory => { TagTable => 'Image::ExifTool::MISB::Security' } },
144 49 => { Name => 'DifferentialPressure', Format => 'int16u', ValueConv => '$val * 5000 / 0xffff' },
145 50 => { Name => 'AngleOfAttack', Format => 'int16s', ValueConv => '$val * 20 / 0x7fff' },
146 51 => { Name => 'VerticalSpeed', Format => 'int16s', ValueConv => '$val * 180 / 0x7fff', Notes => 'm/s' },
147 52 => { Name => 'SideslipAngle', Format => 'int16s', ValueConv => '$val * 20 / 0x7fff' },
148 53 => { Name => 'AirfieldBarometricPressure',Format=> 'int16u', ValueConv => '$val * 5000 / 0xffff' },
149 54 => { Name => 'AirfieldElevation', %altInfo },
150 55 => { Name => 'RelativeHumidity', Format => 'int8u', ValueConv => '$val * 100 / 0xff' },
151 56 => { Name => 'GPSSpeed', Format => 'int8u', Notes => 'm/s' },
152 57 => { Name => 'GroundRange', Format => 'int32u', ValueConv => '$val * 5000000 / 0xffffffff' },
153 58 => { Name => 'FuelRemaining', Format => 'int16u', ValueConv => '$val * 10000 / 0xffff', Notes => 'kg' },
154 59 => { Name => 'CallSign', Format => 'string' },
155 60 => { Name => 'WeaponLoad', Format => 'int16u', PrintConv => 'sprintf("0x%.4x",$val)' },
156 61 => { Name => 'WeaponFired', Format => 'int8u', PrintConv => 'sprintf("0x%.2x",$val)' },
157 62 => { Name => 'LaserPRFCode', Format => 'int16u' },
158 63 => { Name => 'SensorFieldOfViewName', Format => 'int8u',
159 PrintConv => {
160 0 => 'Ultranarrow',
161 1 => 'Narrow',
162 2 => 'Medium',
163 3 => 'Wide',
164 4 => 'Ultrawide',
165 5 => 'Narrow Medium',
166 6 => '2x Ultranarrow',
167 7 => '4x Ultranarrow',
168 },
169 },
170 64 => { Name => 'MagneticHeading', Format => 'int16u', ValueConv => '$val * 360 / 0xffff' },
171 65 => { Name => 'UAS_LSVersionNumber', Format => 'int8u' },
172 66 => { Name => 'TargetLocationCovarianceMatrix', Format => 'undef', ValueConv => '\$val' },
173 67 => { Name => 'AlternateLatitude', %latInfo },
174 68 => { Name => 'AlternateLongitude', %lonInfo },
175 69 => { Name => 'AlternateAltitude', %altInfo },
176 70 => { Name => 'AlternateName', Format => 'string' },
177 71 => { Name => 'AlternateHeading', Format => 'int16u', ValueConv => '$val * 360 / 0xffff' },
178 72 => { Name => 'EventStartTime', %timeInfo },
179 73 => { Name => 'RVTLocalSet', SubDirectory => { TagTable => 'Image::ExifTool::MISB::Unknown' } },
180 74 => { Name => 'VMTIDataSet', SubDirectory => { TagTable => 'Image::ExifTool::MISB::Unknown' } },
181 75 => { Name => 'SensorEllipsoidHeight', %altInfo },
182 76 => { Name => 'AlternateEllipsoidHeight', %altInfo },
183 77 => { Name => 'OperationalMode', Format => 'int8u',
184 PrintConv => {
185 0 => 'Other',
186 1 => 'Operational',
187 2 => 'Training',
188 3 => 'Exercise',
189 4 => 'Maintenance',
190 },
191 },
192 78 => { Name => 'FrameCenterHeightAboveEllipsoid', %altInfo },
193 79 => { Name => 'SensorVelocityNorth', Format => 'int16s', ValueConv => '$val * 327 / 0x7fff' },
194 80 => { Name => 'SensorVelocityEast', Format => 'int16s', ValueConv => '$val * 327 / 0x7fff' },
195 81 => { Name => 'ImageHorizonPixelPack', Format => 'undef', ValueConv => '\$val' },
196 82 => { Name => 'CornerLatitude1', %latInfo },
197 83 => { Name => 'CornerLongitude1', %lonInfo },
198 84 => { Name => 'CornerLatitude2', %latInfo },
199 85 => { Name => 'CornerLongitude2', %lonInfo },
200 86 => { Name => 'CornerLatitude3', %latInfo },
201 87 => { Name => 'CornerLongitude3', %lonInfo },
202 88 => { Name => 'CornerLatitude4', %latInfo },
203 89 => { Name => 'CornerLongitude4', %lonInfo },
204 90 => { Name => 'FullPitchAngle', Format => 'int32s', ValueConv => '$val * 90 / 0x7fffffff' },
205 91 => { Name => 'FullRollAngle', Format => 'int32s', ValueConv => '$val * 90 / 0x7fffffff' },
206 92 => { Name => 'FullAngleOfAttack', Format => 'int32s', ValueConv => '$val * 90 / 0x7fffffff' },
207 93 => { Name => 'FullSideslipAngle', Format => 'int32s', ValueConv => '$val * 90 / 0x7fffffff' },
208 94 => { Name => 'MIISCoreIdentifier', Format => 'undef', ValueConv => '\$val' },
209 95 => { Name => 'SARMotionImageryData', SubDirectory => { TagTable => 'Image::ExifTool::MISB::Unknown' } },
210 96 => { Name => 'TargetWidthExtended', Format => 'undef', ValueConv => '\$val' }, # IMAPB format
211 97 => { Name => 'RangeImageLocalSet', SubDirectory => { TagTable => 'Image::ExifTool::MISB::Unknown' } },
212 98 => { Name => 'GeoregistrationLocalSet', SubDirectory => { TagTable => 'Image::ExifTool::MISB::Unknown' } },
213 99 => { Name => 'CompositeImagingLocalSet', SubDirectory => { TagTable => 'Image::ExifTool::MISB::Unknown' } },
214 100=> { Name => 'SegmentLocalSet', SubDirectory => { TagTable => 'Image::ExifTool::MISB::Unknown' } },
215 101=> { Name => 'AmendLocalSet', SubDirectory => { TagTable => 'Image::ExifTool::MISB::Unknown' } },
216 102=> { Name => 'SDCC-FLP', Format => 'undef', ValueConv => '\$val' }, # IMAPB format
217 103=> { Name => 'DensityAltitudeExtended', Format => 'undef', ValueConv => '\$val' }, # IMAPB format
218 104=> { Name => 'SensorEllipsoidHeightExtended', Format => 'undef', ValueConv => '\$val' }, # IMAPB format
219 105=> { Name => 'AlternateEllipsoidHeightExtended', Format => 'undef', ValueConv => '\$val' }, # IMAPB format
220 );
221  
222 # tags from MISB ST 0102.11 local set
223 %Image::ExifTool::MISB::Security = (
224 GROUPS => { 0 => 'MISB', 1 => 'MISB', 2 => 'Document' },
225 PROCESS_PROC => \&ProcessKLV,
226 NOTES => 'Tags extracted from the MISB ST 0102.11 Security Metadata local set.',
227 1 => { Name => 'SecurityClassification', PrintConv => {
228 1 => 'Unclassified',
229 2 => 'Restricted',
230 3 => 'Confidential',
231 4 => 'Secret',
232 5 => 'Top Secret',
233 }},
234 2 => { Name => 'ClassifyingCountryCodeMethod', PrintConv => {
235 0x01 => 'ISO-3166 Two Letter',
236 0x02 => 'ISO-3166 Three Letter',
237 0x03 => 'FIPS 10-4 Two Letter',
238 0x04 => 'FIPS 10-4 Four Letter',
239 0x05 => 'ISO-3166 Numeric',
240 0x06 => '1059 Two Letter',
241 0x07 => '1059 Three Letter',
242 0x0a => 'FIPS 10-4 Mixed',
243 0x0b => 'ISO 3166 Mixed',
244 0x0c => 'STANAG 1059 Mixed',
245 0x0d => 'GENC Two Letter',
246 0x0e => 'GENC Three Letter',
247 0x0f => 'GENC Numeric',
248 0x10 => 'GENC Mixed',
249 }},
250 3 => { Name => 'ClassifyingCountry', Format => 'string', PrintConv => '$val =~ s(^//)(); $val' },
251 4 => 'SecuritySCI-SHIInformation',
252 5 => { Name => 'Caveats', Format => 'string' },
253 6 => { Name => 'ReleasingInstructions',Format => 'string' },
254 7 => { Name => 'ClassifiedBy', Format => 'string' },
255 8 => { Name => 'DerivedFrom', Format => 'string' },
256 9 => { Name => 'ClassificationReason', Format => 'string' },
257 10 => {
258 Name => 'DeclassificationDate',
259 Format => 'string',
260 Groups => { 2 => 'Time' },
261 ValueConv => '$val =~ s/(\d{4})(\d{2})(\d{2})/$1:$2:$3/; $val',
262 },
263 11 => 'ClassificationAndMarkingSystem',
264 12 => { Name => 'ObjectCountryCodingMethod', PrintConv => {
265 0x01 => 'ISO-3166 Two Letter',
266 0x02 => 'ISO-3166 Three Letter',
267 0x03 => 'ISO-3166 Numeric',
268 0x04 => 'FIPS 10-4 Two Letter',
269 0x05 => 'FIPS 10-4 Four Letter',
270 0x06 => '1059 Two Letter',
271 0x07 => '1059 Three Letter',
272 0x0d => 'GENC Two Letter',
273 0x0e => 'GENC Three Letter',
274 0x0f => 'GENC Numeric',
275 0x40 => 'GENC AdminSub',
276 }},
277 13 => { Name => 'ObjectCountryCodes', Format => 'string', PrintConv => '$val =~ s(^//)(); $val' },
278 14 => { Name => 'ClassificationComments', Format => 'string' },
279 15 => 'UMID',
280 16 => 'StreamID',
281 17 => 'TransportStreamID',
282 21 => 'ItemDesignatorID',
283 22 => { Name => 'SecurityVersion', Format => 'int16u', PrintConv => '"0102.$val"' },
284 23 => {
285 Name => 'ClassifyingCountryCodingMethodDate',
286 Groups => { 2 => 'Time' },
287 Format => 'string',
288 ValueConv => '$val=~tr/-/:/; $val',
289 },
290 24 => {
291 Name => 'ObjectCountryCodingMethodDate',
292 Groups => { 2 => 'Time' },
293 Format => 'string',
294 ValueConv => '$val=~tr/-/:/; $val',
295 },
296 );
297  
298 # I have seen these, but don't know what they are for - PH
299 # (they look interesting, but remain static through my sample video)
300 %Image::ExifTool::MISB::ChurchillNav = (
301 GROUPS => { 0 => 'MISB', 1 => 'MISB', 2 => 'Other' },
302 PROCESS_PROC => \&ProcessKLV,
303 TAG_PREFIX => 'ChurchillNav',
304 NOTES => q{
305 Proprietary tags used by Churchill Navigation units. These tags are all
306 currently unknown, but extracted with the Unknown option.
307 },
308 # Note: tag ID's are decimal (because the MISB specification uses decimal ID's)
309 1 => { Name => 'ChurchillNav_0x0001', Format => 'double', Unknown => 1, Hidden => 1 },
310 2 => { Name => 'ChurchillNav_0x0002', Format => 'double', Unknown => 1, Hidden => 1 },
311 3 => { Name => 'ChurchillNav_0x0003', Format => 'double', Unknown => 1, Hidden => 1 },
312 4 => { Name => 'ChurchillNav_0x0004', Format => 'double', Unknown => 1, Hidden => 1 },
313 5 => { Name => 'ChurchillNav_0x0005', Format => 'double', Unknown => 1, Hidden => 1 },
314 6 => { Name => 'ChurchillNav_0x0006', Format => 'double', Unknown => 1, Hidden => 1 },
315 9 => { Name => 'ChurchillNav_0x0009', Format => 'double', Unknown => 1, Hidden => 1 },
316 10 => { Name => 'ChurchillNav_0x000a', Format => 'double', Unknown => 1, Hidden => 1 },
317 11 => { Name => 'ChurchillNav_0x000b', Format => 'string', Unknown => 1, Hidden => 1 },
318 12 => { Name => 'ChurchillNav_0x000c', Format => 'double', Unknown => 1, Hidden => 1 },
319 13 => { Name => 'ChurchillNav_0x000d', Format => 'double', Unknown => 1, Hidden => 1 },
320 14 => { Name => 'ChurchillNav_0x000e', Format => 'double', Unknown => 1, Hidden => 1 },
321 16 => { Name => 'ChurchillNav_0x0010', Format => 'double', Unknown => 1, Hidden => 1 },
322 17 => { Name => 'ChurchillNav_0x0011', Format => 'double', Unknown => 1, Hidden => 1 },
323 18 => { Name => 'ChurchillNav_0x0012', Format => 'double', Unknown => 1, Hidden => 1 },
324 20 => { Name => 'ChurchillNav_0x0014', Format => 'double', Unknown => 1, Hidden => 1 },
325 );
326  
327 %Image::ExifTool::MISB::Unknown = (
328 GROUPS => { 0 => 'MISB', 1 => 'MISB', 2 => 'Other' },
329 PROCESS_PROC => \&ProcessKLV,
330 NOTES => 'Other tags are extracted with the Unknown option.',
331 );
332  
333 #------------------------------------------------------------------------------
334 # Process KLV (Key-Length-Value) metadata
335 # Inputs: 0) ExifTool ref, 1) dirInfo ref, 2) tag table ref
336 # Returns: 1 if anything was extracted
337 sub ProcessKLV($$$)
338 {
339 my ($et, $dirInfo, $tagTablePtr) = @_;
340 my $dataPt = $$dirInfo{DataPt};
341 my $dirStart = $$dirInfo{DirStart};
342 my $dirEnd = $dirStart + $$dirInfo{DirLen};
343 my $rtnVal = 0;
344 my $pos;
345  
346 $et->VerboseDir($$dirInfo{DirName}, undef, $$dirInfo{DirLen});
347  
348 # loop through KLV packets
349 for ($pos=$dirStart; $pos<$dirEnd-1; ) {
350 my $tag = Get8u($dataPt, $pos++);
351 my $len = Get8u($dataPt, $pos++);
352 if ($len & 0x80) {
353 my $n = $len & 0x7f;
354 last if $pos + $n > $dirEnd;
355 $len = 0;
356 $len = $len * 256 + Get8u($dataPt, $pos++) foreach 1..$n;
357 }
358 last if $pos + $len > $dirEnd;
359 # best guess at decoding the value
360 my $val;
361 my $tagInfo = $$tagTablePtr{$tag} || { };
362 my $format = $$tagInfo{Format} || $defaultFormat{$len};
363 if ($format) {
364 $val = ReadValue($dataPt, $pos, $format, undef, $len);
365 } else {
366 # treat as string or binary data
367 $val = substr($$dataPt, $pos, $len);
368 if ($val !~ /^[\t\n\r\x20-\x7e]*$/) {
369 my $dat = $val;
370 $val = \$val;
371 }
372 }
373 $et->HandleTag($tagTablePtr, $tag, $val,
374 DataPt => $dataPt,
375 Start => $pos,
376 Size => $len,
377 );
378 $rtnVal = 1;
379 $pos += $len;
380 }
381 return $rtnVal;
382 }
383  
384 #------------------------------------------------------------------------------
385 # Parse MISB metadata
386 # Inputs: 0) ExifTool ref, 1) data ref, 2) tag table ref
387 # Returns: 1 if something was extracted, 0 otherwise
388 sub ParseMISB($$$)
389 {
390 my ($et, $dataPt, $tagTablePtr) = @_;
391 my $end = length $$dataPt;
392 my $rtnVal = 0;
393 my $unknown = $$et{OPTIONS}{Unknown};
394 my $verbose = $$et{OPTIONS}{Verbose};
395 my $pos;
396  
397 # increment document number in case we find any tags
398 $$et{DOC_NUM} = ++$$et{DOC_COUNT};
399 $$et{INDENT} .= '| ';
400  
401 # skip the 5-byte header (ref 1 pg. 68)
402 # 0 - int8u: metadata service ID (0x00)
403 # 1 - int8u: sequence number (increments each packet)
404 # 2 - int8u: 0x0f (bits: cell fragmentation 00, decoder config 0, random access 0, reserved 1111)
405 # 3-4 - int16u: data length (ie. packet length - 5)
406 for ($pos = 5; $pos + 16 < $end; ) {
407 my $key = unpack('H*', substr($$dataPt, $pos, 16));
408 $pos += 16;
409 my $len = Get8u($dataPt, $pos);
410 ++$pos;
411 if ($len & 0x80) { # is this a BER long form integer? (Basic Encoding Rules)
412 my $n = $len & 0x7f;
413 $len = 0;
414 return $rtnVal if $pos + $n > $end;
415 $len = $len * 256 + Get8u($dataPt, $pos++) foreach 1..$n;
416 }
417 my $tagInfo = $$tagTablePtr{$key};
418 unless ($tagInfo) {
419 if ($verbose or $unknown) {
420 # (assume this is a data set, but it maybe be a simple tag)
421 $tagInfo = { Name => "MISB_$key", SubDirectory => { TagTable => 'Image::ExifTool::MISB::Unknown' } };
422 $et->VPrint(0," [adding $$tagInfo{Name}]\n");
423 AddTagToTable($tagTablePtr, $key, $tagInfo);
424 } else {
425 # skip this record
426 $pos += $len;
427 next;
428 }
429 }
430 if ($pos + $len > $end) {
431 $len = $end - $pos;
432 $et->VPrint(0, "$$et{INDENT}(truncated record, only $len bytes available)\n");
433 }
434 my $dir = $$tagInfo{SubDirectory};
435 SetByteOrder($$dir{ByteOrder}) if $$dir{ByteOrder};
436 my %dirInfo = (
437 DataPt => $dataPt,
438 DirStart => $pos,
439 DirLen => $len,
440 DirName => $$tagInfo{Name},
441 );
442 ProcessKLV($et, \%dirInfo, GetTagTable($$dir{TagTable})) and $rtnVal = 1;
443 SetByteOrder('MM');
444 $pos += $len;
445 }
446 $$et{INDENT} = substr($$et{INDENT},0,-2);
447 delete $$et{DOC_NUM};
448 --$$et{DOC_COUNT} unless $rtnVal;
449 return $rtnVal;
450 }
451  
452 1; # end
453  
454 __END__