| 1 | package cz.vutbr.feec.packets.rtcp; |
| 2 | |
| 3 | import cz.vutbr.feec.packets.IPacket; |
| 4 | import cz.vutbr.feec.packets.PacketGenerateException; |
| 5 | import cz.vutbr.feec.packets.PacketParseException; |
| 6 | import cz.vutbr.feec.packets.PacketUtils; |
| 7 | |
| 8 | import org.apache.commons.lang.builder.ToStringBuilder; |
| 9 | import org.apache.commons.lang.builder.EqualsBuilder; |
| 10 | import org.apache.commons.lang.builder.HashCodeBuilder; |
| 11 | |
| 12 | /** |
| 13 | * This class encapsulates all the necessary parameters of a |
| 14 | * Reception Report that needs to be handed to the Application |
| 15 | * when a Reception Report is received. |
| 16 | */ |
| 17 | public class ReportBlock implements IPacket{ |
| 18 | private long SSRC; |
| 19 | private int fractionLost; |
| 20 | private long cumulativeNumofPackLost; |
| 21 | private long exHIseqNumRec; |
| 22 | private long interArrJitter; |
| 23 | private long LSR; |
| 24 | private long DLSR; |
| 25 | |
| 26 | public int generate(byte[] buffer, int offset) |
| 27 | throws PacketGenerateException { |
| 28 | assert PacketUtils.checkSize(getSSRC(), 32); |
| 29 | assert PacketUtils.checkSize(getFractionLost(), 8); |
| 30 | assert PacketUtils.checkSize(getCumulativeNumofPackLost(), 24); |
| 31 | assert PacketUtils.checkSize(getExHIseqNumRec(), 32); |
| 32 | assert PacketUtils.checkSize(getInterArrJitter(), 32); |
| 33 | assert PacketUtils.checkSize(getLSR(), 32); |
| 34 | assert PacketUtils.checkSize(getDLSR(), 32); |
| 35 | |
| 36 | PacketUtils.setOctet4(buffer, offset, getSSRC()); |
| 37 | PacketUtils.setOctet1(buffer, offset+4, getFractionLost()); |
| 38 | PacketUtils.setOctet3(buffer, offset+5, getCumulativeNumofPackLost()); |
| 39 | PacketUtils.setOctet4(buffer, offset+8, getExHIseqNumRec()); |
| 40 | PacketUtils.setOctet4(buffer, offset+12, getInterArrJitter()); |
| 41 | PacketUtils.setOctet4(buffer, offset+16, getLSR()); |
| 42 | PacketUtils.setOctet4(buffer, offset+20, getDLSR()); |
| 43 | |
| 44 | return 6*4; |
| 45 | } |
| 46 | public int parse(byte[] buffer, int offset, int length) |
| 47 | throws PacketParseException { |
| 48 | setSSRC(PacketUtils.getOctet4(buffer, offset)); |
| 49 | setFractionLost(PacketUtils.getOctet1(buffer, offset+4)); |
| 50 | setCumulativeNumofPackLost(PacketUtils.getOctet3(buffer, offset+5)); |
| 51 | setExHIseqNumRec(PacketUtils.getOctet4(buffer, offset+8)); |
| 52 | setInterArrJitter(PacketUtils.getOctet4(buffer, offset+12)); |
| 53 | setLSR(PacketUtils.getOctet4(buffer, offset+16)); |
| 54 | setDLSR(PacketUtils.getOctet4(buffer, offset+20)); |
| 55 | return 6*4; |
| 56 | } |
| 57 | |
| 58 | |
| 59 | public long getSSRC() { |
| 60 | return SSRC; |
| 61 | } |
| 62 | public void setSSRC(long ssrc) { |
| 63 | SSRC = ssrc; |
| 64 | } |
| 65 | public int getFractionLost() { |
| 66 | return fractionLost; |
| 67 | } |
| 68 | public void setFractionLost(double fraction_lost) { |
| 69 | this.fractionLost = (byte)(fraction_lost*256); |
| 70 | } |
| 71 | public void setFractionLost(int fraction_lost) { |
| 72 | this.fractionLost = fraction_lost; |
| 73 | } |
| 74 | public long getCumulativeNumofPackLost() { |
| 75 | return cumulativeNumofPackLost; |
| 76 | } |
| 77 | public void setCumulativeNumofPackLost(long cumulativeNumofPackLost) { |
| 78 | this.cumulativeNumofPackLost = cumulativeNumofPackLost; |
| 79 | } |
| 80 | public long getExHIseqNumRec() { |
| 81 | return exHIseqNumRec; |
| 82 | } |
| 83 | public void setExHIseqNumRec(long exHIseqNumRec) { |
| 84 | this.exHIseqNumRec = exHIseqNumRec; |
| 85 | } |
| 86 | public long getInterArrJitter() { |
| 87 | return interArrJitter; |
| 88 | } |
| 89 | public void setInterArrJitter(long interArrJitter) { |
| 90 | this.interArrJitter = interArrJitter; |
| 91 | } |
| 92 | public long getLSR() { |
| 93 | return LSR; |
| 94 | } |
| 95 | public void setLSR(long lsr) { |
| 96 | LSR = lsr; |
| 97 | } |
| 98 | public long getDLSR() { |
| 99 | return DLSR; |
| 100 | } |
| 101 | public void setDLSR(long dlsr) { |
| 102 | DLSR = dlsr; |
| 103 | } |
| 104 | /** |
| 105 | * @see java.lang.Object#toString() |
| 106 | */ |
| 107 | public String toString() { |
| 108 | return new ToStringBuilder(this).append("SSRC", |
| 109 | this.SSRC).append("fraction_lost", |
| 110 | this.fractionLost).append("exHIseqNumRec", this.exHIseqNumRec) |
| 111 | .append("DLSR", this.DLSR).append("cumulativeNumofPackLost", |
| 112 | this.cumulativeNumofPackLost).append("LSR", this.LSR) |
| 113 | .append("interArrJitter", this.interArrJitter).toString(); |
| 114 | } |
| 115 | /** |
| 116 | * @see java.lang.Object#equals(Object) |
| 117 | */ |
| 118 | public boolean equals(Object object) { |
| 119 | if (!(object instanceof ReportBlock)) { |
| 120 | return false; |
| 121 | } |
| 122 | ReportBlock rhs = (ReportBlock) object; |
| 123 | return new EqualsBuilder().append(this.SSRC, rhs.SSRC).append( |
| 124 | this.exHIseqNumRec, rhs.exHIseqNumRec).append( |
| 125 | this.fractionLost, rhs.fractionLost).append( |
| 126 | this.interArrJitter, rhs.interArrJitter).append(this.LSR, |
| 127 | rhs.LSR).append(this.cumulativeNumofPackLost, |
| 128 | rhs.cumulativeNumofPackLost) |
| 129 | .append(this.DLSR, rhs.DLSR).isEquals(); |
| 130 | } |
| 131 | /** |
| 132 | * @see java.lang.Object#hashCode() |
| 133 | */ |
| 134 | public int hashCode() { |
| 135 | return new HashCodeBuilder(-1397927009, -1527314573).append(this.fractionLost).append( |
| 136 | this.exHIseqNumRec).append(this.interArrJitter) |
| 137 | .append(this.LSR).append(this.cumulativeNumofPackLost).append( |
| 138 | this.SSRC).append(this.DLSR).toHashCode(); |
| 139 | } |
| 140 | |
| 141 | } |