/*************************************************
 * Author: 	Evelyn Lai-Tee Cheok
 *			Department of Electrical Engineering
 *			Center for Telecommunications Research
 *			Schapiro Research Building
 *			Columbia University
 *
 * Email: 	laitee@ctr.columbia.edu
 *
 **************************************************/
import java.lang.*;
import java.net.*;
import ReceiverMCSocket;

/** RTP Thread is subclassed from the Java Thread class. The thread
	loops while receiving datagram packet from the receiver multicast socket.
	Packet received is segmented using the disassemble function of the
	RTP Packet Handler before passing on to the Data Handler for dispatching
	to either the Chat Tool or Whiteboard module for further processing. **/

class RTP_Thread extends Thread {
    DatagramPacket pack;
    byte buf[] = new byte[1024];
	MenuWindow main_parent;
	byte data_buf[] = new byte[1024];

	/** Constructor function **/
    public RTP_Thread( MenuWindow parent ) {
        super();
		main_parent = parent;
        pack = new DatagramPacket(buf, buf.length);
 
    }

	/** run() function of thread is overwritten for receiving and 
	  * disassembling datagram packets **/
    public void run() {
        while (true) {
            pack = main_parent.rtp_recvrSock.receiveData(buf);
            if ( (data_buf = main_parent.pkt_handler.disassemble(pack)) 
															!= null ) {
				main_parent.dataHandler.dispatch(data_buf);
			}
        }
    }

	/** Terminates RTP receiver thread **/
    public void stopthread() {
        stop();
    }
}

