Debian Codegraph @

src/com/drew/metadata/mp4/media/Mp4SoundHandler.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.metadata.mp4.media;
22
23 import com.drew.lang.SequentialReader;
24 import com.drew.lang.annotations.NotNull;
25 import com.drew.metadata.Metadata;
26 import com.drew.metadata.mp4.Mp4BoxTypes;
27 import com.drew.metadata.mp4.Mp4Context;
28 import com.drew.metadata.mp4.Mp4Dictionary;
29 import com.drew.metadata.mp4.Mp4MediaHandler;
30
31 import java.io.IOException;
32
33 public class Mp4SoundHandler extends Mp4MediaHandler<Mp4SoundDirectory>
34 {
35 public Mp4SoundHandler(Metadata metadata, Mp4Context context)
36 {
37 super(metadata, context);
38 }
39
40 @NotNull
41 @Override
42 protected Mp4SoundDirectory getDirectory()
43 {
44 return new Mp4SoundDirectory();
45 }
46
47 @Override
48 protected String getMediaInformation()
49 {
50 return Mp4BoxTypes.BOX_SOUND_MEDIA_INFO;
51 }
52
53 @Override
54 public void processSampleDescription(@NotNull SequentialReader reader) throws IOException
55 {
56 // ISO/IED 14496-12:2015 pg.7
57
58 reader.skip(4); // one byte version, three bytes flags
59
60 // ISO/IED 14496-12:2015 pg.33
61
62 long numberOfEntries = reader.getUInt32();
63 long sampleDescriptionSize = reader.getUInt32();
64 String format = reader.getString(4);
65 reader.skip(6); // Reserved
66 int dataReferenceIndex = reader.getUInt16();
67
68 // ISO/IED 14496-12:2015 pg.161
69
70 reader.skip(8); // Reserved
71 int channelCount = reader.getUInt16();
72 int sampleSize = reader.getInt16();
73 reader.skip(2); // Pre-defined
74 reader.skip(2); // Reserved
75 long sampleRate = reader.getUInt32();
76 // ChannelLayout()
77 // DownMix and/or DRC boxes
78 // More boxes as needed
79
80 // TODO review this
81 Mp4Dictionary.setLookup(Mp4SoundDirectory.TAG_AUDIO_FORMAT, format, directory);
82
83 directory.setInt(Mp4SoundDirectory.TAG_NUMBER_OF_CHANNELS, channelCount);
84 directory.setInt(Mp4SoundDirectory.TAG_AUDIO_SAMPLE_SIZE, sampleSize);
85 }
86
87 @Override
88 public void processMediaInformation(@NotNull SequentialReader reader) throws IOException
89 {
90 // ISO/IED 14496-12:2015 pg.7
91
92 reader.skip(4); // one byte version, three bytes flags
93
94 // ISO/IED 14496-12:2015 pg.159
95
96 int balance = reader.getInt16();
97 reader.skip(2); // Reserved
98
99 double integer = balance & 0xFFFF0000;
100 double fraction = (balance & 0x0000FFFF) / Math.pow(2, 4);
101 directory.setDouble(Mp4SoundDirectory.TAG_SOUND_BALANCE, integer + fraction);
102 }
103
104 @Override
105 protected void processTimeToSample(@NotNull SequentialReader reader, Mp4Context context) throws IOException
106 {
107 // ISO/IED 14496-12:2015 pg.7
108
109 reader.skip(4); // one byte version, three bytes flags
110
111 // ISO/IED 14496-12:2015 pg.37
112
113 long entryCount = reader.getUInt32();
114
115 // skip entries (4 bytes sample count, 4 bytes sample delta, per entry)
116 reader.skip(entryCount * 8);
117
118 if (context.timeScale != null) {
119 directory.setDouble(Mp4SoundDirectory.TAG_AUDIO_SAMPLE_RATE, context.timeScale);
120 }
121 }
122 }