1078-优化点播以及通道表结构

This commit is contained in:
648540858 2024-06-08 00:46:08 +08:00
parent 6ae623d639
commit 595d9be283
10 changed files with 85 additions and 39 deletions

View File

@ -20,7 +20,7 @@ public class JTChannel {
* 设备的数据库ID * 设备的数据库ID
*/ */
@Schema(description = "设备的数据库ID") @Schema(description = "设备的数据库ID")
private int terminalId; private int terminalDbId;
/** /**
* 通道ID * 通道ID
@ -41,6 +41,9 @@ public class JTChannel {
@Schema(description = "更新时间") @Schema(description = "更新时间")
private String updateTime; private String updateTime;
@Schema(description = "流信息")
private String stream;
public int getId() { public int getId() {
return id; return id;
} }
@ -57,12 +60,12 @@ public class JTChannel {
this.name = name; this.name = name;
} }
public int getTerminalId() { public int getTerminalDbId() {
return terminalId; return terminalDbId;
} }
public void setTerminalId(int terminalId) { public void setTerminalDbId(int terminalDbId) {
this.terminalId = terminalId; this.terminalDbId = terminalDbId;
} }
public String getCreateTime() { public String getCreateTime() {
@ -97,12 +100,20 @@ public class JTChannel {
this.hasAudio = hasAudio; this.hasAudio = hasAudio;
} }
public String getStream() {
return stream;
}
public void setStream(String stream) {
this.stream = stream;
}
@Override @Override
public String toString() { public String toString() {
return "JTChannel{" + return "JTChannel{" +
"id=" + id + "id=" + id +
", name='" + name + '\'' + ", name='" + name + '\'' +
", terminalId=" + terminalId + ", terminalDbId=" + terminalDbId +
", channelId=" + channelId + ", channelId=" + channelId +
", createTime='" + createTime + '\'' + ", createTime='" + createTime + '\'' +
", updateTime='" + updateTime + '\'' + ", updateTime='" + updateTime + '\'' +

View File

@ -14,18 +14,18 @@ public interface JTChannelMapper {
"from " + "from " +
"wvp_jt_channel jc " + "wvp_jt_channel jc " +
"WHERE " + "WHERE " +
"terminal_id = #{terminalId}" + "terminal_db_id = #{terminalDbId}" +
" <if test='query != null'> AND " + " <if test='query != null'> AND " +
"jc.name LIKE concat('%',#{query},'%') " + "jc.name LIKE concat('%',#{query},'%') " +
"</if> " + "</if> " +
"ORDER BY jc.channel_id " + "ORDER BY jc.channel_id " +
" </script>"}) " </script>"})
List<JTChannel> getAll(@Param("terminalId") int terminalId, @Param("query") String query); List<JTChannel> getAll(@Param("terminalDbId") int terminalDbId, @Param("query") String query);
@Update(value = {" <script>" + @Update(value = {" <script>" +
"UPDATE wvp_jt_channel " + "UPDATE wvp_jt_channel " +
"SET update_time=#{updateTime}" + "SET update_time=#{updateTime}" +
"<if test=\"terminalId != null\">, terminal_id=#{terminalId}</if>" + "<if test=\"terminalDbId != null\">, terminal_db_id=#{terminalDbId}</if>" +
"<if test=\"hasAudio != null\">, has_audio=#{hasAudio}</if>" + "<if test=\"hasAudio != null\">, has_audio=#{hasAudio}</if>" +
"<if test=\"name != null\">, name=#{name}</if>" + "<if test=\"name != null\">, name=#{name}</if>" +
"<if test=\"channelId != null\">, channel_id=#{channelId}</if>" + "<if test=\"channelId != null\">, channel_id=#{channelId}</if>" +
@ -34,14 +34,14 @@ public interface JTChannelMapper {
void update(JTChannel channel); void update(JTChannel channel);
@Insert("INSERT INTO wvp_jt_channel (" + @Insert("INSERT INTO wvp_jt_channel (" +
"terminal_id,"+ "terminal_db_id,"+
"channel_id,"+ "channel_id,"+
"name,"+ "name,"+
"has_audio,"+ "has_audio,"+
"create_time,"+ "create_time,"+
"update_time"+ "update_time"+
") VALUES (" + ") VALUES (" +
"#{terminalId}," + "#{terminalDbId}," +
"#{channelId}," + "#{channelId}," +
"#{name}," + "#{name}," +
"#{hasAudio}," + "#{hasAudio}," +
@ -53,4 +53,13 @@ public interface JTChannelMapper {
@Delete("delete from wvp_jt_channel where id = #{id}") @Delete("delete from wvp_jt_channel where id = #{id}")
void delete(@Param("id") int id); void delete(@Param("id") int id);
@Select(value = {" <script>" +
"SELECT * " +
"from " +
"wvp_jt_channel jc " +
"WHERE " +
"terminal_db_id = #{terminalDbId} and channel_id = #{channelId}" +
" </script>"})
JTChannel getChannel(@Param("terminalDbId") int terminalDbId, @Param("channelId") Integer channelId);
} }

View File

@ -19,6 +19,7 @@ import com.genersoft.iot.vmp.jt1078.event.FtpUploadEvent;
import com.genersoft.iot.vmp.jt1078.proc.request.J1205; import com.genersoft.iot.vmp.jt1078.proc.request.J1205;
import com.genersoft.iot.vmp.jt1078.proc.response.*; import com.genersoft.iot.vmp.jt1078.proc.response.*;
import com.genersoft.iot.vmp.jt1078.service.Ijt1078Service; import com.genersoft.iot.vmp.jt1078.service.Ijt1078Service;
import com.genersoft.iot.vmp.jt1078.session.SessionManager;
import com.genersoft.iot.vmp.media.bean.MediaInfo; import com.genersoft.iot.vmp.media.bean.MediaInfo;
import com.genersoft.iot.vmp.media.bean.MediaServer; import com.genersoft.iot.vmp.media.bean.MediaServer;
import com.genersoft.iot.vmp.media.event.hook.Hook; import com.genersoft.iot.vmp.media.event.hook.Hook;
@ -136,7 +137,13 @@ public class jt1078ServiceImpl implements Ijt1078Service {
@Override @Override
public void play(String phoneNumber, String channelId, int type, GeneralCallback<StreamInfo> callback) { public void play(String phoneNumber, String channelId, int type, GeneralCallback<StreamInfo> callback) {
JTDevice device = getDevice(phoneNumber);
if (device == null) {
throw new ControllerException(ErrorCode.ERROR100.getCode(), "设备不存在");
}
if (SessionManager.INSTANCE.get(phoneNumber) == null) {
throw new ControllerException(ErrorCode.ERROR100.getCode(), "设备离线");
}
// 检查流是否已经存在存在则返回 // 检查流是否已经存在存在则返回
String playKey = VideoManagerConstants.INVITE_INFO_1078_PLAY + phoneNumber + ":" + channelId; String playKey = VideoManagerConstants.INVITE_INFO_1078_PLAY + phoneNumber + ":" + channelId;
List<GeneralCallback<StreamInfo>> errorCallbacks = inviteErrorCallbackMap.computeIfAbsent(playKey, k -> new ArrayList<>()); List<GeneralCallback<StreamInfo>> errorCallbacks = inviteErrorCallbackMap.computeIfAbsent(playKey, k -> new ArrayList<>());
@ -149,14 +156,11 @@ public class jt1078ServiceImpl implements Ijt1078Service {
// 查询流是否存在不存在则删除缓存数据 // 查询流是否存在不存在则删除缓存数据
JSONObject mediaInfo = zlmresTfulUtils.getMediaInfo(mediaServer, "rtp", "rtsp", streamInfo.getStream()); JSONObject mediaInfo = zlmresTfulUtils.getMediaInfo(mediaServer, "rtp", "rtsp", streamInfo.getStream());
if (mediaInfo != null && mediaInfo.getInteger("code") == 0) { if (mediaInfo != null && mediaInfo.getInteger("code") == 0) {
Boolean online = mediaInfo.getBoolean("online"); logger.info("[1078-点播] 点播已经存在,直接返回, phoneNumber {} channelId {}", phoneNumber, channelId);
if (online != null && online) { for (GeneralCallback<StreamInfo> errorCallback : errorCallbacks) {
logger.info("[1078-点播] 点播已经存在,直接返回, phoneNumber {} channelId {}", phoneNumber, channelId); errorCallback.run(InviteErrorCode.SUCCESS.getCode(), InviteErrorCode.SUCCESS.getMsg(), streamInfo);
for (GeneralCallback<StreamInfo> errorCallback : errorCallbacks) {
errorCallback.run(InviteErrorCode.SUCCESS.getCode(), InviteErrorCode.SUCCESS.getMsg(), streamInfo);
}
return;
} }
return;
} }
} }
// 清理数据 // 清理数据
@ -174,7 +178,7 @@ public class jt1078ServiceImpl implements Ijt1078Service {
Hook hook = Hook.getInstance(HookType.on_media_arrival, "rtp", stream, mediaServer.getId()); Hook hook = Hook.getInstance(HookType.on_media_arrival, "rtp", stream, mediaServer.getId());
subscribe.addSubscribe(hook, (hookData) -> { subscribe.addSubscribe(hook, (hookData) -> {
dynamicTask.stop(playKey); dynamicTask.stop(playKey);
logger.info("[1078-点播] 点播成功, phoneNumber {} channelId {}", phoneNumber, channelId); logger.info("[1078-点播] 点播成功, 手机号: {} 通道 {}", phoneNumber, channelId);
// TODO 发送9105 实时音视频传输状态通知 通知丢包率 // TODO 发送9105 实时音视频传输状态通知 通知丢包率
StreamInfo info = onPublishHandler(mediaServer, hookData, phoneNumber, channelId); StreamInfo info = onPublishHandler(mediaServer, hookData, phoneNumber, channelId);
@ -184,6 +188,8 @@ public class jt1078ServiceImpl implements Ijt1078Service {
subscribe.removeSubscribe(hook); subscribe.removeSubscribe(hook);
redisTemplate.opsForValue().set(playKey, info); redisTemplate.opsForValue().set(playKey, info);
}); });
// 开启收流端口
SSRCInfo ssrcInfo = mediaServerService.openRTPServer(mediaServer, stream, "000", false, false, 0, false, false, false, 1);
// 设置超时监听 // 设置超时监听
dynamicTask.startDelay(playKey, () -> { dynamicTask.startDelay(playKey, () -> {
logger.info("[1078-点播] 超时, phoneNumber {} channelId {}", phoneNumber, channelId); logger.info("[1078-点播] 超时, phoneNumber {} channelId {}", phoneNumber, channelId);
@ -191,11 +197,10 @@ public class jt1078ServiceImpl implements Ijt1078Service {
errorCallback.run(InviteErrorCode.ERROR_FOR_SIGNALLING_TIMEOUT.getCode(), errorCallback.run(InviteErrorCode.ERROR_FOR_SIGNALLING_TIMEOUT.getCode(),
InviteErrorCode.ERROR_FOR_SIGNALLING_TIMEOUT.getMsg(), null); InviteErrorCode.ERROR_FOR_SIGNALLING_TIMEOUT.getMsg(), null);
} }
mediaServerService.closeRTPServer(mediaServer, stream);
subscribe.removeSubscribe(hook);
}, userSetting.getPlayTimeout()); }, userSetting.getPlayTimeout());
// 开启收流端口
SSRCInfo ssrcInfo = mediaServerService.openRTPServer(mediaServer, stream, null, false, false, 0, false, false, false, 1);
logger.info("[1078-点播] phoneNumber {} channelId {} 端口: {}", phoneNumber, channelId, ssrcInfo.getPort()); logger.info("[1078-点播] phoneNumber {} channelId {} 端口: {}", phoneNumber, channelId, ssrcInfo.getPort());
J9101 j9101 = new J9101(); J9101 j9101 = new J9101();
j9101.setChannel(Integer.valueOf(channelId)); j9101.setChannel(Integer.valueOf(channelId));
@ -204,9 +209,7 @@ public class jt1078ServiceImpl implements Ijt1078Service {
j9101.setTcpPort(ssrcInfo.getPort()); j9101.setTcpPort(ssrcInfo.getPort());
j9101.setUdpPort(ssrcInfo.getPort()); j9101.setUdpPort(ssrcInfo.getPort());
j9101.setType(type); j9101.setType(type);
Object s = jt1078Template.startLive(phoneNumber, j9101, 6); jt1078Template.startLive(phoneNumber, j9101, 6);
System.out.println("ssss=== " + s);
} }
public StreamInfo onPublishHandler(MediaServer mediaServerItem, HookData hookData, String phoneNumber, String channelId) { public StreamInfo onPublishHandler(MediaServer mediaServerItem, HookData hookData, String phoneNumber, String channelId) {
@ -1011,8 +1014,21 @@ public class jt1078ServiceImpl implements Ijt1078Service {
@Override @Override
public PageInfo<JTChannel> getChannelList(int page, int count, int deviceId, String query) { public PageInfo<JTChannel> getChannelList(int page, int count, int deviceId, String query) {
JTDevice device = getDeviceById(deviceId);
if (device == null) {
throw new ControllerException(ErrorCode.ERROR100.getCode(), "设备不存在");
}
PageHelper.startPage(page, count); PageHelper.startPage(page, count);
List<JTChannel> all = jtChannelMapper.getAll(deviceId, query); List<JTChannel> all = jtChannelMapper.getAll(deviceId, query);
PageInfo<JTChannel> jtChannelPageInfo = new PageInfo<>(all);
for (JTChannel jtChannel : jtChannelPageInfo.getList()) {
String playKey = VideoManagerConstants.INVITE_INFO_1078_PLAY + device.getPhoneNumber() + ":" + jtChannel.getChannelId();
StreamInfo streamInfo = (StreamInfo) redisTemplate.opsForValue().get(playKey);
if (streamInfo != null) {
jtChannel.setStream(streamInfo.getStream());
}
}
return new PageInfo<>(all); return new PageInfo<>(all);
} }
@ -1024,6 +1040,10 @@ public class jt1078ServiceImpl implements Ijt1078Service {
@Override @Override
public void addChannel(JTChannel channel) { public void addChannel(JTChannel channel) {
JTChannel channelInDb = jtChannelMapper.getChannel(channel.getTerminalDbId(), channel.getChannelId());
if (channelInDb != null) {
throw new ControllerException(ErrorCode.ERROR100.getCode(), "通道已存在");
}
channel.setCreateTime(DateUtil.getNow()); channel.setCreateTime(DateUtil.getNow());
channel.setUpdateTime(DateUtil.getNow()); channel.setUpdateTime(DateUtil.getNow());
jtChannelMapper.add(channel); jtChannelMapper.add(channel);

View File

@ -52,7 +52,7 @@
</el-button> </el-button>
<el-button size="medium" v-bind:disabled="device == null || device.online === 0" <el-button size="medium" v-bind:disabled="device == null || device.online === 0"
icon="el-icon-switch-button" icon="el-icon-switch-button"
type="text" style="color: #f56c6c" v-if="!!scope.row.streamId" type="text" style="color: #f56c6c" v-if="!!scope.row.stream"
@click="stopDevicePush(scope.row)">停止 @click="stopDevicePush(scope.row)">停止
</el-button> </el-button>
<el-divider direction="vertical"></el-divider> <el-divider direction="vertical"></el-divider>
@ -162,8 +162,9 @@ export default {
this.currentPage = 1; this.currentPage = 1;
this.count = 15; this.count = 15;
this.deviceService.getDevice(this.deviceId, (result) => { this.deviceService.getDevice(this.deviceId, (result) => {
this.device = result; if (result.code === 0) {
this.device = result.data;
}
}, (error) => { }, (error) => {
console.log("获取设备信息失败") console.log("获取设备信息失败")
console.error(error) console.error(error)
@ -180,6 +181,7 @@ export default {
getDeviceChannelList: function () { getDeviceChannelList: function () {
if (typeof (this.deviceId) == "undefined") return; if (typeof (this.deviceId) == "undefined") return;
this.deviceService.getAllChannel(this.currentPage, this.count, this.searchSrt, this.deviceId, (data)=>{ this.deviceService.getAllChannel(this.currentPage, this.count, this.searchSrt, this.deviceId, (data)=>{
console.log(data)
if (data.code === 0) { if (data.code === 0) {
this.total = data.data.total; this.total = data.data.total;
this.deviceChannelList = data.data.list; this.deviceChannelList = data.data.list;
@ -197,6 +199,7 @@ export default {
this.isLoging = true; this.isLoging = true;
let channelId = itemData.channelId; let channelId = itemData.channelId;
console.log("通知设备推流1" + deviceId + " : " + channelId); console.log("通知设备推流1" + deviceId + " : " + channelId);
console.log(this.device);
let that = this; let that = this;
this.$axios({ this.$axios({
method: 'get', method: 'get',

View File

@ -69,7 +69,7 @@ export default {
method: 'post', method: 'post',
url:`/api/jt1078/terminal/channel/${this.isEdit?'update':'add'}/`, url:`/api/jt1078/terminal/channel/${this.isEdit?'update':'add'}/`,
params: { params: {
terminalId: this.deviceId, terminalDbId: this.deviceId,
name: this.form.name, name: this.form.name,
channelId: this.form.channelId, channelId: this.form.channelId,
} }

View File

@ -30,6 +30,8 @@ class JTDeviceService{
deviceId: deviceId deviceId: deviceId
}, },
}).then((res) => { }).then((res) => {
console.log(11)
console.log(res)
if (typeof (callback) == "function") callback(res.data) if (typeof (callback) == "function") callback(res.data)
}).catch((error) => { }).catch((error) => {
console.log(error); console.log(error);
@ -53,7 +55,7 @@ class JTDeviceService{
getAllChannel(currentPage, count, searchSrt, deviceId, callback, endCallback, errorCallback) { getAllChannel(currentPage, count, searchSrt, deviceId, endCallback, errorCallback) {
this.$axios({ this.$axios({
method: 'get', method: 'get',
url: `/api/jt1078/terminal/channel/list`, url: `/api/jt1078/terminal/channel/list`,

View File

@ -338,13 +338,13 @@ create table wvp_jt_terminal (
); );
create table wvp_jt_channel ( create table wvp_jt_channel (
id serial primary key, id serial primary key,
terminal_db_id integer,
channel_id integer, channel_id integer,
terminal_id integer,
has_audio bool default false, has_audio bool default false,
name character varying(255), name character varying(255),
update_time character varying(50) not null, update_time character varying(50) not null,
create_time character varying(50) not null, create_time character varying(50) not null,
constraint uk_jt_device_id_device_id unique (id, terminal_id) constraint uk_jt_device_id_device_id unique (terminal_db_id, channel_id)
); );
/*初始数据*/ /*初始数据*/

View File

@ -338,13 +338,13 @@ create table wvp_jt_terminal (
); );
create table wvp_jt_channel ( create table wvp_jt_channel (
id serial primary key, id serial primary key,
terminal_db_id integer,
channel_id integer, channel_id integer,
terminal_id integer,
has_audio bool default false, has_audio bool default false,
name character varying(255), name character varying(255),
update_time character varying(50) not null, update_time character varying(50) not null,
create_time character varying(50) not null, create_time character varying(50) not null,
constraint uk_jt_device_id_device_id unique (id, terminal_id) constraint uk_jt_device_id_device_id unique (terminal_db_id, channel_id)
); );
/*初始数据*/ /*初始数据*/

View File

@ -22,11 +22,12 @@ create table wvp_jt_terminal (
create table wvp_jt_channel ( create table wvp_jt_channel (
id serial primary key, id serial primary key,
terminal_id integer, terminal_db_id integer,
channel_id integer, channel_id integer,
has_audio bool default false, has_audio bool default false,
name character varying(255), name character varying(255),
update_time character varying(50) not null, update_time character varying(50) not null,
create_time character varying(50) not null create_time character varying(50) not null,
constraint uk_jt_device_id_device_id unique (terminal_db_id, channel_id)
); );

View File

@ -21,11 +21,11 @@ create table wvp_jt_terminal (
); );
create table wvp_jt_channel ( create table wvp_jt_channel (
id serial primary key, id serial primary key,
terminal_db_id integer,
channel_id integer, channel_id integer,
terminal_id integer,
has_audio bool default false, has_audio bool default false,
name character varying(255), name character varying(255),
update_time character varying(50) not null, update_time character varying(50) not null,
create_time character varying(50) not null, create_time character varying(50) not null,
constraint uk_jt_device_id_device_id unique (id, terminal_id) constraint uk_jt_device_id_device_id unique (terminal_db_id, channel_id)
); );