• GB28181控制、传输流程和协议接口之注册|注销和技术实现


    注册和注销基本要求 SIP客户端、网关、SIP设备、联网系统等 SIP代理(SIP UA)使用IETFRFC3261中定义的方法 15 GB/T28181—2016Register进行注册和注销。

    注册和注销时应进行认证,认证方式应支持数字摘要认证方式,高安全级别的宜支持数字证书的认证方式,数字证书的格式符合附录I中的规定。

    SIP代理在注册过期时间到来之前,应向注册服务器进行刷新注册,刷新注册消息流程应与9.1.2.1 的流程描述一致,并遵循IETFRFC3261对刷新注册的规定。

    若注册失败,SIP代理应间隔一定时间后继续发起注册过程,与上一次注册时间间隔应可调,一般情况下不应短于60s。

    系统、设备注册过期时间应可配置,缺省值为86400s(1d),应在注册过期时间到来之前发送刷新注册消息,为SIP服务器预留适当刷新注册处理时间,注册过期时间不应短于3600s。

    SIP代理注册成功则认为SIP服务器为在线状态,注册失败则认为SIP服务器为离线状态;SIP服务器在SIP代理注册成功后认为其为在线状态,SIP代理注册过期则认为其为离线状态。

    注册流程

    以基本注册流程为例,流程如下:

     注册流程描述如下:

    a) 1:SIP代理向SIP服务器发送 Register请求;

    b) 2:SIP服务器向 SIP代理发送响应401,并在响应的消息头 WWW_Authenticate字段中给出适合SIP代理的认证体制和参数;

    c) 3:SIP代理重新向SIP服务器发送Register请求,在请求的 Authorization字段给出信任书, 包含认证信息;

    d) 4:SIP 服务器对请求进行验证,如果检查出 SIP 代理身份合法,向SIP代理发送成功响应 200OK,如果身份不合法则发送拒绝服务应答。

    基于数字证书的双向认证注册不再赘述。

    注销流程

    注销流程描述如下:

    a) 1:SIP代理向SIP服务器发送Register请求,Expires字段的值为0,表示SIP代理要注销;

    b) 2:SIP服务器向 SIP代理发送响应401,并在响应的消息头 WWW_Authenticate字段中给出适合SIP代理的认证体制和参数;

    c) 3:SIP代理重新向SIP服务器发送 Register请求,在请求的 Authorization字段给出信任书, 包含认证信息,Expires字段的值为0;

    d) 4:SIP 服务器对请求进行验证,如果检查出 SIP 代理身份合法,向 SIP 代理发送成功响应 200OK,如果身份不合法则发送拒绝服务应答。 

    相关技术实现

    1. /*
    2. * CameraPublishActivity.java
    3. * initGB28181Agent 初始化参数
    4. *
    5. * WebSite: https://daniusdk.com
    6. * Github: https://github.com/daniulive/SmarterStreaming
    7. *
    8. */
    9. private boolean initGB28181Agent() {
    10. if ( gb28181_agent_ != null )
    11. return true;
    12. getLocation(context_);
    13. String local_ip_addr = IPAddrUtils.getIpAddress(context_);
    14. Log.i(TAG, "initGB28181Agent local ip addr: " + local_ip_addr);
    15. if ( local_ip_addr == null || local_ip_addr.isEmpty() ) {
    16. Log.e(TAG, "initGB28181Agent local ip is empty");
    17. return false;
    18. }
    19. gb28181_agent_ = GBSIPAgentFactory.getInstance().create();
    20. if ( gb28181_agent_ == null ) {
    21. Log.e(TAG, "initGB28181Agent create agent failed");
    22. return false;
    23. }
    24. gb28181_agent_.addListener(this);
    25. // 必填信息
    26. gb28181_agent_.setLocalAddress(local_ip_addr);
    27. gb28181_agent_.setServerParameter(gb28181_sip_server_addr_, gb28181_sip_server_port_, gb28181_sip_server_id_, gb28181_sip_domain_);
    28. gb28181_agent_.setUserInfo(gb28181_sip_username_, gb28181_sip_password_);
    29. // 可选参数
    30. gb28181_agent_.setUserAgent(gb28181_sip_user_agent_filed_);
    31. gb28181_agent_.setTransportProtocol(gb28181_sip_trans_protocol_==0?"UDP":"TCP");
    32. // GB28181配置
    33. gb28181_agent_.config(gb28181_reg_expired_, gb28181_heartbeat_interval_, gb28181_heartbeat_count_);
    34. //com.gb.ntsignalling.Device gb_device = new com.gb.ntsignalling.Device("34020000001380000001", "安卓测试设备", Build.MANUFACTURER, Build.MODEL,
    35. // "宇宙","火星1","火星", true);
    36. com.gb.ntsignalling.Device gb_device = new com.gb.ntsignalling.Device("33010752991327811433", "安卓测试设备", Build.MANUFACTURER, Build.MODEL,
    37. "宇宙","火星1","火星", true);
    38. if (mLongitude != null && mLatitude != null) {
    39. com.gb.ntsignalling.DevicePosition device_pos = new com.gb.ntsignalling.DevicePosition();
    40. device_pos.setTime(mLocationTime);
    41. device_pos.setLongitude(mLongitude);
    42. device_pos.setLatitude(mLatitude);
    43. gb_device.setPosition(device_pos);
    44. gb_device.setSupportMobilePosition(true); // 设置支持移动位置上报
    45. }
    46. gb28181_agent_.addDevice(gb_device);
    47. /*
    48. com.gb28181.ntsignalling.Device gb_device1 = new com.gb28181.ntsignalling.Device("34020000001380000002", "安卓测试设备2", Build.MANUFACTURER, Build.MODEL,
    49. "宇宙","火星1","火星", true);
    50. if (mLongitude != null && mLatitude != null) {
    51. com.gb28181.ntsignalling.DevicePosition device_pos = new com.gb28181.ntsignalling.DevicePosition();
    52. device_pos.setTime(mLocationTime);
    53. device_pos.setLongitude(mLongitude);
    54. device_pos.setLatitude(mLatitude);
    55. gb_device1.setPosition(device_pos);
    56. gb_device1.setSupportMobilePosition(true);
    57. }
    58. gb28181_agent_.addDevice(gb_device1);
    59. */
    60. if (!gb28181_agent_.createSipStack()) {
    61. gb28181_agent_ = null;
    62. Log.e(TAG, "initGB28181Agent gb28181_agent_.createSipStack failed.");
    63. return false;
    64. }
    65. boolean is_bind_local_port_ok = false;
    66. // 最多尝试5000个端口
    67. int try_end_port = gb28181_sip_local_port_base_ + 5000;
    68. try_end_port = try_end_port > 65536 ?65536: try_end_port;
    69. for (int i = gb28181_sip_local_port_base_; i < try_end_port; ++i) {
    70. if (gb28181_agent_.bindLocalPort(i)) {
    71. is_bind_local_port_ok = true;
    72. break;
    73. }
    74. }
    75. if (!is_bind_local_port_ok) {
    76. gb28181_agent_.releaseSipStack();
    77. gb28181_agent_ = null;
    78. Log.e(TAG, "initGB28181Agent gb28181_agent_.bindLocalPort failed.");
    79. return false;
    80. }
    81. if (!gb28181_agent_.initialize()) {
    82. gb28181_agent_.unBindLocalPort();
    83. gb28181_agent_.releaseSipStack();
    84. gb28181_agent_ = null;
    85. Log.e(TAG, "initGB28181Agent gb28181_agent_.initialize failed.");
    86. return false;
    87. }
    88. return true;
    89. }

    initGB28181Agent() 完成基础化参数配置后,就开始发Register;

    和注册相关的状态反馈如下:

    1. @Override
    2. public void ntsRegisterOK(String dateString) {
    3. Log.i(TAG, "ntsRegisterOK Date: " + (dateString!= null? dateString : ""));
    4. }
    5. @Override
    6. public void ntsRegisterTimeout() {
    7. Log.e(TAG, "ntsRegisterTimeout");
    8. }
    9. @Override
    10. public void ntsRegisterTransportError(String errorInfo) {
    11. Log.e(TAG, "ntsRegisterTransportError error:" + (errorInfo != null?errorInfo :""));
    12. }

    注销的话,Expires字段的值为0即可。

  • 相关阅读:
    Zama的fhEVM:基于全同态加密实现的隐私智能合约
    springboot中@Async的使用
    Vue3问题:如何实现el-tree树的单选?
    【机器学习】如何判断函数凸或非凸?(面试回答)
    Linux网络监控工具 - nethogs
    基于STM32的LoRaWAN无线通信网络设计与实现
    8通道1:2或2:1双向多路复用器/多路解复用器,GRANDMICRO有容微的ASW3810可以代完美替
    Spring Cloud + Nacos 集成Netty Socket.IO
    一次SpringBoot版本升级,引发的血案
    力扣第 387 场周赛第四题 将元素分配到两个数组中 II 二分查找,离散化,线段树
  • 原文地址:https://blog.csdn.net/renhui1112/article/details/126799477