国网B接口语音对讲和广播技术探究及与GB28181差别

简介: 在谈国网B接口的语音广播和语音对讲的时候,大家会觉得,国网B接口是不是和GB28181大同小异?实际上确实信令有差别,但是因为要GB28181设备接入测的对接,再次做国网B接口就简单多了。

接口描述

在谈国网B接口的语音广播和语音对讲的时候,大家会觉得,国网B接口是不是和GB28181大同小异?实际上确实信令有差别,但是因为要GB28181设备接入测的对接,再次做国网B接口就简单多了。


语音对讲和广播包括信令接口和媒体流接口,采用与“调阅实时视频”流程相同的机制,不同之处

在于用户发出的请求消息的 SDP 仅携带音频描述信息。

语音所采用的编解码算法为 ITU-T G.711A。

语音对讲和广播,被调阅的平台无需进行音频分发行为。

接口流程

语音对讲和广播的接口流程如下:


ad8a036e2208446089ec94112c8cd528.png

主要功能流程如下:

a) F1:平台用户,对前端系统指定的前端系统摄像机发起实时音频的调阅请求,发送 INVITE 消

息,携带 SDP 内容,通过平台转发到前端系统。

b) F2:按照 SIP 要求,如前端系统在 0.5 s 内未处理该请求,则先发送 1xx 临时响应给平台。

c) F3:前端系统接受了调阅请求的操作,则发送携带 SDP 的 200 OK 响应到平台。

d) F4:平台发送 ACK 给前端系统,确认会话建立。

e) 实时语音流开始传输,前端设备/用户根据相应的解码器解码并语音输出。

f) F5:用户结束会话,平台发送 BYE 消息到前端系统。

g) F6:前端系统发送确认,将媒体通道拆线,会话结束。

接口参数

SIP头字段如下:

37070de6c3f5421eaec20b999c15ceb8.png

SIP响应码返回码如下:

3d5a2d952a284eae8ff6430796305ff5.pngSIP参数定义:

8a51a45450f14ccaae17ec72a7c9f87a.png

094159f2f4f4424baec15c5cd357ff24.png

RTP 动态 Payload 定义如下:

d5e7cc725be942bb93821b6ee40f63c4.png

消息示例

INVITE sip:前端设备地址编码@前端系统所属平台域名或IP地址 SIP/2.0
From: <sip:用户地址编码@用户所属平台域名或IP地址>;tag=3101300
To: <sip:前端设备地址编码@前端系统所属平台域名或IP地址>
Contact: <sip:用户地址编码@用户所属平台域名或IP地址>
Call-ID: c47k42
Via: SIP/2.0/UDP 用户所属平台IP地址;branch=z9hG4bK
CSeq: 1 INVITE
Content-type: application/SDP
Content-Length: 消息体的长度
v=0
o=- 0 0 IN IP4 用户会话IP地址描述
s=-
c=IN IP4 用户媒体IP地址描述
m=audio 38564 RTP/AVP 8
a=rtpmap:8 PCMA/8000
a=sendrecv

语音会话请求响应如下:

SIP/2.0 200 OK
From: <sip: 用户地址编码@用户所属平台域名或IP地址>;tag=3101300
To: <sip: 前端设备地址编码@前端系统所属平台域名或IP地址>;tag=20b0660
Contact: <sip: 用户地址编码@用户所属平台域名或IP地址>
Call-ID: c47k42
Via: SIP/2.0/UDP 用户所属平台IP地址;branch=z9hG4bK
CSeq: 1 INVITE
Content-type: application/SDP
Content-Length: 消息体的长度
v=0
o=- 0 0 IN IP4 前端设备会话IP地址描述
s=-
c=IN IP4 前端设备媒体IP地址描述
m=audio 1000 RTP/AVP 8
a=rtpmap:8 PCMA/8000
a=sendrecv

