| 1 | package cz.vutbr.feec.packets.rtp; |
| 2 | |
| 3 | import cz.vutbr.feec.packets.IPacket; |
| 4 | import cz.vutbr.feec.packets.PacketGenerateException; |
| 5 | import cz.vutbr.feec.packets.PacketParseException; |
| 6 | |
| 7 | /** |
| 8 | * The Class Packet. |
| 9 | */ |
| 10 | public class RTPHeader implements IPacket { |
| 11 | |
| 12 | /** The version. */ |
| 13 | private int version = 2; |
| 14 | |
| 15 | /** The padding. */ |
| 16 | private int padding; |
| 17 | |
| 18 | /*private int extension; |
| 19 | private int CSRC_count; |
| 20 | private int marker;*/ |
| 21 | |
| 22 | /** The subtype. */ |
| 23 | private int subtype; |
| 24 | |
| 25 | /** The payload type. */ |
| 26 | private int payloadType = 204; |
| 27 | |
| 28 | /*private long seqNumber; |
| 29 | private long timeStamp; |
| 30 | private long SSRC; |
| 31 | private long CSRC;*/ |
| 32 | |
| 33 | /** The length. */ |
| 34 | private int length; |
| 35 | |
| 36 | /** |
| 37 | * Parse byte array and fill packet. |
| 38 | * |
| 39 | * @param startIndex in array |
| 40 | * @param array input |
| 41 | * @param length the length |
| 42 | * |
| 43 | * @return length in bytes |
| 44 | * |
| 45 | * @throws PacketParseException the packet parse exception |
| 46 | */ |
| 47 | public int parse(byte[] array, int startIndex, int length) |
| 48 | throws PacketParseException { |
| 49 | // 5 bits, only for parsing and validating # of ReportBlocks |
| 50 | this.version = (array[0 + startIndex] & 0xc0) >> 6; |
| 51 | this.padding = (array[0 + startIndex] & 0x20) >> 5; |
| 52 | this.subtype = (array[0 + startIndex] & 0x1F); |
| 53 | this.payloadType = array[1 + startIndex] & 0xFF; |
| 54 | this.length = (array[2 + startIndex] & 0xff << 8) | array[3 + startIndex]; |
| 55 | this.length = (this.length+1)*4; //total size in octets |
| 56 | |
| 57 | return 4; |
| 58 | } |
| 59 | |
| 60 | /** |
| 61 | * Gets the length. |
| 62 | * |
| 63 | * @return the length |
| 64 | */ |
| 65 | public int getLength() { |
| 66 | return length; |
| 67 | } |
| 68 | |
| 69 | /** |
| 70 | * Gets the padding. |
| 71 | * |
| 72 | * @return the padding |
| 73 | */ |
| 74 | public int getPadding() { |
| 75 | return padding; |
| 76 | } |
| 77 | |
| 78 | /** |
| 79 | * Sets the padding. |
| 80 | * |
| 81 | * @param padding the padding |
| 82 | */ |
| 83 | public void setPadding(int padding) { |
| 84 | this.padding = padding; |
| 85 | } |
| 86 | |
| 87 | /** |
| 88 | * Gets the payload type. |
| 89 | * |
| 90 | * @return the payload type |
| 91 | */ |
| 92 | public int getPayloadType() { |
| 93 | return payloadType; |
| 94 | } |
| 95 | |
| 96 | /** |
| 97 | * Sets the payload type. |
| 98 | * |
| 99 | * @param payloadType the payload type |
| 100 | */ |
| 101 | public void setPayloadType(int payloadType) { |
| 102 | this.payloadType = payloadType; |
| 103 | } |
| 104 | |
| 105 | /** |
| 106 | * Gets the subtype. |
| 107 | * |
| 108 | * @return the subtype |
| 109 | */ |
| 110 | public int getSubtype() { |
| 111 | return subtype; |
| 112 | } |
| 113 | |
| 114 | /** |
| 115 | * Sets the subtype. |
| 116 | * |
| 117 | * @param subtype the subtype |
| 118 | */ |
| 119 | public void setSubtype(int subtype) { |
| 120 | this.subtype = subtype; |
| 121 | } |
| 122 | |
| 123 | /** |
| 124 | * Gets the version. |
| 125 | * |
| 126 | * @return the version |
| 127 | */ |
| 128 | public int getVersion() { |
| 129 | return version; |
| 130 | } |
| 131 | |
| 132 | /** |
| 133 | * Sets the version. |
| 134 | * |
| 135 | * @param version the version |
| 136 | */ |
| 137 | public void setVersion(int version) { |
| 138 | this.version = version; |
| 139 | } |
| 140 | |
| 141 | public int generate(byte[] resultArray, int startPos) |
| 142 | throws PacketGenerateException { |
| 143 | // TODO Nesmi vracet nula bytu |
| 144 | return 0; |
| 145 | } |
| 146 | |
| 147 | /*public int getExtension() { |
| 148 | return extension; |
| 149 | } |
| 150 | |
| 151 | public void setExtension(int extension) { |
| 152 | this.extension = extension; |
| 153 | } |
| 154 | |
| 155 | public int getCSRC_count() { |
| 156 | return CSRC_count; |
| 157 | } |
| 158 | |
| 159 | public void setCSRC_count(int csrc_count) { |
| 160 | CSRC_count = csrc_count; |
| 161 | } |
| 162 | |
| 163 | public int getMarker() { |
| 164 | return marker; |
| 165 | } |
| 166 | |
| 167 | public void setMarker(int marker) { |
| 168 | this.marker = marker; |
| 169 | } |
| 170 | |
| 171 | public long getSeqNumber() { |
| 172 | return seqNumber; |
| 173 | } |
| 174 | |
| 175 | public void setSeqNumber(long seqNumber) { |
| 176 | this.seqNumber = seqNumber; |
| 177 | } |
| 178 | |
| 179 | public long getTimeStamp() { |
| 180 | return timeStamp; |
| 181 | } |
| 182 | |
| 183 | public void setTimeStamp(long timeStamp) { |
| 184 | this.timeStamp = timeStamp; |
| 185 | } |
| 186 | |
| 187 | public long getSSRC() { |
| 188 | return SSRC; |
| 189 | } |
| 190 | |
| 191 | public void setSSRC(long ssrc) { |
| 192 | SSRC = ssrc; |
| 193 | } |
| 194 | |
| 195 | public long getCSRC() { |
| 196 | return CSRC; |
| 197 | } |
| 198 | |
| 199 | public void setCSRC(long csrc) { |
| 200 | CSRC = csrc; |
| 201 | }*/ |
| 202 | } |