添加云端录像功能
This commit is contained in:
@@ -1,54 +1,54 @@
|
||||
package com.genersoft.iot.vmp.media.zlm;
|
||||
|
||||
import com.genersoft.iot.vmp.conf.MediaConfig;
|
||||
import com.genersoft.iot.vmp.storager.IRedisCatchStorage;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.client.HttpClientErrorException;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/zlm")
|
||||
public class ZLMHTTPProxyController {
|
||||
|
||||
|
||||
// private final static Logger logger = LoggerFactory.getLogger(ZLMHTTPProxyController.class);
|
||||
|
||||
@Autowired
|
||||
private IRedisCatchStorage redisCatchStorage;
|
||||
|
||||
@Autowired
|
||||
private MediaConfig mediaConfig;
|
||||
|
||||
@ResponseBody
|
||||
@RequestMapping(value = "/**/**/**", produces = "application/json;charset=UTF-8")
|
||||
public Object proxy(HttpServletRequest request, HttpServletResponse response){
|
||||
|
||||
if (redisCatchStorage.getMediaInfo() == null) {
|
||||
return "未接入流媒体";
|
||||
}
|
||||
ZLMServerConfig mediaInfo = redisCatchStorage.getMediaInfo();
|
||||
String requestURI = String.format("http://%s:%s%s?%s&%s",
|
||||
mediaInfo.getLocalIP(),
|
||||
mediaConfig.getHttpPort(),
|
||||
request.getRequestURI().replace("/zlm",""),
|
||||
mediaInfo.getHookAdminParams(),
|
||||
request.getQueryString()
|
||||
);
|
||||
// 发送请求
|
||||
RestTemplate restTemplate = new RestTemplate();
|
||||
//将指定的url返回的参数自动封装到自定义好的对应类对象中
|
||||
Object result = null;
|
||||
try {
|
||||
result = restTemplate.getForObject(requestURI,Object.class);
|
||||
|
||||
}catch (HttpClientErrorException httpClientErrorException) {
|
||||
response.setStatus(httpClientErrorException.getStatusCode().value());
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
//package com.genersoft.iot.vmp.media.zlm;
|
||||
//
|
||||
//import com.genersoft.iot.vmp.conf.MediaConfig;
|
||||
//import com.genersoft.iot.vmp.storager.IRedisCatchStorage;
|
||||
//import org.springframework.beans.factory.annotation.Autowired;
|
||||
//import org.springframework.beans.factory.annotation.Value;
|
||||
//import org.springframework.web.bind.annotation.*;
|
||||
//import org.springframework.web.client.HttpClientErrorException;
|
||||
//import org.springframework.web.client.RestTemplate;
|
||||
//
|
||||
//import javax.servlet.http.HttpServletRequest;
|
||||
//import javax.servlet.http.HttpServletResponse;
|
||||
//
|
||||
//@RestController
|
||||
//@RequestMapping("/zlm")
|
||||
//public class ZLMHTTPProxyController {
|
||||
//
|
||||
//
|
||||
// // private final static Logger logger = LoggerFactory.getLogger(ZLMHTTPProxyController.class);
|
||||
//
|
||||
// @Autowired
|
||||
// private IRedisCatchStorage redisCatchStorage;
|
||||
//
|
||||
// @Autowired
|
||||
// private MediaConfig mediaConfig;
|
||||
//
|
||||
// @ResponseBody
|
||||
// @RequestMapping(value = "/**/**/**", produces = "application/json;charset=UTF-8")
|
||||
// public Object proxy(HttpServletRequest request, HttpServletResponse response){
|
||||
//
|
||||
// if (redisCatchStorage.getMediaInfo() == null) {
|
||||
// return "未接入流媒体";
|
||||
// }
|
||||
// ZLMServerConfig mediaInfo = redisCatchStorage.getMediaInfo();
|
||||
// String requestURI = String.format("http://%s:%s%s?%s&%s",
|
||||
// mediaInfo.getLocalIP(),
|
||||
// mediaConfig.getHttpPort(),
|
||||
// request.getRequestURI().replace("/zlm",""),
|
||||
// mediaInfo.getHookAdminParams(),
|
||||
// request.getQueryString()
|
||||
// );
|
||||
// // 发送请求
|
||||
// RestTemplate restTemplate = new RestTemplate();
|
||||
// //将指定的url返回的参数自动封装到自定义好的对应类对象中
|
||||
// Object result = null;
|
||||
// try {
|
||||
// result = restTemplate.getForObject(requestURI,Object.class);
|
||||
//
|
||||
// }catch (HttpClientErrorException httpClientErrorException) {
|
||||
// response.setStatus(httpClientErrorException.getStatusCode().value());
|
||||
// }
|
||||
// return result;
|
||||
// }
|
||||
//}
|
||||
|
||||
@@ -7,6 +7,7 @@ import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.genersoft.iot.vmp.common.StreamInfo;
|
||||
import com.genersoft.iot.vmp.conf.MediaConfig;
|
||||
import com.genersoft.iot.vmp.conf.UserSetup;
|
||||
import com.genersoft.iot.vmp.gb28181.bean.Device;
|
||||
import com.genersoft.iot.vmp.storager.IRedisCatchStorage;
|
||||
import com.genersoft.iot.vmp.storager.IVideoManagerStorager;
|
||||
@@ -62,8 +63,8 @@ public class ZLMHttpHookListener {
|
||||
@Autowired
|
||||
private ZLMHttpHookSubscribe subscribe;
|
||||
|
||||
@Value("${userSettings.autoApplyPlay}")
|
||||
private boolean autoApplyPlay;
|
||||
@Autowired
|
||||
private UserSetup userSetup;
|
||||
|
||||
@Autowired
|
||||
private MediaConfig mediaConfig;
|
||||
@@ -132,10 +133,8 @@ public class ZLMHttpHookListener {
|
||||
@ResponseBody
|
||||
@PostMapping(value = "/on_publish", produces = "application/json;charset=UTF-8")
|
||||
public ResponseEntity<String> onPublish(@RequestBody JSONObject json){
|
||||
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("ZLM HOOK on_publish API调用,参数:" + json.toString());
|
||||
}
|
||||
|
||||
logger.debug("ZLM HOOK on_publish API调用,参数:" + json.toString());
|
||||
|
||||
ZLMHttpHookSubscribe.Event subscribe = this.subscribe.getSubscribe(ZLMHttpHookSubscribe.HookType.on_publish, json);
|
||||
if (subscribe != null) subscribe.response(json);
|
||||
@@ -144,7 +143,7 @@ public class ZLMHttpHookListener {
|
||||
ret.put("code", 0);
|
||||
ret.put("msg", "success");
|
||||
ret.put("enableHls", true);
|
||||
ret.put("enableMP4", false);
|
||||
ret.put("enableMP4", userSetup.isRecordPushLive());
|
||||
ret.put("enableRtxp", true);
|
||||
return new ResponseEntity<String>(ret.toString(),HttpStatus.OK);
|
||||
}
|
||||
@@ -333,7 +332,7 @@ public class ZLMHttpHookListener {
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("ZLM HOOK on_stream_not_found API调用,参数:" + json.toString());
|
||||
}
|
||||
if (autoApplyPlay) {
|
||||
if (userSetup.isAutoApplyPlay()) {
|
||||
String app = json.getString("app");
|
||||
String streamId = json.getString("stream");
|
||||
StreamInfo streamInfo = redisCatchStorage.queryPlayByStreamId(streamId);
|
||||
|
||||
@@ -109,6 +109,10 @@ public class ZLMRunner implements CommandLineRunner {
|
||||
if (StringUtils.isEmpty(mediaConfig.getHookIp())) mediaConfig.setHookIp(sipConfig.getSipIp());
|
||||
String protocol = sslEnabled ? "https" : "http";
|
||||
String hookPrex = String.format("%s://%s:%s/index/hook", protocol, mediaConfig.getHookIp(), serverPort);
|
||||
String recordHookPrex = null;
|
||||
if (mediaConfig.getRecordAssistPort() != 0) {
|
||||
recordHookPrex = String.format("http://127.0.0.1:%s/api/record", mediaConfig.getRecordAssistPort());
|
||||
}
|
||||
Map<String, Object> param = new HashMap<>();
|
||||
param.put("api.secret",mediaConfig.getSecret()); // -profile:v Baseline
|
||||
param.put("ffmpeg.cmd","%s -fflags nobuffer -rtsp_transport tcp -i %s -c:a aac -strict -2 -ar 44100 -ab 48k -c:v libx264 -f flv %s");
|
||||
@@ -116,8 +120,8 @@ public class ZLMRunner implements CommandLineRunner {
|
||||
param.put("hook.on_flow_report","");
|
||||
param.put("hook.on_play",String.format("%s/on_play", hookPrex));
|
||||
param.put("hook.on_http_access","");
|
||||
param.put("hook.on_publish",String.format("%s/on_publish", hookPrex));
|
||||
param.put("hook.on_record_mp4","");
|
||||
param.put("hook.on_publish", String.format("%s/on_publish", hookPrex));
|
||||
param.put("hook.on_record_mp4",recordHookPrex != null? String.format("%s/on_record_mp4", recordHookPrex): "");
|
||||
param.put("hook.on_record_ts","");
|
||||
param.put("hook.on_rtsp_auth","");
|
||||
param.put("hook.on_rtsp_realm","");
|
||||
|
||||
Reference in New Issue
Block a user