获取rtcconfig,

湖北-大华摄像头
LAPTOP-S9HJSOEB\昊天 12 months ago
parent a4d385c98b
commit 05fd3784f4

@ -0,0 +1 @@
{"server":{"ice_credential":"","ice_servers":["stun:stun.l.google.com:19302"],"ice_username":"","http_port":":8083"},"streams":{"camera15":{"disable_audio":true,"url":"rtsp://admin:a1234567@192.168.2.64:8000/Streaming/Channels/1","on_demand":true},"camera14":{"disable_audio":true,"url":"rtsp://admin:a1234567@192.168.2.64:8000/Streaming/Channels/1","on_demand":true}}}

@ -18,6 +18,11 @@
</properties>
<dependencies>
<dependency>
<groupId>com.microsoft.onnxruntime</groupId>
<artifactId>onnxruntime</artifactId>
<version>1.17.0</version> <!-- 根据最新版本替换 -->
</dependency>
<dependency>
<groupId>org.dromara.easyai</groupId>
<artifactId>easyAi</artifactId>

@ -194,4 +194,30 @@ public class CameraController {
}
return Result.success();
}
@GetMapping("/rtcConfig")
@ApiOperation(value = "获取rtcConfig")
public Result<String> rtcConfig(String rtcServer) {
List<Camera> cameraList = cameraService.getCamerasByRtcServer(rtcServer);
JSONObject jsonObject = new JSONObject();
JSONObject server = new JSONObject();
server.put("http_port",":8083");
String [] strings = new String[1];
strings[0] = "stun:stun.l.google.com:19302";
server.put("ice_servers",strings);
server.put("ice_username","");
server.put("ice_credential","");
jsonObject.put("server",server);
JSONObject streams = new JSONObject();
cameraList.forEach(camera -> {
JSONObject obj = new JSONObject();
obj.put("on_demand",false);
obj.put("disable_audio",true);
obj.put("url",camera.getRtsp());
streams.put("camera"+camera.getId(),obj);
});
jsonObject.put("streams",streams);
return Result.success(jsonObject.toJSONString());
}
}

@ -23,6 +23,7 @@ import com.zhehekeji.web.mapper.StreetMapper;
import com.zhehekeji.web.pojo.camera.CameraConfigSearchReq;
import com.zhehekeji.web.pojo.camera.IOImport;
import com.zhehekeji.web.pojo.street.StreetSearch;
import com.zhehekeji.web.util.RtspUrlGenerator;
import io.swagger.models.auth.In;
import lombok.extern.slf4j.Slf4j;
import org.apache.logging.log4j.util.Strings;
@ -70,12 +71,21 @@ public class CameraService {
this.cameraControlLoginModule = cameraControlLoginModule;
}
public List<Camera> getCamerasByRtcServer(String rtcServer){
if(StringUtils.isEmpty(rtcServer)){
rtcServer = "127.0.0.1";
}
return cameraMapper.selectList(new QueryWrapper<Camera>().eq("rtc_server",rtcServer));
}
public Integer add(Camera camera) {
ConfigProperties.CameraConfig cameraConfig = configProperties.getCameraConfig();
camera.setUser(configProperties.getCameraConfig().getCameraUser());
camera.setPassword(configProperties.getCameraConfig().getCameraPassword());
camera.setPort(configProperties.getCameraConfig().getCameraPort());
camera.setUpdateTime(LocalDateTime.now());
camera.setRtsp("rtsp://"+configProperties.getCameraConfig().getCameraUser()+":"+configProperties.getCameraConfig().getCameraPassword()+"@"+camera.getIp()+":554/h264/ch1/sub/av_stream");
camera.setRtsp(RtspUrlGenerator.getRtsp(cameraConfig.getCameraType(),camera.getIp(),camera.getPort(),cameraConfig.getCameraUser(),cameraConfig.getCameraPassword(),camera.getChannel()));
if(StringUtils.isEmpty(camera.getRtcServer())){
camera.setRtcServer("127.0.0.1");
}
@ -90,6 +100,7 @@ public class CameraService {
}
public void edit(Camera camera) {
ConfigProperties.CameraConfig cameraConfig = configProperties.getCameraConfig();
camera.setUpdateTime(LocalDateTime.now());
camera.setPtzId(null);
if(StringUtils.isEmpty(camera.getRtcServer())){
@ -97,7 +108,7 @@ public class CameraService {
}
camera.setPort(configProperties.getCameraConfig().getCameraPort());
camera.setUser(configProperties.getCameraConfig().getCameraUser());
camera.setRtsp("rtsp://"+configProperties.getCameraConfig().getCameraUser()+":"+configProperties.getCameraConfig().getCameraPassword()+"@"+camera.getIp()+":554/h264/ch1/sub/av_stream");
camera.setRtsp(RtspUrlGenerator.getRtsp(cameraConfig.getCameraType(),camera.getIp(),camera.getPort(),cameraConfig.getCameraUser(),cameraConfig.getCameraPassword(),camera.getChannel()));
try {
cameraMapper.updateById(camera);
} catch (DuplicateKeyException e) {

@ -111,7 +111,7 @@ public class CronTab {
}
}
@Scheduled(cron = "${cameraConfig.cameraTimeUpdateCron}")
// @Scheduled(cron = "${cameraConfig.cameraTimeUpdateCron}")
public void cameraTimeUpdate() {
log.info(" cameraTimeUpdate");
long timeStamp = System.currentTimeMillis();

@ -0,0 +1,30 @@
package com.zhehekeji.web.util;
import java.util.Scanner;
public class RtspUrlGenerator {
// 海康的RTSP URL格式
private static String generateHikvisionRtspUrl(String ip, Integer port, String username, String password, String channel) {
return String.format("rtsp://%s:%s@%s:%s/Streaming/Channels/%s", username, password, ip, 554, channel);
}
// 大华的RTSP URL格式
private static String generateDahuaRtspUrl(String ip, Integer port, String username, String password, String channel) {
return String.format("rtsp://%s:%s@%s:%s/cam/realmonitor?channel=%s&subtype=0", username, password, ip, 554, channel);
}
public static String getRtsp(Integer choice,String ip, Integer port, String username, String password, String channel){
String rtspUrl = "";
if (choice == 1) {
rtspUrl = generateHikvisionRtspUrl(ip, port, username, password, channel);
} else if (choice == 2) {
rtspUrl = generateDahuaRtspUrl(ip, port, username, password, channel);
} else {
System.out.println("");
}
return rtspUrl;
}
}

@ -26,7 +26,7 @@ userUrl: http://115.236.65.98:11001
# -----------
# ----默认摄像头的连接信息
cameraConfig:
# ------------球機選擇--- 0:利珀 1海康
# ------------球機選擇--- 0:利珀 1海康 2:大华
cameraType: 1
cameraPassword: a1234567
cameraUser: admin

Loading…
Cancel
Save