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