Commit 6282c81bc5d3da22eaa304ad564d15014bcc4a79

Authored by 648540858
1 parent dda68ac0

移除onvif实现

libs/onvif-java-1.0.2.jar deleted 100644 → 0
No preview for this file type
@@ -212,17 +212,6 @@ @@ -212,17 +212,6 @@
212 <!-- <version>1.0.8</version>--> 212 <!-- <version>1.0.8</version>-->
213 <!-- </dependency>--> 213 <!-- </dependency>-->
214 214
215 -  
216 -  
217 - <!-- onvif协议栈 -->  
218 - <dependency>  
219 - <groupId>be.teletask</groupId>  
220 - <artifactId>onvif-java</artifactId>  
221 - <version>1.0.2</version>  
222 - <scope>system</scope>  
223 - <systemPath>${project.basedir}/libs/onvif-java-1.0.2.jar</systemPath>  
224 - </dependency>  
225 -  
226 <dependency> 215 <dependency>
227 <groupId>org.springframework.boot</groupId> 216 <groupId>org.springframework.boot</groupId>
228 <artifactId>spring-boot-starter-test</artifactId> 217 <artifactId>spring-boot-starter-test</artifactId>
src/main/java/com/genersoft/iot/vmp/onvif/IONVIFServer.java deleted 100644 → 0
1 -package com.genersoft.iot.vmp.onvif;  
2 -  
3 -import be.teletask.onvif.models.OnvifDevice;  
4 -import com.genersoft.iot.vmp.onvif.dto.ONVIFCallBack;  
5 -  
6 -import java.util.List;  
7 -  
8 -public interface IONVIFServer {  
9 -  
10 - void search(int timeout, ONVIFCallBack<List<String>> callBack);  
11 -  
12 - void getRTSPUrl(int timeout, OnvifDevice device, ONVIFCallBack<String> callBack);  
13 -}  
src/main/java/com/genersoft/iot/vmp/onvif/dto/ONVIFCallBack.java deleted 100644 → 0
1 -package com.genersoft.iot.vmp.onvif.dto;  
2 -  
3 -public interface ONVIFCallBack<T> {  
4 - void run(int errorCode, T t);  
5 -}  
src/main/java/com/genersoft/iot/vmp/onvif/impl/ONVIFServerIMpl.java deleted 100644 → 0
1 -package com.genersoft.iot.vmp.onvif.impl;  
2 -  
3 -  
4 -import be.teletask.onvif.DiscoveryManager;  
5 -import be.teletask.onvif.OnvifManager;  
6 -import be.teletask.onvif.listeners.*;  
7 -import be.teletask.onvif.models.*;  
8 -import be.teletask.onvif.responses.OnvifResponse;  
9 -import com.genersoft.iot.vmp.onvif.IONVIFServer;  
10 -import com.genersoft.iot.vmp.onvif.dto.ONVIFCallBack;  
11 -import org.slf4j.Logger;  
12 -import org.slf4j.LoggerFactory;  
13 -import org.springframework.stereotype.Service;  
14 -  
15 -import java.util.ArrayList;  
16 -import java.util.HashMap;  
17 -import java.util.List;  
18 -import java.util.Map;  
19 -  
20 -@SuppressWarnings("rawtypes")  
21 -/**  
22 - * 处理onvif的各种操作  
23 - */  
24 -@Service  
25 -public class ONVIFServerIMpl implements IONVIFServer {  
26 -  
27 - private final static Logger logger = LoggerFactory.getLogger(ONVIFServerIMpl.class);  
28 -  
29 - @Override  
30 - public void search(int timeout, ONVIFCallBack<List<String>> callBack) {  
31 - DiscoveryManager manager = new DiscoveryManager();  
32 - manager.setDiscoveryTimeout(timeout);  
33 - Map<String, Device> deviceMap = new HashMap<>();  
34 - // 搜索设备  
35 - manager.discover(new DiscoveryListener() {  
36 - @Override  
37 - public void onDiscoveryStarted() {  
38 - logger.info("Discovery started");  
39 - }  
40 -  
41 - @Override  
42 - public void onDevicesFound(List<Device> devices) {  
43 - if (devices == null || devices.size() == 0) return;  
44 - for (Device device : devices){  
45 - logger.info(device.getHostName());  
46 - deviceMap.put(device.getHostName(), device);  
47 - }  
48 - }  
49 -  
50 - // 搜索结束  
51 - @Override  
52 - public void onDiscoveryFinished() {  
53 - ArrayList<String> result = new ArrayList<>();  
54 - for (Device device : deviceMap.values()) {  
55 - logger.info(device.getHostName());  
56 - result.add(device.getHostName());  
57 - }  
58 - callBack.run(0, result);  
59 - }  
60 - });  
61 - }  
62 -  
63 - @Override  
64 - public void getRTSPUrl(int timeout, OnvifDevice device, ONVIFCallBack<String> callBack) {  
65 - if (device.getHostName() == null ){  
66 - callBack.run(400, null);  
67 - }  
68 - OnvifManager onvifManager = new OnvifManager();  
69 - onvifManager.setOnvifResponseListener(new OnvifResponseListener(){  
70 -  
71 - @Override  
72 - public void onResponse(OnvifDevice onvifDevice, OnvifResponse response) {  
73 - logger.info("[RESPONSE] " + onvifDevice.getHostName()  
74 - + "======" + response.getErrorCode()  
75 - + "======" + response.getErrorMessage());  
76 - }  
77 -  
78 - @Override  
79 - public void onError(OnvifDevice onvifDevice, int errorCode, String errorMessage) {  
80 - logger.info("[ERROR] " + onvifDevice.getHostName() + "======" + errorCode + "=======" + errorMessage);  
81 - callBack.run(errorCode, errorMessage);  
82 - }  
83 - });  
84 -  
85 - try {  
86 - onvifManager.getServices(device, (OnvifDevice onvifDevice, OnvifServices services) -> {  
87 - if (services.getProfilesPath().equals("/onvif/Media")) {  
88 - onvifDevice.setPath(services);  
89 - onvifManager.getMediaProfiles(onvifDevice, new OnvifMediaProfilesListener() {  
90 - @Override  
91 - public void onMediaProfilesReceived(OnvifDevice device, List<OnvifMediaProfile> mediaProfiles) {  
92 - for (OnvifMediaProfile mediaProfile : mediaProfiles) {  
93 - logger.info(mediaProfile.getName());  
94 - logger.info(mediaProfile.getToken());  
95 - if (mediaProfile.getName().equals("mainStream")) {  
96 - onvifManager.getMediaStreamURI(device, mediaProfile, (OnvifDevice onvifDevice,  
97 - OnvifMediaProfile profile, String uri) -> {  
98 -  
99 - uri = uri.replace("rtsp://", "rtsp://"+ device.getUsername() + ":"+ device.getPassword() + "@");  
100 - logger.info(onvifDevice.getHostName() + "的地址" + uri);  
101 - callBack.run(0, uri);  
102 - });  
103 - }  
104 - }  
105 - }  
106 - });  
107 - }  
108 - });  
109 - }catch (Exception e) {  
110 - callBack.run(400, e.getMessage());  
111 - }  
112 -  
113 -  
114 - }  
115 -}  
src/main/java/com/genersoft/iot/vmp/vmanager/onvif/ONVIFController.java deleted 100644 → 0
1 -package com.genersoft.iot.vmp.vmanager.onvif;  
2 -  
3 -import be.teletask.onvif.models.OnvifDevice;  
4 -import com.genersoft.iot.vmp.gb28181.transmit.callback.DeferredResultHolder;  
5 -import com.genersoft.iot.vmp.gb28181.transmit.callback.RequestMessage;  
6 -import com.genersoft.iot.vmp.onvif.IONVIFServer;  
7 -import com.genersoft.iot.vmp.vmanager.bean.WVPResult;  
8 -import io.swagger.annotations.Api;  
9 -import io.swagger.annotations.ApiImplicitParam;  
10 -import io.swagger.annotations.ApiImplicitParams;  
11 -import io.swagger.annotations.ApiOperation;  
12 -import org.springframework.beans.factory.annotation.Autowired;  
13 -import org.springframework.http.ResponseEntity;  
14 -import org.springframework.web.bind.annotation.*;  
15 -import org.springframework.web.context.request.async.DeferredResult;  
16 -  
17 -import java.util.List;  
18 -import java.util.UUID;  
19 -  
20 -@SuppressWarnings(value = {"rawtypes", "unchecked"})  
21 -@Api(tags = "onvif设备")  
22 -@CrossOrigin  
23 -@RestController  
24 -@RequestMapping("/api/onvif")  
25 -public class ONVIFController {  
26 -  
27 -  
28 - @Autowired  
29 - private DeferredResultHolder resultHolder;  
30 -  
31 - @Autowired  
32 - private IONVIFServer onvifServer;  
33 -  
34 -  
35 - @ApiOperation("搜索")  
36 - @ApiImplicitParams({  
37 - @ApiImplicitParam(name="timeout", value = "超时时间", required = true, dataTypeClass = Integer.class),  
38 - })  
39 - @GetMapping(value = "/search")  
40 - @ResponseBody  
41 - public DeferredResult<ResponseEntity<WVPResult>> search(@RequestParam(required = false)Integer timeout){  
42 - DeferredResult<ResponseEntity<WVPResult>> result = new DeferredResult<>(timeout + 10L);  
43 - String uuid = UUID.randomUUID().toString();  
44 - result.onTimeout(()->{  
45 - RequestMessage msg = new RequestMessage();  
46 - msg.setKey(DeferredResultHolder.CALLBACK_ONVIF );  
47 - msg.setId(uuid);  
48 - WVPResult<String> wvpResult = new WVPResult();  
49 - wvpResult.setCode(0);  
50 - wvpResult.setMsg("搜索超时");  
51 - msg.setData(wvpResult);  
52 - resultHolder.invokeResult(msg);  
53 - });  
54 - resultHolder.put(DeferredResultHolder.CALLBACK_ONVIF, uuid, result);  
55 -  
56 - onvifServer.search(timeout, (errorCode, onvifDevices) ->{  
57 - RequestMessage msg = new RequestMessage();  
58 - msg.setId(DeferredResultHolder.CALLBACK_ONVIF + uuid);  
59 - WVPResult<List<String>> resultData = new WVPResult();  
60 - resultData.setCode(errorCode);  
61 - if (errorCode == 0) {  
62 - resultData.setMsg("success");  
63 - resultData.setData(onvifDevices);  
64 - }else {  
65 - resultData.setMsg("fail");  
66 - }  
67 - msg.setData(resultData);  
68 - msg.setData(resultData);  
69 - resultHolder.invokeResult(msg);  
70 - });  
71 -  
72 - return result;  
73 - }  
74 -  
75 - @ApiOperation("获取onvif的rtsp地址")  
76 - @ApiImplicitParams({  
77 - @ApiImplicitParam(name="timeout", value = "超时时间", required = true, dataTypeClass = Integer.class),  
78 - @ApiImplicitParam(name="hostname", value = "onvif地址", required = true, dataTypeClass = String.class),  
79 - @ApiImplicitParam(name="username", value = "用户名", required = true, dataTypeClass = String.class),  
80 - @ApiImplicitParam(name="password", value = "密码", required = true, dataTypeClass = String.class),  
81 - })  
82 - @GetMapping(value = "/rtsp")  
83 - @ResponseBody  
84 - public DeferredResult<ResponseEntity<WVPResult>> getRTSPUrl(@RequestParam(value="timeout", required=false, defaultValue="3000") Integer timeout,  
85 - @RequestParam(required = true) String hostname,  
86 - @RequestParam(required = false) String username,  
87 - @RequestParam(required = false) String password  
88 - ){  
89 -  
90 - DeferredResult<ResponseEntity<WVPResult>> result = new DeferredResult<>(timeout + 10L);  
91 - String uuid = UUID.randomUUID().toString();  
92 - result.onTimeout(()->{  
93 - RequestMessage msg = new RequestMessage();  
94 - msg.setId(uuid);  
95 - msg.setKey(DeferredResultHolder.CALLBACK_ONVIF);  
96 - WVPResult<String> wvpResult = new WVPResult();  
97 - wvpResult.setCode(0);  
98 - wvpResult.setMsg("获取onvif的rtsp地址超时");  
99 - msg.setData(wvpResult);  
100 - resultHolder.invokeResult(msg);  
101 - });  
102 - resultHolder.put(DeferredResultHolder.CALLBACK_ONVIF, uuid, result);  
103 - OnvifDevice onvifDevice = new OnvifDevice(hostname, username, password);  
104 - onvifServer.getRTSPUrl(timeout, onvifDevice, (errorCode, url) ->{  
105 - RequestMessage msg = new RequestMessage();  
106 - msg.setId(DeferredResultHolder.CALLBACK_ONVIF + uuid);  
107 - WVPResult<String> resultData = new WVPResult();  
108 - resultData.setCode(errorCode);  
109 - if (errorCode == 0) {  
110 - resultData.setMsg("success");  
111 - resultData.setData(url);  
112 - }else {  
113 - resultData.setMsg(url);  
114 - }  
115 - msg.setData(resultData);  
116 -  
117 - resultHolder.invokeResult(msg);  
118 - });  
119 -  
120 - return result;  
121 - }  
122 -  
123 -}  
src/main/resources/all-application.yml
@@ -137,6 +137,8 @@ logging: @@ -137,6 +137,8 @@ logging:
137 com.genersoft.iot.vmp.gb28181: info 137 com.genersoft.iot.vmp.gb28181: info
138 # [根据业务需求配置] 138 # [根据业务需求配置]
139 user-settings: 139 user-settings:
  140 + # [可选] 服务ID,不写则为000000
  141 + server-id:
140 # [可选] 自动点播, 使用固定流地址进行播放时,如果未点播则自动进行点播, 需要rtp.enable=true 142 # [可选] 自动点播, 使用固定流地址进行播放时,如果未点播则自动进行点播, 需要rtp.enable=true
141 auto-apply-play: false 143 auto-apply-play: false
142 # [可选] 部分设备需要扩展SDP,需要打开此设置 144 # [可选] 部分设备需要扩展SDP,需要打开此设置