Debian Codegraph @

src/com/drew/metadata/mov/QuickTimeMediaHandler.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;
22
23 import com.drew.imaging.quicktime.QuickTimeHandler;
24 import com.drew.lang.DateUtil;
25 import com.drew.lang.SequentialByteArrayReader;
26 import com.drew.lang.SequentialReader;
27 import com.drew.lang.annotations.NotNull;
28 import com.drew.lang.annotations.Nullable;
29 import com.drew.metadata.Metadata;
30 import com.drew.metadata.mov.atoms.Atom;
31 import com.drew.metadata.mov.media.QuickTimeMediaDirectory;
32 import java.io.IOException;
33
34 /**
35 * Classes that extend this class should be from the media dat atom types:
36 * https://developer.apple.com/library/content/documentation/QuickTime/QTFF/QTFFChap3/qtff3.html#//apple_ref/doc/uid/TP40000939-CH205-SW1
37 *
38 * @author Payton Garland
39 */
40 public abstract class QuickTimeMediaHandler<T extends QuickTimeDirectory> extends QuickTimeHandler<T>
41 {
42 public QuickTimeMediaHandler(Metadata metadata, QuickTimeContext context)
43 {
44 super(metadata);
45
46 if (context.creationTime != null && context.modificationTime != null) {
47 // Get creation/modification times
48 directory.setDate(
49 QuickTimeMediaDirectory.TAG_CREATION_TIME,
50 DateUtil.get1Jan1904EpochDate(context.creationTime)
51 );
52 directory.setDate(
53 QuickTimeMediaDirectory.TAG_MODIFICATION_TIME,
54 DateUtil.get1Jan1904EpochDate(context.modificationTime)
55 );
56 }
57 }
58
59 @Override
60 public boolean shouldAcceptAtom(@NotNull Atom atom)
61 {
62 return atom.type.equals(getMediaInformation())
63 || atom.type.equals(QuickTimeAtomTypes.ATOM_SAMPLE_DESCRIPTION)
64 || atom.type.equals(QuickTimeAtomTypes.ATOM_TIME_TO_SAMPLE);
65 }
66
67 @Override
68 public boolean shouldAcceptContainer(@NotNull Atom atom)
69 {
70 return atom.type.equals(QuickTimeContainerTypes.ATOM_SAMPLE_TABLE)
71 || atom.type.equals(QuickTimeContainerTypes.ATOM_MEDIA_INFORMATION)
72 || atom.type.equals(QuickTimeContainerTypes.ATOM_MEDIA_BASE)
73 || atom.type.equals("tmcd");
74 }
75
76 @Override
77 public QuickTimeMediaHandler<?> processAtom(@NotNull Atom atom, @Nullable byte[] payload, QuickTimeContext context) throws IOException
78 {
79 if (payload != null) {
80 SequentialReader reader = new SequentialByteArrayReader(payload);
81 if (atom.type.equals(getMediaInformation())) {
82 processMediaInformation(reader, atom);
83 } else if (atom.type.equals(QuickTimeAtomTypes.ATOM_SAMPLE_DESCRIPTION)) {
84 processSampleDescription(reader, atom);
85 } else if (atom.type.equals(QuickTimeAtomTypes.ATOM_TIME_TO_SAMPLE)) {
86 processTimeToSample(reader, atom, context);
87 }
88 }
89 return this;
90 }
91
92 protected abstract String getMediaInformation();
93
94 protected abstract void processSampleDescription(@NotNull SequentialReader reader, @NotNull Atom atom) throws IOException;
95
96 protected abstract void processMediaInformation(@NotNull SequentialReader reader, @NotNull Atom atom) throws IOException;
97
98 protected abstract void processTimeToSample(@NotNull SequentialReader reader, @NotNull Atom atom, QuickTimeContext context) throws IOException;
99 }