Commit f9ab13a14590d310937de7d78a36ee599dce750b

Authored by 648540858
1 parent d4ae8194

添加通道音频设置

添加media配置
... ... @@ -145,16 +145,19 @@
145 145 </dependency>
146 146  
147 147 <dependency>
148   - <groupId>org.mitre.dsmiley.httpproxy</groupId>
149   - <artifactId>smiley-http-proxy-servlet</artifactId>
150   - <version>1.7</version>
151   - </dependency>
152   - <dependency>
153 148 <groupId>com.google.guava</groupId>
154 149 <artifactId>guava</artifactId>
155 150 <version>18.0</version>
156 151 </dependency>
157   -
  152 +
  153 + <!-- okhttp -->
  154 + <dependency>
  155 + <groupId>com.squareup.okhttp3</groupId>
  156 + <artifactId>okhttp</artifactId>
  157 + <version>4.9.0</version>
  158 + </dependency>
  159 +
  160 +
158 161 </dependencies>
159 162  
160 163 <build>
... ...
src/main/java/com/genersoft/iot/vmp/gb28181/bean/DeviceChannel.java
... ... @@ -143,6 +143,11 @@ public class DeviceChannel {
143 143 */
144 144 private String ssrc;
145 145  
  146 + /**
  147 + * 是否含有音频
  148 + */
  149 + private boolean hasAudio;
  150 +
146 151 public String getChannelId() {
147 152 return channelId;
148 153 }
... ... @@ -371,4 +376,16 @@ public class DeviceChannel {
371 376 public void setSubCount(int subCount) {
372 377 this.subCount = subCount;
373 378 }
  379 +
  380 + public void setPTZTypeText(String PTZTypeText) {
  381 + this.PTZTypeText = PTZTypeText;
  382 + }
  383 +
  384 + public boolean isHasAudio() {
  385 + return hasAudio;
  386 + }
  387 +
  388 + public void setHasAudio(boolean hasAudio) {
  389 + this.hasAudio = hasAudio;
  390 + }
374 391 }
... ...
src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/impl/SIPCommander.java
... ... @@ -241,13 +241,6 @@ public class SIPCommander implements ISIPCommander {
241 241  
242 242 StreamInfo streamInfo = new StreamInfo();
243 243 streamInfo.setSsrc(ssrc);
244   -// String streamId = Integer.toHexString(Integer.parseInt(streamInfo.getSsrc()));
245   -// String streamId = String.format("%08x", Integer.parseInt(streamInfo.getSsrc())).toUpperCase(); // ZLM 要求大写且首位补零
246   -// streamInfo.setFlv(String.format("http://%s:%s/rtp/%s.flv", mediaInfo.getLocalIP(), mediaInfo.getHttpPort(), streamId));
247   -// streamInfo.setWS_FLV(String.format("ws://%s:%s/rtp/%s.flv", mediaInfo.getLocalIP(), mediaInfo.getHttpPort(), streamId));
248   -// streamInfo.setRTMP(String.format("rtmp://%s:%s/rtp/%s", mediaInfo.getLocalIP(), mediaInfo.getRtmpPort(), streamId));
249   -// streamInfo.setHLS(String.format("http://%s:%s/rtp/%s/hls.m3u8", mediaInfo.getLocalIP(), mediaInfo.getHttpPort(), streamId));
250   -// streamInfo.setRTSP(String.format("rtsp://%s:%s/rtp/%s", mediaInfo.getLocalIP(), mediaInfo.getRtspPort(), streamId));
251 244 streamInfo.setCahnnelId(channelId);
252 245 streamInfo.setDeviceID(device.getDeviceId());
253 246 storager.startPlay(streamInfo);
... ...
src/main/java/com/genersoft/iot/vmp/gb28181/transmit/request/impl/MessageRequestProcessor.java
... ... @@ -200,6 +200,7 @@ public class MessageRequestProcessor extends SIPRequestAbstractProcessor {
200 200 deviceChannel.setLongitude(itemDevice.element("Longitude") == null? 0.00:Double.parseDouble(XmlUtil.getText(itemDevice,"Longitude")));
201 201 deviceChannel.setLatitude(itemDevice.element("Latitude") == null? 0.00:Double.parseDouble(XmlUtil.getText(itemDevice,"Latitude")));
202 202 deviceChannel.setPTZType(itemDevice.element("PTZType") == null? 0:Integer.parseInt(XmlUtil.getText(itemDevice,"PTZType")));
  203 + deviceChannel.setHasAudio(false); // 默认含有音频为false
203 204 storager.updateChannel(device.getDeviceId(), deviceChannel);
204 205 }
205 206 // 更新
... ...
src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMHTTPProxyController.java
... ... @@ -2,7 +2,6 @@ package com.genersoft.iot.vmp.media.zlm;
2 2  
3 3 import com.alibaba.fastjson.JSONObject;
4 4 import com.genersoft.iot.vmp.storager.IVideoManagerStorager;
5   -import org.apache.http.HttpResponse;
6 5 import org.slf4j.Logger;
7 6 import org.slf4j.LoggerFactory;
8 7 import org.springframework.beans.factory.annotation.Autowired;
... ...
src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMHttpHookListener.java
... ... @@ -14,6 +14,7 @@ import com.genersoft.iot.vmp.utils.IpUtil;
14 14 import org.slf4j.Logger;
15 15 import org.slf4j.LoggerFactory;
16 16 import org.springframework.beans.factory.annotation.Autowired;
  17 +import org.springframework.beans.factory.annotation.Value;
17 18 import org.springframework.http.HttpStatus;
18 19 import org.springframework.http.ResponseEntity;
19 20 import org.springframework.web.bind.annotation.PostMapping;
... ... @@ -44,7 +45,13 @@ public class ZLMHttpHookListener {
44 45  
45 46 @Autowired
46 47 private IVideoManagerStorager storager;
47   -
  48 +
  49 + @Value("${media.ip}")
  50 + private String mediaIp;
  51 +
  52 + @Value("${media.port}")
  53 + private int mediaPort;
  54 +
48 55 /**
49 56 * 流量统计事件,播放器或推流器断开时并且耗用流量超过特定阈值时会触发此事件,阈值通过配置文件general.flowThreshold配置;此事件对回复不敏感。
50 57 *
... ... @@ -308,6 +315,7 @@ public class ZLMHttpHookListener {
308 315 // List<MediaServerConfig> mediaServerConfigs = JSON.parseArray(JSON.toJSONString(json), MediaServerConfig.class);
309 316 // MediaServerConfig mediaServerConfig = mediaServerConfigs.get(0);
310 317 MediaServerConfig mediaServerConfig = JSON.toJavaObject(json, MediaServerConfig.class);
  318 + mediaServerConfig.setLocalIP(mediaIp);
311 319 storager.updateMediaInfo(mediaServerConfig);
312 320 // TODO Auto-generated method stub
313 321  
... ...
src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMRunner.java 0 → 100644
  1 +package com.genersoft.iot.vmp.media.zlm;
  2 +
  3 +import com.alibaba.fastjson.JSON;
  4 +import com.alibaba.fastjson.JSONArray;
  5 +import com.alibaba.fastjson.JSONObject;
  6 +import com.genersoft.iot.vmp.conf.MediaServerConfig;
  7 +import com.genersoft.iot.vmp.storager.IVideoManagerStorager;
  8 +import okhttp3.*;
  9 +import org.slf4j.Logger;
  10 +import org.slf4j.LoggerFactory;
  11 +import org.springframework.beans.factory.annotation.Autowired;
  12 +import org.springframework.beans.factory.annotation.Value;
  13 +import org.springframework.boot.CommandLineRunner;
  14 +import org.springframework.core.annotation.Order;
  15 +import org.springframework.stereotype.Component;
  16 +
  17 +import java.io.IOException;
  18 +import java.io.UnsupportedEncodingException;
  19 +import java.net.URLEncoder;
  20 +
  21 +@Component
  22 +@Order(value=1)
  23 +public class ZLMRunner implements CommandLineRunner {
  24 +
  25 + private final static Logger logger = LoggerFactory.getLogger(ZLMRunner.class);
  26 +
  27 + @Autowired
  28 + private IVideoManagerStorager storager;
  29 +
  30 + @Value("${media.ip}")
  31 + private String mediaIp;
  32 +
  33 + @Value("${media.port}")
  34 + private int mediaPort;
  35 +
  36 + @Value("${media.secret}")
  37 + private String mediaSecret;
  38 +
  39 + @Value("${sip.ip}")
  40 + private String sipIP;
  41 +
  42 + @Value("${server.port}")
  43 + private String serverPort;
  44 +
  45 + @Override
  46 + public void run(String... strings) throws Exception {
  47 + // 获取zlm信息
  48 + logger.info("等待zlm接入...");
  49 + MediaServerConfig mediaServerConfig = getMediaServerConfig();
  50 + if (mediaServerConfig != null) {
  51 + logger.info("zlm接入成功...");
  52 + storager.updateMediaInfo(mediaServerConfig);
  53 + logger.info("设置zlm...");
  54 + saveZLMConfig();
  55 +
  56 + }
  57 + }
  58 +
  59 +
  60 +
  61 + public MediaServerConfig getMediaServerConfig() {
  62 + MediaServerConfig mediaServerConfig = null;
  63 + OkHttpClient client = new OkHttpClient();
  64 + String url = String.format("http://%s:%s/index/api/getServerConfig?secret=%s", mediaIp, mediaPort, mediaSecret);
  65 + //创建一个Request
  66 + Request request = new Request.Builder()
  67 + .get()
  68 + .url(url)
  69 + .build();
  70 + //通过client发起请求
  71 + final Call call = client.newCall(request);
  72 + //执行同步请求,获取Response对象
  73 + Response response = null;
  74 + try {
  75 + response = call.execute();
  76 + if (response.isSuccessful()) {
  77 + String responseStr = response.body().string();
  78 + if (responseStr != null) {
  79 + JSONObject responseJSON = JSON.parseObject(responseStr);
  80 + JSONArray data = responseJSON.getJSONArray("data");
  81 + if (data != null && data.size() > 0) {
  82 + mediaServerConfig = JSON.parseObject(JSON.toJSONString(data.get(0)), MediaServerConfig.class);
  83 + mediaServerConfig.setLocalIP(mediaIp);
  84 + }
  85 + }
  86 + }else {
  87 + logger.error("getMediaServerConfig失败, 1s后重试");
  88 + Thread.sleep(1000);
  89 + getMediaServerConfig();
  90 + }
  91 + } catch (IOException e) {
  92 + e.printStackTrace();
  93 + } catch (InterruptedException e) {
  94 + e.printStackTrace();
  95 + }
  96 +
  97 + return mediaServerConfig;
  98 + }
  99 +
  100 + private void saveZLMConfig() {
  101 + String hookIP = sipIP;
  102 + if (mediaIp.equals(sipIP)) {
  103 + hookIP = "127.0.0.1";
  104 + }
  105 + OkHttpClient client = new OkHttpClient();
  106 + String url = String.format("http://%s:%s/index/api/setServerConfig", mediaIp, mediaPort);
  107 + String hookPrex = String.format("http://%s:%s/index/hook", hookIP, serverPort);
  108 +
  109 + RequestBody body = new FormBody.Builder()
  110 + .add("secret",mediaSecret)
  111 + .add("hook.enable","1")
  112 + .add("hook.on_flow_report","")
  113 + .add("hook.on_http_access","")
  114 + .add("hook.on_publish",String.format("%s/on_publish", hookPrex))
  115 + .add("hook.on_record_mp4","")
  116 + .add("hook.on_record_ts","")
  117 + .add("hook.on_rtsp_auth","")
  118 + .add("hook.on_rtsp_realm","")
  119 + .add("hook.on_server_started",String.format("%s/on_server_started", hookPrex))
  120 + .add("hook.on_shell_login",String.format("%s/on_shell_login", hookPrex))
  121 + .add("hook.on_stream_none_reader",String.format("%s/on_stream_none_reader", hookPrex))
  122 + .add("hook.on_stream_not_found",String.format("%s/on_stream_not_found", hookPrex))
  123 + .add("hook.timeoutSec","20")
  124 + .build();
  125 +
  126 + Request request = new Request.Builder()
  127 + .post(body)
  128 + .url(url)
  129 + .build();
  130 + client.newCall(request).enqueue(new Callback() {
  131 + @Override
  132 + public void onFailure(Call call, IOException e) {
  133 + logger.error("saveZLMConfig ",e);
  134 + }
  135 + @Override
  136 + public void onResponse(Call call, Response response) throws IOException {
  137 + if (response.isSuccessful()) {
  138 + String responseStr = response.body().string();
  139 + if (responseStr != null) {
  140 + JSONObject responseJSON = JSON.parseObject(responseStr);
  141 + if (responseJSON.getInteger("code") == 0) {
  142 + logger.info("设置zlm成功");
  143 + }else {
  144 + logger.info("设置zlm失败: " + responseJSON.getString("msg"));
  145 + }
  146 + }
  147 + }
  148 +
  149 + }
  150 + });
  151 + }
  152 +}
... ...
src/main/java/com/genersoft/iot/vmp/storager/redis/VideoManagerRedisStoragerImpl.java
... ... @@ -344,6 +344,7 @@ public class VideoManagerRedisStoragerImpl implements IVideoManagerStorager {
344 344 */
345 345 @Override
346 346 public boolean stopPlay(StreamInfo streamInfo) {
  347 + if (streamInfo == null) return false;
347 348 return redis.del(String.format("%S_%s_%s_%s", VideoManagerConstants.PLAYER_PREFIX,
348 349 streamInfo.getSsrc(),
349 350 streamInfo.getDeviceID(),
... ...
src/main/java/com/genersoft/iot/vmp/vmanager/device/DeviceController.java
... ... @@ -144,4 +144,10 @@ public class DeviceController {
144 144 PageResult pageResult = storager.querySubChannels(deviceId, channelId, query, channelType, online, page, count);
145 145 return new ResponseEntity<>(pageResult,HttpStatus.OK);
146 146 }
  147 +
  148 + @PostMapping("channel/update/{deviceId}")
  149 + public ResponseEntity<PageResult> updateChannel(@PathVariable String deviceId,DeviceChannel channel){
  150 + storager.updateChannel(deviceId, channel);
  151 + return new ResponseEntity<>(null,HttpStatus.OK);
  152 + }
147 153 }
... ...
src/main/java/com/genersoft/iot/vmp/vmanager/play/PlayController.java
... ... @@ -67,6 +67,7 @@ public class PlayController {
67 67  
68 68 cmder.streamByeCmd(ssrc);
69 69 StreamInfo streamInfo = storager.queryPlayBySSRC(ssrc);
  70 + if (streamInfo == null) return new ResponseEntity<String>(HttpStatus.PAYMENT_REQUIRED);
70 71 storager.stopPlay(streamInfo);
71 72 if (logger.isDebugEnabled()) {
72 73 logger.debug(String.format("设备预览停止API调用,ssrc:%s", ssrc));
... ...
src/main/resources/application.yml
... ... @@ -25,7 +25,6 @@ spring:
25 25 server:
26 26 port: 18080
27 27 sip:
28   -# ip: 10.200.64.63
29 28 ip: 192.168.1.20
30 29 port: 5060
31 30 # 根据国标6.1.2中规定,domain宜采用ID统一编码的前十位编码。国标附录D中定义前8位为中心编码(由省级、市级、区级、基层编号组成,参照GB/T 2260-2007)
... ... @@ -38,4 +37,10 @@ sip:
38 37  
39 38 auth: #32位小写md5加密(默认密码为admin)
40 39 username: admin
41   - password: 21232f297a57a5a743894a0e4a801fc3
42 40 \ No newline at end of file
  41 + password: 21232f297a57a5a743894a0e4a801fc3
  42 +
  43 +media: #zlm服务器的ip与http端口, 重点: 这是http端口
  44 + ip: 192.168.1.20
  45 + port: 9080
  46 + secret: 035c73f7-bb6b-4889-a715-d9eb2d1925cc
  47 +
... ...
web_src/src/components/channelList.vue
... ... @@ -31,10 +31,19 @@
31 31 <el-table ref="channelListTable" :data="deviceChannelList" :height="winHeight" border style="width: 100%">
32 32 <el-table-column prop="channelId" label="通道编号" width="210">
33 33 </el-table-column>
34   - <el-table-column prop="name" label="通道名称" width="500">
  34 + <el-table-column prop="name" label="通道名称">
35 35 </el-table-column>
36 36 <el-table-column prop="subCount" label="子节点数">
37 37 </el-table-column>
  38 + <el-table-column label="开启音频" align="center">
  39 + <template slot-scope="scope">
  40 + <el-switch
  41 + @change="updateChannel(scope.row)"
  42 + v-model="scope.row.hasAudio"
  43 + active-color="#409EFF">
  44 + </el-switch>
  45 + </template>
  46 + </el-table-column>
38 47 <el-table-column label="状态" width="180" align="center">
39 48 <template slot-scope="scope">
40 49 <div slot="reference" class="name-wrapper">
... ... @@ -193,6 +202,7 @@
193 202 },
194 203 //通知设备上传媒体流
195 204 sendDevicePush: function(itemData) {
  205 + console.log(itemData)
196 206 let deviceId = this.deviceId;
197 207 this.isLoging = true;
198 208 let channelId = itemData.channelId;
... ... @@ -204,7 +214,7 @@
204 214 }).then(function(res) {
205 215 let ssrc = res.data.ssrc;
206 216 that.isLoging = false
207   - that.$refs.devicePlayer.play(res.data,deviceId,channelId);
  217 + that.$refs.devicePlayer.play(res.data,deviceId,channelId,itemData.hasAudio);
208 218 }).catch(function(e) {
209 219 });
210 220 },
... ... @@ -256,6 +266,16 @@
256 266 this.currentPage = 1;
257 267 this.total = 0;
258 268 this.initData();
  269 + },
  270 + updateChannel: function(row) {
  271 + console.log(row)
  272 + this.$axios({
  273 + method: 'post',
  274 + url: `/api/channel/update/${this.deviceId}`,
  275 + params: row
  276 + }).then(function(res) {
  277 + console.log(JSON.stringify(res));
  278 + });
259 279 }
260 280  
261 281 }
... ...
web_src/src/components/gb28181/devicePlayer.vue
1 1 <template>
2 2 <div id="devicePlayer">
3 3 <el-dialog title="视频播放" top="0" :visible.sync="showVideoDialog" :destroy-on-close="true" @close="stop()">
4   - <LivePlayer v-if="showVideoDialog" ref="videoPlayer" :videoUrl="videoUrl" :error="videoError" fluent autoplay live stretch></LivePlayer>
  4 + <LivePlayer v-if="showVideoDialog" ref="videoPlayer" :videoUrl="videoUrl" :error="videoError" :hasaudio="hasaudio" fluent autoplay live ></LivePlayer>
5 5 <div id="shared" style="text-align: right; margin-top: 1rem;">
6 6 <el-tabs v-model="tabActiveName">
7 7 <el-tab-pane label="媒体流信息" name="media">
... ... @@ -114,17 +114,22 @@
114 114 ssrc: '',
115 115 deviceId: '',
116 116 channelId: '',
117   - tabActiveName: 'media'
  117 + tabActiveName: 'media',
  118 + hasaudio: false
118 119  
119 120 };
120 121 },
121 122 methods: {
122 123  
123   - play: function(streamInfo, deviceId, channelId) {
  124 + play: function(streamInfo, deviceId, channelId, hasAudio) {
  125 + console.log(hasAudio);
  126 + this.hasaudio = hasAudio;
124 127 this.ssrc = streamInfo.ssrc;
125 128 this.deviceId = deviceId;
126 129 this.channelId = channelId;
127   - this.videoUrl = streamInfo.flv + "?" + new Date().getTime();
  130 + // this.$refs.videoPlayer.hasaudio = hasAudio;
  131 + // this.videoUrl = streamInfo.flv + "?" + new Date().getTime();
  132 + this.videoUrl = streamInfo.ws_flv;
128 133 this.showVideoDialog = true;
129 134 console.log(this.ssrc);
130 135 },
... ...