Results 1 to 10 of 10

Thread: Check whether an application is being published to

  1. #1

    Default Check whether an application is being published to

    Hi folks!

    We're trying to determine how to check whether an application is being published to. We've been using the following method (checking messagesinbytesrate), but it has shortcomings - when the publishing to a stream stops, the messagesinbytesrate does not always immediately drop below any given low threshold. It can taper off slowly and make it appear that the stream is still being published to.

    private String GetStreamRunningStatus(Map<String, List<String>> params) {
        String dir = "";
    
        // Not all required params?  Return failed status.
        if (hasMissingOrEmptyReqParams(new String[]{"MOUNT_NAMES"}, params ))
            return failureString(); // hasMissingOrEmptyReqParams() deals with the error message.
    		
        // Params exist.  Get their values.
        dir = getParam(params,"MOUNT_NAMES");
    
        IVHost vhostSingleton = VHostSingleton.getInstance(vhost.getName(), false);
    		
        String[] streamNames = dir.split(",");
        String allStreamInfoXML = "";
        for (String streamName : streamNames){
            IApplication application = vhostSingleton.getApplication(streamName);
    	IOPerformanceCounter counter = application.getIoPerformanceCounter();
    	Double messagesInBytesRate = counter.getMessagesInBytesRate();
    			
    	allStreamInfoXML += "<Mount>\n";
    	allStreamInfoXML += "<MountName>" + streamName + "</MountName>\n";
    	allStreamInfoXML += "<Running>" + (messagesInBytesRate < 5000 ? "false" : "true") + "</Running>\n";
    	allStreamInfoXML += "<MessagesInBytesRate>" + messagesInBytesRate + "</MessagesInBytesRate>\n";
    	allStreamInfoXML += "</Mount>\n";
        }
    
        return resultString(allStreamInfoXML);
    }
    Is there a better way of doing this? Thanks so much - your help is always appreciated!
    Last edited by vanillary; 05-30-2012 at 01:51 PM.

  2. #2

    Default

    Hi,

    You can use

    IApplication application = vhostSingleton.getApplication(streamName);
    IApplication appInstance = application.getAppInstance("_definst");

    List<String> Published = appInstance.getPublishStreamNames();
    int count = appInstance.getPublisherCount();

    Shamrock

  3. #3

    Default

    Hi Shamrock!

    Thanks very much for the reply - unfortunately, I didn't have luck with that. I always got a value of 0 from getPublisherCount(), whether I was publishing to an app instance or not. I tried not only "_definst", but also "_definst_" and the streamname as arguments for getAppInstance().

    Here's the updated code - can you think of why I might always be getting a count of 0 publishers? If it helps, I'm publishing to the application using Adobe Flash Media Live Encoder 3.2.

    private String GetStreamRunningStatus(Map<String, List<String>> params) {
    	String dir = "";
    
    	// Not all required params?  Return failed status.
    	if (hasMissingOrEmptyReqParams(new String[]{"MOUNT_NAMES"}, params ))
    		return failureString(); // hasMissingOrEmptyReqParams() deals with the error message.
    		
    	// Params exist.  Get their values.
    	dir = getParam(params,"MOUNT_NAMES");
    
    	IVHost vhostSingleton = VHostSingleton.getInstance(vhost.getName(), false);
    		
    	String[] streamNames = dir.split(",");
    	String allStreamInfoXML = "";
    	for (String streamName : streamNames){
    		IApplication application = vhostSingleton.getApplication(streamName);
    		IApplicationInstance appInstance = application.getAppInstance(streamName);
    		int numOfPublishers = appInstance.getPublisherCount();
    
    		allStreamInfoXML += "<Mount>\n";
    		allStreamInfoXML += "<MountName>" + streamName + "</MountName>\n";
    		allStreamInfoXML += "<Running>" + (numOfPublishers > 0 ? "true" : "false") + "</Running>\n";
    		allStreamInfoXML += "<PublisherCount>" + numOfPublishers + "</PublisherCount>\n";
    		allStreamInfoXML += "</Mount>\n";
    	}
    
    	return resultString(allStreamInfoXML);
    }
    Thanks again - I really appreciate your input!

  4. #4

    Default

    Actually, I've been testing out something new that seems very reliable (just in case we can't figure out the problem with GetPublisherCount()). GetMessagesInCount(). This is our latest code:

    private String GetStreamRunningStatus(Map<String, List<String>> params) {
    	String dir = "";
    
    	// Not all required params?  Return failed status.
    	if (hasMissingOrEmptyReqParams(new String[]{"MOUNT_NAMES"}, params ))
    		return failureString(); // hasMissingOrEmptyReqParams() deals with the error message.
    		
    	// Params exist.  Get their values.
    	dir = getParam(params,"MOUNT_NAMES");
    
    	IVHost vhostSingleton = VHostSingleton.getInstance(vhost.getName(), false);
    		
    	String[] streamNames = dir.split(",");
    	String allStreamInfoXML = "";
    	for (String streamName : streamNames){
    		IApplication application = vhostSingleton.getApplication(streamName);
    		IOPerformanceCounter counter = application.getIoPerformanceCounter();
    		Long firstMessagesInCount = counter.getMessagesInCount();
    			
    		try {
    			Thread.sleep(1000);  // Wait for a second 'til the next sample
    		}
    		catch (Exception ex) {
    			// Eat the exception
    		}
    			
    		Long secondMessagesInCount = counter.getMessagesInCount();
    		Long messagesInCountDifference = secondMessagesInCount - firstMessagesInCount;
    			
    		allStreamInfoXML += "<Mount>\n";
    		allStreamInfoXML += "<MountName>" + streamName + "</MountName>\n";
    		allStreamInfoXML += "<Running>" + (messagesInCountDifference > 0 ? "true" : "false") + "</Running>\n";
    		allStreamInfoXML += "<CountDifference>" + messagesInCountDifference + "</CountDifference>\n";
    		allStreamInfoXML += "</Mount>\n";
    	}
    
            return resultString(allStreamInfoXML);
    }
    It always ends up returning false when I stop publishing, and always returns true when I'm publishing. The only thing I'm a little wary about is this - I don't know exactly what kind of data GetMessagesInCount() is returning. The docs only say "Get[s] byte-in message count". What measure does it use to count the messages in? Could there be any repercussions to using this function for this purpose?

    Thanks very much!

  5. #5

    Default

    I have tried this and it seems to work, although i have added some variable definitions so it works, but you should be able to put back into your code.


    		String allStreamInfoXML = "";
    		
    		String dir = "mystream,thisstream";
    
    		IVHost thisVHost = appInstance.getVHost();
    		
    		String[] streamNames = dir.split(",");
    		for (String streamName : streamNames)
    			{
    
    			IApplication applicationA = thisVHost.getApplication(streamName);
    			
    			int numOfPublishers = 0;
    			
    			List<String> TheseAppIns = applicationA.getAppInstanceNames();
    			Iterator<String> ThisAppInsI = TheseAppIns.iterator();
    			while ( ThisAppInsI.hasNext() )
    				{
    				String AppInsName = ThisAppInsI.next();
    				IApplicationInstance appInstanceA = applicationA.getAppInstance(AppInsName);
    				numOfPublishers += appInstanceA.getPublisherCount();
    				}
    			allStreamInfoXML += "<Mount>\n";
    			allStreamInfoXML += "<MountName>" + streamName + "</MountName>\n";
    			allStreamInfoXML += "<Running>" + (numOfPublishers > 0 ? "true" : "false") + "</Running>\n";
    			allStreamInfoXML += "<PublisherCount>" + numOfPublishers + "</PublisherCount>\n";
    			allStreamInfoXML += "</Mount>\n";
    
    			}
    The GetMessagesInCount() may increment if you are using VoD and say chat even if no stream is published, but the above should work for you.

    Shamrock

  6. #6

    Default

    Hi again!

    Man, I just tried that method as well and still no luck - the resulting numOfPublishers is still 0, whether I'm publishing or not.

    This is the latest code. I don't have an app instance to get the vhost from initially (the way you did it), but I've tried it both this way and with my old vhostsingleton method.

    private String GetStreamRunningStatus(Map<String, List<String>> params) {
    	String dir = "";
    
    	// Not all required params?  Return failed status.
    	if (hasMissingOrEmptyReqParams(new String[]{"MOUNT_NAMES"}, params ))
    		return failureString(); // hasMissingOrEmptyReqParams() deals with the error message.
    		
    	// Params exist.  Get their values.
    	dir = getParam(params,"MOUNT_NAMES");
    
    	String[] streamNames = dir.split(",");
    	String allStreamInfoXML = "";
    	for (String streamName : streamNames){
    		IApplication app = vhost.getApplication(streamName);
    
    		int numOfPublishers = 0;
    			
    		List<String> appList = app.getAppInstanceNames();
    		Iterator<String> appListIterator = appList.iterator();
    		while ( appListIterator.hasNext() ){
    			String appName = appListIterator.next();
    			IApplicationInstance appInstance = app.getAppInstance(appName);
    			numOfPublishers += appInstance.getPublisherCount();
    		}
    			
    		allStreamInfoXML += "<Mount>\n";
    		allStreamInfoXML += "<MountName>" + streamName + "</MountName>\n";
    		allStreamInfoXML += "<Running>" + (numOfPublishers > 0 ? "true" : "false") + "</Running>\n";
    		allStreamInfoXML += "<NumOfPublishers>" + numOfPublishers + "</NumOfPublishers>\n";
    		allStreamInfoXML += "</Mount>\n";
    	}
    
    	return resultString(allStreamInfoXML);
    }
    Do you have any other ideas of what I might be doing wrong here, or what might need to be changed? Thanks for letting me know about GetMessagesInCount(), by the way - shame that method has such a flaw!

    Thanks again so much for your help!

  7. #7

    Default

    I haven't been able to come up with anything else to try - does anybody else have any other ideas? Wowza folks, have you got anything on this one?

  8. #8

    Default

    Try something like this:

    String appName = "live";
    
    while(true)
    {
    	IServer server = Server.getInstance();
    	if (server == null)
    		break;
    
    	IVHost vhost = VHostSingleton.getInstance(IVHost.VHOST_DEFAULT);
    	if (vhost == null)
    		break;
    
    	IApplication application = vhost.getApplication(appName);
    	if (application == null)
    		break;
    
    	List<String> appInstanceNames = application.getAppInstanceNames();
    	Iterator<String> iter = appInstanceNames.iterator();
    
    	while(iter.hasNext())
    	{
    		String appInstName = iter.next();
    		IApplicationInstance appInstance2 = application.getAppInstance(appInstName);
    
    		if (appInstance2 == null)
    			continue;
    
    		List<String> publishNames = appInstance2.getPublishStreamNames();
    
    		int publishCount = 0;
    		if (publishNames != null)
    			publishCount = publishNames.size();
    
    		getLogger().info("PublishCount["+appInstance2.getContextStr()+"]: "+publishCount);
    	}
    	break;
    }
    Charlie

  9. #9

    Thumbs up

    Wow! Using that overall idea worked perfectly! Abso-lutely glorious! Thank you so much!

    For anybody who would like to replicate this, here's the final working code:

    private String GetStreamRunningStatus(Map<String, List<String>> params) {
    	String dir = "";
    		
    	// Not all required params?  Return failed status.
    	if (hasMissingOrEmptyReqParams(new String[]{"MOUNT_NAMES"}, params ))
    		return failureString(); // hasMissingOrEmptyReqParams() deals with the error message.
    		
    	// Params exist.  Get their values.
    	dir = getParam(params,"MOUNT_NAMES");
    
    	String[] streamNames = dir.split(",");
    	String allStreamInfoXML = "";
    	for (String streamName : streamNames){
    
    		IApplication application = vhost.getApplication(streamName);
    		if (application == null)
    			continue;
    
    		List<String> appInstanceNames = application.getAppInstanceNames();
    		Iterator<String> iter = appInstanceNames.iterator();
    
    		int publishCount = 0;
    		while(iter.hasNext())
    		{
    			String appInstName = iter.next();
    			IApplicationInstance appInstance = application.getAppInstance(appInstName);
    
    			if (appInstance == null)
    				continue;
    
    			List<String> publishNames = appInstance.getPublishStreamNames();
    	
    			if (publishNames != null)
    				publishCount += publishNames.size();
    		}
    
    		allStreamInfoXML += "<Mount>\n";
    		allStreamInfoXML += "<MountName>" + streamName + "</MountName>\n";
    		allStreamInfoXML += "<Running>" + (publishCount > 0 ? "true" : "false") + "</Running>\n";
    		allStreamInfoXML += "<PublisherCount>" + publishCount + "</PublisherCount>\n";
    		allStreamInfoXML += "</Mount>\n";
    	}
    
    	return resultString(allStreamInfoXML);
    }
    Thanks again, Charlie!

  10. #10

    Default

    No problem, Charlie

Similar Threads

  1. Delete Published SDP file automatically after some times in Native RTP application
    By deepak2113 in forum Live Streaming and Encoder Discussion
    Replies: 5
    Last Post: 12-06-2013, 12:57 AM
  2. How to know what stream is being published
    By mustafama in forum General Forum
    Replies: 3
    Last Post: 03-01-2013, 04:10 AM
  3. get the stream that published in the multicastmap
    By matanf in forum General Forum
    Replies: 7
    Last Post: 06-17-2012, 09:48 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •