作者 钟来

修改接码器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,6 +22,19 @@ public class WebRtcService { @@ -20,6 +22,19 @@ 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 {
  25 + String[] rtspurls = rtspUrl.split(",");
  26 + if(rtspurls.length!=0)
  27 + {
  28 + String playurls = "";
  29 + int i = 1;
  30 + String localip = WebRtcService.getLocalIpAddress();
  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 + {
23 StringBuffer stringBuffer = getZlmApi(); 38 StringBuffer stringBuffer = getZlmApi();
24 stringBuffer.append("/addStreamProxy?"); 39 stringBuffer.append("/addStreamProxy?");
25 stringBuffer.append("secret="); 40 stringBuffer.append("secret=");
@@ -28,9 +43,9 @@ public class WebRtcService { @@ -28,9 +43,9 @@ public class WebRtcService {
28 stringBuffer.append("&app="); 43 stringBuffer.append("&app=");
29 stringBuffer.append(app); 44 stringBuffer.append(app);
30 stringBuffer.append("&stream="); 45 stringBuffer.append("&stream=");
31 - stringBuffer.append(stream); 46 + stringBuffer.append(newStream);
32 stringBuffer.append("&url="); 47 stringBuffer.append("&url=");
33 - stringBuffer.append(rtspUrl); 48 + stringBuffer.append(rtspurl);
34 stringBuffer.append("&enable_auto_close=1"); 49 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); 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);
36 logger.info("添加流的接口请求:"+stringBuffer.toString()); 51 logger.info("添加流的接口请求:"+stringBuffer.toString());
@@ -39,15 +54,38 @@ public class WebRtcService { @@ -39,15 +54,38 @@ public class WebRtcService {
39 if(jsonObject.containsKey("code") && jsonObject.getInteger("code")==0) 54 if(jsonObject.containsKey("code") && jsonObject.getInteger("code")==0)
40 { 55 {
41 jsonObject.put("code",1); 56 jsonObject.put("code",1);
42 - String localip = WebRtcService.getLocalIpAddress();  
43 - String playurl = WebRtcService.getPlayUrl(localip, SysConfig.webrtc_app, stream);  
44 - jsonObject.getJSONObject("data").put("playurl",playurl);  
45 - return jsonObject; 57 + if(!"".equals(playurls))
  58 + {
  59 + playurls += ",";
46 } 60 }
  61 + playurls+=playurl;
  62 + }else {
47 jsonObject.put("code",0); 63 jsonObject.put("code",0);
48 System.out.println(str); 64 System.out.println(str);
49 return jsonObject; 65 return jsonObject;
50 } 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);
  82 + return jsonObject;
  83 + }
  84 + JSONObject jsonObject = new JSONObject();
  85 + jsonObject.put("code",0);
  86 + jsonObject.put("msg","rtspUrl参数错误");
  87 + return jsonObject;
  88 + }
51 89
52 public static String stopStream( String stream,String app,String secret) { 90 public static String stopStream( String stream,String app,String secret) {
53 String url = getZlmApi() + "/close_stream?schema=rtsp&vhost=__defaultVhost__&app=" + app + "&stream=" + stream+"&force=1&secret="+secret; 91 String url = getZlmApi() + "/close_stream?schema=rtsp&vhost=__defaultVhost__&app=" + app + "&stream=" + stream+"&force=1&secret="+secret;