1package com.coremedia.iso.boxes;
2
3import com.coremedia.iso.IsoTypeReader;
4import com.coremedia.iso.IsoTypeWriter;
5import com.googlecode.mp4parser.AbstractFullBox;
6
7import java.nio.ByteBuffer;
8import java.util.Collections;
9import java.util.LinkedList;
10import java.util.List;
11
12public class ProgressiveDownloadInformationBox extends AbstractFullBox {
13
14
15    List<Entry> entries = Collections.emptyList();
16
17    public ProgressiveDownloadInformationBox() {
18        super("pdin");
19    }
20
21    @Override
22    protected long getContentSize() {
23        return 4 + entries.size() * 8;
24    }
25
26    @Override
27    protected void getContent(ByteBuffer byteBuffer) {
28        writeVersionAndFlags(byteBuffer);
29        for (Entry entry : entries) {
30            IsoTypeWriter.writeUInt32(byteBuffer, entry.getRate());
31            IsoTypeWriter.writeUInt32(byteBuffer, entry.getInitialDelay());
32        }
33    }
34
35    public List<Entry> getEntries() {
36        return entries;
37    }
38
39    public void setEntries(List<Entry> entries) {
40        this.entries = entries;
41    }
42
43    @Override
44    public void _parseDetails(ByteBuffer content) {
45        parseVersionAndFlags(content);
46        entries = new LinkedList<Entry>();
47        while (content.remaining() >= 8) {
48            Entry entry = new Entry(IsoTypeReader.readUInt32(content), IsoTypeReader.readUInt32(content));
49            entries.add(entry);
50        }
51    }
52
53
54    public static class Entry {
55        long rate;
56        long initialDelay;
57
58        public Entry(long rate, long initialDelay) {
59            this.rate = rate;
60            this.initialDelay = initialDelay;
61        }
62
63        public long getRate() {
64            return rate;
65        }
66
67        public void setRate(long rate) {
68            this.rate = rate;
69        }
70
71        public long getInitialDelay() {
72            return initialDelay;
73        }
74
75        public void setInitialDelay(long initialDelay) {
76            this.initialDelay = initialDelay;
77        }
78
79        @Override
80        public String toString() {
81            return "Entry{" +
82                    "rate=" + rate +
83                    ", initialDelay=" + initialDelay +
84                    '}';
85        }
86    }
87
88    @Override
89    public String toString() {
90        return "ProgressiveDownloadInfoBox{" +
91                "entries=" + entries +
92                '}';
93    }
94
95}