aboutsummaryrefslogtreecommitdiffstats
path: root/src/net/java/sip/communicator/impl/neomedia/RTCPFeedbackPacket.java
blob: 1eec9f3830c557de0bbd7e81b32e8c71f5f53472 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
/*
 * SIP Communicator, the OpenSource Java VoIP and Instant Messaging client.
 *
 * Distributable under LGPL license.
 * See terms of license at gnu.org.
 */
package net.java.sip.communicator.impl.neomedia;

import javax.media.rtp.*;

/**
 * Represents an RTCP feedback packet as described in RFC4585.
 *
 * @author Sebastien Vincent
 */
public class RTCPFeedbackPacket
{
    /**
     * Feedback message type.
     */
    private int fmt = 0;

    /**
     * Payload type.
     */
    private int payloadType = 0;

    /**
     * SSRC of packet sender.
     */
    private long senderSSRC = 0;

    /**
     * SSRC of media source.
     */
    private long sourceSSRC = 0;

    /**
     * Constructor.
     *
     * @param type feedback message type
     * @param payloadType payload type
     * @param sender sender SSRC
     * @param src source SSRC
     */
    public RTCPFeedbackPacket(int type, int payloadType, long sender, long src)
    {
        this.fmt = type;
        this.payloadType = payloadType;
        this.senderSSRC = sender;
        this.sourceSSRC = src;
    }

    /**
     * Write RTCP packet to output stream of a <tt>DatagramSocket</tt>.
     *
     * @param out <tt>OutputDataStream</tt> of a <tt>DatagramSocket</tt>
     */
    public void writeTo(OutputDataStream out)
    {
        byte data[] = new byte[12];
        byte vpfmt = (byte)((2 << 7) | (0 << 6) | (byte)fmt);

        data[0] = vpfmt;
        data[1] = (byte)payloadType;

        /* length (in 32-bit words minus one) */
        data[2] = 0;
        data[3] = 2; /* common packet is 12 bytes so (12/4) - 1 */

        /* sender SSRC */
        data[4] = (byte)(senderSSRC >> 24);
        data[5] = (byte)((senderSSRC >> 16) & 0xFF);
        data[6] = (byte)((senderSSRC >> 8) & 0xFF);
        data[7] = (byte)(senderSSRC & 0xFF);

        /* source SSRC */
        data[8] = (byte)(sourceSSRC >> 24);
        data[9] = (byte)((sourceSSRC >> 16) & 0xFF);
        data[10] = (byte)((sourceSSRC >> 8) & 0xFF);
        data[11] = (byte)(sourceSSRC & 0xFF);

        /* effective write */
        out.write(data, 0, 12);
    }
}