Debian Codegraph @

src/com/drew/metadata/mp4/Mp4MediaHandler.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;
22
23 import com.drew.imaging.mp4.Mp4Handler;
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.mp4.media.Mp4MediaDirectory;
31
32 import java.io.IOException;
33
34 public abstract class Mp4MediaHandler<T extends Mp4MediaDirectory> extends Mp4Handler<T>
35 {
36 public Mp4MediaHandler(Metadata metadata, Mp4Context context)
37 {
38 super(metadata);
39
40 // Get creation/modification times
41 if (context.creationTime != null) {
42 directory.setDate(
43 Mp4MediaDirectory.TAG_CREATION_TIME,
44 DateUtil.get1Jan1904EpochDate(context.creationTime)
45 );
46 }
47
48 if (context.modificationTime != null) {
49 directory.setDate(
50 Mp4MediaDirectory.TAG_MODIFICATION_TIME,
51 DateUtil.get1Jan1904EpochDate(context.modificationTime)
52 );
53 }
54
55 if (context.language != null) {
56 directory.setString(Mp4MediaDirectory.TAG_LANGUAGE_CODE, context.language);
57 }
58 }
59
60 @Override
61 public boolean shouldAcceptBox(@NotNull String type)
62 {
63 return type.equals(getMediaInformation())
64 || type.equals(Mp4BoxTypes.BOX_SAMPLE_DESCRIPTION)
65 || type.equals(Mp4BoxTypes.BOX_TIME_TO_SAMPLE);
66 }
67
68 @Override
69 public boolean shouldAcceptContainer(@NotNull String type)
70 {
71 return type.equals(Mp4ContainerTypes.BOX_SAMPLE_TABLE)
72 || type.equals(Mp4ContainerTypes.BOX_MEDIA_INFORMATION);
73 }
74
75 @Override
76 public Mp4Handler<?> processBox(@NotNull String type, @Nullable byte[] payload, long boxSize, Mp4Context context) throws IOException
77 {
78 if (payload != null) {
79 SequentialReader reader = new SequentialByteArrayReader(payload);
80 if (type.equals(getMediaInformation())) {
81 processMediaInformation(reader);
82 } else if (type.equals(Mp4BoxTypes.BOX_SAMPLE_DESCRIPTION)) {
83 processSampleDescription(reader);
84 } else if (type.equals(Mp4BoxTypes.BOX_TIME_TO_SAMPLE)) {
85 processTimeToSample(reader, context);
86 }
87 }
88 return this;
89 }
90
91 protected abstract String getMediaInformation();
92
93 protected abstract void processSampleDescription(@NotNull SequentialReader reader) throws IOException;
94
95 protected abstract void processMediaInformation(@NotNull SequentialReader reader) throws IOException;
96
97 protected abstract void processTimeToSample(@NotNull SequentialReader reader, Mp4Context context) throws IOException;
98 }