SilenceTrackImpl.java revision dd9eb897ee7c7b507cbdcf80263bb4b5de6966bf
1package com.googlecode.mp4parser.authoring.tracks;
2
3import com.coremedia.iso.boxes.*;
4import com.googlecode.mp4parser.authoring.Mp4TrackImpl;
5import com.googlecode.mp4parser.authoring.Track;
6import com.googlecode.mp4parser.authoring.TrackMetaData;
7
8import java.nio.ByteBuffer;
9import java.util.Collections;
10import java.util.LinkedList;
11import java.util.List;
12
13/**
14 * This is just a basic idea how things could work but they don't.
15 */
16public class SilenceTrackImpl implements Track {
17    Track source;
18
19    List<ByteBuffer> samples = new LinkedList<ByteBuffer>();
20    TimeToSampleBox.Entry entry;
21
22    public SilenceTrackImpl(Track ofType, long ms) {
23        source = ofType;
24        if ("mp4a".equals(ofType.getSampleDescriptionBox().getSampleEntry().getType())) {
25            long numFrames = getTrackMetaData().getTimescale() * ms / 1000 / 1024;
26            long standZeit = getTrackMetaData().getTimescale() * ms / numFrames / 1000;
27            entry = new TimeToSampleBox.Entry(numFrames, standZeit);
28
29
30            while (numFrames-- > 0) {
31                samples.add((ByteBuffer) ByteBuffer.wrap(new byte[]{
32                        0x21, 0x10, 0x04, 0x60, (byte) 0x8c, 0x1c,
33                }).rewind());
34            }
35
36        } else {
37            throw new RuntimeException("Tracks of type " + ofType.getClass().getSimpleName() + " are not supported");
38        }
39    }
40
41    public SampleDescriptionBox getSampleDescriptionBox() {
42        return source.getSampleDescriptionBox();
43    }
44
45    public List<TimeToSampleBox.Entry> getDecodingTimeEntries() {
46        return Collections.singletonList(entry);
47
48    }
49
50    public TrackMetaData getTrackMetaData() {
51        return source.getTrackMetaData();
52    }
53
54    public String getHandler() {
55        return source.getHandler();
56    }
57
58    public boolean isEnabled() {
59        return source.isEnabled();
60    }
61
62    public boolean isInMovie() {
63        return source.isInMovie();
64    }
65
66    public boolean isInPreview() {
67        return source.isInPreview();
68    }
69
70    public boolean isInPoster() {
71        return source.isInPoster();
72    }
73
74    public List<ByteBuffer> getSamples() {
75        return samples;
76    }
77
78    public Box getMediaHeaderBox() {
79        return source.getMediaHeaderBox();
80    }
81
82    public SubSampleInformationBox getSubsampleInformationBox() {
83        return null;
84    }
85
86    public List<CompositionTimeToSample.Entry> getCompositionTimeEntries() {
87        return null;
88    }
89
90    public long[] getSyncSamples() {
91        return null;
92    }
93
94    public List<SampleDependencyTypeBox.Entry> getSampleDependencies() {
95        return null;
96    }
97
98}
99