| 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.SequentialByteArrayReader; |
| 25 |
import com.drew.lang.SequentialReader; |
| 26 |
import com.drew.lang.annotations.NotNull; |
| 27 |
import com.drew.lang.annotations.Nullable; |
| 28 |
import com.drew.metadata.Metadata; |
| 29 |
import com.drew.metadata.mov.atoms.*; |
| 30 |
import com.drew.metadata.mov.atoms.canon.CanonThumbnailAtom; |
| 31 |
import com.drew.metadata.xmp.XmpReader; |
| 32 |
|
| 33 |
import java.io.IOException; |
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
public class QuickTimeAtomHandler extends QuickTimeHandler<QuickTimeDirectory> |
| 39 |
{ |
| 40 |
private QuickTimeHandlerFactory handlerFactory = new QuickTimeHandlerFactory(this); |
| 41 |
|
| 42 |
public QuickTimeAtomHandler(Metadata metadata) |
| 43 |
{ |
| 44 |
super(metadata); |
| 45 |
} |
| 46 |
|
| 47 |
@NotNull |
| 48 |
@Override |
| 49 |
protected QuickTimeDirectory createDirectory() |
| 50 |
{ |
| 51 |
return new QuickTimeDirectory(); |
| 52 |
} |
| 53 |
|
| 54 |
@Override |
| 55 |
public boolean shouldAcceptAtom(@NotNull Atom atom) |
| 56 |
{ |
| 57 |
return atom.type.equals(QuickTimeAtomTypes.ATOM_FILE_TYPE) |
| 58 |
|| atom.type.equals(QuickTimeAtomTypes.ATOM_MOVIE_HEADER) |
| 59 |
|| atom.type.equals(QuickTimeAtomTypes.ATOM_HANDLER) |
| 60 |
|| atom.type.equals(QuickTimeAtomTypes.ATOM_MEDIA_HEADER) |
| 61 |
|| atom.type.equals(QuickTimeAtomTypes.ATOM_CANON_THUMBNAIL) |
| 62 |
|| atom.type.equals(QuickTimeAtomTypes.ATOM_ADOBE_XMP) |
| 63 |
|| atom.type.equals(QuickTimeAtomTypes.ATOM_TRACK_HEADER); |
| 64 |
} |
| 65 |
|
| 66 |
@Override |
| 67 |
public boolean shouldAcceptContainer(@NotNull Atom atom) |
| 68 |
{ |
| 69 |
return atom.type.equals(QuickTimeContainerTypes.ATOM_TRACK) |
| 70 |
|| atom.type.equals(QuickTimeContainerTypes.ATOM_USER_DATA) |
| 71 |
|| atom.type.equals(QuickTimeContainerTypes.ATOM_METADATA) |
| 72 |
|| atom.type.equals(QuickTimeContainerTypes.ATOM_MOVIE) |
| 73 |
|| atom.type.equals(QuickTimeContainerTypes.ATOM_MEDIA); |
| 74 |
} |
| 75 |
|
| 76 |
@Override |
| 77 |
public QuickTimeHandler<?> processAtom(@NotNull Atom atom, @Nullable byte[] payload, QuickTimeContext context) throws IOException |
| 78 |
{ |
| 79 |
if (payload != null) { |
| 80 |
SequentialReader reader = new SequentialByteArrayReader(payload); |
| 81 |
|
| 82 |
if (atom.type.equals(QuickTimeAtomTypes.ATOM_MOVIE_HEADER)) { |
| 83 |
MovieHeaderAtom movieHeaderAtom = new MovieHeaderAtom(reader, atom); |
| 84 |
movieHeaderAtom.addMetadata(directory); |
| 85 |
} else if (atom.type.equals(QuickTimeAtomTypes.ATOM_FILE_TYPE)) { |
| 86 |
FileTypeCompatibilityAtom fileTypeCompatibilityAtom = new FileTypeCompatibilityAtom(reader, atom); |
| 87 |
fileTypeCompatibilityAtom.addMetadata(directory); |
| 88 |
} else if (atom.type.equals(QuickTimeAtomTypes.ATOM_HANDLER)) { |
| 89 |
HandlerReferenceAtom handlerReferenceAtom = new HandlerReferenceAtom(reader, atom); |
| 90 |
return handlerFactory.getHandler(handlerReferenceAtom.getComponentType(), metadata, context); |
| 91 |
} else if (atom.type.equals(QuickTimeAtomTypes.ATOM_MEDIA_HEADER)) { |
| 92 |
new MediaHeaderAtom(reader, atom, context); |
| 93 |
} else if (atom.type.equals(QuickTimeAtomTypes.ATOM_CANON_THUMBNAIL)) { |
| 94 |
CanonThumbnailAtom canonThumbnailAtom = new CanonThumbnailAtom(reader); |
| 95 |
canonThumbnailAtom.addMetadata(directory); |
| 96 |
} else if (atom.type.equals(QuickTimeAtomTypes.ATOM_ADOBE_XMP)) { |
| 97 |
new XmpReader().extract(payload, metadata, directory); |
| 98 |
} else if (atom.type.equals(QuickTimeAtomTypes.ATOM_TRACK_HEADER)) { |
| 99 |
TrackHeaderAtom trackHeaderAtom = new TrackHeaderAtom(reader, atom); |
| 100 |
trackHeaderAtom.addMetadata(directory); |
| 101 |
} |
| 102 |
} else { |
| 103 |
if (atom.type.equals(QuickTimeContainerTypes.ATOM_COMPRESSED_MOVIE)) { |
| 104 |
directory.addError("Compressed QuickTime movies not supported"); |
| 105 |
} |
| 106 |
} |
| 107 |
|
| 108 |
return this; |
| 109 |
} |
| 110 |
} |