Browse Source

调整ssrc值生成规则;调整API返回消息结构

ntv-wangjian 3 years ago
parent
commit
f76b206e96
6 changed files with 48 additions and 22 deletions
  1. 2
    2
      GB28181Server.js
  2. 18
    5
      GB28181Session.js
  3. 6
    0
      api.txt
  4. 5
    5
      config.js
  5. 10
    6
      stream/server.js
  6. 7
    4
      stream/session.js

+ 2
- 2
GB28181Server.js View File

7
 //GB28181 SIP服务器
7
 //GB28181 SIP服务器
8
 class NodeSIPServer {
8
 class NodeSIPServer {
9
     constructor(config) {
9
     constructor(config) {
10
-		console.log(config);
10
+		//console.log(config);
11
         this.listen = config.GB28181.sipServer.listen || 5060;
11
         this.listen = config.GB28181.sipServer.listen || 5060;
12
         this.host = config.GB28181.sipServer.host || '127.0.0.1';//SIP服务器主机地址
12
         this.host = config.GB28181.sipServer.host || '127.0.0.1';//SIP服务器主机地址
13
         this.defaultPassword = config.GB28181.sipServer.password || '12345678';
13
         this.defaultPassword = config.GB28181.sipServer.password || '12345678';
68
             }
68
             }
69
         });
69
         });
70
 
70
 
71
-        Logger.log(`Node Media GB28181 Sip-Server started on port: ${this.listen}`);
71
+        Logger.log(`GB28181 Sip Server Started on Port: ${this.listen}`);
72
     }
72
     }
73
 
73
 
