Browse Source

移除onvif实现

pull/249/head
648540858 3 years ago
parent
commit
6282c81bc5
  1. BIN
      libs/onvif-java-1.0.2.jar
  2. 11
      pom.xml
  3. 13
      src/main/java/com/genersoft/iot/vmp/onvif/IONVIFServer.java
  4. 5
      src/main/java/com/genersoft/iot/vmp/onvif/dto/ONVIFCallBack.java
  5. 115
      src/main/java/com/genersoft/iot/vmp/onvif/impl/ONVIFServerIMpl.java
  6. 123
      src/main/java/com/genersoft/iot/vmp/vmanager/onvif/ONVIFController.java
  7. 2
      src/main/resources/all-application.yml

BIN
libs/onvif-java-1.0.2.jar

Binary file not shown.

11
pom.xml

@ -212,17 +212,6 @@
<!-- <version>1.0.8</version>--> <!-- <version>1.0.8</version>-->
<!-- </dependency>--> <!-- </dependency>-->
<!-- onvif协议栈 -->
<dependency>
<groupId>be.teletask</groupId>
<artifactId>onvif-java</artifactId>
<version>1.0.2</version>
<scope>system</scope>
<systemPath>${project.basedir}/libs/onvif-java-1.0.2.jar</systemPath>
</dependency>
<dependency> <dependency>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId> <artifactId>spring-boot-starter-test</artifactId>

13
src/main/java/com/genersoft/iot/vmp/onvif/IONVIFServer.java

@ -1,13 +0,0 @@
package com.genersoft.iot.vmp.onvif;
import be.teletask.onvif.models.OnvifDevice;
import com.genersoft.iot.vmp.onvif.dto.ONVIFCallBack;
import java.util.List;
public interface IONVIFServer {
void search(int timeout, ONVIFCallBack<List<String>> callBack);
void getRTSPUrl(int timeout, OnvifDevice device, ONVIFCallBack<String> callBack);
}

5
src/main/java/com/genersoft/iot/vmp/onvif/dto/ONVIFCallBack.java

@ -1,5 +0,0 @@
package com.genersoft.iot.vmp.onvif.dto;
public interface ONVIFCallBack<T> {
void run(int errorCode, T t);
}

115
src/main/java/com/genersoft/iot/vmp/onvif/impl/ONVIFServerIMpl.java

@ -1,115 +0,0 @@
package com.genersoft.iot.vmp.onvif.impl;
import be.teletask.onvif.DiscoveryManager;
import be.teletask.onvif.OnvifManager;
import be.teletask.onvif.listeners.*;
import be.teletask.onvif.models.*;
import be.teletask.onvif.responses.OnvifResponse;
import com.genersoft.iot.vmp.onvif.IONVIFServer;
import com.genersoft.iot.vmp.onvif.dto.ONVIFCallBack;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@SuppressWarnings("rawtypes")
/**
* 处理onvif的各种操作
*/
@Service
public class ONVIFServerIMpl implements IONVIFServer {
private final static Logger logger = LoggerFactory.getLogger(ONVIFServerIMpl.class);
@Override
public void search(int timeout, ONVIFCallBack<List<String>> callBack) {
DiscoveryManager manager = new DiscoveryManager();
manager.setDiscoveryTimeout(timeout);
Map<String, Device> deviceMap = new HashMap<>();
// 搜索设备
manager.discover(new DiscoveryListener() {
@Override
public void onDiscoveryStarted() {
logger.info("Discovery started");
}
@Override
public void onDevicesFound(List<Device> devices) {
if (devices == null || devices.size() == 0) return;
for (Device device : devices){
logger.info(device.getHostName());
deviceMap.put(device.getHostName(), device);
}
}
// 搜索结束
@Override
public void onDiscoveryFinished() {
ArrayList<String> result = new ArrayList<>();
for (Device device : deviceMap.values()) {
logger.info(device.getHostName());
result.add(device.getHostName());
}
callBack.run(0, result);
}
});
}
@Override
public void getRTSPUrl(int timeout, OnvifDevice device, ONVIFCallBack<String> callBack) {
if (device.getHostName() == null ){
callBack.run(400, null);
}
OnvifManager onvifManager = new OnvifManager();
onvifManager.setOnvifResponseListener(new OnvifResponseListener(){
@Override
public void onResponse(OnvifDevice onvifDevice, OnvifResponse response) {
logger.info("[RESPONSE] " + onvifDevice.getHostName()
+ "======" + response.getErrorCode()
+ "======" + response.getErrorMessage());
}
@Override
public void onError(OnvifDevice onvifDevice, int errorCode, String errorMessage) {
logger.info("[ERROR] " + onvifDevice.getHostName() + "======" + errorCode + "=======" + errorMessage);
callBack.run(errorCode, errorMessage);
}
});
try {
onvifManager.getServices(device, (OnvifDevice onvifDevice, OnvifServices services) -> {
if (services.getProfilesPath().equals("/onvif/Media")) {
onvifDevice.setPath(services);
onvifManager.getMediaProfiles(onvifDevice, new OnvifMediaProfilesListener() {
@Override
public void onMediaProfilesReceived(OnvifDevice device, List<OnvifMediaProfile> mediaProfiles) {
for (OnvifMediaProfile mediaProfile : mediaProfiles) {
logger.info(mediaProfile.getName());
logger.info(mediaProfile.getToken());
if (mediaProfile.getName().equals("mainStream")) {
onvifManager.getMediaStreamURI(device, mediaProfile, (OnvifDevice onvifDevice,
OnvifMediaProfile profile, String uri) -> {
uri = uri.replace("rtsp://", "rtsp://"+ device.getUsername() + ":"+ device.getPassword() + "@");
logger.info(onvifDevice.getHostName() + "的地址" + uri);
callBack.run(0, uri);
});
}
}
}
});
}
});
}catch (Exception e) {
callBack.run(400, e.getMessage());
}
}
}

