1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 package org.fourthline.cling.support.model.dlna.types;
16
17 import java.util.regex.Matcher;
18 import java.util.regex.Pattern;
19 import org.fourthline.cling.model.types.InvalidValueException;
20 import org.fourthline.cling.support.model.dlna.types.CodedDataBuffer.TransferMechanism;
21
22
23
24
25
26 public class BufferInfoType {
27
28 final static Pattern pattern = Pattern.compile("^dejitter=(\\d{1,10})(;CDB=(\\d{1,10});BTM=(0|1|2))?(;TD=(\\d{1,10}))?(;BFR=(0|1))?$", Pattern.CASE_INSENSITIVE);
29 private Long dejitterSize;
30 private CodedDataBuffer cdb;
31 private Long targetDuration;
32 private Boolean fullnessReports;
33
34 public BufferInfoType(Long dejitterSize) {
35 this.dejitterSize = dejitterSize;
36 }
37
38 public BufferInfoType(Long dejitterSize, CodedDataBuffer cdb,
39 Long targetDuration, Boolean fullnessReports) {
40 this.dejitterSize = dejitterSize;
41 this.cdb = cdb;
42 this.targetDuration = targetDuration;
43 this.fullnessReports = fullnessReports;
44 }
45
46 public static BufferInfoType valueOf(String s) throws InvalidValueException {
47 Matcher matcher = pattern.matcher(s);
48 if (matcher.matches()) {
49 try {
50 Long dejitterSize = Long.parseLong(matcher.group(1));
51 CodedDataBuffer cdb = null;
52 Long targetDuration = null;
53 Boolean fullnessReports = null;
54
55 if (matcher.group(2) != null) {
56 cdb = new CodedDataBuffer(Long.parseLong(matcher.group(3)),
57 TransferMechanism.values()[Integer.parseInt(matcher.group(4))]);
58 }
59 if (matcher.group(5) != null) {
60 targetDuration = Long.parseLong(matcher.group(6));
61 }
62 if (matcher.group(7) != null) {
63 fullnessReports = matcher.group(8).equals("1");
64 }
65 return new BufferInfoType(dejitterSize, cdb, targetDuration, fullnessReports);
66 } catch (NumberFormatException ex1) {
67 }
68 }
69 throw new InvalidValueException("Can't parse BufferInfoType: " + s);
70 }
71
72 public String getString() {
73 String s = "dejitter=" + dejitterSize.toString();
74 if (cdb != null) {
75 s += ";CDB=" + cdb.getSize().toString() + ";BTM=" + cdb.getTranfer().ordinal();
76 }
77 if (targetDuration != null) {
78 s += ";TD=" + targetDuration.toString();
79 }
80 if (fullnessReports != null) {
81 s += ";BFR=" + (fullnessReports?"1":"0");
82 }
83 return s;
84 }
85
86
87
88
89 public Long getDejitterSize() {
90 return dejitterSize;
91 }
92
93
94
95
96 public CodedDataBuffer getCdb() {
97 return cdb;
98 }
99
100
101
102
103 public Long getTargetDuration() {
104 return targetDuration;
105 }
106
107
108
109
110 public Boolean isFullnessReports() {
111 return fullnessReports;
112 }
113 }