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 #ifndef IMS_MEDIA_DEFINE_H 18 #define IMS_MEDIA_DEFINE_H 19 20 #include <RtpConfig.h> 21 #include <AudioConfig.h> 22 #include <string.h> 23 24 #define DEFAULT_MTU 1500 25 #define SEQ_ROUND_QUARD 655 // 1% of FFFF 26 #define USHORT_SEQ_ROUND_COMPARE(a, b) \ 27 ((((a) >= (b)) && (((b) >= SEQ_ROUND_QUARD) || (((a) <= 0xffff - SEQ_ROUND_QUARD)))) || \ 28 (((a) <= SEQ_ROUND_QUARD) && ((b) >= 0xffff - SEQ_ROUND_QUARD))) 29 #define IMS_MEDIA_WORD_SIZE 4 30 31 using namespace android::telephony::imsmedia; 32 33 enum ImsMediaResult 34 { 35 RESULT_SUCCESS = 0, 36 RESULT_INVALID_PARAM, 37 RESULT_NOT_READY, 38 RESULT_NO_MEMORY, 39 RESULT_NO_RESOURCES, 40 RESULT_PORT_UNAVAILABLE, 41 RESULT_NOT_SUPPORTED, 42 }; 43 44 enum kImsMediaEventType 45 { 46 kImsMediaEventNotifyError = 0, 47 kImsMediaEventStateChanged, 48 kImsMediaEventFirstPacketReceived, 49 kImsMediaEventHeaderExtensionReceived, 50 kImsMediaEventMediaQualityStatus, 51 kImsMediaEventMediaInactivity, 52 kImsMediaEventResolutionChanged, 53 kImsMediaEventNotifyVideoDataUsage, 54 kImsMediaEventNotifyRttReceived, 55 kImsMediaEventNotifyVideoLowestBitrate, 56 }; 57 58 // Internal Request Event 59 enum kImsMediaInternalRequestType 60 { 61 kRequestAudioCmr = 300, 62 kRequestAudioRttdUpdate, 63 kRequestAudioCmrEvs, 64 kRequestVideoCvoUpdate, 65 kRequestVideoBitrateChange, 66 kRequestVideoIdrFrame, 67 kRequestVideoSendNack, 68 kRequestVideoSendPictureLost, 69 kRequestVideoSendTmmbr, 70 kRequestVideoSendTmmbn, 71 kRequestRoundTripTimeDelayUpdate = 310, 72 kRequestAudioPlayingStatus, 73 kCollectPacketInfo, 74 kCollectOptionalInfo, 75 kCollectRxRtpStatus, 76 kCollectJitterBufferSize, 77 kGetRtcpXrReportBlock, 78 kRequestSendRtcpXrReport, 79 }; 80 81 enum kImsMediaErrorNotify 82 { 83 kNotifyErrorSocket = 400, 84 kNotifyErrorSurfaceNotReady, 85 kNotifyErrorCamera, 86 kNotifyErrorEncoder, 87 kNotifyErrorDecoder, 88 }; 89 90 enum ImsMediaStreamType 91 { 92 kStreamRtpTx, 93 kStreamRtpRx, 94 kStreamRtcp, 95 }; 96 97 enum kImsMediaStreamType 98 { 99 kStreamModeRtpTx, 100 kStreamModeRtpRx, 101 kStreamModeRtcp, 102 }; 103 104 enum ImsMediaType 105 { 106 IMS_MEDIA_AUDIO = 0, 107 IMS_MEDIA_VIDEO, 108 IMS_MEDIA_TEXT, 109 }; 110 111 enum AccessNetworkType 112 { 113 ACCESS_NETWORK_UNKNOWN = 0, 114 ACCESS_NETWORK_GERAN = 1, 115 ACCESS_NETWORK_UTRAN = 2, 116 ACCESS_NETWORK_EUTRAN = 3, 117 ACCESS_NETWORK_IWLAN = 5, 118 ACCESS_NETWORK_NGRAN = 6, 119 }; 120 121 enum kProtocolType 122 { 123 kProtocolRtp = 0, 124 kProtocolRtcp, 125 }; 126 127 enum kEvsBandwidth 128 { 129 kEvsBandwidthNone = 0, 130 kEvsBandwidthNB = 1, 131 kEvsBandwidthWB = 2, 132 kEvsBandwidthSWB = 4, 133 kEvsBandwidthFB = 8, 134 }; 135 136 enum kEvsBitrate 137 { 138 /* 6.6 kbps, AMR-IO */ 139 kEvsAmrIoModeBitrate00660 = 0, 140 /* 8.85 kbps, AMR-IO */ 141 kEvsAmrIoModeBitrate00885 = 1, 142 /* 12.65 kbps, AMR-IO */ 143 kEvsAmrIoModeBitrate01265 = 2, 144 /* 14.25 kbps, AMR-IO */ 145 kEvsAmrIoModeBitrate01425 = 3, 146 /* 15.85 kbps, AMR-IO */ 147 kEvsAmrIoModeBitrate01585 = 4, 148 /* 18.25 kbps, AMR-IO */ 149 kEvsAmrIoModeBitrate01825 = 5, 150 /* 19.85 kbps, AMR-IO */ 151 kEvsAmrIoModeBitrate01985 = 6, 152 /* 23.05 kbps, AMR-IO */ 153 kEvsAmrIoModeBitrate02305 = 7, 154 /* 23.85 kbps, AMR-IO */ 155 kEvsAmrIoModeBitrate02385 = 8, 156 /* 5.9 kbps, EVS Primary - SC-VBR 2.8kbps, 7.2kbps, 8kbps*/ 157 kEvsPrimaryModeBitrate00590 = 9, 158 /* 7.2 kbps, EVS Primary */ 159 kEvsPrimaryModeBitrate00720 = 10, 160 /* 8 kbps, EVS Primary */ 161 kEvsPrimaryModeBitrate00800 = 11, 162 /* 9.6 kbps, EVS Primary */ 163 kEvsPrimaryModeBitrate00960 = 12, 164 /* 13.20 kbps, EVS Primary */ 165 kEvsPrimaryModeBitrate01320 = 13, 166 /* 16.4 kbps, EVS Primary */ 167 kEvsPrimaryModeBitrate01640 = 14, 168 /* 24.4 kbps, EVS Primary */ 169 kEvsPrimaryModeBitrate02440 = 15, 170 /* 32 kbps, EVS Primary */ 171 kEvsPrimaryModeBitrate03200 = 16, 172 /* 48 kbps, EVS Primary */ 173 kEvsPrimaryModeBitrate04800 = 17, 174 /* 64 kbps, EVS Primary */ 175 kEvsPrimaryModeBitrate06400 = 18, 176 /* 96 kbps, EVS Primary */ 177 kEvsPrimaryModeBitrate09600 = 19, 178 /* 128 kbps, EVS Primary */ 179 kEvsPrimaryModeBitrate12800 = 20, 180 /* 2.4 kbps, EVS Primary */ 181 kEvsPrimaryModeBitrateSID = 21, 182 /* SPEECH LOST */ 183 kEvsPrimaryModeBitrateSpeechLost = 22, 184 /* NO DATA */ 185 kEvsPrimaryModeBitrateNoData = 23, 186 }; 187 188 enum kEvsCodecMode 189 { 190 kEvsCodecModePrimary = 0, // EVS PRIMARY mode 0 191 kEvsCodecModeAmrIo = 1, // EVS AMR-WB IO mode 1 192 kEvsCodecModeMax = 0x7FFFFFFF 193 }; 194 195 /* CMR Code in TS 26.445 */ 196 enum kEvsCmrCodeType 197 { 198 kEvsCmrCodeTypeNb = 0, // 000: Narrow band 199 kEvsCmrCodeTypeAmrIO = 1, // 001: AMR IO mode 200 kEvsCmrCodeTypeWb = 2, // 010: Wide band 201 kEvsCmrCodeTypeSwb = 3, // 011: Super wide band 202 kEvsCmrCodeTypeFb = 4, // 100: Full band 203 kEvsCmrCodeTypeWbCha = 5, // 101: Wide band(13.2 Channel aware mode) 204 kEvsCmrCodeTypeSwbCha = 6, // 110: Super wide band (13.2 Channel aware mode) 205 kEvsCmrCodeTypeNoReq = 7, // 111: Reserved 206 }; 207 208 /* CMR Definition in TS 26.445 */ 209 enum kEvsCmrCodeDefine 210 { 211 kEvsCmrCodeDefine59 = 0, // 0000 212 kEvsCmrCodeDefine72 = 1, // 0001 213 kEvsCmrCodeDefine80 = 2, // 0010 214 kEvsCmrCodeDefine96 = 3, // 0011 215 kEvsCmrCodeDefine132 = 4, // 0100 216 kEvsCmrCodeDefine164 = 5, // 0101 217 kEvsCmrCodeDefine244 = 6, // 0110 218 kEvsCmrCodeDefine320 = 7, // 0111 219 kEvsCmrCodeDefine480 = 8, // 1000 220 kEvsCmrCodeDefine640 = 9, // 1001 221 kEvsCmrCodeDefine960 = 10, // 1010 222 kEvsCmrCodeDefine1280 = 11, // 1011 223 kEvsCmrCodeDefineNoReq = 15, // 1111 224 225 // Channel aware mode 226 kEvsCmrCodeDefineChaOffset2 = 0, // 0000 227 kEvsCmrCodeDefineChaOffset3 = 1, // 0001 228 kEvsCmrCodeDefineChaOffset5 = 2, // 0010 229 kEvsCmrCodeDefineChaOffset7 = 3, // 0011 230 kEvsCmrCodeDefineChaOffsetH2 = 4, // 0100 231 kEvsCmrCodeDefineChaOffsetH3 = 5, // 0101 232 kEvsCmrCodeDefineChaOffsetH5 = 6, // 0110 233 kEvsCmrCodeDefineChaOffsetH7 = 7, // 0111 234 235 // AMR WB-IO 236 kEvsCmrCodeDefineAmrIo660 = 0, // 0000 237 kEvsCmrCodeDefineAmrIo885 = 1, // 0001 238 kEvsCmrCodeDefineAmrIo1265 = 2, // 0010 239 kEvsCmrCodeDefineAmrIo1425 = 3, // 0011 240 kEvsCmrCodeDefineAmrIo1585 = 4, // 0100 241 kEvsCmrCodeDefineAmrIo1825 = 5, // 0101 242 kEvsCmrCodeDefineAmrIo1985 = 6, // 0110 243 kEvsCmrCodeDefineAmrIo2305 = 7, // 0111 244 kEvsCmrCodeDefineAmrIo2385 = 8, // 1000 245 246 kEvsCmrCodeDefineENUM_MAX = 0x7FFFFFFF 247 }; 248 249 enum ImsMediaSubType 250 { 251 MEDIASUBTYPE_UNDEFINED = 0, 252 // rtp payload header + encoded bitstream 253 MEDIASUBTYPE_RTPPAYLOAD, 254 // rtp packet 255 MEDIASUBTYPE_RTPPACKET, 256 // rtcp packet 257 MEDIASUBTYPE_RTCPPACKET, 258 // rtcp packet 259 MEDIASUBTYPE_RTCPPACKET_BYE, 260 // raw yuv or pcm data 261 MEDIASUBTYPE_RAWDATA, 262 MEDIASUBTYPE_RAWDATA_ROT90, 263 MEDIASUBTYPE_RAWDATA_ROT90_FLIP, 264 MEDIASUBTYPE_RAWDATA_ROT270, 265 MEDIASUBTYPE_RAWDATA_CROP_ROT90, 266 MEDIASUBTYPE_RAWDATA_CROP_ROT90_FLIP, 267 MEDIASUBTYPE_RAWDATA_CROP_ROT270, 268 MEDIASUBTYPE_RAWDATA_CROP, 269 // dtmf packet with start bit set 270 MEDIASUBTYPE_DTMFSTART, 271 // dtmf payload 272 MEDIASUBTYPE_DTMF_PAYLOAD, 273 // dtmf packet with end bit set 274 MEDIASUBTYPE_DTMFEND, 275 MEDIASUBTYPE_VIDEO_CONFIGSTRING, 276 MEDIASUBTYPE_VIDEO_IDR_FRAME, 277 MEDIASUBTYPE_VIDEO_NON_IDR_FRAME, 278 MEDIASUBTYPE_VIDEO_SEI_FRAME, 279 MEDIASUBTYPE_ROT0 = 20, 280 MEDIASUBTYPE_ROT90, 281 MEDIASUBTYPE_ROT180, 282 MEDIASUBTYPE_ROT270, 283 MEDIASUBTYPE_REFRESHED, 284 // rtt bitstream of t.140 format 285 MEDIASUBTYPE_BITSTREAM_T140, 286 // rtt bitstream of t.140 redundant format 287 MEDIASUBTYPE_BITSTREAM_T140_RED, 288 MEDIASUBTYPE_PCM_DATA, 289 MEDIASUBTYPE_PCM_NO_DATA, 290 // Jitter Buffer GetData not ready 291 MEDIASUBTYPE_NOT_READY, 292 MEDIASUBTYPE_BITSTREAM_CODECCONFIG, 293 MEDIASUBTYPE_AUDIO_SID, 294 MEDIASUBTYPE_AUDIO_NODATA, 295 MEDIASUBTYPE_AUDIO_NORMAL, 296 MEDIASUBTYPE_MAX 297 }; 298 299 enum ImsMediaAudioMsgRequest 300 { 301 kAudioOpenSession = 101, 302 kAudioCloseSession, 303 kAudioModifySession, 304 kAudioAddConfig, 305 kAudioDeleteConfig, 306 kAudioConfirmConfig, 307 kAudioSendDtmf, 308 kAudioSendRtpHeaderExtension, 309 kAudioSetMediaQualityThreshold, 310 kAudioRequestRtpReceptionStats = 112, 311 kAudioAdjustDelay, 312 }; 313 314 enum ImsMediaAudioMsgResponse 315 { 316 kAudioOpenSessionSuccess = 201, 317 kAudioOpenSessionFailure, 318 kAudioModifySessionResponse, 319 kAudioAddConfigResponse, 320 kAudioConfirmConfigResponse, 321 kAudioFirstMediaPacketInd, 322 kAudioRtpHeaderExtensionInd, 323 kAudioMediaQualityStatusInd, 324 kAudioTriggerAnbrQueryInd, 325 kAudioDtmfReceivedInd, 326 kAudioCallQualityChangedInd, 327 kAudioSessionClosed, 328 kAudioNotifyRtpReceptionStats, 329 }; 330 331 enum ImsMediaVideoMsgRequest 332 { 333 kVideoOpenSession = 101, 334 kVideoCloseSession, 335 kVideoModifySession, 336 kVideoSetPreviewSurface, 337 kVideoSetDisplaySurface, 338 kVideoSendRtpHeaderExtension, 339 kVideoSetMediaQualityThreshold, 340 kVideoRequestDataUsage, 341 }; 342 343 enum ImsMediaVideoMsgResponse 344 { 345 kVideoOpenSessionSuccess = 201, 346 kVideoOpenSessionFailure, 347 kVideoModifySessionResponse, 348 kVideoFirstMediaPacketInd, 349 kVideoPeerDimensionChanged, 350 kVideoRtpHeaderExtensionInd, 351 kVideoMediaInactivityInd, 352 kVideoBitrateInd, 353 kVideoDataUsageInd, 354 kVideoSessionClosed, 355 }; 356 357 enum ImsMediaTextMsgRequest 358 { 359 kTextOpenSession = 101, 360 kTextCloseSession, 361 kTextModifySession, 362 kTextSetMediaQualityThreshold, 363 kTextSendRtt, 364 }; 365 366 enum ImsMediaTextMsgResponse 367 { 368 kTextOpenSessionSuccess = 201, 369 kTextOpenSessionFailure, 370 kTextModifySessionResponse, 371 kTextMediaInactivityInd, 372 kTextRttReceived, 373 kTextSessionClosed, 374 }; 375 376 #define UNDEFINED_SOCKET_FD (-1) 377 #define T140_BUFFERING_TIME (300) 378 #define RTT_MAX_CHAR_PER_SEC (30) // ATIS_GTT : 30 characters per second 379 #define RTT_MAX_UNICODE_UTF8 (4) 380 #define MAX_RTT_LEN (RTT_MAX_CHAR_PER_SEC * RTT_MAX_UNICODE_UTF8) 381 #define PAYLOADENCODER_TEXT_MAX_REDUNDANT_INTERVAL (16383) 382 383 struct EventParamOpenSession 384 { 385 public: 386 void* mConfig; 387 int rtpFd; 388 int rtcpFd; 389 EventParamOpenSession( 390 int rtp = UNDEFINED_SOCKET_FD, int rtcp = UNDEFINED_SOCKET_FD, void* config = nullptr) : mConfigEventParamOpenSession391 mConfig(config), 392 rtpFd(rtp), 393 rtcpFd(rtcp) 394 { 395 } 396 }; 397 398 struct EventParamDtmf 399 { 400 public: 401 char digit; 402 int duration; 403 EventParamDtmfEventParamDtmf404 EventParamDtmf(char dig, int d) 405 { 406 digit = dig; 407 duration = d; 408 } 409 }; 410 411 enum kAudioCodecType 412 { 413 kAudioCodecNone = 0, 414 kAudioCodecAmr, 415 kAudioCodecAmrWb, 416 kAudioCodecPcmu, 417 kAudioCodecPcma, 418 kAudioCodecEvs, 419 }; 420 421 enum kVideoCodecType 422 { 423 kVideoCodecNone = 0, 424 kVideoCodecAvc, 425 kVideoCodecHevc, 426 }; 427 428 enum kRtpPayloadHeaderMode 429 { 430 // Amr mode 431 kRtpPayloadHeaderModeAmrOctetAligned = 0, // octet aligned mode 432 kRtpPayloadHeaderModeAmrEfficient = 1, // efficient mode 433 // Video packetization mode 434 kRtpPayloadHeaderModeSingleNalUnit = 0, // packet mode 0 435 kRtpPayloadHeaderModeNonInterleaved = 1, // packet mode 1 436 // Evs mode 437 kRtpPayloadHeaderModeEvsCompact = 0, // EVS compact format 0 438 kRtpPayloadHeaderModeEvsHeaderFull = 1, // EVS header-full format 1 439 kRtpPayloadHeaderModeMax 440 }; 441 442 enum kIpVersion 443 { 444 IPV4, 445 IPV6, 446 }; 447 448 enum StreamState 449 { 450 /** The state of the stream created but any nodes are not created */ 451 kStreamStateIdle, 452 /** The state of the stream and nodes are created */ 453 kStreamStateCreated, 454 /** The state of the stream nodes are started and running */ 455 kStreamStateRunning, 456 /** Video state wait surface in stating */ 457 kStreamStateWaitSurface, 458 }; 459 460 enum SessionState 461 { 462 /** The state that the session is created but graph is not created */ 463 kSessionStateOpened, 464 /** The state that the session is created and the TX rtp StreamGraphs are running */ 465 kSessionStateSending, 466 /** The state that the session is created and the RX rtp StreamGraphs are running */ 467 kSessionStateReceiving, 468 /** The state that the session is created and the both TX and Rx rtp StreamGraphs are running */ 469 kSessionStateActive, 470 /** The state that the session is created and the Rtp StreamGraphs is not running */ 471 kSessionStateSuspended, 472 /** The state that the session is closed */ 473 kSessionStateClosed, 474 }; 475 476 enum kSocketOption 477 { 478 kSocketOptionNone = 0, 479 kSocketOptionIpTos = 1, 480 kSocketOptionIpTtl = 2, 481 }; 482 483 enum kRtpPacketStatus 484 { 485 kRtpStatusNotDefined = 0, 486 kRtpStatusNormal, 487 kRtpStatusLate, 488 kRtpStatusDiscarded, 489 kRtpStatusDuplicated, 490 kRtpStatusLost, 491 }; 492 493 enum kRtpDataType 494 { 495 kRtpDataTypeNoData = 0, 496 kRtpDataTypeSid, 497 kRtpDataTypeNormal, 498 }; 499 500 enum kAudioPlayingStatus 501 { 502 kAudioTypeNoData = 0, 503 kAudioTypeVoice, 504 }; 505 506 enum kOptionalReportType 507 { 508 kTimeToLive, 509 kRoundTripDelay, 510 kReportPacketLossGap, 511 kAudioPlayingStatus, 512 }; 513 514 /** TODO: change the name to avoid confusion by similarity */ 515 struct RtpPacket 516 { 517 public: 518 RtpPacket(const uint32_t s = 0, const uint32_t seq = 0, const uint32_t t = 0, 519 const int32_t j = 0, const int32_t ts = 0, const int32_t a = 0, 520 const kRtpDataType type = kRtpDataTypeNoData, 521 const kRtpPacketStatus st = kRtpStatusNotDefined) : ssrcRtpPacket522 ssrc(s), 523 seqNum(seq), 524 TTL(t), 525 jitter(j), 526 timestamp(ts), 527 arrival(a), 528 rtpDataType(type), 529 status(st) 530 { 531 } RtpPacketRtpPacket532 RtpPacket(const RtpPacket& p) 533 { 534 ssrc = p.ssrc; 535 seqNum = p.seqNum; 536 TTL = p.TTL; 537 jitter = p.jitter; 538 timestamp = p.timestamp; 539 arrival = p.arrival; 540 rtpDataType = p.rtpDataType; 541 status = p.status; 542 } 543 544 uint32_t ssrc; 545 uint32_t seqNum; 546 uint32_t TTL; 547 /** transit time difference */ 548 int32_t jitter; 549 int32_t timestamp; 550 /** arrival time */ 551 int32_t arrival; 552 kRtpDataType rtpDataType; 553 kRtpPacketStatus status; 554 }; 555 556 /** 557 * @brief It is lost packet data structure to store the start number of packet sequence and the 558 * number of lost packets 559 */ 560 struct LostPacket 561 { 562 public: 563 LostPacket(uint16_t s = 0, uint32_t num = 0, uint32_t time = 0, uint32_t opt = 0) : seqNumLostPacket564 seqNum(s), 565 numLoss(num), 566 markedTime(time), 567 option(opt) 568 { 569 } 570 /** The rtp sequence number of beginning of lost packet */ 571 uint16_t seqNum; 572 /** The number of lost packets */ 573 uint32_t numLoss; 574 /** The time in milliseconds when determined to lost */ 575 uint32_t markedTime; 576 /** optional parameter for nack */ 577 uint32_t option; 578 }; 579 580 struct RtpHeaderExtensionInfo 581 { 582 public: 583 enum 584 { 585 // RFC 8285#section-4.2, The bit pattern for one byte header 586 kBitPatternForOneByteHeader = 0xBEDE, 587 // RFC 8285#section-4.3, The bit pattern for two byte header 588 kBitPatternForTwoByteHeader = 0x1000, 589 }; 590 591 uint16_t definedByProfile; 592 uint16_t length; // length in word unit 593 int8_t* extensionData; 594 uint16_t extensionDataSize; 595 596 RtpHeaderExtensionInfo( 597 uint16_t profile = 0, uint16_t len = 0, int8_t* data = nullptr, uint16_t size = 0) 598 { 599 definedByProfile = profile; 600 length = len; 601 extensionData = nullptr; 602 extensionDataSize = 0; 603 setExtensionData(data, size); 604 } 605 RtpHeaderExtensionInfoRtpHeaderExtensionInfo606 RtpHeaderExtensionInfo(const RtpHeaderExtensionInfo& extension) 607 { 608 definedByProfile = extension.definedByProfile; 609 extensionData = nullptr; 610 length = extension.length; 611 setExtensionData(extension.extensionData, extension.extensionDataSize); 612 } 613 ~RtpHeaderExtensionInfoRtpHeaderExtensionInfo614 ~RtpHeaderExtensionInfo() 615 { 616 if (extensionData != nullptr) 617 { 618 delete[] extensionData; 619 extensionData = nullptr; 620 } 621 } 622 623 RtpHeaderExtensionInfo& operator=(const RtpHeaderExtensionInfo& extension) 624 { 625 if (this != &extension) 626 { 627 definedByProfile = extension.definedByProfile; 628 length = extension.length; 629 setExtensionData(extension.extensionData, extension.extensionDataSize); 630 } 631 632 return *this; 633 } 634 setExtensionDataRtpHeaderExtensionInfo635 void setExtensionData(int8_t* data, uint16_t dataSize) 636 { 637 if (extensionData != nullptr) 638 { 639 delete[] extensionData; 640 extensionData = nullptr; 641 extensionDataSize = 0; 642 } 643 644 if (data != nullptr) 645 { 646 extensionDataSize = dataSize; 647 extensionData = new int8_t[extensionDataSize]; 648 memcpy(extensionData, data, extensionDataSize); 649 } 650 } 651 }; 652 653 #define MAX_IP_LEN 128 654 #define MAX_REMOTE_POINT 40 655 656 class RtpAddress 657 { 658 public: 659 RtpAddress(const char* ip = nullptr, uint32_t p = 0) 660 { 661 memset(this->ipAddress, 0, MAX_IP_LEN); 662 if (ip != nullptr) 663 { 664 std::strncpy(ipAddress, ip, MAX_IP_LEN); 665 } 666 port = p; 667 } ~RtpAddress()668 ~RtpAddress() {} RtpAddress(const RtpAddress & address)669 RtpAddress(const RtpAddress& address) : 670 port(address.port) 671 { 672 memset(this->ipAddress, 0, MAX_IP_LEN); 673 std::strncpy(this->ipAddress, address.ipAddress, MAX_IP_LEN); 674 } 675 RtpAddress& operator=(const RtpAddress& address) 676 { 677 if (this != &address) 678 { 679 memset(this->ipAddress, 0, MAX_IP_LEN); 680 std::strncpy(this->ipAddress, address.ipAddress, MAX_IP_LEN); 681 this->port = address.port; 682 } 683 684 return *this; 685 } 686 bool operator==(const RtpAddress& address) 687 { 688 return (std::strcmp(this->ipAddress, address.ipAddress) == 0 && this->port == address.port); 689 } 690 bool operator!=(const RtpAddress& address) 691 { 692 return (std::strcmp(this->ipAddress, address.ipAddress) != 0 || this->port != address.port); 693 } 694 char ipAddress[MAX_IP_LEN]; 695 uint32_t port; 696 }; 697 698 struct RtcpRecvReport 699 { 700 public: 701 RtcpRecvReport(const uint32_t s = 0, const uint32_t f = 0, const uint32_t c = 0, 702 const uint32_t e = 0, const uint32_t j = 0, const uint32_t l = 0, 703 const uint32_t d = 0) : ssrcRtcpRecvReport704 ssrc(s), 705 fractionLost(f), 706 cumPktsLost(c), 707 extHighSeqNum(e), 708 jitter(j), 709 lsr(l), 710 delayLsr(d) 711 { 712 } 713 RtcpRecvReportRtcpRecvReport714 RtcpRecvReport(const RtcpRecvReport& report) : 715 ssrc(report.ssrc), 716 fractionLost(report.fractionLost), 717 cumPktsLost(report.cumPktsLost), 718 extHighSeqNum(report.extHighSeqNum), 719 jitter(report.jitter), 720 lsr(report.lsr), 721 delayLsr(report.delayLsr) 722 723 { 724 } 725 726 RtcpRecvReport& operator=(const RtcpRecvReport& report) 727 { 728 if (this != &report) 729 { 730 ssrc = report.ssrc; 731 fractionLost = report.fractionLost; 732 cumPktsLost = report.cumPktsLost; 733 extHighSeqNum = report.extHighSeqNum; 734 jitter = report.jitter; 735 lsr = report.lsr; 736 delayLsr = report.delayLsr; 737 } 738 739 return *this; 740 } 741 742 uint32_t ssrc; 743 uint32_t fractionLost; 744 uint32_t cumPktsLost; 745 uint32_t extHighSeqNum; 746 uint32_t jitter; 747 uint32_t lsr; 748 uint32_t delayLsr; 749 }; 750 751 struct RtcpSr 752 { 753 public: 754 RtcpSr(const uint32_t ntpTsMsw = 0, const uint32_t ntpTsLsw = 0, const uint32_t rtpTs = 0, 755 const uint32_t count = 0, const uint32_t octCount = 0, 756 const RtcpRecvReport& report = RtcpRecvReport()) : ntpTimestampMswRtcpSr757 ntpTimestampMsw(ntpTsMsw), 758 ntpTimestampLsw(ntpTsLsw), 759 rtpTimestamp(rtpTs), 760 sendPktCount(count), 761 sendOctCount(octCount), 762 recvReport(report) 763 { 764 } 765 766 uint32_t ntpTimestampMsw; 767 uint32_t ntpTimestampLsw; 768 uint32_t rtpTimestamp; 769 uint32_t sendPktCount; 770 uint32_t sendOctCount; 771 RtcpRecvReport recvReport; // only one RR block is supported. 772 }; 773 774 struct RtcpRr 775 { 776 public: RtcpRrRtcpRr777 RtcpRr(const RtcpRecvReport& report) : 778 recvReport(report) 779 { 780 } 781 782 RtcpRecvReport recvReport; // only one RR block is supported. 783 }; 784 785 #endif 786