作者 钟来

修改接码器bug

@@ -11,7 +11,9 @@ import org.slf4j.LoggerFactory; @@ -11,7 +11,9 @@ import org.slf4j.LoggerFactory;
11 import java.net.DatagramSocket; 11 import java.net.DatagramSocket;
12 import java.net.InetAddress; 12 import java.net.InetAddress;
13 import java.net.NetworkInterface; 13 import java.net.NetworkInterface;
  14 +import java.util.ArrayList;
14 import java.util.Enumeration; 15 import java.util.Enumeration;
  16 +import java.util.List;
15 17
16 public class WebRtcService { 18 public class WebRtcService {
17 private static Logger logger = LoggerFactory.getLogger(App.class); 19 private static Logger logger = LoggerFactory.getLogger(App.class);
@@ -20,32 +22,68 @@ public class WebRtcService { @@ -20,32 +22,68 @@ public class WebRtcService {
20 22
21 public static JSONObject startStream(String stream,String rtspUrl,String app,String secret,String auto_close) 23 public static JSONObject startStream(String stream,String rtspUrl,String app,String secret,String auto_close)
22 { 24 {
23 - StringBuffer stringBuffer = getZlmApi();  
24 - stringBuffer.append("/addStreamProxy?");  
25 - stringBuffer.append("secret=");  
26 - stringBuffer.append(secret);  
27 - stringBuffer.append("&vhost=__defaultVhost__");  
28 - stringBuffer.append("&app=");  
29 - stringBuffer.append(app);  
30 - stringBuffer.append("&stream=");  
31 - stringBuffer.append(stream);  
32 - stringBuffer.append("&url=");  
33 - stringBuffer.append(rtspUrl);  
34 - stringBuffer.append("&enable_auto_close=1");  
35 - stringBuffer.append("&retry_count=-1&rtp_type=0&timeout_sec=10&enable_hls=false&enable_hls_fmp4=false&enable_mp4=false&enable_rtsp=true&enable_rtmp=false&enable_ts=false&enable_fmp4=true&hls_demand=false&rtsp_demand=false&rtmp_demand=false&ts_demand=false&fmp4_demand=false&enable_audio=true&add_mute_audio=true&mp4_max_second=10&mp4_as_player=false&auto_close="+auto_close);  
36 - logger.info("添加流的接口请求:"+stringBuffer.toString());  
37 - String str = HttpUtil.get(stringBuffer.toString());  
38 - JSONObject jsonObject = JSON.parseObject(str);  
39 - if(jsonObject.containsKey("code") && jsonObject.getInteger("code")==0) 25 + String[] rtspurls = rtspUrl.split(",");
  26 + if(rtspurls.length!=0)
40 { 27 {
41 - jsonObject.put("code",1); 28 + String playurls = "";
  29 + int i = 1;
42 String localip = WebRtcService.getLocalIpAddress(); 30 String localip = WebRtcService.getLocalIpAddress();
43 - String playurl = WebRtcService.getPlayUrl(localip, SysConfig.webrtc_app, stream);  
44 - jsonObject.getJSONObject("data").put("playurl",playurl); 31 + for(String rtspurl : rtspurls) {
  32 + String newStream = stream;
  33 + newStream = stream+"_"+i++;
  34 + String playurl = WebRtcService.getPlayUrl(localip, app, newStream);
  35 + boolean oline = WebRtcService.isMediaOnline(newStream,app, SysConfig.getWebrtcSecret());
  36 + if (!oline)
  37 + {
  38 + StringBuffer stringBuffer = getZlmApi();
  39 + stringBuffer.append("/addStreamProxy?");
  40 + stringBuffer.append("secret=");
  41 + stringBuffer.append(secret);
  42 + stringBuffer.append("&vhost=__defaultVhost__");
  43 + stringBuffer.append("&app=");
  44 + stringBuffer.append(app);
  45 + stringBuffer.append("&stream=");
  46 + stringBuffer.append(newStream);
  47 + stringBuffer.append("&url=");
  48 + stringBuffer.append(rtspurl);
  49 + stringBuffer.append("&enable_auto_close=1");
  50 + stringBuffer.append("&retry_count=-1&rtp_type=0&timeout_sec=10&enable_hls=false&enable_hls_fmp4=false&enable_mp4=false&enable_rtsp=true&enable_rtmp=false&enable_ts=false&enable_fmp4=true&hls_demand=false&rtsp_demand=false&rtmp_demand=false&ts_demand=false&fmp4_demand=false&enable_audio=true&add_mute_audio=true&mp4_max_second=10&mp4_as_player=false&auto_close="+auto_close);
  51 + logger.info("添加流的接口请求:"+stringBuffer.toString());
  52 + String str = HttpUtil.get(stringBuffer.toString());
  53 + JSONObject jsonObject = JSON.parseObject(str);
  54 + if(jsonObject.containsKey("code") && jsonObject.getInteger("code")==0)
  55 + {
  56 + jsonObject.put("code",1);
  57 + if(!"".equals(playurls))
  58 + {
  59 + playurls += ",";
  60 + }
  61 + playurls+=playurl;
  62 + }else {
  63 + jsonObject.put("code",0);
  64 + System.out.println(str);
  65 + return jsonObject;
  66 + }
  67 + }else{
  68 + if(!"".equals(playurls))
  69 + {
  70 + playurls += ",";
  71 + }
  72 + playurls+=playurl;
  73 + }
  74 +
  75 + }
  76 + JSONObject jsonObject = new JSONObject();
  77 + jsonObject.put("code",1);
  78 + JSONObject data = new JSONObject();
  79 + data.put("playurl",playurls);
  80 + data.put("key",secret);
  81 + jsonObject.put("data",data);
45 return jsonObject; 82 return jsonObject;
46 } 83 }
  84 + JSONObject jsonObject = new JSONObject();
47 jsonObject.put("code",0); 85 jsonObject.put("code",0);
48 - System.out.println(str); 86 + jsonObject.put("msg","rtspUrl参数错误");
49 return jsonObject; 87 return jsonObject;
50 } 88 }
51 89