| 1 | package cz.vutbr.feec.session.rtprtcp.internal; |
| 2 | |
| 3 | import org.apache.log4j.Logger; |
| 4 | |
| 5 | /** |
| 6 | * This class creates and starts the RTCP sender and receiver threads. |
| 7 | */ |
| 8 | abstract public class RTCPThreadHandler { |
| 9 | |
| 10 | /** The logger. */ |
| 11 | private static Logger logger = Logger.getLogger(RTCPThreadHandler.class.getName()); |
| 12 | |
| 13 | /** Reference to the RTCP Receiver Thread. */ |
| 14 | protected RTCPInThread rtcpReceiverThread; |
| 15 | |
| 16 | /** Reference to the RTCP Sender Thread. */ |
| 17 | protected RTCPOutThread rtcpSenderThread; |
| 18 | |
| 19 | /** The rtp session. */ |
| 20 | protected Session3550 rtpSession; |
| 21 | |
| 22 | protected RTCPThreadHandler() { |
| 23 | } |
| 24 | |
| 25 | /** |
| 26 | * Starts the RTCP Sender thread. |
| 27 | */ |
| 28 | public void startRTCPSenderThread() { |
| 29 | rtcpSenderThread.start(); |
| 30 | } |
| 31 | |
| 32 | /** |
| 33 | * Starts the RTCP Receiver thread. |
| 34 | */ |
| 35 | public void startRTCPReceiverThread() { |
| 36 | rtcpReceiverThread.start(); |
| 37 | } |
| 38 | |
| 39 | /** |
| 40 | * Reschedule the time to send RTCP packet. |
| 41 | * |
| 42 | * @param expireTime the expire time |
| 43 | */ |
| 44 | public void reschedule(double expireTime) { |
| 45 | rtcpSenderThread.schedule(expireTime); |
| 46 | // interrupt from waiting and reschedule wait period |
| 47 | rtcpSenderThread.interrupt(); |
| 48 | } |
| 49 | |
| 50 | /** |
| 51 | * Interrupts a running RTCP sender thread. This will cause the sender to |
| 52 | * send BYE packet and finally terminate. |
| 53 | */ |
| 54 | public void stopThreads() { |
| 55 | rtcpSenderThread.stopRTCPSender(); |
| 56 | rtcpReceiverThread.stopThread(); |
| 57 | } |
| 58 | |
| 59 | /** |
| 60 | * Mirror packet. |
| 61 | * |
| 62 | * @param packet the packet |
| 63 | */ |
| 64 | public void mirrorPacket(byte[] packet, int length) { |
| 65 | // only sender in SSM mode can mirror packets |
| 66 | assert rtpSession.isSSM() && rtpSession.isSender() : "Only sender in SSM mode can mirror packets."; |
| 67 | logger.debug("MIRORRING RTCP PACKET len:"+packet.length); |
| 68 | rtcpSenderThread.sendPacket(packet, length); |
| 69 | } |
| 70 | |
| 71 | /** |
| 72 | * Gets the dest RTCP port. |
| 73 | * |
| 74 | * @return the dest RTCP port |
| 75 | */ |
| 76 | public int getDestRTCPPort() { |
| 77 | return rtcpSenderThread.getDestRtcpPort(); |
| 78 | } |
| 79 | } |