Procházet zdrojové kódy

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

ntv-wangjian před 3 roky
rodič
revize
f76b206e96
6 změnil soubory, kde provedl 48 přidání a 22 odebrání
  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 Zobrazit soubor

@@ -7,7 +7,7 @@ const NodeSipSession = require('./GB28181Session');
7 7
 //GB28181 SIP服务器
8 8
 class NodeSIPServer {
9 9
     constructor(config) {
10
-		console.log(config);
10
+		//console.log(config);
11 11
         this.listen = config.GB28181.sipServer.listen || 5060;
12 12
         this.host = config.GB28181.sipServer.host || '127.0.0.1';//SIP服务器主机地址
13 13
         this.defaultPassword = config.GB28181.sipServer.password || '12345678';
@@ -68,7 +68,7 @@ class NodeSIPServer {
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 74
     stop() {

+ 18
- 5
GB28181Session.js Zobrazit soubor

@@ -734,7 +734,11 @@ class NodeSipSession {
734 734
             //0: udp,1:tcp/passive ,2:tcp/active
735 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 743
             let host = rhost || "127.0.0.1";
740 744
 
@@ -869,13 +873,21 @@ class NodeSipSession {
869 873
 
870 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 878
                     this.uas.send(session.bye, (response) => {
875 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 891
                     result.result = true;
880 892
                     result.message = 'OK';
881 893
                 }
@@ -935,7 +947,8 @@ class NodeSipSession {
935 947
         // 通知
936 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 953
             switch (content.Notify.CmdType) {
941 954
                 //保活消息

+ 6
- 0
api.txt Zobrazit soubor

@@ -1,3 +1,9 @@
1 1
 /api/v1/vag/devices/{deviceID}/{channelID}/realplay/{action}/{mediaHost}/{mediaPort}/{streamMode}
2
+
3
+播放和停止
2 4
 /api/v1/vag/devices/10000000000000000002/34020000001320000002/realplay/start/8.131.101.81/9000/1
3 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 Zobrazit soubor

@@ -13,11 +13,11 @@ var config = module.exports = {
13 13
         },
14 14
         streamServer: {
15 15
             enable: true,         //是否启用内置流媒体服务 接收/转码/RTMP推送功能,如有支持GB PS RTP 收流服务器,可以设置为flase
16
-            listen: 9000,         //接收设备端rtp流的多路复用端口
16
+            listen: 9200,         //接收设备端rtp流的多路复用端口
17 17
             audio_enable: false,  //是否转发音频流
18 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 21
             invite_port_fixed: true, //设备将流发送的端口,是否固定,true:发送流到多路复用端口 如9200,false:动从rtp_mix_port - rtp_max_port 之间的值中选一个可以用的端口
22 22
             host: '0.0.0.0',         //本地地址
23 23
             rtmpServer: 'rtmp://60.205.164.47/liveshow'  //RTMP服务器基地址
@@ -25,11 +25,11 @@ var config = module.exports = {
25 25
     },
26 26
     VAG: {
27 27
         http: {
28
-            port: 1985,
28
+            port: 82,
29 29
             allow_origin: '*'
30 30
         },
31 31
         auth: {
32
-            api: true,
32
+            api: false,          // true to open base auth
33 33
             api_user: 'admin', //default admin
34 34
             api_pass: 'admin', //default admin
35 35
             play: true,

+ 10
- 6
stream/server.js Zobrazit soubor

@@ -39,20 +39,20 @@ class NodeGB28181StreamServer {
39 39
         if (this.udpServer) {
40 40
             //TCP
41 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 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 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 52
         if (this.udpServer) {
53 53
             //UDP
54 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 58
             this.udpServer.on("message", (msg, info) => {
@@ -127,6 +127,7 @@ class NodeGB28181StreamServer {
127 127
     }
128 128
 
129 129
     //创建TCP主动取流客户端
130
+    //ntv 该逻辑没有被使用
130 131
     createTCPClient(ssrc, host, port) {
131 132
 
132 133
         if (!this.tcpClients[ssrc]) {
@@ -172,15 +173,18 @@ class NodeGB28181StreamServer {
172 173
         if (!context.publishers.has(ssrc)) {
173 174
             var rtmpClient = new NodeRtmpClient(`${this.rtmpServer}/${ssrc}`);
174 175
             rtmpClient.startPush();
175
-
176
+            Logger.log("Publish to rtmp server ",this.rtmpServer,ssrc);
176 177
             //RTMP 发布流状态
177 178
             rtmpClient.on('status', (info) => {
178
-                if (info.code === 'NetStream.Publish.Start')
179
+                if (info.code === 'NetStream.Publish.Start'){
179 180
                     rtmpClient.isPublishStart = true;
181
+                    Logger.log("rtmp stream start ",ssrc);
182
+                }
180 183
             });
181 184
 
182 185
             //连接关闭
183 186
             rtmpClient.on('close', () => {
187
+                Logger.log("rtmp stream closed ",ssrc);
184 188
                 context.nodeEvent.emit('rtmpClientClose', ssrc);
185 189
             });
186 190
 

+ 7
- 4
stream/session.js Zobrazit soubor

@@ -32,6 +32,7 @@ class NodeGB28181StreamServerSession {
32 32
             this.stop();
33 33
             return;
34 34
         }
35
+
35 36
     }
36 37
 
37 38
     stop() {
@@ -73,7 +74,8 @@ class NodeGB28181StreamServerSession {
73 74
 
74 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 80
             this.cache = this.cache.slice(rtplength + 2);
79 81
         }
@@ -100,7 +102,7 @@ class NodeGB28181StreamServerSession {
100 102
     }
101 103
 
102 104
     //处理UDP/RTP包
103
-    static parseRTPacket(cache) {
105
+    static parseRTPacket(cache,that) {
104 106
 
105 107
         let rtpPacket = new RtpPacket(cache);
106 108
         let ssrc = rtpPacket.getSSRC();
@@ -117,7 +119,8 @@ class NodeGB28181StreamServerSession {
117 119
 
118 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 125
         switch (playloadType) {
123 126
             //PS封装
@@ -146,7 +149,7 @@ class NodeGB28181StreamServerSession {
146 149
                             context.nodeEvent.emit('rtpReadyed', this.PrefixInteger(ssrc, 10), second[0] - first[0], packet);
147 150
                         }
148 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…
Zrušit
Uložit