1 /**
2  * Copyright (C) 2024 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #include <RtpReceptionStats.h>
18 
19 namespace android
20 {
21 
22 namespace telephony
23 {
24 
25 namespace imsmedia
26 {
27 
RtpReceptionStats()28 RtpReceptionStats::RtpReceptionStats()
29 {
30     setDefaultConfig();
31 }
32 
RtpReceptionStats(const int32_t rtpTimestamp,const int32_t rtcpSrTimestamp,const int64_t ntp,const int32_t jitterBuffer,const int32_t roundTripTime)33 RtpReceptionStats::RtpReceptionStats(const int32_t rtpTimestamp, const int32_t rtcpSrTimestamp,
34         const int64_t ntp, const int32_t jitterBuffer, const int32_t roundTripTime)
35 {
36     mRtpTimestamp = rtpTimestamp;
37     mRtcpSrTimestamp = rtcpSrTimestamp;
38     mRtcpSrNtpTimestamp = ntp;
39     mJitterBufferMs = jitterBuffer;
40     mRoundTripTimeMs = roundTripTime;
41 }
42 
RtpReceptionStats(const RtpReceptionStats & stats)43 RtpReceptionStats::RtpReceptionStats(const RtpReceptionStats& stats)
44 {
45     mRtpTimestamp = stats.mRtpTimestamp;
46     mRtcpSrTimestamp = stats.mRtcpSrTimestamp;
47     mRtcpSrNtpTimestamp = stats.mRtcpSrNtpTimestamp;
48     mJitterBufferMs = stats.mJitterBufferMs;
49     mRoundTripTimeMs = stats.mRoundTripTimeMs;
50 }
51 
~RtpReceptionStats()52 RtpReceptionStats::~RtpReceptionStats() {}
53 
operator =(const RtpReceptionStats & stats)54 RtpReceptionStats& RtpReceptionStats::operator=(const RtpReceptionStats& stats)
55 {
56     if (this != &stats)
57     {
58         mRtpTimestamp = stats.mRtpTimestamp;
59         mRtcpSrTimestamp = stats.mRtcpSrTimestamp;
60         mRtcpSrNtpTimestamp = stats.mRtcpSrNtpTimestamp;
61         mJitterBufferMs = stats.mJitterBufferMs;
62         mRoundTripTimeMs = stats.mRoundTripTimeMs;
63     }
64     return *this;
65 }
66 
operator ==(const RtpReceptionStats & stats) const67 bool RtpReceptionStats::operator==(const RtpReceptionStats& stats) const
68 {
69     return (mRtpTimestamp == stats.mRtpTimestamp && mRtcpSrTimestamp == stats.mRtcpSrTimestamp &&
70             mRtcpSrNtpTimestamp == stats.mRtcpSrNtpTimestamp &&
71             mJitterBufferMs == stats.mJitterBufferMs && mRoundTripTimeMs == stats.mRoundTripTimeMs);
72 }
73 
operator !=(const RtpReceptionStats & stats) const74 bool RtpReceptionStats::operator!=(const RtpReceptionStats& stats) const
75 {
76     return (mRtpTimestamp != stats.mRtpTimestamp || mRtcpSrTimestamp != stats.mRtcpSrTimestamp ||
77             mRtcpSrNtpTimestamp != stats.mRtcpSrNtpTimestamp ||
78             mJitterBufferMs != stats.mJitterBufferMs || mRoundTripTimeMs != stats.mRoundTripTimeMs);
79 }
80 
writeToParcel(Parcel * out) const81 status_t RtpReceptionStats::writeToParcel(Parcel* out) const
82 {
83     if (out == nullptr)
84     {
85         return BAD_VALUE;
86     }
87 
88     out->writeInt32(mRtpTimestamp);
89     out->writeInt32(mRtcpSrTimestamp);
90     out->writeInt64(mRtcpSrNtpTimestamp);
91     out->writeInt32(mJitterBufferMs);
92     out->writeInt32(mRoundTripTimeMs);
93     return NO_ERROR;
94 }
95 
readFromParcel(const Parcel * in)96 status_t RtpReceptionStats::readFromParcel(const Parcel* in)
97 {
98     if (in == nullptr)
99     {
100         return BAD_VALUE;
101     }
102 
103     in->readInt32(&mRtpTimestamp);
104     in->readInt32(&mRtcpSrTimestamp);
105     in->readInt64(&mRtcpSrNtpTimestamp);
106     in->readInt32(&mJitterBufferMs);
107     in->readInt32(&mRoundTripTimeMs);
108 
109     return NO_ERROR;
110 }
111 
getRtpTimestamp()112 int32_t RtpReceptionStats::getRtpTimestamp()
113 {
114     return mRtpTimestamp;
115 }
116 
setRtpTimestamp(const int32_t timestamp)117 void RtpReceptionStats::setRtpTimestamp(const int32_t timestamp)
118 {
119     mRtpTimestamp = timestamp;
120 }
121 
getRtcpSrTimestamp()122 int32_t RtpReceptionStats::getRtcpSrTimestamp()
123 {
124     return mRtcpSrTimestamp;
125 }
126 
setRtcpSrTimestamp(const int32_t timestamp)127 void RtpReceptionStats::setRtcpSrTimestamp(const int32_t timestamp)
128 {
129     mRtcpSrTimestamp = timestamp;
130 }
131 
getRtcpSrNtpTimestamp()132 int64_t RtpReceptionStats::getRtcpSrNtpTimestamp()
133 {
134     return mRtcpSrNtpTimestamp;
135 }
136 
setRtcpSrNtpTimestamp(const int64_t ntp)137 void RtpReceptionStats::setRtcpSrNtpTimestamp(const int64_t ntp)
138 {
139     mRtcpSrNtpTimestamp = ntp;
140 }
141 
getJitterBufferMs()142 int32_t RtpReceptionStats::getJitterBufferMs()
143 {
144     return mJitterBufferMs;
145 }
146 
setJitterBufferMs(const int32_t jitterBufferMs)147 void RtpReceptionStats::setJitterBufferMs(const int32_t jitterBufferMs)
148 {
149     mJitterBufferMs = jitterBufferMs;
150 }
151 
getRoundTripTimeMs()152 int32_t RtpReceptionStats::getRoundTripTimeMs()
153 {
154     return mRoundTripTimeMs;
155 }
156 
setRoundTripTimeMs(const int32_t roundTripTimeMs)157 void RtpReceptionStats::setRoundTripTimeMs(const int32_t roundTripTimeMs)
158 {
159     mRoundTripTimeMs = roundTripTimeMs;
160 }
161 
setDefaultConfig()162 void RtpReceptionStats::setDefaultConfig()
163 {
164     mRtpTimestamp = 0;
165     mRtcpSrTimestamp = 0;
166     mRtcpSrNtpTimestamp = 0;
167     mJitterBufferMs = 0;
168     mRoundTripTimeMs = 0;
169 }
170 
171 }  // namespace imsmedia
172 
173 }  // namespace telephony
174 
175 }  // namespace android