Rtpcommon.cpp 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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. SoundCardNum = other.SoundCardNum;
  49. SoundCardRoadNum = other.SoundCardRoadNum;
  50. // udpSocket = other.udpSocket; /* 不拷贝udp套接字 */
  51. }
  52. return *this;
  53. }
  54. bool RtpClientKey_t::operator==(const RtpClientKey_t& other) const
  55. {
  56. return (clientIP == other.clientIP && clientPort == other.clientPort &&
  57. SoundCardNum == other.SoundCardNum && SoundCardRoadNum == other.SoundCardRoadNum);
  58. }
  59. bool RtpClientKey_t::operator<(const RtpClientKey_t& other) const
  60. {
  61. if (clientPort < other.clientPort)
  62. return true;
  63. if (clientPort > other.clientPort)
  64. return false;
  65. if (SoundCardNum < other.SoundCardNum)
  66. return true;
  67. if (SoundCardNum > other.SoundCardNum)
  68. return false;
  69. if (SoundCardRoadNum < other.SoundCardRoadNum)
  70. return true;
  71. if (SoundCardRoadNum > other.SoundCardRoadNum)
  72. return false;
  73. return clientIP < other.clientIP; // 最后比较IP地址
  74. }