74
     stop() {
74
     stop() {

+ 18
- 5
GB28181Session.js View File

734
             //0: udp,1:tcp/passive ,2:tcp/active
734
             //0: udp,1:tcp/passive ,2:tcp/active
735
             let selectMode = mode || 0;
735
             let selectMode = mode || 0;
736
 
736
 
737
-            let ssrc = "0" + channelId.substring(16, 20) + channelId.substring(3, 8);
737
+            //ssrc is here  -- by ntv wangjian
738
+            //let ssrc = "0" + channelId.substring(16, 20) + channelId.substring(3, 8);
739
+            let ssed = channelId.substring(13, 20);
740
+            let ised = '' + (parseInt(ssed)*13+10000);
741
+            let ssrc = "0" + ssed + ised.substring(3,5);
738
 
742
 
739
             let host = rhost || "127.0.0.1";
743
             let host = rhost || "127.0.0.1";
740
 
744
 
869
 
873
 
870
                 if (session.bye && session.port === rport && session.host === rhost && session.channelId === channelId && session.play === 'realplay') {
874
                 if (session.bye && session.port === rport && session.host === rhost && session.channelId === channelId && session.play === 'realplay') {
871
 
875
 
872
-                    context.nodeEvent.emit('stopPlayed', session.ssrc);
873
-
876
+                    //ntv 挪到回调中,TODO 这个指令发不成功!
877
+                    //context.nodeEvent.emit('stopPlayed', session.ssrc);
874
                     this.uas.send(session.bye, (response) => {
878
                     this.uas.send(session.bye, (response) => {
875
                         Logger.log(`[${this.id}] StopRealPlay status=${response.status}`);
879
                         Logger.log(`[${this.id}] StopRealPlay status=${response.status}`);
876
-                        delete this.dialogs[key];
880
+                        
881
+                        if(response.status==200){
882
+                            //ntv add 真正结束了才能执行这两句
883
+                            context.nodeEvent.emit('stopPlayed', session.ssrc);
884
+                            delete this.dialogs[key];
885
+                        }
877
                     });
886
                     });
878
 
887
 
888
+                    //ntv
889
+                    this.playmode='';
890
+
879
                     result.result = true;
891
                     result.result = true;
880
                     result.message = 'OK';
892
                     result.message = 'OK';
881
                 }
893
                 }
935
         // 通知
947
         // 通知
936
         if (content.hasOwnProperty('Notify')) {
948
         if (content.hasOwnProperty('Notify')) {
937
 
949
 
938
-            Logger.log(`[${this.id}] Notify CmdType=${content.Notify.CmdType} SN=${content.Notify.SN} length=${request.content.length}`);
950
+            //ntv remove notify log
951
+            //Logger.log(`[${this.id}] Notify CmdType=${content.Notify.CmdType} SN=${content.Notify.SN} length=${request.content.length}`);
939
 
952
 
940
             switch (content.Notify.CmdType) {
953
             switch (content.Notify.CmdType) {
941
                 //保活消息
954
                 //保活消息

+ 6
- 0
api.txt View File

1
 /api/v1/vag/devices/{deviceID}/{channelID}/realplay/{action}/{mediaHost}/{mediaPort}/{streamMode}
1
 /api/v1/vag/devices/{deviceID}/{channelID}/realplay/{action}/{mediaHost}/{mediaPort}/{streamMode}
2
+
3
+播放和停止
2
 /api/v1/vag/devices/10000000000000000002/34020000001320000002/realplay/start/8.131.101.81/9000/1
4
 /api/v1/vag/devices/10000000000000000002/34020000001320000002/realplay/start/8.131.101.81/9000/1
3
 /api/v1/vag/devices/10000000000000000002/34020000001320000002/realplay/stop/8.131.101.81/9000/1
5
 /api/v1/vag/devices/10000000000000000002/34020000001320000002/realplay/stop/8.131.101.81/9000/1
6
+
7
+
8
+获取列表,后面deviceid可选:
9
+/api/v1/vag/devices/10000000000000000003

+ 5
- 5
config.js View File

13
         },
13
         },
14
         streamServer: {
14
         streamServer: {
15
             enable: true,         //是否启用内置流媒体服务 接收/转码/RTMP推送功能,如有支持GB PS RTP 收流服务器,可以设置为flase
15
             enable: true,         //是否启用内置流媒体服务 接收/转码/RTMP推送功能,如有支持GB PS RTP 收流服务器,可以设置为flase
16
-            listen: 9000,         //接收设备端rtp流的多路复用端口
16
+            listen: 9200,         //接收设备端rtp流的多路复用端口
17
             audio_enable: false,  //是否转发音频流
17
             audio_enable: false,  //是否转发音频流
18
             rtp_idle_timeout: 30, //rtp包空闲等待时间,如果指定时间没有收到任何包,rtp监听连接自动停止,发送BYE命令
18
             rtp_idle_timeout: 30, //rtp包空闲等待时间,如果指定时间没有收到任何包,rtp监听连接自动停止,发送BYE命令
19
-            rtp_mix_port: 58200,  //rtp接收监听端口范围,最小值
20
-            rtp_max_port: 58300,  //rtp接收监听端口范围,最大值           
19
+            rtp_mix_port: 9300,  //rtp接收监听端口范围,最小值
20
+            rtp_max_port: 9400,  //rtp接收监听端口范围,最大值           
21
             invite_port_fixed: true, //设备将流发送的端口,是否固定,true:发送流到多路复用端口 如9200,false:动从rtp_mix_port - rtp_max_port 之间的值中选一个可以用的端口
21
             invite_port_fixed: true, //设备将流发送的端口,是否固定,true:发送流到多路复用端口 如9200,false:动从rtp_mix_port - rtp_max_port 之间的值中选一个可以用的端口
22
             host: '0.0.0.0',         //本地地址
22
             host: '0.0.0.0',         //本地地址
23
             rtmpServer: 'rtmp://60.205.164.47/liveshow'  //RTMP服务器基地址
23
             rtmpServer: 'rtmp://60.205.164.47/liveshow'  //RTMP服务器基地址
25
     },
25
     },
26
     VAG: {
26
     VAG: {
27
         http: {
27
         http: {
28
-            port: 1985,
28
+            port: 82,
29
             allow_origin: '*'
29
             allow_origin: '*'
30
         },
30
         },
31
         auth: {
31
         auth: {
32
-            api: true,
32
+            api: false,          // true to open base auth
33
             api_user: 'admin', //default admin
33
             api_user: 'admin', //default admin
34
             api_pass: 'admin', //default admin
34
             api_pass: 'admin', //default admin
35
             play: true,
35
             play: true,

+ 10
- 6
stream/server.js View File

39
         if (this.udpServer) {
39
         if (this.udpServer) {
40
             //TCP
40
             //TCP
41
             this.tcpServer.listen(this.listen, () => {
41
             this.tcpServer.listen(this.listen, () => {
42
-                Logger.log(`Node Media GB28181-Stream/TCP Server started on port: ${this.listen}`);
42
+                Logger.log(`GB28181-Media Server started on TCP port: ${this.listen}`);
43
             });
43
             });
44
             this.tcpServer.on('error', (e) => {
44
             this.tcpServer.on('error', (e) => {
45
-                Logger.error(`Node Media GB28181-Stream/TCP Server ${e}`);
45
+                Logger.error(`GB28181-Media Server ${e}`);
46
             });
46
             });
47
             this.tcpServer.on('close', () => {
47
             this.tcpServer.on('close', () => {
48
-                Logger.log('Node Media GB28181-Stream/TCP Server Close.');
48
+                Logger.log('GB28181-Media Server Close.');
49
             });
49
             });
50
         }
50
         }
51
 
51
 
52
         if (this.udpServer) {
52
         if (this.udpServer) {
53
             //UDP
53
             //UDP
54
             this.udpServer.on("listening", () => {
54
             this.udpServer.on("listening", () => {
55
-                Logger.log(`Node Media GB28181-Stream/UDP Server started on port: ${this.listen}`);
55
+                Logger.log(`GB28181-Media Server started on UDP port: ${this.listen}`);
56
             });
56
             });
57
 
57
 
58
             this.udpServer.on("message", (msg, info) => {
58
             this.udpServer.on("message", (msg, info) => {
127
     }
127
     }
128
 
128
 
129
     //创建TCP主动取流客户端
129
     //创建TCP主动取流客户端
130
+    //ntv 该逻辑没有被使用
130
     createTCPClient(ssrc, host, port) {
131
     createTCPClient(ssrc, host, port) {
131
 
132
 
132
         if (!this.tcpClients[ssrc]) {
133
         if (!this.tcpClients[ssrc]) {
172
         if (!context.publishers.has(ssrc)) {
173
         if (!context.publishers.has(ssrc)) {
173
             var rtmpClient = new NodeRtmpClient(`${this.rtmpServer}/${ssrc}`);
174
             var rtmpClient = new NodeRtmpClient(`${this.rtmpServer}/${ssrc}`);
174
             rtmpClient.startPush();
175
             rtmpClient.startPush();
175
-
176
+            Logger.log("Publish to rtmp server ",this.rtmpServer,ssrc);
176
             //RTMP 发布流状态
177
             //RTMP 发布流状态
177
             rtmpClient.on('status', (info) => {
178
             rtmpClient.on('status', (info) => {
178
-                if (info.code === 'NetStream.Publish.Start')
179
+                if (info.code === 'NetStream.Publish.Start'){
179
                     rtmpClient.isPublishStart = true;
180
                     rtmpClient.isPublishStart = true;
181
+                    Logger.log("rtmp stream start ",ssrc);
182
+                }
180
             });
183
             });
181
 
184
 
182
             //连接关闭
185
             //连接关闭
183
             rtmpClient.on('close', () => {
186
             rtmpClient.on('close', () => {
187
+                Logger.log("rtmp stream closed ",ssrc);
184
                 context.nodeEvent.emit('rtmpClientClose', ssrc);
188
                 context.nodeEvent.emit('rtmpClientClose', ssrc);
185
             });
189
             });
186
 
190
 

+ 7
- 4
stream/session.js View File

32
             this.stop();
32
             this.stop();
33
             return;
33
             return;
34
         }
34
         }
35
+
35
     }
36
     }
36
 
37
 
37
     stop() {
38
     stop() {
73
 
74
 
74
             let rtpData = this.cache.slice(2, rtplength + 2);
75
             let rtpData = this.cache.slice(2, rtplength + 2);
75
 
76
 
76
-            NodeGB28181StreamServerSession.parseRTPacket(rtpData);
77
+            //ntv add 传输this
78
+            NodeGB28181StreamServerSession.parseRTPacket(rtpData,this);
77
 
79
 
78
             this.cache = this.cache.slice(rtplength + 2);
80
             this.cache = this.cache.slice(rtplength + 2);
79
         }
81
         }
100
     }
102
     }
101
 
103
 
102
     //处理UDP/RTP包
104
     //处理UDP/RTP包
103
-    static parseRTPacket(cache) {
105
+    static parseRTPacket(cache,that) {
104
 
106
 
105
         let rtpPacket = new RtpPacket(cache);
107
         let rtpPacket = new RtpPacket(cache);
106
         let ssrc = rtpPacket.getSSRC();
108
         let ssrc = rtpPacket.getSSRC();
117
 
119
 
118
         let session = this.rtpPackets.get(ssrc);
120
         let session = this.rtpPackets.get(ssrc);
119
 
121
 
120
-        Logger.log(`[${ssrc}] RTP Packet: timestamp:${timestamp} seqNumber:${seqNumber} length:${playload.length} `);
122
+		//ntv-wangjian
123
+        //Logger.log(`[${ssrc}] RTP Packet: timestamp:${timestamp} seqNumber:${seqNumber} length:${playload.length} `);
121
 
124
 
122
         switch (playloadType) {
125
         switch (playloadType) {
123
             //PS封装
126
             //PS封装
146
                             context.nodeEvent.emit('rtpReadyed', this.PrefixInteger(ssrc, 10), second[0] - first[0], packet);
149
                             context.nodeEvent.emit('rtpReadyed', this.PrefixInteger(ssrc, 10), second[0] - first[0], packet);
147
                         }
150
                         }
148
                         catch (error) {
151
                         catch (error) {
149
-                            Logger.log(`PS Packet Parse Fail.${error}`);
152
+                            Logger.log(`PS Packet Parse Fail! ${error}`);
150
                         }
153
                         }
151
                     }
154
                     }
152
                 }
155
                 }

Loading…
Cancel
Save