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

Revision 4228, 6.4 KB (checked in by soohyunc, 6 years ago)

(temporary commit)
o now, we can give a packet sequence number and print on console
o and, the receiver print the received packet's seqno on console
o note: this is an experimental commit

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
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)
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
46class Source;
47class SessionManager;
48
49class DataHandler : public IOHandler {
50    public:
51        DataHandler* next;
52        inline DataHandler() : next(0), sm_(0), net_(0), addrp_(0) {}
53//      inline DataHandler(SessionManager& sm) : sm_(sm), net_(0), addrp_(0) {}
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(); // get right type of address
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 * Parameters controling the RTCP report rate timer.
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
84class CtrlHandler : public DataHandler, public Timer {
85    public:
86        CtrlHandler();
87//      inline CtrlHandler(SessionManager& sm) : DataHandler(sm) {}
88        virtual void dispatch(int mask);
89        inline Network* net() const { return (net_); }
90// new for layering - individual report timers for each layer
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_;  /* (estimated) average size of ctrl packets */
100        double rint_;           /* current session report rate (in ms) */
101};
102
103class ReportTimer : public Timer {
104    public:
105        inline ReportTimer(SessionManager& sm) : sm_(sm) {}
106        void timeout();
107    protected:
108        SessionManager& sm_;
109};
110
111class SessionManager : public Transmitter, public MtuAlloc {
112public:
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*); //LLL
119//      virtual void send_bye();
120        virtual inline void send_bye() { send_report(&ch_[0], 1); }
121//      virtual void send_report();
122        virtual void send_report(CtrlHandler*, int bye, int app = 0);
123
124        u_int16_t seqno_;       // received packet sequence number
125
126protected:
127//      void demux(rtphdr* rh, u_char* bp, int cc, Address & addr, int layer);
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        // MBus stuff
164        MBusHandler mb_; // Handles mbus and interfaces to mbus
165                                         // code in common libraries
166        int lipSyncEnabled_;
167
168        /*XXX cleanup*/
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_;  /* (estimated) average size of rtcp packets */
180        double rint_;           /* current session report rate (in ms) */
181
182        int confid_;
183
184        BufferPool* pool_;
185        u_char* pktbuf_;
186
187        SourceManager *sm_;
188};
189
190class AudioSessionManager : public SessionManager {
191    protected:
192        int check_format(int fmt) const;
193};
194
195class VideoSessionManager : public SessionManager {
196    protected:
197        int check_format(int fmt) const;
198};
199
200
201#endif
Note: See TracBrowser for help on using the browser.