648540858
2022-10-18 1af77ab5f7c11a4b3d59c1989b51b9fca29679ce
src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/play/PlayController.java
@@ -3,6 +3,7 @@
import com.alibaba.fastjson.JSONArray;
import com.genersoft.iot.vmp.common.StreamInfo;
import com.genersoft.iot.vmp.conf.exception.ControllerException;
import com.genersoft.iot.vmp.conf.exception.SsrcTransactionNotFoundException;
import com.genersoft.iot.vmp.gb28181.bean.SsrcTransaction;
import com.genersoft.iot.vmp.gb28181.session.VideoStreamSessionManager;
import com.genersoft.iot.vmp.gb28181.bean.Device;
@@ -36,6 +37,9 @@
import com.genersoft.iot.vmp.storager.IVideoManagerStorage;
import org.springframework.web.context.request.async.DeferredResult;
import javax.sip.InvalidArgumentException;
import javax.sip.SipException;
import java.text.ParseException;
import java.util.List;
import java.util.UUID;
@@ -78,7 +82,7 @@
   @Parameter(name = "deviceId", description = "设备国标编号", required = true)
   @Parameter(name = "channelId", description = "通道国标编号", required = true)
   @GetMapping("/start/{deviceId}/{channelId}")
   public DeferredResult<WVPResult<String>> play(@PathVariable String deviceId,
   public DeferredResult<WVPResult<StreamInfo>> play(@PathVariable String deviceId,
                                          @PathVariable String channelId) {
      // 获取可用的zlm
@@ -102,12 +106,23 @@
         throw new ControllerException(ErrorCode.ERROR400);
      }
      Device device = storager.queryVideoDevice(deviceId);
      if (device == null) {
         throw new ControllerException(ErrorCode.ERROR100.getCode(), "设备[" + deviceId + "]不存在");
      }
      StreamInfo streamInfo = redisCatchStorage.queryPlayByDevice(deviceId, channelId);
      if (streamInfo == null) {
         throw new ControllerException(ErrorCode.ERROR100.getCode(), "点播未找到");
      }
      cmder.streamByeCmd(deviceId, channelId, streamInfo.getStream(), null, null);
      try {
         logger.warn("[停止点播] {}/{}", device.getDeviceId(), channelId);
         cmder.streamByeCmd(device, channelId, streamInfo.getStream(), null, null);
      } catch (InvalidArgumentException | SipException | ParseException | SsrcTransactionNotFoundException e) {
         logger.error("[命令发送失败] 停止点播, 发送BYE: {}", e.getMessage());
         throw new ControllerException(ErrorCode.ERROR100.getCode(), "命令发送失败: " + e.getMessage());
      }
      redisCatchStorage.stopPlay(streamInfo);
      storager.stopPlay(streamInfo.getDeviceID(), streamInfo.getChannelId());
@@ -221,18 +236,23 @@
         resultHolder.invokeResult(msg);
         return result;
      }
      cmder.audioBroadcastCmd(device, (event) -> {
         RequestMessage msg = new RequestMessage();
         msg.setKey(key);
         msg.setId(uuid);
         JSONObject json = new JSONObject();
         json.put("DeviceID", deviceId);
         json.put("CmdType", "Broadcast");
         json.put("Result", "Failed");
         json.put("Description", String.format("语音广播操作失败,错误码: %s, %s", event.statusCode, event.msg));
         msg.setData(json);
         resultHolder.invokeResult(msg);
      });
      try {
         cmder.audioBroadcastCmd(device, (event) -> {
            RequestMessage msg = new RequestMessage();
            msg.setKey(key);
            msg.setId(uuid);
            JSONObject json = new JSONObject();
            json.put("DeviceID", deviceId);
            json.put("CmdType", "Broadcast");
            json.put("Result", "Failed");
            json.put("Description", String.format("语音广播操作失败,错误码: %s, %s", event.statusCode, event.msg));
            msg.setData(json);
            resultHolder.invokeResult(msg);
         });
      } catch (InvalidArgumentException | SipException | ParseException e) {
         logger.error("[命令发送失败] 语音广播: {}", e.getMessage());
         throw new ControllerException(ErrorCode.ERROR100.getCode(), "命令发送失败: " + e.getMessage());
      }
      result.onTimeout(() -> {
         logger.warn("语音广播操作超时, 设备未返回应答指令");