Browse Source

优化播放程序,缩短播放加载时间

pull/1/head
Lawrence 4 years ago
parent
commit
f68cfd8de2
  1. 70
      src/main/java/com/genersoft/iot/vmp/vmanager/play/PlayController.java
  2. 23
      web_src/src/components/channelList.vue
  3. 2
      web_src/src/components/gb28181/devicePlayer.vue

70
src/main/java/com/genersoft/iot/vmp/vmanager/play/PlayController.java

@ -39,7 +39,8 @@ public class PlayController {
private ZLMRESTfulUtils zlmresTfulUtils; private ZLMRESTfulUtils zlmresTfulUtils;
@GetMapping("/play/{deviceId}/{channelId}") @GetMapping("/play/{deviceId}/{channelId}")
public ResponseEntity<String> play(@PathVariable String deviceId, @PathVariable String channelId) { public ResponseEntity<String> play(@PathVariable String deviceId, @PathVariable String channelId,
Integer getEncoding) {
Device device = storager.queryVideoDevice(deviceId); Device device = storager.queryVideoDevice(deviceId);
StreamInfo streamInfo = storager.queryPlayByDevice(deviceId, channelId); StreamInfo streamInfo = storager.queryPlayByDevice(deviceId, channelId);
@ -64,40 +65,49 @@ public class PlayController {
long startTime = System.currentTimeMillis(); long startTime = System.currentTimeMillis();
JSONObject rtpInfo = null; JSONObject rtpInfo = null;
while (lockFlag) { if (getEncoding == 1) {
try { while (lockFlag) {
if (System.currentTimeMillis() - startTime > 60 * 1000) { try {
storager.stopPlay(streamInfo); if (System.currentTimeMillis() - startTime > 60 * 1000) {
logger.info("播放等待超时"); storager.stopPlay(streamInfo);
return new ResponseEntity<String>("timeout", HttpStatus.OK); logger.info("播放等待超时");
} else { return new ResponseEntity<String>("timeout", HttpStatus.OK);
streamInfo = storager.queryPlayByDevice(deviceId, channelId); } else {
if (!rtpPushed) { streamInfo = storager.queryPlayByDevice(deviceId, channelId);
logger.info("查询RTP推流信息..."); if (!rtpPushed) {
rtpInfo = zlmresTfulUtils.getRtpInfo(streamId); logger.info("查询RTP推流信息...");
} rtpInfo = zlmresTfulUtils.getRtpInfo(streamId);
if (rtpInfo != null && rtpInfo.getBoolean("exist") && streamInfo != null && streamInfo.getFlv() != null) { }
logger.info("查询流编码信息:" + streamInfo.getFlv()); if (rtpInfo != null && rtpInfo.getBoolean("exist") && streamInfo != null
rtpPushed = true; && streamInfo.getFlv() != null) {
Thread.sleep(2000); logger.info("查询流编码信息:" + streamInfo.getFlv());
JSONObject mediaInfo = zlmresTfulUtils.getMediaInfo("rtp", "rtmp", streamId); rtpPushed = true;
if (mediaInfo.getInteger("code") == 0 && mediaInfo.getBoolean("online")) { Thread.sleep(2000);
lockFlag = false; JSONObject mediaInfo = zlmresTfulUtils.getMediaInfo("rtp", "rtmp", streamId);
logger.info("流编码信息已获取"); if (mediaInfo.getInteger("code") == 0 && mediaInfo.getBoolean("online")) {
JSONArray tracks = mediaInfo.getJSONArray("tracks"); lockFlag = false;
streamInfo.setTracks(tracks); logger.info("流编码信息已获取");
storager.startPlay(streamInfo); JSONArray tracks = mediaInfo.getJSONArray("tracks");
streamInfo.setTracks(tracks);
storager.startPlay(streamInfo);
} else {
logger.info("流编码信息未获取,2秒后重试...");
}
} else { } else {
logger.info("流编码信息未获取,2秒后重试..."); Thread.sleep(2000);
continue;
} }
} else {
Thread.sleep(2000);
continue;
} }
} catch (InterruptedException e) {
e.printStackTrace();
} }
} catch (InterruptedException e) {
e.printStackTrace();
} }
} else {
String flv = storager.getMediaInfo().getLocalIP() + ":" + storager.getMediaInfo().getHttpPort() + "/rtp/"
+ streamId + ".flv";
streamInfo.setFlv("http://" + flv);
streamInfo.setWs_flv("ws://" + flv);
storager.startPlay(streamInfo);
} }
if (logger.isDebugEnabled()) { if (logger.isDebugEnabled()) {

23
web_src/src/components/channelList.vue

@ -58,8 +58,8 @@
<el-button size="mini" icon="el-icon-video-play" @click="sendDevicePush(scope.row)">播放</el-button> <el-button size="mini" icon="el-icon-video-play" @click="sendDevicePush(scope.row)">播放</el-button>
<el-button size="mini" icon="el-icon-switch-button" type="danger" v-if="scope.row.play" @click="stopDevicePush(scope.row)">停止</el-button> <el-button size="mini" icon="el-icon-switch-button" type="danger" v-if="scope.row.play" @click="stopDevicePush(scope.row)">停止</el-button>
<el-button size="mini" icon="el-icon-s-open" type="primary" v-if="scope.row.parental == 1" @click="changeSubchannel(scope.row)">查看</el-button> <el-button size="mini" icon="el-icon-s-open" type="primary" v-if="scope.row.parental == 1" @click="changeSubchannel(scope.row)">查看</el-button>
<el-button size="mini" icon="el-icon-video-camera" type="primary" @click="queryRecords(scope.row)">设备录象</el-button> <el-button size="mini" icon="el-icon-video-camera" type="primary" @click="queryRecords(scope.row)">设备录象</el-button>
<!-- <el-button size="mini" @click="sendDevicePush(scope.row)">录像查询</el-button> --> <!-- <el-button size="mini" @click="sendDevicePush(scope.row)">录像查询</el-button> -->
</el-button-group> </el-button-group>
</template> </template>
</el-table-column> </el-table-column>
@ -197,20 +197,21 @@ export default {
let deviceId = this.deviceId; let deviceId = this.deviceId;
this.isLoging = true; this.isLoging = true;
let channelId = itemData.channelId; let channelId = itemData.channelId;
console.log("通知设备推流1:" + deviceId + " : " + channelId); let getEncoding = itemData.hasAudio ? '1' : '0'
console.log("通知设备推流1:" + deviceId + " : " + channelId + ":" + getEncoding);
let that = this; let that = this;
this.$axios({ this.$axios({
method: 'get', method: 'get',
url: '/api/play/' + deviceId + '/' + channelId url: '/api/play/' + deviceId + '/' + channelId + '?getEncoding=' + getEncoding
}).then(function (res) { }).then(function (res) {
console.log(res.data) console.log(res.data)
let ssrc = res.data.ssrc; let ssrc = res.data.ssrc;
that.isLoging = false; that.isLoging = false;
if (!!ssrc) { if (!!ssrc) {
// that.$refs.devicePlayer.play(res.data, deviceId, channelId, itemData.hasAudio); // that.$refs.devicePlayer.play(res.data, deviceId, channelId, itemData.hasAudio);
that.$refs.devicePlayer.openDialog("media", deviceId, channelId,{ that.$refs.devicePlayer.openDialog("media", deviceId, channelId, {
streamInfo: res.data, streamInfo: res.data,
hasAudio: itemData.hasAudio hasAudio: itemData.hasAudio
}); });
that.initData(); that.initData();
} else { } else {
@ -219,10 +220,10 @@ export default {
}).catch(function (e) {}); }).catch(function (e) {});
}, },
queryRecords: function (itemData) { queryRecords: function (itemData) {
var format = moment().format("YYYY-M-D"); var format = moment().format("YYYY-M-D");
let deviceId = this.deviceId; let deviceId = this.deviceId;
let channelId = itemData.channelId; let channelId = itemData.channelId;
this.$refs.devicePlayer.openDialog("record", deviceId, channelId, {date:format}) this.$refs.devicePlayer.openDialog("record", deviceId, channelId, {date: format})
}, },
stopDevicePush: function (itemData) { stopDevicePush: function (itemData) {
console.log(itemData) console.log(itemData)

2
web_src/src/components/gb28181/devicePlayer.vue

@ -223,7 +223,7 @@ export default {
play: function (streamInfo, hasAudio) { play: function (streamInfo, hasAudio) {
this.hasaudio = hasAudio; this.hasaudio = hasAudio;
// //
if (!!streamInfo.tracks && streamInfo.tracks.length > 0) { if (!!streamInfo.tracks && streamInfo.tracks.length > 0 && hasAudio) {
var realHasAudio = false; var realHasAudio = false;
for (let i = 0; i < streamInfo.tracks.length; i++) { for (let i = 0; i < streamInfo.tracks.length; i++) {
if (streamInfo.tracks[i].codec_type == 1 && streamInfo.tracks[i].codec_id_name == "CodecAAC") { // AAC if (streamInfo.tracks[i].codec_type == 1 && streamInfo.tracks[i].codec_id_name == "CodecAAC") { // AAC

Loading…
Cancel
Save