1 /**
2  * Copyright (C) 2022 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 <CallQuality.h>
18 
19 namespace android
20 {
21 
22 namespace telephony
23 {
24 
25 namespace imsmedia
26 {
27 
28 #define DEFAULT_PARAM (-1)
29 
CallQuality()30 CallQuality::CallQuality()
31 {
32     mDownlinkCallQualityLevel = 0;
33     mUplinkCallQualityLevel = 0;
34     mCallDuration = 0;
35     mNumRtpPacketsTransmitted = 0;
36     mNumRtpPacketsReceived = 0;
37     mNumRtpPacketsTransmittedLost = 0;
38     mNumRtpPacketsNotReceived = 0;
39     mAverageRelativeJitter = 0;
40     mMaxRelativeJitter = 0;
41     mAverageRoundTripTime = 0;
42     mCodecType = DEFAULT_PARAM;
43     mRtpInactivityDetected = false;
44     mRxSilenceDetected = false;
45     mTxSilenceDetected = false;
46     mNumVoiceFrames = 0;
47     mNumNoDataFrames = 0;
48     mNumDroppedRtpPackets = 0;
49     mMinPlayoutDelayMillis = 0;
50     mMaxPlayoutDelayMillis = 0;
51     mNumRtpSidPacketsReceived = 0;
52     mNumRtpDuplicatePackets = 0;
53 }
54 
CallQuality(const CallQuality & quality)55 CallQuality::CallQuality(const CallQuality& quality)
56 {
57     mDownlinkCallQualityLevel = quality.mDownlinkCallQualityLevel;
58     mUplinkCallQualityLevel = quality.mUplinkCallQualityLevel;
59     mCallDuration = quality.mCallDuration;
60     mNumRtpPacketsTransmitted = quality.mNumRtpPacketsTransmitted;
61     mNumRtpPacketsReceived = quality.mNumRtpPacketsReceived;
62     mNumRtpPacketsTransmittedLost = quality.mNumRtpPacketsTransmittedLost;
63     mNumRtpPacketsNotReceived = quality.mNumRtpPacketsNotReceived;
64     mAverageRelativeJitter = quality.mAverageRelativeJitter;
65     mMaxRelativeJitter = quality.mMaxRelativeJitter;
66     mAverageRoundTripTime = quality.mAverageRoundTripTime;
67     mCodecType = quality.mCodecType;
68     mRtpInactivityDetected = quality.mRtpInactivityDetected;
69     mRxSilenceDetected = quality.mRxSilenceDetected;
70     mTxSilenceDetected = quality.mTxSilenceDetected;
71     mNumVoiceFrames = quality.mNumVoiceFrames;
72     mNumNoDataFrames = quality.mNumNoDataFrames;
73     mNumDroppedRtpPackets = quality.mNumDroppedRtpPackets;
74     mMinPlayoutDelayMillis = quality.mMinPlayoutDelayMillis;
75     mMaxPlayoutDelayMillis = quality.mMaxPlayoutDelayMillis;
76     mNumRtpSidPacketsReceived = quality.mNumRtpSidPacketsReceived;
77     mNumRtpDuplicatePackets = quality.mNumRtpDuplicatePackets;
78 }
79 
~CallQuality()80 CallQuality::~CallQuality() {}
81 
operator =(const CallQuality & quality)82 CallQuality& CallQuality::operator=(const CallQuality& quality)
83 {
84     if (this != &quality)
85     {
86         mDownlinkCallQualityLevel = quality.mDownlinkCallQualityLevel;
87         mUplinkCallQualityLevel = quality.mUplinkCallQualityLevel;
88         mCallDuration = quality.mCallDuration;
89         mNumRtpPacketsTransmitted = quality.mNumRtpPacketsTransmitted;
90         mNumRtpPacketsReceived = quality.mNumRtpPacketsReceived;
91         mNumRtpPacketsTransmittedLost = quality.mNumRtpPacketsTransmittedLost;
92         mNumRtpPacketsNotReceived = quality.mNumRtpPacketsNotReceived;
93         mAverageRelativeJitter = quality.mAverageRelativeJitter;
94         mMaxRelativeJitter = quality.mMaxRelativeJitter;
95         mAverageRoundTripTime = quality.mAverageRoundTripTime;
96         mCodecType = quality.mCodecType;
97         mRtpInactivityDetected = quality.mRtpInactivityDetected;
98         mRxSilenceDetected = quality.mRxSilenceDetected;
99         mTxSilenceDetected = quality.mTxSilenceDetected;
100         mNumVoiceFrames = quality.mNumVoiceFrames;
101         mNumNoDataFrames = quality.mNumNoDataFrames;
102         mNumDroppedRtpPackets = quality.mNumDroppedRtpPackets;
103         mMinPlayoutDelayMillis = quality.mMinPlayoutDelayMillis;
104         mMaxPlayoutDelayMillis = quality.mMaxPlayoutDelayMillis;
105         mNumRtpSidPacketsReceived = quality.mNumRtpSidPacketsReceived;
106         mNumRtpDuplicatePackets = quality.mNumRtpDuplicatePackets;
107     }
108     return *this;
109 }
110 
operator ==(const CallQuality & quality) const111 bool CallQuality::operator==(const CallQuality& quality) const
112 {
113     return (mDownlinkCallQualityLevel == quality.mDownlinkCallQualityLevel &&
114             mUplinkCallQualityLevel == quality.mUplinkCallQualityLevel &&
115             mCallDuration == quality.mCallDuration &&
116             mNumRtpPacketsTransmitted == quality.mNumRtpPacketsTransmitted &&
117             mNumRtpPacketsReceived == quality.mNumRtpPacketsReceived &&
118             mNumRtpPacketsTransmittedLost == quality.mNumRtpPacketsTransmittedLost &&
119             mNumRtpPacketsNotReceived == quality.mNumRtpPacketsNotReceived &&
120             mAverageRelativeJitter == quality.mAverageRelativeJitter &&
121             mMaxRelativeJitter == quality.mMaxRelativeJitter &&
122             mAverageRoundTripTime == quality.mAverageRoundTripTime &&
123             mCodecType == quality.mCodecType &&
124             mRtpInactivityDetected == quality.mRtpInactivityDetected &&
125             mRxSilenceDetected == quality.mRxSilenceDetected &&
126             mTxSilenceDetected == quality.mTxSilenceDetected &&
127             mNumVoiceFrames == quality.mNumVoiceFrames &&
128             mNumNoDataFrames == quality.mNumNoDataFrames &&
129             mNumDroppedRtpPackets == quality.mNumDroppedRtpPackets &&
130             mMinPlayoutDelayMillis == quality.mMinPlayoutDelayMillis &&
131             mMaxPlayoutDelayMillis == quality.mMaxPlayoutDelayMillis &&
132             mNumRtpSidPacketsReceived == quality.mNumRtpSidPacketsReceived &&
133             mNumRtpDuplicatePackets == quality.mNumRtpDuplicatePackets);
134 }
135 
operator !=(const CallQuality & quality) const136 bool CallQuality::operator!=(const CallQuality& quality) const
137 {
138     return (mDownlinkCallQualityLevel != quality.mDownlinkCallQualityLevel ||
139             mUplinkCallQualityLevel != quality.mUplinkCallQualityLevel ||
140             mCallDuration != quality.mCallDuration ||
141             mNumRtpPacketsTransmitted != quality.mNumRtpPacketsTransmitted ||
142             mNumRtpPacketsReceived != quality.mNumRtpPacketsReceived ||
143             mNumRtpPacketsTransmittedLost != quality.mNumRtpPacketsTransmittedLost ||
144             mNumRtpPacketsNotReceived != quality.mNumRtpPacketsNotReceived ||
145             mAverageRelativeJitter != quality.mAverageRelativeJitter ||
146             mMaxRelativeJitter != quality.mMaxRelativeJitter ||
147             mAverageRoundTripTime != quality.mAverageRoundTripTime ||
148             mCodecType != quality.mCodecType ||
149             mRtpInactivityDetected != quality.mRtpInactivityDetected ||
150             mRxSilenceDetected != quality.mRxSilenceDetected ||
151             mTxSilenceDetected != quality.mTxSilenceDetected ||
152             mNumVoiceFrames != quality.mNumVoiceFrames ||
153             mNumNoDataFrames != quality.mNumNoDataFrames ||
154             mNumDroppedRtpPackets != quality.mNumDroppedRtpPackets ||
155             mMinPlayoutDelayMillis != quality.mMinPlayoutDelayMillis ||
156             mMaxPlayoutDelayMillis != quality.mMaxPlayoutDelayMillis ||
157             mNumRtpSidPacketsReceived != quality.mNumRtpSidPacketsReceived ||
158             mNumRtpDuplicatePackets != quality.mNumRtpDuplicatePackets);
159 }
160 
writeToParcel(Parcel * out) const161 status_t CallQuality::writeToParcel(Parcel* out) const
162 {
163     status_t err;
164     err = out->writeInt32(mDownlinkCallQualityLevel);
165     if (err != NO_ERROR)
166     {
167         return err;
168     }
169 
170     err = out->writeInt32(mUplinkCallQualityLevel);
171     if (err != NO_ERROR)
172     {
173         return err;
174     }
175 
176     err = out->writeInt32(mCallDuration);
177     if (err != NO_ERROR)
178     {
179         return err;
180     }
181 
182     err = out->writeInt32(mNumRtpPacketsTransmitted);
183     if (err != NO_ERROR)
184     {
185         return err;
186     }
187 
188     err = out->writeInt32(mNumRtpPacketsReceived);
189     if (err != NO_ERROR)
190     {
191         return err;
192     }
193 
194     err = out->writeInt32(mNumRtpPacketsTransmittedLost);
195     if (err != NO_ERROR)
196     {
197         return err;
198     }
199 
200     err = out->writeInt32(mNumRtpPacketsNotReceived);
201     if (err != NO_ERROR)
202     {
203         return err;
204     }
205 
206     err = out->writeInt32(mAverageRelativeJitter);
207     if (err != NO_ERROR)
208     {
209         return err;
210     }
211 
212     err = out->writeInt32(mMaxRelativeJitter);
213     if (err != NO_ERROR)
214     {
215         return err;
216     }
217 
218     err = out->writeInt32(mAverageRoundTripTime);
219     if (err != NO_ERROR)
220     {
221         return err;
222     }
223 
224     err = out->writeInt32(mCodecType);
225     if (err != NO_ERROR)
226     {
227         return err;
228     }
229 
230     int32_t value = 0;
231     mRtpInactivityDetected ? value = 1 : value = 0;
232     err = out->writeInt32(value);
233     if (err != NO_ERROR)
234     {
235         return err;
236     }
237 
238     mRxSilenceDetected ? value = 1 : value = 0;
239     err = out->writeInt32(value);
240     if (err != NO_ERROR)
241     {
242         return err;
243     }
244 
245     mTxSilenceDetected ? value = 1 : value = 0;
246     err = out->writeInt32(value);
247     if (err != NO_ERROR)
248     {
249         return err;
250     }
251 
252     err = out->writeInt32(mNumVoiceFrames);
253     if (err != NO_ERROR)
254     {
255         return err;
256     }
257 
258     err = out->writeInt32(mNumNoDataFrames);
259     if (err != NO_ERROR)
260     {
261         return err;
262     }
263 
264     err = out->writeInt32(mNumDroppedRtpPackets);
265     if (err != NO_ERROR)
266     {
267         return err;
268     }
269 
270     err = out->writeInt64(mMinPlayoutDelayMillis);
271     if (err != NO_ERROR)
272     {
273         return err;
274     }
275 
276     err = out->writeInt64(mMaxPlayoutDelayMillis);
277     if (err != NO_ERROR)
278     {
279         return err;
280     }
281 
282     err = out->writeInt32(mNumRtpSidPacketsReceived);
283     if (err != NO_ERROR)
284     {
285         return err;
286     }
287 
288     err = out->writeInt32(mNumRtpDuplicatePackets);
289     if (err != NO_ERROR)
290     {
291         return err;
292     }
293 
294     return NO_ERROR;
295 }
296 
readFromParcel(const Parcel * in)297 status_t CallQuality::readFromParcel(const Parcel* in)
298 {
299     status_t err;
300     err = in->readInt32(&mDownlinkCallQualityLevel);
301     if (err != NO_ERROR)
302     {
303         return err;
304     }
305 
306     err = in->readInt32(&mUplinkCallQualityLevel);
307     if (err != NO_ERROR)
308     {
309         return err;
310     }
311 
312     err = in->readInt32(&mCallDuration);
313     if (err != NO_ERROR)
314     {
315         return err;
316     }
317 
318     err = in->readInt32(&mNumRtpPacketsTransmitted);
319     if (err != NO_ERROR)
320     {
321         return err;
322     }
323 
324     err = in->readInt32(&mNumRtpPacketsReceived);
325     if (err != NO_ERROR)
326     {
327         return err;
328     }
329 
330     err = in->readInt32(&mNumRtpPacketsTransmittedLost);
331     if (err != NO_ERROR)
332     {
333         return err;
334     }
335 
336     err = in->readInt32(&mNumRtpPacketsNotReceived);
337     if (err != NO_ERROR)
338     {
339         return err;
340     }
341 
342     err = in->readInt32(&mAverageRelativeJitter);
343     if (err != NO_ERROR)
344     {
345         return err;
346     }
347 
348     err = in->readInt32(&mMaxRelativeJitter);
349     if (err != NO_ERROR)
350     {
351         return err;
352     }
353 
354     err = in->readInt32(&mAverageRoundTripTime);
355     if (err != NO_ERROR)
356     {
357         return err;
358     }
359 
360     err = in->readInt32(&mCodecType);
361     if (err != NO_ERROR)
362     {
363         return err;
364     }
365 
366     int32_t value = 0;
367     err = in->readInt32(&value);
368     if (err != NO_ERROR)
369     {
370         return err;
371     }
372 
373     value == 0 ? mRtpInactivityDetected = false : mRtpInactivityDetected = true;
374 
375     err = in->readInt32(&value);
376     if (err != NO_ERROR)
377     {
378         return err;
379     }
380 
381     value == 0 ? mRxSilenceDetected = false : mRxSilenceDetected = true;
382 
383     err = in->readInt32(&value);
384     if (err != NO_ERROR)
385     {
386         return err;
387     }
388 
389     value == 0 ? mTxSilenceDetected = false : mTxSilenceDetected = true;
390 
391     err = in->readInt32(&mNumVoiceFrames);
392     if (err != NO_ERROR)
393     {
394         return err;
395     }
396 
397     err = in->readInt32(&mNumNoDataFrames);
398     if (err != NO_ERROR)
399     {
400         return err;
401     }
402 
403     err = in->readInt32(&mNumDroppedRtpPackets);
404     if (err != NO_ERROR)
405     {
406         return err;
407     }
408 
409     err = in->readInt64(&mMinPlayoutDelayMillis);
410     if (err != NO_ERROR)
411     {
412         return err;
413     }
414 
415     err = in->readInt64(&mMaxPlayoutDelayMillis);
416     if (err != NO_ERROR)
417     {
418         return err;
419     }
420 
421     err = in->readInt32(&mNumRtpSidPacketsReceived);
422     if (err != NO_ERROR)
423     {
424         return err;
425     }
426 
427     err = in->readInt32(&mNumRtpDuplicatePackets);
428     if (err != NO_ERROR)
429     {
430         return err;
431     }
432 
433     return NO_ERROR;
434 }
435 
getDownlinkCallQualityLevel()436 int CallQuality::getDownlinkCallQualityLevel()
437 {
438     return mDownlinkCallQualityLevel;
439 }
440 
setDownlinkCallQualityLevel(const int level)441 void CallQuality::setDownlinkCallQualityLevel(const int level)
442 {
443     mDownlinkCallQualityLevel = level;
444 }
445 
getUplinkCallQualityLevel()446 int CallQuality::getUplinkCallQualityLevel()
447 {
448     return mUplinkCallQualityLevel;
449 }
450 
setUplinkCallQualityLevel(const int level)451 void CallQuality::setUplinkCallQualityLevel(const int level)
452 {
453     mUplinkCallQualityLevel = level;
454 }
455 
getCallDuration()456 int CallQuality::getCallDuration()
457 {
458     return mCallDuration;
459 }
460 
setCallDuration(const int duration)461 void CallQuality::setCallDuration(const int duration)
462 {
463     mCallDuration = duration;
464 }
465 
getNumRtpPacketsTransmitted()466 int CallQuality::getNumRtpPacketsTransmitted()
467 {
468     return mNumRtpPacketsTransmitted;
469 }
470 
setNumRtpPacketsTransmitted(const int num)471 void CallQuality::setNumRtpPacketsTransmitted(const int num)
472 {
473     mNumRtpPacketsTransmitted = num;
474 }
475 
getNumRtpPacketsReceived()476 int CallQuality::getNumRtpPacketsReceived()
477 {
478     return mNumRtpPacketsReceived;
479 }
480 
setNumRtpPacketsReceived(const int num)481 void CallQuality::setNumRtpPacketsReceived(const int num)
482 {
483     mNumRtpPacketsReceived = num;
484 }
485 
getNumRtpPacketsTransmittedLost()486 int CallQuality::getNumRtpPacketsTransmittedLost()
487 {
488     return mNumRtpPacketsTransmittedLost;
489 }
490 
setNumRtpPacketsTransmittedLost(const int num)491 void CallQuality::setNumRtpPacketsTransmittedLost(const int num)
492 {
493     mNumRtpPacketsTransmittedLost = num;
494 }
495 
getNumRtpPacketsNotReceived()496 int CallQuality::getNumRtpPacketsNotReceived()
497 {
498     return mNumRtpPacketsNotReceived;
499 }
500 
setNumRtpPacketsNotReceived(const int num)501 void CallQuality::setNumRtpPacketsNotReceived(const int num)
502 {
503     mNumRtpPacketsNotReceived = num;
504 }
505 
getAverageRelativeJitter()506 int CallQuality::getAverageRelativeJitter()
507 {
508     return mAverageRelativeJitter;
509 }
510 
setAverageRelativeJitter(const int jitter)511 void CallQuality::setAverageRelativeJitter(const int jitter)
512 {
513     mAverageRelativeJitter = jitter;
514 }
515 
getMaxRelativeJitter()516 int CallQuality::getMaxRelativeJitter()
517 {
518     return mMaxRelativeJitter;
519 }
520 
setMaxRelativeJitter(const int jitter)521 void CallQuality::setMaxRelativeJitter(const int jitter)
522 {
523     mMaxRelativeJitter = jitter;
524 }
525 
getAverageRoundTripTime()526 int CallQuality::getAverageRoundTripTime()
527 {
528     return mAverageRoundTripTime;
529 }
530 
setAverageRoundTripTime(const int time)531 void CallQuality::setAverageRoundTripTime(const int time)
532 {
533     mAverageRoundTripTime = time;
534 }
535 
getCodecType()536 int CallQuality::getCodecType()
537 {
538     return mCodecType;
539 }
540 
setCodecType(const int type)541 void CallQuality::setCodecType(const int type)
542 {
543     mCodecType = type;
544 }
545 
getRtpInactivityDetected()546 bool CallQuality::getRtpInactivityDetected()
547 {
548     return mRtpInactivityDetected;
549 }
550 
setRtpInactivityDetected(const bool detected)551 void CallQuality::setRtpInactivityDetected(const bool detected)
552 {
553     mRtpInactivityDetected = detected;
554 }
555 
getRxSilenceDetected()556 bool CallQuality::getRxSilenceDetected()
557 {
558     return mRxSilenceDetected;
559 }
560 
setRxSilenceDetected(const bool detected)561 void CallQuality::setRxSilenceDetected(const bool detected)
562 {
563     mRxSilenceDetected = detected;
564 }
565 
getTxSilenceDetected()566 bool CallQuality::getTxSilenceDetected()
567 {
568     return mTxSilenceDetected;
569 }
570 
setTxSilenceDetected(const bool detected)571 void CallQuality::setTxSilenceDetected(const bool detected)
572 {
573     mTxSilenceDetected = detected;
574 }
575 
getNumVoiceFrames()576 int CallQuality::getNumVoiceFrames()
577 {
578     return mNumVoiceFrames;
579 }
580 
setNumVoiceFrames(const int num)581 void CallQuality::setNumVoiceFrames(const int num)
582 {
583     mNumVoiceFrames = num;
584 }
585 
getNumNoDataFrames()586 int CallQuality::getNumNoDataFrames()
587 {
588     return mNumNoDataFrames;
589 }
590 
setNumNoDataFrames(const int num)591 void CallQuality::setNumNoDataFrames(const int num)
592 {
593     mNumNoDataFrames = num;
594 }
595 
getNumDroppedRtpPackets()596 int CallQuality::getNumDroppedRtpPackets()
597 {
598     return mNumDroppedRtpPackets;
599 }
600 
setNumDroppedRtpPackets(const int num)601 void CallQuality::setNumDroppedRtpPackets(const int num)
602 {
603     mNumDroppedRtpPackets = num;
604 }
605 
getMinPlayoutDelayMillis()606 int64_t CallQuality::getMinPlayoutDelayMillis()
607 {
608     return mMinPlayoutDelayMillis;
609 }
610 
setMinPlayoutDelayMillis(const int64_t delay)611 void CallQuality::setMinPlayoutDelayMillis(const int64_t delay)
612 {
613     mMinPlayoutDelayMillis = delay;
614 }
615 
getMaxPlayoutDelayMillis()616 int64_t CallQuality::getMaxPlayoutDelayMillis()
617 {
618     return mMaxPlayoutDelayMillis;
619 }
620 
setMaxPlayoutDelayMillis(const int64_t delay)621 void CallQuality::setMaxPlayoutDelayMillis(const int64_t delay)
622 {
623     mMaxPlayoutDelayMillis = delay;
624 }
625 
getNumRtpSidPacketsReceived()626 int CallQuality::getNumRtpSidPacketsReceived()
627 {
628     return mNumRtpSidPacketsReceived;
629 }
630 
setNumRtpSidPacketsReceived(const int num)631 void CallQuality::setNumRtpSidPacketsReceived(const int num)
632 {
633     mNumRtpSidPacketsReceived = num;
634 }
635 
getNumRtpDuplicatePackets()636 int CallQuality::getNumRtpDuplicatePackets()
637 {
638     return mNumRtpDuplicatePackets;
639 }
640 
setNumRtpDuplicatePackets(const int num)641 void CallQuality::setNumRtpDuplicatePackets(const int num)
642 {
643     mNumRtpDuplicatePackets = num;
644 }
645 
646 }  // namespace imsmedia
647 
648 }  // namespace telephony
649 
650 }  // namespace android