1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package entagged.audioformats.mp4.util;
20
21 import java.io.UnsupportedEncodingException;
22
23 import entagged.audioformats.generic.TagField;
24 import entagged.audioformats.generic.Utils;
25
26 public class Mp4TagBinaryField extends Mp4TagField {
27
28 protected byte[] dataBytes;
29 protected boolean isBinary = false;
30
31 public Mp4TagBinaryField(String id) {
32 super(id);
33 }
34
35 public Mp4TagBinaryField(String id, byte[] raw) throws UnsupportedEncodingException {
36 super(id, raw);
37 }
38
39 public byte[] getRawContent() {
40 byte[] data = dataBytes;
41 byte[] b = new byte[4 + 4 + 4 + 4 + 4 + 4 + data.length];
42
43 int offset = 0;
44 Utils.copy(Utils.getSizeBigEndian(b.length), b, offset);
45 offset += 4;
46
47 Utils.copy(Utils.getDefaultBytes(getId()), b, offset);
48 offset += 4;
49
50 Utils.copy(Utils.getSizeBigEndian(4+4+4+4+data.length), b, offset);
51 offset += 4;
52
53 Utils.copy(Utils.getDefaultBytes("data"), b, offset);
54 offset += 4;
55
56 Utils.copy(new byte[] {0, 0, 0, (byte) (isBinary() ? 0 : 1) }, b, offset);
57 offset += 4;
58
59 Utils.copy(new byte[] {0, 0, 0, 0}, b, offset);
60 offset += 4;
61
62 Utils.copy(data, b, offset);
63 offset += data.length;
64
65 return b;
66 }
67
68 protected void build(byte[] raw) {
69 int dataSize = Utils.getNumberBigEndian(raw, 0, 3);
70
71 this.dataBytes = new byte[dataSize - 16];
72 for(int i = 16; i<dataSize; i++)
73 this.dataBytes[i-16] = raw[i];
74
75 this.isBinary = ((raw[11]&0x01) == 0);
76 }
77
78 public boolean isBinary() {
79 return isBinary;
80 }
81
82 public boolean isEmpty() {
83 return this.dataBytes.length == 0;
84 }
85
86 public byte[] getData() {
87 return this.dataBytes;
88 }
89
90 public void setData(byte[] d) {
91 this.dataBytes = d;
92 }
93
94 public void copyContent(TagField field) {
95 if(field instanceof Mp4TagBinaryField) {
96 this.dataBytes = ((Mp4TagBinaryField) field).getData();
97 this.isBinary = ((Mp4TagBinaryField) field).isBinary();
98 }
99 }
100 }