增加推流转发到国标,尚不完善
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
package com.genersoft.iot.vmp.storager;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.genersoft.iot.vmp.common.RealVideo;
|
||||
import com.genersoft.iot.vmp.media.zlm.dto.StreamPushItem;
|
||||
import com.genersoft.iot.vmp.common.StreamInfo;
|
||||
import com.genersoft.iot.vmp.conf.MediaServerConfig;
|
||||
import com.genersoft.iot.vmp.gb28181.bean.ParentPlatform;
|
||||
@@ -107,15 +107,4 @@ public interface IRedisCatchStorage {
|
||||
*/
|
||||
boolean isChannelSendingRTP(String channelId);
|
||||
|
||||
/**
|
||||
* 更新媒体流列表
|
||||
* @param mediaList
|
||||
*/
|
||||
void updateMediaList(List<RealVideo> mediaList);
|
||||
|
||||
/**
|
||||
* 获取当前媒体流列表
|
||||
* @return List<RealVideo>
|
||||
*/
|
||||
JSONObject getMediaList(int start, int end);
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ import java.util.List;
|
||||
|
||||
import com.genersoft.iot.vmp.gb28181.bean.*;
|
||||
import com.genersoft.iot.vmp.media.zlm.dto.StreamProxyItem;
|
||||
import com.genersoft.iot.vmp.media.zlm.dto.StreamPushItem;
|
||||
import com.genersoft.iot.vmp.vmanager.platform.bean.ChannelReduce;
|
||||
import com.github.pagehelper.PageInfo;
|
||||
|
||||
@@ -319,4 +320,36 @@ public interface IVideoManagerStorager {
|
||||
* @return
|
||||
*/
|
||||
List<GbStream> queryGbStreamListInPlatform(String platformId);
|
||||
|
||||
/**
|
||||
* 批量更新推流列表
|
||||
* @param streamPushItems
|
||||
*/
|
||||
void updateMediaList(List<StreamPushItem> streamPushItems);
|
||||
|
||||
/**
|
||||
* 更新单个推流
|
||||
* @param streamPushItem
|
||||
*/
|
||||
void updateMedia(StreamPushItem streamPushItem);
|
||||
|
||||
/**
|
||||
* 移除单个推流
|
||||
* @param app
|
||||
* @param stream
|
||||
*/
|
||||
void removeMedia(String app, String stream);
|
||||
|
||||
|
||||
/**
|
||||
* 清空推流列表
|
||||
*/
|
||||
void clearMediaList();
|
||||
|
||||
/**
|
||||
* 设置流离线
|
||||
* @param app
|
||||
* @param streamId
|
||||
*/
|
||||
void mediaOutline(String app, String streamId);
|
||||
}
|
||||
|
||||
@@ -12,9 +12,9 @@ import java.util.List;
|
||||
public interface GbStreamMapper {
|
||||
|
||||
@Insert("INSERT INTO gb_stream (app, stream, gbId, name, " +
|
||||
"longitude, latitude, streamType) VALUES" +
|
||||
"longitude, latitude, streamType, status) VALUES" +
|
||||
"('${app}', '${stream}', '${gbId}', '${name}', " +
|
||||
"'${longitude}', '${latitude}', '${streamType}')")
|
||||
"'${longitude}', '${latitude}', '${streamType}', ${status})")
|
||||
int add(GbStream gbStream);
|
||||
|
||||
@Update("UPDATE gb_stream " +
|
||||
@@ -24,7 +24,8 @@ public interface GbStreamMapper {
|
||||
"name=#{name}," +
|
||||
"streamType=#{streamType}," +
|
||||
"longitude=#{longitude}, " +
|
||||
"latitude=#{latitude}, " +
|
||||
"latitude=#{latitude} " +
|
||||
"status=${status} " +
|
||||
"WHERE app=#{app} AND stream=#{stream} AND gbId=#{gbId}")
|
||||
int update(GbStream gbStream);
|
||||
|
||||
@@ -46,4 +47,9 @@ public interface GbStreamMapper {
|
||||
"LEFT JOIN platform_gb_stream pgs ON gs.app = pgs.app AND gs.stream = pgs.stream " +
|
||||
"WHERE pgs.platformId = '${platformId}'")
|
||||
List<GbStream> queryGbStreamListInPlatform(String platformId);
|
||||
|
||||
@Update("UPDATE gb_stream " +
|
||||
"SET status=${status} " +
|
||||
"WHERE app=#{app} AND stream=#{stream}")
|
||||
void setStatus(String app, String stream, boolean status);
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@ import java.util.List;
|
||||
|
||||
@Mapper
|
||||
@Repository
|
||||
public interface PlarfotmGbStreamMapper {
|
||||
public interface PlatformGbStreamMapper {
|
||||
|
||||
@Insert("INSERT INTO platform_gb_stream (app, stream, platformId) VALUES" +
|
||||
"('${app}', '${stream}', '${platformId}')")
|
||||
@@ -20,9 +20,9 @@ public interface PlarfotmGbStreamMapper {
|
||||
@Delete("DELETE FROM platform_gb_stream WHERE app=#{app} AND stream=#{stream}")
|
||||
int delByAppAndStream(String app, String stream);
|
||||
|
||||
@Delete("DELETE FROM platform_gb_stream WHERE app=#{app} AND stream=#{stream}")
|
||||
@Delete("DELETE FROM platform_gb_stream WHERE platformId=#{platformId}")
|
||||
int delByPlatformId(String platformId);
|
||||
|
||||
@Select("SELECT * FROM platform_gb_stream WHERE app=#{app} AND stream=#{stream} AND platformId=#{platformId}")
|
||||
StreamProxyItem selectOne(String app, String stream, String platformId);
|
||||
@Select("SELECT * FROM platform_gb_stream WHERE app=#{app} AND stream=#{stream}")
|
||||
List<StreamProxyItem> selectByAppAndStream(String app, String stream);
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
package com.genersoft.iot.vmp.storager.dao;
|
||||
|
||||
import com.genersoft.iot.vmp.media.zlm.dto.StreamProxyItem;
|
||||
import com.genersoft.iot.vmp.media.zlm.dto.StreamPushItem;
|
||||
import org.apache.ibatis.annotations.*;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Mapper
|
||||
@Repository
|
||||
public interface StreamPushMapper {
|
||||
|
||||
@Insert("INSERT INTO stream_push (app, stream, totalReaderCount, originType, originTypeStr, " +
|
||||
"createStamp, aliveSecond) VALUES" +
|
||||
"('${app}', '${stream}', '${totalReaderCount}', '${originType}', '${originTypeStr}', " +
|
||||
"'${createStamp}', '${aliveSecond}' )")
|
||||
int add(StreamPushItem streamPushItem);
|
||||
|
||||
@Update("UPDATE stream_push " +
|
||||
"SET app=#{app}," +
|
||||
"stream=#{stream}," +
|
||||
"totalReaderCount=#{totalReaderCount}, " +
|
||||
"originType=#{originType}," +
|
||||
"originTypeStr=#{originTypeStr}, " +
|
||||
"createStamp=#{createStamp}, " +
|
||||
"aliveSecond=#{aliveSecond} " +
|
||||
"WHERE app=#{app} AND stream=#{stream}")
|
||||
int update(StreamPushItem streamPushItem);
|
||||
|
||||
@Delete("DELETE FROM stream_push WHERE app=#{app} AND stream=#{stream}")
|
||||
int del(String app, String stream);
|
||||
|
||||
@Select("SELECT st.*, pgs.gbId, pgs.status, pgs.name, pgs.longitude, pgs.latitude FROM stream_push st LEFT JOIN gb_stream pgs on st.app = pgs.app AND st.stream = pgs.stream")
|
||||
List<StreamPushItem> selectAll();
|
||||
|
||||
@Select("SELECT st.*, pgs.gbId, pgs.status, pgs.name, pgs.longitude, pgs.latitude FROM stream_push st LEFT JOIN gb_stream pgs on st.app = pgs.app AND st.stream = pgs.stream WHERE st.enable=${enable}")
|
||||
List<StreamPushItem> selectForEnable(boolean enable);
|
||||
|
||||
@Select("SELECT st.*, pgs.gbId, pgs.status, pgs.name, pgs.longitude, pgs.latitude FROM stream_push st LEFT JOIN gb_stream pgs on st.app = pgs.app AND st.stream = pgs.stream WHERE st.app=#{app} AND st.stream=#{stream}")
|
||||
StreamPushItem selectOne(String app, String stream);
|
||||
|
||||
@Insert("<script>" +
|
||||
"INSERT INTO stream_push (app, stream, totalReaderCount, originType, originTypeStr, " +
|
||||
"createStamp, aliveSecond) " +
|
||||
"VALUES <foreach collection='streamPushItems' item='item' index='index' >" +
|
||||
"( '${item.app}', '${item.stream}', '${item.totalReaderCount}', '${item.originType}', " +
|
||||
"'${item.originTypeStr}','${item.createStamp}', '${item.aliveSecond}' )" +
|
||||
" </foreach>" +
|
||||
"</script>")
|
||||
void addAll(List<StreamPushItem> streamPushItems);
|
||||
|
||||
@Delete("DELETE FROM stream_push")
|
||||
void clear();
|
||||
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
package com.genersoft.iot.vmp.storager.impl;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.genersoft.iot.vmp.common.RealVideo;
|
||||
import com.genersoft.iot.vmp.media.zlm.dto.StreamPushItem;
|
||||
import com.genersoft.iot.vmp.common.StreamInfo;
|
||||
import com.genersoft.iot.vmp.common.VideoManagerConstants;
|
||||
import com.genersoft.iot.vmp.conf.MediaServerConfig;
|
||||
@@ -261,34 +261,4 @@ public class RedisCatchStorageImpl implements IRedisCatchStorage {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 更新媒体流列表
|
||||
* @param mediaList
|
||||
*/
|
||||
@Override
|
||||
public void updateMediaList(List<RealVideo> mediaList) {
|
||||
String key = VideoManagerConstants.MEDIA_STREAM_PREFIX;
|
||||
redis.del(key);
|
||||
for (int i = 0; i < mediaList.size(); i++) {
|
||||
RealVideo realVideo = mediaList.get(i);
|
||||
redis.zAdd(key, realVideo, realVideo.getCreateStamp());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取当前媒体流列表
|
||||
* @return List<RealVideo>
|
||||
*/
|
||||
@Override
|
||||
public JSONObject getMediaList(int start, int end) {
|
||||
String key = VideoManagerConstants.MEDIA_STREAM_PREFIX;
|
||||
Set<Object> realVideos = redis.ZRange(key, start, end);
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
jsonObject.put("list", new ArrayList(realVideos));
|
||||
jsonObject.put("total", redis.zSize(key));
|
||||
|
||||
return jsonObject;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ import java.util.*;
|
||||
|
||||
import com.genersoft.iot.vmp.gb28181.bean.*;
|
||||
import com.genersoft.iot.vmp.media.zlm.dto.StreamProxyItem;
|
||||
import com.genersoft.iot.vmp.media.zlm.dto.StreamPushItem;
|
||||
import com.genersoft.iot.vmp.storager.IRedisCatchStorage;
|
||||
import com.genersoft.iot.vmp.storager.dao.*;
|
||||
import com.genersoft.iot.vmp.vmanager.platform.bean.ChannelReduce;
|
||||
@@ -53,6 +54,9 @@ public class VideoManagerStoragerImpl implements IVideoManagerStorager {
|
||||
@Autowired
|
||||
private StreamProxyMapper streamProxyMapper;
|
||||
|
||||
@Autowired
|
||||
private StreamPushMapper streamPushMapper;
|
||||
|
||||
@Autowired
|
||||
private GbStreamMapper gbStreamMapper;
|
||||
|
||||
@@ -221,9 +225,10 @@ public class VideoManagerStoragerImpl implements IVideoManagerStorager {
|
||||
*/
|
||||
@Override
|
||||
public synchronized boolean outline(String deviceId) {
|
||||
System.out.println("更新设备离线: " + deviceId);
|
||||
Device device = deviceMapper.getDeviceByDeviceId(deviceId);
|
||||
if (device == null) return false;
|
||||
device.setOnline(0);
|
||||
System.out.println("更新设备离线");
|
||||
return deviceMapper.update(device) > 0;
|
||||
}
|
||||
|
||||
@@ -403,6 +408,7 @@ public class VideoManagerStoragerImpl implements IVideoManagerStorager {
|
||||
TransactionStatus transactionStatus = dataSourceTransactionManager.getTransaction(transactionDefinition);
|
||||
boolean result = false;
|
||||
streamProxyItem.setStreamType("proxy");
|
||||
streamProxyItem.setStatus(true);
|
||||
try {
|
||||
if (gbStreamMapper.add(streamProxyItem)<0 || streamProxyMapper.add(streamProxyItem) < 0) {
|
||||
//事务回滚
|
||||
@@ -504,4 +510,37 @@ public class VideoManagerStoragerImpl implements IVideoManagerStorager {
|
||||
public StreamProxyItem queryStreamProxy(String app, String stream){
|
||||
return streamProxyMapper.selectOne(app, stream);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateMediaList(List<StreamPushItem> streamPushItems) {
|
||||
if (streamPushItems == null || streamPushItems.size() == 0) return;
|
||||
System.out.printf("updateMediaList: " + streamPushItems.size());
|
||||
streamPushMapper.addAll(streamPushItems);
|
||||
// TODO 待优化
|
||||
for (int i = 0; i < streamPushItems.size(); i++) {
|
||||
gbStreamMapper.setStatus(streamPushItems.get(i).getApp(), streamPushItems.get(i).getStream(), true);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateMedia(StreamPushItem streamPushItem) {
|
||||
streamPushMapper.del(streamPushItem.getApp(), streamPushItem.getStream());
|
||||
streamPushMapper.add(streamPushItem);
|
||||
gbStreamMapper.setStatus(streamPushItem.getApp(), streamPushItem.getStream(), true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeMedia(String app, String stream) {
|
||||
streamPushMapper.del(app, stream);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clearMediaList() {
|
||||
streamPushMapper.clear();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mediaOutline(String app, String streamId) {
|
||||
gbStreamMapper.setStatus(app, streamId, false);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user