Web-Based Video Monitoring
by Michael Larson

Example 1:

public class StreamData {
    StringBuffer mType;     //video stream type
    int mOpStatus;          //operating status (new/update/deleted)
    int mState;             //bad/good stream?
    StringBuffer mCode;     //timecode data 
    String mURL;            //name and location
    String mTimeOfLastTest; //time of last test
    String mServerResponse; //status returned from the server
    ArrayList mAddConnInfo; //aux. Server response
    StreamWatch mSW;        //Streamwatch object
}


Example 2:

private void postUpdate(StatusAList aList) {
    mSDBufferVect.add(aList); 
    synchronized (this) {
        notifyAll(); } //wake up at the beginning of a cycle
}

Listing One
ReportMgr.run()
public void run() {
    StatusAList aList;
    System.out.println(new Date().toString() + " ReportMgr::run() running");
    try {
        while(true) {
            while ((aList = (StatusAList)mSiteState.getUpdateBuf()) != null) {
                switch (aList.mStatus) {
                    case Konstants.kSTATUS_HAS_STARTED:
                        startUpdate((ArrayList)aList);
                        break;
                    case Konstants.kSTATUS_IS_UPDATED: 
                        update((ArrayList)aList);
                        break;
                    case Konstants.kSTATUS_IS_COMPLETE:
                        finishUpdate((ArrayList)aList);
                        break;
                    case Konstants.kSTATUS_NO_STREAMS:
                        reportGeneralError(); 
                        break;
                    default:
                        System.out.println(new Date().toString() + 
                           " Bad Status flag in  ReportMgr:run() "); } }
            synchronized(mSiteState) {
                mSiteState.wait(); } } }  //wait for an event to be posted.
            catch (InterruptedException ie) {
                System.out.println(new Date().toString() + 
                " InterruptedException thrown in  ReportMgr:run() " + ie);  } 
            catch (ClassCastException cce) { 
                System.out.println(new Date().toString() + 
                " ClassCastException thrown in  ReportMgr:run() " + cce);  } } 


Listing Two
SiteState.doneWithStatus()
public boolean doneWithStatus(Object sdobj, int status, 
                                   String resp, ArrayList auxData) {
    boolean bChanged = false;
    StatusAList updateAList;
    StreamData sd;
    
    sd = (StreamData)sdobj;
    sd.mTimeOfLastTest = new Date().toString();     
    //find stream, update and notify if status or server response has changed
    if (mStreamVector.contains(sd)) {
        if (sd.mOpStatus != status || sd.mServerResponse != resp) {
            sd.mState = Konstants.kSTATE_UPDATED; 
            bChanged = true; }
        else {
            sd.mState = Konstants.kSTATE_UNCHANGED; }
            sd.mOpStatus = status;
            sd.mServerResponse = resp;
            sd.mAddConnInfo = auxData;
        if (bChanged == true) {     //update if status has changed
            updateAList = new StatusAList();
            updateAList.add(new StreamData(sd));
            updateAList.mStatus = Konstants.kSTATUS_IS_UPDATED;
            postUpdate(updateAList); }
        return true; }      //this stream is still actively monitored
    else {
        return false;}      //didn't find match is deleted
}

Listing Three
RealVideoWatch.run()
public void run()
{
/* Checks on an RTSP streaming server for existance of the DESCRIBE method, 
    then probes for the existance of the live stream.
*/  
    Socket sock = null;
    BufferedReader inStream = null;
    PrintStream outStream = null;
    String s;
    StringBuffer response = null;
    int status = Konstants.kOPSTATUS_STREAM_UNDEFINED;
    ArrayList addStatus = null;
    
    //this indicates a faulty streamlist.xml entry      
    if (mURL == "") {
        return; }
        
    while (true) { //monitor this stream until doneWithStatus() returns false
        System.out.println(new Date().toString() + 
                            " starting to probe camera stream: " + mURL);
        response = new StringBuffer();
        try { 
            sock = new Socket(mIP, mPort);
            System.out.println(new Date().toString() + 
                             " socket opened to server: " + mURL);
            inStream = new BufferedReader(new 
                             InputStreamReader(sock.getInputStream()));
            outStream = new PrintStream(sock.getOutputStream()); 
            //now let's start communicating with the RTSP server        
            if (supportsDescribe(outStream, inStream)) {    
                if (isGood(outStream, inStream, response)) {
                    status = Konstants.kOPSTATUS_STREAM_OK;
                    System.out.println(new Date().toString() + 
                                             " Stream is good: " + mURL);
                    //let's see if we can capture some additional details
                    addStatus = new ArrayList();   //initialize for loop
                    getAuxData(outStream, inStream, addStatus); }           
               else {  //stream not available from RTSP server
                    status = Konstants.kOPSTATUS_STREAM_BAD;
                    addStatus = null;
                    System.out.println(new Date().toString() + 
                                          " Stream is BAD: " + mURL); } } }
        catch (IOException ioe) {
            status = Konstants.kOPSTATUS_STREAM_BAD;
            System.out.println(new Date().toString() + 
                   " IO Exception thrown in RealVideoWatch.run() " + ioe); }
        try {
            if (sock != null) {
                sock.close(); }
            if (!mSiteState.doneWithStatus(mUniqueID, status, 
                                        response.toString(), addStatus) ) { 
                return; } //I've been removed from monitoring
            sleep(Konstants.mDelayBetweenCycles.intValue()); }
        catch (InterruptedException ie) {
            System.out.println(new Date().toString() + 
             " Interrupted Exception thrown in RealVideoWatch.run() " + ie); }
        catch (IOException ioe) {
            System.out.println(new Date().toString() + 
            " Interrupted Exception thrown in RealVideoWatch.run() " + ioe); }
    }
}






3

