From 20dca0f6b664f6124e3492eee2e3ef6dfde80d88 Mon Sep 17 00:00:00 2001
From: panlinlin <648540858@qq.com>
Date: 星期五, 02 四月 2021 19:14:12 +0800
Subject: [PATCH] 增加推流转发到国标,尚不完善
---
src/main/java/com/genersoft/iot/vmp/vmanager/play/PlayController.java | 121 +++++++++++++++++++---------------------
1 files changed, 57 insertions(+), 64 deletions(-)
diff --git a/src/main/java/com/genersoft/iot/vmp/vmanager/play/PlayController.java b/src/main/java/com/genersoft/iot/vmp/vmanager/play/PlayController.java
index 08e5cc4..d104b85 100644
--- a/src/main/java/com/genersoft/iot/vmp/vmanager/play/PlayController.java
+++ b/src/main/java/com/genersoft/iot/vmp/vmanager/play/PlayController.java
@@ -1,13 +1,15 @@
package com.genersoft.iot.vmp.vmanager.play;
-import com.alibaba.fastjson.JSON;
import com.genersoft.iot.vmp.common.StreamInfo;
import com.genersoft.iot.vmp.conf.MediaServerConfig;
+import com.genersoft.iot.vmp.gb28181.bean.Device;
import com.genersoft.iot.vmp.gb28181.transmit.callback.DeferredResultHolder;
import com.genersoft.iot.vmp.gb28181.transmit.callback.RequestMessage;
import com.genersoft.iot.vmp.media.zlm.ZLMRESTfulUtils;
import com.genersoft.iot.vmp.storager.IRedisCatchStorage;
-import com.genersoft.iot.vmp.vmanager.service.IPlayService;
+import com.genersoft.iot.vmp.vmanager.play.bean.PlayResult;
+import com.genersoft.iot.vmp.service.IMediaService;
+import com.genersoft.iot.vmp.service.IPlayService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
@@ -21,13 +23,13 @@
import org.springframework.web.bind.annotation.RestController;
import com.alibaba.fastjson.JSONObject;
-import com.genersoft.iot.vmp.gb28181.bean.Device;
import com.genersoft.iot.vmp.gb28181.transmit.cmd.impl.SIPCommander;
import com.genersoft.iot.vmp.storager.IVideoManagerStorager;
import org.springframework.web.context.request.async.DeferredResult;
-import javax.sip.message.Response;
import java.util.UUID;
+
+import javax.sip.message.Response;
@CrossOrigin
@RestController
@@ -54,67 +56,27 @@
@Autowired
private IPlayService playService;
+ @Autowired
+ private IMediaService mediaService;
+
@GetMapping("/play/{deviceId}/{channelId}")
public DeferredResult<ResponseEntity<String>> play(@PathVariable String deviceId,
@PathVariable String channelId) {
- Device device = storager.queryVideoDevice(deviceId);
- StreamInfo streamInfo = redisCatchStorage.queryPlayByDevice(deviceId, channelId);
-
- UUID uuid = UUID.randomUUID();
- DeferredResult<ResponseEntity<String>> result = new DeferredResult<ResponseEntity<String>>();
-
- // 褰曞儚鏌ヨ浠hannelId浣滀负deviceId鏌ヨ
- resultHolder.put(DeferredResultHolder.CALLBACK_CMD_PlAY + uuid, result);
-
- if (streamInfo == null) {
- // 鍙戦�佺偣鎾秷鎭�
- cmder.playStreamCmd(device, channelId, (JSONObject response) -> {
- logger.info("鏀跺埌璁㈤槄娑堟伅锛� " + response.toJSONString());
- playService.onPublishHandlerForPlay(response, deviceId, channelId, uuid.toString());
- }, event -> {
- RequestMessage msg = new RequestMessage();
- msg.setId(DeferredResultHolder.CALLBACK_CMD_PlAY + uuid);
- Response response = event.getResponse();
- msg.setData(String.format("鐐规挱澶辫触锛� 閿欒鐮侊細 %s, %s", response.getStatusCode(), response.getReasonPhrase()));
- resultHolder.invokeResult(msg);
- });
- } else {
- String streamId = streamInfo.getStreamId();
- JSONObject rtpInfo = zlmresTfulUtils.getRtpInfo(streamId);
- if (rtpInfo.getBoolean("exist")) {
- RequestMessage msg = new RequestMessage();
- msg.setId(DeferredResultHolder.CALLBACK_CMD_PlAY + uuid);
- msg.setData(JSON.toJSONString(streamInfo));
- resultHolder.invokeResult(msg);
- } else {
- redisCatchStorage.stopPlay(streamInfo);
- storager.stopPlay(streamInfo.getDeviceID(), streamInfo.getChannelId());
- cmder.playStreamCmd(device, channelId, (JSONObject response) -> {
- logger.info("鏀跺埌璁㈤槄娑堟伅锛� " + response.toJSONString());
- playService.onPublishHandlerForPlay(response, deviceId, channelId, uuid.toString());
- }, event -> {
- RequestMessage msg = new RequestMessage();
- msg.setId(DeferredResultHolder.CALLBACK_CMD_PlAY + uuid);
- Response response = event.getResponse();
- msg.setData(String.format("鐐规挱澶辫触锛� 閿欒鐮侊細 %s, %s", response.getStatusCode(), response.getReasonPhrase()));
- resultHolder.invokeResult(msg);
- });
- }
- }
+ PlayResult playResult = playService.play(deviceId, channelId, null, null);
// 瓒呮椂澶勭悊
- result.onTimeout(()->{
+ playResult.getResult().onTimeout(()->{
logger.warn(String.format("璁惧鐐规挱瓒呮椂锛宒eviceId锛�%s 锛宑hannelId锛�%s", deviceId, channelId));
// 閲婃斁rtpserver
- cmder.closeRTPServer(device, channelId);
+ cmder.closeRTPServer(playResult.getDevice(), channelId);
RequestMessage msg = new RequestMessage();
- msg.setId(DeferredResultHolder.CALLBACK_CMD_PlAY + uuid);
+ msg.setId(DeferredResultHolder.CALLBACK_CMD_PlAY + playResult.getUuid());
msg.setData("Timeout");
resultHolder.invokeResult(msg);
});
- return result;
+ return playResult.getResult();
}
@PostMapping("/play/{streamId}/stop")
@@ -201,18 +163,7 @@
JSONObject data = jsonObject.getJSONObject("data");
if (data != null) {
result.put("key", data.getString("key"));
- StreamInfo streamInfoResult = new StreamInfo();
- streamInfoResult.setRtmp(dstUrl);
- streamInfoResult.setRtsp(String.format("rtsp://%s:%s/convert/%s", mediaInfo.getWanIp(), mediaInfo.getRtspPort(), streamId));
- streamInfoResult.setStreamId(streamId);
- streamInfoResult.setFlv(String.format("http://%s:%s/convert/%s.flv", mediaInfo.getWanIp(), mediaInfo.getHttpPort(), streamId));
- streamInfoResult.setWs_flv(String.format("ws://%s:%s/convert/%s.flv", mediaInfo.getWanIp(), mediaInfo.getHttpPort(), streamId));
- streamInfoResult.setHls(String.format("http://%s:%s/convert/%s/hls.m3u8", mediaInfo.getWanIp(), mediaInfo.getHttpPort(), streamId));
- streamInfoResult.setWs_hls(String.format("ws://%s:%s/convert/%s/hls.m3u8", mediaInfo.getWanIp(), mediaInfo.getHttpPort(), streamId));
- streamInfoResult.setFmp4(String.format("http://%s:%s/convert/%s.live.mp4", mediaInfo.getWanIp(), mediaInfo.getHttpPort(), streamId));
- streamInfoResult.setWs_fmp4(String.format("ws://%s:%s/convert/%s.live.mp4", mediaInfo.getWanIp(), mediaInfo.getHttpPort(), streamId));
- streamInfoResult.setTs(String.format("http://%s:%s/convert/%s.live.ts", mediaInfo.getWanIp(), mediaInfo.getHttpPort(), streamId));
- streamInfoResult.setWs_ts(String.format("ws://%s:%s/convert/%s.live.ts", mediaInfo.getWanIp(), mediaInfo.getHttpPort(), streamId));
+ StreamInfo streamInfoResult = mediaService.getStreamInfoByAppAndStream("convert", streamId);
result.put("data", streamInfoResult);
}
}else {
@@ -249,5 +200,47 @@
}
return new ResponseEntity<String>( result.toJSONString(), HttpStatus.OK);
}
+
+ /**
+ * 璇煶骞挎挱鍛戒护API鎺ュ彛
+ *
+ * @param deviceId
+ */
+ @GetMapping("/broadcast/{deviceId}")
+ @PostMapping("/broadcast/{deviceId}")
+ public DeferredResult<ResponseEntity<String>> broadcastApi(@PathVariable String deviceId) {
+ if (logger.isDebugEnabled()) {
+ logger.debug("璇煶骞挎挱API璋冪敤");
+ }
+ Device device = storager.queryVideoDevice(deviceId);
+ cmder.audioBroadcastCmd(device, event -> {
+ Response response = event.getResponse();
+ RequestMessage msg = new RequestMessage();
+ msg.setId(DeferredResultHolder.CALLBACK_CMD_BROADCAST + deviceId);
+ JSONObject json = new JSONObject();
+ json.put("DeviceID", deviceId);
+ json.put("CmdType", "Broadcast");
+ json.put("Result", "Failed");
+ json.put("Description", String.format("璇煶骞挎挱鎿嶄綔澶辫触锛岄敊璇爜锛� %s, %s", response.getStatusCode(), response.getReasonPhrase()));
+ msg.setData(json);
+ resultHolder.invokeResult(msg);
+ });
+ DeferredResult<ResponseEntity<String>> result = new DeferredResult<ResponseEntity<String>>(3 * 1000L);
+ result.onTimeout(() -> {
+ logger.warn(String.format("璇煶骞挎挱鎿嶄綔瓒呮椂, 璁惧鏈繑鍥炲簲绛旀寚浠�"));
+ RequestMessage msg = new RequestMessage();
+ msg.setId(DeferredResultHolder.CALLBACK_CMD_BROADCAST + deviceId);
+ JSONObject json = new JSONObject();
+ json.put("DeviceID", deviceId);
+ json.put("CmdType", "Broadcast");
+ json.put("Result", "Failed");
+ json.put("Error", "Timeout. Device did not response to broadcast command.");
+ msg.setData(json);
+ resultHolder.invokeResult(msg);
+ });
+ resultHolder.put(DeferredResultHolder.CALLBACK_CMD_BROADCAST + deviceId, result);
+ return result;
+ }
+
}
--
Gitblit v1.8.0