root/vic/branches/cc/rtp/session.h @ 4245

Revision 4245, 7.0 KB (checked in by soohyunc, 6 years ago)

o now, ackvec build funcion is moved to TfwcRcvr? correctly

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
RevLine 
[900]1/*
2 * Copyright (c) 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)
[4233]34 * $Id$
[900]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
47class Source;
48class SessionManager;
49
50class DataHandler : public IOHandler {
51    public:
[956]52        DataHandler* next;
53        inline DataHandler() : next(0), sm_(0), net_(0), addrp_(0) {}
54//      inline DataHandler(SessionManager& sm) : sm_(sm), net_(0), addrp_(0) {}
[900]55        virtual void dispatch(int mask);
56        inline Network* net() const { return (net_); }
[956]57        virtual void net(Network* net) {
[900]58                unlink();
59                link(net->rchannel(), TK_READABLE);
60                net_ = net;
61                if (addrp_) delete addrp_;
62                addrp_ = net->addr().copy(); // get right type of address
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        }
[956]70        inline void manager(SessionManager* sm) { sm_ = sm; }
[900]71    protected:
[956]72        SessionManager *sm_;
[900]73        Network* net_;
74        Address *addrp_;
75};
[956]76/*
77 * Parameters controling the RTCP report rate timer.
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.)
[900]84
[956]85class CtrlHandler : public DataHandler, public Timer {
[900]86    public:
[956]87        CtrlHandler();
88//      inline CtrlHandler(SessionManager& sm) : DataHandler(sm) {}
[900]89        virtual void dispatch(int mask);
[956]90        inline Network* net() const { return (net_); }
91// new for layering - individual report timers for each layer
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 protected:
98        void schedule_timer();
99        double ctrl_inv_bw_;
100        double ctrl_avg_size_;  /* (estimated) average size of ctrl packets */
101        double rint_;           /* current session report rate (in ms) */
[900]102};
103
104class ReportTimer : public Timer {
105    public:
106        inline ReportTimer(SessionManager& sm) : sm_(sm) {}
107        void timeout();
108    protected:
109        SessionManager& sm_;
110};
111
[4233]112// set AckVec bitmap
[4242]113//#define SET_BIT_VEC(ackvec_, bit) (ackvec_ = ((ackvec_ << 1) | bit))
[4233]114
115// see AckVec bitmap
[4242]116//#define SEE_BIT_VEC(ackvec_, ix, seqno) ((1 << (seqno - ix)) & ackvec_)
[4233]117
[900]118class SessionManager : public Transmitter, public MtuAlloc {
[956]119public:
[900]120        SessionManager();
121        virtual ~SessionManager();
122        virtual int command(int argc, const char*const* argv);
123        virtual void recv(CtrlHandler*);
124        virtual void recv(DataHandler*);
[956]125        virtual void announce(CtrlHandler*); //LLL
126//      virtual void send_bye();
127        virtual inline void send_bye() { send_report(&ch_[0], 1); }
128//      virtual void send_report();
129        virtual void send_report(CtrlHandler*, int bye, int app = 0);
130
131protected:
132//      void demux(rtphdr* rh, u_char* bp, int cc, Address & addr, int layer);
133        void demux(pktbuf* pb, Address & addr);
[900]134        virtual int check_format(int fmt) const = 0;
135        virtual void transmit(pktbuf* pb);
136        void send_report(int bye);
137        int build_bye(rtcphdr* rh, Source& local);
[3995]138        u_char* build_sdes_item(u_char* p, int code, Source&);
[900]139        int build_sdes(rtcphdr* rh, Source& s);
[4184]140        int build_app(rtcphdr* rh, Source& ls, const char *name,
141                        void *data, int datalen);
[900]142
143        void parse_sr(rtcphdr* rh, int flags, u_char* ep,
[956]144                      Source* ps, Address & addr, int layer);
[900]145        void parse_rr(rtcphdr* rh, int flags, u_char* ep,
[956]146                      Source* ps, Address & addr, int layer);
[4234]147        void parse_xr(rtcphdr* rh, int flags, u_char* ep,
148                      Source* ps, Address & addr, int layer);
[900]149        void parse_rr_records(u_int32_t ssrc, rtcp_rr* r, int cnt,
150                              const u_char* ep, Address & addr);
[4234]151        void parse_xr_records(u_int32_t ssrc, rtcp_xr* r, int cnt,
152                              const u_char* ep, Address & addr);
[900]153        int sdesbody(u_int32_t* p, u_char* ep, Source* ps,
[956]154                     Address & addr, u_int32_t ssrc, int layer);
[900]155        void parse_sdes(rtcphdr* rh, int flags, u_char* ep, Source* ps,
[956]156                        Address & addr, u_int32_t ssrc, int layer);
[900]157        void parse_bye(rtcphdr* rh, int flags, u_char* ep, Source* ps);
158
159        int parseopts(const u_char* bp, int cc, Address & addr) const;
160        int ckid(const char*, int len);
161
162        u_int32_t alloc_srcid(Address & addr) const;
163
164        int lipSyncEnabled() { return (lipSyncEnabled_);}
165        void lipSyncEnabled(int v) { lipSyncEnabled_=v;}
166
167        char* stats(char* cp) const;
168
[956]169        DataHandler dh_[NLAYER];
170        CtrlHandler ch_[NLAYER];
[900]171
172        // MBus stuff
173        MBusHandler mb_; // Handles mbus and interfaces to mbus
174                                         // code in common libraries
175        int lipSyncEnabled_;
176
177        /*XXX cleanup*/
178        u_int badversion_;
179        u_int badoptions_;
180        u_int badfmt_;
181        u_int badext_;
182        u_int nrunt_;
183
184        u_int32_t last_np_;
185        u_int32_t sdes_seq_;
186
187        double rtcp_inv_bw_;
188        double rtcp_avg_size_;  /* (estimated) average size of rtcp packets */
189        double rint_;           /* current session report rate (in ms) */
190
191        int confid_;
192
[956]193        BufferPool* pool_;
[900]194        u_char* pktbuf_;
[956]195
196        SourceManager *sm_;
[4245]197        TfwcRcvr *tfwc_rcvr_;
[4233]198
199        // RTP packet sequence number (for the use of AckVec)
200        u_int16_t seqno_;               // RTP packet sequence number
201        u_int16_t lastseq_;             // last packet's seqno
202
203        // AckVector
204        u_int32_t ackvec_;              // this is a bit vector
[900]205};
206
207class AudioSessionManager : public SessionManager {
208    protected:
209        int check_format(int fmt) const;
210};
211
212class VideoSessionManager : public SessionManager {
213    protected:
214        int check_format(int fmt) const;
215};
216
217
218#endif
Note: See TracBrowser for help on using the browser.