summaryrefslogtreecommitdiff
path: root/service/src/com/android/telephony/imsmedia/lib/libimsmedia/protocol/rtp/core/RtcpXrPacket.cpp
blob: 819f13b61aa8914f169ea9040f46b1d728339726 (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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
/**
 * Copyright (C) 2022 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include <RtcpXrPacket.h>
#include <RtpTrace.h>
#include <RtpSession.h>

RtcpXrPacket::RtcpXrPacket() :
        m_reportBlk(nullptr)
{
}

RtcpXrPacket::~RtcpXrPacket()
{
    if (m_reportBlk)
    {
        delete (m_reportBlk);
        m_reportBlk = nullptr;
    }
}

RtcpHeader* RtcpXrPacket::getRtcpHdrInfo()
{
    return &m_objRtcpHdr;
}

RtpDt_Void RtcpXrPacket::setRtcpHdrInfo(RtcpHeader& header)
{
    m_objRtcpHdr = header;
}

RtpBuffer* RtcpXrPacket::getReportBlk()
{
    return m_reportBlk;
}

RtpDt_Void RtcpXrPacket::setReportBlk(IN RtpBuffer* reportBlk)
{
    m_reportBlk = reportBlk;
}

eRTP_STATUS_CODE RtcpXrPacket::decodeRtcpXrPacket(
        IN RtpDt_UChar* pucRtcpXrBuf, IN RtpDt_UInt16 usRtcpXrLen, IN RtpDt_UChar ucPktType)
{
    (RtpDt_Void) pucRtcpXrBuf;
    (RtpDt_Void) usRtcpXrLen;
    (RtpDt_Void) ucPktType;
    RTP_TRACE_ERROR("decodeRtcpXrPacket not implemented.", RTP_ZERO, RTP_ZERO);

    return RTP_FAILURE;
}

eRTP_STATUS_CODE RtcpXrPacket::formRtcpXrPacket(OUT RtpBuffer* pobjRtcpPktBuf)
{
    RtpDt_UInt32 uiXrPktPos = pobjRtcpPktBuf->getLength();
    RtpDt_UInt32 uiCurPos = pobjRtcpPktBuf->getLength();
    RtpDt_UChar* pucBuffer = pobjRtcpPktBuf->getBuffer();

    if (!pucBuffer)
    {
        RTP_TRACE_ERROR("formXrPacket with null buffer", RTP_ZERO, RTP_ZERO);
        return RTP_FAILURE;
    }

    uiCurPos = uiCurPos + RTCP_FIXED_HDR_LEN;
    pucBuffer = pucBuffer + uiCurPos;

    // set the report block buffer
    RtpBuffer* pReportBlk = this->getReportBlk();
    memcpy(pucBuffer, pReportBlk->getBuffer(), pReportBlk->getLength());

    uiCurPos = uiCurPos + pReportBlk->getLength();

    // padding
    RtpDt_UInt32 uiXrPktLen = uiCurPos - uiXrPktPos;
#ifdef ENABLE_PADDING
    RtpDt_UInt32 uiPadLen = RTP_ZERO;
    uiPadLen = uiXrPktLen % RTP_WORD_SIZE;
    if (uiPadLen > RTP_ZERO)
    {
        uiPadLen = RTP_WORD_SIZE - uiPadLen;
        uiXrPktLen = uiXrPktLen + uiPadLen;
        uiCurPos = uiCurPos + uiPadLen;
        pucBuffer = pucBuffer + pReportBlk->getLength();
        memset(pucBuffer, RTP_ZERO, uiPadLen);

        pucBuffer = pucBuffer + uiPadLen;
        pucBuffer = pucBuffer - RTP_ONE;
        *(reinterpret_cast<RtpDt_UChar*>(pucBuffer)) = (RtpDt_UChar)uiPadLen;

        // set pad bit in header
        m_objRtcpHdr.setPadding();
        // set length in header
        m_objRtcpHdr.setLength(uiXrPktLen);
    }
    else
#endif
    {
        // set length in header
        m_objRtcpHdr.setLength(uiXrPktLen);
    }

    pobjRtcpPktBuf->setLength(uiXrPktPos);
    m_objRtcpHdr.formRtcpHeader(pobjRtcpPktBuf);

    // set the current position of the RTCP compound packet
    pobjRtcpPktBuf->setLength(uiCurPos);

    return RTP_SUCCESS;
}