代码实现

    @Override
    public void ntsOnInviteTalk(String deviceId, SessionDescription sessionDescription) {
        handler_.postDelayed(new Runnable() {
            @Override
            public void run() {
                // 先振铃响应下
                gb28181_agent_.respondTalkInvite(180, device_id_);
                MediaSessionDescription audio_description = null;
                SDPRtpMapAttribute rtp_map_attribute = null;
                Vector<MediaSessionDescription> audio_des_list = session_description_.getAudioDescriptions();
                if (audio_des_list != null && !audio_des_list.isEmpty()) {
                    // 先尝试获取PCMA格式
                    for(MediaSessionDescription m : audio_des_list) {
                        if (m != null && m.isValidAddressType() && m.isHasAddress()) {
                            rtp_map_attribute = m.getRtpMapAttribute(SDPRtpMapAttribute.PCMA_ENCODING_NAME);
                            if (rtp_map_attribute != null) {
                                audio_description = m;
                                break;
                            }
                        }
                    }
                    // 如果没有PCMA格式,尝试获取PS格式
                    if (null == rtp_map_attribute) {
                        for(MediaSessionDescription m : audio_des_list) {
                            if (m != null && m.isValidAddressType() && m.isHasAddress()) {
                                rtp_map_attribute = m.getRtpMapAttribute(SDPRtpMapAttribute.PS_ENCODING_NAME);
                                if (rtp_map_attribute != null) {
                                    audio_description = m;
                                    break;
                                }
                            }
                        }
                    }
                }
                if (null == audio_description) {
                    gb28181_agent_.respondTalkInvite(488, device_id_);
                    Log.i(TAG, "ntsOnInviteTalk get audio description is null, response 488, device_id:" + device_id_);
                    return;
                }
                if (null == rtp_map_attribute ) {
                    gb28181_agent_.respondTalkInvite(488, device_id_);
                    Log.i(TAG, "ntsOnInviteTalk get rtp map attribute is null, response 488, device_id:" + device_id_);
                    return;
                }
                Log.i(TAG,"ntsOnInviteTalk, device_id:" +device_id_+", is_tcp:" + audio_description.isRTPOverTCP()
                        + " rtp_port:" + audio_description.getPort() + " ssrc:" + audio_description.getSSRC()
                        + " address_type:" + audio_description.getAddressType() + " address:" + audio_description.getAddress()
                        + " payload_type:" +   rtp_map_attribute.getPayloadType() + " encoding_name:" + rtp_map_attribute.getEncodingName());
                long rtp_sender_handle = libPublisher.CreateRTPSender(0);
                if (0 == rtp_sender_handle) {
                    gb28181_agent_.respondTalkInvite(488, device_id_);
                    Log.i(TAG, "ntsOnInviteTalk CreateRTPSender failed, response 488, device_id:" + device_id_);
                    return;
                }
                gb_talk_rtp_payload_type_  = rtp_map_attribute.getPayloadType();
                gb_talk_rtp_encoding_name_ = rtp_map_attribute.getEncodingName();
                Log.i(TAG, "gb_talk_rtp_payload_type: " + gb_talk_rtp_payload_type_ + " gb_talk_rtp_encoding_name: " + gb_talk_rtp_encoding_name_);
                gb_talk_rtp_encoding_name_ =  "PS";
                libPublisher.SetRTPSenderTransportProtocol(rtp_sender_handle, audio_description.isRTPOverUDP()?0:1);
                libPublisher.SetRTPSenderIPAddressType(rtp_sender_handle, audio_description.isIPv4()?0:1);
                //libPublisher.SetRTPSenderLocalPort(rtp_sender_handle, 0);
                libPublisher.SetRTPSenderLocalPort(rtp_sender_handle, audio_description.getPort());
                libPublisher.SetRTPSenderSSRC(rtp_sender_handle, audio_description.getSSRC());
                libPublisher.SetRTPSenderSocketSendBuffer(rtp_sender_handle, 256*1024); // 音频配置到256KB
                libPublisher.SetRTPSenderClockRate(rtp_sender_handle, rtp_map_attribute.getClockRate());
                libPublisher.SetRTPSenderDestination(rtp_sender_handle, audio_description.getAddress(), audio_description.getPort());
                gb_talk_is_receive_ = audio_description.isHasAttribute("sendrecv");
                Log.i(TAG, "gb_talk_is_receive: " + gb_talk_is_receive_);
                if (gb_talk_is_receive_) {
                    libPublisher.EnableRTPSenderReceive(rtp_sender_handle, 1);
                    // 收包SSRC, 暂时不设置, 因为部分平台ssrc不一致的
                    // libPublisher.SetRTPSenderReceiveSSRC(rtp_sender_handle, audio_description.getSSRC());
                    // 这个一定要设置
                    libPublisher.SetRTPSenderReceivePayloadType(rtp_sender_handle, gb_talk_rtp_payload_type_, gb_talk_rtp_encoding_name_, 2,  rtp_map_attribute.getClockRate());
                    // 目前发现某些平台 PS-PCMA 是8000, 不建议设置
                    if (gb_talk_rtp_encoding_name_.equals("PS")) {
                        libPublisher.SetRTPSenderReceivePSClockFrequency(rtp_sender_handle, 8000);
                     }
                    // 如果是PCMA编码, 采样率和通道可以先不设置
                    // libPublisher.SetRTPSenderReceiveAudioSamplingRate(rtp_sender_handle, 8000);
                    // libPublisher.SetRTPSenderReceiveAudioChannels(rtp_sender_handle, 1);
                }
                if (libPublisher.InitRTPSender(rtp_sender_handle) != 0 ) {
                    gb28181_agent_.respondTalkInvite(488, device_id_);
                    libPublisher.DestoryRTPSender(rtp_sender_handle);
                    return;
                }
                int local_port = libPublisher.GetRTPSenderLocalPort(rtp_sender_handle);
                if (0==local_port) {
                    gb28181_agent_.respondTalkInvite(488, device_id_);
                    libPublisher.DestoryRTPSender(rtp_sender_handle);
                    return;
                }
                Log.i(TAG,"ntsOnInviteTalk get local_port:" + local_port);
                String local_ip_addr = IPAddrUtils.getIpAddress(context_);
                MediaSessionDescription main_local_audio_des = new MediaSessionDescription(audio_description.getType());
                main_local_audio_des.addFormat(String.valueOf(rtp_map_attribute.getPayloadType()));
                main_local_audio_des.addRtpMapAttribute(rtp_map_attribute);
                main_local_audio_des.addAttribute(new SDPAttribute("sendonly"));
                if (audio_description.isRTPOverTCP()) {
                    // tcp主动链接服务端
                    main_local_audio_des.addAttribute(new SDPAttribute("setup", "active"));
                    main_local_audio_des.addAttribute(new SDPAttribute("connection", "new"));
                }
                main_local_audio_des.setPort(local_port);
                main_local_audio_des.setTransportProtocol(audio_description.getTransportProtocol());
                main_local_audio_des.setSSRC(audio_description.getSSRC());
                MediaSessionDescription sub_local_audio_des = null;
                if (gb_talk_is_receive_) {
                    sub_local_audio_des = new MediaSessionDescription(audio_description.getType());
                    sub_local_audio_des.addFormat(String.valueOf(rtp_map_attribute.getPayloadType()));
                    sub_local_audio_des.addRtpMapAttribute(rtp_map_attribute);
                    sub_local_audio_des.addAttribute(new SDPAttribute("recvonly"));
                    if (audio_description.isRTPOverTCP()) {
                        // tcp主动链接服务端
                        sub_local_audio_des.addAttribute(new SDPAttribute("setup", "active"));
                        sub_local_audio_des.addAttribute(new SDPAttribute("connection", "new"));
                    }
                    sub_local_audio_des.setPort(local_port);
                    sub_local_audio_des.setTransportProtocol(audio_description.getTransportProtocol());
                    sub_local_audio_des.setSSRC(audio_description.getSSRC());
                }
                if (!gb28181_agent_.respondTalkInviteOK(device_id_, audio_description.getAddressType(), local_ip_addr, main_local_audio_des, sub_local_audio_des) ) {
                    libPublisher.DestoryRTPSender(rtp_sender_handle);
                    Log.e(TAG, "ntsOnInviteTalk call respondPlayInviteOK failed.");
                    return;
                }
                gb_talk_rtp_sender_handle_ = rtp_sender_handle;
            }
            private String device_id_;
            private SessionDescription session_description_;
            public Runnable set(String device_id, SessionDescription session_des) {
                this.device_id_ = device_id;
                this.session_description_ = session_des;
                return this;
            }
        }.set(deviceId, sessionDescription),0);
    }

