|
|
@@ -10,6 +10,7 @@ import com.genersoft.iot.vmp.conf.exception.ControllerException;
|
|
|
import com.genersoft.iot.vmp.gb28181.event.EventPublisher;
|
|
|
import com.genersoft.iot.vmp.gb28181.event.subscribe.catalog.CatalogEvent;
|
|
|
import com.genersoft.iot.vmp.media.zlm.ZLMRESTfulUtils;
|
|
|
+import com.genersoft.iot.vmp.media.zlm.ZLMServerFactory;
|
|
|
import com.genersoft.iot.vmp.media.zlm.ZlmHttpHookSubscribe;
|
|
|
import com.genersoft.iot.vmp.media.zlm.dto.HookSubscribeFactory;
|
|
|
import com.genersoft.iot.vmp.media.zlm.dto.HookSubscribeForStreamChange;
|
|
|
@@ -61,6 +62,9 @@ public class StreamProxyServiceImpl implements IStreamProxyService {
|
|
|
@Autowired
|
|
|
private ZLMRESTfulUtils zlmresTfulUtils;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private ZLMServerFactory zlmServerFactory;
|
|
|
+
|
|
|
@Autowired
|
|
|
private StreamProxyMapper streamProxyMapper;
|
|
|
|
|
|
@@ -145,7 +149,7 @@ public class StreamProxyServiceImpl implements IStreamProxyService {
|
|
|
dstUrl = String.format("%s://%s:%s/%s/%s", schemaForUri, "127.0.0.1", port, param.getApp(),
|
|
|
param.getStream());
|
|
|
}else {
|
|
|
- dstUrl = String.format("rtmp://%s:%s/%s/%s", "127.0.0.1", mediaInfo.getRtmpPort(), param.getApp(),
|
|
|
+ dstUrl = String.format("rtsp://%s:%s/%s/%s", "127.0.0.1", mediaInfo.getRtspPort(), param.getApp(),
|
|
|
param.getStream());
|
|
|
}
|
|
|
param.setDstUrl(dstUrl);
|
|
|
@@ -170,12 +174,6 @@ public class StreamProxyServiceImpl implements IStreamProxyService {
|
|
|
});
|
|
|
if (param.isEnable()) {
|
|
|
String talkKey = UUID.randomUUID().toString();
|
|
|
-// dynamicTask.startCron(talkKey, ()->{
|
|
|
-// StreamInfo streamInfo = mediaService.getStreamInfoByAppAndStreamWithCheck(param.getApp(), param.getStream(), mediaInfo.getId(), false);
|
|
|
-// if (streamInfo != null) {
|
|
|
-// callback.run(ErrorCode.SUCCESS.getCode(), ErrorCode.SUCCESS.getMsg(), streamInfo);
|
|
|
-// }
|
|
|
-// }, 3000);
|
|
|
String delayTalkKey = UUID.randomUUID().toString();
|
|
|
dynamicTask.startDelay(delayTalkKey, ()->{
|
|
|
StreamInfo streamInfo = mediaService.getStreamInfoByAppAndStreamWithCheck(param.getApp(), param.getStream(), mediaInfo.getId(), false);
|
|
|
@@ -318,13 +316,32 @@ public class StreamProxyServiceImpl implements IStreamProxyService {
|
|
|
if (mediaServerItem == null) {
|
|
|
return null;
|
|
|
}
|
|
|
- if ("default".equals(param.getType())){
|
|
|
- result = zlmresTfulUtils.addStreamProxy(mediaServerItem, param.getApp(), param.getStream(), param.getUrl().trim(),
|
|
|
- param.isEnableAudio(), param.isEnableMp4(), param.getRtpType());
|
|
|
- }else if ("ffmpeg".equals(param.getType())) {
|
|
|
+ if (zlmServerFactory.isStreamReady(mediaServerItem, param.getApp(), param.getStream())) {
|
|
|
+ zlmresTfulUtils.closeStreams(mediaServerItem, param.getApp(), param.getStream());
|
|
|
+ }
|
|
|
+ if ("ffmpeg".equalsIgnoreCase(param.getType())){
|
|
|
result = zlmresTfulUtils.addFFmpegSource(mediaServerItem, param.getSrcUrl().trim(), param.getDstUrl(),
|
|
|
param.getTimeoutMs() + "", param.isEnableAudio(), param.isEnableMp4(),
|
|
|
param.getFfmpegCmdKey());
|
|
|
+ }else {
|
|
|
+ result = zlmresTfulUtils.addStreamProxy(mediaServerItem, param.getApp(), param.getStream(), param.getUrl().trim(),
|
|
|
+ param.isEnableAudio(), param.isEnableMp4(), param.getRtpType());
|
|
|
+ }
|
|
|
+ System.out.println("addStreamProxyToZlm====");
|
|
|
+ System.out.println(result);
|
|
|
+ if (result != null && result.getInteger("code") == 0) {
|
|
|
+ JSONObject data = result.getJSONObject("data");
|
|
|
+ if (data == null) {
|
|
|
+ logger.warn("[获取拉流代理的结果数据Data] 失败: {}", result );
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+ String key = data.getString("key");
|
|
|
+ if (key == null) {
|
|
|
+ logger.warn("[获取拉流代理的结果数据Data中的KEY] 失败: {}", result );
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+ param.setStreamKey(key);
|
|
|
+ streamProxyMapper.update(param);
|
|
|
}
|
|
|
return result;
|
|
|
}
|
|
|
@@ -335,7 +352,12 @@ public class StreamProxyServiceImpl implements IStreamProxyService {
|
|
|
return null;
|
|
|
}
|
|
|
MediaServerItem mediaServerItem = mediaServerService.getOne(param.getMediaServerId());
|
|
|
- JSONObject result = zlmresTfulUtils.closeStreams(mediaServerItem, param.getApp(), param.getStream());
|
|
|
+ JSONObject result = null;
|
|
|
+ if ("ffmpeg".equalsIgnoreCase(param.getType())){
|
|
|
+ result = zlmresTfulUtils.delFFmpegSource(mediaServerItem, param.getStreamKey());
|
|
|
+ }else {
|
|
|
+ result = zlmresTfulUtils.delStreamProxy(mediaServerItem, param.getStreamKey());
|
|
|
+ }
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
@@ -350,19 +372,18 @@ public class StreamProxyServiceImpl implements IStreamProxyService {
|
|
|
if (streamProxyItem != null) {
|
|
|
gbStreamService.sendCatalogMsg(streamProxyItem, CatalogEvent.DEL);
|
|
|
|
|
|
+ // 如果关联了国标那么移除关联
|
|
|
+ platformGbStreamMapper.delByAppAndStream(app, stream);
|
|
|
+ gbStreamMapper.del(app, stream);
|
|
|
+ videoManagerStorager.deleteStreamProxy(app, stream);
|
|
|
+ redisCatchStorage.removeStream(streamProxyItem.getMediaServerId(), "PULL", app, stream);
|
|
|
JSONObject jsonObject = removeStreamProxyFromZlm(streamProxyItem);
|
|
|
if (jsonObject != null && jsonObject.getInteger("code") == 0) {
|
|
|
- // 如果关联了国标那么移除关联
|
|
|
- int i = platformGbStreamMapper.delByAppAndStream(app, stream);
|
|
|
- gbStreamMapper.del(app, stream);
|
|
|
- System.out.println();
|
|
|
- // TODO 如果关联的推流, 那么状态设置为离线
|
|
|
+ logger.info("[移除代理]: 代理: {}/{}, 从zlm移除成功", app, stream);
|
|
|
+ }else {
|
|
|
+ logger.info("[移除代理]: 代理: {}/{}, 从zlm移除失败", app, stream);
|
|
|
}
|
|
|
- videoManagerStorager.deleteStreamProxy(app, stream);
|
|
|
- redisCatchStorage.removeStream(streamProxyItem.getMediaServerId(), "PULL", app, stream);
|
|
|
}
|
|
|
-
|
|
|
-
|
|
|
}
|
|
|
|
|
|
@Override
|