Rtpcommon.cpp 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. #include "Rtpcommon.h"
  2. #include <cstring> // for memset, strncpy
  3. RtpRecvClientInfo_t::RtpRecvClientInfo_t()
  4. {
  5. memset(clientIP, 0, 32);
  6. clientPort = 0;
  7. compareItemID = 0;
  8. compareItemRoadNum = 0;
  9. // memset(sessionName, 0, 32);
  10. type = 0; // 默认类型为0
  11. }
  12. RtpRecvClientInfo_t::RtpRecvClientInfo_t(const RtpRecvClientInfo_t& other)
  13. {
  14. *this = other; // 使用赋值运算符重载来复制数据
  15. }
  16. RtpRecvClientInfo_t& RtpRecvClientInfo_t::operator=(const RtpRecvClientInfo_t& other)
  17. {
  18. if (this != &other)
  19. {
  20. strncpy(clientIP, other.clientIP, sizeof(clientIP) - 1);
  21. clientIP[sizeof(clientIP) - 1] = '\0';
  22. clientPort = other.clientPort;
  23. compareItemID = other.compareItemID;
  24. compareItemRoadNum = other.compareItemRoadNum;
  25. // strncpy(sessionName, other.sessionName, sizeof(sessionName) - 1);
  26. // sessionName[sizeof(sessionName) - 1] = '\0';
  27. type = other.type;
  28. }
  29. return *this;
  30. }
  31. RtpSendClientInfo_t::RtpSendClientInfo_t()
  32. {
  33. }
  34. RtpSendClientInfo_t::RtpSendClientInfo_t(const RtpSendClientInfo_t& other)
  35. {
  36. *this = other;
  37. }
  38. RtpSendClientInfo_t& RtpSendClientInfo_t::operator=(const RtpSendClientInfo_t& other)
  39. {
  40. if (this != &other)
  41. {
  42. localIP = other.localIP;
  43. localPort = other.localPort;
  44. clientIP = other.clientIP;
  45. clientPort = other.clientPort;
  46. // compareItemID = other.compareItemID;
  47. // compareItemRoadNum = other.compareItemRoadNum;
  48. cardPCMInfo = other.cardPCMInfo;
  49. // udpSocket = other.udpSocket; /* 不拷贝udp套接字 */
  50. }
  51. return *this;
  52. }
  53. bool RtpClientKey_t::operator==(const RtpClientKey_t& other) const
  54. {
  55. return (clientIP == other.clientIP && clientPort == other.clientPort &&
  56. cardPCMInfo == other.cardPCMInfo);
  57. }
  58. bool RtpClientKey_t::operator<(const RtpClientKey_t& other) const
  59. {
  60. if (clientPort < other.clientPort)
  61. return true;
  62. if (clientPort > other.clientPort)
  63. return false;
  64. if (cardPCMInfo.pcmInfo.strPCMName < other.cardPCMInfo.pcmInfo.strPCMName)
  65. return true;
  66. if (cardPCMInfo.pcmInfo.strPCMName > other.cardPCMInfo.pcmInfo.strPCMName)
  67. return false;
  68. if (cardPCMInfo.strSoundCardName < other.cardPCMInfo.strSoundCardName)
  69. return true;
  70. if (cardPCMInfo.strSoundCardName > other.cardPCMInfo.strSoundCardName)
  71. return false;
  72. return clientIP < other.clientIP; // 最后比较IP地址
  73. }