class VideoStreamSessionManager {

	@Autowired
	private UserSetting userSetting;

	@Autowired
	private RedisTemplate<Object, Object> redisTemplate;

	/**
	 * 添加一个点播/回放的事务信息
	 * 后续可以通过流Id/callID
	 * @param deviceId 设备ID
	 * @param channelId 通道ID
	 * @param callId 一次请求的CallID
	 * @param stream 流名称
	 * @param mediaServerId 所使用的流媒体ID
	 * @param response 回复
	 */
	public void put(String deviceId, String channelId, String callId, String stream, String ssrc, String mediaServerId, SIPResponse response, InviteSessionType type){
		SsrcTransaction ssrcTransaction = new SsrcTransaction();
		ssrcTransaction.setDeviceId(deviceId);
		ssrcTransaction.setChannelId(channelId);
		ssrcTransaction.setStream(stream);
		ssrcTransaction.setSipTransactionInfo(new SipTransactionInfo(response));
		ssrcTransaction.setCallId(callId);
		ssrcTransaction.setSsrc(ssrc);
		ssrcTransaction.setMediaServerId(mediaServerId);
		ssrcTransaction.setType(type);

		redisTemplate.opsForValue().set(VideoManagerConstants.MEDIA_TRANSACTION_USED_PREFIX + userSetting.getServerId()
				+ ":" +  deviceId + ":" + channelId + ":" + callId + ":" + stream, ssrcTransaction);
	}

	public SsrcTransaction getSsrcTransaction(String deviceId, String channelId, String callId, String stream){

		if (ObjectUtils.isEmpty(deviceId)) {
			deviceId ="*";
		}
		if (ObjectUtils.isEmpty(channelId)) {
			channelId ="*";
		}
		if (ObjectUtils.isEmpty(callId)) {
			callId ="*";
		}
		if (ObjectUtils.isEmpty(stream)) {
			stream ="*";
		}
		String key = VideoManagerConstants.MEDIA_TRANSACTION_USED_PREFIX + userSetting.getServerId() + ":" + deviceId + ":" + channelId + ":" + callId+ ":" + stream;
		List<Object> scanResult = RedisUtil.scan(redisTemplate, key);
		if (scanResult.size() == 0) {
			return null;
		}
		return (SsrcTransaction)redisTemplate.opsForValue().get(scanResult.get(0));
	}

	public SsrcTransaction getSsrcTransactionByCallId(String callId){

		if (ObjectUtils.isEmpty(callId)) {
			return null;
		}
		String key = VideoManagerConstants.MEDIA_TRANSACTION_USED_PREFIX + userSetting.getServerId() + ":*:*:" + callId+ ":*";
		List<Object> scanResult = RedisUtil.scan(redisTemplate, key);
		if (!scanResult.isEmpty()) {
			return (SsrcTransaction)redisTemplate.opsForValue().get(scanResult.get(0));
		}else {
			key = VideoManagerConstants.MEDIA_TRANSACTION_USED_PREFIX + userSetting.getServerId() + ":*:*:play:*";
			scanResult = RedisUtil.scan(redisTemplate, key);
			if (scanResult.isEmpty()) {
				return null;
			}
			for (Object keyObj : scanResult) {
				SsrcTransaction ssrcTransaction = (SsrcTransaction)redisTemplate.opsForValue().get(keyObj);
				if (ssrcTransaction.getSipTransactionInfo() != null &&
						ssrcTransaction.getSipTransactionInfo().getCallId().equals(callId)) {
					return ssrcTransaction;
				}
			}
			return null;
		}

	}

	public List<SsrcTransaction> getSsrcTransactionForAll(String deviceId, String channelId, String callId, String stream){
		if (ObjectUtils.isEmpty(deviceId)) {
			deviceId ="*";
		}
		if (ObjectUtils.isEmpty(channelId)) {
			channelId ="*";
		}
		if (ObjectUtils.isEmpty(callId)) {
			callId ="*";
		}
		if (ObjectUtils.isEmpty(stream)) {
			stream ="*";
		}
		String key = VideoManagerConstants.MEDIA_TRANSACTION_USED_PREFIX + userSetting.getServerId() + ":" + deviceId + ":" + channelId + ":" + callId+ ":" + stream;
		List<Object> scanResult = RedisUtil.scan(redisTemplate, key);
		if (scanResult.size() == 0) {
			return null;
		}
		List<SsrcTransaction> result = new ArrayList<>();
		for (Object keyObj : scanResult) {
			result.add((SsrcTransaction)redisTemplate.opsForValue().get(keyObj));
		}
		return result;
	}

	public String getMediaServerId(String deviceId, String channelId, String stream){
		SsrcTransaction ssrcTransaction = getSsrcTransaction(deviceId, channelId, null, stream);
		if (ssrcTransaction == null) {
			return null;
		}
		return ssrcTransaction.getMediaServerId();
	}

	public String getSSRC(String deviceId, String channelId, String stream){<FILL_FUNCTION_BODY>}
	
	public void remove(String deviceId, String channelId, String stream) {
		List<SsrcTransaction> ssrcTransactionList = getSsrcTransactionForAll(deviceId, channelId, null, stream);
		if (ssrcTransactionList == null || ssrcTransactionList.isEmpty()) {
			return;
		}
		for (SsrcTransaction ssrcTransaction : ssrcTransactionList) {
			redisTemplate.delete(VideoManagerConstants.MEDIA_TRANSACTION_USED_PREFIX + userSetting.getServerId() + ":"
					+  deviceId + ":" + channelId + ":" + ssrcTransaction.getCallId() + ":" + ssrcTransaction.getStream());
		}
	}

	public void removeByCallId(String deviceId, String channelId, String callId) {
		SsrcTransaction ssrcTransaction = getSsrcTransaction(deviceId, channelId, callId, null);
		if (ssrcTransaction == null ) {
			return;
		}
		redisTemplate.delete(VideoManagerConstants.MEDIA_TRANSACTION_USED_PREFIX + userSetting.getServerId() + ":"
				+  deviceId + ":" + channelId + ":" + ssrcTransaction.getCallId() + ":" + ssrcTransaction.getStream());
	}


	public List<SsrcTransaction> getAllSsrc() {
		List<Object> ssrcTransactionKeys = RedisUtil.scan(redisTemplate, String.format("%s_*_*_*_*", VideoManagerConstants.MEDIA_TRANSACTION_USED_PREFIX+ userSetting.getServerId()));
		List<SsrcTransaction> result= new ArrayList<>();
		for (Object ssrcTransactionKey : ssrcTransactionKeys) {
			String key = (String) ssrcTransactionKey;
			SsrcTransaction ssrcTransaction = JsonUtil.redisJsonToObject(redisTemplate, key, SsrcTransaction.class);
			result.add(ssrcTransaction);
		}
		return result;
	}
}

		SsrcTransaction ssrcTransaction = getSsrcTransaction(deviceId, channelId, null, stream);
		if (ssrcTransaction == null) {
			return null;
		}
		return ssrcTransaction.getSsrc();
	
<no_super_class>