| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 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 |
|
| 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 |
} |