| 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.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 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 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 |
|
| 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 |
} |