[推流设备] 修复推流中重启服务导致无法继续播放

pull/1733/head
648540858 2024-12-27 10:42:40 +08:00
parent 3ea236efdd
commit 460f73555e
3 changed files with 66 additions and 65 deletions

View File

@ -106,63 +106,62 @@ public class MediaInfo {
}
}
JSONArray jsonArray = jsonObject.getJSONArray("tracks");
if (jsonArray.isEmpty()) {
return null;
}
for (int i = 0; i < jsonArray.size(); i++) {
JSONObject trackJson = jsonArray.getJSONObject(i);
Integer channels = trackJson.getInteger("channels");
Integer codecId = trackJson.getInteger("codec_id");
Integer codecType = trackJson.getInteger("codec_type");
Integer sampleRate = trackJson.getInteger("sample_rate");
Integer height = trackJson.getInteger("height");
Integer width = trackJson.getInteger("width");
Integer fps = trackJson.getInteger("fps");
Integer loss = trackJson.getInteger("loss");
Integer frames = trackJson.getInteger("frames");
Long keyFrames = trackJson.getLongValue("key_frames");
Integer gop_interval_ms = trackJson.getInteger("gop_interval_ms");
Long gop_size = trackJson.getLongValue("gop_size");
if (!jsonArray.isEmpty()) {
for (int i = 0; i < jsonArray.size(); i++) {
JSONObject trackJson = jsonArray.getJSONObject(i);
Integer channels = trackJson.getInteger("channels");
Integer codecId = trackJson.getInteger("codec_id");
Integer codecType = trackJson.getInteger("codec_type");
Integer sampleRate = trackJson.getInteger("sample_rate");
Integer height = trackJson.getInteger("height");
Integer width = trackJson.getInteger("width");
Integer fps = trackJson.getInteger("fps");
Integer loss = trackJson.getInteger("loss");
Integer frames = trackJson.getInteger("frames");
Long keyFrames = trackJson.getLongValue("key_frames");
Integer gop_interval_ms = trackJson.getInteger("gop_interval_ms");
Long gop_size = trackJson.getLongValue("gop_size");
Long duration = trackJson.getLongValue("duration");
if (channels != null) {
mediaInfo.setAudioChannels(channels);
}
if (sampleRate != null) {
mediaInfo.setAudioSampleRate(sampleRate);
}
if (height != null) {
mediaInfo.setHeight(height);
}
if (width != null) {
mediaInfo.setWidth(width);
}
if (fps != null) {
mediaInfo.setFps(fps);
}
if (loss != null) {
mediaInfo.setLoss(loss);
}
if (duration > 0L) {
mediaInfo.setDuration(duration);
}
if (codecId != null) {
switch (codecId) {
case 0:
mediaInfo.setVideoCodec("H264");
break;
case 1:
mediaInfo.setVideoCodec("H265");
break;
case 2:
mediaInfo.setAudioCodec("AAC");
break;
case 3:
mediaInfo.setAudioCodec("G711A");
break;
case 4:
mediaInfo.setAudioCodec("G711U");
break;
Long duration = trackJson.getLongValue("duration");
if (channels != null) {
mediaInfo.setAudioChannels(channels);
}
if (sampleRate != null) {
mediaInfo.setAudioSampleRate(sampleRate);
}
if (height != null) {
mediaInfo.setHeight(height);
}
if (width != null) {
mediaInfo.setWidth(width);
}
if (fps != null) {
mediaInfo.setFps(fps);
}
if (loss != null) {
mediaInfo.setLoss(loss);
}
if (duration > 0L) {
mediaInfo.setDuration(duration);
}
if (codecId != null) {
switch (codecId) {
case 0:
mediaInfo.setVideoCodec("H264");
break;
case 1:
mediaInfo.setVideoCodec("H265");
break;
case 2:
mediaInfo.setAudioCodec("AAC");
break;
case 3:
mediaInfo.setAudioCodec("G711A");
break;
case 4:
mediaInfo.setAudioCodec("G711U");
break;
}
}
}
}

View File

@ -178,15 +178,17 @@ public class ZLMMediaNodeServerService implements IMediaNodeServerService {
JSONObject mediaList = zlmresTfulUtils.getMediaList(mediaServer, app, stream);
if (mediaList != null) {
if (mediaList.getInteger("code") == 0) {
JSONArray data = mediaList.getJSONArray("data");
if (data == null) {
JSONArray dataArray = mediaList.getJSONArray("data");
if (dataArray == null) {
return streamInfoList;
}
JSONObject mediaJSON = data.getJSONObject(0);
MediaInfo mediaInfo = MediaInfo.getInstance(mediaJSON, mediaServer, userSetting.getServerId());
StreamInfo streamInfo = getStreamInfoByAppAndStream(mediaServer, app, stream, mediaInfo, callId, true);
if (streamInfo != null) {
streamInfoList.add(streamInfo);
for (int i = 0; i < dataArray.size(); i++) {
JSONObject mediaJSON = dataArray.getJSONObject(0);
MediaInfo mediaInfo = MediaInfo.getInstance(mediaJSON, mediaServer, userSetting.getServerId());
StreamInfo streamInfo = getStreamInfoByAppAndStream(mediaServer, mediaInfo.getApp(), mediaInfo.getStream(), mediaInfo, callId, true);
if (streamInfo != null) {
streamInfoList.add(streamInfo);
}
}
}
}

View File

@ -48,9 +48,9 @@ public interface StreamPushMapper {
" from " +
" wvp_stream_push st " +
" LEFT join wvp_device_channel wdc " +
" on st.id = wdc.data_device_id " +
" on wdc.data_type = 2 and st.id = wdc.data_device_id " +
" WHERE " +
" wdc.data_type = 2 " +
" 1=1 " +
" <if test='query != null'> AND (st.app LIKE concat('%',#{query},'%') escape '/' OR st.stream LIKE concat('%',#{query},'%') escape '/' " +
" OR wdc.gb_device_id LIKE concat('%',#{query},'%') escape '/' OR wdc.gb_name LIKE concat('%',#{query},'%') escape '/')</if> " +
" <if test='pushing == true' > AND st.pushing=1</if>" +