Debian Codegraph @

src/com/drew/metadata/mov/atoms/TimeToSampleAtom.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.mov.atoms;
22
23 import com.drew.lang.SequentialReader;
24 import com.drew.metadata.mov.QuickTimeContext;
25 import com.drew.metadata.mov.media.QuickTimeVideoDirectory;
26
27 import java.io.IOException;
28 import java.util.ArrayList;
29
30 /**
31 * https://developer.apple.com/library/content/documentation/QuickTime/QTFF/QTFFChap2/qtff2.html#//apple_ref/doc/uid/TP40000939-CH204-BBCGFJII
32 *
33 * @author Payton Garland
34 */
35 public class TimeToSampleAtom extends FullAtom
36 {
37 private final ArrayList<Entry> entries;
38
39 public TimeToSampleAtom(SequentialReader reader, Atom atom) throws IOException
40 {
41 super(reader, atom);
42
43 long numberOfEntries = reader.getUInt32();
44 if (numberOfEntries < Integer.MAX_VALUE) {
45 entries = new ArrayList<Entry>((int)numberOfEntries);
46 for (int i = 0; i < numberOfEntries; i++) {
47 entries.add(new Entry(reader));
48 }
49 } else {
50 entries = new ArrayList<Entry>();
51 // TODO surface this error somewhere
52 }
53 }
54
55 static class Entry
56 {
57 long sampleCount;
58 long sampleDuration;
59
60 public Entry(SequentialReader reader) throws IOException
61 {
62 sampleCount = reader.getUInt32();
63 sampleDuration = reader.getUInt32();
64 }
65 }
66
67 public void addMetadata(QuickTimeVideoDirectory directory, QuickTimeContext context)
68 {
69 if (context.timeScale != null && entries.size() > 0) {
70 float frameRate = (float)context.timeScale / (float)entries.get(0).sampleDuration;
71 directory.setFloat(QuickTimeVideoDirectory.TAG_FRAME_RATE, frameRate);
72 }
73 }
74 }