|  |  | 
 |  |  | import com.genersoft.iot.vmp.service.bean.SSRCInfo; | 
 |  |  | import com.genersoft.iot.vmp.storager.IRedisCatchStorage; | 
 |  |  | import com.genersoft.iot.vmp.storager.IVideoManagerStorage; | 
 |  |  | import com.genersoft.iot.vmp.utils.DateUtil; | 
 |  |  | import com.genersoft.iot.vmp.utils.SerializeUtils; | 
 |  |  | import gov.nist.javax.sdp.TimeDescriptionImpl; | 
 |  |  | import gov.nist.javax.sdp.fields.TimeField; | 
 |  |  | import javafx.application.Platform; | 
 |  |  | import org.slf4j.Logger; | 
 |  |  | import org.slf4j.LoggerFactory; | 
 |  |  | import org.springframework.beans.factory.InitializingBean; | 
 |  |  | 
 |  |  | import javax.sip.message.Request; | 
 |  |  | import javax.sip.message.Response; | 
 |  |  | import java.text.ParseException; | 
 |  |  | import java.text.SimpleDateFormat; | 
 |  |  | import java.util.Date; | 
 |  |  | import java.time.Instant; | 
 |  |  | import java.util.Vector; | 
 |  |  |  | 
 |  |  | /** | 
 |  |  | 
 |  |  |  | 
 |  |  |             Long startTime = null; | 
 |  |  |             Long stopTime = null; | 
 |  |  |             Date start = null; | 
 |  |  |             Date end = null; | 
 |  |  |             Instant start = null; | 
 |  |  |             Instant end = null; | 
 |  |  |             if (sdp.getTimeDescriptions(false) != null && sdp.getTimeDescriptions(false).size() > 0) { | 
 |  |  |                TimeDescriptionImpl timeDescription = (TimeDescriptionImpl)(sdp.getTimeDescriptions(false).get(0)); | 
 |  |  |                TimeField startTimeFiled = (TimeField)timeDescription.getTime(); | 
 |  |  |                startTime = startTimeFiled.getStartTime(); | 
 |  |  |                stopTime = startTimeFiled.getStopTime(); | 
 |  |  |  | 
 |  |  |                start = new Date(startTime*1000); | 
 |  |  |                end = new Date(stopTime*1000); | 
 |  |  |                start = Instant.ofEpochMilli(startTime*1000); | 
 |  |  |                end = Instant.ofEpochMilli(stopTime*1000); | 
 |  |  |             } | 
 |  |  |             //  获取支持的格式 | 
 |  |  |             Vector mediaDescriptions = sdp.getMediaDescriptions(true); | 
 |  |  | 
 |  |  |                      response = getMessageFactory().createResponse(event.statusCode, evt.getRequest()); | 
 |  |  |                      ServerTransaction serverTransaction = getServerTransaction(evt); | 
 |  |  |                      serverTransaction.sendResponse(response); | 
 |  |  |                      if (serverTransaction.getDialog() != null) serverTransaction.getDialog().delete(); | 
 |  |  |                      if (serverTransaction.getDialog() != null) { | 
 |  |  |                         serverTransaction.getDialog().delete(); | 
 |  |  |                      } | 
 |  |  |                   } catch (ParseException | SipException | InvalidArgumentException e) { | 
 |  |  |                      e.printStackTrace(); | 
 |  |  |                   } | 
 |  |  | 
 |  |  |                sendRtpItem.setApp("rtp"); | 
 |  |  |                if ("Playback".equals(sessionName)) { | 
 |  |  |                   sendRtpItem.setPlayType(InviteStreamType.PLAYBACK); | 
 |  |  |                   SSRCInfo ssrcInfo = mediaServerService.openRTPServer(mediaServerItem, null, true); | 
 |  |  |                   SSRCInfo ssrcInfo = mediaServerService.openRTPServer(mediaServerItem, null, true, true); | 
 |  |  |                   sendRtpItem.setStreamId(ssrcInfo.getStream()); | 
 |  |  |                   // 写入redis, 超时时回复 | 
 |  |  |                   redisCatchStorage.updateSendRTPSever(sendRtpItem); | 
 |  |  |                   SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); | 
 |  |  |                   playService.playBack(mediaServerItem, ssrcInfo, device.getDeviceId(), channelId, format.format(start), | 
 |  |  |                         format.format(end), null, result -> { | 
 |  |  |                   playService.playBack(mediaServerItem, ssrcInfo, device.getDeviceId(), channelId, DateUtil.formatter.format(start), | 
 |  |  |                         DateUtil.formatter.format(end), null, result -> { | 
 |  |  |                         if (result.getCode() != 0){ | 
 |  |  |                            logger.warn("录像回放失败"); | 
 |  |  |                            if (result.getEvent() != null) { | 
 |  |  | 
 |  |  |                      if (mediaServerItem.isRtpEnable()) { | 
 |  |  |                         streamId = String.format("%s_%s", device.getDeviceId(), channelId); | 
 |  |  |                      } | 
 |  |  |                      SSRCInfo ssrcInfo = mediaServerService.openRTPServer(mediaServerItem, streamId, true); | 
 |  |  |                      SSRCInfo ssrcInfo = mediaServerService.openRTPServer(mediaServerItem, streamId, true, false); | 
 |  |  |                      sendRtpItem.setStreamId(ssrcInfo.getStream()); | 
 |  |  |                      // 写入redis, 超时时回复 | 
 |  |  |                      redisCatchStorage.updateSendRTPSever(sendRtpItem); | 
 |  |  | 
 |  |  |                      logger.info("[ app={}, stream={} ]通道离线,启用流后开始推流",gbStream.getApp(), gbStream.getStream()); | 
 |  |  |                      responseAck(evt, Response.BAD_REQUEST, "channel [" + gbStream.getGbId() + "] offline"); | 
 |  |  |                   }else if ("push".equals(gbStream.getStreamType())) { | 
 |  |  |                      if (!platform.isStartOfflinePush()) { | 
 |  |  |                         responseAck(evt, Response.TEMPORARILY_UNAVAILABLE, "channel unavailable"); | 
 |  |  |                         return; | 
 |  |  |                      } | 
 |  |  |                      // 发送redis消息以使设备上线 | 
 |  |  |                      logger.info("[ app={}, stream={} ]通道离线,发送redis信息控制设备开始推流",gbStream.getApp(), gbStream.getStream()); | 
 |  |  |                      MessageForPushChannel messageForPushChannel = new MessageForPushChannel(); |