Commit 4e8659e156767b7f471725840b331a5ec9be9894
Committed by
GitHub
Merge pull request #10 from lawrencehj/master
优化播放程序,缩短加载时间
Showing
5 changed files
with
91 additions
and
46 deletions
pom.xml
| @@ -163,6 +163,7 @@ | @@ -163,6 +163,7 @@ | ||
| 163 | 163 | ||
| 164 | <build> | 164 | <build> |
| 165 | <plugins> | 165 | <plugins> |
| 166 | + | ||
| 166 | <plugin> | 167 | <plugin> |
| 167 | <groupId>org.springframework.boot</groupId> | 168 | <groupId>org.springframework.boot</groupId> |
| 168 | <artifactId>spring-boot-maven-plugin</artifactId> | 169 | <artifactId>spring-boot-maven-plugin</artifactId> |
| @@ -176,6 +177,18 @@ | @@ -176,6 +177,18 @@ | ||
| 176 | <configuration> | 177 | <configuration> |
| 177 | <source>1.8</source> | 178 | <source>1.8</source> |
| 178 | <target>1.8</target> | 179 | <target>1.8</target> |
| 180 | + <!-- | ||
| 181 | + <webResources> | ||
| 182 | + <resource> | ||
| 183 | + <directory>${project.basedir}/libs</directory> | ||
| 184 | + <targetPath>WEB-INF/lib</targetPath> | ||
| 185 | + <filtering>true</filtering> | ||
| 186 | + <includes> | ||
| 187 | + <include>**/*.jar</include> | ||
| 188 | + </includes> | ||
| 189 | + </resource> | ||
| 190 | + </webResources> | ||
| 191 | + --> | ||
| 179 | </configuration> | 192 | </configuration> |
| 180 | </plugin> | 193 | </plugin> |
| 181 | 194 | ||
| @@ -183,6 +196,7 @@ | @@ -183,6 +196,7 @@ | ||
| 183 | <groupId>org.apache.maven.plugins</groupId> | 196 | <groupId>org.apache.maven.plugins</groupId> |
| 184 | <artifactId>maven-surefire-plugin</artifactId> | 197 | <artifactId>maven-surefire-plugin</artifactId> |
| 185 | </plugin> | 198 | </plugin> |
| 199 | + | ||
| 186 | </plugins> | 200 | </plugins> |
| 187 | </build> | 201 | </build> |
| 188 | </project> | 202 | </project> |
src/main/java/com/genersoft/iot/vmp/storager/redis/VideoManagerRedisStoragerImpl.java
| @@ -276,6 +276,7 @@ public class VideoManagerRedisStoragerImpl implements IVideoManagerStorager { | @@ -276,6 +276,7 @@ public class VideoManagerRedisStoragerImpl implements IVideoManagerStorager { | ||
| 276 | PageResult pageResult = new PageResult<Device>(); | 276 | PageResult pageResult = new PageResult<Device>(); |
| 277 | pageResult.setPage(page); | 277 | pageResult.setPage(page); |
| 278 | pageResult.setCount(count); | 278 | pageResult.setCount(count); |
| 279 | + Device device = null; | ||
| 279 | 280 | ||
| 280 | if (deviceIds == null || deviceIds.length == 0) { | 281 | if (deviceIds == null || deviceIds.length == 0) { |
| 281 | 282 | ||
| @@ -284,11 +285,21 @@ public class VideoManagerRedisStoragerImpl implements IVideoManagerStorager { | @@ -284,11 +285,21 @@ public class VideoManagerRedisStoragerImpl implements IVideoManagerStorager { | ||
| 284 | pageResult.setTotal(deviceIdList.size()); | 285 | pageResult.setTotal(deviceIdList.size()); |
| 285 | int maxCount = (page + 1)* count; | 286 | int maxCount = (page + 1)* count; |
| 286 | for (int i = page * count; i < (pageResult.getTotal() > maxCount ? maxCount : pageResult.getTotal() ); i++) { | 287 | for (int i = page * count; i < (pageResult.getTotal() > maxCount ? maxCount : pageResult.getTotal() ); i++) { |
| 287 | - devices.add((Device)redis.get((String)deviceIdList.get(i))); | 288 | + // devices.add((Device)redis.get((String)deviceIdList.get(i))); |
| 289 | + device =(Device)redis.get((String)deviceIdList.get(i)); | ||
| 290 | + if (redis.scan(VideoManagerConstants.KEEPLIVEKEY_PREFIX+device.getDeviceId()).size() == 0){ | ||
| 291 | + outline(device.getDeviceId()); | ||
| 292 | + } | ||
| 293 | + devices.add(device); | ||
| 288 | } | 294 | } |
| 289 | } else { | 295 | } else { |
| 290 | for (int i = 0; i < deviceIds.length; i++) { | 296 | for (int i = 0; i < deviceIds.length; i++) { |
| 291 | - devices.add((Device)redis.get(VideoManagerConstants.DEVICE_PREFIX+deviceIds[i])); | 297 | + // devices.add((Device)redis.get(VideoManagerConstants.DEVICE_PREFIX+deviceIds[i])); |
| 298 | + device = (Device)redis.get(VideoManagerConstants.DEVICE_PREFIX+deviceIds[i]); | ||
| 299 | + if (redis.scan(VideoManagerConstants.KEEPLIVEKEY_PREFIX+device.getDeviceId()).size() == 0){ | ||
| 300 | + outline(device.getDeviceId()); | ||
| 301 | + } | ||
| 302 | + devices.add(device); | ||
| 292 | } | 303 | } |
| 293 | } | 304 | } |
| 294 | pageResult.setData(devices); | 305 | pageResult.setData(devices); |
| @@ -304,16 +315,25 @@ public class VideoManagerRedisStoragerImpl implements IVideoManagerStorager { | @@ -304,16 +315,25 @@ public class VideoManagerRedisStoragerImpl implements IVideoManagerStorager { | ||
| 304 | @Override | 315 | @Override |
| 305 | public List<Device> queryVideoDeviceList(String[] deviceIds) { | 316 | public List<Device> queryVideoDeviceList(String[] deviceIds) { |
| 306 | List<Device> devices = new ArrayList<>(); | 317 | List<Device> devices = new ArrayList<>(); |
| 318 | + Device device = null; | ||
| 307 | 319 | ||
| 308 | if (deviceIds == null || deviceIds.length == 0) { | 320 | if (deviceIds == null || deviceIds.length == 0) { |
| 309 | // List<Object> deviceIdList = redis.keys(VideoManagerConstants.DEVICE_PREFIX+"*"); | 321 | // List<Object> deviceIdList = redis.keys(VideoManagerConstants.DEVICE_PREFIX+"*"); |
| 310 | List<Object> deviceIdList = redis.scan(VideoManagerConstants.DEVICE_PREFIX+"*"); | 322 | List<Object> deviceIdList = redis.scan(VideoManagerConstants.DEVICE_PREFIX+"*"); |
| 311 | for (int i = 0; i < deviceIdList.size(); i++) { | 323 | for (int i = 0; i < deviceIdList.size(); i++) { |
| 312 | - devices.add((Device)redis.get((String)deviceIdList.get(i))); | 324 | + device =(Device)redis.get((String)deviceIdList.get(i)); |
| 325 | + if (redis.scan(VideoManagerConstants.KEEPLIVEKEY_PREFIX+device.getDeviceId()).size() == 0){ | ||
| 326 | + outline(device.getDeviceId()); | ||
| 327 | + } | ||
| 328 | + devices.add(device); | ||
| 313 | } | 329 | } |
| 314 | } else { | 330 | } else { |
| 315 | for (int i = 0; i < deviceIds.length; i++) { | 331 | for (int i = 0; i < deviceIds.length; i++) { |
| 316 | - devices.add((Device)redis.get(VideoManagerConstants.DEVICE_PREFIX+deviceIds[i])); | 332 | + device = (Device)redis.get(VideoManagerConstants.DEVICE_PREFIX+deviceIds[i]); |
| 333 | + if (redis.scan(VideoManagerConstants.KEEPLIVEKEY_PREFIX+device.getDeviceId()).size() == 0){ | ||
| 334 | + outline(device.getDeviceId()); | ||
| 335 | + } | ||
| 336 | + devices.add(device); | ||
| 317 | } | 337 | } |
| 318 | } | 338 | } |
| 319 | return devices; | 339 | return devices; |
src/main/java/com/genersoft/iot/vmp/vmanager/play/PlayController.java
| @@ -39,7 +39,8 @@ public class PlayController { | @@ -39,7 +39,8 @@ public class PlayController { | ||
| 39 | private ZLMRESTfulUtils zlmresTfulUtils; | 39 | private ZLMRESTfulUtils zlmresTfulUtils; |
| 40 | 40 | ||
| 41 | @GetMapping("/play/{deviceId}/{channelId}") | 41 | @GetMapping("/play/{deviceId}/{channelId}") |
| 42 | - public ResponseEntity<String> play(@PathVariable String deviceId, @PathVariable String channelId) { | 42 | + public ResponseEntity<String> play(@PathVariable String deviceId, @PathVariable String channelId, |
| 43 | + Integer getEncoding) { | ||
| 43 | 44 | ||
| 44 | Device device = storager.queryVideoDevice(deviceId); | 45 | Device device = storager.queryVideoDevice(deviceId); |
| 45 | StreamInfo streamInfo = storager.queryPlayByDevice(deviceId, channelId); | 46 | StreamInfo streamInfo = storager.queryPlayByDevice(deviceId, channelId); |
| @@ -64,40 +65,49 @@ public class PlayController { | @@ -64,40 +65,49 @@ public class PlayController { | ||
| 64 | long startTime = System.currentTimeMillis(); | 65 | long startTime = System.currentTimeMillis(); |
| 65 | JSONObject rtpInfo = null; | 66 | JSONObject rtpInfo = null; |
| 66 | 67 | ||
| 67 | - while (lockFlag) { | ||
| 68 | - try { | ||
| 69 | - if (System.currentTimeMillis() - startTime > 60 * 1000) { | ||
| 70 | - storager.stopPlay(streamInfo); | ||
| 71 | - logger.info("播放等待超时"); | ||
| 72 | - return new ResponseEntity<String>("timeout", HttpStatus.OK); | ||
| 73 | - } else { | ||
| 74 | - streamInfo = storager.queryPlayByDevice(deviceId, channelId); | ||
| 75 | - if (!rtpPushed) { | ||
| 76 | - logger.info("查询RTP推流信息..."); | ||
| 77 | - rtpInfo = zlmresTfulUtils.getRtpInfo(streamId); | ||
| 78 | - } | ||
| 79 | - if (rtpInfo != null && rtpInfo.getBoolean("exist") && streamInfo != null && streamInfo.getFlv() != null) { | ||
| 80 | - logger.info("查询流编码信息:" + streamInfo.getFlv()); | ||
| 81 | - rtpPushed = true; | ||
| 82 | - Thread.sleep(2000); | ||
| 83 | - JSONObject mediaInfo = zlmresTfulUtils.getMediaInfo("rtp", "rtmp", streamId); | ||
| 84 | - if (mediaInfo.getInteger("code") == 0 && mediaInfo.getBoolean("online")) { | ||
| 85 | - lockFlag = false; | ||
| 86 | - logger.info("流编码信息已获取"); | ||
| 87 | - JSONArray tracks = mediaInfo.getJSONArray("tracks"); | ||
| 88 | - streamInfo.setTracks(tracks); | ||
| 89 | - storager.startPlay(streamInfo); | 68 | + if (getEncoding == 1) { |
| 69 | + while (lockFlag) { | ||
| 70 | + try { | ||
| 71 | + if (System.currentTimeMillis() - startTime > 60 * 1000) { | ||
| 72 | + storager.stopPlay(streamInfo); | ||
| 73 | + logger.info("播放等待超时"); | ||
| 74 | + return new ResponseEntity<String>("timeout", HttpStatus.OK); | ||
| 75 | + } else { | ||
| 76 | + streamInfo = storager.queryPlayByDevice(deviceId, channelId); | ||
| 77 | + if (!rtpPushed) { | ||
| 78 | + logger.info("查询RTP推流信息..."); | ||
| 79 | + rtpInfo = zlmresTfulUtils.getRtpInfo(streamId); | ||
| 80 | + } | ||
| 81 | + if (rtpInfo != null && rtpInfo.getBoolean("exist") && streamInfo != null | ||
| 82 | + && streamInfo.getFlv() != null) { | ||
| 83 | + logger.info("查询流编码信息:" + streamInfo.getFlv()); | ||
| 84 | + rtpPushed = true; | ||
| 85 | + Thread.sleep(2000); | ||
| 86 | + JSONObject mediaInfo = zlmresTfulUtils.getMediaInfo("rtp", "rtmp", streamId); | ||
| 87 | + if (mediaInfo.getInteger("code") == 0 && mediaInfo.getBoolean("online")) { | ||
| 88 | + lockFlag = false; | ||
| 89 | + logger.info("流编码信息已获取"); | ||
| 90 | + JSONArray tracks = mediaInfo.getJSONArray("tracks"); | ||
| 91 | + streamInfo.setTracks(tracks); | ||
| 92 | + storager.startPlay(streamInfo); | ||
| 93 | + } else { | ||
| 94 | + logger.info("流编码信息未获取,2秒后重试..."); | ||
| 95 | + } | ||
| 90 | } else { | 96 | } else { |
| 91 | - logger.info("流编码信息未获取,2秒后重试..."); | 97 | + Thread.sleep(2000); |
| 98 | + continue; | ||
| 92 | } | 99 | } |
| 93 | - } else { | ||
| 94 | - Thread.sleep(2000); | ||
| 95 | - continue; | ||
| 96 | } | 100 | } |
| 101 | + } catch (InterruptedException e) { | ||
| 102 | + e.printStackTrace(); | ||
| 97 | } | 103 | } |
| 98 | - } catch (InterruptedException e) { | ||
| 99 | - e.printStackTrace(); | ||
| 100 | } | 104 | } |
| 105 | + } else { | ||
| 106 | + String flv = storager.getMediaInfo().getLocalIP() + ":" + storager.getMediaInfo().getHttpPort() + "/rtp/" | ||
| 107 | + + streamId + ".flv"; | ||
| 108 | + streamInfo.setFlv("http://" + flv); | ||
| 109 | + streamInfo.setWs_flv("ws://" + flv); | ||
| 110 | + storager.startPlay(streamInfo); | ||
| 101 | } | 111 | } |
| 102 | 112 | ||
| 103 | if (logger.isDebugEnabled()) { | 113 | if (logger.isDebugEnabled()) { |
web_src/src/components/channelList.vue
| @@ -58,8 +58,8 @@ | @@ -58,8 +58,8 @@ | ||
| 58 | <el-button size="mini" icon="el-icon-video-play" @click="sendDevicePush(scope.row)">播放</el-button> | 58 | <el-button size="mini" icon="el-icon-video-play" @click="sendDevicePush(scope.row)">播放</el-button> |
| 59 | <el-button size="mini" icon="el-icon-switch-button" type="danger" v-if="scope.row.play" @click="stopDevicePush(scope.row)">停止</el-button> | 59 | <el-button size="mini" icon="el-icon-switch-button" type="danger" v-if="scope.row.play" @click="stopDevicePush(scope.row)">停止</el-button> |
| 60 | <el-button size="mini" icon="el-icon-s-open" type="primary" v-if="scope.row.parental == 1" @click="changeSubchannel(scope.row)">查看</el-button> | 60 | <el-button size="mini" icon="el-icon-s-open" type="primary" v-if="scope.row.parental == 1" @click="changeSubchannel(scope.row)">查看</el-button> |
| 61 | - <el-button size="mini" icon="el-icon-video-camera" type="primary" @click="queryRecords(scope.row)">设备录象</el-button> | ||
| 62 | -<!-- <el-button size="mini" @click="sendDevicePush(scope.row)">录像查询</el-button> --> | 61 | + <el-button size="mini" icon="el-icon-video-camera" type="primary" @click="queryRecords(scope.row)">设备录象</el-button> |
| 62 | + <!-- <el-button size="mini" @click="sendDevicePush(scope.row)">录像查询</el-button> --> | ||
| 63 | </el-button-group> | 63 | </el-button-group> |
| 64 | </template> | 64 | </template> |
| 65 | </el-table-column> | 65 | </el-table-column> |
| @@ -197,20 +197,21 @@ export default { | @@ -197,20 +197,21 @@ export default { | ||
| 197 | let deviceId = this.deviceId; | 197 | let deviceId = this.deviceId; |
| 198 | this.isLoging = true; | 198 | this.isLoging = true; |
| 199 | let channelId = itemData.channelId; | 199 | let channelId = itemData.channelId; |
| 200 | - console.log("通知设备推流1:" + deviceId + " : " + channelId); | 200 | + let getEncoding = itemData.hasAudio ? '1' : '0' |
| 201 | + console.log("通知设备推流1:" + deviceId + " : " + channelId + ":" + getEncoding); | ||
| 201 | let that = this; | 202 | let that = this; |
| 202 | this.$axios({ | 203 | this.$axios({ |
| 203 | method: 'get', | 204 | method: 'get', |
| 204 | - url: '/api/play/' + deviceId + '/' + channelId | 205 | + url: '/api/play/' + deviceId + '/' + channelId + '?getEncoding=' + getEncoding |
| 205 | }).then(function (res) { | 206 | }).then(function (res) { |
| 206 | console.log(res.data) | 207 | console.log(res.data) |
| 207 | let ssrc = res.data.ssrc; | 208 | let ssrc = res.data.ssrc; |
| 208 | that.isLoging = false; | 209 | that.isLoging = false; |
| 209 | if (!!ssrc) { | 210 | if (!!ssrc) { |
| 210 | // that.$refs.devicePlayer.play(res.data, deviceId, channelId, itemData.hasAudio); | 211 | // that.$refs.devicePlayer.play(res.data, deviceId, channelId, itemData.hasAudio); |
| 211 | - that.$refs.devicePlayer.openDialog("media", deviceId, channelId,{ | ||
| 212 | - streamInfo: res.data, | ||
| 213 | - hasAudio: itemData.hasAudio | 212 | + that.$refs.devicePlayer.openDialog("media", deviceId, channelId, { |
| 213 | + streamInfo: res.data, | ||
| 214 | + hasAudio: itemData.hasAudio | ||
| 214 | }); | 215 | }); |
| 215 | that.initData(); | 216 | that.initData(); |
| 216 | } else { | 217 | } else { |
| @@ -219,10 +220,10 @@ export default { | @@ -219,10 +220,10 @@ export default { | ||
| 219 | }).catch(function (e) {}); | 220 | }).catch(function (e) {}); |
| 220 | }, | 221 | }, |
| 221 | queryRecords: function (itemData) { | 222 | queryRecords: function (itemData) { |
| 222 | - var format = moment().format("YYYY-M-D"); | ||
| 223 | - let deviceId = this.deviceId; | ||
| 224 | - let channelId = itemData.channelId; | ||
| 225 | - this.$refs.devicePlayer.openDialog("record", deviceId, channelId, {date:format}) | 223 | + var format = moment().format("YYYY-M-D"); |
| 224 | + let deviceId = this.deviceId; | ||
| 225 | + let channelId = itemData.channelId; | ||
| 226 | + this.$refs.devicePlayer.openDialog("record", deviceId, channelId, {date: format}) | ||
| 226 | }, | 227 | }, |
| 227 | stopDevicePush: function (itemData) { | 228 | stopDevicePush: function (itemData) { |
| 228 | console.log(itemData) | 229 | console.log(itemData) |
web_src/src/components/gb28181/devicePlayer.vue
| @@ -223,7 +223,7 @@ export default { | @@ -223,7 +223,7 @@ export default { | ||
| 223 | play: function (streamInfo, hasAudio) { | 223 | play: function (streamInfo, hasAudio) { |
| 224 | this.hasaudio = hasAudio; | 224 | this.hasaudio = hasAudio; |
| 225 | // 根据媒体流信息二次判断 | 225 | // 根据媒体流信息二次判断 |
| 226 | - if (!!streamInfo.tracks && streamInfo.tracks.length > 0) { | 226 | + if (!!streamInfo.tracks && streamInfo.tracks.length > 0 && hasAudio) { |
| 227 | var realHasAudio = false; | 227 | var realHasAudio = false; |
| 228 | for (let i = 0; i < streamInfo.tracks.length; i++) { | 228 | for (let i = 0; i < streamInfo.tracks.length; i++) { |
| 229 | if (streamInfo.tracks[i].codec_type == 1 && streamInfo.tracks[i].codec_id_name == "CodecAAC") { // 判断为AAC音频 | 229 | if (streamInfo.tracks[i].codec_type == 1 && streamInfo.tracks[i].codec_id_name == "CodecAAC") { // 判断为AAC音频 |