·您当前的位置:首页 > 技术教程 > Wowza教程 >

[wowza]Wowza的Http扩展应用的代码

时间:2015-05-06 08:53酷播
[wowza]Wowza的Http扩展应用的代码

[wowza]Wowza的Http扩展应用的代码

  1. package zjzhang.wowza; 
  2. import java.io.*; 
  3. import java.util.*; 
  4. import com.wowza.wms.vhost.*; 
  5. import com.wowza.wms.logging.WMSLoggerFactory; 
  6. import com.wowza.wms.rtp.model.RTPSession; 
  7. import com.wowza.wms.server.*; 
  8. import com.wowza.wms.stream.IMediaStream; 
  9. import com.wowza.wms.stream.MediaStreamMap; 
  10. import com.wowza.wms.application.*; 
  11. import com.wowza.wms.http.*; 
  12. import com.wowza.wms.client.*; 
  13. import com.wowza.wms.http.*; 
  14. import com.wowza.wms.httpstreamer.model.IHTTPStreamerSession; 
  15. public class GetList extends HTTProvider2Base 
  16. {    
  17.     private void outputConnectionInfo(StringBuffer ret, ConnectionCounter counter) 
  18.     { 
  19.         ret.append("<ConnectionsCurrent>"+counter.getCurrent()+"</ConnectionsCurrent>"); 
  20.         ret.append("<ConnectionsTotal>"+counter.getTotal()+"</ConnectionsTotal>"); 
  21.         ret.append("<ConnectionsTotalAccepted>"+counter.getTotalAccepted()+"</ConnectionsTotalAccepted>"); 
  22.         ret.append("<ConnectionsTotalRejected>"+counter.getTotalRejected()+"</ConnectionsTotalRejected>"); 
  23.     } 
  24.      
  25.     public void onHTTPRequest(IVHost inVhost, IHTTPRequest req, IHTTPResponse resp) 
  26.     { 
  27.         if (!doHTTPAuthentication(inVhost, req, resp)) 
  28.             return; 
  29.         StringBuffer ret = new StringBuffer(); 
  30.          
  31.         try 
  32.         { 
  33.             List vhostNames = VHostSingleton.getVHostNames(); 
  34.             ret.append("<?xml version=/"1.0/"?>/n<WowzaMediaServerPro>"); 
  35.                      
  36.             Iterator<String> iter = vhostNames.iterator(); 
  37.             while (iter.hasNext()) 
  38.             { 
  39.                 String vhostName = iter.next(); 
  40.                 IVHost vhost = (IVHost)VHostSingleton.getInstance(vhostName); 
  41.                 if (vhost != null) 
  42.                 { 
  43.                     ret.append("<VHost>"); 
  44.                     ret.append("<Name>"+vhostName+"</Name>"); 
  45.                     ret.append("<TimeRunning>"+vhost.getTimeRunningSeconds()+"</TimeRunning>"); 
  46.                     ret.append("<ConnectionsLimit>"+vhost.getConnectionLimit()+"</ConnectionsLimit>"); 
  47.                      
  48.                     outputConnectionInfo(ret, vhost.getConnectionCounter()); 
  49.                      
  50.                     List appNames = vhost.getApplicationNames(); 
  51.                     List<String> appFolders = vhost.getApplicationFolderNames(); 
  52.                     Iterator<String> appNameIterator = appFolders.iterator(); 
  53.                     while (appNameIterator.hasNext()) 
  54.                     { 
  55.                         String applicationName = appNameIterator.next(); 
  56.                         ret.append("<Application>"); 
  57.                         ret.append("<Name>"+applicationName+"</Name>"); 
  58.                         boolean appExists = appNames.contains(applicationName); 
  59.                         ret.append("<Status>"+(appExists?"loaded":"unloaded")+"</Status>"); 
  60.                         if (appExists) 
  61.                         { 
  62.                             IApplication application = vhost.getApplication(applicationName); 
  63.                             if (application == null) 
  64.                                 continue; 
  65.                              
  66.                             ret.append("<TimeRunning>"+application.getTimeRunningSeconds()+"</TimeRunning>"); 
  67.                             outputConnectionInfo(ret, application.getConnectionCounter()); 
  68.                              
  69.                             List appInstances = application.getAppInstanceNames(); 
  70.                             Iterator<String> iterAppInstances = appInstances.iterator(); 
  71.                             while (iterAppInstances.hasNext()) 
  72.                             { 
  73.                                 String appInstanceName = iterAppInstances.next(); 
  74.                                 IApplicationInstance appInstance = application.getAppInstance(appInstanceName); 
  75.                                 if (appInstance == null) 
  76.                                     continue; 
  77.                                  
  78.                                 ret.append("<ApplicationInstance>"); 
  79.                                 ret.append("<Name>"+appInstance.getName()+"</Name>"); 
  80.                                 ret.append("<TimeRunning>"+appInstance.getTimeRunningSeconds()+"</TimeRunning>"); 
  81.                                  
  82.                                 outputConnectionInfo(ret, appInstance.getConnectionCounter()); 
  83.                                 MediaStreamMap  msm=appInstance.getStreams(); 
  84.                                  
  85.                                  
  86.                                 List<String> publishStreams =msm.getPublishStreamNames(); 
  87.                                 Iterator<String> iterPublish = publishStreams.iterator(); 
  88.                              
  89.                                 while(iterPublish.hasNext()) 
  90.                                 { 
  91.                                     IMediaStream stream = msm.getStream(iterPublish.next()); //appInstance.getClient(c); 
  92.                                     if (stream == null) 
  93.                                         continue; 
  94.                                      
  95.                                     ret.append("<PublishStream>"); 
  96.                                     ret.append("<Name>"+stream.getName()+"</Name>"); 
  97.                                     ret.append("<Type>"+stream.getStreamType()+"</Type>"); 
  98.                                     ret.append("<PublishStreamReady>"+stream.isPublishStreamReady(false, true)+"</PublishStreamReady>"); 
  99.                                     ret.append("<PublishAudioCodecId>"+stream.getPublishAudioCodecId()+"</PublishAudioCodecId>"); 
  100.                                     ret.append("<PublishVideoCodecId>"+stream.getPublishVideoCodecId()+"</PublishVideoCodecId>"); 
  101.                                     List<IMediaStream> playStreams=appInstance.getPlayStreamsByName(stream.getName()); 
  102.                                     if(playStreams!=null) 
  103.                                     { 
  104.                                         ret.append("<SessionsFlash count=/""+playStreams.size()+"/">"); 
  105.                                         Iterator<IMediaStream> iterPlay=playStreams.iterator(); 
  106.                                         while(iterPlay.hasNext()) 
  107.                                         { 
  108.                                             IMediaStream playSessioniterPlay.next(); 
  109.                                             IClient playClient=playSession.getClient(); 
  110.                                             ret.append("<Session>"); 
  111.                                             ret.append("<ClientIP>"+playClient.getIp()+"</ClientIP>"); 
  112.                                             ret.append("<ClientFlashVer>"+playClient.getFlashVer()+"</ClientFlashVer>"); 
  113.                                             ret.append("<ClientConnectTime>"+playClient.getConnectTime()+"</ClientConnectTime>"); 
  114.                                             ret.append("</Session>"); 
  115.                                         } 
  116.                                         ret.append("</SessionsFlash>"); 
  117.                                     } 
  118.                                     else 
  119.                                     { 
  120.                                         ret.append("<SessionsFlash count=/"0/"/>"); 
  121.                                     } 
  122.                                      
  123.                                     List<IHTTPStreamerSession> cupertinoSession=appInstance.getHTTPStreamerSessions(IHTTPStreamerSession.SESSIONPROTOCOL_CUPERTINOSTREAMING, stream.getName()); 
  124.                                     if(cupertinoSession!=null) 
  125.                                     { 
  126.                                         ret.append("<SessionsCupertino count=/""+cupertinoSession.size()+"/">"); 
  127.                                         Iterator<IHTTPStreamerSession> iterPlay=cupertinoSession.iterator(); 
  128.                                         while(iterPlay.hasNext()) 
  129.                                         { 
  130.                                             IHTTPStreamerSession playSessioniterPlay.next(); 
  131.                                             ret.append("<Session>"); 
  132.                                             ret.append("<ClientIP>"+playSession.getIpAddress()+"</ClientIP>"); 
  133.                                             ret.append("<ClientUserAgent>"+playSession.getUserAgent()+"</ClientUserAgent>"); 
  134.                                             ret.append("<ClientConnectTime>"+playSession.getTimeRunning()+"</ClientConnectTime>"); 
  135.                                             ret.append("</Session>"); 
  136.                                         }                                        
  137.                                          
  138.                                         ret.append("</SessionsCupertino>"); 
  139.                                     } 
  140.                                     else 
  141.                                     { 
  142.                                         ret.append("<SessionsCupertino count=/"0/"/>"); 
  143.                                     } 
  144.                                      
  145.                                     List<IHTTPStreamerSession> smoothSession=appInstance.getHTTPStreamerSessions(IHTTPStreamerSession.SESSIONPROTOCOL_SMOOTHSTREAMING, stream.getName()); 
  146.                                     if(smoothSession!=null) 
  147.                                     {                                    
  148.                                         ret.append("<SessionsSmooth count=/""+smoothSession.size()+"/">"); 
  149.                                         Iterator<IHTTPStreamerSession> iterPlay=smoothSession.iterator(); 
  150.                                         while(iterPlay.hasNext()) 
  151.                                         { 
  152.                                             IHTTPStreamerSession playSessioniterPlay.next(); 
  153.                                             ret.append("<Session>"); 
  154.                                             ret.append("<ClientIP>"+playSession.getIpAddress()+"</ClientIP>"); 
  155.                                             ret.append("<ClientUserAgent>"+playSession.getUserAgent()+"</ClientUserAgent>"); 
  156.                                             ret.append("<ClientConnectTime>"+playSession.getTimeRunning()+"</ClientConnectTime>"); 
  157.                                             ret.append("</Session>"); 
  158.                                         }                                        
  159.                                         ret.append("</SessionsSmooth>"); 
  160.                                     } 
  161.                                     else 
  162.                                     { 
  163.                                         ret.append("<SessionsSmooth count=/"0/"/>"); 
  164.                                     } 
  165.                                      
  166.                                     List<RTPSession> rtpStreams=appInstance.getRTPSessions(stream.getName()); 
  167.                                     if(rtpStreams!=null) 
  168.                                     { 
  169.                                         ret.append("<SessionsRTSP count=/""+rtpStreams.size()+"/">"); 
  170.                                         Iterator<RTPSession> iterPlay=rtpStreams.iterator(); 
  171.                                         while(iterPlay.hasNext()) 
  172.                                         { 
  173.                                             RTPSession playSessioniterPlay.next(); 
  174.                                             ret.append("<Session>"); 
  175.                                             ret.append("<ClientIP>"+playSession.getIp()+"</ClientIP>"); 
  176.                                             ret.append("<ClientUserAgent>"+playSession.getUserAgent()+"</ClientUserAgent>"); 
  177.                                             ret.append("</Session>"); 
  178.                                             //ret.append("<ClientConnectTime>"+playSession.get+"</ClientConnectTime>"); 
  179.                                         } 
  180.                                         ret.append("</SessionsRTSP>"); 
  181.                                     } 
  182.                                     else 
  183.                                     { 
  184.                                         ret.append("<SessionsRTSP count=/"0/"/>"); 
  185.                                     } 
  186.                                      
  187.                                     ret.append("</PublishStream>"); 
  188.                                      
  189.                                 } 
  190.                                  
  191. /*                               
  192.                                 List<IClient> clients = appInstance.getClients(); 
  193.                                 Iterator<IClient> iterClient = clients.iterator(); 
  194.                                 while(iterClient.hasNext()) 
  195.                                 { 
  196.                                     IClient client = iterClient.next(); //appInstance.getClient(c); 
  197.                                     if (client == null) 
  198.                                         continue; 
  199.                                     ret.append("<Client>"); 
  200.                                     ret.append("<ClientId>"+client.getClientId()+"</ClientId>"); 
  201.                                     ret.append("<FlashVersion>"+client.getFlashVer()+"</FlashVersion>"); 
  202.                                     ret.append("<IpAddress>"+client.getIp()+"</IpAddress>"); 
  203.                                     ret.append("<Referrer>"+client.getReferrer()+"</Referrer>"); 
  204.                                     ret.append("<TimeRunning>"+client.getTimeRunningSeconds()+"</TimeRunning>"); 
  205.                                     //ret.append("<Duration>"+((double)(System.currentTimeMillis()-client.getConnectTime())/1000.0)+"</Duration>"); 
  206.                                     //ret.append("<DateStarted>"+client.getDateStarted()+"</DateStarted>"); 
  207.                                     ret.append("<URI>"+client.getUri()+"</URI>"); 
  208.                                      
  209.                                     String protocolStr = "unknown"
  210.                                     switch(client.getProtocol()) 
  211.                                     { 
  212.                                     case RtmpSessionInfo.PROTOCOL_RTMP: 
  213.                                         protocolStr = client.isEncrypted()?"RTMPE":"RTMP"; 
  214.                                         break; 
  215.                                     case RtmpSessionInfo.PROTOCOL_RTMPT: 
  216.                                         protocolStr = client.isSSL()?"RTMPS":(client.isEncrypted()?"RTMPTE":"RTMPT"); 
  217.                                         break; 
  218.                                     } 
  219.                                      
  220.                                     ret.append("<Protocol type=/""+client.getProtocol()+"/">"+protocolStr+"</Protocol>"); 
  221.                                     ret.append("<IsSSL>"+client.isSSL()+"</IsSSL>"); 
  222.                                     ret.append("<IsEncrypted>"+client.isEncrypted()+"</IsEncrypted>"); 
  223.                                     ret.append("<Port>"+client.getServerHostPort().getPort()+"</Port>"); 
  224.                                     ret.append("</Client>"); 
  225.                                 } 
  226. */                               
  227.                                 ret.append("</ApplicationInstance>"); 
  228.                             } 
  229.                         } 
  230.                          
  231.                         ret.append("</Application>"); 
  232.                     } 
  233.                      
  234.                     ret.append("</VHost>"); 
  235.                 } 
  236.             } 
  237.              
  238.             ret.append("</WowzaMediaServerPro>"); 
  239.         } 
  240.         catch (Exception e) 
  241.         { 
  242.             WMSLoggerFactory.getLogger(HTTPServerVersion.class).error("HTTPServerInfoXML.onHTTPRequest: "+e.toString()); 
  243.             e.printStackTrace(); 
  244.         } 
  245.                  
  246.         try 
  247.         { 
  248.             resp.setHeader("Content-Type", "text/xml"); 
  249.              
  250.             OutputStream out = resp.getOutputStream(); 
  251.             byte[] outBytes = ret.toString().getBytes(); 
  252.             out.write(outBytes); 
  253.         } 
  254.         catch (Exception e) 
  255.         { 
  256.             WMSLoggerFactory.getLogger(HTTPServerVersion.class).error("HTTPServerInfoXML.onHTTPRequest: "+e.toString()); 
  257.             e.printStackTrace(); 
  258.         } 
  259.          
  260.     } 

[wowza]Wowza的Http扩展应用的代码

  1.   <?xml version="1.0" ?>  
  2. <WowzaMediaServerPro> 
  3. <VHost> 
  4.   <Name>_defaultVHost_</Name>  
  5.   <TimeRunning>233.261</TimeRunning>  
  6.   <ConnectionsLimit>0</ConnectionsLimit>  
  7.   <ConnectionsCurrent>2</ConnectionsCurrent>  
  8.   <ConnectionsTotal>4</ConnectionsTotal>  
  9.   <ConnectionsTotalAccepted>4</ConnectionsTotalAccepted>  
  10.   <ConnectionsTotalRejected>0</ConnectionsTotalRejected>  
  11. <Application> 
  12.   <Name>live</Name>  
  13.   <Status>loaded</Status>  
  14.   <TimeRunning>205.952</TimeRunning>  
  15.   <ConnectionsCurrent>2</ConnectionsCurrent>  
  16.   <ConnectionsTotal>4</ConnectionsTotal>  
  17.   <ConnectionsTotalAccepted>4</ConnectionsTotalAccepted>  
  18.   <ConnectionsTotalRejected>0</ConnectionsTotalRejected>  
  19. <ApplicationInstance> 
  20.   <Name>_definst_</Name>  
  21.   <TimeRunning>205.922</TimeRunning>  
  22.   <ConnectionsCurrent>2</ConnectionsCurrent>  
  23.   <ConnectionsTotal>4</ConnectionsTotal>  
  24.   <ConnectionsTotalAccepted>4</ConnectionsTotalAccepted>  
  25.   <ConnectionsTotalRejected>0</ConnectionsTotalRejected>  
  26. <PublishStream> 
  27.   <Name>zzj</Name>  
  28.   <Type>live</Type>  
  29.   <PublishStreamReady>true</PublishStreamReady>  
  30.   <PublishAudioCodecId>-1</PublishAudioCodecId>  
  31.   <PublishVideoCodecId>7</PublishVideoCodecId>  
  32. <SessionsFlash count="1"> 
  33. <Session> 
  34.   <ClientIP>127.0.0.1</ClientIP>  
  35.   <ClientFlashVer>WIN 10,2,159,1</ClientFlashVer>  
  36.   <ClientConnectTime>1304925496758</ClientConnectTime>  
  37.   </Session> 
  38.   </SessionsFlash> 
  39.   <SessionsCupertino count="0" />  
  40.   <SessionsSmooth count="0" />  
  41.   <SessionsRTSP count="0" />  
  42.   </PublishStream> 
  43.   </ApplicationInstance> 
  44.   </Application> 
  45. <Application> 
  46.   <Name>videochat</Name>  
  47.   <Status>unloaded</Status>  
  48.   </Application> 
  49. <Application> 
  50.   <Name>vod</Name>  
  51.   <Status>unloaded</Status>  
  52.   </Application> 
  53.   </VHost> 
  54.   </WowzaMediaServerPro> 

 支持wowza的播放器下载:http://www.cuplayer.com/CuSunPlayer/download.html



热门文章推荐

请稍候...

保利威视云平台-轻松实现点播直播视频应用

酷播云数据统计分析跨平台播放器