Debian Codegraph @

src/com/drew/imaging/mp3/MpegAudioTypeChecker.java

raw symbols SCIP
1 /*
2 * Copyright 2002-2019 Drew Noakes and contributors
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *
16 * More information about this project is available at:
17 *
18 * https://drewnoakes.com/code/exif/
19 * https://github.com/drewnoakes/metadata-extractor
20 */
21 package com.drew.imaging.mp3;
22
23 import com.drew.imaging.FileType;
24 import com.drew.imaging.TypeChecker;
25
26 public class MpegAudioTypeChecker implements TypeChecker
27 {
28 /*
29 MPEG Audio http://www.mp3-tech.org/programmer/frame_header.html
30
31 Bits
32 11 Frame sync (all bits must be set)
33 2 MPEG Audio version ID
34 00 - MPEG Version 2.5 (later extension of MPEG 2)
35 01 - Reserved
36 10 - MPEG Version 2 (ISO/IEC 13818-3)
37 11 - MPEG Version 1 (ISO/IEC 11172-3)
38 2 Layer description
39 00 - Reserved
40 01 - Layer III
41 10 - Layer II
42 11 - Layer I
43
44 Additional bits contain more information, but are not required for file type identification.
45 */
46 @Override
47 public int getByteCount()
48 {
49 return 3;
50 }
51
52 @Override
53 public FileType checkType(byte[] bytes)
54 {
55 // MPEG audio requires the first 11 bits to be set
56 if (bytes[0] != (byte)0xFF || (bytes[1] & 0xE0) != 0xE0)
57 return FileType.Unknown;
58
59 // The MPEG Audio version ID value of 01 is reserved
60 int version = (bytes[1] >> 3) & 3;
61 if (version == 1)
62 return FileType.Unknown;
63
64 // The layer description value of 00 is reserved
65 int layerDescription = (bytes[1] >> 1) & 3;
66 if (layerDescription == 0)
67 return FileType.Unknown;
68
69 // The bitrate index value of 1111 is disallowed
70 int bitrateIndex = bytes[2] >> 4;
71 if (bitrateIndex == 0x0F)
72 return FileType.Unknown;
73
74 return FileType.Mp3;
75 }
76 }