00001 /* -*- Mode:C++; c-basic-offset:8; tab-width:8; indent-tabs-mode:t -*- */ 00002 /* 00003 * Copyright (c) 1997 Regents of the University of California. 00004 * All rights reserved. 00005 * 00006 * Redistribution and use in source and binary forms, with or without 00007 * modification, are permitted provided that the following conditions 00008 * are met: 00009 * 1. Redistributions of source code must retain the above copyright 00010 * notice, this list of conditions and the following disclaimer. 00011 * 2. Redistributions in binary form must reproduce the above copyright 00012 * notice, this list of conditions and the following disclaimer in the 00013 * documentation and/or other materials provided with the distribution. 00014 * 3. All advertising materials mentioning features or use of this software 00015 * must display the following acknowledgement: 00016 * This product includes software developed by the MASH Research 00017 * Group at the University of California Berkeley. 00018 * 4. Neither the name of the University nor of the Research Group may be 00019 * used to endorse or promote products derived from this software without 00020 * specific prior written permission. 00021 * 00022 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 00023 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00024 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 00025 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 00026 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 00027 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 00028 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 00029 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 00030 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 00031 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 00032 * SUCH DAMAGE. 00033 * 00034 * @(#) $Header: /nfs/jade/vint/CVSROOT/ns-2/apps/rtp.h,v 1.14 2000/09/01 03:04:06 haoboy Exp $ 00035 */ 00036 00037 #ifndef ns_rtp_h 00038 #define ns_rtp_h 00039 00040 #include "config.h" 00041 #include "object.h" 00042 #include "agent.h" 00043 #include "timer-handler.h" 00044 00045 #define RTP_M 0x0080 // marker for significant events 00046 00047 /* rtp packet. For now, just have srcid + seqno. */ 00048 struct hdr_rtp { 00049 u_int32_t srcid_; 00050 int seqno_; 00051 //rtp flags indicating significant event(begining of talkspurt) 00052 u_int16_t flags_; 00053 00054 static int offset_; 00055 inline static int& offset() { return offset_; } 00056 inline static hdr_rtp* access(const Packet* p) { 00057 return (hdr_rtp*) p->access(offset_); 00058 } 00059 00060 /* per-field member functions */ 00061 u_int32_t& srcid() { return (srcid_); } 00062 int& seqno() { return (seqno_); } 00063 u_int16_t& flags() { return (flags_); } 00064 }; 00065 00066 class RTPSource : public TclObject { 00067 public: 00068 RTPSource* next; 00069 00070 RTPSource(u_int32_t srcid); 00071 inline u_int32_t srcid() { return (srcid_); } 00072 inline int np() { return (np_); } 00073 inline int snp() { return (snp_); } 00074 inline int ehsr() { return (ehsr_); } 00075 00076 inline void np(int n) { np_ += n; } 00077 inline void snp(int n) { snp_ = n; } 00078 inline void ehsr(int n) { ehsr_ = n; } 00079 protected: 00080 u_int32_t srcid_; 00081 int np_; 00082 int snp_; 00083 int ehsr_; 00084 }; 00085 00086 class RTPSession : public NsObject { 00087 public: 00088 RTPSession(); 00089 ~RTPSession(); 00090 virtual void recv(Packet* p, Handler*); 00091 virtual void recv_ctrl(Packet* p); 00092 int command(int argc, const char*const* argv); 00093 inline u_int32_t srcid() { return (localsrc_->srcid()); } 00094 int build_report(int bye); 00095 void localsrc_update(int); 00096 protected: 00097 RTPSource* allsrcs_; 00098 RTPSource* localsrc_; 00099 int build_sdes(); 00100 int build_bye(); 00101 RTPSource* lookup(u_int32_t); 00102 void enter(RTPSource*); 00103 int last_np_; 00104 }; 00105 00106 class RTPAgent; 00107 00108 class RTPTimer : public TimerHandler { 00109 public: 00110 RTPTimer(RTPAgent *a) : TimerHandler() { a_ = a; } 00111 protected: 00112 virtual void expire(Event *e); 00113 RTPAgent *a_; 00114 }; 00115 00116 class RTPAgent : public Agent { 00117 public: 00118 RTPAgent(); 00119 virtual void timeout(int); 00120 virtual void recv(Packet* p, Handler*); 00121 virtual int command(int argc, const char*const* argv); 00122 void advanceby(int delta); 00123 virtual void sendmsg(int nbytes, const char *flags = 0); 00124 protected: 00125 virtual void sendpkt(); 00126 virtual void makepkt(Packet*); 00127 void rate_change(); 00128 virtual void start(); 00129 virtual void stop(); 00130 virtual void finish(); 00131 RTPSession* session_; 00132 double lastpkttime_; 00133 int seqno_; 00134 int running_; 00135 int random_; 00136 int maxpkts_; 00137 double interval_; 00138 RTPTimer rtp_timer_; 00139 }; 00140 00141 00142 #endif
1.3.3