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

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

fix warning message:
warning: deprecated conversion from string constant to ‘char*’

  • 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
124protected:
125//      void demux(rtphdr* rh, u_char* bp, int cc, Address & addr, int layer);
126        void demux(pktbuf* pb, Address & addr);
127        virtual int check_format(int fmt) const = 0;
128        virtual void transmit(pktbuf* pb);
129        void send_report(int bye);
130        int build_bye(rtcphdr* rh, Source& local);
131        u_char* build_sdes_item(u_char* p, int code, Source&);
132        int build_sdes(rtcphdr* rh, Source& s);
133        int build_app(rtcphdr* rh, Source& ls, const char *name,
134                        void *data, int datalen);
135
136        void parse_sr(rtcphdr* rh, int flags, u_char* ep,
137                      Source* ps, Address & addr, int layer);
138        void parse_rr(rtcphdr* rh, int flags, u_char* ep,
139                      Source* ps, Address & addr, int layer);
140        void parse_rr_records(u_int32_t ssrc, rtcp_rr* r, int cnt,
141                              const u_char* ep, Address & addr);
142        int sdesbody(u_int32_t* p, u_char* ep, Source* ps,
143                     Address & addr, u_int32_t ssrc, int layer);
144        void parse_sdes(rtcphdr* rh, int flags, u_char* ep, Source* ps,
145                        Address & addr, u_int32_t ssrc, int layer);
146        void parse_bye(rtcphdr* rh, int flags, u_char* ep, Source* ps);
147
148        int parseopts(const u_char* bp, int cc, Address & addr) const;
149        int ckid(const char*, int len);
150
151        u_int32_t alloc_srcid(Address & addr) const;
152
153        int lipSyncEnabled() { return (lipSyncEnabled_);}
154        void lipSyncEnabled(int v) { lipSyncEnabled_=v;}
155
156        char* stats(char* cp) const;
157
158        DataHandler dh_[NLAYER];
159        CtrlHandler ch_[NLAYER];
160
161        // MBus stuff
162        MBusHandler mb_; // Handles mbus and interfaces to mbus
163                                         // code in common libraries
164        int lipSyncEnabled_;
165
166        /*XXX cleanup*/
167        u_int badversion_;
168        u_int badoptions_;
169        u_int badfmt_;
170        u_int badext_;
171        u_int nrunt_;
172
173        u_int32_t last_np_;
174        u_int32_t sdes_seq_;
175
176        double rtcp_inv_bw_;
177        double rtcp_avg_size_;  /* (estimated) average size of rtcp packets */
178        double rint_;           /* current session report rate (in ms) */
179
180        int confid_;
181
182        BufferPool* pool_;
183        u_char* pktbuf_;
184
185        SourceManager *sm_;
186};
187
188class AudioSessionManager : public SessionManager {
189    protected:
190        int check_format(int fmt) const;
191};
192
193class VideoSessionManager : public SessionManager {
194    protected:
195        int check_format(int fmt) const;
196};
197
198
199#endif
Note: See TracBrowser for help on using the browser.