总结

国网B接口的语音广播和语音对讲,和GB28181的还是有些差别,B接口的语音广播和语音对讲,不需要先发broadcast过来,不用设备接入端发invite请求,而是电网平台侧发invite,类似实时视频请求播放流程,感兴趣的开发者,可以根据规范仔细解读研究。

相关文章
|
10月前
|
人工智能 机器人 API
新手一次成功:🦞OpenClaw🦞快速部署教程,2026最新图文流程
OpenClaw(原Clwadbot)是运行于本地的AI创作助手,现升级为Moltbot。本教程详解如何在阿里云轻量应用服务器(2核2G,仅38元/年)上一键部署,并集成钉钉等10+平台,3步完成配置,新手也能一次成功。
|
人工智能 监控 调度
哈希极化、拓扑盲点与拥塞抖动:主流端网协同方案如何缓解万卡集群通信瓶颈?
随着大模型参数规模迈向万亿级,万卡乃至十万卡 GPU 集群正成为 AI 训练基础设施的标配,而万卡集群三大通信瓶颈——哈希极化、拓扑盲点与拥塞抖动,对网络架构提出了前所未有的挑战。本文基于主流互联网大厂的公开实践,深入剖析超大规模集群中端网协同架构的设计思路,并探讨面向 MoE 与 DeepSeek 等新型模型的下一代 AI 网络演进方向。
哈希极化、拓扑盲点与拥塞抖动:主流端网协同方案如何缓解万卡集群通信瓶颈?
|
开发工具 Docker Windows
OpenWrt 通过Docker单独打包passwall ipk
OpenWrt 通过Docker单独打包passwall ipk
|
数据库 Docker 容器
docker容器为啥会开机自启动
通过配置适当的重启策略,Docker容器可以在主机系统重启后自动启动。这对于保持关键服务的高可用性和自动恢复能力非常有用。选择适合的重启策略(如 `always`或 `unless-stopped`),可以确保应用程序在各种情况下保持运行。理解并配置这些策略是确保Docker容器化应用可靠性的关键。
1804 93
|
编解码 监控 安全
GB/T28181规范扫盲和使用场景探讨
GB28181(GB/T 28181-2022)是中国国家标准,规定了安全防范视频监控联网系统的信息传输、交换、控制技术要求。此标准支持设备接入、音视频传输及控制指令交互等功能,适用于各类监控设备如执法记录仪和移动监控系统。技术实现涉及协议栈构建、音视频编码及数据传输等环节。广泛应用在执法记录、移动监控和铁路巡检等领域。例如,海康威视iSecure Center和萤石云平台均支持GB28181协议,实现设备管理和视频传输。此外,大牛直播SDK推出的SmartGBD为Android终端提供了便捷的GB28181接入解决方案,支持多种数据类型接入,增强了设备的互操作性。
3080 0
|
XML Java 程序员
保姆级教程,手把手教你实现SpringBoot自定义starter
保姆级教程,手把手教你实现SpringBoot自定义starter
15243 2
保姆级教程,手把手教你实现SpringBoot自定义starter
|
Linux 网络性能优化 网络安全
Linux(openwrt)下iptables+tc工具实现网络流量限速控制(QoS)
通过以上步骤,您可以在Linux(OpenWrt)系统中使用iptables和tc工具实现网络流量限速控制(QoS)。这种方法灵活且功能强大,可以帮助管理员有效管理网络带宽,确保关键业务的网络性能。希望本文能够为您提供有价值的参考。
4003 28
|
JavaScript 前端开发 安全
跨域解决方案有哪些?
本文介绍了多种跨域解决方案,包括JSONP、CORS、postMessage、WebSocket、document.domain+iframe、window.name、location.hash、Node.js代理、Nginx代理和CORS Anywhere。每种方法都有其适用场景和优缺点,如JSONP简单但只支持GET请求,CORS安全但兼容性稍差,WebSocket适用于实时通信但需服务器支持。开发者可根据具体需求选择合适的跨域方案。
871 3
跨域解决方案有哪些?
|
XML 缓存 Java
搞透 IOC、Spring IOC ,看这篇就够了!
本文详细解析了Spring框架的核心内容——IOC(控制反转)及其依赖注入(DI)的实现原理,帮助读者理解如何通过IOC实现组件解耦,提高程序的灵活性和可维护性。关注【mikechen的互联网架构】,10年+BAT架构经验倾囊相授。
|
XML 缓存 安全
PUT 请求和 POST 请求有什么区别?
【10月更文挑战第25天】PUT请求和POST请求在HTTP协议中有着不同的功能和应用场景,开发者需要根据具体的业务需求和资源操作的性质来选择合适的请求方法,以确保客户端与服务器之间的交互准确、安全且符合预期。