648540858
2022-05-06 5d901b5e3f033e8b04e53420d68626cbd87431c8
src/main/java/com/genersoft/iot/vmp/gb28181/session/VideoStreamSessionManager.java
@@ -78,7 +78,9 @@
   
   public ClientTransaction getTransactionByStream(String deviceId, String channelId, String stream){
      SsrcTransaction ssrcTransaction = getSsrcTransaction(deviceId, channelId, null, stream);
      if (ssrcTransaction == null) return null;
      if (ssrcTransaction == null) {
         return null;
      }
      byte[] transactionByteArray = ssrcTransaction.getTransaction();
      ClientTransaction clientTransaction = (ClientTransaction)SerializeUtils.deSerialize(transactionByteArray);
      return clientTransaction;
@@ -86,39 +88,63 @@
   public SIPDialog getDialogByStream(String deviceId, String channelId, String stream){
      SsrcTransaction ssrcTransaction = getSsrcTransaction(deviceId, channelId, null, stream);
      if (ssrcTransaction == null) return null;
      if (ssrcTransaction == null) {
         return null;
      }
      byte[] dialogByteArray = ssrcTransaction.getDialog();
      if (dialogByteArray == null) return null;
      if (dialogByteArray == null) {
         return null;
      }
      SIPDialog dialog = (SIPDialog)SerializeUtils.deSerialize(dialogByteArray);
      return dialog;
   }
   public SIPDialog getDialogByCallId(String deviceId, String channelId, String callID){
      SsrcTransaction ssrcTransaction = getSsrcTransaction(deviceId, channelId, callID, null);
      if (ssrcTransaction == null) return null;
      if (ssrcTransaction == null) {
         return null;
      }
      byte[] dialogByteArray = ssrcTransaction.getDialog();
      if (dialogByteArray == null) return null;
      if (dialogByteArray == null) {
         return null;
      }
      SIPDialog dialog = (SIPDialog)SerializeUtils.deSerialize(dialogByteArray);
      return dialog;
   }
   public SsrcTransaction getSsrcTransaction(String deviceId, String channelId, String callId, String stream){
      if (StringUtils.isEmpty(callId)) callId ="*";
      if (StringUtils.isEmpty(stream)) stream ="*";
      if (StringUtils.isEmpty(callId)) {
         callId ="*";
      }
      if (StringUtils.isEmpty(stream)) {
         stream ="*";
      }
      String key = VideoManagerConstants.MEDIA_TRANSACTION_USED_PREFIX + userSetting.getServerId() + "_" + deviceId + "_" + channelId + "_" + callId+ "_" + stream;
      List<Object> scanResult = redisUtil.scan(key);
      if (scanResult.size() == 0) return null;
      if (scanResult.size() == 0) {
         return null;
      }
      return (SsrcTransaction)redisUtil.get((String) scanResult.get(0));
   }
   public List<SsrcTransaction> getSsrcTransactionForAll(String deviceId, String channelId, String callId, String stream){
      if (StringUtils.isEmpty(deviceId)) deviceId ="*";
      if (StringUtils.isEmpty(channelId)) channelId ="*";
      if (StringUtils.isEmpty(callId)) callId ="*";
      if (StringUtils.isEmpty(stream)) stream ="*";
      if (StringUtils.isEmpty(deviceId)) {
         deviceId ="*";
      }
      if (StringUtils.isEmpty(channelId)) {
         channelId ="*";
      }
      if (StringUtils.isEmpty(callId)) {
         callId ="*";
      }
      if (StringUtils.isEmpty(stream)) {
         stream ="*";
      }
      String key = VideoManagerConstants.MEDIA_TRANSACTION_USED_PREFIX + userSetting.getServerId() + "_" + deviceId + "_" + channelId + "_" + callId+ "_" + stream;
      List<Object> scanResult = redisUtil.scan(key);
      if (scanResult.size() == 0) return null;
      if (scanResult.size() == 0) {
         return null;
      }
      List<SsrcTransaction> result = new ArrayList<>();
      for (Object keyObj : scanResult) {
         result.add((SsrcTransaction)redisUtil.get((String) keyObj));
@@ -128,19 +154,25 @@
   public String getMediaServerId(String deviceId, String channelId, String stream){
      SsrcTransaction ssrcTransaction = getSsrcTransaction(deviceId, channelId, null, stream);
      if (ssrcTransaction == null) return null;
      if (ssrcTransaction == null) {
         return null;
      }
      return ssrcTransaction.getMediaServerId();
   }
   public String getSSRC(String deviceId, String channelId, String stream){
      SsrcTransaction ssrcTransaction = getSsrcTransaction(deviceId, channelId, null, stream);
      if (ssrcTransaction == null) return null;
      if (ssrcTransaction == null) {
         return null;
      }
      return ssrcTransaction.getSsrc();
   }
   
   public void remove(String deviceId, String channelId, String stream) {
      SsrcTransaction ssrcTransaction = getSsrcTransaction(deviceId, channelId, null, stream);
      if (ssrcTransaction == null) return;
      if (ssrcTransaction == null) {
         return;
      }
      redisUtil.del(VideoManagerConstants.MEDIA_TRANSACTION_USED_PREFIX + userSetting.getServerId() + "_"
            +  deviceId + "_" + channelId + "_" + ssrcTransaction.getCallId() + "_" + ssrcTransaction.getStream());
   }