root/vic/branches/cc/rtp/transmitter.h
@
4683
| Revision 4683, 4.6 KB (checked in by soohyunc, 3 years ago) | |
|---|---|
|
|
| Line | |
|---|---|
| 1 | /* |
| 2 | * Copyright (c) 1993-1995 The Regents of the University of California. |
| 3 | * All rights reserved. |
| 4 | * |
| 5 | * Redistribution and use in source and binary forms, with or without |
| 6 | * modification, are permitted provided that the following conditions |
| 7 | * are met: |
| 8 | * 1. Redistributions of source code must retain the above copyright |
| 9 | * notice, this list of conditions and the following disclaimer. |
| 10 | * 2. Redistributions in binary form must reproduce the above copyright |
| 11 | * notice, this list of conditions and the following disclaimer in the |
| 12 | * documentation and/or other materials provided with the distribution. |
| 13 | * 3. All advertising materials mentioning features or use of this software |
| 14 | * must display the following acknowledgement: |
| 15 | * This product includes software developed by the Network Research |
| 16 | * Group at Lawrence Berkeley National Laboratory. |
| 17 | * 4. Neither the name of the University nor of the Laboratory may be used |
| 18 | * to endorse or promote products derived from this software without |
| 19 | * specific prior written permission. |
| 20 | * |
| 21 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND |
| 22 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 23 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 24 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE |
| 25 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
| 26 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
| 27 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
| 28 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
| 29 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
| 30 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
| 31 | * SUCH DAMAGE. |
| 32 | * |
| 33 | * @(#) $Header$ (LBL) |
| 34 | * $Id$ |
| 35 | */ |
| 36 | |
| 37 | #ifndef vic_transmitter_h |
| 38 | #define vic_transmitter_h |
| 39 | |
| 40 | #ifdef WIN32 |
| 41 | //#include <winsock.h> |
| 42 | #else |
| 43 | #include <sys/param.h> |
| 44 | #include <sys/socket.h> |
| 45 | #include <sys/uio.h> |
| 46 | #endif |
| 47 | #include "vic_tcl.h" |
| 48 | #include "timer.h" |
| 49 | #include "rtp.h" |
| 50 | #include "inet.h" |
| 51 | #include "pktbuf-rtp.h" |
| 52 | #include "cc/tfwc_sndr.h" |
| 53 | #include "cc/tfwc_rcvr.h" |
| 54 | |
| 55 | #define NOCC 100 |
| 56 | #define WBCC 101 |
| 57 | #define RBCC 102 |
| 58 | |
| 59 | /* |
| 60 | * The base object for performing the outbound path of |
| 61 | * the application level protocol. |
| 62 | */ |
| 63 | class Transmitter : public TclObject, public Timer, |
| 64 | public TfwcSndr, public TfwcRcvr { |
| 65 | public: |
| 66 | Transmitter(); |
| 67 | virtual void timeout(); |
| 68 | |
| 69 | struct buffer { |
| 70 | struct buffer* next; |
| 71 | /* |
| 72 | * make buffer twice as big as necessary so we can |
| 73 | * run off end while doing in-place encoding. |
| 74 | */ |
| 75 | u_char data[2 * RTP_MTU]; |
| 76 | }; |
| 77 | /* struct pktbuf { |
| 78 | struct pktbuf* next; |
| 79 | iovec iov[2]; |
| 80 | u_char hdr[MAXHDR]; |
| 81 | buffer* buf; |
| 82 | int layer; |
| 83 | };*/ |
| 84 | static void dump(int fd); |
| 85 | static inline void seqno(u_int16_t s) { seqno_ = s; } |
| 86 | inline void bps(int kbps) { kbps = kbps_; } |
| 87 | inline void loop_layer(int loop_layer) { loop_layer_ = loop_layer; } |
| 88 | inline int loop_layer() { return loop_layer_; } |
| 89 | inline int mtu() { return (mtu_); } |
| 90 | void flush(); |
| 91 | void send(pktbuf*); |
| 92 | inline bool is_cc_on() { return is_cc_active_; } |
| 93 | virtual void cc_tfwc_output(); |
| 94 | void cc_tfwc_output(pktbuf*); |
| 95 | void cc_tfrc_output(); |
| 96 | |
| 97 | /* |
| 98 | * Buffer allocation hooks. |
| 99 | */ |
| 100 | //pktbuf* alloch(u_int32_t, int fmt); |
| 101 | //void release(pktbuf*); |
| 102 | //pktbuf* alloc(u_int32_t, int fmt); |
| 103 | |
| 104 | inline double tx_now() { |
| 105 | timeval tv; |
| 106 | ::gettimeofday(&tv, NULL); |
| 107 | return ((double) tv.tv_sec + 1e-6 * (double) tv.tv_usec); |
| 108 | } |
| 109 | double tx_now_offset_; |
| 110 | |
| 111 | // Tx pktbuf size |
| 112 | int tx_buf_size(); |
| 113 | |
| 114 | protected: |
| 115 | void update(int nbytes); |
| 116 | void dump(int fd, iovec*, int iovel) const; |
| 117 | void loopback(pktbuf*); |
| 118 | void output(pktbuf* pb); |
| 119 | void output_data_only(pktbuf* pb); |
| 120 | virtual void transmit(pktbuf* pb) = 0; |
| 121 | virtual void tx_data_only(pktbuf* pb) = 0; |
| 122 | double gettimeofday_secs() const; |
| 123 | double txtime(pktbuf* pb); |
| 124 | |
| 125 | int mtu_; /* mtu of wire (as seen by application) */ |
| 126 | msghdr mh_; |
| 127 | |
| 128 | int nf_; /* number of frames sent */ |
| 129 | int nb_; /* number of bytes sent */ |
| 130 | int np_; /* number of packets sent */ |
| 131 | |
| 132 | int kbps_; /* bit-rate for interpkt spacing */ |
| 133 | double nextpkttime_; |
| 134 | |
| 135 | /* packet transmission queue */ |
| 136 | int busy_; |
| 137 | pktbuf* head_; |
| 138 | pktbuf* tail_; |
| 139 | |
| 140 | int loop_layer_; /* # of layers to loop back (for testing) */ |
| 141 | |
| 142 | int loopback_; /* true to loopback data packets */ |
| 143 | static int dumpfd_; /* fd to dump packet stream to */ |
| 144 | static u_int16_t seqno_; |
| 145 | |
| 146 | /* Cc related variables */ |
| 147 | bool is_cc_active_; /* is Cc module activated? */ |
| 148 | bool is_buf_empty_; /* is pktbuf empty? */ |
| 149 | int cc_type_; |
| 150 | int epc_; /* experimental packet counter */ |
| 151 | |
| 152 | private: |
| 153 | static pktbuf* freehdrs_; |
| 154 | static buffer* freebufs_; |
| 155 | static int nbufs_; |
| 156 | static int nhdrs_; |
| 157 | }; |
| 158 | |
| 159 | #endif |
Note: See TracBrowser
for help on using the browser.
