All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.xingshuangs.iot.protocol.rtcp.model.RtcpSdesReport Maven / Gradle / Ivy

/*
 * MIT License
 *
 * Copyright (c) 2021-2099 Oscura (xingshuang) 
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in all
 * copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */

package com.github.xingshuangs.iot.protocol.rtcp.model;


import com.github.xingshuangs.iot.common.buff.ByteWriteBuff;
import com.github.xingshuangs.iot.protocol.rtcp.enums.ERtcpPackageType;
import lombok.Data;
import lombok.EqualsAndHashCode;

import java.util.ArrayList;
import java.util.List;

/**
 * 资源描述报告
 * 0                   1                   2                   3
 * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
 * |V=2|P|    SC   |  PT=SDES=202  |             length            |
 * +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+
 * |                          SSRC/CSRC_1                          |
 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
 * |                           SDES items                          |
 * |                              ...                              |
 * +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+
 * |                          SSRC/CSRC_2                          |
 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
 * |                           SDES items                          |
 * |                              ...                              |
 * +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+
 * 

* 0 1 2 3 * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ * | CNAME=1 | length | user and domain name ... * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ * * @author xingshuang */ @Data @EqualsAndHashCode(callSuper = true) public final class RtcpSdesReport extends RtcpBasePackage { private List sdesChunks = new ArrayList<>(); public RtcpSdesReport() { this.header = new RtcpHeader(); this.header.version = 2; this.header.padding = false; this.header.receptionCount = 0; this.header.packageType = ERtcpPackageType.SDES; this.header.length = 1; } public void addRtcpSdesChunk(RtcpSdesChunk chunk) { this.sdesChunks.add(chunk); this.header.receptionCount = this.sdesChunks.size(); this.header.length = this.byteArrayLength() / 4 - 1; } @Override public int byteArrayLength() { int length = 0; length += this.header != null ? this.header.byteArrayLength() : 0; for (RtcpSdesChunk chunk : this.sdesChunks) { length += chunk.byteArrayLength(); } return (int) Math.ceil(length / 4.0) * 4; } @Override public byte[] toByteArray() { ByteWriteBuff buff = ByteWriteBuff.newInstance(this.byteArrayLength()); if (this.header != null) { buff.putBytes(this.header.toByteArray()); } for (RtcpSdesChunk chunk : this.sdesChunks) { buff.putBytes(chunk.toByteArray()); } return buff.getData(); } /** * Parses byte array and converts it to object. * * @param data byte array * @return RtcpHeader */ public static RtcpSdesReport fromBytes(final byte[] data) { return fromBytes(data, 0); } /** * Parses byte array and converts it to object. * * @param data byte array * @param offset index offset * @return RtcpHeader */ public static RtcpSdesReport fromBytes(final byte[] data, final int offset) { if (data.length < 4) { throw new IndexOutOfBoundsException("RtcpReceiverReport, data length < 4"); } int off = offset; RtcpSdesReport res = new RtcpSdesReport(); res.header = RtcpHeader.fromBytes(data, off); off += res.header.byteArrayLength(); for (int i = 0; i < res.header.getReceptionCount(); i++) { RtcpSdesChunk chunk = RtcpSdesChunk.fromBytes(data, off); res.sdesChunks.add(chunk); off += chunk.byteArrayLength(); } return res; } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy