| 1 | |
|---|
| 2 | |
|---|
| 3 | |
|---|
| 4 | |
|---|
| 5 | |
|---|
| 6 | |
|---|
| 7 | |
|---|
| 8 | |
|---|
| 9 | |
|---|
| 10 | |
|---|
| 11 | |
|---|
| 12 | |
|---|
| 13 | |
|---|
| 14 | |
|---|
| 15 | |
|---|
| 16 | |
|---|
| 17 | |
|---|
| 18 | |
|---|
| 19 | |
|---|
| 20 | |
|---|
| 21 | |
|---|
| 22 | |
|---|
| 23 | |
|---|
| 24 | |
|---|
| 25 | |
|---|
| 26 | |
|---|
| 27 | |
|---|
| 28 | |
|---|
| 29 | |
|---|
| 30 | |
|---|
| 31 | |
|---|
| 32 | |
|---|
| 33 | |
|---|
| 34 | |
|---|
| 35 | |
|---|
| 36 | |
|---|
| 37 | #ifndef vic_session_h |
|---|
| 38 | #define vic_session_h |
|---|
| 39 | |
|---|
| 40 | #include "net.h" |
|---|
| 41 | #include "transmitter.h" |
|---|
| 42 | #include "timer.h" |
|---|
| 43 | #include "iohandler.h" |
|---|
| 44 | #include "source.h" |
|---|
| 45 | #include "mbus_handler.h" |
|---|
| 46 | |
|---|
| 47 | class Source; |
|---|
| 48 | class SessionManager; |
|---|
| 49 | |
|---|
| 50 | class DataHandler : public IOHandler { |
|---|
| 51 | public: |
|---|
| 52 | DataHandler* next; |
|---|
| 53 | inline DataHandler() : next(0), sm_(0), net_(0), addrp_(0) {} |
|---|
| 54 | |
|---|
| 55 | virtual void dispatch(int mask); |
|---|
| 56 | inline Network* net() const { return (net_); } |
|---|
| 57 | virtual void net(Network* net) { |
|---|
| 58 | unlink(); |
|---|
| 59 | link(net->rchannel(), TK_READABLE); |
|---|
| 60 | net_ = net; |
|---|
| 61 | if (addrp_) delete addrp_; |
|---|
| 62 | addrp_ = net->addr().copy(); |
|---|
| 63 | } |
|---|
| 64 | inline int recv(u_char* bp, int len, Address*& addrp) { |
|---|
| 65 | return (net_->recv(bp, len, *(addrp = addrp_))); |
|---|
| 66 | } |
|---|
| 67 | inline void send(u_char* bp, int len) { |
|---|
| 68 | net_->send(bp, len); |
|---|
| 69 | } |
|---|
| 70 | inline void manager(SessionManager* sm) { sm_ = sm; } |
|---|
| 71 | protected: |
|---|
| 72 | SessionManager *sm_; |
|---|
| 73 | Network* net_; |
|---|
| 74 | Address *addrp_; |
|---|
| 75 | }; |
|---|
| 76 | |
|---|
| 77 | |
|---|
| 78 | |
|---|
| 79 | #define CTRL_SESSION_BW_FRACTION (0.05) |
|---|
| 80 | #define CTRL_MIN_RPT_TIME (5.) |
|---|
| 81 | #define CTRL_SENDER_BW_FRACTION (0.25) |
|---|
| 82 | #define CTRL_RECEIVER_BW_FRACTION (1. - CTRL_SENDER_BW_FRACTION) |
|---|
| 83 | #define CTRL_SIZE_GAIN (1./8.) |
|---|
| 84 | |
|---|
| 85 | class CtrlHandler : public DataHandler, public Timer { |
|---|
| 86 | public: |
|---|
| 87 | CtrlHandler(); |
|---|
| 88 | |
|---|
| 89 | virtual void dispatch(int mask); |
|---|
| 90 | inline Network* net() const { return (net_); } |
|---|
| 91 | |
|---|
| 92 | virtual void timeout(); |
|---|
| 93 | virtual void net(Network* net); |
|---|
| 94 | void adapt(int nsrc, int nrr, int we_sent); |
|---|
| 95 | void sample_size(int cc); |
|---|
| 96 | inline double rint() const { return (rint_); } |
|---|
| 97 | void send_aoa(); |
|---|
| 98 | void send_ts(); |
|---|
| 99 | |
|---|
| 100 | protected: |
|---|
| 101 | void schedule_timer(); |
|---|
| 102 | double ctrl_inv_bw_; |
|---|
| 103 | double ctrl_avg_size_; |
|---|
| 104 | double rint_; |
|---|
| 105 | }; |
|---|
| 106 | |
|---|
| 107 | class ReportTimer : public Timer { |
|---|
| 108 | public: |
|---|
| 109 | inline ReportTimer(SessionManager& sm) : sm_(sm) {} |
|---|
| 110 | void timeout(); |
|---|
| 111 | protected: |
|---|
| 112 | SessionManager& sm_; |
|---|
| 113 | }; |
|---|
| 114 | |
|---|
| 115 | |
|---|
| 116 | |
|---|
| 117 | |
|---|
| 118 | |
|---|
| 119 | |
|---|
| 120 | |
|---|
| 121 | class SessionManager : public Transmitter, public MtuAlloc { |
|---|
| 122 | public: |
|---|
| 123 | SessionManager(); |
|---|
| 124 | virtual ~SessionManager(); |
|---|
| 125 | virtual int command(int argc, const char*const* argv); |
|---|
| 126 | virtual void recv(CtrlHandler*); |
|---|
| 127 | virtual void recv(DataHandler*); |
|---|
| 128 | virtual void announce(CtrlHandler*); |
|---|
| 129 | |
|---|
| 130 | virtual inline void send_bye() { send_report(&ch_[0], 1); } |
|---|
| 131 | |
|---|
| 132 | virtual void send_report(CtrlHandler*, int bye, int app = 0); |
|---|
| 133 | virtual void send_xreport(CtrlHandler*, int bye, int app = 0); |
|---|
| 134 | void build_aoa_pkt(CtrlHandler* ch); |
|---|
| 135 | void build_ts_pkt(CtrlHandler* ch); |
|---|
| 136 | |
|---|
| 137 | protected: |
|---|
| 138 | |
|---|
| 139 | void demux(pktbuf* pb, Address & addr); |
|---|
| 140 | virtual int check_format(int fmt) const = 0; |
|---|
| 141 | virtual void transmit(pktbuf* pb); |
|---|
| 142 | void send_report(int bye); |
|---|
| 143 | int build_bye(rtcphdr* rh, Source& local); |
|---|
| 144 | u_char* build_sdes_item(u_char* p, int code, Source&); |
|---|
| 145 | int build_sdes(rtcphdr* rh, Source& s); |
|---|
| 146 | int build_app(rtcphdr* rh, Source& ls, const char *name, |
|---|
| 147 | void *data, int datalen); |
|---|
| 148 | |
|---|
| 149 | void parse_sr(rtcphdr* rh, int flags, u_char* ep, |
|---|
| 150 | Source* ps, Address & addr, int layer); |
|---|
| 151 | void parse_rr(rtcphdr* rh, int flags, u_char* ep, |
|---|
| 152 | Source* ps, Address & addr, int layer); |
|---|
| 153 | void parse_xr(rtcphdr* rh, int flags, u_char* ep, |
|---|
| 154 | Source* ps, Address & addr, int layer); |
|---|
| 155 | void parse_rr_records(u_int32_t ssrc, rtcp_rr* r, int cnt, |
|---|
| 156 | const u_char* ep, Address & addr); |
|---|
| 157 | void parse_xr_records(u_int32_t ssrc, rtcp_xr_hdr* xrh, int cnt, |
|---|
| 158 | const u_char* ep, Address & addr); |
|---|
| 159 | int sdesbody(u_int32_t* p, u_char* ep, Source* ps, |
|---|
| 160 | Address & addr, u_int32_t ssrc, int layer); |
|---|
| 161 | void parse_sdes(rtcphdr* rh, int flags, u_char* ep, Source* ps, |
|---|
| 162 | Address & addr, u_int32_t ssrc, int layer); |
|---|
| 163 | void parse_bye(rtcphdr* rh, int flags, u_char* ep, Source* ps); |
|---|
| 164 | u_char* build_ackv_pkt(rtcp_xr_hdr* xrh, u_int32_t ssrc); |
|---|
| 165 | u_char* build_ts_echo_pkt(rtcp_xr_hdr* xrh, u_int32_t ssrc); |
|---|
| 166 | |
|---|
| 167 | int parseopts(const u_char* bp, int cc, Address & addr) const; |
|---|
| 168 | int ckid(const char*, int len); |
|---|
| 169 | |
|---|
| 170 | u_int32_t alloc_srcid(Address & addr) const; |
|---|
| 171 | |
|---|
| 172 | int lipSyncEnabled() { return (lipSyncEnabled_);} |
|---|
| 173 | void lipSyncEnabled(int v) { lipSyncEnabled_=v;} |
|---|
| 174 | |
|---|
| 175 | char* stats(char* cp) const; |
|---|
| 176 | |
|---|
| 177 | DataHandler dh_[NLAYER]; |
|---|
| 178 | CtrlHandler ch_[NLAYER]; |
|---|
| 179 | |
|---|
| 180 | |
|---|
| 181 | MBusHandler mb_; |
|---|
| 182 | |
|---|
| 183 | int lipSyncEnabled_; |
|---|
| 184 | |
|---|
| 185 | |
|---|
| 186 | u_int badversion_; |
|---|
| 187 | u_int badoptions_; |
|---|
| 188 | u_int badfmt_; |
|---|
| 189 | u_int badext_; |
|---|
| 190 | u_int nrunt_; |
|---|
| 191 | |
|---|
| 192 | u_int32_t last_np_; |
|---|
| 193 | u_int32_t sdes_seq_; |
|---|
| 194 | |
|---|
| 195 | double rtcp_inv_bw_; |
|---|
| 196 | double rtcp_avg_size_; |
|---|
| 197 | double rint_; |
|---|
| 198 | |
|---|
| 199 | int confid_; |
|---|
| 200 | |
|---|
| 201 | BufferPool* pool_; |
|---|
| 202 | u_char* pktbuf_; |
|---|
| 203 | |
|---|
| 204 | SourceManager *sm_; |
|---|
| 205 | |
|---|
| 206 | |
|---|
| 207 | u_int16_t seqno_; |
|---|
| 208 | u_int16_t lastseq_; |
|---|
| 209 | u_int16_t ackofack_; |
|---|
| 210 | |
|---|
| 211 | |
|---|
| 212 | u_int32_t ackvec_; |
|---|
| 213 | u_int32_t ts_; |
|---|
| 214 | u_int32_t ts_echo_; |
|---|
| 215 | }; |
|---|
| 216 | |
|---|
| 217 | class AudioSessionManager : public SessionManager { |
|---|
| 218 | protected: |
|---|
| 219 | int check_format(int fmt) const; |
|---|
| 220 | }; |
|---|
| 221 | |
|---|
| 222 | class VideoSessionManager : public SessionManager { |
|---|
| 223 | protected: |
|---|
| 224 | int check_format(int fmt) const; |
|---|
| 225 | }; |
|---|
| 226 | |
|---|
| 227 | |
|---|
| 228 | #endif |
|---|