123
src/main/java/com/genersoft/iot/vmp/vmanager/onvif/ONVIFController.java

@ -1,123 +0,0 @@
package com.genersoft.iot.vmp.vmanager.onvif;
import be.teletask.onvif.models.OnvifDevice;
import com.genersoft.iot.vmp.gb28181.transmit.callback.DeferredResultHolder;
import com.genersoft.iot.vmp.gb28181.transmit.callback.RequestMessage;
import com.genersoft.iot.vmp.onvif.IONVIFServer;
import com.genersoft.iot.vmp.vmanager.bean.WVPResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.context.request.async.DeferredResult;
import java.util.List;
import java.util.UUID;
@SuppressWarnings(value = {"rawtypes", "unchecked"})
@Api(tags = "onvif设备")
@CrossOrigin
@RestController
@RequestMapping("/api/onvif")
public class ONVIFController {
@Autowired
private DeferredResultHolder resultHolder;
@Autowired
private IONVIFServer onvifServer;
@ApiOperation("搜索")
@ApiImplicitParams({
@ApiImplicitParam(name="timeout", value = "超时时间", required = true, dataTypeClass = Integer.class),
})
@GetMapping(value = "/search")
@ResponseBody
public DeferredResult<ResponseEntity<WVPResult>> search(@RequestParam(required = false)Integer timeout){
DeferredResult<ResponseEntity<WVPResult>> result = new DeferredResult<>(timeout + 10L);
String uuid = UUID.randomUUID().toString();
result.onTimeout(()->{
RequestMessage msg = new RequestMessage();
msg.setKey(DeferredResultHolder.CALLBACK_ONVIF );
msg.setId(uuid);
WVPResult<String> wvpResult = new WVPResult();
wvpResult.setCode(0);
wvpResult.setMsg("搜索超时");
msg.setData(wvpResult);
resultHolder.invokeResult(msg);
});
resultHolder.put(DeferredResultHolder.CALLBACK_ONVIF, uuid, result);
onvifServer.search(timeout, (errorCode, onvifDevices) ->{
RequestMessage msg = new RequestMessage();
msg.setId(DeferredResultHolder.CALLBACK_ONVIF + uuid);
WVPResult<List<String>> resultData = new WVPResult();
resultData.setCode(errorCode);
if (errorCode == 0) {
resultData.setMsg("success");
resultData.setData(onvifDevices);
}else {
resultData.setMsg("fail");
}
msg.setData(resultData);
msg.setData(resultData);
resultHolder.invokeResult(msg);
});
return result;
}
@ApiOperation("获取onvif的rtsp地址")
@ApiImplicitParams({
@ApiImplicitParam(name="timeout", value = "超时时间", required = true, dataTypeClass = Integer.class),
@ApiImplicitParam(name="hostname", value = "onvif地址", required = true, dataTypeClass = String.class),
@ApiImplicitParam(name="username", value = "用户名", required = true, dataTypeClass = String.class),
@ApiImplicitParam(name="password", value = "密码", required = true, dataTypeClass = String.class),
})
@GetMapping(value = "/rtsp")
@ResponseBody
public DeferredResult<ResponseEntity<WVPResult>> getRTSPUrl(@RequestParam(value="timeout", required=false, defaultValue="3000") Integer timeout,
@RequestParam(required = true) String hostname,
@RequestParam(required = false) String username,
@RequestParam(required = false) String password
){
DeferredResult<ResponseEntity<WVPResult>> result = new DeferredResult<>(timeout + 10L);
String uuid = UUID.randomUUID().toString();
result.onTimeout(()->{
RequestMessage msg = new RequestMessage();
msg.setId(uuid);
msg.setKey(DeferredResultHolder.CALLBACK_ONVIF);
WVPResult<String> wvpResult = new WVPResult();
wvpResult.setCode(0);
wvpResult.setMsg("获取onvif的rtsp地址超时");
msg.setData(wvpResult);
resultHolder.invokeResult(msg);
});
resultHolder.put(DeferredResultHolder.CALLBACK_ONVIF, uuid, result);
OnvifDevice onvifDevice = new OnvifDevice(hostname, username, password);
onvifServer.getRTSPUrl(timeout, onvifDevice, (errorCode, url) ->{
RequestMessage msg = new RequestMessage();
msg.setId(DeferredResultHolder.CALLBACK_ONVIF + uuid);
WVPResult<String> resultData = new WVPResult();
resultData.setCode(errorCode);
if (errorCode == 0) {
resultData.setMsg("success");
resultData.setData(url);
}else {
resultData.setMsg(url);
}
msg.setData(resultData);
resultHolder.invokeResult(msg);
});
return result;
}
}

2
src/main/resources/all-application.yml

@ -137,6 +137,8 @@ logging:
com.genersoft.iot.vmp.gb28181: info com.genersoft.iot.vmp.gb28181: info
# [根据业务需求配置] # [根据业务需求配置]
user-settings: user-settings:
# [可选] 服务ID,不写则为000000
server-id:
# [可选] 自动点播, 使用固定流地址进行播放时,如果未点播则自动进行点播, 需要rtp.enable=true # [可选] 自动点播, 使用固定流地址进行播放时,如果未点播则自动进行点播, 需要rtp.enable=true
auto-apply-play: false auto-apply-play: false
# [可选] 部分设备需要扩展SDP,需要打开此设置 # [可选] 部分设备需要扩展SDP,需要打开此设置

Loading…
Cancel
Save