Commit 4cdeeb4a3656a35c4b91cbcdd99d8b7c679f5e84
1 parent
0898c63c
修复一些日志设置
Showing
4 changed files
with
120 additions
and
28 deletions
pom.xml
| @@ -169,8 +169,8 @@ | @@ -169,8 +169,8 @@ | ||
| 169 | </dependencies> | 169 | </dependencies> |
| 170 | 170 | ||
| 171 | <build> | 171 | <build> |
| 172 | + <finalName>wvp-2.5.8</finalName> | ||
| 172 | <plugins> | 173 | <plugins> |
| 173 | - | ||
| 174 | <plugin> | 174 | <plugin> |
| 175 | <groupId>org.springframework.boot</groupId> | 175 | <groupId>org.springframework.boot</groupId> |
| 176 | <artifactId>spring-boot-maven-plugin</artifactId> | 176 | <artifactId>spring-boot-maven-plugin</artifactId> |
| @@ -184,18 +184,6 @@ | @@ -184,18 +184,6 @@ | ||
| 184 | <configuration> | 184 | <configuration> |
| 185 | <source>1.8</source> | 185 | <source>1.8</source> |
| 186 | <target>1.8</target> | 186 | <target>1.8</target> |
| 187 | - <!-- | ||
| 188 | - <webResources> | ||
| 189 | - <resource> | ||
| 190 | - <directory>${project.basedir}/libs</directory> | ||
| 191 | - <targetPath>WEB-INF/lib</targetPath> | ||
| 192 | - <filtering>true</filtering> | ||
| 193 | - <includes> | ||
| 194 | - <include>**/*.jar</include> | ||
| 195 | - </includes> | ||
| 196 | - </resource> | ||
| 197 | - </webResources> | ||
| 198 | - --> | ||
| 199 | </configuration> | 187 | </configuration> |
| 200 | </plugin> | 188 | </plugin> |
| 201 | 189 |
src/main/java/com/genersoft/iot/vmp/gb28181/transmit/request/impl/RegisterRequestProcessor.java
| @@ -16,6 +16,8 @@ import javax.sip.header.ViaHeader; | @@ -16,6 +16,8 @@ import javax.sip.header.ViaHeader; | ||
| 16 | import javax.sip.message.Request; | 16 | import javax.sip.message.Request; |
| 17 | import javax.sip.message.Response; | 17 | import javax.sip.message.Response; |
| 18 | 18 | ||
| 19 | +import org.slf4j.Logger; | ||
| 20 | +import org.slf4j.LoggerFactory; | ||
| 19 | import org.springframework.util.StringUtils; | 21 | import org.springframework.util.StringUtils; |
| 20 | 22 | ||
| 21 | import com.genersoft.iot.vmp.common.VideoManagerConstants; | 23 | import com.genersoft.iot.vmp.common.VideoManagerConstants; |
| @@ -39,6 +41,8 @@ import gov.nist.javax.sip.header.Expires; | @@ -39,6 +41,8 @@ import gov.nist.javax.sip.header.Expires; | ||
| 39 | */ | 41 | */ |
| 40 | public class RegisterRequestProcessor extends SIPRequestAbstractProcessor { | 42 | public class RegisterRequestProcessor extends SIPRequestAbstractProcessor { |
| 41 | 43 | ||
| 44 | + private Logger logger = LoggerFactory.getLogger(RegisterRequestProcessor.class); | ||
| 45 | + | ||
| 42 | private SipConfig sipConfig; | 46 | private SipConfig sipConfig; |
| 43 | 47 | ||
| 44 | private RegisterLogicHandler handler; | 48 | private RegisterLogicHandler handler; |
| @@ -46,17 +50,15 @@ public class RegisterRequestProcessor extends SIPRequestAbstractProcessor { | @@ -46,17 +50,15 @@ public class RegisterRequestProcessor extends SIPRequestAbstractProcessor { | ||
| 46 | private IVideoManagerStorager storager; | 50 | private IVideoManagerStorager storager; |
| 47 | 51 | ||
| 48 | private EventPublisher publisher; | 52 | private EventPublisher publisher; |
| 49 | - | ||
| 50 | - /*** | 53 | + |
| 54 | + /** | ||
| 51 | * 收到注册请求 处理 | 55 | * 收到注册请求 处理 |
| 52 | - * | ||
| 53 | - * @param request | ||
| 54 | - * 请求消息 | ||
| 55 | - */ | 56 | + * @param evt |
| 57 | + */ | ||
| 56 | @Override | 58 | @Override |
| 57 | public void process(RequestEvent evt) { | 59 | public void process(RequestEvent evt) { |
| 58 | try { | 60 | try { |
| 59 | - System.out.println("收到注册请求,开始处理"); | 61 | + logger.info("收到注册请求,开始处理"); |
| 60 | Request request = evt.getRequest(); | 62 | Request request = evt.getRequest(); |
| 61 | 63 | ||
| 62 | Response response = null; | 64 | Response response = null; |
| @@ -75,9 +77,9 @@ public class RegisterRequestProcessor extends SIPRequestAbstractProcessor { | @@ -75,9 +77,9 @@ public class RegisterRequestProcessor extends SIPRequestAbstractProcessor { | ||
| 75 | if (authorhead == null || !passwordCorrect) { | 77 | if (authorhead == null || !passwordCorrect) { |
| 76 | 78 | ||
| 77 | if (authorhead == null) { | 79 | if (authorhead == null) { |
| 78 | - System.out.println("未携带授权头 回复401"); | 80 | + logger.info("未携带授权头 回复401"); |
| 79 | } else if (!passwordCorrect) { | 81 | } else if (!passwordCorrect) { |
| 80 | - System.out.println("密码错误 回复401"); | 82 | + logger.info("密码错误 回复401"); |
| 81 | } | 83 | } |
| 82 | response = getMessageFactory().createResponse(Response.UNAUTHORIZED, request); | 84 | response = getMessageFactory().createResponse(Response.UNAUTHORIZED, request); |
| 83 | new DigestServerAuthenticationHelper().generateChallenge(getHeaderFactory(), response, sipConfig.getSipDomain()); | 85 | new DigestServerAuthenticationHelper().generateChallenge(getHeaderFactory(), response, sipConfig.getSipDomain()); |
| @@ -138,12 +140,12 @@ public class RegisterRequestProcessor extends SIPRequestAbstractProcessor { | @@ -138,12 +140,12 @@ public class RegisterRequestProcessor extends SIPRequestAbstractProcessor { | ||
| 138 | // 保存到redis | 140 | // 保存到redis |
| 139 | // 下发catelog查询目录 | 141 | // 下发catelog查询目录 |
| 140 | if (registerFlag == 1 && device != null) { | 142 | if (registerFlag == 1 && device != null) { |
| 141 | - System.out.println("注册成功! deviceId:" + device.getDeviceId()); | 143 | + logger.info("注册成功! deviceId:" + device.getDeviceId()); |
| 142 | storager.updateDevice(device); | 144 | storager.updateDevice(device); |
| 143 | publisher.onlineEventPublish(device.getDeviceId(), VideoManagerConstants.EVENT_ONLINE_REGISTER); | 145 | publisher.onlineEventPublish(device.getDeviceId(), VideoManagerConstants.EVENT_ONLINE_REGISTER); |
| 144 | handler.onRegister(device); | 146 | handler.onRegister(device); |
| 145 | } else if (registerFlag == 2) { | 147 | } else if (registerFlag == 2) { |
| 146 | - System.out.println("注销成功! deviceId:" + device.getDeviceId()); | 148 | + logger.info("注销成功! deviceId:" + device.getDeviceId()); |
| 147 | publisher.outlineEventPublish(device.getDeviceId(), VideoManagerConstants.EVENT_OUTLINE_UNREGISTER); | 149 | publisher.outlineEventPublish(device.getDeviceId(), VideoManagerConstants.EVENT_OUTLINE_UNREGISTER); |
| 148 | } | 150 | } |
| 149 | } catch (SipException | InvalidArgumentException | NoSuchAlgorithmException | ParseException e) { | 151 | } catch (SipException | InvalidArgumentException | NoSuchAlgorithmException | ParseException e) { |
src/main/java/com/genersoft/iot/vmp/web/ApiStreamController.java
| 1 | package com.genersoft.iot.vmp.web; | 1 | package com.genersoft.iot.vmp.web; |
| 2 | 2 | ||
| 3 | import com.alibaba.fastjson.JSON; | 3 | import com.alibaba.fastjson.JSON; |
| 4 | +import com.alibaba.fastjson.JSONArray; | ||
| 4 | import com.alibaba.fastjson.JSONObject; | 5 | import com.alibaba.fastjson.JSONObject; |
| 5 | import com.genersoft.iot.vmp.common.StreamInfo; | 6 | import com.genersoft.iot.vmp.common.StreamInfo; |
| 6 | import com.genersoft.iot.vmp.gb28181.bean.Device; | 7 | import com.genersoft.iot.vmp.gb28181.bean.Device; |
| 7 | import com.genersoft.iot.vmp.gb28181.bean.DeviceChannel; | 8 | import com.genersoft.iot.vmp.gb28181.bean.DeviceChannel; |
| 8 | import com.genersoft.iot.vmp.gb28181.transmit.cmd.impl.SIPCommander; | 9 | import com.genersoft.iot.vmp.gb28181.transmit.cmd.impl.SIPCommander; |
| 10 | +import com.genersoft.iot.vmp.media.zlm.ZLMRESTfulUtils; | ||
| 9 | import com.genersoft.iot.vmp.storager.IVideoManagerStorager; | 11 | import com.genersoft.iot.vmp.storager.IVideoManagerStorager; |
| 10 | import com.genersoft.iot.vmp.vmanager.play.PlayController; | 12 | import com.genersoft.iot.vmp.vmanager.play.PlayController; |
| 11 | import org.slf4j.Logger; | 13 | import org.slf4j.Logger; |
| 12 | import org.slf4j.LoggerFactory; | 14 | import org.slf4j.LoggerFactory; |
| 13 | import org.springframework.beans.factory.annotation.Autowired; | 15 | import org.springframework.beans.factory.annotation.Autowired; |
| 16 | +import org.springframework.beans.factory.annotation.Value; | ||
| 14 | import org.springframework.http.HttpStatus; | 17 | import org.springframework.http.HttpStatus; |
| 15 | import org.springframework.http.ResponseEntity; | 18 | import org.springframework.http.ResponseEntity; |
| 16 | import org.springframework.web.bind.annotation.*; | 19 | import org.springframework.web.bind.annotation.*; |
| @@ -31,6 +34,13 @@ public class ApiStreamController { | @@ -31,6 +34,13 @@ public class ApiStreamController { | ||
| 31 | @Autowired | 34 | @Autowired |
| 32 | private IVideoManagerStorager storager; | 35 | private IVideoManagerStorager storager; |
| 33 | 36 | ||
| 37 | + @Value("${media.closeWaitRTPInfo}") | ||
| 38 | + private boolean closeWaitRTPInfo; | ||
| 39 | + | ||
| 40 | + | ||
| 41 | + @Autowired | ||
| 42 | + private ZLMRESTfulUtils zlmresTfulUtils; | ||
| 43 | + | ||
| 34 | /** | 44 | /** |
| 35 | * 实时直播 - 开始直播 | 45 | * 实时直播 - 开始直播 |
| 36 | * @param serial 设备编号 | 46 | * @param serial 设备编号 |
| @@ -56,28 +66,112 @@ public class ApiStreamController { | @@ -56,28 +66,112 @@ public class ApiStreamController { | ||
| 56 | @RequestParam(required = false)String timeout | 66 | @RequestParam(required = false)String timeout |
| 57 | 67 | ||
| 58 | ){ | 68 | ){ |
| 59 | - | 69 | + int getEncoding = closeWaitRTPInfo? 1: 0; |
| 60 | Device device = storager.queryVideoDevice(serial); | 70 | Device device = storager.queryVideoDevice(serial); |
| 71 | + | ||
| 61 | if (device == null ) { | 72 | if (device == null ) { |
| 62 | JSONObject result = new JSONObject(); | 73 | JSONObject result = new JSONObject(); |
| 63 | result.put("error","device[ " + serial + " ]未找到"); | 74 | result.put("error","device[ " + serial + " ]未找到"); |
| 64 | return result; | 75 | return result; |
| 76 | + }else if (device.getOnline() == 0) { | ||
| 77 | + JSONObject result = new JSONObject(); | ||
| 78 | + result.put("error","device[ " + code + " ]offline"); | ||
| 79 | + return result; | ||
| 65 | } | 80 | } |
| 81 | + | ||
| 66 | DeviceChannel deviceChannel = storager.queryChannel(serial, code); | 82 | DeviceChannel deviceChannel = storager.queryChannel(serial, code); |
| 67 | if (deviceChannel == null) { | 83 | if (deviceChannel == null) { |
| 68 | JSONObject result = new JSONObject(); | 84 | JSONObject result = new JSONObject(); |
| 69 | result.put("error","channel[ " + code + " ]未找到"); | 85 | result.put("error","channel[ " + code + " ]未找到"); |
| 70 | return result; | 86 | return result; |
| 87 | + }else if (deviceChannel.getStatus() == 0) { | ||
| 88 | + JSONObject result = new JSONObject(); | ||
| 89 | + result.put("error","channel[ " + code + " ]offline"); | ||
| 90 | + return result; | ||
| 71 | } | 91 | } |
| 92 | + | ||
| 72 | // 查询是否已经在播放 | 93 | // 查询是否已经在播放 |
| 73 | StreamInfo streamInfo = storager.queryPlayByDevice(device.getDeviceId(), code); | 94 | StreamInfo streamInfo = storager.queryPlayByDevice(device.getDeviceId(), code); |
| 74 | - if (streamInfo == null) streamInfo = cmder.playStreamCmd(device, code); | 95 | + if (streamInfo == null) { |
| 96 | + logger.debug("streamInfo 等于null, 重新点播"); | ||
| 97 | + streamInfo = cmder.playStreamCmd(device, code); | ||
| 98 | + }else { | ||
| 99 | + logger.debug("streamInfo 不等于null, 向流媒体查询是否正在推流"); | ||
| 100 | + String streamId = String.format("%08x", Integer.parseInt(streamInfo.getSsrc())).toUpperCase(); | ||
| 101 | + JSONObject rtpInfo = zlmresTfulUtils.getRtpInfo(streamId); | ||
| 102 | + if (rtpInfo.getBoolean("exist")) { | ||
| 103 | + logger.debug("向流媒体查询正在推流, 直接返回: " + streamInfo.getRtsp()); | ||
| 104 | + JSONObject result = new JSONObject(); | ||
| 105 | + result.put("StreamID", streamInfo.getSsrc()); | ||
| 106 | + result.put("DeviceID", device.getDeviceId()); | ||
| 107 | + result.put("ChannelID", code); | ||
| 108 | + result.put("ChannelName", deviceChannel.getName()); | ||
| 109 | + result.put("ChannelCustomName ", ""); | ||
| 110 | + result.put("FLV ", streamInfo.getFlv()); | ||
| 111 | + result.put("WS_FLV ", streamInfo.getWs_flv()); | ||
| 112 | + result.put("RTMP", streamInfo.getRtmp()); | ||
| 113 | + result.put("HLS", streamInfo.getHls()); | ||
| 114 | + result.put("RTSP", streamInfo.getRtsp()); | ||
| 115 | + result.put("CDN", ""); | ||
| 116 | + result.put("SnapURL", ""); | ||
| 117 | + result.put("Transport", device.getTransport()); | ||
| 118 | + result.put("StartAt", ""); | ||
| 119 | + result.put("Duration", ""); | ||
| 120 | + result.put("SourceVideoCodecName", ""); | ||
| 121 | + result.put("SourceVideoWidth", ""); | ||
| 122 | + result.put("SourceVideoHeight", ""); | ||
| 123 | + result.put("SourceVideoFrameRate", ""); | ||
| 124 | + result.put("SourceAudioCodecName", ""); | ||
| 125 | + result.put("SourceAudioSampleRate", ""); | ||
| 126 | + result.put("AudioEnable", ""); | ||
| 127 | + result.put("Ondemand", ""); | ||
| 128 | + result.put("InBytes", ""); | ||
| 129 | + result.put("InBitRate", ""); | ||
| 130 | + result.put("OutBytes", ""); | ||
| 131 | + result.put("NumOutputs", ""); | ||
| 132 | + result.put("CascadeSize", ""); | ||
| 133 | + result.put("RelaySize", ""); | ||
| 134 | + result.put("ChannelPTZType", 0); | ||
| 135 | + return result; | ||
| 136 | + } else { | ||
| 137 | + logger.debug("向流媒体查询没有推流, 重新点播"); | ||
| 138 | + storager.stopPlay(streamInfo); | ||
| 139 | + streamInfo = cmder.playStreamCmd(device, code); | ||
| 140 | + } | ||
| 141 | + } | ||
| 75 | 142 | ||
| 76 | if (logger.isDebugEnabled()) { | 143 | if (logger.isDebugEnabled()) { |
| 77 | logger.debug(String.format("设备预览 API调用,deviceId:%s ,channelId:%s",serial, code)); | 144 | logger.debug(String.format("设备预览 API调用,deviceId:%s ,channelId:%s",serial, code)); |
| 78 | logger.debug("设备预览 API调用,ssrc:"+streamInfo.getSsrc()+",ZLMedia streamId:"+Integer.toHexString(Integer.parseInt(streamInfo.getSsrc()))); | 145 | logger.debug("设备预览 API调用,ssrc:"+streamInfo.getSsrc()+",ZLMedia streamId:"+Integer.toHexString(Integer.parseInt(streamInfo.getSsrc()))); |
| 79 | } | 146 | } |
| 147 | + boolean lockFlag = true; | ||
| 148 | + long startTime = System.currentTimeMillis(); | ||
| 149 | + while (lockFlag) { | ||
| 150 | + try { | ||
| 151 | + if (System.currentTimeMillis() - startTime > 10 * 1000) { | ||
| 152 | + storager.stopPlay(streamInfo); | ||
| 153 | + logger.info("播放等待超时"); | ||
| 154 | + JSONObject result = new JSONObject(); | ||
| 155 | + result.put("error","timeout"); | ||
| 156 | + return result; | ||
| 157 | + } else { | ||
| 80 | 158 | ||
| 159 | + StreamInfo streamInfoNow = storager.queryPlayByDevice(serial, code); | ||
| 160 | + logger.debug("正在向流媒体查询"); | ||
| 161 | + if (streamInfoNow != null && streamInfoNow.getFlv() != null) { | ||
| 162 | + streamInfo = streamInfoNow; | ||
| 163 | + logger.debug("向流媒体查询到: " + streamInfoNow.getRtsp()); | ||
| 164 | + lockFlag = false; | ||
| 165 | + continue; | ||
| 166 | + } else { | ||
| 167 | + Thread.sleep(2000); | ||
| 168 | + continue; | ||
| 169 | + } | ||
| 170 | + } | ||
| 171 | + } catch (InterruptedException e) { | ||
| 172 | + e.printStackTrace(); | ||
| 173 | + } | ||
| 174 | + } | ||
| 81 | if(streamInfo!=null) { | 175 | if(streamInfo!=null) { |
| 82 | JSONObject result = new JSONObject(); | 176 | JSONObject result = new JSONObject(); |
| 83 | result.put("StreamID", streamInfo.getSsrc()); | 177 | result.put("StreamID", streamInfo.getSsrc()); |
src/main/resources/application.yml
| @@ -49,5 +49,13 @@ media: #zlm服务器的ip与http端口, 重点: 这是http端口 | @@ -49,5 +49,13 @@ media: #zlm服务器的ip与http端口, 重点: 这是http端口 | ||
| 49 | rtp: # 启用udp多端口模式 | 49 | rtp: # 启用udp多端口模式 |
| 50 | enable: true | 50 | enable: true |
| 51 | udpPortRange: 30000,30500 # 端口范围 | 51 | udpPortRange: 30000,30500 # 端口范围 |
| 52 | - | ||
| 53 | - | 52 | +logging: |
| 53 | + file: | ||
| 54 | + name: logs/wvp.log | ||
| 55 | + max-history: 30 | ||
| 56 | + max-size: 10MB | ||
| 57 | + total-size-cap:300MB | ||
| 58 | + level: | ||
| 59 | + com: | ||
| 60 | + genersoft: | ||
| 61 | + iot: debug | ||
| 54 | \ No newline at end of file | 62 | \ No newline at end of file |