| | |
| | | import com.alibaba.fastjson2.JSON; |
| | | import com.alibaba.fastjson2.JSONArray; |
| | | import com.alibaba.fastjson2.JSONObject; |
| | | import com.baomidou.dynamic.datasource.annotation.DS; |
| | | import com.genersoft.iot.vmp.common.CommonCallback; |
| | | import com.genersoft.iot.vmp.common.VideoManagerConstants; |
| | | import com.genersoft.iot.vmp.conf.DynamicTask; |
| | |
| | | import com.genersoft.iot.vmp.utils.JsonUtil; |
| | | import com.genersoft.iot.vmp.utils.redis.RedisUtil; |
| | | import com.genersoft.iot.vmp.vmanager.bean.ErrorCode; |
| | | import com.genersoft.iot.vmp.vmanager.bean.RecordFile; |
| | | import okhttp3.OkHttpClient; |
| | | import okhttp3.Request; |
| | | import okhttp3.Response; |
| | |
| | | import org.springframework.beans.factory.annotation.Value; |
| | | import org.springframework.data.redis.core.RedisTemplate; |
| | | import org.springframework.jdbc.datasource.DataSourceTransactionManager; |
| | | import org.springframework.scheduling.annotation.Async; |
| | | import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.TransactionDefinition; |
| | | import org.springframework.transaction.TransactionStatus; |
| | | import org.springframework.util.Assert; |
| | | import org.springframework.util.ObjectUtils; |
| | | |
| | | import java.io.File; |
| | | import java.time.LocalDateTime; |
| | | import java.util.*; |
| | | import java.util.concurrent.CompletableFuture; |
| | | import java.util.concurrent.ExecutionException; |
| | | |
| | | /** |
| | | * 媒体服务器节点管理 |
| | | */ |
| | | @Service |
| | | @DS("master") |
| | | public class MediaServerServiceImpl implements IMediaServerService { |
| | | |
| | | private final static Logger logger = LoggerFactory.getLogger(MediaServerServiceImpl.class); |
| | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | /** |
| | | * 初始化 |
| | | */ |
| | |
| | | |
| | | @Override |
| | | public SSRCInfo openRTPServer(MediaServerItem mediaServerItem, String streamId, String presetSsrc, boolean ssrcCheck, |
| | | boolean isPlayback, Integer port, Boolean reUsePort, Integer tcpMode) { |
| | | boolean isPlayback, Integer port, Boolean onlyAuto, Boolean reUsePort, Integer tcpMode) { |
| | | if (mediaServerItem == null || mediaServerItem.getId() == null) { |
| | | logger.info("[openRTPServer] 失败, mediaServerItem == null || mediaServerItem.getId() == null"); |
| | | return null; |
| | |
| | | } |
| | | int rtpServerPort; |
| | | if (mediaServerItem.isRtpEnable()) { |
| | | rtpServerPort = zlmServerFactory.createRTPServer(mediaServerItem, streamId, ssrcCheck ? Long.parseLong(ssrc) : 0, port, reUsePort, tcpMode); |
| | | rtpServerPort = zlmServerFactory.createRTPServer(mediaServerItem, streamId, ssrcCheck ? Long.parseLong(ssrc) : 0, port, onlyAuto, reUsePort, tcpMode); |
| | | } else { |
| | | rtpServerPort = mediaServerItem.getRtpProxyPort(); |
| | | } |
| | | return new SSRCInfo(rtpServerPort, ssrc, streamId); |
| | | } |
| | | |
| | | @Override |
| | | public SSRCInfo openRTPServer(MediaServerItem mediaServerItem, String streamId, String ssrc, boolean ssrcCheck, boolean isPlayback, Integer port, Boolean onlyAuto) { |
| | | return openRTPServer(mediaServerItem, streamId, ssrc, ssrcCheck, isPlayback, port, onlyAuto, null, 0); |
| | | } |
| | | |
| | | |
| | | @Override |
| | | public void closeRTPServer(MediaServerItem mediaServerItem, String streamId) { |
| | |
| | | @Override |
| | | public void closeRTPServer(String mediaServerId, String streamId) { |
| | | MediaServerItem mediaServerItem = this.getOne(mediaServerId); |
| | | if (mediaServerItem.isRtpEnable()) { |
| | | if (mediaServerItem != null && mediaServerItem.isRtpEnable()) { |
| | | closeRTPServer(mediaServerItem, streamId); |
| | | } |
| | | zlmresTfulUtils.closeStreams(mediaServerItem, "rtp", streamId); |
| | |
| | | return JsonUtil.redisJsonToObject(redisTemplate, key, MediaServerItem.class); |
| | | } |
| | | |
| | | |
| | | @Override |
| | | public MediaServerItem getDefaultMediaServer() { |
| | | |
| | | return mediaServerMapper.queryDefault(); |
| | | } |
| | | |
| | |
| | | ssrcFactory.initMediaServerSSRC(mediaServerItem.getId(), null); |
| | | String key = VideoManagerConstants.MEDIA_SERVER_PREFIX + userSetting.getServerId() + "_" + mediaServerItem.getId(); |
| | | redisTemplate.opsForValue().set(key, mediaServerItem); |
| | | resetOnlineServerItem(mediaServerItem); |
| | | clearRTPServer(mediaServerItem); |
| | | } |
| | | final String zlmKeepaliveKey = zlmKeepaliveKeyPrefix + mediaServerItem.getId(); |
| | |
| | | |
| | | @Override |
| | | public List<MediaServerItem> getAllWithAssistPort() { |
| | | |
| | | return mediaServerMapper.queryAllWithAssistPort(); |
| | | } |
| | | |
| | | @Override |
| | | public MediaServerItem getMediaServerByAppAndStream(String app, String stream) { |
| | | List<MediaServerItem> mediaServerItemList = getAllOnline(); |
| | | if (mediaServerItemList.isEmpty()) { |
| | | return null; |
| | | } |
| | | for (MediaServerItem mediaServerItem : mediaServerItemList) { |
| | | Boolean streamReady = zlmServerFactory.isStreamReady(mediaServerItem, app, stream); |
| | | if (streamReady) { |
| | | return mediaServerItem; |
| | | } |
| | | } |
| | | return null; |
| | | } |
| | | } |